unified-query
Version:
Composable search input with autocompletion and a rich query-language parser for the Unified Data System
46 lines (45 loc) • 1.36 kB
TypeScript
import { EditorSelection } from '@codemirror/state';
type Key = 'Enter' | 'ArrowDown' | 'ArrowUp';
export interface SearchOptions {
/** The DOM element to mount the editor into */
element: HTMLElement;
/** Called whenever the query text changes */
query?: string;
selection?: EditorSelection;
onChange: (query: string) => void;
onKeydown?: (key: Key) => void;
completions?: Partial<Completions>;
theme?: any;
}
type Entity = {
id: string;
name: string;
kind: string;
};
type Completions = {
by: Entity[];
in: Entity[];
};
export declare class Search {
private opts;
private view;
private completions;
/** Compartment so we can hot‑swap the UUID‑name plugin when collections change */
private readonly completionsComp;
constructor(opts: SearchOptions);
focus(): void;
/** Replace all collections and refresh dependent plugins */
setCompletions(completions: Partial<Completions>): void;
destroy(): void;
private entityMap;
/**
* A simple keyword completer: suggests on `@…`
* You can expand this list as desired.
*/
private keywordCompletion;
private byCompletionSource;
private inCompletionSource;
}
export { toQuery } from './query.js';
export { parse } from './parsers/index.js';
export { createTheme } from './theme.js';