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
@@ -93,6 +93,7 @@ function PanelWithForwardedRef({
93
93
  getPanelStyle,
94
94
  groupId,
95
95
  isPanelCollapsed,
96
+ reevaluatePanelConstraints,
96
97
  registerPanel,
97
98
  resizePanel,
98
99
  unregisterPanel
@@ -134,6 +135,9 @@ function PanelWithForwardedRef({
134
135
  callbacks,
135
136
  constraints
136
137
  } = panelDataRef.current;
138
+ const prevConstraints = {
139
+ ...constraints
140
+ };
137
141
  panelDataRef.current.id = panelId;
138
142
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
139
143
  panelDataRef.current.order = order;
@@ -145,6 +149,12 @@ function PanelWithForwardedRef({
145
149
  constraints.defaultSize = defaultSize;
146
150
  constraints.maxSize = maxSize;
147
151
  constraints.minSize = minSize;
152
+
153
+ // If constraints have changed, we should revisit panel sizes.
154
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
155
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
156
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
157
+ }
148
158
  });
149
159
  useIsomorphicLayoutEffect(() => {
150
160
  const panelData = panelDataRef.current;
@@ -532,12 +542,12 @@ function calculateAriaValues({
532
542
  };
533
543
  }
534
544
 
535
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
536
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
545
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
546
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
537
547
  }
538
548
 
539
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
540
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
549
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
550
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
541
551
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
542
552
  return index !== null && index !== void 0 ? index : null;
543
553
  }
@@ -547,7 +557,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
547
557
  return index != null ? [index, index + 1] : [-1, -1];
548
558
  }
549
559
 
550
- function getPanelGroupElement(id, rootElement) {
560
+ function getPanelGroupElement(id, rootElement = document) {
551
561
  var _dataset;
552
562
  //If the root element is the PanelGroup
553
563
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -562,18 +572,18 @@ function getPanelGroupElement(id, rootElement) {
562
572
  return null;
563
573
  }
564
574
 
565
- function getResizeHandleElement(id, panelGroupElement) {
566
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
575
+ function getResizeHandleElement(id, scope = document) {
576
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
567
577
  if (element) {
568
578
  return element;
569
579
  }
570
580
  return null;
571
581
  }
572
582
 
573
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
583
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
574
584
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
575
- const handle = getResizeHandleElement(handleId, panelGroupElement);
576
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
585
+ const handle = getResizeHandleElement(handleId, scope);
586
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
577
587
  const index = handle ? handles.indexOf(handle) : -1;
578
588
  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;
579
589
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1658,6 +1668,35 @@ function PanelGroupWithForwardedRef({
1658
1668
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1659
1669
  }
1660
1670
  }, []);
1671
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1672
+ const {
1673
+ layout,
1674
+ panelDataArray
1675
+ } = eagerValuesRef.current;
1676
+ const {
1677
+ collapsedSize: prevCollapsedSize = 0,
1678
+ collapsible: prevCollapsible
1679
+ } = prevConstraints;
1680
+ const {
1681
+ collapsedSize: nextCollapsedSize = 0,
1682
+ collapsible: nextCollapsible,
1683
+ maxSize: nextMaxSize = 100,
1684
+ minSize: nextMinSize = 0
1685
+ } = panelData.constraints;
1686
+ const {
1687
+ panelSize: prevPanelSize
1688
+ } = panelDataHelper(panelDataArray, panelData, layout);
1689
+ assert(prevPanelSize != null);
1690
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1691
+ if (prevCollapsedSize !== nextCollapsedSize) {
1692
+ resizePanel(panelData, nextCollapsedSize);
1693
+ }
1694
+ } else if (prevPanelSize < nextMinSize) {
1695
+ resizePanel(panelData, nextMinSize);
1696
+ } else if (prevPanelSize > nextMaxSize) {
1697
+ resizePanel(panelData, nextMaxSize);
1698
+ }
1699
+ }, [resizePanel]);
1661
1700
  const startDragging = useCallback((dragHandleId, event) => {
1662
1701
  const {
1663
1702
  direction
@@ -1708,6 +1747,7 @@ function PanelGroupWithForwardedRef({
1708
1747
  groupId,
1709
1748
  isPanelCollapsed,
1710
1749
  isPanelExpanded,
1750
+ reevaluatePanelConstraints,
1711
1751
  registerPanel,
1712
1752
  registerResizeHandle,
1713
1753
  resizePanel,
@@ -1715,7 +1755,7 @@ function PanelGroupWithForwardedRef({
1715
1755
  stopDragging,
1716
1756
  unregisterPanel,
1717
1757
  panelGroupElement: panelGroupElementRef.current
1718
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1758
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1719
1759
  const style = {
1720
1760
  display: "flex",
1721
1761
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1750,14 +1790,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1750
1790
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1751
1791
  }
1752
1792
  function panelDataHelper(panelDataArray, panelData, layout) {
1753
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1754
1793
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1755
- const panelConstraints = panelConstraintsArray[panelIndex];
1756
1794
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1757
1795
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1758
1796
  const panelSize = layout[panelIndex];
1759
1797
  return {
1760
- ...panelConstraints,
1798
+ ...panelData.constraints,
1761
1799
  panelSize,
1762
1800
  pivotIndices
1763
1801
  };
@@ -1964,55 +2002,22 @@ function PanelResizeHandle({
1964
2002
  }
1965
2003
  PanelResizeHandle.displayName = "PanelResizeHandle";
1966
2004
 
1967
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1968
- if (panelGroupElement == null) {
1969
- return NaN;
1970
- }
1971
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1972
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1973
- if (direction === "horizontal") {
1974
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1975
- return accumulated + handle.offsetWidth;
1976
- }, 0);
1977
- } else {
1978
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1979
- return accumulated + handle.offsetHeight;
1980
- }, 0);
1981
- }
1982
- }
1983
-
1984
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1985
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1986
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1987
- if (direction === "horizontal") {
1988
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1989
- return accumulated + handle.offsetWidth;
1990
- }, 0);
1991
- } else {
1992
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1993
- return accumulated + handle.offsetHeight;
1994
- }, 0);
1995
- }
1996
- }
1997
-
1998
- function getPanelElement(id, panelGroupElement) {
1999
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
2005
+ function getPanelElement(id, scope = document) {
2006
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
2000
2007
  if (element) {
2001
2008
  return element;
2002
2009
  }
2003
2010
  return null;
2004
2011
  }
2005
2012
 
2006
- function getPanelElementsForGroup(groupId, panelGroupElement) {
2007
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2013
+ function getPanelElementsForGroup(groupId, scope = document) {
2014
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2008
2015
  }
2009
2016
 
2010
2017
  exports.Panel = Panel;
2011
2018
  exports.PanelGroup = PanelGroup;
2012
2019
  exports.PanelResizeHandle = PanelResizeHandle;
2013
2020
  exports.assert = assert;
2014
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
2015
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
2016
2021
  exports.getPanelElement = getPanelElement;
2017
2022
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
2018
2023
  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,
@@ -69,6 +69,7 @@ function PanelWithForwardedRef({
69
69
  getPanelStyle,
70
70
  groupId,
71
71
  isPanelCollapsed,
72
+ reevaluatePanelConstraints,
72
73
  registerPanel,
73
74
  resizePanel,
74
75
  unregisterPanel
@@ -110,6 +111,9 @@ function PanelWithForwardedRef({
110
111
  callbacks,
111
112
  constraints
112
113
  } = panelDataRef.current;
114
+ const prevConstraints = {
115
+ ...constraints
116
+ };
113
117
  panelDataRef.current.id = panelId;
114
118
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
115
119
  panelDataRef.current.order = order;
@@ -121,6 +125,12 @@ function PanelWithForwardedRef({
121
125
  constraints.defaultSize = defaultSize;
122
126
  constraints.maxSize = maxSize;
123
127
  constraints.minSize = minSize;
128
+
129
+ // If constraints have changed, we should revisit panel sizes.
130
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
131
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
132
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
133
+ }
124
134
  });
125
135
  useIsomorphicLayoutEffect(() => {
126
136
  const panelData = panelDataRef.current;
@@ -508,12 +518,12 @@ function calculateAriaValues({
508
518
  };
509
519
  }
510
520
 
511
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
512
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
521
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
522
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
513
523
  }
514
524
 
515
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
516
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
525
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
526
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
517
527
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
518
528
  return index !== null && index !== void 0 ? index : null;
519
529
  }
@@ -523,7 +533,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
523
533
  return index != null ? [index, index + 1] : [-1, -1];
524
534
  }
525
535
 
526
- function getPanelGroupElement(id, rootElement) {
536
+ function getPanelGroupElement(id, rootElement = document) {
527
537
  var _dataset;
528
538
  //If the root element is the PanelGroup
529
539
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -538,18 +548,18 @@ function getPanelGroupElement(id, rootElement) {
538
548
  return null;
539
549
  }
540
550
 
541
- function getResizeHandleElement(id, panelGroupElement) {
542
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
551
+ function getResizeHandleElement(id, scope = document) {
552
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
543
553
  if (element) {
544
554
  return element;
545
555
  }
546
556
  return null;
547
557
  }
548
558
 
549
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
559
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
550
560
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
551
- const handle = getResizeHandleElement(handleId, panelGroupElement);
552
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
561
+ const handle = getResizeHandleElement(handleId, scope);
562
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
553
563
  const index = handle ? handles.indexOf(handle) : -1;
554
564
  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;
555
565
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1634,6 +1644,35 @@ function PanelGroupWithForwardedRef({
1634
1644
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1635
1645
  }
1636
1646
  }, []);
1647
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1648
+ const {
1649
+ layout,
1650
+ panelDataArray
1651
+ } = eagerValuesRef.current;
1652
+ const {
1653
+ collapsedSize: prevCollapsedSize = 0,
1654
+ collapsible: prevCollapsible
1655
+ } = prevConstraints;
1656
+ const {
1657
+ collapsedSize: nextCollapsedSize = 0,
1658
+ collapsible: nextCollapsible,
1659
+ maxSize: nextMaxSize = 100,
1660
+ minSize: nextMinSize = 0
1661
+ } = panelData.constraints;
1662
+ const {
1663
+ panelSize: prevPanelSize
1664
+ } = panelDataHelper(panelDataArray, panelData, layout);
1665
+ assert(prevPanelSize != null);
1666
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1667
+ if (prevCollapsedSize !== nextCollapsedSize) {
1668
+ resizePanel(panelData, nextCollapsedSize);
1669
+ }
1670
+ } else if (prevPanelSize < nextMinSize) {
1671
+ resizePanel(panelData, nextMinSize);
1672
+ } else if (prevPanelSize > nextMaxSize) {
1673
+ resizePanel(panelData, nextMaxSize);
1674
+ }
1675
+ }, [resizePanel]);
1637
1676
  const startDragging = useCallback((dragHandleId, event) => {
1638
1677
  const {
1639
1678
  direction
@@ -1684,6 +1723,7 @@ function PanelGroupWithForwardedRef({
1684
1723
  groupId,
1685
1724
  isPanelCollapsed,
1686
1725
  isPanelExpanded,
1726
+ reevaluatePanelConstraints,
1687
1727
  registerPanel,
1688
1728
  registerResizeHandle,
1689
1729
  resizePanel,
@@ -1691,7 +1731,7 @@ function PanelGroupWithForwardedRef({
1691
1731
  stopDragging,
1692
1732
  unregisterPanel,
1693
1733
  panelGroupElement: panelGroupElementRef.current
1694
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1734
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1695
1735
  const style = {
1696
1736
  display: "flex",
1697
1737
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1726,14 +1766,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1726
1766
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1727
1767
  }
1728
1768
  function panelDataHelper(panelDataArray, panelData, layout) {
1729
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1730
1769
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1731
- const panelConstraints = panelConstraintsArray[panelIndex];
1732
1770
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1733
1771
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1734
1772
  const panelSize = layout[panelIndex];
1735
1773
  return {
1736
- ...panelConstraints,
1774
+ ...panelData.constraints,
1737
1775
  panelSize,
1738
1776
  pivotIndices
1739
1777
  };
@@ -1940,47 +1978,16 @@ function PanelResizeHandle({
1940
1978
  }
1941
1979
  PanelResizeHandle.displayName = "PanelResizeHandle";
1942
1980
 
1943
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1944
- if (panelGroupElement == null) {
1945
- return NaN;
1946
- }
1947
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1948
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1949
- if (direction === "horizontal") {
1950
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1951
- return accumulated + handle.offsetWidth;
1952
- }, 0);
1953
- } else {
1954
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1955
- return accumulated + handle.offsetHeight;
1956
- }, 0);
1957
- }
1958
- }
1959
-
1960
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1961
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1962
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1963
- if (direction === "horizontal") {
1964
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1965
- return accumulated + handle.offsetWidth;
1966
- }, 0);
1967
- } else {
1968
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1969
- return accumulated + handle.offsetHeight;
1970
- }, 0);
1971
- }
1972
- }
1973
-
1974
- function getPanelElement(id, panelGroupElement) {
1975
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1981
+ function getPanelElement(id, scope = document) {
1982
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1976
1983
  if (element) {
1977
1984
  return element;
1978
1985
  }
1979
1986
  return null;
1980
1987
  }
1981
1988
 
1982
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1983
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1989
+ function getPanelElementsForGroup(groupId, scope = document) {
1990
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1984
1991
  }
1985
1992
 
1986
- export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
1993
+ export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
@@ -89,6 +89,7 @@ function PanelWithForwardedRef({
89
89
  getPanelStyle,
90
90
  groupId,
91
91
  isPanelCollapsed,
92
+ reevaluatePanelConstraints,
92
93
  registerPanel,
93
94
  resizePanel,
94
95
  unregisterPanel
@@ -465,12 +466,12 @@ function adjustLayoutByDelta({
465
466
  return nextLayout;
466
467
  }
467
468
 
468
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
469
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
469
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
470
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
470
471
  }
471
472
 
472
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
473
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
473
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
474
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
474
475
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
475
476
  return index !== null && index !== void 0 ? index : null;
476
477
  }
@@ -480,7 +481,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
480
481
  return index != null ? [index, index + 1] : [-1, -1];
481
482
  }
482
483
 
483
- function getPanelGroupElement(id, rootElement) {
484
+ function getPanelGroupElement(id, rootElement = document) {
484
485
  var _dataset;
485
486
  //If the root element is the PanelGroup
486
487
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -495,18 +496,18 @@ function getPanelGroupElement(id, rootElement) {
495
496
  return null;
496
497
  }
497
498
 
498
- function getResizeHandleElement(id, panelGroupElement) {
499
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
499
+ function getResizeHandleElement(id, scope = document) {
500
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
500
501
  if (element) {
501
502
  return element;
502
503
  }
503
504
  return null;
504
505
  }
505
506
 
506
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
507
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
507
508
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
508
- const handle = getResizeHandleElement(handleId, panelGroupElement);
509
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
509
+ const handle = getResizeHandleElement(handleId, scope);
510
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
510
511
  const index = handle ? handles.indexOf(handle) : -1;
511
512
  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;
512
513
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1444,6 +1445,35 @@ function PanelGroupWithForwardedRef({
1444
1445
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1445
1446
  }
1446
1447
  }, []);
1448
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1449
+ const {
1450
+ layout,
1451
+ panelDataArray
1452
+ } = eagerValuesRef.current;
1453
+ const {
1454
+ collapsedSize: prevCollapsedSize = 0,
1455
+ collapsible: prevCollapsible
1456
+ } = prevConstraints;
1457
+ const {
1458
+ collapsedSize: nextCollapsedSize = 0,
1459
+ collapsible: nextCollapsible,
1460
+ maxSize: nextMaxSize = 100,
1461
+ minSize: nextMinSize = 0
1462
+ } = panelData.constraints;
1463
+ const {
1464
+ panelSize: prevPanelSize
1465
+ } = panelDataHelper(panelDataArray, panelData, layout);
1466
+ assert(prevPanelSize != null);
1467
+ if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1468
+ if (prevCollapsedSize !== nextCollapsedSize) {
1469
+ resizePanel(panelData, nextCollapsedSize);
1470
+ }
1471
+ } else if (prevPanelSize < nextMinSize) {
1472
+ resizePanel(panelData, nextMinSize);
1473
+ } else if (prevPanelSize > nextMaxSize) {
1474
+ resizePanel(panelData, nextMaxSize);
1475
+ }
1476
+ }, [resizePanel]);
1447
1477
  const startDragging = useCallback((dragHandleId, event) => {
1448
1478
  const {
1449
1479
  direction
@@ -1494,6 +1524,7 @@ function PanelGroupWithForwardedRef({
1494
1524
  groupId,
1495
1525
  isPanelCollapsed,
1496
1526
  isPanelExpanded,
1527
+ reevaluatePanelConstraints,
1497
1528
  registerPanel,
1498
1529
  registerResizeHandle,
1499
1530
  resizePanel,
@@ -1501,7 +1532,7 @@ function PanelGroupWithForwardedRef({
1501
1532
  stopDragging,
1502
1533
  unregisterPanel,
1503
1534
  panelGroupElement: panelGroupElementRef.current
1504
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1535
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1505
1536
  const style = {
1506
1537
  display: "flex",
1507
1538
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1536,14 +1567,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1536
1567
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1537
1568
  }
1538
1569
  function panelDataHelper(panelDataArray, panelData, layout) {
1539
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1540
1570
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1541
- const panelConstraints = panelConstraintsArray[panelIndex];
1542
1571
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1543
1572
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1544
1573
  const panelSize = layout[panelIndex];
1545
1574
  return {
1546
- ...panelConstraints,
1575
+ ...panelData.constraints,
1547
1576
  panelSize,
1548
1577
  pivotIndices
1549
1578
  };
@@ -1750,55 +1779,22 @@ function PanelResizeHandle({
1750
1779
  }
1751
1780
  PanelResizeHandle.displayName = "PanelResizeHandle";
1752
1781
 
1753
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1754
- if (panelGroupElement == null) {
1755
- return NaN;
1756
- }
1757
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1758
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1759
- if (direction === "horizontal") {
1760
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1761
- return accumulated + handle.offsetWidth;
1762
- }, 0);
1763
- } else {
1764
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1765
- return accumulated + handle.offsetHeight;
1766
- }, 0);
1767
- }
1768
- }
1769
-
1770
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1771
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1772
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1773
- if (direction === "horizontal") {
1774
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1775
- return accumulated + handle.offsetWidth;
1776
- }, 0);
1777
- } else {
1778
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1779
- return accumulated + handle.offsetHeight;
1780
- }, 0);
1781
- }
1782
- }
1783
-
1784
- function getPanelElement(id, panelGroupElement) {
1785
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1782
+ function getPanelElement(id, scope = document) {
1783
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1786
1784
  if (element) {
1787
1785
  return element;
1788
1786
  }
1789
1787
  return null;
1790
1788
  }
1791
1789
 
1792
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1793
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1790
+ function getPanelElementsForGroup(groupId, scope = document) {
1791
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1794
1792
  }
1795
1793
 
1796
1794
  exports.Panel = Panel;
1797
1795
  exports.PanelGroup = PanelGroup;
1798
1796
  exports.PanelResizeHandle = PanelResizeHandle;
1799
1797
  exports.assert = assert;
1800
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1801
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1802
1798
  exports.getPanelElement = getPanelElement;
1803
1799
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
1804
1800
  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,