/** * @file * * Mock of the view registry Obsidian exposes as `app.viewRegistry`. */ import type { ViewCreator as ViewCreatorOriginal } from 'obsidian'; import { Events } from '../../obsidian/Events.mjs'; /** * The registry behind `App.viewRegistry`: which creator builds a view of a given type, and which view type a file * extension opens in. * * Lives here rather than in `src/obsidian/` because `ViewRegistry` is an `obsidian-typings` interface with no * `obsidian.d.ts` counterpart — the same case L1 settles for {@link Plugins}. * * It is what makes a leaf's view real: `WorkspaceLeaf.setViewState` asks {@link ViewRegistry.getViewCreatorByType} * and `WorkspaceLeaf.openFile` asks {@link ViewRegistry.getTypeByExtension}, exactly as Obsidian does. * * **Only the Markdown view is registered up front.** Obsidian's own constructor also registers its image, audio, * video, PDF and release-notes views; this package has a class for none of them, and an extension whose registered * type has no creator would open as the unknown-type view where Obsidian opens a real one. Left unregistered, such a * file takes Obsidian's own "no view type for this extension" branch in `openFile` instead, which changes nothing. */ export declare class ViewRegistry extends Events { /** * The view type each file extension opens in, keyed by extension without the leading dot. Obsidian keeps it under * this name too. */ typeByExtension: Record; /** * The creator that builds a view of each type, keyed by view type. Obsidian keeps it under this name too. */ viewByType: Record; /** * Creates a registry holding Obsidian's Markdown view. */ protected constructor(); /** * Mock-only factory: creates a view registry, spyable via `vi.spyOn(ViewRegistry, 'create2__')`. Numbered because * it is the subclass variant of the `Events` factory. * * @returns The new registry. */ static create2__(): ViewRegistry; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(ViewRegistry.prototype, 'constructor2__')`. */ constructor2__(): void; /** * Gets the view type a file extension opens in. * * @param extension - The file extension, without the leading dot. * @returns The view type, or `undefined` when the extension is not registered. */ getTypeByExtension(extension: string): string | undefined; /** * Gets the creator that builds a view of a type. * * @param type - The view type. * @returns The creator, or `undefined` when the type is not registered. */ getViewCreatorByType(type: string): undefined | ViewCreatorOriginal; /** * Checks whether a file extension opens in a registered view type. * * @param extension - The file extension, without the leading dot. * @returns Whether the extension is registered. */ isExtensionRegistered(extension: string): boolean; /** * Registers the file extensions a view type opens. As in Obsidian, every extension is checked before any is * written, so a clash leaves the registry untouched, and `extensions-updated` is triggered afterwards. * * @param extensions - The file extensions, without leading dots. * @param viewType - The view type the extensions open in. * @throws Error when any of the extensions is already registered. */ registerExtensions(extensions: string[], viewType: string): void; /** * Registers the creator that builds views of a type, and triggers `view-registered` with it. * * @param type - The view type. * @param viewCreator - The creator that builds a view of that type for a leaf. * @throws Error when the view type is already registered. */ registerView(type: string, viewCreator: ViewCreatorOriginal): void; /** * Registers a view type and the file extensions that open in it, through {@link ViewRegistry.registerView} and * {@link ViewRegistry.registerExtensions}. * * @param extensions - The file extensions, without leading dots. * @param type - The view type. * @param viewCreator - The creator that builds a view of that type for a leaf. */ registerViewWithExtensions(extensions: string[], type: string, viewCreator: ViewCreatorOriginal): void; /** * Removes file extensions from the registry and triggers `extensions-updated`. As in Obsidian, an extension that * was never registered is skipped silently, and the event fires either way. * * @param extensions - The file extensions, without leading dots. */ unregisterExtensions(extensions: string[]): void; /** * Removes a view type from the registry. As in Obsidian, a type that was never registered changes nothing and * triggers nothing; otherwise `view-unregistered` is triggered with it. * * @param type - The view type. */ unregisterView(type: string): void; }