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.
@@ -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,18 +51,70 @@ function $ad28bce87b00c2be$export$2e2bcd8739ae039({ children: children = null ,
50
51
 
51
52
 
52
53
 
54
+
53
55
  let $968185313205dcfa$var$counter = 0;
54
- function $968185313205dcfa$export$2e2bcd8739ae039() {
55
- const idRef = (0, $fpI56$useRef)(null);
56
- if (idRef.current === null) idRef.current = $968185313205dcfa$var$counter++;
57
- return "" + idRef.current;
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
+ }
58
87
  }
59
88
 
60
89
 
90
+ function $4b6140a59f4bd98c$export$70637efcd850e4ef(event, prevCoordinates) {
91
+ const { screenX: prevScreenX , screenY: prevScreenY } = prevCoordinates;
92
+ const getMovementBetween = (current, prev)=>prev === 0 ? 0 : current - prev;
93
+ if ($4b6140a59f4bd98c$export$ce897e7f0aa63661(event)) {
94
+ const firstTouch = event.touches[0];
95
+ return {
96
+ movementX: getMovementBetween(firstTouch.screenX, prevScreenX),
97
+ movementY: getMovementBetween(firstTouch.screenY, prevScreenY),
98
+ screenX: firstTouch.screenX,
99
+ screenY: firstTouch.screenY
100
+ };
101
+ }
102
+ return {
103
+ movementX: getMovementBetween(event.screenX, prevScreenX),
104
+ movementY: getMovementBetween(event.screenY, prevScreenY),
105
+ screenX: event.screenX,
106
+ screenY: event.screenY
107
+ };
108
+ }
109
+ function $4b6140a59f4bd98c$export$ce897e7f0aa63661(event) {
110
+ return event.type === "touchmove";
111
+ }
112
+
61
113
 
62
114
  const $c44ee3356398c8a1$var$PRECISION = 5;
63
115
  function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
64
116
  const groupId = (0, $968185313205dcfa$export$2e2bcd8739ae039)();
117
+ const [activeHandleId, setActiveHandleId] = (0, $fpI56$useState)(null);
65
118
  const [panels, setPanels] = (0, $fpI56$useState)(new Map());
66
119
  // 0-1 values representing the relative size of each panel.
67
120
  const [sizes, setSizes] = (0, $fpI56$useState)([]);
@@ -73,6 +126,12 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
73
126
  sizes: sizes,
74
127
  width: width
75
128
  });
129
+ // Tracks the most recent coordinates of a touch/mouse event.
130
+ // This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).
131
+ const prevCoordinatesRef = (0, $fpI56$useRef)({
132
+ screenX: 0,
133
+ screenY: 0
134
+ });
76
135
  (0, $fpI56$useLayoutEffect)(()=>{
77
136
  committedValuesRef.current.direction = direction;
78
137
  committedValuesRef.current.height = height;
@@ -91,10 +150,10 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
91
150
  // If this panel has been configured to persist sizing information,
92
151
  // default size should be restored from local storage if possible.
93
152
  let defaultSizes = undefined;
94
- if (autoSaveId) try {
95
- const value = localStorage.getItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels));
96
- if (value) defaultSizes = JSON.parse(value);
97
- } catch (error) {}
153
+ if (autoSaveId) {
154
+ const panelIds = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
155
+ defaultSizes = (0, $6ff1a22b27cc039d$export$9c80c6617f0386da)(autoSaveId, panelIds);
156
+ }
98
157
  if (defaultSizes != null) setSizes(defaultSizes);
99
158
  else {
100
159
  const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
@@ -108,10 +167,11 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
108
167
  panels
109
168
  ]);
110
169
  (0, $fpI56$useEffect)(()=>{
170
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
111
171
  if (autoSaveId) {
112
172
  if (sizes.length === 0 || sizes.length !== panels.size) return;
113
- // If this panel has been configured to persist sizing information, save sizes to local storage.
114
- localStorage.setItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels), JSON.stringify(sizes));
173
+ const panelIds = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels).map((panel)=>panel.id);
174
+ (0, $6ff1a22b27cc039d$export$af183b313c61be4f)(autoSaveId, panelIds, sizes);
115
175
  }
