ObsidianWidgetType
Unofficial
Base class Obsidian puts between its own block widgets and the CodeMirror @codemirror/view#WidgetType.
Tracks the document range the widget stands for, owns the widget’s container element, and provides the shared action-bar, click-forwarding and resize plumbing used by embeds, tables and callouts.
Import:
import type { ObsidianWidgetType } from '@obsidian-typings/obsidian-catalyst-latest';Signature:
export interface ObsidianWidgetType extends WidgetTypeExtends: WidgetType
Properties
| Property | Type | Description | |
|---|---|---|---|
| actionsEl | HTMLElement | null | Element holding the widget's action buttons, or null until the first action is added. | |
| containerEl | HTMLElement | Container element built by ObsidianWidgetType.initDOM and cached by ObsidianWidgetType.toDOM. | |
| end | number | End offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called. | |
| resizeObserver? | ResizeObserver | Observer used by ObsidianWidgetType.resizeWidget, created on first use. | |
| start | number | Start offset of the widget's range in the document, or -1 before ObsidianWidgetType.setPos is called. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| addAction(el, callback) | this | Add an action to the widget's action bar, creating the bar on first use. | |
| addEditButton(view, el) | void | Add the standard edit button, which selects the widget's source range when clicked. | |
| become(dom, widget) | void | Called when a previous DOM element created by a widget of the same type is about to be reused. Equivalent to updateDOM, but for when eq returns true.Can be used as widget ownership transfer. (Inherited from WidgetType) | |
| coordsAt(dom, pos, side) | null | Rect | Override the way screen coordinates for positions at/in the widget are found. (Inherited from WidgetType) | |
| destroy(dom) | void | This is called when an instance of the widget is removed from the editor view. (Inherited from WidgetType) | |
| hookClickHandler(view, el) | void | Make clicks on the element select the widget's source range, unless they land inside a nested editor. | |
| ignoreEvent(event) | boolean | Can be used to configure which kinds of events inside the widget should be ignored by the editor. The default is to ignore all events. (Inherited from WidgetType) | |
| initDOM(view) | HTMLElement | Build the widget's container element. | |
| resizeWidget(view, el) | void | Re-measure the editor whenever the given element resizes. | |
| setOwner(el) | void | Register the widget as the owner of the given element, so that clicks on it can be routed back here. | |
| setPos(start, end) | void | Record the document range the widget stands for. | |
| toDOM(view) | HTMLElement | Get the widget's container element, building it via ObsidianWidgetType.initDOM on first call. |
Links to this page: