Primitives / foldkit-primitives/interaction

Move

namespace · packages/primitives/src/interaction/move.ts:7

export * as Move from './move.js'

Move as a Behavior: attaches the foldkit-primitives/dom Mount to a draggable slot and maps its facts into the view's Messages. No Bundle: a drag's meaning (a threshold, a snap, a reorder) is the parent's update, and the deltas are already facts.

In the guides

Members

Move.behavior

function · packages/primitives/src/interaction/move.ts:21

function behavior<Slots, Input, ParentMessage>(
  bound: SlotView.Bound<Slots, Input, ParentMessage>,
): (
  options: BehaviorOptions<Slots, ParentMessage>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>
function behavior<Slots>(
  slots: SlotView.Unbound<Slots>,
): <Input, ParentMessage>(
  options: BehaviorOptions<Slots, ParentMessage>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>

Move.BehaviorOptions

interface · packages/primitives/src/interaction/move.ts:15

interface BehaviorOptions<Slots, ParentMessage> {
  readonly handle: keyof Slots & string
  readonly toMessage: (fact: Fact) => ParentMessage
}

Move.Fact

type · packages/primitives/src/dom/move.ts:27

type Fact = MoveStarted | Moved | MoveEnded

Move.mount

const · packages/primitives/src/dom/move.ts:51

const mount: Mount.MountDefinitionNoArgs<
  'Move',
  | {
      readonly _tag: 'MoveStarted'
      readonly pointerId: number
      readonly pointerType: string
    }
  | {
      readonly _tag: 'Moved'
      readonly pointerId: number
      readonly deltaX: number
      readonly deltaY: number
      readonly pointerType: string
    }
  | {
      readonly _tag: 'MoveEnded'
      readonly pointerId: number
      readonly completed: boolean
    }
>

Pointer movement on an element as a Mount: a primary-button pointer down captures the pointer, each move reports the delta from where it started, and up ends it completed, while cancel, lost capture, or Escape ends it not completed (the Escape is the drag's and goes no further; the Model, which kept the start, drops the draft). Nothing is decided here: a drag threshold, a snap, or a constraint is the parent's update. Capture is released with the Mount.

Move.Moved

const · packages/primitives/src/dom/move.ts:11

const Moved: Schema.TaggedStruct<
  'Moved',
  {
    readonly pointerId: Schema.Number
    readonly deltaX: Schema.Number
    readonly deltaY: Schema.Number
    readonly pointerType: Schema.String
  }
>

Move.MoveEnded

const · packages/primitives/src/dom/move.ts:20

const MoveEnded: Schema.TaggedStruct<
  'MoveEnded',
  { readonly pointerId: Schema.Number; readonly completed: Schema.Boolean }
>

Move.MoveStarted

const · packages/primitives/src/dom/move.ts:5

const MoveStarted: Schema.TaggedStruct<
  'MoveStarted',
  { readonly pointerId: Schema.Number; readonly pointerType: Schema.String }
>

Move.nudge

function · packages/primitives/src/interaction/move.ts:58

function nudge<Input, Message>(
  options: Box.KeyStep & {
    readonly toMessage: (delta: Box.Delta) => Message
  },
): Behaviors.Keys.Route<Input, Message>

The keyboard's way to do what a drag does, as a Behaviors.Keys route for the handle's keydown owner: Alt with an arrow asks for a nudge by step, and Shift for largeStep (ten steps by default). toMessage receives the delta for update to apply with Box.moveBy or Box.moveEach, so the limits are the drag's, and to announce with LiveAnnounce. Plain arrows are left to the page and the other routes.

Move.resizeKeys

function · packages/primitives/src/interaction/move.ts:82

function resizeKeys<Input, Message>(
  handle: Box.Handle,
  options: Box.KeyStep & {
    readonly toMessage: (delta: Box.Delta) => Message
  },
): Behaviors.Keys.Route<Input, Message>

The same for a resize handle: arrows move the handle's own edges (Shift the larger step), Home and End ask for the smallest and largest size, which Box.resize clamps to its limits. A key the handle does not own (Up on an east handle) is declined and untouched.