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
|
@@ -93,6 +93,7 @@ function PanelWithForwardedRef({
|
|
|
93
93
|
getPanelStyle,
|
|
94
94
|
groupId,
|
|
95
95
|
isPanelCollapsed,
|
|
96
|
+
reevaluatePanelConstraints,
|
|
96
97
|
registerPanel,
|
|
97
98
|
resizePanel,
|
|
98
99
|
unregisterPanel
|
|
@@ -134,6 +135,9 @@ function PanelWithForwardedRef({
|
|
|
134
135
|
callbacks,
|
|
135
136
|
constraints
|
|
136
137
|
} = panelDataRef.current;
|
|
138
|
+
const prevConstraints = {
|
|
139
|
+
...constraints
|
|
140
|
+
};
|
|
137
141
|
panelDataRef.current.id = panelId;
|
|
138
142
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
139
143
|
panelDataRef.current.order = order;
|
|
@@ -145,6 +149,12 @@ function PanelWithForwardedRef({
|
|
|
145
149
|
constraints.defaultSize = defaultSize;
|
|
146
150
|
constraints.maxSize = maxSize;
|
|
147
151
|
constraints.minSize = minSize;
|
|
152
|
+
|
|
153
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
154
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
155
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
156
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
157
|
+
}
|
|
148
158
|
});
|
|
149
159
|
useIsomorphicLayoutEffect(() => {
|
|
150
160
|
const panelData = panelDataRef.current;
|
|
@@ -532,41 +542,48 @@ function calculateAriaValues({
|
|
|
532
542
|
};
|
|
533
543
|
}
|
|
534
544
|
|
|
535
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
536
|
-
return Array.from(
|
|
545
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
546
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
537
547
|
}
|
|
538
548
|
|
|
539
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
540
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
549
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
550
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
541
551
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
542
552
|
return index !== null && index !== void 0 ? index : null;
|
|
543
553
|
}
|
|
544
554
|
|
|
545
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
546
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
555
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
556
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
547
557
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
548
558
|
}
|
|
549
559
|
|
|
550
|
-
function getPanelGroupElement(id) {
|
|
551
|
-
|
|
560
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
561
|
+
var _dataset;
|
|
562
|
+
//If the root element is the PanelGroup
|
|
563
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
564
|
+
return rootElement;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
//Else query children
|
|
568
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
552
569
|
if (element) {
|
|
553
570
|
return element;
|
|
554
571
|
}
|
|
555
572
|
return null;
|
|
556
573
|
}
|
|
557
574
|
|
|
558
|
-
function getResizeHandleElement(id) {
|
|
559
|
-
const element =
|
|
575
|
+
function getResizeHandleElement(id, scope = document) {
|
|
576
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
560
577
|
if (element) {
|
|
561
578
|
return element;
|
|
562
579
|
}
|
|
563
580
|
return null;
|
|
564
581
|
}
|
|
565
582
|
|
|
566
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
583
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
567
584
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
568
|
-
const handle = getResizeHandleElement(handleId);
|
|
569
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
585
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
586
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
570
587
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
571
588
|
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;
|
|
572
589
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -581,13 +598,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
581
598
|
groupId,
|
|
582
599
|
layout,
|
|
583
600
|
panelDataArray,
|
|
601
|
+
panelGroupElement,
|
|
584
602
|
setLayout
|
|
585
603
|
}) {
|
|
586
604
|
const devWarningsRef = useRef({
|
|
587
605
|
didWarnAboutMissingResizeHandle: false
|
|
588
606
|
});
|
|
589
607
|
useIsomorphicLayoutEffect(() => {
|
|
590
|
-
|
|
608
|
+
if (!panelGroupElement) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
591
612
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
592
613
|
const {
|
|
593
614
|
valueMax,
|
|
@@ -626,21 +647,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
626
647
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
627
648
|
});
|
|
628
649
|
};
|
|
629
|
-
}, [groupId, layout, panelDataArray]);
|
|
650
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
630
651
|
useEffect(() => {
|
|
652
|
+
if (!panelGroupElement) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
631
655
|
const eagerValues = eagerValuesRef.current;
|
|
632
656
|
assert(eagerValues);
|
|
633
657
|
const {
|
|
634
658
|
panelDataArray
|
|
635
659
|
} = eagerValues;
|
|
636
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
660
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
637
661
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
638
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
662
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
639
663
|
assert(handles);
|
|
640
664
|
const cleanupFunctions = handles.map(handle => {
|
|
641
665
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
642
666
|
assert(handleId);
|
|
643
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
667
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
644
668
|
if (idBefore == null || idAfter == null) {
|
|
645
669
|
return () => {};
|
|
646
670
|
}
|
|
@@ -667,7 +691,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
667
691
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
668
692
|
layout,
|
|
669
693
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
670
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
694
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
671
695
|
trigger: "keyboard"
|
|
672
696
|
});
|
|
673
697
|
if (layout !== nextLayout) {
|
|
@@ -687,7 +711,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
687
711
|
return () => {
|
|
688
712
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
689
713
|
};
|
|
690
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
714
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
691
715
|
}
|
|
692
716
|
|
|
693
717
|
function areEqual(arrayA, arrayB) {
|
|
@@ -725,9 +749,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
725
749
|
}
|
|
726
750
|
}
|
|
727
751
|
|
|
728
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
752
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
729
753
|
const isHorizontal = direction === "horizontal";
|
|
730
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
754
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
731
755
|
assert(handleElement);
|
|
732
756
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
733
757
|
assert(groupId);
|
|
@@ -735,7 +759,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
735
759
|
initialCursorPosition
|
|
736
760
|
} = initialDragState;
|
|
737
761
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
738
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
762
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
739
763
|
assert(groupElement);
|
|
740
764
|
const groupRect = groupElement.getBoundingClientRect();
|
|
741
765
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -745,7 +769,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
745
769
|
}
|
|
746
770
|
|
|
747
771
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
748
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
772
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
749
773
|
if (isKeyDown(event)) {
|
|
750
774
|
const isHorizontal = direction === "horizontal";
|
|
751
775
|
let delta = 0;
|
|
@@ -782,7 +806,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
782
806
|
if (initialDragState == null) {
|
|
783
807
|
return 0;
|
|
784
808
|
}
|
|
785
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
809
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
786
810
|
}
|
|
787
811
|
}
|
|
788
812
|
|
|
@@ -1056,6 +1080,7 @@ function validatePanelConstraints({
|
|
|
1056
1080
|
assert(panelConstraints);
|
|
1057
1081
|
const {
|
|
1058
1082
|
collapsedSize = 0,
|
|
1083
|
+
collapsible = false,
|
|
1059
1084
|
defaultSize,
|
|
1060
1085
|
maxSize = 100,
|
|
1061
1086
|
minSize = 0
|
|
@@ -1066,7 +1091,7 @@ function validatePanelConstraints({
|
|
|
1066
1091
|
if (defaultSize != null) {
|
|
1067
1092
|
if (defaultSize < 0) {
|
|
1068
1093
|
warnings.push("default size should not be less than 0");
|
|
1069
|
-
} else if (defaultSize < minSize) {
|
|
1094
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
1070
1095
|
warnings.push("default size should not be less than min size");
|
|
1071
1096
|
}
|
|
1072
1097
|
if (defaultSize > 100) {
|
|
@@ -1181,6 +1206,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1181
1206
|
...rest
|
|
1182
1207
|
}) {
|
|
1183
1208
|
const groupId = useUniqueId(idFromProps);
|
|
1209
|
+
const panelGroupElementRef = useRef(null);
|
|
1184
1210
|
const [dragState, setDragState] = useState(null);
|
|
1185
1211
|
const [layout, setLayout] = useState([]);
|
|
1186
1212
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1249,7 +1275,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1249
1275
|
groupId,
|
|
1250
1276
|
layout,
|
|
1251
1277
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1252
|
-
setLayout
|
|
1278
|
+
setLayout,
|
|
1279
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1253
1280
|
});
|
|
1254
1281
|
useEffect(() => {
|
|
1255
1282
|
const {
|
|
@@ -1534,6 +1561,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1534
1561
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1535
1562
|
return function resizeHandler(event) {
|
|
1536
1563
|
event.preventDefault();
|
|
1564
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1565
|
+
if (!panelGroupElement) {
|
|
1566
|
+
return () => null;
|
|
1567
|
+
}
|
|
1537
1568
|
const {
|
|
1538
1569
|
direction,
|
|
1539
1570
|
dragState,
|
|
@@ -1548,8 +1579,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1548
1579
|
const {
|
|
1549
1580
|
initialLayout
|
|
1550
1581
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1551
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1552
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1582
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1583
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1553
1584
|
if (delta === 0) {
|
|
1554
1585
|
return;
|
|
1555
1586
|
}
|
|
@@ -1637,6 +1668,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1637
1668
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1638
1669
|
}
|
|
1639
1670
|
}, []);
|
|
1671
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1672
|
+
const {
|
|
1673
|
+
layout,
|
|
1674
|
+
panelDataArray
|
|
1675
|
+
} = eagerValuesRef.current;
|
|
1676
|
+
const {
|
|
1677
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1678
|
+
collapsible: prevCollapsible,
|
|
1679
|
+
defaultSize: prevDefaultSize,
|
|
1680
|
+
maxSize: prevMaxSize = 100,
|
|
1681
|
+
minSize: prevMinSize = 0
|
|
1682
|
+
} = prevConstraints;
|
|
1683
|
+
const {
|
|
1684
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1685
|
+
collapsible: nextCollapsible,
|
|
1686
|
+
defaultSize: nextDefaultSize,
|
|
1687
|
+
maxSize: nextMaxSize = 100,
|
|
1688
|
+
minSize: nextMinSize = 0
|
|
1689
|
+
} = panelData.constraints;
|
|
1690
|
+
const {
|
|
1691
|
+
panelSize: prevPanelSize
|
|
1692
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1693
|
+
assert(prevPanelSize != null);
|
|
1694
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1695
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1696
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1697
|
+
resizePanel(panelData, nextMinSize);
|
|
1698
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1699
|
+
resizePanel(panelData, nextMaxSize);
|
|
1700
|
+
}
|
|
1701
|
+
}, [resizePanel]);
|
|
1640
1702
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1641
1703
|
const {
|
|
1642
1704
|
direction
|
|
@@ -1644,7 +1706,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1644
1706
|
const {
|
|
1645
1707
|
layout
|
|
1646
1708
|
} = eagerValuesRef.current;
|
|
1647
|
-
|
|
1709
|
+
if (!panelGroupElementRef.current) {
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1648
1713
|
assert(handleElement);
|
|
1649
1714
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1650
1715
|
setDragState({
|
|
@@ -1684,13 +1749,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1684
1749
|
groupId,
|
|
1685
1750
|
isPanelCollapsed,
|
|
1686
1751
|
isPanelExpanded,
|
|
1752
|
+
reevaluatePanelConstraints,
|
|
1687
1753
|
registerPanel,
|
|
1688
1754
|
registerResizeHandle,
|
|
1689
1755
|
resizePanel,
|
|
1690
1756
|
startDragging,
|
|
1691
1757
|
stopDragging,
|
|
1692
|
-
unregisterPanel
|
|
1693
|
-
|
|
1758
|
+
unregisterPanel,
|
|
1759
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1760
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1694
1761
|
const style = {
|
|
1695
1762
|
display: "flex",
|
|
1696
1763
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1708,6 +1775,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1708
1775
|
...style,
|
|
1709
1776
|
...styleFromProps
|
|
1710
1777
|
},
|
|
1778
|
+
ref: panelGroupElementRef,
|
|
1711
1779
|
// CSS selectors
|
|
1712
1780
|
"data-panel-group": "",
|
|
1713
1781
|
"data-panel-group-direction": direction,
|
|
@@ -1724,14 +1792,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1724
1792
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1725
1793
|
}
|
|
1726
1794
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1727
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1728
1795
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1729
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1730
1796
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1731
1797
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1732
1798
|
const panelSize = layout[panelIndex];
|
|
1733
1799
|
return {
|
|
1734
|
-
...
|
|
1800
|
+
...panelData.constraints,
|
|
1735
1801
|
panelSize,
|
|
1736
1802
|
pivotIndices
|
|
1737
1803
|
};
|
|
@@ -1742,13 +1808,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1742
1808
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1743
1809
|
disabled,
|
|
1744
1810
|
handleId,
|
|
1745
|
-
resizeHandler
|
|
1811
|
+
resizeHandler,
|
|
1812
|
+
panelGroupElement
|
|
1746
1813
|
}) {
|
|
1747
1814
|
useEffect(() => {
|
|
1748
|
-
if (disabled || resizeHandler == null) {
|
|
1815
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1749
1816
|
return;
|
|
1750
1817
|
}
|
|
1751
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1818
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1752
1819
|
if (handleElement == null) {
|
|
1753
1820
|
return;
|
|
1754
1821
|
}
|
|
@@ -1773,8 +1840,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1773
1840
|
event.preventDefault();
|
|
1774
1841
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1775
1842
|
assert(groupId);
|
|
1776
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1777
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1843
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1844
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1778
1845
|
assert(index !== null);
|
|
1779
1846
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1780
1847
|
const nextHandle = handles[nextIndex];
|
|
@@ -1787,7 +1854,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1787
1854
|
return () => {
|
|
1788
1855
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1789
1856
|
};
|
|
1790
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1857
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1791
1858
|
}
|
|
1792
1859
|
|
|
1793
1860
|
function PanelResizeHandle({
|
|
@@ -1820,7 +1887,8 @@ function PanelResizeHandle({
|
|
|
1820
1887
|
groupId,
|
|
1821
1888
|
registerResizeHandle,
|
|
1822
1889
|
startDragging,
|
|
1823
|
-
stopDragging
|
|
1890
|
+
stopDragging,
|
|
1891
|
+
panelGroupElement
|
|
1824
1892
|
} = panelGroupContext;
|
|
1825
1893
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1826
1894
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1879,7 +1947,8 @@ function PanelResizeHandle({
|
|
|
1879
1947
|
useWindowSplitterResizeHandlerBehavior({
|
|
1880
1948
|
disabled,
|
|
1881
1949
|
handleId: resizeHandleId,
|
|
1882
|
-
resizeHandler
|
|
1950
|
+
resizeHandler,
|
|
1951
|
+
panelGroupElement
|
|
1883
1952
|
});
|
|
1884
1953
|
const style = {
|
|
1885
1954
|
cursor: getCursorStyle(direction),
|
|
@@ -1935,60 +2004,22 @@ function PanelResizeHandle({
|
|
|
1935
2004
|
}
|
|
1936
2005
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1937
2006
|
|
|
1938
|
-
function
|
|
1939
|
-
const
|
|
1940
|
-
if (panelGroupElement == null) {
|
|
1941
|
-
return NaN;
|
|
1942
|
-
}
|
|
1943
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1944
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1945
|
-
if (direction === "horizontal") {
|
|
1946
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1947
|
-
return accumulated + handle.offsetWidth;
|
|
1948
|
-
}, 0);
|
|
1949
|
-
} else {
|
|
1950
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1951
|
-
return accumulated + handle.offsetHeight;
|
|
1952
|
-
}, 0);
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1957
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1958
|
-
if (panelGroupElement == null) {
|
|
1959
|
-
return NaN;
|
|
1960
|
-
}
|
|
1961
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1962
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1963
|
-
if (direction === "horizontal") {
|
|
1964
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1965
|
-
return accumulated + handle.offsetWidth;
|
|
1966
|
-
}, 0);
|
|
1967
|
-
} else {
|
|
1968
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1969
|
-
return accumulated + handle.offsetHeight;
|
|
1970
|
-
}, 0);
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
function getPanelElement(id) {
|
|
1975
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
2007
|
+
function getPanelElement(id, scope = document) {
|
|
2008
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1976
2009
|
if (element) {
|
|
1977
2010
|
return element;
|
|
1978
2011
|
}
|
|
1979
2012
|
return null;
|
|
1980
2013
|
}
|
|
1981
2014
|
|
|
1982
|
-
function getPanelElementsForGroup(groupId) {
|
|
1983
|
-
return Array.from(
|
|
2015
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
2016
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1984
2017
|
}
|
|
1985
2018
|
|
|
1986
2019
|
exports.Panel = Panel;
|
|
1987
2020
|
exports.PanelGroup = PanelGroup;
|
|
1988
2021
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1989
2022
|
exports.assert = assert;
|
|
1990
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1991
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1992
2023
|
exports.getPanelElement = getPanelElement;
|
|
1993
2024
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1994
2025
|
exports.getPanelGroupElement = getPanelGroupElement;
|