2018-02-14 03:21:15 -07:00
|
|
|
<template>
|
2020-01-29 12:37:25 -07:00
|
|
|
<div class="drylbebk"
|
2020-10-17 05:12:00 -06:00
|
|
|
:class="{ draghover }"
|
2018-02-14 03:21:15 -07:00
|
|
|
@click="onClick"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
2022-11-06 19:49:47 -07:00
|
|
|
<i v-if="folder == null" class="ph-cloud-bold ph-lg"></i>
|
2022-01-27 19:39:49 -07:00
|
|
|
<span>{{ folder == null ? i18n.ts.drive : folder.name }}</span>
|
2018-02-14 03:21:15 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-18 07:06:16 -07:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from 'vue';
|
2022-12-11 20:24:12 -07:00
|
|
|
import * as Misskey from 'calckey-js';
|
2021-11-11 10:02:25 -07:00
|
|
|
import * as os from '@/os';
|
2022-01-18 07:06:16 -07:00
|
|
|
import { i18n } from '@/i18n';
|
2020-01-29 12:37:25 -07:00
|
|
|
|
2022-01-18 07:06:16 -07:00
|
|
|
const props = defineProps<{
|
|
|
|
folder?: Misskey.entities.DriveFolder;
|
|
|
|
parentFolder: Misskey.entities.DriveFolder | null;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2022-05-05 05:45:50 -06:00
|
|
|
(ev: 'move', v?: Misskey.entities.DriveFolder): void;
|
|
|
|
(ev: 'upload', file: File, folder?: Misskey.entities.DriveFolder | null): void;
|
|
|
|
(ev: 'removeFile', v: Misskey.entities.DriveFile['id']): void;
|
|
|
|
(ev: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void;
|
2022-01-18 07:06:16 -07:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const hover = ref(false);
|
|
|
|
const draghover = ref(false);
|
|
|
|
|
|
|
|
function onClick() {
|
|
|
|
emit('move', props.folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseover() {
|
|
|
|
hover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseout() {
|
|
|
|
hover.value = false;
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:45:50 -06:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 07:06:16 -07:00
|
|
|
|
|
|
|
// このフォルダがルートかつカレントディレクトリならドロップ禁止
|
|
|
|
if (props.folder == null && props.parentFolder == null) {
|
2022-05-05 05:45:50 -06:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 07:06:16 -07:00
|
|
|
}
|
|
|
|
|
2022-05-05 05:45:50 -06:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === 'file';
|
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
|
|
|
const isDriveFolder = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FOLDER_;
|
2022-01-18 07:06:16 -07:00
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
2022-05-05 05:45:50 -06:00
|
|
|
ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed === 'all' ? 'copy' : 'move';
|
2022-01-18 07:06:16 -07:00
|
|
|
} else {
|
2022-05-05 05:45:50 -06:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 07:06:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragenter() {
|
|
|
|
if (props.folder || props.parentFolder) draghover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragleave() {
|
|
|
|
if (props.folder || props.parentFolder) draghover.value = false;
|
|
|
|
}
|
|
|
|
|
2022-05-05 05:45:50 -06:00
|
|
|
function onDrop(ev: DragEvent) {
|
2022-01-18 07:06:16 -07:00
|
|
|
draghover.value = false;
|
|
|
|
|
2022-05-05 05:45:50 -06:00
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 07:06:16 -07:00
|
|
|
|
|
|
|
// ファイルだったら
|
2022-05-05 05:45:50 -06:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
for (const file of Array.from(ev.dataTransfer.files)) {
|
2022-01-18 07:06:16 -07:00
|
|
|
emit('upload', file, props.folder);
|
2018-02-14 03:21:15 -07:00
|
|
|
}
|
2022-01-18 07:06:16 -07:00
|
|
|
return;
|
2018-02-14 03:21:15 -07:00
|
|
|
}
|
2022-01-18 07:06:16 -07:00
|
|
|
|
|
|
|
//#region ドライブのファイル
|
2022-05-05 05:45:50 -06:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
|
|
|
if (driveFile != null && driveFile !== '') {
|
2022-01-18 07:06:16 -07:00
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
emit('removeFile', file.id);
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
|
|
|
folderId: props.folder ? props.folder.id : null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
2022-05-05 05:45:50 -06:00
|
|
|
const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
|
|
|
|
if (driveFolder != null && driveFolder !== '') {
|
2022-01-18 07:06:16 -07:00
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
// 移動先が自分自身ならreject
|
2022-05-05 05:45:50 -06:00
|
|
|
if (props.folder && folder.id === props.folder.id) return;
|
2022-01-18 07:06:16 -07:00
|
|
|
emit('removeFolder', folder.id);
|
|
|
|
os.api('drive/folders/update', {
|
|
|
|
folderId: folder.id,
|
|
|
|
parentId: props.folder ? props.folder.id : null
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
2018-02-14 03:21:15 -07:00
|
|
|
</script>
|
|
|
|
|
2020-01-29 12:37:25 -07:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.drylbebk {
|
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2018-02-14 03:21:15 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
&.draghover {
|
2020-01-29 12:37:25 -07:00
|
|
|
background: #eee;
|
|
|
|
}
|
2018-04-14 16:41:10 -06:00
|
|
|
|
2020-01-29 12:37:25 -07:00
|
|
|
> i {
|
|
|
|
margin-right: 4px;
|
|
|
|
}
|
|
|
|
}
|
2018-02-14 03:21:15 -07:00
|
|
|
</style>
|