2023-04-18 23:20:02 +02:00
|
|
|
import {build as buildEditorConfig} from '../wysiwyg/config';
|
|
|
|
import {Component} from './component';
|
2019-08-11 21:04:43 +02:00
|
|
|
|
2022-11-16 14:04:22 +01:00
|
|
|
export class WysiwygEditor extends Component {
|
2017-09-23 13:24:06 +02:00
|
|
|
|
2020-07-05 22:18:17 +02:00
|
|
|
setup() {
|
|
|
|
this.elem = this.$el;
|
|
|
|
|
|
|
|
this.pageId = this.$opts.pageId;
|
|
|
|
this.textDirection = this.$opts.textDirection;
|
2020-04-11 16:48:08 +02:00
|
|
|
this.isDarkMode = document.documentElement.classList.contains('dark-mode');
|
2018-04-01 14:21:11 +02:00
|
|
|
|
2022-02-06 00:15:58 +01:00
|
|
|
this.tinyMceConfig = buildEditorConfig({
|
2022-02-06 22:17:08 +01:00
|
|
|
language: this.$opts.language,
|
2022-02-06 00:15:58 +01: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-06 22:17:08 +01:00
|
|
|
},
|
|
|
|
translationMap: window.editor_translations,
|
2022-02-06 00:15:58 +01:00
|
|
|
});
|
2018-04-01 14:21:11 +02:00
|
|
|
|
2020-07-05 22:18:17 +02:00
|
|
|
window.$events.emitPublic(this.elem, 'editor-tinymce::pre-init', {config: this.tinyMceConfig});
|
2023-02-23 13:30:27 +01:00
|
|
|
window.tinymce.init(this.tinyMceConfig).then(editors => {
|
|
|
|
this.editor = editors[0];
|
|
|
|
});
|
2018-04-01 14:21:11 +02:00
|
|
|
}
|
|
|
|
|
2022-02-06 00:15:58 +01:00
|
|
|
getDrawIoUrl() {
|
2020-04-05 18:27:16 +02:00
|
|
|
const drawioUrlElem = document.querySelector('[drawio-url]');
|
|
|
|
if (drawioUrlElem) {
|
2022-02-06 00:15:58 +01:00
|
|
|
return drawioUrlElem.getAttribute('drawio-url');
|
2018-04-01 14:21:11 +02:00
|
|
|
}
|
2022-02-06 00:15:58 +01:00
|
|
|
return '';
|
2017-09-23 13:24:06 +02:00
|
|
|
}
|
|
|
|
|
2023-02-23 13:30:27 +01:00
|
|
|
/**
|
|
|
|
* Get the content of this editor.
|
|
|
|
* Used by the parent page editor component.
|
|
|
|
* @return {{html: String}}
|
|
|
|
*/
|
|
|
|
getContent() {
|
|
|
|
return {
|
2023-04-18 23:20:02 +02:00
|
|
|
html: this.editor.getContent(),
|
2023-02-23 13:30:27 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-18 23:20:02 +02:00
|
|
|
}
|