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 +8 -0
- package/dist/react-resizable-panels.browser.cjs.js +69 -43
- package/dist/react-resizable-panels.browser.development.cjs.js +70 -44
- package/dist/react-resizable-panels.browser.development.esm.js +70 -44
- package/dist/react-resizable-panels.browser.esm.js +69 -43
- package/dist/react-resizable-panels.cjs.js +69 -43
- package/dist/react-resizable-panels.development.cjs.js +70 -44
- package/dist/react-resizable-panels.development.esm.js +70 -44
- package/dist/react-resizable-panels.development.node.cjs.js +67 -41
- package/dist/react-resizable-panels.development.node.esm.js +67 -41
- package/dist/react-resizable-panels.esm.js +69 -43
- package/dist/react-resizable-panels.node.cjs.js +66 -40
- package/dist/react-resizable-panels.node.esm.js +66 -40
- package/package.json +1 -1
- package/src/PanelGroup.ts +51 -58
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +12 -2
- package/dist/react-resizable-panels.cjs.js.map +0 -1
- package/dist/react-resizable-panels.esm.js.map +0 -1
|
@@ -687,6 +687,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
687
687
|
|
|
688
688
|
function useWindowSplitterPanelGroupBehavior({
|
|
689
689
|
committedValuesRef,
|
|
690
|
+
eagerValuesRef,
|
|
690
691
|
groupId,
|
|
691
692
|
layout,
|
|
692
693
|
panelDataArray,
|
|
@@ -729,7 +730,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
729
730
|
useEffect(() => {
|
|
730
731
|
const {
|
|
731
732
|
panelDataArray
|
|
732
|
-
} =
|
|
733
|
+
} = eagerValuesRef.current;
|
|
733
734
|
const groupElement = getPanelGroupElement(groupId);
|
|
734
735
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
735
736
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -787,7 +788,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
787
788
|
return () => {
|
|
788
789
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
789
790
|
};
|
|
790
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
791
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
791
792
|
}
|
|
792
793
|
|
|
793
794
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1252,11 +1253,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1252
1253
|
id: groupId,
|
|
1253
1254
|
keyboardResizeByPercentage,
|
|
1254
1255
|
keyboardResizeByPixels,
|
|
1255
|
-
layout,
|
|
1256
1256
|
onLayout,
|
|
1257
|
-
panelDataArray: [],
|
|
1258
1257
|
storage
|
|
1259
1258
|
});
|
|
1259
|
+
const eagerValuesRef = useRef({
|
|
1260
|
+
layout,
|
|
1261
|
+
panelDataArray: []
|
|
1262
|
+
});
|
|
1260
1263
|
useRef({
|
|
1261
1264
|
didLogIdAndOrderWarning: false,
|
|
1262
1265
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1266,9 +1269,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1266
1269
|
getId: () => committedValuesRef.current.id,
|
|
1267
1270
|
getLayout: () => {
|
|
1268
1271
|
const {
|
|
1269
|
-
id: groupId
|
|
1270
|
-
layout
|
|
1272
|
+
id: groupId
|
|
1271
1273
|
} = committedValuesRef.current;
|
|
1274
|
+
const {
|
|
1275
|
+
layout
|
|
1276
|
+
} = eagerValuesRef.current;
|
|
1272
1277
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1273
1278
|
return layout.map(sizePercentage => {
|
|
1274
1279
|
return {
|
|
@@ -1280,10 +1285,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1280
1285
|
setLayout: mixedSizes => {
|
|
1281
1286
|
const {
|
|
1282
1287
|
id: groupId,
|
|
1288
|
+
onLayout
|
|
1289
|
+
} = committedValuesRef.current;
|
|
1290
|
+
const {
|
|
1283
1291
|
layout: prevLayout,
|
|
1284
|
-
onLayout,
|
|
1285
1292
|
panelDataArray
|
|
1286
|
-
} =
|
|
1293
|
+
} = eagerValuesRef.current;
|
|
1287
1294
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1288
1295
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1289
1296
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1293,7 +1300,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1293
1300
|
});
|
|
1294
1301
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1295
1302
|
setLayout(safeLayout);
|
|
1296
|
-
|
|
1303
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1297
1304
|
if (onLayout) {
|
|
1298
1305
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1299
1306
|
sizePercentage,
|
|
@@ -1318,15 +1325,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1318
1325
|
|
|
1319
1326
|
useWindowSplitterPanelGroupBehavior({
|
|
1320
1327
|
committedValuesRef,
|
|
1328
|
+
eagerValuesRef,
|
|
1321
1329
|
groupId,
|
|
1322
1330
|
layout,
|
|
1323
|
-
panelDataArray:
|
|
1331
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1324
1332
|
setLayout
|
|
1325
1333
|
});
|
|
1326
1334
|
useEffect(() => {
|
|
1327
1335
|
const {
|
|
1328
1336
|
panelDataArray
|
|
1329
|
-
} =
|
|
1337
|
+
} = eagerValuesRef.current;
|
|
1330
1338
|
|
|
1331
1339
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1332
1340
|
if (autoSaveId) {
|
|
@@ -1343,8 +1351,9 @@ function PanelGroupWithForwardedRef({
|
|
|
1343
1351
|
}, [autoSaveId, layout, storage]);
|
|
1344
1352
|
useIsomorphicLayoutEffect(() => {
|
|
1345
1353
|
const {
|
|
1354
|
+
layout: prevLayout,
|
|
1346
1355
|
panelDataArray
|
|
1347
|
-
} =
|
|
1356
|
+
} = eagerValuesRef.current;
|
|
1348
1357
|
const constraints = panelDataArray.map(({
|
|
1349
1358
|
constraints
|
|
1350
1359
|
}) => constraints);
|
|
@@ -1358,7 +1367,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1358
1367
|
const resizeObserver = new ResizeObserver(() => {
|
|
1359
1368
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1360
1369
|
const {
|
|
1361
|
-
layout: prevLayout,
|
|
1362
1370
|
onLayout
|
|
1363
1371
|
} = committedValuesRef.current;
|
|
1364
1372
|
const nextLayout = validatePanelGroupLayout({
|
|
@@ -1368,7 +1376,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1368
1376
|
});
|
|
1369
1377
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1370
1378
|
setLayout(nextLayout);
|
|
1371
|
-
|
|
1379
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1372
1380
|
if (onLayout) {
|
|
1373
1381
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1374
1382
|
sizePercentage,
|
|
@@ -1391,11 +1399,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1391
1399
|
|
|
1392
1400
|
// External APIs are safe to memoize via committed values ref
|
|
1393
1401
|
const collapsePanel = useCallback(panelData => {
|
|
1402
|
+
const {
|
|
1403
|
+
onLayout
|
|
1404
|
+
} = committedValuesRef.current;
|
|
1394
1405
|
const {
|
|
1395
1406
|
layout: prevLayout,
|
|
1396
|
-
onLayout,
|
|
1397
1407
|
panelDataArray
|
|
1398
|
-
} =
|
|
1408
|
+
} = eagerValuesRef.current;
|
|
1399
1409
|
if (panelData.constraints.collapsible) {
|
|
1400
1410
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1401
1411
|
const {
|
|
@@ -1420,7 +1430,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1420
1430
|
});
|
|
1421
1431
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1422
1432
|
setLayout(nextLayout);
|
|
1423
|
-
|
|
1433
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1424
1434
|
if (onLayout) {
|
|
1425
1435
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1426
1436
|
sizePercentage,
|
|
@@ -1435,11 +1445,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1435
1445
|
|
|
1436
1446
|
// External APIs are safe to memoize via committed values ref
|
|
1437
1447
|
const expandPanel = useCallback(panelData => {
|
|
1448
|
+
const {
|
|
1449
|
+
onLayout
|
|
1450
|
+
} = committedValuesRef.current;
|
|
1438
1451
|
const {
|
|
1439
1452
|
layout: prevLayout,
|
|
1440
|
-
onLayout,
|
|
1441
1453
|
panelDataArray
|
|
1442
|
-
} =
|
|
1454
|
+
} = eagerValuesRef.current;
|
|
1443
1455
|
if (panelData.constraints.collapsible) {
|
|
1444
1456
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1445
1457
|
const {
|
|
@@ -1452,7 +1464,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1452
1464
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1453
1465
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1454
1466
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1455
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1467
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1456
1468
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1457
1469
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1458
1470
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1465,7 +1477,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1465
1477
|
});
|
|
1466
1478
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1467
1479
|
setLayout(nextLayout);
|
|
1468
|
-
|
|
1480
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1469
1481
|
if (onLayout) {
|
|
1470
1482
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1471
1483
|
sizePercentage,
|
|
@@ -1483,7 +1495,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1483
1495
|
const {
|
|
1484
1496
|
layout,
|
|
1485
1497
|
panelDataArray
|
|
1486
|
-
} =
|
|
1498
|
+
} = eagerValuesRef.current;
|
|
1487
1499
|
const {
|
|
1488
1500
|
panelSizePercentage,
|
|
1489
1501
|
panelSizePixels
|
|
@@ -1498,7 +1510,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1498
1510
|
const getPanelStyle = useCallback(panelData => {
|
|
1499
1511
|
const {
|
|
1500
1512
|
panelDataArray
|
|
1501
|
-
} =
|
|
1513
|
+
} = eagerValuesRef.current;
|
|
1502
1514
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1503
1515
|
return computePanelFlexBoxStyle({
|
|
1504
1516
|
dragState,
|
|
@@ -1513,7 +1525,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1513
1525
|
const {
|
|
1514
1526
|
layout,
|
|
1515
1527
|
panelDataArray
|
|
1516
|
-
} =
|
|
1528
|
+
} = eagerValuesRef.current;
|
|
1517
1529
|
const {
|
|
1518
1530
|
collapsedSizePercentage,
|
|
1519
1531
|
collapsible,
|
|
@@ -1527,7 +1539,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1527
1539
|
const {
|
|
1528
1540
|
layout,
|
|
1529
1541
|
panelDataArray
|
|
1530
|
-
} =
|
|
1542
|
+
} = eagerValuesRef.current;
|
|
1531
1543
|
const {
|
|
1532
1544
|
collapsedSizePercentage,
|
|
1533
1545
|
collapsible,
|
|
@@ -1539,11 +1551,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1539
1551
|
const {
|
|
1540
1552
|
autoSaveId,
|
|
1541
1553
|
id: groupId,
|
|
1542
|
-
layout: prevLayout,
|
|
1543
1554
|
onLayout,
|
|
1544
|
-
panelDataArray,
|
|
1545
1555
|
storage
|
|
1546
1556
|
} = committedValuesRef.current;
|
|
1557
|
+
const {
|
|
1558
|
+
layout: prevLayout,
|
|
1559
|
+
panelDataArray
|
|
1560
|
+
} = eagerValuesRef.current;
|
|
1547
1561
|
panelDataArray.push(panelData);
|
|
1548
1562
|
panelDataArray.sort((panelA, panelB) => {
|
|
1549
1563
|
const orderA = panelA.order;
|
|
@@ -1595,9 +1609,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1595
1609
|
layout: unsafeLayout,
|
|
1596
1610
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1597
1611
|
});
|
|
1612
|
+
|
|
1613
|
+
// Offscreen mode makes this a bit weird;
|
|
1614
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1615
|
+
// but the overall layout doesn't change between these two cases.
|
|
1616
|
+
setLayout(nextLayout);
|
|
1617
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1598
1618
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1599
|
-
setLayout(nextLayout);
|
|
1600
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1601
1619
|
if (onLayout) {
|
|
1602
1620
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1603
1621
|
sizePercentage,
|
|
@@ -1616,10 +1634,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1616
1634
|
id: groupId,
|
|
1617
1635
|
keyboardResizeByPercentage,
|
|
1618
1636
|
keyboardResizeByPixels,
|
|
1619
|
-
onLayout
|
|
1620
|
-
panelDataArray,
|
|
1621
|
-
layout: prevLayout
|
|
1637
|
+
onLayout
|
|
1622
1638
|
} = committedValuesRef.current;
|
|
1639
|
+
const {
|
|
1640
|
+
layout: prevLayout,
|
|
1641
|
+
panelDataArray
|
|
1642
|
+
} = eagerValuesRef.current;
|
|
1623
1643
|
const {
|
|
1624
1644
|
initialLayout
|
|
1625
1645
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1675,7 +1695,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1675
1695
|
}
|
|
1676
1696
|
if (layoutChanged) {
|
|
1677
1697
|
setLayout(nextLayout);
|
|
1678
|
-
|
|
1698
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1679
1699
|
if (onLayout) {
|
|
1680
1700
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1681
1701
|
sizePercentage,
|
|
@@ -1689,11 +1709,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1689
1709
|
|
|
1690
1710
|
// External APIs are safe to memoize via committed values ref
|
|
1691
1711
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1712
|
+
const {
|
|
1713
|
+
onLayout
|
|
1714
|
+
} = committedValuesRef.current;
|
|
1692
1715
|
const {
|
|
1693
1716
|
layout: prevLayout,
|
|
1694
|
-
onLayout,
|
|
1695
1717
|
panelDataArray
|
|
1696
|
-
} =
|
|
1718
|
+
} = eagerValuesRef.current;
|
|
1697
1719
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1698
1720
|
const {
|
|
1699
1721
|
groupSizePixels,
|
|
@@ -1713,7 +1735,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1713
1735
|
});
|
|
1714
1736
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1715
1737
|
setLayout(nextLayout);
|
|
1716
|
-
|
|
1738
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1717
1739
|
if (onLayout) {
|
|
1718
1740
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1719
1741
|
sizePercentage,
|
|
@@ -1725,9 +1747,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1725
1747
|
}, [groupId]);
|
|
1726
1748
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1727
1749
|
const {
|
|
1728
|
-
direction
|
|
1729
|
-
layout
|
|
1750
|
+
direction
|
|
1730
1751
|
} = committedValuesRef.current;
|
|
1752
|
+
const {
|
|
1753
|
+
layout
|
|
1754
|
+
} = eagerValuesRef.current;
|
|
1731
1755
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1732
1756
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1733
1757
|
setDragState({
|
|
@@ -1748,10 +1772,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1748
1772
|
const unregisterPanel = useCallback(panelData => {
|
|
1749
1773
|
const {
|
|
1750
1774
|
id: groupId,
|
|
1775
|
+
onLayout
|
|
1776
|
+
} = committedValuesRef.current;
|
|
1777
|
+
const {
|
|
1751
1778
|
layout: prevLayout,
|
|
1752
|
-
onLayout,
|
|
1753
1779
|
panelDataArray
|
|
1754
|
-
} =
|
|
1780
|
+
} = eagerValuesRef.current;
|
|
1755
1781
|
const index = panelDataArray.indexOf(panelData);
|
|
1756
1782
|
if (index >= 0) {
|
|
1757
1783
|
panelDataArray.splice(index, 1);
|
|
@@ -1768,7 +1794,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1768
1794
|
const {
|
|
1769
1795
|
pendingPanelIds
|
|
1770
1796
|
} = unregisterPanelRef.current;
|
|
1771
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1797
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1772
1798
|
|
|
1773
1799
|
// TRICKY
|
|
1774
1800
|
// Strict effects mode
|
|
@@ -1784,7 +1810,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1784
1810
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1785
1811
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1786
1812
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1787
|
-
delete
|
|
1813
|
+
delete map[panelData.id];
|
|
1788
1814
|
}
|
|
1789
1815
|
});
|
|
1790
1816
|
if (!unmountDueToStrictMode) {
|
|
@@ -1809,7 +1835,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1809
1835
|
});
|
|
1810
1836
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1811
1837
|
setLayout(nextLayout);
|
|
1812
|
-
|
|
1838
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1813
1839
|
if (onLayout) {
|
|
1814
1840
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1815
1841
|
sizePercentage,
|
|
@@ -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
|
-
} =
|
|
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
|
-
} =
|
|
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
|
-
|
|
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:
|
|
1357
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1350
1358
|
setLayout
|
|
1351
1359
|
});
|
|
1352
1360
|
useEffect(() => {
|
|
1353
1361
|
const {
|
|
1354
1362
|
panelDataArray
|
|
1355
|
-
} =
|
|
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
|
-
} =
|
|
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
|
-
|
|
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
|
-
} =
|
|
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
|
-
|
|
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
|
-
} =
|
|
1480
|
+
} = eagerValuesRef.current;
|
|
1469
1481
|
if (panelData.constraints.collapsible) {
|
|
1470
1482
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1471
1483
|
const {
|
|
@@ -1478,7 +1490,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1478
1490
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1479
1491
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1480
1492
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1481
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1493
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1482
1494
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1483
1495
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1484
1496
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1491,7 +1503,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1491
1503
|
});
|
|
1492
1504
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1493
1505
|
setLayout(nextLayout);
|
|
1494
|
-
|
|
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
|
-
} =
|
|
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
|
-
} =
|
|
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
|
-
} =
|
|
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
|
-
} =
|
|
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
|
-
|
|
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
|
-
} =
|
|
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
|
-
|
|
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
|
-
} =
|
|
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
|
|
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
|
-
|
|
1864
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1839
1865
|
if (onLayout) {
|
|
1840
1866
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1841
1867
|
sizePercentage,
|