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 0.1.0 to 0.1.1

static/quill-example.gif

2

dist/quill.imageUploader.min.js

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

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.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 o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));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){e.exports=n(2)},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),i=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 o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,r)}if("value"in o)return o.value;var l=o.get;return void 0!==l?l.call(r):void 0},a=o.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),i(t,[{key:"deleteAt",value:function(e,n){console.log("deleteAt",e,n),l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deleteAt",this).call(this,e,2),this.cache={}}}],[{key:"create",value:function(e){console.log({src: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){console.log("value called",e);var t=e.dataset;return{src:t.src,custom:t.custom}}}]),t}();u.blotName="imageBlot",u.className="image-uploading",u.tagName="span",o.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,"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(){this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.onchange=this.fileChanged.bind(this),this.fileHolder.click()}},{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){console.warn(e.message)})}},{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}();Quill.register("modules/imageUploader",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){e.exports=n(2)},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(){this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.onchange=this.fileChanged.bind(this),this.fileHolder.click()}},{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}();Quill.register("modules/imageUploader",s)},function(e,t){}]);
{
"name": "quill-image-uploader",
"version": "0.1.0",
"version": "0.1.1",
"repository": "https://github.com/noeloconnell/quill-image-uploader.git",

@@ -31,2 +31,3 @@ "description": "A module for Quill rich text editor to allow images to be uploaded to a server instead of being base64 encoded",

"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"babel-preset-env": "^1.6.1",

@@ -33,0 +34,0 @@ "css-loader": "^0.28.8",

# Quill ImageHandler Module
A module for Quill rich text editor to allow images to be uploaded to a server instead of being base64 encoded
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## Demo
![Image Uploading Demo GIF](static/quil-example.gif "Image Uploading Demo GIF")
### Install
Install with npm:
```bash

@@ -13,20 +18,32 @@ npm install quill-image-uploader --save

### Webpack/ES6
### Usage
Include the CSS for the loading effect or create your own.
```javascript
const quill = new Quill(editor, {
// ...
modules: {
// ...
modules: {
// ...
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);
});
}
}
imageUploader: {
upload: file => {
// return a Promise that resolves in a link to the uploaded image
return new Promise((resolve, reject) => {
const fd = new FormData();
fd.append("upload_file", file);
const xhr = new XMLHttpRequest();
xhr.open("POST", `${window.location.pathname}/api/files/add`, true);
xhr.onload = () => {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
resolve(response.file_path); // Must resolve as a link to the image
}
};
xhr.send(fd);
});
}
}
}
});
```
```

@@ -0,0 +0,0 @@ import Quill from 'quill';

@@ -0,0 +0,0 @@ import "./blots/image";

@@ -0,0 +0,0 @@ const path = require('path');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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