UNPKG

obsidian

Version:

Type definitions for the latest Obsidian API (https://obsidian.md)

1,721 lines (1,609 loc) 134 kB
/** * This file is automatically generated. * Please do not modify or send pull requests for it. */ import { Extension, StateField } from '@codemirror/state'; import { EditorView, ViewPlugin } from '@codemirror/view'; import * as CodeMirror from 'codemirror'; import * as Moment from 'moment'; declare global { interface ObjectConstructor { isEmpty(object: Record<string, any>): boolean; each<T>(object: { [key: string]: T; }, callback: (value: T, key?: string) => boolean | void, context?: any): boolean; } interface ArrayConstructor { combine<T>(arrays: T[][]): T[]; } interface Array<T> { first(): T | undefined; last(): T | undefined; contains(target: T): boolean; remove(target: T): void; shuffle(): this; unique(): T[]; findLastIndex(predicate: (value: T) => boolean): number; } interface Math { clamp(value: number, min: number, max: number): number; square(value: number): number; } interface StringConstructor { isString(obj: any): obj is string; } interface String { contains(target: string): boolean; startsWith(searchString: string, position?: number): boolean; endsWith(target: string, length?: number): boolean; format(...args: string[]): string; } interface NumberConstructor { isNumber(obj: any): obj is number; } interface Node { detach(): void; empty(): void; insertAfter<T extends Node>(node: T, child: Node | null): T; indexOf(other: Node): number; setChildrenInPlace(children: Node[]): void; appendText(val: string): void; /** * Cross-window capable instanceof check, a drop-in replacement * for instanceof checks on DOM Nodes. Remember to also check * for nulls when necessary. * @param type */ instanceOf<T>(type: { new (): T; }): this is T; /** * The document this node belongs to, or the global document. */ doc: Document; /** * The window object this node belongs to, or the global window. */ win: Window; constructorWin: Window; } interface Element extends Node { getText(): string; setText(val: string | DocumentFragment): void; addClass(...classes: string[]): void; addClasses(classes: string[]): void; removeClass(...classes: string[]): void; removeClasses(classes: string[]): void; toggleClass(classes: string | string[], value: boolean): void; hasClass(cls: string): boolean; setAttr(qualifiedName: string, value: string | number | boolean | null): void; setAttrs(obj: { [key: string]: string | number | boolean | null; }): void; getAttr(qualifiedName: string): string | null; matchParent(selector: string, lastParent?: Element): Element | null; getCssPropertyValue(property: string, pseudoElement?: string): string; isActiveElement(): boolean; } interface HTMLElement extends Element { show(): void; hide(): void; toggle(show: boolean): void; toggleVisibility(visible: boolean): void; /** * Returns whether this element is shown, when the element is attached to the DOM and * none of the parent and ancestor elements are hidden with `display: none`. * * Exception: Does not work on `<body>` and `<html>`, or on elements with `position: fixed`. */ isShown(): boolean; setCssStyles(styles: Partial<CSSStyleDeclaration>): void; setCssProps(props: Record<string, string>): void; /** * Get the inner width of this element without padding. */ readonly innerWidth: number; /** * Get the inner height of this element without padding. */ readonly innerHeight: number; } interface SVGElement extends Element { setCssStyles(styles: Partial<CSSStyleDeclaration>): void; setCssProps(props: Record<string, string>): void; } function isBoolean(obj: any): obj is boolean; function fish(selector: string): HTMLElement | null; function fishAll(selector: string): HTMLElement[]; interface Element extends Node { find(selector: string): Element | null; findAll(selector: string): HTMLElement[]; findAllSelf(selector: string): HTMLElement[]; } interface HTMLElement extends Element { find(selector: string): HTMLElement; findAll(selector: string): HTMLElement[]; findAllSelf(selector: string): HTMLElement[]; } interface DocumentFragment extends Node, NonElementParentNode, ParentNode { find(selector: string): HTMLElement; findAll(selector: string): HTMLElement[]; } interface DomElementInfo { /** * The class to be assigned. Can be a space-separated string or an array of strings. */ cls?: string | string[]; /** * The textContent to be assigned. */ text?: string | DocumentFragment; /** * HTML attributes to be added. */ attr?: { [key: string]: string | number | boolean | null; }; /** * HTML title (for hover tooltip). */ title?: string; /** * The parent element to be assigned to. */ parent?: Node; value?: string; type?: string; prepend?: boolean; placeholder?: string; href?: string; } interface SvgElementInfo { /** * The class to be assigned. Can be a space-separated string or an array of strings. */ cls?: string | string[]; /** * HTML attributes to be added. */ attr?: { [key: string]: string | number | boolean | null; }; /** * The parent element to be assigned to. */ parent?: Node; prepend?: boolean; } interface Node { /** * Create an element and append it to this node. */ createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K]; createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement; createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement; createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K]; } function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, o?: DomElementInfo | string, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K]; function createDiv(o?: DomElementInfo | string, callback?: (el: HTMLDivElement) => void): HTMLDivElement; function createSpan(o?: DomElementInfo | string, callback?: (el: HTMLSpanElement) => void): HTMLSpanElement; function createSvg<K extends keyof SVGElementTagNameMap>(tag: K, o?: SvgElementInfo | string, callback?: (el: SVGElementTagNameMap[K]) => void): SVGElementTagNameMap[K]; function createFragment(callback?: (el: DocumentFragment) => void): DocumentFragment; interface EventListenerInfo { selector: string; listener: Function; options?: boolean | AddEventListenerOptions; callback: Function; } interface HTMLElement extends Element { _EVENTS?: { [K in keyof HTMLElementEventMap]?: EventListenerInfo[]; }; on<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; off<K extends keyof HTMLElementEventMap>(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; onClickEvent(this: HTMLElement, listener: (this: HTMLElement, ev: MouseEvent) => any, options?: boolean | AddEventListenerOptions): void; /** * @param listener - the callback to call when this node is inserted into the DOM. * @param once - if true, this will only fire once and then unhook itself. * @returns destroy - a function to remove the event handler to avoid memory leaks. */ onNodeInserted(this: HTMLElement, listener: () => any, once?: boolean): () => void; /** * @param listener - the callback to call when this node has been migrated to another window. * @returns destroy - a function to remove the event handler to avoid memory leaks. */ onWindowMigrated(this: HTMLElement, listener: (win: Window) => any): () => void; trigger(eventType: string): void; } interface Document { _EVENTS?: { [K in keyof DocumentEventMap]?: EventListenerInfo[]; }; on<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; off<K extends keyof DocumentEventMap>(this: Document, type: K, selector: string, listener: (this: Document, ev: DocumentEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; } interface UIEvent extends Event { targetNode: Node | null; win: Window; doc: Document; /** * Cross-window capable instanceof check, a drop-in replacement * for instanceof checks on UIEvents. * @param type */ instanceOf<T>(type: { new (...data: any[]): T; }): this is T; } interface AjaxOptions { method?: 'GET' | 'POST'; url: string; success?: (response: any, req: XMLHttpRequest) => any; error?: (error: any, req: XMLHttpRequest) => any; data?: object | string | ArrayBuffer; headers?: Record<string, string>; withCredentials?: boolean; req?: XMLHttpRequest; } function ajax(options: AjaxOptions): void; function ajaxPromise(options: AjaxOptions): Promise<any>; function ready(fn: () => any): void; function sleep(ms: number): Promise<void>; function nextFrame(): Promise<void>; /** * The actively focused Window object. This is usually the same as `window` but * it will be different when using popout windows. */ let activeWindow: Window; /** * The actively focused Document object. This is usually the same as `document` but * it will be different when using popout windows. */ let activeDocument: Document; interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage { /** * The actively focused Window object. This is usually the same as `window` but * it will be different when using popout windows. */ activeWindow: Window; /** * The actively focused Document object. This is usually the same as `document` but * it will be different when using popout windows. */ activeDocument: Document; sleep(ms: number): Promise<void>; nextFrame(): Promise<void>; } interface Touch { touchType: 'stylus' | 'direct'; } } /** * Attach to an `<input>` element or a `<div contentEditable>` to add type-ahead * support. * * @public */ export abstract class AbstractInputSuggest<T> extends PopoverSuggest<T> { /** * Limit to the number of elements rendered at once. Set to 0 to disable. Defaults to 100. * @public */ limit: number; /** * Accepts an `<input>` text box or a contenteditable div. * @public */ constructor(app: App, textInputEl: HTMLInputElement | HTMLDivElement); /** * Sets the value into the input element. * @public */ setValue(value: string): void; /** * Gets the value from the input element. * @public */ getValue(): string; /** @public */ protected abstract getSuggestions(query: string): T[] | Promise<T[]>; /** @public */ selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void; /** * Registers a callback to handle when a suggestion is selected by the user. * @public */ onSelect(callback: (value: T, evt: MouseEvent | KeyboardEvent) => any): this; } /** * @public */ export class AbstractTextComponent<T extends HTMLInputElement | HTMLTextAreaElement> extends ValueComponent<string> { /** * @public */ inputEl: T; /** * @public */ constructor(inputEl: T); /** * @public */ setDisabled(disabled: boolean): this; /** * @public */ getValue(): string; /** * @public */ setValue(value: string): this; /** * @public */ setPlaceholder(placeholder: string): this; /** * @public */ onChanged(): void; /** * @public */ onChange(callback: (value: string) => any): this; } /** * Adds an icon to the library. * @param iconId - the icon ID * @param svgContent - the content of the SVG. * @public */ export function addIcon(iconId: string, svgContent: string): void; /** * This is the API version of the app, which follows the release cycle of the desktop app. * Example: '0.13.21' * @public */ export let apiVersion: string; /** * @public */ export class App { /** @public */ keymap: Keymap; /** @public */ scope: Scope; /** @public */ workspace: Workspace; /** @public */ vault: Vault; /** @public */ metadataCache: MetadataCache; /** @public */ fileManager: FileManager; /** * The last known user interaction event, to help commands find out what modifier keys are pressed. * @public */ lastEvent: UserEvent | null; /** * Retrieve value from `localStorage` for this vault. * @param key * @public */ loadLocalStorage(key: string): any | null; /** * Save vault-specific value to `localStorage`. If data is `null`, the entry will be cleared. * @param key * @param data value being saved to localStorage. Must be serializable. * @public */ saveLocalStorage(key: string, data: unknown | null): void; } /** @public */ export function arrayBufferToBase64(buffer: ArrayBuffer): string; /** @public */ export function arrayBufferToHex(data: ArrayBuffer): string; /** @public */ export function base64ToArrayBuffer(base64: string): ArrayBuffer; /** * @public */ export abstract class BaseComponent { /** @public */ disabled: boolean; /** * Facilitates chaining * @public */ then(cb: (component: this) => any): this; /** * @public */ setDisabled(disabled: boolean): this; } /** * @public */ export interface BlockCache extends CacheItem { /** @public */ id: string; } /** * @public */ export interface BlockSubpathResult extends SubpathResult { /** * @public */ type: 'block'; /** * @public */ block: BlockCache; /** * @public */ list?: ListItemCache; } /** * @public */ export class ButtonComponent extends BaseComponent { /** * @public */ buttonEl: HTMLButtonElement; /** * @public */ constructor(containerEl: HTMLElement); /** * @public */ setDisabled(disabled: boolean): this; /** * @public */ setCta(): this; /** * @public */ removeCta(): this; /** * @public */ setWarning(): this; /** * @public */ setTooltip(tooltip: string, options?: TooltipOptions): this; /** * @public */ setButtonText(name: string): this; /** * @public */ setIcon(icon: IconName): this; /** * @public */ setClass(cls: string): this; /** * @public */ onClick(callback: (evt: MouseEvent) => any): this; } /** * @public */ export interface CachedMetadata { /** * @public */ links?: LinkCache[]; /** * @public */ embeds?: EmbedCache[]; /** * @public */ tags?: TagCache[]; /** * @public */ headings?: HeadingCache[]; /** * @public */ footnotes?: FootnoteCache[]; /** * @public */ footnoteRefs?: FootnoteRefCache[]; /** * @public */ referenceLinks?: ReferenceLinkCache[]; /** * Sections are root level markdown blocks, which can be used to divide the document up. * @public */ sections?: SectionCache[]; /** * @public */ listItems?: ListItemCache[]; /** * @public */ frontmatter?: FrontMatterCache; /** * Position of the frontmatter in the file. * @public */ frontmatterPosition?: Pos; /** * @public */ frontmatterLinks?: FrontmatterLinkCache[]; /** * @public */ blocks?: Record<string, BlockCache>; } /** * @public */ export interface CacheItem { /** * Position of this item in the note. * @public */ position: Pos; } /** * Implementation of the vault adapter for mobile devices. * @public */ export class CapacitorAdapter implements DataAdapter { /** * @public */ getName(): string; /** * @public */ mkdir(normalizedPath: string): Promise<void>; /** * @public */ trashSystem(normalizedPath: string): Promise<boolean>; /** * @public */ trashLocal(normalizedPath: string): Promise<void>; /** * @public */ rmdir(normalizedPath: string, recursive: boolean): Promise<void>; /** * @public */ read(normalizedPath: string): Promise<string>; /** * @public */ readBinary(normalizedPath: string): Promise<ArrayBuffer>; /** * @public */ write(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * @public */ writeBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptions): Promise<void>; /** * @public */ append(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * @public */ process(normalizedPath: string, fn: (data: string) => string, options?: DataWriteOptions): Promise<string>; /** * @public */ getResourcePath(normalizedPath: string): string; /** * @public */ remove(normalizedPath: string): Promise<void>; /** * @public */ rename(normalizedPath: string, normalizedNewPath: string): Promise<void>; /** * @public */ copy(normalizedPath: string, normalizedNewPath: string): Promise<void>; /** * @public */ exists(normalizedPath: string, sensitive?: boolean): Promise<boolean>; /** * @public */ stat(normalizedPath: string): Promise<Stat | null>; /** * @public */ list(normalizedPath: string): Promise<ListedFiles>; /** * @public */ getFullPath(normalizedPath: string): string; } /** * A closeable component that can get dismissed via the Android 'back' button. * @public */ export interface CloseableComponent { /** @public */ close(): void; } /** * Color picker component. Values are by default 6-digit hash-prefixed hex strings like `#000000`. * @public */ export class ColorComponent extends ValueComponent<string> { /** * @public */ constructor(containerEl: HTMLElement); /** * @public */ setDisabled(disabled: boolean): this; /** * @public */ getValue(): HexString; /** * @public */ getValueRgb(): RGB; /** * @public */ getValueHsl(): HSL; /** * @public */ setValue(value: HexString): this; /** * @public */ setValueRgb(rgb: RGB): this; /** * @public */ setValueHsl(hsl: HSL): this; /** * @public */ onChange(callback: (value: string) => any): this; } /** * @public */ export interface Command { /** * Globally unique ID to identify this command. * @public */ id: string; /** * Human friendly name for searching. * @public */ name: string; /** * Icon ID to be used in the toolbar. * See {@link https://docs.obsidian.md/Plugins/User+interface/Icons} for available icons and how to add your own. * @public */ icon?: IconName; /** @public */ mobileOnly?: boolean; /** * Whether holding the hotkey should repeatedly trigger this command. * @defaultValue false * @public */ repeatable?: boolean; /** * Simple callback, triggered globally. * @example * ```ts * this.addCommand({ * id: 'print-greeting-to-console', * name: 'Print greeting to console', * callback: () => { * console.log('Hey, you!'); * }, * }); * ``` * @public */ callback?: () => any; /** * Complex callback, overrides the simple callback. * Used to 'check' whether your command can be performed in the current circumstances. * For example, if your command requires the active focused pane to be a MarkdownView, then * you should only return true if the condition is satisfied. Returning false or undefined causes * the command to be hidden from the command palette. * * @param checking - Whether the command palette is just 'checking' if your command should show right now. * If checking is true, then this function should not perform any action. * If checking is false, then this function should perform the action. * @returns Whether this command can be executed at the moment. * * @example * ```ts * this.addCommand({ * id: 'example-command', * name: 'Example command', * checkCallback: (checking: boolean) => { * const value = getRequiredValue(); * * if (value) { * if (!checking) { * doCommand(value); * } * return true; * } * * return false; * } * }); * ``` * * @public */ checkCallback?: (checking: boolean) => boolean | void; /** * A command callback that is only triggered when the user is in an editor. * Overrides `callback` and `checkCallback` * @example * ```ts * this.addCommand({ * id: 'example-command', * name: 'Example command', * editorCallback: (editor: Editor, view: MarkdownView) => { * const sel = editor.getSelection(); * * console.log(`You have selected: ${sel}`); * } * }); * ``` * @public */ editorCallback?: (editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => any; /** * A command callback that is only triggered when the user is in an editor. * Overrides `editorCallback`, `callback` and `checkCallback` * @example * ```ts * this.addCommand({ * id: 'example-command', * name: 'Example command', * editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => { * const value = getRequiredValue(); * * if (value) { * if (!checking) { * doCommand(value); * } * * return true; * } * * return false; * } * }); * ``` * @public */ editorCheckCallback?: (checking: boolean, editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => boolean | void; /** * Sets the default hotkey. It is recommended for plugins to avoid setting default hotkeys if possible, * to avoid conflicting hotkeys with one that's set by the user, even though customized hotkeys have higher priority. * @public */ hotkeys?: Hotkey[]; } /** * @public */ export class Component { /** * Load this component and its children * @public */ load(): void; /** * Override this to load your component * @public * @virtual */ onload(): void; /** * Unload this component and its children * @public */ unload(): void; /** * Override this to unload your component * @public * @virtual */ onunload(): void; /** * Adds a child component, loading it if this component is loaded * @public */ addChild<T extends Component>(component: T): T; /** * Removes a child component, unloading it * @public */ removeChild<T extends Component>(component: T): T; /** * Registers a callback to be called when unloading * @public */ register(cb: () => any): void; /** * Registers an event to be detached when unloading * @public */ registerEvent(eventRef: EventRef): void; /** * Registers an DOM event to be detached when unloading * @public */ registerDomEvent<K extends keyof WindowEventMap>(el: Window, type: K, callback: (this: HTMLElement, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; /** * Registers an DOM event to be detached when unloading * @public */ registerDomEvent<K extends keyof DocumentEventMap>(el: Document, type: K, callback: (this: HTMLElement, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; /** * Registers an DOM event to be detached when unloading * @public */ registerDomEvent<K extends keyof HTMLElementEventMap>(el: HTMLElement, type: K, callback: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; /** * Registers an interval (from setInterval) to be cancelled when unloading * Use {@link window.setInterval} instead of {@link setInterval} to avoid TypeScript confusing between NodeJS vs Browser API * @public */ registerInterval(id: number): number; } /** @public */ export type Constructor<T> = abstract new (...args: any[]) => T; /** * Work directly with files and folders inside a vault. * If possible prefer using the {@link Vault} API over this. * @public */ export interface DataAdapter { /** * @public */ getName(): string; /** * Check if something exists at the given path. For a faster way to synchronously check * if a note or attachment is in the vault, use {@link Vault.getAbstractFileByPath}. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @param sensitive - Some file systems/operating systems are case-insensitive, set to true to force a case-sensitivity check. * @public */ exists(normalizedPath: string, sensitive?: boolean): Promise<boolean>; /** * Retrieve metadata about the given file/folder. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @public */ stat(normalizedPath: string): Promise<Stat | null>; /** * Retrieve a list of all files and folders inside the given folder, non-recursive. * @param normalizedPath - path to folder, use {@link normalizePath} to normalize beforehand. * @public */ list(normalizedPath: string): Promise<ListedFiles>; /** * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @public */ read(normalizedPath: string): Promise<string>; /** * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @public */ readBinary(normalizedPath: string): Promise<ArrayBuffer>; /** * Write to a plaintext file. * If the file exists its content will be overwritten, otherwise the file will be created. * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @param data - new file content * @param options - (Optional) * @public */ write(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * Write to a binary file. * If the file exists its content will be overwritten, otherwise the file will be created. * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @param data - the new file content * @param options - (Optional) * @public */ writeBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptions): Promise<void>; /** * Add text to the end of a plaintext file. * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @param data - the text to append. * @param options - (Optional) * @public */ append(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * Atomically read, modify, and save the contents of a plaintext file. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @param fn - a callback function which returns the new content of the file synchronously. * @param options - write options. * @returns string - the text value of the file that was written. * @public */ process(normalizedPath: string, fn: (data: string) => string, options?: DataWriteOptions): Promise<string>; /** * Returns an URI for the browser engine to use, for example to embed an image. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @public */ getResourcePath(normalizedPath: string): string; /** * Create a directory. * @param normalizedPath - path to use for new folder, use {@link normalizePath} to normalize beforehand. * @public */ mkdir(normalizedPath: string): Promise<void>; /** * Try moving to system trash. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @returns Returns true if succeeded. This can fail due to system trash being disabled. * @public */ trashSystem(normalizedPath: string): Promise<boolean>; /** * Move to local trash. * Files will be moved into the `.trash` folder at the root of the vault. * @param normalizedPath - path to file/folder, use {@link normalizePath} to normalize beforehand. * @public */ trashLocal(normalizedPath: string): Promise<void>; /** * Remove a directory. * @param normalizedPath - path to folder, use {@link normalizePath} to normalize beforehand. * @param recursive - If `true`, delete folders under this folder recursively, if `false` the folder needs to be empty. * @public */ rmdir(normalizedPath: string, recursive: boolean): Promise<void>; /** * Delete a file. * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @public */ remove(normalizedPath: string): Promise<void>; /** * Rename a file or folder. * @param normalizedPath - current path to file/folder, use {@link normalizePath} to normalize beforehand. * @param normalizedNewPath - new path to file/folder, use {@link normalizePath} to normalize beforehand. * @public */ rename(normalizedPath: string, normalizedNewPath: string): Promise<void>; /** * Create a copy of a file. * This will fail if there is already a file at `normalizedNewPath`. * @param normalizedPath - path to file, use {@link normalizePath} to normalize beforehand. * @param normalizedNewPath - path to file, use {@link normalizePath} to normalize beforehand. * @public */ copy(normalizedPath: string, normalizedNewPath: string): Promise<void>; } /** * @public */ export interface DataWriteOptions { /** * Time of creation, represented as a unix timestamp, in milliseconds. * Omit this if you want to keep the default behaviour. * @public * */ ctime?: number; /** * Time of last modification, represented as a unix timestamp, in milliseconds. * Omit this if you want to keep the default behaviour. * @public */ mtime?: number; } /** * A standard debounce function. * Use this to have a time-delayed function only be called once in a given timeframe. * * @param cb - The function to call. * @param timeout - The timeout to wait, in milliseconds * @param resetTimer - Whether to reset the timeout when the debouncer is called again. * @returns a debounced function that takes the same parameter as the original function. * @example * ```ts * const debounced = debounce((text: string) => { * console.log(text); * }, 1000, true); * debounced('Hello world'); // this will not be printed * await sleep(500); * debounced('World, hello'); // this will be printed to the console. * ``` * @public */ export function debounce<T extends unknown[], V>(cb: (...args: [...T]) => V, timeout?: number, resetTimer?: boolean): Debouncer<T, V>; /** @public */ export interface Debouncer<T extends unknown[], V> { /** @public */ (...args: [...T]): this; /** * Cancel any pending debounced function call. * @public */ cancel(): this; /** * If there is any pending function call, clear the timer and call the function immediately. * @public */ run(): V | void; } /** * Manually trigger a tooltip that will appear over the provided element. * * To display a tooltip on hover, use {@link setTooltip} instead. * @public */ export function displayTooltip(newTargetEl: HTMLElement, content: string | DocumentFragment, options?: TooltipOptions): void; /** * @public */ export class DropdownComponent extends ValueComponent<string> { /** * @public */ selectEl: HTMLSelectElement; /** * @public */ constructor(containerEl: HTMLElement); /** * @public */ setDisabled(disabled: boolean): this; /** * @public */ addOption(value: string, display: string): this; /** * @public */ addOptions(options: Record<string, string>): this; /** * @public */ getValue(): string; /** * @public */ setValue(value: string): this; /** * @public */ onChange(callback: (value: string) => any): this; } /** * @public */ export abstract class EditableFileView extends FileView { } /** * A common interface that bridges the gap between CodeMirror 5 and CodeMirror 6. * @public */ export abstract class Editor { /** @public */ getDoc(): this; /** @public */ abstract refresh(): void; /** @public */ abstract getValue(): string; /** @public */ abstract setValue(content: string): void; /** * Get the text at line (0-indexed) * @public */ abstract getLine(line: number): string; /** @public */ setLine(n: number, text: string): void; /** * Gets the number of lines in the document * @public */ abstract lineCount(): number; /** @public */ abstract lastLine(): number; /** @public */ abstract getSelection(): string; /** @public */ somethingSelected(): boolean; /** @public */ abstract getRange(from: EditorPosition, to: EditorPosition): string; /** @public */ abstract replaceSelection(replacement: string, origin?: string): void; /** @public */ abstract replaceRange(replacement: string, from: EditorPosition, to?: EditorPosition, origin?: string): void; /** @public */ abstract getCursor(string?: 'from' | 'to' | 'head' | 'anchor'): EditorPosition; /** @public */ abstract listSelections(): EditorSelection[]; /** @public */ setCursor(pos: EditorPosition | number, ch?: number): void; /** @public */ abstract setSelection(anchor: EditorPosition, head?: EditorPosition): void; /** @public */ abstract setSelections(ranges: EditorSelectionOrCaret[], main?: number): void; /** @public */ abstract focus(): void; /** @public */ abstract blur(): void; /** @public */ abstract hasFocus(): boolean; /** @public */ abstract getScrollInfo(): { /** @public */ top: number; /** @public */ left: number; }; /** @public */ abstract scrollTo(x?: number | null, y?: number | null): void; /** @public */ abstract scrollIntoView(range: EditorRange, center?: boolean): void; /** @public */ abstract undo(): void; /** @public */ abstract redo(): void; /** @public */ abstract exec(command: EditorCommandName): void; /** @public */ abstract transaction(tx: EditorTransaction, origin?: string): void; /** @public */ abstract wordAt(pos: EditorPosition): EditorRange | null; /** @public */ abstract posToOffset(pos: EditorPosition): number; /** @public */ abstract offsetToPos(offset: number): EditorPosition; /** @public */ processLines<T>(read: (line: number, lineText: string) => T | null, write: (line: number, lineText: string, value: T | null) => EditorChange | void, ignoreEmpty?: boolean): void; } /** @public */ export interface EditorChange extends EditorRangeOrCaret { /** @public */ text: string; } /** @public */ export type EditorCommandName = 'goUp' | 'goDown' | 'goLeft' | 'goRight' | 'goStart' | 'goEnd' | 'goWordLeft' | 'goWordRight' | 'indentMore' | 'indentLess' | 'newlineAndIndent' | 'swapLineUp' | 'swapLineDown' | 'deleteLine' | 'toggleFold' | 'foldAll' | 'unfoldAll'; /** * Use this StateField to get a reference to the EditorView * @public */ export const editorEditorField: StateField<EditorView>; /** * Use this StateField to get information about this Markdown editor, such as the associated file, or the Editor. * @public */ export const editorInfoField: StateField<MarkdownFileInfo>; /** * Use this StateField to check whether Live Preview is active * @public */ export const editorLivePreviewField: StateField<boolean>; /** @public */ export interface EditorPosition { /** @public */ line: number; /** @public */ ch: number; } /** @public */ export interface EditorRange { /** @public */ from: EditorPosition; /** @public */ to: EditorPosition; } /** @public */ export interface EditorRangeOrCaret { /** @public */ from: EditorPosition; /** @public */ to?: EditorPosition; } /** @public */ export interface EditorScrollInfo { /** @public */ left: number; /** @public */ top: number; /** @public */ width: number; /** @public */ height: number; /** @public */ clientWidth: number; /** @public */ clientHeight: number; } /** @public */ export interface EditorSelection { /** @public */ anchor: EditorPosition; /** @public */ head: EditorPosition; } /** @public */ export interface EditorSelectionOrCaret { /** @public */ anchor: EditorPosition; /** @public */ head?: EditorPosition; } /** @public */ export abstract class EditorSuggest<T> extends PopoverSuggest<T> { /** * Current suggestion context, containing the result of `onTrigger`. * This will be null any time the EditorSuggest is not supposed to run. * @public */ context: EditorSuggestContext | null; /** * Override this to use a different limit for suggestion items * @public */ limit: number; /** @public */ constructor(app: App); /** * @public */ setInstructions(instructions: Instruction[]): void; /** * Based on the editor line and cursor position, determine if this EditorSuggest should be triggered at this moment. * Typically, you would run a regular expression on the current line text before the cursor. * Return null to indicate that this editor suggest is not supposed to be triggered. * * Please be mindful of performance when implementing this function, as it will be triggered very often (on each keypress). * Keep it simple, and return null as early as possible if you determine that it is not the right time. * @public */ abstract onTrigger(cursor: EditorPosition, editor: Editor, file: TFile | null): EditorSuggestTriggerInfo | null; /** * Generate suggestion items based on this context. Can be async, but preferably sync. * When generating async suggestions, you should pass the context along. * @public */ abstract getSuggestions(context: EditorSuggestContext): T[] | Promise<T[]>; } /** @public */ export interface EditorSuggestContext extends EditorSuggestTriggerInfo { /** @public */ editor: Editor; /** @public */ file: TFile; } /** @public */ export interface EditorSuggestTriggerInfo { /** * The start position of the triggering text. This is used to position the popover. * @public */ start: EditorPosition; /** * The end position of the triggering text. This is used to position the popover. * @public */ end: EditorPosition; /** * They query string (usually the text between start and end) that will be used to generate the suggestion content. * @public */ query: string; } /** @public */ export interface EditorTransaction { /** @public */ replaceSelection?: string; /** @public */ changes?: EditorChange[]; /** * Multiple selections, overrides `selection`. * @public */ selections?: EditorRangeOrCaret[]; /** @public */ selection?: EditorRangeOrCaret; } /** * This is now deprecated - it is now mapped directly to `editorInfoField`, which return a MarkdownFileInfo, which may be a MarkdownView but not necessarily. * @public * @deprecated use {@link editorInfoField} instead. */ export const editorViewField: StateField<MarkdownFileInfo>; /** * @public */ export interface EmbedCache extends ReferenceCache { } /** * @public */ export interface EventRef { } /** * @public */ export class Events { /** * @public */ on(name: string, callback: (...data: unknown[]) => unknown, ctx?: any): EventRef; /** * @public */ off(name: string, callback: (...data: unknown[]) => unknown): void; /** * @public */ offref(ref: EventRef): void; /** * @public */ trigger(name: string, ...data: unknown[]): void; /** * @public */ tryTrigger(evt: EventRef, args: unknown[]): void; } /** * @public */ export class ExtraButtonComponent extends BaseComponent { /** * @public */ extraSettingsEl: HTMLElement; /** * @public */ constructor(containerEl: HTMLElement); /** * @public */ setDisabled(disabled: boolean): this; /** * @public */ setTooltip(tooltip: string, options?: TooltipOptions): this; /** * @param icon - ID of the icon, can use any icon loaded with {@link addIcon} or from the inbuilt library. * @see The Obsidian icon library includes the {@link https://lucide.dev/ Lucide icon library}, any icon name from their site will work here. * @public */ setIcon(icon: IconName): this; /** * @public */ onClick(callback: () => any): this; } /** * Manage the creation, deletion and renaming of files from the UI. * @public */ export class FileManager { /** * Gets the folder that new files should be saved to, given the user's preferences. * @param sourcePath - The path to the current open/focused file, * used when the user wants new files to be created 'in the same folder'. * Use an empty string if there is no active file. * @param newFilePath - The path to the file that will be newly created, * used to infer what settings to use based on the path's extension. * @public */ getNewFileParent(sourcePath: string, newFilePath?: string): TFolder; /** * Rename or move a file safely, and update all links to it depending on the user's preferences. * @param file - the file to rename * @param newPath - the new path for the file * @public */ renameFile(file: TAbstractFile, newPath: string): Promise<void>; /** * Remove a file or a folder from the vault according the user's preferred 'trash' * options (either moving the file to .trash/ or the OS trash bin). * @param file * @public */ trashFile(file: TAbstractFile): Promise<void>; /** * Generate a Markdown link based on the user's preferences. * @param file - the file to link to. * @param sourcePath - where the link is stored in, used to compute relative links. * @param subpath - A subpath, starting with `#`, used for linking to headings or blocks. * @param alias - The display text if it's to be different than the file name. Pass empty string to use file name. * @public */ generateMarkdownLink(file: TFile, sourcePath: string, subpath?: string, alias?: string): string; /** * Atomically read, modify, and save the frontmatter of a note. * The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result. * * Remember to handle errors thrown by this method. * * @param file - the file to be modified. Must be a Markdown file. * @param fn - a callback function which mutates the frontmatter object synchronously. * @param options - write options. * @throws YAMLParseError if the YAML parsing fails * @throws any errors that your callback function throws * @example * ```ts * app.fileManager.processFrontMatter(file, (frontmatter) => { * frontmatter['key1'] = value; * delete frontmatter['key2']; * }); * ``` * @public */ processFrontMatter(file: TFile, fn: (frontmatter: any) => void, options?: DataWriteOptions): Promise<void>; /** * Resolves a unique path for the attachment file being saved. * Ensures that the parent directory exists and dedupes the * filename if the destination filename already exists. * * @param filename Name of the attachment being saved * @param sourcePath The path to the note associated with this attachment, defaults to the workspace's active file. * @returns Full path for where the attachment should be saved, according to the user's settings * @public */ getAvailablePathForAttachment(filename: string, sourcePath?: string): Promise<string>; } /** * @public */ export interface FileStats { /** * Time of creation, represented as a unix timestamp, in milliseconds. * @public */ ctime: number; /** * Time of last modification, represented as a unix timestamp, in milliseconds. * @public */ mtime: number; /** * Size on disk, as bytes. * @public */ size: number; } /** * Implementation of the vault adapter for desktop. * @public */ export class FileSystemAdapter implements DataAdapter { /** * @public */ getName(): string; /** * @public */ getBasePath(): string; /** * @public */ mkdir(normalizedPath: string): Promise<void>; /** * @public */ trashSystem(normalizedPath: string): Promise<boolean>; /** * @public */ trashLocal(normalizedPath: string): Promise<void>; /** * @public */ rmdir(normalizedPath: string, recursive: boolean): Promise<void>; /** * @public */ read(normalizedPath: string): Promise<string>; /** * @public */ readBinary(normalizedPath: string): Promise<ArrayBuffer>; /** * @public */ write(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * @public */ writeBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptions): Promise<void>; /** * @public */ append(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>; /** * @public */ process(normalizedPath: string, fn: (data: string) => string, options?: DataWriteOptions): Promise<string>; /** * @public */ getResourcePath(normalizedPath: string): string; /** * Returns the file:// path of this file * @public */ getFilePath(normalizedPath: string): string; /** * @public */ remove(normalizedPath: string): Promise<void>; /** * @public */ rename(normalizedPath: string, normalizedNewPath: string): Promise<void>; /** * @public */ copy(normalizedPath: string, normalizedNewPath: string): Promise<void>; /** * @public */ exists(normalizedPath: string, sensitive?: boolean): Promise<boolean>; /** * @public */ stat(normalizedPath: string): Promise<Stat | null>; /** * @public */ list(normalizedPath: string): Promise<ListedFiles>; /** * @public */ getFullPath(normalizedPath: string): strin