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
|
@@ -65,6 +65,7 @@ function PanelWithForwardedRef({
|
|
|
65
65
|
getPanelStyle,
|
|
66
66
|
groupId,
|
|
67
67
|
isPanelCollapsed,
|
|
68
|
+
reevaluatePanelConstraints,
|
|
68
69
|
registerPanel,
|
|
69
70
|
resizePanel,
|
|
70
71
|
unregisterPanel
|
|
@@ -441,41 +442,48 @@ function adjustLayoutByDelta({
|
|
|
441
442
|
return nextLayout;
|
|
442
443
|
}
|
|
443
444
|
|
|
444
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
445
|
-
return Array.from(
|
|
445
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
446
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
446
447
|
}
|
|
447
448
|
|
|
448
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
449
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
449
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
450
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
450
451
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
451
452
|
return index !== null && index !== void 0 ? index : null;
|
|
452
453
|
}
|
|
453
454
|
|
|
454
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
455
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
455
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
456
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
456
457
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
457
458
|
}
|
|
458
459
|
|
|
459
|
-
function getPanelGroupElement(id) {
|
|
460
|
-
|
|
460
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
461
|
+
var _dataset;
|
|
462
|
+
//If the root element is the PanelGroup
|
|
463
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
464
|
+
return rootElement;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
//Else query children
|
|
468
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
461
469
|
if (element) {
|
|
462
470
|
return element;
|
|
463
471
|
}
|
|
464
472
|
return null;
|
|
465
473
|
}
|
|
466
474
|
|
|
467
|
-
function getResizeHandleElement(id) {
|
|
468
|
-
const element =
|
|
475
|
+
function getResizeHandleElement(id, scope = document) {
|
|
476
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
469
477
|
if (element) {
|
|
470
478
|
return element;
|
|
471
479
|
}
|
|
472
480
|
return null;
|
|
473
481
|
}
|
|
474
482
|
|
|
475
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
483
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
476
484
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
477
|
-
const handle = getResizeHandleElement(handleId);
|
|
478
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
485
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
486
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
479
487
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
480
488
|
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;
|
|
481
489
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -490,25 +498,29 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
490
498
|
groupId,
|
|
491
499
|
layout,
|
|
492
500
|
panelDataArray,
|
|
501
|
+
panelGroupElement,
|
|
493
502
|
setLayout
|
|
494
503
|
}) {
|
|
495
504
|
useRef({
|
|
496
505
|
didWarnAboutMissingResizeHandle: false
|
|
497
506
|
});
|
|
498
507
|
useEffect(() => {
|
|
508
|
+
if (!panelGroupElement) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
499
511
|
const eagerValues = eagerValuesRef.current;
|
|
500
512
|
assert(eagerValues);
|
|
501
513
|
const {
|
|
502
514
|
panelDataArray
|
|
503
515
|
} = eagerValues;
|
|
504
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
516
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
505
517
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
506
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
518
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
507
519
|
assert(handles);
|
|
508
520
|
const cleanupFunctions = handles.map(handle => {
|
|
509
521
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
510
522
|
assert(handleId);
|
|
511
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
523
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
512
524
|
if (idBefore == null || idAfter == null) {
|
|
513
525
|
return () => {};
|
|
514
526
|
}
|
|
@@ -535,7 +547,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
535
547
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
536
548
|
layout,
|
|
537
549
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
538
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
550
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
539
551
|
trigger: "keyboard"
|
|
540
552
|
});
|
|
541
553
|
if (layout !== nextLayout) {
|
|
@@ -555,7 +567,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
555
567
|
return () => {
|
|
556
568
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
557
569
|
};
|
|
558
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
570
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
559
571
|
}
|
|
560
572
|
|
|
561
573
|
function areEqual(arrayA, arrayB) {
|
|
@@ -593,9 +605,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
593
605
|
}
|
|
594
606
|
}
|
|
595
607
|
|
|
596
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
608
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
597
609
|
const isHorizontal = direction === "horizontal";
|
|
598
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
610
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
599
611
|
assert(handleElement);
|
|
600
612
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
601
613
|
assert(groupId);
|
|
@@ -603,7 +615,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
603
615
|
initialCursorPosition
|
|
604
616
|
} = initialDragState;
|
|
605
617
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
606
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
618
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
607
619
|
assert(groupElement);
|
|
608
620
|
const groupRect = groupElement.getBoundingClientRect();
|
|
609
621
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -613,7 +625,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
613
625
|
}
|
|
614
626
|
|
|
615
627
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
616
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
628
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
617
629
|
if (isKeyDown(event)) {
|
|
618
630
|
const isHorizontal = direction === "horizontal";
|
|
619
631
|
let delta = 0;
|
|
@@ -650,7 +662,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
650
662
|
if (initialDragState == null) {
|
|
651
663
|
return 0;
|
|
652
664
|
}
|
|
653
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
665
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
654
666
|
}
|
|
655
667
|
}
|
|
656
668
|
|
|
@@ -877,6 +889,7 @@ function validatePanelConstraints({
|
|
|
877
889
|
assert(panelConstraints);
|
|
878
890
|
const {
|
|
879
891
|
collapsedSize = 0,
|
|
892
|
+
collapsible = false,
|
|
880
893
|
defaultSize,
|
|
881
894
|
maxSize = 100,
|
|
882
895
|
minSize = 0
|
|
@@ -887,7 +900,7 @@ function validatePanelConstraints({
|
|
|
887
900
|
if (defaultSize != null) {
|
|
888
901
|
if (defaultSize < 0) {
|
|
889
902
|
warnings.push("default size should not be less than 0");
|
|
890
|
-
} else if (defaultSize < minSize) {
|
|
903
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
891
904
|
warnings.push("default size should not be less than min size");
|
|
892
905
|
}
|
|
893
906
|
if (defaultSize > 100) {
|
|
@@ -1002,6 +1015,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1002
1015
|
...rest
|
|
1003
1016
|
}) {
|
|
1004
1017
|
const groupId = useUniqueId(idFromProps);
|
|
1018
|
+
const panelGroupElementRef = useRef(null);
|
|
1005
1019
|
const [dragState, setDragState] = useState(null);
|
|
1006
1020
|
const [layout, setLayout] = useState([]);
|
|
1007
1021
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1062,7 +1076,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1062
1076
|
groupId,
|
|
1063
1077
|
layout,
|
|
1064
1078
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1065
|
-
setLayout
|
|
1079
|
+
setLayout,
|
|
1080
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1066
1081
|
});
|
|
1067
1082
|
useEffect(() => {
|
|
1068
1083
|
const {
|
|
@@ -1299,6 +1314,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1299
1314
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1300
1315
|
return function resizeHandler(event) {
|
|
1301
1316
|
event.preventDefault();
|
|
1317
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1318
|
+
if (!panelGroupElement) {
|
|
1319
|
+
return () => null;
|
|
1320
|
+
}
|
|
1302
1321
|
const {
|
|
1303
1322
|
direction,
|
|
1304
1323
|
dragState,
|
|
@@ -1313,8 +1332,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1313
1332
|
const {
|
|
1314
1333
|
initialLayout
|
|
1315
1334
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1316
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1317
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1335
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1336
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1318
1337
|
if (delta === 0) {
|
|
1319
1338
|
return;
|
|
1320
1339
|
}
|
|
@@ -1402,6 +1421,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1402
1421
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1403
1422
|
}
|
|
1404
1423
|
}, []);
|
|
1424
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1425
|
+
const {
|
|
1426
|
+
layout,
|
|
1427
|
+
panelDataArray
|
|
1428
|
+
} = eagerValuesRef.current;
|
|
1429
|
+
const {
|
|
1430
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1431
|
+
collapsible: prevCollapsible,
|
|
1432
|
+
defaultSize: prevDefaultSize,
|
|
1433
|
+
maxSize: prevMaxSize = 100,
|
|
1434
|
+
minSize: prevMinSize = 0
|
|
1435
|
+
} = prevConstraints;
|
|
1436
|
+
const {
|
|
1437
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1438
|
+
collapsible: nextCollapsible,
|
|
1439
|
+
defaultSize: nextDefaultSize,
|
|
1440
|
+
maxSize: nextMaxSize = 100,
|
|
1441
|
+
minSize: nextMinSize = 0
|
|
1442
|
+
} = panelData.constraints;
|
|
1443
|
+
const {
|
|
1444
|
+
panelSize: prevPanelSize
|
|
1445
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1446
|
+
assert(prevPanelSize != null);
|
|
1447
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1448
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1449
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1450
|
+
resizePanel(panelData, nextMinSize);
|
|
1451
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1452
|
+
resizePanel(panelData, nextMaxSize);
|
|
1453
|
+
}
|
|
1454
|
+
}, [resizePanel]);
|
|
1405
1455
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1406
1456
|
const {
|
|
1407
1457
|
direction
|
|
@@ -1409,7 +1459,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1409
1459
|
const {
|
|
1410
1460
|
layout
|
|
1411
1461
|
} = eagerValuesRef.current;
|
|
1412
|
-
|
|
1462
|
+
if (!panelGroupElementRef.current) {
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1413
1466
|
assert(handleElement);
|
|
1414
1467
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1415
1468
|
setDragState({
|
|
@@ -1449,13 +1502,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1449
1502
|
groupId,
|
|
1450
1503
|
isPanelCollapsed,
|
|
1451
1504
|
isPanelExpanded,
|
|
1505
|
+
reevaluatePanelConstraints,
|
|
1452
1506
|
registerPanel,
|
|
1453
1507
|
registerResizeHandle,
|
|
1454
1508
|
resizePanel,
|
|
1455
1509
|
startDragging,
|
|
1456
1510
|
stopDragging,
|
|
1457
|
-
unregisterPanel
|
|
1458
|
-
|
|
1511
|
+
unregisterPanel,
|
|
1512
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1513
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1459
1514
|
const style = {
|
|
1460
1515
|
display: "flex",
|
|
1461
1516
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1473,6 +1528,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1473
1528
|
...style,
|
|
1474
1529
|
...styleFromProps
|
|
1475
1530
|
},
|
|
1531
|
+
ref: panelGroupElementRef,
|
|
1476
1532
|
// CSS selectors
|
|
1477
1533
|
"data-panel-group": "",
|
|
1478
1534
|
"data-panel-group-direction": direction,
|
|
@@ -1489,14 +1545,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1489
1545
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1490
1546
|
}
|
|
1491
1547
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1492
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1493
1548
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1494
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1495
1549
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1496
1550
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1497
1551
|
const panelSize = layout[panelIndex];
|
|
1498
1552
|
return {
|
|
1499
|
-
...
|
|
1553
|
+
...panelData.constraints,
|
|
1500
1554
|
panelSize,
|
|
1501
1555
|
pivotIndices
|
|
1502
1556
|
};
|
|
@@ -1507,13 +1561,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1507
1561
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1508
1562
|
disabled,
|
|
1509
1563
|
handleId,
|
|
1510
|
-
resizeHandler
|
|
1564
|
+
resizeHandler,
|
|
1565
|
+
panelGroupElement
|
|
1511
1566
|
}) {
|
|
1512
1567
|
useEffect(() => {
|
|
1513
|
-
if (disabled || resizeHandler == null) {
|
|
1568
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1514
1569
|
return;
|
|
1515
1570
|
}
|
|
1516
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1571
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1517
1572
|
if (handleElement == null) {
|
|
1518
1573
|
return;
|
|
1519
1574
|
}
|
|
@@ -1538,8 +1593,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1538
1593
|
event.preventDefault();
|
|
1539
1594
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1540
1595
|
assert(groupId);
|
|
1541
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1542
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1596
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1597
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1543
1598
|
assert(index !== null);
|
|
1544
1599
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1545
1600
|
const nextHandle = handles[nextIndex];
|
|
@@ -1552,7 +1607,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1552
1607
|
return () => {
|
|
1553
1608
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1554
1609
|
};
|
|
1555
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1610
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1556
1611
|
}
|
|
1557
1612
|
|
|
1558
1613
|
function PanelResizeHandle({
|
|
@@ -1585,7 +1640,8 @@ function PanelResizeHandle({
|
|
|
1585
1640
|
groupId,
|
|
1586
1641
|
registerResizeHandle,
|
|
1587
1642
|
startDragging,
|
|
1588
|
-
stopDragging
|
|
1643
|
+
stopDragging,
|
|
1644
|
+
panelGroupElement
|
|
1589
1645
|
} = panelGroupContext;
|
|
1590
1646
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1591
1647
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1644,7 +1700,8 @@ function PanelResizeHandle({
|
|
|
1644
1700
|
useWindowSplitterResizeHandlerBehavior({
|
|
1645
1701
|
disabled,
|
|
1646
1702
|
handleId: resizeHandleId,
|
|
1647
|
-
resizeHandler
|
|
1703
|
+
resizeHandler,
|
|
1704
|
+
panelGroupElement
|
|
1648
1705
|
});
|
|
1649
1706
|
const style = {
|
|
1650
1707
|
cursor: getCursorStyle(direction),
|
|
@@ -1700,52 +1757,16 @@ function PanelResizeHandle({
|
|
|
1700
1757
|
}
|
|
1701
1758
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1702
1759
|
|
|
1703
|
-
function
|
|
1704
|
-
const
|
|
1705
|
-
if (panelGroupElement == null) {
|
|
1706
|
-
return NaN;
|
|
1707
|
-
}
|
|
1708
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1709
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1710
|
-
if (direction === "horizontal") {
|
|
1711
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1712
|
-
return accumulated + handle.offsetWidth;
|
|
1713
|
-
}, 0);
|
|
1714
|
-
} else {
|
|
1715
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1716
|
-
return accumulated + handle.offsetHeight;
|
|
1717
|
-
}, 0);
|
|
1718
|
-
}
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1722
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1723
|
-
if (panelGroupElement == null) {
|
|
1724
|
-
return NaN;
|
|
1725
|
-
}
|
|
1726
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1727
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1728
|
-
if (direction === "horizontal") {
|
|
1729
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1730
|
-
return accumulated + handle.offsetWidth;
|
|
1731
|
-
}, 0);
|
|
1732
|
-
} else {
|
|
1733
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1734
|
-
return accumulated + handle.offsetHeight;
|
|
1735
|
-
}, 0);
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
function getPanelElement(id) {
|
|
1740
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1760
|
+
function getPanelElement(id, scope = document) {
|
|
1761
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1741
1762
|
if (element) {
|
|
1742
1763
|
return element;
|
|
1743
1764
|
}
|
|
1744
1765
|
return null;
|
|
1745
1766
|
}
|
|
1746
1767
|
|
|
1747
|
-
function getPanelElementsForGroup(groupId) {
|
|
1748
|
-
return Array.from(
|
|
1768
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1769
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1749
1770
|
}
|
|
1750
1771
|
|
|
1751
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1772
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|