react-resizable-panels 1.0.7 → 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 (60) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +16 -15
  3. package/dist/declarations/src/Panel.d.ts +3 -3
  4. package/dist/declarations/src/PanelGroup.d.ts +2 -2
  5. package/dist/declarations/src/PanelResizeHandle.d.ts +2 -2
  6. package/dist/declarations/src/index.d.ts +1 -3
  7. package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
  8. package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
  9. package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
  10. package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
  11. package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -1
  12. package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
  13. package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +1 -1
  14. package/dist/declarations/src/vendor/react.d.ts +2 -2
  15. package/dist/react-resizable-panels.browser.cjs.js +114 -84
  16. package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
  17. package/dist/react-resizable-panels.browser.development.cjs.js +116 -85
  18. package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
  19. package/dist/react-resizable-panels.browser.development.esm.js +117 -84
  20. package/dist/react-resizable-panels.browser.esm.js +115 -83
  21. package/dist/react-resizable-panels.cjs.js +114 -84
  22. package/dist/react-resizable-panels.cjs.mjs +0 -2
  23. package/dist/react-resizable-panels.development.cjs.js +116 -85
  24. package/dist/react-resizable-panels.development.cjs.mjs +0 -2
  25. package/dist/react-resizable-panels.development.esm.js +117 -84
  26. package/dist/react-resizable-panels.development.node.cjs.js +102 -83
  27. package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
  28. package/dist/react-resizable-panels.development.node.esm.js +103 -82
  29. package/dist/react-resizable-panels.esm.js +115 -83
  30. package/dist/react-resizable-panels.node.cjs.js +100 -82
  31. package/dist/react-resizable-panels.node.cjs.mjs +0 -2
  32. package/dist/react-resizable-panels.node.esm.js +101 -81
  33. package/package.json +1 -1
  34. package/src/Panel.test.tsx +137 -2
  35. package/src/Panel.ts +16 -2
  36. package/src/PanelGroup.test.tsx +3 -2
  37. package/src/PanelGroup.ts +95 -35
  38. package/src/PanelGroupContext.ts +9 -3
  39. package/src/PanelResizeHandle.test.tsx +3 -3
  40. package/src/PanelResizeHandle.ts +4 -2
  41. package/src/hooks/useWindowSplitterBehavior.ts +14 -5
  42. package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
  43. package/src/index.ts +0 -4
  44. package/src/utils/calculateDeltaPercentage.ts +4 -2
  45. package/src/utils/calculateDragOffsetPercentage.ts +4 -3
  46. package/src/utils/determinePivotIndices.ts +7 -2
  47. package/src/utils/dom/getPanelElement.ts +5 -2
  48. package/src/utils/dom/getPanelElementsForGroup.ts +5 -2
  49. package/src/utils/dom/getPanelGroupElement.ts +14 -2
  50. package/src/utils/dom/getResizeHandleElement.ts +5 -4
  51. package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
  52. package/src/utils/dom/getResizeHandleElementsForGroup.ts +3 -2
  53. package/src/utils/dom/getResizeHandlePanelIds.ts +4 -3
  54. package/src/utils/validatePanelConstraints.test.ts +45 -0
  55. package/src/utils/validatePanelConstraints.ts +5 -1
  56. package/src/vendor/react.ts +2 -0
  57. package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +0 -1
  58. package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +0 -1
  59. package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +0 -29
  60. package/src/utils/dom/getAvailableGroupSizePixels.ts +0 -29
@@ -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
@@ -99,6 +100,9 @@ function PanelWithForwardedRef({
99
100
  callbacks,
100
101
  constraints
101
102
  } = panelDataRef.current;
103
+ const prevConstraints = {
104
+ ...constraints
105
+ };
102
106
  panelDataRef.current.id = panelId;
103
107
  panelDataRef.current.idIsFromProps = idFromProps !== undefined;
104
108
  panelDataRef.current.order = order;
@@ -110,6 +114,12 @@ function PanelWithForwardedRef({
110
114
  constraints.defaultSize = defaultSize;
111
115
  constraints.maxSize = maxSize;
112
116
  constraints.minSize = minSize;
117
+
118
+ // If constraints have changed, we should revisit panel sizes.
119
+ // This is uncommon but may happen if people are trying to implement pixel based constraints.
120
+ if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
121
+ reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
122
+ }
113
123
  });
