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