/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type PatchPath, type ValueTypeOf } from "@elaraai/east"; import { Plan } from "@elaraai/e3-ui/internal"; import { type EditHistory, type EditSession, type HistoryAction, type DragEventValue } from "@elaraai/east-ui-components"; import type { PlanMoveRequest } from "./edit/use-carry.js"; import { type PlanRootValue, type PlanRowId, type PlanRowValue } from "./model.js"; import type { RowKey } from "./plan-state.js"; import type { PlanWholeRows } from "./root/nested.js"; import type { PlanTypedValue } from "./edit/typing.js"; /** The decoded Plan editing declaration (the root's `editing` some-value). */ export type PlanEditingValue = ValueTypeOf; /** One entry as the session holds it — its id. What it draws is derived when a mark needs it. */ export interface PlanEntryRef { /** The entry's id — its key's text, the first segment of its rows' paths. */ readonly id: string; } /** A drafted row's mark — the Sheet's (#879). */ export type PlanDraftMark = "pending" | "incomplete" | "invalid"; /** What {@link usePlanEditing} hands the canvas. */ export interface PlanEditing { /** Whether the root declares editing at all. */ enabled: boolean; /** The session — the history bar reads it. */ session: EditSession; /** The session's key in the Plan's one history, beside its event kinds' (#1194). */ historyKey: string; /** Whether a gesture can be drafted now: a base observed, the session writable. */ available: boolean; /** The session's version — moves with every change to it. */ version: number; /** The root with the drafted entries in place — what the canvas draws. */ value: PlanRootValue; /** Its data-stable twin: a new identity only when the data or the drafts moved. */ data: PlanRootValue; /** Moves when the drafted entries do — a paged canvas reads its windows again then. */ draftsVersion: number; /** The drafted entries, each whole, by id, and their version: what a window over rows read lean draws in their place (#1438). */ drafted: { readonly drafts: ReadonlyMap; readonly version: number; }; /** Each drafted row's mark, by row key. */ marks: ReadonlyMap; /** * A card dropped on a row — drafted into its entry. Stable. * * @returns Whether it was drafted — `false` when the session cannot take * it or the row's series refused it (a job the row's list already * holds, #825) */ drop(event: DragEventValue): boolean; /** * A run, chip, tile or mark moved or resized (#825) — drafted into the * entry its row came from, and, when it lands on a row of another entry, * that entry too, as ONE gesture. Stable. * * @returns Whether it was drafted — `false` when the session cannot take * it or no series wrote it (the item is never taken without being put) */ move(request: PlanMoveRequest): boolean; /** * A number typed into a table cell, or the cell cleared (#1436, #1438) — * drafted into the entry its row came from as one step, labelled as the * history names it. Stable. * * @returns Whether it was drafted — `false` when the session cannot take * it or the row's series wrote nothing (a fraction where its values are * whole, a cleared cell holding none) */ typeValue(typed: PlanTypedValue, label: string): boolean; /** * The rows a gesture waits on, being read whole (#1438): the canvas draws * them, and the rows above them, as in flight until they land and the * gesture is drafted. */ inFlight: ReadonlySet; /** A history bar action. Stable. */ action(action: HistoryAction): void; } /** What {@link usePlanEditing} reads. */ export interface PlanEditingArgs { /** The latest root, as the host gave it. */ value: PlanRootValue; /** Its data-stable twin. */ data: PlanRootValue; /** * Over rows read lean beside their nested series index (#1438), the rows * read whole by key: a gesture drafts each row it touches read whole, and * a Save is confirmed by them. */ whole?: PlanWholeRows | undefined; /** The canvas rows the source holds — inline, every row; paged, the resident windows'. */ rows: readonly PlanRowValue[]; /** Which window each paged row came from. */ origin: ReadonlyMap; /** The view's key. */ storageKey: string; /** A row's name, for a transaction's label — its gutter label. */ labelOf: (key: RowKey) => string; /** * The Plan's one history (#1194), once it holds this session beside its * event kinds': a gesture is one step of it, and the history actions are * its. Without it — or before it holds the session — the session's own. */ history?: { readonly current: EditHistory | undefined; } | undefined; /** * The stored entry the window the canvas draws at a source position read with the entry of an id (#1599, the * paging driver's): what a gesture on a row the canvas shows begins from while its window is read again — after a * Save, or another session's write — never a read at the revision the source reads at now, which is on its way. */ entryOf?: ((id: string, at: number) => Uint8Array | undefined) | undefined; /** * Whether the window the canvas draws at a source position has landed at the revision it reads at (#1599, the * paging driver's): what a Save landed of an entry there is drawn over its window until then, and is the window's * own to draw from then on. */ landedAt?: ((at: number) => boolean) | undefined; } /** The entry a row came from — the first segment of its id's path; none for a top-level section's header. */ export declare function entryOf(id: PlanRowId): string | undefined; /** Where a conflict is among the Plan's rows ({@link conflictPlaceOf}). */ export interface PlanConflictPlace { /** The rows down to it, its entry's first: a works' row, then a crew's below it. */ readonly rows: readonly PlanRowValue[]; /** How many of its path's keys and places those rows name, below its entry. */ readonly keys: number; /** The instant a key past them names — the cell of a table row that holds it (#1438); `undefined` for none. */ readonly at: Date | undefined; } /** * Where a conflict is among the Plan's rows: the deepest row its path's keys * lead to from its entry — a crew's below its works', a measure's below its * ledger's — with every row above it, and the instant a key past it names. * A row's id names each step below its entry by the key itself (a String) or * its text; a path names it by its text, a String's quoted. * * @param rows - The rows the session's entries placed * @param entry - The conflict's entry * @param path - Its path in the entry's draft * @returns Its place; `undefined` where no row is the entry's */ export declare function conflictPlaceOf(rows: readonly PlanRowValue[], entry: string, path: PatchPath): PlanConflictPlace | undefined; /** * The Plan's editing session and gestures, and the canvas with its drafts. * * @param args - The root, its rows as the source holds them, and the view * @returns The session, the drafted canvas, its marks and the gestures */ export declare function usePlanEditing(args: PlanEditingArgs): PlanEditing; //# sourceMappingURL=use-plan-editing.d.ts.map