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.
@@ -693,6 +693,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
693
693
 
694
694
  function useWindowSplitterPanelGroupBehavior({
695
695
  committedValuesRef,
696
+ eagerValuesRef,
696
697
  groupId,
697
698
  layout,
698
699
  panelDataArray,
@@ -745,7 +746,7 @@ function useWindowSplitterPanelGroupBehavior({
745
746
  useEffect(() => {
746
747
  const {
747
748
  panelDataArray
748
- } = committedValuesRef.current;
749
+ } = eagerValuesRef.current;
749
750
  const groupElement = getPanelGroupElement(groupId);
750
751
  assert(groupElement != null, `No group found for id "${groupId}"`);
751
752
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -803,7 +804,7 @@ function useWindowSplitterPanelGroupBehavior({
803
804
  return () => {
804
805
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
805
806
  };
806
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
807
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
807
808
  }
808
809
 
809
810
  function areEqual(arrayA, arrayB) {
@@ -1345,11 +1346,13 @@ function PanelGroupWithForwardedRef({
1345
1346
  id: groupId,
1346
1347
  keyboardResizeByPercentage,
1347
1348
  keyboardResizeByPixels,
1348
- layout,
1349
1349
  onLayout,
1350
- panelDataArray: [],
1351
1350
  storage
1352
1351
  });
1352
+ const eagerValuesRef = useRef({
1353
+ layout,
1354
+ panelDataArray: []
1355
+ });
1353
1356
  const devWarningsRef = useRef({
1354
1357
  didLogIdAndOrderWarning: false,
1355
1358
  didLogPanelConstraintsWarning: false,
@@ -1359,9 +1362,11 @@ function PanelGroupWithForwardedRef({
1359
1362
  getId: () => committedValuesRef.current.id,
1360
1363
  getLayout: () => {
1361
1364
  const {
1362
- id: groupId,
1363
- layout
1365
+ id: groupId
1364
1366
  } = committedValuesRef.current;
1367
+ const {
1368
+ layout
1369
+ } = eagerValuesRef.current;
1365
1370
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1366
1371
  return layout.map(sizePercentage => {
1367
1372
  return {
@@ -1373,10 +1378,12 @@ function PanelGroupWithForwardedRef({
1373
1378
  setLayout: mixedSizes => {
1374
1379
  const {
1375
1380
  id: groupId,
1381
+ onLayout
1382
+ } = committedValuesRef.current;
1383
+ const {
1376
1384
  layout: prevLayout,
1377
- onLayout,
1378
1385
  panelDataArray
1379
- } = committedValuesRef.current;
1386
+ } = eagerValuesRef.current;
1380
1387
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1381
1388
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1382
1389
  const safeLayout = validatePanelGroupLayout({
@@ -1386,7 +1393,7 @@ function PanelGroupWithForwardedRef({
1386
1393
  });
1387
1394
  if (!areEqual(prevLayout, safeLayout)) {
1388
1395
  setLayout(safeLayout);
1389
- committedValuesRef.current.layout = safeLayout;
1396
+ eagerValuesRef.current.layout = safeLayout;
1390
1397
  if (onLayout) {
1391
1398
  onLayout(safeLayout.map(sizePercentage => ({
1392
1399
  sizePercentage,
@@ -1411,15 +1418,16 @@ function PanelGroupWithForwardedRef({
1411
1418
 
1412
1419
  useWindowSplitterPanelGroupBehavior({
1413
1420
  committedValuesRef,
1421
+ eagerValuesRef,
1414
1422
  groupId,
1415
1423
  layout,
1416
- panelDataArray: committedValuesRef.current.panelDataArray,
1424
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1417
1425
  setLayout
1418
1426
  });
1419
1427
  useEffect(() => {
1420
1428
  const {
1421
1429
  panelDataArray
1422
- } = committedValuesRef.current;
1430
+ } = eagerValuesRef.current;
1423
1431
 
1424
1432
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1425
1433
  if (autoSaveId) {
@@ -1436,8 +1444,9 @@ function PanelGroupWithForwardedRef({
1436
1444
  }, [autoSaveId, layout, storage]);
1437
1445
  useIsomorphicLayoutEffect(() => {
1438
1446
  const {
1447
+ layout: prevLayout,
1439
1448
  panelDataArray
1440
- } = committedValuesRef.current;
1449
+ } = eagerValuesRef.current;
1441
1450
  const constraints = panelDataArray.map(({
1442
1451
  constraints
1443
1452
  }) => constraints);
@@ -1451,7 +1460,6 @@ function PanelGroupWithForwardedRef({
1451
1460
  const resizeObserver = new ResizeObserver(() => {
1452
1461
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1453
1462
  const {
1454
- layout: prevLayout,
1455
1463
  onLayout
1456
1464
  } = committedValuesRef.current;
1457
1465
  const nextLayout = validatePanelGroupLayout({
@@ -1461,7 +1469,7 @@ function PanelGroupWithForwardedRef({
1461
1469
  });
1462
1470
  if (!areEqual(prevLayout, nextLayout)) {
1463
1471
  setLayout(nextLayout);
1464
- committedValuesRef.current.layout = nextLayout;
1472
+ eagerValuesRef.current.layout = nextLayout;
1465
1473
  if (onLayout) {
1466
1474
  onLayout(nextLayout.map(sizePercentage => ({
1467
1475
  sizePercentage,
@@ -1483,7 +1491,7 @@ function PanelGroupWithForwardedRef({
1483
1491
  {
1484
1492
  const {
1485
1493
  panelDataArray
1486
- } = committedValuesRef.current;
1494
+ } = eagerValuesRef.current;
1487
1495
  const {
1488
1496
  didLogIdAndOrderWarning,
1489
1497
  didLogPanelConstraintsWarning,
@@ -1526,11 +1534,13 @@ function PanelGroupWithForwardedRef({
1526
1534
 
1527
1535
  // External APIs are safe to memoize via committed values ref
1528
1536
  const collapsePanel = useCallback(panelData => {
1537
+ const {
1538
+ onLayout
1539
+ } = committedValuesRef.current;
1529
1540
  const {
1530
1541
  layout: prevLayout,
1531
- onLayout,
1532
1542
  panelDataArray
1533
- } = committedValuesRef.current;
1543
+ } = eagerValuesRef.current;
1534
1544
  if (panelData.constraints.collapsible) {
1535
1545
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1536
1546
  const {
@@ -1555,7 +1565,7 @@ function PanelGroupWithForwardedRef({
1555
1565
  });
1556
1566
  if (!compareLayouts(prevLayout, nextLayout)) {
1557
1567
  setLayout(nextLayout);
1558
- committedValuesRef.current.layout = nextLayout;
1568
+ eagerValuesRef.current.layout = nextLayout;
1559
1569
  if (onLayout) {
1560
1570
  onLayout(nextLayout.map(sizePercentage => ({
1561
1571
  sizePercentage,
@@ -1570,11 +1580,13 @@ function PanelGroupWithForwardedRef({
1570
1580
 
1571
1581
  // External APIs are safe to memoize via committed values ref
1572
1582
  const expandPanel = useCallback(panelData => {
1583
+ const {
1584
+ onLayout
1585
+ } = committedValuesRef.current;
1573
1586
  const {
1574
1587
  layout: prevLayout,
1575
- onLayout,
1576
1588
  panelDataArray
1577
- } = committedValuesRef.current;
1589
+ } = eagerValuesRef.current;
1578
1590
  if (panelData.constraints.collapsible) {
1579
1591
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1580
1592
  const {
@@ -1587,7 +1599,7 @@ function PanelGroupWithForwardedRef({
1587
1599
  if (panelSizePercentage === collapsedSizePercentage) {
1588
1600
  // Restore this panel to the size it was before it was collapsed, if possible.
1589
1601
  const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
1590
- const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
1602
+ const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
1591
1603
  const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1592
1604
  const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
1593
1605
  const nextLayout = adjustLayoutByDelta({
@@ -1600,7 +1612,7 @@ function PanelGroupWithForwardedRef({
1600
1612
  });
1601
1613
  if (!compareLayouts(prevLayout, nextLayout)) {
1602
1614
  setLayout(nextLayout);
1603
- committedValuesRef.current.layout = nextLayout;
1615
+ eagerValuesRef.current.layout = nextLayout;
1604
1616
  if (onLayout) {
1605
1617
  onLayout(nextLayout.map(sizePercentage => ({
1606
1618
  sizePercentage,
@@ -1618,7 +1630,7 @@ function PanelGroupWithForwardedRef({
1618
1630
  const {
1619
1631
  layout,
1620
1632
  panelDataArray
1621
- } = committedValuesRef.current;
1633
+ } = eagerValuesRef.current;
1622
1634
  const {
1623
1635
  panelSizePercentage,
1624
1636
  panelSizePixels
@@ -1633,7 +1645,7 @@ function PanelGroupWithForwardedRef({
1633
1645
  const getPanelStyle = useCallback(panelData => {
1634
1646
  const {
1635
1647
  panelDataArray
1636
- } = committedValuesRef.current;
1648
+ } = eagerValuesRef.current;
1637
1649
  const panelIndex = panelDataArray.indexOf(panelData);
1638
1650
  return computePanelFlexBoxStyle({
1639
1651
  dragState,
@@ -1648,7 +1660,7 @@ function PanelGroupWithForwardedRef({
1648
1660
  const {
1649
1661
  layout,
1650
1662
  panelDataArray
1651
- } = committedValuesRef.current;
1663
+ } = eagerValuesRef.current;
1652
1664
  const {
1653
1665
  collapsedSizePercentage,
1654
1666
  collapsible,
@@ -1662,7 +1674,7 @@ function PanelGroupWithForwardedRef({
1662
1674
  const {
1663
1675
  layout,
1664
1676
  panelDataArray
1665
- } = committedValuesRef.current;
1677
+ } = eagerValuesRef.current;
1666
1678
  const {
1667
1679
  collapsedSizePercentage,
1668
1680
  collapsible,
@@ -1674,11 +1686,13 @@ function PanelGroupWithForwardedRef({
1674
1686
  const {
1675
1687
  autoSaveId,
1676
1688
  id: groupId,
1677
- layout: prevLayout,
1678
1689
  onLayout,
1679
- panelDataArray,
1680
1690
  storage
1681
1691
  } = committedValuesRef.current;
1692
+ const {
1693
+ layout: prevLayout,
1694
+ panelDataArray
1695
+ } = eagerValuesRef.current;
1682
1696
  panelDataArray.push(panelData);
1683
1697
  panelDataArray.sort((panelA, panelB) => {
1684
1698
  const orderA = panelA.order;
@@ -1730,9 +1744,13 @@ function PanelGroupWithForwardedRef({
1730
1744
  layout: unsafeLayout,
1731
1745
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1732
1746
  });
1747
+
1748
+ // Offscreen mode makes this a bit weird;
1749
+ // Panels unregister when hidden and re-register when shown again,
1750
+ // but the overall layout doesn't change between these two cases.
1751
+ setLayout(nextLayout);
1752
+ eagerValuesRef.current.layout = nextLayout;
1733
1753
  if (!areEqual(prevLayout, nextLayout)) {
1734
- setLayout(nextLayout);
1735
- committedValuesRef.current.layout = nextLayout;
1736
1754
  if (onLayout) {
1737
1755
  onLayout(nextLayout.map(sizePercentage => ({
1738
1756
  sizePercentage,
@@ -1751,10 +1769,12 @@ function PanelGroupWithForwardedRef({
1751
1769
  id: groupId,
1752
1770
  keyboardResizeByPercentage,
1753
1771
  keyboardResizeByPixels,
1754
- onLayout,
1755
- panelDataArray,
1756
- layout: prevLayout
1772
+ onLayout
1757
1773
  } = committedValuesRef.current;
1774
+ const {
1775
+ layout: prevLayout,
1776
+ panelDataArray
1777
+ } = eagerValuesRef.current;
1758
1778
  const {
1759
1779
  initialLayout
1760
1780
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1810,7 +1830,7 @@ function PanelGroupWithForwardedRef({
1810
1830
  }
1811
1831
  if (layoutChanged) {
1812
1832
  setLayout(nextLayout);
1813
- committedValuesRef.current.layout = nextLayout;
1833
+ eagerValuesRef.current.layout = nextLayout;
1814
1834
  if (onLayout) {
1815
1835
  onLayout(nextLayout.map(sizePercentage => ({
1816
1836
  sizePercentage,
@@ -1824,11 +1844,13 @@ function PanelGroupWithForwardedRef({
1824
1844
 
1825
1845
  // External APIs are safe to memoize via committed values ref
1826
1846
  const resizePanel = useCallback((panelData, mixedSizes) => {
1847
+ const {
1848
+ onLayout
1849
+ } = committedValuesRef.current;
1827
1850
  const {
1828
1851
  layout: prevLayout,
1829
- onLayout,
1830
1852
  panelDataArray
1831
- } = committedValuesRef.current;
1853
+ } = eagerValuesRef.current;
1832
1854
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1833
1855
  const {
1834
1856
  groupSizePixels,
@@ -1848,7 +1870,7 @@ function PanelGroupWithForwardedRef({
1848
1870
  });
1849
1871
  if (!compareLayouts(prevLayout, nextLayout)) {
1850
1872
  setLayout(nextLayout);
1851
- committedValuesRef.current.layout = nextLayout;
1873
+ eagerValuesRef.current.layout = nextLayout;
1852
1874
  if (onLayout) {
1853
1875
  onLayout(nextLayout.map(sizePercentage => ({
1854
1876
  sizePercentage,
@@ -1860,9 +1882,11 @@ function PanelGroupWithForwardedRef({
1860
1882
  }, [groupId]);
1861
1883
  const startDragging = useCallback((dragHandleId, event) => {
1862
1884
  const {
1863
- direction,
1864
- layout
1885
+ direction
1865
1886
  } = committedValuesRef.current;
1887
+ const {
1888
+ layout
1889
+ } = eagerValuesRef.current;
1866
1890
  const handleElement = getResizeHandleElement(dragHandleId);
1867
1891
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1868
1892
  setDragState({
@@ -1883,10 +1907,12 @@ function PanelGroupWithForwardedRef({
1883
1907
  const unregisterPanel = useCallback(panelData => {
1884
1908
  const {
1885
1909
  id: groupId,
1910
+ onLayout
1911
+ } = committedValuesRef.current;
1912
+ const {
1886
1913
  layout: prevLayout,
1887
- onLayout,
1888
1914
  panelDataArray
1889
- } = committedValuesRef.current;
1915
+ } = eagerValuesRef.current;
1890
1916
  const index = panelDataArray.indexOf(panelData);
1891
1917
  if (index >= 0) {
1892
1918
  panelDataArray.splice(index, 1);
@@ -1903,7 +1929,7 @@ function PanelGroupWithForwardedRef({
1903
1929
  const {
1904
1930
  pendingPanelIds
1905
1931
  } = unregisterPanelRef.current;
1906
- panelIdToLastNotifiedMixedSizesMapRef.current;
1932
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1907
1933
 
1908
1934
  // TRICKY
1909
1935
  // Strict effects mode
@@ -1919,7 +1945,7 @@ function PanelGroupWithForwardedRef({
1919
1945
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1920
1946
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1921
1947
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1922
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1948
+ delete map[panelData.id];
1923
1949
  }
1924
1950
  });
1925
1951
  if (!unmountDueToStrictMode) {
@@ -1944,7 +1970,7 @@ function PanelGroupWithForwardedRef({
1944
1970
  });
1945
1971
  if (!areEqual(prevLayout, nextLayout)) {
1946
1972
  setLayout(nextLayout);
1947
- committedValuesRef.current.layout = nextLayout;
1973
+ eagerValuesRef.current.layout = nextLayout;
1948
1974
  if (onLayout) {
1949
1975
  onLayout(nextLayout.map(sizePercentage => ({
1950
1976
  sizePercentage,