/** * @file * * Mock of Obsidian's `Modal`, a dialog shown over the workspace. */ import type { Modal as ModalOriginal } from 'obsidian'; import type { App } from './App.cjs'; import { Scope } from './Scope.cjs'; /** * Mock of Obsidian's `Modal` dialog. * * The modal's elements are built detached from the document. {@link Modal.open} calls {@link Modal.onOpen} and then * closes the modal from a zero-delay `setTimeout`, which gives a test one tick to interact with its content. */ export declare class Modal { /** * The app instance the modal belongs to. */ app: App; /** * The dimmed background element behind the modal. */ bgEl: HTMLElement; /** * The outermost element holding the background and the modal. */ containerEl: HTMLElement; /** * The element subclasses render the modal's body into. */ contentEl: HTMLElement; /** * The header element holding the title. */ headerEl: HTMLDivElement; /** * The modal dialog element itself. */ modalEl: HTMLElement; /** * The keymap scope active while the modal is open. */ scope: Scope; /** * Whether the text selection active before opening is restored when the modal closes. */ shouldRestoreSelection: boolean; /** * The element holding the modal's title. */ titleEl: HTMLElement; private closeCallback; /** * Creates the modal and its elements, without opening it. * * @param app - The app instance. */ constructor(app: App); /** * Mock-only factory: creates a modal, spyable via `vi.spyOn(Modal, 'create__')`. * * @param app - The app instance. * @returns The new modal. */ static create__(app: App): Modal; /** * Mock-only: views a value typed as Obsidian's `Modal` as this mock. * * @param value - The value typed as the original `Modal`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: ModalOriginal): Modal; /** * Mock-only: views this mock as Obsidian's `Modal` type. * * @returns The same object, typed as the original `Modal`. */ asOriginalType__(): ModalOriginal; /** * Hides the modal. The mock calls {@link Modal.onClose} and then the callback set by * {@link Modal.setCloseCallback}, if any. */ close(): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(Modal.prototype, 'constructor__')`. * * @param _app - The app the modal was created with. */ constructor__(_app: App): void; /** * Called when the modal closes; subclasses override it to clean up. A no-op by default. */ onClose(): void; /** * Handles the history-back action (the back gesture or the mobile back button) while the modal is the topmost * history handler. As in Obsidian, it closes the modal. */ onHistoryBack(): void; /** * Called when the modal opens; subclasses override it to render content. A no-op by default. */ onOpen(): void; /** * Shows the modal on the active window. The mock calls {@link Modal.onOpen} synchronously and schedules * {@link Modal.close} with a zero-delay `setTimeout`. */ open(): void; /** * Sets a callback to run after the modal closes, replacing any previous one. * * @param callback - The callback to run on close. * @returns This modal, for chaining. */ setCloseCallback(callback: () => unknown): this; /** * Sets the modal's body content. A string replaces the text of {@link Modal.contentEl}; a fragment is appended * to it. * * @param content - The content, as text or as a fragment. * @returns This modal, for chaining. */ setContent(content: DocumentFragment | string): this; /** * Sets the modal's title text. * * @param title - The title. * @returns This modal, for chaining. */ setTitle(title: string): this; }