react-resizable-panels 0.0.6 → 0.0.8
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 +5 -0
- package/README.md +7 -1
- package/dist/react-resizable-panels.d.ts +5 -1
- package/dist/react-resizable-panels.d.ts.map +1 -1
- package/dist/react-resizable-panels.js +132 -49
- package/dist/react-resizable-panels.js.map +1 -1
- package/dist/react-resizable-panels.module.js +132 -50
- package/dist/react-resizable-panels.module.js.map +1 -1
- package/package.json +1 -1
- package/src/PanelContexts.ts +6 -0
- package/src/PanelGroup.tsx +52 -31
- package/src/PanelResizeHandle.tsx +34 -26
- package/src/hooks/useUniqueId.ts +4 -4
- package/src/index.ts +2 -1
- package/src/types.ts +2 -1
- package/src/utils/serialization.ts +49 -0
- package/src/utils/touch.ts +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.8
|
|
4
|
+
* [#7](https://github.com/bvaughn/react-resizable-panels/issues/7): Support "touch" events for mobile compatibility.
|
|
5
|
+
|
|
6
|
+
## 0.0.7
|
|
7
|
+
* 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.
|
|
3
8
|
## 0.0.6
|
|
4
9
|
* [#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.
|
|
5
10
|
## 0.0.5
|
package/README.md
CHANGED
|
@@ -46,4 +46,10 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
|
|
|
46
46
|
| :------------ | :----------- | :---
|
|
47
47
|
| `children` | `?ReactNode` | Custom drag UI; can be any arbitrary React element(s)
|
|
48
48
|
| `className` | `?string` | Class name
|
|
49
|
-
| `disabled` | `?boolean` | Disable drag handle
|
|
49
|
+
| `disabled` | `?boolean` | Disable drag handle
|
|
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,10 +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;
|
|
27
|
+
id?: string | null;
|
|
24
28
|
}): JSX.Element;
|
|
25
29
|
|
|
26
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;AI5CD,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,eA6OP;AC9QD,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,eA+EA","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/utils/serialization.ts","packages/react-resizable-panels/src/src/utils/touch.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,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"}
|
|
@@ -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,18 +59,70 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
|
|
62
|
+
|
|
60
63
|
let $6d548a0d130941e3$var$counter = 0;
|
|
61
|
-
function $6d548a0d130941e3$export$2e2bcd8739ae039() {
|
|
62
|
-
const idRef = (0, $b2QPe$react.useRef)(
|
|
63
|
-
if (idRef.current === null) idRef.current = $6d548a0d130941e3$var$counter++;
|
|
64
|
-
return
|
|
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
|
+
}
|
|
65
95
|
}
|
|
66
96
|
|
|
67
97
|
|
|
98
|
+
function $37410a9246dfda64$export$70637efcd850e4ef(event, prevCoordinates) {
|
|
99
|
+
const { screenX: prevScreenX , screenY: prevScreenY } = prevCoordinates;
|
|
100
|
+
const getMovementBetween = (current, prev)=>prev === 0 ? 0 : current - prev;
|
|
101
|
+
if ($37410a9246dfda64$export$ce897e7f0aa63661(event)) {
|
|
102
|
+
const firstTouch = event.touches[0];
|
|
103
|
+
return {
|
|
104
|
+
movementX: getMovementBetween(firstTouch.screenX, prevScreenX),
|
|
105
|
+
movementY: getMovementBetween(firstTouch.screenY, prevScreenY),
|
|
106
|
+
screenX: firstTouch.screenX,
|
|
107
|
+
screenY: firstTouch.screenY
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
movementX: getMovementBetween(event.screenX, prevScreenX),
|
|
112
|
+
movementY: getMovementBetween(event.screenY, prevScreenY),
|
|
113
|
+
screenX: event.screenX,
|
|
114
|
+
screenY: event.screenY
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function $37410a9246dfda64$export$ce897e7f0aa63661(event) {
|
|
118
|
+
return event.type === "touchmove";
|
|
119
|
+
}
|
|
120
|
+
|
|
68
121
|
|
|
69
122
|
const $d428eaeef644efb2$var$PRECISION = 5;
|
|
70
123
|
function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
|
|
71
124
|
const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)();
|
|
125
|
+
const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
|
|
72
126
|
const [panels, setPanels] = (0, $b2QPe$react.useState)(new Map());
|
|
73
127
|
// 0-1 values representing the relative size of each panel.
|
|
74
128
|
const [sizes, setSizes] = (0, $b2QPe$react.useState)([]);
|
|
@@ -80,6 +134,12 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
80
134
|
sizes: sizes,
|
|
81
135
|
width: width
|
|
82
136
|
});
|
|
137
|
+
// Tracks the most recent coordinates of a touch/mouse event.
|
|
138
|
+
// This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).
|
|
139
|
+
const prevCoordinatesRef = (0, $b2QPe$react.useRef)({
|
|
140
|
+
screenX: 0,
|
|
141
|
+
screenY: 0
|
|
142
|
+
});
|
|
83
143
|
(0, $b2QPe$react.useLayoutEffect)(()=>{
|
|
84
144
|
committedValuesRef.current.direction = direction;
|
|
85
145
|
committedValuesRef.current.height = height;
|
|
@@ -98,10 +158,10 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
98
158
|
// If this panel has been configured to persist sizing information,
|
|
99
159
|
// default size should be restored from local storage if possible.
|
|
100
160
|
let defaultSizes = undefined;
|
|
101
|
-
if (autoSaveId)
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
}
|
|
161
|
+
if (autoSaveId) {
|
|
162
|
+
const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
163
|
+
defaultSizes = (0, $e045b0dd313f33c7$export$9c80c6617f0386da)(autoSaveId, panelIds);
|
|
164
|
+
}
|
|
105
165
|
if (defaultSizes != null) setSizes(defaultSizes);
|
|
106
166
|
else {
|
|
107
167
|
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
@@ -115,10 +175,11 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
115
175
|
panels
|
|
116
176
|
]);
|
|
117
177
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
178
|
+
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
118
179
|
if (autoSaveId) {
|
|
119
180
|
if (sizes.length === 0 || sizes.length !== panels.size) return;
|
|
120
|
-
|
|
121
|
-
|
|
181
|
+
const panelIds = $d428eaeef644efb2$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
|
|
182
|
+
(0, $e045b0dd313f33c7$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
|
|
122
183
|
}
|
|
123
184
|
}, [
|
|
124
185
|
autoSaveId,
|
|
@@ -168,8 +229,13 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
168
229
|
const idBefore = panelsArray[index]?.id ?? null;
|
|
169
230
|
const idAfter = panelsArray[index + 1]?.id ?? null;
|
|
170
231
|
if (idBefore == null || idAfter == null) return;
|
|
232
|
+
const nextCoordinates = (0, $37410a9246dfda64$export$70637efcd850e4ef)(event, prevCoordinatesRef.current);
|
|
233
|
+
prevCoordinatesRef.current = {
|
|
234
|
+
screenX: nextCoordinates.screenX,
|
|
235
|
+
screenY: nextCoordinates.screenY
|
|
236
|
+
};
|
|
171
237
|
const isHorizontal = direction === "horizontal";
|
|
172
|
-
const movement = isHorizontal ?
|
|
238
|
+
const movement = isHorizontal ? nextCoordinates.movementX : nextCoordinates.movementY;
|
|
173
239
|
const delta = isHorizontal ? movement / width : movement / height;
|
|
174
240
|
const nextSizes = $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
|
|
175
241
|
if (prevSizes !== nextSizes) setSizes(nextSizes);
|
|
@@ -186,12 +252,20 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
186
252
|
return nextPanels;
|
|
187
253
|
});
|
|
188
254
|
}, []);
|
|
189
|
-
const
|
|
255
|
+
const panelGroupContext = (0, $b2QPe$react.useMemo)(()=>({
|
|
190
256
|
direction: direction,
|
|
191
257
|
getPanelStyle: getPanelStyle,
|
|
192
258
|
groupId: groupId,
|
|
193
259
|
registerPanel: registerPanel,
|
|
194
260
|
registerResizeHandle: registerResizeHandle,
|
|
261
|
+
startDragging: (id)=>setActiveHandleId(id),
|
|
262
|
+
stopDragging: ()=>{
|
|
263
|
+
setActiveHandleId(null);
|
|
264
|
+
prevCoordinatesRef.current = {
|
|
265
|
+
screenX: 0,
|
|
266
|
+
screenY: 0
|
|
267
|
+
};
|
|
268
|
+
},
|
|
195
269
|
unregisterPanel: unregisterPanel
|
|
196
270
|
}), [
|
|
197
271
|
direction,
|
|
@@ -201,19 +275,31 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
|
|
|
201
275
|
registerResizeHandle,
|
|
202
276
|
unregisterPanel
|
|
203
277
|
]);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
278
|
+
const panelContext = (0, $b2QPe$react.useMemo)(()=>({
|
|
279
|
+
activeHandleId: activeHandleId
|
|
280
|
+
}), [
|
|
281
|
+
activeHandleId
|
|
282
|
+
]);
|
|
283
|
+
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)((0, $3251d17c1c3bce6c$export$f34532ac99e32150).Provider, {
|
|
284
|
+
value: panelContext,
|
|
285
|
+
children: /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
|
|
286
|
+
value: panelGroupContext,
|
|
287
|
+
children: /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
288
|
+
className: className,
|
|
289
|
+
children: children
|
|
290
|
+
}, void 0, false, {
|
|
291
|
+
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
292
|
+
lineNumber: 273,
|
|
293
|
+
columnNumber: 9
|
|
294
|
+
}, this)
|
|
209
295
|
}, void 0, false, {
|
|
210
296
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
211
|
-
lineNumber:
|
|
297
|
+
lineNumber: 272,
|
|
212
298
|
columnNumber: 7
|
|
213
299
|
}, this)
|
|
214
300
|
}, void 0, false, {
|
|
215
301
|
fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
|
|
216
|
-
lineNumber:
|
|
302
|
+
lineNumber: 271,
|
|
217
303
|
columnNumber: 5
|
|
218
304
|
}, this);
|
|
219
305
|
}
|
|
@@ -255,11 +341,6 @@ function $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, p
|
|
|
255
341
|
nextSizes[index] = prevSizes[index] + deltaApplied;
|
|
256
342
|
return nextSizes;
|
|
257
343
|
}
|
|
258
|
-
function $d428eaeef644efb2$var$createLocalStorageKey(autoSaveId, panels) {
|
|
259
|
-
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
260
|
-
const panelIds = panelsArray.map((panel)=>panel.id);
|
|
261
|
-
return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
|
|
262
|
-
}
|
|
263
344
|
function $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width) {
|
|
264
345
|
const panelsArray = $d428eaeef644efb2$var$panelsMapToSortedArray(panels);
|
|
265
346
|
let index = panelsArray.findIndex((panel)=>panel.id === id);
|
|
@@ -289,14 +370,15 @@ function $d428eaeef644efb2$var$panelsMapToSortedArray(panels) {
|
|
|
289
370
|
|
|
290
371
|
|
|
291
372
|
|
|
292
|
-
function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false }) {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
const
|
|
373
|
+
function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idProp = null }) {
|
|
374
|
+
const panelContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$f34532ac99e32150));
|
|
375
|
+
const panelGroupContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
|
|
376
|
+
if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
|
|
377
|
+
const id = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idProp);
|
|
378
|
+
const { activeHandleId: activeHandleId } = panelContext;
|
|
379
|
+
const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
|
|
380
|
+
const isDragging = activeHandleId === id;
|
|
298
381
|
const [resizeHandler, setResizeHandler] = (0, $b2QPe$react.useState)(null);
|
|
299
|
-
const [isDragging, setIsDragging] = (0, $b2QPe$react.useState)(false);
|
|
300
382
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
301
383
|
if (disabled) setResizeHandler(null);
|
|
302
384
|
else {
|
|
@@ -312,43 +394,44 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
|
|
|
312
394
|
(0, $b2QPe$react.useEffect)(()=>{
|
|
313
395
|
if (disabled || resizeHandler == null || !isDragging) return;
|
|
314
396
|
document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
|
|
315
|
-
const
|
|
316
|
-
setIsDragging(false);
|
|
317
|
-
};
|
|
318
|
-
const onMouseMove = (event)=>{
|
|
397
|
+
const onMove = (event)=>{
|
|
319
398
|
resizeHandler(event);
|
|
320
399
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
document.body.addEventListener("
|
|
325
|
-
document.body.addEventListener("mousemove", onMouseMove);
|
|
326
|
-
document.body.addEventListener("mouseup", onMouseUp);
|
|
400
|
+
document.body.addEventListener("mouseleave", stopDragging);
|
|
401
|
+
document.body.addEventListener("mousemove", onMove);
|
|
402
|
+
document.body.addEventListener("touchmove", onMove);
|
|
403
|
+
document.body.addEventListener("mouseup", stopDragging);
|
|
327
404
|
return ()=>{
|
|
328
405
|
document.body.style.cursor = "";
|
|
329
|
-
document.body.removeEventListener("mouseleave",
|
|
330
|
-
document.body.removeEventListener("mousemove",
|
|
331
|
-
document.body.removeEventListener("
|
|
406
|
+
document.body.removeEventListener("mouseleave", stopDragging);
|
|
407
|
+
document.body.removeEventListener("mousemove", onMove);
|
|
408
|
+
document.body.removeEventListener("touchmove", onMove);
|
|
409
|
+
document.body.removeEventListener("mouseup", stopDragging);
|
|
332
410
|
};
|
|
333
411
|
}, [
|
|
334
412
|
direction,
|
|
335
413
|
disabled,
|
|
336
414
|
isDragging,
|
|
337
|
-
resizeHandler
|
|
415
|
+
resizeHandler,
|
|
416
|
+
stopDragging
|
|
338
417
|
]);
|
|
339
418
|
return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
|
|
340
419
|
className: className,
|
|
341
420
|
"data-panel-group-id": groupId,
|
|
342
421
|
"data-panel-resize-handle-id": id,
|
|
343
|
-
onMouseDown: ()=>
|
|
344
|
-
onMouseUp:
|
|
422
|
+
onMouseDown: ()=>startDragging(id),
|
|
423
|
+
onMouseUp: stopDragging,
|
|
424
|
+
onTouchCancel: stopDragging,
|
|
425
|
+
onTouchEnd: stopDragging,
|
|
426
|
+
onTouchStart: ()=>startDragging(id),
|
|
345
427
|
style: {
|
|
346
|
-
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
|
|
428
|
+
cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
|
|
429
|
+
touchAction: "none"
|
|
347
430
|
},
|
|
348
431
|
children: children
|
|
349
432
|
}, void 0, false, {
|
|
350
433
|
fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
|
|
351
|
-
lineNumber:
|
|
434
|
+
lineNumber: 80,
|
|
352
435
|
columnNumber: 5
|
|
353
436
|
}, this);
|
|
354
437
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,0BAAY,EAOnC,IAAI;;;ADJC,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;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M,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,uBAAqB;QACrB,+BAA6B;QAC7B,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/hooks/useUniqueId.ts","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 groupId: string;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (id: 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\";\nimport useUniqueId from \"./hooks/useUniqueId\";\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 groupId = useUniqueId();\n\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 (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 context = useMemo(\n () => ({\n direction,\n getPanelStyle,\n groupId,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n groupId,\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 { useRef } from \"react\";\n\nlet counter = 0;\n\nexport default function useUniqueId(): string {\n const idRef = useRef<number | null>(null);\n if (idRef.current === null) {\n idRef.current = counter++;\n }\n\n return \"\" + idRef.current;\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport useUniqueId from \"./hooks/useUniqueId\";\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\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 id = useUniqueId();\n\n const { direction, groupId, registerResizeHandle } = context;\n\n const setGroupId = useState<string | null>(null);\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 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 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 data-panel-group-id={groupId}\n data-panel-resize-handle-id={id}\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,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;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;YAC9D,aAAa;QACf;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/utils/touch.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, ResizeEvent } from \"./types\";\nimport { loadPanelLayout, savePanelGroupLayout } from \"./utils/serialization\";\nimport { Coordinates, getUpdatedCoordinates } from \"./utils/touch\";\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\n // Tracks the most recent coordinates of a touch/mouse event.\n // This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).\n const prevCoordinatesRef = useRef<Coordinates>({\n screenX: 0,\n screenY: 0,\n });\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: ResizeEvent) => {\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 nextCoordinates = getUpdatedCoordinates(\n event,\n prevCoordinatesRef.current\n );\n prevCoordinatesRef.current = {\n screenX: nextCoordinates.screenX,\n screenY: nextCoordinates.screenY,\n };\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal\n ? nextCoordinates.movementX\n : nextCoordinates.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: () => {\n setActiveHandleId(null);\n prevCoordinatesRef.current = {\n screenX: 0,\n screenY: 0,\n };\n },\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 { ResizeEvent } from \"../types\";\n\nexport type Coordinates = {\n screenX: number;\n screenY: number;\n};\n\nexport type Movement = {\n movementX: number;\n movementY: number;\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX\nexport function getUpdatedCoordinates(\n event: ResizeEvent,\n prevCoordinates: Coordinates\n): Coordinates & Movement {\n const { screenX: prevScreenX, screenY: prevScreenY } = prevCoordinates;\n\n const getMovementBetween = (current: number, prev: number) =>\n prev === 0 ? 0 : current - prev;\n\n if (isTouchMoveEvent(event)) {\n const firstTouch = event.touches[0];\n\n return {\n movementX: getMovementBetween(firstTouch.screenX, prevScreenX),\n movementY: getMovementBetween(firstTouch.screenY, prevScreenY),\n screenX: firstTouch.screenX,\n screenY: firstTouch.screenY,\n };\n }\n\n return {\n movementX: getMovementBetween(event.screenX, prevScreenX),\n movementY: getMovementBetween(event.screenY, prevScreenY),\n screenX: event.screenX,\n screenY: event.screenY,\n };\n}\n\nexport function isTouchMoveEvent(event: ResizeEvent): event is TouchEvent {\n return event.type === \"touchmove\";\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport useUniqueId from \"./hooks/useUniqueId\";\nimport { PanelContext, PanelGroupContext } from \"./PanelContexts\";\nimport type { ResizeHandler, ResizeEvent } 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 onMove = (event: ResizeEvent) => {\n resizeHandler(event);\n };\n\n document.body.addEventListener(\"mouseleave\", stopDragging);\n document.body.addEventListener(\"mousemove\", onMove);\n document.body.addEventListener(\"touchmove\", onMove);\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\", onMove);\n document.body.removeEventListener(\"touchmove\", onMove);\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 onTouchCancel={stopDragging}\n onTouchEnd={stopDragging}\n onTouchStart={() => startDragging(id)}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n touchAction: \"none\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.js.map","sourceRoot":"../../../"}
|