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
|
@@ -91,6 +91,7 @@ function PanelWithForwardedRef({
|
|
|
91
91
|
getPanelStyle,
|
|
92
92
|
groupId,
|
|
93
93
|
isPanelCollapsed,
|
|
94
|
+
reevaluatePanelConstraints,
|
|
94
95
|
registerPanel,
|
|
95
96
|
resizePanel,
|
|
96
97
|
unregisterPanel
|
|
@@ -127,6 +128,9 @@ function PanelWithForwardedRef({
|
|
|
127
128
|
callbacks,
|
|
128
129
|
constraints
|
|
129
130
|
} = panelDataRef.current;
|
|
131
|
+
const prevConstraints = {
|
|
132
|
+
...constraints
|
|
133
|
+
};
|
|
130
134
|
panelDataRef.current.id = panelId;
|
|
131
135
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
132
136
|
panelDataRef.current.order = order;
|
|
@@ -138,6 +142,12 @@ function PanelWithForwardedRef({
|
|
|
138
142
|
constraints.defaultSize = defaultSize;
|
|
139
143
|
constraints.maxSize = maxSize;
|
|
140
144
|
constraints.minSize = minSize;
|
|
145
|
+
|
|
146
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
147
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
148
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
149
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
150
|
+
}
|
|
141
151
|
});
|
|
142
152
|
useIsomorphicLayoutEffect(() => {
|
|
143
153
|
const panelData = panelDataRef.current;
|
|
@@ -525,41 +535,48 @@ function calculateAriaValues({
|
|
|
525
535
|
};
|
|
526
536
|
}
|
|
527
537
|
|
|
528
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
529
|
-
return Array.from(
|
|
538
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
539
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
530
540
|
}
|
|
531
541
|
|
|
532
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
533
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
542
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
543
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
534
544
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
535
545
|
return index !== null && index !== void 0 ? index : null;
|
|
536
546
|
}
|
|
537
547
|
|
|
538
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
539
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
548
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
549
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
540
550
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
541
551
|
}
|
|
542
552
|
|
|
543
|
-
function getPanelGroupElement(id) {
|
|
544
|
-
|
|
553
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
554
|
+
var _dataset;
|
|
555
|
+
//If the root element is the PanelGroup
|
|
556
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
557
|
+
return rootElement;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
//Else query children
|
|
561
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
545
562
|
if (element) {
|
|
546
563
|
return element;
|
|
547
564
|
}
|
|
548
565
|
return null;
|
|
549
566
|
}
|
|
550
567
|
|
|
551
|
-
function getResizeHandleElement(id) {
|
|
552
|
-
const element =
|
|
568
|
+
function getResizeHandleElement(id, scope = document) {
|
|
569
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
553
570
|
if (element) {
|
|
554
571
|
return element;
|
|
555
572
|
}
|
|
556
573
|
return null;
|
|
557
574
|
}
|
|
558
575
|
|
|
559
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
576
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
560
577
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
561
|
-
const handle = getResizeHandleElement(handleId);
|
|
562
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
578
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
579
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
563
580
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
564
581
|
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;
|
|
565
582
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -574,13 +591,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
574
591
|
groupId,
|
|
575
592
|
layout,
|
|
576
593
|
panelDataArray,
|
|
594
|
+
panelGroupElement,
|
|
577
595
|
setLayout
|
|
578
596
|
}) {
|
|
579
597
|
const devWarningsRef = useRef({
|
|
580
598
|
didWarnAboutMissingResizeHandle: false
|
|
581
599
|
});
|
|
582
600
|
useIsomorphicLayoutEffect(() => {
|
|
583
|
-
|
|
601
|
+
if (!panelGroupElement) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
584
605
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
585
606
|
const {
|
|
586
607
|
valueMax,
|
|
@@ -619,21 +640,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
619
640
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
620
641
|
});
|
|
621
642
|
};
|
|
622
|
-
}, [groupId, layout, panelDataArray]);
|
|
643
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
623
644
|
useEffect(() => {
|
|
645
|
+
if (!panelGroupElement) {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
624
648
|
const eagerValues = eagerValuesRef.current;
|
|
625
649
|
assert(eagerValues);
|
|
626
650
|
const {
|
|
627
651
|
panelDataArray
|
|
628
652
|
} = eagerValues;
|
|
629
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
653
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
630
654
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
631
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
655
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
632
656
|
assert(handles);
|
|
633
657
|
const cleanupFunctions = handles.map(handle => {
|
|
634
658
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
635
659
|
assert(handleId);
|
|
636
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
660
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
637
661
|
if (idBefore == null || idAfter == null) {
|
|
638
662
|
return () => {};
|
|
639
663
|
}
|
|
@@ -660,7 +684,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
660
684
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
661
685
|
layout,
|
|
662
686
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
663
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
687
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
664
688
|
trigger: "keyboard"
|
|
665
689
|
});
|
|
666
690
|
if (layout !== nextLayout) {
|
|
@@ -680,7 +704,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
680
704
|
return () => {
|
|
681
705
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
682
706
|
};
|
|
683
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
707
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
684
708
|
}
|
|
685
709
|
|
|
686
710
|
function areEqual(arrayA, arrayB) {
|
|
@@ -718,9 +742,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
718
742
|
}
|
|
719
743
|
}
|
|
720
744
|
|
|
721
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
745
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
722
746
|
const isHorizontal = direction === "horizontal";
|
|
723
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
747
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
724
748
|
assert(handleElement);
|
|
725
749
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
726
750
|
assert(groupId);
|
|
@@ -728,7 +752,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
728
752
|
initialCursorPosition
|
|
729
753
|
} = initialDragState;
|
|
730
754
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
731
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
755
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
732
756
|
assert(groupElement);
|
|
733
757
|
const groupRect = groupElement.getBoundingClientRect();
|
|
734
758
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -738,7 +762,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
738
762
|
}
|
|
739
763
|
|
|
740
764
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
741
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
765
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
742
766
|
if (isKeyDown(event)) {
|
|
743
767
|
const isHorizontal = direction === "horizontal";
|
|
744
768
|
let delta = 0;
|
|
@@ -775,7 +799,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
775
799
|
if (initialDragState == null) {
|
|
776
800
|
return 0;
|
|
777
801
|
}
|
|
778
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
802
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
779
803
|
}
|
|
780
804
|
}
|
|
781
805
|
|
|
@@ -1049,6 +1073,7 @@ function validatePanelConstraints({
|
|
|
1049
1073
|
assert(panelConstraints);
|
|
1050
1074
|
const {
|
|
1051
1075
|
collapsedSize = 0,
|
|
1076
|
+
collapsible = false,
|
|
1052
1077
|
defaultSize,
|
|
1053
1078
|
maxSize = 100,
|
|
1054
1079
|
minSize = 0
|
|
@@ -1059,7 +1084,7 @@ function validatePanelConstraints({
|
|
|
1059
1084
|
if (defaultSize != null) {
|
|
1060
1085
|
if (defaultSize < 0) {
|
|
1061
1086
|
warnings.push("default size should not be less than 0");
|
|
1062
|
-
} else if (defaultSize < minSize) {
|
|
1087
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
1063
1088
|
warnings.push("default size should not be less than min size");
|
|
1064
1089
|
}
|
|
1065
1090
|
if (defaultSize > 100) {
|
|
@@ -1174,6 +1199,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1174
1199
|
...rest
|
|
1175
1200
|
}) {
|
|
1176
1201
|
const groupId = useUniqueId(idFromProps);
|
|
1202
|
+
const panelGroupElementRef = useRef(null);
|
|
1177
1203
|
const [dragState, setDragState] = useState(null);
|
|
1178
1204
|
const [layout, setLayout] = useState([]);
|
|
1179
1205
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1242,7 +1268,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1242
1268
|
groupId,
|
|
1243
1269
|
layout,
|
|
1244
1270
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1245
|
-
setLayout
|
|
1271
|
+
setLayout,
|
|
1272
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1246
1273
|
});
|
|
1247
1274
|
useEffect(() => {
|
|
1248
1275
|
const {
|
|
@@ -1527,6 +1554,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1527
1554
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1528
1555
|
return function resizeHandler(event) {
|
|
1529
1556
|
event.preventDefault();
|
|
1557
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1558
|
+
if (!panelGroupElement) {
|
|
1559
|
+
return () => null;
|
|
1560
|
+
}
|
|
1530
1561
|
const {
|
|
1531
1562
|
direction,
|
|
1532
1563
|
dragState,
|
|
@@ -1541,8 +1572,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1541
1572
|
const {
|
|
1542
1573
|
initialLayout
|
|
1543
1574
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1544
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1545
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1575
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1576
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1546
1577
|
if (delta === 0) {
|
|
1547
1578
|
return;
|
|
1548
1579
|
}
|
|
@@ -1630,6 +1661,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1630
1661
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1631
1662
|
}
|
|
1632
1663
|
}, []);
|
|
1664
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1665
|
+
const {
|
|
1666
|
+
layout,
|
|
1667
|
+
panelDataArray
|
|
1668
|
+
} = eagerValuesRef.current;
|
|
1669
|
+
const {
|
|
1670
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1671
|
+
collapsible: prevCollapsible,
|
|
1672
|
+
defaultSize: prevDefaultSize,
|
|
1673
|
+
maxSize: prevMaxSize = 100,
|
|
1674
|
+
minSize: prevMinSize = 0
|
|
1675
|
+
} = prevConstraints;
|
|
1676
|
+
const {
|
|
1677
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1678
|
+
collapsible: nextCollapsible,
|
|
1679
|
+
defaultSize: nextDefaultSize,
|
|
1680
|
+
maxSize: nextMaxSize = 100,
|
|
1681
|
+
minSize: nextMinSize = 0
|
|
1682
|
+
} = panelData.constraints;
|
|
1683
|
+
const {
|
|
1684
|
+
panelSize: prevPanelSize
|
|
1685
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1686
|
+
assert(prevPanelSize != null);
|
|
1687
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1688
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1689
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1690
|
+
resizePanel(panelData, nextMinSize);
|
|
1691
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1692
|
+
resizePanel(panelData, nextMaxSize);
|
|
1693
|
+
}
|
|
1694
|
+
}, [resizePanel]);
|
|
1633
1695
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1634
1696
|
const {
|
|
1635
1697
|
direction
|
|
@@ -1637,7 +1699,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1637
1699
|
const {
|
|
1638
1700
|
layout
|
|
1639
1701
|
} = eagerValuesRef.current;
|
|
1640
|
-
|
|
1702
|
+
if (!panelGroupElementRef.current) {
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1641
1706
|
assert(handleElement);
|
|
1642
1707
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1643
1708
|
setDragState({
|
|
@@ -1677,13 +1742,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1677
1742
|
groupId,
|
|
1678
1743
|
isPanelCollapsed,
|
|
1679
1744
|
isPanelExpanded,
|
|
1745
|
+
reevaluatePanelConstraints,
|
|
1680
1746
|
registerPanel,
|
|
1681
1747
|
registerResizeHandle,
|
|
1682
1748
|
resizePanel,
|
|
1683
1749
|
startDragging,
|
|
1684
1750
|
stopDragging,
|
|
1685
|
-
unregisterPanel
|
|
1686
|
-
|
|
1751
|
+
unregisterPanel,
|
|
1752
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1753
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1687
1754
|
const style = {
|
|
1688
1755
|
display: "flex",
|
|
1689
1756
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1701,6 +1768,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1701
1768
|
...style,
|
|
1702
1769
|
...styleFromProps
|
|
1703
1770
|
},
|
|
1771
|
+
ref: panelGroupElementRef,
|
|
1704
1772
|
// CSS selectors
|
|
1705
1773
|
"data-panel-group": "",
|
|
1706
1774
|
"data-panel-group-direction": direction,
|
|
@@ -1717,14 +1785,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1717
1785
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1718
1786
|
}
|
|
1719
1787
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1720
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1721
1788
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1722
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1723
1789
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1724
1790
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1725
1791
|
const panelSize = layout[panelIndex];
|
|
1726
1792
|
return {
|
|
1727
|
-
...
|
|
1793
|
+
...panelData.constraints,
|
|
1728
1794
|
panelSize,
|
|
1729
1795
|
pivotIndices
|
|
1730
1796
|
};
|
|
@@ -1735,13 +1801,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1735
1801
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1736
1802
|
disabled,
|
|
1737
1803
|
handleId,
|
|
1738
|
-
resizeHandler
|
|
1804
|
+
resizeHandler,
|
|
1805
|
+
panelGroupElement
|
|
1739
1806
|
}) {
|
|
1740
1807
|
useEffect(() => {
|
|
1741
|
-
if (disabled || resizeHandler == null) {
|
|
1808
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1742
1809
|
return;
|
|
1743
1810
|
}
|
|
1744
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1811
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1745
1812
|
if (handleElement == null) {
|
|
1746
1813
|
return;
|
|
1747
1814
|
}
|
|
@@ -1766,8 +1833,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1766
1833
|
event.preventDefault();
|
|
1767
1834
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1768
1835
|
assert(groupId);
|
|
1769
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1770
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1836
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1837
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1771
1838
|
assert(index !== null);
|
|
1772
1839
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1773
1840
|
const nextHandle = handles[nextIndex];
|
|
@@ -1780,7 +1847,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1780
1847
|
return () => {
|
|
1781
1848
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1782
1849
|
};
|
|
1783
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1850
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1784
1851
|
}
|
|
1785
1852
|
|
|
1786
1853
|
function PanelResizeHandle({
|
|
@@ -1813,7 +1880,8 @@ function PanelResizeHandle({
|
|
|
1813
1880
|
groupId,
|
|
1814
1881
|
registerResizeHandle,
|
|
1815
1882
|
startDragging,
|
|
1816
|
-
stopDragging
|
|
1883
|
+
stopDragging,
|
|
1884
|
+
panelGroupElement
|
|
1817
1885
|
} = panelGroupContext;
|
|
1818
1886
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1819
1887
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1872,7 +1940,8 @@ function PanelResizeHandle({
|
|
|
1872
1940
|
useWindowSplitterResizeHandlerBehavior({
|
|
1873
1941
|
disabled,
|
|
1874
1942
|
handleId: resizeHandleId,
|
|
1875
|
-
resizeHandler
|
|
1943
|
+
resizeHandler,
|
|
1944
|
+
panelGroupElement
|
|
1876
1945
|
});
|
|
1877
1946
|
const style = {
|
|
1878
1947
|
cursor: getCursorStyle(direction),
|
|
@@ -1928,60 +1997,22 @@ function PanelResizeHandle({
|
|
|
1928
1997
|
}
|
|
1929
1998
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1930
1999
|
|
|
1931
|
-
function
|
|
1932
|
-
const
|
|
1933
|
-
if (panelGroupElement == null) {
|
|
1934
|
-
return NaN;
|
|
1935
|
-
}
|
|
1936
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1937
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1938
|
-
if (direction === "horizontal") {
|
|
1939
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1940
|
-
return accumulated + handle.offsetWidth;
|
|
1941
|
-
}, 0);
|
|
1942
|
-
} else {
|
|
1943
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1944
|
-
return accumulated + handle.offsetHeight;
|
|
1945
|
-
}, 0);
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1950
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1951
|
-
if (panelGroupElement == null) {
|
|
1952
|
-
return NaN;
|
|
1953
|
-
}
|
|
1954
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1955
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
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) {
|
|
1968
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
2000
|
+
function getPanelElement(id, scope = document) {
|
|
2001
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1969
2002
|
if (element) {
|
|
1970
2003
|
return element;
|
|
1971
2004
|
}
|
|
1972
2005
|
return null;
|
|
1973
2006
|
}
|
|
1974
2007
|
|
|
1975
|
-
function getPanelElementsForGroup(groupId) {
|
|
1976
|
-
return Array.from(
|
|
2008
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
2009
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1977
2010
|
}
|
|
1978
2011
|
|
|
1979
2012
|
exports.Panel = Panel;
|
|
1980
2013
|
exports.PanelGroup = PanelGroup;
|
|
1981
2014
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1982
2015
|
exports.assert = assert;
|
|
1983
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1984
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1985
2016
|
exports.getPanelElement = getPanelElement;
|
|
1986
2017
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1987
2018
|
exports.getPanelGroupElement = getPanelGroupElement;
|