react-resizable-panels 0.0.5 → 0.0.7
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/CHANGELOG.md +4 -0
- package/README.md +13 -9
- package/dist/react-resizable-panels.d.ts +5 -3
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +114 -45
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +114 -46
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/PanelContexts.ts +8 -1
- package/src/PanelGroup.tsx +46 -32
- package/src/PanelResizeHandle.tsx +35 -26
- package/src/hooks/useUniqueId.ts +12 -0
- package/src/index.ts +2 -1
- package/src/utils/serialization.ts +49 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.7
|
|
4
|
+
* Add `PanelContext` with `activeHandleId` property identifying the resize handle currently being dragged (or `null`). This enables more customized UI/UX when resizing is in progress.
|
|
5
|
+
## 0.0.6
|
|
6
|
+
* [#5](https://github.com/bvaughn/react-resizable-panels/issues/5): Removed `panelBefore` and `panelAfter` props from `PanelResizeHandle`. `PanelGroup` now infers this based on position within the group.
|
|
3
7
|
## 0.0.5
|
|
4
8
|
* TypeScript props type fix
|
|
5
9
|
|
package/README.md
CHANGED
|
@@ -4,16 +4,16 @@ React components for resizable panel groups/layouts
|
|
|
4
4
|
```jsx
|
|
5
5
|
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
6
6
|
|
|
7
|
-
<PanelGroup autoSaveId="
|
|
8
|
-
<Panel defaultSize={0.3} id="
|
|
7
|
+
<PanelGroup autoSaveId="example" direction="horizontal">
|
|
8
|
+
<Panel defaultSize={0.3} id="left">
|
|
9
9
|
<SourcesExplorer />
|
|
10
10
|
</Panel>
|
|
11
|
-
<Panel defaultSize={0.5} id="
|
|
12
|
-
<PanelResizeHandle
|
|
11
|
+
<Panel defaultSize={0.5} id="middle">
|
|
12
|
+
<PanelResizeHandle />
|
|
13
13
|
<SourceViewer />
|
|
14
|
-
<PanelResizeHandle
|
|
14
|
+
<PanelResizeHandle />
|
|
15
15
|
</Panel>
|
|
16
|
-
<Panel defaultSize={0.2} id="
|
|
16
|
+
<Panel defaultSize={0.2} id="right">
|
|
17
17
|
<Console />
|
|
18
18
|
</Panel>
|
|
19
19
|
</PanelGroup>
|
|
@@ -25,7 +25,7 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
|
25
25
|
| prop | type | description
|
|
26
26
|
| :----------- | :-------------------------- | :---
|
|
27
27
|
| `autoSaveId` | `?string` | Unique id used to auto-save group arrangement via `localStorage`
|
|
28
|
-
| `children` | `ReactNode
|
|
28
|
+
| `children` | `ReactNode` | Arbitrary React element(s)
|
|
29
29
|
| `className` | `?string` | Class name
|
|
30
30
|
| `direction` | `"horizontal" \| "vertical"` | Group orientation
|
|
31
31
|
| `height` | `number` | Height of group (in pixels)
|
|
@@ -47,5 +47,9 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
|
47
47
|
| `children` | `?ReactNode` | Custom drag UI; can be any arbitrary React element(s)
|
|
48
48
|
| `className` | `?string` | Class name
|
|
49
49
|
| `disabled` | `?boolean` | Disable drag handle
|
|
50
|
-
| `
|
|
51
|
-
|
|
50
|
+
| `id` | `?string` | Optional resize handle id (must be unique within the current group)
|
|
51
|
+
|
|
52
|
+
### `PanelContext`
|
|
53
|
+
| prop | type | description
|
|
54
|
+
| :----------- | :------------------- | :---
|
|
55
|
+
| `activeHandleId` | `string \| null` | Resize handle currently being dragged (or `null`)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
type Direction = "horizontal" | "vertical";
|
|
3
|
+
export const PanelContext: import("react").Context<{
|
|
4
|
+
activeHandleId: string | null;
|
|
5
|
+
}>;
|
|
3
6
|
export function Panel({ children, className, defaultSize, id, minSize, order, }: {
|
|
4
7
|
children?: ReactNode;
|
|
5
8
|
className?: string;
|
|
@@ -17,12 +20,11 @@ type Props = {
|
|
|
17
20
|
width: number;
|
|
18
21
|
};
|
|
19
22
|
export function PanelGroup({ autoSaveId, children, className, direction, height, width, }: Props): JSX.Element;
|
|
20
|
-
export function PanelResizeHandle({ children, className, disabled,
|
|
23
|
+
export function PanelResizeHandle({ children, className, disabled, id: idProp, }: {
|
|
21
24
|
children?: ReactNode;
|
|
22
25
|
className?: string;
|
|
23
26
|
disabled?: boolean;
|
|
24
|
-
|
|
25
|
-
panelBefore: string;
|
|
27
|
+
id?: string | null;
|
|
26
28
|
}): JSX.Element;
|
|
27
29
|
|
|
28
30
|
//# sourceMappingURL=react-resizable-panels.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;
|
|
1
|
+
{"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACChB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eAwCA;AE9CD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,KAAK,eAqNP;ACpPD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,MAAa,GAClB,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,eA6EA","sources":["packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.tsx","packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map","sourceRoot":"../../../"}
|
|
@@ -6,11 +6,13 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
$parcel$export(module.exports, "Panel", () => $6d390b7f2e6b107f$export$2e2bcd8739ae039);
|
|
9
|
+
$parcel$export(module.exports, "PanelContext", () => $3251d17c1c3bce6c$export$f34532ac99e32150);
|
|
9
10
|
$parcel$export(module.exports, "PanelGroup", () => $d428eaeef644efb2$export$2e2bcd8739ae039);
|
|
10
11
|
$parcel$export(module.exports, "PanelResizeHandle", () => $d578a49f00f1bdeb$export$2e2bcd8739ae039);
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
|
|
15
|
+
const $3251d17c1c3bce6c$export$f34532ac99e32150 = (0, $b2QPe$react.createContext)(null);
|
|
14
16
|
const $3251d17c1c3bce6c$export$7d8c6d083caec74a = (0, $b2QPe$react.createContext)(null);
|
|
15
17
|
|
|
16
18
|
|
|
@@ -57,8 +59,46 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
|
|
62
|
+
|
|
63
|
+
let $6d548a0d130941e3$var$counter = 0;
|
|
64
|
+
function $6d548a0d130941e3$export$2e2bcd8739ae039(id = null) {
|
|
65
|
+
const idRef = (0, $b2QPe$react.useRef)(id);
|
|
66
|
+
if (idRef.current === null) idRef.current = "" + $6d548a0d130941e3$var$counter++;
|
|
67
|
+
return idRef.current;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
function $e045b0dd313f33c7$var$loadSerializedPanelGroupState(autoSaveId) {
|
|
73
|
+
try {
|
|
74
|
+
const serialized = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
|
|
75
|
+
if (serialized) {
|
|
76
|
+
const parsed = JSON.parse(serialized);
|
|
77
|
+
if (typeof parsed === "object" && parsed != null) return parsed;
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function $e045b0dd313f33c7$export$9c80c6617f0386da(autoSaveId, panelIds) {
|
|
83
|
+
const state = $e045b0dd313f33c7$var$loadSerializedPanelGroupState(autoSaveId);
|
|
84
|
+
if (state) return state[panelIds.join(",")] ?? null;
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
function $e045b0dd313f33c7$export$af183b313c61be4f(autoSaveId, panelIds, sizes) {
|
|
88
|
+
const state = $e045b0dd313f33c7$var$loadSerializedPanelGroupState(autoSaveId) || {};
|
|
89
|
+
state[panelIds.join(",")] = sizes;
|
|
90
|
+
try {
|
|
91
|
+
localStorage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(state));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
60
98
|
const $d428eaeef644efb2$var$PRECISION = 5;
|
|
61
99
|
function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
|
|
100
|
+
const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)();
|
|
101
|
+
const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
|
|
62
102
|
const [panels, setPanels] = (0, $b2QPe$react.useState)(new Map());
|
|
63
103
|
// 0-1 values representing the relative size of each panel.
|
|
64
104
|
const [sizes, setSizes] = (0, $b2QPe$react.useState)([]);
|
|
@@ -88,10 +128,10 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
88
128
|
// If this panel has been configured to persist sizing information,
|
|
89
129
|
// default size should be restored from local storage if possible.
|
|
90
130
|
let defaultSizes = undefined;
|
|
91
|
-
if (autoSaveId)
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
}
|
|
131
|
+
if (autoSaveId) {
|
|
132
|
+
const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
133
|
+
defaultSizes = (0, $e045b0dd313f33c7$export$9c80c6617f0386da)(autoSaveId, panelIds);
|
|
134
|
+
}
|
|
95
135
|
if (defaultSizes != null) setSizes(defaultSizes);
|
|
96
136
|
else {
|
|
97
137
|
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
@@ -105,10 +145,11 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
105
145
|
panels
|
|
106
146
|
]);
|
|
107
147
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
148
|
+
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
108
149
|
if (autoSaveId) {
|
|
109
150
|
if (sizes.length === 0 || sizes.length !== panels.size) return;
|
|
110
|
-
|
|
111
|
-
|
|
151
|
+
const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
152
|
+
(0, $e045b0dd313f33c7$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
|
|
112
153
|
}
|
|
113
154
|
}, [
|
|
114
155
|
autoSaveId,
|
|
@@ -147,18 +188,27 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
147
188
|
return nextPanels;
|
|
148
189
|
});
|
|
149
190
|
}, []);
|
|
150
|
-
const registerResizeHandle = (0, $b2QPe$react.useCallback)((
|
|
151
|
-
|
|
191
|
+
const registerResizeHandle = (0, $b2QPe$react.useCallback)((id)=>{
|
|
192
|
+
const resizeHandler = (event)=>{
|
|
152
193
|
event.preventDefault();
|
|
153
194
|
const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
|
|
195
|
+
const handle = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
196
|
+
const handles = Array.from(document.querySelectorAll(`[data-panel-group-id="${groupId}"]`));
|
|
197
|
+
const index = handles.indexOf(handle);
|
|
198
|
+
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
199
|
+
const idBefore = panelsArray[index]?.id ?? null;
|
|
200
|
+
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
201
|
+
if (idBefore == null || idAfter == null) return;
|
|
154
202
|
const isHorizontal = direction === "horizontal";
|
|
155
203
|
const movement = isHorizontal ? event.movementX : event.movementY;
|
|
156
204
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
157
205
|
const nextSizes = $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
|
|
158
206
|
if (prevSizes !== nextSizes) setSizes(nextSizes);
|
|
159
207
|
};
|
|
160
|
-
|
|
161
|
-
}, [
|
|
208
|
+
return resizeHandler;
|
|
209
|
+
}, [
|
|
210
|
+
groupId
|
|
211
|
+
]);
|
|
162
212
|
const unregisterPanel = (0, $b2QPe$react.useCallback)((id)=>{
|
|
163
213
|
setPanels((prevPanels)=>{
|
|
164
214
|
if (!prevPanels.has(id)) return prevPanels;
|
|
@@ -167,32 +217,48 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
167
217
|
return nextPanels;
|
|
168
218
|
});
|
|
169
219
|
}, []);
|
|
170
|
-
const
|
|
220
|
+
const panelGroupContext = (0, $b2QPe$react.useMemo)(()=>({
|
|
171
221
|
direction: direction,
|
|
172
222
|
getPanelStyle: getPanelStyle,
|
|
223
|
+
groupId: groupId,
|
|
173
224
|
registerPanel: registerPanel,
|
|
174
225
|
registerResizeHandle: registerResizeHandle,
|
|
226
|
+
startDragging: (id)=>setActiveHandleId(id),
|
|
227
|
+
stopDragging: ()=>setActiveHandleId(null),
|
|
175
228
|
unregisterPanel: unregisterPanel
|
|
176
229
|
}), [
|
|
177
230
|
direction,
|
|
178
231
|
getPanelStyle,
|
|
232
|
+
groupId,
|
|
179
233
|
registerPanel,
|
|
180
234
|
registerResizeHandle,
|
|
181
235
|
unregisterPanel
|
|
182
236
|
]);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
237
|
+
const panelContext = (0, $b2QPe$react.useMemo)(()=>({
|
|
238
|
+
activeHandleId: activeHandleId
|
|
239
|
+
}), [
|
|
240
|
+
activeHandleId
|
|
241
|
+
]);
|
|
242
|
+
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)((0, $3251d17c1c3bce6c$export$f34532ac99e32150).Provider, {
|
|
243
|
+
value: panelContext,
|
|
244
|
+
children: /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
|
|
245
|
+
value: panelGroupContext,
|
|
246
|
+
children: /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
247
|
+
className: className,
|
|
248
|
+
children: children
|
|
249
|
+
}, void 0, false, {
|
|
250
|
+
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
251
|
+
lineNumber: 247,
|
|
252
|
+
columnNumber: 9
|
|
253
|
+
}, this)
|
|
188
254
|
}, void 0, false, {
|
|
189
255
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
190
|
-
lineNumber:
|
|
256
|
+
lineNumber: 246,
|
|
191
257
|
columnNumber: 7
|
|
192
258
|
}, this)
|
|
193
259
|
}, void 0, false, {
|
|
194
260
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
195
|
-
lineNumber:
|
|
261
|
+
lineNumber: 245,
|
|
196
262
|
columnNumber: 5
|
|
197
263
|
}, this);
|
|
198
264
|
}
|
|
@@ -234,11 +300,6 @@ function $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, p
|
|
|
234
300
|
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
235
301
|
return nextSizes;
|
|
236
302
|
}
|
|
237
|
-
function $d428eaeef644efb2$var$createLocalStorageKey(autoSaveId, panels) {
|
|
238
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
239
|
-
const panelIds = panelsArray.map((panel)=>panel.id);
|
|
240
|
-
return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
|
|
241
|
-
}
|
|
242
303
|
function $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width) {
|
|
243
304
|
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
244
305
|
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
@@ -267,59 +328,67 @@ function $d428eaeef644efb2$var$panelsMapToSortedArray(panels) {
|
|
|
267
328
|
|
|
268
329
|
|
|
269
330
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
331
|
+
|
|
332
|
+
function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idProp = null }) {
|
|
333
|
+
const panelContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$f34532ac99e32150));
|
|
334
|
+
const panelGroupContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
|
|
335
|
+
if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
|
|
336
|
+
const id = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idProp);
|
|
337
|
+
const { activeHandleId: activeHandleId } = panelContext;
|
|
338
|
+
const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
|
|
339
|
+
const isDragging = activeHandleId === id;
|
|
274
340
|
const [resizeHandler, setResizeHandler] = (0, $b2QPe$react.useState)(null);
|
|
275
|
-
const [isDragging, setIsDragging] = (0, $b2QPe$react.useState)(false);
|
|
276
341
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
277
342
|
if (disabled) setResizeHandler(null);
|
|
278
|
-
else
|
|
343
|
+
else {
|
|
344
|
+
const resizeHandler = registerResizeHandle(id);
|
|
345
|
+
setResizeHandler(()=>resizeHandler);
|
|
346
|
+
}
|
|
279
347
|
}, [
|
|
280
348
|
disabled,
|
|
281
|
-
|
|
282
|
-
|
|
349
|
+
groupId,
|
|
350
|
+
id,
|
|
283
351
|
registerResizeHandle
|
|
284
352
|
]);
|
|
285
353
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
286
354
|
if (disabled || resizeHandler == null || !isDragging) return;
|
|
287
355
|
document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
|
|
288
|
-
const onMouseLeave = (_)=>{
|
|
289
|
-
setIsDragging(false);
|
|
290
|
-
};
|
|
291
356
|
const onMouseMove = (event)=>{
|
|
292
357
|
resizeHandler(event);
|
|
293
358
|
};
|
|
294
|
-
|
|
295
|
-
setIsDragging(false);
|
|
296
|
-
};
|
|
297
|
-
document.body.addEventListener("mouseleave", onMouseLeave);
|
|
359
|
+
document.body.addEventListener("mouseleave", stopDragging);
|
|
298
360
|
document.body.addEventListener("mousemove", onMouseMove);
|
|
299
|
-
document.body.addEventListener("
|
|
361
|
+
document.body.addEventListener("touchmove", onMouseMove);
|
|
362
|
+
document.body.addEventListener("mouseup", stopDragging);
|
|
300
363
|
return ()=>{
|
|
301
364
|
document.body.style.cursor = "";
|
|
302
|
-
document.body.removeEventListener("mouseleave",
|
|
365
|
+
document.body.removeEventListener("mouseleave", stopDragging);
|
|
303
366
|
document.body.removeEventListener("mousemove", onMouseMove);
|
|
304
|
-
document.body.removeEventListener("
|
|
367
|
+
document.body.removeEventListener("touchmove", onMouseMove);
|
|
368
|
+
document.body.removeEventListener("mouseup", stopDragging);
|
|
305
369
|
};
|
|
306
370
|
}, [
|
|
307
371
|
direction,
|
|
308
372
|
disabled,
|
|
309
373
|
isDragging,
|
|
310
|
-
resizeHandler
|
|
374
|
+
resizeHandler,
|
|
375
|
+
stopDragging
|
|
311
376
|
]);
|
|
312
377
|
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
313
378
|
className: className,
|
|
314
|
-
|
|
315
|
-
|
|
379
|
+
"data-panel-group-id": groupId,
|
|
380
|
+
"data-panel-resize-handle-id": id,
|
|
381
|
+
onMouseDown: ()=>startDragging(id),
|
|
382
|
+
onMouseUp: stopDragging,
|
|
383
|
+
onTouchStart: ()=>startDragging(id),
|
|
384
|
+
onTouchEnd: stopDragging,
|
|
316
385
|
style: {
|
|
317
386
|
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
|
|
318
387
|
},
|
|
319
388
|
children: children
|
|
320
389
|
}, void 0, false, {
|
|
321
390
|
fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
|
|
322
|
-
lineNumber:
|
|
391
|
+
lineNumber: 80,
|
|
323
392
|
columnNumber: 5
|
|
324
393
|
}, this);
|
|
325
394
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,0BAAY,EAMnC,IAAI;;;ADHC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,aACV,QAAQ,IAAI,GAQb,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CAAC,cAAc,EAAE,QAAQ,oCAAoC,EAAE,YAAY,CAAC;QAG9E,cAAc;IAChB,CAAC;IAED,MAAM,iBAAE,cAAa,iBAAE,cAAa,mBAAE,gBAAe,EAAE,GAAG;IAE1D,CAAA,GAAA,4BAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;mBACA;QACF;QAEA,cAAc,IAAI;QAElB,OAAO,IAAM;YACX,gBAAgB;QAClB;IACF,GAAG;QAAC;QAAa;QAAI;QAAS;QAAO;QAAe;KAAgB;IAEpE,MAAM,QAAQ,cAAc;IAE5B,qBACE,sCAAC;QAAI,WAAW;QAAW,OAAO;kBAC/B;;;;;;AAGP;;AD7DA;AGAA;;;AAuBA,MAAM,kCAAY;AAMH,kDAAoB,cACjC,WAAU,YACV,WAAW,IAAI,cACf,YAAY,gBACZ,UAAS,UACT,OAAM,SACN,MAAK,EACC,EAAE;IACR,MAAM,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,qBAAO,EAA0B,IAAI;IA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Y,CAAC,IAAkB;YACnC,cAAc,KAAK;QACrB;QAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc;QAC7C,SAAS,IAAI,CAAC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,sCAAC;QACC,WAAW;QACX,aAAa,IAAM,cAAc,IAAI;QACrC,WAAW,IAAM,cAAc,KAAK;QACpC,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;;;;;AAGP;;","sources":["packages/react-resizable-panels/src/index.ts","packages/react-resizable-panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n order = null,\n}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\n order?: number | null;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `Panel components must be rendered within a PanelGroup container`\n );\n }\n\n if (minSize > defaultSize) {\n console.error(\n `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`\n );\n\n defaultSize = minSize;\n }\n\n const { getPanelStyle, registerPanel, unregisterPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n order,\n };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);\n\n const style = getPanelStyle(id);\n\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n}\n","import { CSSProperties, createContext } from \"react\";\n\nimport { PanelData, ResizeHandler } from \"./types\";\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: string) => CSSProperties;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (idBefore: string, idAfter: string) => ResizeHandler;\n unregisterPanel: (id: string) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, PanelData } from \"./types\";\n\ntype Props = {\n autoSaveId?: string;\n children?: ReactNode[];\n className?: string;\n direction: Direction;\n height: number;\n width: number;\n};\n\nconst PRECISION = 5;\n\n// TODO [panels]\n// Within an active drag, remember original positions to refine more easily on expand.\n// Look at what the Chrome devtools Sources does.\n\nexport default function PanelGroup({\n autoSaveId,\n children = null,\n className = \"\",\n direction,\n height,\n width,\n}: Props) {\n const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());\n\n // 0-1 values representing the relative size of each panel.\n const [sizes, setSizes] = useState<number[]>([]);\n\n // Store committed values to avoid unnecessarily re-running memoization/effects functions.\n const committedValuesRef = useRef<{\n direction: Direction;\n height: number;\n panels: Map<string, PanelData>;\n sizes: number[];\n width: number;\n }>({\n direction,\n height,\n panels,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\n committedValuesRef.current.panels = panels;\n committedValuesRef.current.sizes = sizes;\n committedValuesRef.current.width = width;\n });\n\n // Once all panels have registered themselves,\n // Compute the initial sizes based on default weights.\n // This assumes that panels register during initial mount (no conditional rendering)!\n useLayoutEffect(() => {\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.size) {\n return;\n }\n\n // TODO [panels]\n // Validate that the total minSize is <= 1.\n\n // If this panel has been configured to persist sizing information,\n // default size should be restored from local storage if possible.\n let defaultSizes: number[] | undefined = undefined;\n if (autoSaveId) {\n try {\n const value = localStorage.getItem(\n createLocalStorageKey(autoSaveId, panels)\n );\n if (value) {\n defaultSizes = JSON.parse(value);\n }\n } catch (error) {}\n }\n\n if (defaultSizes != null) {\n setSizes(defaultSizes);\n } else {\n const panelsArray = panelsMapToSortedArray(panels);\n const totalWeight = panelsArray.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panelsArray.map((panel) => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId, panels]);\n\n useEffect(() => {\n if (autoSaveId) {\n if (sizes.length === 0 || sizes.length !== panels.size) {\n return;\n }\n\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n localStorage.setItem(\n createLocalStorageKey(autoSaveId, panels),\n JSON.stringify(sizes)\n );\n }\n }, [autoSaveId, panels, sizes]);\n\n const getPanelStyle = useCallback(\n (id: string): CSSProperties => {\n const { panels } = committedValuesRef.current;\n\n const offset = getOffset(panels, id, direction, sizes, height, width);\n const size = getSize(panels, id, direction, sizes, height, width);\n\n if (direction === \"horizontal\") {\n return {\n height: \"100%\",\n position: \"absolute\",\n left: offset,\n top: 0,\n width: size,\n };\n } else {\n return {\n height: size,\n position: \"absolute\",\n left: 0,\n top: offset,\n width: \"100%\",\n };\n }\n },\n [direction, height, sizes, width]\n );\n\n const registerPanel = useCallback((id: string, panel: PanelData) => {\n setPanels((prevPanels) => {\n if (prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.set(id, panel);\n\n return nextPanels;\n });\n }, []);\n\n const registerResizeHandle = useCallback(\n (idBefore: string, idAfter: string) => {\n return (event: MouseEvent) => {\n event.preventDefault();\n\n const {\n direction,\n height,\n panels,\n sizes: prevSizes,\n width,\n } = committedValuesRef.current;\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(\n panels,\n idBefore,\n idAfter,\n delta,\n prevSizes\n );\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n\n // TODO [issues/5] Add to Map\n },\n []\n );\n\n const unregisterPanel = useCallback((id: string) => {\n setPanels((prevPanels) => {\n if (!prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.delete(id);\n\n return nextPanels;\n });\n }, []);\n\n const context = useMemo(\n () => ({\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n ]\n );\n\n return (\n <PanelGroupContext.Provider value={context}>\n <div className={className}>{children}</div>\n </PanelGroupContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Map<string, PanelData>,\n idBefore: string,\n idAfter: string,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const nextSizes = prevSizes.concat();\n\n let deltaApplied = 0;\n\n // A resizing panel affects the panels before or after it.\n //\n // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.\n // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.\n //\n // A positive delta means the panel immediately before the resizer should \"expand\".\n // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.\n let pivotId = delta < 0 ? idBefore : idAfter;\n let index = panelsArray.findIndex((panel) => panel.id === pivotId);\n while (true) {\n const panel = panelsArray[index];\n const prevSize = prevSizes[index];\n const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);\n if (prevSize !== nextSize) {\n deltaApplied += prevSize - nextSize;\n\n nextSizes[index] = nextSize;\n\n if (deltaApplied.toPrecision(PRECISION) >= delta.toPrecision(PRECISION)) {\n break;\n }\n }\n\n if (delta < 0) {\n if (--index < 0) {\n break;\n }\n } else {\n if (++index >= panelsArray.length) {\n break;\n }\n }\n }\n\n // If we were unable to resize any of the panels panels, return the previous state.\n // This will essentially bailout and ignore the \"mousemove\" event.\n if (deltaApplied === 0) {\n return prevSizes;\n }\n\n // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.\n pivotId = delta < 0 ? idAfter : idBefore;\n index = panelsArray.findIndex((panel) => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction createLocalStorageKey(\n autoSaveId: string,\n panels: Map<string, PanelData>\n): string {\n const panelsArray = panelsMapToSortedArray(panels);\n const panelIds = panelsArray.map((panel) => panel.id);\n\n return `PanelGroup:sizes:${autoSaveId}${panelIds.join(\"|\")}`;\n}\n\nfunction getOffset(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const panelsArray = panelsMapToSortedArray(panels);\n\n let index = panelsArray.findIndex((panel) => panel.id === id);\n if (index < 0) {\n return 0;\n }\n\n let scaledOffset = 0;\n\n for (index = index - 1; index >= 0; index--) {\n const panel = panelsArray[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.size === 1) {\n return totalSize;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const index = panelsArray.findIndex((panel) => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n return Math.round(size * totalSize);\n}\n\nfunction panelsMapToSortedArray(panels: Map<string, PanelData>): PanelData[] {\n return Array.from(panels.values()).sort((a, b) => a.order - b.order);\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n panelAfter,\n panelBefore,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n panelAfter: string;\n panelBefore: string;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `PanelResizeHandle components must be rendered within a PanelGroup container`\n );\n }\n\n const { direction, registerResizeHandle } = context;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(\n null\n );\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n setResizeHandler(() => registerResizeHandle(panelBefore, panelAfter));\n }\n }, [disabled, panelAfter, panelBefore, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor =\n direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseLeave = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n const onMouseUp = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n document.body.addEventListener(\"mouseleave\", onMouseLeave);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", onMouseUp);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", onMouseLeave);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", onMouseUp);\n };\n }, [direction, disabled, isDragging, resizeHandler]);\n\n return (\n <div\n className={className}\n onMouseDown={() => setIsDragging(true)}\n onMouseUp={() => setIsDragging(false)}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.js.map","sourceRoot":"../../../"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;ACAA;;ACAA;AAIO,MAAM,4CAAe,CAAA,GAAA,0BAAY,EAE9B,IAAI;AAEP,MAAM,4CAAoB,CAAA,GAAA,0BAAY,EASnC,IAAI;;;ADVC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,aACV,QAAQ,IAAI,GAQb,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CAAC,cAAc,EAAE,QAAQ,oCAAoC,EAAE,YAAY,CAAC;QAG9E,cAAc;IAChB,CAAC;IAED,MAAM,iBAAE,cAAa,iBAAE,cAAa,mBAAE,gBAAe,EAAE,GAAG;IAE1D,CAAA,GAAA,4BAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;mBACA;QACF;QAEA,cAAc,IAAI;QAElB,OAAO,IAAM;YACX,gBAAgB;QAClB;IACF,GAAG;QAAC;QAAa;QAAI;QAAS;QAAO;QAAe;KAAgB;IAEpE,MAAM,QAAQ,cAAc;IAE5B,qBACE,sCAAC;QAAI,WAAW;QAAW,OAAO;kBAC/B;;;;;;AAGP;;AD7DA;;AGAA;;ACAA;AAEA,IAAI,gCAAU;AAEC,kDAAqB,KAAoB,IAAI,EAAU;IACpE,MAAM,QAAQ,CAAA,GAAA,mBAAK,EAAiB;IACpC,IAAI,MAAM,OAAO,KAAK,IAAI,EACxB,MAAM,OAAO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panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/utils/serialization.ts","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n order = null,\n}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\n order?: number | null;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `Panel components must be rendered within a PanelGroup container`\n );\n }\n\n if (minSize > defaultSize) {\n console.error(\n `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`\n );\n\n defaultSize = minSize;\n }\n\n const { getPanelStyle, registerPanel, unregisterPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n order,\n };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);\n\n const style = getPanelStyle(id);\n\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n}\n","import { CSSProperties, createContext } from \"react\";\n\nimport { PanelData, ResizeHandler } from \"./types\";\n\nexport const PanelContext = createContext<{\n activeHandleId: string | null;\n} | null>(null);\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: string) => CSSProperties;\n groupId: string;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (id: string) => ResizeHandler;\n startDragging: (id: string) => void;\n stopDragging: () => void;\n unregisterPanel: (id: string) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport useUniqueId from \"./hooks/useUniqueId\";\n\nimport { PanelContext, PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, PanelData } from \"./types\";\nimport { loadPanelLayout, savePanelGroupLayout } from \"./utils/serialization\";\n\ntype Props = {\n autoSaveId?: string;\n children?: ReactNode;\n className?: string;\n direction: Direction;\n height: number;\n width: number;\n};\n\nconst PRECISION = 5;\n\n// TODO [panels]\n// Within an active drag, remember original positions to refine more easily on expand.\n// Look at what the Chrome devtools Sources does.\n\nexport default function PanelGroup({\n autoSaveId,\n children = null,\n className = \"\",\n direction,\n height,\n width,\n}: Props) {\n const groupId = useUniqueId();\n\n const [activeHandleId, setActiveHandleId] = useState<string | null>(null);\n const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());\n\n // 0-1 values representing the relative size of each panel.\n const [sizes, setSizes] = useState<number[]>([]);\n\n // Store committed values to avoid unnecessarily re-running memoization/effects functions.\n const committedValuesRef = useRef<{\n direction: Direction;\n height: number;\n panels: Map<string, PanelData>;\n sizes: number[];\n width: number;\n }>({\n direction,\n height,\n panels,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\n committedValuesRef.current.panels = panels;\n committedValuesRef.current.sizes = sizes;\n committedValuesRef.current.width = width;\n });\n\n // Once all panels have registered themselves,\n // Compute the initial sizes based on default weights.\n // This assumes that panels register during initial mount (no conditional rendering)!\n useLayoutEffect(() => {\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.size) {\n return;\n }\n\n // TODO [panels]\n // Validate that the total minSize is <= 1.\n\n // If this panel has been configured to persist sizing information,\n // default size should be restored from local storage if possible.\n let defaultSizes: number[] | undefined = undefined;\n if (autoSaveId) {\n const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);\n defaultSizes = loadPanelLayout(autoSaveId, panelIds);\n }\n\n if (defaultSizes != null) {\n setSizes(defaultSizes);\n } else {\n const panelsArray = panelsMapToSortedArray(panels);\n const totalWeight = panelsArray.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panelsArray.map((panel) => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId, panels]);\n\n useEffect(() => {\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n if (autoSaveId) {\n if (sizes.length === 0 || sizes.length !== panels.size) {\n return;\n }\n\n const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);\n savePanelGroupLayout(autoSaveId, panelIds, sizes);\n }\n }, [autoSaveId, panels, sizes]);\n\n const getPanelStyle = useCallback(\n (id: string): CSSProperties => {\n const { panels } = committedValuesRef.current;\n\n const offset = getOffset(panels, id, direction, sizes, height, width);\n const size = getSize(panels, id, direction, sizes, height, width);\n\n if (direction === \"horizontal\") {\n return {\n height: \"100%\",\n position: \"absolute\",\n left: offset,\n top: 0,\n width: size,\n };\n } else {\n return {\n height: size,\n position: \"absolute\",\n left: 0,\n top: offset,\n width: \"100%\",\n };\n }\n },\n [direction, height, sizes, width]\n );\n\n const registerPanel = useCallback((id: string, panel: PanelData) => {\n setPanels((prevPanels) => {\n if (prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.set(id, panel);\n\n return nextPanels;\n });\n }, []);\n\n const registerResizeHandle = useCallback(\n (id: string) => {\n const resizeHandler = (event: MouseEvent) => {\n event.preventDefault();\n\n const {\n direction,\n height,\n panels,\n sizes: prevSizes,\n width,\n } = committedValuesRef.current;\n\n const handle = document.querySelector(\n `[data-panel-resize-handle-id=\"${id}\"]`\n );\n const handles = Array.from(\n document.querySelectorAll(`[data-panel-group-id=\"${groupId}\"]`)\n );\n const index = handles.indexOf(handle);\n const panelsArray = panelsMapToSortedArray(panels);\n const idBefore: string | null = panelsArray[index]?.id ?? null;\n const idAfter: string | null = panelsArray[index + 1]?.id ?? null;\n if (idBefore == null || idAfter == null) {\n return;\n }\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(\n panels,\n idBefore,\n idAfter,\n delta,\n prevSizes\n );\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n\n return resizeHandler;\n },\n [groupId]\n );\n\n const unregisterPanel = useCallback((id: string) => {\n setPanels((prevPanels) => {\n if (!prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.delete(id);\n\n return nextPanels;\n });\n }, []);\n\n const panelGroupContext = useMemo(\n () => ({\n direction,\n getPanelStyle,\n groupId,\n registerPanel,\n registerResizeHandle,\n startDragging: (id: string) => setActiveHandleId(id),\n stopDragging: () => setActiveHandleId(null),\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n groupId,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n ]\n );\n\n const panelContext = useMemo(\n () => ({\n activeHandleId,\n }),\n [activeHandleId]\n );\n\n return (\n <PanelContext.Provider value={panelContext}>\n <PanelGroupContext.Provider value={panelGroupContext}>\n <div className={className}>{children}</div>\n </PanelGroupContext.Provider>\n </PanelContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Map<string, PanelData>,\n idBefore: string,\n idAfter: string,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const nextSizes = prevSizes.concat();\n\n let deltaApplied = 0;\n\n // A resizing panel affects the panels before or after it.\n //\n // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.\n // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.\n //\n // A positive delta means the panel immediately before the resizer should \"expand\".\n // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.\n let pivotId = delta < 0 ? idBefore : idAfter;\n let index = panelsArray.findIndex((panel) => panel.id === pivotId);\n while (true) {\n const panel = panelsArray[index];\n const prevSize = prevSizes[index];\n const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);\n if (prevSize !== nextSize) {\n deltaApplied += prevSize - nextSize;\n\n nextSizes[index] = nextSize;\n\n if (deltaApplied.toPrecision(PRECISION) >= delta.toPrecision(PRECISION)) {\n break;\n }\n }\n\n if (delta < 0) {\n if (--index < 0) {\n break;\n }\n } else {\n if (++index >= panelsArray.length) {\n break;\n }\n }\n }\n\n // If we were unable to resize any of the panels panels, return the previous state.\n // This will essentially bailout and ignore the \"mousemove\" event.\n if (deltaApplied === 0) {\n return prevSizes;\n }\n\n // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.\n pivotId = delta < 0 ? idAfter : idBefore;\n index = panelsArray.findIndex((panel) => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction getOffset(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const panelsArray = panelsMapToSortedArray(panels);\n\n let index = panelsArray.findIndex((panel) => panel.id === id);\n if (index < 0) {\n return 0;\n }\n\n let scaledOffset = 0;\n\n for (index = index - 1; index >= 0; index--) {\n const panel = panelsArray[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.size === 1) {\n return totalSize;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const index = panelsArray.findIndex((panel) => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n return Math.round(size * totalSize);\n}\n\nfunction panelsMapToSortedArray(panels: Map<string, PanelData>): PanelData[] {\n return Array.from(panels.values()).sort((a, b) => a.order - b.order);\n}\n","import { useRef } from \"react\";\n\nlet counter = 0;\n\nexport default function useUniqueId(id: string | null = null): string {\n const idRef = useRef<string | null>(id);\n if (idRef.current === null) {\n idRef.current = \"\" + counter++;\n }\n\n return idRef.current;\n}\n","import { PanelData } from \"../types\";\n\ntype SerializedPanelGroupState = { [panelIds: string]: number[] };\n\nfunction loadSerializedPanelGroupState(\n autoSaveId: string\n): SerializedPanelGroupState | null {\n try {\n const serialized = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);\n if (serialized) {\n const parsed = JSON.parse(serialized);\n if (typeof parsed === \"object\" && parsed != null) {\n return parsed;\n }\n }\n } catch (error) {}\n\n return null;\n}\n\nexport function loadPanelLayout(\n autoSaveId: string,\n panelIds: string[]\n): number[] | null {\n const state = loadSerializedPanelGroupState(autoSaveId);\n if (state) {\n return state[panelIds.join(\",\")] ?? null;\n }\n\n return null;\n}\n\nexport function savePanelGroupLayout(\n autoSaveId: string,\n panelIds: string[],\n sizes: number[]\n): void {\n const state = loadSerializedPanelGroupState(autoSaveId) || {};\n state[panelIds.join(\",\")] = sizes;\n\n try {\n localStorage.setItem(\n `PanelGroup:sizes:${autoSaveId}`,\n JSON.stringify(state)\n );\n } catch (error) {\n console.error(error);\n }\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport useUniqueId from \"./hooks/useUniqueId\";\nimport { PanelContext, PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n id: idProp = null,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n id?: string | null;\n}) {\n const panelContext = useContext(PanelContext);\n const panelGroupContext = useContext(PanelGroupContext);\n if (panelContext === null || panelGroupContext === null) {\n throw Error(\n `PanelResizeHandle components must be rendered within a PanelGroup container`\n );\n }\n\n const id = useUniqueId(idProp);\n\n const { activeHandleId } = panelContext;\n const {\n direction,\n groupId,\n registerResizeHandle,\n startDragging,\n stopDragging,\n } = panelGroupContext;\n\n const isDragging = activeHandleId === id;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(\n null\n );\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n const resizeHandler = registerResizeHandle(id);\n setResizeHandler(() => resizeHandler);\n }\n }, [disabled, groupId, id, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor =\n direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n document.body.addEventListener(\"mouseleave\", stopDragging);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"touchmove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", stopDragging);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", stopDragging);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"touchmove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", stopDragging);\n };\n }, [direction, disabled, isDragging, resizeHandler, stopDragging]);\n\n return (\n <div\n className={className}\n data-panel-group-id={groupId}\n data-panel-resize-handle-id={id}\n onMouseDown={() => startDragging(id)}\n onMouseUp={stopDragging}\n onTouchStart={() => startDragging(id)}\n onTouchEnd={stopDragging}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.js.map","sourceRoot":"../../../"}
|
|
@@ -4,6 +4,7 @@ import {useContext as $fpI56$useContext, useLayoutEffect as $fpI56$useLayoutEffe
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
const $f922724f4bad4884$export$f34532ac99e32150 = (0, $fpI56$createContext)(null);
|
|
7
8
|
const $f922724f4bad4884$export$7d8c6d083caec74a = (0, $fpI56$createContext)(null);
|
|
8
9
|
|
|
9
10
|
|
|
@@ -50,8 +51,46 @@ function $ad28bce87b00c2be$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
|
|
55
|
+
let $968185313205dcfa$var$counter = 0;
|
|
56
|
+
function $968185313205dcfa$export$2e2bcd8739ae039(id = null) {
|
|
57
|
+
const idRef = (0, $fpI56$useRef)(id);
|
|
58
|
+
if (idRef.current === null) idRef.current = "" + $968185313205dcfa$var$counter++;
|
|
59
|
+
return idRef.current;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function $6ff1a22b27cc039d$var$loadSerializedPanelGroupState(autoSaveId) {
|
|
65
|
+
try {
|
|
66
|
+
const serialized = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
|
|
67
|
+
if (serialized) {
|
|
68
|
+
const parsed = JSON.parse(serialized);
|
|
69
|
+
if (typeof parsed === "object" && parsed != null) return parsed;
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function $6ff1a22b27cc039d$export$9c80c6617f0386da(autoSaveId, panelIds) {
|
|
75
|
+
const state = $6ff1a22b27cc039d$var$loadSerializedPanelGroupState(autoSaveId);
|
|
76
|
+
if (state) return state[panelIds.join(",")] ?? null;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
function $6ff1a22b27cc039d$export$af183b313c61be4f(autoSaveId, panelIds, sizes) {
|
|
80
|
+
const state = $6ff1a22b27cc039d$var$loadSerializedPanelGroupState(autoSaveId) || {};
|
|
81
|
+
state[panelIds.join(",")] = sizes;
|
|
82
|
+
try {
|
|
83
|
+
localStorage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(state));
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(error);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
53
90
|
const $c44ee3356398c8a1$var$PRECISION = 5;
|
|
54
91
|
function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
|
|
92
|
+
const groupId = (0, $968185313205dcfa$export$2e2bcd8739ae039)();
|
|
93
|
+
const [activeHandleId, setActiveHandleId] = (0, $fpI56$useState)(null);
|
|
55
94
|
const [panels, setPanels] = (0, $fpI56$useState)(new Map());
|
|
56
95
|
// 0-1 values representing the relative size of each panel.
|
|
57
96
|
const [sizes, setSizes] = (0, $fpI56$useState)([]);
|
|
@@ -81,10 +120,10 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
81
120
|
// If this panel has been configured to persist sizing information,
|
|
82
121
|
// default size should be restored from local storage if possible.
|
|
83
122
|
let defaultSizes = undefined;
|
|
84
|
-
if (autoSaveId)
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
}
|
|
123
|
+
if (autoSaveId) {
|
|
124
|
+
const panelIds = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
125
|
+
defaultSizes = (0, $6ff1a22b27cc039d$export$9c80c6617f0386da)(autoSaveId, panelIds);
|
|
126
|
+
}
|
|
88
127
|
if (defaultSizes != null) setSizes(defaultSizes);
|
|
89
128
|
else {
|
|
90
129
|
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
@@ -98,10 +137,11 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
98
137
|
panels
|
|
99
138
|
]);
|
|
100
139
|
(0, $fpI56$useEffect)(()=>{
|
|
140
|
+
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
101
141
|
if (autoSaveId) {
|
|
102
142
|
if (sizes.length === 0 || sizes.length !== panels.size) return;
|
|
103
|
-
|
|
104
|
-
|
|
143
|
+
const panelIds = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
144
|
+
(0, $6ff1a22b27cc039d$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
|
|
105
145
|
}
|
|
106
146
|
}, [
|
|
107
147
|
autoSaveId,
|
|
@@ -140,18 +180,27 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
140
180
|
return nextPanels;
|
|
141
181
|
});
|
|
142
182
|
}, []);
|
|
143
|
-
const registerResizeHandle = (0, $fpI56$useCallback)((
|
|
144
|
-
|
|
183
|
+
const registerResizeHandle = (0, $fpI56$useCallback)((id)=>{
|
|
184
|
+
const resizeHandler = (event)=>{
|
|
145
185
|
event.preventDefault();
|
|
146
186
|
const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
|
|
187
|
+
const handle = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
188
|
+
const handles = Array.from(document.querySelectorAll(`[data-panel-group-id="${groupId}"]`));
|
|
189
|
+
const index = handles.indexOf(handle);
|
|
190
|
+
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
191
|
+
const idBefore = panelsArray[index]?.id ?? null;
|
|
192
|
+
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
193
|
+
if (idBefore == null || idAfter == null) return;
|
|
147
194
|
const isHorizontal = direction === "horizontal";
|
|
148
195
|
const movement = isHorizontal ? event.movementX : event.movementY;
|
|
149
196
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
150
197
|
const nextSizes = $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
|
|
151
198
|
if (prevSizes !== nextSizes) setSizes(nextSizes);
|
|
152
199
|
};
|
|
153
|
-
|
|
154
|
-
}, [
|
|
200
|
+
return resizeHandler;
|
|
201
|
+
}, [
|
|
202
|
+
groupId
|
|
203
|
+
]);
|
|
155
204
|
const unregisterPanel = (0, $fpI56$useCallback)((id)=>{
|
|
156
205
|
setPanels((prevPanels)=>{
|
|
157
206
|
if (!prevPanels.has(id)) return prevPanels;
|
|
@@ -160,32 +209,48 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
160
209
|
return nextPanels;
|
|
161
210
|
});
|
|
162
211
|
}, []);
|
|
163
|
-
const
|
|
212
|
+
const panelGroupContext = (0, $fpI56$useMemo)(()=>({
|
|
164
213
|
direction: direction,
|
|
165
214
|
getPanelStyle: getPanelStyle,
|
|
215
|
+
groupId: groupId,
|
|
166
216
|
registerPanel: registerPanel,
|
|
167
217
|
registerResizeHandle: registerResizeHandle,
|
|
218
|
+
startDragging: (id)=>setActiveHandleId(id),
|
|
219
|
+
stopDragging: ()=>setActiveHandleId(null),
|
|
168
220
|
unregisterPanel: unregisterPanel
|
|
169
221
|
}), [
|
|
170
222
|
direction,
|
|
171
223
|
getPanelStyle,
|
|
224
|
+
groupId,
|
|
172
225
|
registerPanel,
|
|
173
226
|
registerResizeHandle,
|
|
174
227
|
unregisterPanel
|
|
175
228
|
]);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
229
|
+
const panelContext = (0, $fpI56$useMemo)(()=>({
|
|
230
|
+
activeHandleId: activeHandleId
|
|
231
|
+
}), [
|
|
232
|
+
activeHandleId
|
|
233
|
+
]);
|
|
234
|
+
return /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$f34532ac99e32150).Provider, {
|
|
235
|
+
value: panelContext,
|
|
236
|
+
children: /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$7d8c6d083caec74a).Provider, {
|
|
237
|
+
value: panelGroupContext,
|
|
238
|
+
children: /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
|
|
239
|
+
className: className,
|
|
240
|
+
children: children
|
|
241
|
+
}, void 0, false, {
|
|
242
|
+
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
243
|
+
lineNumber: 247,
|
|
244
|
+
columnNumber: 9
|
|
245
|
+
}, this)
|
|
181
246
|
}, void 0, false, {
|
|
182
247
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
183
|
-
lineNumber:
|
|
248
|
+
lineNumber: 246,
|
|
184
249
|
columnNumber: 7
|
|
185
250
|
}, this)
|
|
186
251
|
}, void 0, false, {
|
|
187
252
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
188
|
-
lineNumber:
|
|
253
|
+
lineNumber: 245,
|
|
189
254
|
columnNumber: 5
|
|
190
255
|
}, this);
|
|
191
256
|
}
|
|
@@ -227,11 +292,6 @@ function $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, p
|
|
|
227
292
|
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
228
293
|
return nextSizes;
|
|
229
294
|
}
|
|
230
|
-
function $c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels) {
|
|
231
|
-
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
232
|
-
const panelIds = panelsArray.map((panel)=>panel.id);
|
|
233
|
-
return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
|
|
234
|
-
}
|
|
235
295
|
function $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width) {
|
|
236
296
|
const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
|
|
237
297
|
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
@@ -260,59 +320,67 @@ function $c44ee3356398c8a1$var$panelsMapToSortedArray(panels) {
|
|
|
260
320
|
|
|
261
321
|
|
|
262
322
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
323
|
+
|
|
324
|
+
function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idProp = null }) {
|
|
325
|
+
const panelContext = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$f34532ac99e32150));
|
|
326
|
+
const panelGroupContext = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
|
|
327
|
+
if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
|
|
328
|
+
const id = (0, $968185313205dcfa$export$2e2bcd8739ae039)(idProp);
|
|
329
|
+
const { activeHandleId: activeHandleId } = panelContext;
|
|
330
|
+
const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
|
|
331
|
+
const isDragging = activeHandleId === id;
|
|
267
332
|
const [resizeHandler, setResizeHandler] = (0, $fpI56$useState)(null);
|
|
268
|
-
const [isDragging, setIsDragging] = (0, $fpI56$useState)(false);
|
|
269
333
|
(0, $fpI56$useEffect)(()=>{
|
|
270
334
|
if (disabled) setResizeHandler(null);
|
|
271
|
-
else
|
|
335
|
+
else {
|
|
336
|
+
const resizeHandler = registerResizeHandle(id);
|
|
337
|
+
setResizeHandler(()=>resizeHandler);
|
|
338
|
+
}
|
|
272
339
|
}, [
|
|
273
340
|
disabled,
|
|
274
|
-
|
|
275
|
-
|
|
341
|
+
groupId,
|
|
342
|
+
id,
|
|
276
343
|
registerResizeHandle
|
|
277
344
|
]);
|
|
278
345
|
(0, $fpI56$useEffect)(()=>{
|
|
279
346
|
if (disabled || resizeHandler == null || !isDragging) return;
|
|
280
347
|
document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
|
|
281
|
-
const onMouseLeave = (_)=>{
|
|
282
|
-
setIsDragging(false);
|
|
283
|
-
};
|
|
284
348
|
const onMouseMove = (event)=>{
|
|
285
349
|
resizeHandler(event);
|
|
286
350
|
};
|
|
287
|
-
|
|
288
|
-
setIsDragging(false);
|
|
289
|
-
};
|
|
290
|
-
document.body.addEventListener("mouseleave", onMouseLeave);
|
|
351
|
+
document.body.addEventListener("mouseleave", stopDragging);
|
|
291
352
|
document.body.addEventListener("mousemove", onMouseMove);
|
|
292
|
-
document.body.addEventListener("
|
|
353
|
+
document.body.addEventListener("touchmove", onMouseMove);
|
|
354
|
+
document.body.addEventListener("mouseup", stopDragging);
|
|
293
355
|
return ()=>{
|
|
294
356
|
document.body.style.cursor = "";
|
|
295
|
-
document.body.removeEventListener("mouseleave",
|
|
357
|
+
document.body.removeEventListener("mouseleave", stopDragging);
|
|
296
358
|
document.body.removeEventListener("mousemove", onMouseMove);
|
|
297
|
-
document.body.removeEventListener("
|
|
359
|
+
document.body.removeEventListener("touchmove", onMouseMove);
|
|
360
|
+
document.body.removeEventListener("mouseup", stopDragging);
|
|
298
361
|
};
|
|
299
362
|
}, [
|
|
300
363
|
direction,
|
|
301
364
|
disabled,
|
|
302
365
|
isDragging,
|
|
303
|
-
resizeHandler
|
|
366
|
+
resizeHandler,
|
|
367
|
+
stopDragging
|
|
304
368
|
]);
|
|
305
369
|
return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
|
|
306
370
|
className: className,
|
|
307
|
-
|
|
308
|
-
|
|
371
|
+
"data-panel-group-id": groupId,
|
|
372
|
+
"data-panel-resize-handle-id": id,
|
|
373
|
+
onMouseDown: ()=>startDragging(id),
|
|
374
|
+
onMouseUp: stopDragging,
|
|
375
|
+
onTouchStart: ()=>startDragging(id),
|
|
376
|
+
onTouchEnd: stopDragging,
|
|
309
377
|
style: {
|
|
310
378
|
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
|
|
311
379
|
},
|
|
312
380
|
children: children
|
|
313
381
|
}, void 0, false, {
|
|
314
382
|
fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
|
|
315
|
-
lineNumber:
|
|
383
|
+
lineNumber: 80,
|
|
316
384
|
columnNumber: 5
|
|
317
385
|
}, this);
|
|
318
386
|
}
|
|
@@ -320,5 +388,5 @@ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
320
388
|
|
|
321
389
|
|
|
322
390
|
|
|
323
|
-
export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
|
|
391
|
+
export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $f922724f4bad4884$export$f34532ac99e32150 as PanelContext, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
|
|
324
392
|
//# sourceMappingURL=react-resizable-panels.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,oBAAY,EAMnC,IAAI;;;ADHC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,aACV,QAAQ,IAAI,GAQb,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CAAC,cAAc,EAAE,QAAQ,oCAAoC,EAAE,YAAY,CAAC;QAG9E,cAAc;IAChB,CAAC;IAED,MAAM,iBAAE,cAAa,iBAAE,cAAa,mBAAE,gBAAe,EAAE,GAAG;IAE1D,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;mBACA;QACF;QAEA,cAAc,IAAI;QAElB,OAAO,IAAM;YACX,gBAAgB;QAClB;IACF,GAAG;QAAC;QAAa;QAAI;QAAS;QAAO;QAAe;KAAgB;IAEpE,MAAM,QAAQ,cAAc;IAE5B,qBACE,mBAAC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AAM;QACd,IAAI,YAAY,iBAAiB,IAAI,IAAI,CAAC,YACxC;QAGF,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GACxB,cAAc,eAAe,cAAc,WAAW;QAExD,MAAM,eAAe,CAAC,IAAkB;YACtC,cAAc,KAAK;QACrB;QAEA,MAAM,cAAc,CAAC,QAAsB;YACzC,cAAc;QAChB;QAEA,MAAM,YAAY,CAAC,IAAkB;YACnC,cAAc,KAAK;QACrB;QAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc;QAC7C,SAAS,IAAI,CAAC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,mBAAC;QACC,WAAW;QACX,aAAa,IAAM,cAAc,IAAI;QACrC,WAAW,IAAM,cAAc,KAAK;QACpC,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;;;;;AAGP;;","sources":["packages/react-resizable-panels/src/index.ts","packages/react-resizable-panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n order = null,\n}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\n order?: number | null;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `Panel components must be rendered within a PanelGroup container`\n );\n }\n\n if (minSize > defaultSize) {\n console.error(\n `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`\n );\n\n defaultSize = minSize;\n }\n\n const { getPanelStyle, registerPanel, unregisterPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n order,\n };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);\n\n const style = getPanelStyle(id);\n\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n}\n","import { CSSProperties, createContext } from \"react\";\n\nimport { PanelData, ResizeHandler } from \"./types\";\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: string) => CSSProperties;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (idBefore: string, idAfter: string) => ResizeHandler;\n unregisterPanel: (id: string) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, PanelData } from \"./types\";\n\ntype Props = {\n autoSaveId?: string;\n children?: ReactNode[];\n className?: string;\n direction: Direction;\n height: number;\n width: number;\n};\n\nconst PRECISION = 5;\n\n// TODO [panels]\n// Within an active drag, remember original positions to refine more easily on expand.\n// Look at what the Chrome devtools Sources does.\n\nexport default function PanelGroup({\n autoSaveId,\n children = null,\n className = \"\",\n direction,\n height,\n width,\n}: Props) {\n const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());\n\n // 0-1 values representing the relative size of each panel.\n const [sizes, setSizes] = useState<number[]>([]);\n\n // Store committed values to avoid unnecessarily re-running memoization/effects functions.\n const committedValuesRef = useRef<{\n direction: Direction;\n height: number;\n panels: Map<string, PanelData>;\n sizes: number[];\n width: number;\n }>({\n direction,\n height,\n panels,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\n committedValuesRef.current.panels = panels;\n committedValuesRef.current.sizes = sizes;\n committedValuesRef.current.width = width;\n });\n\n // Once all panels have registered themselves,\n // Compute the initial sizes based on default weights.\n // This assumes that panels register during initial mount (no conditional rendering)!\n useLayoutEffect(() => {\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.size) {\n return;\n }\n\n // TODO [panels]\n // Validate that the total minSize is <= 1.\n\n // If this panel has been configured to persist sizing information,\n // default size should be restored from local storage if possible.\n let defaultSizes: number[] | undefined = undefined;\n if (autoSaveId) {\n try {\n const value = localStorage.getItem(\n createLocalStorageKey(autoSaveId, panels)\n );\n if (value) {\n defaultSizes = JSON.parse(value);\n }\n } catch (error) {}\n }\n\n if (defaultSizes != null) {\n setSizes(defaultSizes);\n } else {\n const panelsArray = panelsMapToSortedArray(panels);\n const totalWeight = panelsArray.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panelsArray.map((panel) => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId, panels]);\n\n useEffect(() => {\n if (autoSaveId) {\n if (sizes.length === 0 || sizes.length !== panels.size) {\n return;\n }\n\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n localStorage.setItem(\n createLocalStorageKey(autoSaveId, panels),\n JSON.stringify(sizes)\n );\n }\n }, [autoSaveId, panels, sizes]);\n\n const getPanelStyle = useCallback(\n (id: string): CSSProperties => {\n const { panels } = committedValuesRef.current;\n\n const offset = getOffset(panels, id, direction, sizes, height, width);\n const size = getSize(panels, id, direction, sizes, height, width);\n\n if (direction === \"horizontal\") {\n return {\n height: \"100%\",\n position: \"absolute\",\n left: offset,\n top: 0,\n width: size,\n };\n } else {\n return {\n height: size,\n position: \"absolute\",\n left: 0,\n top: offset,\n width: \"100%\",\n };\n }\n },\n [direction, height, sizes, width]\n );\n\n const registerPanel = useCallback((id: string, panel: PanelData) => {\n setPanels((prevPanels) => {\n if (prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.set(id, panel);\n\n return nextPanels;\n });\n }, []);\n\n const registerResizeHandle = useCallback(\n (idBefore: string, idAfter: string) => {\n return (event: MouseEvent) => {\n event.preventDefault();\n\n const {\n direction,\n height,\n panels,\n sizes: prevSizes,\n width,\n } = committedValuesRef.current;\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(\n panels,\n idBefore,\n idAfter,\n delta,\n prevSizes\n );\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n\n // TODO [issues/5] Add to Map\n },\n []\n );\n\n const unregisterPanel = useCallback((id: string) => {\n setPanels((prevPanels) => {\n if (!prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.delete(id);\n\n return nextPanels;\n });\n }, []);\n\n const context = useMemo(\n () => ({\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n ]\n );\n\n return (\n <PanelGroupContext.Provider value={context}>\n <div className={className}>{children}</div>\n </PanelGroupContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Map<string, PanelData>,\n idBefore: string,\n idAfter: string,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const nextSizes = prevSizes.concat();\n\n let deltaApplied = 0;\n\n // A resizing panel affects the panels before or after it.\n //\n // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.\n // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.\n //\n // A positive delta means the panel immediately before the resizer should \"expand\".\n // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.\n let pivotId = delta < 0 ? idBefore : idAfter;\n let index = panelsArray.findIndex((panel) => panel.id === pivotId);\n while (true) {\n const panel = panelsArray[index];\n const prevSize = prevSizes[index];\n const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);\n if (prevSize !== nextSize) {\n deltaApplied += prevSize - nextSize;\n\n nextSizes[index] = nextSize;\n\n if (deltaApplied.toPrecision(PRECISION) >= delta.toPrecision(PRECISION)) {\n break;\n }\n }\n\n if (delta < 0) {\n if (--index < 0) {\n break;\n }\n } else {\n if (++index >= panelsArray.length) {\n break;\n }\n }\n }\n\n // If we were unable to resize any of the panels panels, return the previous state.\n // This will essentially bailout and ignore the \"mousemove\" event.\n if (deltaApplied === 0) {\n return prevSizes;\n }\n\n // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.\n pivotId = delta < 0 ? idAfter : idBefore;\n index = panelsArray.findIndex((panel) => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction createLocalStorageKey(\n autoSaveId: string,\n panels: Map<string, PanelData>\n): string {\n const panelsArray = panelsMapToSortedArray(panels);\n const panelIds = panelsArray.map((panel) => panel.id);\n\n return `PanelGroup:sizes:${autoSaveId}${panelIds.join(\"|\")}`;\n}\n\nfunction getOffset(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const panelsArray = panelsMapToSortedArray(panels);\n\n let index = panelsArray.findIndex((panel) => panel.id === id);\n if (index < 0) {\n return 0;\n }\n\n let scaledOffset = 0;\n\n for (index = index - 1; index >= 0; index--) {\n const panel = panelsArray[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.size === 1) {\n return totalSize;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const index = panelsArray.findIndex((panel) => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n return Math.round(size * totalSize);\n}\n\nfunction panelsMapToSortedArray(panels: Map<string, PanelData>): PanelData[] {\n return Array.from(panels.values()).sort((a, b) => a.order - b.order);\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n panelAfter,\n panelBefore,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n panelAfter: string;\n panelBefore: string;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `PanelResizeHandle components must be rendered within a PanelGroup container`\n );\n }\n\n const { direction, registerResizeHandle } = context;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(\n null\n );\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n setResizeHandler(() => registerResizeHandle(panelBefore, panelAfter));\n }\n }, [disabled, panelAfter, panelBefore, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor =\n direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseLeave = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n const onMouseUp = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n document.body.addEventListener(\"mouseleave\", onMouseLeave);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", onMouseUp);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", onMouseLeave);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", onMouseUp);\n };\n }, [direction, disabled, isDragging, resizeHandler]);\n\n return (\n <div\n className={className}\n onMouseDown={() => setIsDragging(true)}\n onMouseUp={() => setIsDragging(false)}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.module.js.map","sourceRoot":"../../../"}
|
|
1
|
+
{"mappings":";;;ACAA;;ACAA;AAIO,MAAM,4CAAe,CAAA,GAAA,oBAAY,EAE9B,IAAI;AAEP,MAAM,4CAAoB,CAAA,GAAA,oBAAY,EASnC,IAAI;;;ADVC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,aACV,QAAQ,IAAI,GAQb,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CAAC,cAAc,EAAE,QAAQ,oCAAoC,EAAE,YAAY,CAAC;QAG9E,cAAc;IAChB,CAAC;IAED,MAAM,iBAAE,cAAa,iBAAE,cAAa,mBAAE,gBAAe,EAAE,GAAG;IAE1D,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;mBACA;QACF;QAEA,cAAc,IAAI;QAElB,OAAO,IAAM;YACX,gBAAgB;QAClB;IACF,GAAG;QAAC;QAAa;QAAI;QAAS;QAAO;QAAe;KAAgB;IAEpE,MAAM,QAAQ,cAAc;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BAAC;QACC,WAAW;QACX,uBAAqB;QACrB,+BAA6B;QAC7B,aAAa,IAAM,cAAc;QACjC,WAAW;QACX,cAAc,IAAM,cAAc;QAClC,YAAY;QACZ,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;;;;;AAGP;","sources":["packages/react-resizable-panels/src/index.ts","packages/react-resizable-panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/hooks/useUniqueId.ts","packages/react-resizable-panels/src/utils/serialization.ts","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n order = null,\n}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\n order?: number | null;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `Panel components must be rendered within a PanelGroup container`\n );\n }\n\n if (minSize > defaultSize) {\n console.error(\n `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`\n );\n\n defaultSize = minSize;\n }\n\n const { getPanelStyle, registerPanel, unregisterPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n order,\n };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);\n\n const style = getPanelStyle(id);\n\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n}\n","import { CSSProperties, createContext } from \"react\";\n\nimport { PanelData, ResizeHandler } from \"./types\";\n\nexport const PanelContext = createContext<{\n activeHandleId: string | null;\n} | null>(null);\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: string) => CSSProperties;\n groupId: string;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (id: string) => ResizeHandler;\n startDragging: (id: string) => void;\n stopDragging: () => void;\n unregisterPanel: (id: string) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport useUniqueId from \"./hooks/useUniqueId\";\n\nimport { PanelContext, PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, PanelData } from \"./types\";\nimport { loadPanelLayout, savePanelGroupLayout } from \"./utils/serialization\";\n\ntype Props = {\n autoSaveId?: string;\n children?: ReactNode;\n className?: string;\n direction: Direction;\n height: number;\n width: number;\n};\n\nconst PRECISION = 5;\n\n// TODO [panels]\n// Within an active drag, remember original positions to refine more easily on expand.\n// Look at what the Chrome devtools Sources does.\n\nexport default function PanelGroup({\n autoSaveId,\n children = null,\n className = \"\",\n direction,\n height,\n width,\n}: Props) {\n const groupId = useUniqueId();\n\n const [activeHandleId, setActiveHandleId] = useState<string | null>(null);\n const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());\n\n // 0-1 values representing the relative size of each panel.\n const [sizes, setSizes] = useState<number[]>([]);\n\n // Store committed values to avoid unnecessarily re-running memoization/effects functions.\n const committedValuesRef = useRef<{\n direction: Direction;\n height: number;\n panels: Map<string, PanelData>;\n sizes: number[];\n width: number;\n }>({\n direction,\n height,\n panels,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\n committedValuesRef.current.panels = panels;\n committedValuesRef.current.sizes = sizes;\n committedValuesRef.current.width = width;\n });\n\n // Once all panels have registered themselves,\n // Compute the initial sizes based on default weights.\n // This assumes that panels register during initial mount (no conditional rendering)!\n useLayoutEffect(() => {\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.size) {\n return;\n }\n\n // TODO [panels]\n // Validate that the total minSize is <= 1.\n\n // If this panel has been configured to persist sizing information,\n // default size should be restored from local storage if possible.\n let defaultSizes: number[] | undefined = undefined;\n if (autoSaveId) {\n const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);\n defaultSizes = loadPanelLayout(autoSaveId, panelIds);\n }\n\n if (defaultSizes != null) {\n setSizes(defaultSizes);\n } else {\n const panelsArray = panelsMapToSortedArray(panels);\n const totalWeight = panelsArray.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panelsArray.map((panel) => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId, panels]);\n\n useEffect(() => {\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n if (autoSaveId) {\n if (sizes.length === 0 || sizes.length !== panels.size) {\n return;\n }\n\n const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);\n savePanelGroupLayout(autoSaveId, panelIds, sizes);\n }\n }, [autoSaveId, panels, sizes]);\n\n const getPanelStyle = useCallback(\n (id: string): CSSProperties => {\n const { panels } = committedValuesRef.current;\n\n const offset = getOffset(panels, id, direction, sizes, height, width);\n const size = getSize(panels, id, direction, sizes, height, width);\n\n if (direction === \"horizontal\") {\n return {\n height: \"100%\",\n position: \"absolute\",\n left: offset,\n top: 0,\n width: size,\n };\n } else {\n return {\n height: size,\n position: \"absolute\",\n left: 0,\n top: offset,\n width: \"100%\",\n };\n }\n },\n [direction, height, sizes, width]\n );\n\n const registerPanel = useCallback((id: string, panel: PanelData) => {\n setPanels((prevPanels) => {\n if (prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.set(id, panel);\n\n return nextPanels;\n });\n }, []);\n\n const registerResizeHandle = useCallback(\n (id: string) => {\n const resizeHandler = (event: MouseEvent) => {\n event.preventDefault();\n\n const {\n direction,\n height,\n panels,\n sizes: prevSizes,\n width,\n } = committedValuesRef.current;\n\n const handle = document.querySelector(\n `[data-panel-resize-handle-id=\"${id}\"]`\n );\n const handles = Array.from(\n document.querySelectorAll(`[data-panel-group-id=\"${groupId}\"]`)\n );\n const index = handles.indexOf(handle);\n const panelsArray = panelsMapToSortedArray(panels);\n const idBefore: string | null = panelsArray[index]?.id ?? null;\n const idAfter: string | null = panelsArray[index + 1]?.id ?? null;\n if (idBefore == null || idAfter == null) {\n return;\n }\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(\n panels,\n idBefore,\n idAfter,\n delta,\n prevSizes\n );\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n\n return resizeHandler;\n },\n [groupId]\n );\n\n const unregisterPanel = useCallback((id: string) => {\n setPanels((prevPanels) => {\n if (!prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.delete(id);\n\n return nextPanels;\n });\n }, []);\n\n const panelGroupContext = useMemo(\n () => ({\n direction,\n getPanelStyle,\n groupId,\n registerPanel,\n registerResizeHandle,\n startDragging: (id: string) => setActiveHandleId(id),\n stopDragging: () => setActiveHandleId(null),\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n groupId,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n ]\n );\n\n const panelContext = useMemo(\n () => ({\n activeHandleId,\n }),\n [activeHandleId]\n );\n\n return (\n <PanelContext.Provider value={panelContext}>\n <PanelGroupContext.Provider value={panelGroupContext}>\n <div className={className}>{children}</div>\n </PanelGroupContext.Provider>\n </PanelContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Map<string, PanelData>,\n idBefore: string,\n idAfter: string,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const nextSizes = prevSizes.concat();\n\n let deltaApplied = 0;\n\n // A resizing panel affects the panels before or after it.\n //\n // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.\n // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.\n //\n // A positive delta means the panel immediately before the resizer should \"expand\".\n // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.\n let pivotId = delta < 0 ? idBefore : idAfter;\n let index = panelsArray.findIndex((panel) => panel.id === pivotId);\n while (true) {\n const panel = panelsArray[index];\n const prevSize = prevSizes[index];\n const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);\n if (prevSize !== nextSize) {\n deltaApplied += prevSize - nextSize;\n\n nextSizes[index] = nextSize;\n\n if (deltaApplied.toPrecision(PRECISION) >= delta.toPrecision(PRECISION)) {\n break;\n }\n }\n\n if (delta < 0) {\n if (--index < 0) {\n break;\n }\n } else {\n if (++index >= panelsArray.length) {\n break;\n }\n }\n }\n\n // If we were unable to resize any of the panels panels, return the previous state.\n // This will essentially bailout and ignore the \"mousemove\" event.\n if (deltaApplied === 0) {\n return prevSizes;\n }\n\n // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.\n pivotId = delta < 0 ? idAfter : idBefore;\n index = panelsArray.findIndex((panel) => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction getOffset(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const panelsArray = panelsMapToSortedArray(panels);\n\n let index = panelsArray.findIndex((panel) => panel.id === id);\n if (index < 0) {\n return 0;\n }\n\n let scaledOffset = 0;\n\n for (index = index - 1; index >= 0; index--) {\n const panel = panelsArray[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.size === 1) {\n return totalSize;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const index = panelsArray.findIndex((panel) => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n return Math.round(size * totalSize);\n}\n\nfunction panelsMapToSortedArray(panels: Map<string, PanelData>): PanelData[] {\n return Array.from(panels.values()).sort((a, b) => a.order - b.order);\n}\n","import { useRef } from \"react\";\n\nlet counter = 0;\n\nexport default function useUniqueId(id: string | null = null): string {\n const idRef = useRef<string | null>(id);\n if (idRef.current === null) {\n idRef.current = \"\" + counter++;\n }\n\n return idRef.current;\n}\n","import { PanelData } from \"../types\";\n\ntype SerializedPanelGroupState = { [panelIds: string]: number[] };\n\nfunction loadSerializedPanelGroupState(\n autoSaveId: string\n): SerializedPanelGroupState | null {\n try {\n const serialized = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);\n if (serialized) {\n const parsed = JSON.parse(serialized);\n if (typeof parsed === \"object\" && parsed != null) {\n return parsed;\n }\n }\n } catch (error) {}\n\n return null;\n}\n\nexport function loadPanelLayout(\n autoSaveId: string,\n panelIds: string[]\n): number[] | null {\n const state = loadSerializedPanelGroupState(autoSaveId);\n if (state) {\n return state[panelIds.join(\",\")] ?? null;\n }\n\n return null;\n}\n\nexport function savePanelGroupLayout(\n autoSaveId: string,\n panelIds: string[],\n sizes: number[]\n): void {\n const state = loadSerializedPanelGroupState(autoSaveId) || {};\n state[panelIds.join(\",\")] = sizes;\n\n try {\n localStorage.setItem(\n `PanelGroup:sizes:${autoSaveId}`,\n JSON.stringify(state)\n );\n } catch (error) {\n console.error(error);\n }\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport useUniqueId from \"./hooks/useUniqueId\";\nimport { PanelContext, PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n id: idProp = null,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n id?: string | null;\n}) {\n const panelContext = useContext(PanelContext);\n const panelGroupContext = useContext(PanelGroupContext);\n if (panelContext === null || panelGroupContext === null) {\n throw Error(\n `PanelResizeHandle components must be rendered within a PanelGroup container`\n );\n }\n\n const id = useUniqueId(idProp);\n\n const { activeHandleId } = panelContext;\n const {\n direction,\n groupId,\n registerResizeHandle,\n startDragging,\n stopDragging,\n } = panelGroupContext;\n\n const isDragging = activeHandleId === id;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(\n null\n );\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n const resizeHandler = registerResizeHandle(id);\n setResizeHandler(() => resizeHandler);\n }\n }, [disabled, groupId, id, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor =\n direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n document.body.addEventListener(\"mouseleave\", stopDragging);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"touchmove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", stopDragging);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", stopDragging);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"touchmove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", stopDragging);\n };\n }, [direction, disabled, isDragging, resizeHandler, stopDragging]);\n\n return (\n <div\n className={className}\n data-panel-group-id={groupId}\n data-panel-resize-handle-id={id}\n onMouseDown={() => startDragging(id)}\n onMouseUp={stopDragging}\n onTouchStart={() => startDragging(id)}\n onTouchEnd={stopDragging}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.module.js.map","sourceRoot":"../../../"}
|
package/package.json
CHANGED
package/src/PanelContexts.ts
CHANGED
|
@@ -2,10 +2,17 @@ import { CSSProperties, createContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { PanelData, ResizeHandler } from "./types";
|
|
4
4
|
|
|
5
|
+
export const PanelContext = createContext<{
|
|
6
|
+
activeHandleId: string | null;
|
|
7
|
+
} | null>(null);
|
|
8
|
+
|
|
5
9
|
export const PanelGroupContext = createContext<{
|
|
6
10
|
direction: "horizontal" | "vertical";
|
|
7
11
|
getPanelStyle: (id: string) => CSSProperties;
|
|
12
|
+
groupId: string;
|
|
8
13
|
registerPanel: (id: string, panel: PanelData) => void;
|
|
9
|
-
registerResizeHandle: (
|
|
14
|
+
registerResizeHandle: (id: string) => ResizeHandler;
|
|
15
|
+
startDragging: (id: string) => void;
|
|
16
|
+
stopDragging: () => void;
|
|
10
17
|
unregisterPanel: (id: string) => void;
|
|
11
18
|
} | null>(null);
|
package/src/PanelGroup.tsx
CHANGED
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useState,
|
|
10
10
|
} from "react";
|
|
11
|
+
import useUniqueId from "./hooks/useUniqueId";
|
|
11
12
|
|
|
12
|
-
import { PanelGroupContext } from "./PanelContexts";
|
|
13
|
+
import { PanelContext, PanelGroupContext } from "./PanelContexts";
|
|
13
14
|
import { Direction, PanelData } from "./types";
|
|
15
|
+
import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
|
|
14
16
|
|
|
15
17
|
type Props = {
|
|
16
18
|
autoSaveId?: string;
|
|
@@ -35,6 +37,9 @@ export default function PanelGroup({
|
|
|
35
37
|
height,
|
|
36
38
|
width,
|
|
37
39
|
}: Props) {
|
|
40
|
+
const groupId = useUniqueId();
|
|
41
|
+
|
|
42
|
+
const [activeHandleId, setActiveHandleId] = useState<string | null>(null);
|
|
38
43
|
const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());
|
|
39
44
|
|
|
40
45
|
// 0-1 values representing the relative size of each panel.
|
|
@@ -78,14 +83,8 @@ export default function PanelGroup({
|
|
|
78
83
|
// default size should be restored from local storage if possible.
|
|
79
84
|
let defaultSizes: number[] | undefined = undefined;
|
|
80
85
|
if (autoSaveId) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
createLocalStorageKey(autoSaveId, panels)
|
|
84
|
-
);
|
|
85
|
-
if (value) {
|
|
86
|
-
defaultSizes = JSON.parse(value);
|
|
87
|
-
}
|
|
88
|
-
} catch (error) {}
|
|
86
|
+
const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);
|
|
87
|
+
defaultSizes = loadPanelLayout(autoSaveId, panelIds);
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
if (defaultSizes != null) {
|
|
@@ -101,16 +100,14 @@ export default function PanelGroup({
|
|
|
101
100
|
}, [autoSaveId, panels]);
|
|
102
101
|
|
|
103
102
|
useEffect(() => {
|
|
103
|
+
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
104
104
|
if (autoSaveId) {
|
|
105
105
|
if (sizes.length === 0 || sizes.length !== panels.size) {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
createLocalStorageKey(autoSaveId, panels),
|
|
112
|
-
JSON.stringify(sizes)
|
|
113
|
-
);
|
|
109
|
+
const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);
|
|
110
|
+
savePanelGroupLayout(autoSaveId, panelIds, sizes);
|
|
114
111
|
}
|
|
115
112
|
}, [autoSaveId, panels, sizes]);
|
|
116
113
|
|
|
@@ -156,8 +153,8 @@ export default function PanelGroup({
|
|
|
156
153
|
}, []);
|
|
157
154
|
|
|
158
155
|
const registerResizeHandle = useCallback(
|
|
159
|
-
(
|
|
160
|
-
|
|
156
|
+
(id: string) => {
|
|
157
|
+
const resizeHandler = (event: MouseEvent) => {
|
|
161
158
|
event.preventDefault();
|
|
162
159
|
|
|
163
160
|
const {
|
|
@@ -168,6 +165,20 @@ export default function PanelGroup({
|
|
|
168
165
|
width,
|
|
169
166
|
} = committedValuesRef.current;
|
|
170
167
|
|
|
168
|
+
const handle = document.querySelector(
|
|
169
|
+
`[data-panel-resize-handle-id="${id}"]`
|
|
170
|
+
);
|
|
171
|
+
const handles = Array.from(
|
|
172
|
+
document.querySelectorAll(`[data-panel-group-id="${groupId}"]`)
|
|
173
|
+
);
|
|
174
|
+
const index = handles.indexOf(handle);
|
|
175
|
+
const panelsArray = panelsMapToSortedArray(panels);
|
|
176
|
+
const idBefore: string | null = panelsArray[index]?.id ?? null;
|
|
177
|
+
const idAfter: string | null = panelsArray[index + 1]?.id ?? null;
|
|
178
|
+
if (idBefore == null || idAfter == null) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
171
182
|
const isHorizontal = direction === "horizontal";
|
|
172
183
|
const movement = isHorizontal ? event.movementX : event.movementY;
|
|
173
184
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
@@ -184,9 +195,9 @@ export default function PanelGroup({
|
|
|
184
195
|
}
|
|
185
196
|
};
|
|
186
197
|
|
|
187
|
-
|
|
198
|
+
return resizeHandler;
|
|
188
199
|
},
|
|
189
|
-
[]
|
|
200
|
+
[groupId]
|
|
190
201
|
);
|
|
191
202
|
|
|
192
203
|
const unregisterPanel = useCallback((id: string) => {
|
|
@@ -202,27 +213,40 @@ export default function PanelGroup({
|
|
|
202
213
|
});
|
|
203
214
|
}, []);
|
|
204
215
|
|
|
205
|
-
const
|
|
216
|
+
const panelGroupContext = useMemo(
|
|
206
217
|
() => ({
|
|
207
218
|
direction,
|
|
208
219
|
getPanelStyle,
|
|
220
|
+
groupId,
|
|
209
221
|
registerPanel,
|
|
210
222
|
registerResizeHandle,
|
|
223
|
+
startDragging: (id: string) => setActiveHandleId(id),
|
|
224
|
+
stopDragging: () => setActiveHandleId(null),
|
|
211
225
|
unregisterPanel,
|
|
212
226
|
}),
|
|
213
227
|
[
|
|
214
228
|
direction,
|
|
215
229
|
getPanelStyle,
|
|
230
|
+
groupId,
|
|
216
231
|
registerPanel,
|
|
217
232
|
registerResizeHandle,
|
|
218
233
|
unregisterPanel,
|
|
219
234
|
]
|
|
220
235
|
);
|
|
221
236
|
|
|
237
|
+
const panelContext = useMemo(
|
|
238
|
+
() => ({
|
|
239
|
+
activeHandleId,
|
|
240
|
+
}),
|
|
241
|
+
[activeHandleId]
|
|
242
|
+
);
|
|
243
|
+
|
|
222
244
|
return (
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
|
|
245
|
+
<PanelContext.Provider value={panelContext}>
|
|
246
|
+
<PanelGroupContext.Provider value={panelGroupContext}>
|
|
247
|
+
<div className={className}>{children}</div>
|
|
248
|
+
</PanelGroupContext.Provider>
|
|
249
|
+
</PanelContext.Provider>
|
|
226
250
|
);
|
|
227
251
|
}
|
|
228
252
|
|
|
@@ -291,16 +315,6 @@ function adjustByDelta(
|
|
|
291
315
|
return nextSizes;
|
|
292
316
|
}
|
|
293
317
|
|
|
294
|
-
function createLocalStorageKey(
|
|
295
|
-
autoSaveId: string,
|
|
296
|
-
panels: Map<string, PanelData>
|
|
297
|
-
): string {
|
|
298
|
-
const panelsArray = panelsMapToSortedArray(panels);
|
|
299
|
-
const panelIds = panelsArray.map((panel) => panel.id);
|
|
300
|
-
|
|
301
|
-
return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
318
|
function getOffset(
|
|
305
319
|
panels: Map<string, PanelData>,
|
|
306
320
|
id: string,
|
|
@@ -1,42 +1,53 @@
|
|
|
1
1
|
import { ReactNode, useContext, useEffect, useState } from "react";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import useUniqueId from "./hooks/useUniqueId";
|
|
4
|
+
import { PanelContext, PanelGroupContext } from "./PanelContexts";
|
|
4
5
|
import { ResizeHandler } from "./types";
|
|
5
6
|
|
|
6
7
|
export default function PanelResizeHandle({
|
|
7
8
|
children = null,
|
|
8
9
|
className = "",
|
|
9
10
|
disabled = false,
|
|
10
|
-
|
|
11
|
-
panelBefore,
|
|
11
|
+
id: idProp = null,
|
|
12
12
|
}: {
|
|
13
13
|
children?: ReactNode;
|
|
14
14
|
className?: string;
|
|
15
15
|
disabled?: boolean;
|
|
16
|
-
|
|
17
|
-
panelBefore: string;
|
|
16
|
+
id?: string | null;
|
|
18
17
|
}) {
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
const panelContext = useContext(PanelContext);
|
|
19
|
+
const panelGroupContext = useContext(PanelGroupContext);
|
|
20
|
+
if (panelContext === null || panelGroupContext === null) {
|
|
21
21
|
throw Error(
|
|
22
22
|
`PanelResizeHandle components must be rendered within a PanelGroup container`
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const id = useUniqueId(idProp);
|
|
27
|
+
|
|
28
|
+
const { activeHandleId } = panelContext;
|
|
29
|
+
const {
|
|
30
|
+
direction,
|
|
31
|
+
groupId,
|
|
32
|
+
registerResizeHandle,
|
|
33
|
+
startDragging,
|
|
34
|
+
stopDragging,
|
|
35
|
+
} = panelGroupContext;
|
|
36
|
+
|
|
37
|
+
const isDragging = activeHandleId === id;
|
|
27
38
|
|
|
28
39
|
const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(
|
|
29
40
|
null
|
|
30
41
|
);
|
|
31
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
32
42
|
|
|
33
43
|
useEffect(() => {
|
|
34
44
|
if (disabled) {
|
|
35
45
|
setResizeHandler(null);
|
|
36
46
|
} else {
|
|
37
|
-
|
|
47
|
+
const resizeHandler = registerResizeHandle(id);
|
|
48
|
+
setResizeHandler(() => resizeHandler);
|
|
38
49
|
}
|
|
39
|
-
}, [disabled,
|
|
50
|
+
}, [disabled, groupId, id, registerResizeHandle]);
|
|
40
51
|
|
|
41
52
|
useEffect(() => {
|
|
42
53
|
if (disabled || resizeHandler == null || !isDragging) {
|
|
@@ -46,36 +57,34 @@ export default function PanelResizeHandle({
|
|
|
46
57
|
document.body.style.cursor =
|
|
47
58
|
direction === "horizontal" ? "ew-resize" : "ns-resize";
|
|
48
59
|
|
|
49
|
-
const onMouseLeave = (_: MouseEvent) => {
|
|
50
|
-
setIsDragging(false);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
60
|
const onMouseMove = (event: MouseEvent) => {
|
|
54
61
|
resizeHandler(event);
|
|
55
62
|
};
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
setIsDragging(false);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
document.body.addEventListener("mouseleave", onMouseLeave);
|
|
64
|
+
document.body.addEventListener("mouseleave", stopDragging);
|
|
62
65
|
document.body.addEventListener("mousemove", onMouseMove);
|
|
63
|
-
document.body.addEventListener("
|
|
66
|
+
document.body.addEventListener("touchmove", onMouseMove);
|
|
67
|
+
document.body.addEventListener("mouseup", stopDragging);
|
|
64
68
|
|
|
65
69
|
return () => {
|
|
66
70
|
document.body.style.cursor = "";
|
|
67
71
|
|
|
68
|
-
document.body.removeEventListener("mouseleave",
|
|
72
|
+
document.body.removeEventListener("mouseleave", stopDragging);
|
|
69
73
|
document.body.removeEventListener("mousemove", onMouseMove);
|
|
70
|
-
document.body.removeEventListener("
|
|
74
|
+
document.body.removeEventListener("touchmove", onMouseMove);
|
|
75
|
+
document.body.removeEventListener("mouseup", stopDragging);
|
|
71
76
|
};
|
|
72
|
-
}, [direction, disabled, isDragging, resizeHandler]);
|
|
77
|
+
}, [direction, disabled, isDragging, resizeHandler, stopDragging]);
|
|
73
78
|
|
|
74
79
|
return (
|
|
75
80
|
<div
|
|
76
81
|
className={className}
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
data-panel-group-id={groupId}
|
|
83
|
+
data-panel-resize-handle-id={id}
|
|
84
|
+
onMouseDown={() => startDragging(id)}
|
|
85
|
+
onMouseUp={stopDragging}
|
|
86
|
+
onTouchStart={() => startDragging(id)}
|
|
87
|
+
onTouchEnd={stopDragging}
|
|
79
88
|
style={{
|
|
80
89
|
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
|
|
81
90
|
}}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
let counter = 0;
|
|
4
|
+
|
|
5
|
+
export default function useUniqueId(id: string | null = null): string {
|
|
6
|
+
const idRef = useRef<string | null>(id);
|
|
7
|
+
if (idRef.current === null) {
|
|
8
|
+
idRef.current = "" + counter++;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return idRef.current;
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Panel from "./Panel";
|
|
2
|
+
import { PanelContext } from "./PanelContexts";
|
|
2
3
|
import PanelGroup from "./PanelGroup";
|
|
3
4
|
import PanelResizeHandle from "./PanelResizeHandle";
|
|
4
5
|
|
|
5
|
-
export { Panel, PanelGroup, PanelResizeHandle };
|
|
6
|
+
export { Panel, PanelContext, PanelGroup, PanelResizeHandle };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PanelData } from "../types";
|
|
2
|
+
|
|
3
|
+
type SerializedPanelGroupState = { [panelIds: string]: number[] };
|
|
4
|
+
|
|
5
|
+
function loadSerializedPanelGroupState(
|
|
6
|
+
autoSaveId: string
|
|
7
|
+
): SerializedPanelGroupState | null {
|
|
8
|
+
try {
|
|
9
|
+
const serialized = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
|
|
10
|
+
if (serialized) {
|
|
11
|
+
const parsed = JSON.parse(serialized);
|
|
12
|
+
if (typeof parsed === "object" && parsed != null) {
|
|
13
|
+
return parsed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {}
|
|
17
|
+
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function loadPanelLayout(
|
|
22
|
+
autoSaveId: string,
|
|
23
|
+
panelIds: string[]
|
|
24
|
+
): number[] | null {
|
|
25
|
+
const state = loadSerializedPanelGroupState(autoSaveId);
|
|
26
|
+
if (state) {
|
|
27
|
+
return state[panelIds.join(",")] ?? null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function savePanelGroupLayout(
|
|
34
|
+
autoSaveId: string,
|
|
35
|
+
panelIds: string[],
|
|
36
|
+
sizes: number[]
|
|
37
|
+
): void {
|
|
38
|
+
const state = loadSerializedPanelGroupState(autoSaveId) || {};
|
|
39
|
+
state[panelIds.join(",")] = sizes;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
localStorage.setItem(
|
|
43
|
+
`PanelGroup:sizes:${autoSaveId}`,
|
|
44
|
+
JSON.stringify(state)
|
|
45
|
+
);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(error);
|
|
48
|
+
}
|
|
49
|
+
}
|