/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * A record's drafted rows as a builder that draws its records' own rows takes * them (#1599) — the Schematic's and the Flowchart's: each drafted row read * through its kind's `read`, whether its draft adds it, and the roles of the * row its session began from. * * - **Whether a draft adds its row is its session's word**, never the * gesture's that made the draft: the session's original of the row holds * none. The original moves apart from the draft. A row a gesture created is * one its record holds once its Save lands, a later draft of it a change of * that row; and a row its record held is one its draft adds once another * session removes it — the draft standing, a conflict to choose. Read once * as the draft was first decoded, a row changed here and removed by another * session was still a row its record held: its builder, which draws a * drafted row its read does not hold only where the draft adds it — any * other is one a narrowing hides, waiting in its session — drew nothing of * it, while its person was asked to choose over it. * - **Decoded once** for the version its session holds of the row and the * original beside it: a session keeps each the same object until a gesture, * a Save or a carry-over replaces it. * - **Held while nothing moves** (`use-drafted-rows.ts`). The rows are read * again whenever the history moves — an original moves with no change of * the drafts' bytes, which is all the shared editing's `drafts` follows — * and a kind's rows are the same map while each row is the same object, so * what draws from them holds still while a Save is sent or read back. * - **Which drafted rows a builder draws** is one rule ({@link DraftedStanding}, * asked by the Schematic, the Flowchart, and the shared cells reader of the * Plan's and the Calendar's events): * a row its read holds, as drafted; a row its draft adds, though no read * holds it; and of any other — a row its record holds, as its session * knows, that the read does not: one a narrowing hides — none, unless the * builder's narrowing is asked of the row itself and holds it. It waits in * its session, and Save sends it. * - **Through a carry-over a drafted row stands as it last stood.** A record * that moves is read again by its builder, and the session reads each * drafted row there by its key only after: until that read lands, what the * session says of a row — that its record holds it — is of the record as it * was (the shared editing's `carrying`). A row drafted here that another session removed is then * in no read, and not yet one its draft adds: taken for one a narrowing * hides, it left its builder for a round trip, and came back with its * conflict. Each drafted row is remembered as its builder last drew it, and * stands so until its session has judged it where the record is. * * Pure: the hook that reads the rows as a builder renders is * `use-drafted-rows.ts`. * * @packageDocumentation */ import { type EastTypeValue } from "@elaraai/east"; import type { EntryVersion } from "@elaraai/east-ui-components"; import type { ScheduleEntryRef } from "./editing.js"; /** A drafted row, as its builder takes it: its roles, as its kind reads them, and whether its draft adds it. */ export interface DraftedRow { /** Its roles. */ readonly roles: R; /** * Whether its draft adds it: its session's original holds no row of its key — a row a gesture created and no Save has * landed, or one another session removed under the draft. No read holds a row of its key for a narrowing's sake. */ readonly created: boolean; /** * The roles of the row its session began from — what its record holds of it, as the session knows it — as its kind * reads them. `undefined` for a row its draft adds. */ readonly began?: R | undefined; /** * Whether its session is carrying its drafts over to a record that moved, and has yet to judge them there * (`EditSession.carrying`): what it says of the row — whether its record holds it — is of the record as it was. * `undefined` for a row whose session is not said — one a Save landed. */ readonly carrying?: boolean | undefined; } /** One kind's drafted rows, by key: the drafted row, or `undefined` for one its draft deletes. */ export type DraftedRows = ReadonlyMap | undefined>; /** A kind whose drafted rows are read. */ export interface DraftedRowsKind { /** What its session is named by in the editing: a kind's slot, a sort. */ readonly key: string; /** Its rows' type. */ readonly rowType: EastTypeValue; /** Its keys' type. */ readonly keyType: EastTypeValue; /** A row's roles, read from its bytes and its key's text. */ readonly read: (bytes: Uint8Array, key: string) => R; } /** A session, as its drafted rows are read from it: each entry's version, and the original beside it. */ export interface DraftedRowsSession { /** Each entry the session holds a version of. */ readonly entries: ReadonlyMap>; /** Each entry as the session's source holds it, as the session knows it. */ readonly originals: ReadonlyMap>; /** Whether the session is carrying its drafts over to a source that moved, and has yet to judge them there. */ readonly carrying: boolean; } /** What each drafted row was read as, by the version its session holds of it: under which key, and beside which original. */ export type DraftedRowsCache = WeakMap, { readonly id: string; readonly original: EntryVersion | undefined; readonly row: DraftedRow; }>; /** Every kind's drafted rows, by what its session is named by: none of a kind with no draft. */ export type DraftedRowsByKind = ReadonlyMap>; /** No kind's drafted rows. */ export declare const NO_DRAFTED_ROWS: DraftedRowsByKind; /** * Which drafted rows a builder draws, and what it last drew of each (see the module docs): one for a builder, kept * while it is mounted. */ export declare class DraftedStanding { /** The drafted rows the builder last drew: by what each kind's session is named by, their keys. */ private drawn; /** * Whether a drafted row is drawn: a row its read holds; one its draft adds; one the builder's narrowing holds, asked * of the row itself; and, while its session has yet to judge it where its record is, one the builder last drew. * * @param kind - What the row's kind's session is named by * @param key - The row's key * @param row - The drafted row: whether its draft adds it, and whether its session has yet to judge it * @param held - Whether the builder's read holds a row of its key, and shows it * @param shown - Whether the builder's narrowing holds the row though its read holds none of it — a builder that * reads a window of its record asks its narrowing of the row itself; never, unless given * @returns Whether it is drawn; a row not drawn waits in its session */ stands(kind: string, key: string, row: Pick, "created" | "carrying">, held: boolean, shown?: () => boolean): boolean; /** * Whether the builder last drew a drafted row: what a row its draft deletes meanwhile is remembered by, drawn * nowhere, so the deletion taken back finds it standing as it did. * * @param kind - What the row's kind's session is named by * @param key - The row's key * @returns Whether it did */ stood(kind: string, key: string): boolean; /** * Remembers a drawing, once every drafted row of it has been asked: the drafted rows it drew, which stand through a * carry-over, in place of the last drawing's. * * @param drawn - Each kind's drafted rows drawn, by key; a kind not named drew none */ drew(drawn: ReadonlyMap>): void; /** * Remembers one kind's part of a drawing, the other kinds' as they were: what a reader that draws its kinds one at * a time tells, once every drafted row of the kind has been asked. * * @param kind - What the kind's session is named by * @param keys - The kind's drafted rows drawn, by key */ drewKind(kind: string, keys: ReadonlySet): void; } /** A row with its kind's drafts in place: its key, its roles, and whether its draft adds it, no stored row showing it. */ export interface DraftedPlaced { /** Its key. */ readonly key: string; /** Its roles: as drafted, where its session holds a draft of it. */ readonly roles: R; /** Whether its draft adds it. */ readonly added: boolean; } /** * One kind's rows with its drafts in place, for a builder that holds the kind's stored rows whole — the Flowchart's * kinds, a Plan's link kinds: each stored row as drafted, or nowhere where its draft deletes it; then each row its draft * adds. A drafted row no stored row shows that its draft does not add waits in its session, drawn nowhere — unless, * through a carry-over, its builder last drew it ({@link DraftedStanding}). * * @typeParam R - A row's roles * @param kind - What the kind's session is named by * @param stored - The kind's stored rows the read holds * @param drafts - The kind's drafts * @param standing - Which drafted rows stand, and what the builder last drew * @param drew - Where the kind's drafted rows these rows hold are told: what the builder then remembers of them * ({@link DraftedStanding.drew}) * @param hidden - Stored rows hidden from the builder, though held; none unless given * @param waits - Told each drafted row drawn nowhere, in the drafts' order; nothing unless given * @returns The rows: the stored ones in their order, then those a draft adds, in the drafts' */ export declare function draftsInPlace(kind: string, stored: ReadonlyMap, drafts: DraftedRows, standing: DraftedStanding, drew: Map>, hidden?: ReadonlySet, waits?: (key: string, roles: R) => void): DraftedPlaced[]; /** * One kind's drafted rows (see the module docs): each read once for the version its session holds of it and the * original beside it. * * @param kind - The kind * @param ids - The keys its drafts hold, in the order the rows are listed * @param session - Its session; `undefined` for a kind with none, whose every row reads as deleted * @param cache - What each drafted row was read as, kept across calls * @param held - The rows as last read: handed back, the same map, where no row moved * @returns The rows, by key: `undefined` for one its draft deletes */ export declare function draftedRowsOf(kind: DraftedRowsKind, ids: Iterable, session: DraftedRowsSession | undefined, cache: DraftedRowsCache, held?: DraftedRows): DraftedRows; /** * A kind's drafted rows, of every kind's: read as the kind's `read` gives them. * * @param rows - Every kind's drafted rows ({@link useDraftedRows}) * @param kind - The kind * @returns Its rows; `undefined` for a kind with no draft */ export declare function draftedOf(rows: DraftedRowsByKind, kind: Pick, "key" | "read">): DraftedRows | undefined; //# sourceMappingURL=drafted-rows.d.ts.map