diff --git a/modules/miks-clipboard.js b/modules/miks-clipboard.js index f387a78..f9f31cc 100644 --- a/modules/miks-clipboard.js +++ b/modules/miks-clipboard.js @@ -1,5 +1,6 @@ import Quill from "quill"; import EditorEvents from "../editor-events"; +import normalizeUrl from "normalize-url"; const Clipboard = Quill.import("modules/clipboard"); const Delta = Quill.import("delta"); @@ -72,15 +73,17 @@ class MiksClipboard extends Clipboard { let func; let imageHandlers = this.editor.imageHandlers; - if(imageHandlers.isDataURI(src)) { + let normalizedSrc = normalizeUrl(src) + + if(imageHandlers.isDataURI(normalizedSrc)) { func = this.editor.options.image.handlers.imageDataURIUpload; - }else if(imageHandlers.isImageSrc(src)) { + }else if(imageHandlers.isImageSrc(normalizedSrc)) { func = this.editor.options.image.handlers.imageSrcUpload; } else { // Local files // Browser has no access to local files // So skip this file and send a message to editor - this.editor.dispatchEvent(EditorEvents.imageSkipped, src); + this.editor.dispatchEvent(EditorEvents.imageSkipped, normalizedSrc); } if(func) { @@ -90,9 +93,9 @@ class MiksClipboard extends Clipboard { let deltaId = imageHandlers.insertImagePlaceholder(placeholderId, index); setTimeout(() => { - imageHandlers.previewInImagePlaceholder(placeholderId, src); + imageHandlers.previewInImagePlaceholder(placeholderId, normalizedSrc); - func(src) + func(normalizedSrc) .then( (imageUrl) => { imageHandlers.replaceImagePlaceholderWithImage(placeholderId, deltaId, imageUrl, appliedDeltas); diff --git a/package-lock.json b/package-lock.json index 8092ce6..7f9ce27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5125,6 +5125,11 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, + "normalize-url": { + "version": "5.0.0", + "resolved": "https://registry.npm.taobao.org/normalize-url/download/normalize-url-5.0.0.tgz", + "integrity": "sha1-9GydwgZwSV5OGPvRtDluQdGZ9jw=" + }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", diff --git a/package.json b/package.json index 0d4f87c..79f7968 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "homepage": "https://github.com/we-miks/collaborative-editor#readme", "dependencies": { "lodash": "^4.17.15", + "normalize-url": "^5.0.0", "quill": "^1.3.7", "quill-image-drop-and-paste": "^1.0.4", "reconnecting-websocket": "^4.4.0",