react-resizable-panels 2.0.10 → 2.0.12

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.
@@ -222,15 +222,15 @@ function isTouchEvent(event) {
222
222
  function getResizeEventCoordinates(event) {
223
223
  if (isMouseEvent(event)) {
224
224
  return {
225
- x: event.pageX,
226
- y: event.pageY
225
+ x: event.clientX,
226
+ y: event.clientY
227
227
  };
228
228
  } else if (isTouchEvent(event)) {
229
229
  const touch = event.touches[0];
230
- if (touch && touch.pageX && touch.pageY) {
230
+ if (touch && touch.clientX && touch.clientY) {
231
231
  return {
232
- x: touch.pageX,
233
- y: touch.pageY
232
+ x: touch.clientX,
233
+ y: touch.clientY
234
234
  };
235
235
  }
236
236
  }
@@ -645,6 +645,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
645
645
  return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
646
646
  }
647
647
 
648
+ function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
649
+ if (actual.length !== expected.length) {
650
+ return false;
651
+ }
652
+ for (let index = 0; index < actual.length; index++) {
653
+ const actualSize = actual[index];
654
+ const expectedSize = expected[index];
655
+ if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
656
+ return false;
657
+ }
658
+ }
659
+ return true;
660
+ }
661
+
648
662
  // Panel size must be in percentages; pixel values should be pre-converted
