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
|
@@ -69,6 +69,7 @@ function PanelWithForwardedRef({
|
|
|
69
69
|
getPanelStyle,
|
|
70
70
|
groupId,
|
|
71
71
|
isPanelCollapsed,
|
|
72
|
+
reevaluatePanelConstraints,
|
|
72
73
|
registerPanel,
|
|
73
74
|
resizePanel,
|
|
74
75
|
unregisterPanel
|
|
@@ -110,6 +111,9 @@ function PanelWithForwardedRef({
|
|
|
110
111
|
callbacks,
|
|
111
112
|
constraints
|
|
112
113
|
} = panelDataRef.current;
|
|
114
|
+
const prevConstraints = {
|
|
115
|
+
...constraints
|
|
116
|
+
};
|
|
113
117
|
panelDataRef.current.id = panelId;
|
|
114
118
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
115
119
|
panelDataRef.current.order = order;
|
|
@@ -121,6 +125,12 @@ function PanelWithForwardedRef({
|
|
|
121
125
|
constraints.defaultSize = defaultSize;
|
|
122
126
|
constraints.maxSize = maxSize;
|
|
123
127
|
constraints.minSize = minSize;
|
|
128
|
+
|
|
129
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
130
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
131
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
132
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
133
|
+
}
|
|
124
134
|
});
|
|
125
135
|
useIsomorphicLayoutEffect(() => {
|
|
126
136
|
const panelData = panelDataRef.current;
|
|
@@ -508,41 +518,48 @@ function calculateAriaValues({
|
|
|
508
518
|
};
|
|
509
519
|
}
|
|
510
520
|
|
|
511
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
512
|
-
return Array.from(
|
|
521
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
522
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
513
523
|
}
|
|
514
524
|
|
|
515
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
516
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
525
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
526
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
517
527
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
518
528
|
return index !== null && index !== void 0 ? index : null;
|
|
519
529
|
}
|
|
520
530
|
|
|
521
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
522
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
531
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
532
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
523
533
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
524
534
|
}
|
|
525
535
|
|
|
526
|
-
function getPanelGroupElement(id) {
|
|
527
|
-
|
|
536
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
537
|
+
var _dataset;
|
|
538
|
+
//If the root element is the PanelGroup
|
|
539
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
540
|
+
return rootElement;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
//Else query children
|
|
544
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
528
545
|
if (element) {
|
|
529
546
|
return element;
|
|
530
547
|
}
|
|
531
548
|
return null;
|
|
532
549
|
}
|
|
533
550
|
|
|
534
|
-
function getResizeHandleElement(id) {
|
|
535
|
-
const element =
|
|
551
|
+
function getResizeHandleElement(id, scope = document) {
|
|
552
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
536
553
|
if (element) {
|
|
537
554
|
return element;
|
|
538
555
|
}
|
|
539
556
|
return null;
|
|
540
557
|
}
|
|
541
558
|
|
|
542
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
559
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
543
560
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
544
|
-
const handle = getResizeHandleElement(handleId);
|
|
545
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
561
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
562
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
546
563
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
547
564
|
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
565
|
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 +574,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
557
574
|
groupId,
|
|
558
575
|
layout,
|
|
559
576
|
panelDataArray,
|
|
577
|
+
panelGroupElement,
|
|
560
578
|
setLayout
|
|
561
579
|
}) {
|
|
562
580
|
const devWarningsRef = useRef({
|
|
563
581
|
didWarnAboutMissingResizeHandle: false
|
|
564
582
|
});
|
|
565
583
|
useIsomorphicLayoutEffect(() => {
|
|
566
|
-
|
|
584
|
+
if (!panelGroupElement) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
567
588
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
568
589
|
const {
|
|
569
590
|
valueMax,
|
|
@@ -602,21 +623,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
602
623
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
603
624
|
});
|
|
604
625
|
};
|
|
605
|
-
}, [groupId, layout, panelDataArray]);
|
|
626
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
606
627
|
useEffect(() => {
|
|
628
|
+
if (!panelGroupElement) {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
607
631
|
const eagerValues = eagerValuesRef.current;
|
|
608
632
|
assert(eagerValues);
|
|
609
633
|
const {
|
|
610
634
|
panelDataArray
|
|
611
635
|
} = eagerValues;
|
|
612
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
636
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
613
637
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
614
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
638
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
615
639
|
assert(handles);
|
|
616
640
|
const cleanupFunctions = handles.map(handle => {
|
|
617
641
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
618
642
|
assert(handleId);
|
|
619
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
643
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
620
644
|
if (idBefore == null || idAfter == null) {
|
|
621
645
|
return () => {};
|
|
622
646
|
}
|
|
@@ -643,7 +667,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
643
667
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
644
668
|
layout,
|
|
645
669
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
646
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
670
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
647
671
|
trigger: "keyboard"
|
|
648
672
|
});
|
|
649
673
|
if (layout !== nextLayout) {
|
|
@@ -663,7 +687,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
663
687
|
return () => {
|
|
664
688
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
665
689
|
};
|
|
666
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
690
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
667
691
|
}
|
|
668
692
|
|
|
669
693
|
function areEqual(arrayA, arrayB) {
|
|
@@ -701,9 +725,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
701
725
|
}
|
|
702
726
|
}
|
|
703
727
|
|
|
704
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
728
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
705
729
|
const isHorizontal = direction === "horizontal";
|
|
706
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
730
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
707
731
|
assert(handleElement);
|
|
708
732
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
709
733
|
assert(groupId);
|
|
@@ -711,7 +735,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
711
735
|
initialCursorPosition
|
|
712
736
|
} = initialDragState;
|
|
713
737
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
714
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
738
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
715
739
|
assert(groupElement);
|
|
716
740
|
const groupRect = groupElement.getBoundingClientRect();
|
|
717
741
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -721,7 +745,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
721
745
|
}
|
|
722
746
|
|
|
723
747
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
724
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
748
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
725
749
|
if (isKeyDown(event)) {
|
|
726
750
|
const isHorizontal = direction === "horizontal";
|
|
727
751
|
let delta = 0;
|
|
@@ -758,7 +782,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
758
782
|
if (initialDragState == null) {
|
|
759
783
|
return 0;
|
|
760
784
|
}
|
|
761
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
785
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
762
786
|
}
|
|
763
787
|
}
|
|
764
788
|
|
|
@@ -1032,6 +1056,7 @@ function validatePanelConstraints({
|
|
|
1032
1056
|
assert(panelConstraints);
|
|
1033
1057
|
const {
|
|
1034
1058
|
collapsedSize = 0,
|
|
1059
|
+
collapsible = false,
|
|
1035
1060
|
defaultSize,
|
|
1036
1061
|
maxSize = 100,
|
|
1037
1062
|
minSize = 0
|
|
@@ -1042,7 +1067,7 @@ function validatePanelConstraints({
|
|
|
1042
1067
|
if (defaultSize != null) {
|
|
1043
1068
|
if (defaultSize < 0) {
|
|
1044
1069
|
warnings.push("default size should not be less than 0");
|
|
1045
|
-
} else if (defaultSize < minSize) {
|
|
1070
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
1046
1071
|
warnings.push("default size should not be less than min size");
|
|
1047
1072
|
}
|
|
1048
1073
|
if (defaultSize > 100) {
|
|
@@ -1157,6 +1182,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1157
1182
|
...rest
|
|
1158
1183
|
}) {
|
|
1159
1184
|
const groupId = useUniqueId(idFromProps);
|
|
1185
|
+
const panelGroupElementRef = useRef(null);
|
|
1160
1186
|
const [dragState, setDragState] = useState(null);
|
|
1161
1187
|
const [layout, setLayout] = useState([]);
|
|
1162
1188
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1225,7 +1251,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1225
1251
|
groupId,
|
|
1226
1252
|
layout,
|
|
1227
1253
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1228
|
-
setLayout
|
|
1254
|
+
setLayout,
|
|
1255
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1229
1256
|
});
|
|
1230
1257
|
useEffect(() => {
|
|
1231
1258
|
const {
|
|
@@ -1510,6 +1537,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1510
1537
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1511
1538
|
return function resizeHandler(event) {
|
|
1512
1539
|
event.preventDefault();
|
|
1540
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1541
|
+
if (!panelGroupElement) {
|
|
1542
|
+
return () => null;
|
|
1543
|
+
}
|
|
1513
1544
|
const {
|
|
1514
1545
|
direction,
|
|
1515
1546
|
dragState,
|
|
@@ -1524,8 +1555,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1524
1555
|
const {
|
|
1525
1556
|
initialLayout
|
|
1526
1557
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1527
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1528
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1558
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1559
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1529
1560
|
if (delta === 0) {
|
|
1530
1561
|
return;
|
|
1531
1562
|
}
|
|
@@ -1613,6 +1644,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1613
1644
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1614
1645
|
}
|
|
1615
1646
|
}, []);
|
|
1647
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1648
|
+
const {
|
|
1649
|
+
layout,
|
|
1650
|
+
panelDataArray
|
|
1651
|
+
} = eagerValuesRef.current;
|
|
1652
|
+
const {
|
|
1653
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1654
|
+
collapsible: prevCollapsible,
|
|
1655
|
+
defaultSize: prevDefaultSize,
|
|
1656
|
+
maxSize: prevMaxSize = 100,
|
|
1657
|
+
minSize: prevMinSize = 0
|
|
1658
|
+
} = prevConstraints;
|
|
1659
|
+
const {
|
|
1660
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1661
|
+
collapsible: nextCollapsible,
|
|
1662
|
+
defaultSize: nextDefaultSize,
|
|
1663
|
+
maxSize: nextMaxSize = 100,
|
|
1664
|
+
minSize: nextMinSize = 0
|
|
1665
|
+
} = panelData.constraints;
|
|
1666
|
+
const {
|
|
1667
|
+
panelSize: prevPanelSize
|
|
1668
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1669
|
+
assert(prevPanelSize != null);
|
|
1670
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1671
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1672
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1673
|
+
resizePanel(panelData, nextMinSize);
|
|
1674
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1675
|
+
resizePanel(panelData, nextMaxSize);
|
|
1676
|
+
}
|
|
1677
|
+
}, [resizePanel]);
|
|
1616
1678
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1617
1679
|
const {
|
|
1618
1680
|
direction
|
|
@@ -1620,7 +1682,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1620
1682
|
const {
|
|
1621
1683
|
layout
|
|
1622
1684
|
} = eagerValuesRef.current;
|
|
1623
|
-
|
|
1685
|
+
if (!panelGroupElementRef.current) {
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1624
1689
|
assert(handleElement);
|
|
1625
1690
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1626
1691
|
setDragState({
|
|
@@ -1660,13 +1725,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1660
1725
|
groupId,
|
|
1661
1726
|
isPanelCollapsed,
|
|
1662
1727
|
isPanelExpanded,
|
|
1728
|
+
reevaluatePanelConstraints,
|
|
1663
1729
|
registerPanel,
|
|
1664
1730
|
registerResizeHandle,
|
|
1665
1731
|
resizePanel,
|
|
1666
1732
|
startDragging,
|
|
1667
1733
|
stopDragging,
|
|
1668
|
-
unregisterPanel
|
|
1669
|
-
|
|
1734
|
+
unregisterPanel,
|
|
1735
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1736
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1670
1737
|
const style = {
|
|
1671
1738
|
display: "flex",
|
|
1672
1739
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1684,6 +1751,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1684
1751
|
...style,
|
|
1685
1752
|
...styleFromProps
|
|
1686
1753
|
},
|
|
1754
|
+
ref: panelGroupElementRef,
|
|
1687
1755
|
// CSS selectors
|
|
1688
1756
|
"data-panel-group": "",
|
|
1689
1757
|
"data-panel-group-direction": direction,
|
|
@@ -1700,14 +1768,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1700
1768
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1701
1769
|
}
|
|
1702
1770
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1703
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1704
1771
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1705
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1706
1772
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1707
1773
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1708
1774
|
const panelSize = layout[panelIndex];
|
|
1709
1775
|
return {
|
|
1710
|
-
...
|
|
1776
|
+
...panelData.constraints,
|
|
1711
1777
|
panelSize,
|
|
1712
1778
|
pivotIndices
|
|
1713
1779
|
};
|
|
@@ -1718,13 +1784,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1718
1784
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1719
1785
|
disabled,
|
|
1720
1786
|
handleId,
|
|
1721
|
-
resizeHandler
|
|
1787
|
+
resizeHandler,
|
|
1788
|
+
panelGroupElement
|
|
1722
1789
|
}) {
|
|
1723
1790
|
useEffect(() => {
|
|
1724
|
-
if (disabled || resizeHandler == null) {
|
|
1791
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1725
1792
|
return;
|
|
1726
1793
|
}
|
|
1727
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1794
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1728
1795
|
if (handleElement == null) {
|
|
1729
1796
|
return;
|
|
1730
1797
|
}
|
|
@@ -1749,8 +1816,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1749
1816
|
event.preventDefault();
|
|
1750
1817
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1751
1818
|
assert(groupId);
|
|
1752
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1753
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1819
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1820
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1754
1821
|
assert(index !== null);
|
|
1755
1822
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1756
1823
|
const nextHandle = handles[nextIndex];
|
|
@@ -1763,7 +1830,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1763
1830
|
return () => {
|
|
1764
1831
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1765
1832
|
};
|
|
1766
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1833
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1767
1834
|
}
|
|
1768
1835
|
|
|
1769
1836
|
function PanelResizeHandle({
|
|
@@ -1796,7 +1863,8 @@ function PanelResizeHandle({
|
|
|
1796
1863
|
groupId,
|
|
1797
1864
|
registerResizeHandle,
|
|
1798
1865
|
startDragging,
|
|
1799
|
-
stopDragging
|
|
1866
|
+
stopDragging,
|
|
1867
|
+
panelGroupElement
|
|
1800
1868
|
} = panelGroupContext;
|
|
1801
1869
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1802
1870
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1855,7 +1923,8 @@ function PanelResizeHandle({
|
|
|
1855
1923
|
useWindowSplitterResizeHandlerBehavior({
|
|
1856
1924
|
disabled,
|
|
1857
1925
|
handleId: resizeHandleId,
|
|
1858
|
-
resizeHandler
|
|
1926
|
+
resizeHandler,
|
|
1927
|
+
panelGroupElement
|
|
1859
1928
|
});
|
|
1860
1929
|
const style = {
|
|
1861
1930
|
cursor: getCursorStyle(direction),
|
|
@@ -1911,52 +1980,16 @@ function PanelResizeHandle({
|
|
|
1911
1980
|
}
|
|
1912
1981
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1913
1982
|
|
|
1914
|
-
function
|
|
1915
|
-
const
|
|
1916
|
-
if (panelGroupElement == null) {
|
|
1917
|
-
return NaN;
|
|
1918
|
-
}
|
|
1919
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1920
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1921
|
-
if (direction === "horizontal") {
|
|
1922
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1923
|
-
return accumulated + handle.offsetWidth;
|
|
1924
|
-
}, 0);
|
|
1925
|
-
} else {
|
|
1926
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1927
|
-
return accumulated + handle.offsetHeight;
|
|
1928
|
-
}, 0);
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1933
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1934
|
-
if (panelGroupElement == null) {
|
|
1935
|
-
return NaN;
|
|
1936
|
-
}
|
|
1937
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1938
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1939
|
-
if (direction === "horizontal") {
|
|
1940
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1941
|
-
return accumulated + handle.offsetWidth;
|
|
1942
|
-
}, 0);
|
|
1943
|
-
} else {
|
|
1944
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1945
|
-
return accumulated + handle.offsetHeight;
|
|
1946
|
-
}, 0);
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
function getPanelElement(id) {
|
|
1951
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1983
|
+
function getPanelElement(id, scope = document) {
|
|
1984
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1952
1985
|
if (element) {
|
|
1953
1986
|
return element;
|
|
1954
1987
|
}
|
|
1955
1988
|
return null;
|
|
1956
1989
|
}
|
|
1957
1990
|
|
|
1958
|
-
function getPanelElementsForGroup(groupId) {
|
|
1959
|
-
return Array.from(
|
|
1991
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1992
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1960
1993
|
}
|
|
1961
1994
|
|
|
1962
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1995
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|