react-resizable-panels 0.0.2 → 0.0.4

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.
@@ -1,94 +1,117 @@
1
- import {jsx as $hgUW1$jsx} from "react/jsx-runtime";
2
- import {useContext as $hgUW1$useContext, useLayoutEffect as $hgUW1$useLayoutEffect, createContext as $hgUW1$createContext, useRef as $hgUW1$useRef, useState as $hgUW1$useState, useEffect as $hgUW1$useEffect, useCallback as $hgUW1$useCallback, useMemo as $hgUW1$useMemo} from "react";
1
+ import {jsxDEV as $fpI56$jsxDEV} from "react/jsx-dev-runtime";
2
+ import {useContext as $fpI56$useContext, useLayoutEffect as $fpI56$useLayoutEffect, createContext as $fpI56$createContext, useState as $fpI56$useState, useRef as $fpI56$useRef, useEffect as $fpI56$useEffect, useCallback as $fpI56$useCallback, useMemo as $fpI56$useMemo} from "react";
3
3
 
4
4
 
5
5
 
6
6
 
7
- const $3a3142702e7d9c06$export$7d8c6d083caec74a = (0, $hgUW1$createContext)(null);
7
+ const $f922724f4bad4884$export$7d8c6d083caec74a = (0, $fpI56$createContext)(null);
8
8
 
9
9
 
10
- function $be6cfb11a13b6f3f$export$2e2bcd8739ae039({ children: children , className: className = "" , defaultSize: defaultSize = 0.1 , id: id , minSize: minSize = 0.1 }) {
11
- const context = (0, $hgUW1$useContext)((0, $3a3142702e7d9c06$export$7d8c6d083caec74a));
10
+ function $ad28bce87b00c2be$export$2e2bcd8739ae039({ children: children = null , className: className = "" , defaultSize: defaultSize = 0.1 , id: id , minSize: minSize = 0.1 , order: order = null }) {
11
+ const context = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
12
12
  if (context === null) throw Error(`Panel components must be rendered within a PanelGroup container`);
13
- const { getPanelStyle: getPanelStyle , registerPanel: registerPanel } = context;
14
- (0, $hgUW1$useLayoutEffect)(()=>{
13
+ if (minSize > defaultSize) {
14
+ console.error(`Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`);
15
+ defaultSize = minSize;
16
+ }
17
+ const { getPanelStyle: getPanelStyle , registerPanel: registerPanel , unregisterPanel: unregisterPanel } = context;
18
+ (0, $fpI56$useLayoutEffect)(()=>{
15
19
  const panel = {
16
20
  defaultSize: defaultSize,
17
21
  id: id,
18
- minSize: minSize
22
+ minSize: minSize,
23
+ order: order
19
24
  };
20
25
  registerPanel(id, panel);
26
+ return ()=>{
27
+ unregisterPanel(id);
28
+ };
21
29
  }, [
22
30
  defaultSize,
31
+ id,
23
32
  minSize,
33
+ order,
24
34
  registerPanel,
25
- id
35
+ unregisterPanel
26
36
  ]);
27
37
  const style = getPanelStyle(id);
28
- return /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
38
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
29
39
  className: className,
30
40
  style: style,
31
41
  children: children
32
- });
42
+ }, void 0, false, {
43
+ fileName: "packages/react-resizable-panels/src/Panel.tsx",
44
+ lineNumber: 58,
45
+ columnNumber: 5
46
+ }, this);
33
47
  }
34
48
 
35
49
 
36
50
 
37
51
 
38
52
 
