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.
@@ -235,15 +235,15 @@ function isTouchEvent(event) {
235
235
  function getResizeEventCoordinates(event) {
236
236
  if (isMouseEvent(event)) {
237
237
  return {
238
- x: event.pageX,
239
- y: event.pageY
238
+ x: event.clientX,
239
+ y: event.clientY
240
240
  };
241
241
  } else if (isTouchEvent(event)) {
242
242
  const touch = event.touches[0];
243
- if (touch && touch.pageX && touch.pageY) {
243
+ if (touch && touch.clientX && touch.clientY) {
244
244
  return {
245
- x: touch.pageX,
246
- y: touch.pageY
245
+ x: touch.clientX,
246
+ y: touch.clientY
247
247
  };
248
248
  }
249
249
  }
@@ -658,6 +658,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
658
658
  return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
659
659
  }
660
660
 
661
+ function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
662
+ if (actual.length !== expected.length) {
663
+ return false;
664
+ }
665
+ for (let index = 0; index < actual.length; index++) {
666
+ const actualSize = actual[index];
667
+ const expectedSize = expected[index];
668
+ if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
669
+ return false;
670
+ }
671
+ }
672
+ return true;
673
+ }
674
+
661
675
  // Panel size must be in percentages; pixel values should be pre-converted
662
676
  function resizePanel({
663
677
  panelConstraints: panelConstraintsArray,
@@ -693,26 +707,29 @@ function resizePanel({
693
707
  // All units must be in percentages; pixel values should be pre-converted
694
708
  function adjustLayoutByDelta({
695
709
  delta,
696
- layout: prevLayout,
710
+ initialLayout,
697
711
  panelConstraints: panelConstraintsArray,
698
712
  pivotIndices,
713
+ prevLayout,
699
714
  trigger
700
715
  }) {
701
716
  if (fuzzyNumbersEqual(delta, 0)) {
702
- return prevLayout;
717
+ return initialLayout;
703
718
  }
704
- const nextLayout = [...prevLayout];
719
+ const nextLayout = [...initialLayout];
705
720
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
706
721
  assert(firstPivotIndex != null, "Invalid first pivot index");
707
722
  assert(secondPivotIndex != null, "Invalid second pivot index");
708
723
  let deltaApplied = 0;
709
724
 
710
- //const DEBUG = [];
711
- //DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
712
- //DEBUG.push(` delta: ${delta}`);
713
- //DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
714
- //DEBUG.push(` trigger: ${trigger}`);
715
- //DEBUG.push("");
725
+ // const DEBUG = [];
726
+ // DEBUG.push(`adjustLayoutByDelta()`);
727
+ // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
728
+ // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
729
+ // DEBUG.push(` delta: ${delta}`);
730
+ // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
731
+ // DEBUG.push(` trigger: ${trigger}`);
732
+ // DEBUG.push("");
716
733
 
717
734
  // A resizing panel affects the panels before or after it.
718
735
  //
@@ -737,18 +754,18 @@ function adjustLayoutByDelta({
737
754
  minSize = 0
738
755
  } = panelConstraints;
739
756
 
740
- //DEBUG.push(`edge case check 1: ${index}`);
741
- //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
757
+ // DEBUG.push(`edge case check 1: ${index}`);
758
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
742
759
  if (collapsible) {
743
- const prevSize = prevLayout[index];
760
+ const prevSize = initialLayout[index];
744
761
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
745
762
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
746
763
  const localDelta = minSize - prevSize;
747
- //DEBUG.push(` -> expand delta: ${localDelta}`);
764
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
748
765
 
749
766
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
750
767
  delta = delta < 0 ? 0 - localDelta : localDelta;
751
- //DEBUG.push(` -> delta: ${delta}`);
768
+ // DEBUG.push(` -> delta: ${delta}`);
752
769
  }
753
770
  }
754
771
  }
@@ -765,24 +782,24 @@ function adjustLayoutByDelta({
765
782
  minSize = 0
766
783
  } = panelConstraints;
767
784
 
768
- //DEBUG.push(`edge case check 2: ${index}`);
769
- //DEBUG.push(` -> collapsible? ${collapsible}`);
785
+ // DEBUG.push(`edge case check 2: ${index}`);
786
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
770
787
  if (collapsible) {
771
- const prevSize = prevLayout[index];
788
+ const prevSize = initialLayout[index];
772
789
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
773
790
  if (fuzzyNumbersEqual(prevSize, minSize)) {
774
791
  const localDelta = prevSize - collapsedSize;
775
- //DEBUG.push(` -> expand delta: ${localDelta}`);
792
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
776
793
 
777
794
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
778
795
  delta = delta < 0 ? 0 - localDelta : localDelta;
779
- //DEBUG.push(` -> delta: ${delta}`);
796
+ // DEBUG.push(` -> delta: ${delta}`);
780
797
  }
781
798
  }
782
799
  }
783
800
  }
784
801
  }
785
- //DEBUG.push("");
802
+ // DEBUG.push("");
786
803
  }
787
804
 
788
805
  {
@@ -796,9 +813,9 @@ function adjustLayoutByDelta({
796
813
  let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
797
814
  let maxAvailableDelta = 0;
798
815
 
799
- //DEBUG.push("pre calc...");
816
+ // DEBUG.push("pre calc...");
800
817
  while (true) {
801
- const prevSize = prevLayout[index];
818
+ const prevSize = initialLayout[index];
802
819
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
803
820
  const maxSafeSize = resizePanel({
804
821
  panelConstraints: panelConstraintsArray,
@@ -806,7 +823,7 @@ function adjustLayoutByDelta({
806
823
  size: 100
807
824
  });
808
825
  const delta = maxSafeSize - prevSize;
809
- //DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
826
+ // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
810
827
 
811
828
  maxAvailableDelta += delta;
812
829
  index += increment;
@@ -815,11 +832,11 @@ function adjustLayoutByDelta({
815
832
  }
816
833
  }
817
834
 
818
- //DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
835
+ // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
819
836
  const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
820
837
  delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
821
- //DEBUG.push(` -> adjusted delta: ${delta}`);
822
- //DEBUG.push("");
838
+ // DEBUG.push(` -> adjusted delta: ${delta}`);
839
+ // DEBUG.push("");
823
840
  }
824
841
 
825
842
  {
@@ -829,7 +846,7 @@ function adjustLayoutByDelta({
829
846
  let index = pivotIndex;
830
847
  while (index >= 0 && index < panelConstraintsArray.length) {
831
848
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
832
- const prevSize = prevLayout[index];
849
+ const prevSize = initialLayout[index];
833
850
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
834
851
  const unsafeSize = prevSize - deltaRemaining;
835
852
  const safeSize = resizePanel({
@@ -853,20 +870,22 @@ function adjustLayoutByDelta({
853
870
  }
854
871
  }
855
872
  }
856
- //DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
857
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
858
- //DEBUG.push("");
873
+ // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
874
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
875
+ // DEBUG.push("");
859
876
 
860
877
  // If we were unable to resize any of the panels panels, return the previous state.
861
878
  // This will essentially bailout and ignore e.g. drags past a panel's boundaries
862
- if (fuzzyNumbersEqual(deltaApplied, 0)) {
863
- //console.log(DEBUG.join("\n"));
879
+ if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
880
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
881
+ // console.log(DEBUG.join("\n"));
882
+
864
883
  return prevLayout;
865
884
  }
866
885
  {
867
886
  // Now distribute the applied delta to the panels in the other direction
868
887
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
869
- const prevSize = prevLayout[pivotIndex];
888
+ const prevSize = initialLayout[pivotIndex];
870
889
  assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
871
890
  const unsafeSize = prevSize + deltaApplied;
872
891
  const safeSize = resizePanel({
@@ -907,17 +926,23 @@ function adjustLayoutByDelta({
907
926
  }
908
927
  }
909
928
  }
910
- //DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
911
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
912
- //DEBUG.push("");
929
+ // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
930
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
931
+ // DEBUG.push("");
913
932
 
914
933
  const totalSize = nextLayout.reduce((total, size) => size + total, 0);
915
- //DEBUG.push(`total size: ${totalSize}`);
916
- //console.log(DEBUG.join("\n"));
934
+ // DEBUG.push(`total size: ${totalSize}`);
917
935
 
936
+ // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
937
+ // In that case, fall back to our most recent valid layout
918
938
  if (!fuzzyNumbersEqual(totalSize, 100)) {
939
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
940
+ // console.log(DEBUG.join("\n"));
941
+
919
942
  return prevLayout;
920
943
  }
944
+
945
+ // console.log(DEBUG.join("\n"));
921
946
  return nextLayout;
922
947
  }
923
948
 
@@ -1024,9 +1049,10 @@ function useWindowSplitterPanelGroupBehavior({
1024
1049
  if (size != null && collapsible) {
1025
1050
  const nextLayout = adjustLayoutByDelta({
1026
1051
  delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1027
- layout,
1052
+ initialLayout: layout,
1028
1053
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
1029
1054
  pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
1055
+ prevLayout: layout,
1030
1056
  trigger: "keyboard"
1031
1057
  });
1032
1058
  if (layout !== nextLayout) {
@@ -1513,9 +1539,10 @@ function PanelGroupWithForwardedRef({
1513
1539
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1514
1540
  const nextLayout = adjustLayoutByDelta({
1515
1541
  delta,
1516
- layout: prevLayout,
1542
+ initialLayout: prevLayout,
1517
1543
  panelConstraints: panelConstraintsArray,
1518
1544
  pivotIndices,
1545
+ prevLayout,
1519
1546
  trigger: "imperative-api"
1520
1547
  });
1521
1548
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1555,9 +1582,10 @@ function PanelGroupWithForwardedRef({
1555
1582
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1556
1583
  const nextLayout = adjustLayoutByDelta({
1557
1584
  delta,
1558
- layout: prevLayout,
1585
+ initialLayout: prevLayout,
1559
1586
  panelConstraints: panelConstraintsArray,
1560
1587
  pivotIndices,
1588
+ prevLayout,
1561
1589
  trigger: "imperative-api"
1562
1590
  });
1563
1591
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1683,9 +1711,10 @@ function PanelGroupWithForwardedRef({
1683
1711
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1684
1712
  const nextLayout = adjustLayoutByDelta({
1685
1713
  delta,
1686
- layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1714
+ initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1687
1715
  panelConstraints,
1688
1716
  pivotIndices,
1717
+ prevLayout,
1689
1718
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1690
1719
  });
1691
1720
  const layoutChanged = !compareLayouts(prevLayout, nextLayout);
@@ -1741,9 +1770,10 @@ function PanelGroupWithForwardedRef({
1741
1770
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1742
1771
  const nextLayout = adjustLayoutByDelta({
1743
1772
  delta,
1744
- layout: prevLayout,
1773
+ initialLayout: prevLayout,
1745
1774
  panelConstraints: panelConstraintsArray,
1746
1775
  pivotIndices,
1776
+ prevLayout,
1747
1777
  trigger: "imperative-api"
1748
1778
  });
1749
1779
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -211,15 +211,15 @@ function isTouchEvent(event) {
211
211
  function getResizeEventCoordinates(event) {
212
212
  if (isMouseEvent(event)) {
213
213
  return {
214
- x: event.pageX,
215
- y: event.pageY
214
+ x: event.clientX,
215
+ y: event.clientY
216
216
  };
217
217
  } else if (isTouchEvent(event)) {
218
218
  const touch = event.touches[0];
219
- if (touch && touch.pageX && touch.pageY) {
219
+ if (touch && touch.clientX && touch.clientY) {
220
220
  return {
221
- x: touch.pageX,
222
- y: touch.pageY
221
+ x: touch.clientX,
222
+ y: touch.clientY
223
223
  };
224
224
  }
225
225
  }
@@ -634,6 +634,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
634
634
  return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
635
635
  }
636
636
 
637
+ function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
638
+ if (actual.length !== expected.length) {
639
+ return false;
640
+ }
641
+ for (let index = 0; index < actual.length; index++) {
642
+ const actualSize = actual[index];
643
+ const expectedSize = expected[index];
644
+ if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
645
+ return false;
646
+ }
647
+ }
648
+ return true;
649
+ }
650
+
637
651
  // Panel size must be in percentages; pixel values should be pre-converted
638
652
  function resizePanel({
639
653
  panelConstraints: panelConstraintsArray,
@@ -669,26 +683,29 @@ function resizePanel({
669
683
  // All units must be in percentages; pixel values should be pre-converted
670
684
  function adjustLayoutByDelta({
671
685
  delta,
672
- layout: prevLayout,
686
+ initialLayout,
673
687
  panelConstraints: panelConstraintsArray,
674
688
  pivotIndices,
689
+ prevLayout,
675
690
  trigger
676
691
  }) {
677
692
  if (fuzzyNumbersEqual(delta, 0)) {
678
- return prevLayout;
693
+ return initialLayout;
679
694
  }
680
- const nextLayout = [...prevLayout];
695
+ const nextLayout = [...initialLayout];
681
696
  const [firstPivotIndex, secondPivotIndex] = pivotIndices;
682
697
  assert(firstPivotIndex != null, "Invalid first pivot index");
683
698
  assert(secondPivotIndex != null, "Invalid second pivot index");
684
699
  let deltaApplied = 0;
685
700
 
686
- //const DEBUG = [];
687
- //DEBUG.push(`adjustLayoutByDelta() ${prevLayout.join(", ")}`);
688
- //DEBUG.push(` delta: ${delta}`);
689
- //DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
690
- //DEBUG.push(` trigger: ${trigger}`);
691
- //DEBUG.push("");
701
+ // const DEBUG = [];
702
+ // DEBUG.push(`adjustLayoutByDelta()`);
703
+ // DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
704
+ // DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
705
+ // DEBUG.push(` delta: ${delta}`);
706
+ // DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
707
+ // DEBUG.push(` trigger: ${trigger}`);
708
+ // DEBUG.push("");
692
709
 
693
710
  // A resizing panel affects the panels before or after it.
694
711
  //
@@ -713,18 +730,18 @@ function adjustLayoutByDelta({
713
730
  minSize = 0
714
731
  } = panelConstraints;
715
732
 
716
- //DEBUG.push(`edge case check 1: ${index}`);
717
- //DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
733
+ // DEBUG.push(`edge case check 1: ${index}`);
734
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
718
735
  if (collapsible) {
719
- const prevSize = prevLayout[index];
736
+ const prevSize = initialLayout[index];
720
737
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
721
738
  if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
722
739
  const localDelta = minSize - prevSize;
723
- //DEBUG.push(` -> expand delta: ${localDelta}`);
740
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
724
741
 
725
742
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
726
743
  delta = delta < 0 ? 0 - localDelta : localDelta;
727
- //DEBUG.push(` -> delta: ${delta}`);
744
+ // DEBUG.push(` -> delta: ${delta}`);
728
745
  }
729
746
  }
730
747
  }
@@ -741,24 +758,24 @@ function adjustLayoutByDelta({
741
758
  minSize = 0
742
759
  } = panelConstraints;
743
760
 
744
- //DEBUG.push(`edge case check 2: ${index}`);
745
- //DEBUG.push(` -> collapsible? ${collapsible}`);
761
+ // DEBUG.push(`edge case check 2: ${index}`);
762
+ // DEBUG.push(` -> collapsible? ${collapsible}`);
746
763
  if (collapsible) {
747
- const prevSize = prevLayout[index];
764
+ const prevSize = initialLayout[index];
748
765
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
749
766
  if (fuzzyNumbersEqual(prevSize, minSize)) {
750
767
  const localDelta = prevSize - collapsedSize;
751
- //DEBUG.push(` -> expand delta: ${localDelta}`);
768
+ // DEBUG.push(` -> expand delta: ${localDelta}`);
752
769
 
753
770
  if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
754
771
  delta = delta < 0 ? 0 - localDelta : localDelta;
755
- //DEBUG.push(` -> delta: ${delta}`);
772
+ // DEBUG.push(` -> delta: ${delta}`);
756
773
  }
757
774
  }
758
775
  }
759
776
  }
760
777
  }
761
- //DEBUG.push("");
778
+ // DEBUG.push("");
762
779
  }
763
780
 
764
781
  {
@@ -772,9 +789,9 @@ function adjustLayoutByDelta({
772
789
  let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
773
790
  let maxAvailableDelta = 0;
774
791
 
775
- //DEBUG.push("pre calc...");
792
+ // DEBUG.push("pre calc...");
776
793
  while (true) {
777
- const prevSize = prevLayout[index];
794
+ const prevSize = initialLayout[index];
778
795
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
779
796
  const maxSafeSize = resizePanel({
780
797
  panelConstraints: panelConstraintsArray,
@@ -782,7 +799,7 @@ function adjustLayoutByDelta({
782
799
  size: 100
783
800
  });
784
801
  const delta = maxSafeSize - prevSize;
785
- //DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
802
+ // DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
786
803
 
787
804
  maxAvailableDelta += delta;
788
805
  index += increment;
@@ -791,11 +808,11 @@ function adjustLayoutByDelta({
791
808
  }
792
809
  }
793
810
 
794
- //DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
811
+ // DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
795
812
  const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
796
813
  delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
797
- //DEBUG.push(` -> adjusted delta: ${delta}`);
798
- //DEBUG.push("");
814
+ // DEBUG.push(` -> adjusted delta: ${delta}`);
815
+ // DEBUG.push("");
799
816
  }
800
817
 
801
818
  {
@@ -805,7 +822,7 @@ function adjustLayoutByDelta({
805
822
  let index = pivotIndex;
806
823
  while (index >= 0 && index < panelConstraintsArray.length) {
807
824
  const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
808
- const prevSize = prevLayout[index];
825
+ const prevSize = initialLayout[index];
809
826
  assert(prevSize != null, `Previous layout not found for panel index ${index}`);
810
827
  const unsafeSize = prevSize - deltaRemaining;
811
828
  const safeSize = resizePanel({
@@ -829,20 +846,22 @@ function adjustLayoutByDelta({
829
846
  }
830
847
  }
831
848
  }
832
- //DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
833
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
834
- //DEBUG.push("");
849
+ // DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
850
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
851
+ // DEBUG.push("");
835
852
 
836
853
  // If we were unable to resize any of the panels panels, return the previous state.
837
854
  // This will essentially bailout and ignore e.g. drags past a panel's boundaries
838
- if (fuzzyNumbersEqual(deltaApplied, 0)) {
839
- //console.log(DEBUG.join("\n"));
855
+ if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
856
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
857
+ // console.log(DEBUG.join("\n"));
858
+
840
859
  return prevLayout;
841
860
  }
842
861
  {
843
862
  // Now distribute the applied delta to the panels in the other direction
844
863
  const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
845
- const prevSize = prevLayout[pivotIndex];
864
+ const prevSize = initialLayout[pivotIndex];
846
865
  assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
847
866
  const unsafeSize = prevSize + deltaApplied;
848
867
  const safeSize = resizePanel({
@@ -883,17 +902,23 @@ function adjustLayoutByDelta({
883
902
  }
884
903
  }
885
904
  }
886
- //DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
887
- //DEBUG.push(` deltaApplied: ${deltaApplied}`);
888
- //DEBUG.push("");
905
+ // DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
906
+ // DEBUG.push(` deltaApplied: ${deltaApplied}`);
907
+ // DEBUG.push("");
889
908
 
890
909
  const totalSize = nextLayout.reduce((total, size) => size + total, 0);
891
- //DEBUG.push(`total size: ${totalSize}`);
892
- //console.log(DEBUG.join("\n"));
910
+ // DEBUG.push(`total size: ${totalSize}`);
893
911
 
912
+ // If our new layout doesn't add up to 100%, that means the requested delta can't be applied
913
+ // In that case, fall back to our most recent valid layout
894
914
  if (!fuzzyNumbersEqual(totalSize, 100)) {
915
+ // DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
916
+ // console.log(DEBUG.join("\n"));
917
+
895
918
  return prevLayout;
896
919
  }
920
+
921
+ // console.log(DEBUG.join("\n"));
897
922
  return nextLayout;
898
923
  }
899
924
 
@@ -1000,9 +1025,10 @@ function useWindowSplitterPanelGroupBehavior({
1000
1025
  if (size != null && collapsible) {
1001
1026
  const nextLayout = adjustLayoutByDelta({
1002
1027
  delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
1003
- layout,
1028
+ initialLayout: layout,
1004
1029
  panelConstraints: panelDataArray.map(panelData => panelData.constraints),
1005
1030
  pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
1031
+ prevLayout: layout,
1006
1032
  trigger: "keyboard"
1007
1033
  });
1008
1034
  if (layout !== nextLayout) {
@@ -1489,9 +1515,10 @@ function PanelGroupWithForwardedRef({
1489
1515
  const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
1490
1516
  const nextLayout = adjustLayoutByDelta({
1491
1517
  delta,
1492
- layout: prevLayout,
1518
+ initialLayout: prevLayout,
1493
1519
  panelConstraints: panelConstraintsArray,
1494
1520
  pivotIndices,
1521
+ prevLayout,
1495
1522
  trigger: "imperative-api"
1496
1523
  });
1497
1524
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1531,9 +1558,10 @@ function PanelGroupWithForwardedRef({
1531
1558
  const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
1532
1559
  const nextLayout = adjustLayoutByDelta({
1533
1560
  delta,
1534
- layout: prevLayout,
1561
+ initialLayout: prevLayout,
1535
1562
  panelConstraints: panelConstraintsArray,
1536
1563
  pivotIndices,
1564
+ prevLayout,
1537
1565
  trigger: "imperative-api"
1538
1566
  });
1539
1567
  if (!compareLayouts(prevLayout, nextLayout)) {
@@ -1659,9 +1687,10 @@ function PanelGroupWithForwardedRef({
1659
1687
  const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
1660
1688
  const nextLayout = adjustLayoutByDelta({
1661
1689
  delta,
1662
- layout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1690
+ initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
1663
1691
  panelConstraints,
1664
1692
  pivotIndices,
1693
+ prevLayout,
1665
1694
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
1666
1695
  });
1667
1696
  const layoutChanged = !compareLayouts(prevLayout, nextLayout);
@@ -1717,9 +1746,10 @@ function PanelGroupWithForwardedRef({
1717
1746
  const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
1718
1747
  const nextLayout = adjustLayoutByDelta({
1719
1748
  delta,
1720
- layout: prevLayout,
1749
+ initialLayout: prevLayout,
1721
1750
  panelConstraints: panelConstraintsArray,
1722
1751
  pivotIndices,
1752
+ prevLayout,
1723
1753
  trigger: "imperative-api"
1724
1754
  });
1725
1755
  if (!compareLayouts(prevLayout, nextLayout)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
package/src/PanelGroup.ts CHANGED
@@ -355,9 +355,10 @@ function PanelGroupWithForwardedRef({
355
355
 
356
356
  const nextLayout = adjustLayoutByDelta({
357
357
  delta,
358
- layout: prevLayout,
358
+ initialLayout: prevLayout,
359
359
  panelConstraints: panelConstraintsArray,
360
360
  pivotIndices,
361
+ prevLayout,
361
362
  trigger: "imperative-api",
362
363
  });
363
364
 
@@ -415,9 +416,10 @@ function PanelGroupWithForwardedRef({
415
416
 
416
417
  const nextLayout = adjustLayoutByDelta({
417
418
  delta,
418
- layout: prevLayout,
419
+ initialLayout: prevLayout,
419
420
  panelConstraints: panelConstraintsArray,
420
421
  pivotIndices,
422
+ prevLayout,
421
423
  trigger: "imperative-api",
422
424
  });
423
425
 
@@ -636,9 +638,10 @@ function PanelGroupWithForwardedRef({
636
638
 
637
639
  const nextLayout = adjustLayoutByDelta({
638
640
  delta,
639
- layout: initialLayout ?? prevLayout,
641
+ initialLayout: initialLayout ?? prevLayout,
640
642
  panelConstraints,
641
643
  pivotIndices,
644
+ prevLayout,
642
645
  trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch",
643
646
  });
644
647
 
@@ -722,9 +725,10 @@ function PanelGroupWithForwardedRef({
722
725
 
723
726
  const nextLayout = adjustLayoutByDelta({
724
727
  delta,
725
- layout: prevLayout,
728
+ initialLayout: prevLayout,
726
729
  panelConstraints: panelConstraintsArray,
727
730
  pivotIndices,
731
+ prevLayout,
728
732
  trigger: "imperative-api",
729
733
  });
730
734
 
@@ -157,7 +157,7 @@ export function useWindowSplitterPanelGroupBehavior({
157
157
  delta: fuzzyNumbersEqual(size, collapsedSize)
158
158
  ? minSize - collapsedSize
159
159
  : collapsedSize - size,
160
- layout,
160
+ initialLayout: layout,
161
161
  panelConstraints: panelDataArray.map(
162
162
  (panelData) => panelData.constraints
163
163
  ),
@@ -166,6 +166,7 @@ export function useWindowSplitterPanelGroupBehavior({
166
166
  handleId,
167
167
  panelGroupElement
168
168
  ),
169
+ prevLayout: layout,
169
170
  trigger: "keyboard",
170
171
  });
171
172
  if (layout !== nextLayout) {