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
@@ -276,7 +276,7 @@ function compare(a, b) {
276
276
  b = ancestors.b.pop();
277
277
  common_ancestor = a;
278
278
  }
279
- assert(common_ancestor);
279
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
280
280
  const z_indexes = {
281
281
  a: get_z_index(find_stacking_context(ancestors.a)),
282
282
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -334,7 +334,7 @@ function find_stacking_context(nodes) {
334
334
  let i = nodes.length;
335
335
  while (i--) {
336
336
  const node = nodes[i];
337
- assert(node);
337
+ assert(node, "Missing node");
338
338
  if (creates_stacking_context(node)) return node;
339
339
  }
340
340
  return null;
@@ -621,7 +621,7 @@ function updateResizeHandlerStates(action, event) {
621
621
  });
622
622
  }
623
623
 
624
- function assert(expectedCondition, message = "Assertion failed!") {
624
+ function assert(expectedCondition, message) {
625
625
  if (!expectedCondition) {
626
626
  console.error(message);
627
627
  throw Error(message);
@@ -652,7 +652,7 @@ function resizePanel({
652
652
  size
653
653
  }) {
654
654
  const panelConstraints = panelConstraintsArray[panelIndex];
655
- assert(panelConstraints != null);
655
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
656
656
  let {
657
657
  collapsedSize = 0,
658
658
  collapsible,
@@ -690,8 +690,8 @@ function adjustLayoutByDelta({
690
690
  }
691
691
  const nextLayout = [...prevLayout];
692
692
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
693
- assert(firstPivotIndex != null);
694
- assert(secondPivotIndex != null);
693
+ assert(firstPivotIndex != null, "Invalid first pivot index");
694
+ assert(secondPivotIndex != null, "Invalid second pivot index");
695
695
  let deltaApplied = 0;
696
696
 
697
697
  //const DEBUG = [];
@@ -717,19 +717,18 @@ function adjustLayoutByDelta({
717
717
  // Check if we should expand a collapsed panel
718
718
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
719
719
  const panelConstraints = panelConstraintsArray[index];
720
- assert(panelConstraints);
720
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
721
+ const {
722
+ collapsedSize = 0,
723
+ collapsible,
724
+ minSize = 0
725
+ } = panelConstraints;
721
726
 
722
727
  //DEBUG.push(`edge case check 1: ${index}`);
723
728
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
724
- if (panelConstraints.collapsible) {
729
+ if (collapsible) {
725
730
  const prevSize = prevLayout[index];
726
- assert(prevSize != null);
727
- const panelConstraints = panelConstraintsArray[index];
728
- assert(panelConstraints);
729
- const {
730
- collapsedSize = 0,
731
- minSize = 0
732
- } = panelConstraints;
731
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
733
732
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
734
733
  const localDelta = minSize - prevSize;
735
734
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -746,22 +745,18 @@ function adjustLayoutByDelta({
746
745
  // Check if we should collapse a panel at its minimum size
747
746
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
748
747
  const panelConstraints = panelConstraintsArray[index];
749
- assert(panelConstraints);
748
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
750
749
  const {
751
- collapsible
750
+ collapsedSize = 0,
751
+ collapsible,
752
+ minSize = 0
752
753
  } = panelConstraints;
753
754
 
754
755
  //DEBUG.push(`edge case check 2: ${index}`);
755
756
  //DEBUG.push(` -> collapsible? ${collapsible}`);
756
757
  if (collapsible) {
757
758
  const prevSize = prevLayout[index];
758
- assert(prevSize != null);
759
- const panelConstraints = panelConstraintsArray[index];
760
- assert(panelConstraints);
761
- const {
762
- collapsedSize = 0,
763
- minSize = 0
764
- } = panelConstraints;
759
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
765
760
  if (fuzzyNumbersEqual(prevSize, minSize)) {
766
761
  const localDelta = prevSize - collapsedSize;
767
762
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -791,7 +786,7 @@ function adjustLayoutByDelta({
791
786
  //DEBUG.push("pre calc...");
792
787
  while (true) {
793
788
  const prevSize = prevLayout[index];
794
- assert(prevSize != null);
789
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
795
790
  const maxSafeSize = resizePanel({
796
791
  panelConstraints: panelConstraintsArray,
797
792
  panelIndex: index,
@@ -822,7 +817,7 @@ function adjustLayoutByDelta({
822
817
  while (index >= 0 && index < panelConstraintsArray.length) {
823
818
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
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 unsafeSize = prevSize - deltaRemaining;
827
822
  const safeSize = resizePanel({
828
823
  panelConstraints: panelConstraintsArray,
@@ -859,7 +854,7 @@ function adjustLayoutByDelta({
859
854
  // Now distribute the applied delta to the panels in the other direction
860
855
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
861
856
  const prevSize = prevLayout[pivotIndex];
862
- assert(prevSize != null);
857
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
863
858
  const unsafeSize = prevSize + deltaApplied;
864
859
  const safeSize = resizePanel({
865
860
  panelConstraints: panelConstraintsArray,
@@ -877,7 +872,7 @@ function adjustLayoutByDelta({
877
872
  let index = pivotIndex;
878
873
  while (index >= 0 && index < panelConstraintsArray.length) {
879
874
  const prevSize = nextLayout[index];
880
- assert(prevSize != null);
875
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
881
876
  const unsafeSize = prevSize + deltaRemaining;
882
877
  const safeSize = resizePanel({
883
878
  panelConstraints: panelConstraintsArray,
@@ -980,17 +975,17 @@ function useWindowSplitterPanelGroupBehavior({
980
975
  return;
981
976
  }
982
977
  const eagerValues = eagerValuesRef.current;
983
- assert(eagerValues);
978
+ assert(eagerValues, `Eager values not found`);
984
979
  const {
985
980
  panelDataArray
986
981
  } = eagerValues;
987
982
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
988
983
  assert(groupElement != null, `No group found for id "${groupId}"`);
989
984
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
990
- assert(handles);
985
+ assert(handles, `No resize handles found for group id "${groupId}"`);
991
986
  const cleanupFunctions = handles.map(handle => {
992
987
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
993
- assert(handleId);
988
+ assert(handleId, `Resize handle element has no handle id attribute`);
994
989
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
995
990
  if (idBefore == null || idAfter == null) {
996
991
  return () => {};
@@ -1006,7 +1001,7 @@ function useWindowSplitterPanelGroupBehavior({
1006
1001
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1007
1002
  if (index >= 0) {
1008
1003
  const panelData = panelDataArray[index];
1009
- assert(panelData);
1004
+ assert(panelData, `No panel data found for index ${index}`);
1010
1005
  const size = layout[index];
1011
1006
  const {
1012
1007
  collapsedSize = 0,
@@ -1065,15 +1060,15 @@ function getResizeEventCursorPosition(direction, event) {
1065
1060
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1066
1061
  const isHorizontal = direction === "horizontal";
1067
1062
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1068
- assert(handleElement);
1063
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1069
1064
  const groupId = handleElement.getAttribute("data-panel-group-id");
1070
- assert(groupId);
1065
+ assert(groupId, `Resize handle element has no group id attribute`);
1071
1066
  let {
1072
1067
  initialCursorPosition
1073
1068
  } = initialDragState;
1074
1069
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1075
1070
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1076
- assert(groupElement);
1071
+ assert(groupElement, `No group element found for id "${groupId}"`);
1077
1072
  const groupRect = groupElement.getBoundingClientRect();
1078
1073
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1079
1074
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1127,7 +1122,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
1127
1122
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1128
1123
  layout.forEach((size, index) => {
1129
1124
  const panelData = panelsArray[index];
1130
- assert(panelData);
1125
+ assert(panelData, `Panel data not found for index ${index}`);
1131
1126
  const {
1132
1127
  callbacks,
1133
1128
  constraints,
@@ -1305,7 +1300,7 @@ function validatePanelConstraints({
1305
1300
  {
1306
1301
  const warnings = [];
1307
1302
  const panelConstraints = panelConstraintsArray[panelIndex];
1308
- assert(panelConstraints);
1303
+ assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
1309
1304
  const {
1310
1305
  collapsedSize = 0,
1311
1306
  collapsible = false,
@@ -1359,7 +1354,7 @@ function validatePanelGroupLayout({
1359
1354
  }
1360
1355
  for (let index = 0; index < panelConstraints.length; index++) {
1361
1356
  const unsafeSize = nextLayout[index];
1362
- assert(unsafeSize != null);
1357
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1363
1358
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1364
1359
  nextLayout[index] = safeSize;
1365
1360
  }
@@ -1369,7 +1364,7 @@ function validatePanelGroupLayout({
1369
1364
  // First pass: Validate the proposed layout given each panel's constraints
1370
1365
  for (let index = 0; index < panelConstraints.length; index++) {
1371
1366
  const unsafeSize = nextLayout[index];
1372
- assert(unsafeSize != null);
1367
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1373
1368
  const safeSize = resizePanel({
1374
1369
  panelConstraints,
1375
1370
  panelIndex: index,
@@ -1386,7 +1381,7 @@ function validatePanelGroupLayout({
1386
1381
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1387
1382
  for (let index = 0; index < panelConstraints.length; index++) {
1388
1383
  const prevSize = nextLayout[index];
1389
- assert(prevSize != null);
1384
+ assert(prevSize != null, `No layout data found for index ${index}`);
1390
1385
  const unsafeSize = prevSize + remainingSize;
1391
1386
  const safeSize = resizePanel({
1392
1387
  panelConstraints,
@@ -1555,7 +1550,7 @@ function PanelGroupWithForwardedRef({
1555
1550
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1556
1551
  for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
1557
1552
  const panelData = panelDataArray[panelIndex];
1558
- assert(panelData);
1553
+ assert(panelData, `Panel data not found for index ${panelIndex}`);
1559
1554
  const isValid = validatePanelConstraints({
1560
1555
  panelConstraints,
1561
1556
  panelId: panelData.id,
@@ -1586,7 +1581,7 @@ function PanelGroupWithForwardedRef({
1586
1581
  panelSize,
1587
1582
  pivotIndices
1588
1583
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1589
- assert(panelSize != null);
1584
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1590
1585
  if (panelSize !== collapsedSize) {
1591
1586
  // Store size before collapse;
1592
1587
  // This is the size that gets restored if the expand() API is used.
@@ -1663,7 +1658,7 @@ function PanelGroupWithForwardedRef({
1663
1658
  const {
1664
1659
  panelSize
1665
1660
  } = panelDataHelper(panelDataArray, panelData, layout);
1666
- assert(panelSize != null);
1661
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1667
1662
  return panelSize;
1668
1663
  }, []);
1669
1664
 
@@ -1707,7 +1702,7 @@ function PanelGroupWithForwardedRef({
1707
1702
  collapsible,
1708
1703
  panelSize
1709
1704
  } = panelDataHelper(panelDataArray, panelData, layout);
1710
- assert(panelSize != null);
1705
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1711
1706
  return !collapsible || panelSize > collapsedSize;
1712
1707
  }, []);
1713
1708
  const registerPanel = useCallback(panelData => {
@@ -1818,7 +1813,7 @@ function PanelGroupWithForwardedRef({
1818
1813
  panelSize,
1819
1814
  pivotIndices
1820
1815
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1821
- assert(panelSize != null);
1816
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1822
1817
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1823
1818
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1824
1819
  const nextLayout = adjustLayoutByDelta({
@@ -1855,7 +1850,10 @@ function PanelGroupWithForwardedRef({
1855
1850
  const {
1856
1851
  panelSize: prevPanelSize
1857
1852
  } = panelDataHelper(panelDataArray, panelData, layout);
1858
- assert(prevPanelSize != null);
1853
+ if (prevPanelSize == null) {
1854
+ // It's possible that the panels in this group have changed since the last render
1855
+ return;
1856
+ }
1859
1857
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1860
1858
  if (prevCollapsedSize !== nextCollapsedSize) {
1861
1859
  resizePanel(panelData, nextCollapsedSize);
@@ -1877,7 +1875,7 @@ function PanelGroupWithForwardedRef({
1877
1875
  return;
1878
1876
  }
1879
1877
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1880
- assert(handleElement);
1878
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
1881
1879
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1882
1880
  setDragState({
1883
1881
  dragHandleId,
@@ -2006,10 +2004,10 @@ function useWindowSplitterResizeHandlerBehavior({
2006
2004
  {
2007
2005
  event.preventDefault();
2008
2006
  const groupId = handleElement.getAttribute("data-panel-group-id");
2009
- assert(groupId);
2007
+ assert(groupId, `No group element found for id "${groupId}"`);
2010
2008
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2011
2009
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2012
- assert(index !== null);
2010
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2013
2011
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2014
2012
  const nextHandle = handles[nextIndex];
2015
2013
  nextHandle.focus();
@@ -2078,7 +2076,7 @@ function PanelResizeHandle({
2078
2076
  return;
2079
2077
  }
2080
2078
  const element = elementRef.current;
2081
- assert(element);
2079
+ assert(element, "Element ref not attached");
2082
2080
  const setResizeHandlerState = (action, isActive, event) => {
2083
2081
  if (isActive) {
2084
2082
  switch (action) {
@@ -303,7 +303,7 @@ function compare(a, b) {
303
303
  b = ancestors.b.pop();
304
304
  common_ancestor = a;
305
305
  }
306
- assert(common_ancestor);
306
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
307
307
  const z_indexes = {
308
308
  a: get_z_index(find_stacking_context(ancestors.a)),
309
309
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -361,7 +361,7 @@ function find_stacking_context(nodes) {
361
361
  let i = nodes.length;
362
362
  while (i--) {
363
363
  const node = nodes[i];
364
- assert(node);
364
+ assert(node, "Missing node");
365
365
  if (creates_stacking_context(node)) return node;
366
366
  }
367
367
  return null;
@@ -648,7 +648,7 @@ function updateResizeHandlerStates(action, event) {
648
648
  });
649
649
  }
650
650
 
651
- function assert(expectedCondition, message = "Assertion failed!") {
651
+ function assert(expectedCondition, message) {
652
652
  if (!expectedCondition) {
653
653
  console.error(message);
654
654
  throw Error(message);
@@ -679,7 +679,7 @@ function resizePanel({
679
679
  size
680
680
  }) {
681
681
  const panelConstraints = panelConstraintsArray[panelIndex];
682
- assert(panelConstraints != null);
682
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
683
683
  let {
684
684
  collapsedSize = 0,
685
685
  collapsible,
@@ -717,8 +717,8 @@ function adjustLayoutByDelta({
717
717
  }
718
718
  const nextLayout = [...prevLayout];
719
719
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
720
- assert(firstPivotIndex != null);
721
- assert(secondPivotIndex != null);
720
+ assert(firstPivotIndex != null, "Invalid first pivot index");
721
+ assert(secondPivotIndex != null, "Invalid second pivot index");
722
722
  let deltaApplied = 0;
723
723
 
724
724
  //const DEBUG = [];
@@ -744,19 +744,18 @@ function adjustLayoutByDelta({
744
744
  // Check if we should expand a collapsed panel
745
745
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
746
746
  const panelConstraints = panelConstraintsArray[index];
747
- assert(panelConstraints);
747
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
748
+ const {
749
+ collapsedSize = 0,
750
+ collapsible,
751
+ minSize = 0
752
+ } = panelConstraints;
748
753
 
749
754
  //DEBUG.push(`edge case check 1: ${index}`);
750
755
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
751
- if (panelConstraints.collapsible) {
756
+ if (collapsible) {
752
757
  const prevSize = prevLayout[index];
753
- assert(prevSize != null);
754
- const panelConstraints = panelConstraintsArray[index];
755
- assert(panelConstraints);
756
- const {
757
- collapsedSize = 0,
758
- minSize = 0
759
- } = panelConstraints;
758
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
760
759
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
761
760
  const localDelta = minSize - prevSize;
762
761
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -773,22 +772,18 @@ function adjustLayoutByDelta({
773
772
  // Check if we should collapse a panel at its minimum size
774
773
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
775
774
  const panelConstraints = panelConstraintsArray[index];
776
- assert(panelConstraints);
775
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
777
776
  const {
778
- collapsible
777
+ collapsedSize = 0,
778
+ collapsible,
779
+ minSize = 0
779
780
  } = panelConstraints;
780
781
 
781
782
  //DEBUG.push(`edge case check 2: ${index}`);
782
783
  //DEBUG.push(` -> collapsible? ${collapsible}`);
783
784
  if (collapsible) {
784
785
  const prevSize = prevLayout[index];
785
- assert(prevSize != null);
786
- const panelConstraints = panelConstraintsArray[index];
787
- assert(panelConstraints);
788
- const {
789
- collapsedSize = 0,
790
- minSize = 0
791
- } = panelConstraints;
786
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
792
787
  if (fuzzyNumbersEqual(prevSize, minSize)) {
793
788
  const localDelta = prevSize - collapsedSize;
794
789
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -818,7 +813,7 @@ function adjustLayoutByDelta({
818
813
  //DEBUG.push("pre calc...");
819
814
  while (true) {
820
815
  const prevSize = prevLayout[index];
821
- assert(prevSize != null);
816
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
822
817
  const maxSafeSize = resizePanel({
823
818
  panelConstraints: panelConstraintsArray,
824
819
  panelIndex: index,
@@ -849,7 +844,7 @@ function adjustLayoutByDelta({
849
844
  while (index >= 0 && index < panelConstraintsArray.length) {
850
845
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
851
846
  const prevSize = prevLayout[index];
852
- assert(prevSize != null);
847
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
853
848
  const unsafeSize = prevSize - deltaRemaining;
854
849
  const safeSize = resizePanel({
855
850
  panelConstraints: panelConstraintsArray,
@@ -886,7 +881,7 @@ function adjustLayoutByDelta({
886
881
  // Now distribute the applied delta to the panels in the other direction
887
882
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
888
883
  const prevSize = prevLayout[pivotIndex];
889
- assert(prevSize != null);
884
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
890
885
  const unsafeSize = prevSize + deltaApplied;
891
886
  const safeSize = resizePanel({
892
887
  panelConstraints: panelConstraintsArray,
@@ -904,7 +899,7 @@ function adjustLayoutByDelta({
904
899
  let index = pivotIndex;
905
900
  while (index >= 0 && index < panelConstraintsArray.length) {
906
901
  const prevSize = nextLayout[index];
907
- assert(prevSize != null);
902
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
908
903
  const unsafeSize = prevSize + deltaRemaining;
909
904
  const safeSize = resizePanel({
910
905
  panelConstraints: panelConstraintsArray,
@@ -950,7 +945,7 @@ function calculateAriaValues({
950
945
  let totalMinSize = 0;
951
946
  let totalMaxSize = 0;
952
947
  const firstIndex = pivotIndices[0];
953
- assert(firstIndex != null);
948
+ assert(firstIndex != null, "No pivot index found");
954
949
 
955
950
  // A panel's effective min/max sizes also need to account for other panel's sizes.
956
951
  panelsArray.forEach((panelData, index) => {
@@ -1059,7 +1054,7 @@ function useWindowSplitterPanelGroupBehavior({
1059
1054
  const resizeHandleElement = resizeHandleElements[index];
1060
1055
  if (resizeHandleElement == null) ; else {
1061
1056
  const panelData = panelDataArray[index];
1062
- assert(panelData);
1057
+ assert(panelData, `No panel data found for index "${index}"`);
1063
1058
  resizeHandleElement.setAttribute("aria-controls", panelData.id);
1064
1059
  resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
1065
1060
  resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
@@ -1080,17 +1075,17 @@ function useWindowSplitterPanelGroupBehavior({
1080
1075
  return;
1081
1076
  }
1082
1077
  const eagerValues = eagerValuesRef.current;
1083
- assert(eagerValues);
1078
+ assert(eagerValues, `Eager values not found`);
1084
1079
  const {
1085
1080
  panelDataArray
1086
1081
  } = eagerValues;
1087
1082
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1088
1083
  assert(groupElement != null, `No group found for id "${groupId}"`);
1089
1084
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1090
- assert(handles);
1085
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1091
1086
  const cleanupFunctions = handles.map(handle => {
1092
1087
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1093
- assert(handleId);
1088
+ assert(handleId, `Resize handle element has no handle id attribute`);
1094
1089
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1095
1090
  if (idBefore == null || idAfter == null) {
1096
1091
  return () => {};
@@ -1106,7 +1101,7 @@ function useWindowSplitterPanelGroupBehavior({
1106
1101
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1107
1102
  if (index >= 0) {
1108
1103
  const panelData = panelDataArray[index];
1109
- assert(panelData);
1104
+ assert(panelData, `No panel data found for index ${index}`);
1110
1105
  const size = layout[index];
1111
1106
  const {
1112
1107
  collapsedSize = 0,
@@ -1165,15 +1160,15 @@ function getResizeEventCursorPosition(direction, event) {
1165
1160
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1166
1161
  const isHorizontal = direction === "horizontal";
1167
1162
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1168
- assert(handleElement);
1163
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1169
1164
  const groupId = handleElement.getAttribute("data-panel-group-id");
1170
- assert(groupId);
1165
+ assert(groupId, `Resize handle element has no group id attribute`);
1171
1166
  let {
1172
1167
  initialCursorPosition
1173
1168
  } = initialDragState;
1174
1169
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1175
1170
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1176
- assert(groupElement);
1171
+ assert(groupElement, `No group element found for id "${groupId}"`);
1177
1172
  const groupRect = groupElement.getBoundingClientRect();
1178
1173
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1179
1174
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1234,7 +1229,7 @@ function calculateUnsafeDefaultLayout({
1234
1229
  // Distribute default sizes first
1235
1230
  for (let index = 0; index < panelDataArray.length; index++) {
1236
1231
  const panelConstraints = panelConstraintsArray[index];
1237
- assert(panelConstraints);
1232
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
1238
1233
  const {
1239
1234
  defaultSize
1240
1235
  } = panelConstraints;
@@ -1248,7 +1243,7 @@ function calculateUnsafeDefaultLayout({
1248
1243
  // Remaining size should be distributed evenly between panels without default sizes
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;
@@ -1268,7 +1263,7 @@ function calculateUnsafeDefaultLayout({
1268
1263
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1269
1264
  layout.forEach((size, index) => {
1270
1265
  const panelData = panelsArray[index];
1271
- assert(panelData);
1266
+ assert(panelData, `Panel data not found for index ${index}`);
1272
1267
  const {
1273
1268
  callbacks,
1274
1269
  constraints,
@@ -1458,7 +1453,7 @@ function validatePanelGroupLayout({
1458
1453
  } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
1459
1454
  for (let index = 0; index < panelConstraints.length; index++) {
1460
1455
  const unsafeSize = nextLayout[index];
1461
- assert(unsafeSize != null);
1456
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1462
1457
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1463
1458
  nextLayout[index] = safeSize;
1464
1459
  }
@@ -1468,7 +1463,7 @@ function validatePanelGroupLayout({
1468
1463
  // First pass: Validate the proposed layout given each panel's constraints
1469
1464
  for (let index = 0; index < panelConstraints.length; index++) {
1470
1465
  const unsafeSize = nextLayout[index];
1471
- assert(unsafeSize != null);
1466
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1472
1467
  const safeSize = resizePanel({
1473
1468
  panelConstraints,
1474
1469
  panelIndex: index,
@@ -1485,7 +1480,7 @@ function validatePanelGroupLayout({
1485
1480
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1486
1481
  for (let index = 0; index < panelConstraints.length; index++) {
1487
1482
  const prevSize = nextLayout[index];
1488
- assert(prevSize != null);
1483
+ assert(prevSize != null, `No layout data found for index ${index}`);
1489
1484
  const unsafeSize = prevSize + remainingSize;
1490
1485
  const safeSize = resizePanel({
1491
1486
  panelConstraints,
@@ -1651,7 +1646,7 @@ function PanelGroupWithForwardedRef({
1651
1646
  panelSize,
1652
1647
  pivotIndices
1653
1648
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1654
- assert(panelSize != null);
1649
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1655
1650
  if (panelSize !== collapsedSize) {
1656
1651
  // Store size before collapse;
1657
1652
  // This is the size that gets restored if the expand() API is used.
@@ -1728,7 +1723,7 @@ function PanelGroupWithForwardedRef({
1728
1723
  const {
1729
1724
  panelSize
1730
1725
  } = panelDataHelper(panelDataArray, panelData, layout);
1731
- assert(panelSize != null);
1726
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1732
1727
  return panelSize;
1733
1728
  }, []);
1734
1729
 
@@ -1772,7 +1767,7 @@ function PanelGroupWithForwardedRef({
1772
1767
  collapsible,
1773
1768
  panelSize
1774
1769
  } = panelDataHelper(panelDataArray, panelData, layout);
1775
- assert(panelSize != null);
1770
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1776
1771
  return !collapsible || panelSize > collapsedSize;
1777
1772
  }, []);
1778
1773
  const registerPanel = useCallback(panelData => {
@@ -1939,7 +1934,7 @@ function PanelGroupWithForwardedRef({
1939
1934
  panelSize,
1940
1935
  pivotIndices
1941
1936
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1942
- assert(panelSize != null);
1937
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1943
1938
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1944
1939
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1945
1940
  const nextLayout = adjustLayoutByDelta({
@@ -1976,7 +1971,10 @@ function PanelGroupWithForwardedRef({
1976
1971
  const {
1977
1972
  panelSize: prevPanelSize
1978
1973
  } = panelDataHelper(panelDataArray, panelData, layout);
1979
- assert(prevPanelSize != null);
1974
+ if (prevPanelSize == null) {
1975
+ // It's possible that the panels in this group have changed since the last render
1976
+ return;
1977
+ }
1980
1978
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1981
1979
  if (prevCollapsedSize !== nextCollapsedSize) {
1982
1980
  resizePanel(panelData, nextCollapsedSize);
@@ -1998,7 +1996,7 @@ function PanelGroupWithForwardedRef({
1998
1996
  return;
1999
1997
  }
2000
1998
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
2001
- assert(handleElement);
1999
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
2002
2000
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
2003
2001
  setDragState({
2004
2002
  dragHandleId,
@@ -2127,10 +2125,10 @@ function useWindowSplitterResizeHandlerBehavior({
2127
2125
  {
2128
2126
  event.preventDefault();
2129
2127
  const groupId = handleElement.getAttribute("data-panel-group-id");
2130
- assert(groupId);
2128
+ assert(groupId, `No group element found for id "${groupId}"`);
2131
2129
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2132
2130
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
2133
- assert(index !== null);
2131
+ assert(index !== null, `No resize element found for id "${handleId}"`);
2134
2132
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
2135
2133
  const nextHandle = handles[nextIndex];
2136
2134
  nextHandle.focus();
@@ -2202,7 +2200,7 @@ function PanelResizeHandle({
2202
2200
  return;
2203
2201
  }
2204
2202
  const element = elementRef.current;
2205
- assert(element);
2203
+ assert(element, "Element ref not attached");
2206
2204
  const setResizeHandlerState = (action, isActive, event) => {
2207
2205
  if (isActive) {
2208
2206
  switch (action) {