2024-05-28 13:04:48 -04:00
|
|
|
import {
|
|
|
|
$getSelection,
|
|
|
|
COMMAND_PRIORITY_LOW,
|
|
|
|
LexicalEditor,
|
|
|
|
SELECTION_CHANGE_COMMAND
|
|
|
|
} from "lexical";
|
2024-05-29 15:38:31 -04:00
|
|
|
import {getMainEditorFullToolbar} from "./toolbars";
|
2024-05-28 13:04:48 -04:00
|
|
|
|
|
|
|
export function buildEditorUI(element: HTMLElement, editor: LexicalEditor) {
|
2024-05-29 15:38:31 -04:00
|
|
|
const toolbar = getMainEditorFullToolbar();
|
|
|
|
toolbar.setContext({editor});
|
|
|
|
element.before(toolbar.getDOMElement());
|
2024-05-28 13:04:48 -04:00
|
|
|
|
|
|
|
// Update button states on editor selection change
|
|
|
|
editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
|
|
|
const selection = $getSelection();
|
2024-05-29 15:38:31 -04:00
|
|
|
toolbar.updateState({editor, selection});
|
2024-05-28 13:04:48 -04:00
|
|
|
return false;
|
|
|
|
}, COMMAND_PRIORITY_LOW);
|
|
|
|
}
|