Skip to content

DragDrop

Defined in: src/modules/drag-drop/drag-drop.ts:84

One drag-and-drop interaction at a time: grab a payload, follow the pointer, find the target under it that accepts the payload, drop there or snap back.

It takes plain points and returns a result. It binds no input listener, captures no pointer and draws nothing, so the same session drives a DOM UI and a canvas board alike: feed it from DOM events, from modules/input, or from a tick system, and draw the dragged item at session.position.

TPayload

TTarget

new DragDrop<TPayload, TTarget>(options): DragDrop<TPayload, TTarget>

Defined in: src/modules/drag-drop/drag-drop.ts:90

DragDropOptions<TPayload, TTarget>

DragDrop<TPayload, TTarget>

get hovered(): TTarget | null

Defined in: src/modules/drag-drop/drag-drop.ts:128

The target the item would land on if released now, or null. Use it to highlight a drop zone.

TTarget | null


get session(): DragSession<TPayload> | null

Defined in: src/modules/drag-drop/drag-drop.ts:160

The drag in progress, or null.

DragSession<TPayload> | null

begin(payload, pointer, origin?): void

Defined in: src/modules/drag-drop/drag-drop.ts:101

Press on payload with the pointer at pointer. origin is the dragged item’s own origin (its top-left, usually), so the item keeps the grab offset instead of jumping to the pointer. Replaces any drag in progress.

TPayload

Vec2

Vec2 = pointer

void


cancel(): void

Defined in: src/modules/drag-drop/drag-drop.ts:108

Abandon the drag in progress without a drop.

void


end(pointer?): DropResult<TPayload, TTarget> | null

Defined in: src/modules/drag-drop/drag-drop.ts:117

Release, optionally at a final pointer, and close the session. Returns the drop result, or null when no drag was in progress or the pointer never crossed the threshold (a click, not a drag).

Vec2

DropResult<TPayload, TTarget> | null


move(pointer): void

Defined in: src/modules/drag-drop/drag-drop.ts:133

Update the pointer. Does nothing without a drag in progress.

Vec2

void