react-resizable-panels 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,94 +1,115 @@
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 }) {
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
22
  minSize: minSize
19
23
  };
20
24
  registerPanel(id, panel);
25
+ return ()=>{
26
+ unregisterPanel(id);
27
+ };
21
28
  }, [
22
29
  defaultSize,
30
+ id,
23
31
  minSize,
24
32
  registerPanel,
25
- id
33
+ unregisterPanel
26
34
  ]);
27
35
  const style = getPanelStyle(id);
28
- return /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
36
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
29
37
  className: className,
30
38
  style: style,
31
39
  children: children
32
- });
40
+ }, void 0, false, {
41
+ fileName: "packages/react-resizable-panels/src/Panel.tsx",
42
+ lineNumber: 55,
43
+ columnNumber: 5
44
+ }, this);
33
45
  }
34
46
 
35
47
 
36
48
 
37
49
 
38
50
 
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)([]);
51
+ const $c44ee3356398c8a1$var$PRECISION = 5;
52
+ function $c44ee3356398c8a1$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
53
+ const [panels, setPanels] = (0, $fpI56$useState)(new Map());
42
54
  // 0-1 values representing the relative size of each panel.
43
- const [sizes, setSizes] = (0, $hgUW1$useState)([]);
55
+ const [sizes, setSizes] = (0, $fpI56$useState)([]);
44
56
  // Store committed values to avoid unnecessarily re-running memoization/effects functions.
