mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-12-02 13:58:57 +08:00
b1c489090e
Also added some basic context toolbar styling
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import {LexicalEditor} from "lexical";
|
|
import {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";
|
|
|
|
export function buildEditorUI(element: HTMLElement, editor: LexicalEditor) {
|
|
const manager = new EditorUIManager();
|
|
const context: EditorUiContext = {
|
|
editor,
|
|
editorDOM: element,
|
|
manager,
|
|
translate: (text: string): string => text,
|
|
lastSelection: null,
|
|
};
|
|
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',
|
|
content: getImageToolbarContent(),
|
|
displayTargetLocator(originalTarget: HTMLElement) {
|
|
return originalTarget.closest('a') || originalTarget;
|
|
}
|
|
});
|
|
manager.registerContextToolbar('link', {
|
|
selector: 'a',
|
|
content: getLinkToolbarContent(),
|
|
});
|
|
|
|
// Register image decorator listener
|
|
manager.registerDecoratorType('image', ImageDecorator);
|
|
} |