2022-02-06 07:15:58 +08:00
|
|
|
import {build as buildEditorConfig} from "../wysiwyg/config";
|
2022-11-16 21:04:22 +08:00
|
|
|
import {Component} from "./component";
|
2019-08-12 03:04:43 +08:00
|
|
|
|
2022-11-16 21:04:22 +08:00
|
|
|
export class WysiwygEditor extends Component {
|
2017-09-23 19:24:06 +08:00
|
|
|
|
2020-07-06 04:18:17 +08:00
|
|
|
setup() {
|
|
|
|
this.elem = this.$el;
|
|
|
|
|
|
|
|
this.pageId = this.$opts.pageId;
|
|
|
|
this.textDirection = this.$opts.textDirection;
|
2020-04-11 22:48:08 +08:00
|
|
|
this.isDarkMode = document.documentElement.classList.contains('dark-mode');
|
2018-04-01 20:21:11 +08:00
|
|
|
|
2022-02-06 07:15:58 +08:00
|
|
|
this.tinyMceConfig = buildEditorConfig({
|
2022-02-07 05:17:08 +08:00
|
|
|
language: this.$opts.language,
|
2022-02-06 07:15:58 +08:00
|
|
|
containerElement: this.elem,
|
|
|
|
darkMode: this.isDarkMode,
|
|
|
|
textDirection: this.textDirection,
|
|
|
|
drawioUrl: this.getDrawIoUrl(),
|
|
|
|
pageId: Number(this.pageId),
|
|
|
|
translations: {
|
|
|
|
imageUploadErrorText: this.$opts.imageUploadErrorText,
|
|
|
|
serverUploadLimitText: this.$opts.serverUploadLimitText,
|
2022-02-07 05:17:08 +08:00
|
|
|
},
|
|
|
|
translationMap: window.editor_translations,
|
2022-02-06 07:15:58 +08:00
|
|
|
});
|
2018-04-01 20:21:11 +08:00
|
|
|
|
2020-07-06 04:18:17 +08:00
|
|
|
window.$events.emitPublic(this.elem, 'editor-tinymce::pre-init', {config: this.tinyMceConfig});
|
2018-04-01 20:21:11 +08:00
|
|
|
window.tinymce.init(this.tinyMceConfig);
|
|
|
|
}
|
|
|
|
|
2022-02-06 07:15:58 +08:00
|
|
|
getDrawIoUrl() {
|
2020-04-06 00:27:16 +08:00
|
|
|
const drawioUrlElem = document.querySelector('[drawio-url]');
|
|
|
|
if (drawioUrlElem) {
|
2022-02-06 07:15:58 +08:00
|
|
|
return drawioUrlElem.getAttribute('drawio-url');
|
2018-04-01 20:21:11 +08:00
|
|
|
}
|
2022-02-06 07:15:58 +08:00
|
|
|
return '';
|
2017-09-23 19:24:06 +08:00
|
|
|
}
|
|
|
|
|
2022-11-16 21:04:22 +08:00
|
|
|
}
|