X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/6be2d3f28c2d59987dba8b2b38714a7b9aae7c6b..ac0a070fc81e3c7c3b81b1782dfaeb5a33fbd476:/resources/assets/js/components/markdown-editor.js diff --git a/resources/assets/js/components/markdown-editor.js b/resources/assets/js/components/markdown-editor.js index b8e2bc040..5fa16ef6e 100644 --- a/resources/assets/js/components/markdown-editor.js +++ b/resources/assets/js/components/markdown-editor.js @@ -64,13 +64,26 @@ class MarkdownEditor { let action = button.getAttribute('data-action'); if (action === 'insertImage') this.actionInsertImage(); if (action === 'insertLink') this.actionShowLinkSelector(); - if (action === 'insertDrawing' && event.ctrlKey) { + if (action === 'insertDrawing' && (event.ctrlKey || event.metaKey)) { this.actionShowImageManager(); return; } if (action === 'insertDrawing') this.actionStartDrawing(); }); + // Mobile section toggling + this.elem.addEventListener('click', event => { + const toolbarLabel = event.target.closest('.editor-toolbar-label'); + if (!toolbarLabel) return; + + const currentActiveSections = this.elem.querySelectorAll('.markdown-editor-wrap'); + for (let activeElem of currentActiveSections) { + activeElem.classList.remove('active'); + } + + toolbarLabel.closest('.markdown-editor-wrap').classList.add('active'); + }); + window.$events.listen('editor-markdown-update', value => { this.cm.setValue(value); this.updateAndRender(); @@ -167,9 +180,20 @@ class MarkdownEditor { // Handle image paste cm.on('paste', (cm, event) => { - if (!event.clipboardData || !event.clipboardData.items) return; - for (let i = 0; i < event.clipboardData.items.length; i++) { - uploadImage(event.clipboardData.items[i].getAsFile()); + const clipboardItems = event.clipboardData.items; + if (!event.clipboardData || !clipboardItems) return; + + // Don't handle if clipboard includes text content + for (let clipboardItem of clipboardItems) { + if (clipboardItem.type.includes('text/')) { + return; + } + } + + for (let clipboardItem of clipboardItems) { + if (clipboardItem.type.includes("image")) { + uploadImage(clipboardItem.getAsFile()); + } } }); @@ -285,7 +309,7 @@ class MarkdownEditor { formData.append('file', file, remoteFilename); formData.append('uploaded_to', context.pageId); - window.$http.post('/images/gallery/upload', formData).then(resp => { + window.$http.post('/images/gallery', formData).then(resp => { const newContent = `[](${resp.data.url})`; replaceContent(placeHolderText, newContent); }).catch(err => { @@ -353,7 +377,7 @@ class MarkdownEditor { uploaded_to: Number(document.getElementById('page-editor').getAttribute('page-id')) }; - window.$http.post(window.baseUrl('/images/drawing/upload'), data).then(resp => { + window.$http.post(window.baseUrl('/images/drawio'), data).then(resp => { this.insertDrawing(resp.data, cursorPos); DrawIO.close(); }).catch(err => { @@ -381,9 +405,7 @@ class MarkdownEditor { const drawingId = imgContainer.getAttribute('drawio-diagram'); DrawIO.show(() => { - return window.$http.get(window.baseUrl(`/images/base64/${drawingId}`)).then(resp => { - return `data:image/png;base64,${resp.data.content}`; - }); + return DrawIO.load(drawingId); }, (pngData) => { let data = { @@ -391,7 +413,7 @@ class MarkdownEditor { uploaded_to: Number(document.getElementById('page-editor').getAttribute('page-id')) }; - window.$http.post(window.baseUrl(`/images/drawing/upload`), data).then(resp => { + window.$http.post(window.baseUrl(`/images/drawio`), data).then(resp => { let newText = `