2018-02-14 19:03:48 +09:00
|
|
|
<template>
|
2023-04-08 09:01:42 +09:00
|
|
|
<div
|
|
|
|
class="rghtznwe"
|
|
|
|
:class="{ draghover }"
|
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
|
|
|
@click="onClick"
|
|
|
|
@contextmenu.stop="onContextmenu"
|
|
|
|
@mouseover="onMouseover"
|
|
|
|
@mouseout="onMouseout"
|
|
|
|
@dragover.prevent.stop="onDragover"
|
|
|
|
@dragenter.prevent="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.prevent.stop="onDrop"
|
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
|
|
|
<p class="name">
|
|
|
|
<template v-if="hover"
|
|
|
|
><i class="ph-folder-notch-open ph-bold ph-lg ph-fw ph-lg"></i
|
|
|
|
></template>
|
|
|
|
<template v-if="!hover"
|
|
|
|
><i class="ph-folder-notch ph-bold ph-lg ph-fw ph-lg"></i
|
|
|
|
></template>
|
|
|
|
{{ folder.name }}
|
|
|
|
</p>
|
|
|
|
<p v-if="defaultStore.state.uploadFolder == folder.id" class="upload">
|
|
|
|
{{ i18n.ts.uploadFolder }}
|
|
|
|
</p>
|
|
|
|
<button
|
|
|
|
v-if="selectMode"
|
|
|
|
class="checkbox _button"
|
|
|
|
:class="{ checked: isSelected }"
|
|
|
|
@click.prevent.stop="checkboxClicked"
|
|
|
|
></button>
|
|
|
|
</div>
|
2018-02-14 19:03:48 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 09:01:42 +09:00
|
|
|
import { computed, defineAsyncComponent, ref } from "vue";
|
|
|
|
import * as Misskey from "calckey-js";
|
|
|
|
import * as os from "@/os";
|
|
|
|
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 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 09:01:42 +09: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 23:06:16 +09:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const hover = ref(false);
|
|
|
|
const draghover = ref(false);
|
|
|
|
const isDragging = ref(false);
|
|
|
|
|
|
|
|
const title = computed(() => props.folder.name);
|
|
|
|
|
2022-01-20 01:27:41 +09:00
|
|
|
function checkboxClicked() {
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("chosen", props.folder);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function onClick() {
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("move", props.folder);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseover() {
|
|
|
|
hover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseout() {
|
2022-06-10 14:36:55 +09:00
|
|
|
hover.value = false;
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
|
2022-01-20 01:27:41 +09:00
|
|
|
function onDragover(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 23:06:16 +09:00
|
|
|
|
|
|
|
// 自分自身がドラッグされている場合
|
|
|
|
if (isDragging.value) {
|
|
|
|
// 自分自身にはドロップさせない
|
2023-04-08 09:01:42 +09:00
|
|
|
ev.dataTransfer.dropEffect = "none";
|
2022-01-18 23:06:16 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === "file";
|
2022-05-05 20:45:50 +09:00
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
2023-04-08 09:01:42 +09:00
|
|
|
const isDriveFolder =
|
|
|
|
ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FOLDER_;
|
2022-01-18 23:06:16 +09:00
|
|
|
|
|
|
|
if (isFile || isDriveFile || isDriveFolder) {
|
2023-04-08 09:01:42 +09:00
|
|
|
ev.dataTransfer.dropEffect =
|
|
|
|
ev.dataTransfer.effectAllowed === "all" ? "copy" : "move";
|
2022-01-18 23:06:16 +09:00
|
|
|
} else {
|
2023-04-08 09:01:42 +09:00
|
|
|
ev.dataTransfer.dropEffect = "none";
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragenter() {
|
|
|
|
if (!isDragging.value) draghover.value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragleave() {
|
|
|
|
draghover.value = false;
|
|
|
|
}
|
|
|
|
|
2022-01-20 01:27:41 +09:00
|
|
|
function onDrop(ev: DragEvent) {
|
2022-01-18 23:06:16 +09:00
|
|
|
draghover.value = false;
|
|
|
|
|
2022-01-20 01:27:41 +09:00
|
|
|
if (!ev.dataTransfer) return;
|
2022-01-18 23:06:16 +09:00
|
|
|
|
|
|
|
// ファイルだったら
|
2022-01-20 01:27:41 +09:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
for (const file of Array.from(ev.dataTransfer.files)) {
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("upload", file, props.folder);
|
2018-02-14 19:03:48 +09:00
|
|
|
}
|
2022-01-18 23:06:16 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#region ドライブのファイル
|
2022-01-20 01:27:41 +09:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
2023-04-08 09:01:42 +09:00
|
|
|
if (driveFile != null && driveFile !== "") {
|
2022-01-18 23:06:16 +09:00
|
|
|
const file = JSON.parse(driveFile);
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("removeFile", file.id);
|
|
|
|
os.api("drive/files/update", {
|
2022-01-18 23:06:16 +09:00
|
|
|
fileId: file.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
folderId: props.folder.id,
|
2022-01-18 23:06:16 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region ドライブのフォルダ
|
2022-01-20 01:27:41 +09:00
|
|
|
const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
|
2023-04-08 09:01:42 +09:00
|
|
|
if (driveFolder != null && driveFolder !== "") {
|
2022-01-18 23:06:16 +09:00
|
|
|
const folder = JSON.parse(driveFolder);
|
|
|
|
|
|
|
|
// 移動先が自分自身ならreject
|
2022-05-05 20:45:50 +09:00
|
|
|
if (folder.id === props.folder.id) return;
|
2022-01-18 23:06:16 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("removeFolder", folder.id);
|
|
|
|
os.api("drive/folders/update", {
|
2022-01-18 23:06:16 +09:00
|
|
|
folderId: folder.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
parentId: props.folder.id,
|
2023-04-08 09:01:42 +09:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
// noop
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
switch (err) {
|
|
|
|
case "detected-circular-definition":
|
|
|
|
os.alert({
|
|
|
|
title: i18n.ts.unableToProcess,
|
|
|
|
text: i18n.ts.circularReferenceFolder,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: i18n.ts.somethingHappened,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
}
|
2018-02-27 06:25:17 +09:00
|
|
|
|
2022-01-20 01:27:41 +09:00
|
|
|
function onDragstart(ev: DragEvent) {
|
|
|
|
if (!ev.dataTransfer) return;
|
2018-02-27 06:25:17 +09:00
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
ev.dataTransfer.effectAllowed = "move";
|
|
|
|
ev.dataTransfer.setData(
|
|
|
|
_DATA_TRANSFER_DRIVE_FOLDER_,
|
|
|
|
JSON.stringify(props.folder)
|
|
|
|
);
|
2022-01-18 23:06:16 +09:00
|
|
|
isDragging.value = true;
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
// 親ブラウザに対して、ドラッグが開始されたフラグを立てる
|
|
|
|
// (=あなたの子供が、ドラッグを開始しましたよ)
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("dragstart");
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
function onDragend() {
|
|
|
|
isDragging.value = false;
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("dragend");
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
function go() {
|
2023-04-08 09:01:42 +09:00
|
|
|
emit("move", props.folder.id);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
function rename() {
|
|
|
|
os.inputText({
|
2022-01-28 11:39:49 +09:00
|
|
|
title: i18n.ts.renameFolder,
|
|
|
|
placeholder: i18n.ts.inputNewFolderName,
|
2022-08-31 00:24:33 +09:00
|
|
|
default: props.folder.name,
|
2022-01-18 23:06:16 +09:00
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2023-04-08 09:01:42 +09:00
|
|
|
os.api("drive/folders/update", {
|
2022-01-18 23:06:16 +09:00
|
|
|
folderId: props.folder.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
name: name,
|
2022-01-18 23:06:16 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
function deleteFolder() {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.api("drive/folders/delete", {
|
2022-08-31 00:24:33 +09:00
|
|
|
folderId: props.folder.id,
|
2023-04-08 09:01:42 +09:00
|
|
|
})
|
|
|
|
.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.ts.unableToDelete,
|
|
|
|
text: i18n.ts.hasChildFilesOrFolders,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: i18n.ts.unableToDelete,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function setAsUploadFolder() {
|
2023-04-08 09:01:42 +09:00
|
|
|
defaultStore.set("uploadFolder", props.folder.id);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
|
2022-01-19 23:51:37 +09:00
|
|
|
function onContextmenu(ev: MouseEvent) {
|
2023-04-08 09:01:42 +09:00
|
|
|
os.contextMenu(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: i18n.ts.openInWindow,
|
|
|
|
icon: "ph-copy ph-bold ph-lg",
|
|
|
|
action: () => {
|
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(
|
|
|
|
() => import("@/components/MkDriveWindow.vue")
|
|
|
|
),
|
|
|
|
{
|
|
|
|
initialFolder: props.folder,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
"closed"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
text: i18n.ts.rename,
|
|
|
|
icon: "ph-cursor-text ph-bold ph-lg",
|
|
|
|
action: rename,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
text: i18n.ts.delete,
|
|
|
|
icon: "ph-trash ph-bold ph-lg",
|
|
|
|
danger: true,
|
|
|
|
action: deleteFolder,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
ev
|
|
|
|
);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
2018-02-14 19:03:48 +09:00
|
|
|
</script>
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rghtznwe {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px;
|
|
|
|
height: 64px;
|
|
|
|
background: var(--driveFolderBg);
|
|
|
|
border-radius: 4px;
|
|
|
|
|
2023-04-08 09:01:42 +09:00
|
|
|
&,
|
|
|
|
* {
|
2020-01-30 04:37:25 +09:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
2019-07-08 04:17:53 +09:00
|
|
|
|
2020-04-22 00:34:56 +09:00
|
|
|
*:not(.checkbox) {
|
2020-01-30 04:37:25 +09:00
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-04-22 00:34:56 +09: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 20:12:00 +09:00
|
|
|
&.draghover {
|
2020-01-30 04:37:25 +09: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 23:22:59 +09:00
|
|
|
> i {
|
2020-01-30 04:37:25 +09: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 19:03:48 +09:00
|
|
|
</style>
|