39
- const $87c6267876d46c1c$var$PRECISION = 5;
40
- function $87c6267876d46c1c$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children , className: className = "" , direction: direction , height: height , width: width }) {
41
- const panelsRef = (0, $hgUW1$useRef)([]);
53
+ const $c44ee3356398c8a1$var$PRECISION = 5;
54
+ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
55
+ const [panels, setPanels] = (0, $fpI56$useState)(new Map());
42
56
  // 0-1 values representing the relative size of each panel.
43
- const [sizes, setSizes] = (0, $hgUW1$useState)([]);
57
+ const [sizes, setSizes] = (0, $fpI56$useState)([]);
44
58
  // Store committed values to avoid unnecessarily re-running memoization/effects functions.
45
- const committedValuesRef = (0, $hgUW1$useRef)({
59
+ const committedValuesRef = (0, $fpI56$useRef)({
46
60
  direction: direction,
47
61
  height: height,
62
+ panels: panels,
48
63
  sizes: sizes,
49
64
  width: width
50
65
  });
51
- (0, $hgUW1$useLayoutEffect)(()=>{
66
+ (0, $fpI56$useLayoutEffect)(()=>{
52
67
  committedValuesRef.current.direction = direction;
53
68
  committedValuesRef.current.height = height;
69
+ committedValuesRef.current.panels = panels;
54
70
  committedValuesRef.current.sizes = sizes;
55
71
  committedValuesRef.current.width = width;
56
72
  });
57
73
  // Once all panels have registered themselves,
58
74
  // Compute the initial sizes based on default weights.
59
75
  // This assumes that panels register during initial mount (no conditional rendering)!
60
- (0, $hgUW1$useLayoutEffect)(()=>{
61
- const panels = panelsRef.current;
76
+ (0, $fpI56$useLayoutEffect)(()=>{
62
77
  const sizes = committedValuesRef.current.sizes;
63
- if (sizes.length === panels.length) return;
78
+ if (sizes.length === panels.size) return;
79
+ // TODO [panels]
80
+ // Validate that the total minSize is <= 1.
64
81
  // If this panel has been configured to persist sizing information,
65
82
  // default size should be restored from local storage if possible.
66
83
  let defaultSizes = undefined;
67
84
  if (autoSaveId) try {
68
- const value = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
85
+ const value = localStorage.getItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels));
69
86
  if (value) defaultSizes = JSON.parse(value);
70
87
  } catch (error) {}
71
- if (sizes.length === 0 && defaultSizes != null && defaultSizes.length === panels.length) setSizes(defaultSizes);
88
+ if (defaultSizes != null) setSizes(defaultSizes);
72
89
  else {
73
- const totalWeight = panels.reduce((weight, panel)=>{
90
+ const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
91
+ const totalWeight = panelsArray.reduce((weight, panel)=>{
74
92
  return weight + panel.defaultSize;
75
93
  }, 0);
76
- setSizes(panels.map((panel)=>panel.defaultSize / totalWeight));
94
+ setSizes(panelsArray.map((panel)=>panel.defaultSize / totalWeight));
77
95
  }
78
96
  }, [
79
- autoSaveId
97
+ autoSaveId,
98
+ panels
80
99
  ]);
81
- (0, $hgUW1$useEffect)(()=>{
82
- if (autoSaveId && sizes.length > 0) // If this panel has been configured to persist sizing information, save sizes to local storage.
83
- localStorage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(sizes));
100
+ (0, $fpI56$useEffect)(()=>{
101
+ if (autoSaveId) {
102
+ if (sizes.length === 0 || sizes.length !== panels.size) return;
103
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
104
+ localStorage.setItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels), JSON.stringify(sizes));
105
+ }
84
106
  }, [
85
107
  autoSaveId,
108
+ panels,
86
109
  sizes
87
110
  ]);
88
- const getPanelStyle = (0, $hgUW1$useCallback)((id)=>{
89
- const panels = panelsRef.current;
90
- const offset = $87c6267876d46c1c$var$getOffset(panels, id, direction, sizes, height, width);
91
- const size = $87c6267876d46c1c$var$getSize(panels, id, direction, sizes, height, width);
111
+ const getPanelStyle = (0, $fpI56$useCallback)((id)=>{
112
+ const { panels: panels } = committedValuesRef.current;
113
+ const offset = $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width);
114
+ const size = $c44ee3356398c8a1$var$getSize(panels, id, direction, sizes, height, width);
92
115
  if (direction === "horizontal") return {
93
116
  height: "100%",
94
117
  position: "absolute",
@@ -109,45 +132,66 @@ function $87c6267876d46c1c$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
109
132
  sizes,
110
133
  width
111
134
  ]);
112
- const registerPanel = (0, $hgUW1$useCallback)((id, panel)=>{
113
- const panels = panelsRef.current;
114
- const index = panels.findIndex((panel)=>panel.id === id);
115
- if (index >= 0) panels.splice(index, 1);
116
- panels.push(panel);
135
+ const registerPanel = (0, $fpI56$useCallback)((id, panel)=>{
136
+ setPanels((prevPanels)=>{
137
+ if (prevPanels.has(id)) return prevPanels;
138
+ const nextPanels = new Map(prevPanels);
139
+ nextPanels.set(id, panel);
140
+ return nextPanels;
141
+ });
117
142
  }, []);
118
- const registerResizeHandle = (0, $hgUW1$useCallback)((idBefore, idAfter)=>{
143
+ const registerResizeHandle = (0, $fpI56$useCallback)((idBefore, idAfter)=>{
119
144
  return (event)=>{
120
145
  event.preventDefault();
121
- const panels = panelsRef.current;
122
- const { direction: direction , height: height , sizes: prevSizes , width: width } = committedValuesRef.current;
146
+ const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
123
147
  const isHorizontal = direction === "horizontal";
124
148
  const movement = isHorizontal ? event.movementX : event.movementY;
125
149
  const delta = isHorizontal ? movement / width : movement / height;
126
- const nextSizes = $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
150
+ const nextSizes = $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
127
151
  if (prevSizes !== nextSizes) setSizes(nextSizes);
128
152
  };
153
+ // TODO [issues/5] Add to Map
154
+ }, []);
155
+ const unregisterPanel = (0, $fpI56$useCallback)((id)=>{
156
+ setPanels((prevPanels)=>{
157
+ if (!prevPanels.has(id)) return prevPanels;
158
+ const nextPanels = new Map(prevPanels);
159
+ nextPanels.delete(id);
160
+ return nextPanels;
161
+ });
129
162
  }, []);
130
- const context = (0, $hgUW1$useMemo)(()=>({
163
+ const context = (0, $fpI56$useMemo)(()=>({
131
164
  direction: direction,
132
165
  getPanelStyle: getPanelStyle,
133
166
  registerPanel: registerPanel,
134
- registerResizeHandle: registerResizeHandle
167
+ registerResizeHandle: registerResizeHandle,
168
+ unregisterPanel: unregisterPanel
135
169
  }), [
136
170
  direction,
137
171
  getPanelStyle,
138
172
  registerPanel,
139
- registerResizeHandle
173
+ registerResizeHandle,
174
+ unregisterPanel
140
175
  ]);
141
- return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $3a3142702e7d9c06$export$7d8c6d083caec74a).Provider, {
176
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$7d8c6d083caec74a).Provider, {
142
177
  value: context,
143
- children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
178
+ children: /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
144
179
  className: className,
145
180
  children: children
146
- })
147
- });
181
+ }, void 0, false, {
182
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
183
+ lineNumber: 224,
184
+ columnNumber: 7
185
+ }, this)
186
+ }, void 0, false, {
187
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
188
+ lineNumber: 223,
189
+ columnNumber: 5
190
+ }, this);
148
191
  }
149
- function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
192
+ function $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
150
193
  if (delta === 0) return prevSizes;
194
+ const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
151
195
  const nextSizes = prevSizes.concat();
152
196
  let deltaApplied = 0;
153
197
  // A resizing panel affects the panels before or after it.
@@ -158,20 +202,20 @@ function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, p
158
202
  // A positive delta means the panel immediately before the resizer should "expand".
159
203
  // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
160
204
  let pivotId = delta < 0 ? idBefore : idAfter;
161
- let index = panels.findIndex((panel)=>panel.id === pivotId);
205
+ let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
162
206
  while(true){
163
- const panel = panels[index];
207
+ const panel = panelsArray[index];
164
208
  const prevSize = prevSizes[index];
165
209
  const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
166
210
  if (prevSize !== nextSize) {
167
211
  deltaApplied += prevSize - nextSize;
168
212
  nextSizes[index] = nextSize;
169
- if (deltaApplied.toPrecision($87c6267876d46c1c$var$PRECISION) >= delta.toPrecision($87c6267876d46c1c$var$PRECISION)) break;
213
+ if (deltaApplied.toPrecision($c44ee3356398c8a1$var$PRECISION) >= delta.toPrecision($c44ee3356398c8a1$var$PRECISION)) break;
170
214
  }
171
215
  if (delta < 0) {
172
216
  if (--index < 0) break;
173
217
  } else {
174
- if (++index >= panels.length) break;
218
+ if (++index >= panelsArray.length) break;
175
219
  }
176
220
  }
177
221
  // If we were unable to resize any of the panels panels, return the previous state.
@@ -179,40 +223,50 @@ function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, p
179
223
  if (deltaApplied === 0) return prevSizes;
180
224
  // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
181
225
  pivotId = delta < 0 ? idAfter : idBefore;
182
- index = panels.findIndex((panel)=>panel.id === pivotId);
226
+ index = panelsArray.findIndex((panel)=>panel.id === pivotId);
183
227
  nextSizes[index] = prevSizes[index] + deltaApplied;
184
228
  return nextSizes;
185
229
  }
186
- function $87c6267876d46c1c$var$getOffset(panels, id, direction, sizes, height, width) {
187
- let index = panels.findIndex((panel)=>panel.id === id);
230
+ function $c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels) {
231
+ const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
232
+ const panelIds = panelsArray.map((panel)=>panel.id);
233
+ return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
234
+ }
235
+ function $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width) {
236
+ const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
237
+ let index = panelsArray.findIndex((panel)=>panel.id === id);
188
238
  if (index < 0) return 0;
189
239
  let scaledOffset = 0;
190
240
  for(index = index - 1; index >= 0; index--){
191
- const panel = panels[index];
192
- scaledOffset += $87c6267876d46c1c$var$getSize(panels, panel.id, direction, sizes, height, width);
241
+ const panel = panelsArray[index];
242
+ scaledOffset += $c44ee3356398c8a1$var$getSize(panels, panel.id, direction, sizes, height, width);
193
243
  }
194
244
  return Math.round(scaledOffset);
195
245
  }
196
- function $87c6267876d46c1c$var$getSize(panels, id, direction, sizes, height, width) {
197
- const index = panels.findIndex((panel)=>panel.id === id);
246
+ function $c44ee3356398c8a1$var$getSize(panels, id, direction, sizes, height, width) {
247
+ const totalSize = direction === "horizontal" ? width : height;
248
+ if (panels.size === 1) return totalSize;
249
+ const panelsArray = $c44ee3356398c8a1$var$panelsMapToSortedArray(panels);
250
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
198
251
  const size = sizes[index];
199
252
  if (size == null) return 0;
200
- const totalSize = direction === "horizontal" ? width : height;
201
- if (panels.length === 1) return totalSize;
202
- else return Math.round(size * totalSize);
253
+ return Math.round(size * totalSize);
254
+ }
255
+ function $c44ee3356398c8a1$var$panelsMapToSortedArray(panels) {
256
+ return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
203
257
  }
204
258
 
205
259
 
206
260
 
207
261
 
208
262
 
209
- function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , panelAfter: panelAfter , panelBefore: panelBefore }) {
210
- const context = (0, $hgUW1$useContext)((0, $3a3142702e7d9c06$export$7d8c6d083caec74a));
263
+ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , panelAfter: panelAfter , panelBefore: panelBefore }) {
264
+ const context = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
211
265
  if (context === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
212
266
  const { direction: direction , registerResizeHandle: registerResizeHandle } = context;
213
- const [resizeHandler, setResizeHandler] = (0, $hgUW1$useState)(null);
214
- const [isDragging, setIsDragging] = (0, $hgUW1$useState)(false);
215
- (0, $hgUW1$useEffect)(()=>{
267
+ const [resizeHandler, setResizeHandler] = (0, $fpI56$useState)(null);
268
+ const [isDragging, setIsDragging] = (0, $fpI56$useState)(false);
269
+ (0, $fpI56$useEffect)(()=>{
216
270
  if (disabled) setResizeHandler(null);
217
271
  else setResizeHandler(()=>registerResizeHandle(panelBefore, panelAfter));
218
272
  }, [
@@ -221,7 +275,7 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
221
275
  panelBefore,
222
276
  registerResizeHandle
223
277
  ]);
224
- (0, $hgUW1$useEffect)(()=>{
278
+ (0, $fpI56$useEffect)(()=>{
225
279
  if (disabled || resizeHandler == null || !isDragging) return;
226
280
  document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
227
281
  const onMouseLeave = (_)=>{
@@ -248,7 +302,7 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
248
302
  isDragging,
249
303
  resizeHandler
250
304
  ]);
251
- return /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
305
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
252
306
  className: className,
253
307
  onMouseDown: ()=>setIsDragging(true),
254
308
  onMouseUp: ()=>setIsDragging(false),
@@ -256,11 +310,15 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
256
310
  cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
257
311
  },
258
312
  children: children
259
- });
313
+ }, void 0, false, {
314
+ fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
315
+ lineNumber: 75,
316
+ columnNumber: 5
317
+ }, this);
260
318
  }
261
319
 
262
320
 
263
321
 
264
322
 
265
- export {$be6cfb11a13b6f3f$export$2e2bcd8739ae039 as Panel, $87c6267876d46c1c$export$2e2bcd8739ae039 as PanelGroup, $74f1c1b08e3b0df5$export$2e2bcd8739ae039 as PanelResizeHandle};
323
+ export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
266
324
  //# sourceMappingURL=react-resizable-panels.module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,oBAAY,EAKnC,IAAI;;;ADDC,kDAAe,YAC5B,SAAQ,aACR,YAAY,kBACZ,cAAc,UACd,GAAE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AC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,gBAAC;QACC,WAAW;QACX,aAAa,IAAM,cAAc,IAAI;QACrC,WAAW,IAAM,cAAc,KAAK;QACpC,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;AAGP;;","sources":["src/index.ts","src/Panel.tsx","src/PanelContexts.ts","src/PanelGroup.tsx","src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { PanelId } from \"./types\";\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,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n}: {\n children: ReactNode;\n className?: string;\n defaultSize?: number;\n id: PanelId;\n minSize?: number;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(`Panel components must be rendered within a PanelGroup container`);\n }\n\n const { getPanelStyle, registerPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n };\n\n registerPanel(id, panel);\n }, [defaultSize, minSize, registerPanel, id]);\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 { Panel, PanelId, ResizeHandler } from \"./types\";\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: PanelId) => CSSProperties;\n registerResizeHandle: (idBefore: PanelId, idAfter: PanelId) => ResizeHandler;\n registerPanel: (id: PanelId, panel: Panel) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, Panel, PanelId } 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({ autoSaveId, children, className = \"\", direction, height, width }: Props) {\n const panelsRef = useRef<Panel[]>([]);\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 sizes: number[];\n width: number;\n }>({\n direction,\n height,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\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 panels = panelsRef.current;\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.length) {\n return;\n }\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(`PanelGroup:sizes:${autoSaveId}`);\n if (value) {\n defaultSizes = JSON.parse(value);\n }\n } catch (error) {}\n }\n\n if (sizes.length === 0 && defaultSizes != null && defaultSizes.length === panels.length) {\n setSizes(defaultSizes);\n } else {\n const totalWeight = panels.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panels.map(panel => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId]);\n\n useEffect(() => {\n if (autoSaveId && sizes.length > 0) {\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n localStorage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(sizes));\n }\n }, [autoSaveId, sizes]);\n\n const getPanelStyle = useCallback(\n (id: PanelId): CSSProperties => {\n const panels = panelsRef.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: PanelId, panel: Panel) => {\n const panels = panelsRef.current;\n const index = panels.findIndex(panel => panel.id === id);\n if (index >= 0) {\n panels.splice(index, 1);\n }\n panels.push(panel);\n }, []);\n\n const registerResizeHandle = useCallback((idBefore: PanelId, idAfter: PanelId) => {\n return (event: MouseEvent) => {\n event.preventDefault();\n\n const panels = panelsRef.current;\n const { direction, height, sizes: prevSizes, width } = committedValuesRef.current;\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n }, []);\n\n const context = useMemo(\n () => ({\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n }),\n [direction, getPanelStyle, registerPanel, registerResizeHandle]\n );\n\n return (\n <PanelGroupContext.Provider value={context}>\n <div className={className}>\n {children}\n </div>\n </PanelGroupContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Panel[],\n idBefore: PanelId,\n idAfter: PanelId,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\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 = panels.findIndex(panel => panel.id === pivotId);\n while (true) {\n const panel = panels[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 >= panels.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 = panels.findIndex(panel => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction getOffset(\n panels: Panel[],\n id: PanelId,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n let index = panels.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 = panels[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Panel[],\n id: PanelId,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const index = panels.findIndex(panel => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.length === 1) {\n return totalSize;\n } else {\n return Math.round(size * totalSize);\n }\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { PanelId, ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n panelAfter,\n panelBefore,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n panelAfter: PanelId;\n panelBefore: PanelId;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);\n }\n\n const { direction, registerResizeHandle } = context;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n setResizeHandler(() => registerResizeHandle(panelBefore, panelAfter));\n }\n }, [disabled, panelAfter, panelBefore, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor = direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseLeave = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n const onMouseUp = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n document.body.addEventListener(\"mouseleave\", onMouseLeave);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", onMouseUp);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", onMouseLeave);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", onMouseUp);\n };\n }, [direction, disabled, isDragging, resizeHandler]);\n\n return (\n <div\n className={className}\n onMouseDown={() => setIsDragging(true)}\n onMouseUp={() => setIsDragging(false)}\n style={{\n cursor: direction === 'horizontal' ? 'ew-resize' : 'ns-resize'\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.module.js.map"}
1
+ {"mappings":";;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,oBAAY,EAMnC,IAAI;;;ADHC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,aACV,QAAQ,IAAI,GAQb,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CAAC,cAAc,EAAE,QAAQ,oCAAoC,EAAE,YAAY,CAAC;QAG9E,cAAc;IAChB,CAAC;IAED,MAAM,iBAAE,cAAa,iBAAE,cAAa,mBAAE,gBAAe,EAAE,GAAG;IAE1D,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;mBACA;QACF;QAEA,cAAc,IAAI;QAElB,OAAO,IAAM;YACX,gBAAgB;QAClB;IACF,GAAG;QAAC;QAAa;QAAI;QAAS;QAAO;QAAe;KAAgB;IAEpE,MAAM,QAAQ,cAAc;IAE5B,qBACE,mBAAC;QAAI,WAAW;QAAW,OAAO;kBAC/B;;;;;;AAGP;;AD7DA;AGAA;;;AAuBA,MAAM,kCAAY;AAMH,kDAAoB,cACjC,WAAU,YACV,WAAW,IAAI,cACf,YAAY,gBACZ,UAAS,UACT,OAAM,SACN,MAAK,EACC,EAAE;IACR,M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AAM,cAAc,CAAC,QAAsB;YACzC,cAAc;QAChB;QAEA,MAAM,YAAY,CAAC,IAAkB;YACnC,cAAc,KAAK;QACrB;QAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc;QAC7C,SAAS,IAAI,CAAC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,mBAAC;QACC,WAAW;QACX,aAAa,IAAM,cAAc,IAAI;QACrC,WAAW,IAAM,cAAc,KAAK;QACpC,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;;;;;AAGP;;","sources":["packages/react-resizable-panels/src/index.ts","packages/react-resizable-panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n order = null,\n}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\n order?: number | null;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `Panel components must be rendered within a PanelGroup container`\n );\n }\n\n if (minSize > defaultSize) {\n console.error(\n `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`\n );\n\n defaultSize = minSize;\n }\n\n const { getPanelStyle, registerPanel, unregisterPanel } = context;\n\n useLayoutEffect(() => {\n const panel = {\n defaultSize,\n id,\n minSize,\n order,\n };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);\n\n const style = getPanelStyle(id);\n\n return (\n <div className={className} style={style}>\n {children}\n </div>\n );\n}\n","import { CSSProperties, createContext } from \"react\";\n\nimport { PanelData, ResizeHandler } from \"./types\";\n\nexport const PanelGroupContext = createContext<{\n direction: \"horizontal\" | \"vertical\";\n getPanelStyle: (id: string) => CSSProperties;\n registerPanel: (id: string, panel: PanelData) => void;\n registerResizeHandle: (idBefore: string, idAfter: string) => ResizeHandler;\n unregisterPanel: (id: string) => void;\n} | null>(null);\n","import {\n CSSProperties,\n ReactNode,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { Direction, PanelData } from \"./types\";\n\ntype Props = {\n autoSaveId?: string;\n children?: ReactNode[];\n className?: string;\n direction: Direction;\n height: number;\n width: number;\n};\n\nconst PRECISION = 5;\n\n// TODO [panels]\n// Within an active drag, remember original positions to refine more easily on expand.\n// Look at what the Chrome devtools Sources does.\n\nexport default function PanelGroup({\n autoSaveId,\n children = null,\n className = \"\",\n direction,\n height,\n width,\n}: Props) {\n const [panels, setPanels] = useState<Map<string, PanelData>>(new Map());\n\n // 0-1 values representing the relative size of each panel.\n const [sizes, setSizes] = useState<number[]>([]);\n\n // Store committed values to avoid unnecessarily re-running memoization/effects functions.\n const committedValuesRef = useRef<{\n direction: Direction;\n height: number;\n panels: Map<string, PanelData>;\n sizes: number[];\n width: number;\n }>({\n direction,\n height,\n panels,\n sizes,\n width,\n });\n useLayoutEffect(() => {\n committedValuesRef.current.direction = direction;\n committedValuesRef.current.height = height;\n committedValuesRef.current.panels = panels;\n committedValuesRef.current.sizes = sizes;\n committedValuesRef.current.width = width;\n });\n\n // Once all panels have registered themselves,\n // Compute the initial sizes based on default weights.\n // This assumes that panels register during initial mount (no conditional rendering)!\n useLayoutEffect(() => {\n const sizes = committedValuesRef.current.sizes;\n if (sizes.length === panels.size) {\n return;\n }\n\n // TODO [panels]\n // Validate that the total minSize is <= 1.\n\n // If this panel has been configured to persist sizing information,\n // default size should be restored from local storage if possible.\n let defaultSizes: number[] | undefined = undefined;\n if (autoSaveId) {\n try {\n const value = localStorage.getItem(\n createLocalStorageKey(autoSaveId, panels)\n );\n if (value) {\n defaultSizes = JSON.parse(value);\n }\n } catch (error) {}\n }\n\n if (defaultSizes != null) {\n setSizes(defaultSizes);\n } else {\n const panelsArray = panelsMapToSortedArray(panels);\n const totalWeight = panelsArray.reduce((weight, panel) => {\n return weight + panel.defaultSize;\n }, 0);\n\n setSizes(panelsArray.map((panel) => panel.defaultSize / totalWeight));\n }\n }, [autoSaveId, panels]);\n\n useEffect(() => {\n if (autoSaveId) {\n if (sizes.length === 0 || sizes.length !== panels.size) {\n return;\n }\n\n // If this panel has been configured to persist sizing information, save sizes to local storage.\n localStorage.setItem(\n createLocalStorageKey(autoSaveId, panels),\n JSON.stringify(sizes)\n );\n }\n }, [autoSaveId, panels, sizes]);\n\n const getPanelStyle = useCallback(\n (id: string): CSSProperties => {\n const { panels } = committedValuesRef.current;\n\n const offset = getOffset(panels, id, direction, sizes, height, width);\n const size = getSize(panels, id, direction, sizes, height, width);\n\n if (direction === \"horizontal\") {\n return {\n height: \"100%\",\n position: \"absolute\",\n left: offset,\n top: 0,\n width: size,\n };\n } else {\n return {\n height: size,\n position: \"absolute\",\n left: 0,\n top: offset,\n width: \"100%\",\n };\n }\n },\n [direction, height, sizes, width]\n );\n\n const registerPanel = useCallback((id: string, panel: PanelData) => {\n setPanels((prevPanels) => {\n if (prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.set(id, panel);\n\n return nextPanels;\n });\n }, []);\n\n const registerResizeHandle = useCallback(\n (idBefore: string, idAfter: string) => {\n return (event: MouseEvent) => {\n event.preventDefault();\n\n const {\n direction,\n height,\n panels,\n sizes: prevSizes,\n width,\n } = committedValuesRef.current;\n\n const isHorizontal = direction === \"horizontal\";\n const movement = isHorizontal ? event.movementX : event.movementY;\n const delta = isHorizontal ? movement / width : movement / height;\n\n const nextSizes = adjustByDelta(\n panels,\n idBefore,\n idAfter,\n delta,\n prevSizes\n );\n if (prevSizes !== nextSizes) {\n setSizes(nextSizes);\n }\n };\n\n // TODO [issues/5] Add to Map\n },\n []\n );\n\n const unregisterPanel = useCallback((id: string) => {\n setPanels((prevPanels) => {\n if (!prevPanels.has(id)) {\n return prevPanels;\n }\n\n const nextPanels = new Map(prevPanels);\n nextPanels.delete(id);\n\n return nextPanels;\n });\n }, []);\n\n const context = useMemo(\n () => ({\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n }),\n [\n direction,\n getPanelStyle,\n registerPanel,\n registerResizeHandle,\n unregisterPanel,\n ]\n );\n\n return (\n <PanelGroupContext.Provider value={context}>\n <div className={className}>{children}</div>\n </PanelGroupContext.Provider>\n );\n}\n\nfunction adjustByDelta(\n panels: Map<string, PanelData>,\n idBefore: string,\n idAfter: string,\n delta: number,\n prevSizes: number[]\n): number[] {\n if (delta === 0) {\n return prevSizes;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const nextSizes = prevSizes.concat();\n\n let deltaApplied = 0;\n\n // A resizing panel affects the panels before or after it.\n //\n // A negative delta means the panel immediately after the resizer should grow/expand by decreasing its offset.\n // Other panels may also need to shrink/contract (and shift) to make room, depending on the min weights.\n //\n // A positive delta means the panel immediately before the resizer should \"expand\".\n // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.\n let pivotId = delta < 0 ? idBefore : idAfter;\n let index = panelsArray.findIndex((panel) => panel.id === pivotId);\n while (true) {\n const panel = panelsArray[index];\n const prevSize = prevSizes[index];\n const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);\n if (prevSize !== nextSize) {\n deltaApplied += prevSize - nextSize;\n\n nextSizes[index] = nextSize;\n\n if (deltaApplied.toPrecision(PRECISION) >= delta.toPrecision(PRECISION)) {\n break;\n }\n }\n\n if (delta < 0) {\n if (--index < 0) {\n break;\n }\n } else {\n if (++index >= panelsArray.length) {\n break;\n }\n }\n }\n\n // If we were unable to resize any of the panels panels, return the previous state.\n // This will essentially bailout and ignore the \"mousemove\" event.\n if (deltaApplied === 0) {\n return prevSizes;\n }\n\n // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.\n pivotId = delta < 0 ? idAfter : idBefore;\n index = panelsArray.findIndex((panel) => panel.id === pivotId);\n nextSizes[index] = prevSizes[index] + deltaApplied;\n\n return nextSizes;\n}\n\nfunction createLocalStorageKey(\n autoSaveId: string,\n panels: Map<string, PanelData>\n): string {\n const panelsArray = panelsMapToSortedArray(panels);\n const panelIds = panelsArray.map((panel) => panel.id);\n\n return `PanelGroup:sizes:${autoSaveId}${panelIds.join(\"|\")}`;\n}\n\nfunction getOffset(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const panelsArray = panelsMapToSortedArray(panels);\n\n let index = panelsArray.findIndex((panel) => panel.id === id);\n if (index < 0) {\n return 0;\n }\n\n let scaledOffset = 0;\n\n for (index = index - 1; index >= 0; index--) {\n const panel = panelsArray[index];\n scaledOffset += getSize(panels, panel.id, direction, sizes, height, width);\n }\n\n return Math.round(scaledOffset);\n}\n\nfunction getSize(\n panels: Map<string, PanelData>,\n id: string,\n direction: Direction,\n sizes: number[],\n height: number,\n width: number\n): number {\n const totalSize = direction === \"horizontal\" ? width : height;\n\n if (panels.size === 1) {\n return totalSize;\n }\n\n const panelsArray = panelsMapToSortedArray(panels);\n\n const index = panelsArray.findIndex((panel) => panel.id === id);\n const size = sizes[index];\n if (size == null) {\n return 0;\n }\n\n return Math.round(size * totalSize);\n}\n\nfunction panelsMapToSortedArray(panels: Map<string, PanelData>): PanelData[] {\n return Array.from(panels.values()).sort((a, b) => a.order - b.order);\n}\n","import { ReactNode, useContext, useEffect, useState } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\nimport { ResizeHandler } from \"./types\";\n\nexport default function PanelResizeHandle({\n children = null,\n className = \"\",\n disabled = false,\n panelAfter,\n panelBefore,\n}: {\n children?: ReactNode;\n className?: string;\n disabled?: boolean;\n panelAfter: string;\n panelBefore: string;\n}) {\n const context = useContext(PanelGroupContext);\n if (context === null) {\n throw Error(\n `PanelResizeHandle components must be rendered within a PanelGroup container`\n );\n }\n\n const { direction, registerResizeHandle } = context;\n\n const [resizeHandler, setResizeHandler] = useState<ResizeHandler | null>(\n null\n );\n const [isDragging, setIsDragging] = useState(false);\n\n useEffect(() => {\n if (disabled) {\n setResizeHandler(null);\n } else {\n setResizeHandler(() => registerResizeHandle(panelBefore, panelAfter));\n }\n }, [disabled, panelAfter, panelBefore, registerResizeHandle]);\n\n useEffect(() => {\n if (disabled || resizeHandler == null || !isDragging) {\n return;\n }\n\n document.body.style.cursor =\n direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\";\n\n const onMouseLeave = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n const onMouseMove = (event: MouseEvent) => {\n resizeHandler(event);\n };\n\n const onMouseUp = (_: MouseEvent) => {\n setIsDragging(false);\n };\n\n document.body.addEventListener(\"mouseleave\", onMouseLeave);\n document.body.addEventListener(\"mousemove\", onMouseMove);\n document.body.addEventListener(\"mouseup\", onMouseUp);\n\n return () => {\n document.body.style.cursor = \"\";\n\n document.body.removeEventListener(\"mouseleave\", onMouseLeave);\n document.body.removeEventListener(\"mousemove\", onMouseMove);\n document.body.removeEventListener(\"mouseup\", onMouseUp);\n };\n }, [direction, disabled, isDragging, resizeHandler]);\n\n return (\n <div\n className={className}\n onMouseDown={() => setIsDragging(true)}\n onMouseUp={() => setIsDragging(false)}\n style={{\n cursor: direction === \"horizontal\" ? \"ew-resize\" : \"ns-resize\",\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"version":3,"file":"react-resizable-panels.module.js.map","sourceRoot":"../../../"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
@@ -13,21 +13,13 @@
13
13
  "module": "dist/react-resizable-panels.module.js",
14
14
  "types": "dist/react-resizable-panels.d.ts",
15
15
  "scripts": {
16
- "dev": "parcel 'website/index.html'",
17
- "watch": "parcel watch",
18
- "build": "parcel build"
16
+ "build": "parcel build",
17
+ "watch": "parcel watch"
19
18
  },
20
19
  "devDependencies": {
21
- "@parcel/packager-ts": "2.8.2",
22
- "@parcel/transformer-typescript-types": "2.8.2",
23
- "parcel": "latest",
24
- "process": "^0.11.10",
25
20
  "react": "latest",
26
- "react-dom": "latest",
27
- "react-virtualized-auto-sizer": "latest",
28
- "typescript": ">=3.0.0"
21
+ "react-dom": "latest"
29
22
  },
30
- "dependencies": {},
31
23
  "peerDependencies": {
32
24
  "react": "^16.14.0 || ^17.0.0 || ^18.0.0",
33
25
  "react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
package/src/Panel.tsx CHANGED
@@ -1,40 +1,56 @@
1
1
  import { ReactNode, useContext, useLayoutEffect } from "react";
2
2
 
3
3
  import { PanelGroupContext } from "./PanelContexts";
4
- import { PanelId } from "./types";
5
4
 
6
5
  // TODO [panels]
7
6
  // Support min pixel size too.
8
7
  // PanelGroup should warn if total width is less min pixel widths.
9
8
  export default function Panel({
10
- children,
9
+ children = null,
11
10
  className = "",
12
11
  defaultSize = 0.1,
13
12
  id,
14
13
  minSize = 0.1,
14
+ order = null,
15
15
  }: {
16
- children: ReactNode;
16
+ children?: ReactNode;
17
17
  className?: string;
18
18
  defaultSize?: number;
19
- id: PanelId;
19
+ id: string;
20
20
  minSize?: number;
21
+ order?: number | null;
21
22
  }) {
22
23
  const context = useContext(PanelGroupContext);
23
24
  if (context === null) {
24
- throw Error(`Panel components must be rendered within a PanelGroup container`);
25
+ throw Error(
26
+ `Panel components must be rendered within a PanelGroup container`
27
+ );
25
28
  }
26
29
 
27
- const { getPanelStyle, registerPanel } = context;
30
+ if (minSize > defaultSize) {
31
+ console.error(
32
+ `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`
33
+ );
34
+
35
+ defaultSize = minSize;
36
+ }
37
+
38
+ const { getPanelStyle, registerPanel, unregisterPanel } = context;
28
39
 
29
40
  useLayoutEffect(() => {
30
41
  const panel = {
31
42
  defaultSize,
32
43
  id,
33
44
  minSize,
45
+ order,
34
46
  };
35
47
 
36
48
  registerPanel(id, panel);
37
- }, [defaultSize, minSize, registerPanel, id]);
49
+
50
+ return () => {
51
+ unregisterPanel(id);
52
+ };
53
+ }, [defaultSize, id, minSize, order, registerPanel, unregisterPanel]);
38
54
 
39
55
  const style = getPanelStyle(id);
40
56
 
@@ -1,10 +1,11 @@
1
1
  import { CSSProperties, createContext } from "react";
2
2
 
3
- import { Panel, PanelId, ResizeHandler } from "./types";
3
+ import { PanelData, ResizeHandler } from "./types";
4
4
 
5
5
  export const PanelGroupContext = createContext<{
6
6
  direction: "horizontal" | "vertical";
7
- getPanelStyle: (id: PanelId) => CSSProperties;
8
- registerResizeHandle: (idBefore: PanelId, idAfter: PanelId) => ResizeHandler;
9
- registerPanel: (id: PanelId, panel: Panel) => void;
7
+ getPanelStyle: (id: string) => CSSProperties;
8
+ registerPanel: (id: string, panel: PanelData) => void;
9
+ registerResizeHandle: (idBefore: string, idAfter: string) => ResizeHandler;
10
+ unregisterPanel: (id: string) => void;
10
11
  } | null>(null);