unified-query
Version:
Composable search input with autocompletion and a rich query-language parser for the Unified Data System
40 lines (39 loc) • 1.29 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;
collections?: Map<string, Collection>;
theme?: any;
}
type Collection = {
id: string;
name: string;
kind: 'space' | 'collection' | 'project';
};
export declare class Search {
private opts;
private view;
private collections?;
/** Compartment so we can hot‑swap the UUID‑name plugin when collections change */
private readonly collectionsCompartment;
constructor(opts: SearchOptions);
focus(): void;
/** Replace all collections and refresh dependent plugins */
setCollections(newCollections: Map<string, Collection>): void;
destroy(): void;
/**
* A simple keyword completer: suggests on `@…`
* You can expand this list as desired.
*/
private keywordCompletion;
private inCompletionSource;
}
export { toQuery } from './query.js';
export { parse } from './parsers/index.js';
export { createTheme } from './theme.js';