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);
|
|
@@ -606,27 +922,13 @@ function areEqual(arrayA, arrayB) {
|
|
|
606
922
|
return true;
|
|
607
923
|
}
|
|
608
924
|
|
|
609
|
-
function isKeyDown(event) {
|
|
610
|
-
return event.type === "keydown";
|
|
611
|
-
}
|
|
612
|
-
function isMouseEvent(event) {
|
|
613
|
-
return event.type.startsWith("mouse");
|
|
614
|
-
}
|
|
615
|
-
function isTouchEvent(event) {
|
|
616
|
-
return event.type.startsWith("touch");
|
|
617
|
-
}
|
|
618
|
-
|
|
619
925
|
function getResizeEventCursorPosition(direction, event) {
|
|
620
926
|
const isHorizontal = direction === "horizontal";
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
627
|
-
} else {
|
|
628
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
629
|
-
}
|
|
927
|
+
const {
|
|
928
|
+
x,
|
|
929
|
+
y
|
|
930
|
+
} = getResizeEventCoordinates(event);
|
|
931
|
+
return isHorizontal ? x : y;
|
|
630
932
|
}
|
|
631
933
|
|
|
632
934
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
@@ -775,44 +1077,6 @@ function computePanelFlexBoxStyle({
|
|
|
775
1077
|
};
|
|
776
1078
|
}
|
|
777
1079
|
|
|
778
|
-
let currentState = null;
|
|
779
|
-
let element = null;
|
|
780
|
-
function getCursorStyle(state) {
|
|
781
|
-
switch (state) {
|
|
782
|
-
case "horizontal":
|
|
783
|
-
return "ew-resize";
|
|
784
|
-
case "horizontal-max":
|
|
785
|
-
return "w-resize";
|
|
786
|
-
case "horizontal-min":
|
|
787
|
-
return "e-resize";
|
|
788
|
-
case "vertical":
|
|
789
|
-
return "ns-resize";
|
|
790
|
-
case "vertical-max":
|
|
791
|
-
return "n-resize";
|
|
792
|
-
case "vertical-min":
|
|
793
|
-
return "s-resize";
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
function resetGlobalCursorStyle() {
|
|
797
|
-
if (element !== null) {
|
|
798
|
-
document.head.removeChild(element);
|
|
799
|
-
currentState = null;
|
|
800
|
-
element = null;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function setGlobalCursorStyle(state) {
|
|
804
|
-
if (currentState === state) {
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
currentState = state;
|
|
808
|
-
const style = getCursorStyle(state);
|
|
809
|
-
if (element === null) {
|
|
810
|
-
element = document.createElement("style");
|
|
811
|
-
document.head.appendChild(element);
|
|
812
|
-
}
|
|
813
|
-
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
1080
|
function debounce(callback, durationMs = 10) {
|
|
817
1081
|
let timeoutId = null;
|
|
818
1082
|
let callable = (...args) => {
|
|
@@ -1386,18 +1650,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1386
1650
|
if (prevDeltaRef.current != delta) {
|
|
1387
1651
|
prevDeltaRef.current = delta;
|
|
1388
1652
|
if (!layoutChanged) {
|
|
1389
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
1390
|
-
// update the cursor style for a visual clue.
|
|
1653
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
1391
1654
|
// This mimics VS Code behavior.
|
|
1392
|
-
|
|
1393
1655
|
if (isHorizontal) {
|
|
1394
|
-
|
|
1656
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
|
|
1395
1657
|
} else {
|
|
1396
|
-
|
|
1658
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
|
|
1397
1659
|
}
|
|
1398
1660
|
} else {
|
|
1399
|
-
|
|
1400
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1661
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
1401
1662
|
}
|
|
1402
1663
|
}
|
|
1403
1664
|
}
|
|
@@ -1452,15 +1713,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1452
1713
|
} = eagerValuesRef.current;
|
|
1453
1714
|
const {
|
|
1454
1715
|
collapsedSize: prevCollapsedSize = 0,
|
|
1455
|
-
collapsible: prevCollapsible
|
|
1456
|
-
defaultSize: prevDefaultSize,
|
|
1457
|
-
maxSize: prevMaxSize = 100,
|
|
1458
|
-
minSize: prevMinSize = 0
|
|
1716
|
+
collapsible: prevCollapsible
|
|
1459
1717
|
} = prevConstraints;
|
|
1460
1718
|
const {
|
|
1461
1719
|
collapsedSize: nextCollapsedSize = 0,
|
|
1462
1720
|
collapsible: nextCollapsible,
|
|
1463
|
-
defaultSize: nextDefaultSize,
|
|
1464
1721
|
maxSize: nextMaxSize = 100,
|
|
1465
1722
|
minSize: nextMinSize = 0
|
|
1466
1723
|
} = panelData.constraints;
|
|
@@ -1468,8 +1725,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1468
1725
|
panelSize: prevPanelSize
|
|
1469
1726
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1470
1727
|
assert(prevPanelSize != null);
|
|
1471
|
-
if (prevCollapsible && nextCollapsible &&
|
|
1472
|
-
|
|
1728
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1729
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1730
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1731
|
+
}
|
|
1473
1732
|
} else if (prevPanelSize < nextMinSize) {
|
|
1474
1733
|
resizePanel(panelData, nextMinSize);
|
|
1475
1734
|
} else if (prevPanelSize > nextMaxSize) {
|
|
@@ -1497,7 +1756,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1497
1756
|
});
|
|
1498
1757
|
}, []);
|
|
1499
1758
|
const stopDragging = useCallback(() => {
|
|
1500
|
-
resetGlobalCursorStyle();
|
|
1501
1759
|
setDragState(null);
|
|
1502
1760
|
}, []);
|
|
1503
1761
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1638,6 +1896,7 @@ function PanelResizeHandle({
|
|
|
1638
1896
|
children = null,
|
|
1639
1897
|
className: classNameFromProps = "",
|
|
1640
1898
|
disabled = false,
|
|
1899
|
+
hitAreaMargins,
|
|
1641
1900
|
id: idFromProps,
|
|
1642
1901
|
onDragging,
|
|
1643
1902
|
style: styleFromProps = {},
|
|
@@ -1660,67 +1919,60 @@ function PanelResizeHandle({
|
|
|
1660
1919
|
}
|
|
1661
1920
|
const {
|
|
1662
1921
|
direction,
|
|
1663
|
-
dragState,
|
|
1664
1922
|
groupId,
|
|
1665
|
-
registerResizeHandle,
|
|
1923
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1666
1924
|
startDragging,
|
|
1667
1925
|
stopDragging,
|
|
1668
1926
|
panelGroupElement
|
|
1669
1927
|
} = panelGroupContext;
|
|
1670
1928
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1671
|
-
const
|
|
1929
|
+
const [state, setState] = useState("inactive");
|
|
1672
1930
|
const [isFocused, setIsFocused] = useState(false);
|
|
1673
1931
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1674
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1675
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1676
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1677
|
-
const element = elementRef.current;
|
|
1678
|
-
assert(element);
|
|
1679
|
-
element.blur();
|
|
1680
|
-
stopDragging();
|
|
1681
|
-
const {
|
|
1682
|
-
onDragging
|
|
1683
|
-
} = callbacksRef.current;
|
|
1684
|
-
if (onDragging) {
|
|
1685
|
-
onDragging(false);
|
|
1686
|
-
}
|
|
1687
|
-
}, [stopDragging]);
|
|
1688
1932
|
useEffect(() => {
|
|
1689
1933
|
if (disabled) {
|
|
1690
1934
|
setResizeHandler(null);
|
|
1691
1935
|
} else {
|
|
1692
|
-
const resizeHandler =
|
|
1936
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1693
1937
|
setResizeHandler(() => resizeHandler);
|
|
1694
1938
|
}
|
|
1695
|
-
}, [disabled, resizeHandleId,
|
|
1939
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1696
1940
|
useEffect(() => {
|
|
1697
|
-
|
|
1941
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
1942
|
+
if (disabled || resizeHandler == null) {
|
|
1698
1943
|
return;
|
|
1699
1944
|
}
|
|
1700
|
-
const onMove = event => {
|
|
1701
|
-
resizeHandler(event);
|
|
1702
|
-
};
|
|
1703
|
-
const onMouseLeave = event => {
|
|
1704
|
-
resizeHandler(event);
|
|
1705
|
-
};
|
|
1706
1945
|
const element = elementRef.current;
|
|
1707
1946
|
assert(element);
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1947
|
+
const setResizeHandlerState = (action, state, event) => {
|
|
1948
|
+
setState(state);
|
|
1949
|
+
switch (action) {
|
|
1950
|
+
case "down":
|
|
1951
|
+
{
|
|
1952
|
+
startDragging(resizeHandleId, event);
|
|
1953
|
+
break;
|
|
1954
|
+
}
|
|
1955
|
+
case "up":
|
|
1956
|
+
{
|
|
1957
|
+
stopDragging();
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
switch (state) {
|
|
1962
|
+
case "drag":
|
|
1963
|
+
{
|
|
1964
|
+
resizeHandler(event);
|
|
1965
|
+
break;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1722
1968
|
};
|
|
1723
|
-
|
|
1969
|
+
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
1970
|
+
// Coarse inputs (e.g. finger/touch)
|
|
1971
|
+
coarse: (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15,
|
|
1972
|
+
// Fine inputs (e.g. mouse)
|
|
1973
|
+
fine: (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5
|
|
1974
|
+
}, setResizeHandlerState);
|
|
1975
|
+
}, [direction, disabled, hitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
|
|
1724
1976
|
useWindowSplitterResizeHandlerBehavior({
|
|
1725
1977
|
disabled,
|
|
1726
1978
|
handleId: resizeHandleId,
|
|
@@ -1728,7 +1980,6 @@ function PanelResizeHandle({
|
|
|
1728
1980
|
panelGroupElement
|
|
1729
1981
|
});
|
|
1730
1982
|
const style = {
|
|
1731
|
-
cursor: getCursorStyle(direction),
|
|
1732
1983
|
touchAction: "none",
|
|
1733
1984
|
userSelect: "none"
|
|
1734
1985
|
};
|
|
@@ -1738,31 +1989,6 @@ function PanelResizeHandle({
|
|
|
1738
1989
|
className: classNameFromProps,
|
|
1739
1990
|
onBlur: () => setIsFocused(false),
|
|
1740
1991
|
onFocus: () => setIsFocused(true),
|
|
1741
|
-
onMouseDown: event => {
|
|
1742
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1743
|
-
const callbacks = callbacksRef.current;
|
|
1744
|
-
assert(callbacks);
|
|
1745
|
-
const {
|
|
1746
|
-
onDragging
|
|
1747
|
-
} = callbacks;
|
|
1748
|
-
if (onDragging) {
|
|
1749
|
-
onDragging(true);
|
|
1750
|
-
}
|
|
1751
|
-
},
|
|
1752
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1753
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1754
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1755
|
-
onTouchStart: event => {
|
|
1756
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1757
|
-
const callbacks = callbacksRef.current;
|
|
1758
|
-
assert(callbacks);
|
|
1759
|
-
const {
|
|
1760
|
-
onDragging
|
|
1761
|
-
} = callbacks;
|
|
1762
|
-
if (onDragging) {
|
|
1763
|
-
onDragging(true);
|
|
1764
|
-
}
|
|
1765
|
-
},
|
|
1766
1992
|
ref: elementRef,
|
|
1767
1993
|
role: "separator",
|
|
1768
1994
|
style: {
|
|
@@ -1774,7 +2000,8 @@ function PanelResizeHandle({
|
|
|
1774
2000
|
"data-panel-group-direction": direction,
|
|
1775
2001
|
"data-panel-group-id": groupId,
|
|
1776
2002
|
"data-resize-handle": "",
|
|
1777
|
-
"data-resize-handle-active":
|
|
2003
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
2004
|
+
"data-resize-handle-state": state,
|
|
1778
2005
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1779
2006
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1780
2007
|
});
|