Table of Contents:
- Installation
- Setup
- Types
- Functions
getApi
(package import)getCallouts
getColor
getTitle
- Events
You can install Callout Manager's plugin API by adding the package through npm
or yarn
.
npm install obsidian-callout-manager
To use the API, you need to get an API handle. Since we can't guarantee plugin load order, it is recommended you do this under an onLayoutReady
callback:
import {CalloutManager, getApi} from "obsidian-callout-manager";
class MyPlugin extends Plugin {
private calloutManager?: CalloutManager<true>;
public async onload() {
this.app.workspace.onLayoutReady(() => {
this.calloutManager = getApi(this);
}
}
}
A callout and its properties.
type Callout = {
id: CalloutID,
color: string,
icon: string,
sources: Array<CalloutSource>,
}
id: CalloutID
The ID of the callout.
This is the part that goes in the callout header.
color: string
The current color of the callout.
This is going to be a comma-delimited RGB tuple.
If you need to parse this, use getColor.
icon: string
The icon associated with the callout.
sources: Array<CalloutSource>
The list of known sources for the callout.
A source is a stylesheet that provides styles for a callout with this ID.
type CalloutID = string;
A type representing the ID of a callout.
type CalloutSource =
{ type: "builtin"; } |
{ type: "custom"; } |
{ type: "snippet"; snippet: string } |
{ type: "theme"; theme: string }
The source of a callout.
builtin
callouts come from Obsidian.custom
callouts were added by Callout Manager.snippet
callouts were added by a user's CSS snippet.theme
callouts were added by the user's current theme.
getApi(owner: Plugin): CalloutManager<true>
Gets an API handle owned by the provided plugin.
getApi(): CalloutManager
Gets an unowned API handle.
This only has access to a subset of API functions.
(handle).getCallouts(): ReadonlyArray<Callout>
Gets the list of available callouts.
(handle).getColor(callout: Callout): RGB | { invalid: string }
Parses the color of a callout into an Obsidian RGB object, or an object containing the property "invalid" if the color is not valid.
If the parsing was successful, you can extract the red, green, and blue channels through color.r
, color.g
, and color.b
respectively.
(handle).getTitle(callout: Callout): string
Gets the default title string for the provided callout.
(owned handle).on("change", listener: () => void)
Adds an event listener that is triggered whenever one or more callouts are changed.
This event is intended to be used as a signal for your plugin to refresh any caches or computed data that relied on the callouts as a source. If you need to determine which callouts have changed, that should be done manually.
(owned handle).off("change", listener: () => void)
Removes a previously-registered change event listener.