114
124
  useIsomorphicLayoutEffect(() => {
115
125
  const panelData = panelDataRef.current;
@@ -497,41 +507,48 @@ function calculateAriaValues({
497
507
  };
498
508
  }
499
509
 
500
- function getResizeHandleElementsForGroup(groupId) {
501
- return Array.from(document.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
510
+ function getResizeHandleElementsForGroup(groupId, scope = document) {
511
+ return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
502
512
  }
503
513
 
504
- function getResizeHandleElementIndex(groupId, id) {
505
- const handles = getResizeHandleElementsForGroup(groupId);
514
+ function getResizeHandleElementIndex(groupId, id, scope = document) {
515
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
506
516
  const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
507
517
  return index !== null && index !== void 0 ? index : null;
508
518
  }
509
519
 
510
- function determinePivotIndices(groupId, dragHandleId) {
511
- const index = getResizeHandleElementIndex(groupId, dragHandleId);
520
+ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
521
+ const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
512
522
  return index != null ? [index, index + 1] : [-1, -1];
513
523
  }
514
524
 
515
- function getPanelGroupElement(id) {
516
- const element = document.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
525
+ function getPanelGroupElement(id, rootElement = document) {
526
+ var _dataset;
527
+ //If the root element is the PanelGroup
528
+ if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
529
+ return rootElement;
530
+ }
531
+
532
+ //Else query children
533
+ const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
517
534
  if (element) {
518
535
  return element;
519
536
  }
520
537
  return null;
521
538
  }
522
539
 
523
- function getResizeHandleElement(id) {
524
- const element = document.querySelector(`[data-panel-resize-handle-id="${id}"]`);
540
+ function getResizeHandleElement(id, scope = document) {
541
+ const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
525
542
  if (element) {
526
543
  return element;
527
544
  }
528
545
  return null;
529
546
  }
530
547
 
531
- function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
548
+ function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
532
549
  var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
533
- const handle = getResizeHandleElement(handleId);
534
- const handles = getResizeHandleElementsForGroup(groupId);
550
+ const handle = getResizeHandleElement(handleId, scope);
551
+ const handles = getResizeHandleElementsForGroup(groupId, scope);
535
552
  const index = handle ? handles.indexOf(handle) : -1;
536
553
  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;
537
554
  const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
@@ -546,13 +563,17 @@ function useWindowSplitterPanelGroupBehavior({
546
563
  groupId,
547
564
  layout,
548
565
  panelDataArray,
566
+ panelGroupElement,
549
567
  setLayout
550
568
  }) {
551
569
  useRef({
552
570
  didWarnAboutMissingResizeHandle: false
553
571
  });
554
572
  useIsomorphicLayoutEffect(() => {
555
- const resizeHandleElements = getResizeHandleElementsForGroup(groupId);
573
+ if (!panelGroupElement) {
574
+ return;
575
+ }
576
+ const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
556
577
  for (let index = 0; index < panelDataArray.length - 1; index++) {
557
578
  const {
558
579
  valueMax,
@@ -581,21 +602,24 @@ function useWindowSplitterPanelGroupBehavior({
581
602
  resizeHandleElement.removeAttribute("aria-valuenow");
582
603
  });
583
604
  };
584
- }, [groupId, layout, panelDataArray]);
605
+ }, [groupId, layout, panelDataArray, panelGroupElement]);
585
606
  useEffect(() => {
607
+ if (!panelGroupElement) {
608
+ return;
609
+ }
586
610
  const eagerValues = eagerValuesRef.current;
587
611
  assert(eagerValues);
588
612
  const {
589
613
  panelDataArray
590
614
  } = eagerValues;
591
- const groupElement = getPanelGroupElement(groupId);
615
+ const groupElement = getPanelGroupElement(groupId, panelGroupElement);
592
616
  assert(groupElement != null, `No group found for id "${groupId}"`);
593
- const handles = getResizeHandleElementsForGroup(groupId);
617
+ const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
594
618
  assert(handles);
595
619
  const cleanupFunctions = handles.map(handle => {
596
620
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
597
621
  assert(handleId);
598
- const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
622
+ const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
599
623
  if (idBefore == null || idAfter == null) {
600
624
  return () => {};
601
625
  }
@@ -622,7 +646,7 @@ function useWindowSplitterPanelGroupBehavior({
622
646
  delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
623
647
  layout,
624
648
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
625
- pivotIndices: determinePivotIndices(groupId, handleId),
649
+ pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
626
650
  trigger: "keyboard"
627
651
  });
628
652
  if (layout !== nextLayout) {
@@ -642,7 +666,7 @@ function useWindowSplitterPanelGroupBehavior({
642
666
  return () => {
643
667
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
644
668
  };
645
- }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
669
+ }, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
646
670
  }
647
671
 
648
672
  function areEqual(arrayA, arrayB) {
@@ -680,9 +704,9 @@ function getResizeEventCursorPosition(direction, event) {
680
704
  }
681
705
  }
682
706
 
683
- function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
707
+ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
684
708
  const isHorizontal = direction === "horizontal";
685
- const handleElement = getResizeHandleElement(dragHandleId);
709
+ const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
686
710
  assert(handleElement);
687
711
  const groupId = handleElement.getAttribute("data-panel-group-id");
688
712
  assert(groupId);
@@ -690,7 +714,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
690
714
  initialCursorPosition
691
715
  } = initialDragState;
692
716
  const cursorPosition = getResizeEventCursorPosition(direction, event);
693
- const groupElement = getPanelGroupElement(groupId);
717
+ const groupElement = getPanelGroupElement(groupId, panelGroupElement);
694
718
  assert(groupElement);
695
719
  const groupRect = groupElement.getBoundingClientRect();
696
720
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
@@ -700,7 +724,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
700
724
  }
701
725
 
702
726
  // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
703
- function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
727
+ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
704
728
  if (isKeyDown(event)) {
705
729
  const isHorizontal = direction === "horizontal";
706
730
  let delta = 0;
@@ -737,7 +761,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
737
761
  if (initialDragState == null) {
738
762
  return 0;
739
763
  }
740
- return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
764
+ return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
741
765
  }
742
766
  }
743
767
 
@@ -1089,6 +1113,7 @@ function PanelGroupWithForwardedRef({
1089
1113
  ...rest
1090
1114
  }) {
1091
1115
  const groupId = useUniqueId(idFromProps);
1116
+ const panelGroupElementRef = useRef(null);
1092
1117
  const [dragState, setDragState] = useState(null);
1093
1118
  const [layout, setLayout] = useState([]);
1094
1119
  const panelIdToLastNotifiedSizeMapRef = useRef({});
@@ -1157,7 +1182,8 @@ function PanelGroupWithForwardedRef({
1157
1182
  groupId,
1158
1183
  layout,
1159
1184
  panelDataArray: eagerValuesRef.current.panelDataArray,
1160
- setLayout
1185
+ setLayout,
1186
+ panelGroupElement: panelGroupElementRef.current
1161
1187
  });
1162
1188
  useEffect(() => {
1163
1189
  const {
@@ -1400,6 +1426,10 @@ function PanelGroupWithForwardedRef({
1400
1426
  const registerResizeHandle = useCallback(dragHandleId => {
1401
1427
  return function resizeHandler(event) {
1402
1428
  event.preventDefault();
1429
+ const panelGroupElement = panelGroupElementRef.current;
1430
+ if (!panelGroupElement) {
1431
+ return () => null;
1432
+ }
1403
1433
  const {
1404
1434
  direction,
1405
1435
  dragState,
@@ -1414,8 +1444,8 @@ function PanelGroupWithForwardedRef({
1414
1444
  const {
1415
1445
  initialLayout
1416
1446
  } = dragState !== null && dragState !== void 0 ? dragState : {};
1417
- const pivotIndices = determinePivotIndices(groupId, dragHandleId);
1418
- let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
1447
+ const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
1448
+ let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
1419
1449
  if (delta === 0) {
1420
1450
  return;
1421
1451
  }
@@ -1503,6 +1533,37 @@ function PanelGroupWithForwardedRef({
1503
1533
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1504
1534
  }
1505
1535
  }, []);
1536
+ const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1537
+ const {
1538
+ layout,
1539
+ panelDataArray
1540
+ } = eagerValuesRef.current;
1541
+ const {
1542
+ collapsedSize: prevCollapsedSize = 0,
1543
+ collapsible: prevCollapsible,
1544
+ defaultSize: prevDefaultSize,
1545
+ maxSize: prevMaxSize = 100,
1546
+ minSize: prevMinSize = 0
1547
+ } = prevConstraints;
1548
+ const {
1549
+ collapsedSize: nextCollapsedSize = 0,
1550
+ collapsible: nextCollapsible,
1551
+ defaultSize: nextDefaultSize,
1552
+ maxSize: nextMaxSize = 100,
1553
+ minSize: nextMinSize = 0
1554
+ } = panelData.constraints;
1555
+ const {
1556
+ panelSize: prevPanelSize
1557
+ } = panelDataHelper(panelDataArray, panelData, layout);
1558
+ assert(prevPanelSize != null);
1559
+ if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
1560
+ resizePanel(panelData, nextCollapsedSize);
1561
+ } else if (prevPanelSize < nextMinSize) {
1562
+ resizePanel(panelData, nextMinSize);
1563
+ } else if (prevPanelSize > nextMaxSize) {
1564
+ resizePanel(panelData, nextMaxSize);
1565
+ }
1566
+ }, [resizePanel]);
1506
1567
  const startDragging = useCallback((dragHandleId, event) => {
1507
1568
  const {
1508
1569
  direction
@@ -1510,7 +1571,10 @@ function PanelGroupWithForwardedRef({
1510
1571
  const {
1511
1572
  layout
1512
1573
  } = eagerValuesRef.current;
1513
- const handleElement = getResizeHandleElement(dragHandleId);
1574
+ if (!panelGroupElementRef.current) {
1575
+ return;
1576
+ }
1577
+ const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1514
1578
  assert(handleElement);
1515
1579
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1516
1580
  setDragState({
@@ -1550,13 +1614,15 @@ function PanelGroupWithForwardedRef({
1550
1614
  groupId,
1551
1615
  isPanelCollapsed,
1552
1616
  isPanelExpanded,
1617
+ reevaluatePanelConstraints,
1553
1618
  registerPanel,
1554
1619
  registerResizeHandle,
1555
1620
  resizePanel,
1556
1621
  startDragging,
1557
1622
  stopDragging,
1558
- unregisterPanel
1559
- }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1623
+ unregisterPanel,
1624
+ panelGroupElement: panelGroupElementRef.current
1625
+ }), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
1560
1626
  const style = {
1561
1627
  display: "flex",
1562
1628
  flexDirection: direction === "horizontal" ? "row" : "column",
@@ -1574,6 +1640,7 @@ function PanelGroupWithForwardedRef({
1574
1640
  ...style,
1575
1641
  ...styleFromProps
1576
1642
  },
1643
+ ref: panelGroupElementRef,
1577
1644
  // CSS selectors
1578
1645
  "data-panel-group": "",
1579
1646
  "data-panel-group-direction": direction,
@@ -1590,14 +1657,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
1590
1657
  return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1591
1658
  }
1592
1659
  function panelDataHelper(panelDataArray, panelData, layout) {
1593
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1594
1660
  const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1595
- const panelConstraints = panelConstraintsArray[panelIndex];
1596
1661
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1597
1662
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
1598
1663
  const panelSize = layout[panelIndex];
1599
1664
  return {
1600
- ...panelConstraints,
1665
+ ...panelData.constraints,
1601
1666
  panelSize,
1602
1667
  pivotIndices
1603
1668
  };
@@ -1608,13 +1673,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
1608
1673
  function useWindowSplitterResizeHandlerBehavior({
1609
1674
  disabled,
1610
1675
  handleId,
1611
- resizeHandler
1676
+ resizeHandler,
1677
+ panelGroupElement
1612
1678
  }) {
1613
1679
  useEffect(() => {
1614
- if (disabled || resizeHandler == null) {
1680
+ if (disabled || resizeHandler == null || panelGroupElement == null) {
1615
1681
  return;
1616
1682
  }
1617
- const handleElement = getResizeHandleElement(handleId);
1683
+ const handleElement = getResizeHandleElement(handleId, panelGroupElement);
1618
1684
  if (handleElement == null) {
1619
1685
  return;
1620
1686
  }
@@ -1639,8 +1705,8 @@ function useWindowSplitterResizeHandlerBehavior({
1639
1705
  event.preventDefault();
1640
1706
  const groupId = handleElement.getAttribute("data-panel-group-id");
1641
1707
  assert(groupId);
1642
- const handles = getResizeHandleElementsForGroup(groupId);
1643
- const index = getResizeHandleElementIndex(groupId, handleId);
1708
+ const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1709
+ const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
1644
1710
  assert(index !== null);
1645
1711
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
1646
1712
  const nextHandle = handles[nextIndex];
@@ -1653,7 +1719,7 @@ function useWindowSplitterResizeHandlerBehavior({
1653
1719
  return () => {
1654
1720
  handleElement.removeEventListener("keydown", onKeyDown);
1655
1721
  };
1656
- }, [disabled, handleId, resizeHandler]);
1722
+ }, [panelGroupElement, disabled, handleId, resizeHandler]);
1657
1723
  }
1658
1724
 
1659
1725
  function PanelResizeHandle({
@@ -1686,7 +1752,8 @@ function PanelResizeHandle({
1686
1752
  groupId,
1687
1753
  registerResizeHandle,
1688
1754
  startDragging,
1689
- stopDragging
1755
+ stopDragging,
1756
+ panelGroupElement
1690
1757
  } = panelGroupContext;
1691
1758
  const resizeHandleId = useUniqueId(idFromProps);
1692
1759
  const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
@@ -1745,7 +1812,8 @@ function PanelResizeHandle({
1745
1812
  useWindowSplitterResizeHandlerBehavior({
1746
1813
  disabled,
1747
1814
  handleId: resizeHandleId,
1748
- resizeHandler
1815
+ resizeHandler,
1816
+ panelGroupElement
1749
1817
  });
1750
1818
  const style = {
1751
1819
  cursor: getCursorStyle(direction),
@@ -1801,52 +1869,16 @@ function PanelResizeHandle({
1801
1869
  }
1802
1870
  PanelResizeHandle.displayName = "PanelResizeHandle";
1803
1871
 
1804
- function calculateAvailablePanelSizeInPixels(groupId) {
1805
- const panelGroupElement = getPanelGroupElement(groupId);
1806
- if (panelGroupElement == null) {
1807
- return NaN;
1808
- }
1809
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1810
- const resizeHandles = getResizeHandleElementsForGroup(groupId);
1811
- if (direction === "horizontal") {
1812
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1813
- return accumulated + handle.offsetWidth;
1814
- }, 0);
1815
- } else {
1816
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1817
- return accumulated + handle.offsetHeight;
1818
- }, 0);
1819
- }
1820
- }
1821
-
1822
- function getAvailableGroupSizePixels(groupId) {
1823
- const panelGroupElement = getPanelGroupElement(groupId);
1824
- if (panelGroupElement == null) {
1825
- return NaN;
1826
- }
1827
- const direction = panelGroupElement.getAttribute("data-panel-group-direction");
1828
- const resizeHandles = getResizeHandleElementsForGroup(groupId);
1829
- if (direction === "horizontal") {
1830
- return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
1831
- return accumulated + handle.offsetWidth;
1832
- }, 0);
1833
- } else {
1834
- return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
1835
- return accumulated + handle.offsetHeight;
1836
- }, 0);
1837
- }
1838
- }
1839
-
1840
- function getPanelElement(id) {
1841
- const element = document.querySelector(`[data-panel-id="${id}"]`);
1872
+ function getPanelElement(id, scope = document) {
1873
+ const element = scope.querySelector(`[data-panel-id="${id}"]`);
1842
1874
  if (element) {
1843
1875
  return element;
1844
1876
  }
1845
1877
  return null;
1846
1878
  }
1847
1879
 
1848
- function getPanelElementsForGroup(groupId) {
1849
- return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1880
+ function getPanelElementsForGroup(groupId, scope = document) {
1881
+ return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
1850
1882
  }
1851
1883
 
1852
- export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
1884
+ export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };