react-resizable-panels 0.0.60 → 0.0.61

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.
@@ -713,6 +713,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
713
713
 
714
714
  function useWindowSplitterPanelGroupBehavior({
715
715
  committedValuesRef,
716
+ eagerValuesRef,
716
717
  groupId,
717
718
  layout,
718
719
  panelDataArray,
@@ -755,7 +756,7 @@ function useWindowSplitterPanelGroupBehavior({
755
756
  useEffect(() => {
756
757
  const {
757
758
  panelDataArray
758
- } = committedValuesRef.current;
759
+ } = eagerValuesRef.current;
759
760
  const groupElement = getPanelGroupElement(groupId);
760
761
  assert(groupElement != null, `No group found for id "${groupId}"`);
761
762
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -813,7 +814,7 @@ function useWindowSplitterPanelGroupBehavior({
813
814
  return () => {
814
815
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
815
816
  };
816
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
817
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
817
818
  }
818
819
 
819
820
  function areEqual(arrayA, arrayB) {
@@ -1278,11 +1279,13 @@ function PanelGroupWithForwardedRef({
1278
1279
  id: groupId,
1279
1280
  keyboardResizeByPercentage,
1280
1281
  keyboardResizeByPixels,
1281
- layout,
1282
1282
  onLayout,
1283
- panelDataArray: [],
1284
1283
  storage
1285
1284
  });
1285
+ const eagerValuesRef = useRef({
1286
+ layout,
1287
+ panelDataArray: []
1288
+ });
1286
1289
  useRef({
1287
1290
  didLogIdAndOrderWarning: false,
1288
1291
  didLogPanelConstraintsWarning: false,
@@ -1292,9 +1295,11 @@ function PanelGroupWithForwardedRef({
1292
1295
  getId: () => committedValuesRef.current.id,
1293
1296
  getLayout: () => {
1294
1297
  const {
1295
- id: groupId,
1296
- layout
1298
+ id: groupId
1297
1299
  } = committedValuesRef.current;
1300
+ const {
1301
+ layout
1302
+ } = eagerValuesRef.current;
1298
1303
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1299
1304
  return layout.map(sizePercentage => {
1300
1305
  return {
@@ -1306,10 +1311,12 @@ function PanelGroupWithForwardedRef({
1306
1311
  setLayout: mixedSizes => {
1307
1312
  const {
1308
1313
  id: groupId,
1314
+ onLayout
1315
+ } = committedValuesRef.current;
1316
+ const {
1309
1317
  layout: prevLayout,
1310
- onLayout,
1311
1318
  panelDataArray
1312
- } = committedValuesRef.current;
1319
+ } = eagerValuesRef.current;
1313
1320
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1314
1321
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1315
1322
  const safeLayout = validatePanelGroupLayout({
@@ -1319,7 +1326,7 @@ function PanelGroupWithForwardedRef({
1319
1326
  });
1320
1327
  if (!areEqual(prevLayout, safeLayout)) {
1321
1328
  setLayout(safeLayout);
1322
- committedValuesRef.current.layout = safeLayout;
1329
+ eagerValuesRef.current.layout = safeLayout;
1323
1330
  if (onLayout) {
1324
1331
  onLayout(safeLayout.map(sizePercentage => ({
1325
1332
  sizePercentage,
@@ -1344,15 +1351,16 @@ function PanelGroupWithForwardedRef({
1344
1351
 
1345
1352
  useWindowSplitterPanelGroupBehavior({
1346
1353
  committedValuesRef,
1354
+ eagerValuesRef,
1347
1355
  groupId,
1348
1356
  layout,
1349
- panelDataArray: committedValuesRef.current.panelDataArray,
1357
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1350
1358
  setLayout
1351
1359
  });
1352
1360
  useEffect(() => {
1353
1361
  const {
1354
1362
  panelDataArray
1355
- } = committedValuesRef.current;
1363
+ } = eagerValuesRef.current;
1356
1364
 
1357
1365
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1358
1366
  if (autoSaveId) {
@@ -1369,8 +1377,9 @@ function PanelGroupWithForwardedRef({
1369
1377
  }, [autoSaveId, layout, storage]);
1370
1378
  useIsomorphicLayoutEffect(() => {
1371
1379
  const {
1380
+ layout: prevLayout,
1372
1381
  panelDataArray
1373
- } = committedValuesRef.current;
1382
+ } = eagerValuesRef.current;
1374
1383
  const constraints = panelDataArray.map(({
1375
1384
  constraints
1376
1385
  }) => constraints);
@@ -1384,7 +1393,6 @@ function PanelGroupWithForwardedRef({
1384
1393
  const resizeObserver = new ResizeObserver(() => {
1385
1394
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1386
1395
  const {
1387
- layout: prevLayout,
1388
1396
  onLayout
1389
1397
  } = committedValuesRef.current;
1390
1398
  const nextLayout = validatePanelGroupLayout({
@@ -1394,7 +1402,7 @@ function PanelGroupWithForwardedRef({
1394
1402
  });
1395
1403
  if (!areEqual(prevLayout, nextLayout)) {
1396
1404
  setLayout(nextLayout);
1397
- committedValuesRef.current.layout = nextLayout;
1405
+ eagerValuesRef.current.layout = nextLayout;
1398
1406
  if (onLayout) {
1399
1407
  onLayout(nextLayout.map(sizePercentage => ({
1400
1408
  sizePercentage,
@@ -1417,11 +1425,13 @@ function PanelGroupWithForwardedRef({
1417
1425
 
1418
1426
  // External APIs are safe to memoize via committed values ref
1419
1427
  const collapsePanel = useCallback(panelData => {
1428
+ const {
1429
+ onLayout
1430
+ } = committedValuesRef.current;
1420
1431
  const {
1421
1432
  layout: prevLayout,
1422
- onLayout,
1423
1433
  panelDataArray
1424
- } = committedValuesRef.current;
1434
+ } = eagerValuesRef.current;
1425
1435
  if (panelData.constraints.collapsible) {
1426
1436
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1427
1437
  const {
@@ -1446,7 +1456,7 @@ function PanelGroupWithForwardedRef({
1446
1456
  });
1447
1457
  if (!compareLayouts(prevLayout, nextLayout)) {
1448
1458
  setLayout(nextLayout);
1449
- committedValuesRef.current.layout = nextLayout;
1459
+ eagerValuesRef.current.layout = nextLayout;
1450
1460
  if (onLayout) {
1451
1461
  onLayout(nextLayout.map(sizePercentage => ({
1452
1462
  sizePercentage,
@@ -1461,11 +1471,13 @@ function PanelGroupWithForwardedRef({
1461
1471
 
1462
1472
  // External APIs are safe to memoize via committed values ref
1463
1473
  const expandPanel = useCallback(panelData => {
1474
+ const {
1475
+ onLayout
1476
+ } = committedValuesRef.current;
1464
1477
  const {
1465
1478
  layout: prevLayout,
1466
- onLayout,
1467
1479
  panelDataArray
1468
- } = committedValuesRef.current;
1480
+ } = eagerValuesRef.current;
1469
1481
  if (panelData.constraints.collapsible) {
1470
1482
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1471
1483
  const {
@@ -1491,7 +1503,7 @@ function PanelGroupWithForwardedRef({
1491
1503
  });
1492
1504
  if (!compareLayouts(prevLayout, nextLayout)) {
1493
1505
  setLayout(nextLayout);
1494
- committedValuesRef.current.layout = nextLayout;
1506
+ eagerValuesRef.current.layout = nextLayout;
1495
1507
  if (onLayout) {
1496
1508
  onLayout(nextLayout.map(sizePercentage => ({
1497
1509
  sizePercentage,
@@ -1509,7 +1521,7 @@ function PanelGroupWithForwardedRef({
1509
1521
  const {
1510
1522
  layout,
1511
1523
  panelDataArray
1512
- } = committedValuesRef.current;
1524
+ } = eagerValuesRef.current;
1513
1525
  const {
1514
1526
  panelSizePercentage,
1515
1527
  panelSizePixels
@@ -1524,7 +1536,7 @@ function PanelGroupWithForwardedRef({
1524
1536
  const getPanelStyle = useCallback(panelData => {
1525
1537
  const {
1526
1538
  panelDataArray
1527
- } = committedValuesRef.current;
1539
+ } = eagerValuesRef.current;
1528
1540
  const panelIndex = panelDataArray.indexOf(panelData);
1529
1541
  return computePanelFlexBoxStyle({
1530
1542
  dragState,
@@ -1539,7 +1551,7 @@ function PanelGroupWithForwardedRef({
1539
1551
  const {
1540
1552
  layout,
1541
1553
  panelDataArray
1542
- } = committedValuesRef.current;
1554
+ } = eagerValuesRef.current;
1543
1555
  const {
1544
1556
  collapsedSizePercentage,
1545
1557
  collapsible,
@@ -1553,7 +1565,7 @@ function PanelGroupWithForwardedRef({
1553
1565
  const {
1554
1566
  layout,
1555
1567
  panelDataArray
1556
- } = committedValuesRef.current;
1568
+ } = eagerValuesRef.current;
1557
1569
  const {
1558
1570
  collapsedSizePercentage,
1559
1571
  collapsible,
@@ -1565,11 +1577,13 @@ function PanelGroupWithForwardedRef({
1565
1577
  const {
1566
1578
  autoSaveId,
1567
1579
  id: groupId,
1568
- layout: prevLayout,
1569
1580
  onLayout,
1570
- panelDataArray,
1571
1581
  storage
1572
1582
  } = committedValuesRef.current;
1583
+ const {
1584
+ layout: prevLayout,
1585
+ panelDataArray
1586
+ } = eagerValuesRef.current;
1573
1587
  panelDataArray.push(panelData);
1574
1588
  panelDataArray.sort((panelA, panelB) => {
1575
1589
  const orderA = panelA.order;
@@ -1621,9 +1635,13 @@ function PanelGroupWithForwardedRef({
1621
1635
  layout: unsafeLayout,
1622
1636
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1623
1637
  });
1638
+
1639
+ // Offscreen mode makes this a bit weird;
1640
+ // Panels unregister when hidden and re-register when shown again,
1641
+ // but the overall layout doesn't change between these two cases.
1642
+ setLayout(nextLayout);
1643
+ eagerValuesRef.current.layout = nextLayout;
1624
1644
  if (!areEqual(prevLayout, nextLayout)) {
1625
- setLayout(nextLayout);
1626
- committedValuesRef.current.layout = nextLayout;
1627
1645
  if (onLayout) {
1628
1646
  onLayout(nextLayout.map(sizePercentage => ({
1629
1647
  sizePercentage,
@@ -1642,10 +1660,12 @@ function PanelGroupWithForwardedRef({
1642
1660
  id: groupId,
1643
1661
  keyboardResizeByPercentage,
1644
1662
  keyboardResizeByPixels,
1645
- onLayout,
1646
- panelDataArray,
1647
- layout: prevLayout
1663
+ onLayout
1648
1664
  } = committedValuesRef.current;
1665
+ const {
1666
+ layout: prevLayout,
1667
+ panelDataArray
1668
+ } = eagerValuesRef.current;
1649
1669
  const {
1650
1670
  initialLayout
1651
1671
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1701,7 +1721,7 @@ function PanelGroupWithForwardedRef({
1701
1721
  }
1702
1722
  if (layoutChanged) {
1703
1723
  setLayout(nextLayout);
1704
- committedValuesRef.current.layout = nextLayout;
1724
+ eagerValuesRef.current.layout = nextLayout;
1705
1725
  if (onLayout) {
1706
1726
  onLayout(nextLayout.map(sizePercentage => ({
1707
1727
  sizePercentage,
@@ -1715,11 +1735,13 @@ function PanelGroupWithForwardedRef({
1715
1735
 
1716
1736
  // External APIs are safe to memoize via committed values ref
1717
1737
  const resizePanel = useCallback((panelData, mixedSizes) => {
1738
+ const {
1739
+ onLayout
1740
+ } = committedValuesRef.current;
1718
1741
  const {
1719
1742
  layout: prevLayout,
1720
- onLayout,
1721
1743
  panelDataArray
1722
- } = committedValuesRef.current;
1744
+ } = eagerValuesRef.current;
1723
1745
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1724
1746
  const {
1725
1747
  groupSizePixels,
@@ -1739,7 +1761,7 @@ function PanelGroupWithForwardedRef({
1739
1761
  });
1740
1762
  if (!compareLayouts(prevLayout, nextLayout)) {
1741
1763
  setLayout(nextLayout);
1742
- committedValuesRef.current.layout = nextLayout;
1764
+ eagerValuesRef.current.layout = nextLayout;
1743
1765
  if (onLayout) {
1744
1766
  onLayout(nextLayout.map(sizePercentage => ({
1745
1767
  sizePercentage,
@@ -1751,9 +1773,11 @@ function PanelGroupWithForwardedRef({
1751
1773
  }, [groupId]);
1752
1774
  const startDragging = useCallback((dragHandleId, event) => {
1753
1775
  const {
1754
- direction,
1755
- layout
1776
+ direction
1756
1777
  } = committedValuesRef.current;
1778
+ const {
1779
+ layout
1780
+ } = eagerValuesRef.current;
1757
1781
  const handleElement = getResizeHandleElement(dragHandleId);
1758
1782
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1759
1783
  setDragState({
@@ -1774,10 +1798,12 @@ function PanelGroupWithForwardedRef({
1774
1798
  const unregisterPanel = useCallback(panelData => {
1775
1799
  const {
1776
1800
  id: groupId,
1801
+ onLayout
1802
+ } = committedValuesRef.current;
1803
+ const {
1777
1804
  layout: prevLayout,
1778
- onLayout,
1779
1805
  panelDataArray
1780
- } = committedValuesRef.current;
1806
+ } = eagerValuesRef.current;
1781
1807
  const index = panelDataArray.indexOf(panelData);
1782
1808
  if (index >= 0) {
1783
1809
  panelDataArray.splice(index, 1);
@@ -1794,7 +1820,7 @@ function PanelGroupWithForwardedRef({
1794
1820
  const {
1795
1821
  pendingPanelIds
1796
1822
  } = unregisterPanelRef.current;
1797
- panelIdToLastNotifiedMixedSizesMapRef.current;
1823
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1798
1824
 
1799
1825
  // TRICKY
1800
1826
  // Strict effects mode
@@ -1810,7 +1836,7 @@ function PanelGroupWithForwardedRef({
1810
1836
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1811
1837
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1812
1838
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1813
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1839
+ delete map[panelData.id];
1814
1840
  }
1815
1841
  });
1816
1842
  if (!unmountDueToStrictMode) {
@@ -1835,7 +1861,7 @@ function PanelGroupWithForwardedRef({
1835
1861
  });
1836
1862
  if (!areEqual(prevLayout, nextLayout)) {
1837
1863
  setLayout(nextLayout);
1838
- committedValuesRef.current.layout = nextLayout;
1864
+ eagerValuesRef.current.layout = nextLayout;
1839
1865
  if (onLayout) {
1840
1866
  onLayout(nextLayout.map(sizePercentage => ({
1841
1867
  sizePercentage,