Primitives / foldkit-primitives/interaction

Marquee

namespace · packages/primitives/src/interaction/marquee.ts:10

export * as Marquee from './marquee.js'

Marquee as a Behavior: a lasso over the container's marked descendants. No Bundle: the rectangle is for the view to draw in a Slot of its own, and the ids it touches are for the parent's update to select, through Selection's Replaced (Marquee.selected combines them with what was selected when the press was additive). It composes with PointerDrag on the same container: a press on a marked descendant is the drag's, a press on empty space is the lasso's.

Members

Marquee.behavior

function · packages/primitives/src/interaction/marquee.ts:50

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>

Marquee.BehaviorOptions

interface · packages/primitives/src/interaction/marquee.ts:25

interface BehaviorOptions<Slots, ParentMessage> {
  readonly container: keyof Slots & string
  readonly attribute: string
  readonly edgeScroll?: EdgeScroll
  readonly toMessage: (fact: MarqueeFact) => ParentMessage
}

Marquee.MarqueeCancelled

const · packages/primitives/src/dom/marquee.ts:37

const MarqueeCancelled: Schema.TaggedStruct<'MarqueeCancelled', {}>

Marquee.MarqueeChanged

const · packages/primitives/src/dom/marquee.ts:22

const MarqueeChanged: Schema.TaggedStruct<
  'MarqueeChanged',
  {
    readonly rect: Schema.Struct<{
      readonly x: Schema.Number
      readonly y: Schema.Number
      readonly width: Schema.Number
      readonly height: Schema.Number
    }>
    readonly ids: Schema.$Array<Schema.String>
    readonly additive: Schema.Boolean
  }
>

Marquee.MarqueeEnded

const · packages/primitives/src/dom/marquee.ts:30

const MarqueeEnded: Schema.TaggedStruct<
  'MarqueeEnded',
  {
    readonly rect: Schema.Struct<{
      readonly x: Schema.Number
      readonly y: Schema.Number
      readonly width: Schema.Number
      readonly height: Schema.Number
    }>
    readonly ids: Schema.$Array<Schema.String>
    readonly additive: Schema.Boolean
  }
>

Marquee.MarqueeFact

type · packages/primitives/src/dom/marquee.ts:40

type MarqueeFact =
  MarqueeStarted | MarqueeChanged | MarqueeEnded | MarqueeCancelled

Marquee.MarqueeRect

const · packages/primitives/src/dom/marquee.ts:8

const MarqueeRect: Schema.Struct<{
  readonly x: Schema.Number
  readonly y: Schema.Number
  readonly width: Schema.Number
  readonly height: Schema.Number
}>

A rectangle in the container's content coordinates: from its padding box's top left, scrolled with it.

Marquee.MarqueeStarted

const · packages/primitives/src/dom/marquee.ts:16

const MarqueeStarted: Schema.TaggedStruct<
  'MarqueeStarted',
  { readonly additive: Schema.Boolean }
>

Marquee.mount

const · packages/primitives/src/dom/marquee.ts:73

const mount: Mount.MountDefinitionWithArgs<
  'Marquee',
  {
    attribute: Schema.String
    edgeScroll: Schema.optionalKey<
      Schema.Struct<{
        readonly edge: Schema.optionalKey<Schema.Number>
        readonly speed: Schema.optionalKey<Schema.Number>
      }>
    >
  },
  | { readonly _tag: 'MarqueeStarted'; readonly additive: boolean }
  | {
      readonly _tag: 'MarqueeChanged'
      readonly rect: {
        readonly x: number
        readonly y: number
        readonly width: number
        readonly height: number
      }
      readonly ids: readonly string[]
      readonly additive: boolean
    }
  | {
      readonly _tag: 'MarqueeEnded'
      readonly rect: {
        readonly x: number
        readonly y: number
        readonly width: number
        readonly height: number
      }
      readonly ids: readonly string[]
      readonly additive: boolean
    }
  | { readonly _tag: 'MarqueeCancelled' }
>

A lasso over an element's marked descendants, as a Mount. A press on empty space (anywhere in the element that is no marked descendant, no control and no scrollbar) that moves past DRAG_THRESHOLD starts a marquee; the rectangle from the press to the pointer, in the element's content coordinates, and the ids of the marked descendants it touches, are reported as the pointer moves. Releasing ends it, and Escape or a cancelled pointer cancels it. A touch never starts one: a finger on empty space scrolls.

It draws nothing and selects nothing: the rectangle is for the view to draw in a Slot of its own, and the ids are for the parent's update to select (Selection's Replaced). A press on a marked descendant is not its business, so it composes with PointerDrag on the same element. The pointer's own geometry is measured as it moves and never kept.

Marquee.selected

function · packages/primitives/src/interaction/marquee.ts:41

function selected(
  before: ReadonlyArray<string>,
  fact: {
    readonly ids: ReadonlyArray<string>
    readonly additive: boolean
  },
): ReadonlyArray<string>

The selection a lasso makes: the ids it touches, or, when the press was additive, those after what was selected before it (the parent keeps that from MarqueeStarted's Message, as the Model before the first change).