Skip to content

ObsidianAPI

Meta Bind API for Obsidian.

Extends

  • API<MetaBindPlugin>

Constructors

new ObsidianAPI()

new ObsidianAPI(plugin): ObsidianAPI

Parameters

Parameter Type

plugin

MetaBindPlugin

Returns

ObsidianAPI

Overrides

API<MetaBindPlugin>.constructor

Defined in

packages/obsidian/src/ObsidianAPI.ts:39

Properties

bindTargetParser

readonly bindTargetParser: BindTargetParser

Inherited from

API.bindTargetParser

Defined in

packages/core/src/api/API.ts:91


buttonActionRunner

readonly buttonActionRunner: ButtonActionRunner

Inherited from

API.buttonActionRunner

Defined in

packages/core/src/api/API.ts:96


buttonManager

readonly buttonManager: ButtonManager

Inherited from

API.buttonManager

Defined in

packages/core/src/api/API.ts:97


buttonParser

readonly buttonParser: ButtonParser

Inherited from

API.buttonParser

Defined in

packages/core/src/api/API.ts:90


inputFieldFactory

readonly inputFieldFactory: InputFieldFactory

Inherited from

API.inputFieldFactory

Defined in

packages/core/src/api/API.ts:93


inputFieldParser

readonly inputFieldParser: InputFieldParser

Inherited from

API.inputFieldParser

Defined in

packages/core/src/api/API.ts:87


jsViewFieldParser

readonly jsViewFieldParser: JsViewFieldParser

Inherited from

API.jsViewFieldParser

Defined in

packages/core/src/api/API.ts:89


plugin

readonly plugin: MetaBindPlugin

Inherited from

API.plugin

Defined in

packages/core/src/api/API.ts:85


syntaxHighlighting

readonly syntaxHighlighting: SyntaxHighlightingAPI

Inherited from

API.syntaxHighlighting

Defined in

packages/core/src/api/API.ts:99


viewFieldFactory

readonly viewFieldFactory: ViewFieldFactory

Inherited from

API.viewFieldFactory

Defined in

packages/core/src/api/API.ts:94


viewFieldParser

readonly viewFieldParser: ViewFieldParser

Inherited from

API.viewFieldParser

Defined in

packages/core/src/api/API.ts:88

Methods

constructMDRCWidget()

constructMDRCWidget(inlineFieldType, content, filePath, component): MarkdownRenderChildWidget

Creates a CM6 widget from a given widget type.

This is only useful fur use in a CodeMirror plugin.

Parameters

Parameter Type Description

inlineFieldType

InlineFieldType

content

string

filePath

string

component

Component

Returns

MarkdownRenderChildWidget

Defined in

packages/obsidian/src/ObsidianAPI.ts:83


createBindTarget()

createBindTarget(storageType, storagePath, property, listenToChildren): BindTargetDeclaration

Creates a bind target declaration.

Parameters

Parameter Type Default value Description

storageType

string

undefined

the storage type (also named metadata source sometimes)

storagePath

string

undefined

the storage path (usually the file path)

property

string[]

undefined

the property path a.b.c = [‘a’, ‘b’, ‘c’]

listenToChildren

boolean

false

whether to listen to children, only relevant for arrays and objects

Returns

BindTargetDeclaration

Inherited from

API.createBindTarget

Defined in

packages/core/src/api/API.ts:641


createButtonGroupMountable()

createButtonGroupMountable(filePath, options): ButtonGroupMountable

Creates a button group from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

ButtonGroupOptions

Returns

ButtonGroupMountable

Inherited from

API.createButtonGroupMountable

Defined in

packages/core/src/api/API.ts:436


createButtonMountable()

createButtonMountable(filePath, options): ButtonMountable

Creates a button from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

ButtonOptions

Returns

ButtonMountable

Inherited from

API.createButtonMountable

Defined in

packages/core/src/api/API.ts:473


createEmbedMountable()

createEmbedMountable(filePath, options): EmbedMountable

Creates a meta bind embed fields from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

EmbedOptions

Returns

EmbedMountable

Inherited from

API.createEmbedMountable

Defined in

packages/core/src/api/API.ts:503


createExcludedMountable()

createExcludedMountable(filePath): ExcludedMountable

Creates an excluded notification mountable for the excluded folders setting.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

Returns

ExcludedMountable

Inherited from

API.createExcludedMountable

Defined in

packages/core/src/api/API.ts:524


