Skip to content

Commit

Permalink
copy and paste support for file and image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
formsdev committed Oct 19, 2023
1 parent e6905b7 commit cac8102
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
20 changes: 14 additions & 6 deletions resources/js/components/forms/FileInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
class="font-semibold text-nt-blue hover:text-nt-blue-dark focus:outline-none focus:underline transition duration-150 ease-in-out"
@click="openFileUpload"
>
Upload {{ multiple ? 'file(s)' : 'a file' }}
Upload {{ multiple ? 'file(s)' : 'a file' }},
</button>
or drag and drop
use drag and drop or paste it
</p>
<p class="mt-1 text-xs text-gray-500">
Up to {{ mbLimit }}mb
Expand Down Expand Up @@ -198,6 +198,10 @@ export default {
if(this.disabled){
this.showUploadModal = false
}
document.removeEventListener('paste', this.onUploadPasteEvent)
if(this.showUploadModal){
document.addEventListener("paste", this.onUploadPasteEvent)
}
}
},
files: {
Expand Down Expand Up @@ -237,11 +241,15 @@ export default {
onUploadDropEvent (e) {
this.uploadDragoverEvent = false
this.uploadDragoverTracking = false
this.droppedFiles(e)
this.droppedFiles(e.dataTransfer.files)
},
droppedFiles (e) {
const droppedFiles = e.dataTransfer.files
onUploadPasteEvent (e) {
if(!this.showUploadModal) return
this.uploadDragoverEvent = false
this.uploadDragoverTracking = false
this.droppedFiles(e.clipboardData.files)
},
droppedFiles (droppedFiles) {
if (!droppedFiles) return
for (let i = 0; i < droppedFiles.length; i++) {
Expand Down
27 changes: 21 additions & 6 deletions resources/js/components/forms/ImageInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
class="font-semibold text-nt-blue hover:text-nt-blue-dark focus:outline-none focus:underline transition duration-150 ease-in-out"
@click="openFileUpload"
>
Upload your image
Upload your image,
</button>
or drag and drop
use drag and drop or paste it
</p>
<p class="mt-1 text-xs text-gray-500">
.jpg, .jpeg, .png, .bmp, .gif, .svg up to 5mb
Expand Down Expand Up @@ -130,6 +130,17 @@ export default {
}
},
watch: {
showUploadModal: {
handler (val) {
document.removeEventListener('paste', this.onUploadPasteEvent)
if(this.showUploadModal){
document.addEventListener("paste", this.onUploadPasteEvent)
}
}
}
},
methods: {
clearUrl () {
this.$set(this.form, this.name, null)
Expand All @@ -141,11 +152,15 @@ export default {
onUploadDropEvent (e) {
this.uploadDragoverEvent = false
this.uploadDragoverTracking = false
this.droppedFiles(e)
this.droppedFiles(e.dataTransfer.files)
},
droppedFiles (e) {
const droppedFiles = e.dataTransfer.files
onUploadPasteEvent (e) {
if(!this.showUploadModal) return
this.uploadDragoverEvent = false
this.uploadDragoverTracking = false
this.droppedFiles(e.clipboardData.files)
},
droppedFiles (droppedFiles) {
if (!droppedFiles) return
this.file = droppedFiles[0]
Expand Down

0 comments on commit cac8102

Please sign in to comment.