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
|
@@ -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
|
}
|
|
@@ -300,7 +300,7 @@ function compare(a, b) {
|
|
|
300
300
|
b = ancestors.b.pop();
|
|
301
301
|
common_ancestor = a;
|
|
302
302
|
}
|
|
303
|
-
assert(common_ancestor);
|
|
303
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
304
304
|
const z_indexes = {
|
|
305
305
|
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
306
306
|
b: get_z_index(find_stacking_context(ancestors.b))
|
|
@@ -358,7 +358,7 @@ function find_stacking_context(nodes) {
|
|
|
358
358
|
let i = nodes.length;
|
|
359
359
|
while (i--) {
|
|
360
360
|
const node = nodes[i];
|
|
361
|
-
assert(node);
|
|
361
|
+
assert(node, "Missing node");
|
|
362
362
|
if (creates_stacking_context(node)) return node;
|
|
363
363
|
}
|
|
364
364
|
return null;
|
|
@@ -645,7 +645,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
645
645
|
});
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
-
function assert(expectedCondition, message
|
|
648
|
+
function assert(expectedCondition, message) {
|
|
649
649
|
if (!expectedCondition) {
|
|
650
650
|
console.error(message);
|
|
651
651
|
throw Error(message);
|
|
@@ -676,7 +676,7 @@ function resizePanel({
|
|
|
676
676
|
size
|
|
677
677
|
}) {
|
|
678
678
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
679
|
-
assert(panelConstraints != null);
|
|
679
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
680
680
|
let {
|
|
681
681
|
collapsedSize = 0,
|
|
682
682
|
collapsible,
|
|
@@ -714,8 +714,8 @@ function adjustLayoutByDelta({
|
|
|
714
714
|
}
|
|
715
715
|
const nextLayout = [...prevLayout];
|
|
716
716
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
717
|
-
assert(firstPivotIndex != null);
|
|
718
|
-
assert(secondPivotIndex != null);
|
|
717
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
718
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
719
719
|
let deltaApplied = 0;
|
|
720
720
|
|
|
721
721
|
//const DEBUG = [];
|
|
@@ -741,19 +741,18 @@ function adjustLayoutByDelta({
|
|
|
741
741
|
// Check if we should expand a collapsed panel
|
|
742
742
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
743
743
|
const panelConstraints = panelConstraintsArray[index];
|
|
744
|
-
assert(panelConstraints);
|
|
744
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
745
|
+
const {
|
|
746
|
+
collapsedSize = 0,
|
|
747
|
+
collapsible,
|
|
748
|
+
minSize = 0
|
|
749
|
+
} = panelConstraints;
|
|
745
750
|
|
|
746
751
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
747
752
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
748
|
-
if (
|
|
753
|
+
if (collapsible) {
|
|
749
754
|
const prevSize = prevLayout[index];
|
|
750
|
-
assert(prevSize != null);
|
|
751
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
752
|
-
assert(panelConstraints);
|
|
753
|
-
const {
|
|
754
|
-
collapsedSize = 0,
|
|
755
|
-
minSize = 0
|
|
756
|
-
} = panelConstraints;
|
|
755
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
757
756
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
758
757
|
const localDelta = minSize - prevSize;
|
|
759
758
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -770,22 +769,18 @@ function adjustLayoutByDelta({
|
|
|
770
769
|
// Check if we should collapse a panel at its minimum size
|
|
771
770
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
772
771
|
const panelConstraints = panelConstraintsArray[index];
|
|
773
|
-
assert(panelConstraints);
|
|
772
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
774
773
|
const {
|
|
775
|
-
|
|
774
|
+
collapsedSize = 0,
|
|
775
|
+
collapsible,
|
|
776
|
+
minSize = 0
|
|
776
777
|
} = panelConstraints;
|
|
777
778
|
|
|
778
779
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
779
780
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
780
781
|
if (collapsible) {
|
|
781
782
|
const prevSize = prevLayout[index];
|
|
782
|
-
assert(prevSize != null);
|
|
783
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
784
|
-
assert(panelConstraints);
|
|
785
|
-
const {
|
|
786
|
-
collapsedSize = 0,
|
|
787
|
-
minSize = 0
|
|
788
|
-
} = panelConstraints;
|
|
783
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
789
784
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
790
785
|
const localDelta = prevSize - collapsedSize;
|
|
791
786
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -815,7 +810,7 @@ function adjustLayoutByDelta({
|
|
|
815
810
|
//DEBUG.push("pre calc...");
|
|
816
811
|
while (true) {
|
|
817
812
|
const prevSize = prevLayout[index];
|
|
818
|
-
assert(prevSize != null);
|
|
813
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
819
814
|
const maxSafeSize = resizePanel({
|
|
820
815
|
panelConstraints: panelConstraintsArray,
|
|
821
816
|
panelIndex: index,
|
|
@@ -846,7 +841,7 @@ function adjustLayoutByDelta({
|
|
|
846
841
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
847
842
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
848
843
|
const prevSize = prevLayout[index];
|
|
849
|
-
assert(prevSize != null);
|
|
844
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
850
845
|
const unsafeSize = prevSize - deltaRemaining;
|
|
851
846
|
const safeSize = resizePanel({
|
|
852
847
|
panelConstraints: panelConstraintsArray,
|
|
@@ -883,7 +878,7 @@ function adjustLayoutByDelta({
|
|
|
883
878
|
// Now distribute the applied delta to the panels in the other direction
|
|
884
879
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
885
880
|
const prevSize = prevLayout[pivotIndex];
|
|
886
|
-
assert(prevSize != null);
|
|
881
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
887
882
|
const unsafeSize = prevSize + deltaApplied;
|
|
888
883
|
const safeSize = resizePanel({
|
|
889
884
|
panelConstraints: panelConstraintsArray,
|
|
@@ -901,7 +896,7 @@ function adjustLayoutByDelta({
|
|
|
901
896
|
let index = pivotIndex;
|
|
902
897
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
903
898
|
const prevSize = nextLayout[index];
|
|
904
|
-
assert(prevSize != null);
|
|
899
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
905
900
|
const unsafeSize = prevSize + deltaRemaining;
|
|
906
901
|
const safeSize = resizePanel({
|
|
907
902
|
panelConstraints: panelConstraintsArray,
|
|
@@ -1004,17 +999,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1004
999
|
return;
|
|
1005
1000
|
}
|
|
1006
1001
|
const eagerValues = eagerValuesRef.current;
|
|
1007
|
-
assert(eagerValues);
|
|
1002
|
+
assert(eagerValues, `Eager values not found`);
|
|
1008
1003
|
const {
|
|
1009
1004
|
panelDataArray
|
|
1010
1005
|
} = eagerValues;
|
|
1011
1006
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1012
1007
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
1013
1008
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1014
|
-
assert(handles);
|
|
1009
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
1015
1010
|
const cleanupFunctions = handles.map(handle => {
|
|
1016
1011
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
1017
|
-
assert(handleId);
|
|
1012
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
1018
1013
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
1019
1014
|
if (idBefore == null || idAfter == null) {
|
|
1020
1015
|
return () => {};
|
|
@@ -1030,7 +1025,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1030
1025
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1031
1026
|
if (index >= 0) {
|
|
1032
1027
|
const panelData = panelDataArray[index];
|
|
1033
|
-
assert(panelData);
|
|
1028
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1034
1029
|
const size = layout[index];
|
|
1035
1030
|
const {
|
|
1036
1031
|
collapsedSize = 0,
|
|
@@ -1089,15 +1084,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1089
1084
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1090
1085
|
const isHorizontal = direction === "horizontal";
|
|
1091
1086
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1092
|
-
assert(handleElement);
|
|
1087
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1093
1088
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1094
|
-
assert(groupId);
|
|
1089
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1095
1090
|
let {
|
|
1096
1091
|
initialCursorPosition
|
|
1097
1092
|
} = initialDragState;
|
|
1098
1093
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1099
1094
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1100
|
-
assert(groupElement);
|
|
1095
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1101
1096
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1102
1097
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1103
1098
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1151,7 +1146,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
1151
1146
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1152
1147
|
layout.forEach((size, index) => {
|
|
1153
1148
|
const panelData = panelsArray[index];
|
|
1154
|
-
assert(panelData);
|
|
1149
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1155
1150
|
const {
|
|
1156
1151
|
callbacks,
|
|
1157
1152
|
constraints,
|
|
@@ -1329,7 +1324,7 @@ function validatePanelConstraints({
|
|
|
1329
1324
|
{
|
|
1330
1325
|
const warnings = [];
|
|
1331
1326
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1332
|
-
assert(panelConstraints);
|
|
1327
|
+
assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
|
|
1333
1328
|
const {
|
|
1334
1329
|
collapsedSize = 0,
|
|
1335
1330
|
collapsible = false,
|
|
@@ -1383,7 +1378,7 @@ function validatePanelGroupLayout({
|
|
|
1383
1378
|
}
|
|
1384
1379
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1385
1380
|
const unsafeSize = nextLayout[index];
|
|
1386
|
-
assert(unsafeSize != null);
|
|
1381
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1387
1382
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1388
1383
|
nextLayout[index] = safeSize;
|
|
1389
1384
|
}
|
|
@@ -1393,7 +1388,7 @@ function validatePanelGroupLayout({
|
|
|
1393
1388
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1394
1389
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1395
1390
|
const unsafeSize = nextLayout[index];
|
|
1396
|
-
assert(unsafeSize != null);
|
|
1391
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1397
1392
|
const safeSize = resizePanel({
|
|
1398
1393
|
panelConstraints,
|
|
1399
1394
|
panelIndex: index,
|
|
@@ -1410,7 +1405,7 @@ function validatePanelGroupLayout({
|
|
|
1410
1405
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1411
1406
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1412
1407
|
const prevSize = nextLayout[index];
|
|
1413
|
-
assert(prevSize != null);
|
|
1408
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1414
1409
|
const unsafeSize = prevSize + remainingSize;
|
|
1415
1410
|
const safeSize = resizePanel({
|
|
1416
1411
|
panelConstraints,
|
|
@@ -1579,7 +1574,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1579
1574
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1580
1575
|
for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
|
|
1581
1576
|
const panelData = panelDataArray[panelIndex];
|
|
1582
|
-
assert(panelData);
|
|
1577
|
+
assert(panelData, `Panel data not found for index ${panelIndex}`);
|
|
1583
1578
|
const isValid = validatePanelConstraints({
|
|
1584
1579
|
panelConstraints,
|
|
1585
1580
|
panelId: panelData.id,
|
|
@@ -1610,7 +1605,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1610
1605
|
panelSize,
|
|
1611
1606
|
pivotIndices
|
|
1612
1607
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1613
|
-
assert(panelSize != null);
|
|
1608
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1614
1609
|
if (panelSize !== collapsedSize) {
|
|
1615
1610
|
// Store size before collapse;
|
|
1616
1611
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1687,7 +1682,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1687
1682
|
const {
|
|
1688
1683
|
panelSize
|
|
1689
1684
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1690
|
-
assert(panelSize != null);
|
|
1685
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1691
1686
|
return panelSize;
|
|
1692
1687
|
}, []);
|
|
1693
1688
|
|
|
@@ -1731,7 +1726,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1731
1726
|
collapsible,
|
|
1732
1727
|
panelSize
|
|
1733
1728
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1734
|
-
assert(panelSize != null);
|
|
1729
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1735
1730
|
return !collapsible || panelSize > collapsedSize;
|
|
1736
1731
|
}, []);
|
|
1737
1732
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1842,7 +1837,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1842
1837
|
panelSize,
|
|
1843
1838
|
pivotIndices
|
|
1844
1839
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1845
|
-
assert(panelSize != null);
|
|
1840
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1846
1841
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1847
1842
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1848
1843
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1879,7 +1874,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1879
1874
|
const {
|
|
1880
1875
|
panelSize: prevPanelSize
|
|
1881
1876
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1882
|
-
|
|
1877
|
+
if (prevPanelSize == null) {
|
|
1878
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1883
1881
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1884
1882
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1885
1883
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1901,7 +1899,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1901
1899
|
return;
|
|
1902
1900
|
}
|
|
1903
1901
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1904
|
-
assert(handleElement);
|
|
1902
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1905
1903
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1906
1904
|
setDragState({
|
|
1907
1905
|
dragHandleId,
|
|
@@ -2030,10 +2028,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2030
2028
|
{
|
|
2031
2029
|
event.preventDefault();
|
|
2032
2030
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2033
|
-
assert(groupId);
|
|
2031
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2034
2032
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2035
2033
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2036
|
-
assert(index !== null);
|
|
2034
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2037
2035
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2038
2036
|
const nextHandle = handles[nextIndex];
|
|
2039
2037
|
nextHandle.focus();
|
|
@@ -2102,7 +2100,7 @@ function PanelResizeHandle({
|
|
|
2102
2100
|
return;
|
|
2103
2101
|
}
|
|
2104
2102
|
const element = elementRef.current;
|
|
2105
|
-
assert(element);
|
|
2103
|
+
assert(element, "Element ref not attached");
|
|
2106
2104
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2107
2105
|
if (isActive) {
|
|
2108
2106
|
switch (action) {
|
|
@@ -222,15 +222,15 @@ function isTouchEvent(event) {
|
|
|
222
222
|
function getResizeEventCoordinates(event) {
|
|
223
223
|
if (isMouseEvent(event)) {
|
|
224
224
|
return {
|
|
225
|
-
x: event.
|
|
226
|
-
y: event.
|
|
225
|
+
x: event.clientX,
|
|
226
|
+
y: event.clientY
|
|
227
227
|
};
|
|
228
228
|
} else if (isTouchEvent(event)) {
|
|
229
229
|
const touch = event.touches[0];
|
|
230
|
-
if (touch && touch.
|
|
230
|
+
if (touch && touch.clientX && touch.clientY) {
|
|
231
231
|
return {
|
|
232
|
-
x: touch.
|
|
233
|
-
y: touch.
|
|
232
|
+
x: touch.clientX,
|
|
233
|
+
y: touch.clientY
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
}
|
|
@@ -276,7 +276,7 @@ function compare(a, b) {
|
|
|
276
276
|
b = ancestors.b.pop();
|
|
277
277
|
common_ancestor = a;
|
|
278
278
|
}
|
|
279
|
-
assert(common_ancestor);
|
|
279
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
280
280
|
const z_indexes = {
|
|
281
281
|
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
282
282
|
b: get_z_index(find_stacking_context(ancestors.b))
|
|
@@ -334,7 +334,7 @@ function find_stacking_context(nodes) {
|
|
|
334
334
|
let i = nodes.length;
|
|
335
335
|
while (i--) {
|
|
336
336
|
const node = nodes[i];
|
|
337
|
-
assert(node);
|
|
337
|
+
assert(node, "Missing node");
|
|
338
338
|
if (creates_stacking_context(node)) return node;
|
|
339
339
|
}
|
|
340
340
|
return null;
|
|
@@ -621,7 +621,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
621
621
|
});
|
|
622
622
|
}
|
|
623
623
|
|
|
624
|
-
function assert(expectedCondition, message
|
|
624
|
+
function assert(expectedCondition, message) {
|
|
625
625
|
if (!expectedCondition) {
|
|
626
626
|
console.error(message);
|
|
627
627
|
throw Error(message);
|
|
@@ -652,7 +652,7 @@ function resizePanel({
|
|
|
652
652
|
size
|
|
653
653
|
}) {
|
|
654
654
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
655
|
-
assert(panelConstraints != null);
|
|
655
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
656
656
|
let {
|
|
657
657
|
collapsedSize = 0,
|
|
658
658
|
collapsible,
|
|
@@ -690,8 +690,8 @@ function adjustLayoutByDelta({
|
|
|
690
690
|
}
|
|
691
691
|
const nextLayout = [...prevLayout];
|
|
692
692
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
693
|
-
assert(firstPivotIndex != null);
|
|
694
|
-
assert(secondPivotIndex != null);
|
|
693
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
694
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
695
695
|
let deltaApplied = 0;
|
|
696
696
|
|
|
697
697
|
//const DEBUG = [];
|
|
@@ -717,19 +717,18 @@ function adjustLayoutByDelta({
|
|
|
717
717
|
// Check if we should expand a collapsed panel
|
|
718
718
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
719
719
|
const panelConstraints = panelConstraintsArray[index];
|
|
720
|
-
assert(panelConstraints);
|
|
720
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
721
|
+
const {
|
|
722
|
+
collapsedSize = 0,
|
|
723
|
+
collapsible,
|
|
724
|
+
minSize = 0
|
|
725
|
+
} = panelConstraints;
|
|
721
726
|
|
|
722
727
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
723
728
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
724
|
-
if (
|
|
729
|
+
if (collapsible) {
|
|
725
730
|
const prevSize = prevLayout[index];
|
|
726
|
-
assert(prevSize != null);
|
|
727
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
728
|
-
assert(panelConstraints);
|
|
729
|
-
const {
|
|
730
|
-
collapsedSize = 0,
|
|
731
|
-
minSize = 0
|
|
732
|
-
} = panelConstraints;
|
|
731
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
733
732
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
734
733
|
const localDelta = minSize - prevSize;
|
|
735
734
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -746,22 +745,18 @@ function adjustLayoutByDelta({
|
|
|
746
745
|
// Check if we should collapse a panel at its minimum size
|
|
747
746
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
748
747
|
const panelConstraints = panelConstraintsArray[index];
|
|
749
|
-
assert(panelConstraints);
|
|
748
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
750
749
|
const {
|
|
751
|
-
|
|
750
|
+
collapsedSize = 0,
|
|
751
|
+
collapsible,
|
|
752
|
+
minSize = 0
|
|
752
753
|
} = panelConstraints;
|
|
753
754
|
|
|
754
755
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
755
756
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
756
757
|
if (collapsible) {
|
|
757
758
|
const prevSize = prevLayout[index];
|
|
758
|
-
assert(prevSize != null);
|
|
759
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
760
|
-
assert(panelConstraints);
|
|
761
|
-
const {
|
|
762
|
-
collapsedSize = 0,
|
|
763
|
-
minSize = 0
|
|
764
|
-
} = panelConstraints;
|
|
759
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
765
760
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
766
761
|
const localDelta = prevSize - collapsedSize;
|
|
767
762
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -791,7 +786,7 @@ function adjustLayoutByDelta({
|
|
|
791
786
|
//DEBUG.push("pre calc...");
|
|
792
787
|
while (true) {
|
|
793
788
|
const prevSize = prevLayout[index];
|
|
794
|
-
assert(prevSize != null);
|
|
789
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
795
790
|
const maxSafeSize = resizePanel({
|
|
796
791
|
panelConstraints: panelConstraintsArray,
|
|
797
792
|
panelIndex: index,
|
|
@@ -822,7 +817,7 @@ function adjustLayoutByDelta({
|
|
|
822
817
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
823
818
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
824
819
|
const prevSize = prevLayout[index];
|
|
825
|
-
assert(prevSize != null);
|
|
820
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
826
821
|
const unsafeSize = prevSize - deltaRemaining;
|
|
827
822
|
const safeSize = resizePanel({
|
|
828
823
|
panelConstraints: panelConstraintsArray,
|
|
@@ -859,7 +854,7 @@ function adjustLayoutByDelta({
|
|
|
859
854
|
// Now distribute the applied delta to the panels in the other direction
|
|
860
855
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
861
856
|
const prevSize = prevLayout[pivotIndex];
|
|
862
|
-
assert(prevSize != null);
|
|
857
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
863
858
|
const unsafeSize = prevSize + deltaApplied;
|
|
864
859
|
const safeSize = resizePanel({
|
|
865
860
|
panelConstraints: panelConstraintsArray,
|
|
@@ -877,7 +872,7 @@ function adjustLayoutByDelta({
|
|
|
877
872
|
let index = pivotIndex;
|
|
878
873
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
879
874
|
const prevSize = nextLayout[index];
|
|
880
|
-
assert(prevSize != null);
|
|
875
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
881
876
|
const unsafeSize = prevSize + deltaRemaining;
|
|
882
877
|
const safeSize = resizePanel({
|
|
883
878
|
panelConstraints: panelConstraintsArray,
|
|
@@ -980,17 +975,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
980
975
|
return;
|
|
981
976
|
}
|
|
982
977
|
const eagerValues = eagerValuesRef.current;
|
|
983
|
-
assert(eagerValues);
|
|
978
|
+
assert(eagerValues, `Eager values not found`);
|
|
984
979
|
const {
|
|
985
980
|
panelDataArray
|
|
986
981
|
} = eagerValues;
|
|
987
982
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
988
983
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
989
984
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
990
|
-
assert(handles);
|
|
985
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
991
986
|
const cleanupFunctions = handles.map(handle => {
|
|
992
987
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
993
|
-
assert(handleId);
|
|
988
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
994
989
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
995
990
|
if (idBefore == null || idAfter == null) {
|
|
996
991
|
return () => {};
|
|
@@ -1006,7 +1001,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1006
1001
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1007
1002
|
if (index >= 0) {
|
|
1008
1003
|
const panelData = panelDataArray[index];
|
|
1009
|
-
assert(panelData);
|
|
1004
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1010
1005
|
const size = layout[index];
|
|
1011
1006
|
const {
|
|
1012
1007
|
collapsedSize = 0,
|
|
@@ -1065,15 +1060,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1065
1060
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1066
1061
|
const isHorizontal = direction === "horizontal";
|
|
1067
1062
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1068
|
-
assert(handleElement);
|
|
1063
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1069
1064
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1070
|
-
assert(groupId);
|
|
1065
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1071
1066
|
let {
|
|
1072
1067
|
initialCursorPosition
|
|
1073
1068
|
} = initialDragState;
|
|
1074
1069
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1075
1070
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1076
|
-
assert(groupElement);
|
|
1071
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1077
1072
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1078
1073
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1079
1074
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1127,7 +1122,7 @@ function calculateDeltaPercentage(event, dragHandleId, direction, initialDragSta
|
|
|
1127
1122
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1128
1123
|
layout.forEach((size, index) => {
|
|
1129
1124
|
const panelData = panelsArray[index];
|
|
1130
|
-
assert(panelData);
|
|
1125
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1131
1126
|
const {
|
|
1132
1127
|
callbacks,
|
|
1133
1128
|
constraints,
|
|
@@ -1305,7 +1300,7 @@ function validatePanelConstraints({
|
|
|
1305
1300
|
{
|
|
1306
1301
|
const warnings = [];
|
|
1307
1302
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
1308
|
-
assert(panelConstraints);
|
|
1303
|
+
assert(panelConstraints, `No panel constraints found for index ${panelIndex}`);
|
|
1309
1304
|
const {
|
|
1310
1305
|
collapsedSize = 0,
|
|
1311
1306
|
collapsible = false,
|
|
@@ -1359,7 +1354,7 @@ function validatePanelGroupLayout({
|
|
|
1359
1354
|
}
|
|
1360
1355
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1361
1356
|
const unsafeSize = nextLayout[index];
|
|
1362
|
-
assert(unsafeSize != null);
|
|
1357
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1363
1358
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1364
1359
|
nextLayout[index] = safeSize;
|
|
1365
1360
|
}
|
|
@@ -1369,7 +1364,7 @@ function validatePanelGroupLayout({
|
|
|
1369
1364
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1370
1365
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1371
1366
|
const unsafeSize = nextLayout[index];
|
|
1372
|
-
assert(unsafeSize != null);
|
|
1367
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1373
1368
|
const safeSize = resizePanel({
|
|
1374
1369
|
panelConstraints,
|
|
1375
1370
|
panelIndex: index,
|
|
@@ -1386,7 +1381,7 @@ function validatePanelGroupLayout({
|
|
|
1386
1381
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1387
1382
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1388
1383
|
const prevSize = nextLayout[index];
|
|
1389
|
-
assert(prevSize != null);
|
|
1384
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1390
1385
|
const unsafeSize = prevSize + remainingSize;
|
|
1391
1386
|
const safeSize = resizePanel({
|
|
1392
1387
|
panelConstraints,
|
|
@@ -1555,7 +1550,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1555
1550
|
const panelConstraints = panelDataArray.map(panelData => panelData.constraints);
|
|
1556
1551
|
for (let panelIndex = 0; panelIndex < panelConstraints.length; panelIndex++) {
|
|
1557
1552
|
const panelData = panelDataArray[panelIndex];
|
|
1558
|
-
assert(panelData);
|
|
1553
|
+
assert(panelData, `Panel data not found for index ${panelIndex}`);
|
|
1559
1554
|
const isValid = validatePanelConstraints({
|
|
1560
1555
|
panelConstraints,
|
|
1561
1556
|
panelId: panelData.id,
|
|
@@ -1586,7 +1581,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1586
1581
|
panelSize,
|
|
1587
1582
|
pivotIndices
|
|
1588
1583
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1589
|
-
assert(panelSize != null);
|
|
1584
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1590
1585
|
if (panelSize !== collapsedSize) {
|
|
1591
1586
|
// Store size before collapse;
|
|
1592
1587
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1663,7 +1658,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1663
1658
|
const {
|
|
1664
1659
|
panelSize
|
|
1665
1660
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1666
|
-
assert(panelSize != null);
|
|
1661
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1667
1662
|
return panelSize;
|
|
1668
1663
|
}, []);
|
|
1669
1664
|
|
|
@@ -1707,7 +1702,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1707
1702
|
collapsible,
|
|
1708
1703
|
panelSize
|
|
1709
1704
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1710
|
-
assert(panelSize != null);
|
|
1705
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1711
1706
|
return !collapsible || panelSize > collapsedSize;
|
|
1712
1707
|
}, []);
|
|
1713
1708
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1818,7 +1813,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1818
1813
|
panelSize,
|
|
1819
1814
|
pivotIndices
|
|
1820
1815
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1821
|
-
assert(panelSize != null);
|
|
1816
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1822
1817
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1823
1818
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1824
1819
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1855,7 +1850,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1855
1850
|
const {
|
|
1856
1851
|
panelSize: prevPanelSize
|
|
1857
1852
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1858
|
-
|
|
1853
|
+
if (prevPanelSize == null) {
|
|
1854
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1859
1857
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1860
1858
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1861
1859
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1877,7 +1875,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1877
1875
|
return;
|
|
1878
1876
|
}
|
|
1879
1877
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1880
|
-
assert(handleElement);
|
|
1878
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1881
1879
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1882
1880
|
setDragState({
|
|
1883
1881
|
dragHandleId,
|
|
@@ -2006,10 +2004,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2006
2004
|
{
|
|
2007
2005
|
event.preventDefault();
|
|
2008
2006
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2009
|
-
assert(groupId);
|
|
2007
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2010
2008
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2011
2009
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2012
|
-
assert(index !== null);
|
|
2010
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2013
2011
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2014
2012
|
const nextHandle = handles[nextIndex];
|
|
2015
2013
|
nextHandle.focus();
|
|
@@ -2078,7 +2076,7 @@ function PanelResizeHandle({
|
|
|
2078
2076
|
return;
|
|
2079
2077
|
}
|
|
2080
2078
|
const element = elementRef.current;
|
|
2081
|
-
assert(element);
|
|
2079
|
+
assert(element, "Element ref not attached");
|
|
2082
2080
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2083
2081
|
if (isActive) {
|
|
2084
2082
|
switch (action) {
|