react-resizable-panels 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +16 -15
- package/dist/declarations/src/Panel.d.ts +3 -3
- package/dist/declarations/src/PanelGroup.d.ts +2 -2
- package/dist/declarations/src/PanelResizeHandle.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +1 -3
- package/dist/declarations/src/utils/dom/getPanelElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getPanelGroupElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElement.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementIndex.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandleElementsForGroup.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getResizeHandlePanelIds.d.ts +1 -1
- package/dist/declarations/src/vendor/react.d.ts +2 -2
- package/dist/react-resizable-panels.browser.cjs.js +114 -84
- package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.cjs.js +116 -85
- package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.esm.js +117 -84
- package/dist/react-resizable-panels.browser.esm.js +115 -83
- package/dist/react-resizable-panels.cjs.js +114 -84
- package/dist/react-resizable-panels.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.cjs.js +116 -85
- package/dist/react-resizable-panels.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.esm.js +117 -84
- package/dist/react-resizable-panels.development.node.cjs.js +102 -83
- package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.node.esm.js +103 -82
- package/dist/react-resizable-panels.esm.js +115 -83
- package/dist/react-resizable-panels.node.cjs.js +100 -82
- package/dist/react-resizable-panels.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.node.esm.js +101 -81
- package/package.json +1 -1
- package/src/Panel.test.tsx +137 -2
- package/src/Panel.ts +16 -2
- package/src/PanelGroup.test.tsx +3 -2
- package/src/PanelGroup.ts +95 -35
- package/src/PanelGroupContext.ts +9 -3
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +4 -2
- package/src/hooks/useWindowSplitterBehavior.ts +14 -5
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
- package/src/index.ts +0 -4
- package/src/utils/calculateDeltaPercentage.ts +4 -2
- package/src/utils/calculateDragOffsetPercentage.ts +4 -3
- package/src/utils/determinePivotIndices.ts +7 -2
- package/src/utils/dom/getPanelElement.ts +5 -2
- package/src/utils/dom/getPanelElementsForGroup.ts +5 -2
- package/src/utils/dom/getPanelGroupElement.ts +14 -2
- package/src/utils/dom/getResizeHandleElement.ts +5 -4
- package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +3 -2
- package/src/utils/dom/getResizeHandlePanelIds.ts +4 -3
- package/src/utils/validatePanelConstraints.test.ts +45 -0
- package/src/utils/validatePanelConstraints.ts +5 -1
- package/src/vendor/react.ts +2 -0
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +0 -1
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +0 -1
- package/src/utils/dom/calculateAvailablePanelSizeInPixels.ts +0 -29
- package/src/utils/dom/getAvailableGroupSizePixels.ts +0 -29
|
@@ -67,6 +67,7 @@ function PanelWithForwardedRef({
|
|
|
67
67
|
getPanelStyle,
|
|
68
68
|
groupId,
|
|
69
69
|
isPanelCollapsed,
|
|
70
|
+
reevaluatePanelConstraints,
|
|
70
71
|
registerPanel,
|
|
71
72
|
resizePanel,
|
|
72
73
|
unregisterPanel
|
|
@@ -97,6 +98,9 @@ function PanelWithForwardedRef({
|
|
|
97
98
|
callbacks,
|
|
98
99
|
constraints
|
|
99
100
|
} = panelDataRef.current;
|
|
101
|
+
const prevConstraints = {
|
|
102
|
+
...constraints
|
|
103
|
+
};
|
|
100
104
|
panelDataRef.current.id = panelId;
|
|
101
105
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
102
106
|
panelDataRef.current.order = order;
|
|
@@ -108,6 +112,12 @@ function PanelWithForwardedRef({
|
|
|
108
112
|
constraints.defaultSize = defaultSize;
|
|
109
113
|
constraints.maxSize = maxSize;
|
|
110
114
|
constraints.minSize = minSize;
|
|
115
|
+
|
|
116
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
117
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
118
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
119
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
120
|
+
}
|
|
111
121
|
});
|
|
112
122
|
useIsomorphicLayoutEffect(() => {
|
|
113
123
|
const panelData = panelDataRef.current;
|
|
@@ -495,41 +505,48 @@ function calculateAriaValues({
|
|
|
495
505
|
};
|
|
496
506
|
}
|
|
497
507
|
|
|
498
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
499
|
-
return Array.from(
|
|
508
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
509
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
500
510
|
}
|
|
501
511
|
|
|
502
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
503
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
512
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
513
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
504
514
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
505
515
|
return index !== null && index !== void 0 ? index : null;
|
|
506
516
|
}
|
|
507
517
|
|
|
508
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
509
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
518
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
519
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
510
520
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
511
521
|
}
|
|
512
522
|
|
|
513
|
-
function getPanelGroupElement(id) {
|
|
514
|
-
|
|
523
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
524
|
+
var _dataset;
|
|
525
|
+
//If the root element is the PanelGroup
|
|
526
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
527
|
+
return rootElement;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
//Else query children
|
|
531
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
515
532
|
if (element) {
|
|
516
533
|
return element;
|
|
517
534
|
}
|
|
518
535
|
return null;
|
|
519
536
|
}
|
|
520
537
|
|
|
521
|
-
function getResizeHandleElement(id) {
|
|
522
|
-
const element =
|
|
538
|
+
function getResizeHandleElement(id, scope = document) {
|
|
539
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
523
540
|
if (element) {
|
|
524
541
|
return element;
|
|
525
542
|
}
|
|
526
543
|
return null;
|
|
527
544
|
}
|
|
528
545
|
|
|
529
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
546
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
530
547
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
531
|
-
const handle = getResizeHandleElement(handleId);
|
|
532
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
548
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
549
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
533
550
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
534
551
|
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;
|
|
535
552
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -544,13 +561,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
544
561
|
groupId,
|
|
545
562
|
layout,
|
|
546
563
|
panelDataArray,
|
|
564
|
+
panelGroupElement,
|
|
547
565
|
setLayout
|
|
548
566
|
}) {
|
|
549
567
|
useRef({
|
|
550
568
|
didWarnAboutMissingResizeHandle: false
|
|
551
569
|
});
|
|
552
570
|
useIsomorphicLayoutEffect(() => {
|
|
553
|
-
|
|
571
|
+
if (!panelGroupElement) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const resizeHandleElements = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
554
575
|
for (let index = 0; index < panelDataArray.length - 1; index++) {
|
|
555
576
|
const {
|
|
556
577
|
valueMax,
|
|
@@ -579,21 +600,24 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
579
600
|
resizeHandleElement.removeAttribute("aria-valuenow");
|
|
580
601
|
});
|
|
581
602
|
};
|
|
582
|
-
}, [groupId, layout, panelDataArray]);
|
|
603
|
+
}, [groupId, layout, panelDataArray, panelGroupElement]);
|
|
583
604
|
useEffect(() => {
|
|
605
|
+
if (!panelGroupElement) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
584
608
|
const eagerValues = eagerValuesRef.current;
|
|
585
609
|
assert(eagerValues);
|
|
586
610
|
const {
|
|
587
611
|
panelDataArray
|
|
588
612
|
} = eagerValues;
|
|
589
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
613
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
590
614
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
591
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
615
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
592
616
|
assert(handles);
|
|
593
617
|
const cleanupFunctions = handles.map(handle => {
|
|
594
618
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
595
619
|
assert(handleId);
|
|
596
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
620
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
597
621
|
if (idBefore == null || idAfter == null) {
|
|
598
622
|
return () => {};
|
|
599
623
|
}
|
|
@@ -620,7 +644,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
620
644
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
621
645
|
layout,
|
|
622
646
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
623
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
647
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
624
648
|
trigger: "keyboard"
|
|
625
649
|
});
|
|
626
650
|
if (layout !== nextLayout) {
|
|
@@ -640,7 +664,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
640
664
|
return () => {
|
|
641
665
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
642
666
|
};
|
|
643
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
667
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
644
668
|
}
|
|
645
669
|
|
|
646
670
|
function areEqual(arrayA, arrayB) {
|
|
@@ -678,9 +702,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
678
702
|
}
|
|
679
703
|
}
|
|
680
704
|
|
|
681
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
705
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
682
706
|
const isHorizontal = direction === "horizontal";
|
|
683
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
707
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
684
708
|
assert(handleElement);
|
|
685
709
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
686
710
|
assert(groupId);
|
|
@@ -688,7 +712,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
688
712
|
initialCursorPosition
|
|
689
713
|
} = initialDragState;
|
|
690
714
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
691
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
715
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
692
716
|
assert(groupElement);
|
|
693
717
|
const groupRect = groupElement.getBoundingClientRect();
|
|
694
718
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -698,7 +722,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
698
722
|
}
|
|
699
723
|
|
|
700
724
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
701
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
725
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
702
726
|
if (isKeyDown(event)) {
|
|
703
727
|
const isHorizontal = direction === "horizontal";
|
|
704
728
|
let delta = 0;
|
|
@@ -735,7 +759,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
735
759
|
if (initialDragState == null) {
|
|
736
760
|
return 0;
|
|
737
761
|
}
|
|
738
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
762
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
739
763
|
}
|
|
740
764
|
}
|
|
741
765
|
|
|
@@ -1087,6 +1111,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1087
1111
|
...rest
|
|
1088
1112
|
}) {
|
|
1089
1113
|
const groupId = useUniqueId(idFromProps);
|
|
1114
|
+
const panelGroupElementRef = useRef(null);
|
|
1090
1115
|
const [dragState, setDragState] = useState(null);
|
|
1091
1116
|
const [layout, setLayout] = useState([]);
|
|
1092
1117
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1155,7 +1180,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1155
1180
|
groupId,
|
|
1156
1181
|
layout,
|
|
1157
1182
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1158
|
-
setLayout
|
|
1183
|
+
setLayout,
|
|
1184
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1159
1185
|
});
|
|
1160
1186
|
useEffect(() => {
|
|
1161
1187
|
const {
|
|
@@ -1398,6 +1424,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1398
1424
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1399
1425
|
return function resizeHandler(event) {
|
|
1400
1426
|
event.preventDefault();
|
|
1427
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1428
|
+
if (!panelGroupElement) {
|
|
1429
|
+
return () => null;
|
|
1430
|
+
}
|
|
1401
1431
|
const {
|
|
1402
1432
|
direction,
|
|
1403
1433
|
dragState,
|
|
@@ -1412,8 +1442,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1412
1442
|
const {
|
|
1413
1443
|
initialLayout
|
|
1414
1444
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1415
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1416
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1445
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1446
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1417
1447
|
if (delta === 0) {
|
|
1418
1448
|
return;
|
|
1419
1449
|
}
|
|
@@ -1501,6 +1531,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1501
1531
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1502
1532
|
}
|
|
1503
1533
|
}, []);
|
|
1534
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1535
|
+
const {
|
|
1536
|
+
layout,
|
|
1537
|
+
panelDataArray
|
|
1538
|
+
} = eagerValuesRef.current;
|
|
1539
|
+
const {
|
|
1540
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1541
|
+
collapsible: prevCollapsible,
|
|
1542
|
+
defaultSize: prevDefaultSize,
|
|
1543
|
+
maxSize: prevMaxSize = 100,
|
|
1544
|
+
minSize: prevMinSize = 0
|
|
1545
|
+
} = prevConstraints;
|
|
1546
|
+
const {
|
|
1547
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1548
|
+
collapsible: nextCollapsible,
|
|
1549
|
+
defaultSize: nextDefaultSize,
|
|
1550
|
+
maxSize: nextMaxSize = 100,
|
|
1551
|
+
minSize: nextMinSize = 0
|
|
1552
|
+
} = panelData.constraints;
|
|
1553
|
+
const {
|
|
1554
|
+
panelSize: prevPanelSize
|
|
1555
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1556
|
+
assert(prevPanelSize != null);
|
|
1557
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1558
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1559
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1560
|
+
resizePanel(panelData, nextMinSize);
|
|
1561
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1562
|
+
resizePanel(panelData, nextMaxSize);
|
|
1563
|
+
}
|
|
1564
|
+
}, [resizePanel]);
|
|
1504
1565
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1505
1566
|
const {
|
|
1506
1567
|
direction
|
|
@@ -1508,7 +1569,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1508
1569
|
const {
|
|
1509
1570
|
layout
|
|
1510
1571
|
} = eagerValuesRef.current;
|
|
1511
|
-
|
|
1572
|
+
if (!panelGroupElementRef.current) {
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1512
1576
|
assert(handleElement);
|
|
1513
1577
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1514
1578
|
setDragState({
|
|
@@ -1548,13 +1612,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1548
1612
|
groupId,
|
|
1549
1613
|
isPanelCollapsed,
|
|
1550
1614
|
isPanelExpanded,
|
|
1615
|
+
reevaluatePanelConstraints,
|
|
1551
1616
|
registerPanel,
|
|
1552
1617
|
registerResizeHandle,
|
|
1553
1618
|
resizePanel,
|
|
1554
1619
|
startDragging,
|
|
1555
1620
|
stopDragging,
|
|
1556
|
-
unregisterPanel
|
|
1557
|
-
|
|
1621
|
+
unregisterPanel,
|
|
1622
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1623
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1558
1624
|
const style = {
|
|
1559
1625
|
display: "flex",
|
|
1560
1626
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1572,6 +1638,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1572
1638
|
...style,
|
|
1573
1639
|
...styleFromProps
|
|
1574
1640
|
},
|
|
1641
|
+
ref: panelGroupElementRef,
|
|
1575
1642
|
// CSS selectors
|
|
1576
1643
|
"data-panel-group": "",
|
|
1577
1644
|
"data-panel-group-direction": direction,
|
|
@@ -1588,14 +1655,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1588
1655
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1589
1656
|
}
|
|
1590
1657
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1591
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1592
1658
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1593
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1594
1659
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1595
1660
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1596
1661
|
const panelSize = layout[panelIndex];
|
|
1597
1662
|
return {
|
|
1598
|
-
...
|
|
1663
|
+
...panelData.constraints,
|
|
1599
1664
|
panelSize,
|
|
1600
1665
|
pivotIndices
|
|
1601
1666
|
};
|
|
@@ -1606,13 +1671,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1606
1671
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1607
1672
|
disabled,
|
|
1608
1673
|
handleId,
|
|
1609
|
-
resizeHandler
|
|
1674
|
+
resizeHandler,
|
|
1675
|
+
panelGroupElement
|
|
1610
1676
|
}) {
|
|
1611
1677
|
useEffect(() => {
|
|
1612
|
-
if (disabled || resizeHandler == null) {
|
|
1678
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1613
1679
|
return;
|
|
1614
1680
|
}
|
|
1615
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1681
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1616
1682
|
if (handleElement == null) {
|
|
1617
1683
|
return;
|
|
1618
1684
|
}
|
|
@@ -1637,8 +1703,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1637
1703
|
event.preventDefault();
|
|
1638
1704
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1639
1705
|
assert(groupId);
|
|
1640
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1641
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1706
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1707
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1642
1708
|
assert(index !== null);
|
|
1643
1709
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1644
1710
|
const nextHandle = handles[nextIndex];
|
|
@@ -1651,7 +1717,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1651
1717
|
return () => {
|
|
1652
1718
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1653
1719
|
};
|
|
1654
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1720
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1655
1721
|
}
|
|
1656
1722
|
|
|
1657
1723
|
function PanelResizeHandle({
|
|
@@ -1684,7 +1750,8 @@ function PanelResizeHandle({
|
|
|
1684
1750
|
groupId,
|
|
1685
1751
|
registerResizeHandle,
|
|
1686
1752
|
startDragging,
|
|
1687
|
-
stopDragging
|
|
1753
|
+
stopDragging,
|
|
1754
|
+
panelGroupElement
|
|
1688
1755
|
} = panelGroupContext;
|
|
1689
1756
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1690
1757
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1743,7 +1810,8 @@ function PanelResizeHandle({
|
|
|
1743
1810
|
useWindowSplitterResizeHandlerBehavior({
|
|
1744
1811
|
disabled,
|
|
1745
1812
|
handleId: resizeHandleId,
|
|
1746
|
-
resizeHandler
|
|
1813
|
+
resizeHandler,
|
|
1814
|
+
panelGroupElement
|
|
1747
1815
|
});
|
|
1748
1816
|
const style = {
|
|
1749
1817
|
cursor: getCursorStyle(direction),
|
|
@@ -1799,52 +1867,16 @@ function PanelResizeHandle({
|
|
|
1799
1867
|
}
|
|
1800
1868
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1801
1869
|
|
|
1802
|
-
function
|
|
1803
|
-
const
|
|
1804
|
-
if (panelGroupElement == null) {
|
|
1805
|
-
return NaN;
|
|
1806
|
-
}
|
|
1807
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1808
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1809
|
-
if (direction === "horizontal") {
|
|
1810
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1811
|
-
return accumulated + handle.offsetWidth;
|
|
1812
|
-
}, 0);
|
|
1813
|
-
} else {
|
|
1814
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1815
|
-
return accumulated + handle.offsetHeight;
|
|
1816
|
-
}, 0);
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1821
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1822
|
-
if (panelGroupElement == null) {
|
|
1823
|
-
return NaN;
|
|
1824
|
-
}
|
|
1825
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1826
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1827
|
-
if (direction === "horizontal") {
|
|
1828
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1829
|
-
return accumulated + handle.offsetWidth;
|
|
1830
|
-
}, 0);
|
|
1831
|
-
} else {
|
|
1832
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1833
|
-
return accumulated + handle.offsetHeight;
|
|
1834
|
-
}, 0);
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
function getPanelElement(id) {
|
|
1839
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1870
|
+
function getPanelElement(id, scope = document) {
|
|
1871
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1840
1872
|
if (element) {
|
|
1841
1873
|
return element;
|
|
1842
1874
|
}
|
|
1843
1875
|
return null;
|
|
1844
1876
|
}
|
|
1845
1877
|
|
|
1846
|
-
function getPanelElementsForGroup(groupId) {
|
|
1847
|
-
return Array.from(
|
|
1878
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1879
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1848
1880
|
}
|
|
1849
1881
|
|
|
1850
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1882
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|