649
663
  function resizePanel({
650
664
  panelConstraints: panelConstraintsArray,
@@ -680,26 +694,29 @@ function resizePanel({
680
694
  // All units must be in percentages; pixel values should be pre-converted
681
695
  function adjustLayoutByDelta({
682
696
  delta,
683
- layout: prevLayout,
697
+ initialLayout,
684
698
  panelConstraints: panelConstraintsArray,
685
699
  pivotIndices,
700
+ prevLayout,
686
701
  trigger
687
702
  }) {
688
703
  if (fuzzyNumbersEqual(delta, 0)) {
689
- return prevLayout;
704
+ return initialLayout;
690
705
  }
691
- const nextLayout = [...prevLayout];
706
+ const nextLayout = [...initialLayout];
692
707
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
693
708
  assert(firstPivotIndex != null, "Invalid first pivot index");
694
709
  assert(secondPivotIndex != null, "Invalid second pivot index");
695
710
  let deltaApplied = 0;
696
711
 
697
- //const DEBUG = [];
698
- //DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
699
- //DEBUG.push(` delta: ${delta}`);
700
- //DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
701
- //DEBUG.push(` trigger: ${trigger}`);
702
- //DEBUG.push("");
712
+ // const DEBUG = [];
713
+ // DEBUG.push(`adjustLayoutByDelta()`);
714
+ // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
715
+ // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
716
+ // DEBUG.push(` delta: ${delta}`);
717
+ // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
718
+ // DEBUG.push(` trigger: ${trigger}`);
719
+ // DEBUG.push("");
703
720
 
704
721
  // A resizing panel affects the panels before or after it.
705
722
  //
@@ -724,18 +741,18 @@ function adjustLayoutByDelta({
724
741
  minSize = 0
725
742
  } = panelConstraints;
726
743
 
727
- //DEBUG.push(`edge case check 1: ${index}`);
728
- //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
744
+ // DEBUG.push(`edge case check 1: ${index}`);
745
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
729
746
  if (collapsible) {
730
- const prevSize = prevLayout[index];
747
+ const prevSize = initialLayout[index];
731
748
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
732
749
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
733
750
  const localDelta = minSize - prevSize;
734
- //DEBUG.push(` -> expand delta: ${localDelta}`);
751
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
735
752
 
736
753
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
737
754
  delta = delta < 0 ? 0 - localDelta : localDelta;
738
- //DEBUG.push(` -> delta: ${delta}`);
755
+ // DEBUG.push(` -> delta: ${delta}`);
739
756
  }
740
757
  }
741
758
  }
@@ -752,24 +769,24 @@ function adjustLayoutByDelta({
752
769
  minSize = 0
753
770
  } = panelConstraints;
754
771
 
755
- //DEBUG.push(`edge case check 2: ${index}`);
756
- //DEBUG.push(` -> collapsible? ${collapsible}`);
772
+ // DEBUG.push(`edge case check 2: ${index}`);
773
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
757
774
  if (collapsible) {
758
- const prevSize = prevLayout[index];
775
+ const prevSize = initialLayout[index];
759
776
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
760
777
  if (fuzzyNumbersEqual(prevSize, minSize)) {
761
778
  const localDelta = prevSize - collapsedSize;
762
- //DEBUG.push(` -> expand delta: ${localDelta}`);
779
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
763
780
 
764
781
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
765
782
  delta = delta < 0 ? 0 - localDelta : localDelta;
766
- //DEBUG.push(` -> delta: ${delta}`);
783
+ // DEBUG.push(` -> delta: ${delta}`);
767
784
  }
768
785
  }
769
786
  }
770
787
  }
771
788
  }
772
- //DEBUG.push("");
789
+ // DEBUG.push("");
773
790
  }
774
791
 
775
792
  {
@@ -783,9 +800,9 @@ function adjustLayoutByDelta({
783
800
  let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
784
801
  let maxAvailableDelta = 0;
785
802
 
786
- //DEBUG.push("pre calc...");
803
+ // DEBUG.push("pre calc...");
787
804
  while (true) {
788
- const prevSize = prevLayout[index];
805
+ const prevSize = initialLayout[index];
789
806
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
790
807
  const maxSafeSize = resizePanel({
791
808
  panelConstraints: panelConstraintsArray,
@@ -793,7 +810,7 @@ function adjustLayoutByDelta({
793
810
  size: 100
794
811
  });
795
812
  const delta = maxSafeSize - prevSize;
796
- //DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
813
+ // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
797
814
 
798
815
  maxAvailableDelta += delta;
799
816
  index += increment;
@@ -802,11 +819,11 @@ function adjustLayoutByDelta({
802
819
  }
803
820
  }
804
821
 
805
- //DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
822
+ // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
806
823
  const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
807
824
  delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
808
- //DEBUG.push(` -> adjusted delta: ${delta}`);
809
- //DEBUG.push("");
825
+ // DEBUG.push(` -> adjusted delta: ${delta}`);
826
+ // DEBUG.push("");
810
827
  }
811
828
 
812
829
  {
@@ -816,7 +833,7 @@ function adjustLayoutByDelta({
816
833
  let index = pivotIndex;
817
834
  while (index >= 0 && index < panelConstraintsArray.length) {
818
835
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
819
- const prevSize = prevLayout[index];
836
+ const prevSize = initialLayout[index];
820
837
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
821
838
  const unsafeSize = prevSize - deltaRemaining;
822
839
  const safeSize = resizePanel({
@@ -840,20 +857,22 @@ function adjustLayoutByDelta({
840
857
  }
841
858
  }
842
859
  }
843
- //DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
844
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
845
- //DEBUG.push("");
860
+ // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
861
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
862
+ // DEBUG.push("");
846
863
 
847
864
  // If we were unable to resize any of the panels panels, return the previous state.
848
865
  // This will essentially bailout and ignore e.g. drags past a panel's boundaries
849
- if (fuzzyNumbersEqual(deltaApplied, 0)) {
850
- //console.log(DEBUG.join("\n"));
866
+ if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
867
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
868
+ // console.log(DEBUG.join("\n"));
869
+
851
870
  return prevLayout;
852
871
  }
853
872
  {
854
873
  // Now distribute the applied delta to the panels in the other direction
855
874
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
856
- const prevSize = prevLayout[pivotIndex];
875
+ const prevSize = initialLayout[pivotIndex];
857
876
  assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
858
877
  const unsafeSize = prevSize + deltaApplied;
859
878
  const safeSize = resizePanel({
@@ -894,17 +913,23 @@ function adjustLayoutByDelta({
894
913
  }
895
914
  }
896
915
  }
897
- //DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
898
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
899
- //DEBUG.push("");
916
+ // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
917
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
918
+ // DEBUG.push("");
900
919
 
901
920
  const totalSize = nextLayout.reduce((total, size) => size + total, 0);
902
- //DEBUG.push(`total size: ${totalSize}`);
903
- //console.log(DEBUG.join("\n"));
921
+ // DEBUG.push(`total size: ${totalSize}`);
904
922
 
923
+ // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
924
+ // In that case, fall back to our most recent valid layout
905
925
  if (!fuzzyNumbersEqual(totalSize, 100)) {
926
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
927
+ // console.log(DEBUG.join("\n"));
928
+
906
929
  return prevLayout;
907
930
  }
931
+
932
+ // console.log(DEBUG.join("\n"));
908
933
  return nextLayout;
909
934
  }
910
935
 
@@ -1011,9 +1036,10 @@ function useWindowSplitterPanelGroupBehavior({
1011
1036
  if (size != null && collapsible) {
1012
1037
  const nextLayout = adjustLayoutByDelta({
1013
1038
  delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1014
- layout,
1039
+ initialLayout: layout,
1015
1040
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
1016
1041
  pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
1042
+ prevLayout: layout,
1017
1043
  trigger: "keyboard"
1018
1044
  });
1019
1045
  if (layout !== nextLayout) {
@@ -1590,9 +1616,10 @@ function PanelGroupWithForwardedRef({
1590
1616
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1591
1617
  const nextLayout = adjustLayoutByDelta({
1592
1618
  delta,
1593
- layout: prevLayout,
1619
+ initialLayout: prevLayout,
1594
1620
  panelConstraints: panelConstraintsArray,
1595
1621
  pivotIndices,
1622
+ prevLayout,
1596
1623
  trigger: "imperative-api"
1597
1624
  });
1598
1625
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1632,9 +1659,10 @@ function PanelGroupWithForwardedRef({
1632
1659
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1633
1660
  const nextLayout = adjustLayoutByDelta({
1634
1661
  delta,
1635
- layout: prevLayout,
1662
+ initialLayout: prevLayout,
1636
1663
  panelConstraints: panelConstraintsArray,
1637
1664
  pivotIndices,
1665
+ prevLayout,
1638
1666
  trigger: "imperative-api"
1639
1667
  });
1640
1668
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1760,9 +1788,10 @@ function PanelGroupWithForwardedRef({
1760
1788
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1761
1789
  const nextLayout = adjustLayoutByDelta({
1762
1790
  delta,
1763
- layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1791
+ initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1764
1792
  panelConstraints,
1765
1793
  pivotIndices,
1794
+ prevLayout,
1766
1795
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1767
1796
  });
1768
1797
  const layoutChanged = !compareLayouts(prevLayout, nextLayout);
@@ -1818,9 +1847,10 @@ function PanelGroupWithForwardedRef({
1818
1847
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1819
1848
  const nextLayout = adjustLayoutByDelta({
1820
1849
  delta,
1821
- layout: prevLayout,
1850
+ initialLayout: prevLayout,
1822
1851
  panelConstraints: panelConstraintsArray,
1823
1852
  pivotIndices,
1853
+ prevLayout,
1824
1854
  trigger: "imperative-api"
1825
1855
  });
1826
1856
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -249,15 +249,15 @@ function isTouchEvent(event) {
249
249
  function getResizeEventCoordinates(event) {
250
250
  if (isMouseEvent(event)) {
251
251
  return {
252
- x: event.pageX,
253
- y: event.pageY
252
+ x: event.clientX,
253
+ y: event.clientY
254
254
  };
255
255
  } else if (isTouchEvent(event)) {
256
256
  const touch = event.touches[0];
257
- if (touch && touch.pageX && touch.pageY) {
257
+ if (touch && touch.clientX && touch.clientY) {
258
258
  return {
259
- x: touch.pageX,
260
- y: touch.pageY
259
+ x: touch.clientX,
260
+ y: touch.clientY
261
261
  };
262
262
  }
263
263
  }
@@ -672,6 +672,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
672
672
  return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
673
673
  }
674
674
 
675
+ function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
676
+ if (actual.length !== expected.length) {
677
+ return false;
678
+ }
679
+ for (let index = 0; index < actual.length; index++) {
680
+ const actualSize = actual[index];
681
+ const expectedSize = expected[index];
682
+ if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
683
+ return false;
684
+ }
685
+ }
686
+ return true;
687
+ }
688
+
675
689
  // Panel size must be in percentages; pixel values should be pre-converted
676
690
  function resizePanel({
677
691
  panelConstraints: panelConstraintsArray,
@@ -707,26 +721,29 @@ function resizePanel({
707
721
  // All units must be in percentages; pixel values should be pre-converted
708
722
  function adjustLayoutByDelta({
709
723
  delta,
710
- layout: prevLayout,
724
+ initialLayout,
711
725
  panelConstraints: panelConstraintsArray,
712
726
  pivotIndices,
727
+ prevLayout,
713
728
  trigger
714
729
  }) {
715
730
  if (fuzzyNumbersEqual(delta, 0)) {
716
- return prevLayout;
731
+ return initialLayout;
717
732
  }
718
- const nextLayout = [...prevLayout];
733
+ const nextLayout = [...initialLayout];
719
734
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
720
735
  assert(firstPivotIndex != null, "Invalid first pivot index");
721
736
  assert(secondPivotIndex != null, "Invalid second pivot index");
722
737
  let deltaApplied = 0;
723
738
 
724
- //const DEBUG = [];
725
- //DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
726
- //DEBUG.push(` delta: ${delta}`);
727
- //DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
728
- //DEBUG.push(` trigger: ${trigger}`);
729
- //DEBUG.push("");
739
+ // const DEBUG = [];
740
+ // DEBUG.push(`adjustLayoutByDelta()`);
741
+ // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
742
+ // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
743
+ // DEBUG.push(` delta: ${delta}`);
744
+ // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
745
+ // DEBUG.push(` trigger: ${trigger}`);
746
+ // DEBUG.push("");
730
747
 
731
748
  // A resizing panel affects the panels before or after it.
732
749
  //
@@ -751,18 +768,18 @@ function adjustLayoutByDelta({
751
768
  minSize = 0
752
769
  } = panelConstraints;
753
770
 
754
- //DEBUG.push(`edge case check 1: ${index}`);
755
- //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
771
+ // DEBUG.push(`edge case check 1: ${index}`);
772
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
756
773
  if (collapsible) {
757
- const prevSize = prevLayout[index];
774
+ const prevSize = initialLayout[index];
758
775
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
759
776
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
760
777
  const localDelta = minSize - prevSize;
761
- //DEBUG.push(` -> expand delta: ${localDelta}`);
778
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
762
779
 
763
780
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
764
781
  delta = delta < 0 ? 0 - localDelta : localDelta;
765
- //DEBUG.push(` -> delta: ${delta}`);
782
+ // DEBUG.push(` -> delta: ${delta}`);
766
783
  }
767
784
  }
768
785
  }
@@ -779,24 +796,24 @@ function adjustLayoutByDelta({
779
796
  minSize = 0
780
797
  } = panelConstraints;
781
798
 
782
- //DEBUG.push(`edge case check 2: ${index}`);
783
- //DEBUG.push(` -> collapsible? ${collapsible}`);
799
+ // DEBUG.push(`edge case check 2: ${index}`);
800
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
784
801
  if (collapsible) {
785
- const prevSize = prevLayout[index];
802
+ const prevSize = initialLayout[index];
786
803
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
787
804
  if (fuzzyNumbersEqual(prevSize, minSize)) {
788
805
  const localDelta = prevSize - collapsedSize;
789
- //DEBUG.push(` -> expand delta: ${localDelta}`);
806
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
790
807
 
791
808
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
792
809
  delta = delta < 0 ? 0 - localDelta : localDelta;
793
- //DEBUG.push(` -> delta: ${delta}`);
810
+ // DEBUG.push(` -> delta: ${delta}`);
794
811
  }
795
812
  }
796
813
  }
797
814
  }
798
815
  }
799
- //DEBUG.push("");
816
+ // DEBUG.push("");
800
817
  }
801
818
 
802
819
  {
@@ -810,9 +827,9 @@ function adjustLayoutByDelta({
810
827
  let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
811
828
  let maxAvailableDelta = 0;
812
829
 
813
- //DEBUG.push("pre calc...");
830
+ // DEBUG.push("pre calc...");
814
831
  while (true) {
815
- const prevSize = prevLayout[index];
832
+ const prevSize = initialLayout[index];
816
833
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
817
834
  const maxSafeSize = resizePanel({
818
835
  panelConstraints: panelConstraintsArray,
@@ -820,7 +837,7 @@ function adjustLayoutByDelta({
820
837
  size: 100
821
838
  });
822
839
  const delta = maxSafeSize - prevSize;
823
- //DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
840
+ // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
824
841
 
825
842
  maxAvailableDelta += delta;
826
843
  index += increment;
@@ -829,11 +846,11 @@ function adjustLayoutByDelta({
829
846
  }
830
847
  }
831
848
 
832
- //DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
849
+ // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
833
850
  const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
834
851
  delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
835
- //DEBUG.push(` -> adjusted delta: ${delta}`);
836
- //DEBUG.push("");
852
+ // DEBUG.push(` -> adjusted delta: ${delta}`);
853
+ // DEBUG.push("");
837
854
  }
838
855
 
839
856
  {
@@ -843,7 +860,7 @@ function adjustLayoutByDelta({
843
860
  let index = pivotIndex;
844
861
  while (index >= 0 && index < panelConstraintsArray.length) {
845
862
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
846
- const prevSize = prevLayout[index];
863
+ const prevSize = initialLayout[index];
847
864
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
848
865
  const unsafeSize = prevSize - deltaRemaining;
849
866
  const safeSize = resizePanel({
@@ -867,20 +884,22 @@ function adjustLayoutByDelta({
867
884
  }
868
885
  }
869
886
  }
870
- //DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
871
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
872
- //DEBUG.push("");
887
+ // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
888
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
889
+ // DEBUG.push("");
873
890
 
874
891
  // If we were unable to resize any of the panels panels, return the previous state.
875
892
  // This will essentially bailout and ignore e.g. drags past a panel's boundaries
876
- if (fuzzyNumbersEqual(deltaApplied, 0)) {
877
- //console.log(DEBUG.join("\n"));
893
+ if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
894
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
895
+ // console.log(DEBUG.join("\n"));
896
+
878
897
  return prevLayout;
879
898
  }
880
899
  {
881
900
  // Now distribute the applied delta to the panels in the other direction
882
901
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
883
- const prevSize = prevLayout[pivotIndex];
902
+ const prevSize = initialLayout[pivotIndex];
884
903
  assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
885
904
  const unsafeSize = prevSize + deltaApplied;
886
905
  const safeSize = resizePanel({
@@ -921,17 +940,23 @@ function adjustLayoutByDelta({
921
940
  }
922
941
  }
923
942
  }
924
- //DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
925
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
926
- //DEBUG.push("");
943
+ // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
944
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
945
+ // DEBUG.push("");
927
946
 
928
947
  const totalSize = nextLayout.reduce((total, size) => size + total, 0);
929
- //DEBUG.push(`total size: ${totalSize}`);
930
- //console.log(DEBUG.join("\n"));
948
+ // DEBUG.push(`total size: ${totalSize}`);
931
949
 
950
+ // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
951
+ // In that case, fall back to our most recent valid layout
932
952
  if (!fuzzyNumbersEqual(totalSize, 100)) {
953
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
954
+ // console.log(DEBUG.join("\n"));
955
+
933
956
  return prevLayout;
934
957
  }
958
+
959
+ // console.log(DEBUG.join("\n"));
935
960
  return nextLayout;
936
961
  }
937
962
 
@@ -1111,9 +1136,10 @@ function useWindowSplitterPanelGroupBehavior({
1111
1136
  if (size != null && collapsible) {
1112
1137
  const nextLayout = adjustLayoutByDelta({
1113
1138
  delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1114
- layout,
1139
+ initialLayout: layout,
1115
1140
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
1116
1141
  pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
1142
+ prevLayout: layout,
1117
1143
  trigger: "keyboard"
1118
1144
  });
1119
1145
  if (layout !== nextLayout) {
@@ -1655,9 +1681,10 @@ function PanelGroupWithForwardedRef({
1655
1681
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1656
1682
  const nextLayout = adjustLayoutByDelta({
1657
1683
  delta,
1658
- layout: prevLayout,
1684
+ initialLayout: prevLayout,
1659
1685
  panelConstraints: panelConstraintsArray,
1660
1686
  pivotIndices,
1687
+ prevLayout,
1661
1688
  trigger: "imperative-api"
1662
1689
  });
1663
1690
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1697,9 +1724,10 @@ function PanelGroupWithForwardedRef({
1697
1724
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1698
1725
  const nextLayout = adjustLayoutByDelta({
1699
1726
  delta,
1700
- layout: prevLayout,
1727
+ initialLayout: prevLayout,
1701
1728
  panelConstraints: panelConstraintsArray,
1702
1729
  pivotIndices,
1730
+ prevLayout,
1703
1731
  trigger: "imperative-api"
1704
1732
  });
1705
1733
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1881,9 +1909,10 @@ function PanelGroupWithForwardedRef({
1881
1909
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1882
1910
  const nextLayout = adjustLayoutByDelta({
1883
1911
  delta,
1884
- layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1912
+ initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1885
1913
  panelConstraints,
1886
1914
  pivotIndices,
1915
+ prevLayout,
1887
1916
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1888
1917
  });
1889
1918
  const layoutChanged = !compareLayouts(prevLayout, nextLayout);
@@ -1939,9 +1968,10 @@ function PanelGroupWithForwardedRef({
1939
1968
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1940
1969
  const nextLayout = adjustLayoutByDelta({
1941
1970
  delta,
1942
- layout: prevLayout,
1971
+ initialLayout: prevLayout,
1943
1972
  panelConstraints: panelConstraintsArray,
1944
1973
  pivotIndices,
1974
+ prevLayout,
1945
1975
  trigger: "imperative-api"
1946
1976
  });
1947
1977
  if (!compareLayouts(prevLayout, nextLayout)) {