obsidian
Version:
Type definitions for the latest Obsidian API (https://obsidian.md)
1,836 lines (1,728 loc) • 173 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 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[];
/**
*
* @since 1.4.4
*/
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
* @since 1.4.10
*/
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
* @since 1.4.10
*/
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
* @since 1.4.10
*/
setValue(value: string): void;
/**
* Gets the value from the input element.
* @public
* @since 1.4.10
*/
getValue(): string;
/**
* @public
* @since 1.5.7
*/
protected abstract getSuggestions(query: string): T[] | Promise<T[]>;
/**
* @public
* @since 1.6.6
*/
selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
/**
* Registers a callback to handle when a suggestion is selected by the user.
* @public
* @since 1.4.10
*/
onSelect(callback: (value: T, evt: MouseEvent | KeyboardEvent) => any): this;
}
/**
* @public
* @since 0.9.21
*/
export class AbstractTextComponent<T extends HTMLInputElement | HTMLTextAreaElement> extends ValueComponent<string> {
/**
* @public
* @since 0.9.7
*/
inputEl: T;
/**
* @public
*/
constructor(inputEl: T);
/**
* @public
* @since 1.2.3
*/
setDisabled(disabled: boolean): this;
/**
* @public
* @since 0.9.7
*/
getValue(): string;
/**
* @public
* @since 0.9.7
*/
setValue(value: string): this;
/**
* @public
* @since 0.9.7
*/
setPlaceholder(placeholder: string): this;
/**
* @public
* @since 0.9.21
*/
onChanged(): void;
/**
* @public
* @since 0.9.7
*/
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
* @since 0.9.7
*/
export class App {
/**
* @public
* @since 0.9.7
*/
keymap: Keymap;
/**
* @public
* @since 0.9.7
*/
scope: Scope;
/**
* @public
* @since 0.9.7
*/
workspace: Workspace;
/**
* @public
* @since 0.9.7
*/
vault: Vault;
/**
* @public
* @since 0.9.7
*/
metadataCache: MetadataCache;
/**
* @public
* @since 0.11.0
*/
fileManager: FileManager;
/**
* The last known user interaction event, to help commands find out what modifier keys are pressed.
* @public
* @since 0.12.17
*/
lastEvent: UserEvent | null;
/**
* @public
* @since 1.10.0
*/
renderContext: RenderContext;
/**
* @public
* @since 1.10.0
*/
isDarkMode(): boolean;
/**
* Retrieve value from `localStorage` for this vault.
* @param key
* @public
* @since 1.8.7
*/
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
* @since 1.8.7
*/
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
* @since 0.10.3
*/
export abstract class BaseComponent {
/**
* @public
* @since 0.10.3
*/
disabled: boolean;
/**
* Facilitates chaining
* @public
* @since 0.9.7
*/
then(cb: (component: this) => any): this;
/**
* @public
* @since 1.2.3
*/
setDisabled(disabled: boolean): this;
}
/**
* @public
* @since 1.10.0
*/
export interface BaseOption {
/**
* @public
* @since 1.10.0
*/
key: string;
/**
* @public
* @since 1.10.0
*/
type: string;
/**
* @public
* @since 1.10.0
*/
displayName: string;
/**
* If provided, the option will be hidden if the function returns true.
*
* @public
* @since 1.10.2
* @param config - Read-only copy of the current view configuration.
*/
shouldHide?: (config: BasesViewConfig) => boolean;
}
/**
* Represents the serialized format of a Bases query as stored in a `.base` file.
*
* @public
* @since 1.10.0
*/
export interface BasesConfigFile {
/**
* @public
* @since 1.10.0
*/
filters?: BasesConfigFileFilter;
/**
* Configuration for properties in this Base.
*
* Valid keys for this object currently include:
*
* - displayName: string
*
* @public
* @since 1.10.0
*/
properties?: Record<string, Record<string, any>>;
/**
* Configuration for formulas used in this Base.
*
* Key: Formula property name.
* Value: Formula string.
*
* @public
* @since 1.10.0
*/
formulas?: Record<string, string>;
/**
* Configuration for summary formulas used in this Base.
*
* Key: Summary formula name.
* Value: Formula string.
*
* @public
* @since 1.10.0
*/
summaries?: Record<string, string>;
/**
* Configuration for views used in this Base.
*
* @public
* @since 1.10.0
*/
views?: BasesConfigFileView[];
}
/**
* @public
* @since 1.10.0
*/
export type BasesConfigFileFilter = string | {
/**
* @public
* @since 1.10.0
*/
and: BasesConfigFileFilter[];
} | {
/**
* @public
* @since 1.10.0
*/
or: BasesConfigFileFilter[];
} | {
/**
* @public
* @since 1.10.0
*/
not: BasesConfigFileFilter[];
};
/**
* @public
* @since 1.10.0
*/
export interface BasesConfigFileView {
/**
* Unique identifier for the view type. Used to select the correct view renderer.
*
* @public
* @since 1.10.0
*/
type: string;
/**
* Friendly name for this view, displayed in the UI to select between views.
*
* @public
* @since 1.10.0
*/
name: string;
/**
* Additional filters, applied only to this view.
*
* @public
* @since 1.10.0
*/
filters?: BasesConfigFileFilter;
/**
* Configuration for grouping the results of this view.
*
* @public
* @since 1.10.0
*/
groupBy?: {
};
/**
* An ordered list of the properties to display in this view.
*
* @public
* @since 1.10.0
*/
order?: string[];
/**
* Configuration of summaries to display for each property in this view.
*
* Key: Property name.
* Value: Summary formula name.
*
* @public
* @since 1.10.0
*/
summaries?: Record<string, string>;
}
/**
* Represent a single "row" or file in a base.
* @public
* @since 1.10.0
*/
export class BasesEntry implements FormulaContext {
/**
* @public
* @since 1.10.0
*/
file: TFile;
/**
* Get the value of the property.
* Note: Errors are returned as {@link ErrorValue}
* @public
* @since 1.10.0
*/
getValue(propertyId: BasesPropertyId): Value | null;
}
/**
* A group of BasesEntry objects for a given value of the groupBy key.
* If there are entries in the results which do not have a value for the
* groupBy key, the key will be the {@link NullValue}.
* @public
* @since 1.10.0
*/
export class BasesEntryGroup {
/**
* The value of the groupBy key for this entry group.
* @public
* @since 1.10.0
*/
key?: Value;
/**
* @public
* @since 1.10.0
*/
entries: BasesEntry[];
/**
* @returns true iff this entry group has a non-null key.
* @public
* @since 1.10.0
*/
hasKey(): boolean;
}
/**
* A parsed version of the {@link BasesPropertyId}.
*
* @public
* @since 1.10.0
*/
export interface BasesProperty {
/**
* @public
* @since 1.10.0
*/
type: BasesPropertyType;
/**
* @public
* @since 1.10.0
*/
name: string;
}
/**
* The full ID of a property, used in the bases config file. The prefixed
* {@link BasesPropertyType} disambiguates properties of the same name but from different sources.
*
* @public
* @since 1.10.0
*/
export type BasesPropertyId = `${BasesPropertyType}.${string}`;
/**
* The three valid "sources" of a property in a Base.
*
* - `note`: Properties from the frontmatter of markdown files in the vault.
* - `formula`: Properties calculated by evaluating a formula from the base config file.
* - `file`: Properties inherent to a file, such as the name, extension, size, etc.
*
* @public
* @since 1.10.0
*/
export type BasesPropertyType = 'note' | 'formula' | 'file';
/**
* The BasesQueryResult contains all of the available information from executing the
* bases query, applying filters, and evaluating formulas. The `data` or `groupedData`
* should be displayed by your view.
*
* @public
* @since 1.10.0
*/
export class BasesQueryResult {
/**
* An ungrouped version of the data, with user-configured sort and limit applied.
* Where appropriate, views should support groupBy by using `groupedData` instead of this value.
*
* @public
* @since 1.10.0
*/
data: BasesEntry[];
/**
* The data to be rendered, grouped according to the groupBy config.
* If there is no groupBy configured, returns a single group with an empty key.
* @public
* @since 1.10.0
*/
get groupedData(): BasesEntryGroup[];
/**
* Visible properties defined by the user.
* @public
* @since 1.10.0
*/
get properties(): BasesPropertyId[];
/**
* Applies a summary function to a single property over a set of entries.
* @public
* @since 1.10.0
*/
getSummaryValue(queryController: QueryController, entries: BasesEntry[], prop: BasesPropertyId, summaryKey: string): Value;
}
/**
* @public
* @since 1.10.0
*/
export type BasesSortConfig = {
/**
* @public
* @since 1.10.0
*/
property: BasesPropertyId;
/**
* @public
* @since 1.10.0
*/
direction: 'ASC' | 'DESC';
};
/**
* Plugins can create a class which extends this in order to render a Base.
* Plugins should create a {@link BaseViewHandlerFactory} function, then call
* `plugin.registerView` to register the view factory.
*
* @public
* @since 1.10.0
*/
export abstract class BasesView extends Component {
/**
* The type ID of this view
* @public
* @since 1.10.0
*/
abstract type: string;
/**
* @public
* @since 1.10.0
*/
app: App;
/**
* The config object for this view.
* @public
* @since 1.10.0
*/
config: BasesViewConfig;
/**
* All available properties from the dataset.
* @public
* @since 1.10.0
*/
allProperties: BasesPropertyId[];
/**
* The most recent output from executing the bases query, applying filters, and evaluating formulas.
* This object will be replaced with a new result set when changes to the vault or Bases config occur,
* so views should not keep a reference to it. Also note the contained BasesEntry objects will be recreated.
* @public
* @since 1.10.0
*/
data: BasesQueryResult;
/**
* @public
* @since 1.10.0
*/
protected constructor(controller: QueryController);
/**
* Called when there is new data for the query. This view should rerender with the updated data.
* @public
* @since 1.10.0
*/
abstract onDataUpdated(): void;
/**
* Display the new note menu for a file with the provided filename and optionally a function to modify the frontmatter.
* @public
* @since 1.10.2
*/
createFileForView(baseFileName?: string, frontmatterProcessor?: (frontmatter: any) => void): Promise<void>;
}
/**
* The in-memory representation of a single entry in the "views" section of a Bases file.
* Contains settings and configuration options set by the user from the toolbar menus and view options.
* @public
* @since 1.10.0
*/
export class BasesViewConfig {
/**
* User-friendly name for this view.
* @public
* @since 1.10.0
*/
name: string;
/**
* Retrieve the user-configured value of options exposed in `BasesViewRegistration.options`.
* @public
* @since 1.10.0
*/
get(key: string): unknown;
/**
* Retrieve a user-configured value from the config, converting it to a BasesPropertyId.
* Returns null if the requested key is not present in the config, or if the value is invalid.
* @public
* @since 1.10.0
*/
getAsPropertyId(key: string): BasesPropertyId | null;
/**
* Retrieve a user-configured value from the config, evaluating it as a
* formula in the context of the current Base. For embedded bases, or bases
* in the sidebar, this means evaluating the formula against the currently
* active file.
*
* @public
* @returns the Value result from evaluating the formula, or NullValue if the formula is invalid, or the key is not present.
* @since 1.10.2
*/
getEvaluatedFormula(view: BasesView, key: string): Value;
/**
* Store configuration data for the view. Views should prefer `BasesViewRegistration.options`
* to allow users to configure options where appropriate.
* @public
* @since 1.10.0
*/
set(key: string, value: any | null): void;
/**
* Ordered list of properties to display in this view.
* In a table, these can be interpreted as the list of visible columns.
* Order is configured by the user through the properties toolbar menu.
* @public
* @since 1.10.0
*/
getOrder(): BasesPropertyId[];
/**
* Retrieve the sorting config for this view. Sort is configured by the user through the sort toolbar menu.
* Removes invalid sort configs. If no (valid) sort config, returns an empty array.
* Does not validate that the properties exists.
*
* Note that data from BasesQueryResult will be presorted.
*
* @public
* @since 1.10.0
*/
getSort(): BasesSortConfig[];
/**
* Retrieve a friendly name for the provided property.
* If the property has been renamed by the user in the Base config, that value is returned.
* File properties may have a default name that is returned, otherwise the name with the property
* type prefix removed is returned.
*
* @public
* @since 1.10.0
*/
getDisplayName(propertyId: BasesPropertyId): string;
}
/**
* Implement this factory function in a {@link BasesViewRegistration} to create a
* new instance of a custom Bases view.
* @param containerEl - The container below the Bases toolbar where the view will be displayed.
* @public
* @since 1.10.0
*/
export type BasesViewFactory = (controller: QueryController, containerEl: HTMLElement) => BasesView;
/**
* Container for options when registering a new Bases view type.
* @public
* @since 1.10.0
*/
export interface BasesViewRegistration {
/**
* @public
* @since 1.10.0
*/
name: string;
/**
* Icon ID to be used in the Bases view selector.
* See {@link https://docs.obsidian.md/Plugins/User+interface/Icons} for available icons and how to add your own.
* @public
* @since 1.10.0
*/
icon: IconName;
/**
* @public
* @since 1.10.0
*/
factory: BasesViewFactory;
/**
* @public
* @since 1.10.0
*/
options?: () => ViewOption[];
}
/**
* @public
* @since 0.11.13
*/
export interface BlockCache extends CacheItem {
/** @public */
id: string;
}
/**
* @public
* @since 0.13.26
*/
export interface BlockSubpathResult extends SubpathResult {
/**
* @public
*/
type: 'block';
/**
* @public
*/
block: BlockCache;
/**
* @public
*/
list?: ListItemCache;
}
/**
* {@link Value} wrapping a boolean.
* @public
* @since 1.10.0
*/
export class BooleanValue extends PrimitiveValue<boolean> {
/**
* @public
* @since 1.10.0
*/
static type: string;
}
/**
* @public
* @since 0.9.7
*/
export class ButtonComponent extends BaseComponent {
/**
* @public
* @since 0.9.7
*/
buttonEl: HTMLButtonElement;
/**
* @public
*/
constructor(containerEl: HTMLElement);
/**
* @public
* @since 1.2.3
*/
setDisabled(disabled: boolean): this;
/**
* @public
* @since 0.9.7
*/
setCta(): this;
/**
* @public
* @since 0.9.20
*/
removeCta(): this;
/**
* @public
* @since 0.11.0
*/
setWarning(): this;
/**
* @public
* @since 1.1.0
*/
setTooltip(tooltip: string, options?: TooltipOptions): this;
/**
* @public
* @since 0.9.7
*/
setButtonText(name: string): this;
/**
* @public
* @since 1.1.0
*/
setIcon(icon: IconName): this;
/**
* @public
* @since 0.9.7
*/
setClass(cls: string): this;
/**
* @public
* @since 0.12.16
*/
onClick(callback: (evt: MouseEvent) => unknown | Promise<unknown>): this;
}
/**
* @public
*/
export interface CachedMetadata {
/**
* @public
*/
links?: LinkCache[];
/**
* @public
*/
embeds?: EmbedCache[];
/**
* @public
*/
tags?: TagCache[];
/**
* @public
*/
headings?: HeadingCache[];
/**
* @public
* @since 1.6.6
*/
footnotes?: FootnoteCache[];
/**
* @public
* @since 1.8.7
*/
footnoteRefs?: FootnoteRefCache[];
/**
* @public
* @since 1.8.7
*/
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
* @since 1.4.0
*/
frontmatterPosition?: Pos;
/**
* @public
* @since 1.4.0
*/
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
* @since 1.7.2
*/
export class CapacitorAdapter implements DataAdapter {
/**
* @public
* @since 1.7.2
*/
getName(): string;
/**
* @public
* @since 1.7.2
*/
mkdir(normalizedPath: string): Promise<void>;
/**
* @public
* @since 1.7.2
*/
trashSystem(normalizedPath: string): Promise<boolean>;
/**
* @public
* @since 1.7.2
*/
trashLocal(normalizedPath: string): Promise<void>;
/**
* @public
* @since 1.7.2
*/
rmdir(normalizedPath: string, recursive: boolean): Promise<void>;
/**
* @public
* @since 1.7.2
*/
read(normalizedPath: string): Promise<string>;
/**
* @public
* @since 1.7.2
*/
readBinary(normalizedPath: string): Promise<ArrayBuffer>;
/**
* @public
* @since 1.7.2
*/
write(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>;
/**
* @public
* @since 1.7.2
*/
writeBinary(normalizedPath: string, data: ArrayBuffer, options?: DataWriteOptions): Promise<void>;
/**
* @public
* @since 1.7.2
*/
append(normalizedPath: string, data: string, options?: DataWriteOptions): Promise<void>;
/**
* @public
* @since 1.7.2
*/
process(normalizedPath: string, fn: (data: string) => string, options?: DataWriteOptions): Promise<string>;
/**
* @public
* @since 1.7.2
*/
getResourcePath(normalizedPath: string): string;
/**
* @public
* @since 1.7.2
*/
remove(normalizedPath: string): Promise<void>;
/**
* @public
* @since 1.7.2
*/
rename(normalizedPath: string, normalizedNewPath: string): Promise<void>;
/**
* @public
* @since 1.7.2
*/
copy(normalizedPath: string, normalizedNewPath: string): Promise<void>;
/**
* @public
* @since 1.7.2
*/
exists(normalizedPath: string, sensitive?: boolean): Promise<boolean>;
/**
* @public
* @since 1.7.2
*/
stat(normalizedPath: string): Promise<Stat | null>;
/**
* @public
* @since 1.7.2
*/
list(normalizedPath: string): Promise<ListedFiles>;
/**
* @public
* @since 1.7.2
*/
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
* @since 1.0.0
*/
export class ColorComponent extends ValueComponent<string> {
/**
* @public
*/
constructor(containerEl: HTMLElement);
/**
* @public
* @since 1.2.3
*/
setDisabled(disabled: boolean): this;
/**
* @public
* @since 1.0.0
*/
getValue(): HexString;
/**
* @public
* @since 1.0.0
*/
getValueRgb(): RGB;
/**
* @public
* @since 1.0.0
*/
getValueHsl(): HSL;
/**
* @public
* @since 1.0.0
*/
setValue(value: HexString): this;
/**
* @public
* @since 1.0.0
*/
setValueRgb(rgb: RGB): this;
/**
* @public
* @since 1.0.0
*/
setValueHsl(hsl: HSL): this;
/**
* @public
* @since 1.0.0
*/
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
* @since 0.12.2
*/
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
* @since 0.12.2
*/
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
* @since 0.9.7
*/
export class Component {
/**
* Load this component and its children
* @public
* @since 0.9.7
*/
load(): void;
/**
* Override this to load your component
* @public
* @virtual
* @since 0.9.7
*/
onload(): void;
/**
* Unload this component and its children
* @public
* @since 0.9.7
*/
unload(): void;
/**
* Override this to unload your component
* @public
* @virtual
* @since 0.9.7
*/
onunload(): void;
/**
* Adds a child component, loading it if this component is loaded
* @public
* @since 0.12.0
*/
addChild<T extends Component>(component: T): T;
/**
* Removes a child component, unloading it
* @public
* @since 0.12.0
*/
removeChild<T extends Component>(component: T): T;
/**
* Registers a callback to be called when unloading
* @public
* @since 0.9.7
*/
register(cb: () => any): void;
/**
* Registers an event to be detached when unloading
* @public
* @since 0.9.7
*/
registerEvent(eventRef: EventRef): void;
/**
* Registers a DOM event to be detached when unloading
* @public
* @since 0.14.8
*/
registerDomEvent<K extends keyof WindowEventMap>(el: Window, type: K, callback: (this: HTMLElement, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Registers a DOM event to be detached when unloading
* @public
* @since 0.14.8
*/
registerDomEvent<K extends keyof DocumentEventMap>(el: Document, type: K, callback: (this: HTMLElement, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
/**
* Registers a DOM event to be detached when unloading
* @public
* @since 0.14.8
*/
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
* @since 0.13.8
*/
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
* @since 0.12.2
*/
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 a 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;
}
/**
* {@link Value} wrapping a Date.
* @public
* @since 1.10.0
*/
export class DateValue extends NotNullValue {
/**
* @public
* @since 1.10.0
*/
toString(): string;
/**
* @returns a new DateValue with any time portion in this DateValue removed.
* @public
* @since 1.10.0
*/
dateOnly(): DateValue;
/**
* @returns a new {@link RelativeDateValue} based on this DateValue.
* @public
* @since 1.10.0
*/
relative(): string;
/**
* @public
* @since 1.10.0
*/
isTruthy(): boolean;
/**
* Create new DateValue from an input string.
*
* @example
* parseFromString("2025-12-31")
* parseFromString("2025-12-31T23:59")
* parseFromString("2025-12-31T23:59:59")
* parseFromString("2025-12-31T23:59:59Z-07")
*
* @param input - An ISO 8601 date or datetime string.
* @public
* @since 1.10.0
*/
static parseFromString(input: string): DateValue | null;
}
/**
* 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
* @since 1.4.4
*/
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
* @since 1.8.7
*/
export function displayTooltip(newTargetEl: HTMLElement, content: string | DocumentFragment, options?: TooltipOptions): void;
/**
* @public
* @s