react-resizable-panels 2.0.9 → 2.0.10

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/declarations/src/utils/assert.d.ts +1 -1
  3. package/dist/react-resizable-panels.browser.cjs.js +50 -52
  4. package/dist/react-resizable-panels.browser.development.cjs.js +52 -54
  5. package/dist/react-resizable-panels.browser.development.esm.js +52 -54
  6. package/dist/react-resizable-panels.browser.esm.js +50 -52
  7. package/dist/react-resizable-panels.cjs.js +50 -52
  8. package/dist/react-resizable-panels.development.cjs.js +52 -54
  9. package/dist/react-resizable-panels.development.esm.js +52 -54
  10. package/dist/react-resizable-panels.development.node.cjs.js +48 -50
  11. package/dist/react-resizable-panels.development.node.esm.js +48 -50
  12. package/dist/react-resizable-panels.esm.js +50 -52
  13. package/dist/react-resizable-panels.node.cjs.js +46 -48
  14. package/dist/react-resizable-panels.node.esm.js +46 -48
  15. package/package.json +1 -1
  16. package/src/Panel.test.tsx +23 -23
  17. package/src/PanelGroup.test.tsx +32 -3
  18. package/src/PanelGroup.ts +25 -7
  19. package/src/PanelResizeHandle.test.tsx +3 -3
  20. package/src/PanelResizeHandle.ts +1 -1
  21. package/src/hooks/useWindowSplitterBehavior.ts +5 -2
  22. package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +5 -5
  23. package/src/utils/adjustLayoutByDelta.ts +47 -20
  24. package/src/utils/assert.ts +1 -1
  25. package/src/utils/calculateAriaValues.ts +1 -1
  26. package/src/utils/calculateDragOffsetPercentage.ts +6 -3
  27. package/src/utils/calculateUnsafeDefaultLayout.ts +2 -2
  28. package/src/utils/callPanelCallbacks.ts +1 -1
  29. package/src/utils/resizePanel.ts +4 -1
  30. package/src/utils/test-utils.ts +1 -1
  31. package/src/utils/validatePanelConstraints.ts +4 -1
  32. package/src/utils/validatePanelGroupLayout.ts +3 -3
  33. package/src/vendor/stacking-order.ts +5 -2
@@ -307,7 +307,7 @@ function compare(a, b) {
307
307
  b = ancestors.b.pop();
308
308
  common_ancestor = a;
309
309
  }
310
- assert(common_ancestor);
310
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
311
311
  const z_indexes = {
312
312
  a: get_z_index(find_stacking_context(ancestors.a)),
313
313
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -365,7 +365,7 @@ function find_stacking_context(nodes) {
365
365
  let i = nodes.length;
366
366
  while (i--) {
367
367
  const node = nodes[i];
368
- assert(node);
368
+ assert(node, "Missing node");
369
369
  if (creates_stacking_context(node)) return node;
370
370
  }
371
371
  return null;
@@ -652,7 +652,7 @@ function updateResizeHandlerStates(action, event) {
652
652
  });
653
653
  }
654
654
 
