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
@@ -314,7 +314,7 @@ function compare(a, b) {
314
314
  b = ancestors.b.pop();
315
315
  common_ancestor = a;
316
316
  }
317
- assert(common_ancestor);
317
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
318
318
  const z_indexes = {
319
319
  a: get_z_index(find_stacking_context(ancestors.a)),
320
320
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -372,7 +372,7 @@ function find_stacking_context(nodes) {
372
372
  let i = nodes.length;
373
373
  while (i--) {
374
374
  const node = nodes[i];
375
- assert(node);
375
+ assert(node, "Missing node");
376
376
  if (creates_stacking_context(node)) return node;
377
377
  }
378
378
  return null;
@@ -659,7 +659,7 @@ function updateResizeHandlerStates(action, event) {
659
659
  });
660
660
  }
661
661
 
662
- function assert(expectedCondition, message = "Assertion failed!") {
662
+ function assert(expectedCondition, message) {
663
663
  if (!expectedCondition) {
664
664
  console.error(message);
665
665
  throw Error(message);
@@ -690,7 +690,7 @@ function resizePanel({
690
690
  size
691
691
  }) {
692
692
  const panelConstraints = panelConstraintsArray[panelIndex];
693
- assert(panelConstraints != null);
693
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
694
694
  let {
695
695
  collapsedSize = 0,
696
696
  collapsible,
@@ -728,8 +728,8 @@ function adjustLayoutByDelta({
728
728
  }
729
729
  const nextLayout = [...prevLayout];
730
730
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
731
- assert(firstPivotIndex != null);
732
- assert(secondPivotIndex != null);
731
+ assert(firstPivotIndex != null, "Invalid first pivot index");
732
+ assert(secondPivotIndex != null, "Invalid second pivot index");
733
733
  let deltaApplied = 0;
734
734
 
735
735
  //const DEBUG = [];
@@ -755,19 +755,18 @@ function adjustLayoutByDelta({
755
755
  // Check if we should expand a collapsed panel
756
756
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
757
757
  const panelConstraints = panelConstraintsArray[index];
758
- assert(panelConstraints);
758
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
759
+ const {
760
+ collapsedSize = 0,
761
+ collapsible,
762
+ minSize = 0
763
+ } = panelConstraints;
759
764
 
760
765
  //DEBUG.push(`edge case check 1: ${index}`);
761
766
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
762
- if (panelConstraints.collapsible) {
767
+ if (collapsible) {
763
768
  const prevSize = prevLayout[index];
764
- assert(prevSize != null);
765
- const panelConstraints = panelConstraintsArray[index];
766
- assert(panelConstraints);
767
- const {
768
- collapsedSize = 0,
769
- minSize = 0
770
- } = panelConstraints;
769
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
771
770
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
772
771
  const localDelta = minSize - prevSize;
773
772
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -784,22 +783,18 @@ function adjustLayoutByDelta({
784
783
  // Check if we should collapse a panel at its minimum size
785
784
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
786
785
  const panelConstraints = panelConstraintsArray[index];
787
- assert(panelConstraints);
786
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
788
787
  const {
789
- collapsible
788
+ collapsedSize = 0,
789
+ collapsible,
790
+ minSize = 0
790
791
  } = panelConstraints;
791
792
 
792
793
  //DEBUG.push(`edge case check 2: ${index}`);
793
794
  //DEBUG.push(` -> collapsible? ${collapsible}`);
794
795
  if (collapsible) {
795
796
  const prevSize = prevLayout[index];
796
- assert(prevSize != null);
797
- const panelConstraints = panelConstraintsArray[index];
798
- assert(panelConstraints);
799
- const {
800
- collapsedSize = 0,
801
- minSize = 0
802
- } = panelConstraints;
797
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
803
798
  if (fuzzyNumbersEqual(prevSize, minSize)) {
804
799
  const localDelta = prevSize - collapsedSize;
805
800
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -829,7 +824,7 @@ function adjustLayoutByDelta({
829
824
  //DEBUG.push("pre calc...");
830
825
  while (true) {
831
826
  const prevSize = prevLayout[index];
832
- assert(prevSize != null);
827
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
833
828
  const maxSafeSize = resizePanel({
834
829
  panelConstraints: panelConstraintsArray,
835
830
  panelIndex: index,
@@ -860,7 +855,7 @@ function adjustLayoutByDelta({
860
855
  while (index >= 0 && index < panelConstraintsArray.length) {
861
856
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
862
857
  const prevSize = prevLayout[index];
863
- assert(prevSize != null);
858
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
864
859
  const unsafeSize = prevSize - deltaRemaining;
865
860
  const safeSize = resizePanel({
866
861
  panelConstraints: panelConstraintsArray,
@@ -897,7 +892,7 @@ function adjustLayoutByDelta({
897
892
  // Now distribute the applied delta to the panels in the other direction
898
893
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
899
894
  const prevSize = prevLayout[pivotIndex];
900
- assert(prevSize != null);
895
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
901
896
  const unsafeSize = prevSize + deltaApplied;
902
897
  const safeSize = resizePanel({
903
898
  panelConstraints: panelConstraintsArray,
@@ -915,7 +910,7 @@ function adjustLayoutByDelta({
915
910
  let index = pivotIndex;
916
911
  while (index >= 0 && index < panelConstraintsArray.length) {
917
912
  const prevSize = nextLayout[index];
918
- assert(prevSize != null);
913
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
919
914
  const unsafeSize = prevSize + deltaRemaining;
920
915
  const safeSize = resizePanel({
921
916
  panelConstraints: panelConstraintsArray,
@@ -961,7 +956,7 @@ function calculateAriaValues({
961
956
  let totalMinSize = 0;
962
957
  let totalMaxSize = 0;
963
958
  const firstIndex = pivotIndices[0];
964
- assert(firstIndex != null);
959
+ assert(firstIndex != null, "No pivot index found");
965
960
 
966
961
  // A panel's effective min/max sizes also need to account for other panel's sizes.
967
962
  panelsArray.forEach((panelData, index) => {
@@ -1080,7 +1075,7 @@ function useWindowSplitterPanelGroupBehavior({
1080
1075
  }
1081
1076
  } else {
1082
1077
  const panelData = panelDataArray[index];
1083
- assert(panelData);
1078
+ assert(panelData, `No panel data found for index "${index}"`);
1084
1079
  resizeHandleElement.setAttribute("aria-controls", panelData.id);
1085
1080
  resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
1086
1081
  resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
@@ -1101,17 +1096,17 @@ function useWindowSplitterPanelGroupBehavior({
1101
1096
  return;
1102
1097
  }
1103
1098
  const eagerValues = eagerValuesRef.current;
1104
- assert(eagerValues);
1099
+ assert(eagerValues, `Eager values not found`);
1105
1100
  const {
1106
1101
  panelDataArray
1107
1102
  } = eagerValues;
1108
1103
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1109
1104
  assert(groupElement != null, `No group found for id "${groupId}"`);
1110
1105
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1111
- assert(handles);
1106
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1112
1107
  const cleanupFunctions = handles.map(handle => {
1113
1108
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1114
- assert(handleId);
1109
+ assert(handleId, `Resize handle element has no handle id attribute`);
1115
1110
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1116
1111
  if (idBefore == null || idAfter == null) {
1117
1112
  return () => {};
@@ -1127,7 +1122,7 @@ function useWindowSplitterPanelGroupBehavior({
1127
1122
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1128
1123
  if (index >= 0) {
1129
1124
  const panelData = panelDataArray[index];
1130
- assert(panelData);
1125
+ assert(panelData, `No panel data found for index ${index}`);
1131
1126
  const size = layout[index];
1132
1127
  const {
1133
1128
  collapsedSize = 0,
@@ -1186,15 +1181,15 @@ function getResizeEventCursorPosition(direction, event) {
1186
1181
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1187
1182
  const isHorizontal = direction === "horizontal";
1188
1183
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1189
- assert(handleElement);
1184
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1190
1185
  const groupId = handleElement.getAttribute("data-panel-group-id");
1191
- assert(groupId);
1186
+ assert(groupId, `Resize handle element has no group id attribute`);
1192
1187
  let {
1193
1188
  initialCursorPosition
1194
1189
  } = initialDragState;
1195
1190
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1196
1191
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1197
- assert(groupElement);
1192
+ assert(groupElement, `No group element found for id "${groupId}"`);
1198
1193
  const groupRect = groupElement.getBoundingClientRect();
1199
1194
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1200
1195
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1255,7 +1250,7 @@ function calculateUnsafeDefaultLayout({
1255
1250
  // Distribute default sizes first
1256
1251
  for (let index = 0; index < panelDataArray.length; index++) {
1257
1252
  const panelConstraints = panelConstraintsArray[index];
1258
- assert(panelConstraints);
1253
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1259
1254
  const {
1260
1255
  defaultSize
1261
1256
  } = panelConstraints;
@@ -1269,7 +1264,7 @@ function calculateUnsafeDefaultLayout({
1269
1264
  // Remaining size should be distributed evenly between panels without default sizes
1270
1265
  for (let index = 0; index < panelDataArray.length; index++) {
1271
1266
  const panelConstraints = panelConstraintsArray[index];
1272
- assert(panelConstraints);
1267
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1273
1268
  const {
1274
1269
  defaultSize
1275
1270
  } = panelConstraints;
@@ -1289,7 +1284,7 @@ function calculateUnsafeDefaultLayout({
1289
1284
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1290
1285
  layout.forEach((size, index) => {
1291
1286
  const panelData = panelsArray[index];
1292
- assert(panelData);
1287
+ assert(panelData, `Panel data not found for index ${index}`);
1293
1288
  const {
1294
1289
  callbacks,
1295
1290
  constraints,
@@ -1473,7 +1468,7 @@ function validatePanelConstraints({
1473
1468
  {
1474
1469
  const warnings = [];
1475
1470
  const panelConstraints = panelConstraintsArray[panelIndex];
1476
- assert(panelConstraints);
1471
+ assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
1477
1472
  const {
1478
1473
  collapsedSize = 0,
1479
1474
  collapsible = false,
@@ -1527,7 +1522,7 @@ function validatePanelGroupLayout({
1527
1522
  }
1528
1523
  for (let index = 0; index < panelConstraints.length; index++) {
1529
1524
  const unsafeSize = nextLayout[index];
1530
- assert(unsafeSize != null);
1525
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1531
1526
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1532
1527
  nextLayout[index] = safeSize;
1533
1528
  }
@@ -1537,7 +1532,7 @@ function validatePanelGroupLayout({
1537
1532
  // First pass: Validate the proposed layout given each panel's constraints
1538
1533
  for (let index = 0; index < panelConstraints.length; index++) {
1539
1534
  const unsafeSize = nextLayout[index];
1540
- assert(unsafeSize != null);
1535
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1541
1536
  const safeSize = resizePanel({
1542
1537
  panelConstraints,
1543
1538
  panelIndex: index,
@@ -1554,7 +1549,7 @@ function validatePanelGroupLayout({
1554
1549
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1555
1550
  for (let index = 0; index < panelConstraints.length; index++) {
1556
1551
  const prevSize = nextLayout[index];
1557
- assert(prevSize != null);
1552
+ assert(prevSize != null, `No layout data found for index ${index}`);
1558
1553
  const unsafeSize = prevSize + remainingSize;
1559
1554
  const safeSize = resizePanel({
1560
1555
  panelConstraints,
@@ -1731,7 +1726,7 @@ function PanelGroupWithForwardedRef({
1731
1726
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1732
1727
  for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
1733
1728
  const panelData = panelDataArray[panelIndex];
1734
- assert(panelData);
1729
+ assert(panelData, `Panel data not found for index ${panelIndex}`);
1735
1730
  const isValid = validatePanelConstraints({
1736
1731
  panelConstraints,
1737
1732
  panelId: panelData.id,
@@ -1762,7 +1757,7 @@ function PanelGroupWithForwardedRef({
1762
1757
  panelSize,
1763
1758
  pivotIndices
1764
1759
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1765
- assert(panelSize != null);
1760
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1766
1761
  if (panelSize !== collapsedSize) {
1767
1762
  // Store size before collapse;
1768
1763
  // This is the size that gets restored if the expand() API is used.
@@ -1839,7 +1834,7 @@ function PanelGroupWithForwardedRef({
1839
1834
  const {
1840
1835
  panelSize
1841
1836
  } = panelDataHelper(panelDataArray, panelData, layout);
1842
- assert(panelSize != null);
1837
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1843
1838
  return panelSize;
1844
1839
  }, []);
1845
1840
 
@@ -1883,7 +1878,7 @@ function PanelGroupWithForwardedRef({
1883
1878
  collapsible,
1884
1879
  panelSize
1885
1880
  } = panelDataHelper(panelDataArray, panelData, layout);
1886
- assert(panelSize != null);
1881
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1887
1882
  return !collapsible || panelSize > collapsedSize;
1888
1883
  }, []);
1889
1884
  const registerPanel = useCallback(panelData => {
@@ -2050,7 +2045,7 @@ function PanelGroupWithForwardedRef({
2050
2045
  panelSize,
2051
2046
  pivotIndices
2052
2047
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
2053
- assert(panelSize != null);
2048
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
2054
2049
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
2055
2050
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
2056
2051
  const nextLayout = adjustLayoutByDelta({
@@ -2087,7 +2082,10 @@ function PanelGroupWithForwardedRef({
2087
2082
  const {
2088
2083
  panelSize: prevPanelSize
2089
2084
  } = panelDataHelper(panelDataArray, panelData, layout);
2090
- assert(prevPanelSize != null);
2085
+ if (prevPanelSize == null) {
2086
+ // It's possible that the panels in this group have changed since the last render
2087
+ return;
2088
+ }
2091
2089
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
2092
2090
  if (prevCollapsedSize !== nextCollapsedSize) {
2093
2091
  resizePanel(panelData, nextCollapsedSize);
@@ -2109,7 +2107,7 @@ function PanelGroupWithForwardedRef({
2109
2107
  return;
2110
2108
  }
2111
2109
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
2112
- assert(handleElement);
2110
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
2113
2111
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
2114
2112
  setDragState({
2115
2113
  dragHandleId,
@@ -2238,10 +2236,10 @@ function useWindowSplitterResizeHandlerBehavior({
2238
2236
  {
2239
2237
  event.preventDefault();
2240
2238
  const groupId = handleElement.getAttribute("data-panel-group-id");
2241
- assert(groupId);
2239
+ assert(groupId, `No group element found for id "${groupId}"`);
2242
2240
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2243
2241
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2244
- assert(index !== null);
2242
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2245
2243
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2246
2244
  const nextHandle = handles[nextIndex];
2247
2245
  nextHandle.focus();
@@ -2313,7 +2311,7 @@ function PanelResizeHandle({
2313
2311
  return;
2314
2312
  }
2315
2313
  const element = elementRef.current;
2316
- assert(element);
2314
+ assert(element, "Element ref not attached");
2317
2315
  const setResizeHandlerState = (action, isActive, event) => {
2318
2316
  if (isActive) {
2319
2317
  switch (action) {
@@ -300,7 +300,7 @@ function compare(a, b) {
300
300
  b = ancestors.b.pop();
301
301
  common_ancestor = a;
302
302
  }
303
- assert(common_ancestor);
303
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
304
304
  const z_indexes = {
305
305
  a: get_z_index(find_stacking_context(ancestors.a)),
306
306
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -358,7 +358,7 @@ function find_stacking_context(nodes) {
358
358
  let i = nodes.length;
359
359
  while (i--) {
360
360
  const node = nodes[i];
361
- assert(node);
361
+ assert(node, "Missing node");
362
362
  if (creates_stacking_context(node)) return node;
363
363
  }
364
364
  return null;
@@ -645,7 +645,7 @@ function updateResizeHandlerStates(action, event) {
645
645
  });
646
646
  }
647
647
 
648
- function assert(expectedCondition, message = "Assertion failed!") {
648
+ function assert(expectedCondition, message) {
649
649
  if (!expectedCondition) {
650
650
  console.error(message);
651
651
  throw Error(message);
@@ -676,7 +676,7 @@ function resizePanel({
676
676
  size
677
677
  }) {
678
678
  const panelConstraints = panelConstraintsArray[panelIndex];
679
- assert(panelConstraints != null);
679
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
680
680
  let {
681
681
  collapsedSize = 0,
682
682
  collapsible,
@@ -714,8 +714,8 @@ function adjustLayoutByDelta({
714
714
  }
715
715
  const nextLayout = [...prevLayout];
716
716
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
717
- assert(firstPivotIndex != null);
718
- assert(secondPivotIndex != null);
717
+ assert(firstPivotIndex != null, "Invalid first pivot index");
718
+ assert(secondPivotIndex != null, "Invalid second pivot index");
719
719
  let deltaApplied = 0;
720
720
 
721
721
  //const DEBUG = [];
@@ -741,19 +741,18 @@ function adjustLayoutByDelta({
741
741
  // Check if we should expand a collapsed panel
742
742
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
743
743
  const panelConstraints = panelConstraintsArray[index];
744
- assert(panelConstraints);
744
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
745
+ const {
746
+ collapsedSize = 0,
747
+ collapsible,
748
+ minSize = 0
749
+ } = panelConstraints;
745
750
 
746
751
  //DEBUG.push(`edge case check 1: ${index}`);
747
752
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
748
- if (panelConstraints.collapsible) {
753
+ if (collapsible) {
749
754
  const prevSize = prevLayout[index];
750
- assert(prevSize != null);
751
- const panelConstraints = panelConstraintsArray[index];
752
- assert(panelConstraints);
753
- const {
754
- collapsedSize = 0,
755
- minSize = 0
756
- } = panelConstraints;
755
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
757
756
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
758
757
  const localDelta = minSize - prevSize;
759
758
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -770,22 +769,18 @@ function adjustLayoutByDelta({
770
769
  // Check if we should collapse a panel at its minimum size
771
770
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
772
771
  const panelConstraints = panelConstraintsArray[index];
773
- assert(panelConstraints);
772
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
774
773
  const {
775
- collapsible
774
+ collapsedSize = 0,
775
+ collapsible,
776
+ minSize = 0
776
777
  } = panelConstraints;
777
778
 
778
779
  //DEBUG.push(`edge case check 2: ${index}`);
779
780
  //DEBUG.push(` -> collapsible? ${collapsible}`);
780
781
  if (collapsible) {
781
782
  const prevSize = prevLayout[index];
782
- assert(prevSize != null);
783
- const panelConstraints = panelConstraintsArray[index];
784
- assert(panelConstraints);
785
- const {
786
- collapsedSize = 0,
787
- minSize = 0
788
- } = panelConstraints;
783
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
789
784
  if (fuzzyNumbersEqual(prevSize, minSize)) {
790
785
  const localDelta = prevSize - collapsedSize;
791
786
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -815,7 +810,7 @@ function adjustLayoutByDelta({
815
810
  //DEBUG.push("pre calc...");
816
811
  while (true) {
817
812
  const prevSize = prevLayout[index];
818
- assert(prevSize != null);
813
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
819
814
  const maxSafeSize = resizePanel({
820
815
  panelConstraints: panelConstraintsArray,
821
816
  panelIndex: index,
@@ -846,7 +841,7 @@ function adjustLayoutByDelta({
846
841
  while (index >= 0 && index < panelConstraintsArray.length) {
847
842
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
848
843
  const prevSize = prevLayout[index];
849
- assert(prevSize != null);
844
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
850
845
  const unsafeSize = prevSize - deltaRemaining;
851
846
  const safeSize = resizePanel({
852
847
  panelConstraints: panelConstraintsArray,
@@ -883,7 +878,7 @@ function adjustLayoutByDelta({
883
878
  // Now distribute the applied delta to the panels in the other direction
884
879
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
885
880
  const prevSize = prevLayout[pivotIndex];
886
- assert(prevSize != null);
881
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
887
882
  const unsafeSize = prevSize + deltaApplied;
888
883
  const safeSize = resizePanel({
889
884
  panelConstraints: panelConstraintsArray,
@@ -901,7 +896,7 @@ function adjustLayoutByDelta({
901
896
  let index = pivotIndex;
902
897
  while (index >= 0 && index < panelConstraintsArray.length) {
903
898
  const prevSize = nextLayout[index];
904
- assert(prevSize != null);
899
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
905
900
  const unsafeSize = prevSize + deltaRemaining;
906
901
  const safeSize = resizePanel({
907
902
  panelConstraints: panelConstraintsArray,
@@ -1004,17 +999,17 @@ function useWindowSplitterPanelGroupBehavior({
1004
999
  return;
1005
1000
  }
1006
1001
  const eagerValues = eagerValuesRef.current;
1007
- assert(eagerValues);
1002
+ assert(eagerValues, `Eager values not found`);
1008
1003
  const {
1009
1004
  panelDataArray
1010
1005
  } = eagerValues;
1011
1006
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1012
1007
  assert(groupElement != null, `No group found for id "${groupId}"`);
1013
1008
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1014
- assert(handles);
1009
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1015
1010
  const cleanupFunctions = handles.map(handle => {
1016
1011
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1017
- assert(handleId);
1012
+ assert(handleId, `Resize handle element has no handle id attribute`);
1018
1013
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1019
1014
  if (idBefore == null || idAfter == null) {
1020
1015
  return () => {};
@@ -1030,7 +1025,7 @@ function useWindowSplitterPanelGroupBehavior({
1030
1025
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1031
1026
  if (index >= 0) {
1032
1027
  const panelData = panelDataArray[index];
1033
- assert(panelData);
1028
+ assert(panelData, `No panel data found for index ${index}`);
1034
1029
  const size = layout[index];
1035
1030
  const {
1036
1031
  collapsedSize = 0,
@@ -1089,15 +1084,15 @@ function getResizeEventCursorPosition(direction, event) {
1089
1084
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1090
1085
  const isHorizontal = direction === "horizontal";
1091
1086
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1092
- assert(handleElement);
1087
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1093
1088
  const groupId = handleElement.getAttribute("data-panel-group-id");
1094
- assert(groupId);
1089
+ assert(groupId, `Resize handle element has no group id attribute`);
1095
1090
  let {
1096
1091
  initialCursorPosition
1097
1092
  } = initialDragState;
1098
1093
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1099
1094
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1100
- assert(groupElement);
1095
+ assert(groupElement, `No group element found for id "${groupId}"`);
1101
1096
  const groupRect = groupElement.getBoundingClientRect();
1102
1097
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1103
1098
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1151,7 +1146,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
1151
1146
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1152
1147
  layout.forEach((size, index) => {
1153
1148
  const panelData = panelsArray[index];
1154
- assert(panelData);
1149
+ assert(panelData, `Panel data not found for index ${index}`);
1155
1150
  const {
1156
1151
  callbacks,
1157
1152
  constraints,
@@ -1329,7 +1324,7 @@ function validatePanelConstraints({
1329
1324
  {
1330
1325
  const warnings = [];
1331
1326
  const panelConstraints = panelConstraintsArray[panelIndex];
1332
- assert(panelConstraints);
1327
+ assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
1333
1328
  const {
1334
1329
  collapsedSize = 0,
1335
1330
  collapsible = false,
@@ -1383,7 +1378,7 @@ function validatePanelGroupLayout({
1383
1378
  }
1384
1379
  for (let index = 0; index < panelConstraints.length; index++) {
1385
1380
  const unsafeSize = nextLayout[index];
1386
- assert(unsafeSize != null);
1381
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1387
1382
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1388
1383
  nextLayout[index] = safeSize;
1389
1384
  }
@@ -1393,7 +1388,7 @@ function validatePanelGroupLayout({
1393
1388
  // First pass: Validate the proposed layout given each panel's constraints
1394
1389
  for (let index = 0; index < panelConstraints.length; index++) {
1395
1390
  const unsafeSize = nextLayout[index];
1396
- assert(unsafeSize != null);
1391
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1397
1392
  const safeSize = resizePanel({
1398
1393
  panelConstraints,
1399
1394
  panelIndex: index,
@@ -1410,7 +1405,7 @@ function validatePanelGroupLayout({
1410
1405
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1411
1406
  for (let index = 0; index < panelConstraints.length; index++) {
1412
1407
  const prevSize = nextLayout[index];
1413
- assert(prevSize != null);
1408
+ assert(prevSize != null, `No layout data found for index ${index}`);
1414
1409
  const unsafeSize = prevSize + remainingSize;
1415
1410
  const safeSize = resizePanel({
1416
1411
  panelConstraints,
@@ -1579,7 +1574,7 @@ function PanelGroupWithForwardedRef({
1579
1574
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1580
1575
  for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
1581
1576
  const panelData = panelDataArray[panelIndex];
1582
- assert(panelData);
1577
+ assert(panelData, `Panel data not found for index ${panelIndex}`);
1583
1578
  const isValid = validatePanelConstraints({
1584
1579
  panelConstraints,
1585
1580
  panelId: panelData.id,
@@ -1610,7 +1605,7 @@ function PanelGroupWithForwardedRef({
1610
1605
  panelSize,
1611
1606
  pivotIndices
1612
1607
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1613
- assert(panelSize != null);
1608
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1614
1609
  if (panelSize !== collapsedSize) {
1615
1610
  // Store size before collapse;
1616
1611
  // This is the size that gets restored if the expand() API is used.
@@ -1687,7 +1682,7 @@ function PanelGroupWithForwardedRef({
1687
1682
  const {
1688
1683
  panelSize
1689
1684
  } = panelDataHelper(panelDataArray, panelData, layout);
1690
- assert(panelSize != null);
1685
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1691
1686
  return panelSize;
1692
1687
  }, []);
1693
1688
 
@@ -1731,7 +1726,7 @@ function PanelGroupWithForwardedRef({
1731
1726
  collapsible,
1732
1727
  panelSize
1733
1728
  } = panelDataHelper(panelDataArray, panelData, layout);
1734
- assert(panelSize != null);
1729
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1735
1730
  return !collapsible || panelSize > collapsedSize;
1736
1731
  }, []);
1737
1732
  const registerPanel = useCallback(panelData => {
@@ -1842,7 +1837,7 @@ function PanelGroupWithForwardedRef({
1842
1837
  panelSize,
1843
1838
  pivotIndices
1844
1839
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1845
- assert(panelSize != null);
1840
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1846
1841
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1847
1842
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1848
1843
  const nextLayout = adjustLayoutByDelta({
@@ -1879,7 +1874,10 @@ function PanelGroupWithForwardedRef({
1879
1874
  const {
1880
1875
  panelSize: prevPanelSize
1881
1876
  } = panelDataHelper(panelDataArray, panelData, layout);
1882
- assert(prevPanelSize != null);
1877
+ if (prevPanelSize == null) {
1878
+ // It's possible that the panels in this group have changed since the last render
1879
+ return;
1880
+ }
1883
1881
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1884
1882
  if (prevCollapsedSize !== nextCollapsedSize) {
1885
1883
  resizePanel(panelData, nextCollapsedSize);
@@ -1901,7 +1899,7 @@ function PanelGroupWithForwardedRef({
1901
1899
  return;
1902
1900
  }
1903
1901
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1904
- assert(handleElement);
1902
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
1905
1903
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1906
1904
  setDragState({
1907
1905
  dragHandleId,
@@ -2030,10 +2028,10 @@ function useWindowSplitterResizeHandlerBehavior({
2030
2028
  {
2031
2029
  event.preventDefault();
2032
2030
  const groupId = handleElement.getAttribute("data-panel-group-id");
2033
- assert(groupId);
2031
+ assert(groupId, `No group element found for id "${groupId}"`);
2034
2032
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2035
2033
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2036
- assert(index !== null);
2034
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2037
2035
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2038
2036
  const nextHandle = handles[nextIndex];
2039
2037
  nextHandle.focus();
@@ -2102,7 +2100,7 @@ function PanelResizeHandle({
2102
2100
  return;
2103
2101
  }
2104
2102
  const element = elementRef.current;
2105
- assert(element);
2103
+ assert(element, "Element ref not attached");
2106
2104
  const setResizeHandlerState = (action, isActive, event) => {
2107
2105
  if (isActive) {
2108
2106
  switch (action) {