1 import {EditorContainerUiElement, EditorUiElement} from "./core";
2 import {el} from "../../helpers";
4 export type EditorContextToolbarDefinition = {
6 content: EditorUiElement[],
7 displayTargetLocator?: (originalTarget: HTMLElement) => HTMLElement;
10 export class EditorContextToolbar extends EditorContainerUiElement {
12 protected buildDOM(): HTMLElement {
14 class: 'editor-context-toolbar',
15 }, this.getChildren().map(child => child.getDOMElement()));
18 attachTo(target: HTMLElement) {
19 const targetBounds = target.getBoundingClientRect();
20 const dom = this.getDOMElement();
21 const domBounds = dom.getBoundingClientRect();
23 const targetMid = targetBounds.left + (targetBounds.width / 2);
24 const targetLeft = targetMid - (domBounds.width / 2);
25 dom.style.top = (targetBounds.bottom + 6) + 'px';
26 dom.style.left = targetLeft + 'px';
29 insert(children: EditorUiElement[]) {
30 this.addChildren(...children);
31 const dom = this.getDOMElement();
32 dom.append(...children.map(child => child.getDOMElement()));
36 const children = this.getChildren();
37 for (const child of children) {
38 child.getDOMElement().remove();
40 this.removeChildren(...children);