/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type ValueTypeOf, type option } from "@elaraai/east"; import { SheetEditingType } from "@elaraai/e3-ui/internal"; import type { RecordSliceBindType } from "@elaraai/east-ui/internal"; import { type EntryKeys } from "@elaraai/east-ui-components"; import { type ShownDrafts } from "./shown-drafts.js"; import { type SheetBounds } from "./bounds.js"; import type { EntryVersion, EntryUpdate, Origin, Placement, SheetTransactions } from "./transactions.js"; import type { SheetEditValue, SheetPagedSourceValue, SheetRowValue } from "./values.js"; type Editing = ValueTypeOf; /** A projection of the transaction session over currently resident source rows. */ export interface LocalLayer { edits: ReadonlyMap; appended: readonly SheetRowValue[]; removed: ReadonlySet; placements: ReadonlyMap; } export declare const EMPTY_LAYER: LocalLayer; /** * How the rows a sheet draws were read: the revision their source is read at * now, and which rows were read before it — standing in until their own read * lands (#851). What a Save landed is drawn over such rows as it left them * (`EditSession.landed`), never as they were before it. */ export interface SheetRowsRead { /** The revision the source is read at now; `undefined` while it names none. */ readonly revision: string | undefined; /** Whether the row drawn at a source position was read before that revision — given none, any row that may yet be drawn. */ readonly before: (position: number | undefined) => boolean; /** * How many rows the source holds, counted at that revision; `undefined` while its count there is not known. What * tells a source's last row, gone from it, from a row whose page was let go (`standing-rows.ts`). */ readonly total?: number | undefined; } /** * One entry, rewritten in the gesture that writes its cells (#1188) — given * the entry's version as the gesture's wire events left it, its new version: * a field no column shows, set on its draft; a duplicate's whole draft * copied, beside the wire row it was copied with. */ export type DraftEdit = (version: EntryVersion) => EntryVersion; /** * The seeds a gesture's new entries take in place of `newRow`'s and * `newGroup`'s (#1187): a dropped template's — the constructor's defaults with * the template's fields over them, built by the same code. */ export interface SheetSeeds { /** A new row's (a new line's) seed. */ newRow?: Editing["newRow"] | undefined; /** A new group's seed, with its lines. */ newGroup?: Editing["newGroup"] | undefined; } /** What {@link useSheetEditing} hands a sheet: its session, the layer over its rows, and its gesture recorder. */ export interface SheetEditingResult { /** The session. */ session: SheetTransactions; /** The session's edits over the resident rows. */ layer: LocalLayer; /** * Each entry the layer draws as a Save sent it — committed and not yet read back, or landed — by the revision it was * drafted at: a count read there holds nothing of it, and one read since holds it already (#1536). `undefined` for * one held from no revision (`LandedEntry.from`): a count read at a revision is the source's own. */ savedFrom: ReadonlyMap; /** * Aggregate a gesture's wire edits, the draft edits beside them (by * entry), and the seeds its new entries take, into one transaction. * Answers whether the session recorded it. A gesture that names itself — an action taken (#1477), `Mark Done` — * gives its `label`; else the label is the origin's. A gesture that `joins` the last one — recorded with the same * key — is one step with it (a phone's cell editor, `Mobile Sheet Spec.md` SH10.1). A gesture with a new entry, or * a new line, the app left a field of empty that no person can set (#1536) throws {@link SheetRefused}, and nothing * is drafted. An entry the sheet no longer draws — scrolled out of the rows read, or out of a narrowing's — begins * from the version a host `held` of it while it was drawn (#1579): what removing a row ticked there takes. */ record: (events: readonly SheetEditValue[], placements?: ReadonlyMap, originOverride?: Origin, draftEdits?: ReadonlyMap, seeds?: SheetSeeds, label?: string, joins?: string, held?: ReadonlyMap) => boolean; /** * Record entry versions a gesture computed whole — the optimiser's answer * (#1409), each entry's draft and wire row given — as one transaction of * the origin and label named. Answers whether the session recorded it. */ recordVersions: (updates: readonly EntryUpdate[], origin: Origin, label: string) => boolean; /** * An entry's version before any gesture: the session's; else, for one a Save landed that the rows have still to read, * the version the Save left (#1583); else the source's, lifted into its draft. */ original: (id: string) => EntryVersion; /** Each drafted entry's draft, encoded. */ drafts: Map; /** * Each entry the layer draws from a draft, and its draft encoded: the session's, and what a Save landed among the * rows read before it — what a sheet's cells from data are read over (#1559). */ layerDrafts: { readonly entries: ReadonlyMap; readonly drafts: ReadonlyMap; }; /** * The drafts an author's callbacks read the rows over (#1599): each row as its person sees it — the layer's draft of * it, else the entry its window was read with — never an entry read on its own at the revision now. */ shown: ShownDrafts; /** * An entry's wire row as the record would show its draft — the Sheet's own `project` (#1475): what a gesture whose * cells a rule reads (an action's summary) draws at once; `prior` while the draft is not complete. */ project: (id: string, draft: unknown, prior: SheetRowValue | undefined) => SheetRowValue | undefined; /** * Several entries of the source's record read by their keys, as a Save's confirmation reads them (#1596) — what an * optimiser's answer reads a row the sheet does not hold by, before its change lands (east-workspace#1622, rule 8). * A tracked read: each entry, `none` for one the record does not hold, by its id; none while the read is on its way; * `undefined` from a reader that reads none together. `undefined` for a source whose rows the sheet holds whole, * which holds every row there is. */ readByKeys: ((ids: readonly string[]) => option>> | undefined) | undefined; /** Editing is available now. */ available: boolean; /** The session's version. */ version: number; } /** * Bind decoded callbacks and retain unresolved requests through remounts. * * @param declared - The decoded editing declaration * @param source - The windowed source — a session edits it only when it is pinned * @param rows - The source's resident rows * @param positions - Each resident row's source position — a failed window before it does not move it (#853) * @param storageKey - The view's key * @param recordSlice - The record query's primary-entry reader, independent of its narrowed windows * @param replacing - Displayed rows belong to the previous query and cannot be edited * @param retained - Displayed rows stand in while a key's far jump is read (#1398, CL10): the source's own rows, which * the session still holds, but they take no gesture until the jump's rows replace them * @param mint - On a sheet with loose rows between its groups (#846), mints a new line's id field — the field a loose row is identified by * @param noun - The host's word for a group: what a refused new group is called (#1536) * @param day - The day a column from data writes its cells at (#1559) — the sheet's, which it reads them at; else the * day each gesture is made on * @param rowsRead - How the rows were read, where they are read apart from a Save's confirmation — a paged source's * pages, read again at the revision it committed: what the Save landed is drawn over the rows read before it until * they are read again. Without it the rows are the source's as it is, and a Save's entries are theirs at once. * @param keys - How a new row is keyed (#1583): the rule the session makes each new row's key by, and makes it another * by where another write adds its own row under it meanwhile; a key the session did not make keeps the two rows a * conflict to choose between * @param bounds - The inspector's numbers held to bounds (#1585): an entry a draft changed waits for Save while one is * outside them, as while a field is still missing; `undefined` holds none * @param rowsId - The id of the windowed source that gives the rows, no narrowing printed into it: what a Save's entries * are read back by key through where no record Slice gives them (#1596) * @param autosave - Whether the builder's Autosave begins on, as its author says; off unless given * @param entryOf - The stored entry the window standing at a row's source position read with it (#1599), where the * sheet's windows carry theirs — the pages', or the lens's: what a gesture on a row the sheet 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 * @returns The session, its layer and gesture recorder, the drafts, and whether editing is available */ export declare function useSheetEditing(declared: Editing, source: SheetPagedSourceValue | undefined, rows: readonly SheetRowValue[], positions: readonly number[], storageKey: string, mint?: () => string, recordSlice?: ValueTypeOf, replacing?: boolean, retained?: boolean, noun?: string, day?: Date, rowsRead?: SheetRowsRead, keys?: EntryKeys, bounds?: SheetBounds, rowsId?: string, autosave?: boolean, entryOf?: (id: string, at: number) => Uint8Array | undefined): SheetEditingResult; export {}; //# sourceMappingURL=use-editing.d.ts.map