45
- const committedValuesRef = (0, $hgUW1$useRef)({
57
+ const committedValuesRef = (0, $fpI56$useRef)({
46
58
  direction: direction,
47
59
  height: height,
60
+ panels: panels,
48
61
  sizes: sizes,
49
62
  width: width
50
63
  });
51
- (0, $hgUW1$useLayoutEffect)(()=>{
64
+ (0, $fpI56$useLayoutEffect)(()=>{
52
65
  committedValuesRef.current.direction = direction;
53
66
  committedValuesRef.current.height = height;
67
+ committedValuesRef.current.panels = panels;
54
68
  committedValuesRef.current.sizes = sizes;
55
69
  committedValuesRef.current.width = width;
56
70
  });
57
71
  // Once all panels have registered themselves,
58
72
  // Compute the initial sizes based on default weights.
59
73
  // This assumes that panels register during initial mount (no conditional rendering)!
60
- (0, $hgUW1$useLayoutEffect)(()=>{
61
- const panels = panelsRef.current;
74
+ (0, $fpI56$useLayoutEffect)(()=>{
62
75
  const sizes = committedValuesRef.current.sizes;
63
- if (sizes.length === panels.length) return;
76
+ if (sizes.length === panels.size) return;
77
+ // TODO [panels]
78
+ // Validate that the total minSize is <= 1.
64
79
  // If this panel has been configured to persist sizing information,
65
80
  // default size should be restored from local storage if possible.
66
81
  let defaultSizes = undefined;
67
82
  if (autoSaveId) try {
68
- const value = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
83
+ const value = localStorage.getItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels));
69
84
  if (value) defaultSizes = JSON.parse(value);
70
85
  } catch (error) {}
71
- if (sizes.length === 0 && defaultSizes != null && defaultSizes.length === panels.length) setSizes(defaultSizes);
86
+ if (defaultSizes != null) setSizes(defaultSizes);
72
87
  else {
73
- const totalWeight = panels.reduce((weight, panel)=>{
88
+ const panelsArray = Array.from(panels.values());
89
+ const totalWeight = panelsArray.reduce((weight, panel)=>{
74
90
  return weight + panel.defaultSize;
75
91
  }, 0);
76
- setSizes(panels.map((panel)=>panel.defaultSize / totalWeight));
92
+ setSizes(panelsArray.map((panel)=>panel.defaultSize / totalWeight));
77
93
  }
78
94
  }, [
79
- autoSaveId
95
+ autoSaveId,
96
+ panels
80
97
  ]);
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));
98
+ (0, $fpI56$useEffect)(()=>{
99
+ if (autoSaveId) {
100
+ if (sizes.length === 0 || sizes.length !== panels.size) return;
101
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
102
+ localStorage.setItem($c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels), JSON.stringify(sizes));
103
+ }
84
104
  }, [
85
105
  autoSaveId,
106
+ panels,
86
107
  sizes
87
108
  ]);
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);
109
+ const getPanelStyle = (0, $fpI56$useCallback)((id)=>{
110
+ const { panels: panels } = committedValuesRef.current;
111
+ const offset = $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width);
112
+ const size = $c44ee3356398c8a1$var$getSize(panels, id, direction, sizes, height, width);
92
113
  if (direction === "horizontal") return {
93
114
  height: "100%",
94
115
  position: "absolute",
@@ -109,45 +130,66 @@ function $87c6267876d46c1c$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
109
130
  sizes,
110
131
  width
111
132
  ]);
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);
133
+ const registerPanel = (0, $fpI56$useCallback)((id, panel)=>{
134
+ setPanels((prevPanels)=>{
135
+ if (prevPanels.has(id)) return prevPanels;
136
+ const nextPanels = new Map(prevPanels);
137
+ nextPanels.set(id, panel);
138
+ return nextPanels;
139
+ });
117
140
  }, []);
118
- const registerResizeHandle = (0, $hgUW1$useCallback)((idBefore, idAfter)=>{
141
+ const registerResizeHandle = (0, $fpI56$useCallback)((idBefore, idAfter)=>{
119
142
  return (event)=>{
120
143
  event.preventDefault();
121
- const panels = panelsRef.current;
122
- const { direction: direction , height: height , sizes: prevSizes , width: width } = committedValuesRef.current;
144
+ const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
123
145
  const isHorizontal = direction === "horizontal";
124
146
  const movement = isHorizontal ? event.movementX : event.movementY;
125
147
  const delta = isHorizontal ? movement / width : movement / height;
126
- const nextSizes = $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
148
+ const nextSizes = $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
127
149
  if (prevSizes !== nextSizes) setSizes(nextSizes);
128
150
  };
151
+ // TODO [issues/5] Add to Map
152
+ }, []);
153
+ const unregisterPanel = (0, $fpI56$useCallback)((id)=>{
154
+ setPanels((prevPanels)=>{
155
+ if (!prevPanels.has(id)) return prevPanels;
156
+ const nextPanels = new Map(prevPanels);
157
+ nextPanels.delete(id);
158
+ return nextPanels;
159
+ });
129
160
  }, []);
130
- const context = (0, $hgUW1$useMemo)(()=>({
161
+ const context = (0, $fpI56$useMemo)(()=>({
131
162
  direction: direction,
132
163
  getPanelStyle: getPanelStyle,
133
164
  registerPanel: registerPanel,
134
- registerResizeHandle: registerResizeHandle
165
+ registerResizeHandle: registerResizeHandle,
166
+ unregisterPanel: unregisterPanel
135
167
  }), [
136
168
  direction,
137
169
  getPanelStyle,
138
170
  registerPanel,
139
- registerResizeHandle
171
+ registerResizeHandle,
172
+ unregisterPanel
140
173
  ]);
141
- return /*#__PURE__*/ (0, $hgUW1$jsx)((0, $3a3142702e7d9c06$export$7d8c6d083caec74a).Provider, {
174
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)((0, $f922724f4bad4884$export$7d8c6d083caec74a).Provider, {
142
175
  value: context,
143
- children: /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
176
+ children: /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
144
177
  className: className,
145
178
  children: children
146
- })
147
- });
179
+ }, void 0, false, {
180
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
181
+ lineNumber: 224,
182
+ columnNumber: 7
183
+ }, this)
184
+ }, void 0, false, {
185
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
186
+ lineNumber: 223,
187
+ columnNumber: 5
188
+ }, this);
148
189
  }
149
- function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
190
+ function $c44ee3356398c8a1$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
150
191
  if (delta === 0) return prevSizes;
192
+ const panelsArray = Array.from(panels.values());
151
193
  const nextSizes = prevSizes.concat();
152
194
  let deltaApplied = 0;
153
195
  // A resizing panel affects the panels before or after it.
@@ -158,20 +200,20 @@ function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, p
158
200
  // A positive delta means the panel immediately before the resizer should "expand".
159
201
  // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
160
202
  let pivotId = delta < 0 ? idBefore : idAfter;
