feat: Add ability to paste file/image from clipboard

This commit is contained in:
David Kubeš 2022-10-14 01:35:52 +02:00
parent 8f4944fda0
commit 7132e9a2cd

View file

@ -1,5 +1,6 @@
<template>
<file-upload
ref="upload"
:size="4096 * 2048"
:accept="allowedFileTypes"
:data="{
@ -48,15 +49,30 @@ 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') {
const file = item.getAsFile();
this.$refs.upload.add(file);
}
});
},
getFileType(fileType) {
return fileType.includes('image') ? 'image' : 'file';
},
async onFileUpload(file) {
if (this.globalConfig.directUploadsEnabled) {
this.onDirectFileUpload(file);
await this.onDirectFileUpload(file);
} else {
this.onIndirectFileUpload(file);
await this.onIndirectFileUpload(file);
}
},
async onDirectFileUpload(file) {