DocsAPI referenceUI machinescommand

command machine

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

@grassroot/ui-machines/command

Package

18 exports
View source packages/ui-machines/src/command/index.ts

Service example

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

Exports

DeclarationView source
CommandBindingModets
type CommandBindingMode = "controlled" | "uncontrolled";
DeclarationView source
CommandChangeReasonts
type CommandChangeReason = "pointer" | "keyboard" | "programmatic" | "trigger" | "input" | "escape" | "outside-click";
DeclarationView source
CommandCommandts
type CommandCommand = CommandObject & ({
readonly type: "VALUE_CHANGE_REQUEST";
readonly value: string;
readonly reason: CommandSelectionReason;
} | {
readonly type: "OPEN_CHANGE_REQUEST";
readonly open: boolean;
readonly reason: Exclude<CommandChangeReason, "input">;
} | {
readonly type: "QUERY_CHANGE_REQUEST";
readonly query: string;
readonly reason: "input" | "programmatic";
} | {
readonly type: "FOCUS_PART";
readonly part: "input" | "panel";
} | {
readonly type: "ANNOUNCE";
readonly key: "selection-changed" | "results-available";
readonly params: {
readonly label: string | null;
readonly count: number | null;
};
readonly politeness: "polite" | "assertive";
});

CommandContext

interface
DeclarationView source
CommandContextts
interface CommandContext<Item extends CommandItem = CommandItem> {
readonly value: string | undefined;
readonly open: boolean;
readonly query: string;
/** Index into the current flattened item list; filtering never creates a second index model. */
readonly highlightedIndex: number;
readonly filteredGroups: readonly CommandGroup<Item>[];
readonly flatItems: readonly Item[];
readonly modes: CommandModes;
}
Name
Kind
Type
Requirement
Description
filteredGroups
property
readonly CommandGroup<Item>[]
required
flatItems
property
readonly Item[]
required
highlightedIndex
property
number
required
Index into the current flattened item list; filtering never creates a second index model.
modes
property
CommandModes
required
open
property
boolean
required
query
property
string
required
value
property
string | undefined
required
Name
filteredGroups
Kind
property
Type
readonly CommandGroup<Item>[]
Requirement
required
Description
Name
flatItems
Kind
property
Type
readonly Item[]
Requirement
required
Description
Name
highlightedIndex
Kind
property
Type
number
Requirement
required
Description
Index into the current flattened item list; filtering never creates a second index model.
Name
modes
Kind
property
Type
CommandModes
Requirement
required
Description
Name
open
Kind
property
Type
boolean
Requirement
required
Description
Name
query
Kind
property
Type
string
Requirement
required
Description
Name
value
Kind
property
Type
string | undefined
Requirement
required
Description
DeclarationView source
CommandDiagnosticCodests
export declare const CommandDiagnosticCodes: readonly DiagnosticCatalogueEntry[];
DeclarationView source
CommandEventts
type CommandEvent = {
readonly type: "OPEN";
readonly reason: Exclude<CommandChangeReason, "input">;
} | {
readonly type: "CLOSE";
readonly reason: Exclude<CommandChangeReason, "input">;
} | {
readonly type: "TOGGLE";
readonly reason: Exclude<CommandChangeReason, "input">;
} | {
readonly type: "SET_QUERY";
readonly query: string;
readonly reason: "input" | "programmatic";
} | {
readonly type: "MOVE";
readonly direction: -1 | 1;
} | {
readonly type: "HIGHLIGHT";
readonly index: number;
} | {
readonly type: "SELECT";
readonly value: string;
readonly reason: CommandSelectionReason;
} | {
readonly type: "RESET";
};
DeclarationView source
CommandFilterts
type CommandFilter<Item extends CommandItem = CommandItem> = (item: Item, normalizedQuery: string) => boolean;
DeclarationView source
CommandGroupts
type CommandGroup<Item extends CommandItem = CommandItem> = CommandGroup$1<Item>;

CommandInput

