/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * An action column's machine as the renderer walks it (#1475, * `Sheet Action Column - Behaviour Spec.md` §0, §10): the cases decoded from * the column's kind, a row's state read off its `Action` cell, its offer — * its state's `next`, or `start` with nothing taken — and the gate that says * whether it may act now. Pure: no React. * * @packageDocumentation */ import { type EastType, type ValueTypeOf } from "@elaraai/east"; import type { Sheet } from "@elaraai/e3-ui/internal"; import type { SheetColumnMeta } from "../model.js"; import type { SheetCellValue, SheetContextValue } from "../values.js"; /** The decoded wire kind of an action column. */ export type SheetActionKindValue = ValueTypeOf; /** One decoded wire case. */ export type SheetActionCaseValue = ValueTypeOf; /** How a case is asked for, decoded. */ export type SheetActionTakeValue = ValueTypeOf; /** Whether a row may act now, decoded. */ export type SheetActionGateValue = ValueTypeOf; /** What an action wrote beside its field, decoded: the row's cells and the band's. */ export type SheetActionUpdatesValue = ValueTypeOf; /** One case of an action column, as the cell and its overlays read it. */ export interface ActionCase { /** The case's name. */ readonly name: string; /** The action's verb. */ readonly label: string; /** The state's word. */ readonly state: string; /** The state's tone; `undefined` is neutral. */ readonly tone: string | undefined; /** A Font Awesome solid icon's name. */ readonly icon: string | undefined; /** The cases a row in this state may go to, in order. */ readonly next: readonly string[]; /** How it is asked for. */ readonly take: SheetActionTakeValue; /** The case's value type. */ readonly valueType: EastType; /** What the form opens with, encoded. */ readonly initial: ((ctx: SheetContextValue) => Uint8Array) | undefined; /** What else taking it writes. */ readonly updates: ((value: Uint8Array, ctx: SheetContextValue, at: Date) => SheetActionUpdatesValue) | undefined; /** The kind S14's grammar labels it by: a button, a choice (a menu) or a form. */ readonly kind: "button" | "choice" | "form"; /** Its value, encoded at its type. */ readonly encode: (value: unknown) => Uint8Array; /** Its value, decoded. */ readonly decode: (bytes: Uint8Array) => unknown; } /** An action column's machine. */ export interface ActionColumn { /** What a row with nothing taken may do. */ readonly start: readonly string[]; /** Every case by name. */ readonly cases: ReadonlyMap; /** The cases in the author's order. */ readonly order: readonly ActionCase[]; /** Whether a row may act now, over its wire context. */ readonly gate: (ctx: SheetContextValue) => SheetActionGateValue; /** The rule cell holding a row's summary. */ readonly summary: string; /** The rule cell holding how the row is named, if any. */ readonly name: string | undefined; /** The rule cell holding the row's words beside its name, if any. */ readonly title: string | undefined; } /** * A column's machine, decoded once per wire column. * * @param meta - The column * @returns Its machine, or `undefined` for any other kind */ export declare function actionColumnOf(meta: SheetColumnMeta | undefined): ActionColumn | undefined; /** * The case a row is in, from its `Action` cell. * * @param cell - The cell * @returns The case's name, or `undefined` while nothing is taken */ export declare function caseOf(cell: SheetCellValue | undefined): string | undefined; /** * The cases a row may go to by the machine alone — its state's `next`, or * `start` with nothing taken — in order. * * @param column - The machine * @param cell - The row's action cell * @returns The offered cases */ export declare function machineOffer(column: ActionColumn, cell: SheetCellValue | undefined): ActionCase[]; /** A row's offer: the machine's, and whether the row may act now. */ export interface ActionOffer { /** The state the row is in, if a case is taken. */ readonly state: ActionCase | undefined; /** The cases the machine offers, in order. */ readonly offered: readonly ActionCase[]; /** Why the row cannot act now (the column's `blocked`). */ readonly blocked: string | undefined; /** The fields its draft still lacks (T6). */ readonly incomplete: readonly string[] | undefined; } /** * A row's offer, its gate asked over its wire context. A gate that throws is * said as the row's blocking reason, never thrown on: a row stays drawn. * * @param column - The machine * @param cell - The row's action cell * @param ctx - The row's wire context, or `undefined` where none is built (a read-only sheet asks none) * @returns The offer */ export declare function offerOf(column: ActionColumn, cell: SheetCellValue | undefined, ctx: SheetContextValue | undefined): ActionOffer; /** Whether a row may take an offered case now. */ export declare function canTake(offer: ActionOffer): boolean; /** * The `Action` cell a case and its value make. * * @param c - The case * @param bytes - Its value, encoded * @returns The cell */ export declare function actionCell(c: ActionCase, bytes: Uint8Array): SheetCellValue; /** A case's label in S14's grammar: a form's verb ends in `…`; a choice's caret is drawn beside it. */ export declare function verbOf(c: ActionCase): string; //# sourceMappingURL=model.d.ts.map