]> BookStack Code Mirror - bookstack/blob - resources/js/components/wysiwyg-editor.js
f6ecb368a3df116973b321141538446f1c57bf68
[bookstack] / resources / js / components / wysiwyg-editor.js
1 import {build as buildEditorConfig} from "../wysiwyg/config";
2
3 class WysiwygEditor {
4
5     setup() {
6         this.elem = this.$el;
7
8         this.pageId = this.$opts.pageId;
9         this.textDirection = this.$opts.textDirection;
10         this.isDarkMode = document.documentElement.classList.contains('dark-mode');
11
12         this.tinyMceConfig = buildEditorConfig({
13             containerElement: this.elem,
14             darkMode: this.isDarkMode,
15             textDirection: this.textDirection,
16             drawioUrl: this.getDrawIoUrl(),
17             pageId: Number(this.pageId),
18             translations: {
19                 imageUploadErrorText: this.$opts.imageUploadErrorText,
20                 serverUploadLimitText: this.$opts.serverUploadLimitText,
21             }
22         });
23
24         window.$events.emitPublic(this.elem, 'editor-tinymce::pre-init', {config: this.tinyMceConfig});
25         window.tinymce.init(this.tinyMceConfig);
26     }
27
28     getDrawIoUrl() {
29         const drawioUrlElem = document.querySelector('[drawio-url]');
30         if (drawioUrlElem) {
31             return drawioUrlElem.getAttribute('drawio-url');
32         }
33         return '';
34     }
35
36 }
37
38 export default WysiwygEditor;