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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.62
4
+
5
+ - Edge case expand/collapse invalid size guard (#220)
6
+
7
+ ## 0.0.61
8
+
9
+ - Better unstable Offscreen/Activity API.
10
+
3
11
  ## 0.0.60
4
12
 
5
13
  - 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 {
@@ -1476,7 +1488,7 @@ function PanelGroupWithForwardedRef({
1476
1488
  if (panelSizePercentage === collapsedSizePercentage) {
1477
1489
  // Restore this panel to the size it was before it was collapsed, if possible.
1478
1490
  const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
1479
- const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
1491
+ const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
1480
1492
  const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1481
1493
  const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
1482
1494
  const nextLayout = adjustLayoutByDelta({
@@ -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,