Installations
npm install quill-image-drop-and-paste
Releases
Compectable with quill@^2.0.2
Published on 07 Aug 2024
feat: add autoConvert option
Published on 18 Apr 2023
Release v1.2.14
Published on 27 Oct 2022
Release v1.2.12
Published on 21 Oct 2022
bugfix: converting arraybuffer to string cause error
Published on 10 May 2022
fix the paste event prevent the clipboard matchers
Published on 22 Feb 2022
Developer
chenjuneking
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
14.21.3
NPM Version
6.14.18
Statistics
107 Stars
89 Commits
43 Forks
3 Watching
2 Branches
9 Contributors
Updated on 18 Nov 2024
Bundle Size
6.54 kB
Minified
2.58 kB
Minified + Gzipped
Languages
TypeScript (40.82%)
CSS (27.91%)
JavaScript (11.37%)
HTML (10.88%)
Vue (6.98%)
Shell (1.86%)
SCSS (0.17%)
Total Downloads
Cumulative downloads
Total Downloads
2,033,958
Last day
-2.1%
3,748
Compared to previous day
Last week
-2.1%
19,581
Compared to previous week
Last month
11.5%
83,137
Compared to previous month
Last year
-2.3%
734,714
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
24
QuillImageDropAndPaste
A quill editor module for drop and paste image, with a callback hook before inserting image into the editor.
This module supported drop and paste image into the quill editor, by default, it would insert a image with a base64 url. Because of a base64 string was too large, if we saved it into the database, it could easilly out of the size of the column, the best practice was to save the image on our server and returned the image's url, and finally we inserted the image with the returned url into the editor.
Examples
Next.js Demo (full example with client and server side image upload implementation)
Install
1npm install quill-image-drop-and-paste --save
Usage
ES6
1import Quill from 'quill' 2import QuillImageDropAndPaste from 'quill-image-drop-and-paste' 3 4Quill.register('modules/imageDropAndPaste', QuillImageDropAndPaste) 5 6const quill = new Quill('#editor-container', { 7 modules: { 8 imageDropAndPaste: { 9 // add an custom image handler 10 handler: imageHandler, 11 }, 12 }, 13}) 14 15/** 16 * Do something to our dropped or pasted image 17 * @param.imageDataUrl {string} - image's dataURL 18 * @param.type {string} - image's mime type 19 * @param.imageData {ImageData} - provided more functions to handle the image 20 * - imageData.toBlob() {function} - convert image to a BLOB Object 21 * - imageData.toFile(filename?: string) {function} - convert image to a File Object. filename is optional, it will generate a random name if the original image didn't have a name. 22 * - imageData.minify(options) {function)- minify the image, return a promise 23 * - options.maxWidth {number} - specify the max width of the image, default is 800 24 * - options.maxHeight {number} - specify the max height of the image, default is 800 25 * - options.quality {number} - specify the quality of the image, default is 0.8 26 */ 27function imageHandler(imageDataUrl, type, imageData) { 28 const blob = imageData.toBlob() 29 const file = imageData.toFile() 30 31 // generate a form data 32 const formData = new FormData() 33 34 // append blob data 35 formData.append('file', blob) 36 37 // or just append the file 38 formData.append('file', file) 39 40 // upload image to your server 41 callUploadAPI(your_upload_url, formData, (err, res) => { 42 if (err) return 43 // success? you should return the uploaded image's url 44 // then insert into the quill editor 45 let index = (quill.getSelection() || {}).index 46 if (index === undefined || index < 0) index = quill.getLength() 47 quill.insertEmbed(index, 'image', res.data.image_url, 'user') 48 }) 49}
Minify image before upload to the server.
1function imageHandler(imageDataUrl, type, imageData) { 2 imageData 3 .minify({ 4 maxWidth: 320, 5 maxHeight: 320, 6 quality: 0.7, 7 }) 8 .then((miniImageData) => { 9 const blob = miniImageData.toBlob() 10 const file = miniImageData.toFile() 11 // create a form data, and upload to the server... 12 }) 13}
Additional, you could rewrite the toolbar's insert image button with our image handler.
1import { ImageData } from 'quill-image-drop-and-paste' 2 3quill.getModule('toolbar').addHandler('image', function (clicked) { 4 if (clicked) { 5 let fileInput = this.container.querySelector('input.ql-image[type=file]') 6 if (fileInput == null) { 7 fileInput = document.createElement('input') 8 fileInput.setAttribute('type', 'file') 9 fileInput.setAttribute( 10 'accept', 11 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon' 12 ) 13 fileInput.classList.add('ql-image') 14 fileInput.addEventListener('change', function (e) { 15 const files = e.target.files 16 let file 17 if (files.length > 0) { 18 file = files[0] 19 const type = file.type 20 const reader = new FileReader() 21 reader.onload = (e) => { 22 // handle the inserted image 23 const dataUrl = e.target.result 24 imageHandler(dataUrl, type, new ImageData(dataUrl, type, file.name)) 25 fileInput.value = '' 26 } 27 reader.readAsDataURL(file) 28 } 29 }) 30 } 31 fileInput.click() 32 } 33})
⚠️ Can be confused:
ImageData
fromquill-image-drop-and-paste
is different from ImageData in the Web API.
Script Tag
Copy dist/quill-image-drop-and-paste.min.js
into your web root or include from node_modules
1<script src="/node_modules/quill-image-drop-and-paste/quill-image-drop-and-paste.min.js"></script>
1const quill = new Quill(editorSelector, { 2 // ... 3 modules: { 4 imageDropAndPaste: { 5 // add an custom image handler 6 handler: imageHandler, 7 }, 8 }, 9}) 10 11// access ImageData 12// avoid to cover window's ImageData constructor, we should give it another name 13const QuillImageData = QuillImageDropAndPaste.ImageData
Finally
If you did not config a image handler, it will insert the image with dataURL into the quill editor directory after your drop/paste.
Options
autoConvert
Automatic insert the image to the editor while the pasted content is an image's url(plain text). Default true
.
enableNativeUploader
Whether enable Quill's original uploader. Default false
.
handler
The image handler.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 5/25 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/publish.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/chenjuneking/quill-image-drop-and-paste/publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/chenjuneking/quill-image-drop-and-paste/publish.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/chenjuneking/quill-image-drop-and-paste/publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/chenjuneking/quill-image-drop-and-paste/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/chenjuneking/quill-image-drop-and-paste/test.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/publish.yml:20
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:25
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Reason
101 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-273r-mgr4-v34f
- Warn: Project is vulnerable to: GHSA-r7qp-cfhv-p84w
- Warn: Project is vulnerable to: GHSA-6h5x-7c5m-7cr7
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-7x7c-qm48-pq9c
- Warn: Project is vulnerable to: GHSA-rc3x-jf5g-xvc5
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-82v2-mx6x-wq7q
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-4943-9vgg-gr5r
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-25hc-qcg6-38wj
- Warn: Project is vulnerable to: GHSA-qm95-pgcg-qqfq
- Warn: Project is vulnerable to: GHSA-cqmj-92xf-r6r9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-hc6q-2mpp-qw7j
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986 / GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-wm7h-9275-46v2
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-9gr3-7897-pp7m
- Warn: Project is vulnerable to: GHSA-25mp-g6fv-mqxx
- Warn: Project is vulnerable to: GHSA-fmvm-x8mv-47mj
- Warn: Project is vulnerable to: GHSA-c59h-r6p8-q9wc
- Warn: Project is vulnerable to: GHSA-g77x-44xx-532m
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-33f9-j839-rf8h
- Warn: Project is vulnerable to: GHSA-c36v-fmgq-m8hx
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-pfq8-rq6v-vf5m
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-5j4c-8p2g-v4jx
- Warn: Project is vulnerable to: GHSA-g3ch-rx76-35fx
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Score
3
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to quill-image-drop-and-paste
quill-image-compress
A Quill rich text editor Module which compresses images uploaded to the editor
quill-image-resize
A module for Quill rich text editor to allow images to be resized.
quill-image-resize-module
A module for Quill rich text editor to allow images to be resized.
quill-image-resize-module-react
A module for Quill rich text editor to allow images to be resized (with react fixes).