feat: Add ability to paste file/image from clipboard (#5627)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
parent
06e2219110
commit
bcde84b5b5
3 changed files with 19 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
<template>
|
||||
<file-upload
|
||||
ref="upload"
|
||||
:size="4096 * 2048"
|
||||
:accept="allowedFileTypes"
|
||||
:data="{
|
||||
|
@ -48,7 +49,23 @@ export default {
|
|||
return ALLOWED_FILE_TYPES;
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
document.addEventListener('paste', this.handleClipboardPaste);
|
||||
},
|
||||
destroyed() {
|
||||
document.removeEventListener('paste', this.handleClipboardPaste);
|
||||
},
|
||||
methods: {
|
||||
handleClipboardPaste(e) {
|
||||
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
|
||||
items.forEach(item => {
|
||||
if (item.kind === 'file') {
|
||||
e.preventDefault();
|
||||
const file = item.getAsFile();
|
||||
this.$refs.upload.add(file);
|
||||
}
|
||||
});
|
||||
},
|
||||
getFileType(fileType) {
|
||||
return fileType.includes('image') ? 'image' : 'file';
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue