react-resizable-panels 1.0.8 → 1.0.9

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 +5 -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 +58 -51
  12. package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
  13. package/dist/react-resizable-panels.browser.development.cjs.js +58 -51
  14. package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
  15. package/dist/react-resizable-panels.browser.development.esm.js +59 -50
  16. package/dist/react-resizable-panels.browser.esm.js +59 -50
  17. package/dist/react-resizable-panels.cjs.js +58 -51
  18. package/dist/react-resizable-panels.cjs.mjs +0 -2
  19. package/dist/react-resizable-panels.development.cjs.js +58 -51
  20. package/dist/react-resizable-panels.development.cjs.mjs +0 -2
  21. package/dist/react-resizable-panels.development.esm.js +59 -50
  22. package/dist/react-resizable-panels.development.node.cjs.js +49 -51
  23. package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
  24. package/dist/react-resizable-panels.development.node.esm.js +50 -50
  25. package/dist/react-resizable-panels.esm.js +59 -50
  26. package/dist/react-resizable-panels.node.cjs.js +49 -51
  27. package/dist/react-resizable-panels.node.cjs.mjs +0 -2
  28. package/dist/react-resizable-panels.node.esm.js +50 -50
  29. package/package.json +1 -1
  30. package/src/Panel.test.tsx +134 -0
  31. package/src/Panel.ts +14 -0
  32. package/src/PanelGroup.ts +47 -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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.9
