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
|
@@ -89,6 +89,7 @@ function PanelWithForwardedRef({
|
|
|
89
89
|
getPanelStyle,
|
|
90
90
|
groupId,
|
|
91
91
|
isPanelCollapsed,
|
|
92
|
+
reevaluatePanelConstraints,
|
|
92
93
|
registerPanel,
|
|
93
94
|
resizePanel,
|
|
94
95
|
unregisterPanel
|
|
@@ -454,41 +455,48 @@ function adjustLayoutByDelta({
|
|
|
454
455
|
return nextLayout;
|
|
455
456
|
}
|
|
456
457
|
|
|
457
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
458
|
-
return Array.from(
|
|
458
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
459
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
459
460
|
}
|
|
460
461
|
|
|
461
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
462
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
462
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
463
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
463
464
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
464
465
|
return index !== null && index !== void 0 ? index : null;
|
|
465
466
|
}
|
|
466
467
|
|
|
467
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
468
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
468
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
469
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
469
470
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
470
471
|
}
|
|
471
472
|
|
|
472
|
-
function getPanelGroupElement(id) {
|
|
473
|
-
|
|
473
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
474
|
+
var _dataset;
|
|
475
|
+
//If the root element is the PanelGroup
|
|
476
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
477
|
+
return rootElement;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
//Else query children
|
|
481
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
474
482
|
if (element) {
|
|
475
483
|
return element;
|
|
476
484
|
}
|
|
477
485
|
return null;
|
|
478
486
|
}
|
|
479
487
|
|
|
480
|
-
function getResizeHandleElement(id) {
|
|
481
|
-
const element =
|
|
488
|
+
function getResizeHandleElement(id, scope = document) {
|
|
489
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
482
490
|
if (element) {
|
|
483
491
|
return element;
|
|
484
492
|
}
|
|
485
493
|
return null;
|
|
486
494
|
}
|
|
487
495
|
|
|
488
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
496
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
489
497
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
490
|
-
const handle = getResizeHandleElement(handleId);
|
|
491
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
498
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
499
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
492
500
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
493
501
|
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;
|
|
494
502
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -503,25 +511,29 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
503
511
|
groupId,
|
|
504
512
|
layout,
|
|
505
513
|
panelDataArray,
|
|
514
|
+
panelGroupElement,
|
|
506
515
|
setLayout
|
|
507
516
|
}) {
|
|
508
517
|
useRef({
|
|
509
518
|
didWarnAboutMissingResizeHandle: false
|
|
510
519
|
});
|
|
511
520
|
useEffect(() => {
|
|
521
|
+
if (!panelGroupElement) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
512
524
|
const eagerValues = eagerValuesRef.current;
|
|
513
525
|
assert(eagerValues);
|
|
514
526
|
const {
|
|
515
527
|
panelDataArray
|
|
516
528
|
} = eagerValues;
|
|
517
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
529
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
518
530
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
519
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
531
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
520
532
|
assert(handles);
|
|
521
533
|
const cleanupFunctions = handles.map(handle => {
|
|
522
534
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
523
535
|
assert(handleId);
|
|
524
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
536
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
525
537
|
if (idBefore == null || idAfter == null) {
|
|
526
538
|
return () => {};
|
|
527
539
|
}
|
|
@@ -548,7 +560,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
548
560
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
549
561
|
layout,
|
|
550
562
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
551
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
563
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
552
564
|
trigger: "keyboard"
|
|
553
565
|
});
|
|
554
566
|
if (layout !== nextLayout) {
|
|
@@ -568,7 +580,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
568
580
|
return () => {
|
|
569
581
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
570
582
|
};
|
|
571
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
583
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
572
584
|
}
|
|
573
585
|
|
|
574
586
|
function areEqual(arrayA, arrayB) {
|
|
@@ -606,9 +618,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
606
618
|
}
|
|
607
619
|
}
|
|
608
620
|
|
|
609
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
621
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
610
622
|
const isHorizontal = direction === "horizontal";
|
|
611
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
623
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
612
624
|
assert(handleElement);
|
|
613
625
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
614
626
|
assert(groupId);
|
|
@@ -616,7 +628,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
616
628
|
initialCursorPosition
|
|
617
629
|
} = initialDragState;
|
|
618
630
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
619
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
631
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
620
632
|
assert(groupElement);
|
|
621
633
|
const groupRect = groupElement.getBoundingClientRect();
|
|
622
634
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -626,7 +638,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
626
638
|
}
|
|
627
639
|
|
|
628
640
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
629
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
641
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
630
642
|
if (isKeyDown(event)) {
|
|
631
643
|
const isHorizontal = direction === "horizontal";
|
|
632
644
|
let delta = 0;
|
|
@@ -663,7 +675,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
663
675
|
if (initialDragState == null) {
|
|
664
676
|
return 0;
|
|
665
677
|
}
|
|
666
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
678
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
667
679
|
}
|
|
668
680
|
}
|
|
669
681
|
|
|
@@ -968,6 +980,7 @@ function PanelGroupWithForwardedRef({
|
|
|
968
980
|
...rest
|
|
969
981
|
}) {
|
|
970
982
|
const groupId = useUniqueId(idFromProps);
|
|
983
|
+
const panelGroupElementRef = useRef(null);
|
|
971
984
|
const [dragState, setDragState] = useState(null);
|
|
972
985
|
const [layout, setLayout] = useState([]);
|
|
973
986
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1028,7 +1041,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1028
1041
|
groupId,
|
|
1029
1042
|
layout,
|
|
1030
1043
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1031
|
-
setLayout
|
|
1044
|
+
setLayout,
|
|
1045
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1032
1046
|
});
|
|
1033
1047
|
useEffect(() => {
|
|
1034
1048
|
const {
|
|
@@ -1223,6 +1237,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1223
1237
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1224
1238
|
return function resizeHandler(event) {
|
|
1225
1239
|
event.preventDefault();
|
|
1240
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1241
|
+
if (!panelGroupElement) {
|
|
1242
|
+
return () => null;
|
|
1243
|
+
}
|
|
1226
1244
|
const {
|
|
1227
1245
|
direction,
|
|
1228
1246
|
dragState,
|
|
@@ -1237,8 +1255,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1237
1255
|
const {
|
|
1238
1256
|
initialLayout
|
|
1239
1257
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1240
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1241
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1258
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1259
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1242
1260
|
if (delta === 0) {
|
|
1243
1261
|
return;
|
|
1244
1262
|
}
|
|
@@ -1326,6 +1344,37 @@ function PanelGroupWithForwardedRef({
|
|
|
1326
1344
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1327
1345
|
}
|
|
1328
1346
|
}, []);
|
|
1347
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1348
|
+
const {
|
|
1349
|
+
layout,
|
|
1350
|
+
panelDataArray
|
|
1351
|
+
} = eagerValuesRef.current;
|
|
1352
|
+
const {
|
|
1353
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1354
|
+
collapsible: prevCollapsible,
|
|
1355
|
+
defaultSize: prevDefaultSize,
|
|
1356
|
+
maxSize: prevMaxSize = 100,
|
|
1357
|
+
minSize: prevMinSize = 0
|
|
1358
|
+
} = prevConstraints;
|
|
1359
|
+
const {
|
|
1360
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1361
|
+
collapsible: nextCollapsible,
|
|
1362
|
+
defaultSize: nextDefaultSize,
|
|
1363
|
+
maxSize: nextMaxSize = 100,
|
|
1364
|
+
minSize: nextMinSize = 0
|
|
1365
|
+
} = panelData.constraints;
|
|
1366
|
+
const {
|
|
1367
|
+
panelSize: prevPanelSize
|
|
1368
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1369
|
+
assert(prevPanelSize != null);
|
|
1370
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1371
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1372
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1373
|
+
resizePanel(panelData, nextMinSize);
|
|
1374
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1375
|
+
resizePanel(panelData, nextMaxSize);
|
|
1376
|
+
}
|
|
1377
|
+
}, [resizePanel]);
|
|
1329
1378
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1330
1379
|
const {
|
|
1331
1380
|
direction
|
|
@@ -1333,7 +1382,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1333
1382
|
const {
|
|
1334
1383
|
layout
|
|
1335
1384
|
} = eagerValuesRef.current;
|
|
1336
|
-
|
|
1385
|
+
if (!panelGroupElementRef.current) {
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1337
1389
|
assert(handleElement);
|
|
1338
1390
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1339
1391
|
setDragState({
|
|
@@ -1373,13 +1425,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1373
1425
|
groupId,
|
|
1374
1426
|
isPanelCollapsed,
|
|
1375
1427
|
isPanelExpanded,
|
|
1428
|
+
reevaluatePanelConstraints,
|
|
1376
1429
|
registerPanel,
|
|
1377
1430
|
registerResizeHandle,
|
|
1378
1431
|
resizePanel,
|
|
1379
1432
|
startDragging,
|
|
1380
1433
|
stopDragging,
|
|
1381
|
-
unregisterPanel
|
|
1382
|
-
|
|
1434
|
+
unregisterPanel,
|
|
1435
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1436
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1383
1437
|
const style = {
|
|
1384
1438
|
display: "flex",
|
|
1385
1439
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1397,6 +1451,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1397
1451
|
...style,
|
|
1398
1452
|
...styleFromProps
|
|
1399
1453
|
},
|
|
1454
|
+
ref: panelGroupElementRef,
|
|
1400
1455
|
// CSS selectors
|
|
1401
1456
|
"data-panel-group": "",
|
|
1402
1457
|
"data-panel-group-direction": direction,
|
|
@@ -1413,14 +1468,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1413
1468
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1414
1469
|
}
|
|
1415
1470
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1416
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1417
1471
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1418
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1419
1472
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1420
1473
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1421
1474
|
const panelSize = layout[panelIndex];
|
|
1422
1475
|
return {
|
|
1423
|
-
...
|
|
1476
|
+
...panelData.constraints,
|
|
1424
1477
|
panelSize,
|
|
1425
1478
|
pivotIndices
|
|
1426
1479
|
};
|
|
@@ -1431,13 +1484,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1431
1484
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1432
1485
|
disabled,
|
|
1433
1486
|
handleId,
|
|
1434
|
-
resizeHandler
|
|
1487
|
+
resizeHandler,
|
|
1488
|
+
panelGroupElement
|
|
1435
1489
|
}) {
|
|
1436
1490
|
useEffect(() => {
|
|
1437
|
-
if (disabled || resizeHandler == null) {
|
|
1491
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1438
1492
|
return;
|
|
1439
1493
|
}
|
|
1440
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1494
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1441
1495
|
if (handleElement == null) {
|
|
1442
1496
|
return;
|
|
1443
1497
|
}
|
|
@@ -1462,8 +1516,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1462
1516
|
event.preventDefault();
|
|
1463
1517
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1464
1518
|
assert(groupId);
|
|
1465
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1466
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1519
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1520
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1467
1521
|
assert(index !== null);
|
|
1468
1522
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1469
1523
|
const nextHandle = handles[nextIndex];
|
|
@@ -1476,7 +1530,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1476
1530
|
return () => {
|
|
1477
1531
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1478
1532
|
};
|
|
1479
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1533
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1480
1534
|
}
|
|
1481
1535
|
|
|
1482
1536
|
function PanelResizeHandle({
|
|
@@ -1509,7 +1563,8 @@ function PanelResizeHandle({
|
|
|
1509
1563
|
groupId,
|
|
1510
1564
|
registerResizeHandle,
|
|
1511
1565
|
startDragging,
|
|
1512
|
-
stopDragging
|
|
1566
|
+
stopDragging,
|
|
1567
|
+
panelGroupElement
|
|
1513
1568
|
} = panelGroupContext;
|
|
1514
1569
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1515
1570
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1568,7 +1623,8 @@ function PanelResizeHandle({
|
|
|
1568
1623
|
useWindowSplitterResizeHandlerBehavior({
|
|
1569
1624
|
disabled,
|
|
1570
1625
|
handleId: resizeHandleId,
|
|
1571
|
-
resizeHandler
|
|
1626
|
+
resizeHandler,
|
|
1627
|
+
panelGroupElement
|
|
1572
1628
|
});
|
|
1573
1629
|
const style = {
|
|
1574
1630
|
cursor: getCursorStyle(direction),
|
|
@@ -1624,60 +1680,22 @@ function PanelResizeHandle({
|
|
|
1624
1680
|
}
|
|
1625
1681
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1626
1682
|
|
|
1627
|
-
function
|
|
1628
|
-
const
|
|
1629
|
-
if (panelGroupElement == null) {
|
|
1630
|
-
return NaN;
|
|
1631
|
-
}
|
|
1632
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1633
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1634
|
-
if (direction === "horizontal") {
|
|
1635
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1636
|
-
return accumulated + handle.offsetWidth;
|
|
1637
|
-
}, 0);
|
|
1638
|
-
} else {
|
|
1639
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1640
|
-
return accumulated + handle.offsetHeight;
|
|
1641
|
-
}, 0);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1646
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1647
|
-
if (panelGroupElement == null) {
|
|
1648
|
-
return NaN;
|
|
1649
|
-
}
|
|
1650
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1651
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1652
|
-
if (direction === "horizontal") {
|
|
1653
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1654
|
-
return accumulated + handle.offsetWidth;
|
|
1655
|
-
}, 0);
|
|
1656
|
-
} else {
|
|
1657
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1658
|
-
return accumulated + handle.offsetHeight;
|
|
1659
|
-
}, 0);
|
|
1660
|
-
}
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
function getPanelElement(id) {
|
|
1664
|
-
const element = document.querySelector(`[data-panel-id="${id}"]`);
|
|
1683
|
+
function getPanelElement(id, scope = document) {
|
|
1684
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1665
1685
|
if (element) {
|
|
1666
1686
|
return element;
|
|
1667
1687
|
}
|
|
1668
1688
|
return null;
|
|
1669
1689
|
}
|
|
1670
1690
|
|
|
1671
|
-
function getPanelElementsForGroup(groupId) {
|
|
1672
|
-
return Array.from(
|
|
1691
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1692
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1673
1693
|
}
|
|
1674
1694
|
|
|
1675
1695
|
exports.Panel = Panel;
|
|
1676
1696
|
exports.PanelGroup = PanelGroup;
|
|
1677
1697
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1678
1698
|
exports.assert = assert;
|
|
1679
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1680
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1681
1699
|
exports.getPanelElement = getPanelElement;
|
|
1682
1700
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1683
1701
|
exports.getPanelGroupElement = getPanelGroupElement;
|