mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-02 13:58:57 +08:00
dc1a40ea74
Structured UI logical to be fairly standard and mostly covered via a base class that handles context and core dom work.
39 lines
904 B
TypeScript
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;
|
|
} |