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,
13 lastSelection: BaseSelection|null,
16 export abstract class EditorUiElement {
17 protected dom: HTMLElement|null = null;
18 private context: EditorUiContext|null = null;
20 protected abstract buildDOM(): HTMLElement;
22 setContext(context: EditorUiContext): void {
23 this.context = context;
26 getContext(): EditorUiContext {
27 if (this.context === null) {
28 throw new Error('Attempted to use EditorUIContext before it has been set');
34 getDOMElement(): HTMLElement {
36 this.dom = this.buildDOM();
43 return this.getContext().translate(text);
46 updateState(state: EditorUiStateUpdate): void {