]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/framework/decorator.ts
a9917ab232fb0232f8ac15ce2a9e8dd8f7829a42
[bookstack] / resources / js / wysiwyg / ui / framework / decorator.ts
1 import {EditorUiContext} from "./core";
2 import {LexicalNode} from "lexical";
3
4 export interface EditorDecoratorAdapter {
5     type: string;
6     getNode(): LexicalNode;
7 }
8
9 export abstract class EditorDecorator {
10
11     protected node: LexicalNode | null = null;
12     protected context: EditorUiContext;
13
14     constructor(context: EditorUiContext) {
15         this.context = context;
16     }
17
18     protected getNode(): LexicalNode {
19         if (!this.node) {
20             throw new Error('Attempted to get use node without it being set');
21         }
22
23         return this.node;
24     }
25
26     setNode(node: LexicalNode) {
27         this.node = node;
28     }
29
30     /**
31      * Render the decorator.
32      * Can run on both creation and update for a node decorator.
33      * If an element is returned, this will be appended to the element
34      * that is being decorated.
35      */
36     abstract render(context: EditorUiContext, decorated: HTMLElement): HTMLElement|void;
37
38 }