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