react-resizable-panels 2.0.9 → 2.0.11
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/declarations/src/utils/assert.d.ts +1 -1
- package/dist/react-resizable-panels.browser.cjs.js +55 -57
- package/dist/react-resizable-panels.browser.development.cjs.js +57 -59
- package/dist/react-resizable-panels.browser.development.esm.js +57 -59
- package/dist/react-resizable-panels.browser.esm.js +55 -57
- package/dist/react-resizable-panels.cjs.js +55 -57
- package/dist/react-resizable-panels.development.cjs.js +57 -59
- package/dist/react-resizable-panels.development.esm.js +57 -59
- package/dist/react-resizable-panels.development.node.cjs.js +53 -55
- package/dist/react-resizable-panels.development.node.esm.js +53 -55
- package/dist/react-resizable-panels.esm.js +55 -57
- package/dist/react-resizable-panels.node.cjs.js +51 -53
- package/dist/react-resizable-panels.node.esm.js +51 -53
- package/package.json +1 -1
- package/src/Panel.test.tsx +23 -23
- package/src/PanelGroup.test.tsx +32 -3
- package/src/PanelGroup.ts +25 -7
- package/src/PanelResizeHandle.test.tsx +3 -3
- package/src/PanelResizeHandle.ts +1 -1
- package/src/hooks/useWindowSplitterBehavior.ts +5 -2
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +5 -5
- package/src/utils/adjustLayoutByDelta.ts +47 -20
- package/src/utils/assert.ts +1 -1
- package/src/utils/calculateAriaValues.ts +1 -1
- package/src/utils/calculateDragOffsetPercentage.ts +6 -3
- package/src/utils/calculateUnsafeDefaultLayout.ts +2 -2
- package/src/utils/callPanelCallbacks.ts +1 -1
- package/src/utils/events/getResizeEventCoordinates.ts +5 -5
- package/src/utils/resizePanel.ts +4 -1
- package/src/utils/test-utils.ts +1 -1
- package/src/utils/validatePanelConstraints.ts +4 -1
- package/src/utils/validatePanelGroupLayout.ts +3 -3
- package/src/vendor/stacking-order.ts +5 -2
|
@@ -249,15 +249,15 @@ function isTouchEvent(event) {
|
|
|
249
249
|
function getResizeEventCoordinates(event) {
|
|
250
250
|
if (isMouseEvent(event)) {
|
|
251
251
|
return {
|
|
252
|
-
x: event.
|
|
253
|
-
y: event.
|
|
252
|
+
x: event.clientX,
|
|
253
|
+
y: event.clientY
|
|
254
254
|
};
|
|
255
255
|
} else if (isTouchEvent(event)) {
|
|
256
256
|
const touch = event.touches[0];
|
|
257
|
-
if (touch && touch.
|
|
257
|
+
if (touch && touch.clientX && touch.clientY) {
|
|
258
258
|
return {
|
|
259
|
-
x: touch.
|
|
260
|
-
y: touch.
|
|
259
|
+
x: touch.clientX,
|
|
260
|
+
y: touch.clientY
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
263
|
}
|
|
@@ -303,7 +303,7 @@ function compare(a, b) {
|
|
|
303
303
|
b = ancestors.b.pop();
|
|
304
304
|
common_ancestor = a;
|
|
305
305
|
}
|
|
306
|
-
assert(common_ancestor);
|
|
306
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
307
307
|
const z_indexes = {
|
|
308
308
|
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
309
309
|
b: get_z_index(find_stacking_context(ancestors.b))
|
|
@@ -361,7 +361,7 @@ function find_stacking_context(nodes) {
|
|
|
361
361
|
let i = nodes.length;
|
|
362
362
|
while (i--) {
|
|
363
363
|
const node = nodes[i];
|
|
364
|
-
assert(node);
|
|
364
|
+
assert(node, "Missing node");
|
|
365
365
|
if (creates_stacking_context(node)) return node;
|
|
366
366
|
}
|
|
367
367
|
return null;
|
|
@@ -648,7 +648,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
648
648
|
});
|
|
649
649
|
}
|
|
650
650
|
|
|
651
|
-
function assert(expectedCondition, message
|
|
651
|
+
function assert(expectedCondition, message) {
|
|
652
652
|
if (!expectedCondition) {
|
|
653
653
|
console.error(message);
|
|
654
654
|
throw Error(message);
|
|
@@ -679,7 +679,7 @@ function resizePanel({
|
|
|
679
679
|
size
|
|
680
680
|
}) {
|
|
681
681
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
682
|
-
assert(panelConstraints != null);
|
|
682
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
683
683
|
let {
|
|
684
684
|
collapsedSize = 0,
|
|
685
685
|
collapsible,
|
|
@@ -717,8 +717,8 @@ function adjustLayoutByDelta({
|
|
|
717
717
|
}
|
|
718
718
|
const nextLayout = [...prevLayout];
|
|
719
719
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
720
|
-
assert(firstPivotIndex != null);
|
|
721
|
-
assert(secondPivotIndex != null);
|
|
720
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
721
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
722
722
|
let deltaApplied = 0;
|
|
723
723
|
|
|
724
724
|
//const DEBUG = [];
|
|
@@ -744,19 +744,18 @@ function adjustLayoutByDelta({
|
|
|
744
744
|
// Check if we should expand a collapsed panel
|
|
745
745
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
746
746
|
const panelConstraints = panelConstraintsArray[index];
|
|
747
|
-
assert(panelConstraints);
|
|
747
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
748
|
+
const {
|
|
749
|
+
collapsedSize = 0,
|
|
750
|
+
collapsible,
|
|
751
|
+
minSize = 0
|
|
752
|
+
} = panelConstraints;
|
|
748
753
|
|
|
749
754
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
750
755
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
751
|
-
if (
|
|
756
|
+
if (collapsible) {
|
|
752
757
|
const prevSize = prevLayout[index];
|
|
753
|
-
assert(prevSize != null);
|
|
754
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
755
|
-
assert(panelConstraints);
|
|
756
|
-
const {
|
|
757
|
-
collapsedSize = 0,
|
|
758
|
-
minSize = 0
|
|
759
|
-
} = panelConstraints;
|
|
758
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
760
759
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
761
760
|
const localDelta = minSize - prevSize;
|
|
762
761
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -773,22 +772,18 @@ function adjustLayoutByDelta({
|
|
|
773
772
|
// Check if we should collapse a panel at its minimum size
|
|
774
773
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
775
774
|
const panelConstraints = panelConstraintsArray[index];
|
|
776
|
-
assert(panelConstraints);
|
|
775
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
777
776
|
const {
|
|
778
|
-
|
|
777
|
+
collapsedSize = 0,
|
|
778
|
+
collapsible,
|
|
779
|
+
minSize = 0
|
|
779
780
|
} = panelConstraints;
|
|
780
781
|
|
|
781
782
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
782
783
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
783
784
|
if (collapsible) {
|
|
784
785
|
const prevSize = prevLayout[index];
|
|
785
|
-
assert(prevSize != null);
|
|
786
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
787
|
-
assert(panelConstraints);
|
|
788
|
-
const {
|
|
789
|
-
collapsedSize = 0,
|
|
790
|
-
minSize = 0
|
|
791
|
-
} = panelConstraints;
|
|
786
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
792
787
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
793
788
|
const localDelta = prevSize - collapsedSize;
|
|
794
789
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -818,7 +813,7 @@ function adjustLayoutByDelta({
|
|
|
818
813
|
//DEBUG.push("pre calc...");
|
|
819
814
|
while (true) {
|
|
820
815
|
const prevSize = prevLayout[index];
|
|
821
|
-
assert(prevSize != null);
|
|
816
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
822
817
|
const maxSafeSize = resizePanel({
|
|
823
818
|
panelConstraints: panelConstraintsArray,
|
|
824
819
|
panelIndex: index,
|
|
@@ -849,7 +844,7 @@ function adjustLayoutByDelta({
|
|
|
849
844
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
850
845
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
851
846
|
const prevSize = prevLayout[index];
|
|
852
|
-
assert(prevSize != null);
|
|
847
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
853
848
|
const unsafeSize = prevSize - deltaRemaining;
|
|
854
849
|
const safeSize = resizePanel({
|
|
855
850
|
panelConstraints: panelConstraintsArray,
|
|
@@ -886,7 +881,7 @@ function adjustLayoutByDelta({
|
|
|
886
881
|
// Now distribute the applied delta to the panels in the other direction
|
|
887
882
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
888
883
|
const prevSize = prevLayout[pivotIndex];
|
|
889
|
-
assert(prevSize != null);
|
|
884
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
890
885
|
const unsafeSize = prevSize + deltaApplied;
|
|
891
886
|
const safeSize = resizePanel({
|
|
892
887
|
panelConstraints: panelConstraintsArray,
|
|
@@ -904,7 +899,7 @@ function adjustLayoutByDelta({
|
|
|
904
899
|
let index = pivotIndex;
|
|
905
900
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
906
901
|
const prevSize = nextLayout[index];
|
|
907
|
-
assert(prevSize != null);
|
|
902
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
908
903
|
const unsafeSize = prevSize + deltaRemaining;
|
|
909
904
|
const safeSize = resizePanel({
|
|
910
905
|
panelConstraints: panelConstraintsArray,
|
|
@@ -950,7 +945,7 @@ function calculateAriaValues({
|
|
|
950
945
|
let totalMinSize = 0;
|
|
951
946
|
let totalMaxSize = 0;
|
|
952
947
|
const firstIndex = pivotIndices[0];
|
|
953
|
-
assert(firstIndex != null);
|
|
948
|
+
assert(firstIndex != null, "No pivot index found");
|
|
954
949
|
|
|
955
950
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
956
951
|
panelsArray.forEach((panelData, index) => {
|
|
@@ -1059,7 +1054,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1059
1054
|
const resizeHandleElement = resizeHandleElements[index];
|
|
1060
1055
|
if (resizeHandleElement == null) ; else {
|
|
1061
1056
|
const panelData = panelDataArray[index];
|
|
1062
|
-
assert(panelData);
|
|
1057
|
+
assert(panelData, `No panel data found for index "${index}"`);
|
|
1063
1058
|
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
1064
1059
|
resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
|
|
1065
1060
|
resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
|
|
@@ -1080,17 +1075,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1080
1075
|
return;
|
|
1081
1076
|
}
|
|
1082
1077
|
const eagerValues = eagerValuesRef.current;
|
|
1083
|
-
assert(eagerValues);
|
|
1078
|
+
assert(eagerValues, `Eager values not found`);
|
|
1084
1079
|
const {
|
|
1085
1080
|
panelDataArray
|
|
1086
1081
|
} = eagerValues;
|
|
1087
1082
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1088
1083
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
1089
1084
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1090
|
-
assert(handles);
|
|
1085
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
1091
1086
|
const cleanupFunctions = handles.map(handle => {
|
|
1092
1087
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
1093
|
-
assert(handleId);
|
|
1088
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
1094
1089
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
1095
1090
|
if (idBefore == null || idAfter == null) {
|
|
1096
1091
|
return () => {};
|
|
@@ -1106,7 +1101,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1106
1101
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1107
1102
|
if (index >= 0) {
|
|
1108
1103
|
const panelData = panelDataArray[index];
|
|
1109
|
-
assert(panelData);
|
|
1104
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1110
1105
|
const size = layout[index];
|
|
1111
1106
|
const {
|
|
1112
1107
|
collapsedSize = 0,
|
|
@@ -1165,15 +1160,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1165
1160
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1166
1161
|
const isHorizontal = direction === "horizontal";
|
|
1167
1162
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1168
|
-
assert(handleElement);
|
|
1163
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1169
1164
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1170
|
-
assert(groupId);
|
|
1165
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1171
1166
|
let {
|
|
1172
1167
|
initialCursorPosition
|
|
1173
1168
|
} = initialDragState;
|
|
1174
1169
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1175
1170
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1176
|
-
assert(groupElement);
|
|
1171
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1177
1172
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1178
1173
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1179
1174
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1234,7 +1229,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1234
1229
|
// Distribute default sizes first
|
|
1235
1230
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1236
1231
|
const panelConstraints = panelConstraintsArray[index];
|
|
1237
|
-
assert(panelConstraints);
|
|
1232
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1238
1233
|
const {
|
|
1239
1234
|
defaultSize
|
|
1240
1235
|
} = panelConstraints;
|
|
@@ -1248,7 +1243,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1248
1243
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
1249
1244
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1250
1245
|
const panelConstraints = panelConstraintsArray[index];
|
|
1251
|
-
assert(panelConstraints);
|
|
1246
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1252
1247
|
const {
|
|
1253
1248
|
defaultSize
|
|
1254
1249
|
} = panelConstraints;
|
|
@@ -1268,7 +1263,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1268
1263
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1269
1264
|
layout.forEach((size, index) => {
|
|
1270
1265
|
const panelData = panelsArray[index];
|
|
1271
|
-
assert(panelData);
|
|
1266
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1272
1267
|
const {
|
|
1273
1268
|
callbacks,
|
|
1274
1269
|
constraints,
|
|
@@ -1458,7 +1453,7 @@ function validatePanelGroupLayout({
|
|
|
1458
1453
|
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
1459
1454
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1460
1455
|
const unsafeSize = nextLayout[index];
|
|
1461
|
-
assert(unsafeSize != null);
|
|
1456
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1462
1457
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1463
1458
|
nextLayout[index] = safeSize;
|
|
1464
1459
|
}
|
|
@@ -1468,7 +1463,7 @@ function validatePanelGroupLayout({
|
|
|
1468
1463
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1469
1464
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1470
1465
|
const unsafeSize = nextLayout[index];
|
|
1471
|
-
assert(unsafeSize != null);
|
|
1466
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1472
1467
|
const safeSize = resizePanel({
|
|
1473
1468
|
panelConstraints,
|
|
1474
1469
|
panelIndex: index,
|
|
@@ -1485,7 +1480,7 @@ function validatePanelGroupLayout({
|
|
|
1485
1480
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1486
1481
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1487
1482
|
const prevSize = nextLayout[index];
|
|
1488
|
-
assert(prevSize != null);
|
|
1483
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1489
1484
|
const unsafeSize = prevSize + remainingSize;
|
|
1490
1485
|
const safeSize = resizePanel({
|
|
1491
1486
|
panelConstraints,
|
|
@@ -1651,7 +1646,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1651
1646
|
panelSize,
|
|
1652
1647
|
pivotIndices
|
|
1653
1648
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1654
|
-
assert(panelSize != null);
|
|
1649
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1655
1650
|
if (panelSize !== collapsedSize) {
|
|
1656
1651
|
// Store size before collapse;
|
|
1657
1652
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1728,7 +1723,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1728
1723
|
const {
|
|
1729
1724
|
panelSize
|
|
1730
1725
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1731
|
-
assert(panelSize != null);
|
|
1726
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1732
1727
|
return panelSize;
|
|
1733
1728
|
}, []);
|
|
1734
1729
|
|
|
@@ -1772,7 +1767,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1772
1767
|
collapsible,
|
|
1773
1768
|
panelSize
|
|
1774
1769
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1775
|
-
assert(panelSize != null);
|
|
1770
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1776
1771
|
return !collapsible || panelSize > collapsedSize;
|
|
1777
1772
|
}, []);
|
|
1778
1773
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1939,7 +1934,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1939
1934
|
panelSize,
|
|
1940
1935
|
pivotIndices
|
|
1941
1936
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1942
|
-
assert(panelSize != null);
|
|
1937
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1943
1938
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1944
1939
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1945
1940
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1976,7 +1971,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1976
1971
|
const {
|
|
1977
1972
|
panelSize: prevPanelSize
|
|
1978
1973
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1979
|
-
|
|
1974
|
+
if (prevPanelSize == null) {
|
|
1975
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1980
1978
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1981
1979
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1982
1980
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1998,7 +1996,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1998
1996
|
return;
|
|
1999
1997
|
}
|
|
2000
1998
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
2001
|
-
assert(handleElement);
|
|
1999
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
2002
2000
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
2003
2001
|
setDragState({
|
|
2004
2002
|
dragHandleId,
|
|
@@ -2127,10 +2125,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2127
2125
|
{
|
|
2128
2126
|
event.preventDefault();
|
|
2129
2127
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2130
|
-
assert(groupId);
|
|
2128
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2131
2129
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2132
2130
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2133
|
-
assert(index !== null);
|
|
2131
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2134
2132
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2135
2133
|
const nextHandle = handles[nextIndex];
|
|
2136
2134
|
nextHandle.focus();
|
|
@@ -2202,7 +2200,7 @@ function PanelResizeHandle({
|
|
|
2202
2200
|
return;
|
|
2203
2201
|
}
|
|
2204
2202
|
const element = elementRef.current;
|
|
2205
|
-
assert(element);
|
|
2203
|
+
assert(element, "Element ref not attached");
|
|
2206
2204
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2207
2205
|
if (isActive) {
|
|
2208
2206
|
switch (action) {
|
|
@@ -235,15 +235,15 @@ function isTouchEvent(event) {
|
|
|
235
235
|
function getResizeEventCoordinates(event) {
|
|
236
236
|
if (isMouseEvent(event)) {
|
|
237
237
|
return {
|
|
238
|
-
x: event.
|
|
239
|
-
y: event.
|
|
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.
|
|
243
|
+
if (touch && touch.clientX && touch.clientY) {
|
|
244
244
|
return {
|
|
245
|
-
x: touch.
|
|
246
|
-
y: touch.
|
|
245
|
+
x: touch.clientX,
|
|
246
|
+
y: touch.clientY
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -289,7 +289,7 @@ function compare(a, b) {
|
|
|
289
289
|
b = ancestors.b.pop();
|
|
290
290
|
common_ancestor = a;
|
|
291
291
|
}
|
|
292
|
-
assert(common_ancestor);
|
|
292
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
293
293
|
const z_indexes = {
|
|
294
294
|
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
295
295
|
b: get_z_index(find_stacking_context(ancestors.b))
|
|
@@ -347,7 +347,7 @@ function find_stacking_context(nodes) {
|
|
|
347
347
|
let i = nodes.length;
|
|
348
348
|
while (i--) {
|
|
349
349
|
const node = nodes[i];
|
|
350
|
-
assert(node);
|
|
350
|
+
assert(node, "Missing node");
|
|
351
351
|
if (creates_stacking_context(node)) return node;
|
|
352
352
|
}
|
|
353
353
|
return null;
|
|
@@ -634,7 +634,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
634
634
|
});
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
-
function assert(expectedCondition, message
|
|
637
|
+
function assert(expectedCondition, message) {
|
|
638
638
|
if (!expectedCondition) {
|
|
639
639
|
console.error(message);
|
|
640
640
|
throw Error(message);
|
|
@@ -665,7 +665,7 @@ function resizePanel({
|
|
|
665
665
|
size
|
|
666
666
|
}) {
|
|
667
667
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
668
|
-
assert(panelConstraints != null);
|
|
668
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
669
669
|
let {
|
|
670
670
|
collapsedSize = 0,
|
|
671
671
|
collapsible,
|
|
@@ -703,8 +703,8 @@ function adjustLayoutByDelta({
|
|
|
703
703
|
}
|
|
704
704
|
const nextLayout = [...prevLayout];
|
|
705
705
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
706
|
-
assert(firstPivotIndex != null);
|
|
707
|
-
assert(secondPivotIndex != null);
|
|
706
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
707
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
708
708
|
let deltaApplied = 0;
|
|
709
709
|
|
|
710
710
|
//const DEBUG = [];
|
|
@@ -730,19 +730,18 @@ function adjustLayoutByDelta({
|
|
|
730
730
|
// Check if we should expand a collapsed panel
|
|
731
731
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
732
732
|
const panelConstraints = panelConstraintsArray[index];
|
|
733
|
-
assert(panelConstraints);
|
|
733
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
734
|
+
const {
|
|
735
|
+
collapsedSize = 0,
|
|
736
|
+
collapsible,
|
|
737
|
+
minSize = 0
|
|
738
|
+
} = panelConstraints;
|
|
734
739
|
|
|
735
740
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
736
741
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
737
|
-
if (
|
|
742
|
+
if (collapsible) {
|
|
738
743
|
const prevSize = prevLayout[index];
|
|
739
|
-
assert(prevSize != null);
|
|
740
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
741
|
-
assert(panelConstraints);
|
|
742
|
-
const {
|
|
743
|
-
collapsedSize = 0,
|
|
744
|
-
minSize = 0
|
|
745
|
-
} = panelConstraints;
|
|
744
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
746
745
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
747
746
|
const localDelta = minSize - prevSize;
|
|
748
747
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -759,22 +758,18 @@ function adjustLayoutByDelta({
|
|
|
759
758
|
// Check if we should collapse a panel at its minimum size
|
|
760
759
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
761
760
|
const panelConstraints = panelConstraintsArray[index];
|
|
762
|
-
assert(panelConstraints);
|
|
761
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
763
762
|
const {
|
|
764
|
-
|
|
763
|
+
collapsedSize = 0,
|
|
764
|
+
collapsible,
|
|
765
|
+
minSize = 0
|
|
765
766
|
} = panelConstraints;
|
|
766
767
|
|
|
767
768
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
768
769
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
769
770
|
if (collapsible) {
|
|
770
771
|
const prevSize = prevLayout[index];
|
|
771
|
-
assert(prevSize != null);
|
|
772
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
773
|
-
assert(panelConstraints);
|
|
774
|
-
const {
|
|
775
|
-
collapsedSize = 0,
|
|
776
|
-
minSize = 0
|
|
777
|
-
} = panelConstraints;
|
|
772
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
778
773
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
779
774
|
const localDelta = prevSize - collapsedSize;
|
|
780
775
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -804,7 +799,7 @@ function adjustLayoutByDelta({
|
|
|
804
799
|
//DEBUG.push("pre calc...");
|
|
805
800
|
while (true) {
|
|
806
801
|
const prevSize = prevLayout[index];
|
|
807
|
-
assert(prevSize != null);
|
|
802
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
808
803
|
const maxSafeSize = resizePanel({
|
|
809
804
|
panelConstraints: panelConstraintsArray,
|
|
810
805
|
panelIndex: index,
|
|
@@ -835,7 +830,7 @@ function adjustLayoutByDelta({
|
|
|
835
830
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
836
831
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
837
832
|
const prevSize = prevLayout[index];
|
|
838
|
-
assert(prevSize != null);
|
|
833
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
839
834
|
const unsafeSize = prevSize - deltaRemaining;
|
|
840
835
|
const safeSize = resizePanel({
|
|
841
836
|
panelConstraints: panelConstraintsArray,
|
|
@@ -872,7 +867,7 @@ function adjustLayoutByDelta({
|
|
|
872
867
|
// Now distribute the applied delta to the panels in the other direction
|
|
873
868
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
874
869
|
const prevSize = prevLayout[pivotIndex];
|
|
875
|
-
assert(prevSize != null);
|
|
870
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
876
871
|
const unsafeSize = prevSize + deltaApplied;
|
|
877
872
|
const safeSize = resizePanel({
|
|
878
873
|
panelConstraints: panelConstraintsArray,
|
|
@@ -890,7 +885,7 @@ function adjustLayoutByDelta({
|
|
|
890
885
|
let index = pivotIndex;
|
|
891
886
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
892
887
|
const prevSize = nextLayout[index];
|
|
893
|
-
assert(prevSize != null);
|
|
888
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
894
889
|
const unsafeSize = prevSize + deltaRemaining;
|
|
895
890
|
const safeSize = resizePanel({
|
|
896
891
|
panelConstraints: panelConstraintsArray,
|
|
@@ -993,17 +988,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
993
988
|
return;
|
|
994
989
|
}
|
|
995
990
|
const eagerValues = eagerValuesRef.current;
|
|
996
|
-
assert(eagerValues);
|
|
991
|
+
assert(eagerValues, `Eager values not found`);
|
|
997
992
|
const {
|
|
998
993
|
panelDataArray
|
|
999
994
|
} = eagerValues;
|
|
1000
995
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1001
996
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
1002
997
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1003
|
-
assert(handles);
|
|
998
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
1004
999
|
const cleanupFunctions = handles.map(handle => {
|
|
1005
1000
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
1006
|
-
assert(handleId);
|
|
1001
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
1007
1002
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
1008
1003
|
if (idBefore == null || idAfter == null) {
|
|
1009
1004
|
return () => {};
|
|
@@ -1019,7 +1014,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1019
1014
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1020
1015
|
if (index >= 0) {
|
|
1021
1016
|
const panelData = panelDataArray[index];
|
|
1022
|
-
assert(panelData);
|
|
1017
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1023
1018
|
const size = layout[index];
|
|
1024
1019
|
const {
|
|
1025
1020
|
collapsedSize = 0,
|
|
@@ -1078,15 +1073,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1078
1073
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1079
1074
|
const isHorizontal = direction === "horizontal";
|
|
1080
1075
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1081
|
-
assert(handleElement);
|
|
1076
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1082
1077
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1083
|
-
assert(groupId);
|
|
1078
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1084
1079
|
let {
|
|
1085
1080
|
initialCursorPosition
|
|
1086
1081
|
} = initialDragState;
|
|
1087
1082
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1088
1083
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1089
|
-
assert(groupElement);
|
|
1084
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1090
1085
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1091
1086
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1092
1087
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1140,7 +1135,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
1140
1135
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1141
1136
|
layout.forEach((size, index) => {
|
|
1142
1137
|
const panelData = panelsArray[index];
|
|
1143
|
-
assert(panelData);
|
|
1138
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1144
1139
|
const {
|
|
1145
1140
|
callbacks,
|
|
1146
1141
|
constraints,
|
|
@@ -1324,7 +1319,7 @@ function validatePanelGroupLayout({
|
|
|
1324
1319
|
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
1325
1320
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1326
1321
|
const unsafeSize = nextLayout[index];
|
|
1327
|
-
assert(unsafeSize != null);
|
|
1322
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1328
1323
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1329
1324
|
nextLayout[index] = safeSize;
|
|
1330
1325
|
}
|
|
@@ -1334,7 +1329,7 @@ function validatePanelGroupLayout({
|
|
|
1334
1329
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1335
1330
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1336
1331
|
const unsafeSize = nextLayout[index];
|
|
1337
|
-
assert(unsafeSize != null);
|
|
1332
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1338
1333
|
const safeSize = resizePanel({
|
|
1339
1334
|
panelConstraints,
|
|
1340
1335
|
panelIndex: index,
|
|
@@ -1351,7 +1346,7 @@ function validatePanelGroupLayout({
|
|
|
1351
1346
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1352
1347
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1353
1348
|
const prevSize = nextLayout[index];
|
|
1354
|
-
assert(prevSize != null);
|
|
1349
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1355
1350
|
const unsafeSize = prevSize + remainingSize;
|
|
1356
1351
|
const safeSize = resizePanel({
|
|
1357
1352
|
panelConstraints,
|
|
@@ -1509,7 +1504,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1509
1504
|
panelSize,
|
|
1510
1505
|
pivotIndices
|
|
1511
1506
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1512
|
-
assert(panelSize != null);
|
|
1507
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1513
1508
|
if (panelSize !== collapsedSize) {
|
|
1514
1509
|
// Store size before collapse;
|
|
1515
1510
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1586,7 +1581,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1586
1581
|
const {
|
|
1587
1582
|
panelSize
|
|
1588
1583
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1589
|
-
assert(panelSize != null);
|
|
1584
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1590
1585
|
return panelSize;
|
|
1591
1586
|
}, []);
|
|
1592
1587
|
|
|
@@ -1630,7 +1625,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1630
1625
|
collapsible,
|
|
1631
1626
|
panelSize
|
|
1632
1627
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1633
|
-
assert(panelSize != null);
|
|
1628
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1634
1629
|
return !collapsible || panelSize > collapsedSize;
|
|
1635
1630
|
}, []);
|
|
1636
1631
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1741,7 +1736,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1741
1736
|
panelSize,
|
|
1742
1737
|
pivotIndices
|
|
1743
1738
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1744
|
-
assert(panelSize != null);
|
|
1739
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1745
1740
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1746
1741
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1747
1742
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1778,7 +1773,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1778
1773
|
const {
|
|
1779
1774
|
panelSize: prevPanelSize
|
|
1780
1775
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1781
|
-
|
|
1776
|
+
if (prevPanelSize == null) {
|
|
1777
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1778
|
+
return;
|
|
1779
|
+
}
|
|
1782
1780
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1783
1781
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1784
1782
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1800,7 +1798,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1800
1798
|
return;
|
|
1801
1799
|
}
|
|
1802
1800
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1803
|
-
assert(handleElement);
|
|
1801
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1804
1802
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1805
1803
|
setDragState({
|
|
1806
1804
|
dragHandleId,
|
|
@@ -1929,10 +1927,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
1929
1927
|
{
|
|
1930
1928
|
event.preventDefault();
|
|
1931
1929
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1932
|
-
assert(groupId);
|
|
1930
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
1933
1931
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1934
1932
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
1935
|
-
assert(index !== null);
|
|
1933
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
1936
1934
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
1937
1935
|
const nextHandle = handles[nextIndex];
|
|
1938
1936
|
nextHandle.focus();
|
|
@@ -2001,7 +1999,7 @@ function PanelResizeHandle({
|
|
|
2001
1999
|
return;
|
|
2002
2000
|
}
|
|
2003
2001
|
const element = elementRef.current;
|
|
2004
|
-
assert(element);
|
|
2002
|
+
assert(element, "Element ref not attached");
|
|
2005
2003
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2006
2004
|
if (isActive) {
|
|
2007
2005
|
switch (action) {
|