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
|
@@ -696,6 +696,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
696
696
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
697
697
|
}
|
|
698
698
|
|
|
699
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
700
|
+
if (actual.length !== expected.length) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
for (let index = 0; index < actual.length; index++) {
|
|
704
|
+
const actualSize = actual[index];
|
|
705
|
+
const expectedSize = expected[index];
|
|
706
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
|
|
699
713
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
700
714
|
function resizePanel({
|
|
701
715
|
panelConstraints: panelConstraintsArray,
|
|
@@ -731,26 +745,29 @@ function resizePanel({
|
|
|
731
745
|
// All units must be in percentages; pixel values should be pre-converted
|
|
732
746
|
function adjustLayoutByDelta({
|
|
733
747
|
delta,
|
|
734
|
-
|
|
748
|
+
initialLayout,
|
|
735
749
|
panelConstraints: panelConstraintsArray,
|
|
736
750
|
pivotIndices,
|
|
751
|
+
prevLayout,
|
|
737
752
|
trigger
|
|
738
753
|
}) {
|
|
739
754
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
740
|
-
return
|
|
755
|
+
return initialLayout;
|
|
741
756
|
}
|
|
742
|
-
const nextLayout = [...
|
|
757
|
+
const nextLayout = [...initialLayout];
|
|
743
758
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
744
759
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
745
760
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
746
761
|
let deltaApplied = 0;
|
|
747
762
|
|
|
748
|
-
//const DEBUG = [];
|
|
749
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
750
|
-
//DEBUG.push(`
|
|
751
|
-
//DEBUG.push(`
|
|
752
|
-
//DEBUG.push(`
|
|
753
|
-
//DEBUG.push("");
|
|
763
|
+
// const DEBUG = [];
|
|
764
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
765
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
766
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
767
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
768
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
769
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
770
|
+
// DEBUG.push("");
|
|
754
771
|
|
|
755
772
|
// A resizing panel affects the panels before or after it.
|
|
756
773
|
//
|
|
@@ -775,18 +792,18 @@ function adjustLayoutByDelta({
|
|
|
775
792
|
minSize = 0
|
|
776
793
|
} = panelConstraints;
|
|
777
794
|
|
|
778
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
779
|
-
//DEBUG.push(` -> collapsible? ${
|
|
795
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
796
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
780
797
|
if (collapsible) {
|
|
781
|
-
const prevSize =
|
|
798
|
+
const prevSize = initialLayout[index];
|
|
782
799
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
783
800
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
784
801
|
const localDelta = minSize - prevSize;
|
|
785
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
802
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
786
803
|
|
|
787
804
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
788
805
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
789
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
806
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
790
807
|
}
|
|
791
808
|
}
|
|
792
809
|
}
|
|
@@ -803,24 +820,24 @@ function adjustLayoutByDelta({
|
|
|
803
820
|
minSize = 0
|
|
804
821
|
} = panelConstraints;
|
|
805
822
|
|
|
806
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
807
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
823
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
824
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
808
825
|
if (collapsible) {
|
|
809
|
-
const prevSize =
|
|
826
|
+
const prevSize = initialLayout[index];
|
|
810
827
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
811
828
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
812
829
|
const localDelta = prevSize - collapsedSize;
|
|
813
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
830
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
814
831
|
|
|
815
832
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
816
833
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
817
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
834
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
818
835
|
}
|
|
819
836
|
}
|
|
820
837
|
}
|
|
821
838
|
}
|
|
822
839
|
}
|
|
823
|
-
//DEBUG.push("");
|
|
840
|
+
// DEBUG.push("");
|
|
824
841
|
}
|
|
825
842
|
|
|
826
843
|
{
|
|
@@ -834,9 +851,9 @@ function adjustLayoutByDelta({
|
|
|
834
851
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
835
852
|
let maxAvailableDelta = 0;
|
|
836
853
|
|
|
837
|
-
//DEBUG.push("pre calc...");
|
|
854
|
+
// DEBUG.push("pre calc...");
|
|
838
855
|
while (true) {
|
|
839
|
-
const prevSize =
|
|
856
|
+
const prevSize = initialLayout[index];
|
|
840
857
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
841
858
|
const maxSafeSize = resizePanel({
|
|
842
859
|
panelConstraints: panelConstraintsArray,
|
|
@@ -844,7 +861,7 @@ function adjustLayoutByDelta({
|
|
|
844
861
|
size: 100
|
|
845
862
|
});
|
|
846
863
|
const delta = maxSafeSize - prevSize;
|
|
847
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
864
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
848
865
|
|
|
849
866
|
maxAvailableDelta += delta;
|
|
850
867
|
index += increment;
|
|
@@ -853,11 +870,11 @@ function adjustLayoutByDelta({
|
|
|
853
870
|
}
|
|
854
871
|
}
|
|
855
872
|
|
|
856
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
873
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
857
874
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
858
875
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
859
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
860
|
-
//DEBUG.push("");
|
|
876
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
877
|
+
// DEBUG.push("");
|
|
861
878
|
}
|
|
862
879
|
|
|
863
880
|
{
|
|
@@ -867,7 +884,7 @@ function adjustLayoutByDelta({
|
|
|
867
884
|
let index = pivotIndex;
|
|
868
885
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
869
886
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
870
|
-
const prevSize =
|
|
887
|
+
const prevSize = initialLayout[index];
|
|
871
888
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
872
889
|
const unsafeSize = prevSize - deltaRemaining;
|
|
873
890
|
const safeSize = resizePanel({
|
|
@@ -891,20 +908,22 @@ function adjustLayoutByDelta({
|
|
|
891
908
|
}
|
|
892
909
|
}
|
|
893
910
|
}
|
|
894
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
895
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
896
|
-
//DEBUG.push("");
|
|
911
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
912
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
913
|
+
// DEBUG.push("");
|
|
897
914
|
|
|
898
915
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
899
916
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
900
|
-
if (
|
|
901
|
-
//
|
|
917
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
918
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
919
|
+
// console.log(DEBUG.join("\n"));
|
|
920
|
+
|
|
902
921
|
return prevLayout;
|
|
903
922
|
}
|
|
904
923
|
{
|
|
905
924
|
// Now distribute the applied delta to the panels in the other direction
|
|
906
925
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
907
|
-
const prevSize =
|
|
926
|
+
const prevSize = initialLayout[pivotIndex];
|
|
908
927
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
909
928
|
const unsafeSize = prevSize + deltaApplied;
|
|
910
929
|
const safeSize = resizePanel({
|
|
@@ -945,17 +964,23 @@ function adjustLayoutByDelta({
|
|
|
945
964
|
}
|
|
946
965
|
}
|
|
947
966
|
}
|
|
948
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
949
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
950
|
-
//DEBUG.push("");
|
|
967
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
968
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
969
|
+
// DEBUG.push("");
|
|
951
970
|
|
|
952
971
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
953
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
954
|
-
//console.log(DEBUG.join("\n"));
|
|
972
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
955
973
|
|
|
974
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
975
|
+
// In that case, fall back to our most recent valid layout
|
|
956
976
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
977
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
978
|
+
// console.log(DEBUG.join("\n"));
|
|
979
|
+
|
|
957
980
|
return prevLayout;
|
|
958
981
|
}
|
|
982
|
+
|
|
983
|
+
// console.log(DEBUG.join("\n"));
|
|
959
984
|
return nextLayout;
|
|
960
985
|
}
|
|
961
986
|
|
|
@@ -1135,9 +1160,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1135
1160
|
if (size != null && collapsible) {
|
|
1136
1161
|
const nextLayout = adjustLayoutByDelta({
|
|
1137
1162
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1138
|
-
layout,
|
|
1163
|
+
initialLayout: layout,
|
|
1139
1164
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1140
1165
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1166
|
+
prevLayout: layout,
|
|
1141
1167
|
trigger: "keyboard"
|
|
1142
1168
|
});
|
|
1143
1169
|
if (layout !== nextLayout) {
|
|
@@ -1679,9 +1705,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1679
1705
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1680
1706
|
const nextLayout = adjustLayoutByDelta({
|
|
1681
1707
|
delta,
|
|
1682
|
-
|
|
1708
|
+
initialLayout: prevLayout,
|
|
1683
1709
|
panelConstraints: panelConstraintsArray,
|
|
1684
1710
|
pivotIndices,
|
|
1711
|
+
prevLayout,
|
|
1685
1712
|
trigger: "imperative-api"
|
|
1686
1713
|
});
|
|
1687
1714
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1721,9 +1748,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1721
1748
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1722
1749
|
const nextLayout = adjustLayoutByDelta({
|
|
1723
1750
|
delta,
|
|
1724
|
-
|
|
1751
|
+
initialLayout: prevLayout,
|
|
1725
1752
|
panelConstraints: panelConstraintsArray,
|
|
1726
1753
|
pivotIndices,
|
|
1754
|
+
prevLayout,
|
|
1727
1755
|
trigger: "imperative-api"
|
|
1728
1756
|
});
|
|
1729
1757
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1905,9 +1933,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1905
1933
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1906
1934
|
const nextLayout = adjustLayoutByDelta({
|
|
1907
1935
|
delta,
|
|
1908
|
-
|
|
1936
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
1909
1937
|
panelConstraints,
|
|
1910
1938
|
pivotIndices,
|
|
1939
|
+
prevLayout,
|
|
1911
1940
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
1912
1941
|
});
|
|
1913
1942
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -1963,9 +1992,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1963
1992
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1964
1993
|
const nextLayout = adjustLayoutByDelta({
|
|
1965
1994
|
delta,
|
|
1966
|
-
|
|
1995
|
+
initialLayout: prevLayout,
|
|
1967
1996
|
panelConstraints: panelConstraintsArray,
|
|
1968
1997
|
pivotIndices,
|
|
1998
|
+
prevLayout,
|
|
1969
1999
|
trigger: "imperative-api"
|
|
1970
2000
|
});
|
|
1971
2001
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -707,6 +707,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
707
707
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
708
708
|
}
|
|
709
709
|
|
|
710
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
711
|
+
if (actual.length !== expected.length) {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
for (let index = 0; index < actual.length; index++) {
|
|
715
|
+
const actualSize = actual[index];
|
|
716
|
+
const expectedSize = expected[index];
|
|
717
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
|
|
710
724
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
711
725
|
function resizePanel({
|
|
712
726
|
panelConstraints: panelConstraintsArray,
|
|
@@ -742,26 +756,29 @@ function resizePanel({
|
|
|
742
756
|
// All units must be in percentages; pixel values should be pre-converted
|
|
743
757
|
function adjustLayoutByDelta({
|
|
744
758
|
delta,
|
|
745
|
-
|
|
759
|
+
initialLayout,
|
|
746
760
|
panelConstraints: panelConstraintsArray,
|
|
747
761
|
pivotIndices,
|
|
762
|
+
prevLayout,
|
|
748
763
|
trigger
|
|
749
764
|
}) {
|
|
750
765
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
751
|
-
return
|
|
766
|
+
return initialLayout;
|
|
752
767
|
}
|
|
753
|
-
const nextLayout = [...
|
|
768
|
+
const nextLayout = [...initialLayout];
|
|
754
769
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
755
770
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
756
771
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
757
772
|
let deltaApplied = 0;
|
|
758
773
|
|
|
759
|
-
//const DEBUG = [];
|
|
760
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
761
|
-
//DEBUG.push(`
|
|
762
|
-
//DEBUG.push(`
|
|
763
|
-
//DEBUG.push(`
|
|
764
|
-
//DEBUG.push("");
|
|
774
|
+
// const DEBUG = [];
|
|
775
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
776
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
777
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
778
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
779
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
780
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
781
|
+
// DEBUG.push("");
|
|
765
782
|
|
|
766
783
|
// A resizing panel affects the panels before or after it.
|
|
767
784
|
//
|
|
@@ -786,18 +803,18 @@ function adjustLayoutByDelta({
|
|
|
786
803
|
minSize = 0
|
|
787
804
|
} = panelConstraints;
|
|
788
805
|
|
|
789
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
790
|
-
//DEBUG.push(` -> collapsible? ${
|
|
806
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
807
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
791
808
|
if (collapsible) {
|
|
792
|
-
const prevSize =
|
|
809
|
+
const prevSize = initialLayout[index];
|
|
793
810
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
794
811
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
795
812
|
const localDelta = minSize - prevSize;
|
|
796
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
813
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
797
814
|
|
|
798
815
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
799
816
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
800
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
817
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
801
818
|
}
|
|
802
819
|
}
|
|
803
820
|
}
|
|
@@ -814,24 +831,24 @@ function adjustLayoutByDelta({
|
|
|
814
831
|
minSize = 0
|
|
815
832
|
} = panelConstraints;
|
|
816
833
|
|
|
817
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
818
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
834
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
835
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
819
836
|
if (collapsible) {
|
|
820
|
-
const prevSize =
|
|
837
|
+
const prevSize = initialLayout[index];
|
|
821
838
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
822
839
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
823
840
|
const localDelta = prevSize - collapsedSize;
|
|
824
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
841
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
825
842
|
|
|
826
843
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
827
844
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
828
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
845
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
829
846
|
}
|
|
830
847
|
}
|
|
831
848
|
}
|
|
832
849
|
}
|
|
833
850
|
}
|
|
834
|
-
//DEBUG.push("");
|
|
851
|
+
// DEBUG.push("");
|
|
835
852
|
}
|
|
836
853
|
|
|
837
854
|
{
|
|
@@ -845,9 +862,9 @@ function adjustLayoutByDelta({
|
|
|
845
862
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
846
863
|
let maxAvailableDelta = 0;
|
|
847
864
|
|
|
848
|
-
//DEBUG.push("pre calc...");
|
|
865
|
+
// DEBUG.push("pre calc...");
|
|
849
866
|
while (true) {
|
|
850
|
-
const prevSize =
|
|
867
|
+
const prevSize = initialLayout[index];
|
|
851
868
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
852
869
|
const maxSafeSize = resizePanel({
|
|
853
870
|
panelConstraints: panelConstraintsArray,
|
|
@@ -855,7 +872,7 @@ function adjustLayoutByDelta({
|
|
|
855
872
|
size: 100
|
|
856
873
|
});
|
|
857
874
|
const delta = maxSafeSize - prevSize;
|
|
858
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
875
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
859
876
|
|
|
860
877
|
maxAvailableDelta += delta;
|
|
861
878
|
index += increment;
|
|
@@ -864,11 +881,11 @@ function adjustLayoutByDelta({
|
|
|
864
881
|
}
|
|
865
882
|
}
|
|
866
883
|
|
|
867
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
884
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
868
885
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
869
886
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
870
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
871
|
-
//DEBUG.push("");
|
|
887
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
888
|
+
// DEBUG.push("");
|
|
872
889
|
}
|
|
873
890
|
|
|
874
891
|
{
|
|
@@ -878,7 +895,7 @@ function adjustLayoutByDelta({
|
|
|
878
895
|
let index = pivotIndex;
|
|
879
896
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
880
897
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
881
|
-
const prevSize =
|
|
898
|
+
const prevSize = initialLayout[index];
|
|
882
899
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
883
900
|
const unsafeSize = prevSize - deltaRemaining;
|
|
884
901
|
const safeSize = resizePanel({
|
|
@@ -902,20 +919,22 @@ function adjustLayoutByDelta({
|
|
|
902
919
|
}
|
|
903
920
|
}
|
|
904
921
|
}
|
|
905
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
906
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
907
|
-
//DEBUG.push("");
|
|
922
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
923
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
924
|
+
// DEBUG.push("");
|
|
908
925
|
|
|
909
926
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
910
927
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
911
|
-
if (
|
|
912
|
-
//
|
|
928
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
929
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
930
|
+
// console.log(DEBUG.join("\n"));
|
|
931
|
+
|
|
913
932
|
return prevLayout;
|
|
914
933
|
}
|
|
915
934
|
{
|
|
916
935
|
// Now distribute the applied delta to the panels in the other direction
|
|
917
936
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
918
|
-
const prevSize =
|
|
937
|
+
const prevSize = initialLayout[pivotIndex];
|
|
919
938
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
920
939
|
const unsafeSize = prevSize + deltaApplied;
|
|
921
940
|
const safeSize = resizePanel({
|
|
@@ -956,17 +975,23 @@ function adjustLayoutByDelta({
|
|
|
956
975
|
}
|
|
957
976
|
}
|
|
958
977
|
}
|
|
959
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
960
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
961
|
-
//DEBUG.push("");
|
|
978
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
979
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
980
|
+
// DEBUG.push("");
|
|
962
981
|
|
|
963
982
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
964
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
965
|
-
//console.log(DEBUG.join("\n"));
|
|
983
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
966
984
|
|
|
985
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
986
|
+
// In that case, fall back to our most recent valid layout
|
|
967
987
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
988
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
989
|
+
// console.log(DEBUG.join("\n"));
|
|
990
|
+
|
|
968
991
|
return prevLayout;
|
|
969
992
|
}
|
|
993
|
+
|
|
994
|
+
// console.log(DEBUG.join("\n"));
|
|
970
995
|
return nextLayout;
|
|
971
996
|
}
|
|
972
997
|
|
|
@@ -1156,9 +1181,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1156
1181
|
if (size != null && collapsible) {
|
|
1157
1182
|
const nextLayout = adjustLayoutByDelta({
|
|
1158
1183
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1159
|
-
layout,
|
|
1184
|
+
initialLayout: layout,
|
|
1160
1185
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1161
1186
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1187
|
+
prevLayout: layout,
|
|
1162
1188
|
trigger: "keyboard"
|
|
1163
1189
|
});
|
|
1164
1190
|
if (layout !== nextLayout) {
|
|
@@ -1790,9 +1816,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1790
1816
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1791
1817
|
const nextLayout = adjustLayoutByDelta({
|
|
1792
1818
|
delta,
|
|
1793
|
-
|
|
1819
|
+
initialLayout: prevLayout,
|
|
1794
1820
|
panelConstraints: panelConstraintsArray,
|
|
1795
1821
|
pivotIndices,
|
|
1822
|
+
prevLayout,
|
|
1796
1823
|
trigger: "imperative-api"
|
|
1797
1824
|
});
|
|
1798
1825
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1832,9 +1859,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1832
1859
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1833
1860
|
const nextLayout = adjustLayoutByDelta({
|
|
1834
1861
|
delta,
|
|
1835
|
-
|
|
1862
|
+
initialLayout: prevLayout,
|
|
1836
1863
|
panelConstraints: panelConstraintsArray,
|
|
1837
1864
|
pivotIndices,
|
|
1865
|
+
prevLayout,
|
|
1838
1866
|
trigger: "imperative-api"
|
|
1839
1867
|
});
|
|
1840
1868
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -2016,9 +2044,10 @@ function PanelGroupWithForwardedRef({
|
|
|
2016
2044
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
2017
2045
|
const nextLayout = adjustLayoutByDelta({
|
|
2018
2046
|
delta,
|
|
2019
|
-
|
|
2047
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
2020
2048
|
panelConstraints,
|
|
2021
2049
|
pivotIndices,
|
|
2050
|
+
prevLayout,
|
|
2022
2051
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
2023
2052
|
});
|
|
2024
2053
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -2074,9 +2103,10 @@ function PanelGroupWithForwardedRef({
|
|
|
2074
2103
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
2075
2104
|
const nextLayout = adjustLayoutByDelta({
|
|
2076
2105
|
delta,
|
|
2077
|
-
|
|
2106
|
+
initialLayout: prevLayout,
|
|
2078
2107
|
panelConstraints: panelConstraintsArray,
|
|
2079
2108
|
pivotIndices,
|
|
2109
|
+
prevLayout,
|
|
2080
2110
|
trigger: "imperative-api"
|
|
2081
2111
|
});
|
|
2082
2112
|
if (!compareLayouts(prevLayout, nextLayout)) {
|