createField()

createField<Type>(type, filePath, options, honorExcludedSetting): FieldMountable

Creates a field of a given type.

Type Parameters

Type Parameter

Type extends FieldType

Parameters

Parameter Type Default value Description

type

Type

undefined

the type of the field

filePath

string

undefined

the file path that the field is located in, or an empty string if it is not in a file

options

FieldOptionMap[Type]

undefined

honorExcludedSetting

boolean

true

whether to honor the excluded folders settings for this field

Returns

FieldMountable

Inherited from

API.createField

Defined in

packages/core/src/api/API.ts:127


createInlineFieldFromString()

createInlineFieldFromString(fieldString, filePath, scope, renderChildType, position?, honorExcludedSetting?): FieldMountable

Creates an inline field from a string. Will throw an error if the string is not a valid declaration.

Parameters

Parameter Type Default value Description

fieldString

string

undefined

the declaration string of the field

filePath

string

undefined

the file path that the field is located in

scope

undefined | BindTargetScope

undefined

optional bind target scope

renderChildType

RenderChildType

RenderChildType.INLINE

the render child type, default INLINE

position?

NotePosition

undefined

an optional note position

honorExcludedSetting?

boolean

true

whether to honor the excluded folders settings for this field

Returns

FieldMountable

Inherited from

API.createInlineFieldFromString

Defined in

packages/core/src/api/API.ts:187


createInlineFieldOfTypeFromString()

createInlineFieldOfTypeFromString(type, declaration, filePath, scope, renderChildType, position?, honorExcludedSetting?): FieldMountable

Creates an inline field of a given type and string. Will throw an error if the string is not a valid inline field type.

Parameters

Parameter Type Default value Description

type

InlineFieldType

undefined

the field type

declaration

string

undefined

the declaration string of the field

filePath

string

undefined

the file path that the field is located in

scope

undefined | BindTargetScope

undefined

optional bind target scope

renderChildType

RenderChildType

RenderChildType.INLINE

the render child type, default INLINE

position?

NotePosition

undefined

an optional note position

honorExcludedSetting?

boolean

true

whether to honor the excluded folders settings for this field

Returns

FieldMountable

Inherited from

API.createInlineFieldOfTypeFromString

Defined in

packages/core/src/api/API.ts:244


createInputFieldMountable()

createInputFieldMountable(filePath, options): InputFieldMountable

Creates an input field from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

InputFieldOptions

Returns

InputFieldMountable

Inherited from

API.createInputFieldMountable

Defined in

packages/core/src/api/API.ts:315


createJsViewFieldMountable()

createJsViewFieldMountable(filePath, options): JsViewFieldMountable

Creates a JS view field from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

JsViewFieldOptions

Returns

JsViewFieldMountable

Inherited from

API.createJsViewFieldMountable

Defined in

packages/core/src/api/API.ts:383


createNotePosition()

createNotePosition(lineStart, lineEnd): NotePosition

Creates a note position from a line start and line end number.

Parameters

Parameter Type Description

lineStart

number

lineEnd

number

Returns

NotePosition

Inherited from

API.createNotePosition

Defined in

packages/core/src/api/API.ts:813


createSignal()

createSignal<T>(value): Signal<T>

Creates a signal.

Type Parameters

Type Parameter

T

Parameters

Parameter Type Description

value

T

Returns

Signal<T>

Inherited from

API.createSignal

Defined in

packages/core/src/api/API.ts:629


createTableMountable()

createTableMountable(filePath, options): TableMountable

Creates a table from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

TableOptions

Returns

TableMountable

Inherited from

API.createTableMountable

Defined in

packages/core/src/api/API.ts:413


createViewFieldMountable()

createViewFieldMountable(filePath, options): ViewFieldMountable

Creates a view field from an options object.

Parameters

Parameter Type Description

filePath

string

the file path that the field is located in or an empty string

options

ViewFieldOptions

Returns

ViewFieldMountable

Inherited from

API.createViewFieldMountable

Defined in

packages/core/src/api/API.ts:349


getInlineFieldDeclarationPrefix()

getInlineFieldDeclarationPrefix(fieldType): string

Gets the prefix of a given widget type. (e.g. INPUT or VIEW).

Parameters

Parameter Type Description

fieldType

FieldType

Returns

string

Inherited from

API.getInlineFieldDeclarationPrefix

Defined in

packages/core/src/api/API.ts:543


