/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The Plan's decoded-value view model (`Plan Spec.md` §6.2) — pure selectors * over the canvas rows: the row-tree index, the visible-row derivation (grain * × collapsed subtrees), and per-row height estimation for the virtualizer. No * React, no DOM. * * Rows arrive as BLOCKS (#823) — the series list's blocks in layout order, each * an ordered stream (#822) whose order IS the render order, each parent before * its descendants — and the canvas draws the blocks one after another. A row * carries a typed id and the block it came from; {@link toCanvasRows} keys * every row by its id's canonical text, which is what every map, DOM attribute * and piece of view state here keys by. The visible walk follows the STREAM and * hides by the explicit `parent` keys — never a tree walk, because a parent's * descendants need not follow it directly (an entry's children under `views` * come after all of its view rows). The derivations still walk the tree, since * a bottom-up aggregate is the same in any order. * * A row's height is a function of facts read off the row once * ({@link heightFactsOf}) and of the UI state ({@link factsHeight}); a paged * window keeps those facts, and nothing else, after its rows are evicted * ({@link windowSkeleton}), so the bands that stand for evicted windows follow * a collapse, a chart toggle or the grain exactly (#823). * * The derivations (`derive.ts`), the body items and link graph * (`body-items.ts`), the instant walks (`row-instants.ts`) and the tree walks * (`row-tree.ts`) live beside it and are re-exported here (#815). * * @packageDocumentation */ import { type OptionType, type StringType, type ValueTypeOf } from "@elaraai/east"; import { Plan } from "@elaraai/e3-ui/internal"; import type { PlanGrain, PlanUiState, RowKey } from "./plan-state.js"; import type { PlanAxisKind } from "./instant.js"; import { type PlanDerived } from "./derive.js"; import { type LinkFamily, type PlanGathered } from "./body-items.js"; export { forEachInstant, axisKindMismatches, type PlanAxisMismatch } from "./row-instants.js"; export { tableRollupSeries, deriveBands, deriveHeatCells, deriveTableCells, deriveTableSeries, derivePlan, stableDerived, type DerivedBand, type HeatScale, type PlanRowDiagnostic, type PlanDerived, type PlanParentSubtotal, type PlanParentSubtotals, } from "./derive.js"; export { linkedRowKeys, bodyItemKey, rowItemKey, placeFailures, firstDiagnosticItem, focusBandKey, focusBodyItems, focusGathers, focusGatheredKeys, focusRoleCounts, focusRoleOf, deriveLinkFamily, PLAN_FOCUS_ROLES, type PlanFocusBand, type PlanFocusRole, type PlanGathered, type PlanBand, type PlanWindowFailure, type PlanBodyItem, type PlanLaneBand, type PlanLaneTracks, type LinkFamily, } from "./body-items.js"; /** The decoded Plan root value. */ export type PlanRootValue = ValueTypeOf; /** One decoded WIRE row — the IR's `PlanRowType` value, as the source serves it. */ export type PlanWireRow = ValueTypeOf; /** One decoded WIRE block — the IR's `PlanBlockType` value (#823): a data * series' rows, which a paged canvas pages on its own, or fixed rows no entry * produces (a section's header, hand-built rows). */ export type PlanWireBlock = ValueTypeOf; export { rowKeyOf, rowIdOfKey, rowKeyWords, type PlanRowId } from "./row-key.js"; /** One decoded link edge (the R1 graph / K8 ribbon shape). */ export type PlanLinkValue = ValueTypeOf; /** * One CANVAS row — a wire row keyed for the canvas (#822). * * @remarks * `key` is the canonical `.east` text of the row's typed `id` * ({@link rowKeyOf}): the index every map, DOM attribute and piece of view * state keys by, and what a drag names the row with. `parent` is the parent's * key. The typed `id` rides along for every payload that names the row — a * callback never sees the text. */ export type PlanRowValue = Omit & { /** The row's key — the canonical text of its id; unique on the canvas. */ readonly key: RowKey; /** The key of the row it nests under (`none` at the top of the stream). */ readonly parent: ValueTypeOf>; /** When this row repeats the id an earlier row in its stream carries: that * row's key. The row keeps a unique key and renders as a diagnostic * (#811) — never a silent drop. */ readonly duplicateOf: RowKey | undefined; /** The block the row came from — its place in the canvas's layout (#823). */ readonly block: number; }; /** * Key a stream of wire rows for the canvas — each row's `key` its id's * canonical text and its `parent` the parent's. * * @remarks * Ids are unique by construction (series keys are unique across the series * tree and a path is unique within a collection) except where hand-built rows * repeat a key. A repeat keeps a distinct key — its text with `#n` appended, * which no printed id can end with — and names the row it repeats in * `duplicateOf`, so it renders as a diagnostic in place. * * @param wire - The rows in stream order * @param block - The block they came from (#823) * @param seen - The ids keyed so far on the canvas, and how often — shared * across a canvas's blocks so a repeat in a later block is caught too * @returns The canvas rows, in the same order */ export declare function toCanvasRows(wire: ReadonlyArray, block?: number, seen?: Map): PlanRowValue[]; /** * The canvas rows of an inline canvas — every block's rows in layout order, * keyed across the whole canvas ({@link toCanvasRows}), once per decoded * block list. * * @remarks * The controller and the canvas both read a root's inline rows. A decoded * value is never mutated, so its array's identity names its rows, and the two * share one keying — and one set of row objects. * * @param blocks - A decoded inline canvas's blocks * @returns Its canvas rows */ export declare function canvasRowsOf(blocks: ReadonlyArray): readonly PlanRowValue[]; /** * Key a paged canvas's resident rows across its blocks — each block's windows * were keyed on their own when they were read, so a later block repeating an * id an earlier block carries (a bound series list naming one series twice) * is re-keyed here, exactly as {@link canvasRowsOf} keys the same rows inline. * * @param rows - The resident rows, block by block * @returns The same rows — the same array when nothing repeats */ export declare function keyAcrossBlocks(rows: readonly PlanRowValue[]): readonly PlanRowValue[]; /** * Whether a row's derived numbers — its member count and its strip — can * cover rows from more than one paged window (#822). * * @remarks * Only a TOP-LEVEL section header's can: its members are its series' entries, * which the source's windows share out. Every other parent derives from one * entry's subtree, which the entry carries whole and a window holds whole, or * from hand-built rows every window serves complete — so its numbers are * exact whether the canvas is inline or paged, loaded or not. A section adds * no path segment, so one at the top (or inside another at the top) sits at * the empty path; one inside an entry sits at that entry's path, and its * members are that entry's. * * @param row - A canvas row * @returns Whether its derived numbers depend on which windows have landed */ export declare function spansWindows(row: PlanRowValue): boolean; /** The canvas rows indexed for traversal. */ export interface PlanRowIndex { /** Rows in STREAM order — the render order. */ rows: ReadonlyArray; /** Row lookup by key. */ byKey: ReadonlyMap; /** Direct children (stream order) by parent key. */ children: ReadonlyMap; /** Top rows (`parent: none`), stream order. */ roots: ReadonlyArray; /** Nesting depth by key (top rows = 0). */ depth: ReadonlyMap; /** The keys of rows the IR declares initially collapsed — any row with * children may be (#822). */ initiallyCollapsed: ReadonlySet; } /** * Build the row index once per decoded value. * * @param rows - The canvas rows in stream order ({@link toCanvasRows}) * @returns The index every other selector walks */ export declare function indexRows(rows: ReadonlyArray): PlanRowIndex; /** One visible line of the canvas body. */ export interface VisibleRow { row: PlanRowValue; /** Nesting depth (drives the 8px/level gutter indent). */ depth: number; /** For group strips / nesting parents: whether the subtree is collapsed. */ collapsed: boolean; /** A row a links focus gathers under its role's band (#1680's review): its role, and the labels of the rows it * nests under, which its sub line says. Absent on every other line. */ gathered?: PlanGathered | undefined; } /** * The visible rows for the current UI state — the §5/§6 derivation: * * - `resource` grain (default): the stream, in order; a collapsed row keeps * its own line and hides exactly its descendants. * - `group` grain: every top-level group strip collapses to its summary * strip; other top rows stay. * * The walk follows the STREAM and hides a row whose parent is hidden or * collapsed — by the explicit `parent` keys, never a tree walk, since a * parent's descendants need not follow it directly (#822: an entry's children * under `views` follow all of its view rows while nesting under the first). * A parent precedes its descendants, so one pass suffices. A row whose parent * is nowhere in the stream is not drawn — it derives nothing either * (`derivePlan` walks the same tree). * * Pinned rows are excluded here — they render above the virtualised body, * under the ruler (`pinnedRows`) — and so are their descendants. * * A links focus reveals nothing here: it gathers its rows under its role bands * wherever they sit, folded or not, and its other rows keep their folds * (`focusBodyItems`, #1680's review). */ export declare function visibleRows(index: PlanRowIndex, /** The UI facts the rows follow — the grain and the collapsed set. */ ui: Pick): VisibleRow[]; /** The pinned rows (IR order) — rendered above the virtualised body. */ export declare function pinnedRows(index: PlanRowIndex): PlanRowValue[]; /** Default span/bucket/cards/table row height. Tables share it: numerals need * no less room than a bar does, and a table row at the dense height beside * default rows read as a mistake. */ export declare const ROW_H: number; /** Dense row height (`density: compact`). */ export declare const ROW_H_DENSE: number; /** Group band height. */ export declare const GROUP_H: number; /** Group summary heat-strip height (collapsed group with cells). */ export declare const GROUP_STRIP_H: number; /** Chart spark / expanded heights. */ export declare const CHART_SPARK_H: number; export declare const CHART_EXPANDED_H: number; /** Heat ROW height — 22px cells (§8) + the 3px insets above and below. */ export declare const HEAT_ROW_H: number; /** Two-line-gutter row minimum (the §8 sheet: row min-height 42px). */ export declare const ROW_H_STACKED: number; /** CONTEXT STRIP height (R2) — an unfocused row of an expand focus compresses * to this, keeping its marks on the shared axis at {@link STRIP_MARK_H}; and a * pinned row a links focus does not gather, its name, value and dot kept in * their cells (#1680's review). */ export declare const STRIP_H: number; /** The mark height inside a context strip — v2's "bars reduced to 7px marks". */ export declare const STRIP_MARK_H: number; /** The row focus (R1 links / R2 expand) threaded to {@link rowHeight} and the body. */ export interface PlanFocusCtx { kind: "links" | "expand"; /** The focused row. */ key: RowKey; /** A links focus (#1680's review): the focused row's family, which it gathers under its role bands, and whether * the band every other row folds into is open. */ links?: { readonly family: LinkFamily; readonly others: boolean; } | undefined; /** R2 — the clamped developer-render height, in px. * * The render lives INSIDE the focused row rather than beside it, because * the gutter has to grow with it: v2 gives the expanded row ONE tall * gutter cell, top-aligned, whose new space is the author's * (`expandGutter`). A render mounted as a sibling row would leave that * cell 32px tall with a blank column beside the render — which is * precisely the tell that the row did not really expand. */ renderPx?: number | undefined; } /** Parse a CSS px size (`"120px"` / `"120"`) to a number; `undefined` for * anything a virtualized row can't be (`"fill"`, percentages). * * The unit test is the doc: `parseFloat("50%")` is `50`, so bare * `parseFloat` silently turned a percentage height into 50px (#615) — * only a `px` suffix or a bare number qualifies. */ export declare function pxOf(size: string): number | undefined; /** * What a row's kind contributes to its height — the part of the kind a height * reads, and nothing else (#823). * * - `group` — whether a collapsed band shows a summary strip. * - `chart` — its declared fixed px, whether it is declared expanded, and the * px its expanded state opens to. * - `table` — how many lines a vertical multi-position stack prints (0 when it * does not stack). * - `buckets` — how many lanes its cells hold. * - `heat`, `row` — every other kind: one height each. */ export type RowKindHeight = { t: "group"; strip: boolean; } | { t: "chart"; fixed: number | undefined; expanded: boolean; expandedPx: number | undefined; expandable: boolean; } | { t: "heat"; } | { t: "table"; lines: number; } | { t: "buckets"; lanes: number; } | { t: "row"; }; /** * Everything a row's height depends on besides the UI state, read once from * the row and its derived numbers (#823). With the UI state it gives the * height ({@link factsHeight}), and it is what an evicted paged window keeps of * each of its rows ({@link WindowSkeleton}): no content, only these. */ export interface RowHeightFacts { /** The row's own declared px (`height`), when it is a px size. */ explicit: number | undefined; /** It renders as a diagnostic row (#811) — its message, never its marks. */ diagnostic: boolean; /** A two-line gutter (a sub line, or the stacked flag) — floors the row. */ twoLine: boolean; /** What its kind contributes. */ kind: RowKindHeight; } /** * A row's height facts. * * @param row - The canvas row * @param derived - The derived numbers, when available. A subtotal parent * carries NO series of its own — its positions are derived — so without * this a vertical multi-position subtotal would measure as a single line and * render taller than the virtualizer was told. * @returns Its facts */ export declare function heightFactsOf(row: PlanRowValue, derived?: PlanDerived): RowHeightFacts; /** * A row's pixel height from its facts and the UI state — the ONE height * arithmetic: the rendered rows ({@link rowHeight}) and the paged ledger's * windows ({@link skeletonHeight}) both come through here, so a band that * stands for evicted rows is exactly as tall as those rows draw (#823). * * @param f - The row's facts * @param key - The row's key * @param collapsed - Whether its subtree is collapsed * @param dense - Whether the canvas is dense * @param chartsExpanded - The chart rows the user expanded * @param focus - An expand focus, when one is active (R2 strips); a links focus changes no body row's height here — * its gathered rows say their path on a second line (`rowHeight`), and its other rows draw as they are * @returns The height, px */ export declare function factsHeight(f: RowHeightFacts, key: RowKey, collapsed: boolean, dense: boolean, chartsExpanded: ReadonlySet, focus?: PlanFocusCtx): number; /** * The chart rows the focused row of an expand focus draws expanded (#1680's * review): an expandable chart's spark ↔ chart is its expand control's, so its * render open, it draws expanded in its band — the user's own expanded rows * beside it. * * @param key - The focused row * @param expandable - Whether its chart is expandable * @param chartsExpanded - The chart rows the user expanded * @returns The chart rows drawn expanded */ export declare function chartsOpenFor(key: RowKey, expandable: boolean, chartsExpanded: ReadonlySet): ReadonlySet; /** * A visible row's pixel height — the virtualizer's size for it AND the height * it renders at (rows are fixed-height by kind), from the density's geometry * table ({@link planGeometry}). * * A links focus (#1680's review) folds each pinned row it does not gather — * above the body, where it cannot fold away — to a 16px strip, and a row it * gathers says the rows it nests under on its sub line, so it takes two lines. * * @param v - The visible row * @param dense - Whether the canvas is dense * @param chartsExpanded - The chart rows the user expanded * @param focus - The row focus, when one is active (R1 links / R2 strips) * @param derived - The derived numbers, when available ({@link heightFactsOf}) * @returns The height, px */ export declare function rowHeight(v: VisibleRow, dense: boolean, chartsExpanded: ReadonlySet, focus?: PlanFocusCtx, derived?: PlanDerived): number; /** * What a paged window keeps of one block's rows once they are evicted (#823): * per row, in stream order, its key, where its parent sits, whether it is * pinned, its declared collapse and its height facts. No content — enough to * say exactly how tall the rows would draw under any UI state, so a band that * stands for them follows a collapse, a chart toggle or the grain without the * window being read again. */ export interface WindowSkeleton { /** Each row's key. */ readonly keys: readonly RowKey[]; /** Each row's parent's index here — −1 when it nests under a row outside * the window (the section header its block sits under) or none. */ readonly parents: readonly number[]; /** Whether the row is at the top of the canvas (no parent at all) — the * group grain folds a group row there. */ readonly top: readonly boolean[]; /** Whether the row is pinned — pinned rows draw above the body. */ readonly pinned: readonly boolean[]; /** Whether the row declares itself collapsed. */ readonly declared: readonly boolean[]; /** Each row's height facts. */ readonly facts: readonly RowHeightFacts[]; } /** * One window's skeleton — computed ONCE, when the window lands. * * @remarks * A window holds its entries whole (#823), so its own rows derive everything * a height reads — a subtotal parent's derived positions, which rows are * diagnostic rows. A block's top rows may nest under a row no window holds * (a section's header, a fixed block): for the derivation they are the * window's roots, and they stay open whatever that header does — when the * header folds, the canvas hides the whole block, bands and all. * * @param rows - One block's rows from one window, in stream order * @param axisKind - The axis kind — a row on another arm measures as the * diagnostic row it renders as * @returns The skeleton */ export declare function windowSkeleton(rows: readonly PlanRowValue[], axisKind?: PlanAxisKind): WindowSkeleton; /** The UI state a skeleton's height reads. */ export interface SkeletonUi { /** The active grain. */ grain: PlanGrain; /** Whether a row's subtree is collapsed — given its key and whether it * declares itself collapsed (a paged row may not have been seeded yet). */ collapsed: (key: RowKey, declared: boolean) => boolean; /** The chart rows the user expanded. */ chartsExpanded: ReadonlySet; } /** * The UI state a window rests at — its declared collapse, no chart expanded, * no focus — under a grain. * * @param grain - The DECLARED grain * @returns The state */ export declare function restUi(grain: PlanGrain): SkeletonUi; /** * How tall a window's rows draw under a UI state — the visible-row walk * ({@link visibleRows}) and the height arithmetic ({@link factsHeight}) over * the skeleton, so the number is the one the body would draw the same rows at. * * @param sk - The window's skeleton * @param ui - The UI state * @param dense - Whether the canvas is dense * @param focus - An expand focus, when one is active — its context strips * (a links focus gathers its rows out of every window into its role bands, * and draws its other rows as they are: its windows measure as though * unfocused) * @returns The height, px */ export declare function skeletonHeight(sk: WindowSkeleton, ui: SkeletonUi, dense: boolean, focus?: PlanFocusCtx): number; /** * The pixel height a window's rows render AT REST (#613) — declared collapse * applied, chart expansion at its declared state, no focus context, pinned * rows excluded (they render in the header, not the body). What the window * ledger seeds its slot rate from: a rate taken from whatever the UI state * happened to be when the first window landed (mid-focus, say) would describe * every unvisited window wrongly for the life of the source. * * @param windowRows - One window's rows, as the source served them * @param grain - The DECLARED grain (`value.grain`; user grain is transient) * @param dense - The declared density * @param axisKind - The axis kind — a row on another arm measures as the * diagnostic row it renders as * @returns The at-rest pixel height of the window's body rows */ export declare function windowRestHeight(windowRows: ReadonlyArray, grain: PlanGrain, dense: boolean, axisKind?: PlanAxisKind): number; //# sourceMappingURL=model.d.ts.map