]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/wysiwyg-editor.js
Lexical: Fixed issues with content not saving
[bookstack] / resources / js / components / wysiwyg-editor.js
index 2f0e660b19fc778644a6554a76c9db1c0bbaad58..5a25819006913a5630d4664b5464e8420e5c8919 100644 (file)
@@ -7,9 +7,45 @@ export class WysiwygEditor extends Component {
         this.editContainer = this.$refs.editContainer;
         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.input.value;
-            wysiwyg.createPageEditorInstance(this.editContainer, editorContent);
+            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(),
         };
     }