Docs/API

Common types

The small types every API page refers to — keys, coordinates, rects, element refs and reactive options.

Options that react

Most options take a value, a ref or a getter, and are read when they are needed: a change applies to the next drag at the latest. The tables mark them value · ref · getter.

A value, a getter or any ref (writable, shallow, computed, readonly — e.g. from useTemplateRef) that the library only reads. Unlike Vue's MaybeRefOrGetter it accepts Ref<string> where string | number is expected.

type MaybeReadonlyRefOrGetter = T | Readonly<Ref<T>> | (() => T)

A value or any ref, for options where a function is a value of its own (an overlay component, an accept rule, a custom animation), so a getter can't be told apart. Hold components in a shallowRef (or a computed): Vue must not make them reactive.

type MaybeReadonlyRef = T | Readonly<Ref<T>>

Elements

The element a composable works on (makeDraggable(target)): the element, a template ref (useTemplateRef) or a getter. It may change (a v-if): the library follows it.

type MaybeElementRef = MaybeReadonlyRefOrGetter<MaybeElement>

An element: an HTML or SVG element, or a component instance (its root element, $el), as a template ref gives them. null or undefined while there is none (not mounted yet).

type MaybeElement = | HTMLElement | SVGElement | ComponentRef | null | undefined

Keys and geometry

An id or a key: of a draggable, a drop target, a list, an item of a list.

type Key = string | number

A point or an offset, in px: a position from the viewport's top-left corner, or an offset from where the drag started (delta, transform).

number

Horizontal, growing to the right.

number

Vertical, growing downward.

A width and a height, in px.

number

Width in px.

number

Height in px.

A box in px, in viewport coordinates, as getBoundingClientRect() gives it.

number

Its top edge, from the top of the viewport.

number

Its left edge, from the left of the viewport.

number

Its width.

number

Its height.

number

Its right edge, from the left of the viewport: left + width.

number

Its bottom edge, from the top of the viewport: top + height.

Status

What the provider is doing:

  • 'idle': nothing;
  • 'activating': a press waits for its activation constraint (a distance, a long press);
  • 'dragging': a drag runs;
  • 'dropping': a drop is decided (an async onBeforeDrop), or an overlay still lands;
  • 'selecting': a selection area draws its band.
type DnDStatus = | 'idle' | 'activating' | 'dragging' | 'dropping' | 'selecting'

How a drag moves, whichever sensor drives it (SensorActivation.type): 'pointer' follows points, 'keyboard' moves by items.

type SensorType = 'pointer' | 'keyboard'

The kind of pointer that pressed (PointerEvent.pointerType): activation is set per kind.

type PointerKind = 'mouse' | 'touch' | 'pen'

A value, or a promise of it: what a hook that may be async returns (onBeforeDrop).

type MaybePromise = T | Promise<T>