/** * @file * * Mock of Obsidian's `FileView`, the base class of views that display a single file. */ import type { FileView as FileViewOriginal, ViewStateResult as ViewStateResultOriginal } from 'obsidian'; import type { WorkspaceLeaf } from './WorkspaceLeaf.mjs'; import { ItemView } from './ItemView.mjs'; import { TFile } from './TFile.mjs'; /** * Mock of Obsidian's `FileView`. * * {@link FileView.setState} resolves the `file` path in the state and loads it through * {@link FileView.loadFile}, exactly as Obsidian does, so `WorkspaceLeaf.openFile` really leaves the view holding * the file. The rename hook does nothing. */ export declare abstract class FileView extends ItemView { /** * Whether the view may stay open with no file loaded. */ allowNoFile: boolean; /** * The file the view currently displays, or `null` when none is loaded. */ file: null | TFile; /** * Whether the view takes part in navigation history. As in Obsidian, a file view opts back into the history the * base view opts out of. */ navigation: boolean; /** * Creates a file view in a leaf. * * @param leaf - The workspace leaf that hosts the view. */ constructor(leaf: WorkspaceLeaf); /** * Mock-only: views a value typed as Obsidian's `FileView` as this mock. * * @param value - The value typed as the original `FileView`. * @returns The same object, typed as the mock. */ static fromOriginalType4__(value: FileViewOriginal): FileView; /** * Mock-only: views this mock as Obsidian's `FileView` type. * * @returns The same object, typed as the original `FileView`. */ asOriginalType4__(): FileViewOriginal; /** * Tells whether the view can open files with the given extension. * * @param _extension - The file extension, without the leading dot. * @returns `false` in the base mock; subclasses override it. */ canAcceptExtension(_extension: string): boolean; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(FileView.prototype, 'constructor4__')`. * * @param _leaf - The leaf the view was created in. */ constructor4__(_leaf: WorkspaceLeaf): void; /** * Gets the text shown in the view's tab header. * * @returns The loaded file's basename, or Obsidian's own `No file` when none is loaded. */ getDisplayText(): string; /** * Gets the view's serializable state, which carries the loaded file's path as Obsidian's does. * * @returns A shallow copy of the inherited view state, with `file` added when a file is loaded. */ getState(): Record; /** * Loads a file into the view, as Obsidian does: the outgoing file is unloaded through * {@link FileView.onUnloadFile}, the new one is stored and passed to {@link FileView.onLoadFile}, and a hook that * throws leaves the view with no file rather than a half-loaded one. Loading the file the view already holds does * nothing. * * The user-facing notice Obsidian shows for a file that failed to load is not modeled; the error is logged, as it * is there. * * @param file - The file to load, or `null` to unload the current one. * @returns Whether the loaded file changed. */ loadFile(file: null | TFile): Promise; /** * Called when the view is loaded. A no-op in the mock. */ onload(): void; /** * Called when a file is loaded into the view, after {@link FileView.loadFile} has stored it in * {@link FileView.file}. An empty hook for subclasses, as in Obsidian. * * @param _file - The file being loaded. */ onLoadFile(_file: TFile): Promise; /** * Called when the displayed file is renamed. A no-op in the mock. * * @param _file - The renamed file. */ onRename(_file: TFile): Promise; /** * Called when a file is unloaded from the view, before {@link FileView.loadFile} clears * {@link FileView.file}. An empty hook for subclasses, as in Obsidian. * * @param _file - The file being unloaded. */ onUnloadFile(_file: TFile): Promise; /** * Restores the view from a serialized state, loading the file its `file` path names, as Obsidian does. A state * naming a path that is not a file unloads the current one; a view left with no file asks the leaf to close it, * unless {@link FileView.allowNoFile} is set. * * Obsidian also schedules the linked-pane sync on the result's `done` callback; `syncState` is not modeled, so the * mock does not. * * @param state - The state to restore. * @param result - The result object the view can update, such as to record history. */ setState(state: unknown, result: ViewStateResultOriginal): Promise; }