Gathering detailed insights and metrics for quill-image-drop-and-paste
Gathering detailed insights and metrics for quill-image-drop-and-paste
Gathering detailed insights and metrics for quill-image-drop-and-paste
Gathering detailed insights and metrics for quill-image-drop-and-paste
npm install quill-image-drop-and-paste
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
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
107 Stars
89 Commits
43 Forks
3 Watching
2 Branches
9 Contributors
Updated on 18 Nov 2024
Minified
Minified + Gzipped
TypeScript (40.82%)
CSS (27.91%)
JavaScript (11.37%)
HTML (10.88%)
Vue (6.98%)
Shell (1.86%)
SCSS (0.17%)
Cumulative downloads
Total Downloads
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
24
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.
Next.js Demo (full example with client and server side image upload implementation)
1npm install quill-image-drop-and-paste --save
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.
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
If you did not config a image handler, it will insert the image with dataURL into the quill editor directory after your drop/paste.
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
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
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
101 existing vulnerabilities detected
Details
Score
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 Morequill-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).