forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
187 lines (148 loc) · 4.95 KB
/
ui.js
File metadata and controls
187 lines (148 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
/**
* UI reducer
* @module reducers/ui
*/
import makeRecord from "../utils/makeRecord";
import { prefs } from "../utils/prefs";
import type { Action, panelPositionType } from "../actions/types";
import type { Record } from "../utils/makeRecord";
export type ActiveSearchType = "project" | "file";
export type OrientationType = "horizontal" | "vertical";
export type SelectedPrimaryPaneTabType = "sources" | "outline";
export type UIState = {
selectedPrimaryPaneTab: SelectedPrimaryPaneTabType,
activeSearch: ?ActiveSearchType,
contextMenu: any,
shownSource: string,
startPanelCollapsed: boolean,
endPanelCollapsed: boolean,
frameworkGroupingOn: boolean,
projectDirectoryRoot: string,
orientation: OrientationType,
highlightedLineRange?: {
start?: number,
end?: number,
sourceId?: number
},
conditionalPanelLine: null | number
};
export const createUIState = makeRecord(
({
selectedPrimaryPaneTab: "sources",
activeSearch: null,
contextMenu: {},
shownSource: "",
projectDirectoryRoot: prefs.projectDirectoryRoot,
startPanelCollapsed: prefs.startPanelCollapsed,
endPanelCollapsed: prefs.endPanelCollapsed,
frameworkGroupingOn: prefs.frameworkGroupingOn,
highlightedLineRange: undefined,
conditionalPanelLine: null,
orientation: "horizontal"
}: UIState)
);
function update(
state: Record<UIState> = createUIState(),
action: Action
): Record<UIState> {
switch (action.type) {
case "TOGGLE_ACTIVE_SEARCH": {
return state.set("activeSearch", action.value);
}
case "TOGGLE_FRAMEWORK_GROUPING": {
prefs.frameworkGroupingOn = action.value;
return state.set("frameworkGroupingOn", action.value);
}
case "SET_CONTEXT_MENU": {
return state.set("contextMenu", action.contextMenu);
}
case "SET_ORIENTATION": {
return state.set("orientation", action.orientation);
}
case "SHOW_SOURCE": {
return state.set("shownSource", action.sourceUrl);
}
case "TOGGLE_PANE": {
if (action.position == "start") {
prefs.startPanelCollapsed = action.paneCollapsed;
return state.set("startPanelCollapsed", action.paneCollapsed);
}
prefs.endPanelCollapsed = action.paneCollapsed;
return state.set("endPanelCollapsed", action.paneCollapsed);
}
case "HIGHLIGHT_LINES":
const { start, end, sourceId } = action.location;
let lineRange = {};
if (start && end && sourceId) {
lineRange = { start, end, sourceId };
}
return state.set("highlightedLineRange", lineRange);
case "CLOSE_QUICK_OPEN":
case "CLEAR_HIGHLIGHT_LINES":
return state.set("highlightedLineRange", {});
case "OPEN_CONDITIONAL_PANEL":
return state.set("conditionalPanelLine", action.line);
case "CLOSE_CONDITIONAL_PANEL":
return state.set("conditionalPanelLine", null);
case "SET_PROJECT_DIRECTORY_ROOT":
prefs.projectDirectoryRoot = action.url;
return state.set("projectDirectoryRoot", action.url);
case "SET_PRIMARY_PANE_TAB":
return state.set("selectedPrimaryPaneTab", action.tabName);
case "CLOSE_PROJECT_SEARCH": {
if (state.get("activeSearch") === "project") {
return state.set("activeSearch", null);
}
return state;
}
default: {
return state;
}
}
}
// NOTE: we'd like to have the app state fully typed
// https://github.com/devtools-html/debugger.html/blob/master/src/reducers/sources.js#L179-L185
type OuterState = { ui: Record<UIState> };
export function getSelectedPrimaryPaneTab(
state: OuterState
): SelectedPrimaryPaneTabType {
return state.ui.get("selectedPrimaryPaneTab");
}
export function getActiveSearch(state: OuterState): ActiveSearchType {
return state.ui.get("activeSearch");
}
export function getContextMenu(state: OuterState): any {
return state.ui.get("contextMenu");
}
export function getFrameworkGroupingState(state: OuterState): boolean {
return state.ui.get("frameworkGroupingOn");
}
export function getShownSource(state: OuterState): boolean {
return state.ui.get("shownSource");
}
export function getPaneCollapse(
state: OuterState,
position: panelPositionType
): boolean {
if (position == "start") {
return state.ui.get("startPanelCollapsed");
}
return state.ui.get("endPanelCollapsed");
}
export function getHighlightedLineRange(state: OuterState) {
return state.ui.get("highlightedLineRange");
}
export function getConditionalPanelLine(state: OuterState): null | number {
return state.ui.get("conditionalPanelLine");
}
export function getProjectDirectoryRoot(state: OuterState): string {
return state.ui.get("projectDirectoryRoot");
}
export function getOrientation(state: OuterState): boolean {
return state.ui.get("orientation");
}
export default update;