]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/framework/toolbars.ts
Lexical: Added base context toolbar logic
[bookstack] / resources / js / wysiwyg / ui / framework / toolbars.ts
1 import {EditorContainerUiElement, EditorUiElement} from "./core";
2 import {el} from "../../helpers";
3
4 export type EditorContextToolbarDefinition = {
5     selector: string;
6     content: EditorUiElement[],
7     displayTargetLocator?: (originalTarget: HTMLElement) => HTMLElement;
8 };
9
10 export class EditorContextToolbar extends EditorContainerUiElement {
11
12     protected buildDOM(): HTMLElement {
13         return el('div', {
14             class: 'editor-context-toolbar',
15         }, this.getChildren().map(child => child.getDOMElement()));
16     }
17
18     attachTo(target: HTMLElement) {
19         // Todo - attach to target position
20         console.log('attaching context toolbar to', target);
21     }
22
23     insert(children: EditorUiElement[]) {
24         this.addChildren(...children);
25         const dom = this.getDOMElement();
26         dom.append(...children.map(child => child.getDOMElement()));
27     }
28
29     empty() {
30         const children = this.getChildren();
31         for (const child of children) {
32             child.getDOMElement().remove();
33         }
34         this.removeChildren(...children);
35     }
36 }