BookStack/resources/js/wysiwyg/ui/framework/base-elements.ts
Dan Brown dc1a40ea74
Lexical: Added ui container type
Structured UI logical to be fairly standard and mostly covered via
a base class that handles context and core dom work.
2024-05-29 20:38:31 +01:00

39 lines
904 B
TypeScript

import {BaseSelection, LexicalEditor} from "lexical";
export type EditorUiStateUpdate = {
editor: LexicalEditor,
selection: BaseSelection|null,
};
export type EditorUiContext = {
editor: LexicalEditor,
};
export abstract class EditorUiElement {
protected dom: HTMLElement|null = null;
private context: EditorUiContext|null = null;
protected abstract buildDOM(): HTMLElement;
setContext(context: EditorUiContext): void {
this.context = context;
}
getContext(): EditorUiContext {
if (this.context === null) {
throw new Error('Attempted to use EditorUIContext before it has been set');
}
return this.context;
}
getDOMElement(): HTMLElement {
if (!this.dom) {
this.dom = this.buildDOM();
}
return this.dom;
}
abstract updateState(state: EditorUiStateUpdate): void;
}