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