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
|
@@ -619,6 +619,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
619
619
|
|
|
620
620
|
function useWindowSplitterPanelGroupBehavior({
|
|
621
621
|
committedValuesRef,
|
|
622
|
+
eagerValuesRef,
|
|
622
623
|
groupId,
|
|
623
624
|
layout,
|
|
624
625
|
panelDataArray,
|
|
@@ -630,7 +631,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
630
631
|
useEffect(() => {
|
|
631
632
|
const {
|
|
632
633
|
panelDataArray
|
|
633
|
-
} =
|
|
634
|
+
} = eagerValuesRef.current;
|
|
634
635
|
const groupElement = getPanelGroupElement(groupId);
|
|
635
636
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
636
637
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -688,7 +689,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
688
689
|
return () => {
|
|
689
690
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
690
691
|
};
|
|
691
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
692
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
692
693
|
}
|
|
693
694
|
|
|
694
695
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1230,11 +1231,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1230
1231
|
id: groupId,
|
|
1231
1232
|
keyboardResizeByPercentage,
|
|
1232
1233
|
keyboardResizeByPixels,
|
|
1233
|
-
layout,
|
|
1234
1234
|
onLayout,
|
|
1235
|
-
panelDataArray: [],
|
|
1236
1235
|
storage
|
|
1237
1236
|
});
|
|
1237
|
+
const eagerValuesRef = useRef({
|
|
1238
|
+
layout,
|
|
1239
|
+
panelDataArray: []
|
|
1240
|
+
});
|
|
1238
1241
|
const devWarningsRef = useRef({
|
|
1239
1242
|
didLogIdAndOrderWarning: false,
|
|
1240
1243
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1244,9 +1247,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1244
1247
|
getId: () => committedValuesRef.current.id,
|
|
1245
1248
|
getLayout: () => {
|
|
1246
1249
|
const {
|
|
1247
|
-
id: groupId
|
|
1248
|
-
layout
|
|
1250
|
+
id: groupId
|
|
1249
1251
|
} = committedValuesRef.current;
|
|
1252
|
+
const {
|
|
1253
|
+
layout
|
|
1254
|
+
} = eagerValuesRef.current;
|
|
1250
1255
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1251
1256
|
return layout.map(sizePercentage => {
|
|
1252
1257
|
return {
|
|
@@ -1258,10 +1263,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1258
1263
|
setLayout: mixedSizes => {
|
|
1259
1264
|
const {
|
|
1260
1265
|
id: groupId,
|
|
1266
|
+
onLayout
|
|
1267
|
+
} = committedValuesRef.current;
|
|
1268
|
+
const {
|
|
1261
1269
|
layout: prevLayout,
|
|
1262
|
-
onLayout,
|
|
1263
1270
|
panelDataArray
|
|
1264
|
-
} =
|
|
1271
|
+
} = eagerValuesRef.current;
|
|
1265
1272
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1266
1273
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1267
1274
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1271,7 +1278,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1271
1278
|
});
|
|
1272
1279
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1273
1280
|
setLayout(safeLayout);
|
|
1274
|
-
|
|
1281
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1275
1282
|
if (onLayout) {
|
|
1276
1283
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1277
1284
|
sizePercentage,
|
|
@@ -1285,15 +1292,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1285
1292
|
|
|
1286
1293
|
useWindowSplitterPanelGroupBehavior({
|
|
1287
1294
|
committedValuesRef,
|
|
1295
|
+
eagerValuesRef,
|
|
1288
1296
|
groupId,
|
|
1289
1297
|
layout,
|
|
1290
|
-
panelDataArray:
|
|
1298
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1291
1299
|
setLayout
|
|
1292
1300
|
});
|
|
1293
1301
|
useEffect(() => {
|
|
1294
1302
|
const {
|
|
1295
1303
|
panelDataArray
|
|
1296
|
-
} =
|
|
1304
|
+
} = eagerValuesRef.current;
|
|
1297
1305
|
|
|
1298
1306
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1299
1307
|
if (autoSaveId) {
|
|
@@ -1314,7 +1322,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1314
1322
|
{
|
|
1315
1323
|
const {
|
|
1316
1324
|
panelDataArray
|
|
1317
|
-
} =
|
|
1325
|
+
} = eagerValuesRef.current;
|
|
1318
1326
|
const {
|
|
1319
1327
|
didLogIdAndOrderWarning,
|
|
1320
1328
|
didLogPanelConstraintsWarning,
|
|
@@ -1357,11 +1365,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1357
1365
|
|
|
1358
1366
|
// External APIs are safe to memoize via committed values ref
|
|
1359
1367
|
const collapsePanel = useCallback(panelData => {
|
|
1368
|
+
const {
|
|
1369
|
+
onLayout
|
|
1370
|
+
} = committedValuesRef.current;
|
|
1360
1371
|
const {
|
|
1361
1372
|
layout: prevLayout,
|
|
1362
|
-
onLayout,
|
|
1363
1373
|
panelDataArray
|
|
1364
|
-
} =
|
|
1374
|
+
} = eagerValuesRef.current;
|
|
1365
1375
|
if (panelData.constraints.collapsible) {
|
|
1366
1376
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1367
1377
|
const {
|
|
@@ -1386,7 +1396,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1386
1396
|
});
|
|
1387
1397
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1388
1398
|
setLayout(nextLayout);
|
|
1389
|
-
|
|
1399
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1390
1400
|
if (onLayout) {
|
|
1391
1401
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1392
1402
|
sizePercentage,
|
|
@@ -1401,11 +1411,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1401
1411
|
|
|
1402
1412
|
// External APIs are safe to memoize via committed values ref
|
|
1403
1413
|
const expandPanel = useCallback(panelData => {
|
|
1414
|
+
const {
|
|
1415
|
+
onLayout
|
|
1416
|
+
} = committedValuesRef.current;
|
|
1404
1417
|
const {
|
|
1405
1418
|
layout: prevLayout,
|
|
1406
|
-
onLayout,
|
|
1407
1419
|
panelDataArray
|
|
1408
|
-
} =
|
|
1420
|
+
} = eagerValuesRef.current;
|
|
1409
1421
|
if (panelData.constraints.collapsible) {
|
|
1410
1422
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1411
1423
|
const {
|
|
@@ -1418,7 +1430,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1418
1430
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1419
1431
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1420
1432
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1421
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1433
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1422
1434
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1423
1435
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1424
1436
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1431,7 +1443,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1431
1443
|
});
|
|
1432
1444
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1433
1445
|
setLayout(nextLayout);
|
|
1434
|
-
|
|
1446
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1435
1447
|
if (onLayout) {
|
|
1436
1448
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1437
1449
|
sizePercentage,
|
|
@@ -1449,7 +1461,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1449
1461
|
const {
|
|
1450
1462
|
layout,
|
|
1451
1463
|
panelDataArray
|
|
1452
|
-
} =
|
|
1464
|
+
} = eagerValuesRef.current;
|
|
1453
1465
|
const {
|
|
1454
1466
|
panelSizePercentage,
|
|
1455
1467
|
panelSizePixels
|
|
@@ -1464,7 +1476,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1464
1476
|
const getPanelStyle = useCallback(panelData => {
|
|
1465
1477
|
const {
|
|
1466
1478
|
panelDataArray
|
|
1467
|
-
} =
|
|
1479
|
+
} = eagerValuesRef.current;
|
|
1468
1480
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1469
1481
|
return computePanelFlexBoxStyle({
|
|
1470
1482
|
dragState,
|
|
@@ -1479,7 +1491,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1479
1491
|
const {
|
|
1480
1492
|
layout,
|
|
1481
1493
|
panelDataArray
|
|
1482
|
-
} =
|
|
1494
|
+
} = eagerValuesRef.current;
|
|
1483
1495
|
const {
|
|
1484
1496
|
collapsedSizePercentage,
|
|
1485
1497
|
collapsible,
|
|
@@ -1493,7 +1505,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1493
1505
|
const {
|
|
1494
1506
|
layout,
|
|
1495
1507
|
panelDataArray
|
|
1496
|
-
} =
|
|
1508
|
+
} = eagerValuesRef.current;
|
|
1497
1509
|
const {
|
|
1498
1510
|
collapsedSizePercentage,
|
|
1499
1511
|
collapsible,
|
|
@@ -1505,11 +1517,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1505
1517
|
const {
|
|
1506
1518
|
autoSaveId,
|
|
1507
1519
|
id: groupId,
|
|
1508
|
-
layout: prevLayout,
|
|
1509
1520
|
onLayout,
|
|
1510
|
-
panelDataArray,
|
|
1511
1521
|
storage
|
|
1512
1522
|
} = committedValuesRef.current;
|
|
1523
|
+
const {
|
|
1524
|
+
layout: prevLayout,
|
|
1525
|
+
panelDataArray
|
|
1526
|
+
} = eagerValuesRef.current;
|
|
1513
1527
|
panelDataArray.push(panelData);
|
|
1514
1528
|
panelDataArray.sort((panelA, panelB) => {
|
|
1515
1529
|
const orderA = panelA.order;
|
|
@@ -1561,9 +1575,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1561
1575
|
layout: unsafeLayout,
|
|
1562
1576
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1563
1577
|
});
|
|
1578
|
+
|
|
1579
|
+
// Offscreen mode makes this a bit weird;
|
|
1580
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1581
|
+
// but the overall layout doesn't change between these two cases.
|
|
1582
|
+
setLayout(nextLayout);
|
|
1583
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1564
1584
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1565
|
-
setLayout(nextLayout);
|
|
1566
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1567
1585
|
if (onLayout) {
|
|
1568
1586
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1569
1587
|
sizePercentage,
|
|
@@ -1582,10 +1600,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1582
1600
|
id: groupId,
|
|
1583
1601
|
keyboardResizeByPercentage,
|
|
1584
1602
|
keyboardResizeByPixels,
|
|
1585
|
-
onLayout
|
|
1586
|
-
panelDataArray,
|
|
1587
|
-
layout: prevLayout
|
|
1603
|
+
onLayout
|
|
1588
1604
|
} = committedValuesRef.current;
|
|
1605
|
+
const {
|
|
1606
|
+
layout: prevLayout,
|
|
1607
|
+
panelDataArray
|
|
1608
|
+
} = eagerValuesRef.current;
|
|
1589
1609
|
const {
|
|
1590
1610
|
initialLayout
|
|
1591
1611
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1641,7 +1661,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1641
1661
|
}
|
|
1642
1662
|
if (layoutChanged) {
|
|
1643
1663
|
setLayout(nextLayout);
|
|
1644
|
-
|
|
1664
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1645
1665
|
if (onLayout) {
|
|
1646
1666
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1647
1667
|
sizePercentage,
|
|
@@ -1655,11 +1675,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1655
1675
|
|
|
1656
1676
|
// External APIs are safe to memoize via committed values ref
|
|
1657
1677
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1678
|
+
const {
|
|
1679
|
+
onLayout
|
|
1680
|
+
} = committedValuesRef.current;
|
|
1658
1681
|
const {
|
|
1659
1682
|
layout: prevLayout,
|
|
1660
|
-
onLayout,
|
|
1661
1683
|
panelDataArray
|
|
1662
|
-
} =
|
|
1684
|
+
} = eagerValuesRef.current;
|
|
1663
1685
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1664
1686
|
const {
|
|
1665
1687
|
groupSizePixels,
|
|
@@ -1679,7 +1701,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1679
1701
|
});
|
|
1680
1702
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1681
1703
|
setLayout(nextLayout);
|
|
1682
|
-
|
|
1704
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1683
1705
|
if (onLayout) {
|
|
1684
1706
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1685
1707
|
sizePercentage,
|
|
@@ -1691,9 +1713,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1691
1713
|
}, [groupId]);
|
|
1692
1714
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1693
1715
|
const {
|
|
1694
|
-
direction
|
|
1695
|
-
layout
|
|
1716
|
+
direction
|
|
1696
1717
|
} = committedValuesRef.current;
|
|
1718
|
+
const {
|
|
1719
|
+
layout
|
|
1720
|
+
} = eagerValuesRef.current;
|
|
1697
1721
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1698
1722
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1699
1723
|
setDragState({
|
|
@@ -1714,10 +1738,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1714
1738
|
const unregisterPanel = useCallback(panelData => {
|
|
1715
1739
|
const {
|
|
1716
1740
|
id: groupId,
|
|
1741
|
+
onLayout
|
|
1742
|
+
} = committedValuesRef.current;
|
|
1743
|
+
const {
|
|
1717
1744
|
layout: prevLayout,
|
|
1718
|
-
onLayout,
|
|
1719
1745
|
panelDataArray
|
|
1720
|
-
} =
|
|
1746
|
+
} = eagerValuesRef.current;
|
|
1721
1747
|
const index = panelDataArray.indexOf(panelData);
|
|
1722
1748
|
if (index >= 0) {
|
|
1723
1749
|
panelDataArray.splice(index, 1);
|
|
@@ -1734,7 +1760,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1734
1760
|
const {
|
|
1735
1761
|
pendingPanelIds
|
|
1736
1762
|
} = unregisterPanelRef.current;
|
|
1737
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1763
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1738
1764
|
|
|
1739
1765
|
// TRICKY
|
|
1740
1766
|
// Strict effects mode
|
|
@@ -1750,7 +1776,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1750
1776
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1751
1777
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1752
1778
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1753
|
-
delete
|
|
1779
|
+
delete map[panelData.id];
|
|
1754
1780
|
}
|
|
1755
1781
|
});
|
|
1756
1782
|
if (!unmountDueToStrictMode) {
|
|
@@ -1775,7 +1801,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1775
1801
|
});
|
|
1776
1802
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1777
1803
|
setLayout(nextLayout);
|
|
1778
|
-
|
|
1804
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1779
1805
|
if (onLayout) {
|
|
1780
1806
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1781
1807
|
sizePercentage,
|
|
@@ -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 {
|
|
@@ -1454,7 +1466,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1454
1466
|
if (panelSizePercentage === collapsedSizePercentage) {
|
|
1455
1467
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1456
1468
|
const prevPanelSizePercentage = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
1457
|
-
const baseSizePercentage = prevPanelSizePercentage != null ? prevPanelSizePercentage : minSizePercentage;
|
|
1469
|
+
const baseSizePercentage = prevPanelSizePercentage != null && prevPanelSizePercentage >= minSizePercentage ? prevPanelSizePercentage : minSizePercentage;
|
|
1458
1470
|
const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
|
|
1459
1471
|
const delta = isLastPanel ? panelSizePercentage - baseSizePercentage : baseSizePercentage - panelSizePercentage;
|
|
1460
1472
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -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,
|