react-resizable-panels 0.0.60 → 0.0.62
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 +8 -0
- package/dist/react-resizable-panels.browser.cjs.js +69 -43
- package/dist/react-resizable-panels.browser.development.cjs.js +70 -44
- package/dist/react-resizable-panels.browser.development.esm.js +70 -44
- package/dist/react-resizable-panels.browser.esm.js +69 -43
- package/dist/react-resizable-panels.cjs.js +69 -43
- package/dist/react-resizable-panels.development.cjs.js +70 -44
- package/dist/react-resizable-panels.development.esm.js +70 -44
- package/dist/react-resizable-panels.development.node.cjs.js +67 -41
- package/dist/react-resizable-panels.development.node.esm.js +67 -41
- package/dist/react-resizable-panels.esm.js +69 -43
- package/dist/react-resizable-panels.node.cjs.js +66 -40
- package/dist/react-resizable-panels.node.esm.js +66 -40
- package/package.json +1 -1
- package/src/PanelGroup.ts +51 -58
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +12 -2
- package/dist/react-resizable-panels.cjs.js.map +0 -1
- package/dist/react-resizable-panels.esm.js.map +0 -1
|
@@ -724,6 +724,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
724
724
|
|
|
725
725
|
function useWindowSplitterPanelGroupBehavior({
|
|
726
726
|
committedValuesRef,
|
|
727
|
+
eagerValuesRef,
|
|
727
728
|
groupId,
|
|
728
729
|
layout,
|
|
729
730
|
panelDataArray,
|
|
@@ -776,7 +777,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
776
777
|
useEffect(() => {
|
|
777
778
|
const {
|
|
778
779
|
panelDataArray
|
|
779
|
-
} =
|
|
780
|
+
} = eagerValuesRef.current;
|
|
780
781
|
const groupElement = getPanelGroupElement(groupId);
|
|
781
782
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
782
783
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -834,7 +835,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
834
835
|
return () => {
|
|
835
836
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
836
837
|
};
|
|
837
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
838
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
838
839
|
}
|
|
839
840
|
|
|
840
841
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1376,11 +1377,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1376
1377
|
id: groupId,
|
|
1377
1378
|
keyboardResizeByPercentage,
|
|
1378
1379
|
keyboardResizeByPixels,
|
|
1379
|
-
layout,
|
|
1380
1380
|
onLayout,
|
|
1381
|
-
panelDataArray: [],
|
|
1382
1381
|
storage
|
|
1383
1382
|
});
|
|
1383
|
+
const eagerValuesRef = useRef({
|
|
1384
|
+
layout,
|
|
1385
|
+
panelDataArray: []
|
|
1386
|
+
});
|
|
1384
1387
|
const devWarningsRef = useRef({
|
|
1385
1388
|
didLogIdAndOrderWarning: false,
|
|
1386
1389
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1390,9 +1393,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1390
1393
|
getId: () => committedValuesRef.current.id,
|
|
1391
1394
|
getLayout: () => {
|
|
1392
1395
|
const {
|
|
1393
|
-
id: groupId
|
|
1394
|
-
layout
|
|
1396
|
+
id: groupId
|
|
1395
1397
|
} = committedValuesRef.current;
|
|
1398
|
+
const {
|
|
1399
|
+
layout
|
|
1400
|
+
} = eagerValuesRef.current;
|
|
1396
1401
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1397
1402
|
return layout.map(sizePercentage => {
|
|
1398
1403
|
return {
|
|
@@ -1404,10 +1409,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1404
1409
|
setLayout: mixedSizes => {
|
|
1405
1410
|
const {
|
|
1406
1411
|
id: groupId,
|
|
1412
|
+
onLayout
|
|
1413
|
+
} = committedValuesRef.current;
|
|
1414
|
+
const {
|
|
1407
1415
|
layout: prevLayout,
|
|
1408
|
-
onLayout,
|
|
1409
1416
|
panelDataArray
|
|
1410
|
-
} =
|
|
1417
|
+
} = eagerValuesRef.current;
|
|
1411
1418
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1412
1419
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1413
1420
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1417,7 +1424,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1417
1424
|
});
|
|
1418
1425
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1419
1426
|
setLayout(safeLayout);
|
|
1420
|
-
|
|
1427
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1421
1428
|
if (onLayout) {
|
|
1422
1429
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1423
1430
|
sizePercentage,
|
|
@@ -1442,15 +1449,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1442
1449
|
|
|
1443
1450
|
useWindowSplitterPanelGroupBehavior({
|
|
1444
1451
|
committedValuesRef,
|
|
1452
|
+
eagerValuesRef,
|
|
1445
1453
|
groupId,
|
|
1446
1454
|
layout,
|
|
1447
|
-
panelDataArray:
|
|
1455
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1448
1456
|
setLayout
|
|
1449
1457
|
});
|
|
1450
1458
|
useEffect(() => {
|
|
1451
1459
|
const {
|
|
1452
1460
|
panelDataArray
|
|
1453
|
-
} =
|
|
1461
|
+
} = eagerValuesRef.current;
|
|
1454
1462
|
|
|
1455
1463
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1456
1464
|
if (autoSaveId) {
|
|
@@ -1467,8 +1475,9 @@ function PanelGroupWithForwardedRef({
|
|
|
1467
1475
|
}, [autoSaveId, layout, storage]);
|
|
1468
1476
|
useIsomorphicLayoutEffect(() => {
|
|
1469
1477
|
const {
|
|
1478
|
+
layout: prevLayout,
|
|
1470
1479
|
panelDataArray
|
|
1471
|
-
} =
|
|
1480
|
+
} = eagerValuesRef.current;
|
|
1472
1481
|
const constraints = panelDataArray.map(({
|
|
1473
1482
|
constraints
|
|
1474
1483
|
}) => constraints);
|
|
@@ -1482,7 +1491,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1482
1491
|
const resizeObserver = new ResizeObserver(() => {
|
|
1483
1492
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1484
1493
|
const {
|
|
1485
|
-
layout: prevLayout,
|
|
1486
1494
|
onLayout
|
|
1487
1495
|
} = committedValuesRef.current;
|
|
1488
1496
|
const nextLayout = validatePanelGroupLayout({
|
|
@@ -1492,7 +1500,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1492
1500
|
});
|
|
1493
1501
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1494
1502
|
setLayout(nextLayout);
|
|
1495
|
-
|
|
1503
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1496
1504
|
if (onLayout) {
|
|
1497
1505
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1498
1506
|
sizePercentage,
|
|
@@ -1514,7 +1522,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1514
1522
|
{
|
|
1515
1523
|
const {
|
|
1516
1524
|
panelDataArray
|
|
1517
|
-
} =
|
|
1525
|
+
} = eagerValuesRef.current;
|
|
1518
1526
|
const {
|
|
1519
1527
|
didLogIdAndOrderWarning,
|
|
1520
1528
|
didLogPanelConstraintsWarning,
|
|
@@ -1557,11 +1565,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1557
1565
|
|
|
1558
1566
|
// External APIs are safe to memoize via committed values ref
|
|
1559
1567
|
const collapsePanel = useCallback(panelData => {
|
|
1568
|
+
const {
|
|
1569
|
+
onLayout
|
|
1570
|
+
} = committedValuesRef.current;
|
|
1560
1571
|
const {
|
|
1561
1572
|
layout: prevLayout,
|
|
1562
|
-
onLayout,
|
|
1563
1573
|
panelDataArray
|
|
1564
|
-
} =
|
|
1574
|
+
} = eagerValuesRef.current;
|
|
1565
1575
|
if (panelData.constraints.collapsible) {
|
|
1566
1576
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1567
1577
|
const {
|
|
@@ -1586,7 +1596,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1586
1596
|
});
|
|
1587
1597
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1588
1598
|
setLayout(nextLayout);
|
|
1589
|
-
|
|
1599
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1590
1600
|
if (onLayout) {
|
|
1591
1601
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1592
1602
|
sizePercentage,
|
|
@@ -1601,11 +1611,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1601
1611
|
|
|
1602
1612
|
// External APIs are safe to memoize via committed values ref
|
|
1603
1613
|
const expandPanel = useCallback(panelData => {
|
|
1614
|
+
const {
|
|
1615
|
+
onLayout
|
|
1616
|
+
} = committedValuesRef.current;
|
|
1604
1617
|
const {
|
|
1605
1618
|
layout: prevLayout,
|
|
1606
|
-
onLayout,
|
|
1607
1619
|
panelDataArray
|
|
1608
|
-
} =
|
|
1620
|
+
} = eagerValuesRef.current;
|
|
1609
1621
|
if (panelData.constraints.collapsible) {
|
|
1610
1622
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1611
1623
|
const {
|
|
@@ -1618,7 +1630,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1618
1630
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1619
1631
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1620
1632
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1621
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1633
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1622
1634
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1623
1635
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1624
1636
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1631,7 +1643,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1631
1643
|
});
|
|
1632
1644
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1633
1645
|
setLayout(nextLayout);
|
|
1634
|
-
|
|
1646
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1635
1647
|
if (onLayout) {
|
|
1636
1648
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1637
1649
|
sizePercentage,
|
|
@@ -1649,7 +1661,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1649
1661
|
const {
|
|
1650
1662
|
layout,
|
|
1651
1663
|
panelDataArray
|
|
1652
|
-
} =
|
|
1664
|
+
} = eagerValuesRef.current;
|
|
1653
1665
|
const {
|
|
1654
1666
|
panelSizePercentage,
|
|
1655
1667
|
panelSizePixels
|
|
@@ -1664,7 +1676,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1664
1676
|
const getPanelStyle = useCallback(panelData => {
|
|
1665
1677
|
const {
|
|
1666
1678
|
panelDataArray
|
|
1667
|
-
} =
|
|
1679
|
+
} = eagerValuesRef.current;
|
|
1668
1680
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1669
1681
|
return computePanelFlexBoxStyle({
|
|
1670
1682
|
dragState,
|
|
@@ -1679,7 +1691,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1679
1691
|
const {
|
|
1680
1692
|
layout,
|
|
1681
1693
|
panelDataArray
|
|
1682
|
-
} =
|
|
1694
|
+
} = eagerValuesRef.current;
|
|
1683
1695
|
const {
|
|
1684
1696
|
collapsedSizePercentage,
|
|
1685
1697
|
collapsible,
|
|
@@ -1693,7 +1705,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1693
1705
|
const {
|
|
1694
1706
|
layout,
|
|
1695
1707
|
panelDataArray
|
|
1696
|
-
} =
|
|
1708
|
+
} = eagerValuesRef.current;
|
|
1697
1709
|
const {
|
|
1698
1710
|
collapsedSizePercentage,
|
|
1699
1711
|
collapsible,
|
|
@@ -1705,11 +1717,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1705
1717
|
const {
|
|
1706
1718
|
autoSaveId,
|
|
1707
1719
|
id: groupId,
|
|
1708
|
-
layout: prevLayout,
|
|
1709
1720
|
onLayout,
|
|
1710
|
-
panelDataArray,
|
|
1711
1721
|
storage
|
|
1712
1722
|
} = committedValuesRef.current;
|
|
1723
|
+
const {
|
|
1724
|
+
layout: prevLayout,
|
|
1725
|
+
panelDataArray
|
|
1726
|
+
} = eagerValuesRef.current;
|
|
1713
1727
|
panelDataArray.push(panelData);
|
|
1714
1728
|
panelDataArray.sort((panelA, panelB) => {
|
|
1715
1729
|
const orderA = panelA.order;
|
|
@@ -1761,9 +1775,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1761
1775
|
layout: unsafeLayout,
|
|
1762
1776
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1763
1777
|
});
|
|
1778
|
+
|
|
1779
|
+
// Offscreen mode makes this a bit weird;
|
|
1780
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1781
|
+
// but the overall layout doesn't change between these two cases.
|
|
1782
|
+
setLayout(nextLayout);
|
|
1783
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1764
1784
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1765
|
-
setLayout(nextLayout);
|
|
1766
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1767
1785
|
if (onLayout) {
|
|
1768
1786
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1769
1787
|
sizePercentage,
|
|
@@ -1782,10 +1800,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1782
1800
|
id: groupId,
|
|
1783
1801
|
keyboardResizeByPercentage,
|
|
1784
1802
|
keyboardResizeByPixels,
|
|
1785
|
-
onLayout
|
|
1786
|
-
panelDataArray,
|
|
1787
|
-
layout: prevLayout
|
|
1803
|
+
onLayout
|
|
1788
1804
|
} = committedValuesRef.current;
|
|
1805
|
+
const {
|
|
1806
|
+
layout: prevLayout,
|
|
1807
|
+
panelDataArray
|
|
1808
|
+
} = eagerValuesRef.current;
|
|
1789
1809
|
const {
|
|
1790
1810
|
initialLayout
|
|
1791
1811
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1841,7 +1861,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1841
1861
|
}
|
|
1842
1862
|
if (layoutChanged) {
|
|
1843
1863
|
setLayout(nextLayout);
|
|
1844
|
-
|
|
1864
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1845
1865
|
if (onLayout) {
|
|
1846
1866
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1847
1867
|
sizePercentage,
|
|
@@ -1855,11 +1875,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1855
1875
|
|
|
1856
1876
|
// External APIs are safe to memoize via committed values ref
|
|
1857
1877
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1878
|
+
const {
|
|
1879
|
+
onLayout
|
|
1880
|
+
} = committedValuesRef.current;
|
|
1858
1881
|
const {
|
|
1859
1882
|
layout: prevLayout,
|
|
1860
|
-
onLayout,
|
|
1861
1883
|
panelDataArray
|
|
1862
|
-
} =
|
|
1884
|
+
} = eagerValuesRef.current;
|
|
1863
1885
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1864
1886
|
const {
|
|
1865
1887
|
groupSizePixels,
|
|
@@ -1879,7 +1901,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1879
1901
|
});
|
|
1880
1902
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1881
1903
|
setLayout(nextLayout);
|
|
1882
|
-
|
|
1904
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1883
1905
|
if (onLayout) {
|
|
1884
1906
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1885
1907
|
sizePercentage,
|
|
@@ -1891,9 +1913,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1891
1913
|
}, [groupId]);
|
|
1892
1914
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1893
1915
|
const {
|
|
1894
|
-
direction
|
|
1895
|
-
layout
|
|
1916
|
+
direction
|
|
1896
1917
|
} = committedValuesRef.current;
|
|
1918
|
+
const {
|
|
1919
|
+
layout
|
|
1920
|
+
} = eagerValuesRef.current;
|
|
1897
1921
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1898
1922
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1899
1923
|
setDragState({
|
|
@@ -1914,10 +1938,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1914
1938
|
const unregisterPanel = useCallback(panelData => {
|
|
1915
1939
|
const {
|
|
1916
1940
|
id: groupId,
|
|
1941
|
+
onLayout
|
|
1942
|
+
} = committedValuesRef.current;
|
|
1943
|
+
const {
|
|
1917
1944
|
layout: prevLayout,
|
|
1918
|
-
onLayout,
|
|
1919
1945
|
panelDataArray
|
|
1920
|
-
} =
|
|
1946
|
+
} = eagerValuesRef.current;
|
|
1921
1947
|
const index = panelDataArray.indexOf(panelData);
|
|
1922
1948
|
if (index >= 0) {
|
|
1923
1949
|
panelDataArray.splice(index, 1);
|
|
@@ -1934,7 +1960,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1934
1960
|
const {
|
|
1935
1961
|
pendingPanelIds
|
|
1936
1962
|
} = unregisterPanelRef.current;
|
|
1937
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1963
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1938
1964
|
|
|
1939
1965
|
// TRICKY
|
|
1940
1966
|
// Strict effects mode
|
|
@@ -1950,7 +1976,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1950
1976
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1951
1977
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1952
1978
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1953
|
-
delete
|
|
1979
|
+
delete map[panelData.id];
|
|
1954
1980
|
}
|
|
1955
1981
|
});
|
|
1956
1982
|
if (!unmountDueToStrictMode) {
|
|
@@ -1975,7 +2001,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1975
2001
|
});
|
|
1976
2002
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1977
2003
|
setLayout(nextLayout);
|
|
1978
|
-
|
|
2004
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1979
2005
|
if (onLayout) {
|
|
1980
2006
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1981
2007
|
sizePercentage,
|