116
176
  }, [
117
177
  autoSaveId,
@@ -161,8 +221,13 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
161
221
  const idBefore = panelsArray[index]?.id ?? null;
162
222
  const idAfter = panelsArray[index + 1]?.id ?? null;
163
223
  if (idBefore == null || idAfter == null) return;
224
+ const nextCoordinates = (0, $4b6140a59f4bd98c$export$70637efcd850e4ef)(event, prevCoordinatesRef.current);
225
+ prevCoordinatesRef.current = {
226
+ screenX: nextCoordinates.screenX,
227
+ screenY: nextCoordinates.screenY
228
+ };
164
229
  const isHorizontal = direction === "horizontal";
165
- const movement = isHorizontal ? event.movementX : event.movementY;
230
+ const movement = isHorizontal ? nextCoordinates.movementX : nextCoordinates.movementY;
166
231
  const delta = isHorizontal ? movement / width : movement / height;
167
232
  const nextSizes = $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
168
233
  if (prevSizes !== nextSizes) setSizes(nextSizes);
@@ -179,12 +244,20 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
179
244
  return nextPanels;
180
245
  });
181
246
  }, []);
182
- const context = (0, $fpI56$useMemo)(()=>({
247
+ const panelGroupContext = (0, $fpI56$useMemo)(()=>({
183
248
  direction: direction,
184
249
  getPanelStyle: getPanelStyle,
185
250
  groupId: groupId,
186
251
  registerPanel: registerPanel,
187
252
  registerResizeHandle: registerResizeHandle,
253
+ startDragging: (id)=>setActiveHandleId(id),
254
+ stopDragging: ()=>{
255
+ setActiveHandleId(null);
256
+ prevCoordinatesRef.current = {
257
+ screenX: 0,
258
+ screenY: 0
259
+ };
260
+ },
188
261
  unregisterPanel: unregisterPanel
189
262
  }), [
190
263
  direction,
@@ -194,19 +267,31 @@ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
194
267
  registerResizeHandle,
195
268
  unregisterPanel
196
269
  ]);
197
- return /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$7d8c6d083caec74a).Provider, {
198
- value: context,
199
- children: /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
200
- className: className,
201
- children: children
270
+ const panelContext = (0, $fpI56$useMemo)(()=>({
271
+ activeHandleId: activeHandleId
272
+ }), [
273
+ activeHandleId
274
+ ]);
275
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$f34532ac99e32150).Provider, {
276
+ value: panelContext,
277
+ children: /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$7d8c6d083caec74a).Provider, {
278
+ value: panelGroupContext,
279
+ children: /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
280
+ className: className,
281
+ children: children
282
+ }, void 0, false, {
283
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
284
+ lineNumber: 273,
285
+ columnNumber: 9
286
+ }, this)
202
287
  }, void 0, false, {
203
288
  fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
204
- lineNumber: 243,
289
+ lineNumber: 272,
205
290
  columnNumber: 7
206
291
  }, this)
207
292
  }, void 0, false, {
208
293
  fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
209
- lineNumber: 242,
294
+ lineNumber: 271,
210
295
  columnNumber: 5
211
296
  }, this);
212
297
  }
@@ -248,11 +333,6 @@ function $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, p
248
333
  nextSizes[index] = prevSizes[index] + deltaApplied;
249
334
  return nextSizes;
250
335
  }
251
- function $c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels) {
252
- const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
253
- const panelIds = panelsArray.map((panel)=>panel.id);
254
- return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
255
- }
256
336
  function $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width) {
257
337
  const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
258
338
  let index = panelsArray.findIndex((panel)=>panel.id === id);
@@ -282,14 +362,15 @@ function $c44ee3356398c8a1$var$panelsMapToSortedArray(panels) {
282
362
 
283
363
 
284
364
 
285
- function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false }) {
286
- const context = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
287
- if (context === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
288
- const id = (0, $968185313205dcfa$export$2e2bcd8739ae039)();
289
- const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle } = context;
290
- const setGroupId = (0, $fpI56$useState)(null);
365
+ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idProp = null }) {
366
+ const panelContext = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$f34532ac99e32150));
367
+ const panelGroupContext = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
368
+ if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
369
+ const id = (0, $968185313205dcfa$export$2e2bcd8739ae039)(idProp);
370
+ const { activeHandleId: activeHandleId } = panelContext;
371
+ const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
372
+ const isDragging = activeHandleId === id;
291
373
  const [resizeHandler, setResizeHandler] = (0, $fpI56$useState)(null);
