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 +4 -0
- package/dist/react-resizable-panels.browser.cjs.js +68 -42
- package/dist/react-resizable-panels.browser.development.cjs.js +69 -43
- package/dist/react-resizable-panels.browser.development.esm.js +69 -43
- package/dist/react-resizable-panels.browser.esm.js +68 -42
- package/dist/react-resizable-panels.cjs.js +68 -42
- package/dist/react-resizable-panels.cjs.js.map +1 -1
- package/dist/react-resizable-panels.development.cjs.js +69 -43
- package/dist/react-resizable-panels.development.esm.js +69 -43
- package/dist/react-resizable-panels.development.node.cjs.js +66 -40
- package/dist/react-resizable-panels.development.node.esm.js +66 -40
- package/dist/react-resizable-panels.esm.js +68 -42
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +65 -39
- package/dist/react-resizable-panels.node.esm.js +65 -39
- package/package.json +1 -1
- package/src/PanelGroup.ts +49 -57
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +12 -2
|
@@ -689,6 +689,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
689
689
|
|
|
690
690
|
function useWindowSplitterPanelGroupBehavior({
|
|
691
691
|
committedValuesRef,
|
|
692
|
+
eagerValuesRef,
|
|
692
693
|
groupId,
|
|
693
694
|
layout,
|
|
694
695
|
panelDataArray,
|
|
@@ -731,7 +732,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
731
732
|
useEffect(() => {
|
|
732
733
|
const {
|
|
733
734
|
panelDataArray
|
|
734
|
-
} =
|
|
735
|
+
} = eagerValuesRef.current;
|
|
735
736
|
const groupElement = getPanelGroupElement(groupId);
|
|
736
737
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
737
738
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -789,7 +790,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
789
790
|
return () => {
|
|
790
791
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
791
792
|
};
|
|
792
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
793
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
793
794
|
}
|
|
794
795
|
|
|
795
796
|
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
|
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,
|
|
@@ -1320,15 +1327,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1320
1327
|
|
|
1321
1328
|
useWindowSplitterPanelGroupBehavior({
|
|
1322
1329
|
committedValuesRef,
|
|
1330
|
+
eagerValuesRef,
|
|
1323
1331
|
groupId,
|
|
1324
1332
|
layout,
|
|
1325
|
-
panelDataArray:
|
|
1333
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1326
1334
|
setLayout
|
|
1327
1335
|
});
|
|
1328
1336
|
useEffect(() => {
|
|
1329
1337
|
const {
|
|
1330
1338
|
panelDataArray
|
|
1331
|
-
} =
|
|
1339
|
+
} = eagerValuesRef.current;
|
|
1332
1340
|
|
|
1333
1341
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1334
1342
|
if (autoSaveId) {
|
|
@@ -1345,8 +1353,9 @@ function PanelGroupWithForwardedRef({
|
|
|
1345
1353
|
}, [autoSaveId, layout, storage]);
|
|
1346
1354
|
useIsomorphicLayoutEffect(() => {
|
|
1347
1355
|
const {
|
|
1356
|
+
layout: prevLayout,
|
|
1348
1357
|
panelDataArray
|
|
1349
|
-
} =
|
|
1358
|
+
} = eagerValuesRef.current;
|
|
1350
1359
|
const constraints = panelDataArray.map(({
|
|
1351
1360
|
constraints
|
|
1352
1361
|
}) => constraints);
|
|
@@ -1360,7 +1369,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1360
1369
|
const resizeObserver = new ResizeObserver(() => {
|
|
1361
1370
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1362
1371
|
const {
|
|
1363
|
-
layout: prevLayout,
|
|
1364
1372
|
onLayout
|
|
1365
1373
|
} = committedValuesRef.current;
|
|
1366
1374
|
const nextLayout = validatePanelGroupLayout({
|
|
@@ -1370,7 +1378,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1370
1378
|
});
|
|
1371
1379
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1372
1380
|
setLayout(nextLayout);
|
|
1373
|
-
|
|
1381
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1374
1382
|
if (onLayout) {
|
|
1375
1383
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1376
1384
|
sizePercentage,
|
|
@@ -1393,11 +1401,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1393
1401
|
|
|
1394
1402
|
// External APIs are safe to memoize via committed values ref
|
|
1395
1403
|
const collapsePanel = useCallback(panelData => {
|
|
1404
|
+
const {
|
|
1405
|
+
onLayout
|
|
1406
|
+
} = committedValuesRef.current;
|
|
1396
1407
|
const {
|
|
1397
1408
|
layout: prevLayout,
|
|
1398
|
-
onLayout,
|
|
1399
1409
|
panelDataArray
|
|
1400
|
-
} =
|
|
1410
|
+
} = eagerValuesRef.current;
|
|
1401
1411
|
if (panelData.constraints.collapsible) {
|
|
1402
1412
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1403
1413
|
const {
|
|
@@ -1422,7 +1432,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1422
1432
|
});
|
|
1423
1433
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1424
1434
|
setLayout(nextLayout);
|
|
1425
|
-
|
|
1435
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1426
1436
|
if (onLayout) {
|
|
1427
1437
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1428
1438
|
sizePercentage,
|
|
@@ -1437,11 +1447,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1437
1447
|
|
|
1438
1448
|
// External APIs are safe to memoize via committed values ref
|
|
1439
1449
|
const expandPanel = useCallback(panelData => {
|
|
1450
|
+
const {
|
|
1451
|
+
onLayout
|
|
1452
|
+
} = committedValuesRef.current;
|
|
1440
1453
|
const {
|
|
1441
1454
|
layout: prevLayout,
|
|
1442
|
-
onLayout,
|
|
1443
1455
|
panelDataArray
|
|
1444
|
-
} =
|
|
1456
|
+
} = eagerValuesRef.current;
|
|
1445
1457
|
if (panelData.constraints.collapsible) {
|
|
1446
1458
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1447
1459
|
const {
|
|
@@ -1467,7 +1479,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1467
1479
|
});
|
|
1468
1480
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1469
1481
|
setLayout(nextLayout);
|
|
1470
|
-
|
|
1482
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1471
1483
|
if (onLayout) {
|
|
1472
1484
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1473
1485
|
sizePercentage,
|
|
@@ -1485,7 +1497,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1485
1497
|
const {
|
|
1486
1498
|
layout,
|
|
1487
1499
|
panelDataArray
|
|
1488
|
-
} =
|
|
1500
|
+
} = eagerValuesRef.current;
|
|
1489
1501
|
const {
|
|
1490
1502
|
panelSizePercentage,
|
|
1491
1503
|
panelSizePixels
|
|
@@ -1500,7 +1512,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1500
1512
|
const getPanelStyle = useCallback(panelData => {
|
|
1501
1513
|
const {
|
|
1502
1514
|
panelDataArray
|
|
1503
|
-
} =
|
|
1515
|
+
} = eagerValuesRef.current;
|
|
1504
1516
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1505
1517
|
return computePanelFlexBoxStyle({
|
|
1506
1518
|
dragState,
|
|
@@ -1515,7 +1527,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1515
1527
|
const {
|
|
1516
1528
|
layout,
|
|
1517
1529
|
panelDataArray
|
|
1518
|
-
} =
|
|
1530
|
+
} = eagerValuesRef.current;
|
|
1519
1531
|
const {
|
|
1520
1532
|
collapsedSizePercentage,
|
|
1521
1533
|
collapsible,
|
|
@@ -1529,7 +1541,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1529
1541
|
const {
|
|
1530
1542
|
layout,
|
|
1531
1543
|
panelDataArray
|
|
1532
|
-
} =
|
|
1544
|
+
} = eagerValuesRef.current;
|
|
1533
1545
|
const {
|
|
1534
1546
|
collapsedSizePercentage,
|
|
1535
1547
|
collapsible,
|
|
@@ -1541,11 +1553,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1541
1553
|
const {
|
|
1542
1554
|
autoSaveId,
|
|
1543
1555
|
id: groupId,
|
|
1544
|
-
layout: prevLayout,
|
|
1545
1556
|
onLayout,
|
|
1546
|
-
panelDataArray,
|
|
1547
1557
|
storage
|
|
1548
1558
|
} = committedValuesRef.current;
|
|
1559
|
+
const {
|
|
1560
|
+
layout: prevLayout,
|
|
1561
|
+
panelDataArray
|
|
1562
|
+
} = eagerValuesRef.current;
|
|
1549
1563
|
panelDataArray.push(panelData);
|
|
1550
1564
|
panelDataArray.sort((panelA, panelB) => {
|
|
1551
1565
|
const orderA = panelA.order;
|
|
@@ -1597,9 +1611,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1597
1611
|
layout: unsafeLayout,
|
|
1598
1612
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1599
1613
|
});
|
|
1614
|
+
|
|
1615
|
+
// Offscreen mode makes this a bit weird;
|
|
1616
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1617
|
+
// but the overall layout doesn't change between these two cases.
|
|
1618
|
+
setLayout(nextLayout);
|
|
1619
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1600
1620
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1601
|
-
setLayout(nextLayout);
|
|
1602
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1603
1621
|
if (onLayout) {
|
|
1604
1622
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1605
1623
|
sizePercentage,
|
|
@@ -1618,10 +1636,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1618
1636
|
id: groupId,
|
|
1619
1637
|
keyboardResizeByPercentage,
|
|
1620
1638
|
keyboardResizeByPixels,
|
|
1621
|
-
onLayout
|
|
1622
|
-
panelDataArray,
|
|
1623
|
-
layout: prevLayout
|
|
1639
|
+
onLayout
|
|
1624
1640
|
} = committedValuesRef.current;
|
|
1641
|
+
const {
|
|
1642
|
+
layout: prevLayout,
|
|
1643
|
+
panelDataArray
|
|
1644
|
+
} = eagerValuesRef.current;
|
|
1625
1645
|
const {
|
|
1626
1646
|
initialLayout
|
|
1627
1647
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1677,7 +1697,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1677
1697
|
}
|
|
1678
1698
|
if (layoutChanged) {
|
|
1679
1699
|
setLayout(nextLayout);
|
|
1680
|
-
|
|
1700
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1681
1701
|
if (onLayout) {
|
|
1682
1702
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1683
1703
|
sizePercentage,
|
|
@@ -1691,11 +1711,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1691
1711
|
|
|
1692
1712
|
// External APIs are safe to memoize via committed values ref
|
|
1693
1713
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1714
|
+
const {
|
|
1715
|
+
onLayout
|
|
1716
|
+
} = committedValuesRef.current;
|
|
1694
1717
|
const {
|
|
1695
1718
|
layout: prevLayout,
|
|
1696
|
-
onLayout,
|
|
1697
1719
|
panelDataArray
|
|
1698
|
-
} =
|
|
1720
|
+
} = eagerValuesRef.current;
|
|
1699
1721
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1700
1722
|
const {
|
|
1701
1723
|
groupSizePixels,
|
|
@@ -1715,7 +1737,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1715
1737
|
});
|
|
1716
1738
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1717
1739
|
setLayout(nextLayout);
|
|
1718
|
-
|
|
1740
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1719
1741
|
if (onLayout) {
|
|
1720
1742
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1721
1743
|
sizePercentage,
|
|
@@ -1727,9 +1749,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1727
1749
|
}, [groupId]);
|
|
1728
1750
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1729
1751
|
const {
|
|
1730
|
-
direction
|
|
1731
|
-
layout
|
|
1752
|
+
direction
|
|
1732
1753
|
} = committedValuesRef.current;
|
|
1754
|
+
const {
|
|
1755
|
+
layout
|
|
1756
|
+
} = eagerValuesRef.current;
|
|
1733
1757
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1734
1758
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1735
1759
|
setDragState({
|
|
@@ -1750,10 +1774,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1750
1774
|
const unregisterPanel = useCallback(panelData => {
|
|
1751
1775
|
const {
|
|
1752
1776
|
id: groupId,
|
|
1777
|
+
onLayout
|
|
1778
|
+
} = committedValuesRef.current;
|
|
1779
|
+
const {
|
|
1753
1780
|
layout: prevLayout,
|
|
1754
|
-
onLayout,
|
|
1755
1781
|
panelDataArray
|
|
1756
|
-
} =
|
|
1782
|
+
} = eagerValuesRef.current;
|
|
1757
1783
|
const index = panelDataArray.indexOf(panelData);
|
|
1758
1784
|
if (index >= 0) {
|
|
1759
1785
|
panelDataArray.splice(index, 1);
|
|
@@ -1770,7 +1796,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1770
1796
|
const {
|
|
1771
1797
|
pendingPanelIds
|
|
1772
1798
|
} = unregisterPanelRef.current;
|
|
1773
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1799
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1774
1800
|
|
|
1775
1801
|
// TRICKY
|
|
1776
1802
|
// Strict effects mode
|
|
@@ -1786,7 +1812,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1786
1812
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1787
1813
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1788
1814
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1789
|
-
delete
|
|
1815
|
+
delete map[panelData.id];
|
|
1790
1816
|
}
|
|
1791
1817
|
});
|
|
1792
1818
|
if (!unmountDueToStrictMode) {
|
|
@@ -1811,7 +1837,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1811
1837
|
});
|
|
1812
1838
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1813
1839
|
setLayout(nextLayout);
|
|
1814
|
-
|
|
1840
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1815
1841
|
if (onLayout) {
|
|
1816
1842
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1817
1843
|
sizePercentage,
|