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
|
@@ -700,6 +700,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
700
700
|
|
|
701
701
|
function useWindowSplitterPanelGroupBehavior({
|
|
702
702
|
committedValuesRef,
|
|
703
|
+
eagerValuesRef,
|
|
703
704
|
groupId,
|
|
704
705
|
layout,
|
|
705
706
|
panelDataArray,
|
|
@@ -752,7 +753,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
752
753
|
useEffect(() => {
|
|
753
754
|
const {
|
|
754
755
|
panelDataArray
|
|
755
|
-
} =
|
|
756
|
+
} = eagerValuesRef.current;
|
|
756
757
|
const groupElement = getPanelGroupElement(groupId);
|
|
757
758
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
758
759
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -810,7 +811,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
810
811
|
return () => {
|
|
811
812
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
812
813
|
};
|
|
813
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
814
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
814
815
|
}
|
|
815
816
|
|
|
816
817
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1352,11 +1353,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1352
1353
|
id: groupId,
|
|
1353
1354
|
keyboardResizeByPercentage,
|
|
1354
1355
|
keyboardResizeByPixels,
|
|
1355
|
-
layout,
|
|
1356
1356
|
onLayout,
|
|
1357
|
-
panelDataArray: [],
|
|
1358
1357
|
storage
|
|
1359
1358
|
});
|
|
1359
|
+
const eagerValuesRef = useRef({
|
|
1360
|
+
layout,
|
|
1361
|
+
panelDataArray: []
|
|
1362
|
+
});
|
|
1360
1363
|
const devWarningsRef = useRef({
|
|
1361
1364
|
didLogIdAndOrderWarning: false,
|
|
1362
1365
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1366,9 +1369,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1366
1369
|
getId: () => committedValuesRef.current.id,
|
|
1367
1370
|
getLayout: () => {
|
|
1368
1371
|
const {
|
|
1369
|
-
id: groupId
|
|
1370
|
-
layout
|
|
1372
|
+
id: groupId
|
|
1371
1373
|
} = committedValuesRef.current;
|
|
1374
|
+
const {
|
|
1375
|
+
layout
|
|
1376
|
+
} = eagerValuesRef.current;
|
|
1372
1377
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1373
1378
|
return layout.map(sizePercentage => {
|
|
1374
1379
|
return {
|
|
@@ -1380,10 +1385,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1380
1385
|
setLayout: mixedSizes => {
|
|
1381
1386
|
const {
|
|
1382
1387
|
id: groupId,
|
|
1388
|
+
onLayout
|
|
1389
|
+
} = committedValuesRef.current;
|
|
1390
|
+
const {
|
|
1383
1391
|
layout: prevLayout,
|
|
1384
|
-
onLayout,
|
|
1385
1392
|
panelDataArray
|
|
1386
|
-
} =
|
|
1393
|
+
} = eagerValuesRef.current;
|
|
1387
1394
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1388
1395
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1389
1396
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1393,7 +1400,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1393
1400
|
});
|
|
1394
1401
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1395
1402
|
setLayout(safeLayout);
|
|
1396
|
-
|
|
1403
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1397
1404
|
if (onLayout) {
|
|
1398
1405
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1399
1406
|
sizePercentage,
|
|
@@ -1418,15 +1425,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1418
1425
|
|
|
1419
1426
|
useWindowSplitterPanelGroupBehavior({
|
|
1420
1427
|
committedValuesRef,
|
|
1428
|
+
eagerValuesRef,
|
|
1421
1429
|
groupId,
|
|
1422
1430
|
layout,
|
|
1423
|
-
panelDataArray:
|
|
1431
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1424
1432
|
setLayout
|
|
1425
1433
|
});
|
|
1426
1434
|
useEffect(() => {
|
|
1427
1435
|
const {
|
|
1428
1436
|
panelDataArray
|
|
1429
|
-
} =
|
|
1437
|
+
} = eagerValuesRef.current;
|
|
1430
1438
|
|
|
1431
1439
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1432
1440
|
if (autoSaveId) {
|
|
@@ -1443,8 +1451,9 @@ function PanelGroupWithForwardedRef({
|
|
|
1443
1451
|
}, [autoSaveId, layout, storage]);
|
|
1444
1452
|
useIsomorphicLayoutEffect(() => {
|
|
1445
1453
|
const {
|
|
1454
|
+
layout: prevLayout,
|
|
1446
1455
|
panelDataArray
|
|
1447
|
-
} =
|
|
1456
|
+
} = eagerValuesRef.current;
|
|
1448
1457
|
const constraints = panelDataArray.map(({
|
|
1449
1458
|
constraints
|
|
1450
1459
|
}) => constraints);
|
|
@@ -1458,7 +1467,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1458
1467
|
const resizeObserver = new ResizeObserver(() => {
|
|
1459
1468
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1460
1469
|
const {
|
|
1461
|
-
layout: prevLayout,
|
|
1462
1470
|
onLayout
|
|
1463
1471
|
} = committedValuesRef.current;
|
|
1464
1472
|
const nextLayout = validatePanelGroupLayout({
|
|
@@ -1468,7 +1476,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1468
1476
|
});
|
|
1469
1477
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1470
1478
|
setLayout(nextLayout);
|
|
1471
|
-
|
|
1479
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1472
1480
|
if (onLayout) {
|
|
1473
1481
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1474
1482
|
sizePercentage,
|
|
@@ -1490,7 +1498,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1490
1498
|
{
|
|
1491
1499
|
const {
|
|
1492
1500
|
panelDataArray
|
|
1493
|
-
} =
|
|
1501
|
+
} = eagerValuesRef.current;
|
|
1494
1502
|
const {
|
|
1495
1503
|
didLogIdAndOrderWarning,
|
|
1496
1504
|
didLogPanelConstraintsWarning,
|
|
@@ -1533,11 +1541,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1533
1541
|
|
|
1534
1542
|
// External APIs are safe to memoize via committed values ref
|
|
1535
1543
|
const collapsePanel = useCallback(panelData => {
|
|
1544
|
+
const {
|
|
1545
|
+
onLayout
|
|
1546
|
+
} = committedValuesRef.current;
|
|
1536
1547
|
const {
|
|
1537
1548
|
layout: prevLayout,
|
|
1538
|
-
onLayout,
|
|
1539
1549
|
panelDataArray
|
|
1540
|
-
} =
|
|
1550
|
+
} = eagerValuesRef.current;
|
|
1541
1551
|
if (panelData.constraints.collapsible) {
|
|
1542
1552
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1543
1553
|
const {
|
|
@@ -1562,7 +1572,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1562
1572
|
});
|
|
1563
1573
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1564
1574
|
setLayout(nextLayout);
|
|
1565
|
-
|
|
1575
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1566
1576
|
if (onLayout) {
|
|
1567
1577
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1568
1578
|
sizePercentage,
|
|
@@ -1577,11 +1587,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1577
1587
|
|
|
1578
1588
|
// External APIs are safe to memoize via committed values ref
|
|
1579
1589
|
const expandPanel = useCallback(panelData => {
|
|
1590
|
+
const {
|
|
1591
|
+
onLayout
|
|
1592
|
+
} = committedValuesRef.current;
|
|
1580
1593
|
const {
|
|
1581
1594
|
layout: prevLayout,
|
|
1582
|
-
onLayout,
|
|
1583
1595
|
panelDataArray
|
|
1584
|
-
} =
|
|
1596
|
+
} = eagerValuesRef.current;
|
|
1585
1597
|
if (panelData.constraints.collapsible) {
|
|
1586
1598
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1587
1599
|
const {
|
|
@@ -1594,7 +1606,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1594
1606
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1595
1607
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1596
1608
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1597
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1609
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1598
1610
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1599
1611
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1600
1612
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1607,7 +1619,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1607
1619
|
});
|
|
1608
1620
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1609
1621
|
setLayout(nextLayout);
|
|
1610
|
-
|
|
1622
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1611
1623
|
if (onLayout) {
|
|
1612
1624
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1613
1625
|
sizePercentage,
|
|
@@ -1625,7 +1637,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1625
1637
|
const {
|
|
1626
1638
|
layout,
|
|
1627
1639
|
panelDataArray
|
|
1628
|
-
} =
|
|
1640
|
+
} = eagerValuesRef.current;
|
|
1629
1641
|
const {
|
|
1630
1642
|
panelSizePercentage,
|
|
1631
1643
|
panelSizePixels
|
|
@@ -1640,7 +1652,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1640
1652
|
const getPanelStyle = useCallback(panelData => {
|
|
1641
1653
|
const {
|
|
1642
1654
|
panelDataArray
|
|
1643
|
-
} =
|
|
1655
|
+
} = eagerValuesRef.current;
|
|
1644
1656
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1645
1657
|
return computePanelFlexBoxStyle({
|
|
1646
1658
|
dragState,
|
|
@@ -1655,7 +1667,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1655
1667
|
const {
|
|
1656
1668
|
layout,
|
|
1657
1669
|
panelDataArray
|
|
1658
|
-
} =
|
|
1670
|
+
} = eagerValuesRef.current;
|
|
1659
1671
|
const {
|
|
1660
1672
|
collapsedSizePercentage,
|
|
1661
1673
|
collapsible,
|
|
@@ -1669,7 +1681,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1669
1681
|
const {
|
|
1670
1682
|
layout,
|
|
1671
1683
|
panelDataArray
|
|
1672
|
-
} =
|
|
1684
|
+
} = eagerValuesRef.current;
|
|
1673
1685
|
const {
|
|
1674
1686
|
collapsedSizePercentage,
|
|
1675
1687
|
collapsible,
|
|
@@ -1681,11 +1693,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1681
1693
|
const {
|
|
1682
1694
|
autoSaveId,
|
|
1683
1695
|
id: groupId,
|
|
1684
|
-
layout: prevLayout,
|
|
1685
1696
|
onLayout,
|
|
1686
|
-
panelDataArray,
|
|
1687
1697
|
storage
|
|
1688
1698
|
} = committedValuesRef.current;
|
|
1699
|
+
const {
|
|
1700
|
+
layout: prevLayout,
|
|
1701
|
+
panelDataArray
|
|
1702
|
+
} = eagerValuesRef.current;
|
|
1689
1703
|
panelDataArray.push(panelData);
|
|
1690
1704
|
panelDataArray.sort((panelA, panelB) => {
|
|
1691
1705
|
const orderA = panelA.order;
|
|
@@ -1737,9 +1751,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1737
1751
|
layout: unsafeLayout,
|
|
1738
1752
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1739
1753
|
});
|
|
1754
|
+
|
|
1755
|
+
// Offscreen mode makes this a bit weird;
|
|
1756
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1757
|
+
// but the overall layout doesn't change between these two cases.
|
|
1758
|
+
setLayout(nextLayout);
|
|
1759
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1740
1760
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1741
|
-
setLayout(nextLayout);
|
|
1742
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1743
1761
|
if (onLayout) {
|
|
1744
1762
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1745
1763
|
sizePercentage,
|
|
@@ -1758,10 +1776,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1758
1776
|
id: groupId,
|
|
1759
1777
|
keyboardResizeByPercentage,
|
|
1760
1778
|
keyboardResizeByPixels,
|
|
1761
|
-
onLayout
|
|
1762
|
-
panelDataArray,
|
|
1763
|
-
layout: prevLayout
|
|
1779
|
+
onLayout
|
|
1764
1780
|
} = committedValuesRef.current;
|
|
1781
|
+
const {
|
|
1782
|
+
layout: prevLayout,
|
|
1783
|
+
panelDataArray
|
|
1784
|
+
} = eagerValuesRef.current;
|
|
1765
1785
|
const {
|
|
1766
1786
|
initialLayout
|
|
1767
1787
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1817,7 +1837,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1817
1837
|
}
|
|
1818
1838
|
if (layoutChanged) {
|
|
1819
1839
|
setLayout(nextLayout);
|
|
1820
|
-
|
|
1840
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1821
1841
|
if (onLayout) {
|
|
1822
1842
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1823
1843
|
sizePercentage,
|
|
@@ -1831,11 +1851,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1831
1851
|
|
|
1832
1852
|
// External APIs are safe to memoize via committed values ref
|
|
1833
1853
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1854
|
+
const {
|
|
1855
|
+
onLayout
|
|
1856
|
+
} = committedValuesRef.current;
|
|
1834
1857
|
const {
|
|
1835
1858
|
layout: prevLayout,
|
|
1836
|
-
onLayout,
|
|
1837
1859
|
panelDataArray
|
|
1838
|
-
} =
|
|
1860
|
+
} = eagerValuesRef.current;
|
|
1839
1861
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1840
1862
|
const {
|
|
1841
1863
|
groupSizePixels,
|
|
@@ -1855,7 +1877,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1855
1877
|
});
|
|
1856
1878
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1857
1879
|
setLayout(nextLayout);
|
|
1858
|
-
|
|
1880
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1859
1881
|
if (onLayout) {
|
|
1860
1882
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1861
1883
|
sizePercentage,
|
|
@@ -1867,9 +1889,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1867
1889
|
}, [groupId]);
|
|
1868
1890
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1869
1891
|
const {
|
|
1870
|
-
direction
|
|
1871
|
-
layout
|
|
1892
|
+
direction
|
|
1872
1893
|
} = committedValuesRef.current;
|
|
1894
|
+
const {
|
|
1895
|
+
layout
|
|
1896
|
+
} = eagerValuesRef.current;
|
|
1873
1897
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1874
1898
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1875
1899
|
setDragState({
|
|
@@ -1890,10 +1914,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1890
1914
|
const unregisterPanel = useCallback(panelData => {
|
|
1891
1915
|
const {
|
|
1892
1916
|
id: groupId,
|
|
1917
|
+
onLayout
|
|
1918
|
+
} = committedValuesRef.current;
|
|
1919
|
+
const {
|
|
1893
1920
|
layout: prevLayout,
|
|
1894
|
-
onLayout,
|
|
1895
1921
|
panelDataArray
|
|
1896
|
-
} =
|
|
1922
|
+
} = eagerValuesRef.current;
|
|
1897
1923
|
const index = panelDataArray.indexOf(panelData);
|
|
1898
1924
|
if (index >= 0) {
|
|
1899
1925
|
panelDataArray.splice(index, 1);
|
|
@@ -1910,7 +1936,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1910
1936
|
const {
|
|
1911
1937
|
pendingPanelIds
|
|
1912
1938
|
} = unregisterPanelRef.current;
|
|
1913
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1939
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1914
1940
|
|
|
1915
1941
|
// TRICKY
|
|
1916
1942
|
// Strict effects mode
|
|
@@ -1926,7 +1952,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1926
1952
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1927
1953
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1928
1954
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1929
|
-
delete
|
|
1955
|
+
delete map[panelData.id];
|
|
1930
1956
|
}
|
|
1931
1957
|
});
|
|
1932
1958
|
if (!unmountDueToStrictMode) {
|
|
@@ -1951,7 +1977,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1951
1977
|
});
|
|
1952
1978
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1953
1979
|
setLayout(nextLayout);
|
|
1954
|
-
|
|
1980
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1955
1981
|
if (onLayout) {
|
|
1956
1982
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1957
1983
|
sizePercentage,
|
|
@@ -643,6 +643,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
643
643
|
|
|
644
644
|
function useWindowSplitterPanelGroupBehavior({
|
|
645
645
|
committedValuesRef,
|
|
646
|
+
eagerValuesRef,
|
|
646
647
|
groupId,
|
|
647
648
|
layout,
|
|
648
649
|
panelDataArray,
|
|
@@ -654,7 +655,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
654
655
|
useEffect(() => {
|
|
655
656
|
const {
|
|
656
657
|
panelDataArray
|
|
657
|
-
} =
|
|
658
|
+
} = eagerValuesRef.current;
|
|
658
659
|
const groupElement = getPanelGroupElement(groupId);
|
|
659
660
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
660
661
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -712,7 +713,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
712
713
|
return () => {
|
|
713
714
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
714
715
|
};
|
|
715
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
716
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
716
717
|
}
|
|
717
718
|
|
|
718
719
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1254,11 +1255,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1254
1255
|
id: groupId,
|
|
1255
1256
|
keyboardResizeByPercentage,
|
|
1256
1257
|
keyboardResizeByPixels,
|
|
1257
|
-
layout,
|
|
1258
1258
|
onLayout,
|
|
1259
|
-
panelDataArray: [],
|
|
1260
1259
|
storage
|
|
1261
1260
|
});
|
|
1261
|
+
const eagerValuesRef = useRef({
|
|
1262
|
+
layout,
|
|
1263
|
+
panelDataArray: []
|
|
1264
|
+
});
|
|
1262
1265
|
const devWarningsRef = useRef({
|
|
1263
1266
|
didLogIdAndOrderWarning: false,
|
|
1264
1267
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1268,9 +1271,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1268
1271
|
getId: () => committedValuesRef.current.id,
|
|
1269
1272
|
getLayout: () => {
|
|
1270
1273
|
const {
|
|
1271
|
-
id: groupId
|
|
1272
|
-
layout
|
|
1274
|
+
id: groupId
|
|
1273
1275
|
} = committedValuesRef.current;
|
|
1276
|
+
const {
|
|
1277
|
+
layout
|
|
1278
|
+
} = eagerValuesRef.current;
|
|
1274
1279
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1275
1280
|
return layout.map(sizePercentage => {
|
|
1276
1281
|
return {
|
|
@@ -1282,10 +1287,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1282
1287
|
setLayout: mixedSizes => {
|
|
1283
1288
|
const {
|
|
1284
1289
|
id: groupId,
|
|
1290
|
+
onLayout
|
|
1291
|
+
} = committedValuesRef.current;
|
|
1292
|
+
const {
|
|
1285
1293
|
layout: prevLayout,
|
|
1286
|
-
onLayout,
|
|
1287
1294
|
panelDataArray
|
|
1288
|
-
} =
|
|
1295
|
+
} = eagerValuesRef.current;
|
|
1289
1296
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1290
1297
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1291
1298
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1295,7 +1302,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1295
1302
|
});
|
|
1296
1303
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1297
1304
|
setLayout(safeLayout);
|
|
1298
|
-
|
|
1305
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1299
1306
|
if (onLayout) {
|
|
1300
1307
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1301
1308
|
sizePercentage,
|
|
@@ -1309,15 +1316,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1309
1316
|
|
|
1310
1317
|
useWindowSplitterPanelGroupBehavior({
|
|
1311
1318
|
committedValuesRef,
|
|
1319
|
+
eagerValuesRef,
|
|
1312
1320
|
groupId,
|
|
1313
1321
|
layout,
|
|
1314
|
-
panelDataArray:
|
|
1322
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1315
1323
|
setLayout
|
|
1316
1324
|
});
|
|
1317
1325
|
useEffect(() => {
|
|
1318
1326
|
const {
|
|
1319
1327
|
panelDataArray
|
|
1320
|
-
} =
|
|
1328
|
+
} = eagerValuesRef.current;
|
|
1321
1329
|
|
|
1322
1330
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1323
1331
|
if (autoSaveId) {
|
|
@@ -1338,7 +1346,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1338
1346
|
{
|
|
1339
1347
|
const {
|
|
1340
1348
|
panelDataArray
|
|
1341
|
-
} =
|
|
1349
|
+
} = eagerValuesRef.current;
|
|
1342
1350
|
const {
|
|
1343
1351
|
didLogIdAndOrderWarning,
|
|
1344
1352
|
didLogPanelConstraintsWarning,
|
|
@@ -1381,11 +1389,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1381
1389
|
|
|
1382
1390
|
// External APIs are safe to memoize via committed values ref
|
|
1383
1391
|
const collapsePanel = useCallback(panelData => {
|
|
1392
|
+
const {
|
|
1393
|
+
onLayout
|
|
1394
|
+
} = committedValuesRef.current;
|
|
1384
1395
|
const {
|
|
1385
1396
|
layout: prevLayout,
|
|
1386
|
-
onLayout,
|
|
1387
1397
|
panelDataArray
|
|
1388
|
-
} =
|
|
1398
|
+
} = eagerValuesRef.current;
|
|
1389
1399
|
if (panelData.constraints.collapsible) {
|
|
1390
1400
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1391
1401
|
const {
|
|
@@ -1410,7 +1420,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1410
1420
|
});
|
|
1411
1421
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1412
1422
|
setLayout(nextLayout);
|
|
1413
|
-
|
|
1423
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1414
1424
|
if (onLayout) {
|
|
1415
1425
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1416
1426
|
sizePercentage,
|
|
@@ -1425,11 +1435,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1425
1435
|
|
|
1426
1436
|
// External APIs are safe to memoize via committed values ref
|
|
1427
1437
|
const expandPanel = useCallback(panelData => {
|
|
1438
|
+
const {
|
|
1439
|
+
onLayout
|
|
1440
|
+
} = committedValuesRef.current;
|
|
1428
1441
|
const {
|
|
1429
1442
|
layout: prevLayout,
|
|
1430
|
-
onLayout,
|
|
1431
1443
|
panelDataArray
|
|
1432
|
-
} =
|
|
1444
|
+
} = eagerValuesRef.current;
|
|
1433
1445
|
if (panelData.constraints.collapsible) {
|
|
1434
1446
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1435
1447
|
const {
|
|
@@ -1442,7 +1454,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1442
1454
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1443
1455
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1444
1456
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1445
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1457
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1446
1458
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1447
1459
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1448
1460
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1455,7 +1467,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1455
1467
|
});
|
|
1456
1468
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1457
1469
|
setLayout(nextLayout);
|
|
1458
|
-
|
|
1470
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1459
1471
|
if (onLayout) {
|
|
1460
1472
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1461
1473
|
sizePercentage,
|
|
@@ -1473,7 +1485,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1473
1485
|
const {
|
|
1474
1486
|
layout,
|
|
1475
1487
|
panelDataArray
|
|
1476
|
-
} =
|
|
1488
|
+
} = eagerValuesRef.current;
|
|
1477
1489
|
const {
|
|
1478
1490
|
panelSizePercentage,
|
|
1479
1491
|
panelSizePixels
|
|
@@ -1488,7 +1500,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1488
1500
|
const getPanelStyle = useCallback(panelData => {
|
|
1489
1501
|
const {
|
|
1490
1502
|
panelDataArray
|
|
1491
|
-
} =
|
|
1503
|
+
} = eagerValuesRef.current;
|
|
1492
1504
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1493
1505
|
return computePanelFlexBoxStyle({
|
|
1494
1506
|
dragState,
|
|
@@ -1503,7 +1515,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1503
1515
|
const {
|
|
1504
1516
|
layout,
|
|
1505
1517
|
panelDataArray
|
|
1506
|
-
} =
|
|
1518
|
+
} = eagerValuesRef.current;
|
|
1507
1519
|
const {
|
|
1508
1520
|
collapsedSizePercentage,
|
|
1509
1521
|
collapsible,
|
|
@@ -1517,7 +1529,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1517
1529
|
const {
|
|
1518
1530
|
layout,
|
|
1519
1531
|
panelDataArray
|
|
1520
|
-
} =
|
|
1532
|
+
} = eagerValuesRef.current;
|
|
1521
1533
|
const {
|
|
1522
1534
|
collapsedSizePercentage,
|
|
1523
1535
|
collapsible,
|
|
@@ -1529,11 +1541,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1529
1541
|
const {
|
|
1530
1542
|
autoSaveId,
|
|
1531
1543
|
id: groupId,
|
|
1532
|
-
layout: prevLayout,
|
|
1533
1544
|
onLayout,
|
|
1534
|
-
panelDataArray,
|
|
1535
1545
|
storage
|
|
1536
1546
|
} = committedValuesRef.current;
|
|
1547
|
+
const {
|
|
1548
|
+
layout: prevLayout,
|
|
1549
|
+
panelDataArray
|
|
1550
|
+
} = eagerValuesRef.current;
|
|
1537
1551
|
panelDataArray.push(panelData);
|
|
1538
1552
|
panelDataArray.sort((panelA, panelB) => {
|
|
1539
1553
|
const orderA = panelA.order;
|
|
@@ -1585,9 +1599,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1585
1599
|
layout: unsafeLayout,
|
|
1586
1600
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1587
1601
|
});
|
|
1602
|
+
|
|
1603
|
+
// Offscreen mode makes this a bit weird;
|
|
1604
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1605
|
+
// but the overall layout doesn't change between these two cases.
|
|
1606
|
+
setLayout(nextLayout);
|
|
1607
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1588
1608
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1589
|
-
setLayout(nextLayout);
|
|
1590
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1591
1609
|
if (onLayout) {
|
|
1592
1610
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1593
1611
|
sizePercentage,
|
|
@@ -1606,10 +1624,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1606
1624
|
id: groupId,
|
|
1607
1625
|
keyboardResizeByPercentage,
|
|
1608
1626
|
keyboardResizeByPixels,
|
|
1609
|
-
onLayout
|
|
1610
|
-
panelDataArray,
|
|
1611
|
-
layout: prevLayout
|
|
1627
|
+
onLayout
|
|
1612
1628
|
} = committedValuesRef.current;
|
|
1629
|
+
const {
|
|
1630
|
+
layout: prevLayout,
|
|
1631
|
+
panelDataArray
|
|
1632
|
+
} = eagerValuesRef.current;
|
|
1613
1633
|
const {
|
|
1614
1634
|
initialLayout
|
|
1615
1635
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1665,7 +1685,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1665
1685
|
}
|
|
1666
1686
|
if (layoutChanged) {
|
|
1667
1687
|
setLayout(nextLayout);
|
|
1668
|
-
|
|
1688
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1669
1689
|
if (onLayout) {
|
|
1670
1690
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1671
1691
|
sizePercentage,
|
|
@@ -1679,11 +1699,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1679
1699
|
|
|
1680
1700
|
// External APIs are safe to memoize via committed values ref
|
|
1681
1701
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1702
|
+
const {
|
|
1703
|
+
onLayout
|
|
1704
|
+
} = committedValuesRef.current;
|
|
1682
1705
|
const {
|
|
1683
1706
|
layout: prevLayout,
|
|
1684
|
-
onLayout,
|
|
1685
1707
|
panelDataArray
|
|
1686
|
-
} =
|
|
1708
|
+
} = eagerValuesRef.current;
|
|
1687
1709
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1688
1710
|
const {
|
|
1689
1711
|
groupSizePixels,
|
|
@@ -1703,7 +1725,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1703
1725
|
});
|
|
1704
1726
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1705
1727
|
setLayout(nextLayout);
|
|
1706
|
-
|
|
1728
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1707
1729
|
if (onLayout) {
|
|
1708
1730
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1709
1731
|
sizePercentage,
|
|
@@ -1715,9 +1737,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1715
1737
|
}, [groupId]);
|
|
1716
1738
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1717
1739
|
const {
|
|
1718
|
-
direction
|
|
1719
|
-
layout
|
|
1740
|
+
direction
|
|
1720
1741
|
} = committedValuesRef.current;
|
|
1742
|
+
const {
|
|
1743
|
+
layout
|
|
1744
|
+
} = eagerValuesRef.current;
|
|
1721
1745
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1722
1746
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1723
1747
|
setDragState({
|
|
@@ -1738,10 +1762,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1738
1762
|
const unregisterPanel = useCallback(panelData => {
|
|
1739
1763
|
const {
|
|
1740
1764
|
id: groupId,
|
|
1765
|
+
onLayout
|
|
1766
|
+
} = committedValuesRef.current;
|
|
1767
|
+
const {
|
|
1741
1768
|
layout: prevLayout,
|
|
1742
|
-
onLayout,
|
|
1743
1769
|
panelDataArray
|
|
1744
|
-
} =
|
|
1770
|
+
} = eagerValuesRef.current;
|
|
1745
1771
|
const index = panelDataArray.indexOf(panelData);
|
|
1746
1772
|
if (index >= 0) {
|
|
1747
1773
|
panelDataArray.splice(index, 1);
|
|
@@ -1758,7 +1784,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1758
1784
|
const {
|
|
1759
1785
|
pendingPanelIds
|
|
1760
1786
|
} = unregisterPanelRef.current;
|
|
1761
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1787
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1762
1788
|
|
|
1763
1789
|
// TRICKY
|
|
1764
1790
|
// Strict effects mode
|
|
@@ -1774,7 +1800,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1774
1800
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1775
1801
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1776
1802
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1777
|
-
delete
|
|
1803
|
+
delete map[panelData.id];
|
|
1778
1804
|
}
|
|
1779
1805
|
});
|
|
1780
1806
|
if (!unmountDueToStrictMode) {
|
|
@@ -1799,7 +1825,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1799
1825
|
});
|
|
1800
1826
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1801
1827
|
setLayout(nextLayout);
|
|
1802
|
-
|
|
1828
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1803
1829
|
if (onLayout) {
|
|
1804
1830
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1805
1831
|
sizePercentage,
|