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.
- package/CHANGELOG.md +8 -0
- package/dist/react-resizable-panels.browser.cjs.js +78 -48
- package/dist/react-resizable-panels.browser.development.cjs.js +78 -48
- package/dist/react-resizable-panels.browser.development.esm.js +78 -48
- package/dist/react-resizable-panels.browser.esm.js +78 -48
- package/dist/react-resizable-panels.cjs.js +78 -48
- package/dist/react-resizable-panels.development.cjs.js +78 -48
- package/dist/react-resizable-panels.development.esm.js +78 -48
- package/dist/react-resizable-panels.development.node.cjs.js +78 -48
- package/dist/react-resizable-panels.development.node.esm.js +78 -48
- package/dist/react-resizable-panels.esm.js +78 -48
- package/dist/react-resizable-panels.node.cjs.js +78 -48
- package/dist/react-resizable-panels.node.esm.js +78 -48
- 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/events/getResizeEventCoordinates.ts +5 -5
- package/src/utils/numbers/fuzzyLayoutsEqual.ts +22 -0
|
@@ -260,15 +260,15 @@ function isTouchEvent(event) {
|
|
|
260
260
|
function getResizeEventCoordinates(event) {
|
|
261
261
|
if (isMouseEvent(event)) {
|
|
262
262
|
return {
|
|
263
|
-
x: event.
|
|
264
|
-
y: event.
|
|
263
|
+
x: event.clientX,
|
|
264
|
+
y: event.clientY
|
|
265
265
|
};
|
|
266
266
|
} else if (isTouchEvent(event)) {
|
|
267
267
|
const touch = event.touches[0];
|
|
268
|
-
if (touch && touch.
|
|
268
|
+
if (touch && touch.clientX && touch.clientY) {
|
|
269
269
|
return {
|
|
270
|
-
x: touch.
|
|
271
|
-
y: touch.
|
|
270
|
+
x: touch.clientX,
|
|
271
|
+
y: touch.clientY
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
}
|
|
@@ -683,6 +683,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
683
683
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
684
684
|
}
|
|
685
685
|
|
|
686
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
687
|
+
if (actual.length !== expected.length) {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
for (let index = 0; index < actual.length; index++) {
|
|
691
|
+
const actualSize = actual[index];
|
|
692
|
+
const expectedSize = expected[index];
|
|
693
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
|
|
686
700
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
687
701
|
function resizePanel({
|
|
688
702
|
panelConstraints: panelConstraintsArray,
|
|
@@ -718,26 +732,29 @@ function resizePanel({
|
|
|
718
732
|
// All units must be in percentages; pixel values should be pre-converted
|
|
719
733
|
function adjustLayoutByDelta({
|
|
720
734
|
delta,
|
|
721
|
-
|
|
735
|
+
initialLayout,
|
|
722
736
|
panelConstraints: panelConstraintsArray,
|
|
723
737
|
pivotIndices,
|
|
738
|
+
prevLayout,
|
|
724
739
|
trigger
|
|
725
740
|
}) {
|
|
726
741
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
727
|
-
return
|
|
742
|
+
return initialLayout;
|
|
728
743
|
}
|
|
729
|
-
const nextLayout = [...
|
|
744
|
+
const nextLayout = [...initialLayout];
|
|
730
745
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
731
746
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
732
747
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
733
748
|
let deltaApplied = 0;
|
|
734
749
|
|
|
735
|
-
//const DEBUG = [];
|
|
736
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
737
|
-
//DEBUG.push(`
|
|
738
|
-
//DEBUG.push(`
|
|
739
|
-
//DEBUG.push(`
|
|
740
|
-
//DEBUG.push("");
|
|
750
|
+
// const DEBUG = [];
|
|
751
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
752
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
753
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
754
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
755
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
756
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
757
|
+
// DEBUG.push("");
|
|
741
758
|
|
|
742
759
|
// A resizing panel affects the panels before or after it.
|
|
743
760
|
//
|
|
@@ -762,18 +779,18 @@ function adjustLayoutByDelta({
|
|
|
762
779
|
minSize = 0
|
|
763
780
|
} = panelConstraints;
|
|
764
781
|
|
|
765
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
766
|
-
//DEBUG.push(` -> collapsible? ${
|
|
782
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
783
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
767
784
|
if (collapsible) {
|
|
768
|
-
const prevSize =
|
|
785
|
+
const prevSize = initialLayout[index];
|
|
769
786
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
770
787
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
771
788
|
const localDelta = minSize - prevSize;
|
|
772
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
789
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
773
790
|
|
|
774
791
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
775
792
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
776
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
793
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
777
794
|
}
|
|
778
795
|
}
|
|
779
796
|
}
|
|
@@ -790,24 +807,24 @@ function adjustLayoutByDelta({
|
|
|
790
807
|
minSize = 0
|
|
791
808
|
} = panelConstraints;
|
|
792
809
|
|
|
793
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
794
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
810
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
811
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
795
812
|
if (collapsible) {
|
|
796
|
-
const prevSize =
|
|
813
|
+
const prevSize = initialLayout[index];
|
|
797
814
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
798
815
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
799
816
|
const localDelta = prevSize - collapsedSize;
|
|
800
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
817
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
801
818
|
|
|
802
819
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
803
820
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
804
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
821
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
805
822
|
}
|
|
806
823
|
}
|
|
807
824
|
}
|
|
808
825
|
}
|
|
809
826
|
}
|
|
810
|
-
//DEBUG.push("");
|
|
827
|
+
// DEBUG.push("");
|
|
811
828
|
}
|
|
812
829
|
|
|
813
830
|
{
|
|
@@ -821,9 +838,9 @@ function adjustLayoutByDelta({
|
|
|
821
838
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
822
839
|
let maxAvailableDelta = 0;
|
|
823
840
|
|
|
824
|
-
//DEBUG.push("pre calc...");
|
|
841
|
+
// DEBUG.push("pre calc...");
|
|
825
842
|
while (true) {
|
|
826
|
-
const prevSize =
|
|
843
|
+
const prevSize = initialLayout[index];
|
|
827
844
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
828
845
|
const maxSafeSize = resizePanel({
|
|
829
846
|
panelConstraints: panelConstraintsArray,
|
|
@@ -831,7 +848,7 @@ function adjustLayoutByDelta({
|
|
|
831
848
|
size: 100
|
|
832
849
|
});
|
|
833
850
|
const delta = maxSafeSize - prevSize;
|
|
834
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
851
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
835
852
|
|
|
836
853
|
maxAvailableDelta += delta;
|
|
837
854
|
index += increment;
|
|
@@ -840,11 +857,11 @@ function adjustLayoutByDelta({
|
|
|
840
857
|
}
|
|
841
858
|
}
|
|
842
859
|
|
|
843
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
860
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
844
861
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
845
862
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
846
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
847
|
-
//DEBUG.push("");
|
|
863
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
864
|
+
// DEBUG.push("");
|
|
848
865
|
}
|
|
849
866
|
|
|
850
867
|
{
|
|
@@ -854,7 +871,7 @@ function adjustLayoutByDelta({
|
|
|
854
871
|
let index = pivotIndex;
|
|
855
872
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
856
873
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
857
|
-
const prevSize =
|
|
874
|
+
const prevSize = initialLayout[index];
|
|
858
875
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
859
876
|
const unsafeSize = prevSize - deltaRemaining;
|
|
860
877
|
const safeSize = resizePanel({
|
|
@@ -878,20 +895,22 @@ function adjustLayoutByDelta({
|
|
|
878
895
|
}
|
|
879
896
|
}
|
|
880
897
|
}
|
|
881
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
882
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
883
|
-
//DEBUG.push("");
|
|
898
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
899
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
900
|
+
// DEBUG.push("");
|
|
884
901
|
|
|
885
902
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
886
903
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
887
|
-
if (
|
|
888
|
-
//
|
|
904
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
905
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
906
|
+
// console.log(DEBUG.join("\n"));
|
|
907
|
+
|
|
889
908
|
return prevLayout;
|
|
890
909
|
}
|
|
891
910
|
{
|
|
892
911
|
// Now distribute the applied delta to the panels in the other direction
|
|
893
912
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
894
|
-
const prevSize =
|
|
913
|
+
const prevSize = initialLayout[pivotIndex];
|
|
895
914
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
896
915
|
const unsafeSize = prevSize + deltaApplied;
|
|
897
916
|
const safeSize = resizePanel({
|
|
@@ -932,17 +951,23 @@ function adjustLayoutByDelta({
|
|
|
932
951
|
}
|
|
933
952
|
}
|
|
934
953
|
}
|
|
935
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
936
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
937
|
-
//DEBUG.push("");
|
|
954
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
955
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
956
|
+
// DEBUG.push("");
|
|
938
957
|
|
|
939
958
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
940
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
941
|
-
//console.log(DEBUG.join("\n"));
|
|
959
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
942
960
|
|
|
961
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
962
|
+
// In that case, fall back to our most recent valid layout
|
|
943
963
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
964
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
965
|
+
// console.log(DEBUG.join("\n"));
|
|
966
|
+
|
|
944
967
|
return prevLayout;
|
|
945
968
|
}
|
|
969
|
+
|
|
970
|
+
// console.log(DEBUG.join("\n"));
|
|
946
971
|
return nextLayout;
|
|
947
972
|
}
|
|
948
973
|
|
|
@@ -1132,9 +1157,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1132
1157
|
if (size != null && collapsible) {
|
|
1133
1158
|
const nextLayout = adjustLayoutByDelta({
|
|
1134
1159
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1135
|
-
layout,
|
|
1160
|
+
initialLayout: layout,
|
|
1136
1161
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1137
1162
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1163
|
+
prevLayout: layout,
|
|
1138
1164
|
trigger: "keyboard"
|
|
1139
1165
|
});
|
|
1140
1166
|
if (layout !== nextLayout) {
|
|
@@ -1766,9 +1792,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1766
1792
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1767
1793
|
const nextLayout = adjustLayoutByDelta({
|
|
1768
1794
|
delta,
|
|
1769
|
-
|
|
1795
|
+
initialLayout: prevLayout,
|
|
1770
1796
|
panelConstraints: panelConstraintsArray,
|
|
1771
1797
|
pivotIndices,
|
|
1798
|
+
prevLayout,
|
|
1772
1799
|
trigger: "imperative-api"
|
|
1773
1800
|
});
|
|
1774
1801
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1808,9 +1835,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1808
1835
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1809
1836
|
const nextLayout = adjustLayoutByDelta({
|
|
1810
1837
|
delta,
|
|
1811
|
-
|
|
1838
|
+
initialLayout: prevLayout,
|
|
1812
1839
|
panelConstraints: panelConstraintsArray,
|
|
1813
1840
|
pivotIndices,
|
|
1841
|
+
prevLayout,
|
|
1814
1842
|
trigger: "imperative-api"
|
|
1815
1843
|
});
|
|
1816
1844
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1992,9 +2020,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1992
2020
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1993
2021
|
const nextLayout = adjustLayoutByDelta({
|
|
1994
2022
|
delta,
|
|
1995
|
-
|
|
2023
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
1996
2024
|
panelConstraints,
|
|
1997
2025
|
pivotIndices,
|
|
2026
|
+
prevLayout,
|
|
1998
2027
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
1999
2028
|
});
|
|
2000
2029
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -2050,9 +2079,10 @@ function PanelGroupWithForwardedRef({
|
|
|
2050
2079
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
2051
2080
|
const nextLayout = adjustLayoutByDelta({
|
|
2052
2081
|
delta,
|
|
2053
|
-
|
|
2082
|
+
initialLayout: prevLayout,
|
|
2054
2083
|
panelConstraints: panelConstraintsArray,
|
|
2055
2084
|
pivotIndices,
|
|
2085
|
+
prevLayout,
|
|
2056
2086
|
trigger: "imperative-api"
|
|
2057
2087
|
});
|
|
2058
2088
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -246,15 +246,15 @@ function isTouchEvent(event) {
|
|
|
246
246
|
function getResizeEventCoordinates(event) {
|
|
247
247
|
if (isMouseEvent(event)) {
|
|
248
248
|
return {
|
|
249
|
-
x: event.
|
|
250
|
-
y: event.
|
|
249
|
+
x: event.clientX,
|
|
250
|
+
y: event.clientY
|
|
251
251
|
};
|
|
252
252
|
} else if (isTouchEvent(event)) {
|
|
253
253
|
const touch = event.touches[0];
|
|
254
|
-
if (touch && touch.
|
|
254
|
+
if (touch && touch.clientX && touch.clientY) {
|
|
255
255
|
return {
|
|
256
|
-
x: touch.
|
|
257
|
-
y: touch.
|
|
256
|
+
x: touch.clientX,
|
|
257
|
+
y: touch.clientY
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
}
|
|
@@ -669,6 +669,20 @@ function fuzzyNumbersEqual(actual, expected, fractionDigits) {
|
|
|
669
669
|
return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
+
function fuzzyLayoutsEqual(actual, expected, fractionDigits) {
|
|
673
|
+
if (actual.length !== expected.length) {
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
for (let index = 0; index < actual.length; index++) {
|
|
677
|
+
const actualSize = actual[index];
|
|
678
|
+
const expectedSize = expected[index];
|
|
679
|
+
if (!fuzzyNumbersEqual(actualSize, expectedSize, fractionDigits)) {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
685
|
+
|
|
672
686
|
// Panel size must be in percentages; pixel values should be pre-converted
|
|
673
687
|
function resizePanel({
|
|
674
688
|
panelConstraints: panelConstraintsArray,
|
|
@@ -704,26 +718,29 @@ function resizePanel({
|
|
|
704
718
|
// All units must be in percentages; pixel values should be pre-converted
|
|
705
719
|
function adjustLayoutByDelta({
|
|
706
720
|
delta,
|
|
707
|
-
|
|
721
|
+
initialLayout,
|
|
708
722
|
panelConstraints: panelConstraintsArray,
|
|
709
723
|
pivotIndices,
|
|
724
|
+
prevLayout,
|
|
710
725
|
trigger
|
|
711
726
|
}) {
|
|
712
727
|
if (fuzzyNumbersEqual(delta, 0)) {
|
|
713
|
-
return
|
|
728
|
+
return initialLayout;
|
|
714
729
|
}
|
|
715
|
-
const nextLayout = [...
|
|
730
|
+
const nextLayout = [...initialLayout];
|
|
716
731
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
717
732
|
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
718
733
|
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
719
734
|
let deltaApplied = 0;
|
|
720
735
|
|
|
721
|
-
//const DEBUG = [];
|
|
722
|
-
//DEBUG.push(`adjustLayoutByDelta()
|
|
723
|
-
//DEBUG.push(`
|
|
724
|
-
//DEBUG.push(`
|
|
725
|
-
//DEBUG.push(`
|
|
726
|
-
//DEBUG.push("");
|
|
736
|
+
// const DEBUG = [];
|
|
737
|
+
// DEBUG.push(`adjustLayoutByDelta()`);
|
|
738
|
+
// DEBUG.push(` initialLayout: ${initialLayout.join(", ")}`);
|
|
739
|
+
// DEBUG.push(` prevLayout: ${prevLayout.join(", ")}`);
|
|
740
|
+
// DEBUG.push(` delta: ${delta}`);
|
|
741
|
+
// DEBUG.push(` pivotIndices: ${pivotIndices.join(", ")}`);
|
|
742
|
+
// DEBUG.push(` trigger: ${trigger}`);
|
|
743
|
+
// DEBUG.push("");
|
|
727
744
|
|
|
728
745
|
// A resizing panel affects the panels before or after it.
|
|
729
746
|
//
|
|
@@ -748,18 +765,18 @@ function adjustLayoutByDelta({
|
|
|
748
765
|
minSize = 0
|
|
749
766
|
} = panelConstraints;
|
|
750
767
|
|
|
751
|
-
//DEBUG.push(`edge case check 1: ${index}`);
|
|
752
|
-
//DEBUG.push(` -> collapsible? ${
|
|
768
|
+
// DEBUG.push(`edge case check 1: ${index}`);
|
|
769
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
753
770
|
if (collapsible) {
|
|
754
|
-
const prevSize =
|
|
771
|
+
const prevSize = initialLayout[index];
|
|
755
772
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
756
773
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
757
774
|
const localDelta = minSize - prevSize;
|
|
758
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
775
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
759
776
|
|
|
760
777
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
761
778
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
762
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
779
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
763
780
|
}
|
|
764
781
|
}
|
|
765
782
|
}
|
|
@@ -776,24 +793,24 @@ function adjustLayoutByDelta({
|
|
|
776
793
|
minSize = 0
|
|
777
794
|
} = panelConstraints;
|
|
778
795
|
|
|
779
|
-
//DEBUG.push(`edge case check 2: ${index}`);
|
|
780
|
-
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
796
|
+
// DEBUG.push(`edge case check 2: ${index}`);
|
|
797
|
+
// DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
781
798
|
if (collapsible) {
|
|
782
|
-
const prevSize =
|
|
799
|
+
const prevSize = initialLayout[index];
|
|
783
800
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
784
801
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
785
802
|
const localDelta = prevSize - collapsedSize;
|
|
786
|
-
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
803
|
+
// DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
787
804
|
|
|
788
805
|
if (fuzzyCompareNumbers(localDelta, Math.abs(delta)) > 0) {
|
|
789
806
|
delta = delta < 0 ? 0 - localDelta : localDelta;
|
|
790
|
-
//DEBUG.push(` -> delta: ${delta}`);
|
|
807
|
+
// DEBUG.push(` -> delta: ${delta}`);
|
|
791
808
|
}
|
|
792
809
|
}
|
|
793
810
|
}
|
|
794
811
|
}
|
|
795
812
|
}
|
|
796
|
-
//DEBUG.push("");
|
|
813
|
+
// DEBUG.push("");
|
|
797
814
|
}
|
|
798
815
|
|
|
799
816
|
{
|
|
@@ -807,9 +824,9 @@ function adjustLayoutByDelta({
|
|
|
807
824
|
let index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
808
825
|
let maxAvailableDelta = 0;
|
|
809
826
|
|
|
810
|
-
//DEBUG.push("pre calc...");
|
|
827
|
+
// DEBUG.push("pre calc...");
|
|
811
828
|
while (true) {
|
|
812
|
-
const prevSize =
|
|
829
|
+
const prevSize = initialLayout[index];
|
|
813
830
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
814
831
|
const maxSafeSize = resizePanel({
|
|
815
832
|
panelConstraints: panelConstraintsArray,
|
|
@@ -817,7 +834,7 @@ function adjustLayoutByDelta({
|
|
|
817
834
|
size: 100
|
|
818
835
|
});
|
|
819
836
|
const delta = maxSafeSize - prevSize;
|
|
820
|
-
//DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
837
|
+
// DEBUG.push(` ${index}: ${prevSize} -> ${maxSafeSize}`);
|
|
821
838
|
|
|
822
839
|
maxAvailableDelta += delta;
|
|
823
840
|
index += increment;
|
|
@@ -826,11 +843,11 @@ function adjustLayoutByDelta({
|
|
|
826
843
|
}
|
|
827
844
|
}
|
|
828
845
|
|
|
829
|
-
//DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
846
|
+
// DEBUG.push(` -> max available delta: ${maxAvailableDelta}`);
|
|
830
847
|
const minAbsDelta = Math.min(Math.abs(delta), Math.abs(maxAvailableDelta));
|
|
831
848
|
delta = delta < 0 ? 0 - minAbsDelta : minAbsDelta;
|
|
832
|
-
//DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
833
|
-
//DEBUG.push("");
|
|
849
|
+
// DEBUG.push(` -> adjusted delta: ${delta}`);
|
|
850
|
+
// DEBUG.push("");
|
|
834
851
|
}
|
|
835
852
|
|
|
836
853
|
{
|
|
@@ -840,7 +857,7 @@ function adjustLayoutByDelta({
|
|
|
840
857
|
let index = pivotIndex;
|
|
841
858
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
842
859
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
843
|
-
const prevSize =
|
|
860
|
+
const prevSize = initialLayout[index];
|
|
844
861
|
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
845
862
|
const unsafeSize = prevSize - deltaRemaining;
|
|
846
863
|
const safeSize = resizePanel({
|
|
@@ -864,20 +881,22 @@ function adjustLayoutByDelta({
|
|
|
864
881
|
}
|
|
865
882
|
}
|
|
866
883
|
}
|
|
867
|
-
//DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
868
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
869
|
-
//DEBUG.push("");
|
|
884
|
+
// DEBUG.push(`after 1: ${nextLayout.join(", ")}`);
|
|
885
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
886
|
+
// DEBUG.push("");
|
|
870
887
|
|
|
871
888
|
// If we were unable to resize any of the panels panels, return the previous state.
|
|
872
889
|
// This will essentially bailout and ignore e.g. drags past a panel's boundaries
|
|
873
|
-
if (
|
|
874
|
-
//
|
|
890
|
+
if (fuzzyLayoutsEqual(prevLayout, nextLayout)) {
|
|
891
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
892
|
+
// console.log(DEBUG.join("\n"));
|
|
893
|
+
|
|
875
894
|
return prevLayout;
|
|
876
895
|
}
|
|
877
896
|
{
|
|
878
897
|
// Now distribute the applied delta to the panels in the other direction
|
|
879
898
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
880
|
-
const prevSize =
|
|
899
|
+
const prevSize = initialLayout[pivotIndex];
|
|
881
900
|
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
882
901
|
const unsafeSize = prevSize + deltaApplied;
|
|
883
902
|
const safeSize = resizePanel({
|
|
@@ -918,17 +937,23 @@ function adjustLayoutByDelta({
|
|
|
918
937
|
}
|
|
919
938
|
}
|
|
920
939
|
}
|
|
921
|
-
//DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
922
|
-
//DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
923
|
-
//DEBUG.push("");
|
|
940
|
+
// DEBUG.push(`after 2: ${nextLayout.join(", ")}`);
|
|
941
|
+
// DEBUG.push(` deltaApplied: ${deltaApplied}`);
|
|
942
|
+
// DEBUG.push("");
|
|
924
943
|
|
|
925
944
|
const totalSize = nextLayout.reduce((total, size) => size + total, 0);
|
|
926
|
-
//DEBUG.push(`total size: ${totalSize}`);
|
|
927
|
-
//console.log(DEBUG.join("\n"));
|
|
945
|
+
// DEBUG.push(`total size: ${totalSize}`);
|
|
928
946
|
|
|
947
|
+
// If our new layout doesn't add up to 100%, that means the requested delta can't be applied
|
|
948
|
+
// In that case, fall back to our most recent valid layout
|
|
929
949
|
if (!fuzzyNumbersEqual(totalSize, 100)) {
|
|
950
|
+
// DEBUG.push(`bailout to previous layout: ${prevLayout.join(", ")}`);
|
|
951
|
+
// console.log(DEBUG.join("\n"));
|
|
952
|
+
|
|
930
953
|
return prevLayout;
|
|
931
954
|
}
|
|
955
|
+
|
|
956
|
+
// console.log(DEBUG.join("\n"));
|
|
932
957
|
return nextLayout;
|
|
933
958
|
}
|
|
934
959
|
|
|
@@ -1035,9 +1060,10 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1035
1060
|
if (size != null && collapsible) {
|
|
1036
1061
|
const nextLayout = adjustLayoutByDelta({
|
|
1037
1062
|
delta: fuzzyNumbersEqual(size, collapsedSize) ? minSize - collapsedSize : collapsedSize - size,
|
|
1038
|
-
layout,
|
|
1063
|
+
initialLayout: layout,
|
|
1039
1064
|
panelConstraints: panelDataArray.map(panelData => panelData.constraints),
|
|
1040
1065
|
pivotIndices: determinePivotIndices(groupId, handleId, panelGroupElement),
|
|
1066
|
+
prevLayout: layout,
|
|
1041
1067
|
trigger: "keyboard"
|
|
1042
1068
|
});
|
|
1043
1069
|
if (layout !== nextLayout) {
|
|
@@ -1614,9 +1640,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1614
1640
|
const delta = isLastPanel ? panelSize - collapsedSize : collapsedSize - panelSize;
|
|
1615
1641
|
const nextLayout = adjustLayoutByDelta({
|
|
1616
1642
|
delta,
|
|
1617
|
-
|
|
1643
|
+
initialLayout: prevLayout,
|
|
1618
1644
|
panelConstraints: panelConstraintsArray,
|
|
1619
1645
|
pivotIndices,
|
|
1646
|
+
prevLayout,
|
|
1620
1647
|
trigger: "imperative-api"
|
|
1621
1648
|
});
|
|
1622
1649
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1656,9 +1683,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1656
1683
|
const delta = isLastPanel ? panelSize - baseSize : baseSize - panelSize;
|
|
1657
1684
|
const nextLayout = adjustLayoutByDelta({
|
|
1658
1685
|
delta,
|
|
1659
|
-
|
|
1686
|
+
initialLayout: prevLayout,
|
|
1660
1687
|
panelConstraints: panelConstraintsArray,
|
|
1661
1688
|
pivotIndices,
|
|
1689
|
+
prevLayout,
|
|
1662
1690
|
trigger: "imperative-api"
|
|
1663
1691
|
});
|
|
1664
1692
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
@@ -1784,9 +1812,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1784
1812
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1785
1813
|
const nextLayout = adjustLayoutByDelta({
|
|
1786
1814
|
delta,
|
|
1787
|
-
|
|
1815
|
+
initialLayout: initialLayout !== null && initialLayout !== void 0 ? initialLayout : prevLayout,
|
|
1788
1816
|
panelConstraints,
|
|
1789
1817
|
pivotIndices,
|
|
1818
|
+
prevLayout,
|
|
1790
1819
|
trigger: isKeyDown(event) ? "keyboard" : "mouse-or-touch"
|
|
1791
1820
|
});
|
|
1792
1821
|
const layoutChanged = !compareLayouts(prevLayout, nextLayout);
|
|
@@ -1842,9 +1871,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1842
1871
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1843
1872
|
const nextLayout = adjustLayoutByDelta({
|
|
1844
1873
|
delta,
|
|
1845
|
-
|
|
1874
|
+
initialLayout: prevLayout,
|
|
1846
1875
|
panelConstraints: panelConstraintsArray,
|
|
1847
1876
|
pivotIndices,
|
|
1877
|
+
prevLayout,
|
|
1848
1878
|
trigger: "imperative-api"
|
|
1849
1879
|
});
|
|
1850
1880
|
if (!compareLayouts(prevLayout, nextLayout)) {
|