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
|
@@ -717,6 +717,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
717
717
|
|
|
718
718
|
function useWindowSplitterPanelGroupBehavior({
|
|
719
719
|
committedValuesRef,
|
|
720
|
+
eagerValuesRef,
|
|
720
721
|
groupId,
|
|
721
722
|
layout,
|
|
722
723
|
panelDataArray,
|
|
@@ -769,7 +770,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
769
770
|
useEffect(() => {
|
|
770
771
|
const {
|
|
771
772
|
panelDataArray
|
|
772
|
-
} =
|
|
773
|
+
} = eagerValuesRef.current;
|
|
773
774
|
const groupElement = getPanelGroupElement(groupId);
|
|
774
775
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
775
776
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -827,7 +828,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
827
828
|
return () => {
|
|
828
829
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
829
830
|
};
|
|
830
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
831
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
831
832
|
}
|
|
832
833
|
|
|
833
834
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1369,11 +1370,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1369
1370
|
id: groupId,
|
|
1370
1371
|
keyboardResizeByPercentage,
|
|
1371
1372
|
keyboardResizeByPixels,
|
|
1372
|
-
layout,
|
|
1373
1373
|
onLayout,
|
|
1374
|
-
panelDataArray: [],
|
|
1375
1374
|
storage
|
|
1376
1375
|
});
|
|
1376
|
+
const eagerValuesRef = useRef({
|
|
1377
|
+
layout,
|
|
1378
|
+
panelDataArray: []
|
|
1379
|
+
});
|
|
1377
1380
|
const devWarningsRef = useRef({
|
|
1378
1381
|
didLogIdAndOrderWarning: false,
|
|
1379
1382
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1383,9 +1386,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1383
1386
|
getId: () => committedValuesRef.current.id,
|
|
1384
1387
|
getLayout: () => {
|
|
1385
1388
|
const {
|
|
1386
|
-
id: groupId
|
|
1387
|
-
layout
|
|
1389
|
+
id: groupId
|
|
1388
1390
|
} = committedValuesRef.current;
|
|
1391
|
+
const {
|
|
1392
|
+
layout
|
|
1393
|
+
} = eagerValuesRef.current;
|
|
1389
1394
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1390
1395
|
return layout.map(sizePercentage => {
|
|
1391
1396
|
return {
|
|
@@ -1397,10 +1402,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1397
1402
|
setLayout: mixedSizes => {
|
|
1398
1403
|
const {
|
|
1399
1404
|
id: groupId,
|
|
1405
|
+
onLayout
|
|
1406
|
+
} = committedValuesRef.current;
|
|
1407
|
+
const {
|
|
1400
1408
|
layout: prevLayout,
|
|
1401
|
-
onLayout,
|
|
1402
1409
|
panelDataArray
|
|
1403
|
-
} =
|
|
1410
|
+
} = eagerValuesRef.current;
|
|
1404
1411
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1405
1412
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1406
1413
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1410,7 +1417,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1410
1417
|
});
|
|
1411
1418
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1412
1419
|
setLayout(safeLayout);
|
|
1413
|
-
|
|
1420
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1414
1421
|
if (onLayout) {
|
|
1415
1422
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1416
1423
|
sizePercentage,
|
|
@@ -1435,15 +1442,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1435
1442
|
|
|
1436
1443
|
useWindowSplitterPanelGroupBehavior({
|
|
1437
1444
|
committedValuesRef,
|
|
1445
|
+
eagerValuesRef,
|
|
1438
1446
|
groupId,
|
|
1439
1447
|
layout,
|
|
1440
|
-
panelDataArray:
|
|
1448
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1441
1449
|
setLayout
|
|
1442
1450
|
});
|
|
1443
1451
|
useEffect(() => {
|
|
1444
1452
|
const {
|
|
1445
1453
|
panelDataArray
|
|
1446
|
-
} =
|
|
1454
|
+
} = eagerValuesRef.current;
|
|
1447
1455
|
|
|
1448
1456
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1449
1457
|
if (autoSaveId) {
|
|
@@ -1460,8 +1468,9 @@ function PanelGroupWithForwardedRef({
|
|
|
1460
1468
|
}, [autoSaveId, layout, storage]);
|
|
1461
1469
|
useIsomorphicLayoutEffect(() => {
|
|
1462
1470
|
const {
|
|
1471
|
+
layout: prevLayout,
|
|
1463
1472
|
panelDataArray
|
|
1464
|
-
} =
|
|
1473
|
+
} = eagerValuesRef.current;
|
|
1465
1474
|
const constraints = panelDataArray.map(({
|
|
1466
1475
|
constraints
|
|
1467
1476
|
}) => constraints);
|
|
@@ -1475,7 +1484,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1475
1484
|
const resizeObserver = new ResizeObserver(() => {
|
|
1476
1485
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1477
1486
|
const {
|
|
1478
|
-
layout: prevLayout,
|
|
1479
1487
|
onLayout
|
|
1480
1488
|
} = committedValuesRef.current;
|
|
1481
1489
|
const nextLayout = validatePanelGroupLayout({
|
|
@@ -1485,7 +1493,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1485
1493
|
});
|
|
1486
1494
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1487
1495
|
setLayout(nextLayout);
|
|
1488
|
-
|
|
1496
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1489
1497
|
if (onLayout) {
|
|
1490
1498
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1491
1499
|
sizePercentage,
|
|
@@ -1507,7 +1515,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1507
1515
|
{
|
|
1508
1516
|
const {
|
|
1509
1517
|
panelDataArray
|
|
1510
|
-
} =
|
|
1518
|
+
} = eagerValuesRef.current;
|
|
1511
1519
|
const {
|
|
1512
1520
|
didLogIdAndOrderWarning,
|
|
1513
1521
|
didLogPanelConstraintsWarning,
|
|
@@ -1550,11 +1558,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1550
1558
|
|
|
1551
1559
|
// External APIs are safe to memoize via committed values ref
|
|
1552
1560
|
const collapsePanel = useCallback(panelData => {
|
|
1561
|
+
const {
|
|
1562
|
+
onLayout
|
|
1563
|
+
} = committedValuesRef.current;
|
|
1553
1564
|
const {
|
|
1554
1565
|
layout: prevLayout,
|
|
1555
|
-
onLayout,
|
|
1556
1566
|
panelDataArray
|
|
1557
|
-
} =
|
|
1567
|
+
} = eagerValuesRef.current;
|
|
1558
1568
|
if (panelData.constraints.collapsible) {
|
|
1559
1569
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1560
1570
|
const {
|
|
@@ -1579,7 +1589,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1579
1589
|
});
|
|
1580
1590
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1581
1591
|
setLayout(nextLayout);
|
|
1582
|
-
|
|
1592
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1583
1593
|
if (onLayout) {
|
|
1584
1594
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1585
1595
|
sizePercentage,
|
|
@@ -1594,11 +1604,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1594
1604
|
|
|
1595
1605
|
// External APIs are safe to memoize via committed values ref
|
|
1596
1606
|
const expandPanel = useCallback(panelData => {
|
|
1607
|
+
const {
|
|
1608
|
+
onLayout
|
|
1609
|
+
} = committedValuesRef.current;
|
|
1597
1610
|
const {
|
|
1598
1611
|
layout: prevLayout,
|
|
1599
|
-
onLayout,
|
|
1600
1612
|
panelDataArray
|
|
1601
|
-
} =
|
|
1613
|
+
} = eagerValuesRef.current;
|
|
1602
1614
|
if (panelData.constraints.collapsible) {
|
|
1603
1615
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1604
1616
|
const {
|
|
@@ -1611,7 +1623,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1611
1623
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1612
1624
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1613
1625
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1614
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1626
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1615
1627
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1616
1628
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1617
1629
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1624,7 +1636,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1624
1636
|
});
|
|
1625
1637
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1626
1638
|
setLayout(nextLayout);
|
|
1627
|
-
|
|
1639
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1628
1640
|
if (onLayout) {
|
|
1629
1641
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1630
1642
|
sizePercentage,
|
|
@@ -1642,7 +1654,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1642
1654
|
const {
|
|
1643
1655
|
layout,
|
|
1644
1656
|
panelDataArray
|
|
1645
|
-
} =
|
|
1657
|
+
} = eagerValuesRef.current;
|
|
1646
1658
|
const {
|
|
1647
1659
|
panelSizePercentage,
|
|
1648
1660
|
panelSizePixels
|
|
@@ -1657,7 +1669,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1657
1669
|
const getPanelStyle = useCallback(panelData => {
|
|
1658
1670
|
const {
|
|
1659
1671
|
panelDataArray
|
|
1660
|
-
} =
|
|
1672
|
+
} = eagerValuesRef.current;
|
|
1661
1673
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1662
1674
|
return computePanelFlexBoxStyle({
|
|
1663
1675
|
dragState,
|
|
@@ -1672,7 +1684,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1672
1684
|
const {
|
|
1673
1685
|
layout,
|
|
1674
1686
|
panelDataArray
|
|
1675
|
-
} =
|
|
1687
|
+
} = eagerValuesRef.current;
|
|
1676
1688
|
const {
|
|
1677
1689
|
collapsedSizePercentage,
|
|
1678
1690
|
collapsible,
|
|
@@ -1686,7 +1698,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1686
1698
|
const {
|
|
1687
1699
|
layout,
|
|
1688
1700
|
panelDataArray
|
|
1689
|
-
} =
|
|
1701
|
+
} = eagerValuesRef.current;
|
|
1690
1702
|
const {
|
|
1691
1703
|
collapsedSizePercentage,
|
|
1692
1704
|
collapsible,
|
|
@@ -1698,11 +1710,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1698
1710
|
const {
|
|
1699
1711
|
autoSaveId,
|
|
1700
1712
|
id: groupId,
|
|
1701
|
-
layout: prevLayout,
|
|
1702
1713
|
onLayout,
|
|
1703
|
-
panelDataArray,
|
|
1704
1714
|
storage
|
|
1705
1715
|
} = committedValuesRef.current;
|
|
1716
|
+
const {
|
|
1717
|
+
layout: prevLayout,
|
|
1718
|
+
panelDataArray
|
|
1719
|
+
} = eagerValuesRef.current;
|
|
1706
1720
|
panelDataArray.push(panelData);
|
|
1707
1721
|
panelDataArray.sort((panelA, panelB) => {
|
|
1708
1722
|
const orderA = panelA.order;
|
|
@@ -1754,9 +1768,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1754
1768
|
layout: unsafeLayout,
|
|
1755
1769
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1756
1770
|
});
|
|
1771
|
+
|
|
1772
|
+
// Offscreen mode makes this a bit weird;
|
|
1773
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1774
|
+
// but the overall layout doesn't change between these two cases.
|
|
1775
|
+
setLayout(nextLayout);
|
|
1776
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1757
1777
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1758
|
-
setLayout(nextLayout);
|
|
1759
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1760
1778
|
if (onLayout) {
|
|
1761
1779
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1762
1780
|
sizePercentage,
|
|
@@ -1775,10 +1793,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1775
1793
|
id: groupId,
|
|
1776
1794
|
keyboardResizeByPercentage,
|
|
1777
1795
|
keyboardResizeByPixels,
|
|
1778
|
-
onLayout
|
|
1779
|
-
panelDataArray,
|
|
1780
|
-
layout: prevLayout
|
|
1796
|
+
onLayout
|
|
1781
1797
|
} = committedValuesRef.current;
|
|
1798
|
+
const {
|
|
1799
|
+
layout: prevLayout,
|
|
1800
|
+
panelDataArray
|
|
1801
|
+
} = eagerValuesRef.current;
|
|
1782
1802
|
const {
|
|
1783
1803
|
initialLayout
|
|
1784
1804
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1834,7 +1854,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1834
1854
|
}
|
|
1835
1855
|
if (layoutChanged) {
|
|
1836
1856
|
setLayout(nextLayout);
|
|
1837
|
-
|
|
1857
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1838
1858
|
if (onLayout) {
|
|
1839
1859
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1840
1860
|
sizePercentage,
|
|
@@ -1848,11 +1868,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1848
1868
|
|
|
1849
1869
|
// External APIs are safe to memoize via committed values ref
|
|
1850
1870
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1871
|
+
const {
|
|
1872
|
+
onLayout
|
|
1873
|
+
} = committedValuesRef.current;
|
|
1851
1874
|
const {
|
|
1852
1875
|
layout: prevLayout,
|
|
1853
|
-
onLayout,
|
|
1854
1876
|
panelDataArray
|
|
1855
|
-
} =
|
|
1877
|
+
} = eagerValuesRef.current;
|
|
1856
1878
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1857
1879
|
const {
|
|
1858
1880
|
groupSizePixels,
|
|
@@ -1872,7 +1894,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1872
1894
|
});
|
|
1873
1895
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1874
1896
|
setLayout(nextLayout);
|
|
1875
|
-
|
|
1897
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1876
1898
|
if (onLayout) {
|
|
1877
1899
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1878
1900
|
sizePercentage,
|
|
@@ -1884,9 +1906,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1884
1906
|
}, [groupId]);
|
|
1885
1907
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1886
1908
|
const {
|
|
1887
|
-
direction
|
|
1888
|
-
layout
|
|
1909
|
+
direction
|
|
1889
1910
|
} = committedValuesRef.current;
|
|
1911
|
+
const {
|
|
1912
|
+
layout
|
|
1913
|
+
} = eagerValuesRef.current;
|
|
1890
1914
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1891
1915
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1892
1916
|
setDragState({
|
|
@@ -1907,10 +1931,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1907
1931
|
const unregisterPanel = useCallback(panelData => {
|
|
1908
1932
|
const {
|
|
1909
1933
|
id: groupId,
|
|
1934
|
+
onLayout
|
|
1935
|
+
} = committedValuesRef.current;
|
|
1936
|
+
const {
|
|
1910
1937
|
layout: prevLayout,
|
|
1911
|
-
onLayout,
|
|
1912
1938
|
panelDataArray
|
|
1913
|
-
} =
|
|
1939
|
+
} = eagerValuesRef.current;
|
|
1914
1940
|
const index = panelDataArray.indexOf(panelData);
|
|
1915
1941
|
if (index >= 0) {
|
|
1916
1942
|
panelDataArray.splice(index, 1);
|
|
@@ -1927,7 +1953,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1927
1953
|
const {
|
|
1928
1954
|
pendingPanelIds
|
|
1929
1955
|
} = unregisterPanelRef.current;
|
|
1930
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1956
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1931
1957
|
|
|
1932
1958
|
// TRICKY
|
|
1933
1959
|
// Strict effects mode
|
|
@@ -1943,7 +1969,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1943
1969
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1944
1970
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1945
1971
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1946
|
-
delete
|
|
1972
|
+
delete map[panelData.id];
|
|
1947
1973
|
}
|
|
1948
1974
|
});
|
|
1949
1975
|
if (!unmountDueToStrictMode) {
|
|
@@ -1968,7 +1994,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1968
1994
|
});
|
|
1969
1995
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1970
1996
|
setLayout(nextLayout);
|
|
1971
|
-
|
|
1997
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1972
1998
|
if (onLayout) {
|
|
1973
1999
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1974
2000
|
sizePercentage,
|