/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * Slots and autocomplete (#934): what each slot of a step card offers, grouped, * with details and meta (`Query Editor Spec.md` §4.5); the steps that fit at a * point, and why the others don't; and what picking an offer, typing in an * input, removing and adding do — each one gesture of the editing session * (#935), as a function from a query value to a query value. * * @packageDocumentation */ import { type EastType } from "@elaraai/east"; import { type Shape } from "../steps/shape.js"; import { type StepKind, type StepQuery } from "../steps/values.js"; import type { ActionRef, InputRef, RemoveRef, SlotRef, SlotValue } from "./refs.js"; import { type Summary } from "./summaries.js"; import { type QueryWords } from "./words.js"; /** One offer of a slot's list. */ export interface SlotItem { /** What picking it sets. */ readonly value: SlotValue; /** Its label. */ readonly label: string; /** A sub-line: a field's kind, a step's hint. */ readonly detail?: string; /** A note: a payload field's case, or why a step is disabled. */ readonly note?: string; /** A meta at the end: a summary, a count, a stat. */ readonly meta?: string; /** The group it is listed under. */ readonly group: string; /** Its icon. */ readonly icon?: string; /** Whether it is listed but cannot be picked. */ readonly disabled?: boolean; /** Whether it is the value typed, offered first. */ readonly typed?: boolean; /** Whether its label reads as data: a number, an ID, a date. */ readonly mono?: boolean; } /** A saved query a builder can open, for the add-step list of a query with no steps. */ export interface SavedOffer { /** Its name. */ readonly name: string; /** The data source it starts from. */ readonly source: string; /** When it was saved or run, in words. */ readonly when?: string; /** Whether it is a recent run rather than a saved query. */ readonly recent?: boolean; } /** What a slot's offers draw on. */ export interface SlotContext { /** The words. */ readonly words: QueryWords; /** The summary of the rows the slot's step takes, once fetched. */ readonly summary?: Summary; /** The saved queries this builder can open (#935's `QueryInternal.rootBound`). */ readonly saved?: readonly SavedOffer[]; /** Each lookup table's size, by name, where the builder knows it. */ readonly sizes?: ReadonlyMap; } /** What picking does: the query after, the slot it opens next, and a step added or a saved query to open. */ export interface SlotResult { /** The query after. */ readonly query: StepQuery; /** The slot to open next, if any. */ readonly open?: SlotRef; /** The step added, for the builder to scroll to. */ readonly added?: string; /** A saved query picked from the add-step list: the builder opens it (§4.13). */ readonly opened?: string; } /** A step that can be added, and whether it fits. */ export interface StepOption { /** The step's kind. */ readonly kind: StepKind; /** Its label in the add-step list. */ readonly label: string; /** Its hint. */ readonly hint: string; /** The words the list's filter matches. */ readonly keywords: string; /** Its icon. */ readonly icon: string; /** Whether it fits the shape there. */ readonly fits: boolean; /** Why not, when it does not. */ readonly reason: string; } /** * The steps that can be added at a point, and why the others cannot * (`Query Editor Spec.md` §4.5). * * @param shape - the shape there * @param root - the root's type, whose lookup tables a Look up reads * @param words - the words * @returns every step of the add-step list, each saying whether it fits */ export declare function stepOptions(shape: Shape, root: EastType, words: QueryWords): StepOption[]; /** * The Quick add buttons at a point (§4.3): Keep rows, Group and total, Sort * by, Keep the first and Show only fields, and List every part and Try the * model where they fit. * * @param shape - the shape at the end of the query * @param root - the root's type * @param words - the words * @returns the buttons, each saying whether it fits */ export declare function quickAddOptions(shape: Shape, root: EastType, words: QueryWords): StepOption[]; /** * What a slot offers (`Query Editor Spec.md` §4.5): every row of the table, * filtered by the text typed. * * @param query - the query * @param root - the root's type: a struct of the data sources * @param slot - the slot * @param text - what is typed in its filter * @param ctx - the words, the summary of the rows there, the saved queries a builder can open and the lookup tables' sizes * @returns the offers, in their groups' order; disabled ones carry their reason */ export declare function slotItems(query: StepQuery, root: EastType, slot: SlotRef, text: string, ctx: SlotContext): SlotItem[]; /** * A slot's popover label — `FIELD`, `COMPARE` as the design system sets it. * * @param slot - the slot * @param words - the words * @returns the label */ export declare function slotLabel(slot: SlotRef, words: QueryWords): string; /** * A slot's filter placeholder: `Type or pick a value`, `Type to filter`. * * @param slot - the slot * @param words - the words * @returns the placeholder */ export declare function slotPlaceholder(slot: SlotRef, words: QueryWords): string; /** * A slot's footer: where its offers come from — `Fields from the checked type`. * * @param slot - the slot * @param words - the words * @returns the hint */ export declare function slotHint(slot: SlotRef, words: QueryWords): string; /** * What a slot says with nothing to offer: `Type a value, then press ⏎.` * * @param slot - the slot * @param words - the words * @returns the words */ export declare function slotEmpty(slot: SlotRef, words: QueryWords): string; /** * The offer a slot's list opens on (§4.5): the slot's current value when it * is listed, else the first that can be picked. * * @param items - the offers * @param query - the query * @param root - the root's type * @param slot - the slot * @returns its index, or `-1` when none can be picked */ export declare function activeItem(items: readonly SlotItem[], query: StepQuery, root: EastType, slot: SlotRef): number; /** * What picking an offer does (`Query Editor Spec.md` §4.5): the query after, * and the slot it opens next. * * @param query - the query * @param slot - the slot * @param item - the offer picked * @param root - the root's type * @param words - the words, to find an added step's first empty slot * @returns the query after, the slot to open, and a step added or a saved query to open * * @remarks * - A field keeps its comparison and value when its kind matches, and opens * the value, or the inner condition's field for has any where. * - A comparison keeps the value unless either side is a year, a month or a * count; has any where gives the condition an inner one, and opens its field. * - A total renames itself while its name is its own (`defaultTotalName`). * - A field shown is named by its own name; a date part rewrites a trailing * year, month or weekday in its name. * - An added step takes its defaults (`newStep`) and opens its first empty slot. */ export declare function applySlot(query: StepQuery, slot: SlotRef, item: SlotItem, root: EastType, words: QueryWords): SlotResult; /** * What typing in an input does (`Query Editor Spec.md` §4.5): counts and * numbers read as numbers, the locale's group separators dropped, and names * become identifiers. * * @param query - the query * @param input - the input * @param raw - what is typed * @param root - the root's type * @param words - the words, for the locale's separators * @returns the query after */ export declare function applyInput(query: StepQuery, input: InputRef, raw: string, root: EastType, words: QueryWords): StepQuery; /** * What a × does: a condition or a group, a total, a field shown, or a field * a Look up brings in, taken out. * * @param query - the query * @param ref - what to take out * @returns the query after */ export declare function applyRemove(query: StepQuery, ref: RemoveRef): StepQuery; /** * What an add does: a condition, a group or a total added, and the slot it * opens; or a slot opened, as Add field does. * * @param query - the query * @param ref - the add * @param root - the root's type * @returns the query after, and the slot to open */ export declare function applyAction(query: StepQuery, ref: ActionRef, root: EastType): { query: StepQuery; open?: SlotRef; }; //# sourceMappingURL=slots.d.ts.map