@polyipseity/obsidian
Version:
Type definitions for the latest Obsidian API (https://obsidian.md)
1,925 lines (1,760 loc) • 128 kB
TypeScript
/**
* 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 Moment from 'moment';
declare global {
interface HTMLElement {
/**
* @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;
}
interface Window {
/**
* The actively focused Window object. This is usually the same as `window` but
* it will be different when using popout windows.
*/
activeWindow: Window;
}
}
/**
* 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): string;
/**
* @public
*/
static readLocalFile(path: string): Promise<ArrayBuffer>;
/**
* @public
*/
static mkdir(path: string): Promise<void>;
}
/**
* @public
*/
export abstract class FileView extends ItemView {
/**
* @public
*/
allowNoFile: boolean;
/**
* @public
*/
file: TFile | null;
/**
* File views can be navigated by default.
* @inheritDoc
* @public
*/
navigation: boolean;
/**
* @public
*/
constructor(leaf: WorkspaceLeaf);
/**
* @public
*/
getDisplayText(): string;
/**
* @public
*/
onload(): void;
/**
* @public
*/
getState(): Record<string, unknown>;
/**
* @public
*/
setState(state: any, result: ViewStateResult): Promise<void>;
/**
* @public
*/
onLoadFile(file: TFile): Promise<void>;
/**
* @public
*/
onUnloadFile(file: TFile): Promise<void>;
/**
* @public
*/
onRename(file: TFile): Promise<void>;
/**
* @public
*/
canAcceptExtension(extension: string): boolean;
}
/**
* Flush the MathJax stylesheet.
* @public
*/
export function finishRenderMath(): Promise<void>;
/**
* @public
*/
export interface FootnoteCache extends CacheItem {
/**
* @public
*/
id: string;
}
/**
* @public
*/
export interface FootnoteRefCache extends CacheItem {
/**
* @public
*/
id: string;
}
/**
* @public
*/
export interface FootnoteSubpathResult extends SubpathResult {
/**
* @public
*/
type: 'footnote';
/**
* @public
*/
footnote: FootnoteCache;
}
/**
* @public
*/
export interface FrontMatterCache {
/**
* @public
*/
[key: string]: any;
}
/** @public */
export interface FrontMatterInfo {
/** @public Whether this file has a frontmatter block */
exists: boolean;
/** @public String representation of the frontmatter */
frontmatter: string;
/** @public Start of the frontmatter contents (excluding the ---) */
from: number;
/** @public End of the frontmatter contents (excluding the ---) */
to: number;
/** @public Offset where the frontmatter block ends (including the ---) */
contentStart: number;
}
/**
* @public
*/
export interface FrontmatterLinkCache extends Reference {
/**
* @public
*/
key: string;
}
/**
* @public
*/
export interface FuzzyMatch<T> {
/** @public */
item: T;
/** @public */
match: SearchResult;
}
/**
* @public
*/
export abstract class FuzzySuggestModal<T> extends SuggestModal<FuzzyMatch<T>> {
/**
* @public
*/
getSuggestions(query: string): FuzzyMatch<T>[];
/**
* @public
*/
renderSuggestion(item: FuzzyMatch<T>, el: HTMLElement): void;
/**
* @public
*/
onChooseSuggestion(item: FuzzyMatch<T>, evt: MouseEvent | KeyboardEvent): void;
/**
* @public
*/
abstract getItems(): T[];
/**
* @public
*/
abstract getItemText(item: T): string;
/**
* @public
*/
abstract onChooseItem(item: T, evt: MouseEvent | KeyboardEvent): void;
}
/**
* Combines all tags from frontmatter and note content into a single array.
* @public
*/
export function getAllTags(cache: CachedMetadata): string[] | null;
/** @public */
export function getBlobArrayBuffer(blob: Blob): Promise<ArrayBuffer>;
/**
* Given the contents of a file, get information about the frontmatter of the file, including
* whether there is a frontmatter block, the offsets of where it starts and ends, and the frontmatter text.
*
* @public
*/
export function getFrontMatterInfo(content: string): FrontMatterInfo;
/**
* Create an SVG from an iconId. Returns null if no icon associated with the iconId.
* @param iconId - the icon ID
* @public
*/
export function getIcon(iconId: string): SVGSVGElement | null;
/**
* Get the list of registered icons.
* @public
*/
export function getIconIds(): IconName[];
/**
* Get the ISO code for the currently configured app language. Defaults to 'en'.
* See {@link https://github.com/obsidianmd/obsidian-translations?tab=readme-ov-file#existing-languages} for list of options.
* @public
*/
export function getLanguage(): string;
/**
* Converts the linktext to a linkpath.
* @param linktext A wikilink without the leading [[ and trailing ]]
* @returns the name of the file that is being linked to.
* @public
*/
export function getLinkpath(linktext: string): string;
/**
* @public
*/
export interface HeadingCache extends CacheItem {
/**
* @public
*/
heading: string;
/**
* Number between 1 and 6.
* @public
*/
level: number;
}
/**
* @public
*/
export interface HeadingSubpathResult extends SubpathResult {
/**
* @public
*/
type: 'heading';
/**
* @public
*/
current: HeadingCache;
/**
* @public
*/
next: HeadingCache;
}
/**
* Hex strings are 6-digit hash-prefixed rgb strings in lowercase form.
* Example: #ffffff
* @public
*/
export type HexString = string;
/** @public */
export function hexToArrayBuffer(hex: string): ArrayBuffer;
/**
* @public
*/
export interface Hotkey {
/** @public */
modifiers: Modifier[];
/** @public */
key: string;
}
/**
* @public
*/
export interface HoverLinkSource {
/**
* Text displayed in the 'Page preview' plugin settings.
* It should match the plugin's display name.
* @public
*/
display: string;
/**
* Whether the `hover-link` event requires the 'Mod' key to be pressed to trigger.
* @public
*/
defaultMod: boolean;
}
/**
* @public
*/
export interface HoverParent {
/** @public */
hoverPopover: HoverPopover | null;
}
/**
* @public
*/
export class HoverPopover extends Component {
/**
* @public
*/
hoverEl: HTMLElement;
/**
* @public
*/
state: PopoverState;
/**
* @public
*/
constructor(parent: HoverParent, targetEl: HTMLElement | null, waitTime?: number, staticPos?: Point | null);
}
/**
* @public
*/
export interface HSL {
/**
* Hue integer value between 0 and 360
* @public
*/
h: number;
/**
* Saturation integer value between 0 and 100
* @public
*/
s: number;
/**
* Lightness integer value between 0 and 100
* @public
*/
l: number;
}
/**
* Converts HTML to a Markdown string.
* @public
*/
export function htmlToMarkdown(html: string | HTMLElement | Document | DocumentFragment): string;
/**
* @public
*/
export interface Instruction {
/** @public */
command: string;
/** @public */
purpose: string;
}
/**
* @public
*/
export interface ISuggestOwner<T> {
/**
* Render the suggestion item into DOM.
* @public
*/
renderSuggestion(value: T, el: HTMLElement): void;
/**
* Called when the user makes a selection.
* @public
*/
selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
}
/**
* @public
*/
export abstract class ItemView extends View {
/** @public */
contentEl: HTMLElement;
/**
* @public
*/
constructor(leaf: WorkspaceLeaf);
/**
* @public
*/
addAction(icon: IconName, title: string, callback: (evt: MouseEvent) => any): HTMLElement;
}
/**
* Iterate links and embeds.
* If callback returns true, the iteration process will be interrupted.
* @returns true if callback ever returns true, false otherwise.
* @public
* @deprecated
*/
export function iterateCacheRefs(cache: CachedMetadata, cb: (ref: ReferenceCache) => boolean | void): boolean;
/**
* If callback returns true, the iteration process will be interrupted.
* @returns true if callback ever returns true, false otherwise.
* @public
*/
export function iterateRefs(refs: Reference[], cb: (ref: Reference) => boolean | void): boolean;
/**
* Manages keymap lifecycle for different {@link Scope}s.
*
* @public
*/
export class Keymap {
/**
* Push a scope onto the scope stack, setting it as the active scope to handle all key events.
* @public
*/
pushScope(scope: Scope): void;
/**
* Remove a scope from the scope stack.
* If the given scope is active, the next scope in the stack will be made active.
* @public
*/
popScope(scope: Scope): void;
/**
* Checks whether the modifier key is pressed during this event.
* @public
*/
static isModifier(evt: MouseEvent | TouchEvent | KeyboardEvent, modifier: Modifier): boolean;
/**
* Translates an event into the type of pane that should open.
* Returns 'tab' if the modifier key Cmd/Ctrl is pressed OR if this is a middle-click MouseEvent.
* Returns 'split' if Cmd/Ctrl+Alt is pressed.
* Returns 'window' if Cmd/Ctrl+Alt+Shift is pressed.
* @public
* */
static isModEvent(evt?: UserEvent | null): PaneType | boolean;
}
/**
* @public
*/
export interface KeymapContext extends KeymapInfo {