]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/ui/index.ts
Lexical: Added ui container type
[bookstack] / resources / js / wysiwyg / ui / index.ts
1 import {
2     $getSelection,
3     COMMAND_PRIORITY_LOW,
4     LexicalEditor,
5     SELECTION_CHANGE_COMMAND
6 } from "lexical";
7 import {getMainEditorFullToolbar} from "./toolbars";
8
9 export function buildEditorUI(element: HTMLElement, editor: LexicalEditor) {
10     const toolbar = getMainEditorFullToolbar();
11     toolbar.setContext({editor});
12     element.before(toolbar.getDOMElement());
13
14     // Update button states on editor selection change
15     editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
16         const selection = $getSelection();
17         toolbar.updateState({editor, selection});
18         return false;
19     }, COMMAND_PRIORITY_LOW);
20 }