/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. * * The paged canvas's key search (#574), framework-free (#815). * * # Bridging a tracked read to a promise * * `` is promise-based (`onFind` returns a `Promise`), while * `seek` is a tracked platform read: `none` means "still searching" and the * channel re-fires when it lands. The two meet here — the query is held, the * read runs as a tracked read so its channel is registered, and the pending * promise settles on the read that lands the answer. * * @packageDocumentation */ import { type EastTypeValue } from "@elaraai/east"; import type { DatasetKeyMatchRange, DatasetKeyQuery, DatasetKeySearchProps } from "@elaraai/east-ui-components"; import type { PlanRowValue } from "../model.js"; import type { PlanPagedSourceValue } from "../use-plan-paging.js"; /** A row names the element it came from by a String — the first segment of * its id's path (#822: a String key as is, any other printed) — so a Plan's * search input is typed against that, whatever the underlying dataset keys * its elements by. */ export declare const CANVAS_KEY_TYPE: EastTypeValue; /** * The key of the element a row came from — its id's first path segment — or * `undefined` for a row no element placed (a section header). * * @param row - A canvas row * @returns The element key */ export declare function elementKeyOf(row: PlanRowValue): string | undefined; /** The decoded `seek` capability of a paged source. */ export type PlanSeekFn = Extract["value"]; /** What the canvas renders from the search. */ export interface PlanSeekSnapshot { /** The key the last query sought, and where its run started in the source * — `null` between searches. */ sought: { key: string; row: number; } | null; /** Why the last search failed — its `seek` threw — until the next search * or a clear (#811: the toolbar states it; the canvas carries on). */ searchError: string | undefined; /** Counts the snapshots of the source's data a standing query was asked * again in (#821, #1199): the search control asks the query it holds again * as it moves, its text kept, so its matches index the new snapshot. */ again: number; } export declare const NO_SEEK: PlanSeekSnapshot; /** Options for {@link createSeekDriver}. */ export interface SeekDriverOptions { /** Drop the paging driver's pending jump pin — a cleared search has no target (#614). */ clearJump: () => void; /** Called once per change to the snapshot. */ onChange: () => void; } /** The search's handle. */ export interface SeekDriver { getSnapshot(): PlanSeekSnapshot; /** The source whose seek and bounded pages answer the search. */ setSource(source: PlanPagedSourceValue | undefined): void; /** Locate a query — resolves when the tracked search lands. */ find(query: DatasetKeyQuery): Promise; /** Read the bounded head of the match run, whether or not its canvas window is resident. */ listRange: DatasetKeySearchProps["onListRange"]; /** A previously labelled source position's key, for an exact jump. */ keyAt(row: number): string | undefined; /** Drop the query and its jump target. */ clear(): void; /** * The source's data moved to another snapshot (#821, #1199): a standing * query's match positions index the previous snapshot's rows, so it is * asked again — `again` moves, and the control asks the query it holds * once more, its text kept. Nothing without a query. A pending jump keeps * its pin: its window lands at the new snapshot like any other. */ askAgain(): void; /** Ask again — a pending search re-subscribes to its answer (after a * {@link SeekDriver.disconnect}), and settles if it has landed. */ refresh(): void; /** Stop listening for the pending answer until the next `refresh`. The * query and its promise are kept. */ disconnect(): void; } /** * Where a search positions the canvas, and where its labels start: the first * loaded row that SHOWS the sought element — its key, else the first whose * key the sought text begins — and, when no block shows one, the first row * whose element sorts at-or-after it. * * @remarks * Each block's windows land in the source's key order, and each series places * its rows in element order, so within a block the rows at-or-after the key * start the match run (#822). A jump moves every block to the target window * (#823), and a block whose series skips the element shows its neighbours * there: the first block that shows the element itself wins, not the first * block. A parent precedes its subtree, so the row found is the element's own, * never a child's (for `views`, its first view row). * * @param rows - The loaded canvas rows, stream order * @param key - The sought key * @returns The index, or `-1` when no loaded row's element sorts at or after it */ export declare function firstAtOrAfter(rows: readonly PlanRowValue[], key: string): number; /** * Create the key search. * * @param options - See {@link SeekDriverOptions} * @returns The driver */ export declare function createSeekDriver(options: SeekDriverOptions): SeekDriver; //# sourceMappingURL=seek.d.ts.map