diff --git a/assets/components/ExternalIcon.vue b/assets/components/ExternalIcon.vue new file mode 100644 index 0000000..efb2c94 --- /dev/null +++ b/assets/components/ExternalIcon.vue @@ -0,0 +1,14 @@ + diff --git a/assets/components/PlusIcon.vue b/assets/components/PlusIcon.vue new file mode 100644 index 0000000..2b35ccd --- /dev/null +++ b/assets/components/PlusIcon.vue @@ -0,0 +1,6 @@ + diff --git a/assets/components/SingleFile.vue b/assets/components/SingleFile.vue new file mode 100644 index 0000000..8f07fff --- /dev/null +++ b/assets/components/SingleFile.vue @@ -0,0 +1,117 @@ + + + diff --git a/assets/components/TrashIcon.vue b/assets/components/TrashIcon.vue new file mode 100644 index 0000000..04016ca --- /dev/null +++ b/assets/components/TrashIcon.vue @@ -0,0 +1,35 @@ + diff --git a/assets/composables/useReadFile.js b/assets/composables/useReadFile.js new file mode 100644 index 0000000..0805616 --- /dev/null +++ b/assets/composables/useReadFile.js @@ -0,0 +1,77 @@ +import accounting from 'accounting'; +import {ref} from 'vue'; + +accounting.settings.currency = { + ...accounting.settings.currency, + precision: 2, + format: '%v %s', + decimal: ',', + thousand: '.', +}; + +export default function () { + const dropping = ref(false); + + async function read(file) { + return new Promise((resolve) => { + var reader = new FileReader(); + reader.onload = function () { + var r = reader.result; + resolve({ + content: r.substr(r.search(',') + 1), + name: file.name, + type: file.type, + size: file.size, + }); + }; + reader.readAsDataURL(file); + }); + } + function onDragEnter(e) { + e.preventDefault(); + e.stopPropagation(); + dropping.value = true; + } + function onDragOver(e) { + e.preventDefault(); + e.stopPropagation(); + } + function onDragLeave(e) { + e.preventDefault(); + e.stopPropagation(); + dropping.value = false; + } + function processDrop(e, maxFiles) { + e.preventDefault(); + e.stopPropagation(); + let dt = e.dataTransfer; + let files = [...dt.files].slice(0, maxFiles ? maxFiles : dt.files.length); + let result = []; + for (const f in files) { + if (typeof files[f] === 'object') { + result.push(files[f]); + } + } + dropping.value = false; + + return result; + } + function size(file) { + if (file.size < 1000) { + return accounting.formatMoney(file.size, {symbol: 'B'}); + } + if (file.size < 1000000) { + return accounting.formatMoney(file.size / 1000, {symbol: 'KB'}); + } + if (file.size < 1000000000) { + return accounting.formatMoney(file.size / 1000000, {symbol: 'MB'}); + } + if (file.size < 1000000000000) { + return accounting.formatMoney(file.size / 1000000000, {symbol: 'GB'}); + } + + return ''; + } + + return {dropping, onDragLeave, onDragOver, onDragEnter, processDrop, read}; +}