2022-09-12 11:11:56 +00:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
v-if="allowsUpload && mediaPathSetUp"
|
2024-02-24 15:37:01 +00:00
|
|
|
v-koel-clickaway="close"
|
2022-09-12 11:11:56 +00:00
|
|
|
:class="{ droppable }"
|
|
|
|
class="drop-zone"
|
|
|
|
@dragleave="onDropLeave"
|
|
|
|
@dragover="onDragOver"
|
|
|
|
@drop="onDrop"
|
|
|
|
>
|
2023-11-10 13:16:06 +00:00
|
|
|
<Icon :icon="faUpload" size="6x" />
|
2022-09-12 11:11:56 +00:00
|
|
|
<h3>Drop to upload</h3>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from 'vue'
|
|
|
|
import { faUpload } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { useUpload } from '@/composables'
|
|
|
|
|
|
|
|
const { allowsUpload, mediaPathSetUp, handleDropEvent } = useUpload()
|
|
|
|
|
2024-02-24 15:37:01 +00:00
|
|
|
const emit = defineEmits<{(e: 'close'): void}>()
|
2022-09-12 11:11:56 +00:00
|
|
|
const droppable = ref(false)
|
|
|
|
|
|
|
|
const onDropLeave = () => (droppable.value = false)
|
|
|
|
|
|
|
|
const onDragOver = (event: DragEvent) => {
|
|
|
|
if (!event.dataTransfer?.types.includes('Files')) return false
|
|
|
|
event.preventDefault()
|
|
|
|
droppable.value = true
|
|
|
|
}
|
|
|
|
|
|
|
|
const onDrop = async (event: DragEvent) => {
|
|
|
|
event.preventDefault()
|
|
|
|
droppable.value = false
|
|
|
|
await handleDropEvent(event)
|
|
|
|
}
|
2024-02-24 15:37:01 +00:00
|
|
|
|
|
|
|
const close = () => emit('close')
|
2022-09-12 11:11:56 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.drop-zone {
|
|
|
|
height: 256px;
|
|
|
|
max-height: 66vh;
|
|
|
|
aspect-ratio: 1/1;
|
|
|
|
outline: 3px dashed #ccc;
|
|
|
|
position: fixed;
|
|
|
|
z-index: 9;
|
|
|
|
transform: translate(calc(50vw - 50%), calc(50vh - 50%));
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
border-radius: 2rem;
|
|
|
|
background: rgba(0, 0, 0, .4);
|
|
|
|
display: flex;
|
|
|
|
align-content: center;
|
|
|
|
justify-content: center;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
overflow: hidden;
|
|
|
|
transition: 0.2s;
|
|
|
|
|
|
|
|
h3 {
|
|
|
|
font-size: 2rem;
|
|
|
|
font-weight: var(--font-weight-thin);
|
|
|
|
margin-top: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.droppable {
|
|
|
|
height: 384px;
|
|
|
|
outline: 3px dashed #fff;
|
|
|
|
background: rgba(0, 0, 0, .9);
|
|
|
|
box-shadow: 0 0 0 999rem rgba(0, 0, 0, .7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|