2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
2024-02-12 02:37:45 +00:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2018-02-14 10:21:15 +00:00
|
|
|
<template>
|
2023-05-19 04:58:09 +00:00
|
|
|
<div
|
|
|
|
:class="[$style.root, { [$style.draghover]: draghover }]"
|
2018-02-14 10:21:15 +00:00
|
|
|
@click="onClick"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
2023-05-19 04:58:09 +00:00
|
|
|
<i v-if="folder == null" class="ti ti-cloud" style="margin-right: 4px;"></i>
|
2022-01-28 02:39:49 +00:00
|
|
|
<span>{{ folder == null ? i18n.ts.drive : folder.name }}</span>
|
2018-02-14 10:21:15 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-18 14:06:16 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from 'vue';
|
|
|
|
import * as Misskey from 'misskey-js';
|
2024-01-04 09:32:46 +00:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { i18n } from '@/i18n.js';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-18 14:06:16 +00:00
|
|
|
const props = defineProps<{
|
|
|
|
folder?: Misskey.entities.DriveFolder;
|
|
|
|
parentFolder: Misskey.entities.DriveFolder | null;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2022-05-05 11:45:50 +00: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 14:06:16 +00: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 11:45:50 +00:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 14:06:16 +00:00
|
|
|
|
|
|
|
// このフォルダがルートかつカレントディレクトリならドロップ禁止
|
|
|
|
if (props.folder == null && props.parentFolder == null) {
|
2022-05-05 11:45:50 +00:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 14:06:16 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 11:45:50 +00: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 14:06:16 +00:00
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
2022-10-12 23:34:23 +00:00
|
|
|
switch (ev.dataTransfer.effectAllowed) {
|
|
|
|
case 'all':
|
|
|
|
case 'uninitialized':
|
2023-07-07 22:08:16 +00:00
|
|
|
case 'copy':
|
|
|
|
case 'copyLink':
|
|
|
|
case 'copyMove':
|
2022-10-12 23:34:23 +00:00
|
|
|
ev.dataTransfer.dropEffect = 'copy';
|
|
|
|
break;
|
|
|
|
case 'linkMove':
|
|
|
|
case 'move':
|
|
|
|
ev.dataTransfer.dropEffect = 'move';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
break;
|
|
|
|
}
|
2022-01-18 14:06:16 +00:00
|
|
|
} else {
|
2022-05-05 11:45:50 +00:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 14:06:16 +00: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 11:45:50 +00:00
|
|
|
function onDrop(ev: DragEvent) {
|
2022-01-18 14:06:16 +00:00
|
|
|
draghover.value = false;
|
|
|
|
|
2022-05-05 11:45:50 +00:00
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 14:06:16 +00:00
|
|
|
|
|
|
|
// ファイルだったら
|
2022-05-05 11:45:50 +00:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
for (const file of Array.from(ev.dataTransfer.files)) {
|
2022-01-18 14:06:16 +00:00
|
|
|
emit('upload', file, props.folder);
|
2018-02-14 10:21:15 +00:00
|
|
|
}
|
2022-01-18 14:06:16 +00:00
|
|
|
return;
|
2018-02-14 10:21:15 +00:00
|
|
|
}
|
2022-01-18 14:06:16 +00:00
|
|
|
|
|
|
|
//#region ドライブのファイル
|
2022-05-05 11:45:50 +00:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
|
|
|
if (driveFile != null && driveFile !== '') {
|
2022-01-18 14:06:16 +00:00
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
emit('removeFile', file.id);
|
2024-01-04 09:32:46 +00:00
|
|
|
misskeyApi('drive/files/update', {
|
2022-01-18 14:06:16 +00:00
|
|
|
fileId: file.id,
|
2022-12-22 07:01:59 +00:00
|
|
|
folderId: props.folder ? props.folder.id : null,
|
2022-01-18 14:06:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
2022-05-05 11:45:50 +00:00
|
|
|
const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
|
|
|
|
if (driveFolder != null && driveFolder !== '') {
|
2022-01-18 14:06:16 +00:00
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
// 移動先が自分自身ならreject
|
2022-05-05 11:45:50 +00:00
|
|
|
if (props.folder && folder.id === props.folder.id) return;
|
2022-01-18 14:06:16 +00:00
|
|
|
emit('removeFolder', folder.id);
|
2024-01-04 09:32:46 +00:00
|
|
|
misskeyApi('drive/folders/update', {
|
2022-01-18 14:06:16 +00:00
|
|
|
folderId: folder.id,
|
2022-12-22 07:01:59 +00:00
|
|
|
parentId: props.folder ? props.folder.id : null,
|
2022-01-18 14:06:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
2018-02-14 10:21:15 +00:00
|
|
|
</script>
|
|
|
|
|
2023-05-19 04:58:09 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-10-17 11:12:00 +00:00
|
|
|
&.draghover {
|
2020-01-29 19:37:25 +00:00
|
|
|
background: #eee;
|
|
|
|
}
|
|
|
|
}
|
2018-02-14 10:21:15 +00:00
|
|
|
</style>
|