161
- let index = panels.findIndex((panel)=>panel.id === pivotId);
203
+ let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
162
204
  while(true){
163
- const panel = panels[index];
205
+ const panel = panelsArray[index];
164
206
  const prevSize = prevSizes[index];
165
207
  const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
166
208
  if (prevSize !== nextSize) {
167
209
  deltaApplied += prevSize - nextSize;
168
210
  nextSizes[index] = nextSize;
169
- if (deltaApplied.toPrecision($87c6267876d46c1c$var$PRECISION) >= delta.toPrecision($87c6267876d46c1c$var$PRECISION)) break;
211
+ if (deltaApplied.toPrecision($c44ee3356398c8a1$var$PRECISION) >= delta.toPrecision($c44ee3356398c8a1$var$PRECISION)) break;
170
212
  }
171
213
  if (delta < 0) {
172
214
  if (--index < 0) break;
173
215
  } else {
174
- if (++index >= panels.length) break;
216
+ if (++index >= panelsArray.length) break;
175
217
  }
176
218
  }
177
219
  // If we were unable to resize any of the panels panels, return the previous state.
@@ -179,40 +221,46 @@ function $87c6267876d46c1c$var$adjustByDelta(panels, idBefore, idAfter, delta, p
179
221
  if (deltaApplied === 0) return prevSizes;
180
222
  // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
181
223
  pivotId = delta < 0 ? idAfter : idBefore;
182
- index = panels.findIndex((panel)=>panel.id === pivotId);
224
+ index = panelsArray.findIndex((panel)=>panel.id === pivotId);
183
225
  nextSizes[index] = prevSizes[index] + deltaApplied;
184
226
  return nextSizes;
185
227
  }
