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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.0.3
4
+ * [#3](https://github.com/bvaughn/react-resizable-panels/issues/3): `Panel`s can be conditionally rendered within a group. `PanelGroup` will persist separate layouts for each combination of visible panels.
5
+
6
+ ## 0.0.2
7
+ * Documentation-only update.
8
+
9
+ ## 0.0.1
10
+ * Initial release.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # react-panel-group
1
+ # react-resizable-panels
2
2
  React components for resizable panel groups/layouts
3
3
 
4
4
  ```jsx
5
- import { Panel, PanelGroup, PanelResizeHandle } from "react-panel-group";
5
+ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
6
6
 
7
7
  <PanelGroup autoSaveId="horizontal-panel" direction="horizontal">
8
8
  <Panel defaultSize={0.3} id="sources-explorer-panel">
@@ -27,7 +27,7 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-panel-group";
27
27
  | `autoSaveId` | `?string` | Unique id used to auto-save group arrangement via `localStorage`
28
28
  | `children` | `ReactNode[]` | Arbitrary React element(s)
29
29
  | `className` | `?string` | Class name
30
- | `direction` | `"horizontal" | "vertical"` | Group orientation
30
+ | `direction` | `"horizontal" \| "vertical"` | Group orientation
31
31
  | `height` | `number` | Height of group (in pixels)
32
32
  | `width` | `number` | Width of group (in pixels)
33
33
 
@@ -46,5 +46,5 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-panel-group";
46
46
  | `children` | `?ReactNode` | Custom drag UI; can be any arbitrary React element(s)
47
47
  | `className` | `?string` | Class name
48
48
  | `disabled` | `?boolean` | Disable drag handle
49
- | `panelAfter` | `PanelId` | Id of panel after (below or to the right of) the drag handle
50
- | `panelBefore` | `PanelId` | Id of panel before (above or to the left of) the drag handle
49
+ | `panelAfter` | `string` | Id of panel after (below or to the right of) the drag handle
50
+ | `panelBefore` | `string` | Id of panel before (above or to the left of) the drag handle
@@ -1,28 +1,27 @@
1
1
  import { ReactNode } from "react";
2
2
  type Direction = "horizontal" | "vertical";
3
- type PanelId = string;
4
3
  export function Panel({ children, className, defaultSize, id, minSize, }: {
5
- children: ReactNode;
4
+ children?: ReactNode;
6
5
  className?: string;
7
6
  defaultSize?: number;
8
- id: PanelId;
7
+ id: string;
9
8
  minSize?: number;
10
- }): any;
9
+ }): JSX.Element;
11
10
  type Props = {
12
11
  autoSaveId?: string;
13
- children: ReactNode[];
12
+ children?: ReactNode[];
14
13
  className?: string;
15
14
  direction: Direction;
16
15
  height: number;
17
16
  width: number;
18
17
  };
19
- export function PanelGroup({ autoSaveId, children, className, direction, height, width }: Props): any;
18
+ export function PanelGroup({ autoSaveId, children, className, direction, height, width, }: Props): JSX.Element;
20
19
  export function PanelResizeHandle({ children, className, disabled, panelAfter, panelBefore, }: {
21
20
  children?: ReactNode;
22
21
  className?: string;
23
22
  disabled?: boolean;
24
- panelAfter: PanelId;
25
- panelBefore: PanelId;
26
- }): any;
23
+ panelAfter: string;
24
+ panelBefore: string;
25
+ }): JSX.Element;
27
26
 
28
27
  //# sourceMappingURL=react-resizable-panels.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;AAElD,eAAsB,MAAM,CAAC;AEM7B,sBAA8B,EAC5B,QAAQ,EACR,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,GACd,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,OAyBA;AC/BD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,2BAAmC,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAc,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,OAyI3G;ACjKD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,UAAU,EACV,WAAW,GACZ,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB,OA+DA","sources":["src/src/types.ts","src/src/PanelContexts.ts","src/src/Panel.tsx","src/src/PanelGroup.tsx","src/src/PanelResizeHandle.tsx","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map"}
1
+ {"mappings":";AAAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;AEOlD,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EACF,OAAa,GACd,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,eAuCA;AC5CD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE,KAAK,eA8LP;AC7ND,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,UAAU,EACV,WAAW,GACZ,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,eAoEA","sources":["packages/react-resizable-panels/src/src/types.ts","packages/react-resizable-panels/src/src/PanelContexts.ts","packages/react-resizable-panels/src/src/Panel.tsx","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map","sourceRoot":"../../../"}
@@ -1,101 +1,122 @@
1
- var $8zHUo$reactjsxruntime = require("react/jsx-runtime");
2
- var $8zHUo$react = require("react");
1
+ var $b2QPe$reactjsxdevruntime = require("react/jsx-dev-runtime");
2
+ var $b2QPe$react = require("react");
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "Panel", () => $e4ec07a709221854$export$2e2bcd8739ae039);
9
- $parcel$export(module.exports, "PanelGroup", () => $da932bb3fa0f399b$export$2e2bcd8739ae039);
10
- $parcel$export(module.exports, "PanelResizeHandle", () => $4eb88cfd3116c797$export$2e2bcd8739ae039);
8
+ $parcel$export(module.exports, "Panel", () => $6d390b7f2e6b107f$export$2e2bcd8739ae039);
9
+ $parcel$export(module.exports, "PanelGroup", () => $d428eaeef644efb2$export$2e2bcd8739ae039);
10
+ $parcel$export(module.exports, "PanelResizeHandle", () => $d578a49f00f1bdeb$export$2e2bcd8739ae039);
11
11
 
12
12
 
13
13
 
14
- const $3cc6571444f2cb80$export$7d8c6d083caec74a = (0, $8zHUo$react.createContext)(null);
14
+ const $3251d17c1c3bce6c$export$7d8c6d083caec74a = (0, $b2QPe$react.createContext)(null);
15
15
 
16
16
 
17
- function $e4ec07a709221854$export$2e2bcd8739ae039({ children: children , className: className = "" , defaultSize: defaultSize = 0.1 , id: id , minSize: minSize = 0.1 }) {
18
- const context = (0, $8zHUo$react.useContext)((0, $3cc6571444f2cb80$export$7d8c6d083caec74a));
17
+ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null , className: className = "" , defaultSize: defaultSize = 0.1 , id: id , minSize: minSize = 0.1 }) {
18
+ const context = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
19
19
  if (context === null) throw Error(`Panel components must be rendered within a PanelGroup container`);
20
- const { getPanelStyle: getPanelStyle , registerPanel: registerPanel } = context;
21
- (0, $8zHUo$react.useLayoutEffect)(()=>{
20
+ if (minSize > defaultSize) {
21
+ console.error(`Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`);
22
+ defaultSize = minSize;
23
+ }
24
+ const { getPanelStyle: getPanelStyle , registerPanel: registerPanel , unregisterPanel: unregisterPanel } = context;
25
+ (0, $b2QPe$react.useLayoutEffect)(()=>{
22
26
  const panel = {
23
27
  defaultSize: defaultSize,
24
28
  id: id,
25
29
  minSize: minSize
26
30
  };
27
31
  registerPanel(id, panel);
32
+ return ()=>{
33
+ unregisterPanel(id);
34
+ };
28
35
  }, [
29
36
  defaultSize,
37
+ id,
30
38
  minSize,
31
39
  registerPanel,
32
- id
40
+ unregisterPanel
33
41
  ]);
34
42
  const style = getPanelStyle(id);
35
- return /*#__PURE__*/ (0, $8zHUo$reactjsxruntime.jsx)("div", {
43
+ return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
36
44
  className: className,
37
45
  style: style,
38
46
  children: children
39
- });
47
+ }, void 0, false, {
48
+ fileName: "packages/react-resizable-panels/src/Panel.tsx",
49
+ lineNumber: 55,
50
+ columnNumber: 5
51
+ }, this);
40
52
  }
41
53
 
42
54
 
43
55
 
44
56
 
45
57
 
46
- const $da932bb3fa0f399b$var$PRECISION = 5;
47
- function $da932bb3fa0f399b$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children , className: className = "" , direction: direction , height: height , width: width }) {
48
- const panelsRef = (0, $8zHUo$react.useRef)([]);
58
+ const $d428eaeef644efb2$var$PRECISION = 5;
59
+ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , width: width }) {
60
+ const [panels, setPanels] = (0, $b2QPe$react.useState)(new Map());
49
61
  // 0-1 values representing the relative size of each panel.
50
- const [sizes, setSizes] = (0, $8zHUo$react.useState)([]);
62
+ const [sizes, setSizes] = (0, $b2QPe$react.useState)([]);
51
63
  // Store committed values to avoid unnecessarily re-running memoization/effects functions.
52
- const committedValuesRef = (0, $8zHUo$react.useRef)({
64
+ const committedValuesRef = (0, $b2QPe$react.useRef)({
53
65
  direction: direction,
54
66
  height: height,
67
+ panels: panels,
55
68
  sizes: sizes,
56
69
  width: width
57
70
  });
58
- (0, $8zHUo$react.useLayoutEffect)(()=>{
71
+ (0, $b2QPe$react.useLayoutEffect)(()=>{
59
72
  committedValuesRef.current.direction = direction;
60
73
  committedValuesRef.current.height = height;
74
+ committedValuesRef.current.panels = panels;
61
75
  committedValuesRef.current.sizes = sizes;
62
76
  committedValuesRef.current.width = width;
63
77
  });
64
78
  // Once all panels have registered themselves,
65
79
  // Compute the initial sizes based on default weights.
66
80
  // This assumes that panels register during initial mount (no conditional rendering)!
67
- (0, $8zHUo$react.useLayoutEffect)(()=>{
68
- const panels = panelsRef.current;
81
+ (0, $b2QPe$react.useLayoutEffect)(()=>{
69
82
  const sizes = committedValuesRef.current.sizes;
70
- if (sizes.length === panels.length) return;
83
+ if (sizes.length === panels.size) return;
84
+ // TODO [panels]
85
+ // Validate that the total minSize is <= 1.
71
86
  // If this panel has been configured to persist sizing information,
72
87
  // default size should be restored from local storage if possible.
73
88
  let defaultSizes = undefined;
74
89
  if (autoSaveId) try {
75
- const value = localStorage.getItem(`PanelGroup:sizes:${autoSaveId}`);
90
+ const value = localStorage.getItem($d428eaeef644efb2$var$createLocalStorageKey(autoSaveId, panels));
76
91
  if (value) defaultSizes = JSON.parse(value);
77
92
  } catch (error) {}
78
- if (sizes.length === 0 && defaultSizes != null && defaultSizes.length === panels.length) setSizes(defaultSizes);
93
+ if (defaultSizes != null) setSizes(defaultSizes);
79
94
  else {
80
- const totalWeight = panels.reduce((weight, panel)=>{
95
+ const panelsArray = Array.from(panels.values());
96
+ const totalWeight = panelsArray.reduce((weight, panel)=>{
81
97
  return weight + panel.defaultSize;
82
98
  }, 0);
83
- setSizes(panels.map((panel)=>panel.defaultSize / totalWeight));
99
+ setSizes(panelsArray.map((panel)=>panel.defaultSize / totalWeight));
84
100
  }
85
101
  }, [
86
- autoSaveId
102
+ autoSaveId,
103
+ panels
87
104
  ]);
88
- (0, $8zHUo$react.useEffect)(()=>{
89
- if (autoSaveId && sizes.length > 0) // If this panel has been configured to persist sizing information, save sizes to local storage.
90
- localStorage.setItem(`PanelGroup:sizes:${autoSaveId}`, JSON.stringify(sizes));
105
+ (0, $b2QPe$react.useEffect)(()=>{
106
+ if (autoSaveId) {
107
+ if (sizes.length === 0 || sizes.length !== panels.size) return;
108
+ // If this panel has been configured to persist sizing information, save sizes to local storage.
109
+ localStorage.setItem($d428eaeef644efb2$var$createLocalStorageKey(autoSaveId, panels), JSON.stringify(sizes));
110
+ }
91
111
  }, [
92
112
  autoSaveId,
113
+ panels,
93
114
  sizes
94
115
  ]);
95
- const getPanelStyle = (0, $8zHUo$react.useCallback)((id)=>{
96
- const panels = panelsRef.current;
97
- const offset = $da932bb3fa0f399b$var$getOffset(panels, id, direction, sizes, height, width);
98
- const size = $da932bb3fa0f399b$var$getSize(panels, id, direction, sizes, height, width);
116
+ const getPanelStyle = (0, $b2QPe$react.useCallback)((id)=>{
117
+ const { panels: panels } = committedValuesRef.current;
118
+ const offset = $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width);
119
+ const size = $d428eaeef644efb2$var$getSize(panels, id, direction, sizes, height, width);
99
120
  if (direction === "horizontal") return {
100
121
  height: "100%",
101
122
  position: "absolute",
@@ -116,45 +137,66 @@ function $da932bb3fa0f399b$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
116
137
  sizes,
117
138
  width
118
139
  ]);
119
- const registerPanel = (0, $8zHUo$react.useCallback)((id, panel)=>{
120
- const panels = panelsRef.current;
121
- const index = panels.findIndex((panel)=>panel.id === id);
122
- if (index >= 0) panels.splice(index, 1);
123
- panels.push(panel);
140
+ const registerPanel = (0, $b2QPe$react.useCallback)((id, panel)=>{
141
+ setPanels((prevPanels)=>{
142
+ if (prevPanels.has(id)) return prevPanels;
143
+ const nextPanels = new Map(prevPanels);
144
+ nextPanels.set(id, panel);
145
+ return nextPanels;
146
+ });
124
147
  }, []);
125
- const registerResizeHandle = (0, $8zHUo$react.useCallback)((idBefore, idAfter)=>{
148
+ const registerResizeHandle = (0, $b2QPe$react.useCallback)((idBefore, idAfter)=>{
126
149
  return (event)=>{
127
150
  event.preventDefault();
128
- const panels = panelsRef.current;
129
- const { direction: direction , height: height , sizes: prevSizes , width: width } = committedValuesRef.current;
151
+ const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
130
152
  const isHorizontal = direction === "horizontal";
131
153
  const movement = isHorizontal ? event.movementX : event.movementY;
132
154
  const delta = isHorizontal ? movement / width : movement / height;
133
- const nextSizes = $da932bb3fa0f399b$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
155
+ const nextSizes = $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes);
134
156
  if (prevSizes !== nextSizes) setSizes(nextSizes);
135
157
  };
158
+ // TODO [issues/5] Add to Map
159
+ }, []);
160
+ const unregisterPanel = (0, $b2QPe$react.useCallback)((id)=>{
161
+ setPanels((prevPanels)=>{
162
+ if (!prevPanels.has(id)) return prevPanels;
163
+ const nextPanels = new Map(prevPanels);
164
+ nextPanels.delete(id);
165
+ return nextPanels;
166
+ });
136
167
  }, []);
137
- const context = (0, $8zHUo$react.useMemo)(()=>({
168
+ const context = (0, $b2QPe$react.useMemo)(()=>({
138
169
  direction: direction,
139
170
  getPanelStyle: getPanelStyle,
140
171
  registerPanel: registerPanel,
141
- registerResizeHandle: registerResizeHandle
172
+ registerResizeHandle: registerResizeHandle,
173
+ unregisterPanel: unregisterPanel
142
174
  }), [
143
175
  direction,
144
176
  getPanelStyle,
145
177
  registerPanel,
146
- registerResizeHandle
178
+ registerResizeHandle,
179
+ unregisterPanel
147
180
  ]);
148
- return /*#__PURE__*/ (0, $8zHUo$reactjsxruntime.jsx)((0, $3cc6571444f2cb80$export$7d8c6d083caec74a).Provider, {
181
+ return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
149
182
  value: context,
150
- children: /*#__PURE__*/ (0, $8zHUo$reactjsxruntime.jsx)("div", {
183
+ children: /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
151
184
  className: className,
152
185
  children: children
153
- })
154
- });
186
+ }, void 0, false, {
187
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
188
+ lineNumber: 224,
189
+ columnNumber: 7
190
+ }, this)
191
+ }, void 0, false, {
192
+ fileName: "packages/react-resizable-panels/src/PanelGroup.tsx",
193
+ lineNumber: 223,
194
+ columnNumber: 5
195
+ }, this);
155
196
  }
156
- function $da932bb3fa0f399b$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
197
+ function $d428eaeef644efb2$var$adjustByDelta(panels, idBefore, idAfter, delta, prevSizes) {
157
198
  if (delta === 0) return prevSizes;
199
+ const panelsArray = Array.from(panels.values());
158
200
  const nextSizes = prevSizes.concat();
159
201
  let deltaApplied = 0;
160
202
  // A resizing panel affects the panels before or after it.
@@ -165,20 +207,20 @@ function $da932bb3fa0f399b$var$adjustByDelta(panels, idBefore, idAfter, delta, p
165
207
  // A positive delta means the panel immediately before the resizer should "expand".
166
208
  // This is accomplished by shrinking/contracting (and shifting) one or more of the panels after the resizer.
167
209
  let pivotId = delta < 0 ? idBefore : idAfter;
168
- let index = panels.findIndex((panel)=>panel.id === pivotId);
210
+ let index = panelsArray.findIndex((panel)=>panel.id === pivotId);
169
211
  while(true){
170
- const panel = panels[index];
212
+ const panel = panelsArray[index];
171
213
  const prevSize = prevSizes[index];
172
214
  const nextSize = Math.max(prevSize - Math.abs(delta), panel.minSize);
173
215
  if (prevSize !== nextSize) {
174
216
  deltaApplied += prevSize - nextSize;
175
217
  nextSizes[index] = nextSize;
176
- if (deltaApplied.toPrecision($da932bb3fa0f399b$var$PRECISION) >= delta.toPrecision($da932bb3fa0f399b$var$PRECISION)) break;
218
+ if (deltaApplied.toPrecision($d428eaeef644efb2$var$PRECISION) >= delta.toPrecision($d428eaeef644efb2$var$PRECISION)) break;
177
219
  }
178
220
  if (delta < 0) {
179
221
  if (--index < 0) break;
180
222
  } else {
181
- if (++index >= panels.length) break;
223
+ if (++index >= panelsArray.length) break;
182
224
  }
183
225
  }
184
226
  // If we were unable to resize any of the panels panels, return the previous state.
@@ -186,40 +228,46 @@ function $da932bb3fa0f399b$var$adjustByDelta(panels, idBefore, idAfter, delta, p
186
228
  if (deltaApplied === 0) return prevSizes;
187
229
  // Adjust the pivot panel before, but only by the amount that surrounding panels were able to shrink/contract.
188
230
  pivotId = delta < 0 ? idAfter : idBefore;
189
- index = panels.findIndex((panel)=>panel.id === pivotId);
231
+ index = panelsArray.findIndex((panel)=>panel.id === pivotId);
190
232
  nextSizes[index] = prevSizes[index] + deltaApplied;
191
233
  return nextSizes;
192
234
  }
193
- function $da932bb3fa0f399b$var$getOffset(panels, id, direction, sizes, height, width) {
194
- let index = panels.findIndex((panel)=>panel.id === id);
235
+ function $d428eaeef644efb2$var$createLocalStorageKey(autoSaveId, panels) {
236
+ const panelIds = Array.from(panels.keys()).sort();
237
+ return `PanelGroup:sizes:${autoSaveId}${panelIds.join("|")}`;
238
+ }
239
+ function $d428eaeef644efb2$var$getOffset(panels, id, direction, sizes, height, width) {
240
+ const panelsArray = Array.from(panels.values());
241
+ let index = panelsArray.findIndex((panel)=>panel.id === id);
195
242
  if (index < 0) return 0;
196
243
  let scaledOffset = 0;
197
244
  for(index = index - 1; index >= 0; index--){
198
- const panel = panels[index];
199
- scaledOffset += $da932bb3fa0f399b$var$getSize(panels, panel.id, direction, sizes, height, width);
245
+ const panel = panelsArray[index];
246
+ scaledOffset += $d428eaeef644efb2$var$getSize(panels, panel.id, direction, sizes, height, width);
200
247
  }
201
248
  return Math.round(scaledOffset);
202
249
  }
203
- function $da932bb3fa0f399b$var$getSize(panels, id, direction, sizes, height, width) {
204
- const index = panels.findIndex((panel)=>panel.id === id);
250
+ function $d428eaeef644efb2$var$getSize(panels, id, direction, sizes, height, width) {
251
+ const totalSize = direction === "horizontal" ? width : height;
252
+ if (panels.size === 1) return totalSize;
253
+ const panelsArray = Array.from(panels.values());
254
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
205
255
  const size = sizes[index];
206
256
  if (size == null) return 0;
207
- const totalSize = direction === "horizontal" ? width : height;
208
- if (panels.length === 1) return totalSize;
209
- else return Math.round(size * totalSize);
257
+ return Math.round(size * totalSize);
210
258
  }
211
259
 
212
260
 
213
261
 
214
262
 
215
263
 
216
- function $4eb88cfd3116c797$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , panelAfter: panelAfter , panelBefore: panelBefore }) {
217
- const context = (0, $8zHUo$react.useContext)((0, $3cc6571444f2cb80$export$7d8c6d083caec74a));
264
+ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , panelAfter: panelAfter , panelBefore: panelBefore }) {
265
+ const context = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
218
266
  if (context === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
219
267
  const { direction: direction , registerResizeHandle: registerResizeHandle } = context;
220
- const [resizeHandler, setResizeHandler] = (0, $8zHUo$react.useState)(null);
221
- const [isDragging, setIsDragging] = (0, $8zHUo$react.useState)(false);
222
- (0, $8zHUo$react.useEffect)(()=>{
268
+ const [resizeHandler, setResizeHandler] = (0, $b2QPe$react.useState)(null);
269
+ const [isDragging, setIsDragging] = (0, $b2QPe$react.useState)(false);
270
+ (0, $b2QPe$react.useEffect)(()=>{
223
271
  if (disabled) setResizeHandler(null);
224
272
  else setResizeHandler(()=>registerResizeHandle(panelBefore, panelAfter));
225
273
  }, [
@@ -228,7 +276,7 @@ function $4eb88cfd3116c797$export$2e2bcd8739ae039({ children: children = null ,
228
276
  panelBefore,
229
277
  registerResizeHandle
230
278
  ]);
231
- (0, $8zHUo$react.useEffect)(()=>{
279
+ (0, $b2QPe$react.useEffect)(()=>{
232
280
  if (disabled || resizeHandler == null || !isDragging) return;
233
281
  document.body.style.cursor = direction === "horizontal" ? "ew-resize" : "ns-resize";
234
282
  const onMouseLeave = (_)=>{
@@ -255,7 +303,7 @@ function $4eb88cfd3116c797$export$2e2bcd8739ae039({ children: children = null ,
255
303
  isDragging,
256
304
  resizeHandler
257
305
  ]);
258
- return /*#__PURE__*/ (0, $8zHUo$reactjsxruntime.jsx)("div", {
306
+ return /*#__PURE__*/ (0, $b2QPe$reactjsxdevruntime.jsxDEV)("div", {
259
307
  className: className,
260
308
  onMouseDown: ()=>setIsDragging(true),
261
309
  onMouseUp: ()=>setIsDragging(false),
@@ -263,7 +311,11 @@ function $4eb88cfd3116c797$export$2e2bcd8739ae039({ children: children = null ,
263
311
  cursor: direction === "horizontal" ? "ew-resize" : "ns-resize"
264
312
  },
265
313
  children: children
266
- });
314
+ }, void 0, false, {
315
+ fileName: "packages/react-resizable-panels/src/PanelResizeHandle.tsx",
316
+ lineNumber: 75,
317
+ columnNumber: 5
318
+ }, this);
267
319
  }
268
320
 
269
321
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,0BAAY,EAKnC,IAAI;;;ADDC,kDAAe,YAC5B,SAAQ,aACR,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,MAOX,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,uBAAS,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,4BAAe,AAAD,EAAE,IAAM;QACpB,MAAM,QAAQ;yBACZ;gBACA;qBACA;QACF;QAEA,cAAc,IAAI;IACpB,GAAG;QAAC;QAAa;QAAS;QAAe;KAAG;IAE5C,MAAM,QAAQ,cAAc;IAE5B,qBACE,gCAAC;QAAI,WAAW;QAAW,OAAO;kBAC/B;;AAGP;;AD7CA;AGAA;;;AAuBA,MAAM,kCAAY;AAMH,kDAAoB,cAAE,WAAU,YAAE,SAAQ,aAAE,YAAY,gBAAI,UAAS,UAAE,OAAM,SAAE,MAAK,EAAS,EAAE;IAC5G,MAAM,YAAY,CAAA,GAAA,mBAAK,EAAW,EAAE;IAEpC,2DAA2D;IAC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AAc,GAAG,CAAA,GAAA,qBAAO,EAAE,KAAK;IAElD,CAAA,GAAA,sBAAS,AAAD,EAAE,IAAM;QACd,IAAI,UACF,iBAAiB,IAAI;aAErB,iBAAiB,IAAM,qBAAqB,aAAa;IAE7D,GAAG;QAAC;QAAU;QAAY;QAAa;KAAqB;IAE5D,CAAA,GAAA,sBAAS,AAAD,EAAE,IAAM;QACd,IAAI,YAAY,iBAAiB,IAAI,IAAI,CAAC,YACxC;QAGF,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,eAAe,cAAc,WAAW;QAEnF,MAAM,eAAe,CAAC,IAAkB;YACtC,cAAc,KAAK;QACrB;QAEA,MAAM,cAAc,CAAC,QAAsB;YACzC,cAAc;QAChB;QAEA,MAAM,YAAY,CAAC,IAAkB;YACnC,cAAc,KAAK;QACrB;QAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc;QAC7C,SAAS,IAAI,CAAC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,gCAAC;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.js.map"}
1
+ {"mappings":";;;;;;;;;;ACAA;;ACAA;AAIO,MAAM,4CAAoB,CAAA,GAAA,0BAAY,EAMnC,IAAI;;;ADHC,kDAAe,YAC5B,WAAW,IAAI,cACf,YAAY,kBACZ,cAAc,UACd,GAAE,WACF,UAAU,MAOX,EAAE;IACD,MAAM,UAAU,CAAA,GAAA,uBAAS,EAAE,CAAA,GAAA,yCAAgB;IAC3C,IAAI,YAAY,IAAI,EAClB,MAAM,MACJ,CAAC,+DAA+D,CAAC,EACjE;IAGJ,IAAI,UAAU,aAAa;QACzB,QAAQ,KAAK,CACX,CA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AG,CAAA,GAAA,qBAAO,EAC/C,IAAI;IAEN,MAAM,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,qBAAO,EAAE,KAAK;IAElD,CAAA,GAAA,sBAAS,AAAD,EAAE,IAAM;QACd,IAAI,UACF,iBAAiB,IAAI;aAErB,iBAAiB,IAAM,qBAAqB,aAAa;IAE7D,GAAG;QAAC;QAAU;QAAY;QAAa;KAAqB;IAE5D,CAAA,GAAA,sBAAS,AAAD,EAAE,IAAM;QACd,IAAI,YAAY,iBAAiB,IAAI,IAAI,CAAC,YACxC;QAGF,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GACxB,cAAc,eAAe,cAAc,WAAW;QAExD,MAAM,eAAe,CAAC,IAAkB;YACtC,cAAc,KAAK;QACrB;QAEA,MAAM,cAAc,CAAC,QAAsB;YACzC,cAAc;QAChB;QAEA,MAAM,YAAY,CAAC,IAAkB;YACnC,cAAc,KAAK;QACrB;QAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc;QAC7C,SAAS,IAAI,CAAC,gBAAgB,CAAC,aAAa;QAC5C,SAAS,IAAI,CAAC,gBAAgB,CAAC,WAAW;QAE1C,OAAO,IAAM;YACX,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG;YAE7B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;YAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,aAAa;YAC/C,SAAS,IAAI,CAAC,mBAAmB,CAAC,WAAW;QAC/C;IACF,GAAG;QAAC;QAAW;QAAU;QAAY;KAAc;IAEnD,qBACE,sCAAC;QACC,WAAW;QACX,aAAa,IAAM,cAAc,IAAI;QACrC,WAAW,IAAM,cAAc,KAAK;QACpC,OAAO;YACL,QAAQ,cAAc,eAAe,cAAc,WAAW;QAChE;kBAEC;;;;;;AAGP;;","sources":["packages/react-resizable-panels/src/index.ts","packages/react-resizable-panels/src/Panel.tsx","packages/react-resizable-panels/src/PanelContexts.ts","packages/react-resizable-panels/src/PanelGroup.tsx","packages/react-resizable-panels/src/PanelResizeHandle.tsx"],"sourcesContent":["import Panel from \"./Panel\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelGroup, PanelResizeHandle };\n","import { ReactNode, useContext, useLayoutEffect } from \"react\";\n\nimport { PanelGroupContext } from \"./PanelContexts\";\n\n// TODO [panels]\n// Support min pixel size too.\n// PanelGroup should warn if total width is less min pixel widths.\nexport default function Panel({\n children = null,\n className = \"\",\n defaultSize = 0.1,\n id,\n minSize = 0.1,\n}: {\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.js.map","sourceRoot":"../../../"}