2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2022-08-30 15:24:33 +00:00
|
|
|
<div
|
2023-05-29 11:05:46 +00:00
|
|
|
:class="[$style.root, { [$style.isSelected]: isSelected }]"
|
2021-11-19 10:36:12 +00:00
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
2020-01-29 19:37:25 +00:00
|
|
|
@click="onClick"
|
2020-10-17 11:12:00 +00:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2020-01-29 19:37:25 +00:00
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
2023-05-29 11:05:46 +00:00
|
|
|
<div style="pointer-events: none;">
|
|
|
|
<div v-if="$i?.avatarId == file.id" :class="[$style.label]">
|
|
|
|
<img :class="$style.labelImg" src="/client-assets/label.svg"/>
|
|
|
|
<p :class="$style.labelText">{{ i18n.ts.avatar }}</p>
|
|
|
|
</div>
|
|
|
|
<div v-if="$i?.bannerId == file.id" :class="[$style.label]">
|
|
|
|
<img :class="$style.labelImg" src="/client-assets/label.svg"/>
|
|
|
|
<p :class="$style.labelText">{{ i18n.ts.banner }}</p>
|
|
|
|
</div>
|
|
|
|
<div v-if="file.isSensitive" :class="[$style.label, $style.red]">
|
|
|
|
<img :class="$style.labelImg" src="/client-assets/label-red.svg"/>
|
2023-07-20 11:18:55 +00:00
|
|
|
<p :class="$style.labelText">{{ i18n.ts.sensitive }}</p>
|
2023-05-29 11:05:46 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<MkDriveFileThumbnail :class="$style.thumbnail" :file="file" fit="contain"/>
|
|
|
|
|
|
|
|
<p :class="$style.name">
|
2023-07-13 22:59:54 +00:00
|
|
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substring(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
|
|
|
<span v-if="file.name.lastIndexOf('.') != -1" style="opacity: 0.5;">{{ file.name.substring(file.name.lastIndexOf('.')) }}</span>
|
2023-05-29 11:05:46 +00:00
|
|
|
</p>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-18 14:06:16 +00:00
|
|
|
<script lang="ts" setup>
|
2023-03-20 04:20:21 +00:00
|
|
|
import { computed, ref } from 'vue';
|
2022-01-18 14:06:16 +00:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
|
2023-09-19 07:37:43 +00:00
|
|
|
import bytes from '@/filters/bytes.js';
|
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { $i } from '@/account.js';
|
2023-10-10 01:43:43 +00:00
|
|
|
import { useRouter } from '@/router.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import { getDriveFileMenu } from '@/scripts/get-drive-file-menu.js';
|
2023-11-02 23:01:22 +00:00
|
|
|
import { deviceKind } from '@/scripts/device-kind.js';
|
2022-01-18 14:06:16 +00:00
|
|
|
|
2023-10-10 01:43:43 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
2022-01-18 14:06:16 +00:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
file: Misskey.entities.DriveFile;
|
2023-07-05 04:54:40 +00:00
|
|
|
folder: Misskey.entities.DriveFolder | null;
|
2022-01-18 14:06:16 +00:00
|
|
|
isSelected?: boolean;
|
|
|
|
selectMode?: boolean;
|
|
|
|
}>(), {
|
|
|
|
isSelected: false,
|
|
|
|
selectMode: false,
|
|
|
|
});
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-18 14:06:16 +00:00
|
|
|
const emit = defineEmits<{
|
2022-05-05 11:45:50 +00:00
|
|
|
(ev: 'chosen', r: Misskey.entities.DriveFile): void;
|
|
|
|
(ev: 'dragstart'): void;
|
|
|
|
(ev: 'dragend'): void;
|
2022-01-18 14:06:16 +00:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const isDragging = ref(false);
|
|
|
|
|
|
|
|
const title = computed(() => `${props.file.name}\n${props.file.type} ${bytes(props.file.size)}`);
|
|
|
|
|
|
|
|
function onClick(ev: MouseEvent) {
|
|
|
|
if (props.selectMode) {
|
|
|
|
emit('chosen', props.file);
|
|
|
|
} else {
|
2023-11-02 23:01:22 +00:00
|
|
|
if (deviceKind === 'desktop') {
|
|
|
|
router.push(`/my/drive/file/${props.file.id}`);
|
|
|
|
} else {
|
|
|
|
os.popupMenu(getDriveFileMenu(props.file, props.folder), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined);
|
|
|
|
}
|
2022-01-18 14:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-05-05 11:45:50 +00:00
|
|
|
function onContextmenu(ev: MouseEvent) {
|
2023-07-05 04:54:40 +00:00
|
|
|
os.contextMenu(getDriveFileMenu(props.file, props.folder), ev);
|
2022-01-18 14:06:16 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-05-05 11:45:50 +00:00
|
|
|
function onDragstart(ev: DragEvent) {
|
|
|
|
if (ev.dataTransfer) {
|
|
|
|
ev.dataTransfer.effectAllowed = 'move';
|
|
|
|
ev.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(props.file));
|
2022-01-18 14:06:16 +00:00
|
|
|
}
|
|
|
|
isDragging.value = true;
|
|
|
|
|
|
|
|
emit('dragstart');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragend() {
|
|
|
|
isDragging.value = false;
|
|
|
|
emit('dragend');
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
</script>
|
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-29 19:37:25 +00:00
|
|
|
position: relative;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
min-height: 180px;
|
2021-12-10 01:46:29 +00:00
|
|
|
border-radius: 8px;
|
2023-05-29 11:05:46 +00:00
|
|
|
cursor: pointer;
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&:hover {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b65a5;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: rgba(#000, 0.1);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b588c;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #ce2212;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
&.isSelected {
|
2020-01-29 19:37:25 +00:00
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--accentLighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: var(--accentDarken);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
2023-05-29 11:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
pointer-events: none;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
2020-01-29 19:37:25 +00:00
|
|
|
position: absolute;
|
2023-05-29 11:05:46 +00:00
|
|
|
z-index: 1;
|
|
|
|
background: #0c7ac9;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:before {
|
2020-01-29 19:37:25 +00:00
|
|
|
top: 0;
|
2023-05-29 11:05:46 +00:00
|
|
|
left: 57px;
|
|
|
|
width: 28px;
|
|
|
|
height: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
top: 57px;
|
2020-01-29 19:37:25 +00:00
|
|
|
left: 0;
|
2023-05-29 11:05:46 +00:00
|
|
|
width: 8px;
|
|
|
|
height: 28px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
&.red {
|
2020-01-29 19:37:25 +00:00
|
|
|
&:before,
|
|
|
|
&:after {
|
2023-05-29 11:05:46 +00:00
|
|
|
background: #c12113;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2023-05-29 11:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
.labelImg {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
.labelText {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 3;
|
|
|
|
top: 19px;
|
|
|
|
left: -28px;
|
|
|
|
width: 120px;
|
|
|
|
margin: 0;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 28px;
|
|
|
|
color: #fff;
|
|
|
|
transform: rotate(-45deg);
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
.thumbnail {
|
|
|
|
width: 110px;
|
|
|
|
height: 110px;
|
|
|
|
margin: auto;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-05-29 11:05:46 +00:00
|
|
|
.name {
|
|
|
|
display: block;
|
|
|
|
margin: 4px 0 0 0;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: center;
|
|
|
|
word-break: break-all;
|
|
|
|
color: var(--fg);
|
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
</style>
|