DocsAPI referenceUI machinesselection

selection machine

The public state machine contract for @grassroot/ui-machines/selection. The machine owns behaviour; the matching headless layer owns composition.

@grassroot/ui-machines/selection

Package

21 exports
View source packages/ui-machines/src/selection/index.ts

Service example

selection.tsts
import { createService } from "@grassroot/statechart";
import { selectionMachine } from "@grassroot/ui-machines/selection";
const service = createService(selectionMachine, { input: {} });
service.start();
service.send({ type: "…" });
service.stop();

Exports

DeclarationView source
dedupeSelectionIdsts
declare function dedupeSelectionIds(ids: readonly string[]): SelectionValue;
Name
Kind
Type
Requirement
ids
parameter
readonly string[]
required
return
return value
SelectionValue
n/a
Name
ids
Kind
parameter
Type
readonly string[]
Requirement
required
Name
return
Kind
return value
Type
SelectionValue
Requirement
n/a
DeclarationView source
EMPTY_SELECTION_IDSts
export declare const EMPTY_SELECTION_IDS: SelectionValue;

isSelectableId

function
DeclarationView source
isSelectableIdts
declare function isSelectableId(id: string, input: SelectionInput): boolean;
Name
Kind
Type
Requirement
id
parameter
string
required
input
parameter
SelectionInput
required
return
return value
boolean
n/a
Name
id
Kind
parameter
Type
string
Requirement
required
Name
input
Kind
parameter
Type
SelectionInput
Requirement
required
Name
return
Kind
return value
Type
boolean
Requirement
n/a
DeclarationView source
rangeSelectionIdsts
declare function rangeSelectionIds(orderedIds: readonly string[], disabledIds: readonly string[], fromId: string | null, toId: string): SelectionValue;
Name
Kind
Type
Requirement
orderedIds
parameter
readonly string[]
required
disabledIds
parameter
readonly string[]
required
fromId
parameter
string | null
required
toId
parameter
string
required
return
return value
SelectionValue
n/a
Name
orderedIds
Kind
parameter
Type
readonly string[]
Requirement
required
Name
disabledIds
Kind
parameter
Type
readonly string[]
Requirement
required
Name
fromId
Kind
parameter
Type
string | null
Requirement
required
Name
toId
Kind
parameter
Type
string
Requirement
required
Name
return
Kind
return value
Type
SelectionValue
Requirement
n/a

sameSelectionIds

function
DeclarationView source
sameSelectionIdsts
declare function sameSelectionIds(left: SelectionValue, right: SelectionValue): boolean;
Name
Kind
Type
Requirement
left
parameter
SelectionValue
required
right
parameter
SelectionValue
required
return
return value
boolean
n/a
Name
left
Kind
parameter
Type
SelectionValue
Requirement
required
Name
right
Kind
parameter
Type
SelectionValue
Requirement
required
Name
return
Kind
return value
Type
boolean
Requirement
n/a
DeclarationView source
SelectionChangeDetailts
type SelectionChangeDetail = {
readonly selectedIds: SelectionValue;
readonly reason: SelectionChangeReason;
};
Name
Kind
Type
Requirement
reason
property
SelectionChangeReason
required
selectedIds
property
SelectionValue
required
Name
reason
Kind
property
Type
SelectionChangeReason
Requirement
required
Name
selectedIds
Kind
property
Type
SelectionValue
Requirement
required
DeclarationView source
SelectionChangeReasonts
type SelectionChangeReason = "pointer" | "keyboard" | "programmatic";
DeclarationView source
SelectionCommandts
type SelectionCommand = CommandObject & {
readonly type: "SELECTION_CHANGE_REQUEST";
readonly selectedIds: SelectionValue;
readonly reason: SelectionChangeReason;
};
Name
Kind
Type
Requirement
reason
property
SelectionChangeReason
required
selectedIds
property
SelectionValue
required
type
property
string
required
Name
reason
Kind
property
Type
SelectionChangeReason
Requirement
required
Name
selectedIds
Kind
property
Type
SelectionValue
Requirement
required
Name
type
Kind
property
Type
string
Requirement
required
DeclarationView source
SelectionContextts
type SelectionContext = {
readonly mode: BindingMode;
readonly selectedIds: SelectionValue;
readonly anchorId: string | null;
};
Name
Kind
Type
Requirement
anchorId
property
string | null
required
mode
property
BindingMode
required
selectedIds
property
SelectionValue
required
Name
anchorId
Kind
property
Type
string | null
Requirement
required
Name
mode
Kind
property
Type
BindingMode
Requirement
required
Name
selectedIds
Kind
property
Type
SelectionValue
Requirement
required
DeclarationView source
SelectionDiagnosticCodests
export declare const SelectionDiagnosticCodes: readonly DiagnosticCatalogueEntry[];
DeclarationView source
SelectionEventts
type SelectionEvent = {
readonly type: "SELECT";
readonly id: string;
readonly reason: SelectionChangeReason;
} | {
readonly type: "TOGGLE";
readonly id: string;
readonly reason: SelectionChangeReason;
} | {
readonly type: "RANGE_EXTEND";
readonly id: string;
readonly reason: SelectionChangeReason;
} | {
readonly type: "SELECT_ALL";
readonly selectableIds: readonly string[];
readonly reason: SelectionChangeReason;
} | {
readonly type: "CLEAR";
readonly reason: SelectionChangeReason;
} | {
readonly type: "REPLACE";
readonly selectedIds: SelectionValue;
readonly reason: SelectionChangeReason;
} | {
readonly type: "RESET";
};

