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
@@ -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,37 @@ 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
+ defaultSize: prevDefaultSize,
1680
+ maxSize: prevMaxSize = 100,
1681
+ minSize: prevMinSize = 0
1682
+ } = prevConstraints;
1683
+ const {
1684
+ collapsedSize: nextCollapsedSize = 0,
1685
+ collapsible: nextCollapsible,
1686
+ defaultSize: nextDefaultSize,
1687
+ maxSize: nextMaxSize = 100,
1688
+ minSize: nextMinSize = 0
1689
+ } = panelData.constraints;
1690
+ const {
1691
+ panelSize: prevPanelSize
1692
+ } = panelDataHelper(panelDataArray, panelData, layout);
1693
+ assert(prevPanelSize != null);
1694
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1695
+ resizePanel(panelData, nextCollapsedSize);
1696
+ } else if (prevPanelSize < nextMinSize) {
1697
+ resizePanel(panelData, nextMinSize);
1698
+ } else if (prevPanelSize > nextMaxSize) {
1699
+ resizePanel(panelData, nextMaxSize);
1700
+ }
1701
+ }, [resizePanel]);
1661
1702
  const startDragging = useCallback((dragHandleId, event) => {
1662
1703
  const {
1663
1704
  direction
@@ -1708,6 +1749,7 @@ function PanelGroupWithForwardedRef({
1708
1749
  groupId,
1709
1750
  isPanelCollapsed,
1710
1751
  isPanelExpanded,
1752
+ reevaluatePanelConstraints,
1711
1753
  registerPanel,
1712
1754
  registerResizeHandle,
1713
1755
  resizePanel,
@@ -1715,7 +1757,7 @@ function PanelGroupWithForwardedRef({
1715
1757
  stopDragging,
1716
1758
  unregisterPanel,
1717
1759
  panelGroupElement: panelGroupElementRef.current
1718
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1760
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1719
1761
  const style = {
1720
1762
  display: "flex",
1721
1763
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1750,14 +1792,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1750
1792
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1751
1793
  }
1752
1794
  function panelDataHelper(panelDataArray, panelData, layout) {
1753
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1754
1795
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1755
- const panelConstraints = panelConstraintsArray[panelIndex];
1756
1796
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1757
1797
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1758
1798
  const panelSize = layout[panelIndex];
1759
1799
  return {
1760
- ...panelConstraints,
1800
+ ...panelData.constraints,
1761
1801
  panelSize,
1762
1802
  pivotIndices
1763
1803
  };
@@ -1964,55 +2004,22 @@ function PanelResizeHandle({
1964
2004
  }
1965
2005
  PanelResizeHandle.displayName = "PanelResizeHandle";
1966
2006
 
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}"]`);
2007
+ function getPanelElement(id, scope = document) {
2008
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
2000
2009
  if (element) {
2001
2010
  return element;
2002
2011
  }
2003
2012
  return null;
2004
2013
  }
2005
2014
 
2006
- function getPanelElementsForGroup(groupId, panelGroupElement) {
2007
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2015
+ function getPanelElementsForGroup(groupId, scope = document) {
2016
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
2008
2017
  }
2009
2018
 
2010
2019
  exports.Panel = Panel;
2011
2020
  exports.PanelGroup = PanelGroup;
2012
2021
  exports.PanelResizeHandle = PanelResizeHandle;
2013
2022
  exports.assert = assert;
2014
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
2015
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
2016
2023
  exports.getPanelElement = getPanelElement;
2017
2024
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
2018
2025
  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,37 @@ 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
+ defaultSize: prevDefaultSize,
1656
+ maxSize: prevMaxSize = 100,
1657
+ minSize: prevMinSize = 0
1658
+ } = prevConstraints;
1659
+ const {
1660
+ collapsedSize: nextCollapsedSize = 0,
1661
+ collapsible: nextCollapsible,
1662
+ defaultSize: nextDefaultSize,
1663
+ maxSize: nextMaxSize = 100,
1664
+ minSize: nextMinSize = 0
1665
+ } = panelData.constraints;
1666
+ const {
1667
+ panelSize: prevPanelSize
1668
+ } = panelDataHelper(panelDataArray, panelData, layout);
1669
+ assert(prevPanelSize != null);
1670
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1671
+ resizePanel(panelData, nextCollapsedSize);
1672
+ } else if (prevPanelSize < nextMinSize) {
1673
+ resizePanel(panelData, nextMinSize);
1674
+ } else if (prevPanelSize > nextMaxSize) {
1675
+ resizePanel(panelData, nextMaxSize);
1676
+ }
1677
+ }, [resizePanel]);
1637
1678
  const startDragging = useCallback((dragHandleId, event) => {
1638
1679
  const {
1639
1680
  direction
@@ -1684,6 +1725,7 @@ function PanelGroupWithForwardedRef({
1684
1725
  groupId,
1685
1726
  isPanelCollapsed,
1686
1727
  isPanelExpanded,
1728
+ reevaluatePanelConstraints,
1687
1729
  registerPanel,
1688
1730
  registerResizeHandle,
1689
1731
  resizePanel,
@@ -1691,7 +1733,7 @@ function PanelGroupWithForwardedRef({
1691
1733
  stopDragging,
1692
1734
  unregisterPanel,
1693
1735
  panelGroupElement: panelGroupElementRef.current
1694
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1736
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1695
1737
  const style = {
1696
1738
  display: "flex",
1697
1739
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1726,14 +1768,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1726
1768
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1727
1769
  }
1728
1770
  function panelDataHelper(panelDataArray, panelData, layout) {
1729
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1730
1771
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1731
- const panelConstraints = panelConstraintsArray[panelIndex];
1732
1772
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1733
1773
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1734
1774
  const panelSize = layout[panelIndex];
1735
1775
  return {
1736
- ...panelConstraints,
1776
+ ...panelData.constraints,
1737
1777
  panelSize,
1738
1778
  pivotIndices
1739
1779
  };
@@ -1940,47 +1980,16 @@ function PanelResizeHandle({
1940
1980
  }
1941
1981
  PanelResizeHandle.displayName = "PanelResizeHandle";
1942
1982
 
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}"]`);
1983
+ function getPanelElement(id, scope = document) {
1984
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1976
1985
  if (element) {
1977
1986
  return element;
1978
1987
  }
1979
1988
  return null;
1980
1989
  }
1981
1990
 
1982
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1983
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1991
+ function getPanelElementsForGroup(groupId, scope = document) {
1992
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1984
1993
  }
1985
1994
 
1986
- export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
1995
+ 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,37 @@ 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
+ defaultSize: prevDefaultSize,
1457
+ maxSize: prevMaxSize = 100,
1458
+ minSize: prevMinSize = 0
1459
+ } = prevConstraints;
1460
+ const {
1461
+ collapsedSize: nextCollapsedSize = 0,
1462
+ collapsible: nextCollapsible,
1463
+ defaultSize: nextDefaultSize,
1464
+ maxSize: nextMaxSize = 100,
1465
+ minSize: nextMinSize = 0
1466
+ } = panelData.constraints;
1467
+ const {
1468
+ panelSize: prevPanelSize
1469
+ } = panelDataHelper(panelDataArray, panelData, layout);
1470
+ assert(prevPanelSize != null);
1471
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1472
+ resizePanel(panelData, nextCollapsedSize);
1473
+ } else if (prevPanelSize < nextMinSize) {
1474
+ resizePanel(panelData, nextMinSize);
1475
+ } else if (prevPanelSize > nextMaxSize) {
1476
+ resizePanel(panelData, nextMaxSize);
1477
+ }
1478
+ }, [resizePanel]);
1447
1479
  const startDragging = useCallback((dragHandleId, event) => {
1448
1480
  const {
1449
1481
  direction
@@ -1494,6 +1526,7 @@ function PanelGroupWithForwardedRef({
1494
1526
  groupId,
1495
1527
  isPanelCollapsed,
1496
1528
  isPanelExpanded,
1529
+ reevaluatePanelConstraints,
1497
1530
  registerPanel,
1498
1531
  registerResizeHandle,
1499
1532
  resizePanel,
@@ -1501,7 +1534,7 @@ function PanelGroupWithForwardedRef({
1501
1534
  stopDragging,
1502
1535
  unregisterPanel,
1503
1536
  panelGroupElement: panelGroupElementRef.current
1504
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1537
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1505
1538
  const style = {
1506
1539
  display: "flex",
1507
1540
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1536,14 +1569,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1536
1569
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1537
1570
  }
1538
1571
  function panelDataHelper(panelDataArray, panelData, layout) {
1539
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1540
1572
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1541
- const panelConstraints = panelConstraintsArray[panelIndex];
1542
1573
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1543
1574
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1544
1575
  const panelSize = layout[panelIndex];
1545
1576
  return {
1546
- ...panelConstraints,
1577
+ ...panelData.constraints,
1547
1578
  panelSize,
1548
1579
  pivotIndices
1549
1580
  };
@@ -1750,55 +1781,22 @@ function PanelResizeHandle({
1750
1781
  }
1751
1782
  PanelResizeHandle.displayName = "PanelResizeHandle";
1752
1783
 
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}"]`);
1784
+ function getPanelElement(id, scope = document) {
1785
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1786
1786
  if (element) {
1787
1787
  return element;
1788
1788
  }
1789
1789
  return null;
1790
1790
  }
1791
1791
 
1792
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1793
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1792
+ function getPanelElementsForGroup(groupId, scope = document) {
1793
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1794
1794
  }
1795
1795
 
1796
1796
  exports.Panel = Panel;
1797
1797
  exports.PanelGroup = PanelGroup;
1798
1798
  exports.PanelResizeHandle = PanelResizeHandle;
1799
1799
  exports.assert = assert;
1800
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1801
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1802
1800
  exports.getPanelElement = getPanelElement;
1803
1801
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
1804
1802
  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,