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
@@ -67,6 +67,7 @@ function PanelWithForwardedRef({
67
67
  getPanelStyle,
68
68
  groupId,
69
69
  isPanelCollapsed,
70
+ reevaluatePanelConstraints,
70
71
  registerPanel,
71
72
  resizePanel,
72
73
  unregisterPanel
@@ -103,6 +104,9 @@ function PanelWithForwardedRef({
103
104
  callbacks,
104
105
  constraints
105
106
  } = panelDataRef.current;
107
+ const prevConstraints = {
108
+ ...constraints
109
+ };
106
110
  panelDataRef.current.id = panelId;
107
111
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
108
112
  panelDataRef.current.order = order;
@@ -114,6 +118,12 @@ function PanelWithForwardedRef({
114
118
  constraints.defaultSize = defaultSize;
115
119
  constraints.maxSize = maxSize;
116
120
  constraints.minSize = minSize;
121
+
122
+ // If constraints have changed, we should revisit panel sizes.
123
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
124
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
125
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
126
+ }
117
127
  });
118
128
  useIsomorphicLayoutEffect(() => {
119
129
  const panelData = panelDataRef.current;
@@ -501,12 +511,12 @@ function calculateAriaValues({
501
511
  };
502
512
  }
503
513
 
504
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
505
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
514
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
515
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
506
516
  }
507
517
 
508
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
509
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
518
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
519
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
510
520
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
511
521
  return index !== null && index !== void 0 ? index : null;
512
522
  }
@@ -516,7 +526,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
516
526
  return index != null ? [index, index + 1] : [-1, -1];
517
527
  }
518
528
 
519
- function getPanelGroupElement(id, rootElement) {
529
+ function getPanelGroupElement(id, rootElement = document) {
520
530
  var _dataset;
521
531
  //If the root element is the PanelGroup
522
532
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -531,18 +541,18 @@ function getPanelGroupElement(id, rootElement) {
531
541
  return null;
532
542
  }
533
543
 
534
- function getResizeHandleElement(id, panelGroupElement) {
535
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
544
+ function getResizeHandleElement(id, scope = document) {
545
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
536
546
  if (element) {
537
547
  return element;
538
548
  }
539
549
  return null;
540
550
  }
541
551
 
542
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
552
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
543
553
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
544
- const handle = getResizeHandleElement(handleId, panelGroupElement);
545
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
554
+ const handle = getResizeHandleElement(handleId, scope);
555
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
546
556
  const index = handle ? handles.indexOf(handle) : -1;
547
557
  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;
548
558
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1627,6 +1637,37 @@ function PanelGroupWithForwardedRef({
1627
1637
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1628
1638
  }
1629
1639
  }, []);
1640
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1641
+ const {
1642
+ layout,
1643
+ panelDataArray
1644
+ } = eagerValuesRef.current;
1645
+ const {
1646
+ collapsedSize: prevCollapsedSize = 0,
1647
+ collapsible: prevCollapsible,
1648
+ defaultSize: prevDefaultSize,
1649
+ maxSize: prevMaxSize = 100,
1650
+ minSize: prevMinSize = 0
1651
+ } = prevConstraints;
1652
+ const {
1653
+ collapsedSize: nextCollapsedSize = 0,
1654
+ collapsible: nextCollapsible,
1655
+ defaultSize: nextDefaultSize,
1656
+ maxSize: nextMaxSize = 100,
1657
+ minSize: nextMinSize = 0
1658
+ } = panelData.constraints;
1659
+ const {
1660
+ panelSize: prevPanelSize
1661
+ } = panelDataHelper(panelDataArray, panelData, layout);
1662
+ assert(prevPanelSize != null);
1663
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1664
+ resizePanel(panelData, nextCollapsedSize);
1665
+ } else if (prevPanelSize < nextMinSize) {
1666
+ resizePanel(panelData, nextMinSize);
1667
+ } else if (prevPanelSize > nextMaxSize) {
1668
+ resizePanel(panelData, nextMaxSize);
1669
+ }
1670
+ }, [resizePanel]);
1630
1671
  const startDragging = useCallback((dragHandleId, event) => {
1631
1672
  const {
1632
1673
  direction
@@ -1677,6 +1718,7 @@ function PanelGroupWithForwardedRef({
1677
1718
  groupId,
1678
1719
  isPanelCollapsed,
1679
1720
  isPanelExpanded,
1721
+ reevaluatePanelConstraints,
1680
1722
  registerPanel,
1681
1723
  registerResizeHandle,
1682
1724
  resizePanel,
@@ -1684,7 +1726,7 @@ function PanelGroupWithForwardedRef({
1684
1726
  stopDragging,
1685
1727
  unregisterPanel,
1686
1728
  panelGroupElement: panelGroupElementRef.current
1687
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1729
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1688
1730
  const style = {
1689
1731
  display: "flex",
1690
1732
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1719,14 +1761,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1719
1761
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1720
1762
  }
1721
1763
  function panelDataHelper(panelDataArray, panelData, layout) {
1722
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1723
1764
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1724
- const panelConstraints = panelConstraintsArray[panelIndex];
1725
1765
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1726
1766
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1727
1767
  const panelSize = layout[panelIndex];
1728
1768
  return {
1729
- ...panelConstraints,
1769
+ ...panelData.constraints,
1730
1770
  panelSize,
1731
1771
  pivotIndices
1732
1772
  };
@@ -1933,47 +1973,16 @@ function PanelResizeHandle({
1933
1973
  }
1934
1974
  PanelResizeHandle.displayName = "PanelResizeHandle";
1935
1975
 
1936
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1937
- if (panelGroupElement == null) {
1938
- return NaN;
1939
- }
1940
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1941
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1942
- if (direction === "horizontal") {
1943
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1944
- return accumulated + handle.offsetWidth;
1945
- }, 0);
1946
- } else {
1947
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1948
- return accumulated + handle.offsetHeight;
1949
- }, 0);
1950
- }
1951
- }
1952
-
1953
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1954
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1955
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1956
- if (direction === "horizontal") {
1957
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1958
- return accumulated + handle.offsetWidth;
1959
- }, 0);
1960
- } else {
1961
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1962
- return accumulated + handle.offsetHeight;
1963
- }, 0);
1964
- }
1965
- }
1966
-
1967
- function getPanelElement(id, panelGroupElement) {
1968
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1976
+ function getPanelElement(id, scope = document) {
1977
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1969
1978
  if (element) {
1970
1979
  return element;
1971
1980
  }
1972
1981
  return null;
1973
1982
  }
1974
1983
 
1975
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1976
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1984
+ function getPanelElementsForGroup(groupId, scope = document) {
1985
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1977
1986
  }
1978
1987
 
1979
- export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
1988
+ export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
@@ -67,6 +67,7 @@ function PanelWithForwardedRef({
67
67
  getPanelStyle,
68
68
  groupId,
69
69
  isPanelCollapsed,
70
+ reevaluatePanelConstraints,
70
71
  registerPanel,
71
72
  resizePanel,
72
73
  unregisterPanel
@@ -97,6 +98,9 @@ function PanelWithForwardedRef({
97
98
  callbacks,
98
99
  constraints
99
100
  } = panelDataRef.current;
101
+ const prevConstraints = {
102
+ ...constraints
103
+ };
100
104
  panelDataRef.current.id = panelId;
101
105
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
102
106
  panelDataRef.current.order = order;
@@ -108,6 +112,12 @@ function PanelWithForwardedRef({
108
112
  constraints.defaultSize = defaultSize;
109
113
  constraints.maxSize = maxSize;
110
114
  constraints.minSize = minSize;
115
+
116
+ // If constraints have changed, we should revisit panel sizes.
117
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
118
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
119
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
120
+ }
111
121
  });
112
122
  useIsomorphicLayoutEffect(() => {
113
123
  const panelData = panelDataRef.current;
@@ -495,12 +505,12 @@ function calculateAriaValues({
495
505
  };
496
506
  }
497
507
 
498
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
499
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
508
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
509
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
500
510
  }
501
511
 
502
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
503
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
512
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
513
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
504
514
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
505
515
  return index !== null && index !== void 0 ? index : null;
506
516
  }
@@ -510,7 +520,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
510
520
  return index != null ? [index, index + 1] : [-1, -1];
511
521
  }
512
522
 
513
- function getPanelGroupElement(id, rootElement) {
523
+ function getPanelGroupElement(id, rootElement = document) {
514
524
  var _dataset;
515
525
  //If the root element is the PanelGroup
516
526
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -525,18 +535,18 @@ function getPanelGroupElement(id, rootElement) {
525
535
  return null;
526
536
  }
527
537
 
528
- function getResizeHandleElement(id, panelGroupElement) {
529
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
538
+ function getResizeHandleElement(id, scope = document) {
539
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
530
540
  if (element) {
531
541
  return element;
532
542
  }
533
543
  return null;
534
544
  }
535
545
 
536
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
546
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
537
547
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
538
- const handle = getResizeHandleElement(handleId, panelGroupElement);
539
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
548
+ const handle = getResizeHandleElement(handleId, scope);
549
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
540
550
  const index = handle ? handles.indexOf(handle) : -1;
541
551
  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;
542
552
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1521,6 +1531,37 @@ function PanelGroupWithForwardedRef({
1521
1531
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1522
1532
  }
1523
1533
  }, []);
1534
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1535
+ const {
1536
+ layout,
1537
+ panelDataArray
1538
+ } = eagerValuesRef.current;
1539
+ const {
1540
+ collapsedSize: prevCollapsedSize = 0,
1541
+ collapsible: prevCollapsible,
1542
+ defaultSize: prevDefaultSize,
1543
+ maxSize: prevMaxSize = 100,
1544
+ minSize: prevMinSize = 0
1545
+ } = prevConstraints;
1546
+ const {
1547
+ collapsedSize: nextCollapsedSize = 0,
1548
+ collapsible: nextCollapsible,
1549
+ defaultSize: nextDefaultSize,
1550
+ maxSize: nextMaxSize = 100,
1551
+ minSize: nextMinSize = 0
1552
+ } = panelData.constraints;
1553
+ const {
1554
+ panelSize: prevPanelSize
1555
+ } = panelDataHelper(panelDataArray, panelData, layout);
1556
+ assert(prevPanelSize != null);
1557
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1558
+ resizePanel(panelData, nextCollapsedSize);
1559
+ } else if (prevPanelSize < nextMinSize) {
1560
+ resizePanel(panelData, nextMinSize);
1561
+ } else if (prevPanelSize > nextMaxSize) {
1562
+ resizePanel(panelData, nextMaxSize);
1563
+ }
1564
+ }, [resizePanel]);
1524
1565
  const startDragging = useCallback((dragHandleId, event) => {
1525
1566
  const {
1526
1567
  direction
@@ -1571,6 +1612,7 @@ function PanelGroupWithForwardedRef({
1571
1612
  groupId,
1572
1613
  isPanelCollapsed,
1573
1614
  isPanelExpanded,
1615
+ reevaluatePanelConstraints,
1574
1616
  registerPanel,
1575
1617
  registerResizeHandle,
1576
1618
  resizePanel,
@@ -1578,7 +1620,7 @@ function PanelGroupWithForwardedRef({
1578
1620
  stopDragging,
1579
1621
  unregisterPanel,
1580
1622
  panelGroupElement: panelGroupElementRef.current
1581
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1623
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1582
1624
  const style = {
1583
1625
  display: "flex",
1584
1626
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1613,14 +1655,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1613
1655
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1614
1656
  }
1615
1657
  function panelDataHelper(panelDataArray, panelData, layout) {
1616
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1617
1658
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1618
- const panelConstraints = panelConstraintsArray[panelIndex];
1619
1659
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1620
1660
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1621
1661
  const panelSize = layout[panelIndex];
1622
1662
  return {
1623
- ...panelConstraints,
1663
+ ...panelData.constraints,
1624
1664
  panelSize,
1625
1665
  pivotIndices
1626
1666
  };
@@ -1827,47 +1867,16 @@ function PanelResizeHandle({
1827
1867
  }
1828
1868
  PanelResizeHandle.displayName = "PanelResizeHandle";
1829
1869
 
1830
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1831
- if (panelGroupElement == null) {
1832
- return NaN;
1833
- }
1834
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1835
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1836
- if (direction === "horizontal") {
1837
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1838
- return accumulated + handle.offsetWidth;
1839
- }, 0);
1840
- } else {
1841
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1842
- return accumulated + handle.offsetHeight;
1843
- }, 0);
1844
- }
1845
- }
1846
-
1847
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1848
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1849
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1850
- if (direction === "horizontal") {
1851
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1852
- return accumulated + handle.offsetWidth;
1853
- }, 0);
1854
- } else {
1855
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1856
- return accumulated + handle.offsetHeight;
1857
- }, 0);
1858
- }
1859
- }
1860
-
1861
- function getPanelElement(id, panelGroupElement) {
1862
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1870
+ function getPanelElement(id, scope = document) {
1871
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1863
1872
  if (element) {
1864
1873
  return element;
1865
1874
  }
1866
1875
  return null;
1867
1876
  }
1868
1877
 
1869
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1870
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1878
+ function getPanelElementsForGroup(groupId, scope = document) {
1879
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1871
1880
  }
1872
1881
 
1873
- export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
1882
+ export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
@@ -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
@@ -123,6 +124,9 @@ function PanelWithForwardedRef({
123
124
  callbacks,
124
125
  constraints
125
126
  } = panelDataRef.current;
127
+ const prevConstraints = {
128
+ ...constraints
129
+ };
126
130
  panelDataRef.current.id = panelId;
127
131
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
128
132
  panelDataRef.current.order = order;
@@ -134,6 +138,12 @@ function PanelWithForwardedRef({
134
138
  constraints.defaultSize = defaultSize;
135
139
  constraints.maxSize = maxSize;
136
140
  constraints.minSize = minSize;
141
+
142
+ // If constraints have changed, we should revisit panel sizes.
143
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
144
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
145
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
146
+ }
137
147
  });
138
148
  useIsomorphicLayoutEffect(() => {
139
149
  const panelData = panelDataRef.current;
@@ -521,12 +531,12 @@ function calculateAriaValues({
521
531
  };
522
532
  }
523
533
 
524
- function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
525
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
534
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
535
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
526
536
  }
527
537
 
528
- function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
529
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
538
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
539
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
530
540
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
531
541
  return index !== null && index !== void 0 ? index : null;
532
542
  }
@@ -536,7 +546,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
536
546
  return index != null ? [index, index + 1] : [-1, -1];
537
547
  }
