@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.
Files changed (30) hide show
  1. package/README.md +111 -35
  2. package/dist/controller/controller-internals.d.ts +4 -4
  3. package/dist/controller/create-drag-controller.d.ts +11 -8
  4. package/dist/controller/create-drag-controller.js +29 -53
  5. package/dist/draggable/create-draggable-binding.js +3 -3
  6. package/dist/droppable/create-drop-container-binding.js +4 -4
  7. package/dist/droppable/create-drop-container.d.ts +1 -1
  8. package/dist/droppable/create-drop-container.js +3 -3
  9. package/dist/droppable/create-droppable-binding.js +4 -4
  10. package/dist/droppable/create-droppable.d.ts +1 -1
  11. package/dist/droppable/create-droppable.js +3 -3
  12. package/dist/index.d.ts +1 -0
  13. package/dist/input/pointer-activation.d.ts +4 -2
  14. package/dist/input/pointer-activation.js +28 -16
  15. package/dist/integration/index.d.ts +2 -2
  16. package/dist/integration/index.js +1 -1
  17. package/dist/runtime/drag-runtime-scope.d.ts +21 -0
  18. package/dist/runtime/{drag-runtime-handle.js → drag-runtime-scope.js} +8 -9
  19. package/dist/runtime/drag-runtime.d.ts +21 -17
  20. package/dist/runtime/drag-runtime.js +279 -155
  21. package/dist/runtime/lifecycle.d.ts +7 -0
  22. package/dist/runtime/types.d.ts +3 -2
  23. package/dist/sortable/create-sortable-binding.js +4 -4
  24. package/dist/sortable/create-sortable.d.ts +1 -1
  25. package/dist/sortable/create-sortable.js +3 -3
  26. package/dist/sortable/sortable-preview.js +20 -17
  27. package/dist/sortable/sortable-registry.d.ts +15 -6
  28. package/dist/sortable/sortable-registry.js +65 -47
  29. package/package.json +2 -1
  30. 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.cancel();
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
- timeoutId: null,
29
- cleanupWindowListeners: () => { },
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.activatePending(pendingActivation);
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.cancel();
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.cleanupWindowListeners = () => {
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.timeoutId = window.setTimeout(() => {
67
- this.activatePending(pendingActivation);
67
+ pendingActivation.activationTimerId = window.setTimeout(() => {
68
+ this.activatePendingPointerDrag(pendingActivation);
68
69
  }, activationDelay);
69
70
  }
70
- this.pendingActivation = pendingActivation;
71
71
  }
72
- cancel() {
72
+ cancelPendingActivation() {
73
73
  const pendingActivation = this.pendingActivation;
74
74
  if (!pendingActivation) {
75
75
  return;
76
76
  }
77
- if (pendingActivation.timeoutId !== null) {
78
- window.clearTimeout(pendingActivation.timeoutId);
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.cleanupWindowListeners();
81
- this.pendingActivation = null;
92
+ window.clearTimeout(pendingActivation.activationTimerId);
93
+ pendingActivation.activationTimerId = null;
82
94
  }
83
- activatePending(pendingActivation) {
95
+ activatePendingPointerDrag(pendingActivation) {
84
96
  if (this.pendingActivation !== pendingActivation) {
85
97
  return;
86
98
  }
87
- this.cancel();
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 { createDragRuntimeHandle, type DragRuntimeHandle, type DragRuntimeHandleConfigureInput, type DragRuntimeHandleOptions, } from "../runtime/drag-runtime-handle.js";
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 { createDragRuntimeHandle, } from "../runtime/drag-runtime-handle.js";
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 createDragRuntimeHandle(options) {
2
+ export function createDragRuntimeScope(options) {
3
3
  const runtime = new DragRuntime(options);
4
- const handle = {
4
+ const scope = {
5
5
  configure: (input) => runtime.configure(input),
6
- cleanup: () => runtime.cleanup(),
7
- dispose: () => runtime.dispose(),
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
- registerBindingCleanup: (record) => runtime.registerBindingCleanup(record),
29
- pruneDisconnectedBindingCleanups: () => runtime.pruneDisconnectedBindingCleanups(),
30
- getBindingCleanupRecordCount: () => runtime.getBindingCleanupRecordCount(),
27
+ registerStaleDomBinding: (record) => runtime.registerStaleDomBinding(record),
28
+ pruneDisconnectedDomBindings: () => runtime.pruneDisconnectedDomBindings(),
29
+ getStaleDomBindingRecordCount: () => runtime.getStaleDomBindingRecordCount(),
31
30
  };
32
- return handle;
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 BindingCleanupRecord = {
7
- cleanup: () => void;
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 cleanupWindowListeners;
20
- private cleanupTextSelectionSuppression;
19
+ private releaseActiveInputListeners;
20
+ private restoreTextSelectionSuppression;
21
21
  private queuedPointerPosition;
22
22
  private pointerFrameId;
23
23
  private subscriptions;
24
- private disposeCallbacks;
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 keepOverlayOnDrop;
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
- cleanup(): void;
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
- onDispose(callback: () => void): () => void;
62
- registerBindingCleanup(record: BindingCleanupRecord): () => void;
63
- pruneDisconnectedBindingCleanups(): void;
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 cleanupActiveDragResources;
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 pruneDisconnectedBindingCleanupRecords;
89
- private disposeBindingCleanupRecords;
91
+ private pruneDisconnectedDomBindingRecords;
90
92
  private clearActiveDropTargetIdIfRemoved;
91
- private notifyDragStart;
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;