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
|
@@ -632,6 +632,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
632
632
|
|
|
633
633
|
function useWindowSplitterPanelGroupBehavior({
|
|
634
634
|
committedValuesRef,
|
|
635
|
+
eagerValuesRef,
|
|
635
636
|
groupId,
|
|
636
637
|
layout,
|
|
637
638
|
panelDataArray,
|
|
@@ -643,7 +644,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
643
644
|
useEffect(() => {
|
|
644
645
|
const {
|
|
645
646
|
panelDataArray
|
|
646
|
-
} =
|
|
647
|
+
} = eagerValuesRef.current;
|
|
647
648
|
const groupElement = getPanelGroupElement(groupId);
|
|
648
649
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
649
650
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -701,7 +702,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
701
702
|
return () => {
|
|
702
703
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
703
704
|
};
|
|
704
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
705
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
705
706
|
}
|
|
706
707
|
|
|
707
708
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1166,11 +1167,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1166
1167
|
id: groupId,
|
|
1167
1168
|
keyboardResizeByPercentage,
|
|
1168
1169
|
keyboardResizeByPixels,
|
|
1169
|
-
layout,
|
|
1170
1170
|
onLayout,
|
|
1171
|
-
panelDataArray: [],
|
|
1172
1171
|
storage
|
|
1173
1172
|
});
|
|
1173
|
+
const eagerValuesRef = useRef({
|
|
1174
|
+
layout,
|
|
1175
|
+
panelDataArray: []
|
|
1176
|
+
});
|
|
1174
1177
|
useRef({
|
|
1175
1178
|
didLogIdAndOrderWarning: false,
|
|
1176
1179
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1180,9 +1183,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1180
1183
|
getId: () => committedValuesRef.current.id,
|
|
1181
1184
|
getLayout: () => {
|
|
1182
1185
|
const {
|
|
1183
|
-
id: groupId
|
|
1184
|
-
layout
|
|
1186
|
+
id: groupId
|
|
1185
1187
|
} = committedValuesRef.current;
|
|
1188
|
+
const {
|
|
1189
|
+
layout
|
|
1190
|
+
} = eagerValuesRef.current;
|
|
1186
1191
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1187
1192
|
return layout.map(sizePercentage => {
|
|
1188
1193
|
return {
|
|
@@ -1194,10 +1199,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1194
1199
|
setLayout: mixedSizes => {
|
|
1195
1200
|
const {
|
|
1196
1201
|
id: groupId,
|
|
1202
|
+
onLayout
|
|
1203
|
+
} = committedValuesRef.current;
|
|
1204
|
+
const {
|
|
1197
1205
|
layout: prevLayout,
|
|
1198
|
-
onLayout,
|
|
1199
1206
|
panelDataArray
|
|
1200
|
-
} =
|
|
1207
|
+
} = eagerValuesRef.current;
|
|
1201
1208
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1202
1209
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1203
1210
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1207,7 +1214,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1207
1214
|
});
|
|
1208
1215
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1209
1216
|
setLayout(safeLayout);
|
|
1210
|
-
|
|
1217
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1211
1218
|
if (onLayout) {
|
|
1212
1219
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1213
1220
|
sizePercentage,
|
|
@@ -1221,15 +1228,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1221
1228
|
|
|
1222
1229
|
useWindowSplitterPanelGroupBehavior({
|
|
1223
1230
|
committedValuesRef,
|
|
1231
|
+
eagerValuesRef,
|
|
1224
1232
|
groupId,
|
|
1225
1233
|
layout,
|
|
1226
|
-
panelDataArray:
|
|
1234
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1227
1235
|
setLayout
|
|
1228
1236
|
});
|
|
1229
1237
|
useEffect(() => {
|
|
1230
1238
|
const {
|
|
1231
1239
|
panelDataArray
|
|
1232
|
-
} =
|
|
1240
|
+
} = eagerValuesRef.current;
|
|
1233
1241
|
|
|
1234
1242
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1235
1243
|
if (autoSaveId) {
|
|
@@ -1251,11 +1259,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1251
1259
|
|
|
1252
1260
|
// External APIs are safe to memoize via committed values ref
|
|
1253
1261
|
const collapsePanel = useCallback(panelData => {
|
|
1262
|
+
const {
|
|
1263
|
+
onLayout
|
|
1264
|
+
} = committedValuesRef.current;
|
|
1254
1265
|
const {
|
|
1255
1266
|
layout: prevLayout,
|
|
1256
|
-
onLayout,
|
|
1257
1267
|
panelDataArray
|
|
1258
|
-
} =
|
|
1268
|
+
} = eagerValuesRef.current;
|
|
1259
1269
|
if (panelData.constraints.collapsible) {
|
|
1260
1270
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1261
1271
|
const {
|
|
@@ -1280,7 +1290,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1280
1290
|
});
|
|
1281
1291
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1282
1292
|
setLayout(nextLayout);
|
|
1283
|
-
|
|
1293
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1284
1294
|
if (onLayout) {
|
|
1285
1295
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1286
1296
|
sizePercentage,
|
|
@@ -1295,11 +1305,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1295
1305
|
|
|
1296
1306
|
// External APIs are safe to memoize via committed values ref
|
|
1297
1307
|
const expandPanel = useCallback(panelData => {
|
|
1308
|
+
const {
|
|
1309
|
+
onLayout
|
|
1310
|
+
} = committedValuesRef.current;
|
|
1298
1311
|
const {
|
|
1299
1312
|
layout: prevLayout,
|
|
1300
|
-
onLayout,
|
|
1301
1313
|
panelDataArray
|
|
1302
|
-
} =
|
|
1314
|
+
} = eagerValuesRef.current;
|
|
1303
1315
|
if (panelData.constraints.collapsible) {
|
|
1304
1316
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1305
1317
|
const {
|
|
@@ -1325,7 +1337,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1325
1337
|
});
|
|
1326
1338
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1327
1339
|
setLayout(nextLayout);
|
|
1328
|
-
|
|
1340
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1329
1341
|
if (onLayout) {
|
|
1330
1342
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1331
1343
|
sizePercentage,
|
|
@@ -1343,7 +1355,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1343
1355
|
const {
|
|
1344
1356
|
layout,
|
|
1345
1357
|
panelDataArray
|
|
1346
|
-
} =
|
|
1358
|
+
} = eagerValuesRef.current;
|
|
1347
1359
|
const {
|
|
1348
1360
|
panelSizePercentage,
|
|
1349
1361
|
panelSizePixels
|
|
@@ -1358,7 +1370,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1358
1370
|
const getPanelStyle = useCallback(panelData => {
|
|
1359
1371
|
const {
|
|
1360
1372
|
panelDataArray
|
|
1361
|
-
} =
|
|
1373
|
+
} = eagerValuesRef.current;
|
|
1362
1374
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1363
1375
|
return computePanelFlexBoxStyle({
|
|
1364
1376
|
dragState,
|
|
@@ -1373,7 +1385,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1373
1385
|
const {
|
|
1374
1386
|
layout,
|
|
1375
1387
|
panelDataArray
|
|
1376
|
-
} =
|
|
1388
|
+
} = eagerValuesRef.current;
|
|
1377
1389
|
const {
|
|
1378
1390
|
collapsedSizePercentage,
|
|
1379
1391
|
collapsible,
|
|
@@ -1387,7 +1399,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1387
1399
|
const {
|
|
1388
1400
|
layout,
|
|
1389
1401
|
panelDataArray
|
|
1390
|
-
} =
|
|
1402
|
+
} = eagerValuesRef.current;
|
|
1391
1403
|
const {
|
|
1392
1404
|
collapsedSizePercentage,
|
|
1393
1405
|
collapsible,
|
|
@@ -1399,11 +1411,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1399
1411
|
const {
|
|
1400
1412
|
autoSaveId,
|
|
1401
1413
|
id: groupId,
|
|
1402
|
-
layout: prevLayout,
|
|
1403
1414
|
onLayout,
|
|
1404
|
-
panelDataArray,
|
|
1405
1415
|
storage
|
|
1406
1416
|
} = committedValuesRef.current;
|
|
1417
|
+
const {
|
|
1418
|
+
layout: prevLayout,
|
|
1419
|
+
panelDataArray
|
|
1420
|
+
} = eagerValuesRef.current;
|
|
1407
1421
|
panelDataArray.push(panelData);
|
|
1408
1422
|
panelDataArray.sort((panelA, panelB) => {
|
|
1409
1423
|
const orderA = panelA.order;
|
|
@@ -1455,9 +1469,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1455
1469
|
layout: unsafeLayout,
|
|
1456
1470
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1457
1471
|
});
|
|
1472
|
+
|
|
1473
|
+
// Offscreen mode makes this a bit weird;
|
|
1474
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1475
|
+
// but the overall layout doesn't change between these two cases.
|
|
1476
|
+
setLayout(nextLayout);
|
|
1477
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1458
1478
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1459
|
-
setLayout(nextLayout);
|
|
1460
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1461
1479
|
if (onLayout) {
|
|
1462
1480
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1463
1481
|
sizePercentage,
|
|
@@ -1476,10 +1494,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1476
1494
|
id: groupId,
|
|
1477
1495
|
keyboardResizeByPercentage,
|
|
1478
1496
|
keyboardResizeByPixels,
|
|
1479
|
-
onLayout
|
|
1480
|
-
panelDataArray,
|
|
1481
|
-
layout: prevLayout
|
|
1497
|
+
onLayout
|
|
1482
1498
|
} = committedValuesRef.current;
|
|
1499
|
+
const {
|
|
1500
|
+
layout: prevLayout,
|
|
1501
|
+
panelDataArray
|
|
1502
|
+
} = eagerValuesRef.current;
|
|
1483
1503
|
const {
|
|
1484
1504
|
initialLayout
|
|
1485
1505
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1535,7 +1555,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1535
1555
|
}
|
|
1536
1556
|
if (layoutChanged) {
|
|
1537
1557
|
setLayout(nextLayout);
|
|
1538
|
-
|
|
1558
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1539
1559
|
if (onLayout) {
|
|
1540
1560
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1541
1561
|
sizePercentage,
|
|
@@ -1549,11 +1569,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1549
1569
|
|
|
1550
1570
|
// External APIs are safe to memoize via committed values ref
|
|
1551
1571
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1572
|
+
const {
|
|
1573
|
+
onLayout
|
|
1574
|
+
} = committedValuesRef.current;
|
|
1552
1575
|
const {
|
|
1553
1576
|
layout: prevLayout,
|
|
1554
|
-
onLayout,
|
|
1555
1577
|
panelDataArray
|
|
1556
|
-
} =
|
|
1578
|
+
} = eagerValuesRef.current;
|
|
1557
1579
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1558
1580
|
const {
|
|
1559
1581
|
groupSizePixels,
|
|
@@ -1573,7 +1595,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1573
1595
|
});
|
|
1574
1596
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1575
1597
|
setLayout(nextLayout);
|
|
1576
|
-
|
|
1598
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1577
1599
|
if (onLayout) {
|
|
1578
1600
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1579
1601
|
sizePercentage,
|
|
@@ -1585,9 +1607,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1585
1607
|
}, [groupId]);
|
|
1586
1608
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1587
1609
|
const {
|
|
1588
|
-
direction
|
|
1589
|
-
layout
|
|
1610
|
+
direction
|
|
1590
1611
|
} = committedValuesRef.current;
|
|
1612
|
+
const {
|
|
1613
|
+
layout
|
|
1614
|
+
} = eagerValuesRef.current;
|
|
1591
1615
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1592
1616
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1593
1617
|
setDragState({
|
|
@@ -1608,10 +1632,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1608
1632
|
const unregisterPanel = useCallback(panelData => {
|
|
1609
1633
|
const {
|
|
1610
1634
|
id: groupId,
|
|
1635
|
+
onLayout
|
|
1636
|
+
} = committedValuesRef.current;
|
|
1637
|
+
const {
|
|
1611
1638
|
layout: prevLayout,
|
|
1612
|
-
onLayout,
|
|
1613
1639
|
panelDataArray
|
|
1614
|
-
} =
|
|
1640
|
+
} = eagerValuesRef.current;
|
|
1615
1641
|
const index = panelDataArray.indexOf(panelData);
|
|
1616
1642
|
if (index >= 0) {
|
|
1617
1643
|
panelDataArray.splice(index, 1);
|
|
@@ -1628,7 +1654,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1628
1654
|
const {
|
|
1629
1655
|
pendingPanelIds
|
|
1630
1656
|
} = unregisterPanelRef.current;
|
|
1631
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1657
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1632
1658
|
|
|
1633
1659
|
// TRICKY
|
|
1634
1660
|
// Strict effects mode
|
|
@@ -1644,7 +1670,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1644
1670
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1645
1671
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1646
1672
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1647
|
-
delete
|
|
1673
|
+
delete map[panelData.id];
|
|
1648
1674
|
}
|
|
1649
1675
|
});
|
|
1650
1676
|
if (!unmountDueToStrictMode) {
|
|
@@ -1669,7 +1695,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1669
1695
|
});
|
|
1670
1696
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1671
1697
|
setLayout(nextLayout);
|
|
1672
|
-
|
|
1698
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1673
1699
|
if (onLayout) {
|
|
1674
1700
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1675
1701
|
sizePercentage,
|
|
@@ -608,6 +608,7 @@ function getResizeHandlePanelIds(groupId, handleId, panelsArray) {
|
|
|
608
608
|
|
|
609
609
|
function useWindowSplitterPanelGroupBehavior({
|
|
610
610
|
committedValuesRef,
|
|
611
|
+
eagerValuesRef,
|
|
611
612
|
groupId,
|
|
612
613
|
layout,
|
|
613
614
|
panelDataArray,
|
|
@@ -619,7 +620,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
619
620
|
useEffect(() => {
|
|
620
621
|
const {
|
|
621
622
|
panelDataArray
|
|
622
|
-
} =
|
|
623
|
+
} = eagerValuesRef.current;
|
|
623
624
|
const groupElement = getPanelGroupElement(groupId);
|
|
624
625
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
625
626
|
const handles = getResizeHandleElementsForGroup(groupId);
|
|
@@ -677,7 +678,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
677
678
|
return () => {
|
|
678
679
|
cleanupFunctions.forEach(cleanupFunction => cleanupFunction());
|
|
679
680
|
};
|
|
680
|
-
}, [committedValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
681
|
+
}, [committedValuesRef, eagerValuesRef, groupId, layout, panelDataArray, setLayout]);
|
|
681
682
|
}
|
|
682
683
|
|
|
683
684
|
function areEqual(arrayA, arrayB) {
|
|
@@ -1142,11 +1143,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1142
1143
|
id: groupId,
|
|
1143
1144
|
keyboardResizeByPercentage,
|
|
1144
1145
|
keyboardResizeByPixels,
|
|
1145
|
-
layout,
|
|
1146
1146
|
onLayout,
|
|
1147
|
-
panelDataArray: [],
|
|
1148
1147
|
storage
|
|
1149
1148
|
});
|
|
1149
|
+
const eagerValuesRef = useRef({
|
|
1150
|
+
layout,
|
|
1151
|
+
panelDataArray: []
|
|
1152
|
+
});
|
|
1150
1153
|
useRef({
|
|
1151
1154
|
didLogIdAndOrderWarning: false,
|
|
1152
1155
|
didLogPanelConstraintsWarning: false,
|
|
@@ -1156,9 +1159,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1156
1159
|
getId: () => committedValuesRef.current.id,
|
|
1157
1160
|
getLayout: () => {
|
|
1158
1161
|
const {
|
|
1159
|
-
id: groupId
|
|
1160
|
-
layout
|
|
1162
|
+
id: groupId
|
|
1161
1163
|
} = committedValuesRef.current;
|
|
1164
|
+
const {
|
|
1165
|
+
layout
|
|
1166
|
+
} = eagerValuesRef.current;
|
|
1162
1167
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1163
1168
|
return layout.map(sizePercentage => {
|
|
1164
1169
|
return {
|
|
@@ -1170,10 +1175,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1170
1175
|
setLayout: mixedSizes => {
|
|
1171
1176
|
const {
|
|
1172
1177
|
id: groupId,
|
|
1178
|
+
onLayout
|
|
1179
|
+
} = committedValuesRef.current;
|
|
1180
|
+
const {
|
|
1173
1181
|
layout: prevLayout,
|
|
1174
|
-
onLayout,
|
|
1175
1182
|
panelDataArray
|
|
1176
|
-
} =
|
|
1183
|
+
} = eagerValuesRef.current;
|
|
1177
1184
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
1178
1185
|
const unsafeLayout = mixedSizes.map(mixedSize => getPercentageSizeFromMixedSizes(mixedSize, groupSizePixels));
|
|
1179
1186
|
const safeLayout = validatePanelGroupLayout({
|
|
@@ -1183,7 +1190,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1183
1190
|
});
|
|
1184
1191
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
1185
1192
|
setLayout(safeLayout);
|
|
1186
|
-
|
|
1193
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
1187
1194
|
if (onLayout) {
|
|
1188
1195
|
onLayout(safeLayout.map(sizePercentage => ({
|
|
1189
1196
|
sizePercentage,
|
|
@@ -1197,15 +1204,16 @@ function PanelGroupWithForwardedRef({
|
|
|
1197
1204
|
|
|
1198
1205
|
useWindowSplitterPanelGroupBehavior({
|
|
1199
1206
|
committedValuesRef,
|
|
1207
|
+
eagerValuesRef,
|
|
1200
1208
|
groupId,
|
|
1201
1209
|
layout,
|
|
1202
|
-
panelDataArray:
|
|
1210
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
1203
1211
|
setLayout
|
|
1204
1212
|
});
|
|
1205
1213
|
useEffect(() => {
|
|
1206
1214
|
const {
|
|
1207
1215
|
panelDataArray
|
|
1208
|
-
} =
|
|
1216
|
+
} = eagerValuesRef.current;
|
|
1209
1217
|
|
|
1210
1218
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
1211
1219
|
if (autoSaveId) {
|
|
@@ -1227,11 +1235,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1227
1235
|
|
|
1228
1236
|
// External APIs are safe to memoize via committed values ref
|
|
1229
1237
|
const collapsePanel = useCallback(panelData => {
|
|
1238
|
+
const {
|
|
1239
|
+
onLayout
|
|
1240
|
+
} = committedValuesRef.current;
|
|
1230
1241
|
const {
|
|
1231
1242
|
layout: prevLayout,
|
|
1232
|
-
onLayout,
|
|
1233
1243
|
panelDataArray
|
|
1234
|
-
} =
|
|
1244
|
+
} = eagerValuesRef.current;
|
|
1235
1245
|
if (panelData.constraints.collapsible) {
|
|
1236
1246
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1237
1247
|
const {
|
|
@@ -1256,7 +1266,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1256
1266
|
});
|
|
1257
1267
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1258
1268
|
setLayout(nextLayout);
|
|
1259
|
-
|
|
1269
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1260
1270
|
if (onLayout) {
|
|
1261
1271
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1262
1272
|
sizePercentage,
|
|
@@ -1271,11 +1281,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1271
1281
|
|
|
1272
1282
|
// External APIs are safe to memoize via committed values ref
|
|
1273
1283
|
const expandPanel = useCallback(panelData => {
|
|
1284
|
+
const {
|
|
1285
|
+
onLayout
|
|
1286
|
+
} = committedValuesRef.current;
|
|
1274
1287
|
const {
|
|
1275
1288
|
layout: prevLayout,
|
|
1276
|
-
onLayout,
|
|
1277
1289
|
panelDataArray
|
|
1278
|
-
} =
|
|
1290
|
+
} = eagerValuesRef.current;
|
|
1279
1291
|
if (panelData.constraints.collapsible) {
|
|
1280
1292
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1281
1293
|
const {
|
|
@@ -1301,7 +1313,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1301
1313
|
});
|
|
1302
1314
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1303
1315
|
setLayout(nextLayout);
|
|
1304
|
-
|
|
1316
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1305
1317
|
if (onLayout) {
|
|
1306
1318
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1307
1319
|
sizePercentage,
|
|
@@ -1319,7 +1331,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1319
1331
|
const {
|
|
1320
1332
|
layout,
|
|
1321
1333
|
panelDataArray
|
|
1322
|
-
} =
|
|
1334
|
+
} = eagerValuesRef.current;
|
|
1323
1335
|
const {
|
|
1324
1336
|
panelSizePercentage,
|
|
1325
1337
|
panelSizePixels
|
|
@@ -1334,7 +1346,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1334
1346
|
const getPanelStyle = useCallback(panelData => {
|
|
1335
1347
|
const {
|
|
1336
1348
|
panelDataArray
|
|
1337
|
-
} =
|
|
1349
|
+
} = eagerValuesRef.current;
|
|
1338
1350
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
1339
1351
|
return computePanelFlexBoxStyle({
|
|
1340
1352
|
dragState,
|
|
@@ -1349,7 +1361,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1349
1361
|
const {
|
|
1350
1362
|
layout,
|
|
1351
1363
|
panelDataArray
|
|
1352
|
-
} =
|
|
1364
|
+
} = eagerValuesRef.current;
|
|
1353
1365
|
const {
|
|
1354
1366
|
collapsedSizePercentage,
|
|
1355
1367
|
collapsible,
|
|
@@ -1363,7 +1375,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1363
1375
|
const {
|
|
1364
1376
|
layout,
|
|
1365
1377
|
panelDataArray
|
|
1366
|
-
} =
|
|
1378
|
+
} = eagerValuesRef.current;
|
|
1367
1379
|
const {
|
|
1368
1380
|
collapsedSizePercentage,
|
|
1369
1381
|
collapsible,
|
|
@@ -1375,11 +1387,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1375
1387
|
const {
|
|
1376
1388
|
autoSaveId,
|
|
1377
1389
|
id: groupId,
|
|
1378
|
-
layout: prevLayout,
|
|
1379
1390
|
onLayout,
|
|
1380
|
-
panelDataArray,
|
|
1381
1391
|
storage
|
|
1382
1392
|
} = committedValuesRef.current;
|
|
1393
|
+
const {
|
|
1394
|
+
layout: prevLayout,
|
|
1395
|
+
panelDataArray
|
|
1396
|
+
} = eagerValuesRef.current;
|
|
1383
1397
|
panelDataArray.push(panelData);
|
|
1384
1398
|
panelDataArray.sort((panelA, panelB) => {
|
|
1385
1399
|
const orderA = panelA.order;
|
|
@@ -1431,9 +1445,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1431
1445
|
layout: unsafeLayout,
|
|
1432
1446
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints)
|
|
1433
1447
|
});
|
|
1448
|
+
|
|
1449
|
+
// Offscreen mode makes this a bit weird;
|
|
1450
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
1451
|
+
// but the overall layout doesn't change between these two cases.
|
|
1452
|
+
setLayout(nextLayout);
|
|
1453
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1434
1454
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1435
|
-
setLayout(nextLayout);
|
|
1436
|
-
committedValuesRef.current.layout = nextLayout;
|
|
1437
1455
|
if (onLayout) {
|
|
1438
1456
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1439
1457
|
sizePercentage,
|
|
@@ -1452,10 +1470,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1452
1470
|
id: groupId,
|
|
1453
1471
|
keyboardResizeByPercentage,
|
|
1454
1472
|
keyboardResizeByPixels,
|
|
1455
|
-
onLayout
|
|
1456
|
-
panelDataArray,
|
|
1457
|
-
layout: prevLayout
|
|
1473
|
+
onLayout
|
|
1458
1474
|
} = committedValuesRef.current;
|
|
1475
|
+
const {
|
|
1476
|
+
layout: prevLayout,
|
|
1477
|
+
panelDataArray
|
|
1478
|
+
} = eagerValuesRef.current;
|
|
1459
1479
|
const {
|
|
1460
1480
|
initialLayout
|
|
1461
1481
|
} = dragState !== null && dragState !== void 0 ? dragState : {};
|
|
@@ -1511,7 +1531,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1511
1531
|
}
|
|
1512
1532
|
if (layoutChanged) {
|
|
1513
1533
|
setLayout(nextLayout);
|
|
1514
|
-
|
|
1534
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1515
1535
|
if (onLayout) {
|
|
1516
1536
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1517
1537
|
sizePercentage,
|
|
@@ -1525,11 +1545,13 @@ function PanelGroupWithForwardedRef({
|
|
|
1525
1545
|
|
|
1526
1546
|
// External APIs are safe to memoize via committed values ref
|
|
1527
1547
|
const resizePanel = useCallback((panelData, mixedSizes) => {
|
|
1548
|
+
const {
|
|
1549
|
+
onLayout
|
|
1550
|
+
} = committedValuesRef.current;
|
|
1528
1551
|
const {
|
|
1529
1552
|
layout: prevLayout,
|
|
1530
|
-
onLayout,
|
|
1531
1553
|
panelDataArray
|
|
1532
|
-
} =
|
|
1554
|
+
} = eagerValuesRef.current;
|
|
1533
1555
|
const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
|
|
1534
1556
|
const {
|
|
1535
1557
|
groupSizePixels,
|
|
@@ -1549,7 +1571,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1549
1571
|
});
|
|
1550
1572
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
1551
1573
|
setLayout(nextLayout);
|
|
1552
|
-
|
|
1574
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1553
1575
|
if (onLayout) {
|
|
1554
1576
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1555
1577
|
sizePercentage,
|
|
@@ -1561,9 +1583,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1561
1583
|
}, [groupId]);
|
|
1562
1584
|
const startDragging = useCallback((dragHandleId, event) => {
|
|
1563
1585
|
const {
|
|
1564
|
-
direction
|
|
1565
|
-
layout
|
|
1586
|
+
direction
|
|
1566
1587
|
} = committedValuesRef.current;
|
|
1588
|
+
const {
|
|
1589
|
+
layout
|
|
1590
|
+
} = eagerValuesRef.current;
|
|
1567
1591
|
const handleElement = getResizeHandleElement(dragHandleId);
|
|
1568
1592
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1569
1593
|
setDragState({
|
|
@@ -1584,10 +1608,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1584
1608
|
const unregisterPanel = useCallback(panelData => {
|
|
1585
1609
|
const {
|
|
1586
1610
|
id: groupId,
|
|
1611
|
+
onLayout
|
|
1612
|
+
} = committedValuesRef.current;
|
|
1613
|
+
const {
|
|
1587
1614
|
layout: prevLayout,
|
|
1588
|
-
onLayout,
|
|
1589
1615
|
panelDataArray
|
|
1590
|
-
} =
|
|
1616
|
+
} = eagerValuesRef.current;
|
|
1591
1617
|
const index = panelDataArray.indexOf(panelData);
|
|
1592
1618
|
if (index >= 0) {
|
|
1593
1619
|
panelDataArray.splice(index, 1);
|
|
@@ -1604,7 +1630,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1604
1630
|
const {
|
|
1605
1631
|
pendingPanelIds
|
|
1606
1632
|
} = unregisterPanelRef.current;
|
|
1607
|
-
panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1633
|
+
const map = panelIdToLastNotifiedMixedSizesMapRef.current;
|
|
1608
1634
|
|
|
1609
1635
|
// TRICKY
|
|
1610
1636
|
// Strict effects mode
|
|
@@ -1620,7 +1646,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1620
1646
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
1621
1647
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
1622
1648
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
1623
|
-
delete
|
|
1649
|
+
delete map[panelData.id];
|
|
1624
1650
|
}
|
|
1625
1651
|
});
|
|
1626
1652
|
if (!unmountDueToStrictMode) {
|
|
@@ -1645,7 +1671,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1645
1671
|
});
|
|
1646
1672
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
1647
1673
|
setLayout(nextLayout);
|
|
1648
|
-
|
|
1674
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
1649
1675
|
if (onLayout) {
|
|
1650
1676
|
onLayout(nextLayout.map(sizePercentage => ({
|
|
1651
1677
|
sizePercentage,
|