From ad48cd3e48ab5b16932d8c38032b80af619f525f Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 13 Sep 2020 18:29:48 +0100 Subject: [PATCH] Continued implementation of attachment drag+drop Cannot get working in chrome reliably due to conflicting handling of events and drag+drop API. Getting attachment drop working breaks other parts of TinyMCE. Implementing current work as should still work for MD editor and within FireFox. Related to #1460 --- app/Uploads/Attachment.php | 15 ++++++++++++++- resources/js/components/markdown-editor.js | 2 +- resources/js/components/sortable-list.js | 2 -- resources/js/components/wysiwyg-editor.js | 2 +- .../views/attachments/manager-list.blade.php | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Uploads/Attachment.php b/app/Uploads/Attachment.php index 3367594ef..66c032be5 100644 --- a/app/Uploads/Attachment.php +++ b/app/Uploads/Attachment.php @@ -3,6 +3,13 @@ use BookStack\Entities\Page; use BookStack\Ownable; +/** + * @property int id + * @property string name + * @property string path + * @property string extension + * @property bool external + */ class Attachment extends Ownable { protected $fillable = ['name', 'order']; @@ -39,13 +46,19 @@ class Attachment extends Ownable return url('/attachments/' . $this->id); } + /** + * Generate a HTML link to this attachment. + */ public function htmlLink(): string { return ''.e($this->name).''; } + /** + * Generate a markdown link to this attachment. + */ public function markdownLink(): string { - + return '['. $this->name .']('. $this->getUrl() .')'; } } diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index 6e646c72b..5ffe4ef4d 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -256,7 +256,7 @@ class MarkdownEditor { } const clipboard = new Clipboard(event.dataTransfer); - if (clipboard.hasItems()) { + if (clipboard.hasItems() && clipboard.getImages().length > 0) { const cursorPos = cm.coordsChar({left: event.pageX, top: event.pageY}); cm.setCursor(cursorPos); event.stopPropagation(); diff --git a/resources/js/components/sortable-list.js b/resources/js/components/sortable-list.js index db50352b8..0af0e11c9 100644 --- a/resources/js/components/sortable-list.js +++ b/resources/js/components/sortable-list.js @@ -21,11 +21,9 @@ class SortableList { this.$emit('sort', {ids: sortable.toArray()}); }, setData(dataTransferItem, dragEl) { - console.log('cat'); const jsonContent = dragEl.getAttribute('data-drag-content'); if (jsonContent) { const contentByType = JSON.parse(jsonContent); - dataTransferItem.setData('bookstack/json', jsonContent); for (const [type, content] of Object.entries(contentByType)) { dataTransferItem.setData(type, content); } diff --git a/resources/js/components/wysiwyg-editor.js b/resources/js/components/wysiwyg-editor.js index 92a678fbd..05897c250 100644 --- a/resources/js/components/wysiwyg-editor.js +++ b/resources/js/components/wysiwyg-editor.js @@ -638,8 +638,8 @@ class WysiwygEditor { }); + // Custom drop event handling editor.on('drop', function (event) { - console.log('drop') let dom = editor.dom, rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint(event.clientX, event.clientY, editor.getDoc()); diff --git a/resources/views/attachments/manager-list.blade.php b/resources/views/attachments/manager-list.blade.php index 671864a3b..30307ff41 100644 --- a/resources/views/attachments/manager-list.blade.php +++ b/resources/views/attachments/manager-list.blade.php @@ -3,7 +3,7 @@
@icon('grip')