import * as i0 from '@angular/core'; import { OnInit, OnChanges, OnDestroy, EventEmitter, ElementRef, SimpleChanges, TemplateRef, ChangeDetectorRef } from '@angular/core'; import { Observable, Subscription } from 'rxjs'; import * as i4 from '@sinequa/components/utils'; import { UIService } from '@sinequa/components/utils'; import { AppService, Query } from '@sinequa/core/app-utils'; import { SuggestQueryWebService, SuggestFieldWebService, Suggestion } from '@sinequa/core/web-services'; import * as i3 from '@angular/common'; interface ScoredAutocompleteItem extends AutocompleteItem { score: number; data: T; category: Tcat; } declare class SuggestService { private suggestQueryWebService; private suggestFieldWebService; private appService; constructor(suggestQueryWebService: SuggestQueryWebService, suggestFieldWebService: SuggestFieldWebService, appService: AppService); get(suggestQuery: string | undefined, text: string, fields?: string | string[], query?: Query, maxCount?: number): Observable[]>; getFields(text: string, fields: string | string[], query?: Query): Observable; /** * Search for the input text in a list of objects and return autocomplete items asynchronously * @param query The text to search for * @param data The list of objects * @param primaryText A function that returns the primary text input given the object * @param secondaryText An (optional) function that returns a list of secondary text inputs given the object */ searchData(category: Tcat, query: string, data: T[], primaryText: (obj: T) => string, secondaryText?: (obj: T) => string[], label?: string): Promise[]>; /** * Searches for the query string inside a given text. Returns a match object containing: * - a score proportional to the number and quality of matches * - the text formatted as HTML with the query found in the text * @param text The text to search * @param query The string to search for * @param secondaryText Secondary fields to search input, with less importance than the primary field * @param data A data object to be included in the match object (for convenience mostly) */ findMatch(text: string, query: string, secondaryText: string[] | undefined, data: T): { display: string; displayHtml: string; score: number; data: T; } | undefined; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Minimal interface for autocomplete items (note that the Suggestion * objects returned by the Suggestion service implement naturally this * interface) */ interface AutocompleteItem { display: string; normalized?: string; category: string; label?: string; rank?: number; } /** * Interface required to be implemented by the dropdown components * binded to this autocomplete directive. * The component is responsible for displaying a list of items * and signaling back if a component was clicked. The component must * also manage navigation through the list (next/previous and selectedValue). */ interface AutocompleteComponent { /** * Whether there are any item to display */ hasItems: boolean; /** * Event emitter for clicks on an autocomplete item */ clicked: EventEmitter; /** * Returns the currently selected item, if any */ selectedValue: AutocompleteItem | undefined; /** * Update the data and state of this component * @param active whether the component should be displayed * @param items The list of items to display */ update(active: boolean, items?: AutocompleteItem[]): void; /** * Select the next item in the list and returns it */ selectNext(): AutocompleteItem | undefined; /** * Select the previous item in the list and returns it */ selectPrevious(): AutocompleteItem | undefined; } /** * States in which the autocomplete component can be */ declare enum AutocompleteState { OFF = "OFF",// Autocomplete is turned off (via @Input()) INIT = "INIT",// Input is not focused, dropdown is closed START = "START",// Input is focused, no text typed in, dropdown is closed ACTIVE = "ACTIVE",// Input is focused, text is typed, suggests are being queried, dropdown is closed OPENED = "OPENED",// Input is focused, text is typed, suggests are available, dropdown/autocomplete component is displayed SELECTED = "SELECTED" } declare class Autocomplete implements OnInit, OnChanges, OnDestroy { /** Reference to the AutocompleteComponent that displays the autocomplete items */ dropdown: AutocompleteComponent; /** Whether the autocomplete should be active or not */ off: boolean; /** Debounce delay between autocomplete queries */ suggestDelay: number; /** Name of the Suggest Query to be used */ suggestQuery: string; /** Custom placeholder */ placeholder: string; _placeholder: any; stateChange: EventEmitter; submit: EventEmitter; private _state; protected readonly inputElement: HTMLInputElement; protected readonly elementRef: ElementRef; protected readonly suggestService: SuggestService; protected readonly appService: AppService; protected readonly uiService: UIService; constructor(); /** * On initialization, we listen to the autocomplete component for * selection events */ ngOnInit(): void; /** * If the off input changes state, react accordingly * @param changes */ ngOnChanges(changes: SimpleChanges): void; protected _dropdownSubscription: Subscription; /** * Unsubscribe when destroying the component */ ngOnDestroy(): void; /** * Return the current state of the autocomplete */ getState(): AutocompleteState; /** * Set the current state of the autocomplete */ protected setState(state: AutocompleteState): void; /** * Get the current text value of the HTML * to which this directive is attached */ protected getInputValue(): string; /** * Set the current text value of the HTML * to which this directive is attached */ protected setInputValue(value: string): void; /** * Sets the content of the based on the given * Autocomplete Item (various implementations are possible, * depending on the item content and nature). * This would be the right method to override to implement * fielded search autocomplete. * @returns true if this autocomplete item should be searched */ protected setAutocompleteItem(item: AutocompleteItem): boolean; /** * INIT state (Input is not focused, dropdown is closed) */ protected init(): void; /** * START state (Input is focused, no text typed in, dropdown is closed) */ protected start(): void; /** * START state and if the has content, immediately switch to ACTIVE */ protected startOrActive(): void; /** * ACTIVE state (Input is focused, text is typed, suggests are being queried, dropdown is closed) */ protected active(): void; /** * Select the given autocomplete suggestion for search * @param submit if, true also trigger a submit * @param item a specific item to submit */ protected select(item: AutocompleteItem, submit?: boolean): void; /** * Switch to OPENED state (from ACTIVE only) */ protected open(): void; /** * Request suggestions from the server, and update the dropdown contents * and autocomplete state asynchronously. * Override this method for a synchronous implementation. */ protected suggest(): void; /** * Actually makes the API call to the suggestService to retrieve suggestions * and process them. */ protected getSuggests(): void; /** * Returns an observable of Suggestions, given some input text * @param value input text for which to return suggestions */ protected getSuggestsObs(value: string, fields?: string[]): Observable; /** * Process suggestions obtained (from whatever mean): * - If data available, filter out fields * - update the dropdown content * - Switch between OPEN and ACTIVE states * - Use changeDetectorRef to update display * @param obs an observable of AutocompleteItem suggestions */ protected processSuggests(obs: Observable): void; /** * Use the suggest service to retrieve suggestions given the input text. * The suggest (autocomplete) query is debounced to avoid flooding the server. */ private readonly debounceSuggest; /** * Returns the caret position within the input */ protected getInputPosition(): number; /** * The following are event listeners applied to the host component * onto which this directive is applied. * The events affect the state of the autocomplete, which triggers * various actions (call to suggest API, etc.). */ /** * Listens to click events on the host */ click(): void; /** * Listens to touchstart events (mobile clicks) on the host */ touchstart(): void; /** * Listens to focus events on the host */ focus(): void; /** * Listens to blur events (out of focus) on the host */ blur(event: FocusEvent): void; /** * Listen to any change in the content and react * according to the current state of the autocomplete * @param event */ inputChanged(event: Event): void; /** * Listen to user's keyboard actions in the , in order to navigate * and select the autocomplete suggestions. * @param event the keyboard */ keydown(event: KeyboardEvent): false | undefined; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } declare class BsAutocompleteList implements AutocompleteComponent { private changeDetectorRef; /** * Template for the display of AutocompleteItem items, passed by transclusion */ itemTpl: TemplateRef; /** * Optional footer template, passed by transclusion */ footerTpl: TemplateRef; /** * Event emitter for clicks on an autocomplete item */ clicked: EventEmitter; _active: boolean; _items: AutocompleteItem[] | undefined; _cursor: number; constructor(changeDetectorRef: ChangeDetectorRef); /** * Update the data and state of this component * @param active whether the component should be displayed * @param items The list of items to display */ update(active: boolean, items?: AutocompleteItem[]): void; /** * Whether there are any item to display */ get hasItems(): boolean; /** * Returns the currently selected item, if any */ get selectedValue(): AutocompleteItem | undefined; /** * Select the next item in the list and returns it */ selectNext(): AutocompleteItem | undefined; /** * Select the previous item in the list and returns it */ selectPrevious(): AutocompleteItem | undefined; /** * Test whether an item is selected * @param item * @param i */ _isSelected(item: AutocompleteItem, i: number): boolean; /** * Listen to click events and emits events * @param item * @param event */ _itemClicked(item: AutocompleteItem, event: any): boolean; /** * This prevents the focus to be removed from the , which clauses the dropdown */ _mouseDown(event: any): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } declare class BsAutocompleteModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } export { Autocomplete, AutocompleteState, BsAutocompleteList, BsAutocompleteModule, SuggestService }; export type { AutocompleteComponent, AutocompleteItem, ScoredAutocompleteItem };