/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import type { Origin } from "@elaraai/east-ui-components"; import type { FlowchartEdit, FlowchartFieldWrites, FlowchartMove, FlowchartNewKey, FlowchartTransitionWrite } from "./editing.js"; import type { FlowchartWaiting } from "./drafted.js"; import type { FlowchartModel, FlowchartRow, FlowchartRows, FlowchartTransitionRoles } from "./model.js"; import type { FlowchartSort } from "./read.js"; /** The gestures the flowchart takes, each one step of the history. */ export type FlowchartGesture = "addLane" | "renameLane" | "deleteLane" | "addState" | "renameState" | "moveStates" | "deleteStates" | "duplicateState" | "connect" | "editLink" | "deleteLink" | "deleteDecision" | "dropCard" | "form" | "details" | "rekey"; /** The gesture each is recorded as, in the history and its patch events. */ export declare const EDIT_ORIGIN: { readonly [G in FlowchartGesture]: Origin; }; /** What a gesture reads: what the flowchart draws, its rows, and what each kind takes. */ export interface FlowchartHolding { /** What the flowchart draws. */ readonly model: FlowchartModel; /** The rows it draws, the drafts in place. */ readonly rows: FlowchartRows; /** The transitions it holds but does not draw, hidden with their far end, their drafts in place. */ readonly hidden: readonly FlowchartRow[]; /** The drafted rows the narrowing hides, waiting in their sessions. */ readonly waiting: readonly FlowchartWaiting[]; /** * Whether a kind takes a gesture now. * * @param sort - The kind */ readonly can: (sort: FlowchartSort) => boolean; /** * Whether the flowchart holds a key of a kind already. * * @param sort - The kind * @param key - The key */ readonly taken: (sort: FlowchartSort, key: string) => boolean; /** * Whether a row of a kind stands under a key (#1549): one a draft deletes stands free. * * @param sort - The kind * @param key - The key */ readonly stands: (sort: FlowchartSort, key: string) => boolean; /** * A new transition's key, unique among the transitions' and those given. * * @param minted - The keys the gesture has minted already */ readonly mintTransition: (minted: ReadonlySet) => string; /** Whether the decisions queue states by their keys: a state's Del takes its key out, and its move to a new key takes it there. */ readonly unqueues: boolean; /** Whether the lanes' order takes a whole number alone: an Integer field. */ readonly wholeLaneOrders: boolean; /** * A new row's key, as its kind makes one (#1549; `editing.ts`' `newKey`). * * @param sort - The row's kind * @param made - The edit making the row, under any key * @param madeUp - The text the gesture makes up, unique by what it is told is taken * @param minted - The keys the gesture has made already */ readonly newKey: (sort: FlowchartSort, made: FlowchartEdit, madeUp: (taken: (key: string) => boolean) => string, minted?: ReadonlySet) => FlowchartNewKey | undefined; /** * The rows a gesture moves under the keys their fields build once it writes them (#1549; `editing.ts`' `moves`). * * @param edits - The gesture's edits */ readonly moves: (edits: readonly FlowchartEdit[]) => FlowchartMove[]; /** * Why the flowchart may not hold every row of a kind it writes (#1580): the rail hides some, or the kind takes no edit * now — a Save in flight, or its rows not read; `undefined` where it holds them all, or writes none of the kind. * * @param sort - The kind */ readonly unheld: (sort: FlowchartSort) => FlowchartUnheld | undefined; /** * Whether a gesture created a row this session: no stored row names it (#1580). * * @param sort - The row's kind * @param key - Its key */ readonly created: (sort: FlowchartSort, key: string) => boolean; } /** Why the flowchart may not hold every row of a kind (#1580): the rail hides some, or the kind takes no edit now. */ export type FlowchartUnheld = "filtered" | "busy"; /** Why a gesture records nothing (#1549), as the footer says it. */ export type FlowchartRefusal = /** The key a row builds is held already, by the row of that key. */ { readonly refusal: "taken"; readonly sort: FlowchartSort; readonly key: string; } /** It names a row held under a placeholder, in another row's field: that row's key is still to be typed. */ | { readonly refusal: "placeholder"; readonly sort: FlowchartSort; readonly key: string; } /** Its kind's keys are of a type the form can't type, by the type's name, and its kind builds none. */ | { readonly refusal: "untyped"; readonly sort: FlowchartSort; readonly type: string; } /** * A row whose key the gesture moves, which rows of another kind name — by that kind (`by`) — that the flowchart doesn't * all hold, and why (#1580): what it leaves out would keep naming the old key. */ | { readonly refusal: "unheld"; readonly sort: FlowchartSort; readonly key: string; readonly by: FlowchartSort; readonly why: FlowchartUnheld; }; /** One gesture's edits, and the key of the row it adds, if it adds one. */ export interface GestureEdits { /** The rows it changes. */ readonly edits: readonly FlowchartEdit[]; /** The key of the row it adds. */ readonly key?: string | undefined; /** Why it records nothing, as the footer says it (#1549): its edits none. */ readonly refused?: FlowchartRefusal | undefined; /** The rows it moves under the keys their fields now build (#1549): where what is selected follows them. */ readonly moved?: readonly FlowchartMove[] | undefined; } /** * A key no row of its kind takes: the key wanted, else that key with `-2`, * `-3`, … after it. * * @param wanted - The key wanted * @param taken - Whether a row takes a key * @returns The key */ export declare function uniqueKey(wanted: string, taken: (key: string) => boolean): string; /** * A key numbered for a new row: `-`, `n` the first number from * `from` whose key no row takes — as + LANE keys a lane `lane-`. * * @param prefix - What the row is: `lane`, `state` * @param from - The first number tried: one past the rows' count * @param taken - Whether a row takes a key * @returns The key, and its number */ export declare function numberedKey(prefix: string, from: number, taken: (key: string) => boolean): { key: string; n: number; }; /** A row as it is placed among its neighbours: its key, and its order — `undefined` for a kind with none. */ export interface Placed { /** Its key. */ readonly key: string; /** Its order. */ readonly order: number | undefined; } /** Where a row lands among its neighbours: its order, and the neighbours after it that move one along. */ export interface Placement { /** Its order. */ readonly order: number; /** The neighbours after it that move along to make room, each with its new order: a whole order's alone. */ readonly shifts: readonly Placed[]; } /** * The order of a row landing among its neighbours: the middle of the two it * lands between; at an end, one past the last or one before the first; among * none, 1. A whole order between two a whole number apart is one past the * first, and the neighbours after it move one along, as far as they need. * * @param rows - Its neighbours, in their order: the row itself left out * @param at - Where it lands among them: 0 before the first, `rows.length` after the last * @param whole - Whether the order takes a whole number alone * @returns Its order, and the neighbours that move */ export declare function between(rows: readonly Placed[], at: number, whole: boolean): Placement; /** * + LANE: a lane at the end of the band row, keyed `lane-`, labelled for * `n`, its order one past the last. * * @param holding - What the gesture reads * @param label - The new lane's label, for its number (`Lane 6`) * @returns Its edits and its key; `undefined` while the lanes take no gesture */ export declare function addLane(holding: FlowchartHolding, label: (n: number) => string): GestureEdits | undefined; /** * A lane card dropped on the band row: a lane from its values where it lands, * keyed `lane-`, its order between the lanes it lands between. * * @param holding - What the gesture reads * @param at - Where it lands among the lanes: 0 before the first, their count at the band row's tail * @param values - The card's values * @returns Its edits and its key; `undefined` while the lanes take no gesture */ export declare function dropLane(holding: FlowchartHolding, at: number, values: Uint8Array): GestureEdits | undefined; /** * A lane's rename: its label. * * @param holding - What the gesture reads * @param key - The lane's key * @param label - Its new label * @returns Its edits; `undefined` while the lanes take no gesture */ export declare function renameLane(holding: FlowchartHolding, key: string, label: string): GestureEdits | undefined; /** * × on a lane: offered while no state the flowchart holds stands in it, whose * states would have no lane to stand in. * * @param holding - What the gesture reads * @param key - The lane's key * @returns Its edits; `undefined` while the lane holds a state, or the lanes take no gesture */ export declare function deleteLane(holding: FlowchartHolding, key: string): GestureEdits | undefined; /** * + STATE from a lane's editor: its key and its label, its lane, its order * one past the lane's last. A key the flowchart holds already is refused. A * key the editor takes no typing of — the states keyed by another type than * String, or building their keys — is the kind's to make, `state-` made up * where it makes one so (#1549). * * @param holding - What the gesture reads * @param band - The band's key * @param key - The state's key, as typed; `undefined` for one the kind makes * @param label - Its label * @returns Its edits and its key, or why it records nothing; `undefined` for a key taken, No lane, or while the states take no gesture */ export declare function addState(holding: FlowchartHolding, band: string, key: string | undefined, label: string): GestureEdits | undefined; /** * A state card dropped on a lane: a state from its values where it lands, * keyed `state-`, its order between the cards it lands between. * * @param holding - What the gesture reads * @param band - The band's key * @param at - Where it lands among the band's states: 0 before the first, their count after the last * @param values - The card's values * @returns Its edits and its key; `undefined` for No lane, or while the states take no gesture */ export declare function dropState(holding: FlowchartHolding, band: string, at: number, values: Uint8Array): GestureEdits | undefined; /** * A state's rename: its label. * * @param holding - What the gesture reads * @param key - The state's key * @param label - Its new label * @returns Its edits; `undefined` while the states take no gesture */ export declare function renameState(holding: FlowchartHolding, key: string, label: string): GestureEdits | undefined; /** * States moved to a band, together: each its lane and its order, evenly * between the two cards they land between, in their order before the move. * * @param holding - What the gesture reads * @param keys - The states' keys * @param band - The band's key * @param at - Where they land among the band's other states; `undefined` after the last * @returns Its edits; `undefined` for No lane, no state among the keys, or while the states take no gesture */ export declare function moveStates(holding: FlowchartHolding, keys: readonly string[], band: string, at?: number): GestureEdits | undefined; /** * Duplicate: the state after itself in its band, under its key made unique, * every field as it has them — or under the key its kind makes (#1549). * * @param holding - What the gesture reads * @param key - The state's key * @returns Its edits and the copy's key; `undefined` for a ghost, or while the states take no gesture */ export declare function duplicateState(holding: FlowchartHolding, key: string): GestureEdits | undefined; /** * Del of states, one step (D6): each state; every transition the flowchart * holds naming one — drawn, or hidden with its far end; and each one's key * from every decision's queue. A ghost — an end no state is keyed by — takes * its transitions alone. A kind read only beside the states is left as it is. * * @param holding - What the gesture reads * @param keys - The states' keys * @returns Its edits; `undefined` for nothing to delete, or a state while the states take no gesture */ export declare function deleteStates(holding: FlowchartHolding, keys: readonly string[]): GestureEdits | undefined; /** * Connect: a transition between two states, keyed unique and never drawn — * its ends, every other field its kind's values of them — or keyed as its kind * makes one (#1549). A state under a placeholder takes no transition until its * key is typed. * * @param holding - What the gesture reads * @param from - The state it leaves * @param to - The state it enters; `from` itself for one in place * @returns Its edits and its key, or why it records nothing; `undefined` while the transitions take no gesture */ export declare function connect(holding: FlowchartHolding, from: string, to: string): GestureEdits | undefined; /** * A transition's ends or its decision, as the inspector writes them: those * given, every other field as it was. * * @param holding - What the gesture reads * @param key - Its key * @param write - Its roles written: an end's new state, its decision — `some(none)` to clear it * @returns Its edits; `undefined` for nothing written, or while the transitions take no gesture */ export declare function editLink(holding: FlowchartHolding, key: string, write: FlowchartTransitionWrite): GestureEdits | undefined; /** * Del of a transition. * * @param holding - What the gesture reads * @param key - Its key * @returns Its edits; `undefined` while the transitions take no gesture */ export declare function deleteLink(holding: FlowchartHolding, key: string): GestureEdits | undefined; /** * A transition card dropped on a transition: its values, its ends and its key * kept. * * @param holding - What the gesture reads * @param key - The transition's key * @param values - The card's values * @returns Its edits; `undefined` while the transitions take no gesture */ export declare function dropTransition(holding: FlowchartHolding, key: string, values: Uint8Array): GestureEdits | undefined; /** * Del of a decision: cleared from every transition the flowchart holds naming * it, while the transitions take a gesture. * * @param holding - What the gesture reads * @param key - The decision's key * @returns Its edits; `undefined` while the decisions take no gesture */ export declare function deleteDecision(holding: FlowchartHolding, key: string): GestureEdits | undefined; /** * The form's fields on a row: those no role writes. * * @param holding - What the gesture reads * @param sort - The row's kind * @param key - Its key * @param sets - The fields it sets * @returns Its edits; `undefined` while the kind takes no gesture */ export declare function setFields(holding: FlowchartHolding, sort: FlowchartSort, key: string, sets: FlowchartFieldWrites): GestureEdits | undefined; /** * A row whole, as a kind's own Details hand it back. * * @param holding - What the gesture reads * @param sort - The row's kind * @param key - Its key * @param row - The row * @returns Its edits; `undefined` while the kind takes no gesture */ export declare function setRow(holding: FlowchartHolding, sort: FlowchartSort, key: string, row: Uint8Array): GestureEdits | undefined; /** * A new row's key, changed in the form before Save (R9): the row under its new * key, and the transitions naming a state and the decisions queuing it, or the * states naming a lane, following it — those drawn, those hidden with their far * end and those waiting. A key a row of the flowchart stands under already is * refused; one whose row a draft deletes is free (#1581). * * @param holding - What the gesture reads * @param sort - The row's kind: a state's or a lane's * @param from - Its key * @param to - Its new key * @returns Its edits; `undefined` for a key taken or empty, or while the kind takes no gesture */ export declare function rekey(holding: FlowchartHolding, sort: "states" | "lanes", from: string, to: string): GestureEdits | undefined; /** * A gesture's edits with each row whose kind builds its key from its row * moved under the key its fields build once the gesture writes them (#1549): * the row copied under its new key before any of its edits, so each writes it * there; then gone from its old key; then what names it following — a lane's * states, a state's transitions and the decisions queuing it — whose own keys, * built from what they name, move them in turn. A key another row stands under * once the gesture is made, or another moving row takes, refuses the gesture, * naming that key — one a row moves off is free, so a swap or a shift passes, * the row copied onto it replacing the one moving off, whose key it leaves * standing (#1581); so does a kind that may name a moving row the flowchart * doesn't hold whole (#1580). * * @param holding - What the gesture reads * @param made - The gesture's edits * @returns The edits with every move, and the rows moved; the refusal, with no edits, where a key is taken or what may * name a moving row isn't held */ export declare function followBuiltKeys(holding: FlowchartHolding, made: GestureEdits): GestureEdits; //# sourceMappingURL=edits.d.ts.map