/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type Formatters, type TickFormatOpt } from "@elaraai/east-ui-components"; import type { SheetCellValue, SheetColumnValue, SheetContextValue, SheetCustomKindValue, SheetGroupValue, SheetLineValue, SheetLinkValue, SheetMemberValue, SheetNounValue, SheetRegisterMemberValue, SheetRootValue, SheetRowValue, SheetSubRowValue } from "./values.js"; import type { SheetWords } from "./words.js"; import { type WhenLevel } from "./parse/date.js"; /** The column kinds (the arms of `SheetColumnKindType`); the last seven only a Record draws (#1528). */ export type SheetKind = "text" | "date" | "quantity" | "integer" | "lookup" | "reference" | "enum" | "set" | "link" | "stamped" | "custom" | "action" | "title" | "person" | "boolean" | "toggle" | "cycle" | "age" | "audit"; /** The copilot latency class of a kind (B§3): deterministic kinds are instant. */ export declare function latencyOf(kind: SheetKind): "instant" | "idle"; /** One decoded column, flattened for the renderer. */ export interface SheetColumnMeta { /** The column key — the row field it sits on. */ key: string; /** The header line. */ header: string; /** The grey second header line. */ sub: string | undefined; /** Track width in px. */ width: number; /** The kind tag. */ kind: SheetKind; /** Whether the sheet writes the column. */ editable: boolean; /** The register the column resolves against (lookup · reference · enum · set · link · person · cycle). */ register: string | undefined; /** An enum, lookup or link column's options rule (#844): the member keys a row is OFFERED (`undefined` = the whole register). Typed text still resolves against the whole register. */ options: ((ctx: SheetContextValue) => readonly string[] | undefined) | undefined; /** A date column's level (#844): how deep a row's date is read and typed, read off the row's cells. */ level: ((cells: ReadonlyMap) => WhenLevel) | undefined; /** A date column's actual (#844): the key of the unrendered cell holding when the work really happened. */ actual: string | undefined; /** The key of the unrendered cell whose text is this column's detail — the hover and the strip (#844). */ detailCell: string | undefined; /** A date column's base column (`4d` counts from it). */ base: string | undefined; /** A date column's display pattern (East date tokens). */ dateFormat: string | undefined; /** A quantity column's unit per driver key. */ uom: ReadonlyMap | undefined; /** A quantity column's one unit for every row, after the value. */ unit: string | undefined; /** A quantity column's display format. */ format: TickFormatOpt; /** A toggle column's words for its two states: what a cell shows, and typed text sets. */ states: { on: string; off: string; } | undefined; /** A stamped column's owner. */ owner: string | undefined; /** A custom kind's "accepts" line. */ accepts: string | undefined; /** A custom kind's compiled parse — typed text + the wire context → an optional cell. */ customParse: SheetCustomKindValue["parse"] | undefined; /** A custom kind's compiled print. */ customPrint: SheetCustomKindValue["print"] | undefined; /** The raw decoded column (the link kind's declaration rides here for P3). */ raw: SheetColumnValue; } /** The column index — in declaration order, and by key. */ export interface SheetColumnIndex { list: readonly SheetColumnMeta[]; byKey: ReadonlyMap; /** Σ widths, for the body's min-width. */ totalWidth: number; } /** Flatten the decoded columns. */ export declare function indexColumns(columns: readonly SheetColumnValue[]): SheetColumnIndex; /** A declared CSS width to px — a bare number or a `px` length; anything else falls back. */ export declare function parseWidth(raw: string | undefined): number | undefined; /** The cell key a group's title rides under — the wire's `SHEET_TITLE_CELL`. */ export declare const TITLE_KEY = "$title"; /** The lens-record key a line's sub rows answer a search under (#844), reserved as {@link TITLE_KEY} is. */ export declare const SUB_ROWS_KEY = "$subRows"; /** The separator inside a line's synthetic id — the group's id, then the line's wire key. */ export declare const LINE_ID_SEP = "\u001F"; /** A line's synthetic id — its group's id and its wire key. */ export declare function lineId(groupId: string, key: string): string; /** The group id and line key a synthetic line id names, or `undefined` for a plain row id. */ export declare function parseLineId(id: string): { groupId: string; key: string; } | undefined; /** The synthetic id of a group's blank line — the copilot's anchor before the line is real. */ export declare function blankLineId(groupId: string): string; /** The wire key a line that the source does not hold yet carries — never a source index. */ export declare const NEW_LINE_KEY = "+"; /** How a line item knows its group: the group's wire row, the line's wire key, its index among the group's wire lines, its 1-based number. */ export interface LineGroup { row: SheetRowValue; key: string; index: number; number: number; } /** * The band's cells and the title span, decoded from the wire group * declaration against the line columns. */ export interface SheetGroupIndex { /** The field holding the lines — an `Array`, so a line's address is its position. */ linesField: string; /** The band's cells by the line column key they sit under (the title under {@link TITLE_KEY}). */ cells: ReadonlyMap; /** How many leading columns the title spans — up to three, stopping before the first column with a band cell. */ titleSpan: number; /** The host's word for a group (#844); `undefined` when it names none — the sheet's words say their own (#861). */ noun: SheetNounValue | undefined; /** Whether rows of the line type stand between the groups (#846) — a LOOSE row: a wire row with no band. */ loose: boolean; } /** * Decode the wire group declaration. * * @param group - The wire group declaration * @param columns - The line columns * @param titleHeader - The sheet's word for the band title's column (#861) * @returns The band's cells, the title span and the host's noun */ export declare function indexGroup(group: SheetGroupValue, columns: SheetColumnIndex, titleHeader: string): SheetGroupIndex; /** * Whether a grouped sheet's row is a LOOSE row between the groups (#846): a * row of the line type, with its own cells and no band. * * @param row - A grouped sheet's wire row * @returns `true` for a loose row, `false` for a group */ export declare function isLooseRow(row: SheetRowValue): boolean; /** * `n group(s)` in the host's noun, in the sheet's words — the count in the * app's locale (#850, #861). * * @param n - The count * @param noun - The host's word for a group * @param words - The sheet's words * @returns The phrase */ export declare function countNoun(n: number, noun: SheetNounValue, words: SheetWords): string; /** A line as a wire row — its group's id and key in the id, the group's `owned`, the line's cells and sub rows. */ export declare function lineRowOf(group: SheetRowValue, line: SheetLineValue): SheetRowValue; /** The pseudo rows of a group's lines, in order. */ export declare function lineRowsOf(group: SheetRowValue): SheetRowValue[]; /** A group row with one line's cells replaced (by wire key), or appended when the key is not among its lines; the line keeps its sub rows. */ export declare function withLine(group: SheetRowValue, key: string, cells: ReadonlyMap): SheetRowValue; /** A group row without the lines at the given wire keys. */ export declare function withoutLines(group: SheetRowValue, keys: ReadonlySet): SheetRowValue; /** A line's ADDRESS in an edit event — its position among its group's lines. */ export declare function lineAddress(index: number): string; /** The band's height per density (px). */ export declare function groupBandPx(size: "sm" | "md" | "lg"): number; /** * The registers by name, with each member indexed by its key, by lower-cased * key or alias, and by the label it shows. A key names its own member before * anything else does — exactly, then case-insensitively before any alias — so * a member a gesture chooses, committed and shown by its key, is never found * again as another member whose alias or key's case its key shares (#1583). */ export interface SheetRegisterIndex { byName: ReadonlyMap; /** Register name → key → member. */ keys: ReadonlyMap>; /** Register name → lower-cased key or alias → member: every member's key first, then the aliases. */ lookup: ReadonlyMap>; /** Register name → lower-cased label → the first member to show it. */ labels: ReadonlyMap>; } /** Index the decoded registers. */ export declare function indexRegisters(registers: ReadonlyMap): SheetRegisterIndex; /** The member a register resolves `text` to — by its key, else by key or alias case-insensitively: what a cell's value names. */ export declare function resolveMember(index: SheetRegisterIndex, register: string | undefined, text: string): SheetRegisterMemberValue | undefined; /** * The member typed text names whole — by its key, else by key or alias * case-insensitively, else by the label it shows, the first member to show * it: a register column is typed in the words its cells show. * * @param index - The registers * @param register - The column's register * @param text - What was typed * @returns The member, or `undefined` where the text names none whole */ export declare function resolveTyped(index: SheetRegisterIndex, register: string | undefined, text: string): SheetRegisterMemberValue | undefined; /** The driver member key a row resolves to — its driver column's String cell. */ export declare function driverKeyOf(row: SheetRowValue | undefined, driverColumn: string | undefined): string | undefined; /** * The unit a quantity cell prints after its value: its row's driver member's, * else the one unit the column gives every row. * * @param meta - The column * @param driverKey - The row's driver member key, if it names one * @returns The unit, or `undefined` for a column with none */ export declare function unitOf(meta: SheetColumnMeta, driverKey: string | undefined): string | undefined; /** The blank cell. */ export declare const NULL_CELL: SheetCellValue; /** The empty link — both halves empty. */ export declare const EMPTY_LINK: SheetLinkValue; /** Whether a cell is blank (`Null`, an empty string, or an empty link). */ export declare function cellIsBlank(cell: SheetCellValue | undefined): boolean; /** Whether a row is blank — every declared cell blank. */ export declare function rowIsBlank(row: SheetRowValue, columns: SheetColumnIndex): boolean; /** A link member's text — the grammar's print form (B§4.1), what copy, search and the editor's buffer use. */ export declare function memberLabel(m: SheetMemberValue): string; /** What a member's CHIP prints — its label, but a counted member as its kind alone: the count rides beside it ({@link memberChipCount}). */ export declare function memberChipLabel(m: SheetMemberValue): string; /** A counted member's count, drawn as its chip's meta; `undefined` for every other member. */ export declare function memberChipCount(m: SheetMemberValue): string | undefined; /** Whether a member draws as a dashed chip (text · placeholder). */ export declare function memberIsDashed(m: SheetMemberValue): boolean; /** A link value's planner text — `a > b` · `b` · `a >` (B§4.2). */ export declare function printLinkText(link: SheetLinkValue): string; /** * A quantity's display text — through the declared format, in the viewer's * language (#852): `1,234.5`, `1.234,5` in German. * * @param n - The number * @param format - The column's declared format; `undefined` for a plain grouped number * @param words - The viewer's formatters * @returns The text; empty for a non-finite number */ export declare function formatQuantity(n: number, format: TickFormatOpt, words: Formatters): string; /** A date's display text — the author's pattern, else `17 Nov 26`; East's own printer either way. */ export declare function formatDateCell(d: Date, pattern: string | undefined): string; /** * A cell's display text by kind (the read-only rendering). A link cell prints * through the grammar; a custom kind through its compiled `print`; a quantity * or integer in the viewer's language (#852) — the language its edit box * reads back. * * @param cell - The cell * @param meta - Its column * @param words - The viewer's formatters * @returns The text */ export declare function cellText(cell: SheetCellValue | undefined, meta: SheetColumnMeta, words: Formatters): string; /** A cell's text by its own tag, kind-agnostic. */ export declare function rawCellText(cell: SheetCellValue): string; /** A sub row's printed text — its lead, detail and id, what a search matches it by. */ export declare function subRowText(s: SheetSubRowValue): string; /** A cell's mark: the words drawn in it, and whether it locks the cell. */ export interface SheetCellMark { /** The mark's words — a note, or why the cell is locked. */ words: string; /** Whether the mark locks the cell, so no gesture writes it. */ lock: boolean; } /** * The mark on a column's cell, read off its row's cells where the column's * marks cross (`SheetMarkCellsType`): the root writes both cells for a mark, * and neither where the row has none. * * @param meta - The column * @param cells - The row's cells, read at the sheet's day; `undefined` for a row that holds none * @returns The mark, or `undefined` where the cell has none */ export declare function markOf(meta: Pick, cells: ReadonlyMap | undefined): SheetCellMark | undefined; /** * Whether a cell takes an edit — the one check every gesture asks, so none * can miss a lock: a step, typing, a paste, a clear, a fill and a drop. Its * column writes, and no mark locks it. * * @param meta - The column * @param cells - The row's cells; `undefined` for a row that holds none * @returns `true` when the cell can be edited */ export declare function cellWritable(meta: Pick, cells: ReadonlyMap | undefined): boolean; /** * Whether a column's cells take a clear. Every column's do but a column from * data's whose value isn't an option (its `from.clears`): there a blank is * nothing it can write. * * @param meta - The column * @returns `true` when a clear writes the cell blank */ export declare function takesClear(meta: Pick): boolean; /** * One unloaded run of a paged source, above or below the resident rows — or, * under the lens (#1349), a stretch of the record it is still reading or * placing, where the narrowing's rows in it will be drawn. */ export interface SheetBand { at: "head" | "tail" | "reading"; /** First source element covered (inclusive). */ from: number; /** Last source element covered (inclusive). */ to: number; /** How many of the sheet's elements it stands for, where that is not every one it covers: under the lens, the narrowing's rows in the stretch. */ elements?: number | undefined; /** The band's pixel height (the ledger's geometry). */ px: number; } /** A resident window of a paged source whose read failed (#853) — one band where its rows would be. */ export interface SheetWindowFailure { /** The window. */ w: number; /** Its first and last source element (inclusive). */ from: number; to: number; /** How many of the sheet's elements it stands for, where that is not every one it covers: under the lens, the narrowing's rows in the segment. */ elements?: number | undefined; /** Its height — the ledger's slot for it, so the rows that replace it take the same space. */ px: number; /** Why its read failed. */ error: string; } /** A failed window, and the row it sits before (`rows.length`: after the last). */ export interface PlacedFailure { failure: SheetWindowFailure; at: number; } /** A contiguous run of rows between failed windows: `[start, end)`, and the source position of `start`. */ export interface RowSegment { start: number; end: number; position: number; } /** * Where a paged run's failed windows sit among the rows on screen, and each * row's position (#853). The rows are the source's resident rows with the * local layer applied: a row the source served keeps its place relative to * the failed windows (by its source position), a row the planner added * follows the row before it. A position counts the rows before it — a row * removed locally renumbers the rows after it, as it always has — and every * element of a failed window before it: those rows exist, they could not be * read. * * @param rows - The rows on screen, in order * @param rowsOffset - The position of the run's first element * @param failures - The failed windows, ascending * @param sourcePosition - A row's source position, by id — `undefined` for a row the source did not serve * @returns Each row's position, where each failed window sits, and the contiguous segments between them */ export declare function layoutRun(rows: readonly SheetRowValue[], rowsOffset: number, failures: readonly SheetWindowFailure[], sourcePosition: (id: string) => number | undefined): { positions: number[]; failures: PlacedFailure[]; segments: RowSegment[]; }; /** * The segment a row sits in — the contiguous run an author's context sees * around it (#853), so `rowsOffset + index` stays each of its rows' position. * A row past the end (a blank row, an append) is in the last one. * * @param segments - The run's segments ({@link layoutRun}) * @param i - The row's index * @returns Its segment */ export declare function segmentOf(segments: readonly RowSegment[], i: number): RowSegment; /** * Where the rows the lens draws sit (#1349): each row's position in the * record — a row the planner added following the row before it — and the * contiguous runs of positions an author's context sees around a row, as * {@link layoutRun} gives them for a paged run. * * @param rows - The rows drawn, in order, the local layer applied * @param sourcePosition - A row's position in the record, by id — `undefined` for a row the record does not hold * @returns Each row's position, no failed windows (the lens draws a failed read as a band of its own), and the runs */ export declare function layoutLensRun(rows: readonly SheetRowValue[], sourcePosition: (id: string) => number | undefined): { positions: number[]; failures: PlacedFailure[]; segments: RowSegment[]; }; /** One body item — a real row (a line, when tagged with its group), a line's sub row, a blank padding row (a group's blank line, when tagged), a group's band, a paged band, or a proposal. */ export type SheetBodyItem = { kind: "real"; /** The row's source position (0-based) — its row number minus one; a line: its GROUP's position. */ position: number; /** Index among the RESIDENT real rows (the wire context's `rowIndex`); a line: its group's. */ residentIndex: number; /** The wire row; a line: the pseudo row over the line's cells ({@link lineRowOf}). */ row: SheetRowValue; /** A lens hit — the brand row number (B§8). */ hit: boolean; /** A line's group (#740). */ group?: LineGroup | undefined; /** A LOOSE row's index among the resident loose rows (#846) — a grouped sheet's row that belongs to no group. */ loose?: number | undefined; } | { kind: "blank"; /** The sheet position the blank would take (0-based); a group's blank line: the group's position. */ position: number; /** Which blank this is (0-based). */ blankIndex: number; /** A group's blank line (#740) — `key` empty, `index` the line it would take. */ group?: LineGroup | undefined; } /** * One SUB ROW under an open line (#844): full width under the line, none * of the columns, outside the row space like a band — the ring never * lands on it. */ | { kind: "subRow"; /** Its line's GROUP position, as the line's item has it. */ position: number; /** The line it hangs under. */ group: LineGroup; /** The line's synthetic id — the key its sub rows open under. */ lineId: string; subRow: SheetSubRowValue; /** Its index under the line, and how many the line has. */ index: number; count: number; } /** A group's band (#740): the title, the eyebrow, the band cells, the fold. */ | { kind: "group"; position: number; residentIndex: number; row: SheetRowValue; folded: boolean; /** The group's line count. */ count: number; } | { kind: "band"; band: SheetBand; } /** A resident window whose read failed (#853): its band, where its rows would be, with the reason and a Retry. */ | { kind: "failed"; failure: SheetWindowFailure; } | { kind: "proposal"; /** The proposal's index under its anchor. */ index: number; /** The row-space index of the anchor row. */ anchorR: number; /** The sheet position the row would take (0-based) — its number minus one. */ position: number; /** The 1-based number it would take (a line: within its group). */ number: number; /** Proposed under a line (#740) — it carries the group's extent rule. */ grouped: boolean; cells: ReadonlyMap; meta: string; }; /** What the body is built from. */ export interface SheetBodyInput { /** The resident real rows, in sheet order (a grouped sheet: the groups). */ rows: readonly SheetRowValue[]; /** The source offset of `rows[0]` (`0` on the inline arm). */ rowsOffset: number; /** Each row's position when the run has failed windows in it (#853, {@link layoutRun}); else `rowsOffset + i`. */ positions?: readonly number[] | undefined; /** The failed windows, each drawn as a band before the row it sits before (#853). */ failures?: readonly PlacedFailure[] | undefined; /** Padding rows below the last real one (a grouped sheet: `> 0` ⇒ each open group ends with a blank line). */ blanks: number; /** Whether blanks may show — the inline arm, or a paged source that is exhausted. */ exhausted: boolean; /** The source's total element count, once known (positions past the resident run). */ total: number | undefined; head: SheetBand | undefined; tail: SheetBand | undefined; /** Whether each group is folded, and whether a line's sub rows were opened or closed by hand (`undefined` = never touched: closed). */ grouped?: { foldedOf: (row: SheetRowValue) => boolean; subRowsOpen?: ((lineId: string) => boolean | undefined) | undefined; } | undefined; } /** * The body items, in order: head band · real rows (a failed window's band * where its rows would be, #853) · tail band · blanks. A grouped sheet builds * bands with their lines ({@link buildGroupedBody}). Under the lens the body * is the lens's ({@link buildLensBody}). */ export declare function buildBody(input: SheetBodyInput): SheetBodyItem[]; /** One item of the lens's layout, the local layer applied to its rows (#1349): what {@link buildLensBody} draws. */ export type LensBodyInput = /** A row drawn — one the narrowing holds, or one the planner added — at its position in the record. */ { kind: "row"; position: number; row: SheetRowValue; hit: boolean; } /** A stretch still being read or placed. */ | { kind: "band"; band: SheetBand; } /** A segment whose read failed, or whose rows disagree with where e3 placed the narrowing's. */ | { kind: "failed"; failure: SheetWindowFailure; }; /** * The body under the lens (#1349): what it laid out over the record, in its * order — each row drawn and its bands. A grouped sheet's rows are its groups, * the records the narrowing holds: each shown group draws its band and, unless * folded, its lines and their open sub rows — a match's lines marked — and no * blank line, for a lens never invites the next row. * * @param items - The layout, the local layer applied to its rows * @param grouped - A grouped sheet's folds and open sub rows (`undefined` on a flat sheet) * @returns The body items */ export declare function buildLensBody(items: readonly LensBodyInput[], grouped: SheetBodyInput["grouped"]): SheetBodyItem[]; /** The heights a sheet draws its items at (#855): a row's, a group band's and a sub row's least height. */ export interface SheetGeometry { rowPx: number; bandPx: number; subRowPx: number; } /** * A body item's least height (#855): what the rows are estimated at until * they are measured, and what the paged driver sizes a window by. * * @param item - The body item * @param g - The sheet's geometry * @returns Its height in px */ export declare function itemPx(item: SheetBodyItem, g: SheetGeometry): number; /** * What one source row draws, in px (#855): the least height of the items the * body builds for it. A flat row — or a loose row between the groups (#846) — * is one row; a group is its band and, unless folded, its lines, their open * sub rows and its blank line when the sheet draws one. The paged driver sizes * a window by it, so an unloaded band is as tall as its rows will be. * * @param row - A source row * @param g - The sheet's geometry * @param grouped - A grouped sheet's folds and open sub rows (`undefined` on a flat sheet) * @param blanks - The grouped sheet's blank lines per group (`0` when it draws none) * @returns Its height in px */ export declare function drawnPx(row: SheetRowValue, g: SheetGeometry, grouped: SheetBodyInput["grouped"], blanks: number): number; /** * The body with the copilot's proposed rows spliced in under their anchor * (B§5.2): dashed-topped hatched rows with real row numbers, excluded from * the row space like bands. Under a line anchor they number on within the * group, after the line's open sub rows. */ export declare function withProposals(body: readonly SheetBodyItem[], anchorBodyIndex: number, rows: readonly { cells: ReadonlyMap; meta: string; }[]): SheetBodyItem[]; /** Whether a body item occupies the ROW space (paged bands, sub rows and proposals do not; group summaries do). */ export declare function isRowSpace(item: SheetBodyItem): boolean; /** The body index of the real row (or the group band) with `id`, if resident. */ export declare function bodyIndexOfId(body: readonly SheetBodyItem[], id: string): number; /** The synthetic id of a blank item — a padding row's by position, a group's blank line's by group. */ export declare function blankIdOf(item: Extract): string; /** The last REAL row's id, if any — what an insert at the end lands after. */ export declare function lastRealId(body: readonly SheetBodyItem[]): string | undefined; /** A mounted body item's box on the screen (px). */ export interface ItemBox { top: number; bottom: number; } /** * What sticks under the column header, read off the MOUNTED rows rather than * estimated offsets, so rows that grew (wrapped chips, a sub row's wrapped * detail) never skew it: * * - the BAND of the group the row under the header belongs to, once that band * has scrolled under the header (#740, G1) — never a folded group's, which * has no lines under the header to stand for, nor over a loose row (#846), * which belongs to no group; * - under that band, the open LINE the row under the band belongs to, once * the line's own row has scrolled under the band — its sub rows scroll * under it, and as its last sub row leaves, the line is pushed up with it. * * An item within a pixel of an edge counts as clear of it, so a row brought * to sit exactly under the band stops sticking. * * @param body - The body items * @param boxes - The mounted items' boxes, by body index * @param headerBottom - The header's bottom edge, on the boxes' scale * @param bandPx - The sticking band's height * @param rowPx - A line's height when its own row is not mounted * @returns The sticking band's body index; the sticking line's, and the top it sits at */ export declare function stickyRows(body: readonly SheetBodyItem[], boxes: ReadonlyMap, headerBottom: number, bandPx: number, rowPx: number): { band: number | undefined; line: { index: number; top: number; } | undefined; }; /** The blank-padding default (B§7). */ export declare const DEFAULT_BLANKS = 18; /** The gutter width default (px, the §7 sheet). */ export declare const DEFAULT_GUTTER_PX = 80; /** The band height (px) of a paged source's unloaded run when the ledger has no better geometry. */ export declare const BAND_MIN_PX = 22; /** The bottom padding below the last blank row (px). */ export declare const BOTTOM_PAD_PX = 120; /** The decoded root's density → recipe size + row height. */ export declare function densityOf(value: SheetRootValue): "sm" | "md" | "lg"; //# sourceMappingURL=model.d.ts.map