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
|
@@ -67,6 +67,7 @@ function PanelWithForwardedRef({
|
|
|
67
67
|
getPanelStyle,
|
|
68
68
|
groupId,
|
|
69
69
|
isPanelCollapsed,
|
|
70
|
+
reevaluatePanelConstraints,
|
|
70
71
|
registerPanel,
|
|
71
72
|
resizePanel,
|
|
72
73
|
unregisterPanel
|
|
@@ -103,6 +104,9 @@ function PanelWithForwardedRef({
|
|
|
103
104
|
callbacks,
|
|
104
105
|
constraints
|
|
105
106
|
} = panelDataRef.current;
|
|
107
|
+
const prevConstraints = {
|
|
108
|
+
...constraints
|
|
109
|
+
};
|
|
106
110
|
panelDataRef.current.id = panelId;
|
|
107
111
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
108
112
|
panelDataRef.current.order = order;
|
|
@@ -114,6 +118,12 @@ function PanelWithForwardedRef({
|
|
|
114
118
|
constraints.defaultSize = defaultSize;
|
|
115
119
|
constraints.maxSize = maxSize;
|
|
116
120
|
constraints.minSize = minSize;
|
|
121
|
+
|
|
122
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
123
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
124
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
125
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
126
|
+
}
|
|
117
127
|
});
|
|
118
128
|
useIsomorphicLayoutEffect(() => {
|
|
119
129
|
const panelData = panelDataRef.current;
|
|
@@ -501,12 +511,12 @@ function calculateAriaValues({
|
|
|
501
511
|
};
|
|
502
512
|
}
|
|
503
513
|
|
|
504
|
-
function getResizeHandleElementsForGroup(groupId,
|
|
505
|
-
return Array.from(
|
|
514
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
515
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
506
516
|
}
|
|
507
517
|
|
|
508
|
-
function getResizeHandleElementIndex(groupId, id,
|
|
509
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
518
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
519
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
510
520
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
511
521
|
return index !== null && index !== void 0 ? index : null;
|
|
512
522
|
}
|
|
@@ -516,7 +526,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
516
526
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
517
527
|
}
|
|
518
528
|
|
|
519
|
-
function getPanelGroupElement(id, rootElement) {
|
|
529
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
520
530
|
var _dataset;
|
|
521
531
|
//If the root element is the PanelGroup
|
|
522
532
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -531,18 +541,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
531
541
|
return null;
|
|
532
542
|
}
|
|
533
543
|
|
|
534
|
-
function getResizeHandleElement(id,
|
|
535
|
-
const element =
|
|
544
|
+
function getResizeHandleElement(id, scope = document) {
|
|
545
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
536
546
|
if (element) {
|
|
537
547
|
return element;
|
|
538
548
|
}
|
|
539
549
|
return null;
|
|
540
550
|
}
|
|
541
551
|
|
|
542
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
552
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
543
553
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
544
|
-
const handle = getResizeHandleElement(handleId,
|
|
545
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
554
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
555
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
546
556
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
547
557
|
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;
|
|
548
558
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -1627,6 +1637,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1627
1637
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1628
1638
|
}
|
|
1629
1639
|
}, []);
|
|
1640
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1641
|
+
const {
|
|
1642
|
+
layout,
|
|
1643
|
+
panelDataArray
|
|
1644
|
+
} = eagerValuesRef.current;
|
|
1645
|
+
const {
|
|
1646
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1647
|
+
collapsible: prevCollapsible
|
|
1648
|
+
} = prevConstraints;
|
|
1649
|
+
const {
|
|
1650
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1651
|
+
collapsible: nextCollapsible,
|
|
1652
|
+
maxSize: nextMaxSize = 100,
|
|
1653
|
+
minSize: nextMinSize = 0
|
|
1654
|
+
} = panelData.constraints;
|
|
1655
|
+
const {
|
|
1656
|
+
panelSize: prevPanelSize
|
|
1657
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1658
|
+
assert(prevPanelSize != null);
|
|
1659
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1660
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1661
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1662
|
+
}
|
|
1663
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1664
|
+
resizePanel(panelData, nextMinSize);
|
|
1665
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1666
|
+
resizePanel(panelData, nextMaxSize);
|
|
1667
|
+
}
|
|
1668
|
+
}, [resizePanel]);
|
|
1630
1669
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1631
1670
|
const {
|
|
1632
1671
|
direction
|
|
@@ -1677,6 +1716,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1677
1716
|
groupId,
|
|
1678
1717
|
isPanelCollapsed,
|
|
1679
1718
|
isPanelExpanded,
|
|
1719
|
+
reevaluatePanelConstraints,
|
|
1680
1720
|
registerPanel,
|
|
1681
1721
|
registerResizeHandle,
|
|
1682
1722
|
resizePanel,
|
|
@@ -1684,7 +1724,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1684
1724
|
stopDragging,
|
|
1685
1725
|
unregisterPanel,
|
|
1686
1726
|
panelGroupElement: panelGroupElementRef.current
|
|
1687
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1727
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1688
1728
|
const style = {
|
|
1689
1729
|
display: "flex",
|
|
1690
1730
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1719,14 +1759,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1719
1759
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1720
1760
|
}
|
|
1721
1761
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1722
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1723
1762
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1724
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1725
1763
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1726
1764
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1727
1765
|
const panelSize = layout[panelIndex];
|
|
1728
1766
|
return {
|
|
1729
|
-
...
|
|
1767
|
+
...panelData.constraints,
|
|
1730
1768
|
panelSize,
|
|
1731
1769
|
pivotIndices
|
|
1732
1770
|
};
|
|
@@ -1933,47 +1971,16 @@ function PanelResizeHandle({
|
|
|
1933
1971
|
}
|
|
1934
1972
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1935
1973
|
|
|
1936
|
-
function
|
|
1937
|
-
|
|
1938
|
-
return NaN;
|
|
1939
|
-
}
|
|
1940
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1941
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1942
|
-
if (direction === "horizontal") {
|
|
1943
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1944
|
-
return accumulated + handle.offsetWidth;
|
|
1945
|
-
}, 0);
|
|
1946
|
-
} else {
|
|
1947
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1948
|
-
return accumulated + handle.offsetHeight;
|
|
1949
|
-
}, 0);
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1954
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1955
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1956
|
-
if (direction === "horizontal") {
|
|
1957
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1958
|
-
return accumulated + handle.offsetWidth;
|
|
1959
|
-
}, 0);
|
|
1960
|
-
} else {
|
|
1961
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1962
|
-
return accumulated + handle.offsetHeight;
|
|
1963
|
-
}, 0);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
|
|
1967
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1968
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1974
|
+
function getPanelElement(id, scope = document) {
|
|
1975
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1969
1976
|
if (element) {
|
|
1970
1977
|
return element;
|
|
1971
1978
|
}
|
|
1972
1979
|
return null;
|
|
1973
1980
|
}
|
|
1974
1981
|
|
|
1975
|
-
function getPanelElementsForGroup(groupId,
|
|
1976
|
-
return Array.from(
|
|
1982
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1983
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1977
1984
|
}
|
|
1978
1985
|
|
|
1979
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1986
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -67,6 +67,7 @@ function PanelWithForwardedRef({
|
|
|
67
67
|
getPanelStyle,
|
|
68
68
|
groupId,
|
|
69
69
|
isPanelCollapsed,
|
|
70
|
+
reevaluatePanelConstraints,
|
|
70
71
|
registerPanel,
|
|
71
72
|
resizePanel,
|
|
72
73
|
unregisterPanel
|
|
@@ -97,6 +98,9 @@ function PanelWithForwardedRef({
|
|
|
97
98
|
callbacks,
|
|
98
99
|
constraints
|
|
99
100
|
} = panelDataRef.current;
|
|
101
|
+
const prevConstraints = {
|
|
102
|
+
...constraints
|
|
103
|
+
};
|
|
100
104
|
panelDataRef.current.id = panelId;
|
|
101
105
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
102
106
|
panelDataRef.current.order = order;
|
|
@@ -108,6 +112,12 @@ function PanelWithForwardedRef({
|
|
|
108
112
|
constraints.defaultSize = defaultSize;
|
|
109
113
|
constraints.maxSize = maxSize;
|
|
110
114
|
constraints.minSize = minSize;
|
|
115
|
+
|
|
116
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
117
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
118
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
119
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
120
|
+
}
|
|
111
121
|
});
|
|
112
122
|
useIsomorphicLayoutEffect(() => {
|
|
113
123
|
const panelData = panelDataRef.current;
|
|
@@ -495,12 +505,12 @@ function calculateAriaValues({
|
|
|
495
505
|
};
|
|
496
506
|
}
|
|
497
507
|
|
|
498
|
-
function getResizeHandleElementsForGroup(groupId,
|
|
499
|
-
return Array.from(
|
|
508
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
509
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
500
510
|
}
|
|
501
511
|
|
|
502
|
-
function getResizeHandleElementIndex(groupId, id,
|
|
503
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
512
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
513
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
504
514
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
505
515
|
return index !== null && index !== void 0 ? index : null;
|
|
506
516
|
}
|
|
@@ -510,7 +520,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
510
520
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
511
521
|
}
|
|
512
522
|
|
|
513
|
-
function getPanelGroupElement(id, rootElement) {
|
|
523
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
514
524
|
var _dataset;
|
|
515
525
|
//If the root element is the PanelGroup
|
|
516
526
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -525,18 +535,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
525
535
|
return null;
|
|
526
536
|
}
|
|
527
537
|
|
|
528
|
-
function getResizeHandleElement(id,
|
|
529
|
-
const element =
|
|
538
|
+
function getResizeHandleElement(id, scope = document) {
|
|
539
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
530
540
|
if (element) {
|
|
531
541
|
return element;
|
|
532
542
|
}
|
|
533
543
|
return null;
|
|
534
544
|
}
|
|
535
545
|
|
|
536
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
546
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
537
547
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
538
|
-
const handle = getResizeHandleElement(handleId,
|
|
539
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
548
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
549
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
540
550
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
541
551
|
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;
|
|
542
552
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -1521,6 +1531,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1521
1531
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1522
1532
|
}
|
|
1523
1533
|
}, []);
|
|
1534
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1535
|
+
const {
|
|
1536
|
+
layout,
|
|
1537
|
+
panelDataArray
|
|
1538
|
+
} = eagerValuesRef.current;
|
|
1539
|
+
const {
|
|
1540
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1541
|
+
collapsible: prevCollapsible
|
|
1542
|
+
} = prevConstraints;
|
|
1543
|
+
const {
|
|
1544
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1545
|
+
collapsible: nextCollapsible,
|
|
1546
|
+
maxSize: nextMaxSize = 100,
|
|
1547
|
+
minSize: nextMinSize = 0
|
|
1548
|
+
} = panelData.constraints;
|
|
1549
|
+
const {
|
|
1550
|
+
panelSize: prevPanelSize
|
|
1551
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1552
|
+
assert(prevPanelSize != null);
|
|
1553
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1554
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1555
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1556
|
+
}
|
|
1557
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1558
|
+
resizePanel(panelData, nextMinSize);
|
|
1559
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1560
|
+
resizePanel(panelData, nextMaxSize);
|
|
1561
|
+
}
|
|
1562
|
+
}, [resizePanel]);
|
|
1524
1563
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1525
1564
|
const {
|
|
1526
1565
|
direction
|
|
@@ -1571,6 +1610,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1571
1610
|
groupId,
|
|
1572
1611
|
isPanelCollapsed,
|
|
1573
1612
|
isPanelExpanded,
|
|
1613
|
+
reevaluatePanelConstraints,
|
|
1574
1614
|
registerPanel,
|
|
1575
1615
|
registerResizeHandle,
|
|
1576
1616
|
resizePanel,
|
|
@@ -1578,7 +1618,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1578
1618
|
stopDragging,
|
|
1579
1619
|
unregisterPanel,
|
|
1580
1620
|
panelGroupElement: panelGroupElementRef.current
|
|
1581
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1621
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1582
1622
|
const style = {
|
|
1583
1623
|
display: "flex",
|
|
1584
1624
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1613,14 +1653,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1613
1653
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1614
1654
|
}
|
|
1615
1655
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1616
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1617
1656
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1618
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1619
1657
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1620
1658
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1621
1659
|
const panelSize = layout[panelIndex];
|
|
1622
1660
|
return {
|
|
1623
|
-
...
|
|
1661
|
+
...panelData.constraints,
|
|
1624
1662
|
panelSize,
|
|
1625
1663
|
pivotIndices
|
|
1626
1664
|
};
|
|
@@ -1827,47 +1865,16 @@ function PanelResizeHandle({
|
|
|
1827
1865
|
}
|
|
1828
1866
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1829
1867
|
|
|
1830
|
-
function
|
|
1831
|
-
|
|
1832
|
-
return NaN;
|
|
1833
|
-
}
|
|
1834
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1835
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1836
|
-
if (direction === "horizontal") {
|
|
1837
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1838
|
-
return accumulated + handle.offsetWidth;
|
|
1839
|
-
}, 0);
|
|
1840
|
-
} else {
|
|
1841
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1842
|
-
return accumulated + handle.offsetHeight;
|
|
1843
|
-
}, 0);
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1848
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1849
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1850
|
-
if (direction === "horizontal") {
|
|
1851
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1852
|
-
return accumulated + handle.offsetWidth;
|
|
1853
|
-
}, 0);
|
|
1854
|
-
} else {
|
|
1855
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1856
|
-
return accumulated + handle.offsetHeight;
|
|
1857
|
-
}, 0);
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1862
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1868
|
+
function getPanelElement(id, scope = document) {
|
|
1869
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1863
1870
|
if (element) {
|
|
1864
1871
|
return element;
|
|
1865
1872
|
}
|
|
1866
1873
|
return null;
|
|
1867
1874
|
}
|
|
1868
1875
|
|
|
1869
|
-
function getPanelElementsForGroup(groupId,
|
|
1870
|
-
return Array.from(
|
|
1876
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1877
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1871
1878
|
}
|
|
1872
1879
|
|
|
1873
|
-
export { Panel, PanelGroup, PanelResizeHandle, assert,
|
|
1880
|
+
export { Panel, PanelGroup, PanelResizeHandle, assert, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds };
|
|
@@ -93,6 +93,7 @@ function PanelWithForwardedRef({
|
|
|
93
93
|
getPanelStyle,
|
|
94
94
|
groupId,
|
|
95
95
|
isPanelCollapsed,
|
|
96
|
+
reevaluatePanelConstraints,
|
|
96
97
|
registerPanel,
|
|
97
98
|
resizePanel,
|
|
98
99
|
unregisterPanel
|
|
@@ -123,6 +124,9 @@ function PanelWithForwardedRef({
|
|
|
123
124
|
callbacks,
|
|
124
125
|
constraints
|
|
125
126
|
} = panelDataRef.current;
|
|
127
|
+
const prevConstraints = {
|
|
128
|
+
...constraints
|
|
129
|
+
};
|
|
126
130
|
panelDataRef.current.id = panelId;
|
|
127
131
|
panelDataRef.current.idIsFromProps = idFromProps !== undefined;
|
|
128
132
|
panelDataRef.current.order = order;
|
|
@@ -134,6 +138,12 @@ function PanelWithForwardedRef({
|
|
|
134
138
|
constraints.defaultSize = defaultSize;
|
|
135
139
|
constraints.maxSize = maxSize;
|
|
136
140
|
constraints.minSize = minSize;
|
|
141
|
+
|
|
142
|
+
// If constraints have changed, we should revisit panel sizes.
|
|
143
|
+
// This is uncommon but may happen if people are trying to implement pixel based constraints.
|
|
144
|
+
if (prevConstraints.collapsedSize !== constraints.collapsedSize || prevConstraints.collapsible !== constraints.collapsible || prevConstraints.maxSize !== constraints.maxSize || prevConstraints.minSize !== constraints.minSize) {
|
|
145
|
+
reevaluatePanelConstraints(panelDataRef.current, prevConstraints);
|
|
146
|
+
}
|
|
137
147
|
});
|
|
138
148
|
useIsomorphicLayoutEffect(() => {
|
|
139
149
|
const panelData = panelDataRef.current;
|
|
@@ -521,12 +531,12 @@ function calculateAriaValues({
|
|
|
521
531
|
};
|
|
522
532
|
}
|
|
523
533
|
|
|
524
|
-
function getResizeHandleElementsForGroup(groupId,
|
|
525
|
-
return Array.from(
|
|
534
|
+
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
535
|
+
return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
|
|
526
536
|
}
|
|
527
537
|
|
|
528
|
-
function getResizeHandleElementIndex(groupId, id,
|
|
529
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
538
|
+
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
539
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
530
540
|
const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
|
|
531
541
|
return index !== null && index !== void 0 ? index : null;
|
|
532
542
|
}
|
|
@@ -536,7 +546,7 @@ function determinePivotIndices(groupId, dragHandleId, panelGroupElement) {
|
|
|
536
546
|
return index != null ? [index, index + 1] : [-1, -1];
|
|
537
547
|
}
|
|
538
548
|
|
|
539
|
-
function getPanelGroupElement(id, rootElement) {
|
|
549
|
+
function getPanelGroupElement(id, rootElement = document) {
|
|
540
550
|
var _dataset;
|
|
541
551
|
//If the root element is the PanelGroup
|
|
542
552
|
if (rootElement instanceof HTMLElement && (rootElement === null || rootElement === void 0 ? void 0 : (_dataset = rootElement.dataset) === null || _dataset === void 0 ? void 0 : _dataset.panelGroupId) == id) {
|
|
@@ -551,18 +561,18 @@ function getPanelGroupElement(id, rootElement) {
|
|
|
551
561
|
return null;
|
|
552
562
|
}
|
|
553
563
|
|
|
554
|
-
function getResizeHandleElement(id,
|
|
555
|
-
const element =
|
|
564
|
+
function getResizeHandleElement(id, scope = document) {
|
|
565
|
+
const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
|
|
556
566
|
if (element) {
|
|
557
567
|
return element;
|
|
558
568
|
}
|
|
559
569
|
return null;
|
|
560
570
|
}
|
|
561
571
|
|
|
562
|
-
function getResizeHandlePanelIds(groupId, handleId, panelsArray,
|
|
572
|
+
function getResizeHandlePanelIds(groupId, handleId, panelsArray, scope = document) {
|
|
563
573
|
var _panelsArray$index$id, _panelsArray$index, _panelsArray$id, _panelsArray;
|
|
564
|
-
const handle = getResizeHandleElement(handleId,
|
|
565
|
-
const handles = getResizeHandleElementsForGroup(groupId,
|
|
574
|
+
const handle = getResizeHandleElement(handleId, scope);
|
|
575
|
+
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
566
576
|
const index = handle ? handles.indexOf(handle) : -1;
|
|
567
577
|
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;
|
|
568
578
|
const idAfter = (_panelsArray$id = (_panelsArray = panelsArray[index + 1]) === null || _panelsArray === void 0 ? void 0 : _panelsArray.id) !== null && _panelsArray$id !== void 0 ? _panelsArray$id : null;
|
|
@@ -1547,6 +1557,35 @@ function PanelGroupWithForwardedRef({
|
|
|
1547
1557
|
callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
|
|
1548
1558
|
}
|
|
1549
1559
|
}, []);
|
|
1560
|
+
const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
|
|
1561
|
+
const {
|
|
1562
|
+
layout,
|
|
1563
|
+
panelDataArray
|
|
1564
|
+
} = eagerValuesRef.current;
|
|
1565
|
+
const {
|
|
1566
|
+
collapsedSize: prevCollapsedSize = 0,
|
|
1567
|
+
collapsible: prevCollapsible
|
|
1568
|
+
} = prevConstraints;
|
|
1569
|
+
const {
|
|
1570
|
+
collapsedSize: nextCollapsedSize = 0,
|
|
1571
|
+
collapsible: nextCollapsible,
|
|
1572
|
+
maxSize: nextMaxSize = 100,
|
|
1573
|
+
minSize: nextMinSize = 0
|
|
1574
|
+
} = panelData.constraints;
|
|
1575
|
+
const {
|
|
1576
|
+
panelSize: prevPanelSize
|
|
1577
|
+
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1578
|
+
assert(prevPanelSize != null);
|
|
1579
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1580
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1581
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1582
|
+
}
|
|
1583
|
+
} else if (prevPanelSize < nextMinSize) {
|
|
1584
|
+
resizePanel(panelData, nextMinSize);
|
|
1585
|
+
} else if (prevPanelSize > nextMaxSize) {
|
|
1586
|
+
resizePanel(panelData, nextMaxSize);
|
|
1587
|
+
}
|
|
1588
|
+
}, [resizePanel]);
|
|
1550
1589
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1551
1590
|
const {
|
|
1552
1591
|
direction
|
|
@@ -1597,6 +1636,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1597
1636
|
groupId,
|
|
1598
1637
|
isPanelCollapsed,
|
|
1599
1638
|
isPanelExpanded,
|
|
1639
|
+
reevaluatePanelConstraints,
|
|
1600
1640
|
registerPanel,
|
|
1601
1641
|
registerResizeHandle,
|
|
1602
1642
|
resizePanel,
|
|
@@ -1604,7 +1644,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1604
1644
|
stopDragging,
|
|
1605
1645
|
unregisterPanel,
|
|
1606
1646
|
panelGroupElement: panelGroupElementRef.current
|
|
1607
|
-
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1647
|
+
}), [collapsePanel, dragState, direction, expandPanel, getPanelSize, getPanelStyle, groupId, isPanelCollapsed, isPanelExpanded, reevaluatePanelConstraints, registerPanel, registerResizeHandle, resizePanel, startDragging, stopDragging, unregisterPanel]);
|
|
1608
1648
|
const style = {
|
|
1609
1649
|
display: "flex",
|
|
1610
1650
|
flexDirection: direction === "horizontal" ? "row" : "column",
|
|
@@ -1639,14 +1679,12 @@ function findPanelDataIndex(panelDataArray, panelData) {
|
|
|
1639
1679
|
return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
|
|
1640
1680
|
}
|
|
1641
1681
|
function panelDataHelper(panelDataArray, panelData, layout) {
|
|
1642
|
-
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1643
1682
|
const panelIndex = findPanelDataIndex(panelDataArray, panelData);
|
|
1644
|
-
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1645
1683
|
const isLastPanel = panelIndex === panelDataArray.length - 1;
|
|
1646
1684
|
const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
|
|
1647
1685
|
const panelSize = layout[panelIndex];
|
|
1648
1686
|
return {
|
|
1649
|
-
...
|
|
1687
|
+
...panelData.constraints,
|
|
1650
1688
|
panelSize,
|
|
1651
1689
|
pivotIndices
|
|
1652
1690
|
};
|
|
@@ -1853,55 +1891,22 @@ function PanelResizeHandle({
|
|
|
1853
1891
|
}
|
|
1854
1892
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
1855
1893
|
|
|
1856
|
-
function
|
|
1857
|
-
|
|
1858
|
-
return NaN;
|
|
1859
|
-
}
|
|
1860
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1861
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1862
|
-
if (direction === "horizontal") {
|
|
1863
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1864
|
-
return accumulated + handle.offsetWidth;
|
|
1865
|
-
}, 0);
|
|
1866
|
-
} else {
|
|
1867
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1868
|
-
return accumulated + handle.offsetHeight;
|
|
1869
|
-
}, 0);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
function getAvailableGroupSizePixels(groupId, panelGroupElement) {
|
|
1874
|
-
const direction = panelGroupElement.getAttribute("data-panel-group-direction");
|
|
1875
|
-
const resizeHandles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1876
|
-
if (direction === "horizontal") {
|
|
1877
|
-
return panelGroupElement.offsetWidth - resizeHandles.reduce((accumulated, handle) => {
|
|
1878
|
-
return accumulated + handle.offsetWidth;
|
|
1879
|
-
}, 0);
|
|
1880
|
-
} else {
|
|
1881
|
-
return panelGroupElement.offsetHeight - resizeHandles.reduce((accumulated, handle) => {
|
|
1882
|
-
return accumulated + handle.offsetHeight;
|
|
1883
|
-
}, 0);
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
function getPanelElement(id, panelGroupElement) {
|
|
1888
|
-
const element = panelGroupElement.querySelector(`[data-panel-id="${id}"]`);
|
|
1894
|
+
function getPanelElement(id, scope = document) {
|
|
1895
|
+
const element = scope.querySelector(`[data-panel-id="${id}"]`);
|
|
1889
1896
|
if (element) {
|
|
1890
1897
|
return element;
|
|
1891
1898
|
}
|
|
1892
1899
|
return null;
|
|
1893
1900
|
}
|
|
1894
1901
|
|
|
1895
|
-
function getPanelElementsForGroup(groupId,
|
|
1896
|
-
return Array.from(
|
|
1902
|
+
function getPanelElementsForGroup(groupId, scope = document) {
|
|
1903
|
+
return Array.from(scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
|
|
1897
1904
|
}
|
|
1898
1905
|
|
|
1899
1906
|
exports.Panel = Panel;
|
|
1900
1907
|
exports.PanelGroup = PanelGroup;
|
|
1901
1908
|
exports.PanelResizeHandle = PanelResizeHandle;
|
|
1902
1909
|
exports.assert = assert;
|
|
1903
|
-
exports.calculateAvailablePanelSizeInPixels = calculateAvailablePanelSizeInPixels;
|
|
1904
|
-
exports.getAvailableGroupSizePixels = getAvailableGroupSizePixels;
|
|
1905
1910
|
exports.getPanelElement = getPanelElement;
|
|
1906
1911
|
exports.getPanelElementsForGroup = getPanelElementsForGroup;
|
|
1907
1912
|
exports.getPanelGroupElement = getPanelGroupElement;
|