2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-12 03:37:45 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2018-02-14 11:03:48 +01:00
|
|
|
<template>
|
2022-08-30 17:24:33 +02:00
|
|
|
<div
|
2023-05-29 13:05:46 +02:00
|
|
|
:class="[$style.root, { [$style.draghover]: draghover }]"
|
2021-11-19 11:36:12 +01:00
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
2018-02-14 11:03:48 +01:00
|
|
|
@click="onClick"
|
2020-11-03 02:27:00 +01:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2018-02-14 11:03:48 +01:00
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseout="onMouseout"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter.prevent="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
2023-05-29 13:05:46 +02:00
|
|
|
<p :class="$style.name">
|
|
|
|
<template v-if="hover"><i :class="$style.icon" class="ti ti-folder ti-fw"></i></template>
|
|
|
|
<template v-if="!hover"><i :class="$style.icon" class="ti ti-folder ti-fw"></i></template>
|
2018-02-14 11:03:48 +01:00
|
|
|
{{ folder.name }}
|
|
|
|
</p>
|
2023-05-29 13:05:46 +02:00
|
|
|
<p v-if="defaultStore.state.uploadFolder == folder.id" :class="$style.upload">
|
2022-01-28 03:39:49 +01:00
|
|
|
{{ i18n.ts.uploadFolder }}
|
2019-07-07 21:17:53 +02:00
|
|
|
</p>
|
2023-05-29 13:05:46 +02:00
|
|
|
<button v-if="selectMode" class="_button" :class="[$style.checkbox, { [$style.checked]: isSelected }]" @click.prevent.stop="checkboxClicked"></button>
|
2018-02-14 11:03:48 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
<script lang="ts" setup>
|
2022-05-01 15:51:07 +02:00
|
|
|
import { computed, defineAsyncComponent, ref } from 'vue';
|
2022-01-18 15:06:16 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { claimAchievement } from '@/scripts/achievements.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
2023-12-13 08:56:19 +01:00
|
|
|
import { MenuItem } from '@/types/menu.js';
|
2022-01-18 15:06:16 +01:00
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
folder: Misskey.entities.DriveFolder;
|
|
|
|
isSelected?: boolean;
|
|
|
|
selectMode?: boolean;
|
|
|
|
}>(), {
|
|
|
|
isSelected: false,
|
|
|
|
selectMode: false,
|
|
|
|
});
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
const emit = defineEmits<{
|
2022-01-19 17:27:41 +01:00
|
|
|
(ev: 'chosen', v: Misskey.entities.DriveFolder): void;
|
|
|
|
(ev: 'move', v: Misskey.entities.DriveFolder): void;
|
|
|
|
(ev: 'upload', file: File, folder: Misskey.entities.DriveFolder);
|
|
|
|
(ev: 'removeFile', v: Misskey.entities.DriveFile['id']): void;
|
|
|
|
(ev: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void;
|
|
|
|
(ev: 'dragstart'): void;
|
|
|
|
(ev: 'dragend'): void;
|
2022-01-18 15:06:16 +01:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const hover = ref(false);
|
|
|
|
const draghover = ref(false);
|
|
|
|
const isDragging = ref(false);
|
|
|
|
|
|
|
|
const title = computed(() => props.folder.name);
|
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
function checkboxClicked() {
|
2022-01-18 15:06:16 +01:00
|
|
|
emit('chosen', props.folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClick() {
|
|
|
|
emit('move', props.folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseover() {
|
|
|
|
hover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseout() {
|
2022-06-10 07:36:55 +02:00
|
|
|
hover.value = false;
|
2022-01-18 15:06:16 +01:00
|
|
|
}
|
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 15:06:16 +01:00
|
|
|
|
|
|
|
// 自分自身がドラッグされている場合
|
|
|
|
if (isDragging.value) {
|
|
|
|
// 自分自身にはドロップさせない
|
2022-01-19 17:27:41 +01:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 15:06:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-05 13:45:50 +02: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 15:06:16 +01:00
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
2022-10-13 01:34:23 +02:00
|
|
|
switch (ev.dataTransfer.effectAllowed) {
|
|
|
|
case 'all':
|
|
|
|
case 'uninitialized':
|
2023-07-08 00:08:16 +02:00
|
|
|
case 'copy':
|
|
|
|
case 'copyLink':
|
|
|
|
case 'copyMove':
|
2022-10-13 01:34:23 +02:00
|
|
|
ev.dataTransfer.dropEffect = 'copy';
|
|
|
|
break;
|
|
|
|
case 'linkMove':
|
|
|
|
case 'move':
|
|
|
|
ev.dataTransfer.dropEffect = 'move';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
|
|
|
break;
|
|
|
|
}
|
2022-01-18 15:06:16 +01:00
|
|
|
} else {
|
2022-01-19 17:27:41 +01:00
|
|
|
ev.dataTransfer.dropEffect = 'none';
|
2022-01-18 15:06:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragenter() {
|
|
|
|
if (!isDragging.value) draghover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragleave() {
|
|
|
|
draghover.value = false;
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
function onDrop(ev: DragEvent) {
|
2022-01-18 15:06:16 +01:00
|
|
|
draghover.value = false;
|
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 15:06:16 +01:00
|
|
|
|
|
|
|
// ファイルだったら
|
2022-01-19 17:27:41 +01:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
for (const file of Array.from(ev.dataTransfer.files)) {
|
2022-01-18 15:06:16 +01:00
|
|
|
emit('upload', file, props.folder);
|
2018-02-14 11:03:48 +01:00
|
|
|
}
|
2022-01-18 15:06:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#region ドライブのファイル
|
2022-01-19 17:27:41 +01:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
2022-05-05 13:45:50 +02:00
|
|
|
if (driveFile != null && driveFile !== '') {
|
2022-01-18 15:06:16 +01:00
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
emit('removeFile', file.id);
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/files/update', {
|
2022-01-18 15:06:16 +01:00
|
|
|
fileId: file.id,
|
2022-08-30 17:24:33 +02:00
|
|
|
folderId: props.folder.id,
|
2022-01-18 15:06:16 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
2022-01-19 17:27:41 +01:00
|
|
|
const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
|
2022-05-05 13:45:50 +02:00
|
|
|
if (driveFolder != null && driveFolder !== '') {
|
2022-01-18 15:06:16 +01:00
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
|
|
|
|
// 移動先が自分自身ならreject
|
2022-05-05 13:45:50 +02:00
|
|
|
if (folder.id === props.folder.id) return;
|
2022-01-18 15:06:16 +01:00
|
|
|
|
|
|
|
emit('removeFolder', folder.id);
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/folders/update', {
|
2022-01-18 15:06:16 +01:00
|
|
|
folderId: folder.id,
|
2022-08-30 17:24:33 +02:00
|
|
|
parentId: props.folder.id,
|
2022-01-18 15:06:16 +01:00
|
|
|
}).then(() => {
|
|
|
|
// noop
|
|
|
|
}).catch(err => {
|
2023-01-21 05:14:55 +01:00
|
|
|
switch (err.code) {
|
|
|
|
case 'RECURSIVE_NESTING':
|
|
|
|
claimAchievement('driveFolderCircularReference');
|
2022-01-18 15:06:16 +01:00
|
|
|
os.alert({
|
2023-01-21 05:14:55 +01:00
|
|
|
type: 'error',
|
2022-01-28 03:39:49 +01:00
|
|
|
title: i18n.ts.unableToProcess,
|
2022-08-30 17:24:33 +02:00
|
|
|
text: i18n.ts.circularReferenceFolder,
|
2022-01-18 15:06:16 +01:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-08-30 17:24:33 +02:00
|
|
|
text: i18n.ts.somethingHappened,
|
2022-01-18 15:06:16 +01:00
|
|
|
});
|
2018-02-26 22:25:17 +01:00
|
|
|
}
|
2022-01-18 15:06:16 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
2018-02-26 22:25:17 +01:00
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
function onDragstart(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2018-02-26 22:25:17 +01:00
|
|
|
|
2022-01-19 17:27:41 +01:00
|
|
|
ev.dataTransfer.effectAllowed = 'move';
|
|
|
|
ev.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FOLDER_, JSON.stringify(props.folder));
|
2022-01-18 15:06:16 +01:00
|
|
|
isDragging.value = true;
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
|
|
|
emit('dragstart');
|
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
function onDragend() {
|
|
|
|
isDragging.value = false;
|
|
|
|
emit('dragend');
|
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
function go() {
|
2024-01-30 11:53:53 +01:00
|
|
|
emit('move', props.folder);
|
2022-01-18 15:06:16 +01:00
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
function rename() {
|
|
|
|
os.inputText({
|
2022-01-28 03:39:49 +01:00
|
|
|
title: i18n.ts.renameFolder,
|
|
|
|
placeholder: i18n.ts.inputNewFolderName,
|
2022-08-30 17:24:33 +02:00
|
|
|
default: props.folder.name,
|
2022-01-18 15:06:16 +01:00
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/folders/update', {
|
2022-01-18 15:06:16 +01:00
|
|
|
folderId: props.folder.id,
|
2022-08-30 17:24:33 +02:00
|
|
|
name: name,
|
2022-01-18 15:06:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
|
2022-01-18 15:06:16 +01:00
|
|
|
function deleteFolder() {
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/folders/delete', {
|
2022-08-30 17:24:33 +02:00
|
|
|
folderId: props.folder.id,
|
2022-01-18 15:06:16 +01:00
|
|
|
}).then(() => {
|
|
|
|
if (defaultStore.state.uploadFolder === props.folder.id) {
|
|
|
|
defaultStore.set('uploadFolder', null);
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
2022-06-10 07:36:55 +02:00
|
|
|
switch (err.id) {
|
2022-01-18 15:06:16 +01:00
|
|
|
case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-01-28 03:39:49 +01:00
|
|
|
title: i18n.ts.unableToDelete,
|
2022-08-30 17:24:33 +02:00
|
|
|
text: i18n.ts.hasChildFilesOrFolders,
|
2018-02-14 11:03:48 +01:00
|
|
|
});
|
2022-01-18 15:06:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-08-30 17:24:33 +02:00
|
|
|
text: i18n.ts.unableToDelete,
|
2018-02-18 04:35:18 +01:00
|
|
|
});
|
2022-01-18 15:06:16 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAsUploadFolder() {
|
|
|
|
defaultStore.set('uploadFolder', props.folder.id);
|
|
|
|
}
|
|
|
|
|
2022-01-19 15:51:37 +01:00
|
|
|
function onContextmenu(ev: MouseEvent) {
|
2023-12-13 08:56:19 +01:00
|
|
|
let menu: MenuItem[];
|
2023-07-08 11:45:41 +02:00
|
|
|
menu = [{
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.openInWindow,
|
2022-12-20 07:24:31 +01:00
|
|
|
icon: 'ti ti-app-window',
|
2022-01-18 15:06:16 +01:00
|
|
|
action: () => {
|
2022-08-30 17:24:33 +02:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkDriveWindow.vue')), {
|
|
|
|
initialFolder: props.folder,
|
2022-01-18 15:06:16 +01:00
|
|
|
}, {
|
|
|
|
}, 'closed');
|
2022-08-30 17:24:33 +02:00
|
|
|
},
|
2023-12-13 08:56:19 +01:00
|
|
|
}, { type: 'divider' }, {
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.rename,
|
2022-12-21 00:39:28 +01:00
|
|
|
icon: 'ti ti-forms',
|
2022-01-18 15:06:16 +01:00
|
|
|
action: rename,
|
2023-12-13 08:56:19 +01:00
|
|
|
}, { type: 'divider' }, {
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.delete,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-trash',
|
2022-01-18 15:06:16 +01:00
|
|
|
danger: true,
|
|
|
|
action: deleteFolder,
|
2023-07-08 11:45:41 +02:00
|
|
|
}];
|
|
|
|
if (defaultStore.state.devMode) {
|
2023-12-13 08:56:19 +01:00
|
|
|
menu = menu.concat([{ type: 'divider' }, {
|
2023-07-08 11:45:41 +02:00
|
|
|
icon: 'ti ti-id',
|
|
|
|
text: i18n.ts.copyFolderId,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(props.folder.id);
|
|
|
|
},
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
os.contextMenu(menu, ev);
|
2022-01-18 15:06:16 +01:00
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
</script>
|
|
|
|
|
2023-05-29 13:05:46 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-29 20:37:25 +01:00
|
|
|
position: relative;
|
|
|
|
padding: 8px;
|
|
|
|
height: 64px;
|
|
|
|
background: var(--driveFolderBg);
|
|
|
|
border-radius: 4px;
|
2023-05-29 13:05:46 +02:00
|
|
|
cursor: pointer;
|
2020-04-21 17:34:56 +02:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
&.draghover {
|
2020-01-29 20:37:25 +01:00
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
pointer-events: none;
|
|
|
|
position: absolute;
|
|
|
|
top: -4px;
|
|
|
|
right: -4px;
|
|
|
|
bottom: -4px;
|
|
|
|
left: -4px;
|
|
|
|
border: 2px dashed var(--focus);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
}
|
2023-05-29 13:05:46 +02:00
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-05-29 13:05:46 +02:00
|
|
|
.checkbox {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 8px;
|
|
|
|
right: 8px;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
background: #fff;
|
|
|
|
border: solid 1px #000;
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
background: var(--accent);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2023-05-29 13:05:46 +02:00
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-05-29 13:05:46 +02:00
|
|
|
.name {
|
|
|
|
margin: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
color: var(--desktopDriveFolderFg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
margin-right: 4px;
|
|
|
|
margin-left: 2px;
|
|
|
|
text-align: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
.upload {
|
|
|
|
margin: 4px 4px;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: right;
|
|
|
|
color: var(--desktopDriveFolderFg);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2018-02-14 11:03:48 +01:00
|
|
|
</style>
|