react-resizable-panels 1.0.0-rc.2 → 1.0.0-rc.4

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.
@@ -667,47 +667,6 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
667
667
  }
668
668
  }
669
669
 
670
- function calculateUnsafeDefaultLayout({
671
- panelDataArray
672
- }) {
673
- const layout = Array(panelDataArray.length);
674
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
675
- let numPanelsWithSizes = 0;
676
- let remainingSize = 100;
677
-
678
- // Distribute default sizes first
679
- for (let index = 0; index < panelDataArray.length; index++) {
680
- const panelConstraints = panelConstraintsArray[index];
681
- assert(panelConstraints);
682
- const {
683
- defaultSize
684
- } = panelConstraints;
685
- if (defaultSize != null) {
686
- numPanelsWithSizes++;
687
- layout[index] = defaultSize;
688
- remainingSize -= defaultSize;
689
- }
690
- }
691
-
692
- // Remaining size should be distributed evenly between panels without default sizes
693
- for (let index = 0; index < panelDataArray.length; index++) {
694
- const panelConstraints = panelConstraintsArray[index];
695
- assert(panelConstraints);
696
- const {
697
- defaultSize
698
- } = panelConstraints;
699
- if (defaultSize != null) {
700
- continue;
701
- }
702
- const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
703
- const size = remainingSize / numRemainingPanels;
704
- numPanelsWithSizes++;
705
- layout[index] = size;
706
- remainingSize -= size;
707
- }
708
- return layout;
709
- }
710
-
711
670
  // Layout should be pre-converted into percentages