538
548
 
539
- function getPanelGroupElement(id, rootElement) {
549
+ function getPanelGroupElement(id, rootElement = document) {
540
550
  var _dataset;
541
551
  //If the root element is the PanelGroup
542
552
  if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
@@ -551,18 +561,18 @@ function getPanelGroupElement(id, rootElement) {
551
561
  return null;
552
562
  }
553
563
 
554
- function getResizeHandleElement(id, panelGroupElement) {
555
- const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
564
+ function getResizeHandleElement(id, scope = document) {
565
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
556
566
  if (element) {
557
567
  return element;
558
568
  }
559
569
  return null;
560
570
  }
561
571
 
562
- function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
572
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
563
573
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
564
- const handle = getResizeHandleElement(handleId, panelGroupElement);
565
- const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
574
+ const handle = getResizeHandleElement(handleId, scope);
575
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
566
576
  const index = handle ? handles.indexOf(handle) : -1;
567
577
  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;
568
578
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -1547,6 +1557,37 @@ function PanelGroupWithForwardedRef({
1547
1557
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1548
1558
  }
1549
1559
  }, []);
1560
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1561
+ const {
1562
+ layout,
1563
+ panelDataArray
1564
+ } = eagerValuesRef.current;
1565
+ const {
1566
+ collapsedSize: prevCollapsedSize = 0,
1567
+ collapsible: prevCollapsible,
1568
+ defaultSize: prevDefaultSize,
1569
+ maxSize: prevMaxSize = 100,
1570
+ minSize: prevMinSize = 0
1571
+ } = prevConstraints;
1572
+ const {
1573
+ collapsedSize: nextCollapsedSize = 0,
1574
+ collapsible: nextCollapsible,
1575
+ defaultSize: nextDefaultSize,
1576
+ maxSize: nextMaxSize = 100,
1577
+ minSize: nextMinSize = 0
1578
+ } = panelData.constraints;
1579
+ const {
1580
+ panelSize: prevPanelSize
1581
+ } = panelDataHelper(panelDataArray, panelData, layout);
1582
+ assert(prevPanelSize != null);
1583
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1584
+ resizePanel(panelData, nextCollapsedSize);
1585
+ } else if (prevPanelSize < nextMinSize) {
1586
+ resizePanel(panelData, nextMinSize);
1587
+ } else if (prevPanelSize > nextMaxSize) {
1588
+ resizePanel(panelData, nextMaxSize);
1589
+ }
1590
+ }, [resizePanel]);
1550
1591
  const startDragging = useCallback((dragHandleId, event) => {
1551
1592
  const {
1552
1593
  direction
@@ -1597,6 +1638,7 @@ function PanelGroupWithForwardedRef({
1597
1638
  groupId,
1598
1639
  isPanelCollapsed,
1599
1640
  isPanelExpanded,
1641
+ reevaluatePanelConstraints,
1600
1642
  registerPanel,
1601
1643
  registerResizeHandle,
1602
1644
  resizePanel,
@@ -1604,7 +1646,7 @@ function PanelGroupWithForwardedRef({
1604
1646
  stopDragging,
1605
1647
  unregisterPanel,
1606
1648
  panelGroupElement: panelGroupElementRef.current
1607
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1649
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1608
1650
  const style = {
1609
1651
  display: "flex",
1610
1652
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1639,14 +1681,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1639
1681
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1640
1682
  }
1641
1683
  function panelDataHelper(panelDataArray, panelData, layout) {
1642
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1643
1684
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1644
- const panelConstraints = panelConstraintsArray[panelIndex];
1645
1685
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1646
1686
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1647
1687
  const panelSize = layout[panelIndex];
1648
1688
  return {
1649
- ...panelConstraints,
1689
+ ...panelData.constraints,
1650
1690
  panelSize,
1651
1691
  pivotIndices
1652
1692
  };
@@ -1853,55 +1893,22 @@ function PanelResizeHandle({
1853
1893
  }
1854
1894
  PanelResizeHandle.displayName = "PanelResizeHandle";
1855
1895
 
1856
- function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
1857
- if (panelGroupElement == null) {
1858
- return NaN;
1859
- }
1860
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1861
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1862
- if (direction === "horizontal") {
1863
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1864
- return accumulated + handle.offsetWidth;
1865
- }, 0);
1866
- } else {
1867
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1868
- return accumulated + handle.offsetHeight;
1869
- }, 0);
1870
- }
1871
- }
1872
-
1873
- function getAvailableGroupSizePixels(groupId, panelGroupElement) {
1874
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1875
- const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1876
- if (direction === "horizontal") {
1877
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1878
- return accumulated + handle.offsetWidth;
1879
- }, 0);
1880
- } else {
1881
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1882
- return accumulated + handle.offsetHeight;
1883
- }, 0);
1884
- }
1885
- }
1886
-
1887
- function getPanelElement(id, panelGroupElement) {
1888
- const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
1896
+ function getPanelElement(id, scope = document) {
1897
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1889
1898
  if (element) {
1890
1899
  return element;
1891
1900
  }
1892
1901
  return null;
1893
1902
  }
1894
1903
 
1895
- function getPanelElementsForGroup(groupId, panelGroupElement) {
1896
- return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1904
+ function getPanelElementsForGroup(groupId, scope = document) {
1905
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1897
1906
  }
1898
1907
 
1899
1908
  exports.Panel = Panel;
1900
1909
  exports.PanelGroup = PanelGroup;
1901
1910
  exports.PanelResizeHandle = PanelResizeHandle;
1902
1911
  exports.assert = assert;
1903
- exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
1904
- exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
1905
1912
  exports.getPanelElement = getPanelElement;
1906
1913
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
1907
1914
  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,