/** * @file * * Mock of Obsidian's `SuggestModal`, a modal that lists suggestions for a typed query. */ import type { Instruction as InstructionOriginal, SuggestModal as SuggestModalOriginal } from 'obsidian'; import type { App } from './App.mjs'; import { Modal } from './Modal.mjs'; /** * Mock of Obsidian's `SuggestModal` base class. * * No suggestion list is driven by typing: a test calls {@link SuggestModal.selectSuggestion} to choose an item. * Instructions are rendered into {@link SuggestModal.instructionsEl} and kept in {@link SuggestModal.instructions__}. * * @typeParam T - The type of a suggestion item. */ export declare abstract class SuggestModal extends Modal { /** * Text shown when there are no suggestions. */ emptyStateText: string; /** * The query input element. */ inputEl: HTMLInputElement; /** * Mock-only: the instructions last passed to {@link SuggestModal.setInstructions}. */ instructions__: InstructionOriginal[]; /** * The `prompt-instructions` element listing the keyboard instructions; attached to the modal only while there are * instructions. */ readonly instructionsEl: HTMLDivElement; /** * The maximum number of suggestions to show. */ limit: number; /** * The element suggestions are rendered into. */ resultContainerEl: HTMLElement; /** * Creates the modal with its query input, result container and detached instructions element. * * @param app - The app instance. */ constructor(app: App); /** * Mock-only: views a value typed as Obsidian's `SuggestModal` as this mock. * * @typeParam T - The type of a suggestion item. * @param value - The value typed as the original `SuggestModal`. * @returns The same object, typed as the mock. */ static fromOriginalType2__(value: SuggestModalOriginal): SuggestModal; /** * Mock-only: views this mock as Obsidian's `SuggestModal` type. * * @returns The same object, typed as the original `SuggestModal`. */ asOriginalType2__(): SuggestModalOriginal; /** * Closes the modal. */ close(): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(SuggestModal.prototype, 'constructor2__')`. * * @param _app - The app the modal was created with. */ constructor2__(_app: App): void; /** * Computes the suggestions for a query. * * @param _query - The text typed into the input. * @returns The matching items, or a promise of them. */ abstract getSuggestions(_query: string): Promise | T[]; /** * Called when the user chooses a suggestion. * * @param item - The chosen item. * @param $event - The mouse or keyboard event that chose it. */ abstract onChooseSuggestion(item: T, $event: KeyboardEvent | MouseEvent): void; /** * Called when a query yields no suggestions. A no-op in the mock. */ onNoSuggestion(): void; /** * Renders one suggestion into its element. * * @param value - The item to render. * @param _el - The element to render it into. */ abstract renderSuggestion(value: T, _el: HTMLElement): void; /** * Chooses the currently highlighted suggestion. A no-op in the mock, which tracks no highlight. * * @param _event - The mouse or keyboard event that triggered the choice. */ selectActiveSuggestion(_event: KeyboardEvent | MouseEvent): void; /** * Chooses a suggestion: calls {@link SuggestModal.onChooseSuggestion}, then closes the modal. * * @param value - The chosen item. * @param $event - The mouse or keyboard event that chose it. */ selectSuggestion(value: T, $event: KeyboardEvent | MouseEvent): void; /** * Sets the keyboard instructions shown below the suggestions. An empty list detaches * {@link SuggestModal.instructionsEl}; otherwise it is re-rendered and appended to the modal. * * @param instructions - The command and purpose pairs to show. */ setInstructions(instructions: InstructionOriginal[]): void; /** * Sets the query input's placeholder text. * * @param placeholder - The placeholder text. */ setPlaceholder(placeholder: string): void; }