/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The canvas body's items and the link graph they are gathered by (split out * of `model.ts`, #815): the R1 family closure and the role bands a links focus * gathers it under, the unloaded bands of a paged source (#577), the error * bands of failed windows (#811), and each item's identity (#812). * * @packageDocumentation */ import type { PlanFocusCtx, PlanLinkValue, PlanRowIndex, VisibleRow } from "./model.js"; import type { RowKey } from "./plan-state.js"; import type { PlanRowDiagnostic } from "./derive.js"; /** Every row key any link edge touches — the rows that grow the `links` control. * A link names its ends by run ref (#824), each carrying its row's id (#822); * the graph keys by the ids' text. */ export declare function linkedRowKeys(links: readonly PlanLinkValue[]): ReadonlySet; /** * A row's part in a links focus (#1680's review): the focused row itself, a row * only upstream of it, a row only downstream of it, or a row both — linked. */ export type PlanFocusRole = "upstream" | "focused" | "linked" | "downstream"; /** The roles a links focus gathers its rows under, in the order their bands stand: upstream, the focused row, the rows * linked both ways, downstream. */ export declare const PLAN_FOCUS_ROLES: readonly PlanFocusRole[]; /** * A band of a links focus's body (#1680's review): a role's, over the rows it * gathers, or the one every other row folds into. */ export interface PlanFocusBand { /** Its role, or `others` for the band the rows the focus does not gather fold into. */ role: PlanFocusRole | "others"; /** * The rows it stands for: a role's family rows wherever the canvas draws them — under the band, pinned above the * body, or not held, folded into the others' band — or the other data rows (their groups' bands not counted). */ count: number; /** Whether its rows show under it: a role's always do, the others' once the band is opened. */ open: boolean; /** The lane tracks it holds: the rule above the first row it gathers, opened for the family's lanes and captions — * the band stands in for that rule, and is as tall as the tracks where they need more than its own height. */ lanes?: PlanLaneTracks | undefined; } /** * A rule a links focus opens for its family's lanes and captions (#1680's review, `shared/links/lanes.ts`): the rule, * by the place among the gathered rows of the row below it, and its tracks' height. */ export interface PlanLaneTracks { readonly rule: number; readonly px: number; } /** A band a links focus opens a rule between two rows it gathers into, holding the rule's lane tracks (#1680's review). */ export interface PlanLaneBand extends PlanLaneTracks { /** The row below it. */ readonly above: RowKey; } /** A row a links focus gathers under its role's band (#1680's review). */ export interface PlanGathered { /** Its role. */ readonly role: PlanFocusRole; /** The labels of the rows it nests under, outermost first — its sub line says them, which tells two rows of one * name apart. Empty for a row at the top. */ readonly path: readonly string[]; } /** * A run of source elements that is NOT resident (#577), rendered as one band. * * Its height comes from the window ledger, so the band and the rows that * replace it occupy exactly the same space — scrolling in loads content without * moving anything below it, and eviction puts the band back with nothing * shifting either. Each paged block has its own (#823): its rows' share of the * elements the band covers. */ export interface PlanBand { /** The block the band belongs to (#823). */ block: number; at: "head" | "tail"; /** First source element the band covers. */ from: number; /** Last source element the band covers (inclusive). */ to: number; /** The band's pixel height. */ px: number; /** Which of its elements are loading (#1082): from the first element of * the first window it covers that is in flight to the last element of * the last (inclusive), when any is. A band far from every window in * flight is loading nothing — it says how many elements it holds. */ loading?: { from: number; to: number; } | undefined; } /** * A resident window whose read FAILED (#811) — one error band where the * window's rows would be, carrying the reason and a Retry. * * The failure belongs to its window: every other window keeps landing and * rendering around it. One read serves every block (#823), so a failed window * is a band in each block that holds it. */ export interface PlanWindowFailure { /** The block the band stands in (#823). */ block: number; /** The window index. */ w: number; /** First source element the window covers. */ from: number; /** Last source element the window covers (inclusive). */ to: number; /** The band's pixel height — the window's ledger slot, floored so the * reason and the Retry stay legible in a short last window. */ px: number; /** Why the read failed. */ error: string; } /** One line of the canvas body: a row, a links focus's band or a rule it opens * for its lanes (#1680's review), an unloaded run of the source (#577, one per * paged block's end — #823), or a window whose read failed (#811). * * The R2 developer render is NOT an item here — it renders inside the * focused row, which grows to hold it (see {@link PlanFocusCtx.renderPx}). * Expand focus still stays inside the virtualizer either way; putting the * render in the row is what lets the GUTTER grow with it. */ export type PlanBodyItem = { kind: "row"; row: VisibleRow; } | { kind: "focus"; band: PlanFocusBand; } | { kind: "lanes"; lanes: PlanLaneBand; } | { kind: "band"; band: PlanBand; } | { kind: "failed"; failure: PlanWindowFailure; }; /** * A body item's identity (#812) — its row's key, a links focus band's role, a * lane band's row below it, its band's block and end, its failed window's * block and window — prefixed by * kind, so no two items of a body share one. The virtualizer keys rows by it, * so a row keeps its component instance when a collapse, a focus or a landing * window moves it; keyed by index, the instance at a moved row's old index was * handed whichever row now sat there. * * @param item - The body item * @returns Its key, unique within one body */ export declare function bodyItemKey(item: PlanBodyItem): string; /** * A links focus band's item key (#1680's review) — what {@link bodyItemKey} * gives it, and what a gathered row's ← steps to. * * @param role - The band's role * @returns Its item key */ export declare function focusBandKey(role: PlanFocusRole | "others"): string; /** * A ROW's item key — what {@link bodyItemKey} gives its body item, and a * pinned row (which the body does not hold) goes by too (#819). * * @param key - The row key * @returns Its item key */ export declare function rowItemKey(key: RowKey): string; /** * Place each failed window's band where its rows would be (#811): after the * last row that came from an EARLIER window, or first when none did. * * @remarks * A block's windows serve its entries in key order and its rows concatenate * them in window order (#823), so a window's rows sit between its neighbours' * — its band goes in the seam. Called once per block, over that block's items. * * @param items - One block's body items, rows in visible order * @param failures - That block's failed windows * @param windowOf - Which window a resident row came from * @returns The items with a `failed` band placed per failure (the same array * when there are none) */ export declare function placeFailures(items: readonly PlanBodyItem[], failures: readonly PlanWindowFailure[], windowOf: (key: RowKey) => number | undefined): readonly PlanBodyItem[]; /** * The body item the diagnostics chip seeks to (#811): the first diagnostic * row in body order — or, when a collapsed group hides it, that group's band. * * @param items - The body items, in order * @param index - The row-tree index * @param diagnostics - The diagnostic rows (`PlanDerived.diagnostics`) * @returns The item index, or `undefined` when no diagnostic row is reachable */ export declare function firstDiagnosticItem(items: readonly PlanBodyItem[], index: PlanRowIndex, diagnostics: ReadonlyMap): number | undefined; /** * A row's role in a links focus (#1680's review): `focused` for the focused * row, `linked` for one both upstream and downstream of it, else `upstream` or * `downstream` — `undefined` for a row the focus does not gather. * * @param family - The focused row's family ({@link deriveLinkFamily}) * @param focus - The focused row * @param key - The row * @returns Its role */ export declare function focusRoleOf(family: LinkFamily, focus: RowKey, key: RowKey): PlanFocusRole | undefined; /** * Whether a links focus gathers a row: the focused row, or one of its family. * * @param focus - The row focus * @param key - The row * @returns Whether a links focus gathers it — `false` under any other focus */ export declare function focusGathers(focus: PlanFocusCtx, key: RowKey): boolean; /** * The rows a links focus gathers, in the order its body stands them (#1680's * review): upstream, the focused row, linked, downstream, each role's in stream * order — the rows its family's lanes are planned over, rule `r` above row `r` * (`shared/links/lanes.ts`). * * @param index - The row index * @param focus - The focused row * @param family - Its family ({@link deriveLinkFamily}) * @returns The gathered rows' keys, top to bottom */ export declare function focusGatheredKeys(index: PlanRowIndex, focus: RowKey, family: LinkFamily): RowKey[]; /** * A links focus's body (#1680's review): its family gathered under one band * per role — upstream, the focused row, linked (only where a row is both), * downstream — each 26px, in the open group band's look, its rows under it in * stream order at one level, wherever they sit and however their sections are * folded; then ONE band every other row folds into, which opens in place. * * @remarks * A role with no rows keeps its band, which says so — the Linked band alone * stands only for a family that has one. A gathered row says the rows it nests * under on its sub line, which tells two rows of one name apart, and opens * nothing: its subtree is the other rows'. Pinned rows draw above the body, and * a row under one draws nowhere — neither is gathered. A role's band counts its * family's rows wherever the canvas draws them: the rows under it, a pinned row * of the family, and a row the canvas does not hold but has placed — one of a * paged source's evicted windows — whose links end at the others' band while * it is folded, where that row is. The others' band counts every other data row * the canvas holds, folded or not; opened, it holds the body's own items for * them — their groups, the unloaded runs of a paged source and its failed * windows among them — as they draw with no focus. * * A rule the family's lanes or one-row captions take (`shared/links/lanes.ts`) * opens into a band of their tracks: the role's band, where the rule lies * between it and its first row, else a lane band of its own between the two * rows. * * @param index - The row index * @param focus - The focused row * @param family - Its family ({@link deriveLinkFamily}) * @param others - Whether the others' band is open, and the items it holds when it is * @param placed - Whether the canvas has placed a row it does not hold (a paged source's evicted window's); none, inline * @param lanes - The rules opened for lanes, by the place of the row below each among {@link focusGatheredKeys}, and each one's tracks' height; none, inline * @returns The body's items */ export declare function focusBodyItems(index: PlanRowIndex, focus: RowKey, family: LinkFamily, others: { readonly open: boolean; readonly items: readonly PlanBodyItem[]; }, placed?: (key: RowKey) => boolean, lanes?: ReadonlyMap): PlanBodyItem[]; /** * The rows a links focus's role bands count, as its caption counts them * (#1680's review): only upstream, both ways, only downstream. * * @param items - The body's items * @returns Each role's count — `undefined` for a body with no links focus */ export declare function focusRoleCounts(items: readonly PlanBodyItem[]): { upstream: number; linked: number; downstream: number; } | undefined; /** A focused row's transitive family over the link graph. */ export interface LinkFamily { /** Rows reaching the focus via edges (any depth). */ upstream: ReadonlySet; /** Rows reachable from the focus via edges (any depth). */ downstream: ReadonlySet; /** Union of both (the full-height set, focus excluded). */ all: ReadonlySet; } /** * Derive the focused row's transitive upstream + downstream family — the * links-focus gather set (R1). Any depth, wherever the rows live; a row * reachable both ways lands in both sets (gathered under the Linked band). */ export declare function deriveLinkFamily(links: readonly PlanLinkValue[], key: RowKey): LinkFamily; //# sourceMappingURL=body-items.d.ts.map