react-resizable-panels 1.0.10 → 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 +5 -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 +362 -133
- package/dist/react-resizable-panels.browser.development.cjs.js +362 -133
- package/dist/react-resizable-panels.browser.development.esm.js +362 -133
- package/dist/react-resizable-panels.browser.esm.js +362 -133
- package/dist/react-resizable-panels.cjs.js +362 -133
- package/dist/react-resizable-panels.development.cjs.js +362 -133
- package/dist/react-resizable-panels.development.esm.js +362 -133
- package/dist/react-resizable-panels.development.node.cjs.js +362 -133
- package/dist/react-resizable-panels.development.node.esm.js +362 -133
- package/dist/react-resizable-panels.esm.js +362 -133
- package/dist/react-resizable-panels.node.cjs.js +362 -133
- package/dist/react-resizable-panels.node.esm.js +362 -133
- package/package.json +1 -1
- package/src/PanelGroup.ts +18 -10
- 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
|
@@ -163,6 +163,322 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
163
163
|
PanelWithForwardedRef.displayName = "Panel";
|
|
164
164
|
Panel.displayName = "forwardRef(Panel)";
|
|
165
165
|
|
|
166
|
+
let currentCursorStyle = null;
|
|
167
|
+
let styleElement = null;
|
|
168
|
+
function getCursorStyle(state, constraintFlags) {
|
|
169
|
+
if (constraintFlags) {
|
|
170
|
+
const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
|
|
171
|
+
const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
|
|
172
|
+
const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
|
|
173
|
+
const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
|
|
174
|
+
if (horizontalMin) {
|
|
175
|
+
if (verticalMin) {
|
|
176
|
+
return "se-resize";
|
|
177
|
+
} else if (verticalMax) {
|
|
178
|
+
return "ne-resize";
|
|
179
|
+
} else {
|
|
180
|
+
return "e-resize";
|
|
181
|
+
}
|
|
182
|
+
} else if (horizontalMax) {
|
|
183
|
+
if (verticalMin) {
|
|
184
|
+
return "sw-resize";
|
|
185
|
+
} else if (verticalMax) {
|
|
186
|
+
return "nw-resize";
|
|
187
|
+
} else {
|
|
188
|
+
return "w-resize";
|
|
189
|
+
}
|
|
190
|
+
} else if (verticalMin) {
|
|
191
|
+
return "s-resize";
|
|
192
|
+
} else if (verticalMax) {
|
|
193
|
+
return "n-resize";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
switch (state) {
|
|
197
|
+
case "horizontal":
|
|
198
|
+
return "ew-resize";
|
|
199
|
+
case "intersection":
|
|
200
|
+
return "move";
|
|
201
|
+
case "vertical":
|
|
202
|
+
return "ns-resize";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function resetGlobalCursorStyle() {
|
|
206
|
+
if (styleElement !== null) {
|
|
207
|
+
document.head.removeChild(styleElement);
|
|
208
|
+
currentCursorStyle = null;
|
|
209
|
+
styleElement = null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function setGlobalCursorStyle(state, constraintFlags) {
|
|
213
|
+
const style = getCursorStyle(state, constraintFlags);
|
|
214
|
+
if (currentCursorStyle === style) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
currentCursorStyle = style;
|
|
218
|
+
if (styleElement === null) {
|
|
219
|
+
styleElement = document.createElement("style");
|
|
220
|
+
document.head.appendChild(styleElement);
|
|
221
|
+
}
|
|
222
|
+
styleElement.innerHTML = `*{cursor: ${style}!important;}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function isKeyDown(event) {
|
|
226
|
+
return event.type === "keydown";
|
|
227
|
+
}
|
|
228
|
+
function isMouseEvent(event) {
|
|
229
|
+
return event.type.startsWith("mouse");
|
|
230
|
+
}
|
|
231
|
+
function isTouchEvent(event) {
|
|
232
|
+
return event.type.startsWith("touch");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function getResizeEventCoordinates(event) {
|
|
236
|
+
if (isMouseEvent(event)) {
|
|
237
|
+
return {
|
|
238
|
+
x: event.pageX,
|
|
239
|
+
y: event.pageY
|
|
240
|
+
};
|
|
241
|
+
} else if (isTouchEvent(event)) {
|
|
242
|
+
const touch = event.touches[0];
|
|
243
|
+
if (touch && touch.pageX && touch.pageY) {
|
|
244
|
+
return {
|
|
245
|
+
x: touch.pageX,
|
|
246
|
+
y: touch.pageY
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
x: Infinity,
|
|
252
|
+
y: Infinity
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function getInputType() {
|
|
257
|
+
if (typeof matchMedia === "function") {
|
|
258
|
+
return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
263
|
+
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
264
|
+
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
265
|
+
const EXCEEDED_VERTICAL_MAX = 0b1000;
|
|
266
|
+
const isCoarsePointer = getInputType() === "coarse";
|
|
267
|
+
let intersectingHandles = [];
|
|
268
|
+
let isPointerDown = false;
|
|
269
|
+
let ownerDocumentCounts = new Map();
|
|
270
|
+
let panelConstraintFlags = new Map();
|
|
271
|
+
const registeredResizeHandlers = new Set();
|
|
272
|
+
function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
|
|
273
|
+
var _ownerDocumentCounts$;
|
|
274
|
+
const {
|
|
275
|
+
ownerDocument
|
|
276
|
+
} = element;
|
|
277
|
+
const data = {
|
|
278
|
+
direction,
|
|
279
|
+
element,
|
|
280
|
+
hitAreaMargins,
|
|
281
|
+
setResizeHandlerState
|
|
282
|
+
};
|
|
283
|
+
const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
|
|
284
|
+
ownerDocumentCounts.set(ownerDocument, count + 1);
|
|
285
|
+
registeredResizeHandlers.add(data);
|
|
286
|
+
updateListeners();
|
|
287
|
+
return function unregisterResizeHandle() {
|
|
288
|
+
var _ownerDocumentCounts$2;
|
|
289
|
+
panelConstraintFlags.delete(resizeHandleId);
|
|
290
|
+
registeredResizeHandlers.delete(data);
|
|
291
|
+
const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
|
|
292
|
+
ownerDocumentCounts.set(ownerDocument, count - 1);
|
|
293
|
+
updateListeners();
|
|
294
|
+
if (count === 1) {
|
|
295
|
+
ownerDocumentCounts.delete(ownerDocument);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function handlePointerDown(event) {
|
|
300
|
+
const {
|
|
301
|
+
x,
|
|
302
|
+
y
|
|
303
|
+
} = getResizeEventCoordinates(event);
|
|
304
|
+
isPointerDown = true;
|
|
305
|
+
updateResizeHandlerStates("down", event);
|
|
306
|
+
recalculateIntersectingHandles({
|
|
307
|
+
x,
|
|
308
|
+
y
|
|
309
|
+
});
|
|
310
|
+
updateListeners();
|
|
311
|
+
if (intersectingHandles.length > 0) {
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function handlePointerMove(event) {
|
|
316
|
+
const {
|
|
317
|
+
x,
|
|
318
|
+
y
|
|
319
|
+
} = getResizeEventCoordinates(event);
|
|
320
|
+
if (isPointerDown) {
|
|
321
|
+
intersectingHandles.forEach(data => {
|
|
322
|
+
const {
|
|
323
|
+
setResizeHandlerState
|
|
324
|
+
} = data;
|
|
325
|
+
setResizeHandlerState("move", "drag", event);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Update cursor based on return value(s) from active handles
|
|
329
|
+
updateCursor();
|
|
330
|
+
} else {
|
|
331
|
+
recalculateIntersectingHandles({
|
|
332
|
+
x,
|
|
333
|
+
y
|
|
334
|
+
});
|
|
335
|
+
updateResizeHandlerStates("move", event);
|
|
336
|
+
updateCursor();
|
|
337
|
+
}
|
|
338
|
+
if (intersectingHandles.length > 0) {
|
|
339
|
+
event.preventDefault();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function handlePointerUp(event) {
|
|
343
|
+
const {
|
|
344
|
+
x,
|
|
345
|
+
y
|
|
346
|
+
} = getResizeEventCoordinates(event);
|
|
347
|
+
panelConstraintFlags.clear();
|
|
348
|
+
isPointerDown = false;
|
|
349
|
+
if (intersectingHandles.length > 0) {
|
|
350
|
+
event.preventDefault();
|
|
351
|
+
}
|
|
352
|
+
recalculateIntersectingHandles({
|
|
353
|
+
x,
|
|
354
|
+
y
|
|
355
|
+
});
|
|
356
|
+
updateResizeHandlerStates("up", event);
|
|
357
|
+
updateCursor();
|
|
358
|
+
updateListeners();
|
|
359
|
+
}
|
|
360
|
+
function recalculateIntersectingHandles({
|
|
361
|
+
x,
|
|
362
|
+
y
|
|
363
|
+
}) {
|
|
364
|
+
intersectingHandles.splice(0);
|
|
365
|
+
registeredResizeHandlers.forEach(data => {
|
|
366
|
+
const {
|
|
367
|
+
element,
|
|
368
|
+
hitAreaMargins
|
|
369
|
+
} = data;
|
|
370
|
+
const {
|
|
371
|
+
bottom,
|
|
372
|
+
left,
|
|
373
|
+
right,
|
|
374
|
+
top
|
|
375
|
+
} = element.getBoundingClientRect();
|
|
376
|
+
const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
|
|
377
|
+
const intersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
|
|
378
|
+
if (intersects) {
|
|
379
|
+
intersectingHandles.push(data);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function reportConstraintsViolation(resizeHandleId, flag) {
|
|
384
|
+
panelConstraintFlags.set(resizeHandleId, flag);
|
|
385
|
+
}
|
|
386
|
+
function updateCursor() {
|
|
387
|
+
let intersectsHorizontal = false;
|
|
388
|
+
let intersectsVertical = false;
|
|
389
|
+
intersectingHandles.forEach(data => {
|
|
390
|
+
const {
|
|
391
|
+
direction
|
|
392
|
+
} = data;
|
|
393
|
+
if (direction === "horizontal") {
|
|
394
|
+
intersectsHorizontal = true;
|
|
395
|
+
} else {
|
|
396
|
+
intersectsVertical = true;
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
let constraintFlags = 0;
|
|
400
|
+
panelConstraintFlags.forEach(flag => {
|
|
401
|
+
constraintFlags |= flag;
|
|
402
|
+
});
|
|
403
|
+
if (intersectsHorizontal && intersectsVertical) {
|
|
404
|
+
setGlobalCursorStyle("intersection", constraintFlags);
|
|
405
|
+
} else if (intersectsHorizontal) {
|
|
406
|
+
setGlobalCursorStyle("horizontal", constraintFlags);
|
|
407
|
+
} else if (intersectsVertical) {
|
|
408
|
+
setGlobalCursorStyle("vertical", constraintFlags);
|
|
409
|
+
} else {
|
|
410
|
+
resetGlobalCursorStyle();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function updateListeners() {
|
|
414
|
+
ownerDocumentCounts.forEach((_, ownerDocument) => {
|
|
415
|
+
const {
|
|
416
|
+
body
|
|
417
|
+
} = ownerDocument;
|
|
418
|
+
body.removeEventListener("contextmenu", handlePointerUp);
|
|
419
|
+
body.removeEventListener("mousedown", handlePointerDown);
|
|
420
|
+
body.removeEventListener("mouseleave", handlePointerMove);
|
|
421
|
+
body.removeEventListener("mousemove", handlePointerMove);
|
|
422
|
+
body.removeEventListener("touchmove", handlePointerMove);
|
|
423
|
+
body.removeEventListener("touchstart", handlePointerDown);
|
|
424
|
+
});
|
|
425
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
426
|
+
window.removeEventListener("touchcancel", handlePointerUp);
|
|
427
|
+
window.removeEventListener("touchend", handlePointerUp);
|
|
428
|
+
if (registerResizeHandle.length > 0) {
|
|
429
|
+
if (isPointerDown) {
|
|
430
|
+
if (intersectingHandles.length > 0) {
|
|
431
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
432
|
+
const {
|
|
433
|
+
body
|
|
434
|
+
} = ownerDocument;
|
|
435
|
+
if (count > 0) {
|
|
436
|
+
body.addEventListener("contextmenu", handlePointerUp);
|
|
437
|
+
body.addEventListener("mouseleave", handlePointerMove);
|
|
438
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
439
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
440
|
+
passive: false
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
446
|
+
window.addEventListener("touchcancel", handlePointerUp);
|
|
447
|
+
window.addEventListener("touchend", handlePointerUp);
|
|
448
|
+
} else {
|
|
449
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
450
|
+
const {
|
|
451
|
+
body
|
|
452
|
+
} = ownerDocument;
|
|
453
|
+
if (count > 0) {
|
|
454
|
+
body.addEventListener("mousedown", handlePointerDown);
|
|
455
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
456
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
457
|
+
passive: false
|
|
458
|
+
});
|
|
459
|
+
body.addEventListener("touchstart", handlePointerDown);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function updateResizeHandlerStates(action, event) {
|
|
466
|
+
registeredResizeHandlers.forEach(data => {
|
|
467
|
+
const {
|
|
468
|
+
setResizeHandlerState
|
|
469
|
+
} = data;
|
|
470
|
+
if (intersectingHandles.includes(data)) {
|
|
471
|
+
if (isPointerDown) {
|
|
472
|
+
setResizeHandlerState(action, "drag", event);
|
|
473
|
+
} else {
|
|
474
|
+
setResizeHandlerState(action, "hover", event);
|
|
475
|
+
}
|
|
476
|
+
} else {
|
|
477
|
+
setResizeHandlerState(action, "inactive", event);
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
166
482
|
function assert(expectedCondition, message = "Assertion failed!") {
|
|
167
483
|
if (!expectedCondition) {
|
|
168
484
|
console.error(message);
|
|
@@ -595,27 +911,13 @@ function areEqual(arrayA, arrayB) {
|
|
|
595
911
|
return true;
|
|
596
912
|
}
|
|
597
913
|
|
|
598
|
-
function isKeyDown(event) {
|
|
599
|
-
return event.type === "keydown";
|
|
600
|
-
}
|
|
601
|
-
function isMouseEvent(event) {
|
|
602
|
-
return event.type.startsWith("mouse");
|
|
603
|
-
}
|
|
604
|
-
function isTouchEvent(event) {
|
|
605
|
-
return event.type.startsWith("touch");
|
|
606
|
-
}
|
|
607
|
-
|
|
608
914
|
function getResizeEventCursorPosition(direction, event) {
|
|
609
915
|
const isHorizontal = direction === "horizontal";
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
616
|
-
} else {
|
|
617
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
618
|
-
}
|
|
916
|
+
const {
|
|
917
|
+
x,
|
|
918
|
+
y
|
|
919
|
+
} = getResizeEventCoordinates(event);
|
|
920
|
+
return isHorizontal ? x : y;
|
|
619
921
|
}
|
|
620
922
|
|
|
621
923
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
@@ -764,44 +1066,6 @@ function computePanelFlexBoxStyle({
|
|
|
764
1066
|
};
|
|
765
1067
|
}
|
|
766
1068
|
|
|
767
|
-
let currentState = null;
|
|
768
|
-
let element = null;
|
|
769
|
-
function getCursorStyle(state) {
|
|
770
|
-
switch (state) {
|
|
771
|
-
case "horizontal":
|
|
772
|
-
return "ew-resize";
|
|
773
|
-
case "horizontal-max":
|
|
774
|
-
return "w-resize";
|
|
775
|
-
case "horizontal-min":
|
|
776
|
-
return "e-resize";
|
|
777
|
-
case "vertical":
|
|
778
|
-
return "ns-resize";
|
|
779
|
-
case "vertical-max":
|
|
780
|
-
return "n-resize";
|
|
781
|
-
case "vertical-min":
|
|
782
|
-
return "s-resize";
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
function resetGlobalCursorStyle() {
|
|
786
|
-
if (element !== null) {
|
|
787
|
-
document.head.removeChild(element);
|
|
788
|
-
currentState = null;
|
|
789
|
-
element = null;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function setGlobalCursorStyle(state) {
|
|
793
|
-
if (currentState === state) {
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
currentState = state;
|
|
797
|
-
const style = getCursorStyle(state);
|
|
798
|
-
if (element === null) {
|
|
799
|
-
element = document.createElement("style");
|
|
800
|
-
document.head.appendChild(element);
|
|
801
|
-
}
|
|
802
|
-
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
1069
|
function debounce(callback, durationMs = 10) {
|
|
806
1070
|
let timeoutId = null;
|
|
807
1071
|
let callable = (...args) => {
|
|
@@ -1285,18 +1549,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1285
1549
|
if (prevDeltaRef.current != delta) {
|
|
1286
1550
|
prevDeltaRef.current = delta;
|
|
1287
1551
|
if (!layoutChanged) {
|
|
1288
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
1289
|
-
// update the cursor style for a visual clue.
|
|
1552
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
1290
1553
|
// This mimics VS Code behavior.
|
|
1291
|
-
|
|
1292
1554
|
if (isHorizontal) {
|
|
1293
|
-
|
|
1555
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
|
|
1294
1556
|
} else {
|
|
1295
|
-
|
|
1557
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
|
|
1296
1558
|
}
|
|
1297
1559
|
} else {
|
|
1298
|
-
|
|
1299
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1560
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
1300
1561
|
}
|
|
1301
1562
|
}
|
|
1302
1563
|
}
|
|
@@ -1394,7 +1655,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1394
1655
|
});
|
|
1395
1656
|
}, []);
|
|
1396
1657
|
const stopDragging = useCallback(() => {
|
|
1397
|
-
resetGlobalCursorStyle();
|
|
1398
1658
|
setDragState(null);
|
|
1399
1659
|
}, []);
|
|
1400
1660
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1535,6 +1795,7 @@ function PanelResizeHandle({
|
|
|
1535
1795
|
children = null,
|
|
1536
1796
|
className: classNameFromProps = "",
|
|
1537
1797
|
disabled = false,
|
|
1798
|
+
hitAreaMargins,
|
|
1538
1799
|
id: idFromProps,
|
|
1539
1800
|
onDragging,
|
|
1540
1801
|
style: styleFromProps = {},
|
|
@@ -1557,67 +1818,60 @@ function PanelResizeHandle({
|
|
|
1557
1818
|
}
|
|
1558
1819
|
const {
|
|
1559
1820
|
direction,
|
|
1560
|
-
dragState,
|
|
1561
1821
|
groupId,
|
|
1562
|
-
registerResizeHandle,
|
|
1822
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1563
1823
|
startDragging,
|
|
1564
1824
|
stopDragging,
|
|
1565
1825
|
panelGroupElement
|
|
1566
1826
|
} = panelGroupContext;
|
|
1567
1827
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1568
|
-
const
|
|
1828
|
+
const [state, setState] = useState("inactive");
|
|
1569
1829
|
const [isFocused, setIsFocused] = useState(false);
|
|
1570
1830
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1571
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1572
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1573
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1574
|
-
const element = elementRef.current;
|
|
1575
|
-
assert(element);
|
|
1576
|
-
element.blur();
|
|
1577
|
-
stopDragging();
|
|
1578
|
-
const {
|
|
1579
|
-
onDragging
|
|
1580
|
-
} = callbacksRef.current;
|
|
1581
|
-
if (onDragging) {
|
|
1582
|
-
onDragging(false);
|
|
1583
|
-
}
|
|
1584
|
-
}, [stopDragging]);
|
|
1585
1831
|
useEffect(() => {
|
|
1586
1832
|
if (disabled) {
|
|
1587
1833
|
setResizeHandler(null);
|
|
1588
1834
|
} else {
|
|
1589
|
-
const resizeHandler =
|
|
1835
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1590
1836
|
setResizeHandler(() => resizeHandler);
|
|
1591
1837
|
}
|
|
1592
|
-
}, [disabled, resizeHandleId,
|
|
1838
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1593
1839
|
useEffect(() => {
|
|
1594
|
-
|
|
1840
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
1841
|
+
if (disabled || resizeHandler == null) {
|
|
1595
1842
|
return;
|
|
1596
1843
|
}
|
|
1597
|
-
const onMove = event => {
|
|
1598
|
-
resizeHandler(event);
|
|
1599
|
-
};
|
|
1600
|
-
const onMouseLeave = event => {
|
|
1601
|
-
resizeHandler(event);
|
|
1602
|
-
};
|
|
1603
1844
|
const element = elementRef.current;
|
|
1604
1845
|
assert(element);
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1846
|
+
const setResizeHandlerState = (action, state, event) => {
|
|
1847
|
+
setState(state);
|
|
1848
|
+
switch (action) {
|
|
1849
|
+
case "down":
|
|
1850
|
+
{
|
|
1851
|
+
startDragging(resizeHandleId, event);
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
case "up":
|
|
1855
|
+
{
|
|
1856
|
+
stopDragging();
|
|
1857
|
+
break;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
switch (state) {
|
|
1861
|
+
case "drag":
|
|
1862
|
+
{
|
|
1863
|
+
resizeHandler(event);
|
|
1864
|
+
break;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1619
1867
|
};
|
|
1620
|
-
|
|
1868
|
+
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
1869
|
+
// Coarse inputs (e.g. finger/touch)
|
|
1870
|
+
coarse: (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15,
|
|
1871
|
+
// Fine inputs (e.g. mouse)
|
|
1872
|
+
fine: (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5
|
|
1873
|
+
}, setResizeHandlerState);
|
|
1874
|
+
}, [direction, disabled, hitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
|
|
1621
1875
|
useWindowSplitterResizeHandlerBehavior({
|
|
1622
1876
|
disabled,
|
|
1623
1877
|
handleId: resizeHandleId,
|
|
@@ -1625,7 +1879,6 @@ function PanelResizeHandle({
|
|
|
1625
1879
|
panelGroupElement
|
|
1626
1880
|
});
|
|
1627
1881
|
const style = {
|
|
1628
|
-
cursor: getCursorStyle(direction),
|
|
1629
1882
|
touchAction: "none",
|
|
1630
1883
|
userSelect: "none"
|
|
1631
1884
|
};
|
|
@@ -1635,31 +1888,6 @@ function PanelResizeHandle({
|
|
|
1635
1888
|
className: classNameFromProps,
|
|
1636
1889
|
onBlur: () => setIsFocused(false),
|
|
1637
1890
|
onFocus: () => setIsFocused(true),
|
|
1638
|
-
onMouseDown: event => {
|
|
1639
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1640
|
-
const callbacks = callbacksRef.current;
|
|
1641
|
-
assert(callbacks);
|
|
1642
|
-
const {
|
|
1643
|
-
onDragging
|
|
1644
|
-
} = callbacks;
|
|
1645
|
-
if (onDragging) {
|
|
1646
|
-
onDragging(true);
|
|
1647
|
-
}
|
|
1648
|
-
},
|
|
1649
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1650
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1651
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1652
|
-
onTouchStart: event => {
|
|
1653
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1654
|
-
const callbacks = callbacksRef.current;
|
|
1655
|
-
assert(callbacks);
|
|
1656
|
-
const {
|
|
1657
|
-
onDragging
|
|
1658
|
-
} = callbacks;
|
|
1659
|
-
if (onDragging) {
|
|
1660
|
-
onDragging(true);
|
|
1661
|
-
}
|
|
1662
|
-
},
|
|
1663
1891
|
ref: elementRef,
|
|
1664
1892
|
role: "separator",
|
|
1665
1893
|
style: {
|
|
@@ -1671,7 +1899,8 @@ function PanelResizeHandle({
|
|
|
1671
1899
|
"data-panel-group-direction": direction,
|
|
1672
1900
|
"data-panel-group-id": groupId,
|
|
1673
1901
|
"data-resize-handle": "",
|
|
1674
|
-
"data-resize-handle-active":
|
|
1902
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
1903
|
+
"data-resize-handle-state": state,
|
|
1675
1904
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1676
1905
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1677
1906
|
});
|