@mk-drag-and-drop/dom 0.5.1 → 0.5.2

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Matthias Kramer
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthias Kramer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -253,6 +253,33 @@ and deduplicate the scheduled work to prevent loops.
253
253
 
254
254
  ## Pointer and keyboard handles
255
255
 
256
+ ### Mobile pointer ownership
257
+
258
+ Dedicated drag handles must declare touch gesture ownership before a gesture
259
+ begins. `createDragHandle` adds the stable `data-dnd-drag-handle` attribute;
260
+ apply the following CSS in every document or shadow root that renders handles:
261
+
262
+ ```css
263
+ [data-dnd-drag-handle] {
264
+ touch-action: none;
265
+ user-select: none;
266
+ -webkit-user-select: none;
267
+ }
268
+ ```
269
+
270
+ `touch-action` cannot be applied from `pointerdown`: the browser decides native
271
+ pan/zoom ownership before the handler runs. The runtime uses pointer capture
272
+ after activation and suppresses standard and WebKit text selection during both
273
+ pending and active pointer input, but neither mechanism replaces the CSS
274
+ contract.
275
+
276
+ For a draggable without a dedicated handle, apply `touch-action` to the
277
+ draggable surface only when that surface should own touch movement. `none`
278
+ prevents ordinary page scrolling from gestures that begin there. An
279
+ axis-specific value can preserve orthogonal native panning, but a vertical drag
280
+ and vertical page scroll cannot own the same gesture simultaneously. Scrolling
281
+ outside dedicated handles remains unaffected.
282
+
256
283
  `activationDelay` and `activationDistance` use OR semantics: either threshold
257
284
  activates. Quick release before activation remains an ordinary click. After an
258
285
  activated pointer drag, the browser click belonging to that interaction and
@@ -4,7 +4,9 @@ export type DomDraggableRuntime = {
4
4
  draggableId: string;
5
5
  group: string;
6
6
  element: HTMLElement;
7
+ pointerCaptureTarget?: Element;
7
8
  pointerId: number;
9
+ pointerType?: string;
8
10
  pointerPosition: DragPoint;
9
11
  }) => void;
10
12
  isKeyboardDragEnabled: () => boolean;