292
- const [isDragging, setIsDragging] = (0, $fpI56$useState)(false);
293
374
  (0, $fpI56$useEffect)(()=>{
294
375
  if (disabled) setResizeHandler(null);
295
376
  else {
@@ -305,43 +386,44 @@ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null ,
305
386
  (0, $fpI56$useEffect)(()=>{
306
387
  if (disabled || resizeHandler == null || !isDragging) return;
307
388
  document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
308
- const onMouseLeave = (_)=>{
309
- setIsDragging(false);
310
- };
311
- const onMouseMove = (event)=>{
389
+ const onMove = (event)=>{
312
390
  resizeHandler(event);
313
391
  };
314
- const onMouseUp = (_)=>{
315
- setIsDragging(false);
316
- };
317
- document.body.addEventListener("mouseleave", onMouseLeave);
318
- document.body.addEventListener("mousemove", onMouseMove);
319
- document.body.addEventListener("mouseup", onMouseUp);
392
+ document.body.addEventListener("mouseleave", stopDragging);
393
+ document.body.addEventListener("mousemove", onMove);
394
+ document.body.addEventListener("touchmove", onMove);
395
+ document.body.addEventListener("mouseup", stopDragging);
320
396
  return ()=>{
321
397
  document.body.style.cursor = "";
322
- document.body.removeEventListener("mouseleave", onMouseLeave);
323
- document.body.removeEventListener("mousemove", onMouseMove);
324
- document.body.removeEventListener("mouseup", onMouseUp);
398
+ document.body.removeEventListener("mouseleave", stopDragging);
399
+ document.body.removeEventListener("mousemove", onMove);
400
+ document.body.removeEventListener("touchmove", onMove);
401
+ document.body.removeEventListener("mouseup", stopDragging);
325
402
  };
326
403
  }, [
327
404
  direction,
328
405
  disabled,
329
406
  isDragging,
330
- resizeHandler
407
+ resizeHandler,
408
+ stopDragging
331
409
  ]);
332
410
  return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
333
411
  className: className,
334
412
  "data-panel-group-id": groupId,
335
413
  "data-panel-resize-handle-id": id,
336
- onMouseDown: ()=>setIsDragging(true),
337
- onMouseUp: ()=>setIsDragging(false),
414
+ onMouseDown: ()=>startDragging(id),
415
+ onMouseUp: stopDragging,
416
+ onTouchCancel: stopDragging,
417
+ onTouchEnd: stopDragging,
418
+ onTouchStart: ()=>startDragging(id),
338
419
  style: {
339
- cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
420
+ cursor: direction === "horizontal" ? "ew-resize" : "ns-resize",
421
+ touchAction: "none"
340
422
  },
341
423
  children: children
342
424
  }, void 0, false, {
343
425
  fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
344
- lineNumber: 76,
426
+ lineNumber: 80,
345
427
  columnNumber: 5
346
428
  }, this);
347
429
  }
@@ -349,5 +431,5 @@ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null ,
349
431
 
350
432
 
351
433
 
352
- export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
434
+ export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $f922724f4bad4884$export$f34532ac99e32150 as PanelContext, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
353
435
  //# sourceMappingURL=react-resizable-panels.module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,oBAAY,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,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;QAAI,WAAW;QAAW,OAAO;kBAC/B;;;;;;AAGP;;AD7DA;AGAA;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AC,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,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.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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AGP;","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.module.js.map","sourceRoot":"../../../"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -2,11 +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;
8
12
  groupId: string;
9
13
  registerPanel: (id: string, panel: PanelData) => void;
10
14
  registerResizeHandle: (id: string) => ResizeHandler;
15
+ startDragging: (id: string) => void;
16
+ stopDragging: () => void;
11
17
  unregisterPanel: (id: string) => void;
12
18
  } | null>(null);
@@ -10,8 +10,10 @@ import {
10
10
  } from "react";
11
11
  import useUniqueId from "./hooks/useUniqueId";
12
12
 
13
- import { PanelGroupContext } from "./PanelContexts";
14
- import { Direction, PanelData } from "./types";
13
+ import { PanelContext, PanelGroupContext } from "./PanelContexts";
14
+ import { Direction, PanelData, ResizeEvent } from "./types";
15
+ import { loadPanelLayout, savePanelGroupLayout } from "./utils/serialization";
16
+ import { Coordinates, getUpdatedCoordinates } from "./utils/touch";
15
17
 
