mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-03 14:23:42 +08:00
c7c0df0964
Added new options that sits on the context, for things needed but not for the core editor, which are defined out of the editor (drawio URL, error message text, pageId etc...)
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import {LexicalEditor} from "lexical";
|
|
import {
|
|
getCodeToolbarContent,
|
|
getImageToolbarContent,
|
|
getLinkToolbarContent,
|
|
getMainEditorFullToolbar
|
|
} from "./toolbars";
|
|
import {EditorUIManager} from "./framework/manager";
|
|
import {image as imageFormDefinition, link as linkFormDefinition, source as sourceFormDefinition} from "./defaults/form-definitions";
|
|
import {ImageDecorator} from "./decorators/image";
|
|
import {EditorUiContext} from "./framework/core";
|
|
import {CodeBlockDecorator} from "./decorators/code-block";
|
|
import {DiagramDecorator} from "./decorators/diagram";
|
|
|
|
export function buildEditorUI(container: HTMLElement, element: HTMLElement, editor: LexicalEditor, options: Record<string, any>): EditorUiContext {
|
|
const manager = new EditorUIManager();
|
|
const context: EditorUiContext = {
|
|
editor,
|
|
containerDOM: container,
|
|
editorDOM: element,
|
|
manager,
|
|
translate: (text: string): string => text,
|
|
lastSelection: null,
|
|
options,
|
|
};
|
|
manager.setContext(context);
|
|
|
|
// Create primary toolbar
|
|
manager.setToolbar(getMainEditorFullToolbar());
|
|
|
|
// Register modals
|
|
manager.registerModal('link', {
|
|
title: 'Insert/Edit link',
|
|
form: linkFormDefinition,
|
|
});
|
|
manager.registerModal('image', {
|
|
title: 'Insert/Edit Image',
|
|
form: imageFormDefinition
|
|
});
|
|
manager.registerModal('source', {
|
|
title: 'Source code',
|
|
form: sourceFormDefinition,
|
|
});
|
|
|
|
// Register context toolbars
|
|
manager.registerContextToolbar('image', {
|
|
selector: 'img:not([drawio-diagram] img)',
|
|
content: getImageToolbarContent(),
|
|
displayTargetLocator(originalTarget: HTMLElement) {
|
|
return originalTarget.closest('a') || originalTarget;
|
|
}
|
|
});
|
|
manager.registerContextToolbar('link', {
|
|
selector: 'a',
|
|
content: getLinkToolbarContent(),
|
|
});
|
|
manager.registerContextToolbar('code', {
|
|
selector: '.editor-code-block-wrap',
|
|
content: getCodeToolbarContent(),
|
|
});
|
|
|
|
// Register image decorator listener
|
|
manager.registerDecoratorType('image', ImageDecorator);
|
|
manager.registerDecoratorType('code', CodeBlockDecorator);
|
|
manager.registerDecoratorType('diagram', DiagramDecorator);
|
|
|
|
return context;
|
|
} |