X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c2ecbf071ffddb3f23dd535495ea361954a5ee57..refs/heads/development:/resources/js/components/wysiwyg-editor.js diff --git a/resources/js/components/wysiwyg-editor.js b/resources/js/components/wysiwyg-editor.js index bdcdd5c51..5a2581900 100644 --- a/resources/js/components/wysiwyg-editor.js +++ b/resources/js/components/wysiwyg-editor.js @@ -5,11 +5,47 @@ export class WysiwygEditor extends Component { setup() { this.elem = this.$el; this.editContainer = this.$refs.editContainer; - this.editContent = this.$refs.editContent; + this.input = this.$refs.input; + + /** @var {SimpleWysiwygEditorInterface|null} */ + this.editor = null; + + const translations = { + ...window.editor_translations, + imageUploadErrorText: this.$opts.imageUploadErrorText, + serverUploadLimitText: this.$opts.serverUploadLimitText, + }; window.importVersioned('wysiwyg').then(wysiwyg => { - const editorContent = this.editContent.textContent; - wysiwyg.createPageEditorInstance(this.editContainer, editorContent); + const editorContent = this.input.value; + this.editor = wysiwyg.createPageEditorInstance(this.editContainer, editorContent, { + drawioUrl: this.getDrawIoUrl(), + pageId: Number(this.$opts.pageId), + darkMode: document.documentElement.classList.contains('dark-mode'), + textDirection: this.$opts.textDirection, + translations, + }); + window.wysiwyg = this.editor; + }); + + let handlingFormSubmit = false; + this.input.form.addEventListener('submit', event => { + if (!this.editor) { + return; + } + + if (!handlingFormSubmit) { + event.preventDefault(); + handlingFormSubmit = true; + this.editor.getContentAsHtml().then(html => { + this.input.value = html; + setTimeout(() => { + this.input.form.requestSubmit(); + }, 5); + }); + } else { + handlingFormSubmit = false; + } }); } @@ -24,12 +60,11 @@ export class WysiwygEditor extends Component { /** * Get the content of this editor. * Used by the parent page editor component. - * @return {{html: String}} + * @return {Promise<{html: String}>} */ - getContent() { - // TODO - Update + async getContent() { return { - html: this.editor.getContent(), + html: await this.editor.getContentAsHtml(), }; }