interface
DeclarationView source
CommandInputts
interface CommandInput<Item extends CommandItem = CommandItem> {
readonly groups: readonly CommandGroup<Item>[];
readonly value?: string;
readonly defaultValue?: string;
readonly open?: boolean;
readonly defaultOpen?: boolean;
readonly query?: string;
readonly defaultQuery?: string;
/** Replaces the default oracle predicate; the machine still owns grouping. */
readonly filter?: CommandFilter<Item>;
}
Name
Kind
Type
Requirement
Description
defaultOpen
property
boolean
optional
defaultQuery
property
string
optional
defaultValue
property
string
optional
filter
property
CommandFilter<Item>
optional
Replaces the default oracle predicate; the machine still owns grouping.
groups
property
readonly CommandGroup<Item>[]
required
open
property
boolean
optional
query
property
string
optional
value
property
string
optional
Name
defaultOpen
Kind
property
Type
boolean
Requirement
optional
Description
Name
defaultQuery
Kind
property
Type
string
Requirement
optional
Description
Name
defaultValue
Kind
property
Type
string
Requirement
optional
Description
Name
filter
Kind
property
Type
CommandFilter<Item>
Requirement
optional
Description
Replaces the default oracle predicate; the machine still owns grouping.
Name
groups
Kind
property
Type
readonly CommandGroup<Item>[]
Requirement
required
Description
Name
open
Kind
property
Type
boolean
Requirement
optional
Description
Name
query
Kind
property
Type
string
Requirement
optional
Description
Name
value
Kind
property
Type
string
Requirement
optional
Description
DeclarationView source
CommandItemts
type CommandItem = CommandItem$1;
DeclarationView source
commandMachinets
export declare const commandMachine: CommandMachine;
DeclarationView source
CommandMachinets
type CommandMachine<Item extends CommandItem = CommandItem> = Machine<CommandInput<Item>, CommandStateValue, CommandContext<Item>, CommandEvent, CommandCommand>;

CommandModes

interface
DeclarationView source
CommandModests
interface CommandModes {
readonly value: CommandBindingMode;
readonly open: CommandBindingMode;
readonly query: CommandBindingMode;
}
Name
Kind
Type
Requirement
open
property
CommandBindingMode
required
query
property
CommandBindingMode
required
value
property
CommandBindingMode
required
Name
open
Kind
property
Type
CommandBindingMode
Requirement
required
Name
query
Kind
property
Type
CommandBindingMode
Requirement
required
Name
value
Kind
property
Type
CommandBindingMode
Requirement
required
DeclarationView source
commandReplaySequencets
export declare const commandReplaySequence: readonly CommandEvent[];
DeclarationView source
CommandSelectionReasonts
type CommandSelectionReason = "pointer" | "keyboard" | "programmatic";
DeclarationView source
commandSelectorsts
export declare const commandSelectors: {
value: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string | undefined;
open: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => boolean;
query: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string;
highlightedIndex: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => number;
filteredGroups: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly CommandGroup<Item>[];
flatItems: <Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly Item[];
};
Name
Kind
Type
Requirement
filteredGroups
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly CommandGroup<Item>[]
required
flatItems
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly Item[]
required
highlightedIndex
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => number
required
open
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => boolean
required
query
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string
required
value
property
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string | undefined
required
Name
filteredGroups
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly CommandGroup<Item>[]
Requirement
required
Name
flatItems
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => readonly Item[]
Requirement
required
Name
highlightedIndex
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => number
Requirement
required
Name
open
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => boolean
Requirement
required
Name
query
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string
Requirement
required
Name
value
Kind
property
Type
<Item extends CommandItem>(snapshot: CommandSnapshot<Item>) => string | undefined
Requirement
required
DeclarationView source
CommandSnapshotts
type CommandSnapshot<Item extends CommandItem = CommandItem> = Snapshot<CommandStateValue, CommandContext<Item>>;
DeclarationView source
CommandStateValuets
type CommandStateValue = "open" | "closed";