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
|
@@ -176,6 +176,322 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
176
176
|
PanelWithForwardedRef.displayName = "Panel";
|
|
177
177
|
Panel.displayName = "forwardRef(Panel)";
|
|
178
178
|
|
|
179
|
+
let currentCursorStyle = null;
|
|
180
|
+
let styleElement = null;
|
|
181
|
+
function getCursorStyle(state, constraintFlags) {
|
|
182
|
+
if (constraintFlags) {
|
|
183
|
+
const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
|
|
184
|
+
const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
|
|
185
|
+
const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
|
|
186
|
+
const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
|
|
187
|
+
if (horizontalMin) {
|
|
188
|
+
if (verticalMin) {
|
|
189
|
+
return "se-resize";
|
|
190
|
+
} else if (verticalMax) {
|
|
191
|
+
return "ne-resize";
|
|
192
|
+
} else {
|
|
193
|
+
return "e-resize";
|
|
194
|
+
}
|
|
195
|
+
} else if (horizontalMax) {
|
|
196
|
+
if (verticalMin) {
|
|
197
|
+
return "sw-resize";
|
|
198
|
+
} else if (verticalMax) {
|
|
199
|
+
return "nw-resize";
|
|
200
|
+
} else {
|
|
201
|
+
return "w-resize";
|
|
202
|
+
}
|
|
203
|
+
} else if (verticalMin) {
|
|
204
|
+
return "s-resize";
|
|
205
|
+
} else if (verticalMax) {
|
|
206
|
+
return "n-resize";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
switch (state) {
|
|
210
|
+
case "horizontal":
|
|
211
|
+
return "ew-resize";
|
|
212
|
+
case "intersection":
|
|
213
|
+
return "move";
|
|
214
|
+
case "vertical":
|
|
215
|
+
return "ns-resize";
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function resetGlobalCursorStyle() {
|
|
219
|
+
if (styleElement !== null) {
|
|
220
|
+
document.head.removeChild(styleElement);
|
|
221
|
+
currentCursorStyle = null;
|
|
222
|
+
styleElement = null;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function setGlobalCursorStyle(state, constraintFlags) {
|
|
226
|
+
const style = getCursorStyle(state, constraintFlags);
|
|
227
|
+
if (currentCursorStyle === style) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
currentCursorStyle = style;
|
|
231
|
+
if (styleElement === null) {
|
|
232
|
+
styleElement = document.createElement("style");
|
|
233
|
+
document.head.appendChild(styleElement);
|
|
234
|
+
}
|
|
235
|
+
styleElement.innerHTML = `*{cursor: ${style}!important;}`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function isKeyDown(event) {
|
|
239
|
+
return event.type === "keydown";
|
|
240
|
+
}
|
|
241
|
+
function isMouseEvent(event) {
|
|
242
|
+
return event.type.startsWith("mouse");
|
|
243
|
+
}
|
|
244
|
+
function isTouchEvent(event) {
|
|
245
|
+
return event.type.startsWith("touch");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function getResizeEventCoordinates(event) {
|
|
249
|
+
if (isMouseEvent(event)) {
|
|
250
|
+
return {
|
|
251
|
+
x: event.pageX,
|
|
252
|
+
y: event.pageY
|
|
253
|
+
};
|
|
254
|
+
} else if (isTouchEvent(event)) {
|
|
255
|
+
const touch = event.touches[0];
|
|
256
|
+
if (touch && touch.pageX && touch.pageY) {
|
|
257
|
+
return {
|
|
258
|
+
x: touch.pageX,
|
|
259
|
+
y: touch.pageY
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
x: Infinity,
|
|
265
|
+
y: Infinity
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function getInputType() {
|
|
270
|
+
if (typeof matchMedia === "function") {
|
|
271
|
+
return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
276
|
+
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
277
|
+
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
278
|
+
const EXCEEDED_VERTICAL_MAX = 0b1000;
|
|
279
|
+
const isCoarsePointer = getInputType() === "coarse";
|
|
280
|
+
let intersectingHandles = [];
|
|
281
|
+
let isPointerDown = false;
|
|
282
|
+
let ownerDocumentCounts = new Map();
|
|
283
|
+
let panelConstraintFlags = new Map();
|
|
284
|
+
const registeredResizeHandlers = new Set();
|
|
285
|
+
function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
|
|
286
|
+
var _ownerDocumentCounts$;
|
|
287
|
+
const {
|
|
288
|
+
ownerDocument
|
|
289
|
+
} = element;
|
|
290
|
+
const data = {
|
|
291
|
+
direction,
|
|
292
|
+
element,
|
|
293
|
+
hitAreaMargins,
|
|
294
|
+
setResizeHandlerState
|
|
295
|
+
};
|
|
296
|
+
const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
|
|
297
|
+
ownerDocumentCounts.set(ownerDocument, count + 1);
|
|
298
|
+
registeredResizeHandlers.add(data);
|
|
299
|
+
updateListeners();
|
|
300
|
+
return function unregisterResizeHandle() {
|
|
301
|
+
var _ownerDocumentCounts$2;
|
|
302
|
+
panelConstraintFlags.delete(resizeHandleId);
|
|
303
|
+
registeredResizeHandlers.delete(data);
|
|
304
|
+
const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
|
|
305
|
+
ownerDocumentCounts.set(ownerDocument, count - 1);
|
|
306
|
+
updateListeners();
|
|
307
|
+
if (count === 1) {
|
|
308
|
+
ownerDocumentCounts.delete(ownerDocument);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function handlePointerDown(event) {
|
|
313
|
+
const {
|
|
314
|
+
x,
|
|
315
|
+
y
|
|
316
|
+
} = getResizeEventCoordinates(event);
|
|
317
|
+
isPointerDown = true;
|
|
318
|
+
updateResizeHandlerStates("down", event);
|
|
319
|
+
recalculateIntersectingHandles({
|
|
320
|
+
x,
|
|
321
|
+
y
|
|
322
|
+
});
|
|
323
|
+
updateListeners();
|
|
324
|
+
if (intersectingHandles.length > 0) {
|
|
325
|
+
event.preventDefault();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function handlePointerMove(event) {
|
|
329
|
+
const {
|
|
330
|
+
x,
|
|
331
|
+
y
|
|
332
|
+
} = getResizeEventCoordinates(event);
|
|
333
|
+
if (isPointerDown) {
|
|
334
|
+
intersectingHandles.forEach(data => {
|
|
335
|
+
const {
|
|
336
|
+
setResizeHandlerState
|
|
337
|
+
} = data;
|
|
338
|
+
setResizeHandlerState("move", "drag", event);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// Update cursor based on return value(s) from active handles
|
|
342
|
+
updateCursor();
|
|
343
|
+
} else {
|
|
344
|
+
recalculateIntersectingHandles({
|
|
345
|
+
x,
|
|
346
|
+
y
|
|
347
|
+
});
|
|
348
|
+
updateResizeHandlerStates("move", event);
|
|
349
|
+
updateCursor();
|
|
350
|
+
}
|
|
351
|
+
if (intersectingHandles.length > 0) {
|
|
352
|
+
event.preventDefault();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function handlePointerUp(event) {
|
|
356
|
+
const {
|
|
357
|
+
x,
|
|
358
|
+
y
|
|
359
|
+
} = getResizeEventCoordinates(event);
|
|
360
|
+
panelConstraintFlags.clear();
|
|
361
|
+
isPointerDown = false;
|
|
362
|
+
if (intersectingHandles.length > 0) {
|
|
363
|
+
event.preventDefault();
|
|
364
|
+
}
|
|
365
|
+
recalculateIntersectingHandles({
|
|
366
|
+
x,
|
|
367
|
+
y
|
|
368
|
+
});
|
|
369
|
+
updateResizeHandlerStates("up", event);
|
|
370
|
+
updateCursor();
|
|
371
|
+
updateListeners();
|
|
372
|
+
}
|
|
373
|
+
function recalculateIntersectingHandles({
|
|
374
|
+
x,
|
|
375
|
+
y
|
|
376
|
+
}) {
|
|
377
|
+
intersectingHandles.splice(0);
|
|
378
|
+
registeredResizeHandlers.forEach(data => {
|
|
379
|
+
const {
|
|
380
|
+
element,
|
|
381
|
+
hitAreaMargins
|
|
382
|
+
} = data;
|
|
383
|
+
const {
|
|
384
|
+
bottom,
|
|
385
|
+
left,
|
|
386
|
+
right,
|
|
387
|
+
top
|
|
388
|
+
} = element.getBoundingClientRect();
|
|
389
|
+
const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
|
|
390
|
+
const intersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
|
|
391
|
+
if (intersects) {
|
|
392
|
+
intersectingHandles.push(data);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function reportConstraintsViolation(resizeHandleId, flag) {
|
|
397
|
+
panelConstraintFlags.set(resizeHandleId, flag);
|
|
398
|
+
}
|
|
399
|
+
function updateCursor() {
|
|
400
|
+
let intersectsHorizontal = false;
|
|
401
|
+
let intersectsVertical = false;
|
|
402
|
+
intersectingHandles.forEach(data => {
|
|
403
|
+
const {
|
|
404
|
+
direction
|
|
405
|
+
} = data;
|
|
406
|
+
if (direction === "horizontal") {
|
|
407
|
+
intersectsHorizontal = true;
|
|
408
|
+
} else {
|
|
409
|
+
intersectsVertical = true;
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
let constraintFlags = 0;
|
|
413
|
+
panelConstraintFlags.forEach(flag => {
|
|
414
|
+
constraintFlags |= flag;
|
|
415
|
+
});
|
|
416
|
+
if (intersectsHorizontal && intersectsVertical) {
|
|
417
|
+
setGlobalCursorStyle("intersection", constraintFlags);
|
|
418
|
+
} else if (intersectsHorizontal) {
|
|
419
|
+
setGlobalCursorStyle("horizontal", constraintFlags);
|
|
420
|
+
} else if (intersectsVertical) {
|
|
421
|
+
setGlobalCursorStyle("vertical", constraintFlags);
|
|
422
|
+
} else {
|
|
423
|
+
resetGlobalCursorStyle();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function updateListeners() {
|
|
427
|
+
ownerDocumentCounts.forEach((_, ownerDocument) => {
|
|
428
|
+
const {
|
|
429
|
+
body
|
|
430
|
+
} = ownerDocument;
|
|
431
|
+
body.removeEventListener("contextmenu", handlePointerUp);
|
|
432
|
+
body.removeEventListener("mousedown", handlePointerDown);
|
|
433
|
+
body.removeEventListener("mouseleave", handlePointerMove);
|
|
434
|
+
body.removeEventListener("mousemove", handlePointerMove);
|
|
435
|
+
body.removeEventListener("touchmove", handlePointerMove);
|
|
436
|
+
body.removeEventListener("touchstart", handlePointerDown);
|
|
437
|
+
});
|
|
438
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
439
|
+
window.removeEventListener("touchcancel", handlePointerUp);
|
|
440
|
+
window.removeEventListener("touchend", handlePointerUp);
|
|
441
|
+
if (registerResizeHandle.length > 0) {
|
|
442
|
+
if (isPointerDown) {
|
|
443
|
+
if (intersectingHandles.length > 0) {
|
|
444
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
445
|
+
const {
|
|
446
|
+
body
|
|
447
|
+
} = ownerDocument;
|
|
448
|
+
if (count > 0) {
|
|
449
|
+
body.addEventListener("contextmenu", handlePointerUp);
|
|
450
|
+
body.addEventListener("mouseleave", handlePointerMove);
|
|
451
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
452
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
453
|
+
passive: false
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
459
|
+
window.addEventListener("touchcancel", handlePointerUp);
|
|
460
|
+
window.addEventListener("touchend", handlePointerUp);
|
|
461
|
+
} else {
|
|
462
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
463
|
+
const {
|
|
464
|
+
body
|
|
465
|
+
} = ownerDocument;
|
|
466
|
+
if (count > 0) {
|
|
467
|
+
body.addEventListener("mousedown", handlePointerDown);
|
|
468
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
469
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
470
|
+
passive: false
|
|
471
|
+
});
|
|
472
|
+
body.addEventListener("touchstart", handlePointerDown);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function updateResizeHandlerStates(action, event) {
|
|
479
|
+
registeredResizeHandlers.forEach(data => {
|
|
480
|
+
const {
|
|
481
|
+
setResizeHandlerState
|
|
482
|
+
} = data;
|
|
483
|
+
if (intersectingHandles.includes(data)) {
|
|
484
|
+
if (isPointerDown) {
|
|
485
|
+
setResizeHandlerState(action, "drag", event);
|
|
486
|
+
} else {
|
|
487
|
+
setResizeHandlerState(action, "hover", event);
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
setResizeHandlerState(action, "inactive", event);
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
179
495
|
function assert(expectedCondition, message = "Assertion failed!") {
|
|
180
496
|
if (!expectedCondition) {
|
|
181
497
|
console.error(message);
|
|
@@ -681,27 +997,13 @@ function areEqual(arrayA, arrayB) {
|
|
|
681
997
|
return true;
|
|
682
998
|
}
|
|
683
999
|
|
|
684
|
-
function isKeyDown(event) {
|
|
685
|
-
return event.type === "keydown";
|
|
686
|
-
}
|
|
687
|
-
function isMouseEvent(event) {
|
|
688
|
-
return event.type.startsWith("mouse");
|
|
689
|
-
}
|
|
690
|
-
function isTouchEvent(event) {
|
|
691
|
-
return event.type.startsWith("touch");
|
|
692
|
-
}
|
|
693
|
-
|
|
694
1000
|
function getResizeEventCursorPosition(direction, event) {
|
|
695
1001
|
const isHorizontal = direction === "horizontal";
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
702
|
-
} else {
|
|
703
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
704
|
-
}
|
|
1002
|
+
const {
|
|
1003
|
+
x,
|
|
1004
|
+
y
|
|
1005
|
+
} = getResizeEventCoordinates(event);
|
|
1006
|
+
return isHorizontal ? x : y;
|
|
705
1007
|
}
|
|
706
1008
|
|
|
707
1009
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
@@ -891,44 +1193,6 @@ function computePanelFlexBoxStyle({
|
|
|
891
1193
|
};
|
|
892
1194
|
}
|
|
893
1195
|
|
|
894
|
-
let currentState = null;
|
|
895
|
-
let element = null;
|
|
896
|
-
function getCursorStyle(state) {
|
|
897
|
-
switch (state) {
|
|
898
|
-
case "horizontal":
|
|
899
|
-
return "ew-resize";
|
|
900
|
-
case "horizontal-max":
|
|
901
|
-
return "w-resize";
|
|
902
|
-
case "horizontal-min":
|
|
903
|
-
return "e-resize";
|
|
904
|
-
case "vertical":
|
|
905
|
-
return "ns-resize";
|
|
906
|
-
case "vertical-max":
|
|
907
|
-
return "n-resize";
|
|
908
|
-
case "vertical-min":
|
|
909
|
-
return "s-resize";
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
function resetGlobalCursorStyle() {
|
|
913
|
-
if (element !== null) {
|
|
914
|
-
document.head.removeChild(element);
|
|
915
|
-
currentState = null;
|
|
916
|
-
element = null;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
function setGlobalCursorStyle(state) {
|
|
920
|
-
if (currentState === state) {
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
currentState = state;
|
|
924
|
-
const style = getCursorStyle(state);
|
|
925
|
-
if (element === null) {
|
|
926
|
-
element = document.createElement("style");
|
|
927
|
-
document.head.appendChild(element);
|
|
928
|
-
}
|
|
929
|
-
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
1196
|
function debounce(callback, durationMs = 10) {
|
|
933
1197
|
let timeoutId = null;
|
|
934
1198
|
let callable = (...args) => {
|
|
@@ -1474,18 +1738,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1474
1738
|
if (prevDeltaRef.current != delta) {
|
|
1475
1739
|
prevDeltaRef.current = delta;
|
|
1476
1740
|
if (!layoutChanged) {
|
|
1477
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
1478
|
-
// update the cursor style for a visual clue.
|
|
1741
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
1479
1742
|
// This mimics VS Code behavior.
|
|
1480
|
-
|
|
1481
1743
|
if (isHorizontal) {
|
|
1482
|
-
|
|
1744
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
|
|
1483
1745
|
} else {
|
|
1484
|
-
|
|
1746
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
|
|
1485
1747
|
}
|
|
1486
1748
|
} else {
|
|
1487
|
-
|
|
1488
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1749
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
1489
1750
|
}
|
|
1490
1751
|
}
|
|
1491
1752
|
}
|
|
@@ -1540,15 +1801,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1540
1801
|
} = eagerValuesRef.current;
|
|
1541
1802
|
const {
|
|
1542
1803
|
collapsedSize: prevCollapsedSize = 0,
|
|
1543
|
-
collapsible: prevCollapsible
|
|
1544
|
-
defaultSize: prevDefaultSize,
|
|
1545
|
-
maxSize: prevMaxSize = 100,
|
|
1546
|
-
minSize: prevMinSize = 0
|
|
1804
|
+
collapsible: prevCollapsible
|
|
1547
1805
|
} = prevConstraints;
|
|
1548
1806
|
const {
|
|
1549
1807
|
collapsedSize: nextCollapsedSize = 0,
|
|
1550
1808
|
collapsible: nextCollapsible,
|
|
1551
|
-
defaultSize: nextDefaultSize,
|
|
1552
1809
|
maxSize: nextMaxSize = 100,
|
|
1553
1810
|
minSize: nextMinSize = 0
|
|
1554
1811
|
} = panelData.constraints;
|
|
@@ -1556,8 +1813,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1556
1813
|
panelSize: prevPanelSize
|
|
1557
1814
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1558
1815
|
assert(prevPanelSize != null);
|
|
1559
|
-
if (prevCollapsible && nextCollapsible &&
|
|
1560
|
-
|
|
1816
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1817
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1818
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1819
|
+
}
|
|
1561
1820
|
} else if (prevPanelSize < nextMinSize) {
|
|
1562
1821
|
resizePanel(panelData, nextMinSize);
|
|
1563
1822
|
} else if (prevPanelSize > nextMaxSize) {
|
|
@@ -1585,7 +1844,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1585
1844
|
});
|
|
1586
1845
|
}, []);
|
|
1587
1846
|
const stopDragging = useCallback(() => {
|
|
1588
|
-
resetGlobalCursorStyle();
|
|
1589
1847
|
setDragState(null);
|
|
1590
1848
|
}, []);
|
|
1591
1849
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1726,6 +1984,7 @@ function PanelResizeHandle({
|
|
|
1726
1984
|
children = null,
|
|
1727
1985
|
className: classNameFromProps = "",
|
|
1728
1986
|
disabled = false,
|
|
1987
|
+
hitAreaMargins,
|
|
1729
1988
|
id: idFromProps,
|
|
1730
1989
|
onDragging,
|
|
1731
1990
|
style: styleFromProps = {},
|
|
@@ -1748,67 +2007,60 @@ function PanelResizeHandle({
|
|
|
1748
2007
|
}
|
|
1749
2008
|
const {
|
|
1750
2009
|
direction,
|
|
1751
|
-
dragState,
|
|
1752
2010
|
groupId,
|
|
1753
|
-
registerResizeHandle,
|
|
2011
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1754
2012
|
startDragging,
|
|
1755
2013
|
stopDragging,
|
|
1756
2014
|
panelGroupElement
|
|
1757
2015
|
} = panelGroupContext;
|
|
1758
2016
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1759
|
-
const
|
|
2017
|
+
const [state, setState] = useState("inactive");
|
|
1760
2018
|
const [isFocused, setIsFocused] = useState(false);
|
|
1761
2019
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1762
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1763
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1764
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1765
|
-
const element = elementRef.current;
|
|
1766
|
-
assert(element);
|
|
1767
|
-
element.blur();
|
|
1768
|
-
stopDragging();
|
|
1769
|
-
const {
|
|
1770
|
-
onDragging
|
|
1771
|
-
} = callbacksRef.current;
|
|
1772
|
-
if (onDragging) {
|
|
1773
|
-
onDragging(false);
|
|
1774
|
-
}
|
|
1775
|
-
}, [stopDragging]);
|
|
1776
2020
|
useEffect(() => {
|
|
1777
2021
|
if (disabled) {
|
|
1778
2022
|
setResizeHandler(null);
|
|
1779
2023
|
} else {
|
|
1780
|
-
const resizeHandler =
|
|
2024
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1781
2025
|
setResizeHandler(() => resizeHandler);
|
|
1782
2026
|
}
|
|
1783
|
-
}, [disabled, resizeHandleId,
|
|
2027
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1784
2028
|
useEffect(() => {
|
|
1785
|
-
|
|
2029
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
2030
|
+
if (disabled || resizeHandler == null) {
|
|
1786
2031
|
return;
|
|
1787
2032
|
}
|
|
1788
|
-
const onMove = event => {
|
|
1789
|
-
resizeHandler(event);
|
|
1790
|
-
};
|
|
1791
|
-
const onMouseLeave = event => {
|
|
1792
|
-
resizeHandler(event);
|
|
1793
|
-
};
|
|
1794
2033
|
const element = elementRef.current;
|
|
1795
2034
|
assert(element);
|
|
1796
|
-
const
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
2035
|
+
const setResizeHandlerState = (action, state, event) => {
|
|
2036
|
+
setState(state);
|
|
2037
|
+
switch (action) {
|
|
2038
|
+
case "down":
|
|
2039
|
+
{
|
|
2040
|
+
startDragging(resizeHandleId, event);
|
|
2041
|
+
break;
|
|
2042
|
+
}
|
|
2043
|
+
case "up":
|
|
2044
|
+
{
|
|
2045
|
+
stopDragging();
|
|
2046
|
+
break;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
switch (state) {
|
|
2050
|
+
case "drag":
|
|
2051
|
+
{
|
|
2052
|
+
resizeHandler(event);
|
|
2053
|
+
break;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
1810
2056
|
};
|
|
1811
|
-
|
|
2057
|
+
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
2058
|
+
// Coarse inputs (e.g. finger/touch)
|
|
2059
|
+
coarse: (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15,
|
|
2060
|
+
// Fine inputs (e.g. mouse)
|
|
2061
|
+
fine: (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5
|
|
2062
|
+
}, setResizeHandlerState);
|
|
2063
|
+
}, [direction, disabled, hitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
|
|
1812
2064
|
useWindowSplitterResizeHandlerBehavior({
|
|
1813
2065
|
disabled,
|
|
1814
2066
|
handleId: resizeHandleId,
|
|
@@ -1816,7 +2068,6 @@ function PanelResizeHandle({
|
|
|
1816
2068
|
panelGroupElement
|
|
1817
2069
|
});
|
|
1818
2070
|
const style = {
|
|
1819
|
-
cursor: getCursorStyle(direction),
|
|
1820
2071
|
touchAction: "none",
|
|
1821
2072
|
userSelect: "none"
|
|
1822
2073
|
};
|
|
@@ -1826,31 +2077,6 @@ function PanelResizeHandle({
|
|
|
1826
2077
|
className: classNameFromProps,
|
|
1827
2078
|
onBlur: () => setIsFocused(false),
|
|
1828
2079
|
onFocus: () => setIsFocused(true),
|
|
1829
|
-
onMouseDown: event => {
|
|
1830
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1831
|
-
const callbacks = callbacksRef.current;
|
|
1832
|
-
assert(callbacks);
|
|
1833
|
-
const {
|
|
1834
|
-
onDragging
|
|
1835
|
-
} = callbacks;
|
|
1836
|
-
if (onDragging) {
|
|
1837
|
-
onDragging(true);
|
|
1838
|
-
}
|
|
1839
|
-
},
|
|
1840
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1841
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1842
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1843
|
-
onTouchStart: event => {
|
|
1844
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1845
|
-
const callbacks = callbacksRef.current;
|
|
1846
|
-
assert(callbacks);
|
|
1847
|
-
const {
|
|
1848
|
-
onDragging
|
|
1849
|
-
} = callbacks;
|
|
1850
|
-
if (onDragging) {
|
|
1851
|
-
onDragging(true);
|
|
1852
|
-
}
|
|
1853
|
-
},
|
|
1854
2080
|
ref: elementRef,
|
|
1855
2081
|
role: "separator",
|
|
1856
2082
|
style: {
|
|
@@ -1862,7 +2088,8 @@ function PanelResizeHandle({
|
|
|
1862
2088
|
"data-panel-group-direction": direction,
|
|
1863
2089
|
"data-panel-group-id": groupId,
|
|
1864
2090
|
"data-resize-handle": "",
|
|
1865
|
-
"data-resize-handle-active":
|
|
2091
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
2092
|
+
"data-resize-handle-state": state,
|
|
1866
2093
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1867
2094
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1868
2095
|
});
|