/** * @file * * Mock of Obsidian's `View`, the content displayed inside a workspace leaf. */ import type { IconName as IconNameOriginal, Menu as MenuOriginal, Scope as ScopeOriginal, View as ViewOriginal, ViewStateResult as ViewStateResultOriginal } from 'obsidian'; import type { App } from './App.mjs'; import type { WorkspaceLeaf } from './WorkspaceLeaf.mjs'; import { Component } from './Component.mjs'; /** * Mock of Obsidian's `View` base class. * * The view's state and ephemeral state are kept in memory and returned as set; opening, closing, resizing and the * pane menu are no-ops. */ export declare abstract class View extends Component { /** * The app instance, taken from the leaf. */ app: App; /** * The view's root element; detached in the mock. */ containerEl: HTMLElement; /** * The view's icon, Obsidian's generic document glyph until a subclass sets its own. */ icon: IconNameOriginal; /** * The workspace leaf hosting the view. */ leaf: WorkspaceLeaf; /** * Whether the view takes part in navigation history, like a file view (`true`), rather than being a static panel * like the file explorer (`false`). As in Obsidian the base view opts out, and a subclass such as `FileView` * opts back in. */ navigation: boolean; /** * An optional scope for hotkeys that apply while the view is focused. */ scope: null | ScopeOriginal; private ephemeralState; private state; /** * Creates the view in a leaf, taking the app from it. * * @param leaf - The workspace leaf that hosts the view. */ constructor(leaf: WorkspaceLeaf); /** * Mock-only: views a value typed as Obsidian's `View` as this mock. * * @param value - The value typed as the original `View`. * @returns The same object, typed as the mock. */ static fromOriginalType2__(value: ViewOriginal): View; /** * Mock-only: views this mock as Obsidian's `View` type. * * @returns The same object, typed as the original `View`. */ asOriginalType2__(): ViewOriginal; /** * Closes the view, as `WorkspaceLeaf.open` does when another view replaces this one. Detaches the view's element, * unloads the component and awaits {@link View.onClose}, exactly as Obsidian does. */ close(): Promise; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(View.prototype, 'constructor2__')`. * * @param _leaf - The leaf the view was created in. */ constructor2__(_leaf: WorkspaceLeaf): void; /** * Gets the human-readable text shown in the view's tab header. * * @returns The display text. */ abstract getDisplayText(): string; /** * Gets the view's ephemeral state, such as scroll position, which is not persisted in the workspace layout. * * @returns The state last passed to {@link View.setEphemeralState}, or an empty object. */ getEphemeralState(): Record; /** * Gets the view's icon. * * @returns The value of {@link View.icon}, or Obsidian's generic document glyph when that has been emptied. */ getIcon(): IconNameOriginal; /** * Gets the view's state, which is persisted in the workspace layout. * * @returns The state last passed to {@link View.setState}, or an empty object. */ getState(): Record; /** * Gets the identifier of the view's type, as registered with `registerView`. * * @returns The view type. */ abstract getViewType(): string; /** * Populates the pane menu shown from the tab header or the "more options" button. A no-op in the mock. * * @param _menu - The menu to populate. * @param _source - Where the menu was opened from, such as `'more-options'` or `'tab-header'`. */ onPaneMenu(_menu: MenuOriginal, _source: string): void; /** * Called when the view's size changes. A no-op in the mock. */ onResize(): void; /** * Opens the view into an element, as `WorkspaceLeaf.open` does. Appends the view's element to it, loads the * component and awaits {@link View.onOpen}, exactly as Obsidian does. * * @param containerEl - The element to append the view's own element to. */ open(containerEl: HTMLElement): Promise; /** * Sets the view's ephemeral state. The mock stores it as given. * * @param state - The ephemeral state. */ setEphemeralState(state: unknown): void; /** * Sets the view's state. The mock stores it as given and leaves the result untouched. * * @param state - The new state. * @param _result - Receives whether the change should be recorded in navigation history. */ setState(state: unknown, _result: ViewStateResultOriginal): Promise; /** * Called when the view is closed, to release its resources. A no-op in the mock. */ protected onClose(): Promise; /** * Called when the view is opened, to build its content. A no-op in the mock. */ protected onOpen(): Promise; }