@mk-drag-and-drop/dom 0.5.0 → 0.5.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/README.md +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/input/keyboard-drag.d.ts +1 -1
- package/dist/input/keyboard-drag.js +3 -3
- package/dist/input/pointer-activation.js +10 -8
- package/dist/input/pointer-drag-state.d.ts +2 -0
- package/dist/input/pointer-drag-state.js +32 -0
- package/dist/integration/index.d.ts +1 -0
- package/dist/integration/index.js +1 -0
- package/dist/runtime/drag-runtime.d.ts +3 -0
- package/dist/runtime/drag-runtime.js +57 -24
- package/dist/runtime/types.d.ts +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
createDropContainer,
|
|
18
18
|
createDroppable,
|
|
19
19
|
createSortable,
|
|
20
|
+
domPointerDragActiveAttribute,
|
|
20
21
|
type DragUpdateEvent,
|
|
21
22
|
type SortableDropPlacement,
|
|
22
23
|
type SortablePreview,
|
|
@@ -264,6 +265,32 @@ interactive-element protection prevents those keys from starting a drag. Use a
|
|
|
264
265
|
noninteractive or separately focusable handle, or explicit commands, for
|
|
265
266
|
keyboard sorting. Editable descendants remain protected.
|
|
266
267
|
|
|
268
|
+
### Active pointer cursor state
|
|
269
|
+
|
|
270
|
+
When a pointer drag activates, the runtime sets the stable
|
|
271
|
+
`data-dnd-pointer-drag-active="true"` contract on the initiating document's
|
|
272
|
+
root element. Pending delay or distance activation and keyboard dragging do not
|
|
273
|
+
set it. The marker is removed when the actual drag ends, before lifecycle
|
|
274
|
+
completion and before any manual overlay release animation finishes.
|
|
275
|
+
|
|
276
|
+
The package does not choose or inject a cursor. Applications can opt into one:
|
|
277
|
+
|
|
278
|
+
```css
|
|
279
|
+
:root[data-dnd-pointer-drag-active="true"],
|
|
280
|
+
:root[data-dnd-pointer-drag-active="true"] *,
|
|
281
|
+
:root[data-dnd-pointer-drag-active="true"] *::before,
|
|
282
|
+
:root[data-dnd-pointer-drag-active="true"] *::after {
|
|
283
|
+
cursor: grabbing !important;
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The descendant selectors and `!important` override explicit application
|
|
288
|
+
cursors such as `text`, `pointer`, or `col-resize`. Add equivalent rules inside
|
|
289
|
+
shadow roots when shadow content declares its own cursor. Each iframe document
|
|
290
|
+
also needs its own consumer stylesheet. The exported
|
|
291
|
+
`domPointerDragActiveAttribute` constant contains the supported attribute name
|
|
292
|
+
for JavaScript and CSS-in-JS integrations.
|
|
293
|
+
|
|
267
294
|
## Targeting and overlays
|
|
268
295
|
|
|
269
296
|
Pointer-based targeting works without an overlay. `centerToCenter` and other
|
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 { domPointerDragActiveAttribute } from "./input/pointer-drag-state.js";
|
|
8
9
|
export type { DragEndResult, DragEndEvent, DragLifecycleCallbacks, DragLifecycleHelpers, DragSource, DragStartEvent, DragUpdateEvent, DropEvent, ActiveDragResetEvent, SortablePreview, } from "./runtime/lifecycle.js";
|
|
9
10
|
export type { RemeasureDropTargetsInput, SortableDropPlacement, } from "./runtime/drop-target-registry.js";
|
|
10
11
|
export type { OverlayReleaseMode } from "./runtime/types.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 { domPointerDragActiveAttribute } from "./input/pointer-drag-state.js";
|
|
7
8
|
export { centerToCenter, pointerToCenter, pointerToRectDistance, } from "./targeting/algorithms.js";
|
|
8
9
|
export { getDistanceToRect, maxOverlayCenterDistanceToRect, maxPointerDistanceToRect, } from "./targeting/constraints.js";
|
|
9
10
|
export { lockToXAxis, lockToYAxis, restrictToContainer, } from "./modifiers/built-ins.js";
|
|
@@ -24,5 +24,5 @@ export declare class KeyboardDragController {
|
|
|
24
24
|
isEnabled(): boolean;
|
|
25
25
|
handleSourceKeyDown(input: SourceKeyboardDragKeyDownInput): boolean;
|
|
26
26
|
handleActiveKeyDown(key: string): boolean;
|
|
27
|
-
bindWindowListeners(): () => void;
|
|
27
|
+
bindWindowListeners(targetWindow?: Window & typeof globalThis): () => void;
|
|
28
28
|
}
|
|
@@ -56,7 +56,7 @@ export class KeyboardDragController {
|
|
|
56
56
|
}
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
-
bindWindowListeners() {
|
|
59
|
+
bindWindowListeners(targetWindow = window) {
|
|
60
60
|
let isCleanedUp = false;
|
|
61
61
|
const handleKeyDown = (event) => {
|
|
62
62
|
if (!this.handleActiveKeyDown(event.key)) {
|
|
@@ -65,13 +65,13 @@ export class KeyboardDragController {
|
|
|
65
65
|
event.preventDefault();
|
|
66
66
|
event.stopPropagation();
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
targetWindow.addEventListener("keydown", handleKeyDown);
|
|
69
69
|
return () => {
|
|
70
70
|
if (isCleanedUp) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
isCleanedUp = true;
|
|
74
|
-
|
|
74
|
+
targetWindow.removeEventListener("keydown", handleKeyDown);
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -11,6 +11,7 @@ export class PointerActivationController {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const { activationDelay, activationDistance } = this.options.getConfiguration();
|
|
14
|
+
const targetWindow = request.element.ownerDocument.defaultView ?? window;
|
|
14
15
|
if (activationDelay === null && activationDistance === null) {
|
|
15
16
|
this.options.startImmediately(request);
|
|
16
17
|
return;
|
|
@@ -26,6 +27,7 @@ export class PointerActivationController {
|
|
|
26
27
|
pointerId: request.pointerId,
|
|
27
28
|
initialPointerPosition,
|
|
28
29
|
latestPointerPosition: initialPointerPosition,
|
|
30
|
+
targetWindow,
|
|
29
31
|
activationTimerId: null,
|
|
30
32
|
releasePendingPointerListeners: null,
|
|
31
33
|
};
|
|
@@ -55,17 +57,17 @@ export class PointerActivationController {
|
|
|
55
57
|
}
|
|
56
58
|
this.cancelPendingActivation();
|
|
57
59
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
targetWindow.addEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
|
|
61
|
+
targetWindow.addEventListener("pointerup", handlePointerEnd, globalPointerListenerCapture);
|
|
62
|
+
targetWindow.addEventListener("pointercancel", handlePointerEnd, globalPointerListenerCapture);
|
|
61
63
|
pendingActivation.releasePendingPointerListeners = () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
targetWindow.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
|
|
65
|
+
targetWindow.removeEventListener("pointerup", handlePointerEnd, globalPointerListenerCapture);
|
|
66
|
+
targetWindow.removeEventListener("pointercancel", handlePointerEnd, globalPointerListenerCapture);
|
|
65
67
|
};
|
|
66
68
|
this.pendingActivation = pendingActivation;
|
|
67
69
|
if (activationDelay !== null) {
|
|
68
|
-
pendingActivation.activationTimerId =
|
|
70
|
+
pendingActivation.activationTimerId = targetWindow.setTimeout(() => {
|
|
69
71
|
this.activatePendingPointerDrag(pendingActivation);
|
|
70
72
|
}, activationDelay);
|
|
71
73
|
}
|
|
@@ -90,7 +92,7 @@ export class PointerActivationController {
|
|
|
90
92
|
if (pendingActivation.activationTimerId === null) {
|
|
91
93
|
return;
|
|
92
94
|
}
|
|
93
|
-
|
|
95
|
+
pendingActivation.targetWindow.clearTimeout(pendingActivation.activationTimerId);
|
|
94
96
|
pendingActivation.activationTimerId = null;
|
|
95
97
|
}
|
|
96
98
|
activatePendingPointerDrag(pendingActivation) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const domPointerDragActiveAttribute = "data-dnd-pointer-drag-active";
|
|
2
|
+
const documentPointerDragStates = new WeakMap();
|
|
3
|
+
export function acquireDocumentPointerDragState(sourceDocument) {
|
|
4
|
+
const owner = {};
|
|
5
|
+
let state = documentPointerDragStates.get(sourceDocument);
|
|
6
|
+
if (!state) {
|
|
7
|
+
state = {
|
|
8
|
+
root: sourceDocument.documentElement,
|
|
9
|
+
previousValue: sourceDocument.documentElement.getAttribute(domPointerDragActiveAttribute),
|
|
10
|
+
owners: new Set(),
|
|
11
|
+
};
|
|
12
|
+
documentPointerDragStates.set(sourceDocument, state);
|
|
13
|
+
}
|
|
14
|
+
state.owners.add(owner);
|
|
15
|
+
state.root.setAttribute(domPointerDragActiveAttribute, "true");
|
|
16
|
+
let released = false;
|
|
17
|
+
return () => {
|
|
18
|
+
if (released) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
released = true;
|
|
22
|
+
if (!state?.owners.delete(owner) || state.owners.size > 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
documentPointerDragStates.delete(sourceDocument);
|
|
26
|
+
if (state.previousValue === null) {
|
|
27
|
+
state.root.removeAttribute(domPointerDragActiveAttribute);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
state.root.setAttribute(domPointerDragActiveAttribute, state.previousValue);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -8,3 +8,4 @@ export { createDomSortable, type CreateDomSortableInput, type DomSortableBehavio
|
|
|
8
8
|
export type { DomSortableRuntime } from "../sortable/sortable-registry.js";
|
|
9
9
|
export type { SortableAxis, SortablePlacementBoundary, } from "../sortable/sortable-options.js";
|
|
10
10
|
export { domDragHandleAttribute } from "../input/drag-handle.js";
|
|
11
|
+
export { domPointerDragActiveAttribute } from "../input/pointer-drag-state.js";
|
|
@@ -4,3 +4,4 @@ export { createDomDroppable, } from "../droppable/create-droppable.js";
|
|
|
4
4
|
export { createDomDropContainer, } from "../droppable/create-drop-container.js";
|
|
5
5
|
export { createDomSortable, } from "../sortable/create-sortable.js";
|
|
6
6
|
export { domDragHandleAttribute } from "../input/drag-handle.js";
|
|
7
|
+
export { domPointerDragActiveAttribute } from "../input/pointer-drag-state.js";
|
|
@@ -18,9 +18,12 @@ export declare class DragRuntime {
|
|
|
18
18
|
private activeDragModifiers;
|
|
19
19
|
private releaseActiveInputListeners;
|
|
20
20
|
private restoreTextSelectionSuppression;
|
|
21
|
+
private releasePointerDragState;
|
|
21
22
|
private releasePostDragClickSuppression;
|
|
22
23
|
private queuedPointerPosition;
|
|
23
24
|
private pointerFrameId;
|
|
25
|
+
private pointerFrameWindow;
|
|
26
|
+
private activeDragWindow;
|
|
24
27
|
private subscriptions;
|
|
25
28
|
private staleDomBindingRecords;
|
|
26
29
|
private lifecycleCallbacks;
|
|
@@ -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 { PointerActivationController } from "../input/pointer-activation.js";
|
|
7
|
+
import { acquireDocumentPointerDragState } from "../input/pointer-drag-state.js";
|
|
7
8
|
import { applyDragModifiers, createActiveDragModifiers, } from "../modifiers/pipeline.js";
|
|
8
9
|
import { getBuiltInTargetingAlgorithmKind, pointerToCenter, } from "../targeting/algorithms.js";
|
|
9
10
|
import { DropTargetRegistry, } from "./drop-target-registry.js";
|
|
@@ -20,9 +21,12 @@ export class DragRuntime {
|
|
|
20
21
|
activeDragModifiers = [];
|
|
21
22
|
releaseActiveInputListeners = null;
|
|
22
23
|
restoreTextSelectionSuppression = null;
|
|
24
|
+
releasePointerDragState = null;
|
|
23
25
|
releasePostDragClickSuppression = null;
|
|
24
26
|
queuedPointerPosition = null;
|
|
25
27
|
pointerFrameId = null;
|
|
28
|
+
pointerFrameWindow = null;
|
|
29
|
+
activeDragWindow = null;
|
|
26
30
|
subscriptions = new Set();
|
|
27
31
|
staleDomBindingRecords = new Set();
|
|
28
32
|
lifecycleCallbacks = {};
|
|
@@ -141,6 +145,7 @@ export class DragRuntime {
|
|
|
141
145
|
draggableId: input.draggableId,
|
|
142
146
|
group: input.group,
|
|
143
147
|
inputType: "keyboard",
|
|
148
|
+
element: input.element,
|
|
144
149
|
pointerPosition,
|
|
145
150
|
sourceRect,
|
|
146
151
|
});
|
|
@@ -177,8 +182,11 @@ export class DragRuntime {
|
|
|
177
182
|
if (this.pointerFrameId !== null) {
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
180
|
-
|
|
185
|
+
const targetWindow = this.activeDragWindow ?? window;
|
|
186
|
+
this.pointerFrameWindow = targetWindow;
|
|
187
|
+
this.pointerFrameId = targetWindow.requestAnimationFrame(() => {
|
|
181
188
|
this.pointerFrameId = null;
|
|
189
|
+
this.pointerFrameWindow = null;
|
|
182
190
|
const nextPointerPosition = this.queuedPointerPosition;
|
|
183
191
|
this.queuedPointerPosition = null;
|
|
184
192
|
if (nextPointerPosition) {
|
|
@@ -486,6 +494,10 @@ export class DragRuntime {
|
|
|
486
494
|
sortablePreview: { status: "inactive" },
|
|
487
495
|
};
|
|
488
496
|
this.setSession(nextSession);
|
|
497
|
+
this.activeDragWindow = input.element.ownerDocument.defaultView ?? window;
|
|
498
|
+
if (input.inputType === "pointer") {
|
|
499
|
+
this.releasePointerDragState = acquireDocumentPointerDragState(input.element.ownerDocument);
|
|
500
|
+
}
|
|
489
501
|
this.remeasureDropTargets({ group: input.group });
|
|
490
502
|
const dragStartEvent = {
|
|
491
503
|
draggableId: input.draggableId,
|
|
@@ -514,12 +526,12 @@ export class DragRuntime {
|
|
|
514
526
|
phase: "dragging",
|
|
515
527
|
},
|
|
516
528
|
});
|
|
517
|
-
this.suppressTextSelection();
|
|
529
|
+
this.suppressTextSelection(input.element.ownerDocument);
|
|
518
530
|
if (input.inputType === "pointer") {
|
|
519
531
|
this.bindPointerWindowListeners(input.pointerId, input.element);
|
|
520
532
|
}
|
|
521
533
|
else {
|
|
522
|
-
this.bindKeyboardWindowListeners();
|
|
534
|
+
this.bindKeyboardWindowListeners(this.activeDragWindow);
|
|
523
535
|
}
|
|
524
536
|
this.notifyDragStartLifecycle(dragStartEvent);
|
|
525
537
|
}
|
|
@@ -655,6 +667,7 @@ export class DragRuntime {
|
|
|
655
667
|
}
|
|
656
668
|
bindPointerWindowListeners(pointerId, initiatingElement) {
|
|
657
669
|
this.releaseActiveInputListeners?.();
|
|
670
|
+
const targetWindow = initiatingElement.ownerDocument.defaultView ?? window;
|
|
658
671
|
let listenersReleased = false;
|
|
659
672
|
const handlePointerMove = (event) => {
|
|
660
673
|
if (event.pointerId !== pointerId) {
|
|
@@ -685,29 +698,31 @@ export class DragRuntime {
|
|
|
685
698
|
this.clearPostDragClickSuppression();
|
|
686
699
|
this.cancelDrag();
|
|
687
700
|
};
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
701
|
+
targetWindow.addEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
|
|
702
|
+
targetWindow.addEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
|
|
703
|
+
targetWindow.addEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
|
|
691
704
|
this.releaseActiveInputListeners = () => {
|
|
692
705
|
if (listenersReleased) {
|
|
693
706
|
return;
|
|
694
707
|
}
|
|
695
708
|
listenersReleased = true;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
709
|
+
targetWindow.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
|
|
710
|
+
targetWindow.removeEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
|
|
711
|
+
targetWindow.removeEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
|
|
699
712
|
};
|
|
700
713
|
}
|
|
701
|
-
bindKeyboardWindowListeners() {
|
|
714
|
+
bindKeyboardWindowListeners(targetWindow) {
|
|
702
715
|
this.releaseActiveInputListeners?.();
|
|
703
|
-
this.releaseActiveInputListeners =
|
|
716
|
+
this.releaseActiveInputListeners =
|
|
717
|
+
this.keyboardDrag.bindWindowListeners(targetWindow);
|
|
704
718
|
}
|
|
705
719
|
suppressNextRelatedClick(initiatingElement) {
|
|
706
720
|
this.clearPostDragClickSuppression();
|
|
721
|
+
const targetWindow = initiatingElement.ownerDocument.defaultView ?? window;
|
|
707
722
|
let timeoutId = null;
|
|
708
723
|
const handleClick = (event) => {
|
|
709
724
|
if (event.detail === 0 ||
|
|
710
|
-
!(event.target instanceof Node) ||
|
|
725
|
+
!(event.target instanceof targetWindow.Node) ||
|
|
711
726
|
!initiatingElement.contains(event.target)) {
|
|
712
727
|
return;
|
|
713
728
|
}
|
|
@@ -716,47 +731,54 @@ export class DragRuntime {
|
|
|
716
731
|
event.stopImmediatePropagation();
|
|
717
732
|
};
|
|
718
733
|
const release = () => {
|
|
719
|
-
|
|
734
|
+
targetWindow.removeEventListener("click", handleClick, true);
|
|
720
735
|
if (timeoutId !== null) {
|
|
721
|
-
|
|
736
|
+
targetWindow.clearTimeout(timeoutId);
|
|
722
737
|
timeoutId = null;
|
|
723
738
|
}
|
|
724
739
|
if (this.releasePostDragClickSuppression === release) {
|
|
725
740
|
this.releasePostDragClickSuppression = null;
|
|
726
741
|
}
|
|
727
742
|
};
|
|
728
|
-
|
|
743
|
+
targetWindow.addEventListener("click", handleClick, true);
|
|
729
744
|
this.releasePostDragClickSuppression = release;
|
|
730
|
-
timeoutId =
|
|
745
|
+
timeoutId = targetWindow.setTimeout(release, 0);
|
|
731
746
|
}
|
|
732
747
|
clearPostDragClickSuppression() {
|
|
733
748
|
const release = this.releasePostDragClickSuppression;
|
|
734
749
|
this.releasePostDragClickSuppression = null;
|
|
735
750
|
release?.();
|
|
736
751
|
}
|
|
737
|
-
suppressTextSelection() {
|
|
752
|
+
suppressTextSelection(sourceDocument) {
|
|
738
753
|
this.restoreTextSelectionSuppression?.();
|
|
739
|
-
const root =
|
|
740
|
-
const body =
|
|
754
|
+
const root = sourceDocument.documentElement;
|
|
755
|
+
const body = sourceDocument.body;
|
|
741
756
|
const previousRootUserSelect = root.style.userSelect;
|
|
742
|
-
const previousBodyUserSelect = body
|
|
757
|
+
const previousBodyUserSelect = body?.style.userSelect;
|
|
743
758
|
root.style.userSelect = "none";
|
|
744
|
-
body
|
|
759
|
+
if (body) {
|
|
760
|
+
body.style.userSelect = "none";
|
|
761
|
+
}
|
|
745
762
|
this.restoreTextSelectionSuppression = () => {
|
|
746
763
|
root.style.userSelect = previousRootUserSelect;
|
|
747
|
-
body
|
|
764
|
+
if (body) {
|
|
765
|
+
body.style.userSelect = previousBodyUserSelect ?? "";
|
|
766
|
+
}
|
|
748
767
|
};
|
|
749
768
|
}
|
|
750
769
|
resetActiveDragState() {
|
|
751
770
|
this.cancelQueuedPointerUpdate();
|
|
752
771
|
this.setSession({ status: "idle" });
|
|
753
772
|
this.activeDragModifiers = [];
|
|
773
|
+
this.activeDragWindow = null;
|
|
754
774
|
}
|
|
755
775
|
releaseActiveInputResources() {
|
|
756
776
|
const releaseActiveInputListeners = this.releaseActiveInputListeners;
|
|
757
777
|
this.releaseActiveInputListeners = null;
|
|
758
778
|
const restoreTextSelectionSuppression = this.restoreTextSelectionSuppression;
|
|
759
779
|
this.restoreTextSelectionSuppression = null;
|
|
780
|
+
const releasePointerDragState = this.releasePointerDragState;
|
|
781
|
+
this.releasePointerDragState = null;
|
|
760
782
|
let releaseError;
|
|
761
783
|
let hasReleaseError = false;
|
|
762
784
|
try {
|
|
@@ -775,6 +797,15 @@ export class DragRuntime {
|
|
|
775
797
|
hasReleaseError = true;
|
|
776
798
|
}
|
|
777
799
|
}
|
|
800
|
+
try {
|
|
801
|
+
releasePointerDragState?.();
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
if (!hasReleaseError) {
|
|
805
|
+
releaseError = error;
|
|
806
|
+
hasReleaseError = true;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
778
809
|
if (hasReleaseError) {
|
|
779
810
|
throw releaseError;
|
|
780
811
|
}
|
|
@@ -784,8 +815,9 @@ export class DragRuntime {
|
|
|
784
815
|
}
|
|
785
816
|
flushQueuedPointerUpdate() {
|
|
786
817
|
if (this.pointerFrameId !== null) {
|
|
787
|
-
window.cancelAnimationFrame(this.pointerFrameId);
|
|
818
|
+
(this.pointerFrameWindow ?? window).cancelAnimationFrame(this.pointerFrameId);
|
|
788
819
|
this.pointerFrameId = null;
|
|
820
|
+
this.pointerFrameWindow = null;
|
|
789
821
|
}
|
|
790
822
|
const nextPointerPosition = this.queuedPointerPosition;
|
|
791
823
|
this.queuedPointerPosition = null;
|
|
@@ -795,8 +827,9 @@ export class DragRuntime {
|
|
|
795
827
|
}
|
|
796
828
|
cancelQueuedPointerUpdate() {
|
|
797
829
|
if (this.pointerFrameId !== null) {
|
|
798
|
-
window.cancelAnimationFrame(this.pointerFrameId);
|
|
830
|
+
(this.pointerFrameWindow ?? window).cancelAnimationFrame(this.pointerFrameId);
|
|
799
831
|
this.pointerFrameId = null;
|
|
832
|
+
this.pointerFrameWindow = null;
|
|
800
833
|
}
|
|
801
834
|
this.queuedPointerPosition = null;
|
|
802
835
|
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -36,13 +36,13 @@ export type RequestDragStartInput = PointerDragActivationRequest;
|
|
|
36
36
|
type BaseStartDragInput = {
|
|
37
37
|
draggableId: string;
|
|
38
38
|
group: DragGroup;
|
|
39
|
+
element: HTMLElement;
|
|
39
40
|
pointerPosition: Point;
|
|
40
41
|
sourceRect: DragRect;
|
|
41
42
|
};
|
|
42
43
|
export type StartDragInput = (BaseStartDragInput & {
|
|
43
44
|
inputType: "pointer";
|
|
44
45
|
pointerId: number;
|
|
45
|
-
element: HTMLElement;
|
|
46
46
|
}) | (BaseStartDragInput & {
|
|
47
47
|
inputType: "keyboard";
|
|
48
48
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mk-drag-and-drop/dom",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
@@ -42,6 +42,14 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"sideEffects": false,
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"eslint": "^8.57.0",
|
|
47
|
+
"jsdom": "^24.1.3",
|
|
48
|
+
"typescript": "5.5.4",
|
|
49
|
+
"vitest": "^2.1.9",
|
|
50
|
+
"@repo/typescript-config": "0.0.0",
|
|
51
|
+
"@repo/eslint-config": "0.0.0"
|
|
52
|
+
},
|
|
45
53
|
"scripts": {
|
|
46
54
|
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
47
55
|
"build": "pnpm run clean && tsc -p tsconfig.json",
|
|
@@ -49,13 +57,5 @@
|
|
|
49
57
|
"lint": "eslint \"src/**/*.ts\"",
|
|
50
58
|
"test": "vitest run",
|
|
51
59
|
"test:watch": "vitest"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"@repo/eslint-config": "workspace:*",
|
|
55
|
-
"@repo/typescript-config": "workspace:*",
|
|
56
|
-
"eslint": "^8.57.0",
|
|
57
|
-
"jsdom": "^24.1.3",
|
|
58
|
-
"typescript": "5.5.4",
|
|
59
|
-
"vitest": "^2.1.9"
|
|
60
60
|
}
|
|
61
|
-
}
|
|
61
|
+
}
|