react-resizable-panels 2.0.8 → 2.0.10
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 +9 -0
- package/dist/declarations/src/utils/assert.d.ts +1 -1
- package/dist/react-resizable-panels.browser.cjs.js +158 -53
- package/dist/react-resizable-panels.browser.development.cjs.js +160 -55
- package/dist/react-resizable-panels.browser.development.esm.js +159 -54
- package/dist/react-resizable-panels.browser.esm.js +157 -52
- package/dist/react-resizable-panels.cjs.js +158 -53
- package/dist/react-resizable-panels.development.cjs.js +160 -55
- package/dist/react-resizable-panels.development.esm.js +159 -54
- package/dist/react-resizable-panels.development.node.cjs.js +156 -51
- package/dist/react-resizable-panels.development.node.esm.js +155 -50
- package/dist/react-resizable-panels.esm.js +157 -52
- package/dist/react-resizable-panels.node.cjs.js +154 -49
- package/dist/react-resizable-panels.node.esm.js +153 -48
- package/package.json +1 -4
- 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/PanelResizeHandleRegistry.ts +2 -2
- 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/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 +133 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { compare } from 'stacking-order';
|
|
3
2
|
|
|
4
3
|
const isBrowser = typeof window !== "undefined";
|
|
5
4
|
|
|
@@ -282,6 +281,114 @@ function intersects(rectOne, rectTwo, strict) {
|
|
|
282
281
|
}
|
|
283
282
|
}
|
|
284
283
|
|
|
284
|
+
// Forked from NPM stacking-order@2.0.0
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Determine which of two nodes appears in front of the other —
|
|
288
|
+
* if `a` is in front, returns 1, otherwise returns -1
|
|
289
|
+
* @param {HTMLElement} a
|
|
290
|
+
* @param {HTMLElement} b
|
|
291
|
+
*/
|
|
292
|
+
function compare(a, b) {
|
|
293
|
+
if (a === b) throw new Error("Cannot compare node with itself");
|
|
294
|
+
const ancestors = {
|
|
295
|
+
a: get_ancestors(a),
|
|
296
|
+
b: get_ancestors(b)
|
|
297
|
+
};
|
|
298
|
+
let common_ancestor;
|
|
299
|
+
|
|
300
|
+
// remove shared ancestors
|
|
301
|
+
while (ancestors.a.at(-1) === ancestors.b.at(-1)) {
|
|
302
|
+
a = ancestors.a.pop();
|
|
303
|
+
b = ancestors.b.pop();
|
|
304
|
+
common_ancestor = a;
|
|
305
|
+
}
|
|
306
|
+
assert(common_ancestor, "Stacking order can only be calculated for elements with a common ancestor");
|
|
307
|
+
const z_indexes = {
|
|
308
|
+
a: get_z_index(find_stacking_context(ancestors.a)),
|
|
309
|
+
b: get_z_index(find_stacking_context(ancestors.b))
|
|
310
|
+
};
|
|
311
|
+
if (z_indexes.a === z_indexes.b) {
|
|
312
|
+
const children = common_ancestor.childNodes;
|
|
313
|
+
const furthest_ancestors = {
|
|
314
|
+
a: ancestors.a.at(-1),
|
|
315
|
+
b: ancestors.b.at(-1)
|
|
316
|
+
};
|
|
317
|
+
let i = children.length;
|
|
318
|
+
while (i--) {
|
|
319
|
+
const child = children[i];
|
|
320
|
+
if (child === furthest_ancestors.a) return 1;
|
|
321
|
+
if (child === furthest_ancestors.b) return -1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return Math.sign(z_indexes.a - z_indexes.b);
|
|
325
|
+
}
|
|
326
|
+
const props = /\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;
|
|
327
|
+
|
|
328
|
+
/** @param {HTMLElement} node */
|
|
329
|
+
function is_flex_item(node) {
|
|
330
|
+
const display = getComputedStyle(get_parent(node)).display;
|
|
331
|
+
return display === "flex" || display === "inline-flex";
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** @param {HTMLElement} node */
|
|
335
|
+
function creates_stacking_context(node) {
|
|
336
|
+
const style = getComputedStyle(node);
|
|
337
|
+
|
|
338
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
339
|
+
if (style.position === "fixed") return true;
|
|
340
|
+
// Forked to fix upstream bug https://github.com/Rich-Harris/stacking-order/issues/3
|
|
341
|
+
// if (
|
|
342
|
+
// (style.zIndex !== "auto" && style.position !== "static") ||
|
|
343
|
+
// is_flex_item(node)
|
|
344
|
+
// )
|
|
345
|
+
if (style.zIndex !== "auto" && (style.position !== "static" || is_flex_item(node))) return true;
|
|
346
|
+
if (+style.opacity < 1) return true;
|
|
347
|
+
if ("transform" in style && style.transform !== "none") return true;
|
|
348
|
+
if ("webkitTransform" in style && style.webkitTransform !== "none") return true;
|
|
349
|
+
if ("mixBlendMode" in style && style.mixBlendMode !== "normal") return true;
|
|
350
|
+
if ("filter" in style && style.filter !== "none") return true;
|
|
351
|
+
if ("webkitFilter" in style && style.webkitFilter !== "none") return true;
|
|
352
|
+
if ("isolation" in style && style.isolation === "isolate") return true;
|
|
353
|
+
if (props.test(style.willChange)) return true;
|
|
354
|
+
// @ts-expect-error
|
|
355
|
+
if (style.webkitOverflowScrolling === "touch") return true;
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** @param {HTMLElement[]} nodes */
|
|
360
|
+
function find_stacking_context(nodes) {
|
|
361
|
+
let i = nodes.length;
|
|
362
|
+
while (i--) {
|
|
363
|
+
const node = nodes[i];
|
|
364
|
+
assert(node, "Missing node");
|
|
365
|
+
if (creates_stacking_context(node)) return node;
|
|
366
|
+
}
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** @param {HTMLElement} node */
|
|
371
|
+
function get_z_index(node) {
|
|
372
|
+
return node && Number(getComputedStyle(node).zIndex) || 0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** @param {HTMLElement} node */
|
|
376
|
+
function get_ancestors(node) {
|
|
377
|
+
const ancestors = [];
|
|
378
|
+
while (node) {
|
|
379
|
+
ancestors.push(node);
|
|
380
|
+
node = get_parent(node);
|
|
381
|
+
}
|
|
382
|
+
return ancestors; // [ node, ... <body>, <html>, document ]
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** @param {HTMLElement} node */
|
|
386
|
+
function get_parent(node) {
|
|
387
|
+
var _node$parentNode;
|
|
388
|
+
// @ts-ignore
|
|
389
|
+
return ((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.host) || node.parentNode;
|
|
390
|
+
}
|
|
391
|
+
|
|
285
392
|
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
286
393
|
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
287
394
|
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
@@ -494,7 +601,7 @@ function updateListeners() {
|
|
|
494
601
|
window.removeEventListener("mouseup", handlePointerUp);
|
|
495
602
|
window.removeEventListener("touchcancel", handlePointerUp);
|
|
496
603
|
window.removeEventListener("touchend", handlePointerUp);
|
|
497
|
-
if (
|
|
604
|
+
if (registeredResizeHandlers.size > 0) {
|
|
498
605
|
if (isPointerDown) {
|
|
499
606
|
if (intersectingHandles.length > 0) {
|
|
500
607
|
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
@@ -541,7 +648,7 @@ function updateResizeHandlerStates(action, event) {
|
|
|
541
648
|
});
|
|
542
649
|
}
|
|
543
650
|
|
|
544
|
-
function assert(expectedCondition, message
|
|
651
|
+
function assert(expectedCondition, message) {
|
|
545
652
|
if (!expectedCondition) {
|
|
546
653
|
console.error(message);
|
|
547
654
|
throw Error(message);
|
|
@@ -572,7 +679,7 @@ function resizePanel({
|
|
|
572
679
|
size
|
|
573
680
|
}) {
|
|
574
681
|
const panelConstraints = panelConstraintsArray[panelIndex];
|
|
575
|
-
assert(panelConstraints != null);
|
|
682
|
+
assert(panelConstraints != null, `Panel constraints not found for index ${panelIndex}`);
|
|
576
683
|
let {
|
|
577
684
|
collapsedSize = 0,
|
|
578
685
|
collapsible,
|
|
@@ -610,8 +717,8 @@ function adjustLayoutByDelta({
|
|
|
610
717
|
}
|
|
611
718
|
const nextLayout = [...prevLayout];
|
|
612
719
|
const [firstPivotIndex, secondPivotIndex] = pivotIndices;
|
|
613
|
-
assert(firstPivotIndex != null);
|
|
614
|
-
assert(secondPivotIndex != null);
|
|
720
|
+
assert(firstPivotIndex != null, "Invalid first pivot index");
|
|
721
|
+
assert(secondPivotIndex != null, "Invalid second pivot index");
|
|
615
722
|
let deltaApplied = 0;
|
|
616
723
|
|
|
617
724
|
//const DEBUG = [];
|
|
@@ -637,19 +744,18 @@ function adjustLayoutByDelta({
|
|
|
637
744
|
// Check if we should expand a collapsed panel
|
|
638
745
|
const index = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
639
746
|
const panelConstraints = panelConstraintsArray[index];
|
|
640
|
-
assert(panelConstraints);
|
|
747
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
748
|
+
const {
|
|
749
|
+
collapsedSize = 0,
|
|
750
|
+
collapsible,
|
|
751
|
+
minSize = 0
|
|
752
|
+
} = panelConstraints;
|
|
641
753
|
|
|
642
754
|
//DEBUG.push(`edge case check 1: ${index}`);
|
|
643
755
|
//DEBUG.push(` -> collapsible? ${constraints.collapsible}`);
|
|
644
|
-
if (
|
|
756
|
+
if (collapsible) {
|
|
645
757
|
const prevSize = prevLayout[index];
|
|
646
|
-
assert(prevSize != null);
|
|
647
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
648
|
-
assert(panelConstraints);
|
|
649
|
-
const {
|
|
650
|
-
collapsedSize = 0,
|
|
651
|
-
minSize = 0
|
|
652
|
-
} = panelConstraints;
|
|
758
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
653
759
|
if (fuzzyNumbersEqual(prevSize, collapsedSize)) {
|
|
654
760
|
const localDelta = minSize - prevSize;
|
|
655
761
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -666,22 +772,18 @@ function adjustLayoutByDelta({
|
|
|
666
772
|
// Check if we should collapse a panel at its minimum size
|
|
667
773
|
const index = delta < 0 ? firstPivotIndex : secondPivotIndex;
|
|
668
774
|
const panelConstraints = panelConstraintsArray[index];
|
|
669
|
-
assert(panelConstraints);
|
|
775
|
+
assert(panelConstraints, `No panel constraints found for index ${index}`);
|
|
670
776
|
const {
|
|
671
|
-
|
|
777
|
+
collapsedSize = 0,
|
|
778
|
+
collapsible,
|
|
779
|
+
minSize = 0
|
|
672
780
|
} = panelConstraints;
|
|
673
781
|
|
|
674
782
|
//DEBUG.push(`edge case check 2: ${index}`);
|
|
675
783
|
//DEBUG.push(` -> collapsible? ${collapsible}`);
|
|
676
784
|
if (collapsible) {
|
|
677
785
|
const prevSize = prevLayout[index];
|
|
678
|
-
assert(prevSize != null);
|
|
679
|
-
const panelConstraints = panelConstraintsArray[index];
|
|
680
|
-
assert(panelConstraints);
|
|
681
|
-
const {
|
|
682
|
-
collapsedSize = 0,
|
|
683
|
-
minSize = 0
|
|
684
|
-
} = panelConstraints;
|
|
786
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
685
787
|
if (fuzzyNumbersEqual(prevSize, minSize)) {
|
|
686
788
|
const localDelta = prevSize - collapsedSize;
|
|
687
789
|
//DEBUG.push(` -> expand delta: ${localDelta}`);
|
|
@@ -711,7 +813,7 @@ function adjustLayoutByDelta({
|
|
|
711
813
|
//DEBUG.push("pre calc...");
|
|
712
814
|
while (true) {
|
|
713
815
|
const prevSize = prevLayout[index];
|
|
714
|
-
assert(prevSize != null);
|
|
816
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
715
817
|
const maxSafeSize = resizePanel({
|
|
716
818
|
panelConstraints: panelConstraintsArray,
|
|
717
819
|
panelIndex: index,
|
|
@@ -742,7 +844,7 @@ function adjustLayoutByDelta({
|
|
|
742
844
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
743
845
|
const deltaRemaining = Math.abs(delta) - Math.abs(deltaApplied);
|
|
744
846
|
const prevSize = prevLayout[index];
|
|
745
|
-
assert(prevSize != null);
|
|
847
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
746
848
|
const unsafeSize = prevSize - deltaRemaining;
|
|
747
849
|
const safeSize = resizePanel({
|
|
748
850
|
panelConstraints: panelConstraintsArray,
|
|
@@ -779,7 +881,7 @@ function adjustLayoutByDelta({
|
|
|
779
881
|
// Now distribute the applied delta to the panels in the other direction
|
|
780
882
|
const pivotIndex = delta < 0 ? secondPivotIndex : firstPivotIndex;
|
|
781
883
|
const prevSize = prevLayout[pivotIndex];
|
|
782
|
-
assert(prevSize != null);
|
|
884
|
+
assert(prevSize != null, `Previous layout not found for panel index ${pivotIndex}`);
|
|
783
885
|
const unsafeSize = prevSize + deltaApplied;
|
|
784
886
|
const safeSize = resizePanel({
|
|
785
887
|
panelConstraints: panelConstraintsArray,
|
|
@@ -797,7 +899,7 @@ function adjustLayoutByDelta({
|
|
|
797
899
|
let index = pivotIndex;
|
|
798
900
|
while (index >= 0 && index < panelConstraintsArray.length) {
|
|
799
901
|
const prevSize = nextLayout[index];
|
|
800
|
-
assert(prevSize != null);
|
|
902
|
+
assert(prevSize != null, `Previous layout not found for panel index ${index}`);
|
|
801
903
|
const unsafeSize = prevSize + deltaRemaining;
|
|
802
904
|
const safeSize = resizePanel({
|
|
803
905
|
panelConstraints: panelConstraintsArray,
|
|
@@ -843,7 +945,7 @@ function calculateAriaValues({
|
|
|
843
945
|
let totalMinSize = 0;
|
|
844
946
|
let totalMaxSize = 0;
|
|
845
947
|
const firstIndex = pivotIndices[0];
|
|
846
|
-
assert(firstIndex != null);
|
|
948
|
+
assert(firstIndex != null, "No pivot index found");
|
|
847
949
|
|
|
848
950
|
// A panel's effective min/max sizes also need to account for other panel's sizes.
|
|
849
951
|
panelsArray.forEach((panelData, index) => {
|
|
@@ -952,7 +1054,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
952
1054
|
const resizeHandleElement = resizeHandleElements[index];
|
|
953
1055
|
if (resizeHandleElement == null) ; else {
|
|
954
1056
|
const panelData = panelDataArray[index];
|
|
955
|
-
assert(panelData);
|
|
1057
|
+
assert(panelData, `No panel data found for index "${index}"`);
|
|
956
1058
|
resizeHandleElement.setAttribute("aria-controls", panelData.id);
|
|
957
1059
|
resizeHandleElement.setAttribute("aria-valuemax", "" + Math.round(valueMax));
|
|
958
1060
|
resizeHandleElement.setAttribute("aria-valuemin", "" + Math.round(valueMin));
|
|
@@ -973,17 +1075,17 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
973
1075
|
return;
|
|
974
1076
|
}
|
|
975
1077
|
const eagerValues = eagerValuesRef.current;
|
|
976
|
-
assert(eagerValues);
|
|
1078
|
+
assert(eagerValues, `Eager values not found`);
|
|
977
1079
|
const {
|
|
978
1080
|
panelDataArray
|
|
979
1081
|
} = eagerValues;
|
|
980
1082
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
981
1083
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
982
1084
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
983
|
-
assert(handles);
|
|
1085
|
+
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
984
1086
|
const cleanupFunctions = handles.map(handle => {
|
|
985
1087
|
const handleId = handle.getAttribute("data-panel-resize-handle-id");
|
|
986
|
-
assert(handleId);
|
|
1088
|
+
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
987
1089
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
988
1090
|
if (idBefore == null || idAfter == null) {
|
|
989
1091
|
return () => {};
|
|
@@ -999,7 +1101,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
999
1101
|
const index = panelDataArray.findIndex(panelData => panelData.id === idBefore);
|
|
1000
1102
|
if (index >= 0) {
|
|
1001
1103
|
const panelData = panelDataArray[index];
|
|
1002
|
-
assert(panelData);
|
|
1104
|
+
assert(panelData, `No panel data found for index ${index}`);
|
|
1003
1105
|
const size = layout[index];
|
|
1004
1106
|
const {
|
|
1005
1107
|
collapsedSize = 0,
|
|
@@ -1058,15 +1160,15 @@ function getResizeEventCursorPosition(direction, event) {
|
|
|
1058
1160
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
1059
1161
|
const isHorizontal = direction === "horizontal";
|
|
1060
1162
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1061
|
-
assert(handleElement);
|
|
1163
|
+
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1062
1164
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
1063
|
-
assert(groupId);
|
|
1165
|
+
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1064
1166
|
let {
|
|
1065
1167
|
initialCursorPosition
|
|
1066
1168
|
} = initialDragState;
|
|
1067
1169
|
const cursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1068
1170
|
const groupElement = getPanelGroupElement(groupId, panelGroupElement);
|
|
1069
|
-
assert(groupElement);
|
|
1171
|
+
assert(groupElement, `No group element found for id "${groupId}"`);
|
|
1070
1172
|
const groupRect = groupElement.getBoundingClientRect();
|
|
1071
1173
|
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;
|
|
1072
1174
|
const offsetPixels = cursorPosition - initialCursorPosition;
|
|
@@ -1127,7 +1229,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1127
1229
|
// Distribute default sizes first
|
|
1128
1230
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1129
1231
|
const panelConstraints = panelConstraintsArray[index];
|
|
1130
|
-
assert(panelConstraints);
|
|
1232
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1131
1233
|
const {
|
|
1132
1234
|
defaultSize
|
|
1133
1235
|
} = panelConstraints;
|
|
@@ -1141,7 +1243,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1141
1243
|
// Remaining size should be distributed evenly between panels without default sizes
|
|
1142
1244
|
for (let index = 0; index < panelDataArray.length; index++) {
|
|
1143
1245
|
const panelConstraints = panelConstraintsArray[index];
|
|
1144
|
-
assert(panelConstraints);
|
|
1246
|
+
assert(panelConstraints, `Panel constraints not found for index ${index}`);
|
|
1145
1247
|
const {
|
|
1146
1248
|
defaultSize
|
|
1147
1249
|
} = panelConstraints;
|
|
@@ -1161,7 +1263,7 @@ function calculateUnsafeDefaultLayout({
|
|
|
1161
1263
|
function callPanelCallbacks(panelsArray, layout, panelIdToLastNotifiedSizeMap) {
|
|
1162
1264
|
layout.forEach((size, index) => {
|
|
1163
1265
|
const panelData = panelsArray[index];
|
|
1164
|
-
assert(panelData);
|
|
1266
|
+
assert(panelData, `Panel data not found for index ${index}`);
|
|
1165
1267
|
const {
|
|
1166
1268
|
callbacks,
|
|
1167
1269
|
constraints,
|
|
@@ -1351,7 +1453,7 @@ function validatePanelGroupLayout({
|
|
|
1351
1453
|
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
|
|
1352
1454
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1353
1455
|
const unsafeSize = nextLayout[index];
|
|
1354
|
-
assert(unsafeSize != null);
|
|
1456
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1355
1457
|
const safeSize = 100 / nextLayoutTotalSize * unsafeSize;
|
|
1356
1458
|
nextLayout[index] = safeSize;
|
|
1357
1459
|
}
|
|
@@ -1361,7 +1463,7 @@ function validatePanelGroupLayout({
|
|
|
1361
1463
|
// First pass: Validate the proposed layout given each panel's constraints
|
|
1362
1464
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1363
1465
|
const unsafeSize = nextLayout[index];
|
|
1364
|
-
assert(unsafeSize != null);
|
|
1466
|
+
assert(unsafeSize != null, `No layout data found for index ${index}`);
|
|
1365
1467
|
const safeSize = resizePanel({
|
|
1366
1468
|
panelConstraints,
|
|
1367
1469
|
panelIndex: index,
|
|
@@ -1378,7 +1480,7 @@ function validatePanelGroupLayout({
|
|
|
1378
1480
|
if (!fuzzyNumbersEqual(remainingSize, 0)) {
|
|
1379
1481
|
for (let index = 0; index < panelConstraints.length; index++) {
|
|
1380
1482
|
const prevSize = nextLayout[index];
|
|
1381
|
-
assert(prevSize != null);
|
|
1483
|
+
assert(prevSize != null, `No layout data found for index ${index}`);
|
|
1382
1484
|
const unsafeSize = prevSize + remainingSize;
|
|
1383
1485
|
const safeSize = resizePanel({
|
|
1384
1486
|
panelConstraints,
|
|
@@ -1544,7 +1646,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1544
1646
|
panelSize,
|
|
1545
1647
|
pivotIndices
|
|
1546
1648
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1547
|
-
assert(panelSize != null);
|
|
1649
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1548
1650
|
if (panelSize !== collapsedSize) {
|
|
1549
1651
|
// Store size before collapse;
|
|
1550
1652
|
// This is the size that gets restored if the expand() API is used.
|
|
@@ -1621,7 +1723,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1621
1723
|
const {
|
|
1622
1724
|
panelSize
|
|
1623
1725
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1624
|
-
assert(panelSize != null);
|
|
1726
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1625
1727
|
return panelSize;
|
|
1626
1728
|
}, []);
|
|
1627
1729
|
|
|
@@ -1665,7 +1767,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1665
1767
|
collapsible,
|
|
1666
1768
|
panelSize
|
|
1667
1769
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1668
|
-
assert(panelSize != null);
|
|
1770
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1669
1771
|
return !collapsible || panelSize > collapsedSize;
|
|
1670
1772
|
}, []);
|
|
1671
1773
|
const registerPanel = useCallback(panelData => {
|
|
@@ -1832,7 +1934,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1832
1934
|
panelSize,
|
|
1833
1935
|
pivotIndices
|
|
1834
1936
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1835
|
-
assert(panelSize != null);
|
|
1937
|
+
assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
|
|
1836
1938
|
const isLastPanel = findPanelDataIndex(panelDataArray, panelData) === panelDataArray.length - 1;
|
|
1837
1939
|
const delta = isLastPanel ? panelSize - unsafePanelSize : unsafePanelSize - panelSize;
|
|
1838
1940
|
const nextLayout = adjustLayoutByDelta({
|
|
@@ -1869,7 +1971,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1869
1971
|
const {
|
|
1870
1972
|
panelSize: prevPanelSize
|
|
1871
1973
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1872
|
-
|
|
1974
|
+
if (prevPanelSize == null) {
|
|
1975
|
+
// It's possible that the panels in this group have changed since the last render
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1873
1978
|
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1874
1979
|
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1875
1980
|
resizePanel(panelData, nextCollapsedSize);
|
|
@@ -1891,7 +1996,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1891
1996
|
return;
|
|
1892
1997
|
}
|
|
1893
1998
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElementRef.current);
|
|
1894
|
-
assert(handleElement);
|
|
1999
|
+
assert(handleElement, `Drag handle element not found for id "${dragHandleId}"`);
|
|
1895
2000
|
const initialCursorPosition = getResizeEventCursorPosition(direction, event);
|
|
1896
2001
|
setDragState({
|
|
1897
2002
|
dragHandleId,
|
|
@@ -2020,10 +2125,10 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2020
2125
|
{
|
|
2021
2126
|
event.preventDefault();
|
|
2022
2127
|
const groupId = handleElement.getAttribute("data-panel-group-id");
|
|
2023
|
-
assert(groupId);
|
|
2128
|
+
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2024
2129
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2025
2130
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
2026
|
-
assert(index !== null);
|
|
2131
|
+
assert(index !== null, `No resize element found for id "${handleId}"`);
|
|
2027
2132
|
const nextIndex = event.shiftKey ? index > 0 ? index - 1 : handles.length - 1 : index + 1 < handles.length ? index + 1 : 0;
|
|
2028
2133
|
const nextHandle = handles[nextIndex];
|
|
2029
2134
|
nextHandle.focus();
|
|
@@ -2095,7 +2200,7 @@ function PanelResizeHandle({
|
|
|
2095
2200
|
return;
|
|
2096
2201
|
}
|
|
2097
2202
|
const element = elementRef.current;
|
|
2098
|
-
assert(element);
|
|
2203
|
+
assert(element, "Element ref not attached");
|
|
2099
2204
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2100
2205
|
if (isActive) {
|
|
2101
2206
|
switch (action) {
|