mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-11-03 02:13:16 +03:00
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.
This commit is contained in:
39
resources/js/wysiwyg/ui/framework/base-elements.ts
Normal file
39
resources/js/wysiwyg/ui/framework/base-elements.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user