getMetadata()

getMetadata(bindTarget): unknown

Reads a property from meta binds metadata cache. If the value is not present in the cache, it will check the underlying source. E.g. Obsidians metadata cache.

Parameters

Parameter Type Description

bindTarget

BindTargetDeclaration

Returns

unknown

Inherited from

API.getMetadata

Defined in

packages/core/src/api/API.ts:723


isInlineFieldDeclaration()

isInlineFieldDeclaration(fieldType, str): boolean

Checks if a string is a declaration of a given widget type.

Parameters

Parameter Type Description

fieldType

FieldType

str

string

the declaration string

Returns

boolean

Inherited from

API.isInlineFieldDeclaration

Defined in

packages/core/src/api/API.ts:574


isInlineFieldDeclarationAndGetType()

isInlineFieldDeclarationAndGetType(str): undefined | InlineFieldType

Checks if a string is any declaration and if yes returns the widget type.

Parameters

Parameter Type Description

str

string

the declaration string

Returns

undefined | InlineFieldType

Inherited from

API.isInlineFieldDeclarationAndGetType

Defined in

packages/core/src/api/API.ts:597


parseBindTarget()

parseBindTarget(declarationString, filePath, scope?): BindTargetDeclaration

Parses a bind target declaration from a string.

Parameters

Parameter Type Description

declarationString

string

the string to parse

filePath

string

the file path that this bind target is relative to

scope?

BindTargetScope

optional bind target scope

Returns

BindTargetDeclaration

Inherited from

API.parseBindTarget

Defined in

packages/core/src/api/API.ts:677


reactiveMetadata()

reactiveMetadata(bindTargets, lifecycleHook, callback): ReactiveComponent

Creates a JS Engine reactive component that will re-render when the given bind targets change.

This requires JS Engine to be installed and enabled!

Parameters

Parameter Type Description

bindTargets

BindTargetDeclaration[]

the bind targets to listen to

lifecycleHook

LifecycleHook

a Component

callback

(…values) => Promise<unknown>

the callback to call with all the values of the bind targets when one of them changes. What ever this callback returns will be rendered by the reactive component.

Returns

ReactiveComponent

Defined in

packages/obsidian/src/ObsidianAPI.ts:109


setMetadata()

setMetadata(bindTarget, value): void

Sets a property in meta binds metadata cache.

Parameters

Parameter Type Description

bindTarget

BindTargetDeclaration

value

unknown

Returns

void

Inherited from

API.setMetadata

Defined in

packages/core/src/api/API.ts:704


subscribeToMetadata()

subscribeToMetadata(bindTarget, lifecycleHook, callback): void

Subscribes to a property in meta binds metadata cache. This expects some sort of lifecycle hook to be passed in. This method will register a callback to the lifecycle hook. To unsubscribe the subscription, the callback registered to the lifecycle hook must be called. In the context of Obsidian, you should pass a Component instance as the lifecycle hook and make sure to unload the component when you are done using the metadata subscription.

NOT UNSUBSCRIBING WILL LEAD TO MEMORY LEAKS.

Parameters

Parameter Type Description

bindTarget

BindTargetDeclaration

lifecycleHook

LifecycleHook

In Obsidian this is an instance of the Component class. The subscription will be automatically unsubscribed when the component is unloaded.

callback

(value) => void

Returns

void

Inherited from

API.subscribeToMetadata

Defined in

packages/core/src/api/API.ts:773


updateMetadata()

updateMetadata(bindTarget, updateFn): void

Updates a property in meta binds metadata cache.

Parameters

Parameter Type Description

bindTarget

BindTargetDeclaration

updateFn

(value) => unknown

a function that takes the current value and returns the new value

Returns

void

Inherited from

API.updateMetadata

Defined in

packages/core/src/api/API.ts:742


wrapInMDRC()

wrapInMDRC(mountable, containerEl, component): MountableMDRC

Wraps any mountable in a MarkdownRenderChild and adds it as a child to the passed in ComponentLike.

A ComponentLike is either a Component or a MarkdownPostProcessorContext

Parameters

Parameter Type Description

mountable

Mountable

the mountable to wrap in a MarkdownRenderChild

containerEl

HTMLElement

the element to mount the MarkdownRenderChild to

component

ComponentLike

the ComponentLike to register the MarkdownRenderChild to

Returns

MountableMDRC

Defined in

packages/obsidian/src/ObsidianAPI.ts:53