655
- function assert(expectedCondition, message = "Assertion failed!") {
655
+ function assert(expectedCondition, message) {
656
656
  if (!expectedCondition) {
657
657
  console.error(message);
658
658
  throw Error(message);
@@ -683,7 +683,7 @@ function resizePanel({
683
683
  size
684
684
  }) {
685
685
  const panelConstraints = panelConstraintsArray[panelIndex];
686
- assert(panelConstraints != null);
686
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
687
687
  let {
688
688
  collapsedSize = 0,
689
689
  collapsible,
@@ -721,8 +721,8 @@ function adjustLayoutByDelta({
721
721
  }
722
722
  const nextLayout = [...prevLayout];
723
723
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
724
- assert(firstPivotIndex != null);
725
- assert(secondPivotIndex != null);
724
+ assert(firstPivotIndex != null, "Invalid first pivot index");
725
+ assert(secondPivotIndex != null, "Invalid second pivot index");
726
726
  let deltaApplied = 0;
727
727
 
728
728
  //const DEBUG = [];
@@ -748,19 +748,18 @@ function adjustLayoutByDelta({
748
748
  // Check if we should expand a collapsed panel
749
749
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
750
750
  const panelConstraints = panelConstraintsArray[index];
751
- assert(panelConstraints);
751
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
752
+ const {
753
+ collapsedSize = 0,
754
+ collapsible,
755
+ minSize = 0
756
+ } = panelConstraints;
752
757
 
753
758
  //DEBUG.push(`edge case check 1: ${index}`);
754
759
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
755
- if (panelConstraints.collapsible) {
760
+ if (collapsible) {
756
761
  const prevSize = prevLayout[index];
757
- assert(prevSize != null);
758
- const panelConstraints = panelConstraintsArray[index];
759
- assert(panelConstraints);
760
- const {
761
- collapsedSize = 0,
762
- minSize = 0
763
- } = panelConstraints;
762
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
764
763
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
765
764
  const localDelta = minSize - prevSize;
766
765
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -777,22 +776,18 @@ function adjustLayoutByDelta({
777
776
  // Check if we should collapse a panel at its minimum size
778
777
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
779
778
  const panelConstraints = panelConstraintsArray[index];
780
- assert(panelConstraints);
779
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
781
780
  const {
782
- collapsible
781
+ collapsedSize = 0,
782
+ collapsible,
783
+ minSize = 0
783
784
  } = panelConstraints;
784
785
 
785
786
  //DEBUG.push(`edge case check 2: ${index}`);
786
787
  //DEBUG.push(` -> collapsible? ${collapsible}`);
787
788
  if (collapsible) {
788
789
  const prevSize = prevLayout[index];
789
- assert(prevSize != null);
790
- const panelConstraints = panelConstraintsArray[index];
791
- assert(panelConstraints);
792
- const {
793
- collapsedSize = 0,
794
- minSize = 0
795
- } = panelConstraints;
790
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
796
791
  if (fuzzyNumbersEqual(prevSize, minSize)) {
797
792
  const localDelta = prevSize - collapsedSize;
798
793
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -822,7 +817,7 @@ function adjustLayoutByDelta({
822
817
  //DEBUG.push("pre calc...");
823
818
  while (true) {
824
819
  const prevSize = prevLayout[index];
825
- assert(prevSize != null);
820
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
826
821
  const maxSafeSize = resizePanel({
827
822
  panelConstraints: panelConstraintsArray,
828
823
  panelIndex: index,
@@ -853,7 +848,7 @@ function adjustLayoutByDelta({
853
848
  while (index >= 0 && index < panelConstraintsArray.length) {
854
849
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
855
850
  const prevSize = prevLayout[index];
856
- assert(prevSize != null);
851
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
857
852
  const unsafeSize = prevSize - deltaRemaining;
858
853
  const safeSize = resizePanel({
859
854
  panelConstraints: panelConstraintsArray,
@@ -890,7 +885,7 @@ function adjustLayoutByDelta({
890
885
  // Now distribute the applied delta to the panels in the other direction
891
886
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
892
887
  const prevSize = prevLayout[pivotIndex];
893
- assert(prevSize != null);
888
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
894
889
  const unsafeSize = prevSize + deltaApplied;
895
890
  const safeSize = resizePanel({
896
891
  panelConstraints: panelConstraintsArray,
@@ -908,7 +903,7 @@ function adjustLayoutByDelta({
908
903
  let index = pivotIndex;
909
904
  while (index >= 0 && index < panelConstraintsArray.length) {
910
905
  const prevSize = nextLayout[index];
911
- assert(prevSize != null);
906
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
912
907
  const unsafeSize = prevSize + deltaRemaining;
913
908
  const safeSize = resizePanel({
914
909
  panelConstraints: panelConstraintsArray,
@@ -954,7 +949,7 @@ function calculateAriaValues({
954
949
  let totalMinSize = 0;
955
950
  let totalMaxSize = 0;
956
951
  const firstIndex = pivotIndices[0];
957
- assert(firstIndex != null);
952
+ assert(firstIndex != null, "No pivot index found");
958
953
 
959
954
  // A panel's effective min/max sizes also need to account for other panel's sizes.
960
955
  panelsArray.forEach((panelData, index) => {
@@ -1073,7 +1068,7 @@ function useWindowSplitterPanelGroupBehavior({
1073
1068
  }
1074
1069
  } else {
1075
1070
  const panelData = panelDataArray[index];
1076
- assert(panelData);
1071
+ assert(panelData, `No panel data found for index "${index}"`);
1077
1072
  resizeHandleElement.setAttribute("aria-controls", panelData.id);
1078
1073
  resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
1079
1074
  resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
@@ -1094,17 +1089,17 @@ function useWindowSplitterPanelGroupBehavior({
1094
1089
  return;
1095
1090
  }
1096
1091
  const eagerValues = eagerValuesRef.current;
1097
- assert(eagerValues);
1092
+ assert(eagerValues, `Eager values not found`);
1098
1093
  const {
1099
1094
  panelDataArray
1100
1095
  } = eagerValues;
1101
1096
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1102
1097
  assert(groupElement != null, `No group found for id "${groupId}"`);
1103
1098
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1104
- assert(handles);
1099
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1105
1100
  const cleanupFunctions = handles.map(handle => {
1106
1101
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1107
- assert(handleId);
1102
+ assert(handleId, `Resize handle element has no handle id attribute`);
1108
1103
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1109
1104
  if (idBefore == null || idAfter == null) {
1110
1105
  return () => {};
@@ -1120,7 +1115,7 @@ function useWindowSplitterPanelGroupBehavior({
1120
1115
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1121
1116
  if (index >= 0) {
1122
1117
  const panelData = panelDataArray[index];
1123
- assert(panelData);
1118
+ assert(panelData, `No panel data found for index ${index}`);
1124
1119
  const size = layout[index];
1125
1120
  const {
1126
1121
  collapsedSize = 0,
@@ -1179,15 +1174,15 @@ function getResizeEventCursorPosition(direction, event) {
1179
1174
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1180
1175
  const isHorizontal = direction === "horizontal";
1181
1176
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1182
- assert(handleElement);
1177
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1183
1178
  const groupId = handleElement.getAttribute("data-panel-group-id");
1184
- assert(groupId);
1179
+ assert(groupId, `Resize handle element has no group id attribute`);
1185
1180
  let {
1186
1181
  initialCursorPosition
1187
1182
  } = initialDragState;
1188
1183
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1189
1184
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1190
- assert(groupElement);
1185
+ assert(groupElement, `No group element found for id "${groupId}"`);
1191
1186
  const groupRect = groupElement.getBoundingClientRect();
1192
1187
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1193
1188
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1248,7 +1243,7 @@ function calculateUnsafeDefaultLayout({
1248
1243
  // Distribute default sizes first
1249
1244
  for (let index = 0; index < panelDataArray.length; index++) {
1250
1245
  const panelConstraints = panelConstraintsArray[index];
1251
- assert(panelConstraints);
1246
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1252
1247
  const {
1253
1248
  defaultSize
1254
1249
  } = panelConstraints;
@@ -1262,7 +1257,7 @@ function calculateUnsafeDefaultLayout({
1262
1257
  // Remaining size should be distributed evenly between panels without default sizes
1263
1258
  for (let index = 0; index < panelDataArray.length; index++) {
1264
1259
  const panelConstraints = panelConstraintsArray[index];
1265
- assert(panelConstraints);
1260
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1266
1261
  const {
1267
1262
  defaultSize
1268
1263
  } = panelConstraints;
@@ -1282,7 +1277,7 @@ function calculateUnsafeDefaultLayout({
1282
1277
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1283
1278
  layout.forEach((size, index) => {
1284
1279
  const panelData = panelsArray[index];
1285
- assert(panelData);
1280
+ assert(panelData, `Panel data not found for index ${index}`);
1286
1281
  const {
1287
1282
  callbacks,
1288
1283
  constraints,
@@ -1466,7 +1461,7 @@ function validatePanelConstraints({
1466
1461
  {
1467
1462
  const warnings = [];
1468
1463
  const panelConstraints = panelConstraintsArray[panelIndex];
1469
- assert(panelConstraints);
1464
+ assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
1470
1465
  const {
1471
1466
  collapsedSize = 0,
1472
1467
  collapsible = false,
@@ -1520,7 +1515,7 @@ function validatePanelGroupLayout({
1520
1515
  }
1521
1516
  for (let index = 0; index < panelConstraints.length; index++) {
1522
1517
  const unsafeSize = nextLayout[index];
1523
- assert(unsafeSize != null);
1518
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1524
1519
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1525
1520
  nextLayout[index] = safeSize;
1526
1521
  }
@@ -1530,7 +1525,7 @@ function validatePanelGroupLayout({
1530
1525
  // First pass: Validate the proposed layout given each panel's constraints
1531
1526
  for (let index = 0; index < panelConstraints.length; index++) {
1532
1527
  const unsafeSize = nextLayout[index];
1533
- assert(unsafeSize != null);
1528
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1534
1529
  const safeSize = resizePanel({
1535
1530
  panelConstraints,
1536
1531
  panelIndex: index,
@@ -1547,7 +1542,7 @@ function validatePanelGroupLayout({
1547
1542
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1548
1543
  for (let index = 0; index < panelConstraints.length; index++) {
1549
1544
  const prevSize = nextLayout[index];
1550
- assert(prevSize != null);
1545
+ assert(prevSize != null, `No layout data found for index ${index}`);
1551
1546
  const unsafeSize = prevSize + remainingSize;
1552
1547
  const safeSize = resizePanel({
1553
1548
  panelConstraints,
@@ -1724,7 +1719,7 @@ function PanelGroupWithForwardedRef({
1724
1719
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1725
1720
  for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
1726
1721
  const panelData = panelDataArray[panelIndex];
1727
- assert(panelData);
1722
+ assert(panelData, `Panel data not found for index ${panelIndex}`);
1728
1723
  const isValid = validatePanelConstraints({
1729
1724
  panelConstraints,
1730
1725
  panelId: panelData.id,
@@ -1755,7 +1750,7 @@ function PanelGroupWithForwardedRef({
1755
1750
  panelSize,
1756
1751
  pivotIndices
1757
1752
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1758
- assert(panelSize != null);
1753
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1759
1754
  if (panelSize !== collapsedSize) {
1760
1755
  // Store size before collapse;
1761
1756
  // This is the size that gets restored if the expand() API is used.
@@ -1832,7 +1827,7 @@ function PanelGroupWithForwardedRef({
1832
1827
  const {
1833
1828
  panelSize
1834
1829
  } = panelDataHelper(panelDataArray, panelData, layout);
1835
- assert(panelSize != null);
1830
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1836
1831
  return panelSize;
1837
1832
  }, []);
1838
1833
 
@@ -1876,7 +1871,7 @@ function PanelGroupWithForwardedRef({
1876
1871
  collapsible,
1877
1872
  panelSize
1878
1873
  } = panelDataHelper(panelDataArray, panelData, layout);
1879
- assert(panelSize != null);
1874
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1880
1875
  return !collapsible || panelSize > collapsedSize;
1881
1876
  }, []);
1882
1877
  const registerPanel = useCallback(panelData => {
@@ -2043,7 +2038,7 @@ function PanelGroupWithForwardedRef({
2043
2038
  panelSize,
2044
2039
  pivotIndices
2045
2040
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
2046
- assert(panelSize != null);
2041
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
2047
2042
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
2048
2043
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
2049
2044
  const nextLayout = adjustLayoutByDelta({
@@ -2080,7 +2075,10 @@ function PanelGroupWithForwardedRef({
2080
2075
  const {
2081
2076
  panelSize: prevPanelSize
2082
2077
  } = panelDataHelper(panelDataArray, panelData, layout);
2083
- assert(prevPanelSize != null);
2078
+ if (prevPanelSize == null) {
2079
+ // It's possible that the panels in this group have changed since the last render
2080
+ return;
2081
+ }
2084
2082
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
2085
2083
  if (prevCollapsedSize !== nextCollapsedSize) {
2086
2084
  resizePanel(panelData, nextCollapsedSize);
@@ -2102,7 +2100,7 @@ function PanelGroupWithForwardedRef({
2102
2100
  return;
2103
2101
  }
2104
2102
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
2105
- assert(handleElement);
2103
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
2106
2104
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
2107
2105
  setDragState({
2108
2106
  dragHandleId,
@@ -2231,10 +2229,10 @@ function useWindowSplitterResizeHandlerBehavior({
2231
2229
  {
2232
2230
  event.preventDefault();
2233
2231
  const groupId = handleElement.getAttribute("data-panel-group-id");
2234
- assert(groupId);
2232
+ assert(groupId, `No group element found for id "${groupId}"`);
2235
2233
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2236
2234
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2237
- assert(index !== null);
2235
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2238
2236
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2239
2237
  const nextHandle = handles[nextIndex];
2240
2238
  nextHandle.focus();
@@ -2306,7 +2304,7 @@ function PanelResizeHandle({
2306
2304
  return;
2307
2305
  }
2308
2306
  const element = elementRef.current;
2309
- assert(element);
2307
+ assert(element, "Element ref not attached");
2310
2308
  const setResizeHandlerState = (action, isActive, event) => {
2311
2309
  if (isActive) {
2312
2310
  switch (action) {
@@ -301,7 +301,7 @@ function compare(a, b) {
301
301
  b = ancestors.b.pop();
302
302
  common_ancestor = a;
303
303
  }
304
- assert(common_ancestor);
304
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
305
305
  const z_indexes = {
306
306
  a: get_z_index(find_stacking_context(ancestors.a)),
307
307
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -359,7 +359,7 @@ function find_stacking_context(nodes) {
359
359
  let i = nodes.length;
360
360
  while (i--) {
361
361
  const node = nodes[i];
362
- assert(node);
362
+ assert(node, "Missing node");
363
363
  if (creates_stacking_context(node)) return node;
364
364
  }
365
365
  return null;
@@ -646,7 +646,7 @@ function updateResizeHandlerStates(action, event) {
646
646
  });
647
647
  }
648
648
 
649
- function assert(expectedCondition, message = "Assertion failed!") {
649
+ function assert(expectedCondition, message) {
650
650
  if (!expectedCondition) {
651
651
  console.error(message);
652
652
  throw Error(message);
@@ -677,7 +677,7 @@ function resizePanel({
677
677
  size
678
678
  }) {
679
679
  const panelConstraints = panelConstraintsArray[panelIndex];
680
- assert(panelConstraints != null);
680
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
681
681
  let {
682
682
  collapsedSize = 0,
683
683
  collapsible,
@@ -715,8 +715,8 @@ function adjustLayoutByDelta({
715
715
  }
716
716
  const nextLayout = [...prevLayout];
717
717
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
718
- assert(firstPivotIndex != null);
719
- assert(secondPivotIndex != null);
718
+ assert(firstPivotIndex != null, "Invalid first pivot index");
719
+ assert(secondPivotIndex != null, "Invalid second pivot index");
720
720
  let deltaApplied = 0;
721
721
 
722
722
  //const DEBUG = [];
@@ -742,19 +742,18 @@ function adjustLayoutByDelta({
742
742
  // Check if we should expand a collapsed panel
743
743
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
744
744
  const panelConstraints = panelConstraintsArray[index];
745
- assert(panelConstraints);
745
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
746
+ const {
747
+ collapsedSize = 0,
748
+ collapsible,
749
+ minSize = 0
750
+ } = panelConstraints;
746
751
 
747
752
  //DEBUG.push(`edge case check 1: ${index}`);
748
753
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
749
- if (panelConstraints.collapsible) {
754
+ if (collapsible) {
750
755
  const prevSize = prevLayout[index];
751
- assert(prevSize != null);
752
- const panelConstraints = panelConstraintsArray[index];
753
- assert(panelConstraints);
754
- const {
755
- collapsedSize = 0,
756
- minSize = 0
757
- } = panelConstraints;
756
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
758
757
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
759
758
  const localDelta = minSize - prevSize;
760
759
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -771,22 +770,18 @@ function adjustLayoutByDelta({
771
770
  // Check if we should collapse a panel at its minimum size
772
771
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
773
772
  const panelConstraints = panelConstraintsArray[index];
774
- assert(panelConstraints);
773
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
775
774
  const {
776
- collapsible
775
+ collapsedSize = 0,
776
+ collapsible,
777
+ minSize = 0
777
778
  } = panelConstraints;
778
779
 
779
780
  //DEBUG.push(`edge case check 2: ${index}`);
780
781
  //DEBUG.push(` -> collapsible? ${collapsible}`);
781
782
  if (collapsible) {
782
783
  const prevSize = prevLayout[index];
783
- assert(prevSize != null);
784
- const panelConstraints = panelConstraintsArray[index];
785
- assert(panelConstraints);
786
- const {
787
- collapsedSize = 0,
788
- minSize = 0
789
- } = panelConstraints;
784
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
790
785
  if (fuzzyNumbersEqual(prevSize, minSize)) {
791
786
  const localDelta = prevSize - collapsedSize;
792
787
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -816,7 +811,7 @@ function adjustLayoutByDelta({
816
811
  //DEBUG.push("pre calc...");
817
812
  while (true) {
818
813
  const prevSize = prevLayout[index];
819
- assert(prevSize != null);
814
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
820
815
  const maxSafeSize = resizePanel({
821
816
  panelConstraints: panelConstraintsArray,
822
817
  panelIndex: index,
@@ -847,7 +842,7 @@ function adjustLayoutByDelta({
847
842
  while (index >= 0 && index < panelConstraintsArray.length) {
848
843
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
849
844
  const prevSize = prevLayout[index];
850
- assert(prevSize != null);
845
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
851
846
  const unsafeSize = prevSize - deltaRemaining;
852
847
  const safeSize = resizePanel({
853
848
  panelConstraints: panelConstraintsArray,
@@ -884,7 +879,7 @@ function adjustLayoutByDelta({
884
879
  // Now distribute the applied delta to the panels in the other direction
885
880
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
886
881
  const prevSize = prevLayout[pivotIndex];
887
- assert(prevSize != null);
882
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
888
883
  const unsafeSize = prevSize + deltaApplied;
889
884
  const safeSize = resizePanel({
890
885
  panelConstraints: panelConstraintsArray,
@@ -902,7 +897,7 @@ function adjustLayoutByDelta({
902
897
  let index = pivotIndex;
903
898
  while (index >= 0 && index < panelConstraintsArray.length) {
904
899
  const prevSize = nextLayout[index];
905
- assert(prevSize != null);
900
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
906
901
  const unsafeSize = prevSize + deltaRemaining;
907
902
  const safeSize = resizePanel({
908
903
  panelConstraints: panelConstraintsArray,
@@ -948,7 +943,7 @@ function calculateAriaValues({
948
943
  let totalMinSize = 0;
949
944
  let totalMaxSize = 0;
950
945
  const firstIndex = pivotIndices[0];
951
- assert(firstIndex != null);
946
+ assert(firstIndex != null, "No pivot index found");
952
947
 
953
948
  // A panel's effective min/max sizes also need to account for other panel's sizes.
954
949
  panelsArray.forEach((panelData, index) => {
@@ -1057,7 +1052,7 @@ function useWindowSplitterPanelGroupBehavior({
1057
1052
  const resizeHandleElement = resizeHandleElements[index];
1058
1053
  if (resizeHandleElement == null) ; else {
1059
1054
  const panelData = panelDataArray[index];
1060
- assert(panelData);
1055
+ assert(panelData, `No panel data found for index "${index}"`);
1061
1056
  resizeHandleElement.setAttribute("aria-controls", panelData.id);
1062
1057
  resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
1063
1058
  resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
@@ -1078,17 +1073,17 @@ function useWindowSplitterPanelGroupBehavior({
1078
1073
  return;
1079
1074
  }
1080
1075
  const eagerValues = eagerValuesRef.current;
1081
- assert(eagerValues);
1076
+ assert(eagerValues, `Eager values not found`);
1082
1077
  const {
1083
1078
  panelDataArray
1084
1079
  } = eagerValues;
1085
1080
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1086
1081
  assert(groupElement != null, `No group found for id "${groupId}"`);
1087
1082
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1088
- assert(handles);
1083
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1089
1084
  const cleanupFunctions = handles.map(handle => {
1090
1085
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1091
- assert(handleId);
1086
+ assert(handleId, `Resize handle element has no handle id attribute`);
1092
1087
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1093
1088
  if (idBefore == null || idAfter == null) {
1094
1089
  return () => {};
@@ -1104,7 +1099,7 @@ function useWindowSplitterPanelGroupBehavior({
1104
1099
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1105
1100
  if (index >= 0) {
1106
1101
  const panelData = panelDataArray[index];
1107
- assert(panelData);
1102
+ assert(panelData, `No panel data found for index ${index}`);
1108
1103
  const size = layout[index];
1109
1104
  const {
1110
1105
  collapsedSize = 0,
@@ -1163,15 +1158,15 @@ function getResizeEventCursorPosition(direction, event) {
1163
1158
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1164
1159
  const isHorizontal = direction === "horizontal";
1165
1160
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1166
- assert(handleElement);
1161
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1167
1162
  const groupId = handleElement.getAttribute("data-panel-group-id");
1168
- assert(groupId);
1163
+ assert(groupId, `Resize handle element has no group id attribute`);
1169
1164
  let {
1170
1165
  initialCursorPosition
1171
1166
  } = initialDragState;
1172
1167
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1173
1168
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1174
- assert(groupElement);
1169
+ assert(groupElement, `No group element found for id "${groupId}"`);
1175
1170
  const groupRect = groupElement.getBoundingClientRect();
1176
1171
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1177
1172
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1232,7 +1227,7 @@ function calculateUnsafeDefaultLayout({
1232
1227
  // Distribute default sizes first
1233
1228
  for (let index = 0; index < panelDataArray.length; index++) {
1234
1229
  const panelConstraints = panelConstraintsArray[index];
1235
- assert(panelConstraints);
1230
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1236
1231
  const {
1237
1232
  defaultSize
1238
1233
  } = panelConstraints;
@@ -1246,7 +1241,7 @@ function calculateUnsafeDefaultLayout({
1246
1241
  // Remaining size should be distributed evenly between panels without default sizes
1247
1242
  for (let index = 0; index < panelDataArray.length; index++) {
1248
1243
  const panelConstraints = panelConstraintsArray[index];
1249
- assert(panelConstraints);
1244
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1250
1245
  const {
1251
1246
  defaultSize
1252
1247
  } = panelConstraints;
@@ -1266,7 +1261,7 @@ function calculateUnsafeDefaultLayout({
1266
1261
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1267
1262
  layout.forEach((size, index) => {
1268
1263
  const panelData = panelsArray[index];
1269
- assert(panelData);
1264
+ assert(panelData, `Panel data not found for index ${index}`);
1270
1265
  const {
1271
1266
  callbacks,
1272
1267
  constraints,
@@ -1456,7 +1451,7 @@ function validatePanelGroupLayout({
1456
1451
  } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
1457
1452
  for (let index = 0; index < panelConstraints.length; index++) {
1458
1453
  const unsafeSize = nextLayout[index];
1459
- assert(unsafeSize != null);
1454
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1460
1455
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1461
1456
  nextLayout[index] = safeSize;
1462
1457
  }
@@ -1466,7 +1461,7 @@ function validatePanelGroupLayout({
1466
1461
  // First pass: Validate the proposed layout given each panel's constraints
1467
1462
  for (let index = 0; index < panelConstraints.length; index++) {
1468
1463
  const unsafeSize = nextLayout[index];
1469
- assert(unsafeSize != null);
1464
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1470
1465
  const safeSize = resizePanel({
1471
1466
  panelConstraints,
1472
1467
  panelIndex: index,
@@ -1483,7 +1478,7 @@ function validatePanelGroupLayout({
1483
1478
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1484
1479
  for (let index = 0; index < panelConstraints.length; index++) {
1485
1480
  const prevSize = nextLayout[index];
1486
- assert(prevSize != null);
1481
+ assert(prevSize != null, `No layout data found for index ${index}`);
1487
1482
  const unsafeSize = prevSize + remainingSize;
1488
1483
  const safeSize = resizePanel({
1489
1484
  panelConstraints,
@@ -1649,7 +1644,7 @@ function PanelGroupWithForwardedRef({
1649
1644
  panelSize,
1650
1645
  pivotIndices
1651
1646
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1652
- assert(panelSize != null);
1647
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1653
1648
  if (panelSize !== collapsedSize) {
1654
1649
  // Store size before collapse;
1655
1650
  // This is the size that gets restored if the expand() API is used.
@@ -1726,7 +1721,7 @@ function PanelGroupWithForwardedRef({
1726
1721
  const {
1727
1722
  panelSize
1728
1723
  } = panelDataHelper(panelDataArray, panelData, layout);
1729
- assert(panelSize != null);
1724
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1730
1725
  return panelSize;
1731
1726
  }, []);
1732
1727
 
@@ -1770,7 +1765,7 @@ function PanelGroupWithForwardedRef({
1770
1765
  collapsible,
1771
1766
  panelSize
1772
1767
  } = panelDataHelper(panelDataArray, panelData, layout);
1773
- assert(panelSize != null);
1768
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1774
1769
  return !collapsible || panelSize > collapsedSize;
1775
1770
  }, []);
1776
1771
  const registerPanel = useCallback(panelData => {
@@ -1937,7 +1932,7 @@ function PanelGroupWithForwardedRef({
1937
1932
  panelSize,
1938
1933
  pivotIndices
1939
1934
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1940
- assert(panelSize != null);
1935
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1941
1936
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1942
1937
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1943
1938
  const nextLayout = adjustLayoutByDelta({
@@ -1974,7 +1969,10 @@ function PanelGroupWithForwardedRef({
1974
1969
  const {
1975
1970
  panelSize: prevPanelSize
1976
1971
  } = panelDataHelper(panelDataArray, panelData, layout);
1977
- assert(prevPanelSize != null);
1972
+ if (prevPanelSize == null) {
1973
+ // It's possible that the panels in this group have changed since the last render
1974
+ return;
1975
+ }
1978
1976
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1979
1977
  if (prevCollapsedSize !== nextCollapsedSize) {
1980
1978
  resizePanel(panelData, nextCollapsedSize);
@@ -1996,7 +1994,7 @@ function PanelGroupWithForwardedRef({
1996
1994
  return;
1997
1995
  }
1998
1996
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1999
- assert(handleElement);
1997
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
2000
1998
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
2001
1999
  setDragState({
2002
2000
  dragHandleId,
@@ -2125,10 +2123,10 @@ function useWindowSplitterResizeHandlerBehavior({
2125
2123
  {
2126
2124
  event.preventDefault();
2127
2125
  const groupId = handleElement.getAttribute("data-panel-group-id");
2128
- assert(groupId);
2126
+ assert(groupId, `No group element found for id "${groupId}"`);
2129
2127
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2130
2128
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2131
- assert(index !== null);
2129
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2132
2130
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2133
2131
  const nextHandle = handles[nextIndex];
2134
2132
  nextHandle.focus();
@@ -2200,7 +2198,7 @@ function PanelResizeHandle({
2200
2198
  return;
2201
2199
  }
2202
2200
  const element = elementRef.current;
2203
- assert(element);
2201
+ assert(element, "Element ref not attached");
2204
2202
  const setResizeHandlerState = (action, isActive, event) => {
2205
2203
  if (isActive) {
2206
2204
  switch (action) {