Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quill-image-uploader

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quill-image-uploader - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

.vscode/settings.json

2

dist/demo.min.js

@@ -1,1 +0,1 @@

!function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=Quill},function(e,t,n){"use strict";n.r(t);var i=n(0),r=n.n(i),o=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),a=function e(t,n,i){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,n);if(void 0===r){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,i)}if("value"in r)return r.value;var a=r.get;return void 0!==a?a.call(i):void 0},l=r.a.import("blots/block"),u=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,l),o(t,[{key:"deleteAt",value:function(e,n){a(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deleteAt",this).call(this,e,2),this.cache={}}}],[{key:"create",value:function(e){var n=a(t.__proto__||Object.getPrototypeOf(t),"create",this).call(this,e);if(!0===e)return n;var i=document.createElement("img");return i.setAttribute("src",e),n.appendChild(i),n}},{key:"value",value:function(e){var t=e.dataset;return{src:t.src,custom:t.custom}}}]),t}();u.blotName="imageBlot",u.className="image-uploading",u.tagName="span",r.a.register({"formats/imageBlot":u}),n(3);var c=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),s=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.quill=t,this.options=n,this.range=null,this.options.upload,this.quill.getModule("toolbar").addHandler("image",this.selectLocalImage.bind(this))}return c(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=this.fileChanged.bind(this),document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame(function(){document.body.removeChild(e.fileHolder)})}},{key:"fileChanged",value:function(){var e=this,t=this.fileHolder.files[0],n=new FileReader;n.addEventListener("load",function(){var t=n.result;e.insertBase64Image(t)},!1),t&&n.readAsDataURL(t),this.options.upload(t).then(function(t){e.insertToEditor(t)},function(e){})}},{key:"insertBase64Image",value:function(e){var t=this.range;this.quill.insertEmbed(t.index,"imageBlot",""+e)}},{key:"insertToEditor",value:function(e){var t=this.range;this.quill.deleteText(t.index,2),this.quill.insertEmbed(t.index,"image",""+e),t.index++,this.quill.setSelection(t,"api")}}]),e}();t.default=s},function(e,t,n){"use strict";n.r(t);var i=n(0),r=n.n(i),o=n(1);r.a.register("modules/imageUploader",o.default),new r.a("#editor",{theme:"snow",modules:{toolbar:{container:[[{header:[1,2,3,!1]}],["bold","italic"],["clean"],["image"]]},imageUploader:{upload:function(e){return new Promise(function(e,t){setTimeout(function(){e("https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/JavaScript-logo.png/480px-JavaScript-logo.png")},3500)})}}}})},function(e,t){}]);
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=Quill},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n.n(o),i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=function e(t,n,o){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,n);if(void 0===r){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,o)}if("value"in r)return r.value;var a=r.get;return void 0!==a?a.call(o):void 0};function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var s=function(e){function t(){return l(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"deleteAt",value:function(e,n){a(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deleteAt",this).call(this,e,n),this.cache={}}}],[{key:"create",value:function(e){var n=a(t.__proto__||Object.getPrototypeOf(t),"create",this).call(this,e);if(!0===e)return n;var o=document.createElement("img");return o.setAttribute("src",e),n.appendChild(o),n}},{key:"value",value:function(e){var t=e.dataset;return{src:t.src,custom:t.custom}}}]),t}(r.a.import("blots/block"));s.blotName="imageBlot",s.className="image-uploading",s.tagName="span",r.a.register({"formats/imageBlot":s});n(3);var c=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();var f=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.quill=t,this.options=n,this.range=null,"function"!=typeof this.options.upload&&console.warn("[Missing config] upload function that returns a promise is required"),this.quill.getModule("toolbar").addHandler("image",this.selectLocalImage.bind(this))}return c(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=this.fileChanged.bind(this),document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:function(){var e=this,t=this.fileHolder.files[0],n=new FileReader;n.addEventListener("load",(function(){var t=n.result;e.insertBase64Image(t)}),!1),t&&n.readAsDataURL(t),this.options.upload(t).then((function(t){e.insertToEditor(t)}),(function(t){e.removeBase64Image(),console.warn(t)}))}},{key:"insertBase64Image",value:function(e){var t=this.range;this.quill.insertEmbed(t.index,"imageBlot",""+e)}},{key:"insertToEditor",value:function(e){var t=this.range;this.quill.deleteText(t.index,3),this.quill.insertEmbed(t.index,"image",""+e),t.index++,this.quill.setSelection(t,"api")}},{key:"removeBase64Image",value:function(){var e=this.range;this.quill.deleteText(e.index,3)}}]),e}();t.default=f},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n.n(o),i=n(1);r.a.debug("warn"),r.a.register("modules/imageUploader",i.default);var a=new r.a("#editor",{theme:"snow",modules:{toolbar:{container:[[{header:[1,2,3,!1]}],["bold","italic"],["clean"],["image"]]},imageUploader:{upload:function(e){var t=new FileReader;return new Promise((function(n,o){t.addEventListener("load",(function(){var e=t.result;setTimeout((function(){n(e)}),1500)}),!1),e?t.readAsDataURL(e):o("No file selected")}))}}}});a.on("text-change",(function(e,t,n){"api"==n?console.log("An API call triggered this change."):"user"==n&&console.log("A user action triggered this change."),console.log(t,e)})),a.on("selection-change",(function(e,t,n){if(e)if(0==e.length)console.log("User cursor is on",e.index);else{var o=a.getText(e.index,e.length);console.log("User has highlighted",o)}else console.log("Cursor not in the editor")}))},function(e,t){}]);

@@ -1,1 +0,1 @@

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=Quill},function(e,t,n){"use strict";n.r(t);var r=n(0),i=n.n(r),o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),l=function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var l=i.get;return void 0!==l?l.call(r):void 0},a=i.a.import("blots/block"),u=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,a),o(t,[{key:"deleteAt",value:function(e,n){l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deleteAt",this).call(this,e,2),this.cache={}}}],[{key:"create",value:function(e){var n=l(t.__proto__||Object.getPrototypeOf(t),"create",this).call(this,e);if(!0===e)return n;var r=document.createElement("img");return r.setAttribute("src",e),n.appendChild(r),n}},{key:"value",value:function(e){var t=e.dataset;return{src:t.src,custom:t.custom}}}]),t}();u.blotName="imageBlot",u.className="image-uploading",u.tagName="span",i.a.register({"formats/imageBlot":u}),n(3);var c=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),s=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.quill=t,this.options=n,this.range=null,this.options.upload,this.quill.getModule("toolbar").addHandler("image",this.selectLocalImage.bind(this))}return c(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=this.fileChanged.bind(this),document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame(function(){document.body.removeChild(e.fileHolder)})}},{key:"fileChanged",value:function(){var e=this,t=this.fileHolder.files[0],n=new FileReader;n.addEventListener("load",function(){var t=n.result;e.insertBase64Image(t)},!1),t&&n.readAsDataURL(t),this.options.upload(t).then(function(t){e.insertToEditor(t)},function(e){})}},{key:"insertBase64Image",value:function(e){var t=this.range;this.quill.insertEmbed(t.index,"imageBlot",""+e)}},{key:"insertToEditor",value:function(e){var t=this.range;this.quill.deleteText(t.index,2),this.quill.insertEmbed(t.index,"image",""+e),t.index++,this.quill.setSelection(t,"api")}}]),e}();t.default=s},,function(e,t){}]);
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=Quill},function(e,t,n){"use strict";n.r(t);var r=n(0),i=n.n(r),o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=function e(t,n,r){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,n);if(void 0===i){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,r)}if("value"in i)return i.value;var a=i.get;return void 0!==a?a.call(r):void 0};function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var c=function(e){function t(){return l(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),o(t,[{key:"deleteAt",value:function(e,n){a(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deleteAt",this).call(this,e,n),this.cache={}}}],[{key:"create",value:function(e){var n=a(t.__proto__||Object.getPrototypeOf(t),"create",this).call(this,e);if(!0===e)return n;var r=document.createElement("img");return r.setAttribute("src",e),n.appendChild(r),n}},{key:"value",value:function(e){var t=e.dataset;return{src:t.src,custom:t.custom}}}]),t}(i.a.import("blots/block"));c.blotName="imageBlot",c.className="image-uploading",c.tagName="span",i.a.register({"formats/imageBlot":c});n(3);var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var f=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.quill=t,this.options=n,this.range=null,"function"!=typeof this.options.upload&&console.warn("[Missing config] upload function that returns a promise is required"),this.quill.getModule("toolbar").addHandler("image",this.selectLocalImage.bind(this))}return s(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=this.fileChanged.bind(this),document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:function(){var e=this,t=this.fileHolder.files[0],n=new FileReader;n.addEventListener("load",(function(){var t=n.result;e.insertBase64Image(t)}),!1),t&&n.readAsDataURL(t),this.options.upload(t).then((function(t){e.insertToEditor(t)}),(function(t){e.removeBase64Image(),console.warn(t)}))}},{key:"insertBase64Image",value:function(e){var t=this.range;this.quill.insertEmbed(t.index,"imageBlot",""+e)}},{key:"insertToEditor",value:function(e){var t=this.range;this.quill.deleteText(t.index,3),this.quill.insertEmbed(t.index,"image",""+e),t.index++,this.quill.setSelection(t,"api")}},{key:"removeBase64Image",value:function(){var e=this.range;this.quill.deleteText(e.index,3)}}]),e}();t.default=f},,function(e,t){}]);
{
"name": "quill-image-uploader",
"version": "1.0.2",
"repository": "https://github.com/noeloconnell/quill-image-uploader.git",
"description": "A module for Quill rich text editor to allow images to be uploaded to a server instead of being base64 encoded",
"main": "src/quill.imageUploader.js",
"eslintConfig": {
"extends": "airbnb",
"env": {
"browser": true
}
},
"scripts": {
"watch": "webpack --watch --progress --mode production",
"start": "webpack-dev-server --hot --open",
"build": "webpack --mode production",
"publish": "npm publish"
},
"keywords": [
"quill",
"quilljs",
"image",
"upload"
],
"author": "",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.8",
"eslint": "^4.15.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"jshint": "^2.9.5",
"style-loader": "^0.19.1",
"uglifyjs-webpack-plugin": "^1.1.6",
"webpack": "^4.1.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {
"quill": "^1.3.6"
}
}
"name": "quill-image-uploader",
"version": "1.1.0",
"repository": "https://github.com/noeloconnell/quill-image-uploader.git",
"description": "A module for Quill rich text editor to allow images to be uploaded to a server instead of being base64 encoded",
"main": "src/quill.imageUploader.js",
"eslintConfig": {
"extends": "airbnb",
"env": {
"browser": true
}
},
"scripts": {
"watch": "webpack --watch --progress --mode production",
"start": "webpack-dev-server --mode development",
"build": "webpack --mode production",
"publish": "npm publish"
},
"keywords": [
"quill",
"quilljs",
"image",
"upload"
],
"author": "",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-preset-env": "^1.6.1",
"css-loader": "^0.28.8",
"eslint": "^4.15.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"jshint": "^2.9.5",
"style-loader": "^0.19.1",
"terser-webpack-plugin": "^2.3.5",
"webpack": "^4.1.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {
"quill": "^1.3.6"
}
}

@@ -6,20 +6,20 @@ import Quill from "quill";

export class LoadingImage extends InlineBlot {
static create(src) {
const node = super.create(src);
if (src === true) return node;
static create(src) {
const node = super.create(src);
if (src === true) return node;
const image = document.createElement("img");
image.setAttribute("src", src);
node.appendChild(image);
const image = document.createElement("img");
image.setAttribute("src", src);
node.appendChild(image);
return node;
}
deleteAt(index, length) {
super.deleteAt(index, 2);
this.cache = {};
}
static value(domNode) {
const { src, custom } = domNode.dataset;
return { src, custom };
}
return node;
}
deleteAt(index, length) {
super.deleteAt(index, length);
this.cache = {};
}
static value(domNode) {
const { src, custom } = domNode.dataset;
return { src, custom };
}
}

@@ -30,2 +30,2 @@

LoadingImage.tagName = "span";
Quill.register({ "formats/imageBlot": LoadingImage });
Quill.register({ "formats/imageBlot": LoadingImage });
import Quill from "quill";
import ImageUploader from "./quill.imageUploader.js";
Quill.debug('warn');
Quill.register("modules/imageUploader", ImageUploader);
const fullToolbarOptions = [
[{ header: [1, 2, 3, false] }],
["bold", "italic"],
["clean"],
["image"]
[{ header: [1, 2, 3, false] }],
["bold", "italic"],
["clean"],
["image"]
];
var quill = new Quill("#editor", {
theme: "snow",
modules: {
toolbar: {
container: fullToolbarOptions
},
imageUploader: {
upload: file => {
const fileReader = new FileReader();
return new Promise((resolve, reject) => {
var quill = new Quill("#editor", {
theme: "snow",
modules: {
toolbar: {
container: fullToolbarOptions
},
imageUploader: {
upload: file => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/JavaScript-logo.png/480px-JavaScript-logo.png"
);
}, 3500);
});
}
fileReader.addEventListener(
'load',
() => {
let base64ImageSrc = fileReader.result;
setTimeout(() => {
resolve(base64ImageSrc);
//reject('Issue uploading file');
}, 1500);
},
false
);
if (file) {
fileReader.readAsDataURL(file);
} else {
reject("No file selected");
}
});
}
}
}
}
});
quill.on('text-change', function(delta, oldDelta, source) {
if (source == 'api') {
console.log("An API call triggered this change.");
} else if (source == 'user') {
console.log("A user action triggered this change.");
}
console.log(oldDelta, delta);
});
quill.on('selection-change', function(range, oldRange, source) {
if (range) {
if (range.length == 0) {
console.log('User cursor is on', range.index);
} else {
var text = quill.getText(range.index, range.length);
console.log('User has highlighted', text);
}
} else {
console.log('Cursor not in the editor');
}
});

@@ -6,79 +6,85 @@ import './blots/image';

class ImageUploader {
constructor(quill, options) {
this.quill = quill;
this.options = options;
this.range = null;
constructor(quill, options) {
this.quill = quill;
this.options = options;
this.range = null;
if (typeof this.options.upload !== 'function')
console.warn(
'[Missing config] upload function that returns a promise is required'
);
if (typeof this.options.upload !== 'function')
console.warn(
'[Missing config] upload function that returns a promise is required'
);
var toolbar = this.quill.getModule('toolbar');
toolbar.addHandler('image', this.selectLocalImage.bind(this));
}
var toolbar = this.quill.getModule('toolbar');
toolbar.addHandler('image', this.selectLocalImage.bind(this));
}
selectLocalImage() {
this.range = this.quill.getSelection();
this.fileHolder = document.createElement('input');
this.fileHolder.setAttribute('type', 'file');
this.fileHolder.setAttribute('accept', 'image/*');
this.fileHolder.setAttribute('style', 'visibility:hidden');
selectLocalImage() {
this.range = this.quill.getSelection();
this.fileHolder = document.createElement('input');
this.fileHolder.setAttribute('type', 'file');
this.fileHolder.setAttribute('accept', 'image/*');
this.fileHolder.setAttribute('style', 'visibility:hidden');
this.fileHolder.onchange = this.fileChanged.bind(this);
this.fileHolder.onchange = this.fileChanged.bind(this);
document.body.appendChild(this.fileHolder);
document.body.appendChild(this.fileHolder);
this.fileHolder.click();
this.fileHolder.click();
window.requestAnimationFrame(() => {
document.body.removeChild(this.fileHolder);
});
}
window.requestAnimationFrame(() => {
document.body.removeChild(this.fileHolder);
});
}
fileChanged() {
const file = this.fileHolder.files[0];
fileChanged() {
const file = this.fileHolder.files[0];
const fileReader = new FileReader();
const fileReader = new FileReader();
fileReader.addEventListener(
'load',
() => {
let base64ImageSrc = fileReader.result;
this.insertBase64Image(base64ImageSrc);
},
false
);
fileReader.addEventListener(
'load',
() => {
let base64ImageSrc = fileReader.result;
this.insertBase64Image(base64ImageSrc);
},
false
);
if (file) {
fileReader.readAsDataURL(file);
}
if (file) {
fileReader.readAsDataURL(file);
}
this.options.upload(file).then(
imageUrl => {
this.insertToEditor(imageUrl);
},
error => {
console.warn(error.message);
}
);
}
this.options.upload(file).then(
imageUrl => {
this.insertToEditor(imageUrl);
},
error => {
this.removeBase64Image();
console.warn(error);
}
);
}
insertBase64Image(url) {
const range = this.range;
this.quill.insertEmbed(range.index, 'imageBlot', `${url}`);
}
insertBase64Image(url) {
const range = this.range;
this.quill.insertEmbed(range.index, 'imageBlot', `${url}`);
}
insertToEditor(url) {
const range = this.range;
// Delete the placeholder image
this.quill.deleteText(range.index, 2);
// Insert the server saved image
this.quill.insertEmbed(range.index, 'image', `${url}`);
insertToEditor(url) {
const range = this.range;
// Delete the placeholder image
this.quill.deleteText(range.index, 3);
// Insert the server saved image
this.quill.insertEmbed(range.index, 'image', `${url}`);
range.index++;
this.quill.setSelection(range, 'api');
}
range.index++;
this.quill.setSelection(range, 'api');
}
removeBase64Image() {
const range = this.range;
this.quill.deleteText(range.index, 3);
}
}
export default ImageUploader;
export default ImageUploader;
const path = require("path");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = [
{
module.exports = [{
entry: {
"quill.imageUploader": "./src/quill.imageUploader.js",
demo: "./src/demo.js"
"quill.imageUploader": "./src/quill.imageUploader.js",
demo: "./src/demo.js"
},
output: {
filename: "[name].min.js",
path: path.resolve(__dirname, "dist")
filename: "[name].min.js",
path: path.resolve(__dirname, "dist")
},
// devServer: {
// contentBase: './src',
// contentBase: './src',
// },
externals: {
quill: "Quill"
quill: "Quill"
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: true,
cache: true,
parallel: true,
sourceMap: true, // Must be set to true if using source-maps in production
terserOptions: {
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
extractComments: 'all',
compress: {
drop_console: false,
},
}
}),
],
},
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: "css-loader",
options: {
minimize: true
rules: [{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [{
loader: "css-loader",
options: {
minimize: true
}
}]
})
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
})
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
}
]
},
plugins: [
new UglifyJSPlugin({
extractComments: true
}),
new ExtractTextPlugin("quill.imageUploader.min.css")
new ExtractTextPlugin("quill.imageUploader.min.css")
]
}
];
}];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc