react-resizable-panels 1.0.0-rc.2 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-resizable-panels.browser.cjs.js +26 -10
- package/dist/react-resizable-panels.browser.development.cjs.js +26 -10
- package/dist/react-resizable-panels.browser.development.esm.js +26 -10
- package/dist/react-resizable-panels.browser.esm.js +26 -10
- package/dist/react-resizable-panels.cjs.d.ts +1 -88
- package/dist/react-resizable-panels.cjs.d.ts.map +1 -1
- package/dist/react-resizable-panels.cjs.js +1741 -1488
- package/dist/react-resizable-panels.development.cjs.js +26 -10
- package/dist/react-resizable-panels.development.esm.js +26 -10
- package/dist/react-resizable-panels.development.node.cjs.js +26 -10
- package/dist/react-resizable-panels.development.node.esm.js +26 -10
- package/dist/react-resizable-panels.esm.js +1716 -1483
- package/dist/react-resizable-panels.node.cjs.js +26 -10
- package/dist/react-resizable-panels.node.esm.js +26 -10
- package/package.json +1 -1
- package/src/NewPanelGroup.ts +149 -0
- package/dist/react-resizable-panels.cjs.js.map +0 -1
- package/dist/react-resizable-panels.esm.js.map +0 -1
|
@@ -1,1625 +1,1858 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
const $6901cffdef780071$export$4e09c449d6c407f7 = true;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const $aedbef154d609804$export$df77466336fe5355 = true;
|
|
1
|
+
import * as React from 'react';
|
|
7
2
|
|
|
3
|
+
const isBrowser = typeof window !== "undefined";
|
|
8
4
|
|
|
9
5
|
// This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
|
|
10
|
-
// and limitations with ParcelJS parsing of the useId workaround (used below).
|
|
11
|
-
// For the time being, all react-resizable-panels must import "react" with the "* as React" syntax.
|
|
12
|
-
// To avoid mistakes, we use the ESLint "no-restricted-imports" to prevent "react" imports except in this file.
|
|
13
|
-
// See https://github.com/bvaughn/react-resizable-panels/issues/118
|
|
14
|
-
// eslint-disable-next-line no-restricted-imports
|
|
15
|
-
|
|
16
|
-
const { createElement: $ef07efbe5fa7d87e$export$c8a8987d4410bf2d, createContext: $ef07efbe5fa7d87e$export$fd42f52fd3ae1109, createRef: $ef07efbe5fa7d87e$export$7d1e3a5e95ceca43, forwardRef: $ef07efbe5fa7d87e$export$257a8862b851cb5b, useCallback: $ef07efbe5fa7d87e$export$35808ee640e87ca7, useContext: $ef07efbe5fa7d87e$export$fae74005e78b1a27, useEffect: $ef07efbe5fa7d87e$export$6d9c69b0de29b591, useImperativeHandle: $ef07efbe5fa7d87e$export$d5a552a76deda3c2, useLayoutEffect: $ef07efbe5fa7d87e$export$e5c5a5f917a5871c, useMemo: $ef07efbe5fa7d87e$export$1538c33de8887b59, useRef: $ef07efbe5fa7d87e$export$b8f5890fc79d6aca, useState: $ef07efbe5fa7d87e$export$60241385465d0a34 } = $jhddX$react;
|
|
17
|
-
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
18
|
-
const $ef07efbe5fa7d87e$export$f680877a34711e37 = $jhddX$react["useId".toString()];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const $e30963544e64b604$export$7d8c6d083caec74a = (0, $ef07efbe5fa7d87e$export$fd42f52fd3ae1109)(null);
|
|
22
|
-
$e30963544e64b604$export$7d8c6d083caec74a.displayName = "PanelGroupContext";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const $3f95d3e171760903$var$useIsomorphicLayoutEffect = (0, $6901cffdef780071$export$4e09c449d6c407f7) ? (0, $ef07efbe5fa7d87e$export$e5c5a5f917a5871c) : ()=>{};
|
|
28
|
-
var $3f95d3e171760903$export$2e2bcd8739ae039 = $3f95d3e171760903$var$useIsomorphicLayoutEffect;
|
|
29
6
|
|
|
7
|
+
// eslint-disable-next-line no-restricted-imports
|
|
30
8
|
|
|
9
|
+
const {
|
|
10
|
+
createElement,
|
|
11
|
+
createContext,
|
|
12
|
+
createRef,
|
|
13
|
+
forwardRef,
|
|
14
|
+
useCallback,
|
|
15
|
+
useContext,
|
|
16
|
+
useEffect,
|
|
17
|
+
useImperativeHandle,
|
|
18
|
+
useLayoutEffect,
|
|
19
|
+
useMemo,
|
|
20
|
+
useRef,
|
|
21
|
+
useState
|
|
22
|
+
} = React;
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
|
|
25
|
+
const useId = React["useId".toString()];
|
|
26
|
+
|
|
27
|
+
const PanelGroupContext = createContext(null);
|
|
28
|
+
PanelGroupContext.displayName = "PanelGroupContext";
|
|
29
|
+
|
|
30
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : () => {};
|
|
31
|
+
|
|
32
|
+
const wrappedUseId = typeof useId === "function" ? useId : () => null;
|
|
33
|
+
let counter = 0;
|
|
34
|
+
function useUniqueId(idFromParams = null) {
|
|
35
|
+
const idFromUseId = wrappedUseId();
|
|
36
|
+
const idRef = useRef(idFromParams || idFromUseId || null);
|
|
37
|
+
if (idRef.current === null) {
|
|
38
|
+
idRef.current = "" + counter++;
|
|
39
|
+
}
|
|
40
|
+
return idFromParams !== null && idFromParams !== void 0 ? idFromParams : idRef.current;
|
|
39
41
|
}
|
|
40
42
|
|
|
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
|
-
|
|
43
|
+
function PanelWithForwardedRef({
|
|
44
|
+
children,
|
|
45
|
+
className: classNameFromProps = "",
|
|
46
|
+
collapsedSize,
|
|
47
|
+
collapsible,
|
|
48
|
+
defaultSize,
|
|
49
|
+
forwardedRef,
|
|
50
|
+
id: idFromProps,
|
|
51
|
+
maxSize,
|
|
52
|
+
minSize,
|
|
53
|
+
onCollapse,
|
|
54
|
+
onExpand,
|
|
55
|
+
onResize,
|
|
56
|
+
order,
|
|
57
|
+
style: styleFromProps,
|
|
58
|
+
tagName: Type = "div",
|
|
59
|
+
...rest
|
|
60
|
+
}) {
|
|
61
|
+
const context = useContext(PanelGroupContext);
|
|
62
|
+
if (context === null) {
|
|
63
|
+
throw Error(`Panel components must be rendered within a PanelGroup container`);
|
|
64
|
+
}
|
|
65
|
+
const {
|
|
66
|
+
collapsePanel,
|
|
67
|
+
expandPanel,
|
|
68
|
+
getPanelSize,
|
|
69
|
+
getPanelStyle,
|
|
70
|
+
groupId,
|
|
71
|
+
isPanelCollapsed,
|
|
72
|
+
registerPanel,
|
|
73
|
+
resizePanel,
|
|
74
|
+
unregisterPanel
|
|
75
|
+
} = context;
|
|
76
|
+
const panelId = useUniqueId(idFromProps);
|
|
77
|
+
const panelDataRef = useRef({
|
|
78
|
+
callbacks: {
|
|
79
|
+
onCollapse,
|
|
80
|
+
onExpand,
|
|
81
|
+
onResize
|
|
82
|
+
},
|
|
83
|
+
constraints: {
|
|
84
|
+
collapsedSize,
|
|
85
|
+
collapsible,
|
|
86
|
+
defaultSize,
|
|
87
|
+
maxSize,
|
|
88
|
+
minSize
|
|
89
|
+
},
|
|
90
|
+
id: panelId,
|
|
91
|
+
idIsFromProps: idFromProps !== undefined,
|
|
92
|
+
order
|
|
93
|
+
});
|
|
94
|
+
useRef({
|
|
95
|
+
didLogMissingDefaultSizeWarning: false
|
|
96
|
+
});
|
|
97
|
+
useIsomorphicLayoutEffect(() => {
|
|
98
|
+
const {
|
|
99
|
+
callbacks,
|
|
100
|
+
constraints
|
|
101
|
+
} = panelDataRef.current;
|
|
102
|
+
panelDataRef.current.id = panelId;
|
|
103
|
+
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
104
|
+
panelDataRef.current.order = order;
|
|
105
|
+
callbacks.onCollapse = onCollapse;
|
|
106
|
+
callbacks.onExpand = onExpand;
|
|
107
|
+
callbacks.onResize = onResize;
|
|
108
|
+
constraints.collapsedSize = collapsedSize;
|
|
109
|
+
constraints.collapsible = collapsible;
|
|
110
|
+
constraints.defaultSize = defaultSize;
|
|
111
|
+
constraints.maxSize = maxSize;
|
|
112
|
+
constraints.minSize = minSize;
|
|
113
|
+
});
|
|
114
|
+
useIsomorphicLayoutEffect(() => {
|
|
115
|
+
const panelData = panelDataRef.current;
|
|
116
|
+
registerPanel(panelData);
|
|
117
|
+
return () => {
|
|
118
|
+
unregisterPanel(panelData);
|
|
119
|
+
};
|
|
120
|
+
}, [order, panelId, registerPanel, unregisterPanel]);
|
|
121
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
122
|
+
collapse: () => {
|
|
123
|
+
collapsePanel(panelDataRef.current);
|
|
124
|
+
},
|
|
125
|
+
expand: () => {
|
|
126
|
+
expandPanel(panelDataRef.current);
|
|
127
|
+
},
|
|
128
|
+
getId() {
|
|
129
|
+
return panelId;
|
|
130
|
+
},
|
|
131
|
+
getSize() {
|
|
132
|
+
return getPanelSize(panelDataRef.current);
|
|
133
|
+
},
|
|
134
|
+
isCollapsed() {
|
|
135
|
+
return isPanelCollapsed(panelDataRef.current);
|
|
136
|
+
},
|
|
137
|
+
isExpanded() {
|
|
138
|
+
return !isPanelCollapsed(panelDataRef.current);
|
|
139
|
+
},
|
|
140
|
+
resize: size => {
|
|
141
|
+
resizePanel(panelDataRef.current, size);
|
|
77
142
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
unregisterPanel(panelData);
|
|
97
|
-
};
|
|
98
|
-
}, [
|
|
99
|
-
order,
|
|
100
|
-
panelId,
|
|
101
|
-
registerPanel,
|
|
102
|
-
unregisterPanel
|
|
103
|
-
]);
|
|
104
|
-
(0, $ef07efbe5fa7d87e$export$d5a552a76deda3c2)(forwardedRef, ()=>({
|
|
105
|
-
collapse: ()=>{
|
|
106
|
-
collapsePanel(panelDataRef.current);
|
|
107
|
-
},
|
|
108
|
-
expand: ()=>{
|
|
109
|
-
expandPanel(panelDataRef.current);
|
|
110
|
-
},
|
|
111
|
-
getId () {
|
|
112
|
-
return panelId;
|
|
113
|
-
},
|
|
114
|
-
getSize () {
|
|
115
|
-
return getPanelSize(panelDataRef.current);
|
|
116
|
-
},
|
|
117
|
-
isCollapsed () {
|
|
118
|
-
return isPanelCollapsed(panelDataRef.current);
|
|
119
|
-
},
|
|
120
|
-
isExpanded () {
|
|
121
|
-
return !isPanelCollapsed(panelDataRef.current);
|
|
122
|
-
},
|
|
123
|
-
resize: (size)=>{
|
|
124
|
-
resizePanel(panelDataRef.current, size);
|
|
125
|
-
}
|
|
126
|
-
}), [
|
|
127
|
-
collapsePanel,
|
|
128
|
-
expandPanel,
|
|
129
|
-
getPanelSize,
|
|
130
|
-
isPanelCollapsed,
|
|
131
|
-
panelId,
|
|
132
|
-
resizePanel
|
|
133
|
-
]);
|
|
134
|
-
const style = getPanelStyle(panelDataRef.current);
|
|
135
|
-
return (0, $ef07efbe5fa7d87e$export$c8a8987d4410bf2d)(Type, {
|
|
136
|
-
...rest,
|
|
137
|
-
children: children,
|
|
138
|
-
className: classNameFromProps,
|
|
139
|
-
style: {
|
|
140
|
-
...style,
|
|
141
|
-
...styleFromProps
|
|
142
|
-
},
|
|
143
|
-
// CSS selectors
|
|
144
|
-
"data-panel": "",
|
|
145
|
-
"data-panel-id": panelId,
|
|
146
|
-
"data-panel-group-id": groupId,
|
|
147
|
-
// e2e test attributes
|
|
148
|
-
"data-panel-collapsible": (0, $aedbef154d609804$export$df77466336fe5355) ? collapsible || undefined : undefined,
|
|
149
|
-
"data-panel-size": (0, $aedbef154d609804$export$df77466336fe5355) ? parseFloat("" + style.flexGrow).toFixed(1) : undefined
|
|
150
|
-
});
|
|
143
|
+
}), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
|
|
144
|
+
const style = getPanelStyle(panelDataRef.current);
|
|
145
|
+
return createElement(Type, {
|
|
146
|
+
...rest,
|
|
147
|
+
children,
|
|
148
|
+
className: classNameFromProps,
|
|
149
|
+
style: {
|
|
150
|
+
...style,
|
|
151
|
+
...styleFromProps
|
|
152
|
+
},
|
|
153
|
+
// CSS selectors
|
|
154
|
+
"data-panel": "",
|
|
155
|
+
"data-panel-id": panelId,
|
|
156
|
+
"data-panel-group-id": groupId,
|
|
157
|
+
// e2e test attributes
|
|
158
|
+
"data-panel-collapsible": undefined,
|
|
159
|
+
"data-panel-size": undefined
|
|
160
|
+
});
|
|
151
161
|
}
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
function $5f33910cd46e8ae7$export$a7a9523472993e97(expectedCondition, message = "Assertion failed!") {
|
|
166
|
-
if (!expectedCondition) {
|
|
167
|
-
console.error(message);
|
|
168
|
-
throw Error(message);
|
|
169
|
-
}
|
|
162
|
+
const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
163
|
+
...props,
|
|
164
|
+
forwardedRef: ref
|
|
165
|
+
}));
|
|
166
|
+
PanelWithForwardedRef.displayName = "Panel";
|
|
167
|
+
Panel.displayName = "forwardRef(Panel)";
|
|
168
|
+
|
|
169
|
+
function assert(expectedCondition, message = "Assertion failed!") {
|
|
170
|
+
if (!expectedCondition) {
|
|
171
|
+
console.error(message);
|
|
172
|
+
throw Error(message);
|
|
173
|
+
}
|
|
170
174
|
}
|
|
171
175
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
const PRECISION = 10;
|
|
177
|
+
|
|
178
|
+
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
179
|
+
actual = parseFloat(actual.toFixed(fractionDigits));
|
|
180
|
+
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
181
|
+
const delta = actual - expected;
|
|
182
|
+
if (delta === 0) {
|
|
183
|
+
return 0;
|
|
184
|
+
} else {
|
|
185
|
+
return delta > 0 ? 1 : -1;
|
|
186
|
+
}
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
function $ee71a189401d6914$export$db9c8bd2fae72e82(actual, expected, fractionDigits) {
|
|
187
|
-
return (0, $fa17b68d3c9353a3$export$1d75b1119dff900)(actual, expected, fractionDigits) === 0;
|
|
189
|
+
function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
190
|
+
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
188
191
|
}
|
|
189
192
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
193
|
+
// Panel size must be in percentages; pixel values should be pre-converted
|
|
194
|
+
function resizePanel({
|
|
195
|
+
panelConstraints: panelConstraintsArray,
|
|
196
|
+
panelIndex,
|
|
197
|
+
size
|
|
198
|
+
}) {
|
|
199
|
+
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
200
|
+
assert(panelConstraints != null);
|
|
201
|
+
let {
|
|
202
|
+
collapsedSize = 0,
|
|
203
|
+
collapsible,
|
|
204
|
+
maxSize = 100,
|
|
205
|
+
minSize = 0
|
|
206
|
+
} = panelConstraints;
|
|
207
|
+
if (fuzzyCompareNumbers(size, minSize) < 0) {
|
|
208
|
+
if (collapsible) {
|
|
209
|
+
// Collapsible panels should snap closed or open only once they cross the halfway point between collapsed and min size.
|
|
210
|
+
const halfwayPoint = (collapsedSize + minSize) / 2;
|
|
211
|
+
if (fuzzyCompareNumbers(size, halfwayPoint) < 0) {
|
|
212
|
+
size = collapsedSize;
|
|
213
|
+
} else {
|
|
214
|
+
size = minSize;
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
size = minSize;
|
|
205
218
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
219
|
+
}
|
|
220
|
+
size = Math.min(maxSize, size);
|
|
221
|
+
size = parseFloat(size.toFixed(PRECISION));
|
|
222
|
+
return size;
|
|
209
223
|
}
|
|
210
224
|
|
|
211
|
-
|
|
212
|
-
function
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
225
|
+
// All units must be in percentages; pixel values should be pre-converted
|
|
226
|
+
function adjustLayoutByDelta({
|
|
227
|
+
delta,
|
|
228
|
+
layout: prevLayout,
|
|
229
|
+
panelConstraints: panelConstraintsArray,
|
|
230
|
+
pivotIndices,
|
|
231
|
+
trigger
|
|
232
|
+
}) {
|
|
233
|
+
if (fuzzyNumbersEqual(delta, 0)) {
|
|
234
|
+
return prevLayout;
|
|
235
|
+
}
|
|
236
|
+
const nextLayout = [...prevLayout];
|
|
237
|
+
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
238
|
+
assert(firstPivotIndex != null);
|
|
239
|
+
assert(secondPivotIndex != null);
|
|
240
|
+
let deltaApplied = 0;
|
|
241
|
+
|
|
242
|
+
//const DEBUG = [];
|
|
243
|
+
//DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
|
|
244
|
+
//DEBUG.push(` delta: ${delta}`);
|
|
245
|
+
//DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
246
|
+
//DEBUG.push(` trigger: ${trigger}`);
|
|
247
|
+
//DEBUG.push("");
|
|
248
|
+
|
|
249
|
+
// A resizing panel affects the panels before or after it.
|
|
250
|
+
//
|
|
251
|
+
// A negative delta means the panel(s) immediately after the resize handle should grow/expand by decreasing its offset.
|
|
252
|
+
// Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.
|
|
253
|
+
//
|
|
254
|
+
// A positive delta means the panel(s) immediately before the resize handle should "expand".
|
|
255
|
+
// This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resize handle.
|
|
256
|
+
|
|
257
|
+
{
|
|
221
258
|
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
|
|
222
259
|
// We no longer check the halfway threshold because this may prevent the panel from expanding at all.
|
|
223
260
|
if (trigger === "keyboard") {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
261
|
+
{
|
|
262
|
+
// Check if we should expand a collapsed panel
|
|
263
|
+
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
264
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
265
|
+
assert(panelConstraints);
|
|
266
|
+
|
|
267
|
+
//DEBUG.push(`edge case check 1: ${index}`);
|
|
268
|
+
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
269
|
+
if (panelConstraints.collapsible) {
|
|
270
|
+
const prevSize = prevLayout[index];
|
|
271
|
+
assert(prevSize != null);
|
|
272
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
273
|
+
assert(panelConstraints);
|
|
274
|
+
const {
|
|
275
|
+
collapsedSize = 0,
|
|
276
|
+
minSize = 0
|
|
277
|
+
} = panelConstraints;
|
|
278
|
+
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
279
|
+
const localDelta = minSize - prevSize;
|
|
280
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
281
|
+
|
|
282
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
283
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
284
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
242
285
|
}
|
|
286
|
+
}
|
|
243
287
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
{
|
|
291
|
+
// Check if we should collapse a panel at its minimum size
|
|
292
|
+
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
293
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
294
|
+
assert(panelConstraints);
|
|
295
|
+
const {
|
|
296
|
+
collapsible
|
|
297
|
+
} = panelConstraints;
|
|
298
|
+
|
|
299
|
+
//DEBUG.push(`edge case check 2: ${index}`);
|
|
300
|
+
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
301
|
+
if (collapsible) {
|
|
302
|
+
const prevSize = prevLayout[index];
|
|
303
|
+
assert(prevSize != null);
|
|
304
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
305
|
+
assert(panelConstraints);
|
|
306
|
+
const {
|
|
307
|
+
collapsedSize = 0,
|
|
308
|
+
minSize = 0
|
|
309
|
+
} = panelConstraints;
|
|
310
|
+
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
311
|
+
const localDelta = prevSize - collapsedSize;
|
|
312
|
+
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
313
|
+
|
|
314
|
+
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
315
|
+
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
316
|
+
//DEBUG.push(` -> delta: ${delta}`);
|
|
263
317
|
}
|
|
318
|
+
}
|
|
264
319
|
}
|
|
320
|
+
}
|
|
265
321
|
}
|
|
266
|
-
{
|
|
267
|
-
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
268
|
-
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
269
|
-
// If this amount is less than the requested delta, adjust the requested delta.
|
|
270
|
-
// If this amount is greater than the requested delta, that's useful information too–
|
|
271
|
-
// as an expanding panel might change from collapsed to min size.
|
|
272
|
-
const increment = delta < 0 ? 1 : -1;
|
|
273
|
-
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
274
|
-
let maxAvailableDelta = 0;
|
|
275
|
-
//DEBUG.push("pre calc...");
|
|
276
|
-
while(true){
|
|
277
|
-
const prevSize = prevLayout[index];
|
|
278
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(prevSize != null);
|
|
279
|
-
const maxSafeSize = (0, $40f29f7a20511409$export$2f98edcf4006376f)({
|
|
280
|
-
panelConstraints: panelConstraintsArray,
|
|
281
|
-
panelIndex: index,
|
|
282
|
-
size: 100
|
|
283
|
-
});
|
|
284
|
-
const delta = maxSafeSize - prevSize;
|
|
285
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
286
|
-
maxAvailableDelta += delta;
|
|
287
|
-
index += increment;
|
|
288
|
-
if (index < 0 || index >= panelConstraintsArray.length) break;
|
|
289
|
-
}
|
|
290
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
291
|
-
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
292
|
-
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
293
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
294
322
|
//DEBUG.push("");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
{
|
|
326
|
+
// Pre-calculate max available delta in the opposite direction of our pivot.
|
|
327
|
+
// This will be the maximum amount we're allowed to expand/contract the panels in the primary direction.
|
|
328
|
+
// If this amount is less than the requested delta, adjust the requested delta.
|
|
329
|
+
// If this amount is greater than the requested delta, that's useful information too–
|
|
330
|
+
// as an expanding panel might change from collapsed to min size.
|
|
331
|
+
|
|
332
|
+
const increment = delta < 0 ? 1 : -1;
|
|
333
|
+
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
334
|
+
let maxAvailableDelta = 0;
|
|
335
|
+
|
|
336
|
+
//DEBUG.push("pre calc...");
|
|
337
|
+
while (true) {
|
|
338
|
+
const prevSize = prevLayout[index];
|
|
339
|
+
assert(prevSize != null);
|
|
340
|
+
const maxSafeSize = resizePanel({
|
|
341
|
+
panelConstraints: panelConstraintsArray,
|
|
342
|
+
panelIndex: index,
|
|
343
|
+
size: 100
|
|
344
|
+
});
|
|
345
|
+
const delta = maxSafeSize - prevSize;
|
|
346
|
+
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
347
|
+
|
|
348
|
+
maxAvailableDelta += delta;
|
|
349
|
+
index += increment;
|
|
350
|
+
if (index < 0 || index >= panelConstraintsArray.length) {
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
295
353
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
302
|
-
const prevSize = prevLayout[index];
|
|
303
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(prevSize != null);
|
|
304
|
-
const unsafeSize = prevSize - deltaRemaining;
|
|
305
|
-
const safeSize = (0, $40f29f7a20511409$export$2f98edcf4006376f)({
|
|
306
|
-
panelConstraints: panelConstraintsArray,
|
|
307
|
-
panelIndex: index,
|
|
308
|
-
size: unsafeSize
|
|
309
|
-
});
|
|
310
|
-
if (!(0, $ee71a189401d6914$export$db9c8bd2fae72e82)(prevSize, safeSize)) {
|
|
311
|
-
deltaApplied += prevSize - safeSize;
|
|
312
|
-
nextLayout[index] = safeSize;
|
|
313
|
-
if (deltaApplied.toPrecision(3).localeCompare(Math.abs(delta).toPrecision(3), undefined, {
|
|
314
|
-
numeric: true
|
|
315
|
-
}) >= 0) break;
|
|
316
|
-
}
|
|
317
|
-
if (delta < 0) index--;
|
|
318
|
-
else index++;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
322
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
354
|
+
|
|
355
|
+
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
356
|
+
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
357
|
+
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
358
|
+
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
323
359
|
//DEBUG.push("");
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(prevSize != null);
|
|
349
|
-
const unsafeSize = prevSize + deltaRemaining;
|
|
350
|
-
const safeSize = (0, $40f29f7a20511409$export$2f98edcf4006376f)({
|
|
351
|
-
panelConstraints: panelConstraintsArray,
|
|
352
|
-
panelIndex: index,
|
|
353
|
-
size: unsafeSize
|
|
354
|
-
});
|
|
355
|
-
if (!(0, $ee71a189401d6914$export$db9c8bd2fae72e82)(prevSize, safeSize)) {
|
|
356
|
-
deltaRemaining -= safeSize - prevSize;
|
|
357
|
-
nextLayout[index] = safeSize;
|
|
358
|
-
}
|
|
359
|
-
if ((0, $ee71a189401d6914$export$db9c8bd2fae72e82)(deltaRemaining, 0)) break;
|
|
360
|
-
if (delta > 0) index--;
|
|
361
|
-
else index++;
|
|
362
|
-
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
{
|
|
363
|
+
// Delta added to a panel needs to be subtracted from other panels (within the constraints that those panels allow).
|
|
364
|
+
|
|
365
|
+
const pivotIndex = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
366
|
+
let index = pivotIndex;
|
|
367
|
+
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
368
|
+
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
369
|
+
const prevSize = prevLayout[index];
|
|
370
|
+
assert(prevSize != null);
|
|
371
|
+
const unsafeSize = prevSize - deltaRemaining;
|
|
372
|
+
const safeSize = resizePanel({
|
|
373
|
+
panelConstraints: panelConstraintsArray,
|
|
374
|
+
panelIndex: index,
|
|
375
|
+
size: unsafeSize
|
|
376
|
+
});
|
|
377
|
+
if (!fuzzyNumbersEqual(prevSize, safeSize)) {
|
|
378
|
+
deltaApplied += prevSize - safeSize;
|
|
379
|
+
nextLayout[index] = safeSize;
|
|
380
|
+
if (deltaApplied.toPrecision(3).localeCompare(Math.abs(delta).toPrecision(3), undefined, {
|
|
381
|
+
numeric: true
|
|
382
|
+
}) >= 0) {
|
|
383
|
+
break;
|
|
363
384
|
}
|
|
385
|
+
}
|
|
386
|
+
if (delta < 0) {
|
|
387
|
+
index--;
|
|
388
|
+
} else {
|
|
389
|
+
index++;
|
|
390
|
+
}
|
|
364
391
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
392
|
+
}
|
|
393
|
+
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
394
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
395
|
+
//DEBUG.push("");
|
|
396
|
+
|
|
397
|
+
// If we were unable to resize any of the panels panels, return the previous state.
|
|
398
|
+
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
399
|
+
if (fuzzyNumbersEqual(deltaApplied, 0)) {
|
|
370
400
|
//console.log(DEBUG.join("\n"));
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
401
|
+
return prevLayout;
|
|
402
|
+
}
|
|
403
|
+
{
|
|
404
|
+
// Now distribute the applied delta to the panels in the other direction
|
|
405
|
+
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
406
|
+
const prevSize = prevLayout[pivotIndex];
|
|
407
|
+
assert(prevSize != null);
|
|
408
|
+
const unsafeSize = prevSize + deltaApplied;
|
|
409
|
+
const safeSize = resizePanel({
|
|
410
|
+
panelConstraints: panelConstraintsArray,
|
|
411
|
+
panelIndex: pivotIndex,
|
|
412
|
+
size: unsafeSize
|
|
413
|
+
});
|
|
376
414
|
|
|
415
|
+
// Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
|
|
416
|
+
nextLayout[pivotIndex] = safeSize;
|
|
377
417
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
418
|
+
// Edge case where expanding or contracting one panel caused another one to change collapsed state
|
|
419
|
+
if (!fuzzyNumbersEqual(safeSize, unsafeSize)) {
|
|
420
|
+
let deltaRemaining = unsafeSize - safeSize;
|
|
421
|
+
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
422
|
+
let index = pivotIndex;
|
|
423
|
+
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
424
|
+
const prevSize = nextLayout[index];
|
|
425
|
+
assert(prevSize != null);
|
|
426
|
+
const unsafeSize = prevSize + deltaRemaining;
|
|
427
|
+
const safeSize = resizePanel({
|
|
428
|
+
panelConstraints: panelConstraintsArray,
|
|
429
|
+
panelIndex: index,
|
|
430
|
+
size: unsafeSize
|
|
431
|
+
});
|
|
432
|
+
if (!fuzzyNumbersEqual(prevSize, safeSize)) {
|
|
433
|
+
deltaRemaining -= safeSize - prevSize;
|
|
434
|
+
nextLayout[index] = safeSize;
|
|
435
|
+
}
|
|
436
|
+
if (fuzzyNumbersEqual(deltaRemaining, 0)) {
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
if (delta > 0) {
|
|
440
|
+
index--;
|
|
392
441
|
} else {
|
|
393
|
-
|
|
394
|
-
totalMaxSize += maxSize;
|
|
442
|
+
index++;
|
|
395
443
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
valueMin: valueMin,
|
|
403
|
-
valueNow: valueNow
|
|
404
|
-
};
|
|
405
|
-
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
448
|
+
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
449
|
+
//DEBUG.push("");
|
|
406
450
|
|
|
451
|
+
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
452
|
+
//DEBUG.push(`total size: ${totalSize}`);
|
|
453
|
+
//console.log(DEBUG.join("\n"));
|
|
407
454
|
|
|
408
|
-
|
|
409
|
-
return
|
|
455
|
+
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
456
|
+
return prevLayout;
|
|
457
|
+
}
|
|
458
|
+
return nextLayout;
|
|
410
459
|
}
|
|
411
460
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
461
|
+
function calculateAriaValues({
|
|
462
|
+
layout,
|
|
463
|
+
panelsArray,
|
|
464
|
+
pivotIndices
|
|
465
|
+
}) {
|
|
466
|
+
let currentMinSize = 0;
|
|
467
|
+
let currentMaxSize = 100;
|
|
468
|
+
let totalMinSize = 0;
|
|
469
|
+
let totalMaxSize = 0;
|
|
470
|
+
const firstIndex = pivotIndices[0];
|
|
471
|
+
assert(firstIndex != null);
|
|
472
|
+
|
|
473
|
+
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
474
|
+
panelsArray.forEach((panelData, index) => {
|
|
475
|
+
const {
|
|
476
|
+
constraints
|
|
477
|
+
} = panelData;
|
|
478
|
+
const {
|
|
479
|
+
maxSize = 100,
|
|
480
|
+
minSize = 0
|
|
481
|
+
} = constraints;
|
|
482
|
+
if (index === firstIndex) {
|
|
483
|
+
currentMinSize = minSize;
|
|
484
|
+
currentMaxSize = maxSize;
|
|
485
|
+
} else {
|
|
486
|
+
totalMinSize += minSize;
|
|
487
|
+
totalMaxSize += maxSize;
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
const valueMax = Math.min(currentMaxSize, 100 - totalMinSize);
|
|
491
|
+
const valueMin = Math.max(currentMinSize, 100 - totalMaxSize);
|
|
492
|
+
const valueNow = layout[firstIndex];
|
|
493
|
+
return {
|
|
494
|
+
valueMax,
|
|
495
|
+
valueMin,
|
|
496
|
+
valueNow
|
|
497
|
+
};
|
|
417
498
|
}
|
|
418
499
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const index = (0, $a144d12e0d2017d1$export$4c92fedbbc2381ca)(groupId, dragHandleId);
|
|
422
|
-
return index != null ? [
|
|
423
|
-
index,
|
|
424
|
-
index + 1
|
|
425
|
-
] : [
|
|
426
|
-
-1,
|
|
427
|
-
-1
|
|
428
|
-
];
|
|
500
|
+
function getResizeHandleElementsForGroup(groupId) {
|
|
501
|
+
return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
429
502
|
}
|
|
430
503
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return null;
|
|
504
|
+
function getResizeHandleElementIndex(groupId, id) {
|
|
505
|
+
const handles = getResizeHandleElementsForGroup(groupId);
|
|
506
|
+
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
507
|
+
return index !== null && index !== void 0 ? index : null;
|
|
436
508
|
}
|
|
437
509
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
442
|
-
if (element) return element;
|
|
443
|
-
return null;
|
|
510
|
+
function determinePivotIndices(groupId, dragHandleId) {
|
|
511
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
512
|
+
return index != null ? [index, index + 1] : [-1, -1];
|
|
444
513
|
}
|
|
445
514
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const index = handle ? handles.indexOf(handle) : -1;
|
|
453
|
-
var _panelsArray_index_id;
|
|
454
|
-
const idBefore = (_panelsArray_index_id = (_panelsArray_index = panelsArray[index]) === null || _panelsArray_index === void 0 ? void 0 : _panelsArray_index.id) !== null && _panelsArray_index_id !== void 0 ? _panelsArray_index_id : null;
|
|
455
|
-
var _panelsArray__id;
|
|
456
|
-
const idAfter = (_panelsArray__id = (_panelsArray_ = panelsArray[index + 1]) === null || _panelsArray_ === void 0 ? void 0 : _panelsArray_.id) !== null && _panelsArray__id !== void 0 ? _panelsArray__id : null;
|
|
457
|
-
return [
|
|
458
|
-
idBefore,
|
|
459
|
-
idAfter
|
|
460
|
-
];
|
|
515
|
+
function getPanelGroupElement(id) {
|
|
516
|
+
const element = document.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
517
|
+
if (element) {
|
|
518
|
+
return element;
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
461
521
|
}
|
|
462
522
|
|
|
523
|
+
function getResizeHandleElement(id) {
|
|
524
|
+
const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
525
|
+
if (element) {
|
|
526
|
+
return element;
|
|
527
|
+
}
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
463
530
|
|
|
531
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
532
|
+
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
533
|
+
const handle = getResizeHandleElement(handleId);
|
|
534
|
+
const handles = getResizeHandleElementsForGroup(groupId);
|
|
535
|
+
const index = handle ? handles.indexOf(handle) : -1;
|
|
536
|
+
const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
|
|
537
|
+
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
538
|
+
return [idBefore, idAfter];
|
|
539
|
+
}
|
|
464
540
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
541
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
|
|
542
|
+
|
|
543
|
+
function useWindowSplitterPanelGroupBehavior({
|
|
544
|
+
committedValuesRef,
|
|
545
|
+
eagerValuesRef,
|
|
546
|
+
groupId,
|
|
547
|
+
layout,
|
|
548
|
+
panelDataArray,
|
|
549
|
+
setLayout
|
|
550
|
+
}) {
|
|
551
|
+
useRef({
|
|
552
|
+
didWarnAboutMissingResizeHandle: false
|
|
553
|
+
});
|
|
554
|
+
useIsomorphicLayoutEffect(() => {
|
|
555
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId);
|
|
556
|
+
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
557
|
+
const {
|
|
558
|
+
valueMax,
|
|
559
|
+
valueMin,
|
|
560
|
+
valueNow
|
|
561
|
+
} = calculateAriaValues({
|
|
562
|
+
layout,
|
|
563
|
+
panelsArray: panelDataArray,
|
|
564
|
+
pivotIndices: [index, index + 1]
|
|
565
|
+
});
|
|
566
|
+
const resizeHandleElement = resizeHandleElements[index];
|
|
567
|
+
if (resizeHandleElement == null) ; else {
|
|
568
|
+
const panelData = panelDataArray[index];
|
|
569
|
+
assert(panelData);
|
|
570
|
+
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
571
|
+
resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
|
|
572
|
+
resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
|
|
573
|
+
resizeHandleElement.setAttribute("aria-valuenow", valueNow != null ? "" + Math.round(valueNow) : "");
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return () => {
|
|
577
|
+
resizeHandleElements.forEach((resizeHandleElement, index) => {
|
|
578
|
+
resizeHandleElement.removeAttribute("aria-controls");
|
|
579
|
+
resizeHandleElement.removeAttribute("aria-valuemax");
|
|
580
|
+
resizeHandleElement.removeAttribute("aria-valuemin");
|
|
581
|
+
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
582
|
+
});
|
|
583
|
+
};
|
|
584
|
+
}, [groupId, layout, panelDataArray]);
|
|
585
|
+
useEffect(() => {
|
|
586
|
+
const eagerValues = eagerValuesRef.current;
|
|
587
|
+
assert(eagerValues);
|
|
588
|
+
const {
|
|
589
|
+
panelDataArray
|
|
590
|
+
} = eagerValues;
|
|
591
|
+
const groupElement = getPanelGroupElement(groupId);
|
|
592
|
+
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
593
|
+
const handles = getResizeHandleElementsForGroup(groupId);
|
|
594
|
+
assert(handles);
|
|
595
|
+
const cleanupFunctions = handles.map(handle => {
|
|
596
|
+
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
597
|
+
assert(handleId);
|
|
598
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
599
|
+
if (idBefore == null || idAfter == null) {
|
|
600
|
+
return () => {};
|
|
601
|
+
}
|
|
602
|
+
const onKeyDown = event => {
|
|
603
|
+
if (event.defaultPrevented) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
switch (event.key) {
|
|
607
|
+
case "Enter":
|
|
608
|
+
{
|
|
609
|
+
event.preventDefault();
|
|
610
|
+
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
611
|
+
if (index >= 0) {
|
|
492
612
|
const panelData = panelDataArray[index];
|
|
493
|
-
(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
613
|
+
assert(panelData);
|
|
614
|
+
const size = layout[index];
|
|
615
|
+
const {
|
|
616
|
+
collapsedSize = 0,
|
|
617
|
+
collapsible,
|
|
618
|
+
minSize = 0
|
|
619
|
+
} = panelData.constraints;
|
|
620
|
+
if (size != null && collapsible) {
|
|
621
|
+
const nextLayout = adjustLayoutByDelta({
|
|
622
|
+
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
623
|
+
layout,
|
|
624
|
+
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
625
|
+
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
626
|
+
trigger: "keyboard"
|
|
627
|
+
});
|
|
628
|
+
if (layout !== nextLayout) {
|
|
629
|
+
setLayout(nextLayout);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
break;
|
|
498
634
|
}
|
|
499
635
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
layout,
|
|
511
|
-
panelDataArray
|
|
512
|
-
]);
|
|
513
|
-
(0, $ef07efbe5fa7d87e$export$6d9c69b0de29b591)(()=>{
|
|
514
|
-
const eagerValues = eagerValuesRef.current;
|
|
515
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(eagerValues);
|
|
516
|
-
const { panelDataArray: panelDataArray } = eagerValues;
|
|
517
|
-
const groupElement = (0, $18131dcc0be2e4e0$export$4e72aefa594058df)(groupId);
|
|
518
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(groupElement != null, `No group found for id "${groupId}"`);
|
|
519
|
-
const handles = (0, $9196ba7c0d09e3f3$export$63eb605e437b214f)(groupId);
|
|
520
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(handles);
|
|
521
|
-
const cleanupFunctions = handles.map((handle)=>{
|
|
522
|
-
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
523
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(handleId);
|
|
524
|
-
const [idBefore, idAfter] = (0, $1420c4509c675b80$export$68d3a33c21dfbe27)(groupId, handleId, panelDataArray);
|
|
525
|
-
if (idBefore == null || idAfter == null) return ()=>{};
|
|
526
|
-
const onKeyDown = (event)=>{
|
|
527
|
-
if (event.defaultPrevented) return;
|
|
528
|
-
switch(event.key){
|
|
529
|
-
case "Enter":
|
|
530
|
-
{
|
|
531
|
-
event.preventDefault();
|
|
532
|
-
const index = panelDataArray.findIndex((panelData)=>panelData.id === idBefore);
|
|
533
|
-
if (index >= 0) {
|
|
534
|
-
const panelData = panelDataArray[index];
|
|
535
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(panelData);
|
|
536
|
-
const size = layout[index];
|
|
537
|
-
const { collapsedSize: collapsedSize = 0, collapsible: collapsible, minSize: minSize = 0 } = panelData.constraints;
|
|
538
|
-
if (size != null && collapsible) {
|
|
539
|
-
const nextLayout = (0, $fe96098ae4f2a44d$export$7fead5cc734d205b)({
|
|
540
|
-
delta: (0, $ee71a189401d6914$export$db9c8bd2fae72e82)(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
541
|
-
layout: layout,
|
|
542
|
-
panelConstraints: panelDataArray.map((panelData)=>panelData.constraints),
|
|
543
|
-
pivotIndices: (0, $0a239c1e1cd1e940$export$cf92598869f99b8f)(groupId, handleId),
|
|
544
|
-
trigger: "keyboard"
|
|
545
|
-
});
|
|
546
|
-
if (layout !== nextLayout) setLayout(nextLayout);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
break;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
handle.addEventListener("keydown", onKeyDown);
|
|
554
|
-
return ()=>{
|
|
555
|
-
handle.removeEventListener("keydown", onKeyDown);
|
|
556
|
-
};
|
|
557
|
-
});
|
|
558
|
-
return ()=>{
|
|
559
|
-
cleanupFunctions.forEach((cleanupFunction)=>cleanupFunction());
|
|
560
|
-
};
|
|
561
|
-
}, [
|
|
562
|
-
committedValuesRef,
|
|
563
|
-
eagerValuesRef,
|
|
564
|
-
groupId,
|
|
565
|
-
layout,
|
|
566
|
-
panelDataArray,
|
|
567
|
-
setLayout
|
|
568
|
-
]);
|
|
636
|
+
};
|
|
637
|
+
handle.addEventListener("keydown", onKeyDown);
|
|
638
|
+
return () => {
|
|
639
|
+
handle.removeEventListener("keydown", onKeyDown);
|
|
640
|
+
};
|
|
641
|
+
});
|
|
642
|
+
return () => {
|
|
643
|
+
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
644
|
+
};
|
|
645
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
569
646
|
}
|
|
570
647
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
648
|
+
function areEqual(arrayA, arrayB) {
|
|
649
|
+
if (arrayA.length !== arrayB.length) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
for (let index = 0; index < arrayA.length; index++) {
|
|
653
|
+
if (arrayA[index] !== arrayB[index]) {
|
|
654
|
+
return false;
|
|
577
655
|
}
|
|
578
|
-
|
|
656
|
+
}
|
|
657
|
+
return true;
|
|
579
658
|
}
|
|
580
659
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
function $5bf95d6f4b7f490d$export$e7bf60a870f429b0(event) {
|
|
588
|
-
return event.type === "keydown";
|
|
660
|
+
function isKeyDown(event) {
|
|
661
|
+
return event.type === "keydown";
|
|
589
662
|
}
|
|
590
|
-
function
|
|
591
|
-
|
|
663
|
+
function isMouseEvent(event) {
|
|
664
|
+
return event.type.startsWith("mouse");
|
|
592
665
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
666
|
+
function isTouchEvent(event) {
|
|
667
|
+
return event.type.startsWith("touch");
|
|
595
668
|
}
|
|
596
669
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
670
|
+
function getResizeEventCursorPosition(direction, event) {
|
|
671
|
+
const isHorizontal = direction === "horizontal";
|
|
672
|
+
if (isMouseEvent(event)) {
|
|
673
|
+
return isHorizontal ? event.clientX : event.clientY;
|
|
674
|
+
} else if (isTouchEvent(event)) {
|
|
675
|
+
const firstTouch = event.touches[0];
|
|
676
|
+
assert(firstTouch);
|
|
677
|
+
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
678
|
+
} else {
|
|
679
|
+
throw Error(`Unsupported event type "${event.type}"`);
|
|
680
|
+
}
|
|
606
681
|
}
|
|
607
682
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
683
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
684
|
+
const isHorizontal = direction === "horizontal";
|
|
685
|
+
const handleElement = getResizeHandleElement(dragHandleId);
|
|
686
|
+
assert(handleElement);
|
|
687
|
+
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
688
|
+
assert(groupId);
|
|
689
|
+
let {
|
|
690
|
+
initialCursorPosition
|
|
691
|
+
} = initialDragState;
|
|
692
|
+
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
693
|
+
const groupElement = getPanelGroupElement(groupId);
|
|
694
|
+
assert(groupElement);
|
|
695
|
+
const groupRect = groupElement.getBoundingClientRect();
|
|
696
|
+
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
697
|
+
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
698
|
+
const offsetPercentage = offsetPixels / groupSizeInPixels * 100;
|
|
699
|
+
return offsetPercentage;
|
|
624
700
|
}
|
|
625
701
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
let movement = 0;
|
|
636
|
-
switch(event.key){
|
|
637
|
-
case "ArrowDown":
|
|
638
|
-
movement = isHorizontal ? 0 : delta;
|
|
639
|
-
break;
|
|
640
|
-
case "ArrowLeft":
|
|
641
|
-
movement = isHorizontal ? -delta : 0;
|
|
642
|
-
break;
|
|
643
|
-
case "ArrowRight":
|
|
644
|
-
movement = isHorizontal ? delta : 0;
|
|
645
|
-
break;
|
|
646
|
-
case "ArrowUp":
|
|
647
|
-
movement = isHorizontal ? 0 : -delta;
|
|
648
|
-
break;
|
|
649
|
-
case "End":
|
|
650
|
-
movement = 100;
|
|
651
|
-
break;
|
|
652
|
-
case "Home":
|
|
653
|
-
movement = -100;
|
|
654
|
-
break;
|
|
655
|
-
}
|
|
656
|
-
return movement;
|
|
702
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
703
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
704
|
+
if (isKeyDown(event)) {
|
|
705
|
+
const isHorizontal = direction === "horizontal";
|
|
706
|
+
let delta = 0;
|
|
707
|
+
if (event.shiftKey) {
|
|
708
|
+
delta = 100;
|
|
709
|
+
} else if (keyboardResizeBy != null) {
|
|
710
|
+
delta = keyboardResizeBy;
|
|
657
711
|
} else {
|
|
658
|
-
|
|
659
|
-
|
|
712
|
+
delta = 10;
|
|
713
|
+
}
|
|
714
|
+
let movement = 0;
|
|
715
|
+
switch (event.key) {
|
|
716
|
+
case "ArrowDown":
|
|
717
|
+
movement = isHorizontal ? 0 : delta;
|
|
718
|
+
break;
|
|
719
|
+
case "ArrowLeft":
|
|
720
|
+
movement = isHorizontal ? -delta : 0;
|
|
721
|
+
break;
|
|
722
|
+
case "ArrowRight":
|
|
723
|
+
movement = isHorizontal ? delta : 0;
|
|
724
|
+
break;
|
|
725
|
+
case "ArrowUp":
|
|
726
|
+
movement = isHorizontal ? 0 : -delta;
|
|
727
|
+
break;
|
|
728
|
+
case "End":
|
|
729
|
+
movement = 100;
|
|
730
|
+
break;
|
|
731
|
+
case "Home":
|
|
732
|
+
movement = -100;
|
|
733
|
+
break;
|
|
660
734
|
}
|
|
735
|
+
return movement;
|
|
736
|
+
} else {
|
|
737
|
+
if (initialDragState == null) {
|
|
738
|
+
return 0;
|
|
739
|
+
}
|
|
740
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
741
|
+
}
|
|
661
742
|
}
|
|
662
743
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
744
|
+
function calculateUnsafeDefaultLayout({
|
|
745
|
+
panelDataArray
|
|
746
|
+
}) {
|
|
747
|
+
const layout = Array(panelDataArray.length);
|
|
748
|
+
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
749
|
+
let numPanelsWithSizes = 0;
|
|
750
|
+
let remainingSize = 100;
|
|
751
|
+
|
|
752
|
+
// Distribute default sizes first
|
|
753
|
+
for (let index = 0; index < panelDataArray.length; index++) {
|
|
754
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
755
|
+
assert(panelConstraints);
|
|
756
|
+
const {
|
|
757
|
+
defaultSize
|
|
758
|
+
} = panelConstraints;
|
|
759
|
+
if (defaultSize != null) {
|
|
760
|
+
numPanelsWithSizes++;
|
|
761
|
+
layout[index] = defaultSize;
|
|
762
|
+
remainingSize -= defaultSize;
|
|
680
763
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Remaining size should be distributed evenly between panels without default sizes
|
|
767
|
+
for (let index = 0; index < panelDataArray.length; index++) {
|
|
768
|
+
const panelConstraints = panelConstraintsArray[index];
|
|
769
|
+
assert(panelConstraints);
|
|
770
|
+
const {
|
|
771
|
+
defaultSize
|
|
772
|
+
} = panelConstraints;
|
|
773
|
+
if (defaultSize != null) {
|
|
774
|
+
continue;
|
|
692
775
|
}
|
|
693
|
-
|
|
776
|
+
const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
|
|
777
|
+
const size = remainingSize / numRemainingPanels;
|
|
778
|
+
numPanelsWithSizes++;
|
|
779
|
+
layout[index] = size;
|
|
780
|
+
remainingSize -= size;
|
|
781
|
+
}
|
|
782
|
+
return layout;
|
|
694
783
|
}
|
|
695
784
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
785
|
+
// Layout should be pre-converted into percentages
|
|
786
|
+
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
787
|
+
layout.forEach((size, index) => {
|
|
788
|
+
const panelData = panelsArray[index];
|
|
789
|
+
assert(panelData);
|
|
790
|
+
const {
|
|
791
|
+
callbacks,
|
|
792
|
+
constraints,
|
|
793
|
+
id: panelId
|
|
794
|
+
} = panelData;
|
|
795
|
+
const {
|
|
796
|
+
collapsedSize = 0,
|
|
797
|
+
collapsible
|
|
798
|
+
} = constraints;
|
|
799
|
+
const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
|
|
800
|
+
if (lastNotifiedSize == null || size !== lastNotifiedSize) {
|
|
801
|
+
panelIdToLastNotifiedSizeMap[panelId] = size;
|
|
802
|
+
const {
|
|
803
|
+
onCollapse,
|
|
804
|
+
onExpand,
|
|
805
|
+
onResize
|
|
806
|
+
} = callbacks;
|
|
807
|
+
if (onResize) {
|
|
808
|
+
onResize(size, lastNotifiedSize);
|
|
809
|
+
}
|
|
810
|
+
if (collapsible && (onCollapse || onExpand)) {
|
|
811
|
+
if (onExpand && (lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
|
|
812
|
+
onExpand();
|
|
713
813
|
}
|
|
714
|
-
|
|
814
|
+
if (onCollapse && (lastNotifiedSize == null || lastNotifiedSize !== collapsedSize) && size === collapsedSize) {
|
|
815
|
+
onCollapse();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
715
820
|
}
|
|
716
821
|
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
822
|
+
function compareLayouts(a, b) {
|
|
823
|
+
if (a.length !== b.length) {
|
|
824
|
+
return false;
|
|
825
|
+
} else {
|
|
826
|
+
for (let index = 0; index < a.length; index++) {
|
|
827
|
+
if (a[index] != b[index]) {
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
722
830
|
}
|
|
723
|
-
|
|
831
|
+
}
|
|
832
|
+
return true;
|
|
724
833
|
}
|
|
725
834
|
|
|
726
|
-
|
|
727
835
|
// This method returns a number between 1 and 100 representing
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
836
|
+
|
|
837
|
+
// the % of the group's overall space this panel should occupy.
|
|
838
|
+
function computePanelFlexBoxStyle({
|
|
839
|
+
dragState,
|
|
840
|
+
layout,
|
|
841
|
+
panelData,
|
|
842
|
+
panelIndex,
|
|
843
|
+
precision = 3
|
|
844
|
+
}) {
|
|
845
|
+
const size = layout[panelIndex];
|
|
846
|
+
let flexGrow;
|
|
847
|
+
if (panelData.length === 1) {
|
|
733
848
|
flexGrow = "1";
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
849
|
+
} else if (size == null) {
|
|
850
|
+
// Initial render (before panels have registered themselves)
|
|
851
|
+
flexGrow = "1";
|
|
852
|
+
} else {
|
|
853
|
+
flexGrow = size.toPrecision(precision);
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
flexBasis: 0,
|
|
857
|
+
flexGrow,
|
|
858
|
+
flexShrink: 1,
|
|
859
|
+
// Without this, Panel sizes may be unintentionally overridden by their content
|
|
860
|
+
overflow: "hidden",
|
|
861
|
+
// Disable pointer events inside of a panel during resize
|
|
862
|
+
// This avoid edge cases like nested iframes
|
|
863
|
+
pointerEvents: dragState !== null ? "none" : undefined
|
|
864
|
+
};
|
|
745
865
|
}
|
|
746
866
|
|
|
747
|
-
|
|
748
|
-
let
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}
|
|
867
|
+
let currentState = null;
|
|
868
|
+
let element = null;
|
|
869
|
+
function getCursorStyle(state) {
|
|
870
|
+
switch (state) {
|
|
871
|
+
case "horizontal":
|
|
872
|
+
return "ew-resize";
|
|
873
|
+
case "horizontal-max":
|
|
874
|
+
return "w-resize";
|
|
875
|
+
case "horizontal-min":
|
|
876
|
+
return "e-resize";
|
|
877
|
+
case "vertical":
|
|
878
|
+
return "ns-resize";
|
|
879
|
+
case "vertical-max":
|
|
880
|
+
return "n-resize";
|
|
881
|
+
case "vertical-min":
|
|
882
|
+
return "s-resize";
|
|
883
|
+
}
|
|
765
884
|
}
|
|
766
|
-
function
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
885
|
+
function resetGlobalCursorStyle() {
|
|
886
|
+
if (element !== null) {
|
|
887
|
+
document.head.removeChild(element);
|
|
888
|
+
currentState = null;
|
|
889
|
+
element = null;
|
|
890
|
+
}
|
|
772
891
|
}
|
|
773
|
-
function
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
892
|
+
function setGlobalCursorStyle(state) {
|
|
893
|
+
if (currentState === state) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
currentState = state;
|
|
897
|
+
const style = getCursorStyle(state);
|
|
898
|
+
if (element === null) {
|
|
899
|
+
element = document.createElement("style");
|
|
900
|
+
document.head.appendChild(element);
|
|
901
|
+
}
|
|
902
|
+
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
782
903
|
}
|
|
783
904
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
};
|
|
793
|
-
|
|
905
|
+
function debounce(callback, durationMs = 10) {
|
|
906
|
+
let timeoutId = null;
|
|
907
|
+
let callable = (...args) => {
|
|
908
|
+
if (timeoutId !== null) {
|
|
909
|
+
clearTimeout(timeoutId);
|
|
910
|
+
}
|
|
911
|
+
timeoutId = setTimeout(() => {
|
|
912
|
+
callback(...args);
|
|
913
|
+
}, durationMs);
|
|
914
|
+
};
|
|
915
|
+
return callable;
|
|
794
916
|
}
|
|
795
917
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
function $8b4e4613c531093d$export$80bbb698e7429afe(groupId) {
|
|
799
|
-
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
918
|
+
function getPanelElementsForGroup(groupId) {
|
|
919
|
+
return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
800
920
|
}
|
|
801
921
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
function
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
console.error(error);
|
|
819
|
-
storageObject.getItem = ()=>null;
|
|
820
|
-
storageObject.setItem = ()=>{};
|
|
922
|
+
// PanelGroup might be rendering in a server-side environment where localStorage is not available
|
|
923
|
+
// or on a browser with cookies/storage disabled.
|
|
924
|
+
// In either case, this function avoids accessing localStorage until needed,
|
|
925
|
+
// and avoids throwing user-visible errors.
|
|
926
|
+
function initializeDefaultStorage(storageObject) {
|
|
927
|
+
try {
|
|
928
|
+
if (typeof localStorage !== "undefined") {
|
|
929
|
+
// Bypass this check for future calls
|
|
930
|
+
storageObject.getItem = name => {
|
|
931
|
+
return localStorage.getItem(name);
|
|
932
|
+
};
|
|
933
|
+
storageObject.setItem = (name, value) => {
|
|
934
|
+
localStorage.setItem(name, value);
|
|
935
|
+
};
|
|
936
|
+
} else {
|
|
937
|
+
throw new Error("localStorage not supported in this environment");
|
|
821
938
|
}
|
|
939
|
+
} catch (error) {
|
|
940
|
+
console.error(error);
|
|
941
|
+
storageObject.getItem = () => null;
|
|
942
|
+
storageObject.setItem = () => {};
|
|
943
|
+
}
|
|
822
944
|
}
|
|
823
945
|
|
|
824
|
-
|
|
825
946
|
// Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
|
|
826
947
|
// so they should not be used as part of the serialization key.
|
|
827
948
|
// Using the min/max size attributes should work well enough as a backup.
|
|
828
949
|
// Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
|
|
829
|
-
function
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
if (typeof parsed === "object" && parsed != null) return parsed;
|
|
842
|
-
}
|
|
843
|
-
} catch (error) {}
|
|
844
|
-
return null;
|
|
845
|
-
}
|
|
846
|
-
function $6889c3a3ed41cfd1$export$9c80c6617f0386da(autoSaveId, panels, storage) {
|
|
847
|
-
const state = $6889c3a3ed41cfd1$var$loadSerializedPanelGroupState(autoSaveId, storage);
|
|
848
|
-
if (state) {
|
|
849
|
-
const key = $6889c3a3ed41cfd1$var$getSerializationKey(panels);
|
|
850
|
-
var _state_key;
|
|
851
|
-
return (_state_key = state[key]) !== null && _state_key !== void 0 ? _state_key : null;
|
|
950
|
+
function getSerializationKey(panels) {
|
|
951
|
+
return panels.map(panel => {
|
|
952
|
+
const {
|
|
953
|
+
constraints,
|
|
954
|
+
id,
|
|
955
|
+
idIsFromProps,
|
|
956
|
+
order
|
|
957
|
+
} = panel;
|
|
958
|
+
if (idIsFromProps) {
|
|
959
|
+
return id;
|
|
960
|
+
} else {
|
|
961
|
+
return `${order}:${JSON.stringify(constraints)}`;
|
|
852
962
|
}
|
|
853
|
-
|
|
963
|
+
}).sort((a, b) => a.localeCompare(b)).join(",");
|
|
854
964
|
}
|
|
855
|
-
function
|
|
856
|
-
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
965
|
+
function loadSerializedPanelGroupState(autoSaveId, storage) {
|
|
966
|
+
try {
|
|
967
|
+
const serialized = storage.getItem(`PanelGroup:sizes:${autoSaveId}`);
|
|
968
|
+
if (serialized) {
|
|
969
|
+
const parsed = JSON.parse(serialized);
|
|
970
|
+
if (typeof parsed === "object" && parsed != null) {
|
|
971
|
+
return parsed;
|
|
972
|
+
}
|
|
863
973
|
}
|
|
974
|
+
} catch (error) {}
|
|
975
|
+
return null;
|
|
976
|
+
}
|
|
977
|
+
function loadPanelLayout(autoSaveId, panels, storage) {
|
|
978
|
+
const state = loadSerializedPanelGroupState(autoSaveId, storage);
|
|
979
|
+
if (state) {
|
|
980
|
+
var _state$key;
|
|
981
|
+
const key = getSerializationKey(panels);
|
|
982
|
+
return (_state$key = state[key]) !== null && _state$key !== void 0 ? _state$key : null;
|
|
983
|
+
}
|
|
984
|
+
return null;
|
|
985
|
+
}
|
|
986
|
+
function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
|
|
987
|
+
const key = getSerializationKey(panels);
|
|
988
|
+
const state = loadSerializedPanelGroupState(autoSaveId, storage) || {};
|
|
989
|
+
state[key] = sizes;
|
|
990
|
+
try {
|
|
991
|
+
storage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(state));
|
|
992
|
+
} catch (error) {
|
|
993
|
+
console.error(error);
|
|
994
|
+
}
|
|
864
995
|
}
|
|
865
996
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
997
|
+
// All units must be in percentages; pixel values should be pre-converted
|
|
998
|
+
function validatePanelGroupLayout({
|
|
999
|
+
layout: prevLayout,
|
|
1000
|
+
panelConstraints
|
|
1001
|
+
}) {
|
|
1002
|
+
const nextLayout = [...prevLayout];
|
|
1003
|
+
const nextLayoutTotalSize = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
|
|
1004
|
+
|
|
1005
|
+
// Validate layout expectations
|
|
1006
|
+
if (nextLayout.length !== panelConstraints.length) {
|
|
1007
|
+
throw Error(`Invalid ${panelConstraints.length} panel layout: ${nextLayout.map(size => `${size}%`).join(", ")}`);
|
|
1008
|
+
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
1009
|
+
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1010
|
+
const unsafeSize = nextLayout[index];
|
|
1011
|
+
assert(unsafeSize != null);
|
|
1012
|
+
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1013
|
+
nextLayout[index] = safeSize;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
let remainingSize = 0;
|
|
1017
|
+
|
|
1018
|
+
// First pass: Validate the proposed layout given each panel's constraints
|
|
1019
|
+
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1020
|
+
const unsafeSize = nextLayout[index];
|
|
1021
|
+
assert(unsafeSize != null);
|
|
1022
|
+
const safeSize = resizePanel({
|
|
1023
|
+
panelConstraints,
|
|
1024
|
+
panelIndex: index,
|
|
1025
|
+
size: unsafeSize
|
|
1026
|
+
});
|
|
1027
|
+
if (unsafeSize != safeSize) {
|
|
1028
|
+
remainingSize += unsafeSize - safeSize;
|
|
1029
|
+
nextLayout[index] = safeSize;
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// If there is additional, left over space, assign it to any panel(s) that permits it
|
|
1034
|
+
// (It's not worth taking multiple additional passes to evenly distribute)
|
|
1035
|
+
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1036
|
+
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1037
|
+
const prevSize = nextLayout[index];
|
|
1038
|
+
assert(prevSize != null);
|
|
1039
|
+
const unsafeSize = prevSize + remainingSize;
|
|
1040
|
+
const safeSize = resizePanel({
|
|
1041
|
+
panelConstraints,
|
|
1042
|
+
panelIndex: index,
|
|
1043
|
+
size: unsafeSize
|
|
1044
|
+
});
|
|
1045
|
+
if (prevSize !== safeSize) {
|
|
1046
|
+
remainingSize -= safeSize - prevSize;
|
|
1047
|
+
nextLayout[index] = safeSize;
|
|
1048
|
+
|
|
1049
|
+
// Once we've used up the remainder, bail
|
|
1050
|
+
if (fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1051
|
+
break;
|
|
887
1052
|
}
|
|
1053
|
+
}
|
|
888
1054
|
}
|
|
889
|
-
|
|
1055
|
+
}
|
|
1056
|
+
return nextLayout;
|
|
890
1057
|
}
|
|
891
1058
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
1059
|
+
const LOCAL_STORAGE_DEBOUNCE_INTERVAL = 100;
|
|
1060
|
+
const defaultStorage = {
|
|
1061
|
+
getItem: name => {
|
|
1062
|
+
initializeDefaultStorage(defaultStorage);
|
|
1063
|
+
return defaultStorage.getItem(name);
|
|
1064
|
+
},
|
|
1065
|
+
setItem: (name, value) => {
|
|
1066
|
+
initializeDefaultStorage(defaultStorage);
|
|
1067
|
+
defaultStorage.setItem(name, value);
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
const debounceMap = {};
|
|
1071
|
+
function PanelGroupWithForwardedRef({
|
|
1072
|
+
autoSaveId = null,
|
|
1073
|
+
children,
|
|
1074
|
+
className: classNameFromProps = "",
|
|
1075
|
+
direction,
|
|
1076
|
+
forwardedRef,
|
|
1077
|
+
id: idFromProps = null,
|
|
1078
|
+
onLayout = null,
|
|
1079
|
+
keyboardResizeBy = null,
|
|
1080
|
+
storage = defaultStorage,
|
|
1081
|
+
style: styleFromProps,
|
|
1082
|
+
tagName: Type = "div",
|
|
1083
|
+
...rest
|
|
1084
|
+
}) {
|
|
1085
|
+
const groupId = useUniqueId(idFromProps);
|
|
1086
|
+
const [dragState, setDragState] = useState(null);
|
|
1087
|
+
const [layout, setLayout] = useState([]);
|
|
1088
|
+
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
1089
|
+
const panelSizeBeforeCollapseRef = useRef(new Map());
|
|
1090
|
+
const prevDeltaRef = useRef(0);
|
|
1091
|
+
const committedValuesRef = useRef({
|
|
1092
|
+
autoSaveId,
|
|
1093
|
+
direction,
|
|
1094
|
+
dragState,
|
|
1095
|
+
id: groupId,
|
|
1096
|
+
keyboardResizeBy,
|
|
1097
|
+
onLayout,
|
|
1098
|
+
storage
|
|
1099
|
+
});
|
|
1100
|
+
const eagerValuesRef = useRef({
|
|
1101
|
+
layout,
|
|
1102
|
+
panelDataArray: []
|
|
1103
|
+
});
|
|
1104
|
+
useRef({
|
|
1105
|
+
didLogIdAndOrderWarning: false,
|
|
1106
|
+
didLogPanelConstraintsWarning: false,
|
|
1107
|
+
prevPanelIds: []
|
|
1108
|
+
});
|
|
1109
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
1110
|
+
getId: () => committedValuesRef.current.id,
|
|
1111
|
+
getLayout: () => {
|
|
1112
|
+
const {
|
|
1113
|
+
layout
|
|
1114
|
+
} = eagerValuesRef.current;
|
|
1115
|
+
return layout;
|
|
1116
|
+
},
|
|
1117
|
+
setLayout: unsafeLayout => {
|
|
1118
|
+
const {
|
|
1119
|
+
onLayout
|
|
1120
|
+
} = committedValuesRef.current;
|
|
1121
|
+
const {
|
|
1122
|
+
layout: prevLayout,
|
|
1123
|
+
panelDataArray
|
|
1124
|
+
} = eagerValuesRef.current;
|
|
1125
|
+
const safeLayout = validatePanelGroupLayout({
|
|
1126
|
+
layout: unsafeLayout,
|
|
1127
|
+
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1128
|
+
});
|
|
1129
|
+
if (!areEqual(prevLayout, safeLayout)) {
|
|
1130
|
+
setLayout(safeLayout);
|
|
1131
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1132
|
+
if (onLayout) {
|
|
1133
|
+
onLayout(safeLayout);
|
|
913
1134
|
}
|
|
1135
|
+
callPanelCallbacks(panelDataArray, safeLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}), []);
|
|
1139
|
+
useIsomorphicLayoutEffect(() => {
|
|
1140
|
+
committedValuesRef.current.autoSaveId = autoSaveId;
|
|
1141
|
+
committedValuesRef.current.direction = direction;
|
|
1142
|
+
committedValuesRef.current.dragState = dragState;
|
|
1143
|
+
committedValuesRef.current.id = groupId;
|
|
1144
|
+
committedValuesRef.current.onLayout = onLayout;
|
|
1145
|
+
committedValuesRef.current.storage = storage;
|
|
1146
|
+
});
|
|
1147
|
+
useWindowSplitterPanelGroupBehavior({
|
|
1148
|
+
committedValuesRef,
|
|
1149
|
+
eagerValuesRef,
|
|
1150
|
+
groupId,
|
|
1151
|
+
layout,
|
|
1152
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1153
|
+
setLayout
|
|
1154
|
+
});
|
|
1155
|
+
useEffect(() => {
|
|
1156
|
+
const {
|
|
1157
|
+
panelDataArray
|
|
1158
|
+
} = eagerValuesRef.current;
|
|
1159
|
+
|
|
1160
|
+
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1161
|
+
if (autoSaveId) {
|
|
1162
|
+
if (layout.length === 0 || layout.length !== panelDataArray.length) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
let debouncedSave = debounceMap[autoSaveId];
|
|
1166
|
+
|
|
1167
|
+
// Limit the frequency of localStorage updates.
|
|
1168
|
+
if (debouncedSave == null) {
|
|
1169
|
+
debouncedSave = debounce(savePanelGroupLayout, LOCAL_STORAGE_DEBOUNCE_INTERVAL);
|
|
1170
|
+
debounceMap[autoSaveId] = debouncedSave;
|
|
1171
|
+
}
|
|
1172
|
+
debouncedSave(autoSaveId, panelDataArray, layout, storage);
|
|
914
1173
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1174
|
+
}, [autoSaveId, layout, storage]);
|
|
1175
|
+
|
|
1176
|
+
// DEV warnings
|
|
1177
|
+
useEffect(() => {
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
// External APIs are safe to memoize via committed values ref
|
|
1181
|
+
const collapsePanel = useCallback(panelData => {
|
|
1182
|
+
const {
|
|
1183
|
+
onLayout
|
|
1184
|
+
} = committedValuesRef.current;
|
|
1185
|
+
const {
|
|
1186
|
+
layout: prevLayout,
|
|
1187
|
+
panelDataArray
|
|
1188
|
+
} = eagerValuesRef.current;
|
|
1189
|
+
if (panelData.constraints.collapsible) {
|
|
1190
|
+
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1191
|
+
const {
|
|
1192
|
+
collapsedSize = 0,
|
|
1193
|
+
panelSize,
|
|
1194
|
+
pivotIndices
|
|
1195
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1196
|
+
assert(panelSize != null);
|
|
1197
|
+
if (panelSize !== collapsedSize) {
|
|
1198
|
+
// Store size before collapse;
|
|
1199
|
+
// This is the size that gets restored if the expand() API is used.
|
|
1200
|
+
panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
|
|
1201
|
+
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1202
|
+
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1203
|
+
const nextLayout = adjustLayoutByDelta({
|
|
1204
|
+
delta,
|
|
1205
|
+
layout: prevLayout,
|
|
1206
|
+
panelConstraints: panelConstraintsArray,
|
|
1207
|
+
pivotIndices,
|
|
1208
|
+
trigger: "imperative-api"
|
|
924
1209
|
});
|
|
925
|
-
if (
|
|
926
|
-
|
|
927
|
-
|
|
1210
|
+
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1211
|
+
setLayout(nextLayout);
|
|
1212
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1213
|
+
if (onLayout) {
|
|
1214
|
+
onLayout(nextLayout);
|
|
1215
|
+
}
|
|
1216
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
928
1217
|
}
|
|
1218
|
+
}
|
|
929
1219
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1220
|
+
}, []);
|
|
1221
|
+
|
|
1222
|
+
// External APIs are safe to memoize via committed values ref
|
|
1223
|
+
const expandPanel = useCallback(panelData => {
|
|
1224
|
+
const {
|
|
1225
|
+
onLayout
|
|
1226
|
+
} = committedValuesRef.current;
|
|
1227
|
+
const {
|
|
1228
|
+
layout: prevLayout,
|
|
1229
|
+
panelDataArray
|
|
1230
|
+
} = eagerValuesRef.current;
|
|
1231
|
+
if (panelData.constraints.collapsible) {
|
|
1232
|
+
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1233
|
+
const {
|
|
1234
|
+
collapsedSize = 0,
|
|
1235
|
+
panelSize,
|
|
1236
|
+
minSize = 0,
|
|
1237
|
+
pivotIndices
|
|
1238
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1239
|
+
if (panelSize === collapsedSize) {
|
|
1240
|
+
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1241
|
+
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1242
|
+
const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
|
|
1243
|
+
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1244
|
+
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1245
|
+
const nextLayout = adjustLayoutByDelta({
|
|
1246
|
+
delta,
|
|
1247
|
+
layout: prevLayout,
|
|
1248
|
+
panelConstraints: panelConstraintsArray,
|
|
1249
|
+
pivotIndices,
|
|
1250
|
+
trigger: "imperative-api"
|
|
940
1251
|
});
|
|
941
|
-
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1252
|
+
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1253
|
+
setLayout(nextLayout);
|
|
1254
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1255
|
+
if (onLayout) {
|
|
1256
|
+
onLayout(nextLayout);
|
|
1257
|
+
}
|
|
1258
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
946
1259
|
}
|
|
1260
|
+
}
|
|
947
1261
|
}
|
|
948
|
-
|
|
949
|
-
|
|
1262
|
+
}, []);
|
|
1263
|
+
|
|
1264
|
+
// External APIs are safe to memoize via committed values ref
|
|
1265
|
+
const getPanelSize = useCallback(panelData => {
|
|
1266
|
+
const {
|
|
1267
|
+
layout,
|
|
1268
|
+
panelDataArray
|
|
1269
|
+
} = eagerValuesRef.current;
|
|
1270
|
+
const {
|
|
1271
|
+
panelSize
|
|
1272
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1273
|
+
assert(panelSize != null);
|
|
1274
|
+
return panelSize;
|
|
1275
|
+
}, []);
|
|
1276
|
+
|
|
1277
|
+
// This API should never read from committedValuesRef
|
|
1278
|
+
const getPanelStyle = useCallback(panelData => {
|
|
1279
|
+
const {
|
|
1280
|
+
panelDataArray
|
|
1281
|
+
} = eagerValuesRef.current;
|
|
1282
|
+
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1283
|
+
return computePanelFlexBoxStyle({
|
|
1284
|
+
dragState,
|
|
1285
|
+
layout,
|
|
1286
|
+
panelData: panelDataArray,
|
|
1287
|
+
panelIndex
|
|
1288
|
+
});
|
|
1289
|
+
}, [dragState, layout]);
|
|
1290
|
+
|
|
1291
|
+
// External APIs are safe to memoize via committed values ref
|
|
1292
|
+
const isPanelCollapsed = useCallback(panelData => {
|
|
1293
|
+
const {
|
|
1294
|
+
layout,
|
|
1295
|
+
panelDataArray
|
|
1296
|
+
} = eagerValuesRef.current;
|
|
1297
|
+
const {
|
|
1298
|
+
collapsedSize,
|
|
1299
|
+
collapsible,
|
|
1300
|
+
panelSize
|
|
1301
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1302
|
+
return collapsible === true && panelSize === collapsedSize;
|
|
1303
|
+
}, []);
|
|
1304
|
+
|
|
1305
|
+
// External APIs are safe to memoize via committed values ref
|
|
1306
|
+
const isPanelExpanded = useCallback(panelData => {
|
|
1307
|
+
const {
|
|
1308
|
+
layout,
|
|
1309
|
+
panelDataArray
|
|
1310
|
+
} = eagerValuesRef.current;
|
|
1311
|
+
const {
|
|
1312
|
+
collapsedSize = 0,
|
|
1313
|
+
collapsible,
|
|
1314
|
+
panelSize
|
|
1315
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1316
|
+
assert(panelSize != null);
|
|
1317
|
+
return !collapsible || panelSize > collapsedSize;
|
|
1318
|
+
}, []);
|
|
1319
|
+
const registerPanel = useCallback(panelData => {
|
|
1320
|
+
const {
|
|
1321
|
+
autoSaveId,
|
|
1322
|
+
id: groupId,
|
|
1323
|
+
onLayout,
|
|
1324
|
+
storage
|
|
1325
|
+
} = committedValuesRef.current;
|
|
1326
|
+
const {
|
|
1327
|
+
layout: prevLayout,
|
|
1328
|
+
panelDataArray
|
|
1329
|
+
} = eagerValuesRef.current;
|
|
1330
|
+
|
|
1331
|
+
// HACK
|
|
1332
|
+
// This appears to be triggered by some React Suspense+Offscreen+StrictMode bug;
|
|
1333
|
+
// see app.replay.io/recording/17b6e11d-4500-4173-b23d-61dfd141fed1
|
|
1334
|
+
const index = findPanelDataIndex(panelDataArray, panelData);
|
|
1335
|
+
if (index >= 0) {
|
|
1336
|
+
if (panelData.idIsFromProps) {
|
|
1337
|
+
console.warn(`Panel with id "${panelData.id}" registered twice`);
|
|
1338
|
+
} else {
|
|
1339
|
+
console.warn(`Panel registered twice`);
|
|
1340
|
+
}
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
panelDataArray.push(panelData);
|
|
1344
|
+
panelDataArray.sort((panelA, panelB) => {
|
|
1345
|
+
const orderA = panelA.order;
|
|
1346
|
+
const orderB = panelB.order;
|
|
1347
|
+
if (orderA == null && orderB == null) {
|
|
1348
|
+
return 0;
|
|
1349
|
+
} else if (orderA == null) {
|
|
1350
|
+
return -1;
|
|
1351
|
+
} else if (orderB == null) {
|
|
1352
|
+
return 1;
|
|
1353
|
+
} else {
|
|
1354
|
+
return orderA - orderB;
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
950
1357
|
|
|
1358
|
+
// Wait until all panels have registered before we try to compute layout;
|
|
1359
|
+
// doing it earlier is both wasteful and may trigger misleading warnings in development mode.
|
|
1360
|
+
const panelElements = getPanelElementsForGroup(groupId);
|
|
1361
|
+
if (panelElements.length !== panelDataArray.length) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
951
1364
|
|
|
1365
|
+
// If this panel has been configured to persist sizing information,
|
|
1366
|
+
// default size should be restored from local storage if possible.
|
|
1367
|
+
let unsafeLayout = null;
|
|
1368
|
+
if (autoSaveId) {
|
|
1369
|
+
unsafeLayout = loadPanelLayout(autoSaveId, panelDataArray, storage);
|
|
1370
|
+
}
|
|
1371
|
+
if (unsafeLayout == null) {
|
|
1372
|
+
unsafeLayout = calculateUnsafeDefaultLayout({
|
|
1373
|
+
panelDataArray
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
952
1376
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1377
|
+
// Validate even saved layouts in case something has changed since last render
|
|
1378
|
+
// e.g. for pixel groups, this could be the size of the window
|
|
1379
|
+
const nextLayout = validatePanelGroupLayout({
|
|
1380
|
+
layout: unsafeLayout,
|
|
1381
|
+
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
// Offscreen mode makes this a bit weird;
|
|
1385
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1386
|
+
// but the overall layout doesn't change between these two cases.
|
|
1387
|
+
setLayout(nextLayout);
|
|
1388
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1389
|
+
if (!areEqual(prevLayout, nextLayout)) {
|
|
1390
|
+
if (onLayout) {
|
|
1391
|
+
onLayout(nextLayout);
|
|
1392
|
+
}
|
|
1393
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
962
1394
|
}
|
|
963
|
-
};
|
|
964
|
-
const
|
|
965
|
-
function
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
const panelSizeBeforeCollapseRef = (0, $ef07efbe5fa7d87e$export$b8f5890fc79d6aca)(new Map());
|
|
971
|
-
const prevDeltaRef = (0, $ef07efbe5fa7d87e$export$b8f5890fc79d6aca)(0);
|
|
972
|
-
const committedValuesRef = (0, $ef07efbe5fa7d87e$export$b8f5890fc79d6aca)({
|
|
973
|
-
autoSaveId: autoSaveId,
|
|
974
|
-
direction: direction,
|
|
975
|
-
dragState: dragState,
|
|
1395
|
+
}, []);
|
|
1396
|
+
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1397
|
+
return function resizeHandler(event) {
|
|
1398
|
+
event.preventDefault();
|
|
1399
|
+
const {
|
|
1400
|
+
direction,
|
|
1401
|
+
dragState,
|
|
976
1402
|
id: groupId,
|
|
977
|
-
keyboardResizeBy
|
|
978
|
-
onLayout
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
setLayout: setLayout
|
|
1026
|
-
});
|
|
1027
|
-
(0, $ef07efbe5fa7d87e$export$6d9c69b0de29b591)(()=>{
|
|
1028
|
-
const { panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1029
|
-
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1030
|
-
if (autoSaveId) {
|
|
1031
|
-
if (layout.length === 0 || layout.length !== panelDataArray.length) return;
|
|
1032
|
-
let debouncedSave = $3daa5d4c086ea816$var$debounceMap[autoSaveId];
|
|
1033
|
-
// Limit the frequency of localStorage updates.
|
|
1034
|
-
if (debouncedSave == null) {
|
|
1035
|
-
debouncedSave = (0, $f7d932e9304c1581$export$2e2bcd8739ae039)((0, $6889c3a3ed41cfd1$export$af183b313c61be4f), $3daa5d4c086ea816$var$LOCAL_STORAGE_DEBOUNCE_INTERVAL);
|
|
1036
|
-
$3daa5d4c086ea816$var$debounceMap[autoSaveId] = debouncedSave;
|
|
1403
|
+
keyboardResizeBy,
|
|
1404
|
+
onLayout
|
|
1405
|
+
} = committedValuesRef.current;
|
|
1406
|
+
const {
|
|
1407
|
+
layout: prevLayout,
|
|
1408
|
+
panelDataArray
|
|
1409
|
+
} = eagerValuesRef.current;
|
|
1410
|
+
const {
|
|
1411
|
+
initialLayout
|
|
1412
|
+
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1413
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1414
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1415
|
+
if (delta === 0) {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
// Support RTL layouts
|
|
1420
|
+
const isHorizontal = direction === "horizontal";
|
|
1421
|
+
if (document.dir === "rtl" && isHorizontal) {
|
|
1422
|
+
delta = -delta;
|
|
1423
|
+
}
|
|
1424
|
+
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1425
|
+
const nextLayout = adjustLayoutByDelta({
|
|
1426
|
+
delta,
|
|
1427
|
+
layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
1428
|
+
panelConstraints,
|
|
1429
|
+
pivotIndices,
|
|
1430
|
+
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
1431
|
+
});
|
|
1432
|
+
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
1433
|
+
|
|
1434
|
+
// Only update the cursor for layout changes triggered by touch/mouse events (not keyboard)
|
|
1435
|
+
// Update the cursor even if the layout hasn't changed (we may need to show an invalid cursor state)
|
|
1436
|
+
if (isMouseEvent(event) || isTouchEvent(event)) {
|
|
1437
|
+
// Watch for multiple subsequent deltas; this might occur for tiny cursor movements.
|
|
1438
|
+
// In this case, Panel sizes might not change–
|
|
1439
|
+
// but updating cursor in this scenario would cause a flicker.
|
|
1440
|
+
if (prevDeltaRef.current != delta) {
|
|
1441
|
+
prevDeltaRef.current = delta;
|
|
1442
|
+
if (!layoutChanged) {
|
|
1443
|
+
// If the pointer has moved too far to resize the panel any further,
|
|
1444
|
+
// update the cursor style for a visual clue.
|
|
1445
|
+
// This mimics VS Code behavior.
|
|
1446
|
+
|
|
1447
|
+
if (isHorizontal) {
|
|
1448
|
+
setGlobalCursorStyle(delta < 0 ? "horizontal-min" : "horizontal-max");
|
|
1449
|
+
} else {
|
|
1450
|
+
setGlobalCursorStyle(delta < 0 ? "vertical-min" : "vertical-max");
|
|
1037
1451
|
}
|
|
1038
|
-
|
|
1452
|
+
} else {
|
|
1453
|
+
// Reset the cursor style to the the normal resize cursor.
|
|
1454
|
+
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1455
|
+
}
|
|
1039
1456
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
(0, $ef07efbe5fa7d87e$export$6d9c69b0de29b591)(()=>{
|
|
1047
|
-
if (0, $aedbef154d609804$export$df77466336fe5355) {
|
|
1048
|
-
const { panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1049
|
-
const { didLogIdAndOrderWarning: didLogIdAndOrderWarning, didLogPanelConstraintsWarning: didLogPanelConstraintsWarning, prevPanelIds: prevPanelIds } = devWarningsRef.current;
|
|
1050
|
-
if (!didLogIdAndOrderWarning) {
|
|
1051
|
-
const panelIds = panelDataArray.map(({ id: id })=>id);
|
|
1052
|
-
devWarningsRef.current.prevPanelIds = panelIds;
|
|
1053
|
-
const panelsHaveChanged = prevPanelIds.length > 0 && !(0, $c892f0f705e6ded5$export$b141efd0b0fb9174)(prevPanelIds, panelIds);
|
|
1054
|
-
if (panelsHaveChanged) {
|
|
1055
|
-
if (panelDataArray.find(({ idIsFromProps: idIsFromProps, order: order })=>!idIsFromProps || order == null)) {
|
|
1056
|
-
devWarningsRef.current.didLogIdAndOrderWarning = true;
|
|
1057
|
-
console.warn(`WARNING: Panel id and order props recommended when panels are dynamically rendered`);
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
if (!didLogPanelConstraintsWarning) {
|
|
1062
|
-
const panelConstraints = panelDataArray.map((panelData)=>panelData.constraints);
|
|
1063
|
-
for(let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++){
|
|
1064
|
-
const panelData = panelDataArray[panelIndex];
|
|
1065
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(panelData);
|
|
1066
|
-
const isValid = (0, $006440f9579d3b07$export$d00cfefa2c395b39)({
|
|
1067
|
-
panelConstraints: panelConstraints,
|
|
1068
|
-
panelId: panelData.id,
|
|
1069
|
-
panelIndex: panelIndex
|
|
1070
|
-
});
|
|
1071
|
-
if (!isValid) {
|
|
1072
|
-
devWarningsRef.current.didLogPanelConstraintsWarning = true;
|
|
1073
|
-
break;
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1457
|
+
}
|
|
1458
|
+
if (layoutChanged) {
|
|
1459
|
+
setLayout(nextLayout);
|
|
1460
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1461
|
+
if (onLayout) {
|
|
1462
|
+
onLayout(nextLayout);
|
|
1077
1463
|
}
|
|
1464
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
}, []);
|
|
1468
|
+
|
|
1469
|
+
// External APIs are safe to memoize via committed values ref
|
|
1470
|
+
const resizePanel = useCallback((panelData, unsafePanelSize) => {
|
|
1471
|
+
const {
|
|
1472
|
+
onLayout
|
|
1473
|
+
} = committedValuesRef.current;
|
|
1474
|
+
const {
|
|
1475
|
+
layout: prevLayout,
|
|
1476
|
+
panelDataArray
|
|
1477
|
+
} = eagerValuesRef.current;
|
|
1478
|
+
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1479
|
+
const {
|
|
1480
|
+
panelSize,
|
|
1481
|
+
pivotIndices
|
|
1482
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1483
|
+
assert(panelSize != null);
|
|
1484
|
+
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1485
|
+
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1486
|
+
const nextLayout = adjustLayoutByDelta({
|
|
1487
|
+
delta,
|
|
1488
|
+
layout: prevLayout,
|
|
1489
|
+
panelConstraints: panelConstraintsArray,
|
|
1490
|
+
pivotIndices,
|
|
1491
|
+
trigger: "imperative-api"
|
|
1078
1492
|
});
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
});
|
|
1155
|
-
}, [
|
|
1156
|
-
dragState,
|
|
1157
|
-
layout
|
|
1158
|
-
]);
|
|
1159
|
-
// External APIs are safe to memoize via committed values ref
|
|
1160
|
-
const isPanelCollapsed = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((panelData)=>{
|
|
1161
|
-
const { layout: layout, panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1162
|
-
const { collapsedSize: collapsedSize, collapsible: collapsible, panelSize: panelSize } = $3daa5d4c086ea816$var$panelDataHelper(panelDataArray, panelData, layout);
|
|
1163
|
-
return collapsible === true && panelSize === collapsedSize;
|
|
1164
|
-
}, []);
|
|
1165
|
-
// External APIs are safe to memoize via committed values ref
|
|
1166
|
-
const isPanelExpanded = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((panelData)=>{
|
|
1167
|
-
const { layout: layout, panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1168
|
-
const { collapsedSize: collapsedSize = 0, collapsible: collapsible, panelSize: panelSize } = $3daa5d4c086ea816$var$panelDataHelper(panelDataArray, panelData, layout);
|
|
1169
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(panelSize != null);
|
|
1170
|
-
return !collapsible || panelSize > collapsedSize;
|
|
1171
|
-
}, []);
|
|
1172
|
-
const registerPanel = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((panelData)=>{
|
|
1173
|
-
const { autoSaveId: autoSaveId, id: groupId, onLayout: onLayout, storage: storage } = committedValuesRef.current;
|
|
1174
|
-
const { layout: prevLayout, panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1175
|
-
// HACK
|
|
1176
|
-
// This appears to be triggered by some React Suspense+Offscreen+StrictMode bug;
|
|
1177
|
-
// see app.replay.io/recording/17b6e11d-4500-4173-b23d-61dfd141fed1
|
|
1178
|
-
const index = $3daa5d4c086ea816$var$findPanelDataIndex(panelDataArray, panelData);
|
|
1179
|
-
if (index >= 0) {
|
|
1180
|
-
if (panelData.idIsFromProps) console.warn(`Panel with id "${panelData.id}" registered twice`);
|
|
1181
|
-
else console.warn(`Panel registered twice`);
|
|
1182
|
-
return;
|
|
1493
|
+
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1494
|
+
setLayout(nextLayout);
|
|
1495
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1496
|
+
if (onLayout) {
|
|
1497
|
+
onLayout(nextLayout);
|
|
1498
|
+
}
|
|
1499
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1500
|
+
}
|
|
1501
|
+
}, []);
|
|
1502
|
+
const startDragging = useCallback((dragHandleId, event) => {
|
|
1503
|
+
const {
|
|
1504
|
+
direction
|
|
1505
|
+
} = committedValuesRef.current;
|
|
1506
|
+
const {
|
|
1507
|
+
layout
|
|
1508
|
+
} = eagerValuesRef.current;
|
|
1509
|
+
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1510
|
+
assert(handleElement);
|
|
1511
|
+
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1512
|
+
setDragState({
|
|
1513
|
+
dragHandleId,
|
|
1514
|
+
dragHandleRect: handleElement.getBoundingClientRect(),
|
|
1515
|
+
initialCursorPosition,
|
|
1516
|
+
initialLayout: layout
|
|
1517
|
+
});
|
|
1518
|
+
}, []);
|
|
1519
|
+
const stopDragging = useCallback(() => {
|
|
1520
|
+
resetGlobalCursorStyle();
|
|
1521
|
+
setDragState(null);
|
|
1522
|
+
}, []);
|
|
1523
|
+
const unregisterPanelRef = useRef({
|
|
1524
|
+
pendingPanelIds: new Set(),
|
|
1525
|
+
timeout: null
|
|
1526
|
+
});
|
|
1527
|
+
const unregisterPanel = useCallback(panelData => {
|
|
1528
|
+
const {
|
|
1529
|
+
onLayout
|
|
1530
|
+
} = committedValuesRef.current;
|
|
1531
|
+
const {
|
|
1532
|
+
layout: prevLayout,
|
|
1533
|
+
panelDataArray
|
|
1534
|
+
} = eagerValuesRef.current;
|
|
1535
|
+
const index = findPanelDataIndex(panelDataArray, panelData);
|
|
1536
|
+
if (index >= 0) {
|
|
1537
|
+
panelDataArray.splice(index, 1);
|
|
1538
|
+
unregisterPanelRef.current.pendingPanelIds.add(panelData.id);
|
|
1539
|
+
}
|
|
1540
|
+
if (unregisterPanelRef.current.timeout != null) {
|
|
1541
|
+
clearTimeout(unregisterPanelRef.current.timeout);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// Batch panel unmounts so that we only calculate layout once;
|
|
1545
|
+
// This is more efficient and avoids misleading warnings in development mode.
|
|
1546
|
+
// We can't check the DOM to detect this because Panel elements have not yet been removed.
|
|
1547
|
+
unregisterPanelRef.current.timeout = setTimeout(() => {
|
|
1548
|
+
const {
|
|
1549
|
+
pendingPanelIds
|
|
1550
|
+
} = unregisterPanelRef.current;
|
|
1551
|
+
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1552
|
+
|
|
1553
|
+
// TRICKY
|
|
1554
|
+
// Strict effects mode
|
|
1555
|
+
let unmountDueToStrictMode = false;
|
|
1556
|
+
pendingPanelIds.forEach(panelId => {
|
|
1557
|
+
pendingPanelIds.delete(panelId);
|
|
1558
|
+
if (panelDataArray.find(({
|
|
1559
|
+
id
|
|
1560
|
+
}) => id === panelId) != null) {
|
|
1561
|
+
unmountDueToStrictMode = true;
|
|
1562
|
+
} else {
|
|
1563
|
+
// TRICKY
|
|
1564
|
+
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1565
|
+
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1566
|
+
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1567
|
+
delete panelIdToLastNotifiedSizeMap[panelId];
|
|
1183
1568
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
});
|
|
1204
|
-
// Validate even saved layouts in case something has changed since last render
|
|
1205
|
-
// e.g. for pixel groups, this could be the size of the window
|
|
1206
|
-
const nextLayout = (0, $6f1a05873bb6ec6f$export$64432a52a1035c18)({
|
|
1207
|
-
layout: unsafeLayout,
|
|
1208
|
-
panelConstraints: panelDataArray.map((panelData)=>panelData.constraints)
|
|
1209
|
-
});
|
|
1210
|
-
// Offscreen mode makes this a bit weird;
|
|
1211
|
-
// Panels unregister when hidden and re-register when shown again,
|
|
1212
|
-
// but the overall layout doesn't change between these two cases.
|
|
1569
|
+
});
|
|
1570
|
+
if (unmountDueToStrictMode) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
if (panelDataArray.length === 0) {
|
|
1574
|
+
// The group is unmounting; skip layout calculation.
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
let unsafeLayout = calculateUnsafeDefaultLayout({
|
|
1578
|
+
panelDataArray
|
|
1579
|
+
});
|
|
1580
|
+
|
|
1581
|
+
// Validate even saved layouts in case something has changed since last render
|
|
1582
|
+
// e.g. for pixel groups, this could be the size of the window
|
|
1583
|
+
const nextLayout = validatePanelGroupLayout({
|
|
1584
|
+
layout: unsafeLayout,
|
|
1585
|
+
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1586
|
+
});
|
|
1587
|
+
if (!areEqual(prevLayout, nextLayout)) {
|
|
1213
1588
|
setLayout(nextLayout);
|
|
1214
1589
|
eagerValuesRef.current.layout = nextLayout;
|
|
1215
|
-
if (
|
|
1216
|
-
|
|
1217
|
-
(0, $2743876c6469fb21$export$b8e48269e4faa934)(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1590
|
+
if (onLayout) {
|
|
1591
|
+
onLayout(nextLayout);
|
|
1218
1592
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
if (onLayout) onLayout(nextLayout);
|
|
1263
|
-
(0, $2743876c6469fb21$export$b8e48269e4faa934)(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
|
-
}, []);
|
|
1267
|
-
// External APIs are safe to memoize via committed values ref
|
|
1268
|
-
const resizePanel = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((panelData, unsafePanelSize)=>{
|
|
1269
|
-
const { onLayout: onLayout } = committedValuesRef.current;
|
|
1270
|
-
const { layout: prevLayout, panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1271
|
-
const panelConstraintsArray = panelDataArray.map((panelData)=>panelData.constraints);
|
|
1272
|
-
const { panelSize: panelSize, pivotIndices: pivotIndices } = $3daa5d4c086ea816$var$panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1273
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(panelSize != null);
|
|
1274
|
-
const isLastPanel = $3daa5d4c086ea816$var$findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1275
|
-
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1276
|
-
const nextLayout = (0, $fe96098ae4f2a44d$export$7fead5cc734d205b)({
|
|
1277
|
-
delta: delta,
|
|
1278
|
-
layout: prevLayout,
|
|
1279
|
-
panelConstraints: panelConstraintsArray,
|
|
1280
|
-
pivotIndices: pivotIndices,
|
|
1281
|
-
trigger: "imperative-api"
|
|
1282
|
-
});
|
|
1283
|
-
if (!(0, $81d2449822663a2a$export$a10903e2e57656c1)(prevLayout, nextLayout)) {
|
|
1284
|
-
setLayout(nextLayout);
|
|
1285
|
-
eagerValuesRef.current.layout = nextLayout;
|
|
1286
|
-
if (onLayout) onLayout(nextLayout);
|
|
1287
|
-
(0, $2743876c6469fb21$export$b8e48269e4faa934)(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1288
|
-
}
|
|
1289
|
-
}, []);
|
|
1290
|
-
const startDragging = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((dragHandleId, event)=>{
|
|
1291
|
-
const { direction: direction } = committedValuesRef.current;
|
|
1292
|
-
const { layout: layout } = eagerValuesRef.current;
|
|
1293
|
-
const handleElement = (0, $99b0d18e36332b26$export$4c5229c874a62620)(dragHandleId);
|
|
1294
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(handleElement);
|
|
1295
|
-
const initialCursorPosition = (0, $a568cbd9a3e686f5$export$ae0c59ca751ba81d)(direction, event);
|
|
1296
|
-
setDragState({
|
|
1297
|
-
dragHandleId: dragHandleId,
|
|
1298
|
-
dragHandleRect: handleElement.getBoundingClientRect(),
|
|
1299
|
-
initialCursorPosition: initialCursorPosition,
|
|
1300
|
-
initialLayout: layout
|
|
1301
|
-
});
|
|
1302
|
-
}, []);
|
|
1303
|
-
const stopDragging = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)(()=>{
|
|
1304
|
-
(0, $8d9d88bebf1a8ace$export$b61932ee18f96e08)();
|
|
1305
|
-
setDragState(null);
|
|
1306
|
-
}, []);
|
|
1307
|
-
const unregisterPanelRef = (0, $ef07efbe5fa7d87e$export$b8f5890fc79d6aca)({
|
|
1308
|
-
pendingPanelIds: new Set(),
|
|
1309
|
-
timeout: null
|
|
1310
|
-
});
|
|
1311
|
-
const unregisterPanel = (0, $ef07efbe5fa7d87e$export$35808ee640e87ca7)((panelData)=>{
|
|
1312
|
-
const { onLayout: onLayout } = committedValuesRef.current;
|
|
1313
|
-
const { layout: prevLayout, panelDataArray: panelDataArray } = eagerValuesRef.current;
|
|
1314
|
-
const index = $3daa5d4c086ea816$var$findPanelDataIndex(panelDataArray, panelData);
|
|
1315
|
-
if (index >= 0) {
|
|
1316
|
-
panelDataArray.splice(index, 1);
|
|
1317
|
-
unregisterPanelRef.current.pendingPanelIds.add(panelData.id);
|
|
1318
|
-
}
|
|
1319
|
-
if (unregisterPanelRef.current.timeout != null) clearTimeout(unregisterPanelRef.current.timeout);
|
|
1320
|
-
// Batch panel unmounts so that we only calculate layout once;
|
|
1321
|
-
// This is more efficient and avoids misleading warnings in development mode.
|
|
1322
|
-
// We can't check the DOM to detect this because Panel elements have not yet been removed.
|
|
1323
|
-
unregisterPanelRef.current.timeout = setTimeout(()=>{
|
|
1324
|
-
const { pendingPanelIds: pendingPanelIds } = unregisterPanelRef.current;
|
|
1325
|
-
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1326
|
-
// TRICKY
|
|
1327
|
-
// Strict effects mode
|
|
1328
|
-
let unmountDueToStrictMode = false;
|
|
1329
|
-
pendingPanelIds.forEach((panelId)=>{
|
|
1330
|
-
pendingPanelIds.delete(panelId);
|
|
1331
|
-
if (panelDataArray.find(({ id: id })=>id === panelId) != null) unmountDueToStrictMode = true;
|
|
1332
|
-
else // TRICKY
|
|
1333
|
-
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1334
|
-
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1335
|
-
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1336
|
-
delete panelIdToLastNotifiedSizeMap[panelId];
|
|
1337
|
-
});
|
|
1338
|
-
if (unmountDueToStrictMode) return;
|
|
1339
|
-
if (panelDataArray.length === 0) // The group is unmounting; skip layout calculation.
|
|
1340
|
-
return;
|
|
1341
|
-
let unsafeLayout = (0, $457c46ca858cf2c6$export$47337a21c443778e)({
|
|
1342
|
-
panelDataArray: panelDataArray
|
|
1343
|
-
});
|
|
1344
|
-
// Validate even saved layouts in case something has changed since last render
|
|
1345
|
-
// e.g. for pixel groups, this could be the size of the window
|
|
1346
|
-
const nextLayout = (0, $6f1a05873bb6ec6f$export$64432a52a1035c18)({
|
|
1347
|
-
layout: unsafeLayout,
|
|
1348
|
-
panelConstraints: panelDataArray.map((panelData)=>panelData.constraints)
|
|
1349
|
-
});
|
|
1350
|
-
if (!(0, $c892f0f705e6ded5$export$b141efd0b0fb9174)(prevLayout, nextLayout)) {
|
|
1351
|
-
setLayout(nextLayout);
|
|
1352
|
-
eagerValuesRef.current.layout = nextLayout;
|
|
1353
|
-
if (onLayout) onLayout(nextLayout);
|
|
1354
|
-
(0, $2743876c6469fb21$export$b8e48269e4faa934)(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1355
|
-
}
|
|
1356
|
-
}, 0);
|
|
1357
|
-
}, []);
|
|
1358
|
-
const context = (0, $ef07efbe5fa7d87e$export$1538c33de8887b59)(()=>({
|
|
1359
|
-
collapsePanel: collapsePanel,
|
|
1360
|
-
direction: direction,
|
|
1361
|
-
dragState: dragState,
|
|
1362
|
-
expandPanel: expandPanel,
|
|
1363
|
-
getPanelSize: getPanelSize,
|
|
1364
|
-
getPanelStyle: getPanelStyle,
|
|
1365
|
-
groupId: groupId,
|
|
1366
|
-
isPanelCollapsed: isPanelCollapsed,
|
|
1367
|
-
isPanelExpanded: isPanelExpanded,
|
|
1368
|
-
registerPanel: registerPanel,
|
|
1369
|
-
registerResizeHandle: registerResizeHandle,
|
|
1370
|
-
resizePanel: resizePanel,
|
|
1371
|
-
startDragging: startDragging,
|
|
1372
|
-
stopDragging: stopDragging,
|
|
1373
|
-
unregisterPanel: unregisterPanel
|
|
1374
|
-
}), [
|
|
1375
|
-
collapsePanel,
|
|
1376
|
-
dragState,
|
|
1377
|
-
direction,
|
|
1378
|
-
expandPanel,
|
|
1379
|
-
getPanelSize,
|
|
1380
|
-
getPanelStyle,
|
|
1381
|
-
groupId,
|
|
1382
|
-
isPanelCollapsed,
|
|
1383
|
-
isPanelExpanded,
|
|
1384
|
-
registerPanel,
|
|
1385
|
-
registerResizeHandle,
|
|
1386
|
-
resizePanel,
|
|
1387
|
-
startDragging,
|
|
1388
|
-
stopDragging,
|
|
1389
|
-
unregisterPanel
|
|
1390
|
-
]);
|
|
1391
|
-
const style = {
|
|
1392
|
-
display: "flex",
|
|
1393
|
-
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
1394
|
-
height: "100%",
|
|
1395
|
-
overflow: "hidden",
|
|
1396
|
-
width: "100%"
|
|
1397
|
-
};
|
|
1398
|
-
return (0, $ef07efbe5fa7d87e$export$c8a8987d4410bf2d)((0, $e30963544e64b604$export$7d8c6d083caec74a).Provider, {
|
|
1399
|
-
value: context
|
|
1400
|
-
}, (0, $ef07efbe5fa7d87e$export$c8a8987d4410bf2d)(Type, {
|
|
1401
|
-
...rest,
|
|
1402
|
-
children: children,
|
|
1403
|
-
className: classNameFromProps,
|
|
1404
|
-
style: {
|
|
1405
|
-
...style,
|
|
1406
|
-
...styleFromProps
|
|
1407
|
-
},
|
|
1408
|
-
// CSS selectors
|
|
1409
|
-
"data-panel-group": "",
|
|
1410
|
-
"data-panel-group-direction": direction,
|
|
1411
|
-
"data-panel-group-id": groupId
|
|
1412
|
-
}));
|
|
1413
|
-
}
|
|
1414
|
-
const $3daa5d4c086ea816$export$1d05749f6f573bb = (0, $ef07efbe5fa7d87e$export$257a8862b851cb5b)((props, ref)=>(0, $ef07efbe5fa7d87e$export$c8a8987d4410bf2d)($3daa5d4c086ea816$var$PanelGroupWithForwardedRef, {
|
|
1415
|
-
...props,
|
|
1416
|
-
forwardedRef: ref
|
|
1417
|
-
}));
|
|
1418
|
-
$3daa5d4c086ea816$var$PanelGroupWithForwardedRef.displayName = "PanelGroup";
|
|
1419
|
-
$3daa5d4c086ea816$export$1d05749f6f573bb.displayName = "forwardRef(PanelGroup)";
|
|
1420
|
-
function $3daa5d4c086ea816$var$findPanelDataIndex(panelDataArray, panelData) {
|
|
1421
|
-
return panelDataArray.findIndex((prevPanelData)=>prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1593
|
+
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1594
|
+
}
|
|
1595
|
+
}, 0);
|
|
1596
|
+
}, []);
|
|
1597
|
+
const context = useMemo(() => ({
|
|
1598
|
+
collapsePanel,
|
|
1599
|
+
direction,
|
|
1600
|
+
dragState,
|
|
1601
|
+
expandPanel,
|
|
1602
|
+
getPanelSize,
|
|
1603
|
+
getPanelStyle,
|
|
1604
|
+
groupId,
|
|
1605
|
+
isPanelCollapsed,
|
|
1606
|
+
isPanelExpanded,
|
|
1607
|
+
registerPanel,
|
|
1608
|
+
registerResizeHandle,
|
|
1609
|
+
resizePanel,
|
|
1610
|
+
startDragging,
|
|
1611
|
+
stopDragging,
|
|
1612
|
+
unregisterPanel
|
|
1613
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1614
|
+
const style = {
|
|
1615
|
+
display: "flex",
|
|
1616
|
+
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
1617
|
+
height: "100%",
|
|
1618
|
+
overflow: "hidden",
|
|
1619
|
+
width: "100%"
|
|
1620
|
+
};
|
|
1621
|
+
return createElement(PanelGroupContext.Provider, {
|
|
1622
|
+
value: context
|
|
1623
|
+
}, createElement(Type, {
|
|
1624
|
+
...rest,
|
|
1625
|
+
children,
|
|
1626
|
+
className: classNameFromProps,
|
|
1627
|
+
style: {
|
|
1628
|
+
...style,
|
|
1629
|
+
...styleFromProps
|
|
1630
|
+
},
|
|
1631
|
+
// CSS selectors
|
|
1632
|
+
"data-panel-group": "",
|
|
1633
|
+
"data-panel-group-direction": direction,
|
|
1634
|
+
"data-panel-group-id": groupId
|
|
1635
|
+
}));
|
|
1422
1636
|
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
] : [
|
|
1432
|
-
panelIndex,
|
|
1433
|
-
panelIndex + 1
|
|
1434
|
-
];
|
|
1435
|
-
const panelSize = layout[panelIndex];
|
|
1436
|
-
return {
|
|
1437
|
-
...panelConstraints,
|
|
1438
|
-
panelSize: panelSize,
|
|
1439
|
-
pivotIndices: pivotIndices
|
|
1440
|
-
};
|
|
1637
|
+
const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
|
|
1638
|
+
...props,
|
|
1639
|
+
forwardedRef: ref
|
|
1640
|
+
}));
|
|
1641
|
+
PanelGroupWithForwardedRef.displayName = "PanelGroup";
|
|
1642
|
+
PanelGroup.displayName = "forwardRef(PanelGroup)";
|
|
1643
|
+
function findPanelDataIndex(panelDataArray, panelData) {
|
|
1644
|
+
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1441
1645
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
const handleElement = (0, $99b0d18e36332b26$export$4c5229c874a62620)(handleId);
|
|
1455
|
-
if (handleElement == null) return;
|
|
1456
|
-
const onKeyDown = (event)=>{
|
|
1457
|
-
if (event.defaultPrevented) return;
|
|
1458
|
-
switch(event.key){
|
|
1459
|
-
case "ArrowDown":
|
|
1460
|
-
case "ArrowLeft":
|
|
1461
|
-
case "ArrowRight":
|
|
1462
|
-
case "ArrowUp":
|
|
1463
|
-
case "End":
|
|
1464
|
-
case "Home":
|
|
1465
|
-
event.preventDefault();
|
|
1466
|
-
resizeHandler(event);
|
|
1467
|
-
break;
|
|
1468
|
-
case "F6":
|
|
1469
|
-
{
|
|
1470
|
-
event.preventDefault();
|
|
1471
|
-
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1472
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(groupId);
|
|
1473
|
-
const handles = (0, $9196ba7c0d09e3f3$export$63eb605e437b214f)(groupId);
|
|
1474
|
-
const index = (0, $a144d12e0d2017d1$export$4c92fedbbc2381ca)(groupId, handleId);
|
|
1475
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(index !== null);
|
|
1476
|
-
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1477
|
-
const nextHandle = handles[nextIndex];
|
|
1478
|
-
nextHandle.focus();
|
|
1479
|
-
break;
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1483
|
-
handleElement.addEventListener("keydown", onKeyDown);
|
|
1484
|
-
return ()=>{
|
|
1485
|
-
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1486
|
-
};
|
|
1487
|
-
}, [
|
|
1488
|
-
disabled,
|
|
1489
|
-
handleId,
|
|
1490
|
-
resizeHandler
|
|
1491
|
-
]);
|
|
1646
|
+
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1647
|
+
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1648
|
+
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1649
|
+
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1650
|
+
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1651
|
+
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1652
|
+
const panelSize = layout[panelIndex];
|
|
1653
|
+
return {
|
|
1654
|
+
...panelConstraints,
|
|
1655
|
+
panelSize,
|
|
1656
|
+
pivotIndices
|
|
1657
|
+
};
|
|
1492
1658
|
}
|
|
1493
1659
|
|
|
1660
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/
|
|
1494
1661
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
const { onDragging: onDragging } = callbacksRef.current;
|
|
1522
|
-
if (onDragging) onDragging(false);
|
|
1523
|
-
}, [
|
|
1524
|
-
stopDragging
|
|
1525
|
-
]);
|
|
1526
|
-
(0, $ef07efbe5fa7d87e$export$6d9c69b0de29b591)(()=>{
|
|
1527
|
-
if (disabled) setResizeHandler(null);
|
|
1528
|
-
else {
|
|
1529
|
-
const resizeHandler = registerResizeHandle(resizeHandleId);
|
|
1530
|
-
setResizeHandler(()=>resizeHandler);
|
|
1531
|
-
}
|
|
1532
|
-
}, [
|
|
1533
|
-
disabled,
|
|
1534
|
-
resizeHandleId,
|
|
1535
|
-
registerResizeHandle
|
|
1536
|
-
]);
|
|
1537
|
-
(0, $ef07efbe5fa7d87e$export$6d9c69b0de29b591)(()=>{
|
|
1538
|
-
if (disabled || resizeHandler == null || !isDragging) return;
|
|
1539
|
-
const onMove = (event)=>{
|
|
1540
|
-
resizeHandler(event);
|
|
1541
|
-
};
|
|
1542
|
-
const onMouseLeave = (event)=>{
|
|
1662
|
+
function useWindowSplitterResizeHandlerBehavior({
|
|
1663
|
+
disabled,
|
|
1664
|
+
handleId,
|
|
1665
|
+
resizeHandler
|
|
1666
|
+
}) {
|
|
1667
|
+
useEffect(() => {
|
|
1668
|
+
if (disabled || resizeHandler == null) {
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
const handleElement = getResizeHandleElement(handleId);
|
|
1672
|
+
if (handleElement == null) {
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
const onKeyDown = event => {
|
|
1676
|
+
if (event.defaultPrevented) {
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
switch (event.key) {
|
|
1680
|
+
case "ArrowDown":
|
|
1681
|
+
case "ArrowLeft":
|
|
1682
|
+
case "ArrowRight":
|
|
1683
|
+
case "ArrowUp":
|
|
1684
|
+
case "End":
|
|
1685
|
+
case "Home":
|
|
1686
|
+
{
|
|
1687
|
+
event.preventDefault();
|
|
1543
1688
|
resizeHandler(event);
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
window.removeEventListener("touchend", stopDraggingAndBlur);
|
|
1561
|
-
};
|
|
1562
|
-
}, [
|
|
1563
|
-
direction,
|
|
1564
|
-
disabled,
|
|
1565
|
-
isDragging,
|
|
1566
|
-
resizeHandler,
|
|
1567
|
-
stopDraggingAndBlur
|
|
1568
|
-
]);
|
|
1569
|
-
(0, $4a90471e7083b52f$export$33b0bea6ac3ffb03)({
|
|
1570
|
-
disabled: disabled,
|
|
1571
|
-
handleId: resizeHandleId,
|
|
1572
|
-
resizeHandler: resizeHandler
|
|
1573
|
-
});
|
|
1574
|
-
const style = {
|
|
1575
|
-
cursor: (0, $8d9d88bebf1a8ace$export$fa35f3322c52262f)(direction),
|
|
1576
|
-
touchAction: "none",
|
|
1577
|
-
userSelect: "none"
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
case "F6":
|
|
1692
|
+
{
|
|
1693
|
+
event.preventDefault();
|
|
1694
|
+
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1695
|
+
assert(groupId);
|
|
1696
|
+
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1697
|
+
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1698
|
+
assert(index !== null);
|
|
1699
|
+
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1700
|
+
const nextHandle = handles[nextIndex];
|
|
1701
|
+
nextHandle.focus();
|
|
1702
|
+
break;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1578
1705
|
};
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
onFocus: ()=>setIsFocused(true),
|
|
1585
|
-
onMouseDown: (event)=>{
|
|
1586
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1587
|
-
const callbacks = callbacksRef.current;
|
|
1588
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(callbacks);
|
|
1589
|
-
const { onDragging: onDragging } = callbacks;
|
|
1590
|
-
if (onDragging) onDragging(true);
|
|
1591
|
-
},
|
|
1592
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1593
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1594
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1595
|
-
onTouchStart: (event)=>{
|
|
1596
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1597
|
-
const callbacks = callbacksRef.current;
|
|
1598
|
-
(0, $5f33910cd46e8ae7$export$a7a9523472993e97)(callbacks);
|
|
1599
|
-
const { onDragging: onDragging } = callbacks;
|
|
1600
|
-
if (onDragging) onDragging(true);
|
|
1601
|
-
},
|
|
1602
|
-
ref: divElementRef,
|
|
1603
|
-
role: "separator",
|
|
1604
|
-
style: {
|
|
1605
|
-
...style,
|
|
1606
|
-
...styleFromProps
|
|
1607
|
-
},
|
|
1608
|
-
tabIndex: tabIndex,
|
|
1609
|
-
// CSS selectors
|
|
1610
|
-
"data-panel-group-direction": direction,
|
|
1611
|
-
"data-panel-group-id": groupId,
|
|
1612
|
-
"data-resize-handle": "",
|
|
1613
|
-
"data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
1614
|
-
"data-panel-resize-handle-enabled": !disabled,
|
|
1615
|
-
"data-panel-resize-handle-id": resizeHandleId
|
|
1616
|
-
});
|
|
1706
|
+
handleElement.addEventListener("keydown", onKeyDown);
|
|
1707
|
+
return () => {
|
|
1708
|
+
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1709
|
+
};
|
|
1710
|
+
}, [disabled, handleId, resizeHandler]);
|
|
1617
1711
|
}
|
|
1618
|
-
$971f2c37f9d2b98e$export$8829ecf6b6b15484.displayName = "PanelResizeHandle";
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
1712
|
|
|
1713
|
+
function PanelResizeHandle({
|
|
1714
|
+
children = null,
|
|
1715
|
+
className: classNameFromProps = "",
|
|
1716
|
+
disabled = false,
|
|
1717
|
+
id: idFromProps,
|
|
1718
|
+
onDragging,
|
|
1719
|
+
style: styleFromProps = {},
|
|
1720
|
+
tabIndex = 0,
|
|
1721
|
+
tagName: Type = "div",
|
|
1722
|
+
...rest
|
|
1723
|
+
}) {
|
|
1724
|
+
const divElementRef = useRef(null);
|
|
1725
|
+
|
|
1726
|
+
// Use a ref to guard against users passing inline props
|
|
1727
|
+
const callbacksRef = useRef({
|
|
1728
|
+
onDragging
|
|
1729
|
+
});
|
|
1730
|
+
useEffect(() => {
|
|
1731
|
+
callbacksRef.current.onDragging = onDragging;
|
|
1732
|
+
});
|
|
1733
|
+
const panelGroupContext = useContext(PanelGroupContext);
|
|
1734
|
+
if (panelGroupContext === null) {
|
|
1735
|
+
throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
|
|
1736
|
+
}
|
|
1737
|
+
const {
|
|
1738
|
+
direction,
|
|
1739
|
+
dragState,
|
|
1740
|
+
groupId,
|
|
1741
|
+
registerResizeHandle,
|
|
1742
|
+
startDragging,
|
|
1743
|
+
stopDragging
|
|
1744
|
+
} = panelGroupContext;
|
|
1745
|
+
const resizeHandleId = useUniqueId(idFromProps);
|
|
1746
|
+
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
1747
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
1748
|
+
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1749
|
+
const stopDraggingAndBlur = useCallback(() => {
|
|
1750
|
+
// Clicking on the drag handle shouldn't leave it focused;
|
|
1751
|
+
// That would cause the PanelGroup to think it was still active.
|
|
1752
|
+
const divElement = divElementRef.current;
|
|
1753
|
+
assert(divElement);
|
|
1754
|
+
divElement.blur();
|
|
1755
|
+
stopDragging();
|
|
1756
|
+
const {
|
|
1757
|
+
onDragging
|
|
1758
|
+
} = callbacksRef.current;
|
|
1759
|
+
if (onDragging) {
|
|
1760
|
+
onDragging(false);
|
|
1761
|
+
}
|
|
1762
|
+
}, [stopDragging]);
|
|
1763
|
+
useEffect(() => {
|
|
1764
|
+
if (disabled) {
|
|
1765
|
+
setResizeHandler(null);
|
|
1766
|
+
} else {
|
|
1767
|
+
const resizeHandler = registerResizeHandle(resizeHandleId);
|
|
1768
|
+
setResizeHandler(() => resizeHandler);
|
|
1769
|
+
}
|
|
1770
|
+
}, [disabled, resizeHandleId, registerResizeHandle]);
|
|
1771
|
+
useEffect(() => {
|
|
1772
|
+
if (disabled || resizeHandler == null || !isDragging) {
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
const onMove = event => {
|
|
1776
|
+
resizeHandler(event);
|
|
1777
|
+
};
|
|
1778
|
+
const onMouseLeave = event => {
|
|
1779
|
+
resizeHandler(event);
|
|
1780
|
+
};
|
|
1781
|
+
const divElement = divElementRef.current;
|
|
1782
|
+
assert(divElement);
|
|
1783
|
+
const targetDocument = divElement.ownerDocument;
|
|
1784
|
+
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1785
|
+
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1786
|
+
targetDocument.body.addEventListener("touchmove", onMove);
|
|
1787
|
+
targetDocument.body.addEventListener("mouseleave", onMouseLeave);
|
|
1788
|
+
window.addEventListener("mouseup", stopDraggingAndBlur);
|
|
1789
|
+
window.addEventListener("touchend", stopDraggingAndBlur);
|
|
1790
|
+
return () => {
|
|
1791
|
+
targetDocument.body.removeEventListener("contextmenu", stopDraggingAndBlur);
|
|
1792
|
+
targetDocument.body.removeEventListener("mousemove", onMove);
|
|
1793
|
+
targetDocument.body.removeEventListener("touchmove", onMove);
|
|
1794
|
+
targetDocument.body.removeEventListener("mouseleave", onMouseLeave);
|
|
1795
|
+
window.removeEventListener("mouseup", stopDraggingAndBlur);
|
|
1796
|
+
window.removeEventListener("touchend", stopDraggingAndBlur);
|
|
1797
|
+
};
|
|
1798
|
+
}, [direction, disabled, isDragging, resizeHandler, stopDraggingAndBlur]);
|
|
1799
|
+
useWindowSplitterResizeHandlerBehavior({
|
|
1800
|
+
disabled,
|
|
1801
|
+
handleId: resizeHandleId,
|
|
1802
|
+
resizeHandler
|
|
1803
|
+
});
|
|
1804
|
+
const style = {
|
|
1805
|
+
cursor: getCursorStyle(direction),
|
|
1806
|
+
touchAction: "none",
|
|
1807
|
+
userSelect: "none"
|
|
1808
|
+
};
|
|
1809
|
+
return createElement(Type, {
|
|
1810
|
+
...rest,
|
|
1811
|
+
children,
|
|
1812
|
+
className: classNameFromProps,
|
|
1813
|
+
onBlur: () => setIsFocused(false),
|
|
1814
|
+
onFocus: () => setIsFocused(true),
|
|
1815
|
+
onMouseDown: event => {
|
|
1816
|
+
startDragging(resizeHandleId, event.nativeEvent);
|
|
1817
|
+
const callbacks = callbacksRef.current;
|
|
1818
|
+
assert(callbacks);
|
|
1819
|
+
const {
|
|
1820
|
+
onDragging
|
|
1821
|
+
} = callbacks;
|
|
1822
|
+
if (onDragging) {
|
|
1823
|
+
onDragging(true);
|
|
1824
|
+
}
|
|
1825
|
+
},
|
|
1826
|
+
onMouseUp: stopDraggingAndBlur,
|
|
1827
|
+
onTouchCancel: stopDraggingAndBlur,
|
|
1828
|
+
onTouchEnd: stopDraggingAndBlur,
|
|
1829
|
+
onTouchStart: event => {
|
|
1830
|
+
startDragging(resizeHandleId, event.nativeEvent);
|
|
1831
|
+
const callbacks = callbacksRef.current;
|
|
1832
|
+
assert(callbacks);
|
|
1833
|
+
const {
|
|
1834
|
+
onDragging
|
|
1835
|
+
} = callbacks;
|
|
1836
|
+
if (onDragging) {
|
|
1837
|
+
onDragging(true);
|
|
1838
|
+
}
|
|
1839
|
+
},
|
|
1840
|
+
ref: divElementRef,
|
|
1841
|
+
role: "separator",
|
|
1842
|
+
style: {
|
|
1843
|
+
...style,
|
|
1844
|
+
...styleFromProps
|
|
1845
|
+
},
|
|
1846
|
+
tabIndex,
|
|
1847
|
+
// CSS selectors
|
|
1848
|
+
"data-panel-group-direction": direction,
|
|
1849
|
+
"data-panel-group-id": groupId,
|
|
1850
|
+
"data-resize-handle": "",
|
|
1851
|
+
"data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
1852
|
+
"data-panel-resize-handle-enabled": !disabled,
|
|
1853
|
+
"data-panel-resize-handle-id": resizeHandleId
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1623
1857
|
|
|
1624
|
-
export {
|
|
1625
|
-
//# sourceMappingURL=react-resizable-panels.esm.js.map
|
|
1858
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert };
|