1 import {BaseSelection, LexicalEditor} from "lexical";
2 import {EditorUIManager} from "./manager";
4 export type EditorUiStateUpdate = {
6 selection: BaseSelection|null,
9 export type EditorUiContext = {
10 editor: LexicalEditor,
11 translate: (text: string) => string,
12 manager: EditorUIManager,
15 export abstract class EditorUiElement {
16 protected dom: HTMLElement|null = null;
17 private context: EditorUiContext|null = null;
19 protected abstract buildDOM(): HTMLElement;
21 setContext(context: EditorUiContext): void {
22 this.context = context;
25 getContext(): EditorUiContext {
26 if (this.context === null) {
27 throw new Error('Attempted to use EditorUIContext before it has been set');
33 getDOMElement(): HTMLElement {
35 this.dom = this.buildDOM();
42 return this.getContext().translate(text);
45 updateState(state: EditorUiStateUpdate): void {