Skip to content

ObsAPI

Defined in: packages/obsidian/src/ObsAPI.ts:38

Meta Bind API for Obsidian.

  • API<ObsComponents>

new ObsAPI(mb): ObsAPI

Defined in: packages/obsidian/src/ObsAPI.ts:42

Parameter Type

mb

ObsMetaBind

ObsAPI

API<ObsComponents>.constructor

readonly mb: MetaBind<ObsComponents>

Defined in: packages/core/src/api/API.ts:63

API.mb

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

Defined in: packages/obsidian/src/ObsAPI.ts:88

Creates a CM6 widget from a given widget type.

This is only useful for use in a CodeMirror plugin.

Parameter Type Description

inlineFieldType

InlineFieldType

content

string

filePath

string

component

Component

MarkdownRenderChildWidget


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

Defined in: packages/core/src/api/API.ts:591

Creates a bind target declaration.

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 access path as an array. E.g. for the path cache.a.b.c, the array would be ['a', 'b', 'c'].

listenToChildren

boolean

false

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

BindTargetDeclaration

API.createBindTarget


createButtonGroupMountable(filePath, options): ButtonGroupMountable

Defined in: packages/core/src/api/API.ts:386

Creates a button group from an options object.

Parameter Type Description

filePath

string

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

options

ButtonGroupOptions

ButtonGroupMountable

API.createButtonGroupMountable


createButtonMountable(filePath, options): ButtonMountable

Defined in: packages/core/src/api/API.ts:423

Creates a button from an options object.

Parameter Type Description

filePath

string

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

options

ButtonOptions

ButtonMountable

API.createButtonMountable


createEmbedMountable(filePath, options): EmbedMountable

Defined in: packages/core/src/api/API.ts:453

Creates a meta bind embed fields from an options object.

Parameter Type Description

filePath

string

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

options

EmbedOptions

EmbedMountable

API.createEmbedMountable


createExcludedMountable(filePath): ExcludedMountable

Defined in: packages/core/src/api/API.ts:474

Creates an excluded notification mountable for the excluded folders setting.

Parameter Type Description

filePath

string

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

ExcludedMountable

API.createExcludedMountable


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

Defined in: packages/core/src/api/API.ts:77

Creates a field of a given type.

Type Parameter

Type extends FieldType

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

FieldMountable

API.createField


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

Defined in: packages/core/src/api/API.ts:137

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

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

FieldMountable

API.createInlineFieldFromString


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

Defined in: packages/core/src/api/API.ts:194

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

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

FieldMountable

API.createInlineFieldOfTypeFromString


createInputFieldMountable(filePath, options): InputFieldMountable

Defined in: packages/core/src/api/API.ts:265

Creates an input field from an options object.

Parameter Type Description

filePath

string

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

options

InputFieldOptions

InputFieldMountable

API.createInputFieldMountable


createJsViewFieldMountable(filePath, options): JsViewFieldMountable

Defined in: packages/core/src/api/API.ts:333

Creates a JS view field from an options object.

Parameter Type Description

filePath

string

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

options

JsViewFieldOptions

JsViewFieldMountable

API.createJsViewFieldMountable


createNotePosition(lineStart, lineEnd): NotePosition

Defined in: packages/core/src/api/API.ts:783

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

Parameter Type Description

lineStart

number

lineEnd

number

NotePosition

API.createNotePosition


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

Defined in: packages/core/src/api/API.ts:579

Creates a signal.

Type Parameter

T

Parameter Type Description

value

T

Signal<T>

API.createSignal


createTableMountable(filePath, options): TableMountable

Defined in: packages/core/src/api/API.ts:363

Creates a table from an options object.

Parameter Type Description

filePath

string

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

options

TableOptions

TableMountable

API.createTableMountable


createViewFieldMountable(filePath, options): ViewFieldMountable

Defined in: packages/core/src/api/API.ts:299

Creates a view field from an options object.

Parameter Type Description

filePath

string

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

options

ViewFieldOptions

ViewFieldMountable

API.createViewFieldMountable


getInlineFieldDeclarationPrefix(fieldType): string

Defined in: packages/core/src/api/API.ts:493

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

Parameter Type Description

fieldType

FieldType

string

API.getInlineFieldDeclarationPrefix


getMetadata(bindTarget): unknown

Defined in: packages/core/src/api/API.ts:685

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.

Parameter Type Description

bindTarget

BindTargetDeclaration

unknown

// Assumes you use the JS Engine plugin to run this.
const mb = engine.getPlugin("obsidian-meta-bind-plugin").api;
const bindTarget = mb.parseBindTarget("property", context.file.path);
const value = mb.getMetadata(bindTarget);

API.getMetadata


isInlineFieldDeclaration(fieldType, str): boolean

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

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

Parameter Type Description

fieldType

FieldType

str

string

the declaration string

boolean

API.isInlineFieldDeclaration


isInlineFieldDeclarationAndGetType(str): undefined | InlineFieldType

Defined in: packages/core/src/api/API.ts:547

Checks if a string is any declaration. If yes, it returns the widget type, otherwise undefined.

Parameter Type Description

str

string

the declaration string

undefined | InlineFieldType

API.isInlineFieldDeclarationAndGetType


mathJSImport(object, options?): void

Defined in: packages/core/src/api/API.ts:805

Import new definitions into the internal mathJS instance. For details on how to use, see https://mathjs.org/docs/reference/functions/import.html

Parameter Type

object

ImportObject | ImportObject[]

options?

ImportOptions

void

API.mathJSImport


parseBindTarget(declarationString, filePath, scope?): BindTargetDeclaration

Defined in: packages/core/src/api/API.ts:627

Parses a bind target declaration from a string.

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

BindTargetDeclaration

API.parseBindTarget


reactiveMetadata(bindTargets, lifecycleHook, callback): ReactiveComponent

Defined in: packages/obsidian/src/ObsAPI.ts:114

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!

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.

ReactiveComponent


setMetadata(bindTarget, value): void

Defined in: packages/core/src/api/API.ts:660

Sets a property in meta binds metadata cache.

Parameter Type Description

bindTarget

BindTargetDeclaration

value

unknown

void

// Assumes you use the JS Engine plugin to run this.
const mb = engine.getPlugin("obsidian-meta-bind-plugin").api;
const bindTarget = mb.parseBindTarget("property", context.file.path);
mb.setMetadata(bindTarget, "some value");

API.setMetadata


subscribeToMetadata(bindTarget, lifecycleHook, callback): void

Defined in: packages/core/src/api/API.ts:743

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.

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

void

API.subscribeToMetadata


updateMetadata(bindTarget, updateFn): void

Defined in: packages/core/src/api/API.ts:712

Updates a property in meta binds metadata cache.

Parameter Type Description

bindTarget

BindTargetDeclaration

updateFn

(value) => unknown

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

void

// Assumes you use the JS Engine plugin to run this.
const mb = engine.getPlugin("obsidian-meta-bind-plugin").api;
const bindTarget = mb.parseBindTarget("property", context.file.path);
mb.updateMetadata(bindTarget, (value) => {
return value + 1;
});

API.updateMetadata


wrapInMDRC(mountable, containerEl, component): MountableMDRC

Defined in: packages/obsidian/src/ObsAPI.ts:58

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

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

MountableMDRC