/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type ResidencyOptions } from "@elaraai/east-ui-components/internal"; import { type SheetBand, type SheetWindowFailure } from "./model.js"; import type { SheetPagedSourceValue, SheetRowValue } from "./values.js"; /** Source elements per window. */ export declare const SHEET_PAGE_SIZE = 200; /** * Where the viewport is, in the caller's terms — and, where the caller can * say, the source elements it shows (`shows`): what the footer's loading line * and the grid's busy follow (#1398), never the windows read ahead of it. */ export type SheetViewport = { kind: "row"; offset: number; shows?: ElementSpan | undefined; } | { kind: "band"; at: "head" | "tail"; px?: number | undefined; shows?: ElementSpan | undefined; }; /** A stretch of source elements, first and last (inclusive). */ export interface ElementSpan { readonly from: number; readonly to: number; } /** What the driver returns. */ export interface SheetPaging { /** The resident rows — the run nearest the viewport (#876), in stream order (a failed window's rows are not among them, #853). */ rows: SheetRowValue[]; /** Each resident row's source position — a row after a failed window keeps its own (#853). */ positions: readonly number[]; /** The source offset of `rows[0]`. */ rowsOffset: number; /** The resident windows whose read failed, ascending (#853): each is a band where its rows would be. */ failures: readonly SheetWindowFailure[]; /** Every element above the run — not resident, still loading, or past a window still loading (#876). */ head: SheetBand | undefined; /** Every element below the run — not resident, still loading, or past a window still loading (#876). */ tail: SheetBand | undefined; /** The source's element count, once known. */ total: number | undefined; /** * The revision that count was read at — the last one that gave a count, while it stands in for this one's (#851); * `undefined` with no count. What a Save's rows are counted over: a count read since holds them (#1536). */ totalRevision: string | undefined; /** Whether every source element is resident. */ exhausted: boolean; /** Whether a requested window is still in flight — one the view shows, or one read ahead of it. */ loading: boolean; /** The windows in flight, ascending: a run is busy while one of its own is (#1398). */ pending: readonly number[]; /** * The resident windows whose rows are the previous revision's, standing in until their read at this one lands (#851), * ascending: what a Save's rows are drawn over as it left them, never as they were before it. */ standing: readonly number[]; /** The revision the source is read at — its `revision()`, as last read (#851); `undefined` while it names none. */ revision: string | undefined; /** * Whether the view waits for a window it shows (#1398): one in flight, or one 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 grid's busy follow — never a window read ahead of the view, which nothing on screen waits for. */ viewLoading: boolean; /** The source elements the view waits for (#1398, CL3): the stretch of windows in flight among those it shows, first and last element; `undefined` while none is. */ reading: { from: number; to: number; } | undefined; /** The last query is still displayed while its replacement loads. */ replacing: boolean; /** * The rows shown were read another way — by a page this source's is not equivalent to (#809) — and stand in while * its windows are read again (#1599): retained, taking no gesture, until every window the run holds has landed. */ reread: boolean; /** * The rows shown as a key went past them stand in while the window it goes to is read (#1398, CL10): retained, * and the line says that window is read (`reading`). */ held: boolean; /** Why the SOURCE could not be read — its `total()` or `revision()` threw — while its rows show (#853): chrome, never their replacement. */ sourceError: string | undefined; /** Why the source could not be read before anything landed: there is nothing else to show, so this is the whole sheet (#853). */ error: string | undefined; /** * Whether a window of this source has landed (#1398, CL5): the cold load is over. A scroll far from the rows, * every window it shows still on its way, draws the runs where they meet the view — never the cover again. */ landedOnce: boolean; /** Bump for `VirtualRows`' `sizeVersion` — heights change at constant count. */ sizeVersion: number; /** A pending jump (#854): its target window, and whether it has SETTLED — the run around it has stopped moving and the target's window is in the run (#876), so the sheet can show it. While one is pending it owns the viewport. */ jump: { window: number; settled: boolean; } | undefined; /** Tell the driver where the viewport is. Ignored while a jump is pending (#854). */ reportViewport: (at: SheetViewport, isScrolling: boolean) => void; /** * Jump to a source element (a seek result): pin its window and rebase. A key's jump (`hold`) that takes the rows * shown off the run leaves them standing in until it has settled (`held`, #1398, CL10). */ jumpToElement: (element: number, hold?: boolean) => void; /** * Drop any pending jump — the search was cleared, or the sheet has shown the jump's target and hands the viewport * back (#854) — or, while a key's jump holds the rows shown, put the run back as it was (#1398). */ clearJump: () => void; /** Ask again (#853): the failed window `w`, or — with none — the source and every failed window. At once (#1398): a source that can refresh rearms what failed first, and the windows are read again a microtask on, so the gap a read alone waits after a failure never holds a Retry back. */ retry: (w?: number) => void; /** * The stored entry the window standing at a source position read with the row of an id (#1599) — the window whose * rows are drawn there, landed or standing in from the revision before: what a gesture on a row the sheet shows * begins from, and what its marks are read over. `undefined` where the source's windows carry none. */ entryOf: (id: string, at: number) => Uint8Array | undefined; } /** * The windows in flight that the view shows (#1398): those its stretch of * elements meets — or, where the caller has not said what it shows, the * window the viewport is centred in. * * @param pending - The windows in flight, ascending * @param shows - The source elements the view shows, if known * @param at - The viewport's window * @returns The windows in flight among those it shows, ascending */ export declare function pendingInView(pending: readonly number[], shows: ElementSpan | undefined, at: number): readonly number[]; /** * The elements being read (#1398, CL3): of the windows in flight, the * stretch of adjacent ones nearest the viewport's window — what the footer's * loading line names. * * @param pending - The windows in flight, ascending * @param at - The viewport's window * @param total - The source's element count, once known: the last window ends there * @returns The stretch's first and last element; `undefined` with none in flight */ export declare function readingStretch(pending: readonly number[], at: number, total: number | undefined): { from: number; to: number; } | undefined; /** * Drive a paged sheet source. * * @param source - The decoded `paged` arm (undefined ⇒ inline sheet; idles) * @param heightOf - What one source row draws, in px — the body's own geometry (#855); a new function re-measures the landed windows * @param policy - Residency policy (defaults to the Plan's) * @param family - Stable record identity; query changes within it retain the last usable view * @returns The resident rows, the bands, and the callbacks the renderer feeds */ export declare function useSheetPaging(source: SheetPagedSourceValue | undefined, heightOf: (row: SheetRowValue) => number, policy?: ResidencyOptions, family?: string): SheetPaging; //# sourceMappingURL=paging.d.ts.map