712
671
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
713
672
  layout.forEach((size, index) => {
@@ -841,10 +800,6 @@ function debounce(callback, durationMs = 10) {
841
800
  return callable;
842
801
  }
843
802
 
844
- function getPanelElementsForGroup(groupId) {
845
- return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
846
- }
847
-
848
803
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
849
804
  // or on a browser with cookies/storage disabled.
850
805
  // In either case, this function avoids accessing localStorage until needed,
@@ -900,15 +855,6 @@ function loadSerializedPanelGroupState(autoSaveId, storage) {
900
855
  } catch (error) {}
901
856
  return null;
902
857
  }
903
- function loadPanelLayout(autoSaveId, panels, storage) {
904
- const state = loadSerializedPanelGroupState(autoSaveId, storage);
905
- if (state) {
906
- var _state$key;
907
- const key = getSerializationKey(panels);
908
- return (_state$key = state[key]) !== null && _state$key !== void 0 ? _state$key : null;
909
- }
910
- return null;
911
- }
912
858
  function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
913
859
  const key = getSerializationKey(panels);
914
860
  const state = loadSerializedPanelGroupState(autoSaveId, storage) || {};
@@ -1011,6 +957,7 @@ function PanelGroupWithForwardedRef({
1011
957
  const groupId = useUniqueId(idFromProps);
1012
958
  const [dragState, setDragState] = useState(null);
1013
959
  const [layout, setLayout] = useState([]);
960
+ useState([]);
1014
961
  const panelIdToLastNotifiedSizeMapRef = useRef({});
1015
962
  const panelSizeBeforeCollapseRef = useRef(new Map());
1016
963
  const prevDeltaRef = useRef(0);
@@ -1025,7 +972,8 @@ function PanelGroupWithForwardedRef({
1025
972
  });
1026
973
  const eagerValuesRef = useRef({
1027
974
  layout,
1028
- panelDataArray: []
975
+ panelDataArray: [],
976
+ panelDataArrayChanged: false
1029
977
  });
1030
978
  useRef({
1031
979
  didLogIdAndOrderWarning: false,
@@ -1116,7 +1064,7 @@ function PanelGroupWithForwardedRef({
1116
1064
  // Store size before collapse;
1117
1065
  // This is the size that gets restored if the expand() API is used.
1118
1066
  panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
1119
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1067
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1120
1068
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1121
1069
  const nextLayout = adjustLayoutByDelta({
1122
1070
  delta,
@@ -1158,7 +1106,7 @@ function PanelGroupWithForwardedRef({
1158
1106
  // Restore this panel to the size it was before it was collapsed, if possible.
1159
1107
  const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
1160
1108
  const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
1161
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1109
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1162
1110
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1163
1111
  const nextLayout = adjustLayoutByDelta({
1164
1112
  delta,
@@ -1197,7 +1145,7 @@ function PanelGroupWithForwardedRef({
1197
1145
  const {
1198
1146
  panelDataArray
1199
1147
  } = eagerValuesRef.current;
1200
- const panelIndex = panelDataArray.indexOf(panelData);
1148
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1201
1149
  return computePanelFlexBoxStyle({
1202
1150
  dragState,
1203
1151
  layout,
@@ -1236,13 +1184,6 @@ function PanelGroupWithForwardedRef({
1236
1184
  }, []);
1237
1185
  const registerPanel = useCallback(panelData => {
1238
1186
  const {
1239
- autoSaveId,
1240
- id: groupId,
1241
- onLayout,
1242
- storage
1243
- } = committedValuesRef.current;
1244
- const {
1245
- layout: prevLayout,
1246
1187
  panelDataArray
1247
1188
  } = eagerValuesRef.current;
1248
1189
  panelDataArray.push(panelData);
@@ -1259,44 +1200,7 @@ function PanelGroupWithForwardedRef({
1259
1200
  return orderA - orderB;
1260
1201
  }
1261
1202
  });
1262
-
1263
- // Wait until all panels have registered before we try to compute layout;
1264
- // doing it earlier is both wasteful and may trigger misleading warnings in development mode.
1265
- const panelElements = getPanelElementsForGroup(groupId);
1266
- if (panelElements.length !== panelDataArray.length) {
1267
- return;
1268
- }
1269
-
1270
- // If this panel has been configured to persist sizing information,
1271
- // default size should be restored from local storage if possible.
1272
- let unsafeLayout = null;
1273
- if (autoSaveId) {
1274
- unsafeLayout = loadPanelLayout(autoSaveId, panelDataArray, storage);
1275
- }
1276
- if (unsafeLayout == null) {
1277
- unsafeLayout = calculateUnsafeDefaultLayout({
1278
- panelDataArray
1279
- });
1280
- }
1281
-
1282
- // Validate even saved layouts in case something has changed since last render
1283
- // e.g. for pixel groups, this could be the size of the window
1284
- const nextLayout = validatePanelGroupLayout({
1285
- layout: unsafeLayout,
1286
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1287
- });
1288
-
1289
- // Offscreen mode makes this a bit weird;
1290
- // Panels unregister when hidden and re-register when shown again,
1291
- // but the overall layout doesn't change between these two cases.
1292
- setLayout(nextLayout);
1293
- eagerValuesRef.current.layout = nextLayout;
1294
- if (!areEqual(prevLayout, nextLayout)) {
1295
- if (onLayout) {
1296
- onLayout(nextLayout);
1297
- }
1298
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1299
- }
1203
+ eagerValuesRef.current.panelDataArrayChanged = true;
1300
1204
  }, []);
1301
1205
  const registerResizeHandle = useCallback(dragHandleId => {
1302
1206
  return function resizeHandler(event) {
@@ -1386,7 +1290,7 @@ function PanelGroupWithForwardedRef({
1386
1290
  pivotIndices
1387
1291
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1388
1292
  assert(panelSize != null);
1389
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1293
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1390
1294
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1391
1295
  const nextLayout = adjustLayoutByDelta({
1392
1296
  delta,
@@ -1425,79 +1329,21 @@ function PanelGroupWithForwardedRef({
1425
1329
  resetGlobalCursorStyle();
1426
1330
  setDragState(null);
1427
1331
  }, []);
1428
- const unregisterPanelRef = useRef({
1429
- pendingPanelIds: new Set(),
1430
- timeout: null
1431
- });
1432
1332
  const unregisterPanel = useCallback(panelData => {
1433
1333
  const {
1434
- onLayout
1435
- } = committedValuesRef.current;
1436
- const {
1437
- layout: prevLayout,
1438
1334
  panelDataArray
1439
1335
  } = eagerValuesRef.current;
1440
- const index = panelDataArray.indexOf(panelData);
1336
+ const index = findPanelDataIndex(panelDataArray, panelData);
1441
1337
  if (index >= 0) {
1442
1338
  panelDataArray.splice(index, 1);
1443
- unregisterPanelRef.current.pendingPanelIds.add(panelData.id);
1444
- }
1445
- if (unregisterPanelRef.current.timeout != null) {
1446
- clearTimeout(unregisterPanelRef.current.timeout);
1447
- }
1448
-
1449
- // Batch panel unmounts so that we only calculate layout once;
1450
- // This is more efficient and avoids misleading warnings in development mode.
1451
- // We can't check the DOM to detect this because Panel elements have not yet been removed.
1452
- unregisterPanelRef.current.timeout = setTimeout(() => {
1453
- const {
1454
- pendingPanelIds
1455
- } = unregisterPanelRef.current;
1456
- const map = panelIdToLastNotifiedSizeMapRef.current;
1457
1339
 
1458
1340
  // TRICKY
1459
- // Strict effects mode
1460
- let unmountDueToStrictMode = false;
1461
- pendingPanelIds.forEach(panelId => {
1462
- pendingPanelIds.delete(panelId);
1463
- if (panelDataArray.find(({
1464
- id
1465
- }) => id === panelId) != null) {
1466
- unmountDueToStrictMode = true;
1467
-
1468
- // TRICKY
1469
- // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1470
- // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1471
- // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1472
- delete map[panelData.id];
1473
- }
1474
- });
1475
- if (!unmountDueToStrictMode) {
1476
- return;
1477
- }
1478
- if (panelDataArray.length === 0) {
1479
- // The group is unmounting; skip layout calculation.
1480
- return;
1481
- }
1482
- let unsafeLayout = calculateUnsafeDefaultLayout({
1483
- panelDataArray
1484
- });
1485
-
1486
- // Validate even saved layouts in case something has changed since last render
1487
- // e.g. for pixel groups, this could be the size of the window
1488
- const nextLayout = validatePanelGroupLayout({
1489
- layout: unsafeLayout,
1490
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1491
- });
1492
- if (!areEqual(prevLayout, nextLayout)) {
1493
- setLayout(nextLayout);
1494
- eagerValuesRef.current.layout = nextLayout;
1495
- if (onLayout) {
1496
- onLayout(nextLayout);
1497
- }
1498
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1499
- }
1500
- }, 0);
1341
+ // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1342
+ // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1343
+ // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1344
+ delete panelIdToLastNotifiedSizeMapRef.current[panelData.id];
1345
+ eagerValuesRef.current.panelDataArrayChanged = true;
1346
+ }
1501
1347
  }, []);
1502
1348
  const context = useMemo(() => ({
1503
1349
  collapsePanel,
@@ -1545,9 +1391,12 @@ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwar
1545
1391
  }));
1546
1392
  PanelGroupWithForwardedRef.displayName = "PanelGroup";
1547
1393
  PanelGroup.displayName = "forwardRef(PanelGroup)";
1394
+ function findPanelDataIndex(panelDataArray, panelData) {
1395
+ return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1396
+ }
1548
1397
  function panelDataHelper(panelDataArray, panelData, layout) {
1549
1398
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1550
- const panelIndex = panelDataArray.indexOf(panelData);
1399
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1551
1400
  const panelConstraints = panelConstraintsArray[panelIndex];
1552
1401
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1553
1402
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
@@ -643,47 +643,6 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
643
643
  }
644
644
  }
645
645
 
646
- function calculateUnsafeDefaultLayout({
647
- panelDataArray
648
- }) {
649
- const layout = Array(panelDataArray.length);
650
- const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
651
- let numPanelsWithSizes = 0;
652
- let remainingSize = 100;
653
-
654
- // Distribute default sizes first
655
- for (let index = 0; index < panelDataArray.length; index++) {
656
- const panelConstraints = panelConstraintsArray[index];
657
- assert(panelConstraints);
658
- const {
659
- defaultSize
660
- } = panelConstraints;
661
- if (defaultSize != null) {
662
- numPanelsWithSizes++;
663
- layout[index] = defaultSize;
664
- remainingSize -= defaultSize;
665
- }
666
- }
667
-
668
- // Remaining size should be distributed evenly between panels without default sizes
669
- for (let index = 0; index < panelDataArray.length; index++) {
670
- const panelConstraints = panelConstraintsArray[index];
671
- assert(panelConstraints);
672
- const {
673
- defaultSize
674
- } = panelConstraints;
675
- if (defaultSize != null) {
676
- continue;
677
- }
678
- const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
679
- const size = remainingSize / numRemainingPanels;
680
- numPanelsWithSizes++;
681
- layout[index] = size;
682
- remainingSize -= size;
683
- }
684
- return layout;
685
- }
686
-
687
646
  // Layout should be pre-converted into percentages
688
647
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
689
648
  layout.forEach((size, index) => {
@@ -817,10 +776,6 @@ function debounce(callback, durationMs = 10) {
817
776
  return callable;
818
777
  }
819
778
 
820
- function getPanelElementsForGroup(groupId) {
821
- return Array.from(document.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`));
822
- }
823
-
824
779
  // PanelGroup might be rendering in a server-side environment where localStorage is not available
825
780
  // or on a browser with cookies/storage disabled.
826
781
  // In either case, this function avoids accessing localStorage until needed,
@@ -876,15 +831,6 @@ function loadSerializedPanelGroupState(autoSaveId, storage) {
876
831
  } catch (error) {}
877
832
  return null;
878
833
  }
879
- function loadPanelLayout(autoSaveId, panels, storage) {
880
- const state = loadSerializedPanelGroupState(autoSaveId, storage);
881
- if (state) {
882
- var _state$key;
883
- const key = getSerializationKey(panels);
884
- return (_state$key = state[key]) !== null && _state$key !== void 0 ? _state$key : null;
885
- }
886
- return null;
887
- }
888
834
  function savePanelGroupLayout(autoSaveId, panels, sizes, storage) {
889
835
  const key = getSerializationKey(panels);
890
836
  const state = loadSerializedPanelGroupState(autoSaveId, storage) || {};
@@ -987,6 +933,7 @@ function PanelGroupWithForwardedRef({
987
933
  const groupId = useUniqueId(idFromProps);
988
934
  const [dragState, setDragState] = useState(null);
989
935
  const [layout, setLayout] = useState([]);
936
+ useState([]);
990
937
  const panelIdToLastNotifiedSizeMapRef = useRef({});
991
938
  const panelSizeBeforeCollapseRef = useRef(new Map());
992
939
  const prevDeltaRef = useRef(0);
@@ -1001,7 +948,8 @@ function PanelGroupWithForwardedRef({
1001
948
  });
1002
949
  const eagerValuesRef = useRef({
1003
950
  layout,
1004
- panelDataArray: []
951
+ panelDataArray: [],
952
+ panelDataArrayChanged: false
1005
953
  });
1006
954
  useRef({
1007
955
  didLogIdAndOrderWarning: false,
@@ -1092,7 +1040,7 @@ function PanelGroupWithForwardedRef({
1092
1040
  // Store size before collapse;
1093
1041
  // This is the size that gets restored if the expand() API is used.
1094
1042
  panelSizeBeforeCollapseRef.current.set(panelData.id, panelSize);
1095
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1043
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1096
1044
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1097
1045
  const nextLayout = adjustLayoutByDelta({
1098
1046
  delta,
@@ -1134,7 +1082,7 @@ function PanelGroupWithForwardedRef({
1134
1082
  // Restore this panel to the size it was before it was collapsed, if possible.
1135
1083
  const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
1136
1084
  const baseSize = prevPanelSize != null && prevPanelSize >= minSize ? prevPanelSize : minSize;
1137
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1085
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1138
1086
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1139
1087
  const nextLayout = adjustLayoutByDelta({
1140
1088
  delta,
@@ -1173,7 +1121,7 @@ function PanelGroupWithForwardedRef({
1173
1121
  const {
1174
1122
  panelDataArray
1175
1123
  } = eagerValuesRef.current;
1176
- const panelIndex = panelDataArray.indexOf(panelData);
1124
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1177
1125
  return computePanelFlexBoxStyle({
1178
1126
  dragState,
1179
1127
  layout,
@@ -1212,13 +1160,6 @@ function PanelGroupWithForwardedRef({
1212
1160
  }, []);
1213
1161
  const registerPanel = useCallback(panelData => {
1214
1162
  const {
1215
- autoSaveId,
1216
- id: groupId,
1217
- onLayout,
1218
- storage
1219
- } = committedValuesRef.current;
1220
- const {
1221
- layout: prevLayout,
1222
1163
  panelDataArray
1223
1164
  } = eagerValuesRef.current;
1224
1165
  panelDataArray.push(panelData);
@@ -1235,44 +1176,7 @@ function PanelGroupWithForwardedRef({
1235
1176
  return orderA - orderB;
1236
1177
  }
1237
1178
  });
1238
-
1239
- // Wait until all panels have registered before we try to compute layout;
1240
- // doing it earlier is both wasteful and may trigger misleading warnings in development mode.
1241
- const panelElements = getPanelElementsForGroup(groupId);
1242
- if (panelElements.length !== panelDataArray.length) {
1243
- return;
1244
- }
1245
-
1246
- // If this panel has been configured to persist sizing information,
1247
- // default size should be restored from local storage if possible.
1248
- let unsafeLayout = null;
1249
- if (autoSaveId) {
1250
- unsafeLayout = loadPanelLayout(autoSaveId, panelDataArray, storage);
1251
- }
1252
- if (unsafeLayout == null) {
1253
- unsafeLayout = calculateUnsafeDefaultLayout({
1254
- panelDataArray
1255
- });
1256
- }
1257
-
1258
- // Validate even saved layouts in case something has changed since last render
1259
- // e.g. for pixel groups, this could be the size of the window
1260
- const nextLayout = validatePanelGroupLayout({
1261
- layout: unsafeLayout,
1262
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1263
- });
1264
-
1265
- // Offscreen mode makes this a bit weird;
1266
- // Panels unregister when hidden and re-register when shown again,
1267
- // but the overall layout doesn't change between these two cases.
1268
- setLayout(nextLayout);
1269
- eagerValuesRef.current.layout = nextLayout;
1270
- if (!areEqual(prevLayout, nextLayout)) {
1271
- if (onLayout) {
1272
- onLayout(nextLayout);
1273
- }
1274
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1275
- }
1179
+ eagerValuesRef.current.panelDataArrayChanged = true;
1276
1180
  }, []);
1277
1181
  const registerResizeHandle = useCallback(dragHandleId => {
1278
1182
  return function resizeHandler(event) {
@@ -1362,7 +1266,7 @@ function PanelGroupWithForwardedRef({
1362
1266
  pivotIndices
1363
1267
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1364
1268
  assert(panelSize != null);
1365
- const isLastPanel = panelDataArray.indexOf(panelData) === panelDataArray.length - 1;
1269
+ const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1366
1270
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1367
1271
  const nextLayout = adjustLayoutByDelta({
1368
1272
  delta,
@@ -1401,79 +1305,21 @@ function PanelGroupWithForwardedRef({
1401
1305
  resetGlobalCursorStyle();
1402
1306
  setDragState(null);
1403
1307
  }, []);
1404
- const unregisterPanelRef = useRef({
1405
- pendingPanelIds: new Set(),
1406
- timeout: null
1407
- });
1408
1308
  const unregisterPanel = useCallback(panelData => {
1409
1309
  const {
1410
- onLayout
1411
- } = committedValuesRef.current;
1412
- const {
1413
- layout: prevLayout,
1414
1310
  panelDataArray
1415
1311
  } = eagerValuesRef.current;
1416
- const index = panelDataArray.indexOf(panelData);
1312
+ const index = findPanelDataIndex(panelDataArray, panelData);
1417
1313
  if (index >= 0) {
1418
1314
  panelDataArray.splice(index, 1);
1419
- unregisterPanelRef.current.pendingPanelIds.add(panelData.id);
1420
- }
1421
- if (unregisterPanelRef.current.timeout != null) {
1422
- clearTimeout(unregisterPanelRef.current.timeout);
1423
- }
1424
-
1425
- // Batch panel unmounts so that we only calculate layout once;
1426
- // This is more efficient and avoids misleading warnings in development mode.
1427
- // We can't check the DOM to detect this because Panel elements have not yet been removed.
1428
- unregisterPanelRef.current.timeout = setTimeout(() => {
1429
- const {
1430
- pendingPanelIds
1431
- } = unregisterPanelRef.current;
1432
- const map = panelIdToLastNotifiedSizeMapRef.current;
1433
1315
 
1434
1316
  // TRICKY
1435
- // Strict effects mode
1436
- let unmountDueToStrictMode = false;
1437
- pendingPanelIds.forEach(panelId => {
1438
- pendingPanelIds.delete(panelId);
1439
- if (panelDataArray.find(({
1440
- id
1441
- }) => id === panelId) != null) {
1442
- unmountDueToStrictMode = true;
1443
-
1444
- // TRICKY
1445
- // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1446
- // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1447
- // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1448
- delete map[panelData.id];
1449
- }
1450
- });
1451
- if (!unmountDueToStrictMode) {
1452
- return;
1453
- }
1454
- if (panelDataArray.length === 0) {
1455
- // The group is unmounting; skip layout calculation.
1456
- return;
1457
- }
1458
- let unsafeLayout = calculateUnsafeDefaultLayout({
1459
- panelDataArray
1460
- });
1461
-
1462
- // Validate even saved layouts in case something has changed since last render
1463
- // e.g. for pixel groups, this could be the size of the window
1464
- const nextLayout = validatePanelGroupLayout({
1465
- layout: unsafeLayout,
1466
- panelConstraints: panelDataArray.map(panelData => panelData.constraints)
1467
- });
1468
- if (!areEqual(prevLayout, nextLayout)) {
1469
- setLayout(nextLayout);
1470
- eagerValuesRef.current.layout = nextLayout;
1471
- if (onLayout) {
1472
- onLayout(nextLayout);
1473
- }
1474
- callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1475
- }
1476
- }, 0);
1317
+ // When a panel is removed from the group, we should delete the most recent prev-size entry for it.
1318
+ // If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
1319
+ // Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
1320
+ delete panelIdToLastNotifiedSizeMapRef.current[panelData.id];
1321
+ eagerValuesRef.current.panelDataArrayChanged = true;
1322
+ }
1477
1323
  }, []);
1478
1324
  const context = useMemo(() => ({
1479
1325
  collapsePanel,
@@ -1521,9 +1367,12 @@ const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwar
1521
1367
  }));
1522
1368
  PanelGroupWithForwardedRef.displayName = "PanelGroup";
1523
1369
  PanelGroup.displayName = "forwardRef(PanelGroup)";
1370
+ function findPanelDataIndex(panelDataArray, panelData) {
1371
+ return panelDataArray.findIndex(prevPanelData => prevPanelData === panelData || prevPanelData.id === panelData.id);
1372
+ }
1524
1373
  function panelDataHelper(panelDataArray, panelData, layout) {
1525
1374
  const panelConstraintsArray = panelDataArray.map(panelData => panelData.constraints);
1526
- const panelIndex = panelDataArray.indexOf(panelData);
1375
+ const panelIndex = findPanelDataIndex(panelDataArray, panelData);
1527
1376
  const panelConstraints = panelConstraintsArray[panelIndex];
1528
1377
  const isLastPanel = panelIndex === panelDataArray.length - 1;
1529
1378
  const pivotIndices = isLastPanel ? [panelIndex - 1, panelIndex] : [panelIndex, panelIndex + 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.4",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",