Selection.Args
const · packages/primitives/src/interaction/selection.ts:46
const Args: Schema.Struct<{
readonly mode: Schema.Literals<readonly ['single', 'multiple', 'none']>
readonly allowEmpty: Schema.Boolean
}>Primitives / foldkit-primitives/interaction
namespace · packages/primitives/src/interaction/selection.ts:10
export * as Selection from './selection.js'Selection over a set of items: which ids are selected, and the anchor a
range extends from. mode is 'single' (a click replaces), 'multiple'
(a click toggles), or 'none'. Single mode keeps one item selected unless
allowEmpty. A range needs the items' order, which the view knows and the
Bundle does not, so Ranged carries it. The Behavior says the state in
ARIA and wires a plain click; a Shift range comes from Press, whose
Pressed carries shiftKey.
Selection.Argsconst · packages/primitives/src/interaction/selection.ts:46
const Args: Schema.Struct<{
readonly mode: Schema.Literals<readonly ['single', 'multiple', 'none']>
readonly allowEmpty: Schema.Boolean
}>Selection.behaviorfunction · packages/primitives/src/interaction/selection.ts:166
function behavior<Field extends string, const A extends Args = Args>(
declared: Declared<typeof bundle, Field>,
args: A,
): {
<Slots, Input extends { readonly [K in Field]: Model }, ParentMessage>(
bound: SlotView.Bound<Slots, Input, ParentMessage>,
): <Item extends keyof Slots & string, Click extends boolean = true>(
options: BehaviorOptions<Input, Slots, Item, Click>,
) => Behavior.NamedBehavior<
Slots,
Input,
ParentMessage,
| A11y.ProvidedOn<Item, 'state:aria-selected'>
| ([Click] extends [true]
? [A['mode']] extends ['single' | 'multiple']
? A11y.ProvidedOn<Item, 'activation'>
: never
: never)
>
<Slots>(
slots: SlotView.Unbound<Slots>,
): <Input extends { readonly [K in Field]: Model }, ParentMessage>(
options: BehaviorOptions<Input, Slots>,
) => Behavior.NamedBehavior<Slots, Input, ParentMessage>
}Writes aria-selected on each item from the placed slice, and
aria-multiselectable on the container in multiple mode; wires OnClick
to Activated unless told not to. A disabled item gets no click.
Selection.BehaviorOptionsinterface · packages/primitives/src/interaction/selection.ts:145
interface BehaviorOptions<
Input,
Slots,
Item extends keyof Slots & string = keyof Slots & string,
Click extends boolean = boolean,
> {
readonly container?: keyof Slots & string
readonly item: Item
readonly items: (input: Input) => Behaviors.Collection.Items<unknown>
readonly click?: Click
}Selection.betweenfunction · packages/primitives/src/interaction/selection.ts:56
function between(
order: ReadonlyArray<string>,
from: string | null,
to: string,
): ReadonlyArray<string>The ids between from and to in order, inclusive, in order's order.
Selection.bundleconst · packages/primitives/src/interaction/selection.ts:122
const bundle: Bundle.Bundle<"Selection", { readonly mode: "none" | "multiple" | "single"; readonly allowEmpty: boolean; }, { readonly selected: readonly string[]; readonly anchor: string | null; readonly ranged: readonly string[]; }, { readonly _tag: "Cleared"; } | { readonly _tag: "Selected"; readonly id: string; } | { readonly _tag: "Activated"; readonly id: string; } | { readonly _tag: "Ranged"; readonly id: string; readonly order: readonly string[]; } | { readonly _tag: "Replaced"; readonly ids: readonly string[]; }, never, never, never, NoView, {}, { activate: (model: Model, id: string) => Readonly<{ model: { readonly selected: readonly string[]; readonly anchor: string | null; readonly ranged: readonly string[]; }; commands?: Update.Commands<{ readonly _tag: "Cleared"; } | { readonly _tag: "Selected"; readonly id: string; } | { readonly _tag: "Activated"; readonly id: string; } | { readonly _tag: "Ranged"; readonly id: string; readonly order: readonly string[]; } | { readonly _tag: "Replaced"; readonly ids: readonly string[]; }, never>; outMessage?: never; }>; select: (model: Model, id: string) => Readonly<{ model: { readonly selected: readonly string[]; readonly anchor: string | null; readonly ranged: readonly string[]; }; commands?: Update.Commands<{ readonly _tag: "Cleared"; } | { readonly _tag: "Selected"; readonly id: string; } | { readonly _tag: "Activated"; readonly id: string; } | { readonly _tag: "Ranged"; readonly id: string; readonly order: readonly string[]; } | { readonl …;Selection.Messageconst · packages/primitives/src/interaction/selection.ts:32
const Message: MessageUnion<{
readonly Activated: { readonly id: Schema.String }
readonly Selected: { readonly id: Schema.String }
readonly Ranged: {
readonly id: Schema.String
readonly order: Schema.$Array<Schema.String>
}
readonly Replaced: { readonly ids: Schema.$Array<Schema.String> }
readonly Cleared: {}
}>Selection.Modeconst · packages/primitives/src/interaction/selection.ts:18
const Mode: Schema.Literals<readonly ['single', 'multiple', 'none']>Selection.Modelconst · packages/primitives/src/interaction/selection.ts:21
const Model: Schema.Struct<{
readonly selected: Schema.$Array<Schema.String>
readonly anchor: Schema.NullOr<Schema.String>
readonly ranged: Schema.$Array<Schema.String>
}>