@mk-drag-and-drop/dom 0.5.2 → 0.5.3
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/README.md +20 -11
- package/dist/draggable/create-draggable.js +8 -5
- package/dist/input/drag-handle.d.ts +5 -2
- package/dist/input/drag-handle.js +21 -11
- package/dist/input/native-drag-suppression.d.ts +1 -0
- package/dist/input/native-drag-suppression.js +5 -0
- package/dist/runtime/drag-runtime.js +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,19 +278,28 @@ draggable surface only when that surface should own touch movement. `none`
|
|
|
278
278
|
prevents ordinary page scrolling from gestures that begin there. An
|
|
279
279
|
axis-specific value can preserve orthogonal native panning, but a vertical drag
|
|
280
280
|
and vertical page scroll cannot own the same gesture simultaneously. Scrolling
|
|
281
|
-
outside dedicated handles remains unaffected.
|
|
281
|
+
outside dedicated handles remains unaffected. If the draggable is an inline
|
|
282
|
+
anchor, use a display value such as `inline-block` so `touch-action` applies.
|
|
282
283
|
|
|
283
284
|
`activationDelay` and `activationDistance` use OR semantics: either threshold
|
|
284
|
-
activates.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
285
|
+
activates. Without a dedicated handle, pointer drags can start on links
|
|
286
|
+
(`a[href]` and `role="link"`), including when the draggable is itself a link.
|
|
287
|
+
Buttons, inputs, selects, textareas, options, elements with `role="button"` or
|
|
288
|
+
`role="textbox"`, and content-editable elements are protected from pointer drag
|
|
289
|
+
starts. When a draggable has a dedicated handle, pointer drags start only from
|
|
290
|
+
that handle.
|
|
291
|
+
|
|
292
|
+
Native browser dragging is suppressed in the draggable subtree while pointer
|
|
293
|
+
activation is pending or active. A quick release before activation follows the
|
|
294
|
+
link as usual. After activation, the generated click on the initiating draggable
|
|
295
|
+
subtree is suppressed. Later unrelated, programmatic, and keyboard clicks remain
|
|
296
|
+
available.
|
|
297
|
+
|
|
298
|
+
Keyboard drag starts protect links as well as the controls and editable elements
|
|
299
|
+
listed above. Enter on a focused link follows it. A button marked with
|
|
300
|
+
`createDragHandle({ element })` can start a pointer drag and still uses Space and
|
|
301
|
+
Enter for its button/menu action. Use a noninteractive or separately focusable
|
|
302
|
+
handle, or explicit commands, for keyboard sorting.
|
|
294
303
|
|
|
295
304
|
### Active pointer cursor state
|
|
296
305
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPointerDragStartTarget, shouldHandleKeyboardDragFromTarget, } from "../input/drag-handle.js";
|
|
2
2
|
export function createDomDraggable(input) {
|
|
3
3
|
return {
|
|
4
4
|
onPointerDown: (event) => {
|
|
@@ -6,24 +6,27 @@ export function createDomDraggable(input) {
|
|
|
6
6
|
if (!element) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const dragStartTarget = getPointerDragStartTarget({
|
|
10
10
|
draggableElement: element,
|
|
11
11
|
eventTarget: event.target,
|
|
12
12
|
});
|
|
13
|
-
if (!
|
|
13
|
+
if (!dragStartTarget) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
if (event.isPrimary === false ||
|
|
17
17
|
(event.button !== undefined && event.button !== 0)) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
// A canceled pointerdown can prevent a touch tap from clicking the link.
|
|
21
|
+
if (!dragStartTarget.preservePointerDownDefault) {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
}
|
|
21
24
|
event.stopPropagation();
|
|
22
25
|
input.runtime.requestDragStart({
|
|
23
26
|
draggableId: input.draggableId,
|
|
24
27
|
group: input.group,
|
|
25
28
|
element,
|
|
26
|
-
pointerCaptureTarget,
|
|
29
|
+
pointerCaptureTarget: dragStartTarget.captureTarget,
|
|
27
30
|
pointerId: event.pointerId,
|
|
28
31
|
pointerType: event.pointerType,
|
|
29
32
|
pointerPosition: {
|
|
@@ -4,10 +4,13 @@ export declare function shouldStartDragFromTarget(input: {
|
|
|
4
4
|
draggableElement: HTMLElement;
|
|
5
5
|
eventTarget: EventTarget | null;
|
|
6
6
|
}): boolean;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function getPointerDragStartTarget(input: {
|
|
8
8
|
draggableElement: HTMLElement;
|
|
9
9
|
eventTarget: EventTarget | null;
|
|
10
|
-
}):
|
|
10
|
+
}): {
|
|
11
|
+
captureTarget: Element;
|
|
12
|
+
preservePointerDownDefault: boolean;
|
|
13
|
+
} | null;
|
|
11
14
|
export declare function shouldHandleKeyboardDragFromTarget(input: {
|
|
12
15
|
draggableElement: HTMLElement;
|
|
13
16
|
eventTarget: EventTarget | null;
|
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
export const domDragHandleAttribute = "data-dnd-drag-handle";
|
|
2
2
|
export const domDragHandleSelector = `[${domDragHandleAttribute}]`;
|
|
3
|
-
const
|
|
4
|
-
"a[href]",
|
|
3
|
+
const pointerInteractiveElementSelector = [
|
|
5
4
|
"button",
|
|
6
5
|
"input",
|
|
7
6
|
"option",
|
|
8
7
|
"select",
|
|
9
8
|
"textarea",
|
|
10
9
|
"[role='button']",
|
|
11
|
-
"[role='link']",
|
|
12
10
|
"[role='textbox']",
|
|
13
11
|
].join(",");
|
|
12
|
+
const linkElementSelector = "a[href],[role='link']";
|
|
13
|
+
const keyboardInteractiveElementSelector = [
|
|
14
|
+
pointerInteractiveElementSelector,
|
|
15
|
+
linkElementSelector,
|
|
16
|
+
].join(",");
|
|
14
17
|
export function shouldStartDragFromTarget(input) {
|
|
15
|
-
return
|
|
18
|
+
return getPointerDragStartTarget(input) !== null;
|
|
16
19
|
}
|
|
17
|
-
export function
|
|
20
|
+
export function getPointerDragStartTarget(input) {
|
|
18
21
|
const eventTarget = getEventTargetElement(input.eventTarget);
|
|
19
22
|
if (!eventTarget) {
|
|
20
23
|
return null;
|
|
21
24
|
}
|
|
22
25
|
const hasDragHandle = input.draggableElement.querySelector(domDragHandleSelector) !== null;
|
|
23
26
|
if (!hasDragHandle) {
|
|
24
|
-
|
|
27
|
+
if (isInteractiveDragTarget({
|
|
25
28
|
draggableElement: input.draggableElement,
|
|
26
29
|
eventTarget,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
selector: pointerInteractiveElementSelector,
|
|
31
|
+
})) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
captureTarget: input.draggableElement,
|
|
36
|
+
preservePointerDownDefault: closestWithin(eventTarget, linkElementSelector, input.draggableElement) !== null,
|
|
37
|
+
};
|
|
30
38
|
}
|
|
31
39
|
const closestDragHandle = eventTarget.closest(domDragHandleSelector);
|
|
32
40
|
return closestDragHandle !== null &&
|
|
33
41
|
input.draggableElement.contains(closestDragHandle)
|
|
34
|
-
? closestDragHandle
|
|
42
|
+
? { captureTarget: closestDragHandle, preservePointerDownDefault: false }
|
|
35
43
|
: null;
|
|
36
44
|
}
|
|
37
45
|
export function shouldHandleKeyboardDragFromTarget(input) {
|
|
@@ -42,6 +50,7 @@ export function shouldHandleKeyboardDragFromTarget(input) {
|
|
|
42
50
|
if (isInteractiveDragTarget({
|
|
43
51
|
draggableElement: input.draggableElement,
|
|
44
52
|
eventTarget,
|
|
53
|
+
selector: keyboardInteractiveElementSelector,
|
|
45
54
|
})) {
|
|
46
55
|
return false;
|
|
47
56
|
}
|
|
@@ -56,7 +65,8 @@ function getEventTargetElement(target) {
|
|
|
56
65
|
return target instanceof Element ? target : null;
|
|
57
66
|
}
|
|
58
67
|
function isInteractiveDragTarget(input) {
|
|
59
|
-
return (closestWithin(input.eventTarget,
|
|
68
|
+
return (closestWithin(input.eventTarget, input.selector, input.draggableElement) !==
|
|
69
|
+
null ||
|
|
60
70
|
getEditableElement(input.eventTarget, input.draggableElement) !== null);
|
|
61
71
|
}
|
|
62
72
|
function closestWithin(element, selector, boundary) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function suppressNativeDragStart(element: HTMLElement): () => void;
|
|
@@ -4,6 +4,7 @@ import { defaultKeyboardConfiguration, normalizeKeyboardConfiguration, normalize
|
|
|
4
4
|
import { KeyboardDragController, } from "../input/keyboard-drag.js";
|
|
5
5
|
import { globalPointerListenerCapture } from "../input/global-pointer-listeners.js";
|
|
6
6
|
import { acquireDocumentSelectionSuppression } from "../input/document-selection-state.js";
|
|
7
|
+
import { suppressNativeDragStart } from "../input/native-drag-suppression.js";
|
|
7
8
|
import { PointerActivationController } from "../input/pointer-activation.js";
|
|
8
9
|
import { acquireDocumentPointerDragState } from "../input/pointer-drag-state.js";
|
|
9
10
|
import { applyDragModifiers, createActiveDragModifiers, } from "../modifiers/pipeline.js";
|
|
@@ -50,7 +51,14 @@ export class DragRuntime {
|
|
|
50
51
|
pointerActivation = new PointerActivationController({
|
|
51
52
|
getConfiguration: () => this.pointerConfiguration,
|
|
52
53
|
isDragging: () => this.isDragging,
|
|
53
|
-
acquirePendingResources: (
|
|
54
|
+
acquirePendingResources: ({ element }) => {
|
|
55
|
+
const restoreTextSelection = acquireDocumentSelectionSuppression(element.ownerDocument);
|
|
56
|
+
const releaseNativeDragSuppression = suppressNativeDragStart(element);
|
|
57
|
+
return () => {
|
|
58
|
+
releaseNativeDragSuppression();
|
|
59
|
+
restoreTextSelection();
|
|
60
|
+
};
|
|
61
|
+
},
|
|
54
62
|
startImmediately: (request) => {
|
|
55
63
|
if (!request.element.isConnected) {
|
|
56
64
|
return;
|
|
@@ -676,6 +684,7 @@ export class DragRuntime {
|
|
|
676
684
|
bindPointerWindowListeners(pointerId, initiatingElement, pointerCaptureTarget) {
|
|
677
685
|
this.releaseActiveInputListeners?.();
|
|
678
686
|
const targetWindow = initiatingElement.ownerDocument.defaultView ?? window;
|
|
687
|
+
const releaseNativeDragSuppression = suppressNativeDragStart(initiatingElement);
|
|
679
688
|
let listenersReleased = false;
|
|
680
689
|
const ensurePointerCapture = () => {
|
|
681
690
|
if (!pointerCaptureTarget.isConnected ||
|
|
@@ -749,6 +758,7 @@ export class DragRuntime {
|
|
|
749
758
|
if (this.ensureActivePointerCapture === ensurePointerCapture) {
|
|
750
759
|
this.ensureActivePointerCapture = null;
|
|
751
760
|
}
|
|
761
|
+
releaseNativeDragSuppression();
|
|
752
762
|
releasePointerCapture();
|
|
753
763
|
targetWindow.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
|
|
754
764
|
targetWindow.removeEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
|
package/package.json
CHANGED