]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/drop-paste-handling.js
Update docker-compose.yml
[bookstack] / resources / js / wysiwyg / drop-paste-handling.js
index 33078cd1d5687b74fb877ef8dd2719dd4e0f59ff..172ad970f0de8a5e51f495a012b88bf157107b85 100644 (file)
@@ -61,7 +61,7 @@ function paste(editor, options, event) {
                 editor.dom.replace(newEl, id);
             }).catch(err => {
                 editor.dom.remove(id);
-                window.$events.emit('error', options.translations.imageUploadErrorText);
+                window.$events.error(err?.data?.message || options.translations.imageUploadErrorText);
                 console.error(err);
             });
         }, 10);
@@ -149,11 +149,26 @@ function drop(editor, options, event) {
     wrap = null;
 }
 
+/**
+ * @param {Editor} editor
+ * @param {DragEvent} event
+ */
+function dragOver(editor, event) {
+    // This custom handling essentially emulates the default TinyMCE behaviour while allowing us
+    // to specifically call preventDefault on the event to allow the drop of custom elements.
+    event.preventDefault();
+    editor.focus();
+    const rangeUtils = window.tinymce.dom.RangeUtils;
+    const range = rangeUtils.getCaretRangeFromPoint(event.clientX ?? 0, event.clientY ?? 0, editor.getDoc());
+    editor.selection.setRng(range);
+}
+
 /**
  * @param {Editor} editor
  * @param {WysiwygConfigOptions} options
  */
 export function listenForDragAndPaste(editor, options) {
+    editor.on('dragover', event => dragOver(editor, event));
     editor.on('dragstart', () => dragStart(editor));
     editor.on('drop', event => drop(editor, options, event));
     editor.on('paste', event => paste(editor, options, event));