react-resizable-panels 1.0.10 → 2.0.1
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 +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
|
@@ -139,6 +139,322 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
|
|
|
139
139
|
PanelWithForwardedRef.displayName = "Panel";
|
|
140
140
|
Panel.displayName = "forwardRef(Panel)";
|
|
141
141
|
|
|
142
|
+
let currentCursorStyle = null;
|
|
143
|
+
let styleElement = null;
|
|
144
|
+
function getCursorStyle(state, constraintFlags) {
|
|
145
|
+
if (constraintFlags) {
|
|
146
|
+
const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
|
|
147
|
+
const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
|
|
148
|
+
const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
|
|
149
|
+
const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
|
|
150
|
+
if (horizontalMin) {
|
|
151
|
+
if (verticalMin) {
|
|
152
|
+
return "se-resize";
|
|
153
|
+
} else if (verticalMax) {
|
|
154
|
+
return "ne-resize";
|
|
155
|
+
} else {
|
|
156
|
+
return "e-resize";
|
|
157
|
+
}
|
|
158
|
+
} else if (horizontalMax) {
|
|
159
|
+
if (verticalMin) {
|
|
160
|
+
return "sw-resize";
|
|
161
|
+
} else if (verticalMax) {
|
|
162
|
+
return "nw-resize";
|
|
163
|
+
} else {
|
|
164
|
+
return "w-resize";
|
|
165
|
+
}
|
|
166
|
+
} else if (verticalMin) {
|
|
167
|
+
return "s-resize";
|
|
168
|
+
} else if (verticalMax) {
|
|
169
|
+
return "n-resize";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
switch (state) {
|
|
173
|
+
case "horizontal":
|
|
174
|
+
return "ew-resize";
|
|
175
|
+
case "intersection":
|
|
176
|
+
return "move";
|
|
177
|
+
case "vertical":
|
|
178
|
+
return "ns-resize";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function resetGlobalCursorStyle() {
|
|
182
|
+
if (styleElement !== null) {
|
|
183
|
+
document.head.removeChild(styleElement);
|
|
184
|
+
currentCursorStyle = null;
|
|
185
|
+
styleElement = null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function setGlobalCursorStyle(state, constraintFlags) {
|
|
189
|
+
const style = getCursorStyle(state, constraintFlags);
|
|
190
|
+
if (currentCursorStyle === style) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
currentCursorStyle = style;
|
|
194
|
+
if (styleElement === null) {
|
|
195
|
+
styleElement = document.createElement("style");
|
|
196
|
+
document.head.appendChild(styleElement);
|
|
197
|
+
}
|
|
198
|
+
styleElement.innerHTML = `*{cursor: ${style}!important;}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function isKeyDown(event) {
|
|
202
|
+
return event.type === "keydown";
|
|
203
|
+
}
|
|
204
|
+
function isMouseEvent(event) {
|
|
205
|
+
return event.type.startsWith("mouse");
|
|
206
|
+
}
|
|
207
|
+
function isTouchEvent(event) {
|
|
208
|
+
return event.type.startsWith("touch");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getResizeEventCoordinates(event) {
|
|
212
|
+
if (isMouseEvent(event)) {
|
|
213
|
+
return {
|
|
214
|
+
x: event.pageX,
|
|
215
|
+
y: event.pageY
|
|
216
|
+
};
|
|
217
|
+
} else if (isTouchEvent(event)) {
|
|
218
|
+
const touch = event.touches[0];
|
|
219
|
+
if (touch && touch.pageX && touch.pageY) {
|
|
220
|
+
return {
|
|
221
|
+
x: touch.pageX,
|
|
222
|
+
y: touch.pageY
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
x: Infinity,
|
|
228
|
+
y: Infinity
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function getInputType() {
|
|
233
|
+
if (typeof matchMedia === "function") {
|
|
234
|
+
return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const EXCEEDED_HORIZONTAL_MIN = 0b0001;
|
|
239
|
+
const EXCEEDED_HORIZONTAL_MAX = 0b0010;
|
|
240
|
+
const EXCEEDED_VERTICAL_MIN = 0b0100;
|
|
241
|
+
const EXCEEDED_VERTICAL_MAX = 0b1000;
|
|
242
|
+
const isCoarsePointer = getInputType() === "coarse";
|
|
243
|
+
let intersectingHandles = [];
|
|
244
|
+
let isPointerDown = false;
|
|
245
|
+
let ownerDocumentCounts = new Map();
|
|
246
|
+
let panelConstraintFlags = new Map();
|
|
247
|
+
const registeredResizeHandlers = new Set();
|
|
248
|
+
function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins, setResizeHandlerState) {
|
|
249
|
+
var _ownerDocumentCounts$;
|
|
250
|
+
const {
|
|
251
|
+
ownerDocument
|
|
252
|
+
} = element;
|
|
253
|
+
const data = {
|
|
254
|
+
direction,
|
|
255
|
+
element,
|
|
256
|
+
hitAreaMargins,
|
|
257
|
+
setResizeHandlerState
|
|
258
|
+
};
|
|
259
|
+
const count = (_ownerDocumentCounts$ = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$ !== void 0 ? _ownerDocumentCounts$ : 0;
|
|
260
|
+
ownerDocumentCounts.set(ownerDocument, count + 1);
|
|
261
|
+
registeredResizeHandlers.add(data);
|
|
262
|
+
updateListeners();
|
|
263
|
+
return function unregisterResizeHandle() {
|
|
264
|
+
var _ownerDocumentCounts$2;
|
|
265
|
+
panelConstraintFlags.delete(resizeHandleId);
|
|
266
|
+
registeredResizeHandlers.delete(data);
|
|
267
|
+
const count = (_ownerDocumentCounts$2 = ownerDocumentCounts.get(ownerDocument)) !== null && _ownerDocumentCounts$2 !== void 0 ? _ownerDocumentCounts$2 : 1;
|
|
268
|
+
ownerDocumentCounts.set(ownerDocument, count - 1);
|
|
269
|
+
updateListeners();
|
|
270
|
+
if (count === 1) {
|
|
271
|
+
ownerDocumentCounts.delete(ownerDocument);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function handlePointerDown(event) {
|
|
276
|
+
const {
|
|
277
|
+
x,
|
|
278
|
+
y
|
|
279
|
+
} = getResizeEventCoordinates(event);
|
|
280
|
+
isPointerDown = true;
|
|
281
|
+
recalculateIntersectingHandles({
|
|
282
|
+
x,
|
|
283
|
+
y
|
|
284
|
+
});
|
|
285
|
+
updateListeners();
|
|
286
|
+
if (intersectingHandles.length > 0) {
|
|
287
|
+
updateResizeHandlerStates("down", event);
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function handlePointerMove(event) {
|
|
292
|
+
const {
|
|
293
|
+
x,
|
|
294
|
+
y
|
|
295
|
+
} = getResizeEventCoordinates(event);
|
|
296
|
+
if (isPointerDown) {
|
|
297
|
+
intersectingHandles.forEach(data => {
|
|
298
|
+
const {
|
|
299
|
+
setResizeHandlerState
|
|
300
|
+
} = data;
|
|
301
|
+
setResizeHandlerState("move", "drag", event);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// Update cursor based on return value(s) from active handles
|
|
305
|
+
updateCursor();
|
|
306
|
+
} else {
|
|
307
|
+
recalculateIntersectingHandles({
|
|
308
|
+
x,
|
|
309
|
+
y
|
|
310
|
+
});
|
|
311
|
+
updateResizeHandlerStates("move", event);
|
|
312
|
+
updateCursor();
|
|
313
|
+
}
|
|
314
|
+
if (intersectingHandles.length > 0) {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function handlePointerUp(event) {
|
|
319
|
+
const {
|
|
320
|
+
x,
|
|
321
|
+
y
|
|
322
|
+
} = getResizeEventCoordinates(event);
|
|
323
|
+
panelConstraintFlags.clear();
|
|
324
|
+
isPointerDown = false;
|
|
325
|
+
if (intersectingHandles.length > 0) {
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
}
|
|
328
|
+
recalculateIntersectingHandles({
|
|
329
|
+
x,
|
|
330
|
+
y
|
|
331
|
+
});
|
|
332
|
+
updateResizeHandlerStates("up", event);
|
|
333
|
+
updateCursor();
|
|
334
|
+
updateListeners();
|
|
335
|
+
}
|
|
336
|
+
function recalculateIntersectingHandles({
|
|
337
|
+
x,
|
|
338
|
+
y
|
|
339
|
+
}) {
|
|
340
|
+
intersectingHandles.splice(0);
|
|
341
|
+
registeredResizeHandlers.forEach(data => {
|
|
342
|
+
const {
|
|
343
|
+
element,
|
|
344
|
+
hitAreaMargins
|
|
345
|
+
} = data;
|
|
346
|
+
const {
|
|
347
|
+
bottom,
|
|
348
|
+
left,
|
|
349
|
+
right,
|
|
350
|
+
top
|
|
351
|
+
} = element.getBoundingClientRect();
|
|
352
|
+
const margin = isCoarsePointer ? hitAreaMargins.coarse : hitAreaMargins.fine;
|
|
353
|
+
const intersects = x >= left - margin && x <= right + margin && y >= top - margin && y <= bottom + margin;
|
|
354
|
+
if (intersects) {
|
|
355
|
+
intersectingHandles.push(data);
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
function reportConstraintsViolation(resizeHandleId, flag) {
|
|
360
|
+
panelConstraintFlags.set(resizeHandleId, flag);
|
|
361
|
+
}
|
|
362
|
+
function updateCursor() {
|
|
363
|
+
let intersectsHorizontal = false;
|
|
364
|
+
let intersectsVertical = false;
|
|
365
|
+
intersectingHandles.forEach(data => {
|
|
366
|
+
const {
|
|
367
|
+
direction
|
|
368
|
+
} = data;
|
|
369
|
+
if (direction === "horizontal") {
|
|
370
|
+
intersectsHorizontal = true;
|
|
371
|
+
} else {
|
|
372
|
+
intersectsVertical = true;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
let constraintFlags = 0;
|
|
376
|
+
panelConstraintFlags.forEach(flag => {
|
|
377
|
+
constraintFlags |= flag;
|
|
378
|
+
});
|
|
379
|
+
if (intersectsHorizontal && intersectsVertical) {
|
|
380
|
+
setGlobalCursorStyle("intersection", constraintFlags);
|
|
381
|
+
} else if (intersectsHorizontal) {
|
|
382
|
+
setGlobalCursorStyle("horizontal", constraintFlags);
|
|
383
|
+
} else if (intersectsVertical) {
|
|
384
|
+
setGlobalCursorStyle("vertical", constraintFlags);
|
|
385
|
+
} else {
|
|
386
|
+
resetGlobalCursorStyle();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function updateListeners() {
|
|
390
|
+
ownerDocumentCounts.forEach((_, ownerDocument) => {
|
|
391
|
+
const {
|
|
392
|
+
body
|
|
393
|
+
} = ownerDocument;
|
|
394
|
+
body.removeEventListener("contextmenu", handlePointerUp);
|
|
395
|
+
body.removeEventListener("mousedown", handlePointerDown);
|
|
396
|
+
body.removeEventListener("mouseleave", handlePointerMove);
|
|
397
|
+
body.removeEventListener("mousemove", handlePointerMove);
|
|
398
|
+
body.removeEventListener("touchmove", handlePointerMove);
|
|
399
|
+
body.removeEventListener("touchstart", handlePointerDown);
|
|
400
|
+
});
|
|
401
|
+
window.removeEventListener("mouseup", handlePointerUp);
|
|
402
|
+
window.removeEventListener("touchcancel", handlePointerUp);
|
|
403
|
+
window.removeEventListener("touchend", handlePointerUp);
|
|
404
|
+
if (registerResizeHandle.length > 0) {
|
|
405
|
+
if (isPointerDown) {
|
|
406
|
+
if (intersectingHandles.length > 0) {
|
|
407
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
408
|
+
const {
|
|
409
|
+
body
|
|
410
|
+
} = ownerDocument;
|
|
411
|
+
if (count > 0) {
|
|
412
|
+
body.addEventListener("contextmenu", handlePointerUp);
|
|
413
|
+
body.addEventListener("mouseleave", handlePointerMove);
|
|
414
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
415
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
416
|
+
passive: false
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
window.addEventListener("mouseup", handlePointerUp);
|
|
422
|
+
window.addEventListener("touchcancel", handlePointerUp);
|
|
423
|
+
window.addEventListener("touchend", handlePointerUp);
|
|
424
|
+
} else {
|
|
425
|
+
ownerDocumentCounts.forEach((count, ownerDocument) => {
|
|
426
|
+
const {
|
|
427
|
+
body
|
|
428
|
+
} = ownerDocument;
|
|
429
|
+
if (count > 0) {
|
|
430
|
+
body.addEventListener("mousedown", handlePointerDown);
|
|
431
|
+
body.addEventListener("mousemove", handlePointerMove);
|
|
432
|
+
body.addEventListener("touchmove", handlePointerMove, {
|
|
433
|
+
passive: false
|
|
434
|
+
});
|
|
435
|
+
body.addEventListener("touchstart", handlePointerDown);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
function updateResizeHandlerStates(action, event) {
|
|
442
|
+
registeredResizeHandlers.forEach(data => {
|
|
443
|
+
const {
|
|
444
|
+
setResizeHandlerState
|
|
445
|
+
} = data;
|
|
446
|
+
if (intersectingHandles.includes(data)) {
|
|
447
|
+
if (isPointerDown) {
|
|
448
|
+
setResizeHandlerState(action, "drag", event);
|
|
449
|
+
} else {
|
|
450
|
+
setResizeHandlerState(action, "hover", event);
|
|
451
|
+
}
|
|
452
|
+
} else {
|
|
453
|
+
setResizeHandlerState(action, "inactive", event);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
142
458
|
function assert(expectedCondition, message = "Assertion failed!") {
|
|
143
459
|
if (!expectedCondition) {
|
|
144
460
|
console.error(message);
|
|
@@ -571,27 +887,13 @@ function areEqual(arrayA, arrayB) {
|
|
|
571
887
|
return true;
|
|
572
888
|
}
|
|
573
889
|
|
|
574
|
-
function isKeyDown(event) {
|
|
575
|
-
return event.type === "keydown";
|
|
576
|
-
}
|
|
577
|
-
function isMouseEvent(event) {
|
|
578
|
-
return event.type.startsWith("mouse");
|
|
579
|
-
}
|
|
580
|
-
function isTouchEvent(event) {
|
|
581
|
-
return event.type.startsWith("touch");
|
|
582
|
-
}
|
|
583
|
-
|
|
584
890
|
function getResizeEventCursorPosition(direction, event) {
|
|
585
891
|
const isHorizontal = direction === "horizontal";
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
592
|
-
} else {
|
|
593
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
594
|
-
}
|
|
892
|
+
const {
|
|
893
|
+
x,
|
|
894
|
+
y
|
|
895
|
+
} = getResizeEventCoordinates(event);
|
|
896
|
+
return isHorizontal ? x : y;
|
|
595
897
|
}
|
|
596
898
|
|
|
597
899
|
function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDragState, panelGroupElement) {
|
|
@@ -740,44 +1042,6 @@ function computePanelFlexBoxStyle({
|
|
|
740
1042
|
};
|
|
741
1043
|
}
|
|
742
1044
|
|
|
743
|
-
let currentState = null;
|
|
744
|
-
let element = null;
|
|
745
|
-
function getCursorStyle(state) {
|
|
746
|
-
switch (state) {
|
|
747
|
-
case "horizontal":
|
|
748
|
-
return "ew-resize";
|
|
749
|
-
case "horizontal-max":
|
|
750
|
-
return "w-resize";
|
|
751
|
-
case "horizontal-min":
|
|
752
|
-
return "e-resize";
|
|
753
|
-
case "vertical":
|
|
754
|
-
return "ns-resize";
|
|
755
|
-
case "vertical-max":
|
|
756
|
-
return "n-resize";
|
|
757
|
-
case "vertical-min":
|
|
758
|
-
return "s-resize";
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
function resetGlobalCursorStyle() {
|
|
762
|
-
if (element !== null) {
|
|
763
|
-
document.head.removeChild(element);
|
|
764
|
-
currentState = null;
|
|
765
|
-
element = null;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
function setGlobalCursorStyle(state) {
|
|
769
|
-
if (currentState === state) {
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
currentState = state;
|
|
773
|
-
const style = getCursorStyle(state);
|
|
774
|
-
if (element === null) {
|
|
775
|
-
element = document.createElement("style");
|
|
776
|
-
document.head.appendChild(element);
|
|
777
|
-
}
|
|
778
|
-
element.innerHTML = `*{cursor: ${style}!important;}`;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
1045
|
function debounce(callback, durationMs = 10) {
|
|
782
1046
|
let timeoutId = null;
|
|
783
1047
|
let callable = (...args) => {
|
|
@@ -1261,18 +1525,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1261
1525
|
if (prevDeltaRef.current != delta) {
|
|
1262
1526
|
prevDeltaRef.current = delta;
|
|
1263
1527
|
if (!layoutChanged) {
|
|
1264
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
1265
|
-
// update the cursor style for a visual clue.
|
|
1528
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
1266
1529
|
// This mimics VS Code behavior.
|
|
1267
|
-
|
|
1268
1530
|
if (isHorizontal) {
|
|
1269
|
-
|
|
1531
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX);
|
|
1270
1532
|
} else {
|
|
1271
|
-
|
|
1533
|
+
reportConstraintsViolation(dragHandleId, delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX);
|
|
1272
1534
|
}
|
|
1273
1535
|
} else {
|
|
1274
|
-
|
|
1275
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
1536
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
1276
1537
|
}
|
|
1277
1538
|
}
|
|
1278
1539
|
}
|
|
@@ -1370,7 +1631,6 @@ function PanelGroupWithForwardedRef({
|
|
|
1370
1631
|
});
|
|
1371
1632
|
}, []);
|
|
1372
1633
|
const stopDragging = useCallback(() => {
|
|
1373
|
-
resetGlobalCursorStyle();
|
|
1374
1634
|
setDragState(null);
|
|
1375
1635
|
}, []);
|
|
1376
1636
|
const unregisterPanel = useCallback(panelData => {
|
|
@@ -1511,6 +1771,7 @@ function PanelResizeHandle({
|
|
|
1511
1771
|
children = null,
|
|
1512
1772
|
className: classNameFromProps = "",
|
|
1513
1773
|
disabled = false,
|
|
1774
|
+
hitAreaMargins,
|
|
1514
1775
|
id: idFromProps,
|
|
1515
1776
|
onDragging,
|
|
1516
1777
|
style: styleFromProps = {},
|
|
@@ -1533,67 +1794,60 @@ function PanelResizeHandle({
|
|
|
1533
1794
|
}
|
|
1534
1795
|
const {
|
|
1535
1796
|
direction,
|
|
1536
|
-
dragState,
|
|
1537
1797
|
groupId,
|
|
1538
|
-
registerResizeHandle,
|
|
1798
|
+
registerResizeHandle: registerResizeHandleWithParentGroup,
|
|
1539
1799
|
startDragging,
|
|
1540
1800
|
stopDragging,
|
|
1541
1801
|
panelGroupElement
|
|
1542
1802
|
} = panelGroupContext;
|
|
1543
1803
|
const resizeHandleId = useUniqueId(idFromProps);
|
|
1544
|
-
const
|
|
1804
|
+
const [state, setState] = useState("inactive");
|
|
1545
1805
|
const [isFocused, setIsFocused] = useState(false);
|
|
1546
1806
|
const [resizeHandler, setResizeHandler] = useState(null);
|
|
1547
|
-
const stopDraggingAndBlur = useCallback(() => {
|
|
1548
|
-
// Clicking on the drag handle shouldn't leave it focused;
|
|
1549
|
-
// That would cause the PanelGroup to think it was still active.
|
|
1550
|
-
const element = elementRef.current;
|
|
1551
|
-
assert(element);
|
|
1552
|
-
element.blur();
|
|
1553
|
-
stopDragging();
|
|
1554
|
-
const {
|
|
1555
|
-
onDragging
|
|
1556
|
-
} = callbacksRef.current;
|
|
1557
|
-
if (onDragging) {
|
|
1558
|
-
onDragging(false);
|
|
1559
|
-
}
|
|
1560
|
-
}, [stopDragging]);
|
|
1561
1807
|
useEffect(() => {
|
|
1562
1808
|
if (disabled) {
|
|
1563
1809
|
setResizeHandler(null);
|
|
1564
1810
|
} else {
|
|
1565
|
-
const resizeHandler =
|
|
1811
|
+
const resizeHandler = registerResizeHandleWithParentGroup(resizeHandleId);
|
|
1566
1812
|
setResizeHandler(() => resizeHandler);
|
|
1567
1813
|
}
|
|
1568
|
-
}, [disabled, resizeHandleId,
|
|
1814
|
+
}, [disabled, resizeHandleId, registerResizeHandleWithParentGroup]);
|
|
1569
1815
|
useEffect(() => {
|
|
1570
|
-
|
|
1816
|
+
var _hitAreaMargins$coars, _hitAreaMargins$fine;
|
|
1817
|
+
if (disabled || resizeHandler == null) {
|
|
1571
1818
|
return;
|
|
1572
1819
|
}
|
|
1573
|
-
const onMove = event => {
|
|
1574
|
-
resizeHandler(event);
|
|
1575
|
-
};
|
|
1576
|
-
const onMouseLeave = event => {
|
|
1577
|
-
resizeHandler(event);
|
|
1578
|
-
};
|
|
1579
1820
|
const element = elementRef.current;
|
|
1580
1821
|
assert(element);
|
|
1581
|
-
const
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1822
|
+
const setResizeHandlerState = (action, state, event) => {
|
|
1823
|
+
setState(state);
|
|
1824
|
+
switch (action) {
|
|
1825
|
+
case "down":
|
|
1826
|
+
{
|
|
1827
|
+
startDragging(resizeHandleId, event);
|
|
1828
|
+
break;
|
|
1829
|
+
}
|
|
1830
|
+
case "up":
|
|
1831
|
+
{
|
|
1832
|
+
stopDragging();
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
switch (state) {
|
|
1837
|
+
case "drag":
|
|
1838
|
+
{
|
|
1839
|
+
resizeHandler(event);
|
|
1840
|
+
break;
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1595
1843
|
};
|
|
1596
|
-
|
|
1844
|
+
return registerResizeHandle(resizeHandleId, element, direction, {
|
|
1845
|
+
// Coarse inputs (e.g. finger/touch)
|
|
1846
|
+
coarse: (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15,
|
|
1847
|
+
// Fine inputs (e.g. mouse)
|
|
1848
|
+
fine: (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5
|
|
1849
|
+
}, setResizeHandlerState);
|
|
1850
|
+
}, [direction, disabled, hitAreaMargins, registerResizeHandleWithParentGroup, resizeHandleId, resizeHandler, startDragging, stopDragging]);
|
|
1597
1851
|
useWindowSplitterResizeHandlerBehavior({
|
|
1598
1852
|
disabled,
|
|
1599
1853
|
handleId: resizeHandleId,
|
|
@@ -1601,7 +1855,6 @@ function PanelResizeHandle({
|
|
|
1601
1855
|
panelGroupElement
|
|
1602
1856
|
});
|
|
1603
1857
|
const style = {
|
|
1604
|
-
cursor: getCursorStyle(direction),
|
|
1605
1858
|
touchAction: "none",
|
|
1606
1859
|
userSelect: "none"
|
|
1607
1860
|
};
|
|
@@ -1611,31 +1864,6 @@ function PanelResizeHandle({
|
|
|
1611
1864
|
className: classNameFromProps,
|
|
1612
1865
|
onBlur: () => setIsFocused(false),
|
|
1613
1866
|
onFocus: () => setIsFocused(true),
|
|
1614
|
-
onMouseDown: event => {
|
|
1615
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1616
|
-
const callbacks = callbacksRef.current;
|
|
1617
|
-
assert(callbacks);
|
|
1618
|
-
const {
|
|
1619
|
-
onDragging
|
|
1620
|
-
} = callbacks;
|
|
1621
|
-
if (onDragging) {
|
|
1622
|
-
onDragging(true);
|
|
1623
|
-
}
|
|
1624
|
-
},
|
|
1625
|
-
onMouseUp: stopDraggingAndBlur,
|
|
1626
|
-
onTouchCancel: stopDraggingAndBlur,
|
|
1627
|
-
onTouchEnd: stopDraggingAndBlur,
|
|
1628
|
-
onTouchStart: event => {
|
|
1629
|
-
startDragging(resizeHandleId, event.nativeEvent);
|
|
1630
|
-
const callbacks = callbacksRef.current;
|
|
1631
|
-
assert(callbacks);
|
|
1632
|
-
const {
|
|
1633
|
-
onDragging
|
|
1634
|
-
} = callbacks;
|
|
1635
|
-
if (onDragging) {
|
|
1636
|
-
onDragging(true);
|
|
1637
|
-
}
|
|
1638
|
-
},
|
|
1639
1867
|
ref: elementRef,
|
|
1640
1868
|
role: "separator",
|
|
1641
1869
|
style: {
|
|
@@ -1647,7 +1875,8 @@ function PanelResizeHandle({
|
|
|
1647
1875
|
"data-panel-group-direction": direction,
|
|
1648
1876
|
"data-panel-group-id": groupId,
|
|
1649
1877
|
"data-resize-handle": "",
|
|
1650
|
-
"data-resize-handle-active":
|
|
1878
|
+
"data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
|
|
1879
|
+
"data-resize-handle-state": state,
|
|
1651
1880
|
"data-panel-resize-handle-enabled": !disabled,
|
|
1652
1881
|
"data-panel-resize-handle-id": resizeHandleId
|
|
1653
1882
|
});
|
package/package.json
CHANGED
package/src/PanelGroup.ts
CHANGED
|
@@ -6,6 +6,13 @@ import {
|
|
|
6
6
|
ResizeEvent,
|
|
7
7
|
TPanelGroupContext,
|
|
8
8
|
} from "./PanelGroupContext";
|
|
9
|
+
import {
|
|
10
|
+
EXCEEDED_HORIZONTAL_MAX,
|
|
11
|
+
EXCEEDED_HORIZONTAL_MIN,
|
|
12
|
+
EXCEEDED_VERTICAL_MAX,
|
|
13
|
+
EXCEEDED_VERTICAL_MIN,
|
|
14
|
+
reportConstraintsViolation,
|
|
15
|
+
} from "./PanelResizeHandleRegistry";
|
|
9
16
|
import useIsomorphicLayoutEffect from "./hooks/useIsomorphicEffect";
|
|
10
17
|
import useUniqueId from "./hooks/useUniqueId";
|
|
11
18
|
import { useWindowSplitterPanelGroupBehavior } from "./hooks/useWindowSplitterPanelGroupBehavior";
|
|
@@ -23,7 +30,7 @@ import debounce from "./utils/debounce";
|
|
|
23
30
|
import { determinePivotIndices } from "./utils/determinePivotIndices";
|
|
24
31
|
import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
|
|
25
32
|
import { isKeyDown, isMouseEvent, isTouchEvent } from "./utils/events";
|
|
26
|
-
import { getResizeEventCursorPosition } from "./utils/getResizeEventCursorPosition";
|
|
33
|
+
import { getResizeEventCursorPosition } from "./utils/events/getResizeEventCursorPosition";
|
|
27
34
|
import { initializeDefaultStorage } from "./utils/initializeDefaultStorage";
|
|
28
35
|
import {
|
|
29
36
|
loadPanelGroupState,
|
|
@@ -571,6 +578,7 @@ function PanelGroupWithForwardedRef({
|
|
|
571
578
|
if (!panelGroupElement) {
|
|
572
579
|
return () => null;
|
|
573
580
|
}
|
|
581
|
+
|
|
574
582
|
const {
|
|
575
583
|
direction,
|
|
576
584
|
dragState,
|
|
@@ -630,20 +638,21 @@ function PanelGroupWithForwardedRef({
|
|
|
630
638
|
prevDeltaRef.current = delta;
|
|
631
639
|
|
|
632
640
|
if (!layoutChanged) {
|
|
633
|
-
// If the pointer has moved too far to resize the panel any further,
|
|
634
|
-
// update the cursor style for a visual clue.
|
|
641
|
+
// If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
|
|
635
642
|
// This mimics VS Code behavior.
|
|
636
|
-
|
|
637
643
|
if (isHorizontal) {
|
|
638
|
-
|
|
639
|
-
|
|
644
|
+
reportConstraintsViolation(
|
|
645
|
+
dragHandleId,
|
|
646
|
+
delta < 0 ? EXCEEDED_HORIZONTAL_MIN : EXCEEDED_HORIZONTAL_MAX
|
|
640
647
|
);
|
|
641
648
|
} else {
|
|
642
|
-
|
|
649
|
+
reportConstraintsViolation(
|
|
650
|
+
dragHandleId,
|
|
651
|
+
delta < 0 ? EXCEEDED_VERTICAL_MIN : EXCEEDED_VERTICAL_MAX
|
|
652
|
+
);
|
|
643
653
|
}
|
|
644
654
|
} else {
|
|
645
|
-
|
|
646
|
-
setGlobalCursorStyle(isHorizontal ? "horizontal" : "vertical");
|
|
655
|
+
reportConstraintsViolation(dragHandleId, 0);
|
|
647
656
|
}
|
|
648
657
|
}
|
|
649
658
|
}
|
|
@@ -790,7 +799,6 @@ function PanelGroupWithForwardedRef({
|
|
|
790
799
|
);
|
|
791
800
|
|
|
792
801
|
const stopDragging = useCallback(() => {
|
|
793
|
-
resetGlobalCursorStyle();
|
|
794
802
|
setDragState(null);
|
|
795
803
|
}, []);
|
|
796
804
|
|