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.
- package/CHANGELOG.md +11 -0
- package/README.md +16 -15
- package/dist/declarations/src/Panel.d.ts +3 -3
- package/dist/declarations/src/PanelGroup.d.ts +2 -2
- package/dist/declarations/src/PanelResizeHandle.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +1 -3
- 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 +114 -84
- package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.cjs.js +116 -85
- package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.esm.js +117 -84
- package/dist/react-resizable-panels.browser.esm.js +115 -83
- package/dist/react-resizable-panels.cjs.js +114 -84
- package/dist/react-resizable-panels.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.cjs.js +116 -85
- package/dist/react-resizable-panels.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.esm.js +117 -84
- package/dist/react-resizable-panels.development.node.cjs.js +102 -83
- package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.node.esm.js +103 -82
- package/dist/react-resizable-panels.esm.js +115 -83
- package/dist/react-resizable-panels.node.cjs.js +100 -82
- package/dist/react-resizable-panels.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.node.esm.js +101 -81
- package/package.json +1 -1
- package/src/Panel.test.tsx +137 -2
- package/src/Panel.ts +16 -2
- package/src/PanelGroup.test.tsx +3 -2
- package/src/PanelGroup.ts +95 -35
- package/src/PanelGroupContext.ts +9 -3
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +4 -2
- package/src/hooks/useWindowSplitterBehavior.ts +14 -5
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
- package/src/index.ts +0 -4
- 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/getPanelElement.ts +5 -2
- package/src/utils/dom/getPanelElementsForGroup.ts +5 -2
- package/src/utils/dom/getPanelGroupElement.ts +14 -2
- package/src/utils/dom/getResizeHandleElement.ts +5 -4
- package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +3 -2
- 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
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +0 -1
- package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +0 -29
- package/src/utils/dom/getAvailableGroupSizePixels.ts +0 -29
|
@@ -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,41 +511,48 @@ function calculateAriaValues({
|
|
|
501
511
|
};
|
|
502
512
|
}
|
|
503
513
|
|
|
504
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
505
|
-
return Array.from(
|
|
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) {
|
|
509
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
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
|
}
|
|
513
523
|
|
|
514
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
515
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
524
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
525
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
516
526
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
517
527
|
}
|
|
518
528
|
|
|
519
|
-
function getPanelGroupElement(id) {
|
|
520
|
-
|
|
529
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
530
|
+
var _dataset;
|
|
531
|
+
//If the root element is the PanelGroup
|
|
532
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
533
|
+
return rootElement;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
//Else query children
|
|
537
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
521
538
|
if (element) {
|
|
522
539
|
return element;
|
|
523
540
|
}
|
|
524
541
|
return null;
|
|
525
542
|
}
|
|
526
543
|
|
|
527
|
-
function getResizeHandleElement(id) {
|
|
528
|
-
const element =
|
|
544
|
+
function getResizeHandleElement(id, scope = document) {
|
|
545
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
529
546
|
if (element) {
|
|
530
547
|
return element;
|
|
531
548
|
}
|
|
532
549
|
return null;
|
|
533
550
|
}
|
|
534
551
|
|
|
535
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
552
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
536
553
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
537
|
-
const handle = getResizeHandleElement(handleId);
|
|
538
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
554
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
555
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
539
556
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
540
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;
|
|
541
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;
|
|
@@ -550,13 +567,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
550
567
|
groupId,
|
|
551
568
|
layout,
|
|
552
569
|
panelDataArray,
|
|
570
|
+
panelGroupElement,
|
|
553
571
|
setLayout
|
|
554
572
|
}) {
|
|
555
573
|
const devWarningsRef = useRef({
|
|
556
574
|
didWarnAboutMissingResizeHandle: false
|
|
557
575
|
});
|
|
558
576
|
useIsomorphicLayoutEffect(() => {
|
|
559
|
-
|
|
577
|
+
if (!panelGroupElement) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
560
581
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
561
582
|
const {
|
|
562
583
|
valueMax,
|
|
@@ -595,21 +616,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
595
616
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
596
617
|
});
|
|
597
618
|
};
|
|
598
|
-
}, [groupId, layout, panelDataArray]);
|
|
619
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
599
620
|
useEffect(() => {
|
|
621
|
+
if (!panelGroupElement) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
600
624
|
const eagerValues = eagerValuesRef.current;
|
|
601
625
|
assert(eagerValues);
|
|
602
626
|
const {
|
|
603
627
|
panelDataArray
|
|
604
628
|
} = eagerValues;
|
|
605
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
629
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
606
630
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
607
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
631
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
608
632
|
assert(handles);
|
|
609
633
|
const cleanupFunctions = handles.map(handle => {
|
|
610
634
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
611
635
|
assert(handleId);
|
|
612
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
636
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
613
637
|
if (idBefore == null || idAfter == null) {
|
|
614
638
|
return () => {};
|
|
615
639
|
}
|
|
@@ -636,7 +660,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
636
660
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
637
661
|
layout,
|
|
638
662
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
639
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
663
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
640
664
|
trigger: "keyboard"
|
|
641
665
|
});
|
|
642
666
|
if (layout !== nextLayout) {
|
|
@@ -656,7 +680,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
656
680
|
return () => {
|
|
657
681
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
658
682
|
};
|
|
659
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
683
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
660
684
|
}
|
|
661
685
|
|
|
662
686
|
function areEqual(arrayA, arrayB) {
|
|
@@ -694,9 +718,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
694
718
|
}
|
|
695
719
|
}
|
|
696
720
|
|
|
697
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
721
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
698
722
|
const isHorizontal = direction === "horizontal";
|
|
699
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
723
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
700
724
|
assert(handleElement);
|
|
701
725
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
702
726
|
assert(groupId);
|
|
@@ -704,7 +728,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
704
728
|
initialCursorPosition
|
|
705
729
|
} = initialDragState;
|
|
706
730
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
707
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
731
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
708
732
|
assert(groupElement);
|
|
709
733
|
const groupRect = groupElement.getBoundingClientRect();
|
|
710
734
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -714,7 +738,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
714
738
|
}
|
|
715
739
|
|
|
716
740
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
717
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
741
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
718
742
|
if (isKeyDown(event)) {
|
|
719
743
|
const isHorizontal = direction === "horizontal";
|
|
720
744
|
let delta = 0;
|
|
@@ -751,7 +775,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
751
775
|
if (initialDragState == null) {
|
|
752
776
|
return 0;
|
|
753
777
|
}
|
|
754
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
778
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
755
779
|
}
|
|
756
780
|
}
|
|
757
781
|
|
|
@@ -1025,6 +1049,7 @@ function validatePanelConstraints({
|
|
|
1025
1049
|
assert(panelConstraints);
|
|
1026
1050
|
const {
|
|
1027
1051
|
collapsedSize = 0,
|
|
1052
|
+
collapsible = false,
|
|
1028
1053
|
defaultSize,
|
|
1029
1054
|
maxSize = 100,
|
|
1030
1055
|
minSize = 0
|
|
@@ -1035,7 +1060,7 @@ function validatePanelConstraints({
|
|
|
1035
1060
|
if (defaultSize != null) {
|
|
1036
1061
|
if (defaultSize < 0) {
|
|
1037
1062
|
warnings.push("default size should not be less than 0");
|
|
1038
|
-
} else if (defaultSize < minSize) {
|
|
1063
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
1039
1064
|
warnings.push("default size should not be less than min size");
|
|
1040
1065
|
}
|
|
1041
1066
|
if (defaultSize > 100) {
|
|
@@ -1150,6 +1175,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1150
1175
|
...rest
|
|
1151
1176
|
}) {
|
|
1152
1177
|
const groupId = useUniqueId(idFromProps);
|
|
1178
|
+
const panelGroupElementRef = useRef(null);
|
|
1153
1179
|
const [dragState, setDragState] = useState(null);
|
|
1154
1180
|
const [layout, setLayout] = useState([]);
|
|
1155
1181
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1218,7 +1244,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1218
1244
|
groupId,
|
|
1219
1245
|
layout,
|
|
1220
1246
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1221
|
-
setLayout
|
|
1247
|
+
setLayout,
|
|
1248
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1222
1249
|
});
|
|
1223
1250
|
useEffect(() => {
|
|
1224
1251
|
const {
|
|
@@ -1503,6 +1530,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1503
1530
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1504
1531
|
return function resizeHandler(event) {
|
|
1505
1532
|
event.preventDefault();
|
|
1533
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1534
|
+
if (!panelGroupElement) {
|
|
1535
|
+
return () => null;
|
|
1536
|
+
}
|
|
1506
1537
|
const {
|
|
1507
1538
|
direction,
|
|
1508
1539
|
dragState,
|
|
@@ -1517,8 +1548,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1517
1548
|
const {
|
|
1518
1549
|
initialLayout
|
|
1519
1550
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1520
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1521
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1551
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1552
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1522
1553
|
if (delta === 0) {
|
|
1523
1554
|
return;
|
|
1524
1555
|
}
|
|
@@ -1606,6 +1637,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1606
1637
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1607
1638
|
}
|
|
1608
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]);
|
|
1609
1671
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1610
1672
|
const {
|
|
1611
1673
|
direction
|
|
@@ -1613,7 +1675,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1613
1675
|
const {
|
|
1614
1676
|
layout
|
|
1615
1677
|
} = eagerValuesRef.current;
|
|
1616
|
-
|
|
1678
|
+
if (!panelGroupElementRef.current) {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1617
1682
|
assert(handleElement);
|
|
1618
1683
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1619
1684
|
setDragState({
|
|
@@ -1653,13 +1718,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1653
1718
|
groupId,
|
|
1654
1719
|
isPanelCollapsed,
|
|
1655
1720
|
isPanelExpanded,
|
|
1721
|
+
reevaluatePanelConstraints,
|
|
1656
1722
|
registerPanel,
|
|
1657
1723
|
registerResizeHandle,
|
|
1658
1724
|
resizePanel,
|
|
1659
1725
|
startDragging,
|
|
1660
1726
|
stopDragging,
|
|
1661
|
-
unregisterPanel
|
|
1662
|
-
|
|
1727
|
+
unregisterPanel,
|
|
1728
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1729
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1663
1730
|
const style = {
|
|
1664
1731
|
display: "flex",
|
|
1665
1732
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1677,6 +1744,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1677
1744
|
...style,
|
|
1678
1745
|
...styleFromProps
|
|
1679
1746
|
},
|
|
1747
|
+
ref: panelGroupElementRef,
|
|
1680
1748
|
// CSS selectors
|
|
1681
1749
|
"data-panel-group": "",
|
|
1682
1750
|
"data-panel-group-direction": direction,
|
|
@@ -1693,14 +1761,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1693
1761
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1694
1762
|
}
|
|
1695
1763
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1696
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1697
1764
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1698
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1699
1765
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1700
1766
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1701
1767
|
const panelSize = layout[panelIndex];
|
|
1702
1768
|
return {
|
|
1703
|
-
...
|
|
1769
|
+
...panelData.constraints,
|
|
1704
1770
|
panelSize,
|
|
1705
1771
|
pivotIndices
|
|
1706
1772
|
};
|
|
@@ -1711,13 +1777,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1711
1777
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1712
1778
|
disabled,
|
|
1713
1779
|
handleId,
|
|
1714
|
-
resizeHandler
|
|
1780
|
+
resizeHandler,
|
|
1781
|
+
panelGroupElement
|
|
1715
1782
|
}) {
|
|
1716
1783
|
useEffect(() => {
|
|
1717
|
-
if (disabled || resizeHandler == null) {
|
|
1784
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1718
1785
|
return;
|
|
1719
1786
|
}
|
|
1720
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1787
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1721
1788
|
if (handleElement == null) {
|
|
1722
1789
|
return;
|
|
1723
1790
|
}
|
|
@@ -1742,8 +1809,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1742
1809
|
event.preventDefault();
|
|
1743
1810
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1744
1811
|
assert(groupId);
|
|
1745
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1746
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1812
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1813
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1747
1814
|
assert(index !== null);
|
|
1748
1815
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1749
1816
|
const nextHandle = handles[nextIndex];
|
|
@@ -1756,7 +1823,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1756
1823
|
return () => {
|
|
1757
1824
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1758
1825
|
};
|
|
1759
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1826
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1760
1827
|
}
|
|
1761
1828
|
|
|
1762
1829
|
function PanelResizeHandle({
|
|
@@ -1789,7 +1856,8 @@ function PanelResizeHandle({
|
|
|
1789
1856
|
groupId,
|
|
1790
1857
|
registerResizeHandle,
|
|
1791
1858
|
startDragging,
|
|
1792
|
-
stopDragging
|
|
1859
|
+
stopDragging,
|
|
1860
|
+
panelGroupElement
|
|
1793
1861
|
} = panelGroupContext;
|
|
1794
1862
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1795
1863
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1848,7 +1916,8 @@ function PanelResizeHandle({
|
|
|
1848
1916
|
useWindowSplitterResizeHandlerBehavior({
|
|
1849
1917
|
disabled,
|
|
1850
1918
|
handleId: resizeHandleId,
|
|
1851
|
-
resizeHandler
|
|
1919
|
+
resizeHandler,
|
|
1920
|
+
panelGroupElement
|
|
1852
1921
|
});
|
|
1853
1922
|
const style = {
|
|
1854
1923
|
cursor: getCursorStyle(direction),
|
|
@@ -1904,52 +1973,16 @@ function PanelResizeHandle({
|
|
|
1904
1973
|
}
|
|
1905
1974
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1906
1975
|
|
|
1907
|
-
function
|
|
1908
|
-
const
|
|
1909
|
-
if (panelGroupElement == null) {
|
|
1910
|
-
return NaN;
|
|
1911
|
-
}
|
|
1912
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1913
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1914
|
-
if (direction === "horizontal") {
|
|
1915
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1916
|
-
return accumulated + handle.offsetWidth;
|
|
1917
|
-
}, 0);
|
|
1918
|
-
} else {
|
|
1919
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1920
|
-
return accumulated + handle.offsetHeight;
|
|
1921
|
-
}, 0);
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1926
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1927
|
-
if (panelGroupElement == null) {
|
|
1928
|
-
return NaN;
|
|
1929
|
-
}
|
|
1930
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1931
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1932
|
-
if (direction === "horizontal") {
|
|
1933
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1934
|
-
return accumulated + handle.offsetWidth;
|
|
1935
|
-
}, 0);
|
|
1936
|
-
} else {
|
|
1937
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1938
|
-
return accumulated + handle.offsetHeight;
|
|
1939
|
-
}, 0);
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
function getPanelElement(id) {
|
|
1944
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1976
|
+
function getPanelElement(id, scope = document) {
|
|
1977
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1945
1978
|
if (element) {
|
|
1946
1979
|
return element;
|
|
1947
1980
|
}
|
|
1948
1981
|
return null;
|
|
1949
1982
|
}
|
|
1950
1983
|
|
|
1951
|
-
function getPanelElementsForGroup(groupId) {
|
|
1952
|
-
return Array.from(
|
|
1984
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1985
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1953
1986
|
}
|
|
1954
1987
|
|
|
1955
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1988
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|