2021-02-16 00:07:13 +01:00
|
|
|
<file-drop multiple class="file-drop file-drop-realm-{realm}" accept={mediaAccept} ref:fileDrop >
|
2018-12-15 11:06:12 +01:00
|
|
|
<div class="file-drop-info">
|
|
|
|
<div class="file-drop-info-text">
|
2020-11-29 23:13:27 +01:00
|
|
|
<span class="file-drop-info-text-valid">{intl.dropToUpload}</span>
|
|
|
|
<span class="file-drop-info-text-invalid">{intl.invalidFileType}</span>
|
2018-12-15 11:06:12 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<slot></slot>
|
|
|
|
</file-drop>
|
|
|
|
<style>
|
|
|
|
.file-drop {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
2019-04-13 20:02:25 +02:00
|
|
|
max-width: 100%;
|
|
|
|
width: 100%;
|
2018-12-15 11:06:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.file-drop-info {
|
|
|
|
display: none;
|
|
|
|
pointer-events: none;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
z-index: 6000;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-drop-info-text {
|
|
|
|
font-size: 1.2em;
|
|
|
|
color: var(--button-text);
|
|
|
|
padding: 10px 20px;
|
|
|
|
border: 2px dashed var(--button-text);
|
|
|
|
border-radius: 6px;
|
|
|
|
}
|
|
|
|
|
2019-02-14 17:46:43 +01:00
|
|
|
.file-drop-realm-dialog {
|
2019-02-14 03:38:34 +01:00
|
|
|
max-height: 100%;
|
|
|
|
overflow-y: auto;
|
|
|
|
overflow-x: hidden;
|
|
|
|
scrollbar-width: none;
|
|
|
|
-ms-overflow-style: none;
|
|
|
|
}
|
|
|
|
|
2019-02-14 17:46:43 +01:00
|
|
|
.file-drop-realm-dialog::-webkit-scrollbar {
|
2019-02-14 03:38:34 +01:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2018-12-15 11:06:12 +01:00
|
|
|
:global(.file-drop.drop-valid .file-drop-info, .file-drop.drop-invalid .file-drop-info) {
|
|
|
|
display: flex;
|
|
|
|
background: var(--file-drop-mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(.file-drop.drop-valid .file-drop-info-text-invalid, .file-drop.drop-invalid .file-drop-info-text-valid) {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
2021-07-05 05:19:04 +02:00
|
|
|
import { mediaAccept } from '../../_static/media.js'
|
|
|
|
import { doMediaUpload } from '../../_actions/media.js'
|
2018-12-15 11:06:12 +01:00
|
|
|
if (process.browser) {
|
|
|
|
require('file-drop-element')
|
|
|
|
}
|
|
|
|
export default {
|
|
|
|
oncreate () {
|
|
|
|
this.onFileDrop = this.onFileDrop.bind(this)
|
|
|
|
this.refs.fileDrop.addEventListener('filedrop', this.onFileDrop)
|
|
|
|
},
|
|
|
|
ondestroy () {
|
|
|
|
this.refs.fileDrop.removeEventListener('filedrop', this.onFileDRop)
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
mediaAccept
|
|
|
|
}),
|
|
|
|
methods: {
|
2019-02-20 07:24:03 +01:00
|
|
|
async onFileDrop (e) {
|
2019-08-03 22:49:37 +02:00
|
|
|
const { files } = e
|
|
|
|
const { realm } = this.get()
|
|
|
|
for (const file of files) { // upload one at a time to avoid hitting limits
|
2019-02-20 07:24:03 +01:00
|
|
|
await doMediaUpload(realm, file)
|
|
|
|
}
|
2018-12-15 11:06:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|