mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-02 14:11:10 +08:00
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;
|
||
|
}
|