ObsAPI
Defined in: packages/obsidian/src/ObsAPI.ts:38
Meta Bind API for Obsidian.
Extends
Section titled “Extends”API
<ObsComponents
>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ObsAPI(
mb
):ObsAPI
Defined in: packages/obsidian/src/ObsAPI.ts:42
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
Returns
Section titled “Returns”ObsAPI
Overrides
Section titled “Overrides”API<ObsComponents>.constructor
Properties
Section titled “Properties”
readonly
mb:MetaBind
<ObsComponents
>
Defined in: packages/core/src/api/API.ts:63
Inherited from
Section titled “Inherited from”API.mb
Methods
Section titled “Methods”constructMDRCWidget()
Section titled “constructMDRCWidget()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
||
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”MarkdownRenderChildWidget
createBindTarget()
Section titled “createBindTarget()”createBindTarget(
storageType
,storagePath
,property
,listenToChildren
):BindTargetDeclaration
Defined in: packages/core/src/api/API.ts:591
Creates a bind target declaration.
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
|
|
|
the storage type (also named metadata source sometimes) |
|
|
|
the storage path (usually the file path) |
|
|
|
the property access path as an array. E.g. for the path |
|
|
|
whether to listen to children, only relevant for arrays and objects |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.createBindTarget
createButtonGroupMountable()
Section titled “createButtonGroupMountable()”createButtonGroupMountable(
filePath
,options
):ButtonGroupMountable
Defined in: packages/core/src/api/API.ts:386
Creates a button group from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”ButtonGroupMountable
Inherited from
Section titled “Inherited from”API.createButtonGroupMountable
createButtonMountable()
Section titled “createButtonMountable()”createButtonMountable(
filePath
,options
):ButtonMountable
Defined in: packages/core/src/api/API.ts:423
Creates a button from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”ButtonMountable
Inherited from
Section titled “Inherited from”API.createButtonMountable
createEmbedMountable()
Section titled “createEmbedMountable()”createEmbedMountable(
filePath
,options
):EmbedMountable
Defined in: packages/core/src/api/API.ts:453
Creates a meta bind embed fields from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”EmbedMountable
Inherited from
Section titled “Inherited from”API.createEmbedMountable
createExcludedMountable()
Section titled “createExcludedMountable()”createExcludedMountable(
filePath
):ExcludedMountable
Defined in: packages/core/src/api/API.ts:474
Creates an excluded notification mountable for the excluded folders setting.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
Returns
Section titled “Returns”ExcludedMountable
Inherited from
Section titled “Inherited from”API.createExcludedMountable
createField()
Section titled “createField()”createField<
Type
>(type
,filePath
,options
,honorExcludedSetting
):FieldMountable
Defined in: packages/core/src/api/API.ts:77
Creates a field of a given type.
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
|
|
|
the type of the field |
|
|
|
the file path that the field is located in, or an empty string if it is not in a file |
|
|
|
|
|
|
|
whether to honor the excluded folders settings for this field |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.createField
createInlineFieldFromString()
Section titled “createInlineFieldFromString()”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.
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
|
|
|
the declaration string of the field |
|
|
|
the file path that the field is located in |
|
|
|
optional bind target scope |
|
|
the render child type, default INLINE |
|
|
|
an optional note position |
|
|
|
|
whether to honor the excluded folders settings for this field |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.createInlineFieldFromString
createInlineFieldOfTypeFromString()
Section titled “createInlineFieldOfTypeFromString()”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.
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
|
|
the field type |
|
|
|
|
the declaration string of the field |
|
|
|
the file path that the field is located in |
|
|
|
optional bind target scope |
|
|
the render child type, default INLINE |
|
|
|
an optional note position |
|
|
|
|
whether to honor the excluded folders settings for this field |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.createInlineFieldOfTypeFromString
createInputFieldMountable()
Section titled “createInputFieldMountable()”createInputFieldMountable(
filePath
,options
):InputFieldMountable
Defined in: packages/core/src/api/API.ts:265
Creates an input field from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”InputFieldMountable
Inherited from
Section titled “Inherited from”API.createInputFieldMountable
createJsViewFieldMountable()
Section titled “createJsViewFieldMountable()”createJsViewFieldMountable(
filePath
,options
):JsViewFieldMountable
Defined in: packages/core/src/api/API.ts:333
Creates a JS view field from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”JsViewFieldMountable
Inherited from
Section titled “Inherited from”API.createJsViewFieldMountable
createNotePosition()
Section titled “createNotePosition()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
|
|
|
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.createNotePosition
createSignal()
Section titled “createSignal()”createSignal<
T
>(value
):Signal
<T
>
Defined in: packages/core/src/api/API.ts:579
Creates a signal.
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
Returns
Section titled “Returns”Signal
<T
>
Inherited from
Section titled “Inherited from”API.createSignal
createTableMountable()
Section titled “createTableMountable()”createTableMountable(
filePath
,options
):TableMountable
Defined in: packages/core/src/api/API.ts:363
Creates a table from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”TableMountable
Inherited from
Section titled “Inherited from”API.createTableMountable
createViewFieldMountable()
Section titled “createViewFieldMountable()”createViewFieldMountable(
filePath
,options
):ViewFieldMountable
Defined in: packages/core/src/api/API.ts:299
Creates a view field from an options object.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the file path that the field is located in or an empty string |
|
Returns
Section titled “Returns”ViewFieldMountable
Inherited from
Section titled “Inherited from”API.createViewFieldMountable
getInlineFieldDeclarationPrefix()
Section titled “getInlineFieldDeclarationPrefix()”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).
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”API.getInlineFieldDeclarationPrefix
getMetadata()
Section titled “getMetadata()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
Returns
Section titled “Returns”unknown
Example
Section titled “Example”// 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);
Inherited from
Section titled “Inherited from”API.getMetadata
isInlineFieldDeclaration()
Section titled “isInlineFieldDeclaration()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
||
|
|
the declaration string |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”API.isInlineFieldDeclaration
isInlineFieldDeclarationAndGetType()
Section titled “isInlineFieldDeclarationAndGetType()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the declaration string |
Returns
Section titled “Returns”undefined
| InlineFieldType
Inherited from
Section titled “Inherited from”API.isInlineFieldDeclarationAndGetType
mathJSImport()
Section titled “mathJSImport()”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
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
|
|
|
|
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”API.mathJSImport
parseBindTarget()
Section titled “parseBindTarget()”parseBindTarget(
declarationString
,filePath
,scope?
):BindTargetDeclaration
Defined in: packages/core/src/api/API.ts:627
Parses a bind target declaration from a string.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
|
the string to parse |
|
|
the file path that this bind target is relative to |
|
|
optional bind target scope |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”API.parseBindTarget
reactiveMetadata()
Section titled “reactiveMetadata()”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!
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
the bind targets to listen to |
|
|
|
|
|
(… |
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
Section titled “Returns”ReactiveComponent
setMetadata()
Section titled “setMetadata()”setMetadata(
bindTarget
,value
):void
Defined in: packages/core/src/api/API.ts:660
Sets a property in meta binds metadata cache.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
||
|
|
Returns
Section titled “Returns”void
Example
Section titled “Example”// 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");
Inherited from
Section titled “Inherited from”API.setMetadata
subscribeToMetadata()
Section titled “subscribeToMetadata()”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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
||
|
|
In Obsidian this is an instance of the Component class. The subscription will be automatically unsubscribed when the component is unloaded. |
|
( |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”API.subscribeToMetadata
updateMetadata()
Section titled “updateMetadata()”updateMetadata(
bindTarget
,updateFn
):void
Defined in: packages/core/src/api/API.ts:712
Updates a property in meta binds metadata cache.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
||
|
( |
a function that takes the current value and returns the new value |
Returns
Section titled “Returns”void
Example
Section titled “Example”// 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;});
Inherited from
Section titled “Inherited from”API.updateMetadata
wrapInMDRC()
Section titled “wrapInMDRC()”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
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
|
the mountable to wrap in a MarkdownRenderChild |
|
|
the element to mount the MarkdownRenderChild to |
|
|
the ComponentLike to register the MarkdownRenderChild to |
Returns
Section titled “Returns”MountableMDRC