@@ -27,6 +29,7 @@ export type DomDraggablePointerDownEvent = {
27
29
  preventDefault: () => void;
28
30
  stopPropagation: () => void;
29
31
  pointerId: number;
32
+ pointerType?: string;
30
33
  button?: number;
31
34
  isPrimary?: boolean;
32
35
  clientX: number;
@@ -1,4 +1,4 @@
1
- import { shouldHandleKeyboardDragFromTarget, shouldStartDragFromTarget, } from "../input/drag-handle.js";
1
+ import { getPointerCaptureTarget, shouldHandleKeyboardDragFromTarget, } from "../input/drag-handle.js";
2
2
  export function createDomDraggable(input) {
3
3
  return {
4
4
  onPointerDown: (event) => {
@@ -6,10 +6,11 @@ export function createDomDraggable(input) {
6
6
  if (!element) {
7
7
  return;
8
8
  }
9
- if (!shouldStartDragFromTarget({
9
+ const pointerCaptureTarget = getPointerCaptureTarget({
10
10
  draggableElement: element,
11
11
  eventTarget: event.target,
12
- })) {
12
+ });
13
+ if (!pointerCaptureTarget) {
13
14
  return;
14
15
  }
15
16
  if (event.isPrimary === false ||
@@ -22,7 +23,9 @@ export function createDomDraggable(input) {
22
23
  draggableId: input.draggableId,
23
24
  group: input.group,
24
25
  element,
26
+ pointerCaptureTarget,
25
27
  pointerId: event.pointerId,
28
+ pointerType: event.pointerType,
26
29
  pointerPosition: {
27
30
  x: event.clientX,
28
31
  y: event.clientY,
@@ -50,7 +53,7 @@ export function createDomDraggable(input) {
50
53
  event.preventDefault();
51
54
  event.stopPropagation();
52
55
  },
53
- tabIndex: (input.keyboardDragEnabled ?? input.runtime.isKeyboardDragEnabled())
56
+ tabIndex: input.keyboardDragEnabled ?? input.runtime.isKeyboardDragEnabled()
54
57
  ? 0
55
58
  : undefined,
56
59
  };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { createDropContainer, type CreateDropContainerInput, } from "./droppable
5
5
  export { createSortable, type CreateSortableInput, } from "./sortable/create-sortable-binding.js";
6
6
  export type { SortableAxis, SortablePlacementBoundary, } from "./sortable/sortable-options.js";
7
7
  export { createDragHandle, type CreateDragHandleInput, } from "./input/create-drag-handle.js";
8
+ export { domDragHandleAttribute } from "./input/drag-handle.js";
8
9
  export { domPointerDragActiveAttribute } from "./input/pointer-drag-state.js";
9
10
  export type { DragEndResult, DragEndEvent, DragLifecycleCallbacks, DragLifecycleHelpers, DragSource, DragStartEvent, DragUpdateEvent, DropEvent, ActiveDragResetEvent, SortablePreview, } from "./runtime/lifecycle.js";
10
11
  export type { RemeasureDropTargetsInput, SortableDropPlacement, } from "./runtime/drop-target-registry.js";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { createDroppable, } from "./droppable/create-droppable-binding.js";
4
4
  export { createDropContainer, } from "./droppable/create-drop-container-binding.js";
5
5
  export { createSortable, } from "./sortable/create-sortable-binding.js";
6
6
  export { createDragHandle, } from "./input/create-drag-handle.js";
7
+ export { domDragHandleAttribute } from "./input/drag-handle.js";
7
8
  export { domPointerDragActiveAttribute } from "./input/pointer-drag-state.js";
8
9
  export { centerToCenter, pointerToCenter, pointerToRectDistance, } from "./targeting/algorithms.js";
9
10
  export { getDistanceToRect, maxOverlayCenterDistanceToRect, maxPointerDistanceToRect, } from "./targeting/constraints.js";
@@ -0,0 +1 @@
1
+ export declare function acquireDocumentSelectionSuppression(sourceDocument: Document): () => void;
@@ -0,0 +1,89 @@
1
+ const selectionPropertyNames = ["user-select", "-webkit-user-select"];
2
+ const documentSelectionStates = new WeakMap();
3
+ export function acquireDocumentSelectionSuppression(sourceDocument) {
4
+ const owner = {};
5
+ let state = documentSelectionStates.get(sourceDocument);
6
+ if (!state) {
7
+ const elements = [
8
+ sourceDocument.documentElement,
9
+ ...(sourceDocument.body ? [sourceDocument.body] : []),
10
+ ];
11
+ const snapshots = elements.map(createElementSelectionSnapshot);
12
+ const handleSelectStart = (event) => {
13
+ event.preventDefault();
14
+ };
15
+ state = {
16
+ owners: new Set(),
17
+ snapshots,
18
+ handleSelectStart,
19
+ };
20
+ documentSelectionStates.set(sourceDocument, state);
21
+ for (const element of elements) {
22
+ for (const propertyName of selectionPropertyNames) {
23
+ setSelectionProperty(element.style, propertyName, "none");
24
+ }
25
+ }
26
+ sourceDocument.addEventListener("selectstart", handleSelectStart, true);
27
+ }
28
+ state.owners.add(owner);
29
+ let released = false;
30
+ return () => {
31
+ if (released) {
32
+ return;
33
+ }
34
+ released = true;
35
+ if (!state?.owners.delete(owner) || state.owners.size > 0) {
36
+ return;
37
+ }
38
+ documentSelectionStates.delete(sourceDocument);
39
+ sourceDocument.removeEventListener("selectstart", state.handleSelectStart, true);
40
+ for (const snapshot of state.snapshots) {
41
+ restoreElementSelectionSnapshot(snapshot);
42
+ }
43
+ };
44
+ }
45
+ function createElementSelectionSnapshot(element) {
46
+ return {
47
+ element,
48
+ properties: selectionPropertyNames.map((name) => ({
49
+ name,
50
+ present: hasInlineProperty(element.style, name) ||
51
+ getSelectionProperty(element.style, name) !== "",
52
+ value: getSelectionProperty(element.style, name),
53
+ priority: element.style.getPropertyPriority(name),
54
+ })),
55
+ };
56
+ }
57
+ function restoreElementSelectionSnapshot(snapshot) {
58
+ for (const property of snapshot.properties) {
59
+ if (property.present) {
60
+ setSelectionProperty(snapshot.element.style, property.name, property.value, property.priority);
61
+ }
62
+ else {
63
+ snapshot.element.style.removeProperty(property.name);
64
+ if (property.name === "-webkit-user-select") {
65
+ snapshot.element.style.webkitUserSelect = "";
66
+ }
67
+ }
68
+ }
69
+ }
70
+ function getSelectionProperty(style, name) {
71
+ const cssValue = style.getPropertyValue(name);
72
+ return name === "-webkit-user-select" && cssValue === ""
73
+ ? style.webkitUserSelect ?? ""
74
+ : cssValue;
75
+ }
76
+ function setSelectionProperty(style, name, value, priority = "") {
77
+ style.setProperty(name, value, priority);
78
+ if (name === "-webkit-user-select" && style.webkitUserSelect !== value) {
79
+ style.webkitUserSelect = value;
80
+ }
81
+ }
82
+ function hasInlineProperty(style, name) {
83
+ for (let index = 0; index < style.length; index += 1) {
84
+ if (style.item(index) === name) {
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ }
@@ -4,6 +4,10 @@ export declare function shouldStartDragFromTarget(input: {
4
4
  draggableElement: HTMLElement;
5
5
  eventTarget: EventTarget | null;
6
6
  }): boolean;
7
+ export declare function getPointerCaptureTarget(input: {
8
+ draggableElement: HTMLElement;
9
+ eventTarget: EventTarget | null;
10
+ }): Element | null;
7
11
  export declare function shouldHandleKeyboardDragFromTarget(input: {
8
12
  draggableElement: HTMLElement;
9
13
  eventTarget: EventTarget | null;
@@ -12,20 +12,27 @@ const interactiveElementSelector = [
12
12
  "[role='textbox']",
13
13
  ].join(",");
14
14
  export function shouldStartDragFromTarget(input) {
15
+ return getPointerCaptureTarget(input) !== null;
16
+ }
17
+ export function getPointerCaptureTarget(input) {
15
18
  const eventTarget = getEventTargetElement(input.eventTarget);
16
19
  if (!eventTarget) {
17
- return false;
20
+ return null;
18
21
  }
19
22
  const hasDragHandle = input.draggableElement.querySelector(domDragHandleSelector) !== null;
20
23
  if (!hasDragHandle) {
21
- return !isInteractiveDragTarget({
24
+ return isInteractiveDragTarget({
22
25
  draggableElement: input.draggableElement,
23
26
  eventTarget,
24
- });
27
+ })
28
+ ? null
29
+ : input.draggableElement;
25
30
  }
26
31
  const closestDragHandle = eventTarget.closest(domDragHandleSelector);
27
- return (closestDragHandle !== null &&
28
- input.draggableElement.contains(closestDragHandle));
32
+ return closestDragHandle !== null &&
33
+ input.draggableElement.contains(closestDragHandle)
34
+ ? closestDragHandle
35
+ : null;
29
36
  }
30
37
  export function shouldHandleKeyboardDragFromTarget(input) {
31
38
  const eventTarget = getEventTargetElement(input.eventTarget);
@@ -4,20 +4,25 @@ export type PointerDragActivationRequest = {
4
4
  draggableId: string;
5
5
  group: string;
6
6
  element: HTMLElement;
7
+ pointerCaptureTarget?: Element;
7
8
  pointerId: number;
9
+ pointerType?: string;
8
10
  pointerPosition: DragPoint;
9
11
  };
10
12
  export type ActivatedPointerDrag = {
11
13
  draggableId: string;
12
14
  group: string;
13
15
  element: HTMLElement;
16
+ pointerCaptureTarget: Element;
14
17
  pointerId: number;
18
+ pointerType: string;
15
19
  initialPointerPosition: DragPoint;
16
20
  latestPointerPosition: DragPoint;
17
21
  };
18
22
  export type PointerActivationControllerOptions = {
19
23
  getConfiguration: () => NormalizedPointerConfiguration;
20
24
  isDragging: () => boolean;
25
+ acquirePendingResources?: (request: PointerDragActivationRequest) => () => void;
21
26
  startImmediately: (request: PointerDragActivationRequest) => void;
22
27
  activate: (activation: ActivatedPointerDrag) => void;
23
28
  };
@@ -24,12 +24,15 @@ export class PointerActivationController {
24
24
  draggableId: request.draggableId,
25
25
  group: request.group,
26
26
  element: request.element,
27
+ pointerCaptureTarget: request.pointerCaptureTarget ?? request.element,
27
28
  pointerId: request.pointerId,
29
+ pointerType: request.pointerType ?? "",
28
30
  initialPointerPosition,
29
31
  latestPointerPosition: initialPointerPosition,
30
32
  targetWindow,
31
33
  activationTimerId: null,
32
34
  releasePendingPointerListeners: null,
35
+ releasePendingResources: this.options.acquirePendingResources?.(request) ?? null,
33
36
  };
34
37
  const handlePointerMove = (event) => {
35
38
  if (event.pointerId !== pendingActivation.pointerId) {
@@ -87,6 +90,9 @@ export class PointerActivationController {
87
90
  const releasePendingPointerListeners = pendingActivation.releasePendingPointerListeners;
88
91
  pendingActivation.releasePendingPointerListeners = null;
89
92
  releasePendingPointerListeners?.();
93
+ const releasePendingResources = pendingActivation.releasePendingResources;
94
+ pendingActivation.releasePendingResources = null;
95
+ releasePendingResources?.();
90
96
  }
91
97
  clearPendingActivationTimer(pendingActivation) {
92
98
  if (pendingActivation.activationTimerId === null) {
@@ -99,14 +105,23 @@ export class PointerActivationController {
99
105
  if (this.pendingActivation !== pendingActivation) {
100
106
  return;
101
107
  }
108
+ const releasePendingResources = pendingActivation.releasePendingResources;
109
+ pendingActivation.releasePendingResources = null;
102
110
  this.clearPendingActivation(pendingActivation);
103
- this.options.activate({
104
- draggableId: pendingActivation.draggableId,
105
- group: pendingActivation.group,
106
- element: pendingActivation.element,
107
- pointerId: pendingActivation.pointerId,
108
- initialPointerPosition: pendingActivation.initialPointerPosition,
109
- latestPointerPosition: pendingActivation.latestPointerPosition,
110
- });
111
+ try {
112
+ this.options.activate({
113
+ draggableId: pendingActivation.draggableId,
114
+ group: pendingActivation.group,
115
+ element: pendingActivation.element,
116
+ pointerCaptureTarget: pendingActivation.pointerCaptureTarget,
117
+ pointerId: pendingActivation.pointerId,
118
+ pointerType: pendingActivation.pointerType,
119
+ initialPointerPosition: pendingActivation.initialPointerPosition,
120
+ latestPointerPosition: pendingActivation.latestPointerPosition,
121
+ });
122
+ }
123
+ finally {
124
+ releasePendingResources?.();
125
+ }
111
126
  }
112
127
  }
@@ -17,6 +17,7 @@ export declare class DragRuntime {
17
17
  private modifiers;
18
18
  private activeDragModifiers;
19
19
  private releaseActiveInputListeners;
20
+ private ensureActivePointerCapture;
20
21
  private restoreTextSelectionSuppression;
21
22
  private releasePointerDragState;
22
23
  private releasePostDragClickSuppression;
@@ -3,6 +3,7 @@ import { getOverlayMeasurement, getOverlayRect, } from "../geometry/overlay.js";
3
3
  import { defaultKeyboardConfiguration, normalizeKeyboardConfiguration, normalizePointerConfiguration, } from "../input/config.js";
4
4
  import { KeyboardDragController, } from "../input/keyboard-drag.js";
5
5
  import { globalPointerListenerCapture } from "../input/global-pointer-listeners.js";
6
+ import { acquireDocumentSelectionSuppression } from "../input/document-selection-state.js";
6
7
  import { PointerActivationController } from "../input/pointer-activation.js";
7
8
  import { acquireDocumentPointerDragState } from "../input/pointer-drag-state.js";
8
9
  import { applyDragModifiers, createActiveDragModifiers, } from "../modifiers/pipeline.js";
@@ -20,6 +21,7 @@ export class DragRuntime {
20
21
  modifiers = [];
21
22
  activeDragModifiers = [];
22
23
  releaseActiveInputListeners = null;
24
+ ensureActivePointerCapture = null;
23
25
  restoreTextSelectionSuppression = null;
24
26
  releasePointerDragState = null;
25
27
  releasePostDragClickSuppression = null;
@@ -48,6 +50,7 @@ export class DragRuntime {
48
50
  pointerActivation = new PointerActivationController({
49
51
  getConfiguration: () => this.pointerConfiguration,
50
52
  isDragging: () => this.isDragging,
53
+ acquirePendingResources: (request) => acquireDocumentSelectionSuppression(request.element.ownerDocument),
51
54
  startImmediately: (request) => {
52
55
  if (!request.element.isConnected) {
53
56
  return;
@@ -57,6 +60,8 @@ export class DragRuntime {
57
60
  group: request.group,
58
61
  inputType: "pointer",
59
62
  pointerId: request.pointerId,
63
+ pointerCaptureTarget: request.pointerCaptureTarget ?? request.element,
64
+ pointerType: request.pointerType,
60
65
  element: request.element,
61
66
  pointerPosition: request.pointerPosition,
62
67
  sourceRect: measureDomElement(request.element),
@@ -71,6 +76,8 @@ export class DragRuntime {
71
76
  group: activation.group,
72
77
  inputType: "pointer",
73
78
  pointerId: activation.pointerId,
79
+ pointerCaptureTarget: activation.pointerCaptureTarget,
80
+ pointerType: activation.pointerType,
74
81
  element: activation.element,
75
82
  pointerPosition: activation.initialPointerPosition,
76
83
  sourceRect: measureDomElement(activation.element),
@@ -248,6 +255,7 @@ export class DragRuntime {
248
255
  placementPosition: sortablePlacementPosition,
249
256
  movementPosition: rawPointerPosition,
250
257
  });
258
+ this.ensureActivePointerCapture?.();
251
259
  const sortablePreview = this.getSortablePreview(nextSession);
252
260
  const completedSession = {
253
261
  ...nextSession,
@@ -528,7 +536,7 @@ export class DragRuntime {
528
536
  });
529
537
  this.suppressTextSelection(input.element.ownerDocument);
530
538
  if (input.inputType === "pointer") {
531
- this.bindPointerWindowListeners(input.pointerId, input.element);
539
+ this.bindPointerWindowListeners(input.pointerId, input.element, input.pointerCaptureTarget ?? input.element);
532
540
  }
533
541
  else {
534
542
  this.bindKeyboardWindowListeners(this.activeDragWindow);
@@ -665,10 +673,40 @@ export class DragRuntime {
665
673
  }
666
674
  this.clearOverlayHost();
667
675
  }
668
- bindPointerWindowListeners(pointerId, initiatingElement) {
676
+ bindPointerWindowListeners(pointerId, initiatingElement, pointerCaptureTarget) {
669
677
  this.releaseActiveInputListeners?.();
670
678
  const targetWindow = initiatingElement.ownerDocument.defaultView ?? window;
671
679
  let listenersReleased = false;
680
+ const ensurePointerCapture = () => {
681
+ if (!pointerCaptureTarget.isConnected ||
682
+ typeof pointerCaptureTarget.setPointerCapture !== "function") {
683
+ return;
684
+ }
685
+ try {
686
+ if (typeof pointerCaptureTarget.hasPointerCapture === "function" &&
687
+ pointerCaptureTarget.hasPointerCapture(pointerId)) {
688
+ return;
689
+ }
690
+ pointerCaptureTarget.setPointerCapture(pointerId);
691
+ }
692
+ catch {
693
+ // Window listeners remain the fallback when capture is unavailable.
694
+ }
695
+ };
696
+ const releasePointerCapture = () => {
697
+ if (typeof pointerCaptureTarget.releasePointerCapture !== "function") {
698
+ return;
699
+ }
700
+ try {
701
+ if (typeof pointerCaptureTarget.hasPointerCapture !== "function" ||
702
+ pointerCaptureTarget.hasPointerCapture(pointerId)) {
703
+ pointerCaptureTarget.releasePointerCapture(pointerId);
704
+ }
705
+ }
706
+ catch {
707
+ // Pointerup/cancel may have already released capture implicitly.
708
+ }
709
+ };
672
710
  const handlePointerMove = (event) => {
673
711
  if (event.pointerId !== pointerId) {
674
712
  return;
@@ -701,11 +739,17 @@ export class DragRuntime {
701
739
  targetWindow.addEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
702
740
  targetWindow.addEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
703
741
  targetWindow.addEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
742
+ this.ensureActivePointerCapture = ensurePointerCapture;
743
+ ensurePointerCapture();
704
744
  this.releaseActiveInputListeners = () => {
705
745
  if (listenersReleased) {
706
746
  return;
707
747
  }
708
748
  listenersReleased = true;
749
+ if (this.ensureActivePointerCapture === ensurePointerCapture) {
750
+ this.ensureActivePointerCapture = null;
751
+ }
752
+ releasePointerCapture();
709
753
  targetWindow.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
710
754
  targetWindow.removeEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
711
755
  targetWindow.removeEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
@@ -751,20 +795,8 @@ export class DragRuntime {
751
795
  }
752
796
  suppressTextSelection(sourceDocument) {
753
797
  this.restoreTextSelectionSuppression?.();
754
- const root = sourceDocument.documentElement;
755
- const body = sourceDocument.body;
756
- const previousRootUserSelect = root.style.userSelect;
757
- const previousBodyUserSelect = body?.style.userSelect;
758
- root.style.userSelect = "none";
759
- if (body) {
760
- body.style.userSelect = "none";
761
- }
762
- this.restoreTextSelectionSuppression = () => {
763
- root.style.userSelect = previousRootUserSelect;
764
- if (body) {
765
- body.style.userSelect = previousBodyUserSelect ?? "";
766
- }
767
- };
798
+ this.restoreTextSelectionSuppression =
799
+ acquireDocumentSelectionSuppression(sourceDocument);
768
800
  }
769
801
  resetActiveDragState() {
770
802
  this.cancelQueuedPointerUpdate();
@@ -775,6 +807,7 @@ export class DragRuntime {
775
807
  releaseActiveInputResources() {
776
808
  const releaseActiveInputListeners = this.releaseActiveInputListeners;
777
809
  this.releaseActiveInputListeners = null;
810
+ this.ensureActivePointerCapture = null;
778
811
  const restoreTextSelectionSuppression = this.restoreTextSelectionSuppression;
779
812
  this.restoreTextSelectionSuppression = null;
780
813
  const releasePointerDragState = this.releasePointerDragState;
@@ -43,6 +43,8 @@ type BaseStartDragInput = {
43
43
  export type StartDragInput = (BaseStartDragInput & {
44
44
  inputType: "pointer";
45
45
  pointerId: number;
46
+ pointerCaptureTarget?: Element;
47
+ pointerType?: string;
46
48
  }) | (BaseStartDragInput & {
47
49
  inputType: "keyboard";
48
50
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mk-drag-and-drop/dom",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Headless DOM drag-and-drop primitives for draggable, droppable, sortable, and grouped interactions.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://mkramer.dev",
@@ -47,8 +47,8 @@
47
47
  "jsdom": "^24.1.3",
48
48
  "typescript": "5.5.4",
49
49
  "vitest": "^2.1.9",
50
- "@repo/typescript-config": "0.0.0",
51
- "@repo/eslint-config": "0.0.0"
50
+ "@repo/eslint-config": "0.0.0",
51
+ "@repo/typescript-config": "0.0.0"
52
52
  },
53
53
  "scripts": {
54
54
  "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",