/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Flowchart's drops (#1501, `Flowchart Records Spec.md` R14, D5, D8) — * pure and React-free: what a library card does where it lands, decided as * data before anything is drawn or written. The frame records a plan as one * step of the editing's history (`use-drop.ts`), and the canvas works out * where a drag rests from its own drawing. * * - **What is dragged** ({@link FlowchartDropCard}, {@link dropHostOf}): a * card of a tab that drops — a state's card, which adds a state where it * lands on a lane; a transition's card, which gives a transition its values; * a lane's card, which adds a lane where it lands on the band row; an * author's card, whose patch sets its fields on a row of the kind it names. * - **Where a drag rests** ({@link FlowchartDropAtType}, {@link dropAtPoint}): * what lies under the pointer of what the card lands on — a lane, and the * row a new state takes in it; a state; a transition, near its line; a * lane's header; the gap between two lanes, or the band row's tail; a * decision's diamond — or the canvas, where nothing it lands on lies. A row * the narrowing draws as context, and the band *No lane*, take no card. The * shared drag grammar's `CellRef` carries it in its `row`, printed. * - **What a drop does** ({@link planDrop}, {@link dropEdits}): a state from * the card's values in the lane it lands in, keyed `state-`, its order * between the cards it lands between; a transition given the card's values, * its ends and its key kept; a lane from the card's values where it lands, * keyed `lane-`, its order between the lanes'; an author's card's fields * set — or refused, with the reason the ghost says in red: anywhere but what * the card lands on, a kind read only (R13), a kind taking no edit now, a * kind adding no row — its keys of a type the form can't type, building none * — or a state's card on a lane whose key is still to be typed (#1549). * - **⏎ on a card** ({@link enterAt}): a drop on the canvas's selection — a * state's card after the selected state, at the end of the selected lane, or * at the end of the first lane; a lane's card after the selected lane, or at * the band row's tail; any other card on what is selected, when that is what * it lands on. * - **Its words** ({@link dropCaption}, {@link dropName}, {@link dropRefusal}, * {@link dropLabel}) and **its marks** ({@link markOf}): the lane it lands * in and the row, the gap a lane lands in, or what it sets its fields on. * * @packageDocumentation */ import { IntegerType, NullType, StringType, StructType, VariantType, type ValueTypeOf } from "@elaraai/east"; import { type DragPayload, type DropCellOptions, type DropVeto } from "@elaraai/east-ui-components"; import type { FlowchartFieldWrites } from "./editing.js"; import { type FlowchartHolding, type GestureEdits } from "./edits.js"; import type { FlowchartLayout, Pt } from "./layout.js"; import type { FlowchartDropPlaceWord, FlowchartDropRefusalWord, FlowchartDropWhatWord, FlowchartLandsWord, FlowchartMessages } from "./messages.js"; import type { FlowchartModel, FlowchartValue } from "./model.js"; import type { FlowchartSort } from "./read.js"; import { type FlowchartSelection } from "./selection.js"; /** What a library card lands on. */ export type FlowchartLands = FlowchartLandsWord; /** A card the canvas takes, as the Flowchart reads it: what its drop does, and its name. */ export type FlowchartDropCard = /** A state's card: a new state where it lands on a lane, every field but its lane and its order the card's values. */ { readonly does: "addState"; readonly label: string; readonly values: Uint8Array; } /** A transition's card: its values given to the transition it lands on, its ends and its key kept. */ | { readonly does: "retype"; readonly label: string; readonly values: Uint8Array; } /** A lane's card: a new lane where it lands on the band row, every field but its order the card's values. */ | { readonly does: "addLane"; readonly label: string; readonly values: Uint8Array; } /** An author's card: the fields its patch sets, on a row of the kind its patch names. */ | { readonly does: "set"; readonly sort: FlowchartSort; readonly label: string; readonly sets: FlowchartFieldWrites; }; /** * The kind a card writes. * * @param card - The card * @returns The kind */ export declare function cardSort(card: FlowchartDropCard): FlowchartSort; /** * What a card lands on. * * @param card - The card * @returns What it lands on */ export declare function landsOf(card: FlowchartDropCard): FlowchartLands; /** What the canvas takes dropped: its drop target, and each library whose cards drop — its cards by key. */ export interface FlowchartDropHost { /** The Flowchart's drop target: the surface its canvas registers on. */ readonly surface: string; /** Each library whose cards drop, by its id: its cards, by key. */ readonly libraries: ReadonlyMap>; } /** A kind's cards, as the wire carries them. */ type Templates = FlowchartValue["states"]["templates"]; /** The kinds that carry cards, as the drops read them. */ export interface FlowchartCardKinds { /** The states' cards. */ readonly states: Templates; /** The transitions' cards; none for a Flowchart given no transitions. */ readonly transitions: Templates; /** The lanes' cards; none for a Flowchart given no lanes. */ readonly lanes: Templates; } /** * What the canvas takes dropped, from the tabs the payload lists: the Steps * tab's cards, each adding a state; the Transitions tab's, each giving a * transition its values; the Lanes tab's, each adding a lane; and each * author's tab whose patch names a kind, its cards by their keys. An author's * tab with no `drop` drops nothing. * * @param surface - The Flowchart's drop target * @param libraryOf - The library a tab's cards drag from, by the tab's key * @param tabs - The tabs the payload lists * @param kinds - The kinds' cards * @returns What the canvas takes */ export declare function dropHostOf(surface: string, libraryOf: (tabKey: string) => string, tabs: FlowchartValue["library"], kinds: FlowchartCardKinds): FlowchartDropHost; /** * A card the canvas takes, by its library and its key. * * @param host - What the canvas takes * @param library - The card's library * @param key - The card's key * @returns The card, or `undefined` for one no tab that drops lists */ export declare function cardOf(host: FlowchartDropHost, library: string, key: string): FlowchartDropCard | undefined; /** Where a drag rests over the canvas, for what it carries — what a Flowchart's drop `CellRef` names in its `row`, printed. */ export declare const FlowchartDropAtType: VariantType<{ /** A band, by its key, and the row a new state takes in it: after the states above the pointer. */ readonly lane: StructType<{ readonly lane: StringType; readonly row: IntegerType; }>; /** A state, by its key. */ readonly state: StringType; /** A transition, by its key. */ readonly transition: StringType; /** A lane's header, by the lane's key. */ readonly header: StringType; /** Where a new lane lands among the lanes: 0 before the first, their count at the band row's tail. */ readonly gap: IntegerType; /** A decision's diamond, by the decision's key. */ readonly decision: StringType; /** The canvas, where nothing the card lands on lies under the pointer. */ readonly canvas: NullType; }>; /** Where a drag rests, decoded. */ export type FlowchartDropAt = ValueTypeOf; /** Where a drag rests, as its `CellRef` carries it. */ export declare const printDropAt: (at: FlowchartDropAt) => string; /** * Where a drop's `CellRef` says the drag rests. * * @param text - The `CellRef`'s `row` * @returns Where it rests, or `undefined` when the text names nowhere — a coordinate another surface made */ export declare function readDropAt(text: string): FlowchartDropAt | undefined; /** The canvas, where nothing a card lands on lies: where the canvas's drop cell rests before a drag says otherwise. */ export declare const ON_CANVAS: FlowchartDropAt; /** How near a transition's line a drag rests on it, either side, in px — wider than the line's 12px hit path, so nobody has to hit the line. */ export declare const LINK_PAD = 10; /** How near a decision's diamond a drag rests on it: its half-diagonal, 11px, and a margin. */ export declare const DIAMOND_PAD = 16; /** * The row a new state takes in a band, at a point: after every state of the * band whose middle lies above the pointer — in TD, before it. * * @param layout - The laid-out flowchart * @param held - How many states the band draws * @param p - The point, in the canvas's px * @returns The row, from 0 — before the band's first state — to `held`, after its last */ export declare function rowAt(layout: FlowchartLayout, held: number, p: Pt): number; /** * The transition whose line runs nearest a point, within {@link LINK_PAD} — * one drawn as context left out; an in-place transition, folded into its * state's `↻` badge, has no line. * * @param layout - The laid-out flowchart * @param model - The view model: which transitions draw as context * @param p - The point * @returns Its key, or `undefined` */ export declare function linkAt(layout: FlowchartLayout, model: FlowchartModel, p: Pt): string | undefined; /** * The decision whose diamond lies under a point, within {@link DIAMOND_PAD} * of its middle — a transition naming a decision the Flowchart doesn't hold, * or one drawn as context, draws none a card lands on. * * @param layout - The laid-out flowchart * @param model - The view model: the decisions each transition names * @param p - The point * @returns The decision's key, or `undefined` */ export declare function diamondAt(layout: FlowchartLayout, model: FlowchartModel, p: Pt): string | undefined; /** * The lane whose header holds a point: the band's strip before its first row * — across the top in LR, down the side in TD. Only a lane of the app's has a * header a card lands on: never *No lane*, nor the one band of a Flowchart * given no lanes. * * @param layout - The laid-out flowchart * @param model - The view model * @param p - The point * @returns The lane's key, or `undefined` */ export declare function headerAt(layout: FlowchartLayout, model: FlowchartModel, p: Pt): string | undefined; /** * Where a new lane lands at a point: before the first lane of the app's whose * middle lies past the pointer — after the last, the band row's tail. A * Flowchart given no lanes has no gap. * * @param layout - The laid-out flowchart * @param model - The view model * @param p - The point * @returns The gap, from 0 to the lanes' count; `undefined` with no lanes given */ export declare function gapAt(layout: FlowchartLayout, model: FlowchartModel, p: Pt): number | undefined; /** * Where a gap stands along the lanes' axis: the start of the lane it lands * before, or the end of the last lane of the app's. * * @param layout - The laid-out flowchart * @param at - The gap * @returns Its place, in the canvas's px — LR's x, TD's y */ export declare function gapLine(layout: FlowchartLayout, at: number): number; /** * Where a drag rests at a point of the canvas, for a card that lands on what * it names: a band and the row a new state takes in it ({@link rowAt}) — * never *No lane*; a state — its card, or as near as `connect.ts`' drop pad — * never a ghost; a transition near its line; a lane's header; a gap between * the lanes ({@link gapAt}); a decision's diamond. A row drawn as context * takes no card. Anywhere else, the canvas. * * @param lands - What the card lands on * @param layout - The laid-out flowchart * @param model - The view model * @param p - The point, in the canvas's px * @returns Where the drag rests */ export declare function dropAtPoint(lands: FlowchartLands, layout: FlowchartLayout, model: FlowchartModel, p: Pt): FlowchartDropAt; /** What a drop reads of the Flowchart as it stands. */ export interface FlowchartDropContext { /** What the Flowchart draws now, the drafts in place. */ readonly model: FlowchartModel; /** Whether a kind is edited at all: bound with its patch door, and the Flowchart not read only (R13). */ readonly editable: (sort: FlowchartSort) => boolean; /** Whether a kind takes an edit now: no Save on its way, nothing the canvas draws standing in. */ readonly available: (sort: FlowchartSort) => boolean; /** A kind's name, as a sentence writes it (`state`). */ readonly kindName: (sort: FlowchartSort) => string; /** Why a kind adds no row (#1549): its key type's name, where the form can't type it and the kind builds none; `undefined` for one that adds rows. */ readonly untyped: (sort: FlowchartSort) => string | undefined; } /** Why a drop is refused where it rests: in its words, or — what it lands on having left the drawing — in none. */ export type FlowchartDropRefusal = { readonly why: "gone"; } | FlowchartDropRefusalWord; /** What a drop does where it rests. */ export type FlowchartDropPlan = /** A state added in a band at a row, from a card's values, and where its words say it lands. */ { readonly kind: "addState"; readonly band: string; readonly row: number; readonly values: Uint8Array; readonly place: FlowchartDropPlaceWord; } /** A transition given a card's values, and what it is, in words. */ | { readonly kind: "retype"; readonly key: string; readonly values: Uint8Array; readonly what: FlowchartDropWhatWord; } /** A lane added among the lanes, from a card's values, and where its words say it lands. */ | { readonly kind: "addLane"; readonly at: number; readonly values: Uint8Array; readonly place: FlowchartDropPlaceWord; } /** An author's card's fields set on a row of a kind, and what it is, in words. */ | { readonly kind: "set"; readonly sort: FlowchartSort; readonly key: string; readonly sets: FlowchartFieldWrites; readonly what: FlowchartDropWhatWord; } | { readonly kind: "refused"; readonly why: FlowchartDropRefusal; }; /** * What a drop does where it rests — see the module docs. A card of a kind * read only, or of a kind taking no edit now, is refused wherever it rests, and * so is one adding a row of a kind that adds none (#1549); otherwise a card is * refused anywhere but what it lands on, and says nothing where that has left * the drawing. * * @param card - The card dragged * @param at - Where the drag rests * @param ctx - The Flowchart as it stands * @returns What the drop does, or why it is refused */ export declare function planDrop(card: FlowchartDropCard, at: FlowchartDropAt, ctx: FlowchartDropContext): FlowchartDropPlan; /** * The edits a plan writes, one step of the history: a state from the card's * values where it lands; a transition's values; a lane from the card's values * where it lands; an author's card's fields — none for a refusal. * * @param plan - The plan * @param holding - What the Flowchart holds now * @returns The edits and the key of the row they add; `undefined` for a refusal, or a kind taking no gesture */ export declare function dropEdits(plan: FlowchartDropPlan, holding: FlowchartHolding): GestureEdits | undefined; /** * What a drop brings onto the canvas, which it selects: the state or the lane * it added; nothing for a drop on a row. * * @param plan - The plan * @param edits - What it wrote * @returns The selection, or `undefined` */ export declare function droppedSelection(plan: FlowchartDropPlan, edits: GestureEdits): FlowchartSelection | undefined; /** * Where ⏎ on a card drops it: on the canvas's selection. A state's card lands * after the selected state, in its band; with a lane selected, at the end of * that lane; with neither, at the end of the first band that takes states. A * lane's card lands after the selected lane, else at the band row's tail. Any * other card lands on the selected state, transition, decision or lane when it * lands on that. A selection the drawing no longer holds is none. * * @param lands - What the card lands on * @param selection - What the canvas has selected * @param model - What the Flowchart draws now * @returns Where it drops — the canvas, where the selection takes no such card */ export declare function enterAt(lands: FlowchartLands, selection: FlowchartSelection | null, model: FlowchartModel): FlowchartDropAt; /** What the canvas marks while a drag rests where it lands: the band and the row a state takes, the gap a lane lands in, a lane's header, or what a card sets its fields on. */ export type FlowchartDropMark = { readonly kind: "lane"; readonly lane: string; readonly row: number; } | { readonly kind: "gap"; readonly at: number; } | { readonly kind: "header"; readonly lane: string; } | { readonly kind: "state" | "transition" | "decision"; readonly key: string; }; /** * What the canvas marks for a plan: the band a state lands in and its row, * the gap a lane lands in, the lane whose header a card sets, or the state, * transition or decision a card lands on — nothing for a refusal. * * @param plan - The plan * @returns The mark, or `undefined` */ export declare function markOf(plan: FlowchartDropPlan): FlowchartDropMark | undefined; /** * Whether two marks are one: what the canvas draws need not move. * * @param a - A mark, or none * @param b - Another, or none * @returns Whether they mark the same place */ export declare function markEqual(a: FlowchartDropMark | undefined, b: FlowchartDropMark | undefined): boolean; /** * What the ghost says of a plan: where a state lands — `after SRT in Sort` — * where a lane lands — `before Sort` — or what a card sets its fields on — * `onto SRT → LDD` — or, red, why it can't: `Drop onto a transition`. * * @param plan - The plan * @param m - The Flowchart's messages * @returns The caption; `undefined` for a refusal that says nothing */ export declare function dropCaption(plan: FlowchartDropPlan, m: FlowchartMessages): string | undefined; /** * Why a plan is refused, as the footer says it for a card's ⏎. * * @param plan - The plan * @param m - The Flowchart's messages * @returns The words; `undefined` for a plan that lands, or a refusal that says nothing */ export declare function dropRefusal(plan: FlowchartDropPlan, m: FlowchartMessages): string | undefined; /** * Where a plan lands, as a screen reader hears the drag layer say it — `Sort, * after SRT`, `SRT → LDD` — or, refused, the canvas. * * @param plan - The plan * @param m - The Flowchart's messages * @returns The name */ export declare function dropName(plan: FlowchartDropPlan, m: FlowchartMessages): string; /** * A drop's step in the history, and its Save's — `Drop Held on Sort, after * SRT`. * * @param plan - The plan: one that lands * @param card - The card dropped * @param m - The Flowchart's messages * @returns The name */ export declare function dropLabel(plan: FlowchartDropPlan, card: FlowchartDropCard, m: FlowchartMessages): string; /** * What the canvas hands the drag layer as its one drop cell: built by the * frame and held still while the Flowchart takes drops, its functions reading * the Flowchart as it stands. The canvas works out where a drag rests from its * own drawing, and marks it. */ export interface FlowchartCanvasDrop { /** The surface the cell registers on: the Flowchart's drop target. */ readonly surface: string; /** What a drag carries, as the Flowchart reads it — a card a tab of its library drops — or `undefined`. */ readonly cardOf: (payload: DragPayload) => FlowchartDropCard | undefined; /** What a drop of a card where a drag rests does, over the Flowchart as it stands. */ readonly plan: (card: FlowchartDropCard, at: FlowchartDropAt) => FlowchartDropPlan; /** The veto: whether the drop a candidate event makes lands. */ readonly canDrop: DropVeto; /** What the ghost says where the drag rests, and that place's name for the announcements. */ readonly options: Required>; } export {}; //# sourceMappingURL=drop.d.ts.map