react-resizable-panels 1.0.8 → 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 +5 -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 +58 -51
- package/dist/react-resizable-panels.browser.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.cjs.js +58 -51
- package/dist/react-resizable-panels.browser.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.browser.development.esm.js +59 -50
- package/dist/react-resizable-panels.browser.esm.js +59 -50
- package/dist/react-resizable-panels.cjs.js +58 -51
- package/dist/react-resizable-panels.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.cjs.js +58 -51
- package/dist/react-resizable-panels.development.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.esm.js +59 -50
- package/dist/react-resizable-panels.development.node.cjs.js +49 -51
- package/dist/react-resizable-panels.development.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.development.node.esm.js +50 -50
- package/dist/react-resizable-panels.esm.js +59 -50
- package/dist/react-resizable-panels.node.cjs.js +49 -51
- package/dist/react-resizable-panels.node.cjs.mjs +0 -2
- package/dist/react-resizable-panels.node.esm.js +50 -50
- package/package.json +1 -1
- package/src/Panel.test.tsx +134 -0
- package/src/Panel.ts +14 -0
- package/src/PanelGroup.ts +47 -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,37 @@ 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
|
+
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]);
|
|
1423
1455
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1424
1456
|
const {
|
|
1425
1457
|
direction
|
|
@@ -1470,6 +1502,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1470
1502
|
groupId,
|
|
1471
1503
|
isPanelCollapsed,
|
|
1472
1504
|
isPanelExpanded,
|
|
1505
|
+
reevaluatePanelConstraints,
|
|
1473
1506
|
registerPanel,
|
|
1474
1507
|
registerResizeHandle,
|
|
1475
1508
|
resizePanel,
|
|
@@ -1477,7 +1510,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1477
1510
|
stopDragging,
|
|
1478
1511
|
unregisterPanel,
|
|
1479
1512
|
panelGroupElement: panelGroupElementRef.current
|
|
1480
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1513
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1481
1514
|
const style = {
|
|
1482
1515
|
display: "flex",
|
|
1483
1516
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1512,14 +1545,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1512
1545
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1513
1546
|
}
|
|
1514
1547
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1515
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1516
1548
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1517
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1518
1549
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1519
1550
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1520
1551
|
const panelSize = layout[panelIndex];
|
|
1521
1552
|
return {
|
|
1522
|
-
...
|
|
1553
|
+
...panelData.constraints,
|
|
1523
1554
|
panelSize,
|
|
1524
1555
|
pivotIndices
|
|
1525
1556
|
};
|
|
@@ -1726,47 +1757,16 @@ function PanelResizeHandle({
|
|
|
1726
1757
|
}
|
|
1727
1758
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1728
1759
|
|
|
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}"]`);
|
|
1760
|
+
function getPanelElement(id, scope = document) {
|
|
1761
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1762
1762
|
if (element) {
|
|
1763
1763
|
return element;
|
|
1764
1764
|
}
|
|
1765
1765
|
return null;
|
|
1766
1766
|
}
|
|
1767
1767
|
|
|
1768
|
-
function getPanelElementsForGroup(groupId,
|
|
1769
|
-
return Array.from(
|
|
1768
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1769
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1770
1770
|
}
|
|
1771
1771
|
|
|
1772
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1772
|
+
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,37 @@ 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
|
+
defaultSize: prevDefaultSize,
|
|
1545
|
+
maxSize: prevMaxSize = 100,
|
|
1546
|
+
minSize: prevMinSize = 0
|
|
1547
|
+
} = prevConstraints;
|
|
1548
|
+
const {
|
|
1549
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1550
|
+
collapsible: nextCollapsible,
|
|
1551
|
+
defaultSize: nextDefaultSize,
|
|
1552
|
+
maxSize: nextMaxSize = 100,
|
|
1553
|
+
minSize: nextMinSize = 0
|
|
1554
|
+
} = panelData.constraints;
|
|
1555
|
+
const {
|
|
1556
|
+
panelSize: prevPanelSize
|
|
1557
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1558
|
+
assert(prevPanelSize != null);
|
|
1559
|
+
if (prevCollapsible && nextCollapsible && prevCollapsedSize !== nextCollapsedSize && prevPanelSize === prevCollapsedSize) {
|
|
1560
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1561
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1562
|
+
resizePanel(panelData, nextMinSize);
|
|
1563
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1564
|
+
resizePanel(panelData, nextMaxSize);
|
|
1565
|
+
}
|
|
1566
|
+
}, [resizePanel]);
|
|
1526
1567
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1527
1568
|
const {
|
|
1528
1569
|
direction
|
|
@@ -1573,6 +1614,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1573
1614
|
groupId,
|
|
1574
1615
|
isPanelCollapsed,
|
|
1575
1616
|
isPanelExpanded,
|
|
1617
|
+
reevaluatePanelConstraints,
|
|
1576
1618
|
registerPanel,
|
|
1577
1619
|
registerResizeHandle,
|
|
1578
1620
|
resizePanel,
|
|
@@ -1580,7 +1622,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1580
1622
|
stopDragging,
|
|
1581
1623
|
unregisterPanel,
|
|
1582
1624
|
panelGroupElement: panelGroupElementRef.current
|
|
1583
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1625
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1584
1626
|
const style = {
|
|
1585
1627
|
display: "flex",
|
|
1586
1628
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1615,14 +1657,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1615
1657
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1616
1658
|
}
|
|
1617
1659
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1618
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1619
1660
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1620
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1621
1661
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1622
1662
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1623
1663
|
const panelSize = layout[panelIndex];
|
|
1624
1664
|
return {
|
|
1625
|
-
...
|
|
1665
|
+
...panelData.constraints,
|
|
1626
1666
|
panelSize,
|
|
1627
1667
|
pivotIndices
|
|
1628
1668
|
};
|
|
@@ -1829,47 +1869,16 @@ function PanelResizeHandle({
|
|
|
1829
1869
|
}
|
|
1830
1870
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1831
1871
|
|
|
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}"]`);
|
|
1872
|
+
function getPanelElement(id, scope = document) {
|
|
1873
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1865
1874
|
if (element) {
|
|
1866
1875
|
return element;
|
|
1867
1876
|
}
|
|
1868
1877
|
return null;
|
|
1869
1878
|
}
|
|
1870
1879
|
|
|
1871
|
-
function getPanelElementsForGroup(groupId,
|
|
1872
|
-
return Array.from(
|
|
1880
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1881
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1873
1882
|
}
|
|
1874
1883
|
|
|
1875
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1884
|
+
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,37 @@ 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
|
+
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]);
|
|
1346
1378
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1347
1379
|
const {
|
|
1348
1380
|
direction
|
|
@@ -1393,6 +1425,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1393
1425
|
groupId,
|
|
1394
1426
|
isPanelCollapsed,
|
|
1395
1427
|
isPanelExpanded,
|
|
1428
|
+
reevaluatePanelConstraints,
|
|
1396
1429
|
registerPanel,
|
|
1397
1430
|
registerResizeHandle,
|
|
1398
1431
|
resizePanel,
|
|
@@ -1400,7 +1433,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1400
1433
|
stopDragging,
|
|
1401
1434
|
unregisterPanel,
|
|
1402
1435
|
panelGroupElement: panelGroupElementRef.current
|
|
1403
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1436
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1404
1437
|
const style = {
|
|
1405
1438
|
display: "flex",
|
|
1406
1439
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1435,14 +1468,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1435
1468
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1436
1469
|
}
|
|
1437
1470
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1438
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1439
1471
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1440
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1441
1472
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1442
1473
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1443
1474
|
const panelSize = layout[panelIndex];
|
|
1444
1475
|
return {
|
|
1445
|
-
...
|
|
1476
|
+
...panelData.constraints,
|
|
1446
1477
|
panelSize,
|
|
1447
1478
|
pivotIndices
|
|
1448
1479
|
};
|
|
@@ -1649,55 +1680,22 @@ function PanelResizeHandle({
|
|
|
1649
1680
|
}
|
|
1650
1681
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1651
1682
|
|
|
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}"]`);
|
|
1683
|
+
function getPanelElement(id, scope = document) {
|
|
1684
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1685
1685
|
if (element) {
|
|
1686
1686
|
return element;
|
|
1687
1687
|
}
|
|
1688
1688
|
return null;
|
|
1689
1689
|
}
|
|
1690
1690
|
|
|
1691
|
-
function getPanelElementsForGroup(groupId,
|
|
1692
|
-
return Array.from(
|
|
1691
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1692
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1693
1693
|
}
|
|
1694
1694
|
|
|
1695
1695
|
exports.Panel = Panel;
|
|
1696
1696
|
exports.PanelGroup = PanelGroup;
|
|
1697
1697
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1698
1698
|
exports.assert = assert;
|
|
1699
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1700
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1701
1699
|
exports.getPanelElement = getPanelElement;
|
|
1702
1700
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1703
1701
|
exports.getPanelGroupElement = getPanelGroupElement;
|