1 import {EditorUiContext} from "./core";
2 import {LexicalNode} from "lexical";
4 export interface EditorDecoratorAdapter {
6 getNode(): LexicalNode;
9 export abstract class EditorDecorator {
11 protected node: LexicalNode | null = null;
12 protected context: EditorUiContext;
14 private onDestroyCallbacks: (() => void)[] = [];
16 constructor(context: EditorUiContext) {
17 this.context = context;
20 protected getNode(): LexicalNode {
22 throw new Error('Attempted to get use node without it being set');
28 setNode(node: LexicalNode) {
33 * Register a callback to be ran on destroy of this decorator's node.
35 protected onDestroy(callback: () => void) {
36 this.onDestroyCallbacks.push(callback);
40 * Render the decorator.
41 * Can run on both creation and update for a node decorator.
42 * If an element is returned, this will be appended to the element
43 * that is being decorated.
45 abstract render(context: EditorUiContext, decorated: HTMLElement): HTMLElement|void;
48 * Destroy this decorator. Used for tear-down operations upon destruction
49 * of the underlying node this decorator is attached to.
51 destroy(context: EditorUiContext): void {
52 for (const callback of this.onDestroyCallbacks) {