/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. * * The canvas's keyboard map (#819), as a model: the grid's items in order * (pinned rows, then the body — rows, a links focus's bands, the bands * standing for a paged source's unloaded runs, failed windows), and what a key * does from one of them. Pure, so the whole map is testable without a DOM; the * canvas root runs the moves it returns (`index.tsx`). * * # Rows * * ↑ / ↓ step between items, Home / End go to the first / last, PgUp / PgDn * move a viewport's worth. → opens a closed section (or chart) and, on an open * section, steps to its first child; ← closes an open one, or steps to its * parent — a row a links focus gathers, to its role's band. Enter does what a * click on the row does — select it, or return from a row focus on a strip — * and Space toggles its section or chart. A links focus's others' band opens * and folds as a section's does (#1680's review); a role's band opens nothing. * * # Bands * * An unloaded run is ONE grid item (its row count is unknowable — see * `window-ledger.ts`), so a key cannot land on a row that is not there yet. * Fetch, then move (#1398, CL10): a step or a page past the rows read asks * the source for the window beside the run, and leaves an INTENT — the focus * waits on the item it set out from, never on the run, and once the rows land * it moves on to the row the key was headed for: the next row, or the row a * page on, never the last row before the run. Home and End past a run read * the source's first or last window where it is, the rows shown standing in * where they are, retained, the focus on the item it set out from, and the * focus lands on its first or last row as that window's rows replace them. A * source that reports no total has no bands: there the move waits on the item * it started from while a window loads. * * A run takes the focus only from a click into it (or as the grid's stop): it * stands for the rows the view shows there, and a key that moves through them * — ↑ ↓ PgUp PgDn — waits for them (`wait`): once they land the focus goes to * the first of them in view, and a page goes on from there. Such a key pressed * while a move waits — on the run, or on the row a step or a page set out * from — waits with it, and the canvas plays them in turn once the rows are in * (`goOn`): none is lost. * * # Widgets * * Tab from a row walks its widgets in reading order — its controls, its * elements in time order, the author's render — and past the last, out of * the canvas. ← / → step between the elements in time order * (Home / End to the first / last), and Esc returns to the row. A bucket * cell's `+n` chip stands in the walk where the tiles it folds would be, and a * folded tile is out of it (#1267). * * @packageDocumentation */ import type { PlanEvent, RowKey } from "../plan-state.js"; import type { PlanViewport } from "../use-plan-paging.js"; import type { PlanNavAlign } from "../controller/index.js"; import { type PlanBodyItem, type PlanFocusCtx, type PlanRowIndex, type VisibleRow } from "../model.js"; /** One item of the grid, as the keyboard sees it. */ export interface PlanNavItem { /** Its `bodyItemKey`. */ key: string; /** What it is — a links focus's band is a group's. */ kind: "row" | "group" | "band" | "failed"; /** A band's block and side, and its pixel height (End reaches its far * edge) — a move onto it asks that block for the window beside its run * (#823). */ band?: { block: number; at: "head" | "tail"; px: number; } | undefined; /** The parent row's item key, when the row nests — ← steps there. */ parent?: string | undefined; /** Its section / chart toggle — what Space and ← / → dispatch — and * whether it is open now. */ toggle?: { event: PlanEvent; open: boolean; } | undefined; /** Whether it nests rows — → steps into an open one. */ nests: boolean; /** What Enter does — the row's click. */ activate?: PlanEvent | undefined; /** Its height (px) — how far PgUp / PgDn travel. */ h: number; } /** What the grid's items are built from. */ export interface PlanNavSource { /** The pinned rows (the grid's first rows) and their heights. */ pinned: readonly VisibleRow[]; pinnedHeights: readonly number[]; /** The body items and their heights. */ items: readonly PlanBodyItem[]; heights: readonly number[]; /** The row index — who nests. */ index: PlanRowIndex; /** The chart rows the user expanded. */ chartsExpanded: ReadonlySet; /** The row focus, if any — its strips return on Enter. */ focusCtx: PlanFocusCtx | undefined; } /** * The grid's items as the keyboard sees them — pinned rows first, then the * body in order. * * @param src - The rows, bands and state they are built from * @returns The items */ export declare function planNavItems(src: PlanNavSource): PlanNavItem[]; /** A pending move across a band — resolved once the band's rows land. */ export type PlanNavIntent = /** Headed one step `dir` from the item `from`. */ { t: "step"; from: string; dir: 1 | -1; } /** * Headed a page `dir` from the item `from` (#1398, CL10): `rest` of the page still to go once the rows past the band * land — px of the viewport's height, or rows where the viewport could not be measured (`by`). */ | { t: "page"; from: string; dir: 1 | -1; rest: number; by: "px" | "items"; } /** Headed for the source's first / last row, from the item `from`. */ | { t: "first"; from: string; } | { t: "last"; from: string; }; /** A key that moves through the rows a run stands for, pressed while the run holds the focus. */ export type PlanWaitKey = "ArrowDown" | "ArrowUp" | "PageDown" | "PageUp"; /** What a key does. */ export type PlanNavMove = /** Move focus onto an item — scrolled into view as `align` says, or not at all. */ { t: "focus"; key: string; align: PlanNavAlign | undefined; } /** * Fetch, then move (#1398, CL10): ask the source for the window beside a run, and leave an intent — the focus * waiting on the item it set out from, never on the run, and the view where it is, until the rows land. */ | { t: "fetch"; demand: PlanViewport; intent: PlanNavIntent; } /** Home / End past a run: read the source's first or last window where it is, the rows shown standing in, and land on its first or last row once it is in. */ | { t: "edge"; edge: "first" | "last"; } /** A key on a run holding the focus: it waits for the run's rows in view, and goes on from the first of them. */ | { t: "wait"; key: PlanWaitKey; } /** An interaction on the item — focus stays on (or lands on) `focus`, * since the interaction may re-render the item as another element (a * strip becoming a row). */ | { t: "event"; event: PlanEvent; focus: string; } /** A key the map owns that does nothing here (the edge of the grid). */ | { t: "none"; }; /** * What a key does from an item. * * @param items - The grid's items, in order * @param from - The focused item's key * @param key - The `KeyboardEvent.key` * @param pageHeight - The viewport's height (px) — how far a page moves; 0 when unknown * @returns The move, or `undefined` for a key the row map does not own */ export declare function planNavKey(items: readonly PlanNavItem[], from: string, key: string, pageHeight: number): PlanNavMove | undefined; /** Where a pending band move stands after the grid changed. */ export type PlanNavResolution = { t: "resolved"; key: string; } /** Still waiting — and, where the rows landed so far stop short of where it is headed, the run past them to ask for. */ | { t: "pending"; ask?: PlanViewport | undefined; } | { t: "cancel"; }; /** * What the grid knows of its source's ends — an inline canvas holds both, and * never loads. */ export interface PlanNavEdges { /** A window is still in flight: rows may yet arrive. */ loading: boolean; /** The source's first element is resident. */ atStart: boolean; /** The source's last element is resident. */ atEnd: boolean; } /** * Where a pending band move stands against the grid now. A demanded window * can be IN FLIGHT without a band standing for it — a source that reports no * total has no bands — so an item missing past the move's start is not the * end of the source: the move waits while a window loads, and for Home / End * until the source's own first / last element is resident. It resolves on a * row — or a failed window, which has its own Retry — and is cancelled once * the item it started from is gone, or nothing more can arrive: Home and End's * too, which wait among the rows they set out from (#1398, CL10) — gone while * the far end is not in, those rows are another's now, a new narrowing's or a * new count's, and the move goes with them. * * @param items - The grid's items now * @param intent - The pending move * @param edges - What the grid knows of its source's ends * @returns Its resolution */ export declare function resolveNavIntent(items: readonly PlanNavItem[], intent: PlanNavIntent, edges: PlanNavEdges): PlanNavResolution; /** What a row's walk steps through in time order: its elements, and a bucket * cell's `+n` chip where the tiles it folds would be (#1267). */ export declare const PLAN_WALK_SELECTOR = "[data-run],[data-event],[data-chip],[data-mark],[data-cell],[data-tile-more]"; /** * The grid item (row, band) a node belongs to in THIS canvas — a canvas nested * in an expand render answers for its own. * * @param node - A DOM node (an event target) * @param body - The canvas body * @returns The item element, or `null` */ export declare function gridItemOf(node: EventTarget | null, body: HTMLElement): HTMLElement | null; /** * A row's elements in time order — the runs, tiles, chips, marks and cells it * draws inside the window (overscan marks, clipped out of view, are not * reachable), and a bucket cell's `+n` chip in place of the tiles it folds * (#1267). * * @param row - The row element * @param body - The canvas body * @returns Its focusable elements, earliest first */ export declare function plotElements(row: HTMLElement, body: HTMLElement): HTMLElement[]; /** * A row's widgets in reading order, cell by cell — the gutter's controls, the * plot's elements in time order then anything the author's render mounts. The * Tab walk through a row. * * @param row - The row element * @param body - The canvas body * @returns Its widgets, in walk order */ export declare function rowWidgets(row: HTMLElement, body: HTMLElement): HTMLElement[]; //# sourceMappingURL=keyboard.d.ts.map