Primitives / foldkit-primitives/dom

PointerDrag

const · packages/primitives/src/dom/pointer-drag.ts:100

const PointerDrag: Mount.MountDefinitionWithArgs<
  'PointerDrag',
  {
    attribute: Schema.String
    targets: Schema.optionalKey<
      Schema.Struct<{
        readonly attribute: Schema.String
        readonly within: Schema.String
      }>
    >
    part: Schema.optionalKey<Schema.String>
  },
  | { readonly _tag: 'DragStarted'; readonly id: string }
  | {
      readonly _tag: 'DraggedOver'
      readonly over: {
        readonly id: string
        readonly zone: 'before' | 'inside' | 'after'
        readonly part?: string
      } | null
      readonly region?: boolean
    }
  | {
      readonly _tag: 'DragDropped'
      readonly id: string
      readonly over: {
        readonly id: string
        readonly zone: 'before' | 'inside' | 'after'
        readonly part?: string
      } | null
      readonly region?: boolean
    }
  | { readonly _tag: 'DragCancelled'; readonly id: string }
>

Dragging one marked descendant of an element onto another, as a Mount. A descendant is marked by an attribute whose value is its id, as Targets marks them; a press on one that then moves past a threshold starts a drag, and the pointer's place over another marked descendant is reported with the zone of it the pointer is in: its first third (before), its middle (inside), or its last third (after). Releasing drops, and Escape or a cancelled pointer ends the drag with nothing dropped.

It writes no roles, no tabindex and no key handling, so the marked elements can be anything: a tree's rows, a canvas's nodes. The keyboard's way to do what a drag does is the parent's to give. Geometry is measured when the pointer moves and never kept; what a drop means is the parent's update.