/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type CheckJqResult } from "@elaraai/east"; import type { Origin } from "@elaraai/east-ui-components"; import { type Card, type SourceCard } from "./model/cards.js"; import type { SlotRef } from "./model/refs.js"; import { type SavedOffer, type SlotItem, type StepOption } from "./model/slots.js"; import { type SummaryCache } from "./model/summaries.js"; import { type QueryWords } from "./model/words.js"; import type { QueryRoot } from "./one-shot.js"; import { type QueryEntry, type QueryHeader } from "./session.js"; import type { CardActions } from "./step-card.js"; import type { QueryCheckLine, QueryGivesLine } from "./status-line.js"; import { type CheckedSteps } from "./steps/check.js"; import { type StepKind, type StepQuery } from "./steps/values.js"; import type { QueryView } from "./toolbar.js"; /** A notice at the top of the Query tab: what just happened. */ export interface QueryNotice { /** Its identity among the notices. */ readonly id: number; /** What it says. */ readonly text: string; } /** A slot's autocomplete, open. */ export interface OpenSlot { /** The slot. */ readonly ref: SlotRef; /** Its key. */ readonly key: string; /** The element it hangs from. */ readonly anchor: HTMLElement; } /** What the autocomplete of the open slot shows, and what it is told. */ export interface SlotPopover { /** The slot. */ readonly slot: OpenSlot; /** Changes when the offers' source does — a summary arriving — so the list opens afresh on its current value. */ readonly generation: string; /** Its label, filter placeholder, footer, empty words and keys. */ readonly label: string; readonly placeholder: string; readonly hint: string; readonly empty: string; readonly keys: string; /** The offers for the text typed. */ readonly items: readonly SlotItem[]; /** The text typed. */ readonly text: string; /** The offer active as it opens. */ readonly initialActive: number; /** Told each change of the text. */ readonly onText: (text: string) => void; /** Told the offer picked. */ readonly onPick: (item: SlotItem) => void; /** Told it closes. */ readonly onClose: () => void; } /** What editing the open query needs. */ export interface QueryEditorOptions { /** The query's entries as its drafts stand. */ readonly entries: readonly QueryEntry[]; /** The query's entries as the drafts stand this moment — after a gesture in the same event, too. */ readonly current: () => readonly QueryEntry[] | undefined; /** Records a gesture: the entries it leaves, as one transaction. */ readonly gesture: (next: readonly QueryEntry[], origin: Origin, label: string) => boolean; /** Moves with every change of the session. */ readonly version: number; /** The root. */ readonly root: QueryRoot; /** The views this builder offers, in the switch's order: the `views` prop's. */ readonly views: readonly QueryView[]; /** The words. */ readonly words: QueryWords; /** The builder's summaries, and the latest hash of each data source a run has read. */ readonly summaries: { readonly cache: SummaryCache; readonly hashes: ReadonlyMap; }; /** The saved queries the add-step list of a query with no steps offers. */ readonly saved: readonly SavedOffer[]; /** Opens a saved query picked from the add-step list. */ readonly onOpenSaved: (name: string) => void; /** Shows the Query tab, the pane expanded: Visual · jq picked. */ readonly onShowQuery: () => void; /** The builder's element: the autocomplete hangs inside it, and the slots are found in it. */ readonly bounds: () => HTMLElement | null; /** Its session's source id: another query opened starts afresh. */ readonly sourceId: string; /** The rows a fresh run of the steps counted at each stage, by step id (#938): the shape lines count them. */ readonly counts?: ReadonlyMap | undefined; /** * The notice a query arrives with when it opens (#939) — "Opened “Big * orders” from the library.", "Started a new query on customers." — by its * session's source id: shown when that query opens, in place of the last * query's notices. */ readonly arrival?: { readonly sourceId: string; readonly text: string; } | undefined; } /** Editing the open query: what the surfaces draw, and what they do. */ export interface QueryEditor { /** The header. */ readonly header: QueryHeader; /** The steps, as a query on the header's data source. */ readonly query: StepQuery; /** The steps' check; `undefined` while the program is jq. */ readonly checked: CheckedSteps | undefined; /** The source's card, and each step's; empty while the program is jq. */ readonly source: SourceCard | undefined; readonly cards: readonly Card[]; /** The Quick add buttons at the end of the query. */ readonly quick: readonly StepOption[]; /** The view shown. */ readonly view: QueryView; /** The views this builder offers: Visual · jq shows only where there are two. */ readonly views: readonly QueryView[]; /** Shows a view: to jq prints the program; back to visual parses it. */ readonly setView: (view: QueryView) => void; /** The jq as typed, in the jq view. */ readonly jqText: string; /** Told each change of the jq typed. */ readonly onJqText: (text: string) => void; /** The jq typed in and left: one gesture. */ readonly leaveJq: () => void; /** A fix taken in the jq view: the jq typed so far left, then the text the fix makes, a gesture of its own, under its label. */ readonly onJqFix: (text: string, label: string) => void; /** The jq view's check of the jq as typed; `undefined` in the visual view. */ readonly jqChecked: CheckJqResult | undefined; /** The jq view's note: unfinished steps left out, or the jq kept for its syntax. */ readonly jqNote: string | undefined; /** The root, which the jq view completes and reads steps over. */ readonly root: QueryRoot; /** The builder's summaries, whose values the jq view's completions offer. */ readonly summaries: QueryEditorOptions["summaries"]; /** The program as it stands: what Run runs and Copy jq copies — in the jq view, the jq as typed. */ readonly program: string; /** The status line's check, and the shape the query gives. */ readonly check: QueryCheckLine; readonly gives: QueryGivesLine | undefined; /** The notices, newest last; a notice dismissed. */ readonly notices: readonly QueryNotice[]; readonly dismiss: (id: number) => void; /** The parts' and the cards' asks. */ readonly actions: CardActions; /** A Quick add button pressed. */ readonly onQuick: (kind: StepKind) => void; /** The open slot's autocomplete. */ readonly popover: SlotPopover | undefined; } /** * Editing the open query — see the module docs. * * @param options - The session's entries and gesture, the root, the words and the builder's element * @returns What the surfaces draw, and what they do */ export declare function useQueryEditor(options: QueryEditorOptions): QueryEditor; //# sourceMappingURL=use-query-editor.d.ts.map