react-resizable-panels 1.0.6 → 1.0.8
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 +10 -0
- package/README.md +20 -4
- package/dist/declarations/src/Panel.d.ts +6 -6
- package/dist/declarations/src/PanelGroup.d.ts +5 -5
- package/dist/declarations/src/PanelResizeHandle.d.ts +4 -4
- package/dist/declarations/src/utils/dom/calculateAvailablePanelSizeInPixels.d.ts +1 -1
- package/dist/declarations/src/utils/dom/getAvailableGroupSizePixels.d.ts +1 -1
- 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 +82 -59
- package/dist/react-resizable-panels.browser.development.cjs.js +84 -60
- package/dist/react-resizable-panels.browser.development.esm.js +84 -60
- package/dist/react-resizable-panels.browser.esm.js +82 -59
- package/dist/react-resizable-panels.cjs.js +82 -59
- package/dist/react-resizable-panels.development.cjs.js +84 -60
- package/dist/react-resizable-panels.development.esm.js +84 -60
- package/dist/react-resizable-panels.development.node.cjs.js +79 -58
- package/dist/react-resizable-panels.development.node.esm.js +79 -58
- package/dist/react-resizable-panels.esm.js +82 -59
- package/dist/react-resizable-panels.node.cjs.js +77 -57
- package/dist/react-resizable-panels.node.esm.js +77 -57
- package/package.json +1 -1
- package/src/Panel.test.tsx +3 -2
- package/src/Panel.ts +7 -4
- package/src/PanelGroup.test.tsx +3 -2
- package/src/PanelGroup.ts +53 -30
- package/src/PanelGroupContext.ts +4 -2
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +17 -12
- package/src/hooks/useWindowSplitterBehavior.ts +15 -6
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +23 -7
- 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/calculateAvailablePanelSizeInPixels.ts +8 -3
- package/src/utils/dom/getAvailableGroupSizePixels.ts +8 -7
- package/src/utils/dom/getPanelElement.ts +6 -3
- package/src/utils/dom/getPanelElementsForGroup.ts +7 -2
- package/src/utils/dom/getPanelGroupElement.ts +15 -3
- package/src/utils/dom/getResizeHandleElement.ts +6 -3
- package/src/utils/dom/getResizeHandleElementIndex.ts +3 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +4 -3
- 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
|
@@ -465,41 +465,48 @@ function adjustLayoutByDelta({
|
|
|
465
465
|
return nextLayout;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
function getResizeHandleElementsForGroup(groupId) {
|
|
469
|
-
return Array.from(
|
|
468
|
+
function getResizeHandleElementsForGroup(groupId, panelGroupElement) {
|
|
469
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
-
function getResizeHandleElementIndex(groupId, id) {
|
|
473
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
472
|
+
function getResizeHandleElementIndex(groupId, id, panelGroupElement) {
|
|
473
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
474
474
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
475
475
|
return index !== null && index !== void 0 ? index : null;
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
function determinePivotIndices(groupId, dragHandleId) {
|
|
479
|
-
const index = getResizeHandleElementIndex(groupId, dragHandleId);
|
|
478
|
+
function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
479
|
+
const index = getResizeHandleElementIndex(groupId, dragHandleId, panelGroupElement);
|
|
480
480
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
481
481
|
}
|
|
482
482
|
|
|
483
|
-
function getPanelGroupElement(id) {
|
|
484
|
-
|
|
483
|
+
function getPanelGroupElement(id, rootElement) {
|
|
484
|
+
var _dataset;
|
|
485
|
+
//If the root element is the PanelGroup
|
|
486
|
+
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
487
|
+
return rootElement;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
//Else query children
|
|
491
|
+
const element = rootElement.querySelector(`[data-panel-group][data-panel-group-id="${id}"]`);
|
|
485
492
|
if (element) {
|
|
486
493
|
return element;
|
|
487
494
|
}
|
|
488
495
|
return null;
|
|
489
496
|
}
|
|
490
497
|
|
|
491
|
-
function getResizeHandleElement(id) {
|
|
492
|
-
const element =
|
|
498
|
+
function getResizeHandleElement(id, panelGroupElement) {
|
|
499
|
+
const element = panelGroupElement.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
493
500
|
if (element) {
|
|
494
501
|
return element;
|
|
495
502
|
}
|
|
496
503
|
return null;
|
|
497
504
|
}
|
|
498
505
|
|
|
499
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
506
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, panelGroupElement) {
|
|
500
507
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
501
|
-
const handle = getResizeHandleElement(handleId);
|
|
502
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
508
|
+
const handle = getResizeHandleElement(handleId, panelGroupElement);
|
|
509
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
503
510
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
504
511
|
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;
|
|
505
512
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -514,25 +521,29 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
514
521
|
groupId,
|
|
515
522
|
layout,
|
|
516
523
|
panelDataArray,
|
|
524
|
+
panelGroupElement,
|
|
517
525
|
setLayout
|
|
518
526
|
}) {
|
|
519
527
|
useRef({
|
|
520
528
|
didWarnAboutMissingResizeHandle: false
|
|
521
529
|
});
|
|
522
530
|
useEffect(() => {
|
|
531
|
+
if (!panelGroupElement) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
523
534
|
const eagerValues = eagerValuesRef.current;
|
|
524
535
|
assert(eagerValues);
|
|
525
536
|
const {
|
|
526
537
|
panelDataArray
|
|
527
538
|
} = eagerValues;
|
|
528
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
539
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
529
540
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
530
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
541
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
531
542
|
assert(handles);
|
|
532
543
|
const cleanupFunctions = handles.map(handle => {
|
|
533
544
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
534
545
|
assert(handleId);
|
|
535
|
-
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray);
|
|
546
|
+
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
536
547
|
if (idBefore == null || idAfter == null) {
|
|
537
548
|
return () => {};
|
|
538
549
|
}
|
|
@@ -559,7 +570,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
559
570
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
560
571
|
layout,
|
|
561
572
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
562
|
-
pivotIndices: determinePivotIndices(groupId, handleId),
|
|
573
|
+
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
563
574
|
trigger: "keyboard"
|
|
564
575
|
});
|
|
565
576
|
if (layout !== nextLayout) {
|
|
@@ -579,7 +590,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
579
590
|
return () => {
|
|
580
591
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
581
592
|
};
|
|
582
|
-
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
593
|
+
}, [panelGroupElement, committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
583
594
|
}
|
|
584
595
|
|
|
585
596
|
function areEqual(arrayA, arrayB) {
|
|
@@ -617,9 +628,9 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
617
628
|
}
|
|
618
629
|
}
|
|
619
630
|
|
|
620
|
-
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState) {
|
|
631
|
+
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
621
632
|
const isHorizontal = direction === "horizontal";
|
|
622
|
-
const handleElement = getResizeHandleElement(dragHandleId);
|
|
633
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
623
634
|
assert(handleElement);
|
|
624
635
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
625
636
|
assert(groupId);
|
|
@@ -627,7 +638,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
627
638
|
initialCursorPosition
|
|
628
639
|
} = initialDragState;
|
|
629
640
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
630
|
-
const groupElement = getPanelGroupElement(groupId);
|
|
641
|
+
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
631
642
|
assert(groupElement);
|
|
632
643
|
const groupRect = groupElement.getBoundingClientRect();
|
|
633
644
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
@@ -637,7 +648,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
637
648
|
}
|
|
638
649
|
|
|
639
650
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
640
|
-
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy) {
|
|
651
|
+
function calculateDeltaPercentage(event, dragHandleId, direction, initialDragState, keyboardResizeBy, panelGroupElement) {
|
|
641
652
|
if (isKeyDown(event)) {
|
|
642
653
|
const isHorizontal = direction === "horizontal";
|
|
643
654
|
let delta = 0;
|
|
@@ -674,7 +685,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
674
685
|
if (initialDragState == null) {
|
|
675
686
|
return 0;
|
|
676
687
|
}
|
|
677
|
-
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState);
|
|
688
|
+
return calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement);
|
|
678
689
|
}
|
|
679
690
|
}
|
|
680
691
|
|
|
@@ -901,6 +912,7 @@ function validatePanelConstraints({
|
|
|
901
912
|
assert(panelConstraints);
|
|
902
913
|
const {
|
|
903
914
|
collapsedSize = 0,
|
|
915
|
+
collapsible = false,
|
|
904
916
|
defaultSize,
|
|
905
917
|
maxSize = 100,
|
|
906
918
|
minSize = 0
|
|
@@ -911,7 +923,7 @@ function validatePanelConstraints({
|
|
|
911
923
|
if (defaultSize != null) {
|
|
912
924
|
if (defaultSize < 0) {
|
|
913
925
|
warnings.push("default size should not be less than 0");
|
|
914
|
-
} else if (defaultSize < minSize) {
|
|
926
|
+
} else if (defaultSize < minSize && (!collapsible || defaultSize !== collapsedSize)) {
|
|
915
927
|
warnings.push("default size should not be less than min size");
|
|
916
928
|
}
|
|
917
929
|
if (defaultSize > 100) {
|
|
@@ -1026,6 +1038,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1026
1038
|
...rest
|
|
1027
1039
|
}) {
|
|
1028
1040
|
const groupId = useUniqueId(idFromProps);
|
|
1041
|
+
const panelGroupElementRef = useRef(null);
|
|
1029
1042
|
const [dragState, setDragState] = useState(null);
|
|
1030
1043
|
const [layout, setLayout] = useState([]);
|
|
1031
1044
|
const panelIdToLastNotifiedSizeMapRef = useRef({});
|
|
@@ -1086,7 +1099,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1086
1099
|
groupId,
|
|
1087
1100
|
layout,
|
|
1088
1101
|
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1089
|
-
setLayout
|
|
1102
|
+
setLayout,
|
|
1103
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1090
1104
|
});
|
|
1091
1105
|
useEffect(() => {
|
|
1092
1106
|
const {
|
|
@@ -1323,6 +1337,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1323
1337
|
const registerResizeHandle = useCallback(dragHandleId => {
|
|
1324
1338
|
return function resizeHandler(event) {
|
|
1325
1339
|
event.preventDefault();
|
|
1340
|
+
const panelGroupElement = panelGroupElementRef.current;
|
|
1341
|
+
if (!panelGroupElement) {
|
|
1342
|
+
return () => null;
|
|
1343
|
+
}
|
|
1326
1344
|
const {
|
|
1327
1345
|
direction,
|
|
1328
1346
|
dragState,
|
|
@@ -1337,8 +1355,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1337
1355
|
const {
|
|
1338
1356
|
initialLayout
|
|
1339
1357
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
1340
|
-
const pivotIndices = determinePivotIndices(groupId, dragHandleId);
|
|
1341
|
-
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy);
|
|
1358
|
+
const pivotIndices = determinePivotIndices(groupId, dragHandleId, panelGroupElement);
|
|
1359
|
+
let delta = calculateDeltaPercentage(event, dragHandleId, direction, dragState, keyboardResizeBy, panelGroupElement);
|
|
1342
1360
|
if (delta === 0) {
|
|
1343
1361
|
return;
|
|
1344
1362
|
}
|
|
@@ -1433,7 +1451,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1433
1451
|
const {
|
|
1434
1452
|
layout
|
|
1435
1453
|
} = eagerValuesRef.current;
|
|
1436
|
-
|
|
1454
|
+
if (!panelGroupElementRef.current) {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1437
1458
|
assert(handleElement);
|
|
1438
1459
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1439
1460
|
setDragState({
|
|
@@ -1478,7 +1499,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1478
1499
|
resizePanel,
|
|
1479
1500
|
startDragging,
|
|
1480
1501
|
stopDragging,
|
|
1481
|
-
unregisterPanel
|
|
1502
|
+
unregisterPanel,
|
|
1503
|
+
panelGroupElement: panelGroupElementRef.current
|
|
1482
1504
|
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1483
1505
|
const style = {
|
|
1484
1506
|
display: "flex",
|
|
@@ -1497,6 +1519,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1497
1519
|
...style,
|
|
1498
1520
|
...styleFromProps
|
|
1499
1521
|
},
|
|
1522
|
+
ref: panelGroupElementRef,
|
|
1500
1523
|
// CSS selectors
|
|
1501
1524
|
"data-panel-group": "",
|
|
1502
1525
|
"data-panel-group-direction": direction,
|
|
@@ -1531,13 +1554,14 @@ function panelDataHelper(panelDataArray, panelData, layout) {
|
|
|
1531
1554
|
function useWindowSplitterResizeHandlerBehavior({
|
|
1532
1555
|
disabled,
|
|
1533
1556
|
handleId,
|
|
1534
|
-
resizeHandler
|
|
1557
|
+
resizeHandler,
|
|
1558
|
+
panelGroupElement
|
|
1535
1559
|
}) {
|
|
1536
1560
|
useEffect(() => {
|
|
1537
|
-
if (disabled || resizeHandler == null) {
|
|
1561
|
+
if (disabled || resizeHandler == null || panelGroupElement == null) {
|
|
1538
1562
|
return;
|
|
1539
1563
|
}
|
|
1540
|
-
const handleElement = getResizeHandleElement(handleId);
|
|
1564
|
+
const handleElement = getResizeHandleElement(handleId, panelGroupElement);
|
|
1541
1565
|
if (handleElement == null) {
|
|
1542
1566
|
return;
|
|
1543
1567
|
}
|
|
@@ -1562,8 +1586,8 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1562
1586
|
event.preventDefault();
|
|
1563
1587
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1564
1588
|
assert(groupId);
|
|
1565
|
-
const handles = getResizeHandleElementsForGroup(groupId);
|
|
1566
|
-
const index = getResizeHandleElementIndex(groupId, handleId);
|
|
1589
|
+
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1590
|
+
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1567
1591
|
assert(index !== null);
|
|
1568
1592
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1569
1593
|
const nextHandle = handles[nextIndex];
|
|
@@ -1576,7 +1600,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1576
1600
|
return () => {
|
|
1577
1601
|
handleElement.removeEventListener("keydown", onKeyDown);
|
|
1578
1602
|
};
|
|
1579
|
-
}, [disabled, handleId, resizeHandler]);
|
|
1603
|
+
}, [panelGroupElement, disabled, handleId, resizeHandler]);
|
|
1580
1604
|
}
|
|
1581
1605
|
|
|
1582
1606
|
function PanelResizeHandle({
|
|
@@ -1590,7 +1614,7 @@ function PanelResizeHandle({
|
|
|
1590
1614
|
tagName: Type = "div",
|
|
1591
1615
|
...rest
|
|
1592
1616
|
}) {
|
|
1593
|
-
const
|
|
1617
|
+
const elementRef = useRef(null);
|
|
1594
1618
|
|
|
1595
1619
|
// Use a ref to guard against users passing inline props
|
|
1596
1620
|
const callbacksRef = useRef({
|
|
@@ -1609,7 +1633,8 @@ function PanelResizeHandle({
|
|
|
1609
1633
|
groupId,
|
|
1610
1634
|
registerResizeHandle,
|
|
1611
1635
|
startDragging,
|
|
1612
|
-
stopDragging
|
|
1636
|
+
stopDragging,
|
|
1637
|
+
panelGroupElement
|
|
1613
1638
|
} = panelGroupContext;
|
|
1614
1639
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1615
1640
|
const isDragging = (dragState === null || dragState === void 0 ? void 0 : dragState.dragHandleId) === resizeHandleId;
|
|
@@ -1618,9 +1643,9 @@ function PanelResizeHandle({
|
|
|
1618
1643
|
const stopDraggingAndBlur = useCallback(() => {
|
|
1619
1644
|
// Clicking on the drag handle shouldn't leave it focused;
|
|
1620
1645
|
// That would cause the PanelGroup to think it was still active.
|
|
1621
|
-
const
|
|
1622
|
-
assert(
|
|
1623
|
-
|
|
1646
|
+
const element = elementRef.current;
|
|
1647
|
+
assert(element);
|
|
1648
|
+
element.blur();
|
|
1624
1649
|
stopDragging();
|
|
1625
1650
|
const {
|
|
1626
1651
|
onDragging
|
|
@@ -1647,9 +1672,9 @@ function PanelResizeHandle({
|
|
|
1647
1672
|
const onMouseLeave = event => {
|
|
1648
1673
|
resizeHandler(event);
|
|
1649
1674
|
};
|
|
1650
|
-
const
|
|
1651
|
-
assert(
|
|
1652
|
-
const targetDocument =
|
|
1675
|
+
const element = elementRef.current;
|
|
1676
|
+
assert(element);
|
|
1677
|
+
const targetDocument = element.ownerDocument;
|
|
1653
1678
|
targetDocument.body.addEventListener("contextmenu", stopDraggingAndBlur);
|
|
1654
1679
|
targetDocument.body.addEventListener("mousemove", onMove);
|
|
1655
1680
|
targetDocument.body.addEventListener("touchmove", onMove);
|
|
@@ -1668,7 +1693,8 @@ function PanelResizeHandle({
|
|
|
1668
1693
|
useWindowSplitterResizeHandlerBehavior({
|
|
1669
1694
|
disabled,
|
|
1670
1695
|
handleId: resizeHandleId,
|
|
1671
|
-
resizeHandler
|
|
1696
|
+
resizeHandler,
|
|
1697
|
+
panelGroupElement
|
|
1672
1698
|
});
|
|
1673
1699
|
const style = {
|
|
1674
1700
|
cursor: getCursorStyle(direction),
|
|
@@ -1706,7 +1732,7 @@ function PanelResizeHandle({
|
|
|
1706
1732
|
onDragging(true);
|
|
1707
1733
|
}
|
|
1708
1734
|
},
|
|
1709
|
-
ref:
|
|
1735
|
+
ref: elementRef,
|
|
1710
1736
|
role: "separator",
|
|
1711
1737
|
style: {
|
|
1712
1738
|
...style,
|
|
@@ -1724,13 +1750,12 @@ function PanelResizeHandle({
|
|
|
1724
1750
|
}
|
|
1725
1751
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1726
1752
|
|
|
1727
|
-
function calculateAvailablePanelSizeInPixels(groupId) {
|
|
1728
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1753
|
+
function calculateAvailablePanelSizeInPixels(groupId, panelGroupElement) {
|
|
1729
1754
|
if (panelGroupElement == null) {
|
|
1730
1755
|
return NaN;
|
|
1731
1756
|
}
|
|
1732
1757
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1733
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1758
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1734
1759
|
if (direction === "horizontal") {
|
|
1735
1760
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1736
1761
|
return accumulated + handle.offsetWidth;
|
|
@@ -1742,13 +1767,9 @@ function calculateAvailablePanelSizeInPixels(groupId) {
|
|
|
1742
1767
|
}
|
|
1743
1768
|
}
|
|
1744
1769
|
|
|
1745
|
-
function getAvailableGroupSizePixels(groupId) {
|
|
1746
|
-
const panelGroupElement = getPanelGroupElement(groupId);
|
|
1747
|
-
if (panelGroupElement == null) {
|
|
1748
|
-
return NaN;
|
|
1749
|
-
}
|
|
1770
|
+
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1750
1771
|
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1751
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId);
|
|
1772
|
+
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1752
1773
|
if (direction === "horizontal") {
|
|
1753
1774
|
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1754
1775
|
return accumulated + handle.offsetWidth;
|
|
@@ -1760,16 +1781,16 @@ function getAvailableGroupSizePixels(groupId) {
|
|
|
1760
1781
|
}
|
|
1761
1782
|
}
|
|
1762
1783
|
|
|
1763
|
-
function getPanelElement(id) {
|
|
1764
|
-
const element =
|
|
1784
|
+
function getPanelElement(id, panelGroupElement) {
|
|
1785
|
+
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1765
1786
|
if (element) {
|
|
1766
1787
|
return element;
|
|
1767
1788
|
}
|
|
1768
1789
|
return null;
|
|
1769
1790
|
}
|
|
1770
1791
|
|
|
1771
|
-
function getPanelElementsForGroup(groupId) {
|
|
1772
|
-
return Array.from(
|
|
1792
|
+
function getPanelElementsForGroup(groupId, panelGroupElement) {
|
|
1793
|
+
return Array.from(panelGroupElement.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1773
1794
|
}
|
|
1774
1795
|
|
|
1775
1796
|
exports.Panel = Panel;
|