react-resizable-panels 0.0.58 → 0.0.59
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 +6 -0
- package/dist/react-resizable-panels.browser.cjs.js +77 -20
- package/dist/react-resizable-panels.browser.development.cjs.js +77 -20
- package/dist/react-resizable-panels.browser.development.esm.js +77 -20
- package/dist/react-resizable-panels.browser.esm.js +77 -20
- package/dist/react-resizable-panels.cjs.js +77 -20
- package/dist/react-resizable-panels.cjs.js.map +1 -1
- package/dist/react-resizable-panels.development.cjs.js +77 -20
- package/dist/react-resizable-panels.development.esm.js +77 -20
- package/dist/react-resizable-panels.development.node.cjs.js +46 -18
- package/dist/react-resizable-panels.development.node.esm.js +46 -18
- package/dist/react-resizable-panels.esm.js +77 -20
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +46 -18
- package/dist/react-resizable-panels.node.esm.js +46 -18
- package/package.json +1 -1
- package/src/PanelGroup.ts +84 -2
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +15 -15
|
@@ -174,8 +174,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
174
174
|
PanelWithForwardedRef.displayName = "Panel";
|
|
175
175
|
Panel.displayName = "forwardRef(Panel)";
|
|
176
176
|
|
|
177
|
-
const PRECISION = 10;
|
|
178
|
-
|
|
179
177
|
function convertPixelsToPercentage(pixels, groupSizePixels) {
|
|
180
178
|
return pixels / groupSizePixels * 100;
|
|
181
179
|
}
|
|
@@ -253,6 +251,8 @@ function computePercentagePanelConstraints(panelConstraintsArray, panelIndex, gr
|
|
|
253
251
|
};
|
|
254
252
|
}
|
|
255
253
|
|
|
254
|
+
const PRECISION = 10;
|
|
255
|
+
|
|
256
256
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
257
257
|
actual = parseFloat(actual.toFixed(fractionDigits));
|
|
258
258
|
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
@@ -726,15 +726,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
726
726
|
}, [groupId, layout, panelDataArray]);
|
|
727
727
|
useEffect(() => {
|
|
728
728
|
const {
|
|
729
|
-
direction,
|
|
730
729
|
panelDataArray
|
|
731
730
|
} = committedValuesRef.current;
|
|
732
731
|
const groupElement = getPanelGroupElement(groupId);
|
|
733
732
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
734
|
-
const {
|
|
735
|
-
height,
|
|
736
|
-
width
|
|
737
|
-
} = groupElement.getBoundingClientRect();
|
|
738
733
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
739
734
|
const cleanupFunctions = handles.map(handle => {
|
|
740
735
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
@@ -754,21 +749,19 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
754
749
|
if (index >= 0) {
|
|
755
750
|
const panelData = panelDataArray[index];
|
|
756
751
|
const size = layout[index];
|
|
757
|
-
if (size != null) {
|
|
758
|
-
var _getPercentageSizeFro;
|
|
752
|
+
if (size != null && panelData.constraints.collapsible) {
|
|
753
|
+
var _getPercentageSizeFro, _getPercentageSizeFro2;
|
|
759
754
|
const groupSizePixels = getAvailableGroupSizePixels(groupId);
|
|
760
|
-
const
|
|
755
|
+
const collapsedSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
|
|
756
|
+
sizePercentage: panelData.constraints.collapsedSizePercentage,
|
|
757
|
+
sizePixels: panelData.constraints.collapsedSizePixels
|
|
758
|
+
}, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
|
|
759
|
+
const minSize = (_getPercentageSizeFro2 = getPercentageSizeFromMixedSizes({
|
|
761
760
|
sizePercentage: panelData.constraints.minSizePercentage,
|
|
762
761
|
sizePixels: panelData.constraints.minSizePixels
|
|
763
|
-
}, groupSizePixels)) !== null &&
|
|
764
|
-
let delta = 0;
|
|
765
|
-
if (size.toPrecision(PRECISION) <= minSize.toPrecision(PRECISION)) {
|
|
766
|
-
delta = direction === "horizontal" ? width : height;
|
|
767
|
-
} else {
|
|
768
|
-
delta = -(direction === "horizontal" ? width : height);
|
|
769
|
-
}
|
|
762
|
+
}, groupSizePixels)) !== null && _getPercentageSizeFro2 !== void 0 ? _getPercentageSizeFro2 : 0;
|
|
770
763
|
const nextLayout = adjustLayoutByDelta({
|
|
771
|
-
delta,
|
|
764
|
+
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
772
765
|
groupSizePixels,
|
|
773
766
|
layout,
|
|
774
767
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
@@ -1247,6 +1240,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1247
1240
|
const panelIdToLastNotifiedMixedSizesMapRef = useRef({});
|
|
1248
1241
|
const panelSizeBeforeCollapseRef = useRef(new Map());
|
|
1249
1242
|
const prevDeltaRef = useRef(0);
|
|
1243
|
+
const [imperativeApiQueue, setImperativeApiQueue] = useState([]);
|
|
1250
1244
|
const committedValuesRef = useRef({
|
|
1251
1245
|
direction,
|
|
1252
1246
|
dragState,
|
|
@@ -1355,8 +1349,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1355
1349
|
}
|
|
1356
1350
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1357
1351
|
if (groupSizePixels <= 0) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1352
|
+
if (shouldMonitorPixelBasedConstraints(panelDataArray.map(({
|
|
1353
|
+
constraints
|
|
1354
|
+
}) => constraints))) {
|
|
1355
|
+
// Wait until the group has rendered a non-zero size before computing layout.
|
|
1356
|
+
return;
|
|
1357
|
+
}
|
|
1360
1358
|
}
|
|
1361
1359
|
if (unsafeLayout == null) {
|
|
1362
1360
|
unsafeLayout = calculateUnsafeDefaultLayout({
|
|
@@ -1434,6 +1432,17 @@ function PanelGroupWithForwardedRef({
|
|
|
1434
1432
|
onLayout,
|
|
1435
1433
|
panelDataArray
|
|
1436
1434
|
} = committedValuesRef.current;
|
|
1435
|
+
|
|
1436
|
+
// See issues/211
|
|
1437
|
+
if (panelDataArray.find(({
|
|
1438
|
+
id
|
|
1439
|
+
}) => id === panelData.id) == null) {
|
|
1440
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1441
|
+
panelData,
|
|
1442
|
+
type: "collapse"
|
|
1443
|
+
}]);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1437
1446
|
if (panelData.constraints.collapsible) {
|
|
1438
1447
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1439
1448
|
const {
|
|
@@ -1477,6 +1486,17 @@ function PanelGroupWithForwardedRef({
|
|
|
1477
1486
|
onLayout,
|
|
1478
1487
|
panelDataArray
|
|
1479
1488
|
} = committedValuesRef.current;
|
|
1489
|
+
|
|
1490
|
+
// See issues/211
|
|
1491
|
+
if (panelDataArray.find(({
|
|
1492
|
+
id
|
|
1493
|
+
}) => id === panelData.id) == null) {
|
|
1494
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1495
|
+
panelData,
|
|
1496
|
+
type: "expand"
|
|
1497
|
+
}]);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1480
1500
|
if (panelData.constraints.collapsible) {
|
|
1481
1501
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1482
1502
|
const {
|
|
@@ -1672,6 +1692,18 @@ function PanelGroupWithForwardedRef({
|
|
|
1672
1692
|
onLayout,
|
|
1673
1693
|
panelDataArray
|
|
1674
1694
|
} = committedValuesRef.current;
|
|
1695
|
+
|
|
1696
|
+
// See issues/211
|
|
1697
|
+
if (panelDataArray.find(({
|
|
1698
|
+
id
|
|
1699
|
+
}) => id === panelData.id) == null) {
|
|
1700
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1701
|
+
panelData,
|
|
1702
|
+
mixedSizes,
|
|
1703
|
+
type: "resize"
|
|
1704
|
+
}]);
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1675
1707
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1676
1708
|
const {
|
|
1677
1709
|
groupSizePixels,
|
|
@@ -1729,6 +1761,31 @@ function PanelGroupWithForwardedRef({
|
|
|
1729
1761
|
return panelDataArray;
|
|
1730
1762
|
});
|
|
1731
1763
|
}, []);
|
|
1764
|
+
|
|
1765
|
+
// Handle imperative API calls that were made before panels were registered
|
|
1766
|
+
useIsomorphicLayoutEffect(() => {
|
|
1767
|
+
const queue = imperativeApiQueue;
|
|
1768
|
+
while (queue.length > 0) {
|
|
1769
|
+
const current = queue.shift();
|
|
1770
|
+
switch (current.type) {
|
|
1771
|
+
case "collapse":
|
|
1772
|
+
{
|
|
1773
|
+
collapsePanel(current.panelData);
|
|
1774
|
+
break;
|
|
1775
|
+
}
|
|
1776
|
+
case "expand":
|
|
1777
|
+
{
|
|
1778
|
+
expandPanel(current.panelData);
|
|
1779
|
+
break;
|
|
1780
|
+
}
|
|
1781
|
+
case "resize":
|
|
1782
|
+
{
|
|
1783
|
+
resizePanel(current.panelData, current.mixedSizes);
|
|
1784
|
+
break;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}, [collapsePanel, expandPanel, imperativeApiQueue, layout, panelDataArray, resizePanel]);
|
|
1732
1789
|
const context = useMemo(() => ({
|
|
1733
1790
|
collapsePanel,
|
|
1734
1791
|
direction,
|
|
@@ -200,8 +200,6 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
200
200
|
PanelWithForwardedRef.displayName = "Panel";
|
|
201
201
|
Panel.displayName = "forwardRef(Panel)";
|
|
202
202
|
|
|
203
|
-
const PRECISION = 10;
|
|
204
|
-
|
|
205
203
|
function convertPixelsToPercentage(pixels, groupSizePixels) {
|
|
206
204
|
return pixels / groupSizePixels * 100;
|
|
207
205
|
}
|
|
@@ -279,6 +277,8 @@ function computePercentagePanelConstraints(panelConstraintsArray, panelIndex, gr
|
|
|
279
277
|
};
|
|
280
278
|
}
|
|
281
279
|
|
|
280
|
+
const PRECISION = 10;
|
|
281
|
+
|
|
282
282
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
283
283
|
actual = parseFloat(actual.toFixed(fractionDigits));
|
|
284
284
|
expected = parseFloat(expected.toFixed(fractionDigits));
|
|
@@ -752,15 +752,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
752
752
|
}, [groupId, layout, panelDataArray]);
|
|
753
753
|
useEffect(() => {
|
|
754
754
|
const {
|
|
755
|
-
direction,
|
|
756
755
|
panelDataArray
|
|
757
756
|
} = committedValuesRef.current;
|
|
758
757
|
const groupElement = getPanelGroupElement(groupId);
|
|
759
758
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
760
|
-
const {
|
|
761
|
-
height,
|
|
762
|
-
width
|
|
763
|
-
} = groupElement.getBoundingClientRect();
|
|
764
759
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
765
760
|
const cleanupFunctions = handles.map(handle => {
|
|
766
761
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
@@ -780,21 +775,19 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
780
775
|
if (index >= 0) {
|
|
781
776
|
const panelData = panelDataArray[index];
|
|
782
777
|
const size = layout[index];
|
|
783
|
-
if (size != null) {
|
|
784
|
-
var _getPercentageSizeFro;
|
|
778
|
+
if (size != null && panelData.constraints.collapsible) {
|
|
779
|
+
var _getPercentageSizeFro, _getPercentageSizeFro2;
|
|
785
780
|
const groupSizePixels = getAvailableGroupSizePixels(groupId);
|
|
786
|
-
const
|
|
781
|
+
const collapsedSize = (_getPercentageSizeFro = getPercentageSizeFromMixedSizes({
|
|
782
|
+
sizePercentage: panelData.constraints.collapsedSizePercentage,
|
|
783
|
+
sizePixels: panelData.constraints.collapsedSizePixels
|
|
784
|
+
}, groupSizePixels)) !== null && _getPercentageSizeFro !== void 0 ? _getPercentageSizeFro : 0;
|
|
785
|
+
const minSize = (_getPercentageSizeFro2 = getPercentageSizeFromMixedSizes({
|
|
787
786
|
sizePercentage: panelData.constraints.minSizePercentage,
|
|
788
787
|
sizePixels: panelData.constraints.minSizePixels
|
|
789
|
-
}, groupSizePixels)) !== null &&
|
|
790
|
-
let delta = 0;
|
|
791
|
-
if (size.toPrecision(PRECISION) <= minSize.toPrecision(PRECISION)) {
|
|
792
|
-
delta = direction === "horizontal" ? width : height;
|
|
793
|
-
} else {
|
|
794
|
-
delta = -(direction === "horizontal" ? width : height);
|
|
795
|
-
}
|
|
788
|
+
}, groupSizePixels)) !== null && _getPercentageSizeFro2 !== void 0 ? _getPercentageSizeFro2 : 0;
|
|
796
789
|
const nextLayout = adjustLayoutByDelta({
|
|
797
|
-
delta,
|
|
790
|
+
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
798
791
|
groupSizePixels,
|
|
799
792
|
layout,
|
|
800
793
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
@@ -1273,6 +1266,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1273
1266
|
const panelIdToLastNotifiedMixedSizesMapRef = useRef({});
|
|
1274
1267
|
const panelSizeBeforeCollapseRef = useRef(new Map());
|
|
1275
1268
|
const prevDeltaRef = useRef(0);
|
|
1269
|
+
const [imperativeApiQueue, setImperativeApiQueue] = useState([]);
|
|
1276
1270
|
const committedValuesRef = useRef({
|
|
1277
1271
|
direction,
|
|
1278
1272
|
dragState,
|
|
@@ -1381,8 +1375,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1381
1375
|
}
|
|
1382
1376
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1383
1377
|
if (groupSizePixels <= 0) {
|
|
1384
|
-
|
|
1385
|
-
|
|
1378
|
+
if (shouldMonitorPixelBasedConstraints(panelDataArray.map(({
|
|
1379
|
+
constraints
|
|
1380
|
+
}) => constraints))) {
|
|
1381
|
+
// Wait until the group has rendered a non-zero size before computing layout.
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1386
1384
|
}
|
|
1387
1385
|
if (unsafeLayout == null) {
|
|
1388
1386
|
unsafeLayout = calculateUnsafeDefaultLayout({
|
|
@@ -1460,6 +1458,17 @@ function PanelGroupWithForwardedRef({
|
|
|
1460
1458
|
onLayout,
|
|
1461
1459
|
panelDataArray
|
|
1462
1460
|
} = committedValuesRef.current;
|
|
1461
|
+
|
|
1462
|
+
// See issues/211
|
|
1463
|
+
if (panelDataArray.find(({
|
|
1464
|
+
id
|
|
1465
|
+
}) => id === panelData.id) == null) {
|
|
1466
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1467
|
+
panelData,
|
|
1468
|
+
type: "collapse"
|
|
1469
|
+
}]);
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1463
1472
|
if (panelData.constraints.collapsible) {
|
|
1464
1473
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1465
1474
|
const {
|
|
@@ -1503,6 +1512,17 @@ function PanelGroupWithForwardedRef({
|
|
|
1503
1512
|
onLayout,
|
|
1504
1513
|
panelDataArray
|
|
1505
1514
|
} = committedValuesRef.current;
|
|
1515
|
+
|
|
1516
|
+
// See issues/211
|
|
1517
|
+
if (panelDataArray.find(({
|
|
1518
|
+
id
|
|
1519
|
+
}) => id === panelData.id) == null) {
|
|
1520
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1521
|
+
panelData,
|
|
1522
|
+
type: "expand"
|
|
1523
|
+
}]);
|
|
1524
|
+
return;
|
|
1525
|
+
}
|
|
1506
1526
|
if (panelData.constraints.collapsible) {
|
|
1507
1527
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1508
1528
|
const {
|
|
@@ -1698,6 +1718,18 @@ function PanelGroupWithForwardedRef({
|
|
|
1698
1718
|
onLayout,
|
|
1699
1719
|
panelDataArray
|
|
1700
1720
|
} = committedValuesRef.current;
|
|
1721
|
+
|
|
1722
|
+
// See issues/211
|
|
1723
|
+
if (panelDataArray.find(({
|
|
1724
|
+
id
|
|
1725
|
+
}) => id === panelData.id) == null) {
|
|
1726
|
+
setImperativeApiQueue(prev => [...prev, {
|
|
1727
|
+
panelData,
|
|
1728
|
+
mixedSizes,
|
|
1729
|
+
type: "resize"
|
|
1730
|
+
}]);
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1701
1733
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1702
1734
|
const {
|
|
1703
1735
|
groupSizePixels,
|
|
@@ -1755,6 +1787,31 @@ function PanelGroupWithForwardedRef({
|
|
|
1755
1787
|
return panelDataArray;
|
|
1756
1788
|
});
|
|
1757
1789
|
}, []);
|
|
1790
|
+
|
|
1791
|
+
// Handle imperative API calls that were made before panels were registered
|
|
1792
|
+
useIsomorphicLayoutEffect(() => {
|
|
1793
|
+
const queue = imperativeApiQueue;
|
|
1794
|
+
while (queue.length > 0) {
|
|
1795
|
+
const current = queue.shift();
|
|
1796
|
+
switch (current.type) {
|
|
1797
|
+
case "collapse":
|
|
1798
|
+
{
|
|
1799
|
+
collapsePanel(current.panelData);
|
|
1800
|
+
break;
|
|
1801
|
+
}
|
|
1802
|
+
case "expand":
|
|
1803
|
+
{
|
|
1804
|
+
expandPanel(current.panelData);
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
case "resize":
|
|
1808
|
+
{
|
|
1809
|
+
resizePanel(current.panelData, current.mixedSizes);
|
|
1810
|
+
break;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
}, [collapsePanel, expandPanel, imperativeApiQueue, layout, panelDataArray, resizePanel]);
|
|
1758
1815
|
const context = useMemo(() => ({
|
|
1759
1816
|
collapsePanel,
|
|
1760
1817
|
direction,
|