react-resizable-panels 2.0.11 → 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.
- package/CHANGELOG.md +4 -0
- package/dist/react-resizable-panels.browser.cjs.js +73 -43
- package/dist/react-resizable-panels.browser.development.cjs.js +73 -43
- package/dist/react-resizable-panels.browser.development.esm.js +73 -43
- package/dist/react-resizable-panels.browser.esm.js +73 -43
- package/dist/react-resizable-panels.cjs.js +73 -43
- package/dist/react-resizable-panels.development.cjs.js +73 -43
- package/dist/react-resizable-panels.development.esm.js +73 -43
- package/dist/react-resizable-panels.development.node.cjs.js +73 -43
- package/dist/react-resizable-panels.development.node.esm.js +73 -43
- package/dist/react-resizable-panels.esm.js +73 -43
- package/dist/react-resizable-panels.node.cjs.js +73 -43
- package/dist/react-resizable-panels.node.esm.js +73 -43
- package/package.json +1 -1
- package/src/PanelGroup.ts +8 -4
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +2 -1
- package/src/utils/adjustLayoutByDelta.test.ts +268 -115
- package/src/utils/adjustLayoutByDelta.ts +51 -39
- package/src/utils/numbers/fuzzyLayoutsEqual.ts +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.0.12
|
|
4
|
+
|
|
5
|
+
- Improve resize for edge cases with collapsed panels; intermediate resize states should now fall back to the most recent valid layout rather than the initial layout (#311)
|
|
6
|
+
|
|
3
7
|
## 2.0.11
|
|
4
8
|
|
|
5
9
|
- Fix resize handle cursor hit detection when when viewport is scrolled (#305)
|
|
@@ -694,6 +694,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
694
694
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
695
695
|
}
|
|
696
696
|
|
|
697
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
698
|
+
if (actual.length !== expected.length) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
for (let index = 0; index < actual.length; index++) {
|
|
702
|
+
const actualSize = actual[index];
|
|
703
|
+
const expectedSize = expected[index];
|
|
704
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
|
|
697
711
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
698
712
|
function resizePanel({
|
|
699
713
|
panelConstraints: panelConstraintsArray,
|
|
@@ -729,26 +743,29 @@ function resizePanel({
|
|
|
729
743
|
// All units must be in percentages; pixel values should be pre-converted
|
|
730
744
|
function adjustLayoutByDelta({
|
|
731
745
|
delta,
|
|
732
|
-
|
|
746
|
+
initialLayout,
|
|
733
747
|
panelConstraints: panelConstraintsArray,
|
|
734
748
|
pivotIndices,
|
|
749
|
+
prevLayout,
|
|
735
750
|
trigger
|
|
736
751
|
}) {
|
|
737
752
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
738
|
-
return
|
|
753
|
+
return initialLayout;
|
|
739
754
|
}
|
|
740
|
-
const nextLayout = [...
|
|
755
|
+
const nextLayout = [...initialLayout];
|
|
741
756
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
742
757
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
743
758
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
744
759
|
let deltaApplied = 0;
|
|
745
760
|
|
|
746
|
-
//const DEBUG = [];
|
|
747
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
748
|
-
//DEBUG.push(`
|
|
749
|
-
//DEBUG.push(`
|
|
750
|
-
//DEBUG.push(`
|
|
751
|
-
//DEBUG.push("");
|
|
761
|
+
// const DEBUG = [];
|
|
762
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
763
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
764
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
765
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
766
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
767
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
768
|
+
// DEBUG.push("");
|
|
752
769
|
|
|
753
770
|
// A resizing panel affects the panels before or after it.
|
|
754
771
|
//
|
|
@@ -773,18 +790,18 @@ function adjustLayoutByDelta({
|
|
|
773
790
|
minSize = 0
|
|
774
791
|
} = panelConstraints;
|
|
775
792
|
|
|
776
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
777
|
-
//DEBUG.push(` -> collapsible? ${
|
|
793
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
794
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
778
795
|
if (collapsible) {
|
|
779
|
-
const prevSize =
|
|
796
|
+
const prevSize = initialLayout[index];
|
|
780
797
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
781
798
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
782
799
|
const localDelta = minSize - prevSize;
|
|
783
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
800
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
784
801
|
|
|
785
802
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
786
803
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
787
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
804
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
788
805
|
}
|
|
789
806
|
}
|
|
790
807
|
}
|
|
@@ -801,24 +818,24 @@ function adjustLayoutByDelta({
|
|
|
801
818
|
minSize = 0
|
|
802
819
|
} = panelConstraints;
|
|
803
820
|
|
|
804
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
805
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
821
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
822
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
806
823
|
if (collapsible) {
|
|
807
|
-
const prevSize =
|
|
824
|
+
const prevSize = initialLayout[index];
|
|
808
825
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
809
826
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
810
827
|
const localDelta = prevSize - collapsedSize;
|
|
811
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
828
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
812
829
|
|
|
813
830
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
814
831
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
815
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
832
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
816
833
|
}
|
|
817
834
|
}
|
|
818
835
|
}
|
|
819
836
|
}
|
|
820
837
|
}
|
|
821
|
-
//DEBUG.push("");
|
|
838
|
+
// DEBUG.push("");
|
|
822
839
|
}
|
|
823
840
|
|
|
824
841
|
{
|
|
@@ -832,9 +849,9 @@ function adjustLayoutByDelta({
|
|
|
832
849
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
833
850
|
let maxAvailableDelta = 0;
|
|
834
851
|
|
|
835
|
-
//DEBUG.push("pre calc...");
|
|
852
|
+
// DEBUG.push("pre calc...");
|
|
836
853
|
while (true) {
|
|
837
|
-
const prevSize =
|
|
854
|
+
const prevSize = initialLayout[index];
|
|
838
855
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
839
856
|
const maxSafeSize = resizePanel({
|
|
840
857
|
panelConstraints: panelConstraintsArray,
|
|
@@ -842,7 +859,7 @@ function adjustLayoutByDelta({
|
|
|
842
859
|
size: 100
|
|
843
860
|
});
|
|
844
861
|
const delta = maxSafeSize - prevSize;
|
|
845
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
862
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
846
863
|
|
|
847
864
|
maxAvailableDelta += delta;
|
|
848
865
|
index += increment;
|
|
@@ -851,11 +868,11 @@ function adjustLayoutByDelta({
|
|
|
851
868
|
}
|
|
852
869
|
}
|
|
853
870
|
|
|
854
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
871
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
855
872
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
856
873
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
857
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
858
|
-
//DEBUG.push("");
|
|
874
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
875
|
+
// DEBUG.push("");
|
|
859
876
|
}
|
|
860
877
|
|
|
861
878
|
{
|
|
@@ -865,7 +882,7 @@ function adjustLayoutByDelta({
|
|
|
865
882
|
let index = pivotIndex;
|
|
866
883
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
867
884
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
868
|
-
const prevSize =
|
|
885
|
+
const prevSize = initialLayout[index];
|
|
869
886
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
870
887
|
const unsafeSize = prevSize - deltaRemaining;
|
|
871
888
|
const safeSize = resizePanel({
|
|
@@ -889,20 +906,22 @@ function adjustLayoutByDelta({
|
|
|
889
906
|
}
|
|
890
907
|
}
|
|
891
908
|
}
|
|
892
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
893
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
894
|
-
//DEBUG.push("");
|
|
909
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
910
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
911
|
+
// DEBUG.push("");
|
|
895
912
|
|
|
896
913
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
897
914
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
898
|
-
if (
|
|
899
|
-
//
|
|
915
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
916
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
917
|
+
// console.log(DEBUG.join("\n"));
|
|
918
|
+
|
|
900
919
|
return prevLayout;
|
|
901
920
|
}
|
|
902
921
|
{
|
|
903
922
|
// Now distribute the applied delta to the panels in the other direction
|
|
904
923
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
905
|
-
const prevSize =
|
|
924
|
+
const prevSize = initialLayout[pivotIndex];
|
|
906
925
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
907
926
|
const unsafeSize = prevSize + deltaApplied;
|
|
908
927
|
const safeSize = resizePanel({
|
|
@@ -943,17 +962,23 @@ function adjustLayoutByDelta({
|
|
|
943
962
|
}
|
|
944
963
|
}
|
|
945
964
|
}
|
|
946
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
947
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
948
|
-
//DEBUG.push("");
|
|
965
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
966
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
967
|
+
// DEBUG.push("");
|
|
949
968
|
|
|
950
969
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
951
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
952
|
-
//console.log(DEBUG.join("\n"));
|
|
970
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
953
971
|
|
|
972
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
973
|
+
// In that case, fall back to our most recent valid layout
|
|
954
974
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
975
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
976
|
+
// console.log(DEBUG.join("\n"));
|
|
977
|
+
|
|
955
978
|
return prevLayout;
|
|
956
979
|
}
|
|
980
|
+
|
|
981
|
+
// console.log(DEBUG.join("\n"));
|
|
957
982
|
return nextLayout;
|
|
958
983
|
}
|
|
959
984
|
|
|
@@ -1133,9 +1158,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1133
1158
|
if (size != null && collapsible) {
|
|
1134
1159
|
const nextLayout = adjustLayoutByDelta({
|
|
1135
1160
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1136
|
-
layout,
|
|
1161
|
+
initialLayout: layout,
|
|
1137
1162
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1138
1163
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1164
|
+
prevLayout: layout,
|
|
1139
1165
|
trigger: "keyboard"
|
|
1140
1166
|
});
|
|
1141
1167
|
if (layout !== nextLayout) {
|
|
@@ -1677,9 +1703,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1677
1703
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1678
1704
|
const nextLayout = adjustLayoutByDelta({
|
|
1679
1705
|
delta,
|
|
1680
|
-
|
|
1706
|
+
initialLayout: prevLayout,
|
|
1681
1707
|
panelConstraints: panelConstraintsArray,
|
|
1682
1708
|
pivotIndices,
|
|
1709
|
+
prevLayout,
|
|
1683
1710
|
trigger: "imperative-api"
|
|
1684
1711
|
});
|
|
1685
1712
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1719,9 +1746,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1719
1746
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1720
1747
|
const nextLayout = adjustLayoutByDelta({
|
|
1721
1748
|
delta,
|
|
1722
|
-
|
|
1749
|
+
initialLayout: prevLayout,
|
|
1723
1750
|
panelConstraints: panelConstraintsArray,
|
|
1724
1751
|
pivotIndices,
|
|
1752
|
+
prevLayout,
|
|
1725
1753
|
trigger: "imperative-api"
|
|
1726
1754
|
});
|
|
1727
1755
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1903,9 +1931,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1903
1931
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1904
1932
|
const nextLayout = adjustLayoutByDelta({
|
|
1905
1933
|
delta,
|
|
1906
|
-
|
|
1934
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
1907
1935
|
panelConstraints,
|
|
1908
1936
|
pivotIndices,
|
|
1937
|
+
prevLayout,
|
|
1909
1938
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
1910
1939
|
});
|
|
1911
1940
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -1961,9 +1990,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1961
1990
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1962
1991
|
const nextLayout = adjustLayoutByDelta({
|
|
1963
1992
|
delta,
|
|
1964
|
-
|
|
1993
|
+
initialLayout: prevLayout,
|
|
1965
1994
|
panelConstraints: panelConstraintsArray,
|
|
1966
1995
|
pivotIndices,
|
|
1996
|
+
prevLayout,
|
|
1967
1997
|
trigger: "imperative-api"
|
|
1968
1998
|
});
|
|
1969
1999
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -700,6 +700,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
700
700
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
701
701
|
}
|
|
702
702
|
|
|
703
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
704
|
+
if (actual.length !== expected.length) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
for (let index = 0; index < actual.length; index++) {
|
|
708
|
+
const actualSize = actual[index];
|
|
709
|
+
const expectedSize = expected[index];
|
|
710
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
|
|
703
717
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
704
718
|
function resizePanel({
|
|
705
719
|
panelConstraints: panelConstraintsArray,
|
|
@@ -735,26 +749,29 @@ function resizePanel({
|
|
|
735
749
|
// All units must be in percentages; pixel values should be pre-converted
|
|
736
750
|
function adjustLayoutByDelta({
|
|
737
751
|
delta,
|
|
738
|
-
|
|
752
|
+
initialLayout,
|
|
739
753
|
panelConstraints: panelConstraintsArray,
|
|
740
754
|
pivotIndices,
|
|
755
|
+
prevLayout,
|
|
741
756
|
trigger
|
|
742
757
|
}) {
|
|
743
758
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
744
|
-
return
|
|
759
|
+
return initialLayout;
|
|
745
760
|
}
|
|
746
|
-
const nextLayout = [...
|
|
761
|
+
const nextLayout = [...initialLayout];
|
|
747
762
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
748
763
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
749
764
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
750
765
|
let deltaApplied = 0;
|
|
751
766
|
|
|
752
|
-
//const DEBUG = [];
|
|
753
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
754
|
-
//DEBUG.push(`
|
|
755
|
-
//DEBUG.push(`
|
|
756
|
-
//DEBUG.push(`
|
|
757
|
-
//DEBUG.push("");
|
|
767
|
+
// const DEBUG = [];
|
|
768
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
769
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
770
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
771
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
772
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
773
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
774
|
+
// DEBUG.push("");
|
|
758
775
|
|
|
759
776
|
// A resizing panel affects the panels before or after it.
|
|
760
777
|
//
|
|
@@ -779,18 +796,18 @@ function adjustLayoutByDelta({
|
|
|
779
796
|
minSize = 0
|
|
780
797
|
} = panelConstraints;
|
|
781
798
|
|
|
782
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
783
|
-
//DEBUG.push(` -> collapsible? ${
|
|
799
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
800
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
784
801
|
if (collapsible) {
|
|
785
|
-
const prevSize =
|
|
802
|
+
const prevSize = initialLayout[index];
|
|
786
803
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
787
804
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
788
805
|
const localDelta = minSize - prevSize;
|
|
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
|
}
|
|
@@ -807,24 +824,24 @@ function adjustLayoutByDelta({
|
|
|
807
824
|
minSize = 0
|
|
808
825
|
} = panelConstraints;
|
|
809
826
|
|
|
810
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
811
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
827
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
828
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
812
829
|
if (collapsible) {
|
|
813
|
-
const prevSize =
|
|
830
|
+
const prevSize = initialLayout[index];
|
|
814
831
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
815
832
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
816
833
|
const localDelta = prevSize - collapsedSize;
|
|
817
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
834
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
818
835
|
|
|
819
836
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
820
837
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
821
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
838
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
822
839
|
}
|
|
823
840
|
}
|
|
824
841
|
}
|
|
825
842
|
}
|
|
826
843
|
}
|
|
827
|
-
//DEBUG.push("");
|
|
844
|
+
// DEBUG.push("");
|
|
828
845
|
}
|
|
829
846
|
|
|
830
847
|
{
|
|
@@ -838,9 +855,9 @@ function adjustLayoutByDelta({
|
|
|
838
855
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
839
856
|
let maxAvailableDelta = 0;
|
|
840
857
|
|
|
841
|
-
//DEBUG.push("pre calc...");
|
|
858
|
+
// DEBUG.push("pre calc...");
|
|
842
859
|
while (true) {
|
|
843
|
-
const prevSize =
|
|
860
|
+
const prevSize = initialLayout[index];
|
|
844
861
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
845
862
|
const maxSafeSize = resizePanel({
|
|
846
863
|
panelConstraints: panelConstraintsArray,
|
|
@@ -848,7 +865,7 @@ function adjustLayoutByDelta({
|
|
|
848
865
|
size: 100
|
|
849
866
|
});
|
|
850
867
|
const delta = maxSafeSize - prevSize;
|
|
851
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
868
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
852
869
|
|
|
853
870
|
maxAvailableDelta += delta;
|
|
854
871
|
index += increment;
|
|
@@ -857,11 +874,11 @@ function adjustLayoutByDelta({
|
|
|
857
874
|
}
|
|
858
875
|
}
|
|
859
876
|
|
|
860
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
877
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
861
878
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
862
879
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
863
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
864
|
-
//DEBUG.push("");
|
|
880
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
881
|
+
// DEBUG.push("");
|
|
865
882
|
}
|
|
866
883
|
|
|
867
884
|
{
|
|
@@ -871,7 +888,7 @@ function adjustLayoutByDelta({
|
|
|
871
888
|
let index = pivotIndex;
|
|
872
889
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
873
890
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
874
|
-
const prevSize =
|
|
891
|
+
const prevSize = initialLayout[index];
|
|
875
892
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
876
893
|
const unsafeSize = prevSize - deltaRemaining;
|
|
877
894
|
const safeSize = resizePanel({
|
|
@@ -895,20 +912,22 @@ function adjustLayoutByDelta({
|
|
|
895
912
|
}
|
|
896
913
|
}
|
|
897
914
|
}
|
|
898
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
899
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
900
|
-
//DEBUG.push("");
|
|
915
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
916
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
917
|
+
// DEBUG.push("");
|
|
901
918
|
|
|
902
919
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
903
920
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
904
|
-
if (
|
|
905
|
-
//
|
|
921
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
922
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
923
|
+
// console.log(DEBUG.join("\n"));
|
|
924
|
+
|
|
906
925
|
return prevLayout;
|
|
907
926
|
}
|
|
908
927
|
{
|
|
909
928
|
// Now distribute the applied delta to the panels in the other direction
|
|
910
929
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
911
|
-
const prevSize =
|
|
930
|
+
const prevSize = initialLayout[pivotIndex];
|
|
912
931
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
913
932
|
const unsafeSize = prevSize + deltaApplied;
|
|
914
933
|
const safeSize = resizePanel({
|
|
@@ -949,17 +968,23 @@ function adjustLayoutByDelta({
|
|
|
949
968
|
}
|
|
950
969
|
}
|
|
951
970
|
}
|
|
952
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
953
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
954
|
-
//DEBUG.push("");
|
|
971
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
972
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
973
|
+
// DEBUG.push("");
|
|
955
974
|
|
|
956
975
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
957
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
958
|
-
//console.log(DEBUG.join("\n"));
|
|
976
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
959
977
|
|
|
978
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
979
|
+
// In that case, fall back to our most recent valid layout
|
|
960
980
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
981
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
982
|
+
// console.log(DEBUG.join("\n"));
|
|
983
|
+
|
|
961
984
|
return prevLayout;
|
|
962
985
|
}
|
|
986
|
+
|
|
987
|
+
// console.log(DEBUG.join("\n"));
|
|
963
988
|
return nextLayout;
|
|
964
989
|
}
|
|
965
990
|
|
|
@@ -1149,9 +1174,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1149
1174
|
if (size != null && collapsible) {
|
|
1150
1175
|
const nextLayout = adjustLayoutByDelta({
|
|
1151
1176
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1152
|
-
layout,
|
|
1177
|
+
initialLayout: layout,
|
|
1153
1178
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1154
1179
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1180
|
+
prevLayout: layout,
|
|
1155
1181
|
trigger: "keyboard"
|
|
1156
1182
|
});
|
|
1157
1183
|
if (layout !== nextLayout) {
|
|
@@ -1783,9 +1809,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1783
1809
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1784
1810
|
const nextLayout = adjustLayoutByDelta({
|
|
1785
1811
|
delta,
|
|
1786
|
-
|
|
1812
|
+
initialLayout: prevLayout,
|
|
1787
1813
|
panelConstraints: panelConstraintsArray,
|
|
1788
1814
|
pivotIndices,
|
|
1815
|
+
prevLayout,
|
|
1789
1816
|
trigger: "imperative-api"
|
|
1790
1817
|
});
|
|
1791
1818
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1825,9 +1852,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1825
1852
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1826
1853
|
const nextLayout = adjustLayoutByDelta({
|
|
1827
1854
|
delta,
|
|
1828
|
-
|
|
1855
|
+
initialLayout: prevLayout,
|
|
1829
1856
|
panelConstraints: panelConstraintsArray,
|
|
1830
1857
|
pivotIndices,
|
|
1858
|
+
prevLayout,
|
|
1831
1859
|
trigger: "imperative-api"
|
|
1832
1860
|
});
|
|
1833
1861
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -2009,9 +2037,10 @@ function PanelGroupWithForwardedRef({
|
|
|
2009
2037
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
2010
2038
|
const nextLayout = adjustLayoutByDelta({
|
|
2011
2039
|
delta,
|
|
2012
|
-
|
|
2040
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
2013
2041
|
panelConstraints,
|
|
2014
2042
|
pivotIndices,
|
|
2043
|
+
prevLayout,
|
|
2015
2044
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
2016
2045
|
});
|
|
2017
2046
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -2067,9 +2096,10 @@ function PanelGroupWithForwardedRef({
|
|
|
2067
2096
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
2068
2097
|
const nextLayout = adjustLayoutByDelta({
|
|
2069
2098
|
delta,
|
|
2070
|
-
|
|
2099
|
+
initialLayout: prevLayout,
|
|
2071
2100
|
panelConstraints: panelConstraintsArray,
|
|
2072
2101
|
pivotIndices,
|
|
2102
|
+
prevLayout,
|
|
2073
2103
|
trigger: "imperative-api"
|
|
2074
2104
|
});
|
|
2075
2105
|
if (!compareLayouts(prevLayout, nextLayout)) {
|