react-resizable-panels 1.0.8 → 1.0.10
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 +9 -0
- package/README.md +16 -15
- 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/react-resizable-panels.browser.cjs.js +56 -51
- package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.cjs.js +56 -51
- package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.esm.js +57 -50
- package/dist/react-resizable-panels.browser.esm.js +57 -50
- package/dist/react-resizable-panels.cjs.js +56 -51
- package/dist/react-resizable-panels.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.cjs.js +56 -51
- package/dist/react-resizable-panels.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.esm.js +57 -50
- package/dist/react-resizable-panels.development.node.cjs.js +47 -51
- package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.node.esm.js +48 -50
- package/dist/react-resizable-panels.esm.js +57 -50
- package/dist/react-resizable-panels.node.cjs.js +47 -51
- package/dist/react-resizable-panels.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.node.esm.js +48 -50
- package/package.json +1 -1
- package/src/Panel.test.tsx +186 -0
- package/src/Panel.ts +14 -0
- package/src/PanelGroup.ts +46 -7
- package/src/PanelGroupContext.ts +5 -1
- package/src/index.ts +0 -4
- package/src/utils/dom/getPanelElement.ts +2 -2
- package/src/utils/dom/getPanelElementsForGroup.ts +2 -4
- package/src/utils/dom/getPanelGroupElement.ts +1 -1
- package/src/utils/dom/getResizeHandleElement.ts +2 -4
- package/src/utils/dom/getResizeHandleElementIndex.ts +2 -2
- package/src/utils/dom/getResizeHandleElementsForGroup.ts +2 -2
- package/src/utils/dom/getResizeHandlePanelIds.ts +3 -3
- 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 -34
- package/src/utils/dom/getAvailableGroupSizePixels.ts +0 -30
|
@@ -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,12 +442,12 @@ 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
|
}
|
|
@@ -456,7 +457,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
456
457
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
457
458
|
}
|
|
458
459
|
|
|
459
|
-
function getPanelGroupElement(id, rootElement) {
|
|
460
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
460
461
|
var _dataset;
|
|
461
462
|
//If the root element is the PanelGroup
|
|
462
463
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -471,18 +472,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
471
472
|
return null;
|
|
472
473
|
}
|
|
473
474
|
|
|
474
|
-
function getResizeHandleElement(id,
|
|
475
|
-
const element =
|
|
475
|
+
function getResizeHandleElement(id, scope = document) {
|
|
476
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
476
477
|
if (element) {
|
|
477
478
|
return element;
|
|
478
479
|
}
|
|
479
480
|
return null;
|
|
480
481
|
}
|
|
481
482
|
|
|
482
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
483
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
483
484
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
484
|
-
const handle = getResizeHandleElement(handleId,
|
|
485
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
485
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
486
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
486
487
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
487
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;
|
|
488
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;
|
|
@@ -1420,6 +1421,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1420
1421
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1421
1422
|
}
|
|
1422
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
|
+
} = prevConstraints;
|
|
1433
|
+
const {
|
|
1434
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1435
|
+
collapsible: nextCollapsible,
|
|
1436
|
+
maxSize: nextMaxSize = 100,
|
|
1437
|
+
minSize: nextMinSize = 0
|
|
1438
|
+
} = panelData.constraints;
|
|
1439
|
+
const {
|
|
1440
|
+
panelSize: prevPanelSize
|
|
1441
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1442
|
+
assert(prevPanelSize != null);
|
|
1443
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1444
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1445
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1446
|
+
}
|
|
1447
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1448
|
+
resizePanel(panelData, nextMinSize);
|
|
1449
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1450
|
+
resizePanel(panelData, nextMaxSize);
|
|
1451
|
+
}
|
|
1452
|
+
}, [resizePanel]);
|
|
1423
1453
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1424
1454
|
const {
|
|
1425
1455
|
direction
|
|
@@ -1470,6 +1500,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1470
1500
|
groupId,
|
|
1471
1501
|
isPanelCollapsed,
|
|
1472
1502
|
isPanelExpanded,
|
|
1503
|
+
reevaluatePanelConstraints,
|
|
1473
1504
|
registerPanel,
|
|
1474
1505
|
registerResizeHandle,
|
|
1475
1506
|
resizePanel,
|
|
@@ -1477,7 +1508,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1477
1508
|
stopDragging,
|
|
1478
1509
|
unregisterPanel,
|
|
1479
1510
|
panelGroupElement: panelGroupElementRef.current
|
|
1480
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1511
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1481
1512
|
const style = {
|
|
1482
1513
|
display: "flex",
|
|
1483
1514
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1512,14 +1543,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1512
1543
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1513
1544
|
}
|
|
1514
1545
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1515
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1516
1546
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1517
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1518
1547
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1519
1548
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1520
1549
|
const panelSize = layout[panelIndex];
|
|
1521
1550
|
return {
|
|
1522
|
-
...
|
|
1551
|
+
...panelData.constraints,
|
|
1523
1552
|
panelSize,
|
|
1524
1553
|
pivotIndices
|
|
1525
1554
|
};
|
|
@@ -1726,47 +1755,16 @@ function PanelResizeHandle({
|
|
|
1726
1755
|
}
|
|
1727
1756
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1728
1757
|
|
|
1729
|
-
function
|
|
1730
|
-
|
|
1731
|
-
return NaN;
|
|
1732
|
-
}
|
|
1733
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1734
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1735
|
-
if (direction === "horizontal") {
|
|
1736
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1737
|
-
return accumulated + handle.offsetWidth;
|
|
1738
|
-
}, 0);
|
|
1739
|
-
} else {
|
|
1740
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1741
|
-
return accumulated + handle.offsetHeight;
|
|
1742
|
-
}, 0);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1747
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1748
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1749
|
-
if (direction === "horizontal") {
|
|
1750
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1751
|
-
return accumulated + handle.offsetWidth;
|
|
1752
|
-
}, 0);
|
|
1753
|
-
} else {
|
|
1754
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1755
|
-
return accumulated + handle.offsetHeight;
|
|
1756
|
-
}, 0);
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1761
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1758
|
+
function getPanelElement(id, scope = document) {
|
|
1759
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1762
1760
|
if (element) {
|
|
1763
1761
|
return element;
|
|
1764
1762
|
}
|
|
1765
1763
|
return null;
|
|
1766
1764
|
}
|
|
1767
1765
|
|
|
1768
|
-
function getPanelElementsForGroup(groupId,
|
|
1769
|
-
return Array.from(
|
|
1766
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1767
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1770
1768
|
}
|
|
1771
1769
|
|
|
1772
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1770
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -69,6 +69,7 @@ function PanelWithForwardedRef({
|
|
|
69
69
|
getPanelStyle,
|
|
70
70
|
groupId,
|
|
71
71
|
isPanelCollapsed,
|
|
72
|
+
reevaluatePanelConstraints,
|
|
72
73
|
registerPanel,
|
|
73
74
|
resizePanel,
|
|
74
75
|
unregisterPanel
|
|
@@ -99,6 +100,9 @@ function PanelWithForwardedRef({
|
|
|
99
100
|
callbacks,
|
|
100
101
|
constraints
|
|
101
102
|
} = panelDataRef.current;
|
|
103
|
+
const prevConstraints = {
|
|
104
|
+
...constraints
|
|
105
|
+
};
|
|
102
106
|
panelDataRef.current.id = panelId;
|
|
103
107
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
104
108
|
panelDataRef.current.order = order;
|
|
@@ -110,6 +114,12 @@ function PanelWithForwardedRef({
|
|
|
110
114
|
constraints.defaultSize = defaultSize;
|
|
111
115
|
constraints.maxSize = maxSize;
|
|
112
116
|
constraints.minSize = minSize;
|
|
117
|
+
|
|
118
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
119
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
120
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
121
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
122
|
+
}
|
|
113
123
|
});
|
|
114
124
|
useIsomorphicLayoutEffect(() => {
|
|
115
125
|
const panelData = panelDataRef.current;
|
|
@@ -497,12 +507,12 @@ function calculateAriaValues({
|
|
|
497
507
|
};
|
|
498
508
|
}
|
|
499
509
|
|
|
500
|
-
function getResizeHandleElementsForGroup(groupId,
|
|
501
|
-
return Array.from(
|
|
510
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
511
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
502
512
|
}
|
|
503
513
|
|
|
504
|
-
function getResizeHandleElementIndex(groupId, id,
|
|
505
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
514
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
515
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
506
516
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
507
517
|
return index !== null && index !== void 0 ? index : null;
|
|
508
518
|
}
|
|
@@ -512,7 +522,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
512
522
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
513
523
|
}
|
|
514
524
|
|
|
515
|
-
function getPanelGroupElement(id, rootElement) {
|
|
525
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
516
526
|
var _dataset;
|
|
517
527
|
//If the root element is the PanelGroup
|
|
518
528
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -527,18 +537,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
527
537
|
return null;
|
|
528
538
|
}
|
|
529
539
|
|
|
530
|
-
function getResizeHandleElement(id,
|
|
531
|
-
const element =
|
|
540
|
+
function getResizeHandleElement(id, scope = document) {
|
|
541
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
532
542
|
if (element) {
|
|
533
543
|
return element;
|
|
534
544
|
}
|
|
535
545
|
return null;
|
|
536
546
|
}
|
|
537
547
|
|
|
538
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
548
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
539
549
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
540
|
-
const handle = getResizeHandleElement(handleId,
|
|
541
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
550
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
551
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
542
552
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
543
553
|
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;
|
|
544
554
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -1523,6 +1533,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1523
1533
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1524
1534
|
}
|
|
1525
1535
|
}, []);
|
|
1536
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1537
|
+
const {
|
|
1538
|
+
layout,
|
|
1539
|
+
panelDataArray
|
|
1540
|
+
} = eagerValuesRef.current;
|
|
1541
|
+
const {
|
|
1542
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1543
|
+
collapsible: prevCollapsible
|
|
1544
|
+
} = prevConstraints;
|
|
1545
|
+
const {
|
|
1546
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1547
|
+
collapsible: nextCollapsible,
|
|
1548
|
+
maxSize: nextMaxSize = 100,
|
|
1549
|
+
minSize: nextMinSize = 0
|
|
1550
|
+
} = panelData.constraints;
|
|
1551
|
+
const {
|
|
1552
|
+
panelSize: prevPanelSize
|
|
1553
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1554
|
+
assert(prevPanelSize != null);
|
|
1555
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1556
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1557
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1558
|
+
}
|
|
1559
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1560
|
+
resizePanel(panelData, nextMinSize);
|
|
1561
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1562
|
+
resizePanel(panelData, nextMaxSize);
|
|
1563
|
+
}
|
|
1564
|
+
}, [resizePanel]);
|
|
1526
1565
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1527
1566
|
const {
|
|
1528
1567
|
direction
|
|
@@ -1573,6 +1612,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1573
1612
|
groupId,
|
|
1574
1613
|
isPanelCollapsed,
|
|
1575
1614
|
isPanelExpanded,
|
|
1615
|
+
reevaluatePanelConstraints,
|
|
1576
1616
|
registerPanel,
|
|
1577
1617
|
registerResizeHandle,
|
|
1578
1618
|
resizePanel,
|
|
@@ -1580,7 +1620,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1580
1620
|
stopDragging,
|
|
1581
1621
|
unregisterPanel,
|
|
1582
1622
|
panelGroupElement: panelGroupElementRef.current
|
|
1583
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1623
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1584
1624
|
const style = {
|
|
1585
1625
|
display: "flex",
|
|
1586
1626
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1615,14 +1655,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1615
1655
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1616
1656
|
}
|
|
1617
1657
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1618
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1619
1658
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1620
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1621
1659
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1622
1660
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1623
1661
|
const panelSize = layout[panelIndex];
|
|
1624
1662
|
return {
|
|
1625
|
-
...
|
|
1663
|
+
...panelData.constraints,
|
|
1626
1664
|
panelSize,
|
|
1627
1665
|
pivotIndices
|
|
1628
1666
|
};
|
|
@@ -1829,47 +1867,16 @@ function PanelResizeHandle({
|
|
|
1829
1867
|
}
|
|
1830
1868
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1831
1869
|
|
|
1832
|
-
function
|
|
1833
|
-
|
|
1834
|
-
return NaN;
|
|
1835
|
-
}
|
|
1836
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1837
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1838
|
-
if (direction === "horizontal") {
|
|
1839
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1840
|
-
return accumulated + handle.offsetWidth;
|
|
1841
|
-
}, 0);
|
|
1842
|
-
} else {
|
|
1843
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1844
|
-
return accumulated + handle.offsetHeight;
|
|
1845
|
-
}, 0);
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1850
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1851
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1852
|
-
if (direction === "horizontal") {
|
|
1853
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1854
|
-
return accumulated + handle.offsetWidth;
|
|
1855
|
-
}, 0);
|
|
1856
|
-
} else {
|
|
1857
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1858
|
-
return accumulated + handle.offsetHeight;
|
|
1859
|
-
}, 0);
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1864
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1870
|
+
function getPanelElement(id, scope = document) {
|
|
1871
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1865
1872
|
if (element) {
|
|
1866
1873
|
return element;
|
|
1867
1874
|
}
|
|
1868
1875
|
return null;
|
|
1869
1876
|
}
|
|
1870
1877
|
|
|
1871
|
-
function getPanelElementsForGroup(groupId,
|
|
1872
|
-
return Array.from(
|
|
1878
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1879
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1873
1880
|
}
|
|
1874
1881
|
|
|
1875
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1882
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -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,12 +455,12 @@ 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
|
}
|
|
@@ -469,7 +470,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
469
470
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
470
471
|
}
|
|
471
472
|
|
|
472
|
-
function getPanelGroupElement(id, rootElement) {
|
|
473
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
473
474
|
var _dataset;
|
|
474
475
|
//If the root element is the PanelGroup
|
|
475
476
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -484,18 +485,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
484
485
|
return null;
|
|
485
486
|
}
|
|
486
487
|
|
|
487
|
-
function getResizeHandleElement(id,
|
|
488
|
-
const element =
|
|
488
|
+
function getResizeHandleElement(id, scope = document) {
|
|
489
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
489
490
|
if (element) {
|
|
490
491
|
return element;
|
|
491
492
|
}
|
|
492
493
|
return null;
|
|
493
494
|
}
|
|
494
495
|
|
|
495
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
496
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
496
497
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
497
|
-
const handle = getResizeHandleElement(handleId,
|
|
498
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
498
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
499
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
499
500
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
500
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;
|
|
501
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;
|
|
@@ -1343,6 +1344,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1343
1344
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1344
1345
|
}
|
|
1345
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
|
+
} = prevConstraints;
|
|
1356
|
+
const {
|
|
1357
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1358
|
+
collapsible: nextCollapsible,
|
|
1359
|
+
maxSize: nextMaxSize = 100,
|
|
1360
|
+
minSize: nextMinSize = 0
|
|
1361
|
+
} = panelData.constraints;
|
|
1362
|
+
const {
|
|
1363
|
+
panelSize: prevPanelSize
|
|
1364
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1365
|
+
assert(prevPanelSize != null);
|
|
1366
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1367
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1368
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1369
|
+
}
|
|
1370
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1371
|
+
resizePanel(panelData, nextMinSize);
|
|
1372
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1373
|
+
resizePanel(panelData, nextMaxSize);
|
|
1374
|
+
}
|
|
1375
|
+
}, [resizePanel]);
|
|
1346
1376
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1347
1377
|
const {
|
|
1348
1378
|
direction
|
|
@@ -1393,6 +1423,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1393
1423
|
groupId,
|
|
1394
1424
|
isPanelCollapsed,
|
|
1395
1425
|
isPanelExpanded,
|
|
1426
|
+
reevaluatePanelConstraints,
|
|
1396
1427
|
registerPanel,
|
|
1397
1428
|
registerResizeHandle,
|
|
1398
1429
|
resizePanel,
|
|
@@ -1400,7 +1431,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1400
1431
|
stopDragging,
|
|
1401
1432
|
unregisterPanel,
|
|
1402
1433
|
panelGroupElement: panelGroupElementRef.current
|
|
1403
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1434
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1404
1435
|
const style = {
|
|
1405
1436
|
display: "flex",
|
|
1406
1437
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1435,14 +1466,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1435
1466
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1436
1467
|
}
|
|
1437
1468
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1438
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1439
1469
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1440
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1441
1470
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1442
1471
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1443
1472
|
const panelSize = layout[panelIndex];
|
|
1444
1473
|
return {
|
|
1445
|
-
...
|
|
1474
|
+
...panelData.constraints,
|
|
1446
1475
|
panelSize,
|
|
1447
1476
|
pivotIndices
|
|
1448
1477
|
};
|
|
@@ -1649,55 +1678,22 @@ function PanelResizeHandle({
|
|
|
1649
1678
|
}
|
|
1650
1679
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1651
1680
|
|
|
1652
|
-
function
|
|
1653
|
-
|
|
1654
|
-
return NaN;
|
|
1655
|
-
}
|
|
1656
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1657
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1658
|
-
if (direction === "horizontal") {
|
|
1659
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1660
|
-
return accumulated + handle.offsetWidth;
|
|
1661
|
-
}, 0);
|
|
1662
|
-
} else {
|
|
1663
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1664
|
-
return accumulated + handle.offsetHeight;
|
|
1665
|
-
}, 0);
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1670
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1671
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1672
|
-
if (direction === "horizontal") {
|
|
1673
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1674
|
-
return accumulated + handle.offsetWidth;
|
|
1675
|
-
}, 0);
|
|
1676
|
-
} else {
|
|
1677
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1678
|
-
return accumulated + handle.offsetHeight;
|
|
1679
|
-
}, 0);
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1684
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1681
|
+
function getPanelElement(id, scope = document) {
|
|
1682
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1685
1683
|
if (element) {
|
|
1686
1684
|
return element;
|
|
1687
1685
|
}
|
|
1688
1686
|
return null;
|
|
1689
1687
|
}
|
|
1690
1688
|
|
|
1691
|
-
function getPanelElementsForGroup(groupId,
|
|
1692
|
-
return Array.from(
|
|
1689
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1690
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1693
1691
|
}
|
|
1694
1692
|
|
|
1695
1693
|
exports.Panel = Panel;
|
|
1696
1694
|
exports.PanelGroup = PanelGroup;
|
|
1697
1695
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1698
1696
|
exports.assert = assert;
|
|
1699
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1700
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1701
1697
|
exports.getPanelElement = getPanelElement;
|
|
1702
1698
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1703
1699
|
exports.getPanelGroupElement = getPanelGroupElement;
|