4
+
5
+ - DOM util methods scope param defaults to `document` (#262)
6
+ - Updating a `Panel`'s pixel constraints will trigger revalidation of the `Panel`'s size (#266)
7
+
3
8
  ## 1.0.8
4
9
 
5
10
  - 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
+ | `onExpande` | `?() => 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,37 @@ 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
+ defaultSize: prevDefaultSize,
1567
+ maxSize: prevMaxSize = 100,
1568
+ minSize: prevMinSize = 0
1569
+ } = prevConstraints;
1570
+ const {
1571
+ collapsedSize: nextCollapsedSize = 0,
1572
+ collapsible: nextCollapsible,
1573
+ defaultSize: nextDefaultSize,
1574
+ maxSize: nextMaxSize = 100,
1575
+ minSize: nextMinSize = 0
1576
+ } = panelData.constraints;
1577
+ const {
1578
+ panelSize: prevPanelSize
1579
+ } = panelDataHelper(panelDataArray, panelData, layout);
1580
+ assert(prevPanelSize != null);
1581
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1582
+ resizePanel(panelData, nextCollapsedSize);
1583
+ } else if (prevPanelSize < nextMinSize) {
1584
+ resizePanel(panelData, nextMinSize);
1585
+ } else if (prevPanelSize > nextMaxSize) {
1586
+ resizePanel(panelData, nextMaxSize);
1587
+ }
1588
+ }, [resizePanel]);
1548
1589
  const startDragging = useCallback((dragHandleId, event) => {
1549
1590
  const {
1550
1591
  direction
@@ -1595,6 +1636,7 @@ function PanelGroupWithForwardedRef({
1595
1636
  groupId,
1596
1637
  isPanelCollapsed,
1597
1638
  isPanelExpanded,
1639
+ reevaluatePanelConstraints,
1598
1640
  registerPanel,
1599
1641
  registerResizeHandle,
1600
1642
  resizePanel,
@@ -1602,7 +1644,7 @@ function PanelGroupWithForwardedRef({
1602
1644
  stopDragging,
1603
1645
  unregisterPanel,
1604
1646
  panelGroupElement: panelGroupElementRef.current
1605
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1647
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1606
1648
  const style = {
1607
1649
  display: "flex",
1608
1650
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1637,14 +1679,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1637
1679
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1638
1680
  }
1639
1681
  function panelDataHelper(panelDataArray, panelData, layout) {
1640
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1641
1682
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1642
- const panelConstraints = panelConstraintsArray[panelIndex];
1643
1683
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1644
1684
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1645
1685
  const panelSize = layout[panelIndex];
1646
1686
  return {
1647
- ...panelConstraints,
1687
+ ...panelData.constraints,
1648
1688
  panelSize,
1649
1689
  pivotIndices
1650
1690
  };
@@ -1851,55 +1891,22 @@ function PanelResizeHandle({
1851
1891
  }
1852
1892
  PanelResizeHandle.displayName = "PanelResizeHandle";
1853
1893
 
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}"]`);
1894
+ function getPanelElement(id, scope = document) {
1895
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1887
1896
  if (element) {
1888
1897
  return element;
1889
1898
  }
1890
1899
  return null;
1891
1900
  }
1892
1901
 
1893
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1894
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1902
+ function getPanelElementsForGroup(groupId, scope = document) {
1903
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1895
1904
  }
1896
1905
 
1897
1906
  exports.Panel = Panel;
1898
1907
  exports.PanelGroup = PanelGroup;
1899
1908
  exports.PanelResizeHandle = PanelResizeHandle;
1900
1909
  exports.assert = assert;
1901
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1902
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1903
1910
  exports.getPanelElement = getPanelElement;
1904
1911
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
1905
1912
  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,37 @@ 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
+ defaultSize: prevDefaultSize,
1673
+ maxSize: prevMaxSize = 100,
1674
+ minSize: prevMinSize = 0
1675
+ } = prevConstraints;
1676
+ const {
1677
+ collapsedSize: nextCollapsedSize = 0,
1678
+ collapsible: nextCollapsible,
1679
+ defaultSize: nextDefaultSize,
1680
+ maxSize: nextMaxSize = 100,
1681
+ minSize: nextMinSize = 0
1682
+ } = panelData.constraints;
1683
+ const {
1684
+ panelSize: prevPanelSize
1685
+ } = panelDataHelper(panelDataArray, panelData, layout);
1686
+ assert(prevPanelSize != null);
1687
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1688
+ resizePanel(panelData, nextCollapsedSize);
1689
+ } else if (prevPanelSize < nextMinSize) {
1690
+ resizePanel(panelData, nextMinSize);
1691
+ } else if (prevPanelSize > nextMaxSize) {
1692
+ resizePanel(panelData, nextMaxSize);
1693
+ }
1694
+ }, [resizePanel]);
1654
1695
  const startDragging = useCallback((dragHandleId, event) => {
1655
1696
  const {
1656
1697
  direction
@@ -1701,6 +1742,7 @@ function PanelGroupWithForwardedRef({
1701
1742
  groupId,
1702
1743
  isPanelCollapsed,
1703
1744
  isPanelExpanded,
1745
+ reevaluatePanelConstraints,
1704
1746
  registerPanel,
1705
1747
  registerResizeHandle,
1706
1748
  resizePanel,
@@ -1708,7 +1750,7 @@ function PanelGroupWithForwardedRef({
1708
1750
  stopDragging,
1709
1751
  unregisterPanel,
1710
1752
  panelGroupElement: panelGroupElementRef.current
1711
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1753
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1712
1754
  const style = {
1713
1755
  display: "flex",
1714
1756
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1743,14 +1785,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1743
1785
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1744
1786
  }
1745
1787
  function panelDataHelper(panelDataArray, panelData, layout) {
1746
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1747
1788
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1748
- const panelConstraints = panelConstraintsArray[panelIndex];
1749
1789
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1750
1790
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1751
1791
  const panelSize = layout[panelIndex];
1752
1792
  return {
1753
- ...panelConstraints,
1793
+ ...panelData.constraints,
1754
1794
  panelSize,
1755
1795
  pivotIndices
1756
1796
  };
@@ -1957,55 +1997,22 @@ function PanelResizeHandle({
1957
1997
  }
1958
1998
  PanelResizeHandle.displayName = "PanelResizeHandle";
1959
1999
 
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}"]`);
2000
+ function getPanelElement(id, scope = document) {
2001
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1993
2002
  if (element) {
1994
2003
  return element;
1995
2004
  }
1996
2005
  return null;
1997
2006
  }
1998
2007
 
1999
- function getPanelElementsForGroup(groupId, panelGroupElement) {
2000
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2008
+ function getPanelElementsForGroup(groupId, scope = document) {
2009
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2001
2010
  }
2002
2011
 
2003
2012
  exports.Panel = Panel;
2004
2013
  exports.PanelGroup = PanelGroup;
2005
2014
  exports.PanelResizeHandle = PanelResizeHandle;
2006
2015
  exports.assert = assert;
2007
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
2008
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
2009
2016
  exports.getPanelElement = getPanelElement;
2010
2017
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
2011
2018
  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,