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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.61
4
+
5
+ - Better unstable Offscreen/Activity API.
6
+
3
7
  ## 0.0.60
4
8
 
5
9
  - Better support imperative API usage from mount effects.
@@ -711,6 +711,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
711
711
 
712
712
  function useWindowSplitterPanelGroupBehavior({
713
713
  committedValuesRef,
714
+ eagerValuesRef,
714
715
  groupId,
715
716
  layout,
716
717
  panelDataArray,
@@ -753,7 +754,7 @@ function useWindowSplitterPanelGroupBehavior({
753
754
  useEffect(() => {
754
755
  const {
755
756
  panelDataArray
756
- } = committedValuesRef.current;
757
+ } = eagerValuesRef.current;
757
758
  const groupElement = getPanelGroupElement(groupId);
758
759
  assert(groupElement != null, `No group found for id "${groupId}"`);
759
760
  const handles = getResizeHandleElementsForGroup(groupId);
@@ -811,7 +812,7 @@ function useWindowSplitterPanelGroupBehavior({
811
812
  return () => {
812
813
  cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
813
814
  };
814
- }, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
815
+ }, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
815
816
  }
816
817
 
817
818
  function areEqual(arrayA, arrayB) {
@@ -1276,11 +1277,13 @@ function PanelGroupWithForwardedRef({
1276
1277
  id: groupId,
1277
1278
  keyboardResizeByPercentage,
1278
1279
  keyboardResizeByPixels,
1279
- layout,
1280
1280
  onLayout,
1281
- panelDataArray: [],
1282
1281
  storage
1283
1282
  });
1283
+ const eagerValuesRef = useRef({
1284
+ layout,
1285
+ panelDataArray: []
1286
+ });
1284
1287
  useRef({
1285
1288
  didLogIdAndOrderWarning: false,
1286
1289
  didLogPanelConstraintsWarning: false,
@@ -1290,9 +1293,11 @@ function PanelGroupWithForwardedRef({
1290
1293
  getId: () => committedValuesRef.current.id,
1291
1294
  getLayout: () => {
1292
1295
  const {
1293
- id: groupId,
1294
- layout
1296
+ id: groupId
1295
1297
  } = committedValuesRef.current;
1298
+ const {
1299
+ layout
1300
+ } = eagerValuesRef.current;
1296
1301
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1297
1302
  return layout.map(sizePercentage => {
1298
1303
  return {
@@ -1304,10 +1309,12 @@ function PanelGroupWithForwardedRef({
1304
1309
  setLayout: mixedSizes => {
1305
1310
  const {
1306
1311
  id: groupId,
1312
+ onLayout
1313
+ } = committedValuesRef.current;
1314
+ const {
1307
1315
  layout: prevLayout,
1308
- onLayout,
1309
1316
  panelDataArray
1310
- } = committedValuesRef.current;
1317
+ } = eagerValuesRef.current;
1311
1318
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1312
1319
  const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
1313
1320
  const safeLayout = validatePanelGroupLayout({
@@ -1317,7 +1324,7 @@ function PanelGroupWithForwardedRef({
1317
1324
  });
1318
1325
  if (!areEqual(prevLayout, safeLayout)) {
1319
1326
  setLayout(safeLayout);
1320
- committedValuesRef.current.layout = safeLayout;
1327
+ eagerValuesRef.current.layout = safeLayout;
1321
1328
  if (onLayout) {
1322
1329
  onLayout(safeLayout.map(sizePercentage => ({
1323
1330
  sizePercentage,
@@ -1342,15 +1349,16 @@ function PanelGroupWithForwardedRef({
1342
1349
 
1343
1350
  useWindowSplitterPanelGroupBehavior({
1344
1351
  committedValuesRef,
1352
+ eagerValuesRef,
1345
1353
  groupId,
1346
1354
  layout,
1347
- panelDataArray: committedValuesRef.current.panelDataArray,
1355
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1348
1356
  setLayout
1349
1357
  });
1350
1358
  useEffect(() => {
1351
1359
  const {
1352
1360
  panelDataArray
1353
- } = committedValuesRef.current;
1361
+ } = eagerValuesRef.current;
1354
1362
 
1355
1363
  // If this panel has been configured to persist sizing information, save sizes to local storage.
1356
1364
  if (autoSaveId) {
@@ -1367,8 +1375,9 @@ function PanelGroupWithForwardedRef({
1367
1375
  }, [autoSaveId, layout, storage]);
1368
1376
  useIsomorphicLayoutEffect(() => {
1369
1377
  const {
1378
+ layout: prevLayout,
1370
1379
  panelDataArray
1371
- } = committedValuesRef.current;
1380
+ } = eagerValuesRef.current;
1372
1381
  const constraints = panelDataArray.map(({
1373
1382
  constraints
1374
1383
  }) => constraints);
@@ -1382,7 +1391,6 @@ function PanelGroupWithForwardedRef({
1382
1391
  const resizeObserver = new ResizeObserver(() => {
1383
1392
  const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
1384
1393
  const {
1385
- layout: prevLayout,
1386
1394
  onLayout
1387
1395
  } = committedValuesRef.current;
1388
1396
  const nextLayout = validatePanelGroupLayout({
@@ -1392,7 +1400,7 @@ function PanelGroupWithForwardedRef({
1392
1400
  });
1393
1401
  if (!areEqual(prevLayout, nextLayout)) {
1394
1402
  setLayout(nextLayout);
1395
- committedValuesRef.current.layout = nextLayout;
1403
+ eagerValuesRef.current.layout = nextLayout;
1396
1404
  if (onLayout) {
1397
1405
  onLayout(nextLayout.map(sizePercentage => ({
1398
1406
  sizePercentage,
@@ -1415,11 +1423,13 @@ function PanelGroupWithForwardedRef({
1415
1423
 
1416
1424
  // External APIs are safe to memoize via committed values ref
1417
1425
  const collapsePanel = useCallback(panelData => {
1426
+ const {
1427
+ onLayout
1428
+ } = committedValuesRef.current;
1418
1429
  const {
1419
1430
  layout: prevLayout,
1420
- onLayout,
1421
1431
  panelDataArray
1422
- } = committedValuesRef.current;
1432
+ } = eagerValuesRef.current;
1423
1433
  if (panelData.constraints.collapsible) {
1424
1434
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1425
1435
  const {
@@ -1444,7 +1454,7 @@ function PanelGroupWithForwardedRef({
1444
1454
  });
1445
1455
  if (!compareLayouts(prevLayout, nextLayout)) {
1446
1456
  setLayout(nextLayout);
1447
- committedValuesRef.current.layout = nextLayout;
1457
+ eagerValuesRef.current.layout = nextLayout;
1448
1458
  if (onLayout) {
1449
1459
  onLayout(nextLayout.map(sizePercentage => ({
1450
1460
  sizePercentage,
@@ -1459,11 +1469,13 @@ function PanelGroupWithForwardedRef({
1459
1469
 
1460
1470
  // External APIs are safe to memoize via committed values ref
1461
1471
  const expandPanel = useCallback(panelData => {
1472
+ const {
1473
+ onLayout
1474
+ } = committedValuesRef.current;
1462
1475
  const {
1463
1476
  layout: prevLayout,
1464
- onLayout,
1465
1477
  panelDataArray
1466
- } = committedValuesRef.current;
1478
+ } = eagerValuesRef.current;
1467
1479
  if (panelData.constraints.collapsible) {
1468
1480
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1469
1481
  const {
@@ -1489,7 +1501,7 @@ function PanelGroupWithForwardedRef({
1489
1501
  });
1490
1502
  if (!compareLayouts(prevLayout, nextLayout)) {
1491
1503
  setLayout(nextLayout);
1492
- committedValuesRef.current.layout = nextLayout;
1504
+ eagerValuesRef.current.layout = nextLayout;
1493
1505
  if (onLayout) {
1494
1506
  onLayout(nextLayout.map(sizePercentage => ({
1495
1507
  sizePercentage,
@@ -1507,7 +1519,7 @@ function PanelGroupWithForwardedRef({
1507
1519
  const {
1508
1520
  layout,
1509
1521
  panelDataArray
1510
- } = committedValuesRef.current;
1522
+ } = eagerValuesRef.current;
1511
1523
  const {
1512
1524
  panelSizePercentage,
1513
1525
  panelSizePixels
@@ -1522,7 +1534,7 @@ function PanelGroupWithForwardedRef({
1522
1534
  const getPanelStyle = useCallback(panelData => {
1523
1535
  const {
1524
1536
  panelDataArray
1525
- } = committedValuesRef.current;
1537
+ } = eagerValuesRef.current;
1526
1538
  const panelIndex = panelDataArray.indexOf(panelData);
1527
1539
  return computePanelFlexBoxStyle({
1528
1540
  dragState,
@@ -1537,7 +1549,7 @@ function PanelGroupWithForwardedRef({
1537
1549
  const {
1538
1550
  layout,
1539
1551
  panelDataArray
1540
- } = committedValuesRef.current;
1552
+ } = eagerValuesRef.current;
1541
1553
  const {
1542
1554
  collapsedSizePercentage,
1543
1555
  collapsible,
@@ -1551,7 +1563,7 @@ function PanelGroupWithForwardedRef({
1551
1563
  const {
1552
1564
  layout,
1553
1565
  panelDataArray
1554
- } = committedValuesRef.current;
1566
+ } = eagerValuesRef.current;
1555
1567
  const {
1556
1568
  collapsedSizePercentage,
1557
1569
  collapsible,
@@ -1563,11 +1575,13 @@ function PanelGroupWithForwardedRef({
1563
1575
  const {
1564
1576
  autoSaveId,
1565
1577
  id: groupId,
1566
- layout: prevLayout,
1567
1578
  onLayout,
1568
- panelDataArray,
1569
1579
  storage
1570
1580
  } = committedValuesRef.current;
1581
+ const {
1582
+ layout: prevLayout,
1583
+ panelDataArray
1584
+ } = eagerValuesRef.current;
1571
1585
  panelDataArray.push(panelData);
1572
1586
  panelDataArray.sort((panelA, panelB) => {
1573
1587
  const orderA = panelA.order;
@@ -1619,9 +1633,13 @@ function PanelGroupWithForwardedRef({
1619
1633
  layout: unsafeLayout,
1620
1634
  panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1621
1635
  });
1636
+
1637
+ // Offscreen mode makes this a bit weird;
1638
+ // Panels unregister when hidden and re-register when shown again,
1639
+ // but the overall layout doesn't change between these two cases.
1640
+ setLayout(nextLayout);
1641
+ eagerValuesRef.current.layout = nextLayout;
1622
1642
  if (!areEqual(prevLayout, nextLayout)) {
1623
- setLayout(nextLayout);
1624
- committedValuesRef.current.layout = nextLayout;
1625
1643
  if (onLayout) {
1626
1644
  onLayout(nextLayout.map(sizePercentage => ({
1627
1645
  sizePercentage,
@@ -1640,10 +1658,12 @@ function PanelGroupWithForwardedRef({
1640
1658
  id: groupId,
1641
1659
  keyboardResizeByPercentage,
1642
1660
  keyboardResizeByPixels,
1643
- onLayout,
1644
- panelDataArray,
1645
- layout: prevLayout
1661
+ onLayout
1646
1662
  } = committedValuesRef.current;
1663
+ const {
1664
+ layout: prevLayout,
1665
+ panelDataArray
1666
+ } = eagerValuesRef.current;
1647
1667
  const {
1648
1668
  initialLayout
1649
1669
  } = dragState !== null && dragState !== void 0 ? dragState : {};
@@ -1699,7 +1719,7 @@ function PanelGroupWithForwardedRef({
1699
1719
  }
1700
1720
  if (layoutChanged) {
1701
1721
  setLayout(nextLayout);
1702
- committedValuesRef.current.layout = nextLayout;
1722
+ eagerValuesRef.current.layout = nextLayout;
1703
1723
  if (onLayout) {
1704
1724
  onLayout(nextLayout.map(sizePercentage => ({
1705
1725
  sizePercentage,
@@ -1713,11 +1733,13 @@ function PanelGroupWithForwardedRef({
1713
1733
 
1714
1734
  // External APIs are safe to memoize via committed values ref
1715
1735
  const resizePanel = useCallback((panelData, mixedSizes) => {
1736
+ const {
1737
+ onLayout
1738
+ } = committedValuesRef.current;
1716
1739
  const {
1717
1740
  layout: prevLayout,
1718
- onLayout,
1719
1741
  panelDataArray
1720
- } = committedValuesRef.current;
1742
+ } = eagerValuesRef.current;
1721
1743
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1722
1744
  const {
1723
1745
  groupSizePixels,
@@ -1737,7 +1759,7 @@ function PanelGroupWithForwardedRef({
1737
1759
  });
1738
1760
  if (!compareLayouts(prevLayout, nextLayout)) {
1739
1761
  setLayout(nextLayout);
1740
- committedValuesRef.current.layout = nextLayout;
1762
+ eagerValuesRef.current.layout = nextLayout;
1741
1763
  if (onLayout) {
1742
1764
  onLayout(nextLayout.map(sizePercentage => ({
1743
1765
  sizePercentage,
@@ -1749,9 +1771,11 @@ function PanelGroupWithForwardedRef({
1749
1771
  }, [groupId]);
1750
1772
  const startDragging = useCallback((dragHandleId, event) => {
1751
1773
  const {
1752
- direction,
1753
- layout
1774
+ direction
1754
1775
  } = committedValuesRef.current;
1776
+ const {
1777
+ layout
1778
+ } = eagerValuesRef.current;
1755
1779
  const handleElement = getResizeHandleElement(dragHandleId);
1756
1780
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1757
1781
  setDragState({
@@ -1772,10 +1796,12 @@ function PanelGroupWithForwardedRef({
1772
1796
  const unregisterPanel = useCallback(panelData => {
1773
1797
  const {
1774
1798
  id: groupId,
1799
+ onLayout
1800
+ } = committedValuesRef.current;
1801
+ const {
1775
1802
  layout: prevLayout,
1776
- onLayout,
1777
1803
  panelDataArray
1778
- } = committedValuesRef.current;
1804
+ } = eagerValuesRef.current;
1779
1805
  const index = panelDataArray.indexOf(panelData);
1780
1806
  if (index >= 0) {
1781
1807
  panelDataArray.splice(index, 1);
@@ -1792,7 +1818,7 @@ function PanelGroupWithForwardedRef({
1792
1818
  const {
1793
1819
  pendingPanelIds
1794
1820
  } = unregisterPanelRef.current;
1795
- panelIdToLastNotifiedMixedSizesMapRef.current;
1821
+ const map = panelIdToLastNotifiedMixedSizesMapRef.current;
1796
1822
 
1797
1823
  // TRICKY
1798
1824
  // Strict effects mode
@@ -1808,7 +1834,7 @@ function PanelGroupWithForwardedRef({
1808
1834
  // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1809
1835
  // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1810
1836
  // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1811
- delete panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
1837
+ delete map[panelData.id];
1812
1838
  }
1813
1839
  });
1814
1840
  if (!unmountDueToStrictMode) {
@@ -1833,7 +1859,7 @@ function PanelGroupWithForwardedRef({
1833
1859
  });
1834
1860
  if (!areEqual(prevLayout, nextLayout)) {
1835
1861
  setLayout(nextLayout);
1836
- committedValuesRef.current.layout = nextLayout;
1862
+ eagerValuesRef.current.layout = nextLayout;
1837
1863
  if (onLayout) {
1838
1864
  onLayout(nextLayout.map(sizePercentage => ({
1839
1865
  sizePercentage,
@@ -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
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- committedValuesRef.current.layout = safeLayout;
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: committedValuesRef.current.panelDataArray,
1448
+ panelDataArray: eagerValuesRef.current.panelDataArray,
1441
1449
  setLayout
1442
1450
  });
1443
1451
  useEffect(() => {
1444
1452
  const {
1445
1453
  panelDataArray
1446
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- committedValuesRef.current.layout = nextLayout;
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
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- committedValuesRef.current.layout = nextLayout;
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
- } = committedValuesRef.current;
1613
+ } = eagerValuesRef.current;
1602
1614
  if (panelData.constraints.collapsible) {
1603
1615
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1604
1616
  const {
@@ -1624,7 +1636,7 @@ function PanelGroupWithForwardedRef({
1624
1636
  });
1625
1637
  if (!compareLayouts(prevLayout, nextLayout)) {
1626
1638
  setLayout(nextLayout);
1627
- committedValuesRef.current.layout = nextLayout;
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
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- } = committedValuesRef.current;
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
- committedValuesRef.current.layout = nextLayout;
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
- } = committedValuesRef.current;
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
- committedValuesRef.current.layout = nextLayout;
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
- } = committedValuesRef.current;
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 panelIdToLastNotifiedMixedSizesMapRef.current[panelData.id];
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
- committedValuesRef.current.layout = nextLayout;
1997
+ eagerValuesRef.current.layout = nextLayout;
1972
1998
  if (onLayout) {
1973
1999
  onLayout(nextLayout.map(sizePercentage => ({
1974
2000
  sizePercentage,