BookStack/resources/js/wysiwyg/ui/index.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

20 lines
641 B
TypeScript

import {
$getSelection,
COMMAND_PRIORITY_LOW,
LexicalEditor,
SELECTION_CHANGE_COMMAND
} from "lexical";
import {getMainEditorFullToolbar} from "./toolbars";
export function buildEditorUI(element: HTMLElement, editor: LexicalEditor) {
const toolbar = getMainEditorFullToolbar();
toolbar.setContext({editor});
element.before(toolbar.getDOMElement());
// Update button states on editor selection change
editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
const selection = $getSelection();
toolbar.updateState({editor, selection});
return false;
}, COMMAND_PRIORITY_LOW);
}