/** * @file * * Mock of Obsidian's `MarkdownPreviewView`, the reading mode of a Markdown view. */ import type { MarkdownPreviewView as MarkdownPreviewViewOriginal } from 'obsidian'; import type { MarkdownView } from './MarkdownView.cjs'; import type { TFile } from './TFile.cjs'; import { MarkdownRenderer } from './MarkdownRenderer.cjs'; /** * Mock of Obsidian's `MarkdownPreviewView`. * * Nothing is rendered: the text passed to {@link MarkdownPreviewView.set} and the scroll position are only * remembered. The owning view registers it as its reading mode, so `setViewData(data, true)` and `clear()` reach * it as they reach the edit mode; the mock is never IN reading mode, so `getViewData()` never reads it. */ export declare class MarkdownPreviewView extends MarkdownRenderer { /** * The element the preview renders into; shared with the owning Markdown view. */ containerEl: HTMLElement; /** * The mode this view is, as `MarkdownView.registerMode` keys it and `MarkdownView.getMode()` reports it. */ readonly type = "preview"; /** * The file open in the owning Markdown view. * * @returns The Markdown view's file; the mock throws when that view has no file. */ get file(): TFile; private data; private readonly markdownView; private scroll; /** * Creates the reading mode of a Markdown view. * * @param markdownView - The Markdown view that owns this mode. */ constructor(markdownView: MarkdownView); /** * Mock-only factory: creates a preview view, spyable via `vi.spyOn(MarkdownPreviewView, 'create3__')`. The * subclass variant of `MarkdownRenderChild.create2__`. * * @param markdownView - The Markdown view that owns this mode. * @returns The new preview view. */ static create3__(markdownView: MarkdownView): MarkdownPreviewView; /** * Mock-only: views a value typed as Obsidian's `MarkdownPreviewView` as this mock. * * @param value - The value typed as the original `MarkdownPreviewView`. * @returns The same object, typed as the mock. */ static fromOriginalType4__(value: MarkdownPreviewViewOriginal): MarkdownPreviewView; /** * Scrolls the preview to a position. The mock only remembers it for {@link MarkdownPreviewView.getScroll}. * * @param scroll - The scroll position. */ applyScroll(scroll: number): void; /** * Mock-only: views this mock as Obsidian's `MarkdownPreviewView` type. * * @returns The same object, typed as the original `MarkdownPreviewView`. */ asOriginalType4__(): MarkdownPreviewViewOriginal; /** * Clears the previewed text. */ clear(): void; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(MarkdownPreviewView.prototype, 'constructor4__')`. * * @param _markdownView - The Markdown view the preview view was created with. */ constructor4__(_markdownView: MarkdownView): void; /** * Gets the previewed Markdown text. * * @returns The text last passed to {@link MarkdownPreviewView.set}, or an empty string. */ get(): string; /** * Gets the current scroll position. * * @returns The position last passed to {@link MarkdownPreviewView.applyScroll}, or `0`. */ getScroll(): number; /** * Re-renders the preview. A no-op in the mock, which renders nothing. * * @param _full - Whether to discard every rendered section and render from scratch. */ rerender(_full?: boolean): void; /** * Replaces the previewed Markdown text. * * @param data - The new text. * @param _clear - Whether to reset view state, as when a different file is loaded; ignored by the mock. */ set(data: string, _clear: boolean): void; }