react-resizable-panels 0.0.14 → 0.0.16

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.16 (unreleased)
4
+ * Bug fix: Resize handle ARIA attributes now rendering proper min/max/now values for Window Splitter.
5
+ * Bug fix: Up/down arrows are ignored for _horizontal_ layouts and left/right arrows are ignored for _vertical_ layouts as per Window Splitter spec.
6
+ * [#36](https://github.com/bvaughn/react-resizable-panels/issues/36): Removed `PanelContext` in favor of adding `data-resize-handle-active` attribute to active resize handles. This attribute can be used to update the style for active handles.
7
+
8
+ ## 0.0.15
9
+ * [#30](https://github.com/bvaughn/react-resizable-panels/issues/30): `PanelGroup` uses `display: flex` rather than absolute positioning. This provides several benefits: (a) more responsive resizing for nested groups, (b) no explicit `width`/`height` props, and (c) `PanelResizeHandle` components can now be rendered directly within `PanelGroup` (rather than as children of `Panel`s).
10
+
3
11
  ## 0.0.14
4
12
  * [#23](https://github.com/bvaughn/react-resizable-panels/issues/23): Fix small regression with `autoSaveId` that was introduced with non-deterministic `useId` ids.
5
13
 
package/README.md CHANGED
@@ -5,15 +5,15 @@ React components for resizable panel groups/layouts
5
5
  import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
6
6
 
7
7
  <PanelGroup autoSaveId="example" direction="horizontal">
8
- <Panel defaultSize={0.3}>
8
+ <Panel defaultSize={25}>
9
9
  <SourcesExplorer />
10
10
  </Panel>
11
- <Panel defaultSize={0.5}>
12
- <PanelResizeHandle />
11
+ <PanelResizeHandle />
12
+ <Panel>
13
13
  <SourceViewer />
14
- <PanelResizeHandle />
15
14
  </Panel>
16
- <Panel defaultSize={0.2}>
15
+ <PanelResizeHandle />
16
+ <Panel defaultSize={25}>
17
17
  <Console />
18
18
  </Panel>
19
19
  </PanelGroup>
@@ -28,18 +28,16 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
28
28
  | `children` | `ReactNode` | Arbitrary React element(s)
29
29
  | `className` | `?string` | Class name
30
30
  | `direction` | `"horizontal" \| "vertical"` | Group orientation
31
- | `height` | `number` | Height of group (in pixels)
32
31
  | `id` | `?string` | Optional group id; falls back to `useId` when not provided
33
- | `width` | `number` | Width of group (in pixels)
34
32
 
35
33
  ### `Panel`
36
34
  | prop | type | description
37
35
  | :------------ | :---------- | :---
38
36
  | `children` | `ReactNode` | Arbitrary React element(s)
39
37
  | `className` | `?string` | Class name
40
- | `defaultSize` | `?number` | Initial size of panel (relative to other panels within the group)
38
+ | `defaultSize` | `?number` | Initial size of panel (numeric value between 1-100)
41
39
  | `id` | `?string` | Optional panel id (unique within group); falls back to `useId` when not provided
42
- | `minSize` | `?number` | Minum allowable size of panel (0.0 - 1.0)
40
+ | `minSize` | `?number` | Minimum allowable size of panel (numeric value between 1-100)
43
41
  | `order` | `?number` | Order of panel within group; required for groups with conditionally rendered panels
44
42
 
45
43
  ### `PanelResizeHandle`
@@ -49,8 +47,3 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
49
47
  | `className` | `?string` | Class name
50
48
  | `disabled` | `?boolean` | Disable drag handle
51
49
  | `id` | `?string` | Optional resize handle id (unique within group); falls back to `useId` when not provided
52
-
53
- ### `PanelContext`
54
- | prop | type | description
55
- | :----------- | :------------------- | :---
56
- | `activeHandleId` | `string \| null` | Resize handle currently being dragged (or `null`)
@@ -1,12 +1,9 @@
1
1
  import { ReactNode } from "react";
2
2
  type Direction = "horizontal" | "vertical";
3
- export const PanelContext: import("react").Context<{
4
- activeHandleId: string | null;
5
- }>;
6
3
  export function Panel({ children, className, defaultSize, id: idFromProps, minSize, order, }: {
7
4
  children?: ReactNode;
8
5
  className?: string;
9
- defaultSize?: number;
6
+ defaultSize?: number | null;
10
7
  id?: string | null;
11
8
  minSize?: number;
12
9
  order?: number | null;
@@ -16,11 +13,9 @@ type Props = {
16
13
  children?: ReactNode;
17
14
  className?: string;
18
15
  direction: Direction;
19
- height: number;
20
16
  id?: string | null;
21
- width: number;
22
17
  };
23
- export function PanelGroup({ autoSaveId, children, className, direction, height, id: idFromProps, width, }: Props): JSX.Element;
18
+ export function PanelGroup({ autoSaveId, children, className, direction, id: idFromProps, }: Props): JSX.Element;
24
19
  export function PanelResizeHandle({ children, className, disabled, id: idFromProps, }: {
25
20
  children?: ReactNode;
26
21
  className?: string;
@@ -1 +1 @@
1
- {"mappings":";ACAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;ACIlD,OAAO,MAAM;oBACK,MAAM,GAAG,IAAI;EAChB,CAAC;ACEhB,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAiB,EACjB,EAAE,EAAE,WAAkB,EACtB,OAAa,EACb,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eA+CA;AMlCD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAMF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,MAAM,EACN,EAAE,EAAE,WAAkB,EACtB,KAAK,GACN,EAAE,KAAK,eAyOP;ACpRD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,WAAkB,GACvB,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,eAuGA","sources":["packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","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/utils/serialization.ts","packages/react-resizable-panels/src/src/constants.ts","packages/react-resizable-panels/src/src/utils/group.ts","packages/react-resizable-panels/src/src/utils/coordinates.ts","packages/react-resizable-panels/src/src/hooks/useWindowSplitterBehavior.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,"import Panel from \"./Panel\";\nimport { PanelContext } from \"./PanelContexts\";\nimport PanelGroup from \"./PanelGroup\";\nimport PanelResizeHandle from \"./PanelResizeHandle\";\n\nexport { Panel, PanelContext, PanelGroup, PanelResizeHandle };\n"],"names":[],"version":3,"file":"react-resizable-panels.d.ts.map"}
1
+ {"mappings":";ACAA,iBAAwB,YAAY,GAAG,UAAU,CAAC;AEQlD,sBAA8B,EAC5B,QAAe,EACf,SAAc,EACd,WAAkB,EAClB,EAAE,EAAE,WAAkB,EACtB,OAAY,EACZ,KAAY,GACb,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,eAyDA;AM9CD,aAAa;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,CAAC;AAMF,2BAAmC,EACjC,UAAU,EACV,QAAe,EACf,SAAc,EACd,SAAS,EACT,EAAE,EAAE,WAAkB,GACvB,EAAE,KAAK,eA8OP;ACnRD,kCAA0C,EACxC,QAAe,EACf,SAAc,EACd,QAAgB,EAChB,EAAE,EAAE,WAAkB,GACvB,EAAE;IACD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,eA6GA","sources":["packages/react-resizable-panels/src/src/hooks/useUniqueId.ts","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/utils/serialization.ts","packages/react-resizable-panels/src/src/constants.ts","packages/react-resizable-panels/src/src/utils/group.ts","packages/react-resizable-panels/src/src/utils/coordinates.ts","packages/react-resizable-panels/src/src/hooks/useWindowSplitterBehavior.ts","packages/react-resizable-panels/src/src/PanelGroup.tsx","packages/react-resizable-panels/src/src/PanelResizeHandle.tsx","packages/react-resizable-panels/src/src/index.ts","packages/react-resizable-panels/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,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"}
@@ -6,7 +6,6 @@ function $parcel$export(e, n, v, s) {
6
6
  }
7
7
 
8
8
  $parcel$export(module.exports, "Panel", () => $6d390b7f2e6b107f$export$2e2bcd8739ae039);
9
- $parcel$export(module.exports, "PanelContext", () => $3251d17c1c3bce6c$export$f34532ac99e32150);
10
9
  $parcel$export(module.exports, "PanelGroup", () => $d428eaeef644efb2$export$2e2bcd8739ae039);
11
10
  $parcel$export(module.exports, "PanelResizeHandle", () => $d578a49f00f1bdeb$export$2e2bcd8739ae039);
12
11
 
@@ -22,17 +21,20 @@ function $6d548a0d130941e3$export$2e2bcd8739ae039(idFromParams = null) {
22
21
 
23
22
 
24
23
 
25
- const $3251d17c1c3bce6c$export$f34532ac99e32150 = (0, $b2QPe$react.createContext)(null);
26
24
  const $3251d17c1c3bce6c$export$7d8c6d083caec74a = (0, $b2QPe$react.createContext)(null);
27
25
 
28
26
 
29
- function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null , className: className = "" , defaultSize: defaultSize = 0.1 , id: idFromProps = null , minSize: minSize = 0.1 , order: order = null }) {
27
+ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null , className: className = "" , defaultSize: defaultSize = null , id: idFromProps = null , minSize: minSize = 10 , order: order = null }) {
30
28
  const context = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
31
29
  if (context === null) throw Error(`Panel components must be rendered within a PanelGroup container`);
32
30
  const panelId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idFromProps);
33
- if (minSize > defaultSize) {
34
- console.error(`Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`);
35
- defaultSize = minSize;
31
+ if (minSize < 0 || minSize > 100) throw Error(`Panel minSize must be between 0 and 100, but was ${minSize}`);
32
+ if (defaultSize !== null) {
33
+ if (defaultSize < 0 || defaultSize > 100) throw Error(`Panel defaultSize must be between 0 and 100, but was ${defaultSize}`);
34
+ else if (minSize > defaultSize) {
35
+ console.error(`Panel minSize ${minSize} cannot be greater than defaultSize ${defaultSize}`);
36
+ defaultSize = minSize;
37
+ }
36
38
  }
37
39
  const { getPanelStyle: getPanelStyle , registerPanel: registerPanel , unregisterPanel: unregisterPanel } = context;
38
40
  (0, $b2QPe$react.useLayoutEffect)(()=>{
@@ -68,13 +70,15 @@ function $6d390b7f2e6b107f$export$2e2bcd8739ae039({ children: children = null ,
68
70
 
69
71
 
70
72
 
71
-
72
73
  // Note that Panel ids might be user-provided (stable) or useId generated (non-deterministic)
73
74
  // so they should not be used as part of the serialization key.
74
75
  // Using an attribute like minSize instead should work well enough.
75
76
  // Pre-sorting by minSize allows remembering layouts even if panels are re-ordered/dragged.
76
77
  function $e045b0dd313f33c7$var$getSerializationKey(panels) {
77
- return panels.map((panel)=>panel.minSize.toPrecision(2)).sort().join(",");
78
+ return panels.map((panel)=>{
79
+ const { minSize: minSize , order: order } = panel;
80
+ return order ? `${order}:${minSize}` : `${minSize}`;
81
+ }).sort((a, b)=>a.localeCompare(b)).join(",");
78
82
  }
79
83
  function $e045b0dd313f33c7$var$loadSerializedPanelGroupState(autoSaveId) {
80
84
  try {
@@ -106,7 +110,7 @@ function $e045b0dd313f33c7$export$af183b313c61be4f(autoSaveId, panels, sizes) {
106
110
  }
107
111
 
108
112
 
109
- const $3237bc4a138172cd$export$d6d3992f3becc879 = 5;
113
+ const $3237bc4a138172cd$export$d6d3992f3becc879 = 10;
110
114
 
111
115
 
112
116
  function $d520236daad9c5d5$export$f50bae335f53943c(panels, idBefore, idAfter, delta, prevSizes) {
@@ -147,22 +151,24 @@ function $d520236daad9c5d5$export$f50bae335f53943c(panels, idBefore, idAfter, de
147
151
  nextSizes[index] = prevSizes[index] + deltaApplied;
148
152
  return nextSizes;
149
153
  }
150
- function $d520236daad9c5d5$export$622cea445a1c5b7d(panels, id, direction, sizes, height, width) {
154
+ function $d520236daad9c5d5$export$6f43503e166de6fb(panels, id, sizes) {
155
+ if (panels.size === 1) return "100";
151
156
  const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
152
- let index = panelsArray.findIndex((panel)=>panel.id === id);
153
- if (index < 0) return 0;
154
- let scaledOffset = 0;
155
- for(index = index - 1; index >= 0; index--){
156
- const panel = panelsArray[index];
157
- scaledOffset += $d520236daad9c5d5$export$31b21d0167753bb4(panels, panel.id, direction, sizes, height, width);
158
- }
159
- return Math.round(scaledOffset);
157
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
158
+ const size = sizes[index];
159
+ if (size == null) return "0";
160
+ return size.toPrecision((0, $3237bc4a138172cd$export$d6d3992f3becc879));
160
161
  }
161
162
  function $d520236daad9c5d5$export$7361ed18ff57179e(id) {
162
163
  const element = document.querySelector(`[data-panel-id="${id}"]`);
163
164
  if (element) return element;
164
165
  return null;
165
166
  }
167
+ function $d520236daad9c5d5$export$5e67632cf3550a9c(id) {
168
+ const element = document.querySelector(`[data-panel-group-id="${id}"]`);
169
+ if (element) return element;
170
+ return null;
171
+ }
166
172
  function $d520236daad9c5d5$export$2e27d3a347680388(id) {
167
173
  const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
168
174
  if (element) return element;
@@ -193,15 +199,6 @@ function $d520236daad9c5d5$export$68d3a33c21dfbe27(groupId, handleId, panelsArra
193
199
  function $d520236daad9c5d5$export$a861c0ad45885494(panels) {
194
200
  return Array.from(panels.values()).sort((a, b)=>a.order - b.order);
195
201
  }
196
- function $d520236daad9c5d5$export$31b21d0167753bb4(panels, id, direction, sizes, height, width) {
197
- const totalSize = direction === "horizontal" ? width : height;
198
- if (panels.size === 1) return totalSize;
199
- const panelsArray = $d520236daad9c5d5$export$a861c0ad45885494(panels);
200
- const index = panelsArray.findIndex((panel)=>panel.id === id);
201
- const size = sizes[index];
202
- if (size == null) return 0;
203
- return Math.round(size * totalSize);
204
- }
205
202
 
206
203
 
207
204
  function $f5af57c8e042a4ad$export$ec391ce65b083ed4(event, handleId, direction, initialOffset = 0) {
@@ -217,21 +214,23 @@ function $f5af57c8e042a4ad$export$ec391ce65b083ed4(event, handleId, direction, i
217
214
  const elementOffset = isHorizontal ? rect.left : rect.top;
218
215
  return pointerOffset - elementOffset - initialOffset;
219
216
  }
220
- function $f5af57c8e042a4ad$export$354b17c0684607ed(event, handleId, { height: height , width: width }, direction, initialOffset) {
217
+ function $f5af57c8e042a4ad$export$354b17c0684607ed(event, groupId, handleId, direction, initialOffset) {
221
218
  const isHorizontal = direction === "horizontal";
222
- const size = isHorizontal ? width : height;
219
+ const groupElement = (0, $d520236daad9c5d5$export$5e67632cf3550a9c)(groupId);
220
+ const rect = groupElement.getBoundingClientRect();
221
+ const size = isHorizontal ? rect.width : rect.height;
223
222
  if ($f5af57c8e042a4ad$export$e7bf60a870f429b0(event)) {
224
223
  const denominator = event.shiftKey ? 10 : 100;
225
224
  const delta = size / denominator;
226
225
  switch(event.key){
227
226
  case "ArrowDown":
228
- return delta;
227
+ return isHorizontal ? 0 : delta;
229
228
  case "ArrowLeft":
230
- return -delta;
229
+ return isHorizontal ? -delta : 0;
231
230
  case "ArrowRight":
232
- return delta;
231
+ return isHorizontal ? delta : 0;
233
232
  case "ArrowUp":
234
- return -delta;
233
+ return isHorizontal ? 0 : -delta;
235
234
  case "End":
236
235
  if (isHorizontal) return size;
237
236
  else return size;
@@ -258,7 +257,9 @@ function $f5af57c8e042a4ad$export$c4dfce035d43d1e0(event) {
258
257
 
259
258
  function $63be9a96d8675f03$export$d9fcbe062527d159({ committedValuesRef: committedValuesRef , groupId: groupId , panels: panels , setSizes: setSizes , sizes: sizes }) {
260
259
  (0, $b2QPe$react.useEffect)(()=>{
261
- const { direction: direction , height: height , panels: panels , width: width } = committedValuesRef.current;
260
+ const { direction: direction , panels: panels } = committedValuesRef.current;
261
+ const groupElement = (0, $d520236daad9c5d5$export$5e67632cf3550a9c)(groupId);
262
+ const { height: height , width: width } = groupElement.getBoundingClientRect();
262
263
  const handles = (0, $d520236daad9c5d5$export$ae14931f0a0256a3)(groupId);
263
264
  const cleanupFunctions = handles.map((handle)=>{
264
265
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
@@ -268,13 +269,12 @@ function $63be9a96d8675f03$export$d9fcbe062527d159({ committedValuesRef: committ
268
269
  const ariaValueMax = panelsArray.reduce((difference, panel)=>{
269
270
  if (panel.id !== idBefore) return difference - panel.minSize;
270
271
  return difference;
271
- }, 1);
272
+ }, 100);
272
273
  const ariaValueMin = panelsArray.find((panel)=>panel.id == idBefore)?.minSize ?? 0;
273
- const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, idBefore, direction, sizes, height, width);
274
- const ariaValueNow = size / (direction === "horizontal" ? width : height);
275
- handle.setAttribute("aria-valuemax", "" + Math.round(100 * ariaValueMax));
276
- handle.setAttribute("aria-valuemin", "" + Math.round(100 * ariaValueMin));
277
- handle.setAttribute("aria-valuenow", "" + Math.round(100 * ariaValueNow));
274
+ const flexGrow = (0, $d520236daad9c5d5$export$6f43503e166de6fb)(panels, idBefore, sizes);
275
+ handle.setAttribute("aria-valuemax", "" + Math.round(ariaValueMax));
276
+ handle.setAttribute("aria-valuemin", "" + Math.round(ariaValueMin));
277
+ handle.setAttribute("aria-valuenow", "" + Math.round(parseInt(flexGrow)));
278
278
  const onKeyDown = (event)=>{
279
279
  switch(event.key){
280
280
  case "Enter":
@@ -354,7 +354,7 @@ function $63be9a96d8675f03$export$33b0bea6ac3ffb03({ disabled: disabled , handle
354
354
 
355
355
 
356
356
 
357
- function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , height: height , id: idFromProps = null , width: width }) {
357
+ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: className = "" , direction: direction , id: idFromProps = null }) {
358
358
  const groupId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idFromProps);
359
359
  const [activeHandleId, setActiveHandleId] = (0, $b2QPe$react.useState)(null);
360
360
  const [panels, setPanels] = (0, $b2QPe$react.useState)(new Map());
@@ -364,17 +364,13 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
364
364
  // Store committed values to avoid unnecessarily re-running memoization/effects functions.
365
365
  const committedValuesRef = (0, $b2QPe$react.useRef)({
366
366
  direction: direction,
367
- height: height,
368
367
  panels: panels,
369
- sizes: sizes,
370
- width: width
368
+ sizes: sizes
371
369
  });
372
370
  (0, $b2QPe$react.useLayoutEffect)(()=>{
373
371
  committedValuesRef.current.direction = direction;
374
- committedValuesRef.current.height = height;
375
372
  committedValuesRef.current.panels = panels;
376
373
  committedValuesRef.current.sizes = sizes;
377
- committedValuesRef.current.width = width;
378
374
  });
379
375
  (0, $63be9a96d8675f03$export$d9fcbe062527d159)({
380
376
  committedValuesRef: committedValuesRef,
@@ -389,8 +385,6 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
389
385
  (0, $b2QPe$react.useLayoutEffect)(()=>{
390
386
  const sizes = committedValuesRef.current.sizes;
391
387
  if (sizes.length === panels.size) return;
392
- // TODO [panels]
393
- // Validate that the total minSize is <= 1.
394
388
  // If this panel has been configured to persist sizing information,
395
389
  // default size should be restored from local storage if possible.
396
390
  let defaultSizes = undefined;
@@ -401,10 +395,20 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
401
395
  if (defaultSizes != null) setSizes(defaultSizes);
402
396
  else {
403
397
  const panelsArray1 = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
404
- const totalWeight = panelsArray1.reduce((weight, panel)=>{
405
- return weight + panel.defaultSize;
406
- }, 0);
407
- setSizes(panelsArray1.map((panel)=>panel.defaultSize / totalWeight));
398
+ let panelsWithNullDefaultSize = 0;
399
+ let totalDefaultSize = 0;
400
+ let totalMinSize = 0;
401
+ panelsArray1.forEach((panel)=>{
402
+ totalMinSize += panel.minSize;
403
+ if (panel.defaultSize === null) panelsWithNullDefaultSize++;
404
+ else totalDefaultSize += panel.defaultSize;
405
+ });
406
+ if (totalDefaultSize > 100) throw new Error(`The sum of the defaultSize of all panels in a group cannot exceed 100.`);
407
+ else if (totalMinSize > 100) throw new Error(`The sum of the minSize of all panels in a group cannot exceed 100.`);
408
+ setSizes(panelsArray1.map((panel)=>{
409
+ if (panel.defaultSize === null) return (100 - totalDefaultSize) / panelsWithNullDefaultSize;
410
+ return panel.defaultSize;
411
+ }));
408
412
  }
409
413
  }, [
410
414
  autoSaveId,
@@ -424,27 +428,13 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
424
428
  ]);
425
429
  const getPanelStyle = (0, $b2QPe$react.useCallback)((id)=>{
426
430
  const { panels: panels } = committedValuesRef.current;
427
- const offset = (0, $d520236daad9c5d5$export$622cea445a1c5b7d)(panels, id, direction, sizes, height, width);
428
- const size = (0, $d520236daad9c5d5$export$31b21d0167753bb4)(panels, id, direction, sizes, height, width);
429
- if (direction === "horizontal") return {
430
- height: "100%",
431
- position: "absolute",
432
- left: offset,
433
- top: 0,
434
- width: size
435
- };
436
- else return {
437
- height: size,
438
- position: "absolute",
439
- left: 0,
440
- top: offset,
441
- width: "100%"
431
+ const size = (0, $d520236daad9c5d5$export$6f43503e166de6fb)(panels, id, sizes);
432
+ return {
433
+ flexGrow: size
442
434
  };
443
435
  }, [
444
436
  direction,
445
- height,
446
- sizes,
447
- width
437
+ sizes
448
438
  ]);
449
439
  const registerPanel = (0, $b2QPe$react.useCallback)((id, panel)=>{
450
440
  setPanels((prevPanels)=>{
@@ -457,16 +447,17 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
457
447
  const registerResizeHandle = (0, $b2QPe$react.useCallback)((handleId)=>{
458
448
  const resizeHandler = (event)=>{
459
449
  event.preventDefault();
460
- const { direction: direction , height: height , panels: panels , sizes: prevSizes , width: width } = committedValuesRef.current;
450
+ const { direction: direction , panels: panels , sizes: prevSizes } = committedValuesRef.current;
461
451
  const panelsArray = (0, $d520236daad9c5d5$export$a861c0ad45885494)(panels);
462
452
  const [idBefore, idAfter] = (0, $d520236daad9c5d5$export$68d3a33c21dfbe27)(groupId, handleId, panelsArray);
463
453
  if (idBefore == null || idAfter == null) return;
464
- const movement = (0, $f5af57c8e042a4ad$export$354b17c0684607ed)(event, handleId, {
465
- height: height,
466
- width: width
467
- }, direction, dragOffsetRef.current);
454
+ const movement = (0, $f5af57c8e042a4ad$export$354b17c0684607ed)(event, groupId, handleId, direction, dragOffsetRef.current);
455
+ if (movement === 0) return;
456
+ const groupElement = (0, $d520236daad9c5d5$export$5e67632cf3550a9c)(groupId);
457
+ const rect = groupElement.getBoundingClientRect();
468
458
  const isHorizontal = direction === "horizontal";
469
- const delta = isHorizontal ? movement / width : movement / height;
459
+ const size = isHorizontal ? rect.width : rect.height;
460
+ const delta = movement / size * 100;
470
461
  const nextSizes = (0, $d520236daad9c5d5$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
471
462
  if (prevSizes !== nextSizes) setSizes(nextSizes);
472
463
  };
@@ -482,7 +473,8 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
482
473
  return nextPanels;
483
474
  });
484
475
  }, []);
485
- const panelGroupContext = (0, $b2QPe$react.useMemo)(()=>({
476
+ const context = (0, $b2QPe$react.useMemo)(()=>({
477
+ activeHandleId: activeHandleId,
486
478
  direction: direction,
487
479
  getPanelStyle: getPanelStyle,
488
480
  groupId: groupId,
@@ -497,6 +489,7 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
497
489
  },
498
490
  unregisterPanel: unregisterPanel
499
491
  }), [
492
+ activeHandleId,
500
493
  direction,
501
494
  getPanelStyle,
502
495
  groupId,
@@ -504,25 +497,19 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
504
497
  registerResizeHandle,
505
498
  unregisterPanel
506
499
  ]);
507
- const panelContext = (0, $b2QPe$react.useMemo)(()=>({
508
- activeHandleId: activeHandleId
509
- }), [
510
- activeHandleId
511
- ]);
512
- return /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)((0, $3251d17c1c3bce6c$export$f34532ac99e32150).Provider, {
513
- value: panelContext,
514
- children: /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
515
- value: panelGroupContext,
516
- children: /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)("div", {
517
- className: className,
518
- "data-panel-group-id": groupId,
519
- style: {
520
- height: height,
521
- position: "relative",
522
- width: width
523
- },
524
- children: children
525
- })
500
+ const style = {
501
+ display: "flex",
502
+ flexDirection: direction === "horizontal" ? "row" : "column",
503
+ height: "100%",
504
+ width: "100%"
505
+ };
506
+ return /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a).Provider, {
507
+ value: context,
508
+ children: /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)("div", {
509
+ className: className,
510
+ "data-panel-group-id": groupId,
511
+ style: style,
512
+ children: children
526
513
  })
527
514
  });
528
515
  }
@@ -535,13 +522,12 @@ function $d428eaeef644efb2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
535
522
 
536
523
  function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null , className: className = "" , disabled: disabled = false , id: idFromProps = null }) {
537
524
  const divElementRef = (0, $b2QPe$react.useRef)(null);
538
- const panelContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$f34532ac99e32150));
539
525
  const panelGroupContext = (0, $b2QPe$react.useContext)((0, $3251d17c1c3bce6c$export$7d8c6d083caec74a));
540
- if (panelContext === null || panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
541
- const { activeHandleId: activeHandleId } = panelContext;
542
- const { direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
526
+ if (panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
527
+ const { activeHandleId: activeHandleId , direction: direction , groupId: groupId , registerResizeHandle: registerResizeHandle , startDragging: startDragging , stopDragging: stopDragging } = panelGroupContext;
543
528
  const resizeHandleId = (0, $6d548a0d130941e3$export$2e2bcd8739ae039)(idFromProps);
544
529
  const isDragging = activeHandleId === resizeHandleId;
530
+ const [isFocused, setIsFocused] = (0, $b2QPe$react.useState)(false);
545
531
  const [resizeHandler, setResizeHandler] = (0, $b2QPe$react.useState)(null);
546
532
  const stopDraggingAndBlur = (0, $b2QPe$react.useCallback)(()=>{
547
533
  // Clicking on the drag handle shouldn't leave it focused;
@@ -596,9 +582,12 @@ function $d578a49f00f1bdeb$export$2e2bcd8739ae039({ children: children = null ,
596
582
  });
597
583
  return /*#__PURE__*/ (0, $b2QPe$reactjsxruntime.jsx)("div", {
598
584
  className: className,
585
+ "data-resize-handle-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
599
586
  "data-panel-group-id": groupId,
600
587
  "data-panel-resize-handle-enabled": !disabled,
601
588
  "data-panel-resize-handle-id": resizeHandleId,
589
+ onBlur: ()=>setIsFocused(false),
590
+ onFocus: ()=>setIsFocused(true),
602
591
  onMouseDown: (event)=>startDragging(resizeHandleId, event.nativeEvent),
603
592
  onMouseUp: stopDraggingAndBlur,
604
593
  onTouchCancel: stopDraggingAndBlur,