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
|
@@ -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
|
}
|
|
@@ -1351,15 +1612,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1351
1612
|
} = eagerValuesRef.current;
|
|
1352
1613
|
const {
|
|
1353
1614
|
collapsedSize: prevCollapsedSize = 0,
|
|
1354
|
-
collapsible: prevCollapsible
|
|
1355
|
-
defaultSize: prevDefaultSize,
|
|
1356
|
-
maxSize: prevMaxSize = 100,
|
|
1357
|
-
minSize: prevMinSize = 0
|
|
1615
|
+
collapsible: prevCollapsible
|
|
1358
1616
|
} = prevConstraints;
|
|
1359
1617
|
const {
|
|
1360
1618
|
collapsedSize: nextCollapsedSize = 0,
|
|
1361
1619
|
collapsible: nextCollapsible,
|
|
1362
|
-
defaultSize: nextDefaultSize,
|
|
1363
1620
|
maxSize: nextMaxSize = 100,
|
|
1364
1621
|
minSize: nextMinSize = 0
|
|
1365
1622
|
} = panelData.constraints;
|
|
@@ -1367,8 +1624,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1367
1624
|
panelSize: prevPanelSize
|
|
1368
1625
|
} = panelDataHelper(panelDataArray, panelData, layout);
|
|
1369
1626
|
assert(prevPanelSize != null);
|
|
1370
|
-
if (prevCollapsible && nextCollapsible &&
|
|
1371
|
-
|
|
1627
|
+
if (prevCollapsible && nextCollapsible && prevPanelSize === prevCollapsedSize) {
|
|
1628
|
+
if (prevCollapsedSize !== nextCollapsedSize) {
|
|
1629
|
+
resizePanel(panelData, nextCollapsedSize);
|
|
1630
|
+
}
|
|
1372
1631
|
} else if (prevPanelSize < nextMinSize) {
|
|
1373
1632
|
resizePanel(panelData, nextMinSize);
|
|
1374
1633
|
} else if (prevPanelSize > nextMaxSize) {
|
|
@@ -1396,7 +1655,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1396
1655
|
});
|
|
1397
1656
|
}, []);
|
|
1398
1657
|
const stopDragging = useCallback(() => {
|
|
1399
|
-
resetGlobalCursorStyle();
|
|
1400
1658
|
setDragState(null);
|
|
1401
1659
|
}, []);
|
|
1402
1660
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1537,6 +1795,7 @@ function PanelResizeHandle({
|
|
|
1537
1795
|
children = null,
|
|
1538
1796
|
className: classNameFromProps = "",
|
|
1539
1797
|
disabled = false,
|
|
1798
|
+
hitAreaMargins,
|
|
1540
1799
|
id: idFromProps,
|
|
1541
1800
|
onDragging,
|
|
1542
1801
|
style: styleFromProps = {},
|
|
@@ -1559,67 +1818,60 @@ function PanelResizeHandle({
|
|
|
1559
1818
|
}
|
|
1560
1819
|
const {
|
|
1561
1820
|
direction,
|
|
1562
|
-
dragState,
|
|
1563
1821
|
groupId,
|
|
1564
|
-
registerResizeHandle,
|
|
1822
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1565
1823
|
startDragging,
|
|
1566
1824
|
stopDragging,
|
|
1567
1825
|
panelGroupElement
|
|
1568
1826
|
} = panelGroupContext;
|
|
1569
1827
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1570
|
-
const
|
|
1828
|
+
const [state, setState] = useState("inactive");
|
|
1571
1829
|
const [isFocused, setIsFocused] = useState(false);
|
|
1572
1830
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1573
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1574
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1575
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1576
|
-
const element = elementRef.current;
|
|
1577
|
-
assert(element);
|
|
1578
|
-
element.blur();
|
|
1579
|
-
stopDragging();
|
|
1580
|
-
const {
|
|
1581
|
-
onDragging
|
|
1582
|
-
} = callbacksRef.current;
|
|
1583
|
-
if (onDragging) {
|
|
1584
|
-
onDragging(false);
|
|
1585
|
-
}
|
|
1586
|
-
}, [stopDragging]);
|
|
1587
1831
|
useEffect(() => {
|
|
1588
1832
|
if (disabled) {
|
|
1589
1833
|
setResizeHandler(null);
|
|
1590
1834
|
} else {
|
|
1591
|
-
const resizeHandler =
|
|
1835
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1592
1836
|
setResizeHandler(() => resizeHandler);
|
|
1593
1837
|
}
|
|
1594
|
-
}, [disabled, resizeHandleId,
|
|
1838
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1595
1839
|
useEffect(() => {
|
|
1596
|
-
|
|
1840
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
1841
|
+
if (disabled || resizeHandler == null) {
|
|
1597
1842
|
return;
|
|
1598
1843
|
}
|
|
1599
|
-
const onMove = event => {
|
|
1600
|
-
resizeHandler(event);
|
|
1601
|
-
};
|
|
1602
|
-
const onMouseLeave = event => {
|
|
1603
|
-
resizeHandler(event);
|
|
1604
|
-
};
|
|
1605
1844
|
const element = elementRef.current;
|
|
1606
1845
|
assert(element);
|
|
1607
|
-
const
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
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
|
+
}
|
|
1621
1867
|
};
|
|
1622
|
-
|
|
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]);
|
|
1623
1875
|
useWindowSplitterResizeHandlerBehavior({
|
|
1624
1876
|
disabled,
|
|
1625
1877
|
handleId: resizeHandleId,
|
|
@@ -1627,7 +1879,6 @@ function PanelResizeHandle({
|
|
|
1627
1879
|
panelGroupElement
|
|
1628
1880
|
});
|
|
1629
1881
|
const style = {
|
|
1630
|
-
cursor: getCursorStyle(direction),
|
|
1631
1882
|
touchAction: "none",
|
|
1632
1883
|
userSelect: "none"
|
|
1633
1884
|
};
|
|
@@ -1637,31 +1888,6 @@ function PanelResizeHandle({
|
|
|
1637
1888
|
className: classNameFromProps,
|
|
1638
1889
|
onBlur: () => setIsFocused(false),
|
|
1639
1890
|
onFocus: () => setIsFocused(true),
|
|
1640
|
-
onMouseDown: event => {
|
|
1641
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1642
|
-
const callbacks = callbacksRef.current;
|
|
1643
|
-
assert(callbacks);
|
|
1644
|
-
const {
|
|
1645
|
-
onDragging
|
|
1646
|
-
} = callbacks;
|
|
1647
|
-
if (onDragging) {
|
|
1648
|
-
onDragging(true);
|
|
1649
|
-
}
|
|
1650
|
-
},
|
|
1651
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1652
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1653
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1654
|
-
onTouchStart: event => {
|
|
1655
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1656
|
-
const callbacks = callbacksRef.current;
|
|
1657
|
-
assert(callbacks);
|
|
1658
|
-
const {
|
|
1659
|
-
onDragging
|
|
1660
|
-
} = callbacks;
|
|
1661
|
-
if (onDragging) {
|
|
1662
|
-
onDragging(true);
|
|
1663
|
-
}
|
|
1664
|
-
},
|
|
1665
1891
|
ref: elementRef,
|
|
1666
1892
|
role: "separator",
|
|
1667
1893
|
style: {
|
|
@@ -1673,7 +1899,8 @@ function PanelResizeHandle({
|
|
|
1673
1899
|
"data-panel-group-direction": direction,
|
|
1674
1900
|
"data-panel-group-id": groupId,
|
|
1675
1901
|
"data-resize-handle": "",
|
|
1676
|
-
"data-resize-handle-active":
|
|
1902
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
1903
|
+
"data-resize-handle-state": state,
|
|
1677
1904
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1678
1905
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1679
1906
|
});
|