quill-image-drop-module
Advanced tools
Comparing version 1.0.2 to 1.0.3
# Changelog | ||
## v1.0.3 - March 29, 2017 | ||
- Drop images at mouse coordinates instead of last caret position ([Issue #2](https://github.com/kensnyder/quill-image-drop-module/issues/2)) | ||
## v1.0.2 - March 25, 2017 | ||
@@ -4,0 +8,0 @@ |
(function(){var exports={}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function e(e,t){for(var a=0;a<t.length;a++){var i=t[a];i.enumerable=i.enumerable||false;i.configurable=true;if("value"in i)i.writable=true;Object.defineProperty(e,i.key,i)}}return function(t,a,i){if(a)e(t.prototype,a);if(i)e(t,i);return t}}();function _classCallCheck(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}var ImageDrop=exports.ImageDrop=function(){function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,e);this.quill=t;this.handleDrop=this.handleDrop.bind(this);this.handlePaste=this.handlePaste.bind(this);this.quill.root.addEventListener("drop",this.handleDrop,false);this.quill.root.addEventListener("paste",this.handlePaste,false)}_createClass(e,[{key:"handleDrop",value:function e(t){t.preventDefault();if(t.dataTransfer&&t.dataTransfer.files&&t.dataTransfer.files.length){this.readFiles(t.dataTransfer.files,this.insert.bind(this))}}},{key:"handlePaste",value:function e(t){var a=this;if(t.clipboardData&&t.clipboardData.items&&t.clipboardData.items.length){this.readFiles(t.clipboardData.items,function(e){var t=a.quill.getSelection();if(t){}else{setTimeout(function(){return a.insert(e)},0)}})}}},{key:"insert",value:function e(t){var a=(this.quill.getSelection()||{}).index||this.quill.getLength();this.quill.insertEmbed(a,"image",t,"user")}},{key:"readFiles",value:function e(t,a){[].forEach.call(t,function(e){if(!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)){return}var t=new FileReader;t.onload=function(e){a(e.target.result)};var i=e.getAsFile?e.getAsFile():e;if(i instanceof Blob){t.readAsDataURL(i)}})}}]);return e}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function e(e,t){for(var a=0;a<t.length;a++){var i=t[a];i.enumerable=i.enumerable||false;i.configurable=true;if("value"in i)i.writable=true;Object.defineProperty(e,i.key,i)}}return function(t,a,i){if(a)e(t.prototype,a);if(i)e(t,i);return t}}();function _classCallCheck(e,t){if(!(e instanceof t)){throw new TypeError("Cannot call a class as a function")}}var ImageDrop=exports.ImageDrop=function(){function e(t){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,e);this.quill=t;this.handleDrop=this.handleDrop.bind(this);this.handlePaste=this.handlePaste.bind(this);this.quill.root.addEventListener("drop",this.handleDrop,false);this.quill.root.addEventListener("paste",this.handlePaste,false)}_createClass(e,[{key:"handleDrop",value:function e(t){t.preventDefault();if(t.dataTransfer&&t.dataTransfer.files&&t.dataTransfer.files.length){if(document.caretRangeFromPoint){var a=document.getSelection();var i=document.caretRangeFromPoint(t.clientX,t.clientY);if(a&&i){a.setBaseAndExtent(i.startContainer,i.startOffset,i.startContainer,i.startOffset)}}this.readFiles(t.dataTransfer.files,this.insert.bind(this))}}},{key:"handlePaste",value:function e(t){var a=this;if(t.clipboardData&&t.clipboardData.items&&t.clipboardData.items.length){this.readFiles(t.clipboardData.items,function(e){var t=a.quill.getSelection();if(t){}else{setTimeout(function(){return a.insert(e)},0)}})}}},{key:"insert",value:function e(t){var a=(this.quill.getSelection()||{}).index||this.quill.getLength();this.quill.insertEmbed(a,"image",t,"user")}},{key:"readFiles",value:function e(t,a){[].forEach.call(t,function(e){if(!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)){return}var t=new FileReader;t.onload=function(e){a(e.target.result)};var i=e.getAsFile?e.getAsFile():e;if(i instanceof Blob){t.readAsDataURL(i)}})}}]);return e}(); | ||
window.Quill.register('modules/imageDrop',exports.ImageDrop);})(); |
@@ -31,2 +31,9 @@ /** | ||
if (evt.dataTransfer && evt.dataTransfer.files && evt.dataTransfer.files.length) { | ||
if (document.caretRangeFromPoint) { | ||
const selection = document.getSelection(); | ||
const range = document.caretRangeFromPoint(evt.clientX, evt.clientY); | ||
if (selection && range) { | ||
selection.setBaseAndExtent(range.startContainer, range.startOffset, range.startContainer, range.startOffset); | ||
} | ||
} | ||
this.readFiles(evt.dataTransfer.files, this.insert.bind(this)); | ||
@@ -33,0 +40,0 @@ } |
{ | ||
"name": "quill-image-drop-module", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A module for Quill rich text editor to allow images to be pasted and drag/dropped into the editor.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,2 +31,9 @@ /** | ||
if (evt.dataTransfer && evt.dataTransfer.files && evt.dataTransfer.files.length) { | ||
if (document.caretRangeFromPoint) { | ||
const selection = document.getSelection(); | ||
const range = document.caretRangeFromPoint(evt.clientX, evt.clientY); | ||
if (selection && range) { | ||
selection.setBaseAndExtent(range.startContainer, range.startOffset, range.startContainer, range.startOffset); | ||
} | ||
} | ||
this.readFiles(evt.dataTransfer.files, this.insert.bind(this)); | ||
@@ -33,0 +40,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11225
196