react-resizable-panels 2.1.8 → 2.1.9
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/LICENSE +21 -0
- package/dist/declarations/src/PanelGroup.d.ts +1 -1
- package/dist/declarations/src/PanelResizeHandle.d.ts +1 -1
- package/dist/declarations/src/constants.d.ts +15 -0
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/react-resizable-panels.browser.cjs.js +135 -105
- package/dist/react-resizable-panels.browser.cjs.mjs +1 -0
- package/dist/react-resizable-panels.browser.development.cjs.js +135 -105
- package/dist/react-resizable-panels.browser.development.cjs.mjs +1 -0
- package/dist/react-resizable-panels.browser.development.esm.js +135 -106
- package/dist/react-resizable-panels.browser.esm.js +135 -106
- package/dist/react-resizable-panels.cjs.js +135 -105
- package/dist/react-resizable-panels.cjs.mjs +1 -0
- package/dist/react-resizable-panels.development.cjs.js +135 -105
- package/dist/react-resizable-panels.development.cjs.mjs +1 -0
- package/dist/react-resizable-panels.development.esm.js +135 -106
- package/dist/react-resizable-panels.development.node.cjs.js +135 -105
- package/dist/react-resizable-panels.development.node.cjs.mjs +1 -0
- package/dist/react-resizable-panels.development.node.esm.js +135 -106
- package/dist/react-resizable-panels.esm.js +135 -106
- package/dist/react-resizable-panels.node.cjs.js +135 -105
- package/dist/react-resizable-panels.node.cjs.mjs +1 -0
- package/dist/react-resizable-panels.node.esm.js +135 -106
- package/package.json +12 -12
|
@@ -31,6 +31,22 @@ const isBrowser = typeof window !== "undefined";
|
|
|
31
31
|
const PanelGroupContext = React.createContext(null);
|
|
32
32
|
PanelGroupContext.displayName = "PanelGroupContext";
|
|
33
33
|
|
|
34
|
+
const DATA_ATTRIBUTES = {
|
|
35
|
+
group: "data-panel-group",
|
|
36
|
+
groupDirection: "data-panel-group-direction",
|
|
37
|
+
groupId: "data-panel-group-id",
|
|
38
|
+
panel: "data-panel",
|
|
39
|
+
panelCollapsible: "data-panel-collapsible",
|
|
40
|
+
panelId: "data-panel-id",
|
|
41
|
+
panelSize: "data-panel-size",
|
|
42
|
+
resizeHandle: "data-resize-handle",
|
|
43
|
+
resizeHandleActive: "data-resize-handle-active",
|
|
44
|
+
resizeHandleEnabled: "data-panel-resize-handle-enabled",
|
|
45
|
+
resizeHandleId: "data-panel-resize-handle-id",
|
|
46
|
+
resizeHandleState: "data-resize-handle-state"
|
|
47
|
+
};
|
|
48
|
+
const PRECISION = 10;
|
|
49
|
+
|
|
34
50
|
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : () => {};
|
|
35
51
|
|
|
36
52
|
const useId = React__namespace["useId".toString()];
|
|
@@ -167,11 +183,11 @@ function PanelWithForwardedRef({
|
|
|
167
183
|
...styleFromProps
|
|
168
184
|
},
|
|
169
185
|
// CSS selectors
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
186
|
+
[DATA_ATTRIBUTES.groupId]: groupId,
|
|
187
|
+
[DATA_ATTRIBUTES.panel]: "",
|
|
188
|
+
[DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
|
|
189
|
+
[DATA_ATTRIBUTES.panelId]: panelId,
|
|
190
|
+
[DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
|
|
175
191
|
});
|
|
176
192
|
}
|
|
177
193
|
const Panel = React.forwardRef((props, ref) => React.createElement(PanelWithForwardedRef, {
|
|
@@ -191,6 +207,7 @@ function setNonce(value) {
|
|
|
191
207
|
|
|
192
208
|
let currentCursorStyle = null;
|
|
193
209
|
let enabled = true;
|
|
210
|
+
let prevRuleIndex = -1;
|
|
194
211
|
let styleElement = null;
|
|
195
212
|
function disableGlobalCursorStyles() {
|
|
196
213
|
enabled = false;
|
|
@@ -240,9 +257,11 @@ function resetGlobalCursorStyle() {
|
|
|
240
257
|
document.head.removeChild(styleElement);
|
|
241
258
|
currentCursorStyle = null;
|
|
242
259
|
styleElement = null;
|
|
260
|
+
prevRuleIndex = -1;
|
|
243
261
|
}
|
|
244
262
|
}
|
|
245
263
|
function setGlobalCursorStyle(state, constraintFlags) {
|
|
264
|
+
var _styleElement$sheet$i, _styleElement$sheet2;
|
|
246
265
|
if (!enabled) {
|
|
247
266
|
return;
|
|
248
267
|
}
|
|
@@ -259,7 +278,11 @@ function setGlobalCursorStyle(state, constraintFlags) {
|
|
|
259
278
|
}
|
|
260
279
|
document.head.appendChild(styleElement);
|
|
261
280
|
}
|
|
262
|
-
|
|
281
|
+
if (prevRuleIndex >= 0) {
|
|
282
|
+
var _styleElement$sheet;
|
|
283
|
+
(_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
|
|
284
|
+
}
|
|
285
|
+
prevRuleIndex = (_styleElement$sheet$i = (_styleElement$sheet2 = styleElement.sheet) === null || _styleElement$sheet2 === void 0 ? void 0 : _styleElement$sheet2.insertRule(`*{cursor: ${style} !important;}`)) !== null && _styleElement$sheet$i !== void 0 ? _styleElement$sheet$i : -1;
|
|
263
286
|
}
|
|
264
287
|
|
|
265
288
|
function isKeyDown(event) {
|
|
@@ -490,7 +513,9 @@ function handlePointerDown(event) {
|
|
|
490
513
|
if (intersectingHandles.length > 0) {
|
|
491
514
|
updateResizeHandlerStates("down", event);
|
|
492
515
|
event.preventDefault();
|
|
493
|
-
|
|
516
|
+
if (!isWithinResizeHandle(target)) {
|
|
517
|
+
event.stopImmediatePropagation();
|
|
518
|
+
}
|
|
494
519
|
}
|
|
495
520
|
}
|
|
496
521
|
function handlePointerMove(event) {
|
|
@@ -539,6 +564,9 @@ function handlePointerUp(event) {
|
|
|
539
564
|
isPointerDown = false;
|
|
540
565
|
if (intersectingHandles.length > 0) {
|
|
541
566
|
event.preventDefault();
|
|
567
|
+
if (!isWithinResizeHandle(target)) {
|
|
568
|
+
event.stopImmediatePropagation();
|
|
569
|
+
}
|
|
542
570
|
}
|
|
543
571
|
updateResizeHandlerStates("up", event);
|
|
544
572
|
recalculateIntersectingHandles({
|
|
@@ -549,6 +577,16 @@ function handlePointerUp(event) {
|
|
|
549
577
|
updateCursor();
|
|
550
578
|
updateListeners();
|
|
551
579
|
}
|
|
580
|
+
function isWithinResizeHandle(element) {
|
|
581
|
+
let currentElement = element;
|
|
582
|
+
while (currentElement) {
|
|
583
|
+
if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
|
|
584
|
+
return true;
|
|
585
|
+
}
|
|
586
|
+
currentElement = currentElement.parentElement;
|
|
587
|
+
}
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
552
590
|
function recalculateIntersectingHandles({
|
|
553
591
|
target,
|
|
554
592
|
x,
|
|
@@ -640,49 +678,42 @@ function updateCursor() {
|
|
|
640
678
|
resetGlobalCursorStyle();
|
|
641
679
|
}
|
|
642
680
|
}
|
|
681
|
+
let listenersAbortController = new AbortController();
|
|
643
682
|
function updateListeners() {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
window.removeEventListener("pointerup", handlePointerUp);
|
|
656
|
-
window.removeEventListener("pointercancel", handlePointerUp);
|
|
657
|
-
if (registeredResizeHandlers.size > 0) {
|
|
658
|
-
if (isPointerDown) {
|
|
659
|
-
if (intersectingHandles.length > 0) {
|
|
660
|
-
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
661
|
-
const {
|
|
662
|
-
body
|
|
663
|
-
} = ownerDocument;
|
|
664
|
-
if (count > 0) {
|
|
665
|
-
body.addEventListener("contextmenu", handlePointerUp);
|
|
666
|
-
body.addEventListener("pointerleave", handlePointerMove);
|
|
667
|
-
body.addEventListener("pointermove", handlePointerMove);
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
window.addEventListener("pointerup", handlePointerUp);
|
|
672
|
-
window.addEventListener("pointercancel", handlePointerUp);
|
|
673
|
-
} else {
|
|
683
|
+
listenersAbortController.abort();
|
|
684
|
+
listenersAbortController = new AbortController();
|
|
685
|
+
const options = {
|
|
686
|
+
capture: true,
|
|
687
|
+
signal: listenersAbortController.signal
|
|
688
|
+
};
|
|
689
|
+
if (!registeredResizeHandlers.size) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (isPointerDown) {
|
|
693
|
+
if (intersectingHandles.length > 0) {
|
|
674
694
|
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
675
695
|
const {
|
|
676
696
|
body
|
|
677
697
|
} = ownerDocument;
|
|
678
698
|
if (count > 0) {
|
|
679
|
-
body.addEventListener("
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
body.addEventListener("pointermove", handlePointerMove);
|
|
699
|
+
body.addEventListener("contextmenu", handlePointerUp, options);
|
|
700
|
+
body.addEventListener("pointerleave", handlePointerMove, options);
|
|
701
|
+
body.addEventListener("pointermove", handlePointerMove, options);
|
|
683
702
|
}
|
|
684
703
|
});
|
|
685
704
|
}
|
|
705
|
+
window.addEventListener("pointerup", handlePointerUp, options);
|
|
706
|
+
window.addEventListener("pointercancel", handlePointerUp, options);
|
|
707
|
+
} else {
|
|
708
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
709
|
+
const {
|
|
710
|
+
body
|
|
711
|
+
} = ownerDocument;
|
|
712
|
+
if (count > 0) {
|
|
713
|
+
body.addEventListener("pointerdown", handlePointerDown, options);
|
|
714
|
+
body.addEventListener("pointermove", handlePointerMove, options);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
686
717
|
}
|
|
687
718
|
}
|
|
688
719
|
function updateResizeHandlerStates(action, event) {
|
|
@@ -707,8 +738,6 @@ function assert(expectedCondition, message) {
|
|
|
707
738
|
}
|
|
708
739
|
}
|
|
709
740
|
|
|
710
|
-
const PRECISION = 10;
|
|
711
|
-
|
|
712
741
|
function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
|
|
713
742
|
if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
|
|
714
743
|
return 0;
|
|
@@ -1052,12 +1081,12 @@ function calculateAriaValues({
|
|
|
1052
1081
|
}
|
|
1053
1082
|
|
|
1054
1083
|
function getResizeHandleElementsForGroup(groupId, scope = document) {
|
|
1055
|
-
return Array.from(scope.querySelectorAll(`[
|
|
1084
|
+
return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
|
|
1056
1085
|
}
|
|
1057
1086
|
|
|
1058
1087
|
function getResizeHandleElementIndex(groupId, id, scope = document) {
|
|
1059
1088
|
const handles = getResizeHandleElementsForGroup(groupId, scope);
|
|
1060
|
-
const index = handles.findIndex(handle => handle.getAttribute(
|
|
1089
|
+
const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
|
|
1061
1090
|
return index !== null && index !== void 0 ? index : null;
|
|
1062
1091
|
}
|
|
1063
1092
|
|
|
@@ -1082,7 +1111,7 @@ function getPanelGroupElement(id, rootElement = document) {
|
|
|
1082
1111
|
}
|
|
1083
1112
|
|
|
1084
1113
|
function getResizeHandleElement(id, scope = document) {
|
|
1085
|
-
const element = scope.querySelector(`[
|
|
1114
|
+
const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
|
|
1086
1115
|
if (element) {
|
|
1087
1116
|
return element;
|
|
1088
1117
|
}
|
|
@@ -1161,7 +1190,7 @@ function useWindowSplitterPanelGroupBehavior({
|
|
|
1161
1190
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
1162
1191
|
assert(handles, `No resize handles found for group id "${groupId}"`);
|
|
1163
1192
|
const cleanupFunctions = handles.map(handle => {
|
|
1164
|
-
const handleId = handle.getAttribute(
|
|
1193
|
+
const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
|
|
1165
1194
|
assert(handleId, `Resize handle element has no handle id attribute`);
|
|
1166
1195
|
const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
|
|
1167
1196
|
if (idBefore == null || idAfter == null) {
|
|
@@ -1239,7 +1268,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
|
|
|
1239
1268
|
const isHorizontal = direction === "horizontal";
|
|
1240
1269
|
const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
|
|
1241
1270
|
assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
|
|
1242
|
-
const groupId = handleElement.getAttribute(
|
|
1271
|
+
const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
|
|
1243
1272
|
assert(groupId, `Resize handle element has no group id attribute`);
|
|
1244
1273
|
let {
|
|
1245
1274
|
initialCursorPosition
|
|
@@ -2155,9 +2184,9 @@ function PanelGroupWithForwardedRef({
|
|
|
2155
2184
|
...styleFromProps
|
|
2156
2185
|
},
|
|
2157
2186
|
// CSS selectors
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2187
|
+
[DATA_ATTRIBUTES.group]: "",
|
|
2188
|
+
[DATA_ATTRIBUTES.groupDirection]: direction,
|
|
2189
|
+
[DATA_ATTRIBUTES.groupId]: groupId
|
|
2161
2190
|
}));
|
|
2162
2191
|
}
|
|
2163
2192
|
const PanelGroup = React.forwardRef((props, ref) => React.createElement(PanelGroupWithForwardedRef, {
|
|
@@ -2216,7 +2245,7 @@ function useWindowSplitterResizeHandlerBehavior({
|
|
|
2216
2245
|
case "F6":
|
|
2217
2246
|
{
|
|
2218
2247
|
event.preventDefault();
|
|
2219
|
-
const groupId = handleElement.getAttribute(
|
|
2248
|
+
const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
|
|
2220
2249
|
assert(groupId, `No group element found for id "${groupId}"`);
|
|
2221
2250
|
const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
|
|
2222
2251
|
const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
|
|
@@ -2311,54 +2340,54 @@ function PanelResizeHandle({
|
|
|
2311
2340
|
assert(element, "Element ref not attached");
|
|
2312
2341
|
let didMove = false;
|
|
2313
2342
|
const setResizeHandlerState = (action, isActive, event) => {
|
|
2314
|
-
if (isActive) {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
onDragging
|
|
2327
|
-
onPointerDown
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
resizeHandler(event);
|
|
2341
|
-
break;
|
|
2342
|
-
}
|
|
2343
|
-
case "up":
|
|
2344
|
-
{
|
|
2343
|
+
if (!isActive) {
|
|
2344
|
+
setState("inactive");
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
switch (action) {
|
|
2348
|
+
case "down":
|
|
2349
|
+
{
|
|
2350
|
+
setState("drag");
|
|
2351
|
+
didMove = false;
|
|
2352
|
+
assert(event, 'Expected event to be defined for "down" action');
|
|
2353
|
+
startDragging(resizeHandleId, event);
|
|
2354
|
+
const {
|
|
2355
|
+
onDragging,
|
|
2356
|
+
onPointerDown
|
|
2357
|
+
} = callbacksRef.current;
|
|
2358
|
+
onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
|
|
2359
|
+
onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
|
|
2360
|
+
break;
|
|
2361
|
+
}
|
|
2362
|
+
case "move":
|
|
2363
|
+
{
|
|
2364
|
+
const {
|
|
2365
|
+
state
|
|
2366
|
+
} = committedValuesRef.current;
|
|
2367
|
+
didMove = true;
|
|
2368
|
+
if (state !== "drag") {
|
|
2345
2369
|
setState("hover");
|
|
2346
|
-
stopDragging();
|
|
2347
|
-
const {
|
|
2348
|
-
onClick,
|
|
2349
|
-
onDragging,
|
|
2350
|
-
onPointerUp
|
|
2351
|
-
} = callbacksRef.current;
|
|
2352
|
-
onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
|
|
2353
|
-
onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
|
|
2354
|
-
if (!didMove) {
|
|
2355
|
-
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
2356
|
-
}
|
|
2357
|
-
break;
|
|
2358
2370
|
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2371
|
+
assert(event, 'Expected event to be defined for "move" action');
|
|
2372
|
+
resizeHandler(event);
|
|
2373
|
+
break;
|
|
2374
|
+
}
|
|
2375
|
+
case "up":
|
|
2376
|
+
{
|
|
2377
|
+
setState("hover");
|
|
2378
|
+
stopDragging();
|
|
2379
|
+
const {
|
|
2380
|
+
onClick,
|
|
2381
|
+
onDragging,
|
|
2382
|
+
onPointerUp
|
|
2383
|
+
} = callbacksRef.current;
|
|
2384
|
+
onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
|
|
2385
|
+
onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
|
|
2386
|
+
if (!didMove) {
|
|
2387
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
2388
|
+
}
|
|
2389
|
+
break;
|
|
2390
|
+
}
|
|
2362
2391
|
}
|
|
2363
2392
|
};
|
|
2364
2393
|
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
@@ -2397,13 +2426,13 @@ function PanelResizeHandle({
|
|
|
2397
2426
|
},
|
|
2398
2427
|
tabIndex,
|
|
2399
2428
|
// CSS selectors
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2429
|
+
[DATA_ATTRIBUTES.groupDirection]: direction,
|
|
2430
|
+
[DATA_ATTRIBUTES.groupId]: groupId,
|
|
2431
|
+
[DATA_ATTRIBUTES.resizeHandle]: "",
|
|
2432
|
+
[DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
2433
|
+
[DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
|
|
2434
|
+
[DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
|
|
2435
|
+
[DATA_ATTRIBUTES.resizeHandleState]: state
|
|
2407
2436
|
});
|
|
2408
2437
|
}
|
|
2409
2438
|
PanelResizeHandle.displayName = "PanelResizeHandle";
|
|
@@ -2437,6 +2466,7 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
|
|
|
2437
2466
|
};
|
|
2438
2467
|
}
|
|
2439
2468
|
|
|
2469
|
+
exports.DATA_ATTRIBUTES = DATA_ATTRIBUTES;
|
|
2440
2470
|
exports.Panel = Panel;
|
|
2441
2471
|
exports.PanelGroup = PanelGroup;
|
|
2442
2472
|
exports.PanelResizeHandle = PanelResizeHandle;
|