react-resizable-panels 1.0.6 → 1.0.8
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.
- package/CHANGELOG.md +10 -0
- package/README.md +20 -4
- package/dist/declarations/src/Panel.d.ts +6 -6
- package/dist/declarations/src/PanelGroup.d.ts +5 -5
- package/dist/declarations/src/PanelResizeHandle.d.ts +4 -4
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +1 -1
- package/dist/declarations/src/vendor/react.d.ts +2 -2
- package/dist/react-resizable-panels.browser.cjs.js +82 -59
- package/dist/react-resizable-panels.browser.development.cjs.js +84 -60
- package/dist/react-resizable-panels.browser.development.esm.js +84 -60
- package/dist/react-resizable-panels.browser.esm.js +82 -59
- package/dist/react-resizable-panels.cjs.js +82 -59
- package/dist/react-resizable-panels.development.cjs.js +84 -60
- package/dist/react-resizable-panels.development.esm.js +84 -60
- package/dist/react-resizable-panels.development.node.cjs.js +79 -58
- package/dist/react-resizable-panels.development.node.esm.js +79 -58
- package/dist/react-resizable-panels.esm.js +82 -59
- package/dist/react-resizable-panels.node.cjs.js +77 -57
- package/dist/react-resizable-panels.node.esm.js +77 -57
- package/package.json +1 -1
- package/src/Panel.test.tsx +3 -2
- package/src/Panel.ts +7 -4
- package/src/PanelGroup.test.tsx +3 -2
- package/src/PanelGroup.ts +53 -30
- package/src/PanelGroupContext.ts +4 -2
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +17 -12
- package/src/hooks/useWindowSplitterBehavior.ts +15 -6
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
- package/src/utils/calculateDeltaPercentage.ts +4 -2
- package/src/utils/calculateDragOffsetPercentage.ts +4 -3
- package/src/utils/determinePivotIndices.ts +7 -2
- package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +8 -3
- package/src/utils/dom/getAvailableGroupSizePixels.ts +8 -7
- package/src/utils/dom/getPanelElement.ts +6 -3
- package/src/utils/dom/getPanelElementsForGroup.ts +7 -2
- package/src/utils/dom/getPanelGroupElement.ts +15 -3
- package/src/utils/dom/getResizeHandleElement.ts +6 -3
- package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +4 -3
- package/src/utils/dom/getResizeHandlePanelIds.ts +4 -3
- package/src/utils/validatePanelConstraints.test.ts +45 -0
- package/src/utils/validatePanelConstraints.ts +5 -1
- package/src/vendor/react.ts +2 -0
|
@@ -508,41 +508,48 @@ function calculateAriaValues({
|
|
|
508
508
|
};
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
512
|
-
return Array.from(
|
|
511
|
+
function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
|
|
512
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
513
513
|
}
|
|
514
514
|
|
|
515
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
516
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
515
|
+
function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
|
|
516
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
517
517
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
518
518
|
return index !== null && index !== void 0 ? index : null;
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
522
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
521
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
522
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
523
523
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
function getPanelGroupElement(id) {
|
|
527
|
-
|
|
526
|
+
function getPanelGroupElement(id, rootElement) {
|
|
527
|
+
var _dataset;
|
|
528
|
+
//If the root element is the PanelGroup
|
|
529
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
530
|
+
return rootElement;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
//Else query children
|
|
534
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
528
535
|
if (element) {
|
|
529
536
|
return element;
|
|
530
537
|
}
|
|
531
538
|
return null;
|
|
532
539
|
}
|
|
533
540
|
|
|
534
|
-
function getResizeHandleElement(id) {
|
|
535
|
-
const element =
|
|
541
|
+
function getResizeHandleElement(id, panelGroupElement) {
|
|
542
|
+
const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
536
543
|
if (element) {
|
|
537
544
|
return element;
|
|
538
545
|
}
|
|
539
546
|
return null;
|
|
540
547
|
}
|
|
541
548
|
|
|
542
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
549
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
|
|
543
550
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
544
|
-
const handle = getResizeHandleElement(handleId);
|
|
545
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
551
|
+
const handle = getResizeHandleElement(handleId, panelGroupElement);
|
|
552
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
546
553
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
547
554
|
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
555
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -557,13 +564,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
557
564
|
groupId,
|
|
558
565
|
layout,
|
|
559
566
|
panelDataArray,
|
|
567
|
+
panelGroupElement,
|
|
560
568
|
setLayout
|
|
561
569
|
}) {
|
|
562
570
|
const devWarningsRef = useRef({
|
|
563
571
|
didWarnAboutMissingResizeHandle: false
|
|
564
572
|
});
|
|
565
573
|
useIsomorphicLayoutEffect(() => {
|
|
566
|
-
|
|
574
|
+
if (!panelGroupElement) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
567
578
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
568
579
|
const {
|
|
569
580
|
valueMax,
|
|
@@ -602,21 +613,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
602
613
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
603
614
|
});
|
|
604
615
|
};
|
|
605
|
-
}, [groupId, layout, panelDataArray]);
|
|
616
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
606
617
|
useEffect(() => {
|
|
618
|
+
if (!panelGroupElement) {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
607
621
|
const eagerValues = eagerValuesRef.current;
|
|
608
622
|
assert(eagerValues);
|
|
609
623
|
const {
|
|
610
624
|
panelDataArray
|
|
611
625
|
} = eagerValues;
|
|
612
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
626
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
613
627
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
614
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
628
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
615
629
|
assert(handles);
|
|
616
630
|
const cleanupFunctions = handles.map(handle => {
|
|
617
631
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
618
632
|
assert(handleId);
|
|
619
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
633
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
620
634
|
if (idBefore == null || idAfter == null) {
|
|
621
635
|
return () => {};
|
|
622
636
|
}
|
|
@@ -643,7 +657,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
643
657
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
644
658
|
layout,
|
|
645
659
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
646
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
660
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
647
661
|
trigger: "keyboard"
|
|
648
662
|
});
|
|
649
663
|
if (layout !== nextLayout) {
|
|
@@ -663,7 +677,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
663
677
|
return () => {
|
|
664
678
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
665
679
|
};
|
|
666
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
680
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
667
681
|
}
|
|
668
682
|
|
|
669
683
|
function areEqual(arrayA, arrayB) {
|
|
@@ -701,9 +715,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
701
715
|
}
|
|
702
716
|
}
|
|
703
717
|
|
|
704
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
718
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
705
719
|
const isHorizontal = direction === "horizontal";
|
|
706
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
720
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
707
721
|
assert(handleElement);
|
|
708
722
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
709
723
|
assert(groupId);
|
|
@@ -711,7 +725,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
711
725
|
initialCursorPosition
|
|
712
726
|
} = initialDragState;
|
|
713
727
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
714
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
728
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
715
729
|
assert(groupElement);
|
|
716
730
|
const groupRect = groupElement.getBoundingClientRect();
|
|
717
731
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -721,7 +735,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
721
735
|
}
|
|
722
736
|
|
|
723
737
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
724
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
738
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
725
739
|
if (isKeyDown(event)) {
|
|
726
740
|
const isHorizontal = direction === "horizontal";
|
|
727
741
|
let delta = 0;
|
|
@@ -758,7 +772,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
758
772
|
if (initialDragState == null) {
|
|
759
773
|
return 0;
|
|
760
774
|
}
|
|
761
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
775
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
762
776
|
}
|
|
763
777
|
}
|
|
764
778
|
|
|
@@ -1032,6 +1046,7 @@ function validatePanelConstraints({
|
|
|
1032
1046
|
assert(panelConstraints);
|
|
1033
1047
|
const {
|
|
1034
1048
|
collapsedSize = 0,
|
|
1049
|
+
collapsible = false,
|
|
1035
1050
|
defaultSize,
|
|
1036
1051
|
maxSize = 100,
|
|
1037
1052
|
minSize = 0
|
|
@@ -1042,7 +1057,7 @@ function validatePanelConstraints({
|
|
|
1042
1057
|
if (defaultSize != null) {
|
|
1043
1058
|
if (defaultSize < 0) {
|
|
1044
1059
|
warnings.push("default size should not be less than 0");
|
|
1045
|
-
} else if (defaultSize < minSize) {
|
|
1060
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
1046
1061
|
warnings.push("default size should not be less than min size");
|
|
1047
1062
|
}
|
|
1048
1063
|
if (defaultSize > 100) {
|
|
@@ -1157,6 +1172,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1157
1172
|
...rest
|
|
1158
1173
|
}) {
|
|
1159
1174
|
const groupId = useUniqueId(idFromProps);
|
|
1175
|
+
const panelGroupElementRef = useRef(null);
|
|
1160
1176
|
const [dragState, setDragState] = useState(null);
|
|
1161
1177
|
const [layout, setLayout] = useState([]);
|
|
1162
1178
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1225,7 +1241,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1225
1241
|
groupId,
|
|
1226
1242
|
layout,
|
|
1227
1243
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1228
|
-
setLayout
|
|
1244
|
+
setLayout,
|
|
1245
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1229
1246
|
});
|
|
1230
1247
|
useEffect(() => {
|
|
1231
1248
|
const {
|
|
@@ -1510,6 +1527,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1510
1527
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1511
1528
|
return function resizeHandler(event) {
|
|
1512
1529
|
event.preventDefault();
|
|
1530
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1531
|
+
if (!panelGroupElement) {
|
|
1532
|
+
return () => null;
|
|
1533
|
+
}
|
|
1513
1534
|
const {
|
|
1514
1535
|
direction,
|
|
1515
1536
|
dragState,
|
|
@@ -1524,8 +1545,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1524
1545
|
const {
|
|
1525
1546
|
initialLayout
|
|
1526
1547
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1527
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1528
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1548
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1549
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1529
1550
|
if (delta === 0) {
|
|
1530
1551
|
return;
|
|
1531
1552
|
}
|
|
@@ -1620,7 +1641,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1620
1641
|
const {
|
|
1621
1642
|
layout
|
|
1622
1643
|
} = eagerValuesRef.current;
|
|
1623
|
-
|
|
1644
|
+
if (!panelGroupElementRef.current) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1624
1648
|
assert(handleElement);
|
|
1625
1649
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1626
1650
|
setDragState({
|
|
@@ -1665,7 +1689,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1665
1689
|
resizePanel,
|
|
1666
1690
|
startDragging,
|
|
1667
1691
|
stopDragging,
|
|
1668
|
-
unregisterPanel
|
|
1692
|
+
unregisterPanel,
|
|
1693
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1669
1694
|
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1670
1695
|
const style = {
|
|
1671
1696
|
display: "flex",
|
|
@@ -1684,6 +1709,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1684
1709
|
...style,
|
|
1685
1710
|
...styleFromProps
|
|
1686
1711
|
},
|
|
1712
|
+
ref: panelGroupElementRef,
|
|
1687
1713
|
// CSS selectors
|
|
1688
1714
|
"data-panel-group": "",
|
|
1689
1715
|
"data-panel-group-direction": direction,
|
|
@@ -1718,13 +1744,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1718
1744
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1719
1745
|
disabled,
|
|
1720
1746
|
handleId,
|
|
1721
|
-
resizeHandler
|
|
1747
|
+
resizeHandler,
|
|
1748
|
+
panelGroupElement
|
|
1722
1749
|
}) {
|
|
1723
1750
|
useEffect(() => {
|
|
1724
|
-
if (disabled || resizeHandler == null) {
|
|
1751
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1725
1752
|
return;
|
|
1726
1753
|
}
|
|
1727
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1754
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1728
1755
|
if (handleElement == null) {
|
|
1729
1756
|
return;
|
|
1730
1757
|
}
|
|
@@ -1749,8 +1776,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1749
1776
|
event.preventDefault();
|
|
1750
1777
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1751
1778
|
assert(groupId);
|
|
1752
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1753
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1779
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1780
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1754
1781
|
assert(index !== null);
|
|
1755
1782
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1756
1783
|
const nextHandle = handles[nextIndex];
|
|
@@ -1763,7 +1790,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1763
1790
|
return () => {
|
|
1764
1791
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1765
1792
|
};
|
|
1766
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1793
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1767
1794
|
}
|
|
1768
1795
|
|
|
1769
1796
|
function PanelResizeHandle({
|
|
@@ -1777,7 +1804,7 @@ function PanelResizeHandle({
|
|
|
1777
1804
|
tagName: Type = "div",
|
|
1778
1805
|
...rest
|
|
1779
1806
|
}) {
|
|
1780
|
-
const
|
|
1807
|
+
const elementRef = useRef(null);
|
|
1781
1808
|
|
|
1782
1809
|
// Use a ref to guard against users passing inline props
|
|
1783
1810
|
const callbacksRef = useRef({
|
|
@@ -1796,7 +1823,8 @@ function PanelResizeHandle({
|
|
|
1796
1823
|
groupId,
|
|
1797
1824
|
registerResizeHandle,
|
|
1798
1825
|
startDragging,
|
|
1799
|
-
stopDragging
|
|
1826
|
+
stopDragging,
|
|
1827
|
+
panelGroupElement
|
|
1800
1828
|
} = panelGroupContext;
|
|
1801
1829
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1802
1830
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1805,9 +1833,9 @@ function PanelResizeHandle({
|
|
|
1805
1833
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1806
1834
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1807
1835
|
// That would cause the PanelGroup to think it was still active.
|
|
1808
|
-
const
|
|
1809
|
-
assert(
|
|
1810
|
-
|
|
1836
|
+
const element = elementRef.current;
|
|
1837
|
+
assert(element);
|
|
1838
|
+
element.blur();
|
|
1811
1839
|
stopDragging();
|
|
1812
1840
|
const {
|
|
1813
1841
|
onDragging
|
|
@@ -1834,9 +1862,9 @@ function PanelResizeHandle({
|
|
|
1834
1862
|
const onMouseLeave = event => {
|
|
1835
1863
|
resizeHandler(event);
|
|
1836
1864
|
};
|
|
1837
|
-
const
|
|
1838
|
-
assert(
|
|
1839
|
-
const targetDocument =
|
|
1865
|
+
const element = elementRef.current;
|
|
1866
|
+
assert(element);
|
|
1867
|
+
const targetDocument = element.ownerDocument;
|
|
1840
1868
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1841
1869
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1842
1870
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1855,7 +1883,8 @@ function PanelResizeHandle({
|
|
|
1855
1883
|
useWindowSplitterResizeHandlerBehavior({
|
|
1856
1884
|
disabled,
|
|
1857
1885
|
handleId: resizeHandleId,
|
|
1858
|
-
resizeHandler
|
|
1886
|
+
resizeHandler,
|
|
1887
|
+
panelGroupElement
|
|
1859
1888
|
});
|
|
1860
1889
|
const style = {
|
|
1861
1890
|
cursor: getCursorStyle(direction),
|
|
@@ -1893,7 +1922,7 @@ function PanelResizeHandle({
|
|
|
1893
1922
|
onDragging(true);
|
|
1894
1923
|
}
|
|
1895
1924
|
},
|
|
1896
|
-
ref:
|
|
1925
|
+
ref: elementRef,
|
|
1897
1926
|
role: "separator",
|
|
1898
1927
|
style: {
|
|
1899
1928
|
...style,
|
|
@@ -1911,13 +1940,12 @@ function PanelResizeHandle({
|
|
|
1911
1940
|
}
|
|
1912
1941
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1913
1942
|
|
|
1914
|
-
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1915
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1943
|
+
function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
|
|
1916
1944
|
if (panelGroupElement == null) {
|
|
1917
1945
|
return NaN;
|
|
1918
1946
|
}
|
|
1919
1947
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1920
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1948
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1921
1949
|
if (direction === "horizontal") {
|
|
1922
1950
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1923
1951
|
return accumulated + handle.offsetWidth;
|
|
@@ -1929,13 +1957,9 @@ function calculateAvailablePanelSizeInPixels(groupId) {
|
|
|
1929
1957
|
}
|
|
1930
1958
|
}
|
|
1931
1959
|
|
|
1932
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1933
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1934
|
-
if (panelGroupElement == null) {
|
|
1935
|
-
return NaN;
|
|
1936
|
-
}
|
|
1960
|
+
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1937
1961
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1938
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1962
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1939
1963
|
if (direction === "horizontal") {
|
|
1940
1964
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1941
1965
|
return accumulated + handle.offsetWidth;
|
|
@@ -1947,16 +1971,16 @@ function getAvailableGroupSizePixels(groupId) {
|
|
|
1947
1971
|
}
|
|
1948
1972
|
}
|
|
1949
1973
|
|
|
1950
|
-
function getPanelElement(id) {
|
|
1951
|
-
const element =
|
|
1974
|
+
function getPanelElement(id, panelGroupElement) {
|
|
1975
|
+
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1952
1976
|
if (element) {
|
|
1953
1977
|
return element;
|
|
1954
1978
|
}
|
|
1955
1979
|
return null;
|
|
1956
1980
|
}
|
|
1957
1981
|
|
|
1958
|
-
function getPanelElementsForGroup(groupId) {
|
|
1959
|
-
return Array.from(
|
|
1982
|
+
function getPanelElementsForGroup(groupId, panelGroupElement) {
|
|
1983
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1960
1984
|
}
|
|
1961
1985
|
|
|
1962
1986
|
export { Panel, PanelGroup, PanelResizeHandle, assert, calculateAvailablePanelSizeInPixels, getAvailableGroupSizePixels, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|