From: Dan Brown Date: Mon, 23 May 2022 13:38:34 +0000 (+0100) Subject: Updated markdown editor to use svg drawio images X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/641a26cdf7bcf68bae7dc38597dd539d19bf5ee7?ds=inline Updated markdown editor to use svg drawio images - Also tweaked page editor to not error when the current user does not have permission to change editor type. --- diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index 71a56af55..8d117870c 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -462,7 +462,7 @@ class MarkdownEditor { } insertDrawing(image, originalCursor) { - const newText = `
`; + const newText = DrawIO.buildDrawingContentHtml(image); this.cm.focus(); this.cm.replaceSelection(newText); this.cm.setCursor(originalCursor.line, originalCursor.ch + newText.length); @@ -488,13 +488,14 @@ class MarkdownEditor { }; window.$http.post("/images/drawio", data).then(resp => { - let newText = `
`; - let newContent = this.cm.getValue().split('\n').map(line => { - if (line.indexOf(`drawio-diagram="${drawingId}"`) !== -1) { - return newText; - } - return line; + const image = resp.data; + const newText = DrawIO.buildDrawingContentHtml(image); + + const newContent = this.cm.getValue().split('\n').map(line => { + const isDrawing = line.includes(`drawio-diagram="${drawingId}"`); + return isDrawing ? newText : line; }).join('\n'); + this.cm.setValue(newContent); this.cm.setCursor(cursorPos); this.cm.focus(); diff --git a/resources/js/components/page-editor.js b/resources/js/components/page-editor.js index ce123e987..f6e52c707 100644 --- a/resources/js/components/page-editor.js +++ b/resources/js/components/page-editor.js @@ -24,7 +24,7 @@ class PageEditor { this.draftDisplayIcon = this.$refs.draftDisplayIcon; this.changelogInput = this.$refs.changelogInput; this.changelogDisplay = this.$refs.changelogDisplay; - this.changeEditorButtons = this.$manyRefs.changeEditor; + this.changeEditorButtons = this.$manyRefs.changeEditor || []; this.switchDialogContainer = this.$refs.switchDialog; // Translations