/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. * * The paged canvas's driver (#577), framework-free (#815) — the loop between * where the viewport is and which windows are resident, as plain state. The * run, its bands, the stand-in, the demand and the jump's pin are the windowed * logic it shares with the Sheet's driver (`shared/windowed.ts`, #1398); what * is the Plan's own is its blocks, their skeletons, the rows it has seen and * the committed-snapshot handshake its jumps settle on. * * # Blocks page on their own (#823) * * A canvas is its series list's blocks, one after another. Each data series is * a PAGED block — its entries' rows, each entry whole — and a section's header * or a list of hand-built rows is a FIXED block, the same in every window and * drawn once. One read of a window serves every block (the derived source * applies the whole series list to it), so windows are fetched and cached * ONCE, for all of them. What each paged block owns is its geometry: * * - a {@link WindowLedger}, the scroll geometry of its rows in source * ELEMENTS, which remembers every window it has ever measured; * - a {@link Residency}, one contiguous run of whole windows, which follows * the viewport a window at a time and rebases on a far jump; * - the SKELETON of every window it has seen ({@link WindowSkeleton}) — what * its rows' heights depend on, and nothing else — so the ledger is measured * under the CURRENT collapse, grain and charts, and an evicted window's band * follows them exactly ({@link PagingDriver.remeasure}). * * The viewport is in one block at a time: a report names a row, a band or a * failed window, which name their block, and only that block's demand moves. * A jump moves every block — the first one that shows the sought entry is * where the canvas scrolls. * * ``` * viewport ──▶ block's residency.advance ──▶ readWindows ──▶ each block's ledger * ▲ │ * └──────────────────── the renderer's range signal ◀────────────┘ * ``` * * # A window loading beside the run never moves it (#876) * * What a block draws is its RUN: the stretch of its resident windows that are * in — landed, or failed (#811) — around the one nearest the element the * viewport is centred on. A window still in flight ends the stretch, since its * rows are not there to hold its slot: it, and every window past it, stay the * band's until it lands, and landing it takes exactly the band's slot. So a * window loading above or below the rows on screen never takes them off it, * even when a window beyond it lands first, and a rebased run whose windows * are all on the wire is still the whole of its block — its bands meet where * it will land. The bands follow the run, not the residency, and so does * where a band report measures from. The Sheet's driver does the same. * * # One settle, one notification * * Every input — a source, a viewport report, a jump, a Retry, a window landing * (its tracked channel firing) — runs ONE settle: read the demanded windows, * teach the ledgers what landed, advance the demand, and read again while the * demand moved, until it holds still. Only then is the snapshot published, and * only when it differs (#815). * * # A band report carries pixels * * A head/tail band is a single body item spanning every unloaded window on that * side, so "over the band" alone can only name the window adjacent to the run * — which walks the gap one fetch per landing. The report therefore carries how * many PIXELS into the band the viewport center sits (#612), measured from the * band's own top, which the block's ledger places exactly (the band was sized * FROM the ledger): the window under the scrollbar thumb resolves through * {@link elementAtOffset}, and a far drag rebases instead of walking. * * # Demand follows intent * * Nothing is fetched or evicted while the view flies past: the frame reports * a scroll at rest once it shows intent — held still 100 ms, a scrollbar * drag's pause among them, or slowed below a viewport per 200 ms (#1398, CL6) * — so a fling asks for the window it slows over before the gesture ends. Each * block reads ahead the way its viewport travels, two windows ahead and one * behind (`travelOf`). * * # What the view waits for * * The footer's loading line and the frame's busy follow the windows the view * shows — each row's in the reported range, a run's nearest its rows, the * window under the view and a jump's target (`viewLoading`) — never a window * read ahead of it, which nothing on screen waits for (#1398). Settled with * the rest, so a landing says it in the commit that draws it. They follow them * from the moment the view shows them: the window under the view that is * neither in nor asked yet — the view on its way over rows not read, or * resting there before it has shown the intent its read waits for (CL6) — is * waited for already, so the line's reveal clock runs from the view's arrival, * never from the read's. * * # A jump owns the viewport (#812) * * A key search REBASES every block on its target window, but the canvas can * only scroll to the target once its row is on screen. Until then every * viewport report is taken from where the canvas still is, and honouring one * would rebase a run back and undo the jump. So while the target window is * pinned, reports move nothing. The pin drops once the window SETTLES (it * lands, or its read fails) AND the canvas has committed a snapshot that holds * it ({@link PagingDriver.committed}). * * # A far key keeps the view it left standing (#1398, CL10) * * Home and End past a run go to the source's first or last window as a jump * does, but fetch, then move: where the jump takes the rows drawn off the run * — its demand rebases there — the view the key left stands in until that * window is in — the snapshot drawn as the key came, whole, its rows where * they were (`standing`) — and the windows it drew stay in the cache, never * pruned for the jump's run. The far window landing (or failing) publishes the * jump's own view in the same settle. A clear before then (`clearJump`) — the * keyboard moving on among the rows that stand in — puts every block back as * it was, the windows it drew still read, so nothing is read again for it. * * # A failure belongs to its window (#811) * * A window whose read throws is one error band at its ledger slot in each * block that holds it, with a Retry, while every other window keeps landing. * A `total()` that throws is the SOURCE's failure and surfaces as * `sourceError`; neither ever replaces the canvas. * * # A revision change keeps the rows (#821) * * The rows cached for a PINNED source belong to its `revision()`. When the * revision moves, the resident windows are read again at the new one, and * until each lands the rows it had stand in: the canvas never empties between * two snapshots of its data. The geometry stays too — the ledgers' measured * heights and their total, until the new snapshot's total says otherwise. A * fixed block's rows are the revision's as well: the first window read at a * new revision brings them, and the old ones stand in until it lands (#1192 — * a Plan's event rows ride its source's windows as fixed blocks, and move with * every revision). A `paged` source names no snapshot: its rows are its id's * for as long as the canvas holds it. A source the canvas composes over another * names the snapshot of its data apart from its revision (#1199), and the * snapshot is published beside the revision: a new revision over the same * data reads the windows again and is no new snapshot, which is what a key * search's answer indexes. * * # A new narrowing is a new result (#1344, #1354) * * A `live` source — the rail's `rows` source, or a paged resource kind's * source over its windows (#1344) — keeps its id under every narrowing, and * names the narrowing its windows belong to (`query`), read before the windows * as the revision is. A new narrowing holds other rows at other positions, so * it is a new result, as a new source of the same record is: the view the last * one drew stands in, whole, until the new one's first window lands — whatever * window read ahead beside it lands before it — and its geometry and its * windows start again from its first. The snapshot names the narrowing its * rows belong to (`narrowing`), the stand-in's the last one's. * * # A source that derives its rows another way keeps the view (#1599) * * The derived `page` wraps the series pipeline and the Plan's own rows, so a * source whose `page` is not EQUIVALENT to the one that filled the cache * derives other rows from the same windows under the same id and revision * (#809): its windows are read again. At rest the runtime still holds their * raw pages, and they are read in the same settle. While a read of the source * is on its way — after a Save, another session's write, a task run again — * it holds none: the view the last source drew stands in, whole and retained * (`standing`), until the window under the view is in, as a far key's view * does. Dropped with nothing to stand in, every row left the canvas until that * read landed, whenever the author's block was evaluated again meanwhile — a * record it reads whole having moved, the Plan's own rows' among them. * * @packageDocumentation */ import { type ResidencyOptions } from "@elaraai/east-ui-components/internal"; import { type PlanBand, type PlanRowValue, type PlanWindowFailure, type WindowSkeleton } from "../model.js"; import type { RowKey } from "../plan-state.js"; import { type PlanPagedSourceValue, type PlanViewport } from "../use-plan-paging.js"; /** Where a resident row came from — its block and its window (#823). */ export interface PlanRowOrigin { block: number; w: number; } /** A landed element span — where it starts and ends, and how many elements it holds. */ export interface PlanResidentSpan { /** The first landed element. */ from: number; /** The element after the last landed one (exclusive). */ to: number; /** How many elements have landed — fewer than the span when a window * inside it failed (#811). (A window still in flight is never inside * it: it ends the run, #876.) */ elements: number; } /** One block of a paged canvas — what it holds and what stands for the rest (#823). */ export interface PlanPagedBlock { /** Its place in the canvas's layout. */ index: number; /** Whether no entry produces its rows (a section's header, hand-built * rows): drawn once, never paged. */ fixed: boolean; /** The key of the row its top rows nest under — the header of the section * it sits in — if any. Its bands hide with that row's subtree. */ parent: RowKey | undefined; /** How many chart rows each of the source's entries makes in it, when every entry makes as many — its shape's * (#1398): what the narrow layout's Measures tab counts the source by; `undefined` where that varies by entry, and * for a fixed block. */ charts: number | undefined; /** Every element above its run (#876) — not resident, still loading, or * past a window still loading — if any. */ head: PlanBand | undefined; /** Every element below its run, likewise, if any. */ tail: PlanBand | undefined; /** Its run's windows whose read failed, ascending (#811). */ failures: readonly PlanWindowFailure[]; /** What has LANDED of its run. */ resident: PlanResidentSpan | undefined; } /** What the canvas renders from the driver — replaced whole, and only when * something in it changed. */ export interface PlanPagingSnapshot { /** Which publish this is — they count up, so the canvas can say which one * it committed. */ seq: number; /** The resident rows — block after block, each paged block's windows * concatenated in window order (#823). */ rows: readonly PlanRowValue[]; /** Which block and window each paged row came from. */ origin: ReadonlyMap; /** The canvas's blocks, in layout order — empty on an inline canvas. */ blocks: readonly PlanPagedBlock[]; /** The source's element count, once known. */ total: number | undefined; /** What has landed of the block the viewport is in — of its run (#876), * never the demanded interval, which would claim elements are loaded * that are still on the wire. The span and the count differ when a * window inside the run failed (#811). */ resident: PlanResidentSpan | undefined; /** Whether every paged block holds every element — the source's rows are * all on the canvas, so no count on it is partial. */ complete: boolean; /** Whether a requested window is still in flight — one the view shows, or one read ahead of it. */ loading: boolean; /** * Whether the view waits for a window it shows (#1398): one in flight, or the window under it not read and not asked * yet — the view on its way over rows not read, or resting there before its read is asked (CL6). What the footer's * loading line and the frame's busy follow — never a window read ahead of the view, which nothing on screen waits for. */ viewLoading: boolean; /** The elements being read (#1398, CL3): of the bands of the block the * viewport is in, the loading span nearest it — what the footer's loading * line names; `undefined` while none is, or before the source's count. */ reading: { from: number; to: number; } | undefined; /** Whether the view the last narrowing drew stands in while a new one's * first window is read (#1354): the footer's line says it is filtering. */ replacing: boolean; /** * Whether the view a far key left stands in while the window it goes to is read (#1398, CL10) — Home or End past * a run: its rows where they were, retained, and the line saying that window is read (`reading`). So does the view * a source drew before it derived its rows another way, while the window under it is read again (#1599). */ standing: boolean; /** The narrowing the rows belong to, as a live source names it (`query()`, * #1354) — the stand-in's the last narrowing's until the new one's rows * land (#1344): what the rows in view are reported under, so a reader of * their cells reads none of another narrowing's. `undefined` for a source * that names none. */ narrowing: string | undefined; /** The resident windows whose read failed, ascending — one each, whatever * blocks hold it (#811). */ failures: readonly PlanWindowFailure[]; /** Why the SOURCE could not be read — its `total()` threw. Chrome, never a * canvas replacement (#811). */ sourceError: string | undefined; /** The source's revision — the snapshot of its data these rows are read * from — once it names one (#821). */ revision: string | undefined; /** The snapshot of the data itself (#1199): the source's own `snapshot()`, * or its revision when it names none. A revision that moved over the same * data — windows read again, new rows composed into them — leaves it. */ dataSnapshot: string | undefined; } /** The snapshot of a driver with no source (an inline canvas). */ export declare const IDLE_PAGING: PlanPagingSnapshot; /** Where a row the body does not hold sits (#823): in one of its block's * bands, this many px below the band's top — the ledger offset of the window * it was last seen in. */ export interface PlanRowPlace { block: number; at: "head" | "tail"; px: number; } /** * Where a view resting over rows not read rests (#1398) — over one of a * block's bands, or a failed window's: the source element under its top, and * how many px into that element's window it is, by the ledger's geometry. What * a remount opens at, and puts the view back on. */ export interface PlanUnreadPlace { /** The element under the view's top. */ element: number; /** Px from the top of the element's window to the view's top. */ px: number; } /** Options for {@link createPagingDriver}. */ export interface PagingDriverOptions { /** One block's rows from one landed window, as the heights need them — its * skeleton, taken once per landing (#823). */ skeletonOf: (rows: readonly PlanRowValue[]) => WindowSkeleton; /** A skeleton's height under the CURRENT UI state — the body's own height * arithmetic, so a band is exactly as tall as the rows it stands for. */ heightOf: (sk: WindowSkeleton) => number; /** A skeleton's height AT REST — declared collapse, no charts expanded, no * focus: what the ledger seeds its slot rate from. */ restHeightOf: (sk: WindowSkeleton) => number; /** Residency policy (defaults to {@link DEFAULT_RESIDENCY}). */ policy?: ResidencyOptions | undefined; /** Called once per settle that changed the snapshot. */ onChange: () => void; } /** The driver's handle. */ export interface PagingDriver { /** The current snapshot — the same object until something changes. */ getSnapshot(): PlanPagingSnapshot; /** Drive a (new) source; `undefined` idles the driver (an inline canvas). */ setSource(source: PlanPagedSourceValue | undefined, retainPrevious?: boolean): void; /** Where the viewport is. Ignored while a jump is pending — the jump owns * the viewport until its window settles (#812). */ reportViewport(at: PlanViewport, scrolling: boolean): void; /** Jump to a source element (a seek result): pin its window in every * block and move the demand there — a run extends to a near target and * rebases on a far one (the step policy's `rebaseGap`), so the windows in * between a far jump are never fetched. */ jumpToElement(element: number): void; /** * Go to a source element the keyboard goes to — Home or End past a run (#1398, CL10): a jump, but while its window * is not in, the view drawn as the key came stands in (`standing`), its windows kept, until it lands; a clear * ({@link clearJump}) before then puts that view back. */ standTo(element: number): void; /** Whether a far key's view stands in now ({@link standTo}). */ standing(): boolean; /** Open at a source element — where a remounted canvas left off (#813). * Like a jump, but the run STARTS there however near the resident one * is: nothing between is fetched for a place the user is not going to * scroll through. With a block, only that block opens there. */ openAt(element: number, block?: number): void; /** Drop any pending jump pin — a cleared search has no target (#614) — or, while a far key's view stands in, put * that view back as it was: every block where it was, nothing read again for it (#1398). */ clearJump(): void; /** * The canvas committed `rendered`: it is on screen, and the canvas has * scrolled to a jump's target if it could. A jump whose window settled in * or before that snapshot hands the viewport back (#812). */ committed(rendered: PlanPagingSnapshot): void; /** * Ask a failed window again — or, with none named, every failed window and * the source's own reads: has the source rearm what failed (its `refresh`), * then drops the failure records and reads again, a microtask on, once it * has (#811, #1398). A source with no `refresh` is read again at once. */ retry(w?: number): void; /** * The stored entry the window standing at a source position read with the entry of an id (#1599) — the window * whose rows the canvas draws there, landed or standing in from before: what a gesture on a row the canvas shows * begins from, whatever revision its source has moved to since. `undefined` where the source's windows carry none. */ entryOf(id: string, at: number): Uint8Array | undefined; /** * Whether the window at a source position has landed at the revision the driver reads at — its rows the source's * own now, never ones standing in from before (#1599): what a Save landed of an entry there is the window's to * draw from then on. */ landedAt(at: number): boolean; /** Settle again with the current inputs. */ refresh(): void; /** What the rows draw at changed (a collapse, the grain, a chart toggle, * an expand focus, the density): measure every window each block has * seen again, from its skeleton, and settle (#823). */ remeasure(): void; /** What a skeleton is taken with changed (the axis kind, which decides * which rows are diagnostics): resident windows take theirs again. */ reskeleton(): void; /** Where a visited row the body does not hold sits — in which block's * band, and how far down it (#823: a link into an evicted window, or * into a landed one past a window still in flight, #876). `undefined` * for a row never seen, or one whose window is in its block's run. */ placeOf(key: RowKey): PlanRowPlace | undefined; /** * Where a view whose top is `px` into a band of rows not read rests (#1398): one of a block's bands, or a failed * window's, as drawn — by the elements it stands for, never the run the driver has moved on to since. `undefined` * for a block the driver does not page, or before its ledger knows a window. */ unreadPlace(band: Pick, px: number): PlanUnreadPlace | undefined; /** Which block and window a row was last seen in, resident or evicted — * what a request to bring it into view opens (#824). `undefined` for a * row no window has shown. */ seenAt(key: RowKey): PlanRowOrigin | undefined; /** Whether a jump is pending (its window pinned). */ jumping(): boolean; /** Stop listening to the source's channels until the next settle — a * `refresh` subscribes afresh. State is kept. */ disconnect(): void; } /** * Create a paging driver. * * @param options - See {@link PagingDriverOptions} * @returns The driver */ export declare function createPagingDriver(options: PagingDriverOptions): PagingDriver; //# sourceMappingURL=paging.d.ts.map