186
- function $87c6267876d46c1c$var$getOffset(panels, id, direction, sizes, height, width) {
187
- let index = panels.findIndex((panel)=>panel.id === id);
228
+ function $c44ee3356398c8a1$var$createLocalStorageKey(autoSaveId, panels) {
229
+ const panelIds = Array.from(panels.keys()).sort();
230
+ return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
231
+ }
232
+ function $c44ee3356398c8a1$var$getOffset(panels, id, direction, sizes, height, width) {
233
+ const panelsArray = Array.from(panels.values());
234
+ let index = panelsArray.findIndex((panel)=>panel.id === id);
188
235
  if (index < 0) return 0;
189
236
  let scaledOffset = 0;
190
237
  for(index = index - 1; index >= 0; index--){
191
- const panel = panels[index];
192
- scaledOffset += $87c6267876d46c1c$var$getSize(panels, panel.id, direction, sizes, height, width);
238
+ const panel = panelsArray[index];
239
+ scaledOffset += $c44ee3356398c8a1$var$getSize(panels, panel.id, direction, sizes, height, width);
193
240
  }
194
241
  return Math.round(scaledOffset);
195
242
  }
196
- function $87c6267876d46c1c$var$getSize(panels, id, direction, sizes, height, width) {
197
- const index = panels.findIndex((panel)=>panel.id === id);
243
+ function $c44ee3356398c8a1$var$getSize(panels, id, direction, sizes, height, width) {
244
+ const totalSize = direction === "horizontal" ? width : height;
245
+ if (panels.size === 1) return totalSize;
246
+ const panelsArray = Array.from(panels.values());
247
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
198
248
  const size = sizes[index];
199
249
  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);
250
+ return Math.round(size * totalSize);
203
251
  }
204
252
 
205
253
 
206
254
 
207
255
 
208
256
 
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));
257
+ function $b067b37706bb37b8$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , panelAfter: panelAfter , panelBefore: panelBefore }) {
258
+ const context = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
211
259
  if (context === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
212
260
  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)(()=>{
261
+ const [resizeHandler, setResizeHandler] = (0, $fpI56$useState)(null);
262
+ const [isDragging, setIsDragging] = (0, $fpI56$useState)(false);
263
+ (0, $fpI56$useEffect)(()=>{
216
264
  if (disabled) setResizeHandler(null);
217
265
  else setResizeHandler(()=>registerResizeHandle(panelBefore, panelAfter));
218
266
  }, [
@@ -221,7 +269,7 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
221
269
  panelBefore,
222
270
  registerResizeHandle
223
271
  ]);
224
- (0, $hgUW1$useEffect)(()=>{
272
+ (0, $fpI56$useEffect)(()=>{
225
273
  if (disabled || resizeHandler == null || !isDragging) return;
226
274
  document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
227
275
  const onMouseLeave = (_)=>{
@@ -248,7 +296,7 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
248
296
  isDragging,
249
297
  resizeHandler
250
298
  ]);
251
- return /*#__PURE__*/ (0, $hgUW1$jsx)("div", {
299
+ return /*#__PURE__*/ (0, $fpI56$jsxDEV)("div", {
252
300
  className: className,
253
301
  onMouseDown: ()=>setIsDragging(true),
254
302
  onMouseUp: ()=>setIsDragging(false),
@@ -256,11 +304,15 @@ function $74f1c1b08e3b0df5$export$2e2bcd8739ae039({ children: children = null ,
256
304
  cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
257
305
  },
258
306
  children: children
259
- });
307
+ }, void 0, false, {
308
+ fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
309
+ lineNumber: 75,
310
+ columnNumber: 5
311
+ }, this);
260
312
  }
261
313
 
262
314
 
263
315
 
264
316
 
265
- export {$be6cfb11a13b6f3f$export$2e2bcd8739ae039 as Panel, $87c6267876d46c1c$export$2e2bcd8739ae039 as PanelGroup, $74f1c1b08e3b0df5$export$2e2bcd8739ae039 as PanelResizeHandle};
317
+ export {$ad28bce87b00c2be$export$2e2bcd8739ae039 as Panel, $c44ee3356398c8a1$export$2e2bcd8739ae039 as PanelGroup, $b067b37706bb37b8$export$2e2bcd8739ae039 as PanelResizeHandle};
266
318
  //# 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,WACF,UAAU,MAOX,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MAAM,CAAC,+DAA+D,CAAC,EAAE;IAGjF,MAAM,iBAAE,cAAa,iBAAE,cAAa,EAAE,GAAG;IAEzC,CAAA,GAAA,sBAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gB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F,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
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AAS,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}: {\n children?: ReactNode;\n className?: string;\n defaultSize?: number;\n id: string;\n minSize?: number;\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 };\n\n registerPanel(id, panel);\n\n return () => {\n unregisterPanel(id);\n };\n }, [defaultSize, id, minSize, 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: PanelData[] = Array.from(panels.values());\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: PanelData[] = Array.from(panels.values());\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 panelIds = Array.from(panels.keys()).sort();\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: PanelData[] = Array.from(panels.values());\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: PanelData[] = Array.from(panels.values());\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","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.1",
3
+ "version": "0.0.3",
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,30 +1,39 @@
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,
15
14
  }: {
16
- children: ReactNode;
15
+ children?: ReactNode;
17
16
  className?: string;
18
17
  defaultSize?: number;
19
- id: PanelId;
18
+ id: string;
20
19
  minSize?: number;
21
20
  }) {
22
21
  const context = useContext(PanelGroupContext);
23
22
  if (context === null) {
24
- throw Error(`Panel components must be rendered within a PanelGroup container`);
23
+ throw Error(
24
+ `Panel components must be rendered within a PanelGroup container`
25
+ );
25
26
  }
26
27
 
27
- const { getPanelStyle, registerPanel } = context;
28
+ if (minSize > defaultSize) {
29
+ console.error(
30
+ `Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`
31
+ );
32
+
33
+ defaultSize = minSize;
34
+ }
35
+
36
+ const { getPanelStyle, registerPanel, unregisterPanel } = context;
28
37
 
29
38
  useLayoutEffect(() => {
30
39
  const panel = {
@@ -34,7 +43,11 @@ export default function Panel({
34
43
  };
35
44
 
36
45
  registerPanel(id, panel);
37
- }, [defaultSize, minSize, registerPanel, id]);
46
+
47
+ return () => {
48
+ unregisterPanel(id);
49
+ };
50
+ }, [defaultSize, id, minSize, registerPanel, unregisterPanel]);
38
51
 
39
52
  const style = getPanelStyle(id);
40
53
 
@@ -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);