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
|
|
@@ -123,6 +124,9 @@ function PanelWithForwardedRef({
|
|
|
123
124
|
callbacks,
|
|
124
125
|
constraints
|
|
125
126
|
} = panelDataRef.current;
|
|
127
|
+
const prevConstraints = {
|
|
128
|
+
...constraints
|
|
129
|
+
};
|
|
126
130
|
panelDataRef.current.id = panelId;
|
|
127
131
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
128
132
|
panelDataRef.current.order = order;
|
|
@@ -134,6 +138,12 @@ function PanelWithForwardedRef({
|
|
|
134
138
|
constraints.defaultSize = defaultSize;
|
|
135
139
|
constraints.maxSize = maxSize;
|
|
136
140
|
constraints.minSize = minSize;
|
|
141
|
+
|
|
142
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
143
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
144
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
145
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
146
|
+
}
|
|
137
147
|
});
|
|
138
148
|
useIsomorphicLayoutEffect(() => {
|
|
139
149
|
const panelData = panelDataRef.current;
|
|
@@ -521,41 +531,48 @@ function calculateAriaValues({
|
|
|
521
531
|
};
|
|
522
532
|
}
|
|
523
533
|
|
|
524
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
525
|
-
return Array.from(
|
|
534
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
535
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
526
536
|
}
|
|
527
537
|
|
|
528
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
529
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
538
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
539
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
530
540
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
531
541
|
return index !== null && index !== void 0 ? index : null;
|
|
532
542
|
}
|
|
533
543
|
|
|
534
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
535
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
544
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
545
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
536
546
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
537
547
|
}
|
|
538
548
|
|
|
539
|
-
function getPanelGroupElement(id) {
|
|
540
|
-
|
|
549
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
550
|
+
var _dataset;
|
|
551
|
+
//If the root element is the PanelGroup
|
|
552
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
553
|
+
return rootElement;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
//Else query children
|
|
557
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
541
558
|
if (element) {
|
|
542
559
|
return element;
|
|
543
560
|
}
|
|
544
561
|
return null;
|
|
545
562
|
}
|
|
546
563
|
|
|
547
|
-
function getResizeHandleElement(id) {
|
|
548
|
-
const element =
|
|
564
|
+
function getResizeHandleElement(id, scope = document) {
|
|
565
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
549
566
|
if (element) {
|
|
550
567
|
return element;
|
|
551
568
|
}
|
|
552
569
|
return null;
|
|
553
570
|
}
|
|
554
571
|
|
|
555
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
572
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
556
573
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
557
|
-
const handle = getResizeHandleElement(handleId);
|
|
558
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
574
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
575
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
559
576
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
560
577
|
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;
|
|
561
578
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -570,13 +587,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
570
587
|
groupId,
|
|
571
588
|
layout,
|
|
572
589
|
panelDataArray,
|
|
590
|
+
panelGroupElement,
|
|
573
591
|
setLayout
|
|
574
592
|
}) {
|
|
575
593
|
useRef({
|
|
576
594
|
didWarnAboutMissingResizeHandle: false
|
|
577
595
|
});
|
|
578
596
|
useIsomorphicLayoutEffect(() => {
|
|
579
|
-
|
|
597
|
+
if (!panelGroupElement) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
580
601
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
581
602
|
const {
|
|
582
603
|
valueMax,
|
|
@@ -605,21 +626,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
605
626
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
606
627
|
});
|
|
607
628
|
};
|
|
608
|
-
}, [groupId, layout, panelDataArray]);
|
|
629
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
609
630
|
useEffect(() => {
|
|
631
|
+
if (!panelGroupElement) {
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
610
634
|
const eagerValues = eagerValuesRef.current;
|
|
611
635
|
assert(eagerValues);
|
|
612
636
|
const {
|
|
613
637
|
panelDataArray
|
|
614
638
|
} = eagerValues;
|
|
615
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
639
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
616
640
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
617
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
641
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
618
642
|
assert(handles);
|
|
619
643
|
const cleanupFunctions = handles.map(handle => {
|
|
620
644
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
621
645
|
assert(handleId);
|
|
622
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
646
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
623
647
|
if (idBefore == null || idAfter == null) {
|
|
624
648
|
return () => {};
|
|
625
649
|
}
|
|
@@ -646,7 +670,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
646
670
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
647
671
|
layout,
|
|
648
672
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
649
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
673
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
650
674
|
trigger: "keyboard"
|
|
651
675
|
});
|
|
652
676
|
if (layout !== nextLayout) {
|
|
@@ -666,7 +690,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
666
690
|
return () => {
|
|
667
691
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
668
692
|
};
|
|
669
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
693
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
670
694
|
}
|
|
671
695
|
|
|
672
696
|
function areEqual(arrayA, arrayB) {
|
|
@@ -704,9 +728,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
704
728
|
}
|
|
705
729
|
}
|
|
706
730
|
|
|
707
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
731
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
708
732
|
const isHorizontal = direction === "horizontal";
|
|
709
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
733
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
710
734
|
assert(handleElement);
|
|
711
735
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
712
736
|
assert(groupId);
|
|
@@ -714,7 +738,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
714
738
|
initialCursorPosition
|
|
715
739
|
} = initialDragState;
|
|
716
740
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
717
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
741
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
718
742
|
assert(groupElement);
|
|
719
743
|
const groupRect = groupElement.getBoundingClientRect();
|
|
720
744
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -724,7 +748,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
724
748
|
}
|
|
725
749
|
|
|
726
750
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
727
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
751
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
728
752
|
if (isKeyDown(event)) {
|
|
729
753
|
const isHorizontal = direction === "horizontal";
|
|
730
754
|
let delta = 0;
|
|
@@ -761,7 +785,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
761
785
|
if (initialDragState == null) {
|
|
762
786
|
return 0;
|
|
763
787
|
}
|
|
764
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
788
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
765
789
|
}
|
|
766
790
|
}
|
|
767
791
|
|
|
@@ -1113,6 +1137,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1113
1137
|
...rest
|
|
1114
1138
|
}) {
|
|
1115
1139
|
const groupId = useUniqueId(idFromProps);
|
|
1140
|
+
const panelGroupElementRef = useRef(null);
|
|
1116
1141
|
const [dragState, setDragState] = useState(null);
|
|
1117
1142
|
const [layout, setLayout] = useState([]);
|
|
1118
1143
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1181,7 +1206,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1181
1206
|
groupId,
|
|
1182
1207
|
layout,
|
|
1183
1208
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1184
|
-
setLayout
|
|
1209
|
+
setLayout,
|
|
1210
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1185
1211
|
});
|
|
1186
1212
|
useEffect(() => {
|
|
1187
1213
|
const {
|
|
@@ -1424,6 +1450,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1424
1450
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1425
1451
|
return function resizeHandler(event) {
|
|
1426
1452
|
event.preventDefault();
|
|
1453
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1454
|
+
if (!panelGroupElement) {
|
|
1455
|
+
return () => null;
|
|
1456
|
+
}
|
|
1427
1457
|
const {
|
|
1428
1458
|
direction,
|
|
1429
1459
|
dragState,
|
|
@@ -1438,8 +1468,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1438
1468
|
const {
|
|
1439
1469
|
initialLayout
|
|
1440
1470
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1441
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1442
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1471
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1472
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1443
1473
|
if (delta === 0) {
|
|
1444
1474
|
return;
|
|
1445
1475
|
}
|
|
@@ -1527,6 +1557,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1527
1557
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1528
1558
|
}
|
|
1529
1559
|
}, []);
|
|
1560
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1561
|
+
const {
|
|
1562
|
+
layout,
|
|
1563
|
+
panelDataArray
|
|
1564
|
+
} = eagerValuesRef.current;
|
|
1565
|
+
const {
|
|
1566
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1567
|
+
collapsible: prevCollapsible,
|
|
1568
|
+
defaultSize: prevDefaultSize,
|
|
1569
|
+
maxSize: prevMaxSize = 100,
|
|
1570
|
+
minSize: prevMinSize = 0
|
|
1571
|
+
} = prevConstraints;
|
|
1572
|
+
const {
|
|
1573
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1574
|
+
collapsible: nextCollapsible,
|
|
1575
|
+
defaultSize: nextDefaultSize,
|
|
1576
|
+
maxSize: nextMaxSize = 100,
|
|
1577
|
+
minSize: nextMinSize = 0
|
|
1578
|
+
} = panelData.constraints;
|
|
1579
|
+
const {
|
|
1580
|
+
panelSize: prevPanelSize
|
|
1581
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1582
|
+
assert(prevPanelSize != null);
|
|
1583
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1584
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1585
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1586
|
+
resizePanel(panelData, nextMinSize);
|
|
1587
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1588
|
+
resizePanel(panelData, nextMaxSize);
|
|
1589
|
+
}
|
|
1590
|
+
}, [resizePanel]);
|
|
1530
1591
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1531
1592
|
const {
|
|
1532
1593
|
direction
|
|
@@ -1534,7 +1595,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1534
1595
|
const {
|
|
1535
1596
|
layout
|
|
1536
1597
|
} = eagerValuesRef.current;
|
|
1537
|
-
|
|
1598
|
+
if (!panelGroupElementRef.current) {
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1538
1602
|
assert(handleElement);
|
|
1539
1603
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1540
1604
|
setDragState({
|
|
@@ -1574,13 +1638,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1574
1638
|
groupId,
|
|
1575
1639
|
isPanelCollapsed,
|
|
1576
1640
|
isPanelExpanded,
|
|
1641
|
+
reevaluatePanelConstraints,
|
|
1577
1642
|
registerPanel,
|
|
1578
1643
|
registerResizeHandle,
|
|
1579
1644
|
resizePanel,
|
|
1580
1645
|
startDragging,
|
|
1581
1646
|
stopDragging,
|
|
1582
|
-
unregisterPanel
|
|
1583
|
-
|
|
1647
|
+
unregisterPanel,
|
|
1648
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1649
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1584
1650
|
const style = {
|
|
1585
1651
|
display: "flex",
|
|
1586
1652
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1598,6 +1664,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1598
1664
|
...style,
|
|
1599
1665
|
...styleFromProps
|
|
1600
1666
|
},
|
|
1667
|
+
ref: panelGroupElementRef,
|
|
1601
1668
|
// CSS selectors
|
|
1602
1669
|
"data-panel-group": "",
|
|
1603
1670
|
"data-panel-group-direction": direction,
|
|
@@ -1614,14 +1681,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1614
1681
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1615
1682
|
}
|
|
1616
1683
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1617
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1618
1684
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1619
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1620
1685
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1621
1686
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1622
1687
|
const panelSize = layout[panelIndex];
|
|
1623
1688
|
return {
|
|
1624
|
-
...
|
|
1689
|
+
...panelData.constraints,
|
|
1625
1690
|
panelSize,
|
|
1626
1691
|
pivotIndices
|
|
1627
1692
|
};
|
|
@@ -1632,13 +1697,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1632
1697
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1633
1698
|
disabled,
|
|
1634
1699
|
handleId,
|
|
1635
|
-
resizeHandler
|
|
1700
|
+
resizeHandler,
|
|
1701
|
+
panelGroupElement
|
|
1636
1702
|
}) {
|
|
1637
1703
|
useEffect(() => {
|
|
1638
|
-
if (disabled || resizeHandler == null) {
|
|
1704
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1639
1705
|
return;
|
|
1640
1706
|
}
|
|
1641
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1707
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1642
1708
|
if (handleElement == null) {
|
|
1643
1709
|
return;
|
|
1644
1710
|
}
|
|
@@ -1663,8 +1729,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1663
1729
|
event.preventDefault();
|
|
1664
1730
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1665
1731
|
assert(groupId);
|
|
1666
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1667
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1732
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1733
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1668
1734
|
assert(index !== null);
|
|
1669
1735
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1670
1736
|
const nextHandle = handles[nextIndex];
|
|
@@ -1677,7 +1743,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1677
1743
|
return () => {
|
|
1678
1744
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1679
1745
|
};
|
|
1680
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1746
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1681
1747
|
}
|
|
1682
1748
|
|
|
1683
1749
|
function PanelResizeHandle({
|
|
@@ -1710,7 +1776,8 @@ function PanelResizeHandle({
|
|
|
1710
1776
|
groupId,
|
|
1711
1777
|
registerResizeHandle,
|
|
1712
1778
|
startDragging,
|
|
1713
|
-
stopDragging
|
|
1779
|
+
stopDragging,
|
|
1780
|
+
panelGroupElement
|
|
1714
1781
|
} = panelGroupContext;
|
|
1715
1782
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1716
1783
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1769,7 +1836,8 @@ function PanelResizeHandle({
|
|
|
1769
1836
|
useWindowSplitterResizeHandlerBehavior({
|
|
1770
1837
|
disabled,
|
|
1771
1838
|
handleId: resizeHandleId,
|
|
1772
|
-
resizeHandler
|
|
1839
|
+
resizeHandler,
|
|
1840
|
+
panelGroupElement
|
|
1773
1841
|
});
|
|
1774
1842
|
const style = {
|
|
1775
1843
|
cursor: getCursorStyle(direction),
|
|
@@ -1825,60 +1893,22 @@ function PanelResizeHandle({
|
|
|
1825
1893
|
}
|
|
1826
1894
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1827
1895
|
|
|
1828
|
-
function
|
|
1829
|
-
const
|
|
1830
|
-
if (panelGroupElement == null) {
|
|
1831
|
-
return NaN;
|
|
1832
|
-
}
|
|
1833
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1834
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1835
|
-
if (direction === "horizontal") {
|
|
1836
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1837
|
-
return accumulated + handle.offsetWidth;
|
|
1838
|
-
}, 0);
|
|
1839
|
-
} else {
|
|
1840
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1841
|
-
return accumulated + handle.offsetHeight;
|
|
1842
|
-
}, 0);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1847
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1848
|
-
if (panelGroupElement == null) {
|
|
1849
|
-
return NaN;
|
|
1850
|
-
}
|
|
1851
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1852
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1853
|
-
if (direction === "horizontal") {
|
|
1854
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1855
|
-
return accumulated + handle.offsetWidth;
|
|
1856
|
-
}, 0);
|
|
1857
|
-
} else {
|
|
1858
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1859
|
-
return accumulated + handle.offsetHeight;
|
|
1860
|
-
}, 0);
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
function getPanelElement(id) {
|
|
1865
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1896
|
+
function getPanelElement(id, scope = document) {
|
|
1897
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1866
1898
|
if (element) {
|
|
1867
1899
|
return element;
|
|
1868
1900
|
}
|
|
1869
1901
|
return null;
|
|
1870
1902
|
}
|
|
1871
1903
|
|
|
1872
|
-
function getPanelElementsForGroup(groupId) {
|
|
1873
|
-
return Array.from(
|
|
1904
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1905
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1874
1906
|
}
|
|
1875
1907
|
|
|
1876
1908
|
exports.Panel = Panel;
|
|
1877
1909
|
exports.PanelGroup = PanelGroup;
|
|
1878
1910
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1879
1911
|
exports.assert = assert;
|
|
1880
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1881
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1882
1912
|
exports.getPanelElement = getPanelElement;
|
|
1883
1913
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1884
1914
|
exports.getPanelGroupElement = getPanelGroupElement;
|