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
@@ -289,7 +289,7 @@ function compare(a, b) {
289
289
  b = ancestors.b.pop();
290
290
  common_ancestor = a;
291
291
  }
292
- assert(common_ancestor);
292
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
293
293
  const z_indexes = {
294
294
  a: get_z_index(find_stacking_context(ancestors.a)),
295
295
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -347,7 +347,7 @@ function find_stacking_context(nodes) {
347
347
  let i = nodes.length;
348
348
  while (i--) {
349
349
  const node = nodes[i];
350
- assert(node);
350
+ assert(node, "Missing node");
351
351
  if (creates_stacking_context(node)) return node;
352
352
  }
353
353
  return null;
@@ -634,7 +634,7 @@ function updateResizeHandlerStates(action, event) {
634
634
  });
635
635
  }
636
636
 
637
- function assert(expectedCondition, message = "Assertion failed!") {
637
+ function assert(expectedCondition, message) {
638
638
  if (!expectedCondition) {
639
639
  console.error(message);
640
640
  throw Error(message);
@@ -665,7 +665,7 @@ function resizePanel({
665
665
  size
666
666
  }) {
667
667
  const panelConstraints = panelConstraintsArray[panelIndex];
668
- assert(panelConstraints != null);
668
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
669
669
  let {
670
670
  collapsedSize = 0,
671
671
  collapsible,
@@ -703,8 +703,8 @@ function adjustLayoutByDelta({
703
703
  }
704
704
  const nextLayout = [...prevLayout];
705
705
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
706
- assert(firstPivotIndex != null);
707
- assert(secondPivotIndex != null);
706
+ assert(firstPivotIndex != null, "Invalid first pivot index");
707
+ assert(secondPivotIndex != null, "Invalid second pivot index");
708
708
  let deltaApplied = 0;
709
709
 
710
710
  //const DEBUG = [];
@@ -730,19 +730,18 @@ function adjustLayoutByDelta({
730
730
  // Check if we should expand a collapsed panel
731
731
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
732
732
  const panelConstraints = panelConstraintsArray[index];
733
- assert(panelConstraints);
733
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
734
+ const {
735
+ collapsedSize = 0,
736
+ collapsible,
737
+ minSize = 0
738
+ } = panelConstraints;
734
739
 
735
740
  //DEBUG.push(`edge case check 1: ${index}`);
736
741
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
737
- if (panelConstraints.collapsible) {
742
+ if (collapsible) {
738
743
  const prevSize = prevLayout[index];
739
- assert(prevSize != null);
740
- const panelConstraints = panelConstraintsArray[index];
741
- assert(panelConstraints);
742
- const {
743
- collapsedSize = 0,
744
- minSize = 0
745
- } = panelConstraints;
744
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
746
745
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
747
746
  const localDelta = minSize - prevSize;
748
747
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -759,22 +758,18 @@ function adjustLayoutByDelta({
759
758
  // Check if we should collapse a panel at its minimum size
760
759
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
761
760
  const panelConstraints = panelConstraintsArray[index];
762
- assert(panelConstraints);
761
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
763
762
  const {
764
- collapsible
763
+ collapsedSize = 0,
764
+ collapsible,
765
+ minSize = 0
765
766
  } = panelConstraints;
766
767
 
767
768
  //DEBUG.push(`edge case check 2: ${index}`);
768
769
  //DEBUG.push(` -> collapsible? ${collapsible}`);
769
770
  if (collapsible) {
770
771
  const prevSize = prevLayout[index];
771
- assert(prevSize != null);
772
- const panelConstraints = panelConstraintsArray[index];
773
- assert(panelConstraints);
774
- const {
775
- collapsedSize = 0,
776
- minSize = 0
777
- } = panelConstraints;
772
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
778
773
  if (fuzzyNumbersEqual(prevSize, minSize)) {
779
774
  const localDelta = prevSize - collapsedSize;
780
775
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -804,7 +799,7 @@ function adjustLayoutByDelta({
804
799
  //DEBUG.push("pre calc...");
805
800
  while (true) {
806
801
  const prevSize = prevLayout[index];
807
- assert(prevSize != null);
802
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
808
803
  const maxSafeSize = resizePanel({
809
804
  panelConstraints: panelConstraintsArray,
810
805
  panelIndex: index,
@@ -835,7 +830,7 @@ function adjustLayoutByDelta({
835
830
  while (index >= 0 && index < panelConstraintsArray.length) {
836
831
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
837
832
  const prevSize = prevLayout[index];
838
- assert(prevSize != null);
833
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
839
834
  const unsafeSize = prevSize - deltaRemaining;
840
835
  const safeSize = resizePanel({
841
836
  panelConstraints: panelConstraintsArray,
@@ -872,7 +867,7 @@ function adjustLayoutByDelta({
872
867
  // Now distribute the applied delta to the panels in the other direction
873
868
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
874
869
  const prevSize = prevLayout[pivotIndex];
875
- assert(prevSize != null);
870
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
876
871
  const unsafeSize = prevSize + deltaApplied;
877
872
  const safeSize = resizePanel({
878
873
  panelConstraints: panelConstraintsArray,
@@ -890,7 +885,7 @@ function adjustLayoutByDelta({
890
885
  let index = pivotIndex;
891
886
  while (index >= 0 && index < panelConstraintsArray.length) {
892
887
  const prevSize = nextLayout[index];
893
- assert(prevSize != null);
888
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
894
889
  const unsafeSize = prevSize + deltaRemaining;
895
890
  const safeSize = resizePanel({
896
891
  panelConstraints: panelConstraintsArray,
@@ -993,17 +988,17 @@ function useWindowSplitterPanelGroupBehavior({
993
988
  return;
994
989
  }
995
990
  const eagerValues = eagerValuesRef.current;
996
- assert(eagerValues);
991
+ assert(eagerValues, `Eager values not found`);
997
992
  const {
998
993
  panelDataArray
999
994
  } = eagerValues;
1000
995
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1001
996
  assert(groupElement != null, `No group found for id "${groupId}"`);
1002
997
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1003
- assert(handles);
998
+ assert(handles, `No resize handles found for group id "${groupId}"`);
1004
999
  const cleanupFunctions = handles.map(handle => {
1005
1000
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
1006
- assert(handleId);
1001
+ assert(handleId, `Resize handle element has no handle id attribute`);
1007
1002
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1008
1003
  if (idBefore == null || idAfter == null) {
1009
1004
  return () => {};
@@ -1019,7 +1014,7 @@ function useWindowSplitterPanelGroupBehavior({
1019
1014
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
1020
1015
  if (index >= 0) {
1021
1016
  const panelData = panelDataArray[index];
1022
- assert(panelData);
1017
+ assert(panelData, `No panel data found for index ${index}`);
1023
1018
  const size = layout[index];
1024
1019
  const {
1025
1020
  collapsedSize = 0,
@@ -1078,15 +1073,15 @@ function getResizeEventCursorPosition(direction, event) {
1078
1073
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1079
1074
  const isHorizontal = direction === "horizontal";
1080
1075
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1081
- assert(handleElement);
1076
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1082
1077
  const groupId = handleElement.getAttribute("data-panel-group-id");
1083
- assert(groupId);
1078
+ assert(groupId, `Resize handle element has no group id attribute`);
1084
1079
  let {
1085
1080
  initialCursorPosition
1086
1081
  } = initialDragState;
1087
1082
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1088
1083
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1089
- assert(groupElement);
1084
+ assert(groupElement, `No group element found for id "${groupId}"`);
1090
1085
  const groupRect = groupElement.getBoundingClientRect();
1091
1086
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1092
1087
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1140,7 +1135,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
1140
1135
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1141
1136
  layout.forEach((size, index) => {
1142
1137
  const panelData = panelsArray[index];
1143
- assert(panelData);
1138
+ assert(panelData, `Panel data not found for index ${index}`);
1144
1139
  const {
1145
1140
  callbacks,
1146
1141
  constraints,
@@ -1324,7 +1319,7 @@ function validatePanelGroupLayout({
1324
1319
  } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
1325
1320
  for (let index = 0; index < panelConstraints.length; index++) {
1326
1321
  const unsafeSize = nextLayout[index];
1327
- assert(unsafeSize != null);
1322
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1328
1323
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1329
1324
  nextLayout[index] = safeSize;
1330
1325
  }
@@ -1334,7 +1329,7 @@ function validatePanelGroupLayout({
1334
1329
  // First pass: Validate the proposed layout given each panel's constraints
1335
1330
  for (let index = 0; index < panelConstraints.length; index++) {
1336
1331
  const unsafeSize = nextLayout[index];
1337
- assert(unsafeSize != null);
1332
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1338
1333
  const safeSize = resizePanel({
1339
1334
  panelConstraints,
1340
1335
  panelIndex: index,
@@ -1351,7 +1346,7 @@ function validatePanelGroupLayout({
1351
1346
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1352
1347
  for (let index = 0; index < panelConstraints.length; index++) {
1353
1348
  const prevSize = nextLayout[index];
1354
- assert(prevSize != null);
1349
+ assert(prevSize != null, `No layout data found for index ${index}`);
1355
1350
  const unsafeSize = prevSize + remainingSize;
1356
1351
  const safeSize = resizePanel({
1357
1352
  panelConstraints,
@@ -1509,7 +1504,7 @@ function PanelGroupWithForwardedRef({
1509
1504
  panelSize,
1510
1505
  pivotIndices
1511
1506
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1512
- assert(panelSize != null);
1507
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1513
1508
  if (panelSize !== collapsedSize) {
1514
1509
  // Store size before collapse;
1515
1510
  // This is the size that gets restored if the expand() API is used.
@@ -1586,7 +1581,7 @@ function PanelGroupWithForwardedRef({
1586
1581
  const {
1587
1582
  panelSize
1588
1583
  } = panelDataHelper(panelDataArray, panelData, layout);
1589
- assert(panelSize != null);
1584
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1590
1585
  return panelSize;
1591
1586
  }, []);
1592
1587
 
@@ -1630,7 +1625,7 @@ function PanelGroupWithForwardedRef({
1630
1625
  collapsible,
1631
1626
  panelSize
1632
1627
  } = panelDataHelper(panelDataArray, panelData, layout);
1633
- assert(panelSize != null);
1628
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1634
1629
  return !collapsible || panelSize > collapsedSize;
1635
1630
  }, []);
1636
1631
  const registerPanel = useCallback(panelData => {
@@ -1741,7 +1736,7 @@ function PanelGroupWithForwardedRef({
1741
1736
  panelSize,
1742
1737
  pivotIndices
1743
1738
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1744
- assert(panelSize != null);
1739
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1745
1740
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1746
1741
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1747
1742
  const nextLayout = adjustLayoutByDelta({
@@ -1778,7 +1773,10 @@ function PanelGroupWithForwardedRef({
1778
1773
  const {
1779
1774
  panelSize: prevPanelSize
1780
1775
  } = panelDataHelper(panelDataArray, panelData, layout);
1781
- assert(prevPanelSize != null);
1776
+ if (prevPanelSize == null) {
1777
+ // It's possible that the panels in this group have changed since the last render
1778
+ return;
1779
+ }
1782
1780
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1783
1781
  if (prevCollapsedSize !== nextCollapsedSize) {
1784
1782
  resizePanel(panelData, nextCollapsedSize);
@@ -1800,7 +1798,7 @@ function PanelGroupWithForwardedRef({
1800
1798
  return;
1801
1799
  }
1802
1800
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1803
- assert(handleElement);
1801
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
1804
1802
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1805
1803
  setDragState({
1806
1804
  dragHandleId,
@@ -1929,10 +1927,10 @@ function useWindowSplitterResizeHandlerBehavior({
1929
1927
  {
1930
1928
  event.preventDefault();
1931
1929
  const groupId = handleElement.getAttribute("data-panel-group-id");
1932
- assert(groupId);
1930
+ assert(groupId, `No group element found for id "${groupId}"`);
1933
1931
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1934
1932
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
1935
- assert(index !== null);
1933
+ assert(index !== null, `No resize element found for id "${handleId}"`);
1936
1934
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
1937
1935
  const nextHandle = handles[nextIndex];
1938
1936
  nextHandle.focus();
@@ -2001,7 +1999,7 @@ function PanelResizeHandle({
2001
1999
  return;
2002
2000
  }
2003
2001
  const element = elementRef.current;
2004
- assert(element);
2002
+ assert(element, "Element ref not attached");
2005
2003
  const setResizeHandlerState = (action, isActive, event) => {
2006
2004
  if (isActive) {
2007
2005
  switch (action) {
@@ -265,7 +265,7 @@ function compare(a, b) {
265
265
  b = ancestors.b.pop();
266
266
  common_ancestor = a;
267
267
  }
268
- assert(common_ancestor);
268
+ assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
269
269
  const z_indexes = {
270
270
  a: get_z_index(find_stacking_context(ancestors.a)),
271
271
  b: get_z_index(find_stacking_context(ancestors.b))
@@ -323,7 +323,7 @@ function find_stacking_context(nodes) {
323
323
  let i = nodes.length;
324
324
  while (i--) {
325
325
  const node = nodes[i];
326
- assert(node);
326
+ assert(node, "Missing node");
327
327
  if (creates_stacking_context(node)) return node;
328
328
  }
329
329
  return null;
@@ -610,7 +610,7 @@ function updateResizeHandlerStates(action, event) {
610
610
  });
611
611
  }
612
612
 
613
- function assert(expectedCondition, message = "Assertion failed!") {
613
+ function assert(expectedCondition, message) {
614
614
  if (!expectedCondition) {
615
615
  console.error(message);
616
616
  throw Error(message);
@@ -641,7 +641,7 @@ function resizePanel({
641
641
  size
642
642
  }) {
643
643
  const panelConstraints = panelConstraintsArray[panelIndex];
644
- assert(panelConstraints != null);
644
+ assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
645
645
  let {
646
646
  collapsedSize = 0,
647
647
  collapsible,
@@ -679,8 +679,8 @@ function adjustLayoutByDelta({
679
679
  }
680
680
  const nextLayout = [...prevLayout];
681
681
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
682
- assert(firstPivotIndex != null);
683
- assert(secondPivotIndex != null);
682
+ assert(firstPivotIndex != null, "Invalid first pivot index");
683
+ assert(secondPivotIndex != null, "Invalid second pivot index");
684
684
  let deltaApplied = 0;
685
685
 
686
686
  //const DEBUG = [];
@@ -706,19 +706,18 @@ function adjustLayoutByDelta({
706
706
  // Check if we should expand a collapsed panel
707
707
  const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
708
708
  const panelConstraints = panelConstraintsArray[index];
709
- assert(panelConstraints);
709
+ assert(panelConstraints, `Panel constraints not found for index ${index}`);
710
+ const {
711
+ collapsedSize = 0,
712
+ collapsible,
713
+ minSize = 0
714
+ } = panelConstraints;
710
715
 
711
716
  //DEBUG.push(`edge case check 1: ${index}`);
712
717
  //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
713
- if (panelConstraints.collapsible) {
718
+ if (collapsible) {
714
719
  const prevSize = prevLayout[index];
715
- assert(prevSize != null);
716
- const panelConstraints = panelConstraintsArray[index];
717
- assert(panelConstraints);
718
- const {
719
- collapsedSize = 0,
720
- minSize = 0
721
- } = panelConstraints;
720
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
722
721
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
723
722
  const localDelta = minSize - prevSize;
724
723
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -735,22 +734,18 @@ function adjustLayoutByDelta({
735
734
  // Check if we should collapse a panel at its minimum size
736
735
  const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
737
736
  const panelConstraints = panelConstraintsArray[index];
738
- assert(panelConstraints);
737
+ assert(panelConstraints, `No panel constraints found for index ${index}`);
739
738
  const {
740
- collapsible
739
+ collapsedSize = 0,
740
+ collapsible,
741
+ minSize = 0
741
742
  } = panelConstraints;
742
743
 
743
744
  //DEBUG.push(`edge case check 2: ${index}`);
744
745
  //DEBUG.push(` -> collapsible? ${collapsible}`);
745
746
  if (collapsible) {
746
747
  const prevSize = prevLayout[index];
747
- assert(prevSize != null);
748
- const panelConstraints = panelConstraintsArray[index];
749
- assert(panelConstraints);
750
- const {
751
- collapsedSize = 0,
752
- minSize = 0
753
- } = panelConstraints;
748
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
754
749
  if (fuzzyNumbersEqual(prevSize, minSize)) {
755
750
  const localDelta = prevSize - collapsedSize;
756
751
  //DEBUG.push(` -> expand delta: ${localDelta}`);
@@ -780,7 +775,7 @@ function adjustLayoutByDelta({
780
775
  //DEBUG.push("pre calc...");
781
776
  while (true) {
782
777
  const prevSize = prevLayout[index];
783
- assert(prevSize != null);
778
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
784
779
  const maxSafeSize = resizePanel({
785
780
  panelConstraints: panelConstraintsArray,
786
781
  panelIndex: index,
@@ -811,7 +806,7 @@ function adjustLayoutByDelta({
811
806
  while (index >= 0 && index < panelConstraintsArray.length) {
812
807
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
813
808
  const prevSize = prevLayout[index];
814
- assert(prevSize != null);
809
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
815
810
  const unsafeSize = prevSize - deltaRemaining;
816
811
  const safeSize = resizePanel({
817
812
  panelConstraints: panelConstraintsArray,
@@ -848,7 +843,7 @@ function adjustLayoutByDelta({
848
843
  // Now distribute the applied delta to the panels in the other direction
849
844
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
850
845
  const prevSize = prevLayout[pivotIndex];
851
- assert(prevSize != null);
846
+ assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
852
847
  const unsafeSize = prevSize + deltaApplied;
853
848
  const safeSize = resizePanel({
854
849
  panelConstraints: panelConstraintsArray,
@@ -866,7 +861,7 @@ function adjustLayoutByDelta({
866
861
  let index = pivotIndex;
867
862
  while (index >= 0 && index < panelConstraintsArray.length) {
868
863
  const prevSize = nextLayout[index];
869
- assert(prevSize != null);
864
+ assert(prevSize != null, `Previous layout not found for panel index ${index}`);
870
865
  const unsafeSize = prevSize + deltaRemaining;
871
866
  const safeSize = resizePanel({
872
867
  panelConstraints: panelConstraintsArray,
@@ -969,17 +964,17 @@ function useWindowSplitterPanelGroupBehavior({
969
964
  return;
970
965
  }
971
966
  const eagerValues = eagerValuesRef.current;
972
- assert(eagerValues);
967
+ assert(eagerValues, `Eager values not found`);
973
968
  const {
974
969
  panelDataArray
975
970
  } = eagerValues;
976
971
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
977
972
  assert(groupElement != null, `No group found for id "${groupId}"`);
978
973
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
979
- assert(handles);
974
+ assert(handles, `No resize handles found for group id "${groupId}"`);
980
975
  const cleanupFunctions = handles.map(handle => {
981
976
  const handleId = handle.getAttribute("data-panel-resize-handle-id");
982
- assert(handleId);
977
+ assert(handleId, `Resize handle element has no handle id attribute`);
983
978
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
984
979
  if (idBefore == null || idAfter == null) {
985
980
  return () => {};
@@ -995,7 +990,7 @@ function useWindowSplitterPanelGroupBehavior({
995
990
  const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
996
991
  if (index >= 0) {
997
992
  const panelData = panelDataArray[index];
998
- assert(panelData);
993
+ assert(panelData, `No panel data found for index ${index}`);
999
994
  const size = layout[index];
1000
995
  const {
1001
996
  collapsedSize = 0,
@@ -1054,15 +1049,15 @@ function getResizeEventCursorPosition(direction, event) {
1054
1049
  function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
1055
1050
  const isHorizontal = direction === "horizontal";
1056
1051
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1057
- assert(handleElement);
1052
+ assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1058
1053
  const groupId = handleElement.getAttribute("data-panel-group-id");
1059
- assert(groupId);
1054
+ assert(groupId, `Resize handle element has no group id attribute`);
1060
1055
  let {
1061
1056
  initialCursorPosition
1062
1057
  } = initialDragState;
1063
1058
  const cursorPosition = getResizeEventCursorPosition(direction, event);
1064
1059
  const groupElement = getPanelGroupElement(groupId, panelGroupElement);
1065
- assert(groupElement);
1060
+ assert(groupElement, `No group element found for id "${groupId}"`);
1066
1061
  const groupRect = groupElement.getBoundingClientRect();
1067
1062
  const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
1068
1063
  const offsetPixels = cursorPosition - initialCursorPosition;
@@ -1116,7 +1111,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
1116
1111
  function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
1117
1112
  layout.forEach((size, index) => {
1118
1113
  const panelData = panelsArray[index];
1119
- assert(panelData);
1114
+ assert(panelData, `Panel data not found for index ${index}`);
1120
1115
  const {
1121
1116
  callbacks,
1122
1117
  constraints,
@@ -1300,7 +1295,7 @@ function validatePanelGroupLayout({
1300
1295
  } else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
1301
1296
  for (let index = 0; index < panelConstraints.length; index++) {
1302
1297
  const unsafeSize = nextLayout[index];
1303
- assert(unsafeSize != null);
1298
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1304
1299
  const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
1305
1300
  nextLayout[index] = safeSize;
1306
1301
  }
@@ -1310,7 +1305,7 @@ function validatePanelGroupLayout({
1310
1305
  // First pass: Validate the proposed layout given each panel's constraints
1311
1306
  for (let index = 0; index < panelConstraints.length; index++) {
1312
1307
  const unsafeSize = nextLayout[index];
1313
- assert(unsafeSize != null);
1308
+ assert(unsafeSize != null, `No layout data found for index ${index}`);
1314
1309
  const safeSize = resizePanel({
1315
1310
  panelConstraints,
1316
1311
  panelIndex: index,
@@ -1327,7 +1322,7 @@ function validatePanelGroupLayout({
1327
1322
  if (!fuzzyNumbersEqual(remainingSize, 0)) {
1328
1323
  for (let index = 0; index < panelConstraints.length; index++) {
1329
1324
  const prevSize = nextLayout[index];
1330
- assert(prevSize != null);
1325
+ assert(prevSize != null, `No layout data found for index ${index}`);
1331
1326
  const unsafeSize = prevSize + remainingSize;
1332
1327
  const safeSize = resizePanel({
1333
1328
  panelConstraints,
@@ -1485,7 +1480,7 @@ function PanelGroupWithForwardedRef({
1485
1480
  panelSize,
1486
1481
  pivotIndices
1487
1482
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1488
- assert(panelSize != null);
1483
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1489
1484
  if (panelSize !== collapsedSize) {
1490
1485
  // Store size before collapse;
1491
1486
  // This is the size that gets restored if the expand() API is used.
@@ -1562,7 +1557,7 @@ function PanelGroupWithForwardedRef({
1562
1557
  const {
1563
1558
  panelSize
1564
1559
  } = panelDataHelper(panelDataArray, panelData, layout);
1565
- assert(panelSize != null);
1560
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1566
1561
  return panelSize;
1567
1562
  }, []);
1568
1563
 
@@ -1606,7 +1601,7 @@ function PanelGroupWithForwardedRef({
1606
1601
  collapsible,
1607
1602
  panelSize
1608
1603
  } = panelDataHelper(panelDataArray, panelData, layout);
1609
- assert(panelSize != null);
1604
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1610
1605
  return !collapsible || panelSize > collapsedSize;
1611
1606
  }, []);
1612
1607
  const registerPanel = useCallback(panelData => {
@@ -1717,7 +1712,7 @@ function PanelGroupWithForwardedRef({
1717
1712
  panelSize,
1718
1713
  pivotIndices
1719
1714
  } = panelDataHelper(panelDataArray, panelData, prevLayout);
1720
- assert(panelSize != null);
1715
+ assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1721
1716
  const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
1722
1717
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1723
1718
  const nextLayout = adjustLayoutByDelta({
@@ -1754,7 +1749,10 @@ function PanelGroupWithForwardedRef({
1754
1749
  const {
1755
1750
  panelSize: prevPanelSize
1756
1751
  } = panelDataHelper(panelDataArray, panelData, layout);
1757
- assert(prevPanelSize != null);
1752
+ if (prevPanelSize == null) {
1753
+ // It's possible that the panels in this group have changed since the last render
1754
+ return;
1755
+ }
1758
1756
  if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
1759
1757
  if (prevCollapsedSize !== nextCollapsedSize) {
1760
1758
  resizePanel(panelData, nextCollapsedSize);
@@ -1776,7 +1774,7 @@ function PanelGroupWithForwardedRef({
1776
1774
  return;
1777
1775
  }
1778
1776
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
1779
- assert(handleElement);
1777
+ assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
1780
1778
  const initialCursorPosition = getResizeEventCursorPosition(direction, event);
1781
1779
  setDragState({
1782
1780
  dragHandleId,
@@ -1905,10 +1903,10 @@ function useWindowSplitterResizeHandlerBehavior({
1905
1903
  {
1906
1904
  event.preventDefault();
1907
1905
  const groupId = handleElement.getAttribute("data-panel-group-id");
1908
- assert(groupId);
1906
+ assert(groupId, `No group element found for id "${groupId}"`);
1909
1907
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1910
1908
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
1911
- assert(index !== null);
1909
+ assert(index !== null, `No resize element found for id "${handleId}"`);
1912
1910
  const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
1913
1911
  const nextHandle = handles[nextIndex];
1914
1912
  nextHandle.focus();
@@ -1977,7 +1975,7 @@ function PanelResizeHandle({
1977
1975
  return;
1978
1976
  }
1979
1977
  const element = elementRef.current;
1980
- assert(element);
1978
+ assert(element, "Element ref not attached");
1981
1979
  const setResizeHandlerState = (action, isActive, event) => {
1982
1980
  if (isActive) {
1983
1981
  switch (action) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",