/** * @file * * Mock of Obsidian's `RenderContext`, the context Bases values are rendered in. */ import type { HoverPopover as HoverPopoverOriginal, RenderContext as RenderContextOriginal } from 'obsidian'; import type { App } from './App.mjs'; import type { TFile } from './TFile.mjs'; import type { Value } from './Value.mjs'; /** * Mock of Obsidian's `RenderContext`, which provides utilities for rendering Bases values and acts as the hover * parent for popovers they open. * * Its three render helpers and its `app` field are real Obsidian internals `obsidian.d.ts` omits and * `obsidian-typings` declares, so per L4 they carry their real names with no `__` suffix. Each builds the DOM * Obsidian builds; what each one leaves out, and why, is said at its own site. */ export declare class RenderContext { /** * The app the context renders against. Obsidian's `RenderContext` takes it in its constructor and keeps it, * and its three render helpers read the workspace, the metadata cache and the vault through it. */ app: App; /** * The hover popover currently attached to this context, or `null` when none is open. */ hoverPopover: HoverPopoverOriginal | null; /** * Creates a render context. Use {@link RenderContext.create__} from outside the class. * * @param app - The app instance. */ protected constructor(app: App); /** * Mock-only factory: creates a render context, spyable via `vi.spyOn(RenderContext, 'create__')`. * * @param app - The app instance. * @returns The new render context. */ static create__(app: App): RenderContext; /** * Mock-only: views a value typed as Obsidian's `RenderContext` as this mock. * * @param value - The value typed as the original `RenderContext`. * @returns The same object, typed as the mock. */ static fromOriginalType__(value: RenderContextOriginal): RenderContext; /** * Mock-only: views this mock as Obsidian's `RenderContext` type. * * @returns The same object, typed as the original `RenderContext`. */ asOriginalType__(): RenderContextOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(RenderContext.prototype, 'constructor__')`. * * @param _app - The app the context was created with. */ constructor__(_app: App): void; /** * Renders an external link into a container element, as Obsidian does: an `a.external-link` opening in a new * tab, showing the display value when there is one and the URL itself otherwise. * * Obsidian also wires a click that calls `window.open` and a context menu through * `Workspace.handleExternalLinkContextMenu`. Neither is modeled: that workspace member is unmocked, and * jsdom has no `window.open` to call, so a click here does nothing. * * @param url - The link URL. * @param display - The display value, or `null` to use the URL as text. * @param containerEl - The container element to render into. */ renderExternalLink(url: string, display: null | Value, containerEl: HTMLElement): void; /** * Renders an internal file link into a container element, as Obsidian does: a `span.internal-link` inside a * `markdown-rendered` container, carrying the link text as `data-href` and marked `is-unresolved` when the * link resolves to nothing. A left or middle click opens the link through `Workspace.openLinkText`, and a * middle click's default is suppressed first, as Obsidian suppresses it. * * The display value is rendered into the link UNLESS it is an embed size such as `200` or `200x100` on a * link to an image, which is Obsidian's own guard: such a display is a size, not a label, so the link falls * back to showing the target. * * Obsidian also wires a context menu, `app.dragManager.handleDrag` and a `hover-link` trigger. None is * modeled: `App.dragManager` is unmocked, and the menu needs the app's own translated delete label. * * @param file - The target file, or a link path to resolve. * @param display - The display value, or `null` to use the file name as text. * @param containerEl - The container element to render into. */ renderFileLink(file: string | TFile, display: null | Value, containerEl: HTMLElement): void; /** * Renders a tag link into a container element, as Obsidian does: an `a.tag` whose text is the tag without * its leading `#`. * * Obsidian also wires a click that opens the global search for the tag. That is not modeled, because it * reads `App.internalPlugins`, which this mock deliberately leaves unmocked - a vault reporting no core * plugins would be a lie rather than an empty vault. * * @param tag - The tag, including its leading `#`. * @param containerEl - The container element to render into. */ renderTag(tag: string, containerEl: HTMLElement): void; }