16
18
  type Props = {
17
19
  autoSaveId?: string;
@@ -38,6 +40,7 @@ export default function PanelGroup({
38
40
  }: Props) {
39
41
  const groupId = useUniqueId();
40
42
 
43
+ const [activeHandleId, setActiveHandleId] = useState<string | null>(null);
41
44
  const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());
42
45
 
43
46
  // 0-1 values representing the relative size of each panel.
@@ -57,6 +60,14 @@ export default function PanelGroup({
57
60
  sizes,
58
61
  width,
59
62
  });
63
+
64
+ // Tracks the most recent coordinates of a touch/mouse event.
65
+ // This is needed to calculate movement (because TouchEvent doesn't support movementX and movementY).
66
+ const prevCoordinatesRef = useRef<Coordinates>({
67
+ screenX: 0,
68
+ screenY: 0,
69
+ });
70
+
60
71
  useLayoutEffect(() => {
61
72
  committedValuesRef.current.direction = direction;
62
73
  committedValuesRef.current.height = height;
@@ -81,14 +92,8 @@ export default function PanelGroup({
81
92
  // default size should be restored from local storage if possible.
82
93
  let defaultSizes: number[] | undefined = undefined;
83
94
  if (autoSaveId) {
84
- try {
85
- const value = localStorage.getItem(
86
- createLocalStorageKey(autoSaveId, panels)
87
- );
88
- if (value) {
89
- defaultSizes = JSON.parse(value);
90
- }
91
- } catch (error) {}
95
+ const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);
96
+ defaultSizes = loadPanelLayout(autoSaveId, panelIds);
92
97
  }
93
98
 
94
99
  if (defaultSizes != null) {
@@ -104,16 +109,14 @@ export default function PanelGroup({
104
109
  }, [autoSaveId, panels]);
105
110
 
106
111
  useEffect(() => {
112
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
107
113
  if (autoSaveId) {
108
114
  if (sizes.length === 0 || sizes.length !== panels.size) {
109
115
  return;
110
116
  }
111
117
 
112
- // If this panel has been configured to persist sizing information, save sizes to local storage.
113
- localStorage.setItem(
114
- createLocalStorageKey(autoSaveId, panels),
115
- JSON.stringify(sizes)
116
- );
118
+ const panelIds = panelsMapToSortedArray(panels).map((panel) => panel.id);
119
+ savePanelGroupLayout(autoSaveId, panelIds, sizes);
117
120
  }
118
121
  }, [autoSaveId, panels, sizes]);
119
122
 
@@ -160,7 +163,7 @@ export default function PanelGroup({
160
163
 
161
164
  const registerResizeHandle = useCallback(
162
165
  (id: string) => {
163
- const resizeHandler = (event: MouseEvent) => {
166
+ const resizeHandler = (event: ResizeEvent) => {
164
167
  event.preventDefault();
165
168
 
166
169
  const {
@@ -185,8 +188,19 @@ export default function PanelGroup({
185
188
  return;
186
189
  }
187
190
 
191
+ const nextCoordinates = getUpdatedCoordinates(
192
+ event,
193
+ prevCoordinatesRef.current
194
+ );
195
+ prevCoordinatesRef.current = {
196
+ screenX: nextCoordinates.screenX,
197
+ screenY: nextCoordinates.screenY,
198
+ };
199
+
188
200
  const isHorizontal = direction === "horizontal";
189
- const movement = isHorizontal ? event.movementX : event.movementY;
201
+ const movement = isHorizontal
202
+ ? nextCoordinates.movementX
203
+ : nextCoordinates.movementY;
190
204
  const delta = isHorizontal ? movement / width : movement / height;
191
205
 
192
206
  const nextSizes = adjustByDelta(
@@ -219,13 +233,21 @@ export default function PanelGroup({
219
233
  });
220
234
  }, []);
221
235
 
222
- const context = useMemo(
236
+ const panelGroupContext = useMemo(
223
237
  () => ({
224
238
  direction,
225
239
  getPanelStyle,
226
240
  groupId,
227
241
  registerPanel,
228
242
  registerResizeHandle,
243
+ startDragging: (id: string) => setActiveHandleId(id),
244
+ stopDragging: () => {
245
+ setActiveHandleId(null);
246
+ prevCoordinatesRef.current = {
247
+ screenX: 0,
248
+ screenY: 0,
249
+ };
250
+ },
229
251
  unregisterPanel,
230
252
  }),
231
253
  [
@@ -238,10 +260,19 @@ export default function PanelGroup({
238
260
  ]
239
261
  );
240
262
 
263
+ const panelContext = useMemo(
264
+ () => ({
265
+ activeHandleId,
266
+ }),
267
+ [activeHandleId]
268
+ );
269
+
241
270
  return (
242
- <PanelGroupContext.Provider value={context}>
243
- <div className={className}>{children}</div>
244
- </PanelGroupContext.Provider>
271
+ <PanelContext.Provider value={panelContext}>
272
+ <PanelGroupContext.Provider value={panelGroupContext}>
273
+ <div className={className}>{children}</div>
274
+ </PanelGroupContext.Provider>
275
+ </PanelContext.Provider>
245
276
  );
246
277
  }
247
278
 
@@ -310,16 +341,6 @@ function adjustByDelta(
310
341
  return nextSizes;
311
342
  }
312
343
 
313
- function createLocalStorageKey(
314
- autoSaveId: string,
315
- panels: Map<string, PanelData>
316
- ): string {
317
- const panelsArray = panelsMapToSortedArray(panels);
318
- const panelIds = panelsArray.map((panel) => panel.id);
319
-
320
- return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
321
- }
322
-
323
344
  function getOffset(
324
345
  panels: Map<string, PanelData>,
325
346
  id: string,