react-resizable-panels 1.0.8 → 1.0.10

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +16 -15
  3. package/dist/declarations/src/index.d.ts +1 -3
  4. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
  5. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
  6. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
  7. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
  8. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -1
  9. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
  10. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +1 -1
  11. package/dist/react-resizable-panels.browser.cjs.js +56 -51
  12. package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
  13. package/dist/react-resizable-panels.browser.development.cjs.js +56 -51
  14. package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
  15. package/dist/react-resizable-panels.browser.development.esm.js +57 -50
  16. package/dist/react-resizable-panels.browser.esm.js +57 -50
  17. package/dist/react-resizable-panels.cjs.js +56 -51
  18. package/dist/react-resizable-panels.cjs.mjs +0 -2
  19. package/dist/react-resizable-panels.development.cjs.js +56 -51
  20. package/dist/react-resizable-panels.development.cjs.mjs +0 -2
  21. package/dist/react-resizable-panels.development.esm.js +57 -50
  22. package/dist/react-resizable-panels.development.node.cjs.js +47 -51
  23. package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
  24. package/dist/react-resizable-panels.development.node.esm.js +48 -50
  25. package/dist/react-resizable-panels.esm.js +57 -50
  26. package/dist/react-resizable-panels.node.cjs.js +47 -51
  27. package/dist/react-resizable-panels.node.cjs.mjs +0 -2
  28. package/dist/react-resizable-panels.node.esm.js +48 -50
  29. package/package.json +1 -1
  30. package/src/Panel.test.tsx +186 -0
  31. package/src/Panel.ts +14 -0
  32. package/src/PanelGroup.ts +46 -7
  33. package/src/PanelGroupContext.ts +5 -1
  34. package/src/index.ts +0 -4
  35. package/src/utils/dom/getPanelElement.ts +2 -2
  36. package/src/utils/dom/getPanelElementsForGroup.ts +2 -4
  37. package/src/utils/dom/getPanelGroupElement.ts +1 -1
  38. package/src/utils/dom/getResizeHandleElement.ts +2 -4
  39. package/src/utils/dom/getResizeHandleElementIndex.ts +2 -2
  40. package/src/utils/dom/getResizeHandleElementsForGroup.ts +2 -2
  41. package/src/utils/dom/getResizeHandlePanelIds.ts +3 -3
  42. package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +0 -1
  43. package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +0 -1
  44. package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +0 -34
  45. package/src/utils/dom/getAvailableGroupSizePixels.ts +0 -30
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.10
4
+
5
+ - Fixed edge case constraints check bug that could cause a collapsed panel to re-expand unnecessarily (#273)
6
+
7
+ ## 1.0.9
8
+
9
+ - DOM util methods scope param defaults to `document` (#262)
10
+ - Updating a `Panel`'s pixel constraints will trigger revalidation of the `Panel`'s size (#266)
11
+
3
12
  ## 1.0.8
4
13
 
5
14
  - Update component signature to declare `ReactElement` return type (rather than `ReactNode`) (#256)
package/README.md CHANGED
@@ -52,21 +52,22 @@ import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
52
52
 
53
53
  ### `Panel`
54
54
 
55
- | prop | type | description |
56
- | :-------------- | :------------------------------ | :-------------------------------------------------------------------------------------------- |
57
- | `children` | `ReactNode` | Arbitrary React element(s) |
58
- | `className` | `?string` | Class name to attach to root element |
59
- | `collapsedSize` | `?number=0` | Panel should collapse to this size |
60
- | `collapsible` | `?boolean=false` | Panel should collapse when resized beyond its `minSize` |
61
- | `defaultSize` | `?number` | Initial size of panel (numeric value between 1-100) |
62
- | `id` | `?string` | Panel id (unique within group); falls back to `useId` when not provided |
63
- | `maxSize` | `?number = 100` | Maximum allowable size of panel (numeric value between 1-100); defaults to `100` |
64
- | `minSize` | `?number = 10` | Minimum allowable size of panel (numeric value between 1-100); defaults to `10` |
65
- | `onCollapse` | `?(collapsed: boolean) => void` | Called when panel is collapsed; `collapsed` boolean parameter reflecting the new state |
66
- | `onResize` | `?(size: number) => void` | Called when panel is resized; `size` parameter is a numeric value between 1-100. <sup>1</sup> |
67
- | `order` | `?number` | Order of panel within group; required for groups with conditionally rendered panels |
68
- | `style` | `?CSSProperties` | CSS style to attach to root element |
69
- | `tagName` | `?string = "div"` | HTML element tag name for root element |
55
+ | prop | type | description |
56
+ | :-------------- | :------------------------ | :-------------------------------------------------------------------------------------------- |
57
+ | `children` | `ReactNode` | Arbitrary React element(s) |
58
+ | `className` | `?string` | Class name to attach to root element |
59
+ | `collapsedSize` | `?number=0` | Panel should collapse to this size |
60
+ | `collapsible` | `?boolean=false` | Panel should collapse when resized beyond its `minSize` |
61
+ | `defaultSize` | `?number` | Initial size of panel (numeric value between 1-100) |
62
+ | `id` | `?string` | Panel id (unique within group); falls back to `useId` when not provided |
63
+ | `maxSize` | `?number = 100` | Maximum allowable size of panel (numeric value between 1-100); defaults to `100` |
64
+ | `minSize` | `?number = 10` | Minimum allowable size of panel (numeric value between 1-100); defaults to `10` |
65
+ | `onCollapse` | `?() => void` | Called when panel is collapsed |
66
+ | `onExpand` | `?() => void` | Called when panel is expanded |
67
+ | `onResize` | `?(size: number) => void` | Called when panel is resized; `size` parameter is a numeric value between 1-100. <sup>1</sup> |
68
+ | `order` | `?number` | Order of panel within group; required for groups with conditionally rendered panels |
69
+ | `style` | `?CSSProperties` | CSS style to attach to root element |
70
+ | `tagName` | `?string = "div"` | HTML element tag name for root element |
70
71
 
71
72
  <sup>1</sup>: If any `Panel` has an `onResize` callback, the `order` prop should be provided for all `Panel`s.
72
73
 
@@ -2,8 +2,6 @@ import { Panel } from "./Panel.js";
2
2
  import { PanelGroup } from "./PanelGroup.js";
3
3
  import { PanelResizeHandle } from "./PanelResizeHandle.js";
4
4
  import { assert } from "./utils/assert.js";
5
- import { calculateAvailablePanelSizeInPixels } from "./utils/dom/calculateAvailablePanelSizeInPixels.js";
6
- import { getAvailableGroupSizePixels } from "./utils/dom/getAvailableGroupSizePixels.js";
7
5
  import { getPanelElement } from "./utils/dom/getPanelElement.js";
8
6
  import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup.js";
9
7
  import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement.js";
@@ -14,4 +12,4 @@ import { getResizeHandlePanelIds } from "./utils/dom/getResizeHandlePanelIds.js"
14
12
  import type { ImperativePanelHandle, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps } from "./Panel.js";
15
13
  import type { ImperativePanelGroupHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage } from "./PanelGroup.js";
16
14
  import type { PanelResizeHandleOnDragging, PanelResizeHandleProps } from "./PanelResizeHandle.js";
17
- export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, };
15
+ export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, };
@@ -1 +1 @@
1
- export declare function getPanelElement(id: string, panelGroupElement: HTMLElement): HTMLElement | null;
1
+ export declare function getPanelElement(id: string, scope?: ParentNode | HTMLElement): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getPanelElementsForGroup(groupId: string, panelGroupElement: HTMLElement): HTMLElement[];
1
+ export declare function getPanelElementsForGroup(groupId: string, scope?: ParentNode | HTMLElement): HTMLElement[];
@@ -1 +1 @@
1
- export declare function getPanelGroupElement(id: string, rootElement: ParentNode | HTMLElement): HTMLElement | null;
1
+ export declare function getPanelGroupElement(id: string, rootElement?: ParentNode | HTMLElement): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getResizeHandleElement(id: string, panelGroupElement: ParentNode): HTMLElement | null;
1
+ export declare function getResizeHandleElement(id: string, scope?: ParentNode | HTMLElement): HTMLElement | null;
@@ -1 +1 @@
1
- export declare function getResizeHandleElementIndex(groupId: string, id: string, panelGroupElement: ParentNode): number | null;
1
+ export declare function getResizeHandleElementIndex(groupId: string, id: string, scope?: ParentNode | HTMLElement): number | null;
@@ -1 +1 @@
1
- export declare function getResizeHandleElementsForGroup(groupId: string, panelGroupElement: ParentNode): HTMLElement[];
1
+ export declare function getResizeHandleElementsForGroup(groupId: string, scope?: ParentNode | HTMLElement): HTMLElement[];
@@ -1,2 +1,2 @@
1
1
  import { PanelData } from "../../Panel.js";
2
- export declare function getResizeHandlePanelIds(groupId: string, handleId: string, panelsArray: PanelData[], panelGroupElement: ParentNode): [idBefore: string | null, idAfter: string | null];
2
+ export declare function getResizeHandlePanelIds(groupId: string, handleId: string, panelsArray: PanelData[], scope?: ParentNode | HTMLElement): [idBefore: string | null, idAfter: string | null];
@@ -91,6 +91,7 @@ function PanelWithForwardedRef({
91
91
  getPanelStyle,
92
92
  groupId,
93
93
  isPanelCollapsed,
94
+ reevaluatePanelConstraints,
94
95
  registerPanel,
95
96
  resizePanel,
96
97
  unregisterPanel
@@ -121,6 +122,9 @@ function PanelWithForwardedRef({
121
122
  callbacks,
122
123
  constraints
123
124
  } = panelDataRef.current;
125
+ const prevConstraints = {
126
+ ...constraints
127
+ };
124
128
  panelDataRef.current.id = panelId;
125
129
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
126
130
  panelDataRef.current.order = order;
@@ -132,6 +136,12 @@ function PanelWithForwardedRef({
132
136
  constraints.defaultSize = defaultSize;
133
137
  constraints.maxSize = maxSize;
134
138
  constraints.minSize = minSize;
139
+
140
+ // If constraints have changed, we should revisit panel sizes.
141
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
142
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
143
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
144
+ }
135
145
  });
136
146
  useIsomorphicLayoutEffect(() => {
137
147
  const panelData = panelDataRef.current;
@@ -519,12 +529,12 @@ function calculateAriaValues({
519
529
  };
520
530
  }
521
531
 
522
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
523
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
532
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
533
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
524
534
  }
525
535
 
526
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
527
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
536
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
537
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
528
538
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
529
539
  return index !== null && index !== void 0 ? index : null;
530
540
  }
@@ -534,7 +544,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
534
544
  return index != null ? [index, index + 1] : [-1, -1];
535
545
  }
536
546
 
537
- function getPanelGroupElement(id, rootElement) {
547
+ function getPanelGroupElement(id, rootElement = document) {
538
548
  var _dataset;
539
549
  //If the root element is the PanelGroup
540
550
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -549,18 +559,18 @@ function getPanelGroupElement(id, rootElement) {
549
559
  return null;
550
560
  }
551
561
 
552
- function getResizeHandleElement(id, panelGroupElement) {
553
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
562
+ function getResizeHandleElement(id, scope = document) {
563
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
554
564
  if (element) {
555
565
  return element;
556
566
  }
557
567
  return null;
558
568
  }
559
569
 
560
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
570
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
561
571
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
562
- const handle = getResizeHandleElement(handleId, panelGroupElement);
563
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
572
+ const handle = getResizeHandleElement(handleId, scope);
573
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
564
574
  const index = handle ? handles.indexOf(handle) : -1;
565
575
  const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
566
576
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1545,6 +1555,35 @@ function PanelGroupWithForwardedRef({
1545
1555
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1546
1556
  }
1547
1557
  }, []);
1558
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1559
+ const {
1560
+ layout,
1561
+ panelDataArray
1562
+ } = eagerValuesRef.current;
1563
+ const {
1564
+ collapsedSize: prevCollapsedSize = 0,
1565
+ collapsible: prevCollapsible
1566
+ } = prevConstraints;
1567
+ const {
1568
+ collapsedSize: nextCollapsedSize = 0,
1569
+ collapsible: nextCollapsible,
1570
+ maxSize: nextMaxSize = 100,
1571
+ minSize: nextMinSize = 0
1572
+ } = panelData.constraints;
1573
+ const {
1574
+ panelSize: prevPanelSize
1575
+ } = panelDataHelper(panelDataArray, panelData, layout);
1576
+ assert(prevPanelSize != null);
1577
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1578
+ if (prevCollapsedSize !== nextCollapsedSize) {
1579
+ resizePanel(panelData, nextCollapsedSize);
1580
+ }
1581
+ } else if (prevPanelSize < nextMinSize) {
1582
+ resizePanel(panelData, nextMinSize);
1583
+ } else if (prevPanelSize > nextMaxSize) {
1584
+ resizePanel(panelData, nextMaxSize);
1585
+ }
1586
+ }, [resizePanel]);
1548
1587
  const startDragging = useCallback((dragHandleId, event) => {
1549
1588
  const {
1550
1589
  direction
@@ -1595,6 +1634,7 @@ function PanelGroupWithForwardedRef({
1595
1634
  groupId,
1596
1635
  isPanelCollapsed,
1597
1636
  isPanelExpanded,
1637
+ reevaluatePanelConstraints,
1598
1638
  registerPanel,
1599
1639
  registerResizeHandle,
1600
1640
  resizePanel,
@@ -1602,7 +1642,7 @@ function PanelGroupWithForwardedRef({
1602
1642
  stopDragging,
1603
1643
  unregisterPanel,
1604
1644
  panelGroupElement: panelGroupElementRef.current
1605
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1645
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1606
1646
  const style = {
1607
1647
  display: "flex",
1608
1648
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1637,14 +1677,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1637
1677
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1638
1678
  }
1639
1679
  function panelDataHelper(panelDataArray, panelData, layout) {
1640
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1641
1680
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1642
- const panelConstraints = panelConstraintsArray[panelIndex];
1643
1681
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1644
1682
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1645
1683
  const panelSize = layout[panelIndex];
1646
1684
  return {
1647
- ...panelConstraints,
1685
+ ...panelData.constraints,
1648
1686
  panelSize,
1649
1687
  pivotIndices
1650
1688
  };
@@ -1851,55 +1889,22 @@ function PanelResizeHandle({
1851
1889
  }
1852
1890
  PanelResizeHandle.displayName = "PanelResizeHandle";
1853
1891
 
1854
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1855
- if (panelGroupElement == null) {
1856
- return NaN;
1857
- }
1858
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1859
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1860
- if (direction === "horizontal") {
1861
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1862
- return accumulated + handle.offsetWidth;
1863
- }, 0);
1864
- } else {
1865
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1866
- return accumulated + handle.offsetHeight;
1867
- }, 0);
1868
- }
1869
- }
1870
-
1871
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1872
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1873
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1874
- if (direction === "horizontal") {
1875
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1876
- return accumulated + handle.offsetWidth;
1877
- }, 0);
1878
- } else {
1879
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1880
- return accumulated + handle.offsetHeight;
1881
- }, 0);
1882
- }
1883
- }
1884
-
1885
- function getPanelElement(id, panelGroupElement) {
1886
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1892
+ function getPanelElement(id, scope = document) {
1893
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1887
1894
  if (element) {
1888
1895
  return element;
1889
1896
  }
1890
1897
  return null;
1891
1898
  }
1892
1899
 
1893
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1894
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1900
+ function getPanelElementsForGroup(groupId, scope = document) {
1901
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1895
1902
  }
1896
1903
 
1897
1904
  exports.Panel = Panel;
1898
1905
  exports.PanelGroup = PanelGroup;
1899
1906
  exports.PanelResizeHandle = PanelResizeHandle;
1900
1907
  exports.assert = assert;
1901
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1902
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1903
1908
  exports.getPanelElement = getPanelElement;
1904
1909
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
1905
1910
  exports.getPanelGroupElement = getPanelGroupElement;
@@ -3,8 +3,6 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
- calculateAvailablePanelSizeInPixels,
7
- getAvailableGroupSizePixels,
8
6
  getPanelElement,
9
7
  getPanelElementsForGroup,
10
8
  getPanelGroupElement,
@@ -91,6 +91,7 @@ function PanelWithForwardedRef({
91
91
  getPanelStyle,
92
92
  groupId,
93
93
  isPanelCollapsed,
94
+ reevaluatePanelConstraints,
94
95
  registerPanel,
95
96
  resizePanel,
96
97
  unregisterPanel
@@ -127,6 +128,9 @@ function PanelWithForwardedRef({
127
128
  callbacks,
128
129
  constraints
129
130
  } = panelDataRef.current;
131
+ const prevConstraints = {
132
+ ...constraints
133
+ };
130
134
  panelDataRef.current.id = panelId;
131
135
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
132
136
  panelDataRef.current.order = order;
@@ -138,6 +142,12 @@ function PanelWithForwardedRef({
138
142
  constraints.defaultSize = defaultSize;
139
143
  constraints.maxSize = maxSize;
140
144
  constraints.minSize = minSize;
145
+
146
+ // If constraints have changed, we should revisit panel sizes.
147
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
148
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
149
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
150
+ }
141
151
  });
142
152
  useIsomorphicLayoutEffect(() => {
143
153
  const panelData = panelDataRef.current;
@@ -525,12 +535,12 @@ function calculateAriaValues({
525
535
  };
526
536
  }
527
537
 
528
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
529
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
538
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
539
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
530
540
  }
531
541
 
532
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
533
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
542
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
543
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
534
544
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
535
545
  return index !== null && index !== void 0 ? index : null;
536
546
  }
@@ -540,7 +550,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
540
550
  return index != null ? [index, index + 1] : [-1, -1];
541
551
  }
542
552
 
543
- function getPanelGroupElement(id, rootElement) {
553
+ function getPanelGroupElement(id, rootElement = document) {
544
554
  var _dataset;
545
555
  //If the root element is the PanelGroup
546
556
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -555,18 +565,18 @@ function getPanelGroupElement(id, rootElement) {
555
565
  return null;
556
566
  }
557
567
 
558
- function getResizeHandleElement(id, panelGroupElement) {
559
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
568
+ function getResizeHandleElement(id, scope = document) {
569
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
560
570
  if (element) {
561
571
  return element;
562
572
  }
563
573
  return null;
564
574
  }
565
575
 
566
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
576
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
567
577
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
568
- const handle = getResizeHandleElement(handleId, panelGroupElement);
569
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
578
+ const handle = getResizeHandleElement(handleId, scope);
579
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
570
580
  const index = handle ? handles.indexOf(handle) : -1;
571
581
  const idBefore = (_panelsArray$index$id = (_panelsArray$index = panelsArray[index]) === null || _panelsArray$index === void 0 ? void 0 : _panelsArray$index.id) !== null && _panelsArray$index$id !== void 0 ? _panelsArray$index$id : null;
572
582
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1651,6 +1661,35 @@ function PanelGroupWithForwardedRef({
1651
1661
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1652
1662
  }
1653
1663
  }, []);
1664
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1665
+ const {
1666
+ layout,
1667
+ panelDataArray
1668
+ } = eagerValuesRef.current;
1669
+ const {
1670
+ collapsedSize: prevCollapsedSize = 0,
1671
+ collapsible: prevCollapsible
1672
+ } = prevConstraints;
1673
+ const {
1674
+ collapsedSize: nextCollapsedSize = 0,
1675
+ collapsible: nextCollapsible,
1676
+ maxSize: nextMaxSize = 100,
1677
+ minSize: nextMinSize = 0
1678
+ } = panelData.constraints;
1679
+ const {
1680
+ panelSize: prevPanelSize
1681
+ } = panelDataHelper(panelDataArray, panelData, layout);
1682
+ assert(prevPanelSize != null);
1683
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1684
+ if (prevCollapsedSize !== nextCollapsedSize) {
1685
+ resizePanel(panelData, nextCollapsedSize);
1686
+ }
1687
+ } else if (prevPanelSize < nextMinSize) {
1688
+ resizePanel(panelData, nextMinSize);
1689
+ } else if (prevPanelSize > nextMaxSize) {
1690
+ resizePanel(panelData, nextMaxSize);
1691
+ }
1692
+ }, [resizePanel]);
1654
1693
  const startDragging = useCallback((dragHandleId, event) => {
1655
1694
  const {
1656
1695
  direction
@@ -1701,6 +1740,7 @@ function PanelGroupWithForwardedRef({
1701
1740
  groupId,
1702
1741
  isPanelCollapsed,
1703
1742
  isPanelExpanded,
1743
+ reevaluatePanelConstraints,
1704
1744
  registerPanel,
1705
1745
  registerResizeHandle,
1706
1746
  resizePanel,
@@ -1708,7 +1748,7 @@ function PanelGroupWithForwardedRef({
1708
1748
  stopDragging,
1709
1749
  unregisterPanel,
1710
1750
  panelGroupElement: panelGroupElementRef.current
1711
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1751
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1712
1752
  const style = {
1713
1753
  display: "flex",
1714
1754
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1743,14 +1783,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1743
1783
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1744
1784
  }
1745
1785
  function panelDataHelper(panelDataArray, panelData, layout) {
1746
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1747
1786
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1748
- const panelConstraints = panelConstraintsArray[panelIndex];
1749
1787
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1750
1788
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1751
1789
  const panelSize = layout[panelIndex];
1752
1790
  return {
1753
- ...panelConstraints,
1791
+ ...panelData.constraints,
1754
1792
  panelSize,
1755
1793
  pivotIndices
1756
1794
  };
@@ -1957,55 +1995,22 @@ function PanelResizeHandle({
1957
1995
  }
1958
1996
  PanelResizeHandle.displayName = "PanelResizeHandle";
1959
1997
 
1960
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1961
- if (panelGroupElement == null) {
1962
- return NaN;
1963
- }
1964
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1965
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1966
- if (direction === "horizontal") {
1967
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1968
- return accumulated + handle.offsetWidth;
1969
- }, 0);
1970
- } else {
1971
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1972
- return accumulated + handle.offsetHeight;
1973
- }, 0);
1974
- }
1975
- }
1976
-
1977
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1978
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1979
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1980
- if (direction === "horizontal") {
1981
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1982
- return accumulated + handle.offsetWidth;
1983
- }, 0);
1984
- } else {
1985
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1986
- return accumulated + handle.offsetHeight;
1987
- }, 0);
1988
- }
1989
- }
1990
-
1991
- function getPanelElement(id, panelGroupElement) {
1992
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1998
+ function getPanelElement(id, scope = document) {
1999
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1993
2000
  if (element) {
1994
2001
  return element;
1995
2002
  }
1996
2003
  return null;
1997
2004
  }
1998
2005
 
1999
- function getPanelElementsForGroup(groupId, panelGroupElement) {
2000
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2006
+ function getPanelElementsForGroup(groupId, scope = document) {
2007
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2001
2008
  }
2002
2009
 
2003
2010
  exports.Panel = Panel;
2004
2011
  exports.PanelGroup = PanelGroup;
2005
2012
  exports.PanelResizeHandle = PanelResizeHandle;
2006
2013
  exports.assert = assert;
2007
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
2008
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
2009
2014
  exports.getPanelElement = getPanelElement;
2010
2015
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
2011
2016
  exports.getPanelGroupElement = getPanelGroupElement;
@@ -3,8 +3,6 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
- calculateAvailablePanelSizeInPixels,
7
- getAvailableGroupSizePixels,
8
6
  getPanelElement,
9
7
  getPanelElementsForGroup,
10
8
  getPanelGroupElement,