/** * @file * * Shared type declarations for shapes Obsidian declares inline or only in `obsidian-typings`. */ import type { Events, SplitDirection, ViewState, ViewStateResult as ViewStateResultOriginal } from 'obsidian'; /** * Every file and folder path in an in-memory filesystem, as `InMemoryAdapter.listAll__` returns them. */ export interface AdapterListing { readonly files: string[]; readonly folders: string[]; } /** * The request options of Obsidian's global `ajax` and `ajaxPromise` helpers: URL, method, body, headers, * credentials mode, an optional existing request object, and the success and error callbacks. */ export interface AjaxOptions { readonly data?: ArrayBuffer | object | string; readonly error?: (error: unknown, request: XMLHttpRequest) => unknown; readonly headers?: Record; readonly method?: 'GET' | 'POST'; readonly req?: XMLHttpRequest; readonly success?: (response: unknown, request: XMLHttpRequest) => unknown; readonly url: string; readonly withCredentials?: boolean; } /** * A scroll position, as `Editor.getScrollInfo` returns it. */ export interface CoordsLeftTop { readonly left: number; readonly top: number; } /** * A delegated listener registration, as Obsidian keeps it in an element's or document's `_EVENTS` record: the * selector and listener it was registered with, its options, and the wrapper actually added with * `addEventListener`. */ export interface EventListenerInfo { readonly callback: EventListener; readonly listener: unknown; readonly options?: AddEventListenerOptions | boolean | undefined; readonly selector: string; } /** * A registered event handler as Obsidian stores it in `Events._`, and the shape of the `EventRef` returned for it: * the owning `Events`, the event name, the callback and its `this` context. */ export interface EventsEntry { readonly ctx: unknown; readonly e: Events; readonly fn: (...data: unknown[]) => unknown; readonly name: string; } /** * The per-file record `MetadataCache.fileCache` keeps: the content hash its metadata is stored under, and the * file's modification time and size when it was indexed. */ export interface FileCacheEntry { readonly hash: string; readonly mtime: number; readonly size: number; } /** * A return type that may be `T` or nothing, as `obsidian.d.ts` writes `T | void` for callbacks. * * @typeParam T - The type returned when something is returned. */ export type MaybeReturn = T | void; /** * The parts of a wikilink's link text, as `parseLinktext` returns them: the file path and the subpath, which is a * heading or block reference. */ export interface ParsedLinktext { readonly path: string; readonly subpath: string; } /** * A ribbon's saved state, as `WorkspaceRibbon.serialize` returns it: whether each ribbon item is hidden, keyed by * item id, in display order. */ export interface RibbonState { readonly hiddenItems: Record; } /** * A serialized workspace layout, the shape `Workspace.getLayout` returns and `Workspace.setLayout` reads: the * main, left, right and floating trees, the left ribbon, the id of the active leaf and, in `workspace.json`, the * recently opened files. Every key is optional, because `setLayout` accepts a partial layout and fills in the rest. */ export interface SerializedWorkspace { readonly 'active'?: string; readonly 'floating'?: SerializedWorkspaceItem; readonly 'lastOpenFiles'?: string[]; readonly 'left'?: SerializedWorkspaceItem; readonly 'left-ribbon'?: Partial; readonly 'main'?: SerializedWorkspaceItem; readonly 'right'?: SerializedWorkspaceItem; } /** * One serialized node of the workspace layout tree, as `WorkspaceItem.serialize` returns it. `id` and `type` are * always present; each subclass adds its own keys. */ export interface SerializedWorkspaceItem { children?: SerializedWorkspaceItem[]; readonly collapsed?: boolean; readonly currentTab?: number; readonly dimension?: number; readonly direction?: SplitDirection; readonly group?: string; readonly id: string; readonly pinned?: boolean; readonly stacked?: boolean; readonly state?: ViewState; readonly type: string; readonly width?: number; } /** * The options Obsidian's `createSvg` helpers accept: classes, attributes, a parent to insert into, and whether to * prepend there. */ export interface SvgElementInfo { readonly attr?: Record; readonly cls?: string | string[]; readonly parent?: Node; readonly prepend?: boolean; } /** * The whole of the result object Obsidian passes to `View.setState`, which the view fills in to tell the leaf what * the state change implies. * * `obsidian.d.ts` declares only `history`; Obsidian's own `setViewState` reads three more off the same object, so * they are inlined here per L3 rather than claimed as mock-only members. * * `obsidian-typings` declares all three as well, in the same shapes, but that does not retire this interface: L3 * keeps the package out of `src/`, which therefore type-checks against `obsidian.d.ts` alone. */ export interface ViewStateResultInternal extends ViewStateResultOriginal { /** * Set by a view that cannot show what it was given — a file view with no file — to make the leaf go back to its * empty view. */ close?: boolean; /** * A callback the leaf runs once the state change has settled. */ readonly done?: () => void; /** * Set by a view whose state change alters the layout, which makes the leaf ask the workspace to update it. */ layout?: boolean; } /** * The options of `Workspace.ensureSideLeaf`: whether to activate, split and reveal the leaf, and the view state to * set on it. */ export interface WorkspaceEnsureSideLeafOptions { readonly active?: boolean; readonly reveal?: boolean; readonly split?: boolean; readonly state?: unknown; } /** * The options of `Workspace.setActiveLeaf`: whether to focus the leaf. */ export interface WorkspaceSetActiveLeafOptions { readonly focus?: boolean; }