@mk-drag-and-drop/dom 0.1.0 → 0.3.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/README.md +111 -35
- package/dist/controller/controller-internals.d.ts +4 -4
- package/dist/controller/create-drag-controller.d.ts +11 -8
- package/dist/controller/create-drag-controller.js +29 -53
- package/dist/draggable/create-draggable-binding.js +3 -3
- package/dist/droppable/create-drop-container-binding.js +4 -4
- package/dist/droppable/create-drop-container.d.ts +1 -1
- package/dist/droppable/create-drop-container.js +3 -3
- package/dist/droppable/create-droppable-binding.js +4 -4
- package/dist/droppable/create-droppable.d.ts +1 -1
- package/dist/droppable/create-droppable.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/input/pointer-activation.d.ts +4 -2
- package/dist/input/pointer-activation.js +28 -16
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/runtime/drag-runtime-scope.d.ts +21 -0
- package/dist/runtime/{drag-runtime-handle.js → drag-runtime-scope.js} +8 -9
- package/dist/runtime/drag-runtime.d.ts +21 -17
- package/dist/runtime/drag-runtime.js +279 -155
- package/dist/runtime/lifecycle.d.ts +7 -0
- package/dist/runtime/types.d.ts +3 -2
- package/dist/sortable/create-sortable-binding.js +4 -4
- package/dist/sortable/create-sortable.d.ts +1 -1
- package/dist/sortable/create-sortable.js +3 -3
- package/dist/sortable/sortable-preview.js +20 -17
- package/dist/sortable/sortable-registry.d.ts +15 -6
- package/dist/sortable/sortable-registry.js +65 -47
- package/package.json +2 -1
- package/dist/runtime/drag-runtime-handle.d.ts +0 -22
|
@@ -5,7 +5,7 @@ export class PointerActivationController {
|
|
|
5
5
|
this.options = options;
|
|
6
6
|
}
|
|
7
7
|
request(request) {
|
|
8
|
-
this.
|
|
8
|
+
this.cancelPendingActivation();
|
|
9
9
|
if (this.options.isDragging()) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
@@ -25,8 +25,8 @@ export class PointerActivationController {
|
|
|
25
25
|
pointerId: request.pointerId,
|
|
26
26
|
initialPointerPosition,
|
|
27
27
|
latestPointerPosition: initialPointerPosition,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
activationTimerId: null,
|
|
29
|
+
releasePendingPointerListeners: null,
|
|
30
30
|
};
|
|
31
31
|
const handlePointerMove = (event) => {
|
|
32
32
|
if (event.pointerId !== pendingActivation.pointerId) {
|
|
@@ -45,46 +45,58 @@ export class PointerActivationController {
|
|
|
45
45
|
const distanceSquared = distanceX * distanceX + distanceY * distanceY;
|
|
46
46
|
const activationDistanceSquared = activationDistance * activationDistance;
|
|
47
47
|
if (distanceSquared >= activationDistanceSquared) {
|
|
48
|
-
this.
|
|
48
|
+
this.activatePendingPointerDrag(pendingActivation);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
const handlePointerEnd = (event) => {
|
|
52
52
|
if (event.pointerId !== pendingActivation.pointerId) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
this.
|
|
55
|
+
this.cancelPendingActivation();
|
|
56
56
|
};
|
|
57
57
|
window.addEventListener("pointermove", handlePointerMove);
|
|
58
58
|
window.addEventListener("pointerup", handlePointerEnd);
|
|
59
59
|
window.addEventListener("pointercancel", handlePointerEnd);
|
|
60
|
-
pendingActivation.
|
|
60
|
+
pendingActivation.releasePendingPointerListeners = () => {
|
|
61
61
|
window.removeEventListener("pointermove", handlePointerMove);
|
|
62
62
|
window.removeEventListener("pointerup", handlePointerEnd);
|
|
63
63
|
window.removeEventListener("pointercancel", handlePointerEnd);
|
|
64
64
|
};
|
|
65
|
+
this.pendingActivation = pendingActivation;
|
|
65
66
|
if (activationDelay !== null) {
|
|
66
|
-
pendingActivation.
|
|
67
|
-
this.
|
|
67
|
+
pendingActivation.activationTimerId = window.setTimeout(() => {
|
|
68
|
+
this.activatePendingPointerDrag(pendingActivation);
|
|
68
69
|
}, activationDelay);
|
|
69
70
|
}
|
|
70
|
-
this.pendingActivation = pendingActivation;
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
cancelPendingActivation() {
|
|
73
73
|
const pendingActivation = this.pendingActivation;
|
|
74
74
|
if (!pendingActivation) {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
this.clearPendingActivation(pendingActivation);
|
|
78
|
+
}
|
|
79
|
+
clearPendingActivation(pendingActivation) {
|
|
80
|
+
if (this.pendingActivation === pendingActivation) {
|
|
81
|
+
this.pendingActivation = null;
|
|
82
|
+
}
|
|
83
|
+
this.clearPendingActivationTimer(pendingActivation);
|
|
84
|
+
const releasePendingPointerListeners = pendingActivation.releasePendingPointerListeners;
|
|
85
|
+
pendingActivation.releasePendingPointerListeners = null;
|
|
86
|
+
releasePendingPointerListeners?.();
|
|
87
|
+
}
|
|
88
|
+
clearPendingActivationTimer(pendingActivation) {
|
|
89
|
+
if (pendingActivation.activationTimerId === null) {
|
|
90
|
+
return;
|
|
79
91
|
}
|
|
80
|
-
pendingActivation.
|
|
81
|
-
|
|
92
|
+
window.clearTimeout(pendingActivation.activationTimerId);
|
|
93
|
+
pendingActivation.activationTimerId = null;
|
|
82
94
|
}
|
|
83
|
-
|
|
95
|
+
activatePendingPointerDrag(pendingActivation) {
|
|
84
96
|
if (this.pendingActivation !== pendingActivation) {
|
|
85
97
|
return;
|
|
86
98
|
}
|
|
87
|
-
this.
|
|
99
|
+
this.clearPendingActivation(pendingActivation);
|
|
88
100
|
this.options.activate({
|
|
89
101
|
draggableId: pendingActivation.draggableId,
|
|
90
102
|
group: pendingActivation.group,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { DragOverlayHostUpdate, DragOverlayPhase, DragOverlayRenderState, DragState, } from "../runtime/types.js";
|
|
1
|
+
export { createDragRuntimeScope, type DragRuntimeScope, type DragRuntimeScopeConfigureInput, type DragRuntimeScopeOptions, } from "../runtime/drag-runtime-scope.js";
|
|
2
|
+
export type { DragOverlayHostUpdate, DragOverlayPhase, DragOverlayRenderState, DragState, OverlayReleaseMode, } from "../runtime/types.js";
|
|
3
3
|
export type { DragRuntimeSubscription } from "../runtime/lifecycle.js";
|
|
4
4
|
export { createDomDraggable, type CreateDomDraggableInput, type DomDraggableBehavior, type DomDraggableKeyDownEvent, type DomDraggablePointerDownEvent, type DomDraggableRuntime, } from "../draggable/create-draggable.js";
|
|
5
5
|
export { createDomDroppable, type CreateDomDroppableInput, type DomDroppableBehavior, type DomDroppableRuntime, } from "../droppable/create-droppable.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createDragRuntimeScope, } from "../runtime/drag-runtime-scope.js";
|
|
2
2
|
export { createDomDraggable, } from "../draggable/create-draggable.js";
|
|
3
3
|
export { createDomDroppable, } from "../droppable/create-droppable.js";
|
|
4
4
|
export { createDomDropContainer, } from "../droppable/create-drop-container.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DragRect } from "../geometry/rects.js";
|
|
2
|
+
import type { DomDraggableRuntime } from "../draggable/create-draggable.js";
|
|
3
|
+
import type { DomDropContainerRuntime } from "../droppable/create-drop-container.js";
|
|
4
|
+
import type { DomDroppableRuntime } from "../droppable/create-droppable.js";
|
|
5
|
+
import type { DomSortableRuntime } from "../sortable/sortable-registry.js";
|
|
6
|
+
import { type StaleDomBindingRecord } from "./drag-runtime.js";
|
|
7
|
+
import type { DragRuntimeConfigureInput, DragRuntimeOptions } from "./types.js";
|
|
8
|
+
export type DragRuntimeScopeOptions = DragRuntimeOptions;
|
|
9
|
+
export type DragRuntimeScopeConfigureInput = DragRuntimeConfigureInput;
|
|
10
|
+
export type DragRuntimeScope = DomDraggableRuntime & DomDroppableRuntime & DomDropContainerRuntime & DomSortableRuntime & {
|
|
11
|
+
configure: (input: DragRuntimeScopeConfigureInput) => void;
|
|
12
|
+
cancelDrag: () => void;
|
|
13
|
+
releaseActiveDragResources: () => void;
|
|
14
|
+
setOverlayRect: (overlayRect: DragRect | null) => void;
|
|
15
|
+
};
|
|
16
|
+
export type InternalStaleDomBindingRuntime = {
|
|
17
|
+
registerStaleDomBinding: (record: StaleDomBindingRecord) => () => void;
|
|
18
|
+
pruneDisconnectedDomBindings: () => void;
|
|
19
|
+
getStaleDomBindingRecordCount: () => number;
|
|
20
|
+
};
|
|
21
|
+
export declare function createDragRuntimeScope(options?: DragRuntimeScopeOptions): DragRuntimeScope;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DragRuntime } from "./drag-runtime.js";
|
|
2
|
-
export function
|
|
2
|
+
export function createDragRuntimeScope(options) {
|
|
3
3
|
const runtime = new DragRuntime(options);
|
|
4
|
-
const
|
|
4
|
+
const scope = {
|
|
5
5
|
configure: (input) => runtime.configure(input),
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
cancelDrag: () => runtime.cancelDrag(),
|
|
7
|
+
releaseActiveDragResources: () => runtime.releaseActiveDragResources(),
|
|
8
8
|
setOverlayRect: (overlayRect) => runtime.setOverlayRect(overlayRect),
|
|
9
9
|
requestDragStart: (input) => runtime.requestDragStart(input),
|
|
10
10
|
isKeyboardDragEnabled: () => runtime.isKeyboardDragEnabled(),
|
|
@@ -23,11 +23,10 @@ export function createDragRuntimeHandle(options) {
|
|
|
23
23
|
},
|
|
24
24
|
getDropTargetRegistration: (dropTargetId, group) => runtime.getDropTargetRegistration(dropTargetId, group),
|
|
25
25
|
subscribe: (subscription) => runtime.subscribe(subscription),
|
|
26
|
-
onDispose: (callback) => runtime.onDispose(callback),
|
|
27
26
|
remeasureDropTargets: (input) => runtime.remeasureDropTargets(input),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
registerStaleDomBinding: (record) => runtime.registerStaleDomBinding(record),
|
|
28
|
+
pruneDisconnectedDomBindings: () => runtime.pruneDisconnectedDomBindings(),
|
|
29
|
+
getStaleDomBindingRecordCount: () => runtime.getStaleDomBindingRecordCount(),
|
|
31
30
|
};
|
|
32
|
-
return
|
|
31
|
+
return scope;
|
|
33
32
|
}
|
|
@@ -3,8 +3,8 @@ import { type KeyboardMoveDirection, type SourceKeyboardDragKeyDownInput as Keyb
|
|
|
3
3
|
import { type DragGroup, type RegisterDropTargetOptions, type RemeasureDropTargetsInput } from "./drop-target-registry.js";
|
|
4
4
|
import type { DragRuntimeSubscription } from "./lifecycle.js";
|
|
5
5
|
import type { DragRuntimeConfigureInput, DragRuntimeOptions, Point, RequestDragStartInput, RequestKeyboardDragStartInput } from "./types.js";
|
|
6
|
-
export type
|
|
7
|
-
|
|
6
|
+
export type StaleDomBindingRecord = {
|
|
7
|
+
release: () => void;
|
|
8
8
|
isConnected: () => boolean;
|
|
9
9
|
};
|
|
10
10
|
export declare class DragRuntime {
|
|
@@ -16,13 +16,12 @@ export declare class DragRuntime {
|
|
|
16
16
|
private session;
|
|
17
17
|
private modifiers;
|
|
18
18
|
private activeDragModifiers;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
19
|
+
private releaseActiveInputListeners;
|
|
20
|
+
private restoreTextSelectionSuppression;
|
|
21
21
|
private queuedPointerPosition;
|
|
22
22
|
private pointerFrameId;
|
|
23
23
|
private subscriptions;
|
|
24
|
-
private
|
|
25
|
-
private bindingCleanupRecords;
|
|
24
|
+
private staleDomBindingRecords;
|
|
26
25
|
private lifecycleCallbacks;
|
|
27
26
|
private lifecycleHelpers;
|
|
28
27
|
private lifecycleDropTargetRectSnapshot;
|
|
@@ -32,7 +31,7 @@ export declare class DragRuntime {
|
|
|
32
31
|
private updateOverlayHost;
|
|
33
32
|
private targetingAlgorithm;
|
|
34
33
|
private hasDragOverlay;
|
|
35
|
-
private
|
|
34
|
+
private overlayRelease;
|
|
36
35
|
private targetingConstraint;
|
|
37
36
|
private pointerActivation;
|
|
38
37
|
private keyboardDrag;
|
|
@@ -45,31 +44,35 @@ export declare class DragRuntime {
|
|
|
45
44
|
moveKeyboardDrag(direction: KeyboardMoveDirection): void;
|
|
46
45
|
updatePointer(rawPointerPosition: Point): void;
|
|
47
46
|
private updatePointerNow;
|
|
47
|
+
private updatePointerNowOrRelease;
|
|
48
|
+
private finishDragAfterQueuedPointerUpdate;
|
|
48
49
|
endDrag(): void;
|
|
49
50
|
cancelDrag(): void;
|
|
51
|
+
cancelPendingActivation(): void;
|
|
50
52
|
registerDropTarget(dropTargetId: string, element: HTMLElement, group: DragGroup, options?: RegisterDropTargetOptions): void;
|
|
51
53
|
unregisterDropTarget(dropTargetId: string, element?: HTMLElement): void;
|
|
52
54
|
registerDropContainer(containerId: string, element: HTMLElement, group: DragGroup): void;
|
|
53
55
|
unregisterDropContainer(containerId: string, element?: HTMLElement): void;
|
|
54
|
-
|
|
56
|
+
releaseActiveDragResources(): void;
|
|
57
|
+
private releaseActiveDragResourcesAndRethrow;
|
|
55
58
|
getDropTargetRect(dropTargetId: string): DragRect | null;
|
|
56
59
|
getDropTargetRegistration(dropTargetId: string, group?: DragGroup): import("./drop-target-registry.js").DropTargetRegistration | null;
|
|
57
60
|
getCurrentDragRect(): DragRect | null;
|
|
58
61
|
setOverlayRect(overlayRect: DragRect | null): void;
|
|
59
62
|
remeasureDropTargets(input?: RemeasureDropTargetsInput): void;
|
|
60
63
|
subscribe(subscription: DragRuntimeSubscription): () => void;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
getBindingCleanupRecordCount(): number;
|
|
65
|
-
dispose(): void;
|
|
64
|
+
registerStaleDomBinding(record: StaleDomBindingRecord): () => void;
|
|
65
|
+
pruneDisconnectedDomBindings(): void;
|
|
66
|
+
getStaleDomBindingRecordCount(): number;
|
|
66
67
|
private startDragNow;
|
|
67
68
|
private finishDrag;
|
|
69
|
+
private releaseOverlayAfterDrag;
|
|
68
70
|
private bindPointerWindowListeners;
|
|
69
71
|
private bindKeyboardWindowListeners;
|
|
70
72
|
private suppressTextSelection;
|
|
71
73
|
private resetActiveDragState;
|
|
72
|
-
private
|
|
74
|
+
private releaseActiveInputResources;
|
|
75
|
+
private clearOverlayHost;
|
|
73
76
|
private flushQueuedPointerUpdate;
|
|
74
77
|
private cancelQueuedPointerUpdate;
|
|
75
78
|
private setSession;
|
|
@@ -85,12 +88,13 @@ export declare class DragRuntime {
|
|
|
85
88
|
private getAvailableDropTargets;
|
|
86
89
|
private getCurrentDragRectAt;
|
|
87
90
|
private removeDisconnectedDropTargets;
|
|
88
|
-
private
|
|
89
|
-
private disposeBindingCleanupRecords;
|
|
91
|
+
private pruneDisconnectedDomBindingRecords;
|
|
90
92
|
private clearActiveDropTargetIdIfRemoved;
|
|
91
|
-
private
|
|
93
|
+
private notifyDragStartSubscriptions;
|
|
94
|
+
private notifyDragStartLifecycle;
|
|
92
95
|
private notifyDragUpdate;
|
|
93
96
|
private notifyDragEnd;
|
|
94
97
|
private notifyDrop;
|
|
98
|
+
private notifyActiveDragReset;
|
|
95
99
|
}
|
|
96
100
|
export declare function createDragRuntime(options?: DragRuntimeOptions): DragRuntime;
|