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.
20 lines
641 B
TypeScript
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);
|
|
} |