SelectionInput

interface
DeclarationView source
SelectionInputts
interface SelectionInput {
readonly mode: SelectionMode;
readonly selectedIds?: SelectionValue;
readonly defaultSelectedIds?: SelectionValue;
readonly orderedIds: readonly string[];
readonly disabledIds?: readonly string[];
}
Name
Kind
Type
Requirement
defaultSelectedIds
property
SelectionValue
optional
disabledIds
property
readonly string[]
optional
mode
property
SelectionMode
required
orderedIds
property
readonly string[]
required
selectedIds
property
SelectionValue
optional
Name
defaultSelectedIds
Kind
property
Type
SelectionValue
Requirement
optional
Name
disabledIds
Kind
property
Type
readonly string[]
Requirement
optional
Name
mode
Kind
property
Type
SelectionMode
Requirement
required
Name
orderedIds
Kind
property
Type
readonly string[]
Requirement
required
Name
selectedIds
Kind
property
Type
SelectionValue
Requirement
optional
DeclarationView source
selectionMachinets
export declare const selectionMachine: SelectionMachine;
DeclarationView source
SelectionMachinets
type SelectionMachine = Machine<SelectionInput, SelectionStateValue, SelectionContext, SelectionEvent, SelectionCommand>;
DeclarationView source
SelectionMachineStatets
type SelectionMachineState = MachineState<SelectionStateValue, SelectionContext>;
DeclarationView source
SelectionModets
type SelectionMode = "none" | "single" | "multiple";
DeclarationView source
selectionReplaySequencets
export declare const selectionReplaySequence: readonly SelectionEvent[];
DeclarationView source
selectionSelectorsts
export declare const selectionSelectors: {
selectedIds: (snapshot: SelectionSnapshot) => SelectionValue;
anchorId: (snapshot: SelectionSnapshot) => string | null;
bindingMode: (snapshot: SelectionSnapshot) => BindingMode;
isSelected: (snapshot: SelectionSnapshot, id: string) => boolean;
};
Name
Kind
Type
Requirement
anchorId
property
(snapshot: SelectionSnapshot) => string | null
required
bindingMode
property
(snapshot: SelectionSnapshot) => BindingMode
required
isSelected
property
(snapshot: SelectionSnapshot, id: string) => boolean
required
selectedIds
property
(snapshot: SelectionSnapshot) => SelectionValue
required
Name
anchorId
Kind
property
Type
(snapshot: SelectionSnapshot) => string | null
Requirement
required
Name
bindingMode
Kind
property
Type
(snapshot: SelectionSnapshot) => BindingMode
Requirement
required
Name
isSelected
Kind
property
Type
(snapshot: SelectionSnapshot, id: string) => boolean
Requirement
required
Name
selectedIds
Kind
property
Type
(snapshot: SelectionSnapshot) => SelectionValue
Requirement
required
DeclarationView source
SelectionSnapshotts
type SelectionSnapshot = Snapshot<SelectionStateValue, SelectionContext>;
DeclarationView source
SelectionStateValuets
type SelectionStateValue = "ready";
DeclarationView source
SelectionValuets
type SelectionValue = readonly string[];