react-resizable-panels 1.0.9 → 2.0.0
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/README.md +29 -104
- package/dist/declarations/src/PanelResizeHandle.d.ts +3 -1
- package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +20 -0
- package/dist/react-resizable-panels.browser.cjs.js +367 -140
- package/dist/react-resizable-panels.browser.development.cjs.js +367 -140
- package/dist/react-resizable-panels.browser.development.esm.js +367 -140
- package/dist/react-resizable-panels.browser.esm.js +367 -140
- package/dist/react-resizable-panels.cjs.js +367 -140
- package/dist/react-resizable-panels.development.cjs.js +367 -140
- package/dist/react-resizable-panels.development.esm.js +367 -140
- package/dist/react-resizable-panels.development.node.cjs.js +367 -140
- package/dist/react-resizable-panels.development.node.esm.js +367 -140
- package/dist/react-resizable-panels.esm.js +367 -140
- package/dist/react-resizable-panels.node.cjs.js +367 -140
- package/dist/react-resizable-panels.node.esm.js +367 -140
- package/package.json +1 -1
- package/src/Panel.test.tsx +52 -0
- package/src/PanelGroup.ts +23 -16
- package/src/PanelResizeHandle.ts +64 -82
- package/src/PanelResizeHandleRegistry.ts +263 -0
- package/src/utils/calculateDragOffsetPercentage.ts +1 -1
- package/src/utils/cursor.ts +63 -33
- package/src/utils/events/getResizeEventCoordinates.ts +24 -0
- package/src/utils/events/getResizeEventCursorPosition.ts +14 -0
- package/src/utils/{events.ts → events/index.ts} +1 -1
- package/src/utils/getInputType.ts +5 -0
- package/src/utils/getResizeEventCursorPosition.ts +0 -21
|
@@ -198,6 +198,322 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
198
198
|
PanelWithForwardedRef.displayName = "Panel";
|
|
199
199
|
Panel.displayName = "forwardRef(Panel)";
|
|
200
200
|
|
|
201
|
+
let currentCursorStyle = null;
|
|
202
|
+
let styleElement = null;
|
|
203
|
+
function getCursorStyle(state, constraintFlags) {
|
|
204
|
+
if (constraintFlags) {
|
|
205
|
+
const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
|
|
206
|
+
const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
|
|
207
|
+
const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
|
|
208
|
+
const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
|
|
209
|
+
if (horizontalMin) {
|
|
210
|
+
if (verticalMin) {
|
|
211
|
+
return "se-resize";
|
|
212
|
+
} else if (verticalMax) {
|
|
213
|
+
return "ne-resize";
|
|
214
|
+
} else {
|
|
215
|
+
return "e-resize";
|
|
216
|
+
}
|
|
217
|
+
} else if (horizontalMax) {
|
|
218
|
+
if (verticalMin) {
|
|
219
|
+
return "sw-resize";
|
|
220
|
+
} else if (verticalMax) {
|
|
221
|
+
return "nw-resize";
|
|
222
|
+
} else {
|
|
223
|
+
return "w-resize";
|
|
224
|
+
}
|
|
225
|
+
} else if (verticalMin) {
|
|
226
|
+
return "s-resize";
|
|
227
|
+
} else if (verticalMax) {
|
|
228
|
+
return "n-resize";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
switch (state) {
|
|
232
|
+
case "horizontal":
|
|
233
|
+
return "ew-resize";
|
|
234
|
+
case "intersection":
|
|
235
|
+
return "move";
|
|
236
|
+
case "vertical":
|
|
237
|
+
return "ns-resize";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function resetGlobalCursorStyle() {
|
|
241
|
+
if (styleElement !== null) {
|
|
242
|
+
document.head.removeChild(styleElement);
|
|
243
|
+
currentCursorStyle = null;
|
|
244
|
+
styleElement = null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function setGlobalCursorStyle(state, constraintFlags) {
|
|
248
|
+
const style = getCursorStyle(state, constraintFlags);
|
|
249
|
+
if (currentCursorStyle === style) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
currentCursorStyle = style;
|
|
253
|
+
if (styleElement === null) {
|
|
254
|
+
styleElement = document.createElement("style");
|
|
255
|
+
document.head.appendChild(styleElement);
|
|
256
|
+
}
|
|
257
|
+
styleElement.innerHTML = `*{cursor: ${style}!important;}`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function isKeyDown(event) {
|
|
261
|
+
return event.type === "keydown";
|
|
262
|
+
}
|
|
263
|
+
function isMouseEvent(event) {
|
|
264
|
+
return event.type.startsWith("mouse");
|
|
265
|
+
}
|
|
266
|
+
function isTouchEvent(event) {
|
|
267
|
+
return event.type.startsWith("touch");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function getResizeEventCoordinates(event) {
|
|
271
|
+
if (isMouseEvent(event)) {
|
|
272
|
+
return {
|
|
273
|
+
x: event.pageX,
|
|
274
|
+
y: event.pageY
|
|
275
|
+
};
|
|
276
|
+
} else if (isTouchEvent(event)) {
|
|
277
|
+
const touch = event.touches[0];
|
|
278
|
+
if (touch && touch.pageX && touch.pageY) {
|
|
279
|
+
return {
|
|
280
|
+
x: touch.pageX,
|
|
281
|
+
y: touch.pageY
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
x: Infinity,
|
|
287
|
+
y: Infinity
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function getInputType() {
|
|
292
|
+
if (typeof matchMedia === "function") {
|
|
293
|
+
return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
298
|
+
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
299
|
+
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
300
|
+
const EXCEEDED_VERTICAL_MAX = 0b1000;
|
|
301
|
+
const isCoarsePointer = getInputType() === "coarse";
|
|
302
|
+
let intersectingHandles = [];
|
|
303
|
+
let isPointerDown = false;
|
|
304
|
+
let ownerDocumentCounts = new Map();
|
|
305
|
+
let panelConstraintFlags = new Map();
|
|
306
|
+
const registeredResizeHandlers = new Set();
|
|
307
|
+
function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
|
|
308
|
+
var _ownerDocumentCounts$;
|
|
309
|
+
const {
|
|
310
|
+
ownerDocument
|
|
311
|
+
} = element;
|
|
312
|
+
const data = {
|
|
313
|
+
direction,
|
|
314
|
+
element,
|
|
315
|
+
hitAreaMargins,
|
|
316
|
+
setResizeHandlerState
|
|
317
|
+
};
|
|
318
|
+
const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
|
|
319
|
+
ownerDocumentCounts.set(ownerDocument, count + 1);
|
|
320
|
+
registeredResizeHandlers.add(data);
|
|
321
|
+
updateListeners();
|
|
322
|
+
return function unregisterResizeHandle() {
|
|
323
|
+
var _ownerDocumentCounts$2;
|
|
324
|
+
panelConstraintFlags.delete(resizeHandleId);
|
|
325
|
+
registeredResizeHandlers.delete(data);
|
|
326
|
+
const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
|
|
327
|
+
ownerDocumentCounts.set(ownerDocument, count - 1);
|
|
328
|
+
updateListeners();
|
|
329
|
+
if (count === 1) {
|
|
330
|
+
ownerDocumentCounts.delete(ownerDocument);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function handlePointerDown(event) {
|
|
335
|
+
const {
|
|
336
|
+
x,
|
|
337
|
+
y
|
|
338
|
+
} = getResizeEventCoordinates(event);
|
|
339
|
+
isPointerDown = true;
|
|
340
|
+
updateResizeHandlerStates("down", event);
|
|
341
|
+
recalculateIntersectingHandles({
|
|
342
|
+
x,
|
|
343
|
+
y
|
|
344
|
+
});
|
|
345
|
+
updateListeners();
|
|
346
|
+
if (intersectingHandles.length > 0) {
|
|
347
|
+
event.preventDefault();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function handlePointerMove(event) {
|
|
351
|
+
const {
|
|
352
|
+
x,
|
|
353
|
+
y
|
|
354
|
+
} = getResizeEventCoordinates(event);
|
|
355
|
+
if (isPointerDown) {
|
|
356
|
+
intersectingHandles.forEach(data => {
|
|
357
|
+
const {
|
|
358
|
+
setResizeHandlerState
|
|
359
|
+
} = data;
|
|
360
|
+
setResizeHandlerState("move", "drag", event);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// Update cursor based on return value(s) from active handles
|
|
364
|
+
updateCursor();
|
|
365
|
+
} else {
|
|
366
|
+
recalculateIntersectingHandles({
|
|
367
|
+
x,
|
|
368
|
+
y
|
|
369
|
+
});
|
|
370
|
+
updateResizeHandlerStates("move", event);
|
|
371
|
+
updateCursor();
|
|
372
|
+
}
|
|
373
|
+
if (intersectingHandles.length > 0) {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function handlePointerUp(event) {
|
|
378
|
+
const {
|
|
379
|
+
x,
|
|
380
|
+
y
|
|
381
|
+
} = getResizeEventCoordinates(event);
|
|
382
|
+
panelConstraintFlags.clear();
|
|
383
|
+
isPointerDown = false;
|
|
384
|
+
if (intersectingHandles.length > 0) {
|
|
385
|
+
event.preventDefault();
|
|
386
|
+
}
|
|
387
|
+
recalculateIntersectingHandles({
|
|
388
|
+
x,
|
|
389
|
+
y
|
|
390
|
+
});
|
|
391
|
+
updateResizeHandlerStates("up", event);
|
|
392
|
+
updateCursor();
|
|
393
|
+
updateListeners();
|
|
394
|
+
}
|
|
395
|
+
function recalculateIntersectingHandles({
|
|
396
|
+
x,
|
|
397
|
+
y
|
|
398
|
+
}) {
|
|
399
|
+
intersectingHandles.splice(0);
|
|
400
|
+
registeredResizeHandlers.forEach(data => {
|
|
401
|
+
const {
|
|
402
|
+
element,
|
|
403
|
+
hitAreaMargins
|
|
404
|
+
} = data;
|
|
405
|
+
const {
|
|
406
|
+
bottom,
|
|
407
|
+
left,
|
|
408
|
+
right,
|
|
409
|
+
top
|
|
410
|
+
} = element.getBoundingClientRect();
|
|
411
|
+
const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
|
|
412
|
+
const intersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
|
|
413
|
+
if (intersects) {
|
|
414
|
+
intersectingHandles.push(data);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
function reportConstraintsViolation(resizeHandleId, flag) {
|
|
419
|
+
panelConstraintFlags.set(resizeHandleId, flag);
|
|
420
|
+
}
|
|
421
|
+
function updateCursor() {
|
|
422
|
+
let intersectsHorizontal = false;
|
|
423
|
+
let intersectsVertical = false;
|
|
424
|
+
intersectingHandles.forEach(data => {
|
|
425
|
+
const {
|
|
426
|
+
direction
|
|
427
|
+
} = data;
|
|
428
|
+
if (direction === "horizontal") {
|
|
429
|
+
intersectsHorizontal = true;
|
|
430
|
+
} else {
|
|
431
|
+
intersectsVertical = true;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
let constraintFlags = 0;
|
|
435
|
+
panelConstraintFlags.forEach(flag => {
|
|
436
|
+
constraintFlags |= flag;
|
|
437
|
+
});
|
|
438
|
+
if (intersectsHorizontal && intersectsVertical) {
|
|
439
|
+
setGlobalCursorStyle("intersection", constraintFlags);
|
|
440
|
+
} else if (intersectsHorizontal) {
|
|
441
|
+
setGlobalCursorStyle("horizontal", constraintFlags);
|
|
442
|
+
} else if (intersectsVertical) {
|
|
443
|
+
setGlobalCursorStyle("vertical", constraintFlags);
|
|
444
|
+
} else {
|
|
445
|
+
resetGlobalCursorStyle();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function updateListeners() {
|
|
449
|
+
ownerDocumentCounts.forEach((_, ownerDocument) => {
|
|
450
|
+
const {
|
|
451
|
+
body
|
|
452
|
+
} = ownerDocument;
|
|
453
|
+
body.removeEventListener("contextmenu", handlePointerUp);
|
|
454
|
+
body.removeEventListener("mousedown", handlePointerDown);
|
|
455
|
+
body.removeEventListener("mouseleave", handlePointerMove);
|
|
456
|
+
body.removeEventListener("mousemove", handlePointerMove);
|
|
457
|
+
body.removeEventListener("touchmove", handlePointerMove);
|
|
458
|
+
body.removeEventListener("touchstart", handlePointerDown);
|
|
459
|
+
});
|
|
460
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
461
|
+
window.removeEventListener("touchcancel", handlePointerUp);
|
|
462
|
+
window.removeEventListener("touchend", handlePointerUp);
|
|
463
|
+
if (registerResizeHandle.length > 0) {
|
|
464
|
+
if (isPointerDown) {
|
|
465
|
+
if (intersectingHandles.length > 0) {
|
|
466
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
467
|
+
const {
|
|
468
|
+
body
|
|
469
|
+
} = ownerDocument;
|
|
470
|
+
if (count > 0) {
|
|
471
|
+
body.addEventListener("contextmenu", handlePointerUp);
|
|
472
|
+
body.addEventListener("mouseleave", handlePointerMove);
|
|
473
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
474
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
475
|
+
passive: false
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
481
|
+
window.addEventListener("touchcancel", handlePointerUp);
|
|
482
|
+
window.addEventListener("touchend", handlePointerUp);
|
|
483
|
+
} else {
|
|
484
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
485
|
+
const {
|
|
486
|
+
body
|
|
487
|
+
} = ownerDocument;
|
|
488
|
+
if (count > 0) {
|
|
489
|
+
body.addEventListener("mousedown", handlePointerDown);
|
|
490
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
491
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
492
|
+
passive: false
|
|
493
|
+
});
|
|
494
|
+
body.addEventListener("touchstart", handlePointerDown);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function updateResizeHandlerStates(action, event) {
|
|
501
|
+
registeredResizeHandlers.forEach(data => {
|
|
502
|
+
const {
|
|
503
|
+
setResizeHandlerState
|
|
504
|
+
} = data;
|
|
505
|
+
if (intersectingHandles.includes(data)) {
|
|
506
|
+
if (isPointerDown) {
|
|
507
|
+
setResizeHandlerState(action, "drag", event);
|
|
508
|
+
} else {
|
|
509
|
+
setResizeHandlerState(action, "hover", event);
|
|
510
|
+
}
|
|
511
|
+
} else {
|
|
512
|
+
setResizeHandlerState(action, "inactive", event);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
201
517
|
function assert(expectedCondition, message = "Assertion failed!") {
|
|
202
518
|
if (!expectedCondition) {
|
|
203
519
|
console.error(message);
|
|
@@ -703,27 +1019,13 @@ function areEqual(arrayA, arrayB) {
|
|
|
703
1019
|
return true;
|
|
704
1020
|
}
|
|
705
1021
|
|
|
706
|
-
function isKeyDown(event) {
|
|
707
|
-
return event.type === "keydown";
|
|
708
|
-
}
|
|
709
|
-
function isMouseEvent(event) {
|
|
710
|
-
return event.type.startsWith("mouse");
|
|
711
|
-
}
|
|
712
|
-
function isTouchEvent(event) {
|
|
713
|
-
return event.type.startsWith("touch");
|
|
714
|
-
}
|
|
715
|
-
|
|
716
1022
|
function getResizeEventCursorPosition(direction, event) {
|
|
717
1023
|
const isHorizontal = direction === "horizontal";
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
724
|
-
} else {
|
|
725
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
726
|
-
}
|
|
1024
|
+
const {
|
|
1025
|
+
x,
|
|
1026
|
+
y
|
|
1027
|
+
} = getResizeEventCoordinates(event);
|
|
1028
|
+
return isHorizontal ? x : y;
|
|
727
1029
|
}
|
|
728
1030
|
|
|
729
1031
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
@@ -913,44 +1215,6 @@ function computePanelFlexBoxStyle({
|
|
|
913
1215
|
};
|
|
914
1216
|
}
|
|
915
1217
|
|
|
916
|
-
let currentState = null;
|
|
917
|
-
let element = null;
|
|
918
|
-
function getCursorStyle(state) {
|
|
919
|
-
switch (state) {
|
|
920
|
-
case "horizontal":
|
|
921
|
-
return "ew-resize";
|
|
922
|
-
case "horizontal-max":
|
|
923
|
-
return "w-resize";
|
|
924
|
-
case "horizontal-min":
|
|
925
|
-
return "e-resize";
|
|
926
|
-
case "vertical":
|
|
927
|
-
return "ns-resize";
|
|
928
|
-
case "vertical-max":
|
|
929
|
-
return "n-resize";
|
|
930
|
-
case "vertical-min":
|
|
931
|
-
return "s-resize";
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
function resetGlobalCursorStyle() {
|
|
935
|
-
if (element !== null) {
|
|
936
|
-
document.head.removeChild(element);
|
|
937
|
-
currentState = null;
|
|
938
|
-
element = null;
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
function setGlobalCursorStyle(state) {
|
|
942
|
-
if (currentState === state) {
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
|
-
currentState = state;
|
|
946
|
-
const style = getCursorStyle(state);
|
|
947
|
-
if (element === null) {
|
|
948
|
-
element = document.createElement("style");
|
|
949
|
-
document.head.appendChild(element);
|
|
950
|
-
}
|
|
951
|
-
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
1218
|
function debounce(callback, durationMs = 10) {
|
|
955
1219
|
let timeoutId = null;
|
|
956
1220
|
let callable = (...args) => {
|
|
@@ -1496,18 +1760,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1496
1760
|
if (prevDeltaRef.current != delta) {
|
|
1497
1761
|
prevDeltaRef.current = delta;
|
|
1498
1762
|
if (!layoutChanged) {
|
|
1499
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
1500
|
-
// update the cursor style for a visual clue.
|
|
1763
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
1501
1764
|
// This mimics VS Code behavior.
|
|
1502
|
-
|
|
1503
1765
|
if (isHorizontal) {
|
|
1504
|
-
|
|
1766
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
|
|
1505
1767
|
} else {
|
|
1506
|
-
|
|
1768
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
|
|
1507
1769
|
}
|
|
1508
1770
|
} else {
|
|
1509
|
-
|
|
1510
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1771
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
1511
1772
|
}
|
|
1512
1773
|
}
|
|
1513
1774
|
}
|
|
@@ -1562,15 +1823,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1562
1823
|
} = eagerValuesRef.current;
|
|
1563
1824
|
const {
|
|
1564
1825
|
collapsedSize: prevCollapsedSize = 0,
|
|
1565
|
-
collapsible: prevCollapsible
|
|
1566
|
-
defaultSize: prevDefaultSize,
|
|
1567
|
-
maxSize: prevMaxSize = 100,
|
|
1568
|
-
minSize: prevMinSize = 0
|
|
1826
|
+
collapsible: prevCollapsible
|
|
1569
1827
|
} = prevConstraints;
|
|
1570
1828
|
const {
|
|
1571
1829
|
collapsedSize: nextCollapsedSize = 0,
|
|
1572
1830
|
collapsible: nextCollapsible,
|
|
1573
|
-
defaultSize: nextDefaultSize,
|
|
1574
1831
|
maxSize: nextMaxSize = 100,
|
|
1575
1832
|
minSize: nextMinSize = 0
|
|
1576
1833
|
} = panelData.constraints;
|
|
@@ -1578,8 +1835,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1578
1835
|
panelSize: prevPanelSize
|
|
1579
1836
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1580
1837
|
assert(prevPanelSize != null);
|
|
1581
|
-
if (prevCollapsible && nextCollapsible &&
|
|
1582
|
-
|
|
1838
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1839
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1840
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1841
|
+
}
|
|
1583
1842
|
} else if (prevPanelSize < nextMinSize) {
|
|
1584
1843
|
resizePanel(panelData, nextMinSize);
|
|
1585
1844
|
} else if (prevPanelSize > nextMaxSize) {
|
|
@@ -1607,7 +1866,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1607
1866
|
});
|
|
1608
1867
|
}, []);
|
|
1609
1868
|
const stopDragging = useCallback(() => {
|
|
1610
|
-
resetGlobalCursorStyle();
|
|
1611
1869
|
setDragState(null);
|
|
1612
1870
|
}, []);
|
|
1613
1871
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1748,6 +2006,7 @@ function PanelResizeHandle({
|
|
|
1748
2006
|
children = null,
|
|
1749
2007
|
className: classNameFromProps = "",
|
|
1750
2008
|
disabled = false,
|
|
2009
|
+
hitAreaMargins,
|
|
1751
2010
|
id: idFromProps,
|
|
1752
2011
|
onDragging,
|
|
1753
2012
|
style: styleFromProps = {},
|
|
@@ -1770,67 +2029,60 @@ function PanelResizeHandle({
|
|
|
1770
2029
|
}
|
|
1771
2030
|
const {
|
|
1772
2031
|
direction,
|
|
1773
|
-
dragState,
|
|
1774
2032
|
groupId,
|
|
1775
|
-
registerResizeHandle,
|
|
2033
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1776
2034
|
startDragging,
|
|
1777
2035
|
stopDragging,
|
|
1778
2036
|
panelGroupElement
|
|
1779
2037
|
} = panelGroupContext;
|
|
1780
2038
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1781
|
-
const
|
|
2039
|
+
const [state, setState] = useState("inactive");
|
|
1782
2040
|
const [isFocused, setIsFocused] = useState(false);
|
|
1783
2041
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1784
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1785
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1786
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1787
|
-
const element = elementRef.current;
|
|
1788
|
-
assert(element);
|
|
1789
|
-
element.blur();
|
|
1790
|
-
stopDragging();
|
|
1791
|
-
const {
|
|
1792
|
-
onDragging
|
|
1793
|
-
} = callbacksRef.current;
|
|
1794
|
-
if (onDragging) {
|
|
1795
|
-
onDragging(false);
|
|
1796
|
-
}
|
|
1797
|
-
}, [stopDragging]);
|
|
1798
2042
|
useEffect(() => {
|
|
1799
2043
|
if (disabled) {
|
|
1800
2044
|
setResizeHandler(null);
|
|
1801
2045
|
} else {
|
|
1802
|
-
const resizeHandler =
|
|
2046
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1803
2047
|
setResizeHandler(() => resizeHandler);
|
|
1804
2048
|
}
|
|
1805
|
-
}, [disabled, resizeHandleId,
|
|
2049
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1806
2050
|
useEffect(() => {
|
|
1807
|
-
|
|
2051
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
2052
|
+
if (disabled || resizeHandler == null) {
|
|
1808
2053
|
return;
|
|
1809
2054
|
}
|
|
1810
|
-
const onMove = event => {
|
|
1811
|
-
resizeHandler(event);
|
|
1812
|
-
};
|
|
1813
|
-
const onMouseLeave = event => {
|
|
1814
|
-
resizeHandler(event);
|
|
1815
|
-
};
|
|
1816
2055
|
const element = elementRef.current;
|
|
1817
2056
|
assert(element);
|
|
1818
|
-
const
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2057
|
+
const setResizeHandlerState = (action, state, event) => {
|
|
2058
|
+
setState(state);
|
|
2059
|
+
switch (action) {
|
|
2060
|
+
case "down":
|
|
2061
|
+
{
|
|
2062
|
+
startDragging(resizeHandleId, event);
|
|
2063
|
+
break;
|
|
2064
|
+
}
|
|
2065
|
+
case "up":
|
|
2066
|
+
{
|
|
2067
|
+
stopDragging();
|
|
2068
|
+
break;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
switch (state) {
|
|
2072
|
+
case "drag":
|
|
2073
|
+
{
|
|
2074
|
+
resizeHandler(event);
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
1832
2078
|
};
|
|
1833
|
-
|
|
2079
|
+
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
2080
|
+
// Coarse inputs (e.g. finger/touch)
|
|
2081
|
+
coarse: (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15,
|
|
2082
|
+
// Fine inputs (e.g. mouse)
|
|
2083
|
+
fine: (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5
|
|
2084
|
+
}, setResizeHandlerState);
|
|
2085
|
+
}, [direction, disabled, hitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
|
|
1834
2086
|
useWindowSplitterResizeHandlerBehavior({
|
|
1835
2087
|
disabled,
|
|
1836
2088
|
handleId: resizeHandleId,
|
|
@@ -1838,7 +2090,6 @@ function PanelResizeHandle({
|
|
|
1838
2090
|
panelGroupElement
|
|
1839
2091
|
});
|
|
1840
2092
|
const style = {
|
|
1841
|
-
cursor: getCursorStyle(direction),
|
|
1842
2093
|
touchAction: "none",
|
|
1843
2094
|
userSelect: "none"
|
|
1844
2095
|
};
|
|
@@ -1848,31 +2099,6 @@ function PanelResizeHandle({
|
|
|
1848
2099
|
className: classNameFromProps,
|
|
1849
2100
|
onBlur: () => setIsFocused(false),
|
|
1850
2101
|
onFocus: () => setIsFocused(true),
|
|
1851
|
-
onMouseDown: event => {
|
|
1852
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1853
|
-
const callbacks = callbacksRef.current;
|
|
1854
|
-
assert(callbacks);
|
|
1855
|
-
const {
|
|
1856
|
-
onDragging
|
|
1857
|
-
} = callbacks;
|
|
1858
|
-
if (onDragging) {
|
|
1859
|
-
onDragging(true);
|
|
1860
|
-
}
|
|
1861
|
-
},
|
|
1862
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1863
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1864
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1865
|
-
onTouchStart: event => {
|
|
1866
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1867
|
-
const callbacks = callbacksRef.current;
|
|
1868
|
-
assert(callbacks);
|
|
1869
|
-
const {
|
|
1870
|
-
onDragging
|
|
1871
|
-
} = callbacks;
|
|
1872
|
-
if (onDragging) {
|
|
1873
|
-
onDragging(true);
|
|
1874
|
-
}
|
|
1875
|
-
},
|
|
1876
2102
|
ref: elementRef,
|
|
1877
2103
|
role: "separator",
|
|
1878
2104
|
style: {
|
|
@@ -1884,7 +2110,8 @@ function PanelResizeHandle({
|
|
|
1884
2110
|
"data-panel-group-direction": direction,
|
|
1885
2111
|
"data-panel-group-id": groupId,
|
|
1886
2112
|
"data-resize-handle": "",
|
|
1887
|
-
"data-resize-handle-active":
|
|
2113
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
2114
|
+
"data-resize-handle-state": state,
|
|
1888
2115
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1889
2116
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1890
2117
|
});
|