import { E as TreeSearchHost } from "./tree-component-BE7OEIiH.js"; import { o as TreeNode } from "./types-6hpXRKt7.js"; import { p as ListSelectIntentSource } from "./list-selection-types-CKTt7Rrw.js"; import "./icon-YIyJDwM9.js"; import { ReactiveController, ReactiveControllerHost, TemplateResult, nothing } from "lit"; import { FzfOptions } from "fzf"; import { CommandRegistry } from "@clinth/ui-commands"; type IncrSearchResult = { readonly item: T; readonly positions: ReadonlySet; readonly score: number; }; type IncrSearchState = { readonly query: string; readonly results: ReadonlyArray>; readonly positionsByItem: ReadonlyMap>; }; type IncrSearchChangeCallback = (state: IncrSearchState) => void; type IncrSearchOptions = { readonly items?: readonly T[]; readonly selector?: (item: T) => string; readonly fzf?: Partial>; readonly onChange?: IncrSearchChangeCallback; }; type IncrSearch = { readonly setItems: (items: readonly T[], signal?: AbortSignal) => Promise; readonly setQuery: (query: string, signal?: AbortSignal) => Promise>; readonly clearQuery: () => Promise; readonly state: IncrSearchState; readonly onChange: (cb: IncrSearchChangeCallback) => () => void; readonly dispose: () => void; }; type FuzzySearchOptions = { readonly selector?: (item: T) => string; readonly fzf?: Partial>; }; type FuzzySearch = { readonly find: (query: string) => ReadonlyArray>; readonly items: readonly T[]; }; type HighlightTarget = { readonly element: Element; readonly text?: string; readonly positions: ReadonlySet; }; type HighlightOptions = { readonly key?: string; }; type ElementIncrSearchOptions = { readonly container: Element; readonly itemSelector: string; readonly getLabel?: (el: Element) => string; readonly getKey?: (el: Element) => string; readonly labelSelector?: string; readonly highlightKey?: string; readonly fzf?: Partial>; readonly onChange?: IncrSearchChangeCallback<{ key: string; label: string; }>; }; /** * Creates an ixfx-ac-text-compatible `completionProvider` function from a * static item list. Uses synchronous fuzzy search wrapped in a Promise so it * fits the async provider signature. * * Each returned item has `positions` populated with matched character indices, * which `ixfx-ac-text` uses to render CSS Custom Highlights on the label. * * Empty query returns all items in original order (no positions). * `limit` caps how many (best-first) results are returned and built; without * it every match is, which at 100k items and a short query is the whole list. * A cancelled signal causes the returned promise to reject with an AbortError. */ declare function createAcCompletionProvider(items: readonly T[], options?: Pick, `selector`> & { readonly limit?: number; }): (query: string, signal: AbortSignal) => Promise; }>>; type IncrSearchTreeOptions = { selector: (item: { node: TreeNode; depth: number; }) => string; /** * CSS selector for the label elements inside the shadow root. * Defaults to `.tree-label` (suitable for ixfx-tree-list). * Use `.label` for ixfx-miller-list. */ labelSelector?: string; highlightKey?: string; input?: HTMLInputElement; fzf?: Partial>; }; /** * External-input filter-search controller for `TreeSearchHost` components. * * @deprecated `ixfx-tree-list` / `ixfx-miller-list` now have a built-in * incremental-search popover with navigate / select / filter modes — invoke * `el.registry.invoke('list.search.filter')` (see `docs/infra-incremental.md`) * instead of wiring an external ``. This class remains for existing * consumers and covers filter mode only. * * @example Using with ixfx-tree-list: * ```typescript * const ctrl = new IncrSearchTreeController(myTreeList, { * selector: item => item.node.item.label, * }); * ctrl.connect(); * ``` * * @example Using with ixfx-miller-list (different label selector): * ```typescript * const ctrl = new IncrSearchTreeController(myMillerList, { * selector: item => item.node.item.label, * labelSelector: '.label', * }); * ctrl.connect(); * ``` */ declare class IncrSearchTreeController { #private; constructor(el: TreeSearchHost, opts: IncrSearchTreeOptions); connect(): void; disconnect(): void; setQuery(query: string): Promise; clearQuery(): Promise; } /** * The three things incremental search can do to a list / tree component. See * `docs/infra-incremental.md`. * * - `navigate` — move the cursor to the best match; ↑/↓ cycle between matches; * Enter activates the current match and closes. * - `select` — (re)select every item whose label matches, live as you type. * - `filter` — hide items that don't match; restored when the popover closes * (unless `stickyFilter` keeps it on Enter). */ type ListSearchMode = `navigate` | `select` | `filter`; /** Canonical order — used for the switch-row and to normalise a requested set. */ declare const LIST_SEARCH_MODES: readonly ListSearchMode[]; type SearchItem = { readonly key: string; readonly label: string; }; /** * Everything {@link ListSearchController} needs to drive a specific host. One is * supplied per component; `createElementListSearchAdapter` and * `createTreeListSearchAdapter` cover the common shapes. */ interface ListSearchAdapter { /** All searchable items, in display order. */ getItems: () => readonly TItem[]; /** Text matched against the query. */ getLabel: (item: TItem) => string; /** Stable identity for an item. */ getKey: (item: TItem) => string; /** `navigate`: move the cursor to `item` and reveal it. `undefined` = no-op. */ focusItem: (item: TItem | undefined) => void; /** `navigate` + Enter: activate `item` (falls back to `focusItem`). */ activateItem?: (item: TItem) => void; /** `select` / "Select matches": replace the selection with `items`. */ selectItems: (items: readonly TItem[]) => void; /** `filter`: hide items whose key is not in `matchedKeys`; `undefined` clears the filter. */ applyFilter: (matchedKeys: ReadonlySet | undefined) => void; /** Where matched-character highlights are painted (usually the shadow root). */ highlightRoot?: () => ShadowRoot | Element | null | undefined; /** CSS selector for the label elements inside {@link highlightRoot}. */ highlightSelector?: string; /** Given a label element, the key of the item it belongs to. */ highlightKeyOf?: (labelEl: Element) => string | undefined; /** Text of a label element as fzf saw it (defaults to `el.textContent`). */ highlightText?: (labelEl: Element) => string; /** `CSS.highlights` registry key. Defaults to `incr-search-highlight`. */ highlightKey?: string; /** Element whose child-list mutations should trigger a `refresh()`. */ container?: () => Element | null | undefined; } interface ListSearchControllerOptions { adapter: ListSearchAdapter; /** * Modes this instance offers, as entry points and as in-popover switch * targets. The controller intersects this with {@link LIST_SEARCH_MODES}, so * pass the intersection of the component's own capability and any * consumer-set `search-modes`. Empty ⇒ search disabled. Default: all three. */ modes?: readonly ListSearchMode[]; fzf?: Partial>; placeholder?: string; /** Initial {@link ListSearchController.stickyFilter}. Default false. */ stickyFilter?: boolean; } type ListSearchHost = ReactiveControllerHost & HTMLElement & { renderRoot?: DocumentFragment | HTMLElement; }; /** * Shared brain for the three-mode incremental-search popover. A Lit * `ReactiveController`: the host adds `listSearchStyles` to `static styles`, * drops `${controller.renderField()}` into `render()`, and registers the * commands with {@link registerListSearchCommands}. See `docs/infra-incremental.md`. */ declare class ListSearchController implements ReactiveController { #private; /** * When true, Enter in `filter` mode closes the popover but keeps the filter, * shown as a "Filtered: …" chip. Clear it with the chip's ×, Escape on the * host, or {@link clearFilter}; click the chip to edit the query. */ stickyFilter: boolean; constructor(host: ListSearchHost, options: ListSearchControllerOptions); /** `false` when no modes are available — the host should register no commands and render no field. */ get enabled(): boolean; /** The modes actually offered (component capability ∩ consumer request). */ get registeredModes(): readonly ListSearchMode[]; /** * Replace the offered mode set (normalised to {@link LIST_SEARCH_MODES} * order). If the current mode is dropped the popover closes and falls back to * the first remaining mode. Callers should re-run * {@link registerListSearchCommands} afterwards. */ setModes(modes: readonly ListSearchMode[]): void; get isOpen(): boolean; get mode(): ListSearchMode; get query(): string; get matchCount(): number; get matchIndex(): number; /** The query of a filter kept applied after the popover closed (see {@link stickyFilter}). */ get keptFilter(): string | undefined; hostConnected(): void; hostDisconnected(): void; /** * Open the popover in `mode` (clamped to the available set). When it is * already open the query is kept: the mode switches if it differs and the * input is refocused with its text selected. */ open(mode: ListSearchMode): void; /** Close the popover, restoring any live filter. Selection / cursor stay put. */ close(): void; /** Remove a filter kept by {@link stickyFilter}. No-op when none is kept. */ clearFilter(): void; setQuery(query: string): void; /** Re-interpret the current query under a new mode (undoing the old mode's effect). */ switchMode(next: ListSearchMode): void; /** * Step through {@link registeredModes} (wrapping) and switch to the result. * Bound to Tab / Shift+Tab in the popover input. */ cycleMode(delta: 1 | -1): void; /** Refocus the popover input (text selected) without touching the query. No-op when closed. */ focus(): void; /** One-shot: turn the current match set into the selection, staying in the current mode. */ selectMatches(source?: ListSelectIntentSource): void; nextMatch(): void; prevMatch(): void; /** * Enter: in `navigate` activate the current match; then close. In `filter` * with {@link stickyFilter} and a query, close but keep the filter. */ commit(): void; /** * Rebuild the searchable item set from the adapter. Called on open and on container mutation. * While search is idle (popover closed, no filter held) nothing reads the index, so a mutation only marks it * stale: rebuilding it is O(items) (a `{ key, label }` and a fuzzy-index entry per item: ~25 ms and ~15 MB at 100k), * and it was paid on every insert, remove and update. */ refresh(): void; /** Re-paint highlights without rebuilding the item set. Use when the rendered window changes. */ repaintHighlights(): void; /** Popover markup. Pair with `listSearchStyles` in the host's `static styles`. */ renderField(): TemplateResult | typeof nothing; } /** One searchable item in data-backed mode. */ type DataListSearchItem = { key: string; index: number; }; interface DataListSearchAdapterOptions { /** Total number of items in the whole collection (search sees all of them). */ rawCount: () => number; /** Raw (unfiltered) index → key. */ rawKeyAt: (index: number) => string; /** Raw (unfiltered) index → text matched against the query. */ rawSearchTextAt: (index: number) => string; /** Raw index → whether the item takes part in search. Default: all do. */ isSearchable?: (index: number) => boolean; /** `filter` mode: the host hides items whose key is not in `matchedKeys` (`undefined` clears). */ onFilterChange?: (matchedKeys: ReadonlySet | undefined) => void; /** `navigate` + Enter: activate the item with this key. Falls back to `focusKey`. */ onActivate?: (key: string) => void; /** Where matched-character highlights are painted (usually the shadow root). */ getHighlightRoot?: () => ShadowRoot | Element | null | undefined; } /** * A {@link ListSearchAdapter} over a data-backed list. Unlike the element * adapter it never materialises an element per item — it reads keys and text * straight from the source by index. Highlights are painted on whatever * captions are currently rendered in the shadow window; offscreen matches paint * when scrolled into view. See `docs/infra-incremental.md`. */ declare function createDataListSearchAdapter(host: { focusKey: (key: string) => void; selectKeys: (keys: Iterable) => void; }, options: DataListSearchAdapterOptions): ListSearchAdapter; /** * The slice of a list component the element adapter drives. `ixfx-grid-list`, * `ixfx-vertical-list` and `ixfx-detail-list` all satisfy it. */ interface ElementListSearchHost extends HTMLElement { focusKey: (key: string) => void; selectKeys: (keys: Iterable) => void; activateKey?: (key: string) => void; } interface ElementListSearchAdapterOptions { /** Selector for item elements, relative to the host. Default `:scope > *`. */ itemSelector?: string; getLabel?: (el: Element) => string; getKey?: (el: Element) => string; /** `CSS.highlights` registry key for matched-character highlights. */ highlightKey?: string; /** Full ordered item set, including rows not currently in the DOM (virtualised hosts). Defaults to querying `itemSelector`. */ getAllItems?: () => Element[]; /** Items for which this returns `false` take no part in search. Default: all do. */ isSearchable?: (el: Element) => boolean; /** Observe host child-list mutations to refresh the item set. Default true. */ observeContainer?: boolean; } /** * A {@link ListSearchAdapter} over the light-DOM item elements of a list * component. Filter mode toggles `hidden` (only on elements it hid itself, so a * consumer's own `hidden` items are left alone). Highlights are painted on the * item elements in the light DOM — the consuming page styles * `::highlight()`. See `docs/infra-incremental.md`. */ declare function createElementListSearchAdapter(host: ElementListSearchHost, options?: ElementListSearchAdapterOptions): ListSearchAdapter; type ElementItem = { readonly key: string; readonly label: string; }; type ElementIncrSearch = { readonly setQuery: (query: string, signal?: AbortSignal) => Promise; readonly clearQuery: () => Promise; readonly refresh: () => void; readonly onChange: (cb: IncrSearchChangeCallback) => () => void; readonly dispose: () => void; }; /** * DOM filter-search over a container's item elements (sets `hidden` on * non-matches, applies highlights). * * @deprecated The list components (`ixfx-grid-list`, `ixfx-vertical-list`, * `ixfx-detail-list`, …) now have a built-in navigate / select / filter search * popover — see `docs/infra-incremental.md` and `ListSearchController`. Kept for * standalone / non-component use. */ declare function createElementIncrSearch(opts: ElementIncrSearchOptions): ElementIncrSearch; declare function createFuzzySearch(items: readonly T[], options?: FuzzySearchOptions): FuzzySearch; declare function applyHighlights(targets: readonly HighlightTarget[], options?: HighlightOptions): void; declare function clearHighlights(options?: HighlightOptions): void; declare function buildHighlightTargets(root: ShadowRoot | Element, itemSelector: string, positionsByItem: ReadonlyMap>, getItem: (el: Element) => T | undefined, getText: (el: Element) => string): HighlightTarget[]; declare function createIncrSearch(options?: IncrSearchOptions): IncrSearch; /** Command ids registered by {@link registerListSearchCommands}, keyed by mode. */ declare const LIST_SEARCH_COMMAND_IDS: Readonly>; interface RegisterListSearchCommandsOptions { /** * Prefix for command ids, e.g. `grid-list` ⇒ `grid-list.search.filter`. When * omitted the shared ids from {@link LIST_SEARCH_COMMAND_IDS} are used so a * single dispatch (`ixfx-grouped-item-lister.dispatch('list.search.filter')`) * fans out to every list. */ idPrefix?: string; } /** * Register one command per mode the controller offers (see * `controller.registeredModes`). Each command opens the search popover in its * mode. Returns a function that unregisters them again — call it from * `disconnectedCallback`. See `docs/infra-incremental.md`. */ declare function registerListSearchCommands(registry: CommandRegistry, controller: ListSearchController, options?: RegisterListSearchCommandsOptions): () => void; /** * Styles for the incremental-search popover rendered by * `ListSearchController.renderField()`. Add to a component's `static styles`; * the class names are the contract between this fragment and `renderField()`. * * The host must give the popover a positioned ancestor (a wrapper with * `position: relative`, or `:host { position: relative }`). Tunables: * `--list-search-inset` (default `8px`) offsets it from the top-right corner. * * See `docs/infra-incremental.md`. */ declare const listSearchStyles: import("lit").CSSResult; type TreeSearchItem = { node: TreeNode; depth: number; }; interface TreeListSearchAdapterOptions { /** Label-element selector inside the shadow root. Default `.tree-label`; `ixfx-miller-list` uses `.label`. */ labelSelector?: string; /** `CSS.highlights` registry key for matched-character highlights. */ highlightKey?: string; getLabel?: (item: TreeSearchItem) => string; } /** * A {@link ListSearchAdapter} over any `TreeSearchHost` (`ixfx-tree-list`, * `ixfx-miller-list`, `ixfx-crumb-navigation`). Navigate reveals the match * (expands its ancestors, moves the cursor); select drives `selectMany`; filter * sets `filterPredicate`. The item set is the whole tree — `getNodes()` returns * every node regardless of expansion or an active filter — so refining a query * can always re-surface a node. See `docs/infra-incremental.md`. */ declare function createTreeListSearchAdapter(host: TreeSearchHost, options?: TreeListSearchAdapterOptions): ListSearchAdapter; export { FuzzySearch as A, ListSearchControllerOptions as C, IncrSearchTreeOptions as D, IncrSearchTreeController as E, IncrSearchChangeCallback as F, IncrSearchOptions as I, IncrSearchResult as L, HighlightOptions as M, HighlightTarget as N, createAcCompletionProvider as O, IncrSearch as P, IncrSearchState as R, ListSearchController as S, ListSearchMode as T, DataListSearchAdapterOptions as _, RegisterListSearchCommandsOptions as a, LIST_SEARCH_MODES as b, applyHighlights as c, createFuzzySearch as d, ElementIncrSearch as f, createElementListSearchAdapter as g, ElementListSearchHost as h, LIST_SEARCH_COMMAND_IDS as i, FuzzySearchOptions as j, ElementIncrSearchOptions as k, buildHighlightTargets as l, ElementListSearchAdapterOptions as m, createTreeListSearchAdapter as n, registerListSearchCommands as o, createElementIncrSearch as p, listSearchStyles as r, createIncrSearch as s, TreeListSearchAdapterOptions as t, clearHighlights as u, DataListSearchItem as v, ListSearchHost as w, ListSearchAdapter as x, createDataListSearchAdapter as y };