egirlskey/packages/frontend/src/ui/deck/column.vue

433 lines
10 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
2023-05-20 01:12:18 +00:00
<div
:class="[$style.root, { [$style.paged]: isMainColumn, [$style.naked]: naked, [$style.active]: active, [$style.draghover]: draghover, [$style.dragging]: dragging, [$style.dropready]: dropready }]"
@dragover.prevent.stop="onDragover"
@dragleave="onDragleave"
@drop.prevent.stop="onDrop"
>
2022-07-03 11:30:58 +00:00
<header
2023-01-10 01:30:38 +00:00
:class="[$style.header]"
draggable="true"
@click="goTop"
@dragstart="onDragstart"
@dragend="onDragend"
@contextmenu.prevent.stop="onContextmenu"
@wheel="emit('headerWheel', $event)"
>
2023-05-26 01:48:49 +00:00
<svg viewBox="0 0 256 128" :class="$style.tabShape">
<g transform="matrix(6.2431,0,0,6.2431,-677.417,-29.3839)">
2023-05-26 02:31:39 +00:00
<path d="M149.512,4.707L108.507,4.707C116.252,4.719 118.758,14.958 118.758,14.958C118.758,14.958 121.381,25.283 129.009,25.209L149.512,25.209L149.512,4.707Z" style="fill:var(--deckBg);"/>
2023-05-26 01:48:49 +00:00
</g>
</svg>
2023-05-26 02:31:39 +00:00
<div :class="$style.color"></div>
2023-01-10 00:53:01 +00:00
<button v-if="isStacked && !isMainColumn" :class="$style.toggleActive" class="_button" @click="toggleActive">
2023-09-30 19:53:52 +00:00
<template v-if="active"><i class="ph-caret-up ph-bold ph-lg"></i></template>
<template v-else><i class="ph-caret-down ph-bold ph-lg"></i></template>
</button>
2023-01-10 00:53:01 +00:00
<span :class="$style.title"><slot name="header"></slot></span>
2023-06-01 09:07:30 +00:00
<svg viewBox="0 0 16 16" version="1.1" :class="$style.grabber">
<path fill="currentColor" d="M10 13a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm0-4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm-4 4a1 1 0 1 1 0-2 1 1 0 0 1 0 2Zm5-9a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM7 8a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM6 5a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"></path>
</svg>
2023-09-30 19:53:52 +00:00
<button v-tooltip="i18n.ts.settings" :class="$style.menu" class="_button" @click.stop="showSettingsMenu"><i class="ph-dots-three ph-bold ph-lg"></i></button>
</header>
2023-05-20 01:12:18 +00:00
<div v-if="active" ref="body" :class="$style.body">
<slot></slot>
</div>
2023-05-20 01:12:18 +00:00
</div>
</template>
<script lang="ts" setup>
import { onBeforeUnmount, onMounted, provide, watch, shallowRef, ref, computed } from 'vue';
import { updateColumn, swapLeftColumn, swapRightColumn, swapUpColumn, swapDownColumn, stackLeftColumn, popRightColumn, removeColumn, swapColumn, Column } from './deck-store.js';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { MenuItem } from '@/types/menu.js';
provide('shouldHeaderThin', true);
provide('shouldOmitHeaderTitle', true);
provide('forceSpacerMin', true);
const props = withDefaults(defineProps<{
column: Column;
isStacked?: boolean;
naked?: boolean;
2022-07-16 20:33:21 +00:00
menu?: MenuItem[];
refresher?: () => Promise<void>;
}>(), {
isStacked: false,
naked: false,
});
const emit = defineEmits<{
(ev: 'headerWheel', ctx: WheelEvent): void;
}>();
const body = shallowRef<HTMLDivElement | null>();
const dragging = ref(false);
watch(dragging, v => os.deckGlobalEvents.emit(v ? 'column.dragStart' : 'column.dragEnd'));
const draghover = ref(false);
const dropready = ref(false);
const isMainColumn = computed(() => props.column.type === 'main');
const active = computed(() => props.column.active !== false);
onMounted(() => {
os.deckGlobalEvents.on('column.dragStart', onOtherDragStart);
os.deckGlobalEvents.on('column.dragEnd', onOtherDragEnd);
});
onBeforeUnmount(() => {
os.deckGlobalEvents.off('column.dragStart', onOtherDragStart);
os.deckGlobalEvents.off('column.dragEnd', onOtherDragEnd);
});
function onOtherDragStart() {
dropready.value = true;
}
function onOtherDragEnd() {
dropready.value = false;
}
function toggleActive() {
if (!props.isStacked) return;
updateColumn(props.column.id, {
2022-07-03 11:30:58 +00:00
active: !props.column.active,
});
}
function getMenu() {
let items: MenuItem[] = [{
icon: 'ph-gear ph-bold ph-lg',
2022-07-16 20:33:21 +00:00
text: i18n.ts._deck.configureColumn,
action: async () => {
const { canceled, result } = await os.form(props.column.name, {
name: {
type: 'string',
label: i18n.ts.name,
2022-07-03 11:30:58 +00:00
default: props.column.name,
},
width: {
type: 'number',
label: i18n.ts.width,
description: i18n.ts._deck.usedAsMinWidthWhenFlexible,
2022-07-03 11:30:58 +00:00
default: props.column.width,
},
flexible: {
type: 'boolean',
label: i18n.ts._deck.flexible,
2022-07-03 11:30:58 +00:00
default: props.column.flexible,
},
});
if (canceled) return;
updateColumn(props.column.id, result);
2022-07-03 11:30:58 +00:00
},
}, {
2022-07-17 14:18:05 +00:00
type: 'parent',
text: i18n.ts.move + '...',
2023-09-30 22:46:42 +00:00
icon: 'ph-arrows-out-cardinal ph-bold ph-lg',
2022-07-17 14:18:05 +00:00
children: [{
icon: 'ph-arrow-left ph-bold ph-lg',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapLeft,
action: () => {
swapLeftColumn(props.column.id);
},
}, {
icon: 'ph-arrow-right ph-bold ph-lg',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapRight,
action: () => {
swapRightColumn(props.column.id);
},
}, props.isStacked ? {
2023-09-30 22:46:42 +00:00
icon: 'ph-arrow-up ph-bold ph-lg',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapUp,
action: () => {
swapUpColumn(props.column.id);
},
} : undefined, props.isStacked ? {
2023-09-30 22:46:42 +00:00
icon: 'ph-arrow-down ph-bold ph-lg',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapDown,
action: () => {
swapDownColumn(props.column.id);
},
} : undefined],
}, {
2023-09-30 22:46:42 +00:00
icon: 'ph-stack ph-bold ph-lg',
text: i18n.ts._deck.stackLeft,
action: () => {
stackLeftColumn(props.column.id);
2022-07-03 11:30:58 +00:00
},
}, props.isStacked ? {
2023-09-30 22:46:42 +00:00
icon: 'ph-frame-corners ph-bold ph-lg',
text: i18n.ts._deck.popRight,
action: () => {
popRightColumn(props.column.id);
2022-07-03 11:30:58 +00:00
},
} : undefined, { type: 'divider' }, {
2023-09-30 19:53:52 +00:00
icon: 'ph-trash ph-bold ph-lg',
text: i18n.ts.remove,
danger: true,
action: () => {
removeColumn(props.column.id);
2022-07-03 11:30:58 +00:00
},
}];
2022-07-03 11:30:58 +00:00
2022-07-16 20:33:21 +00:00
if (props.menu) {
items.unshift({ type: 'divider' });
2022-07-16 20:33:21 +00:00
items = props.menu.concat(items);
2022-07-03 11:30:58 +00:00
}
if (props.refresher) {
items = [{
2023-11-23 18:22:34 +00:00
icon: 'ph-arrows-counter-clockwise ph-bold ph-lg',
text: i18n.ts.reload,
action: () => {
if (props.refresher) {
props.refresher();
}
},
}, ...items];
}
return items;
}
2022-07-03 11:30:58 +00:00
function showSettingsMenu(ev: MouseEvent) {
os.popupMenu(getMenu(), ev.currentTarget ?? ev.target);
}
function onContextmenu(ev: MouseEvent) {
os.contextMenu(getMenu(), ev);
}
function goTop() {
if (body.value) {
body.value.scrollTo({
2023-05-20 01:12:18 +00:00
top: 0,
behavior: 'smooth',
});
}
}
function onDragstart(ev) {
ev.dataTransfer.effectAllowed = 'move';
ev.dataTransfer.setData(_DATA_TRANSFER_DECK_COLUMN_, props.column.id);
// Chromeのバグで、Dragstartハンドラ内ですぐにDOMを変更する(=リアクティブなプロパティを変更する)とDragが終了してしまう
// SEE: https://stackoverflow.com/questions/19639969/html5-dragend-event-firing-immediately
window.setTimeout(() => {
dragging.value = true;
}, 10);
}
function onDragend(ev) {
dragging.value = false;
}
function onDragover(ev) {
// 自分自身がドラッグされている場合
if (dragging.value) {
// 自分自身にはドロップさせない
ev.dataTransfer.dropEffect = 'none';
} else {
const isDeckColumn = ev.dataTransfer.types[0] === _DATA_TRANSFER_DECK_COLUMN_;
ev.dataTransfer.dropEffect = isDeckColumn ? 'move' : 'none';
if (isDeckColumn) draghover.value = true;
}
}
function onDragleave() {
draghover.value = false;
}
function onDrop(ev) {
draghover.value = false;
os.deckGlobalEvents.emit('column.dragEnd');
const id = ev.dataTransfer.getData(_DATA_TRANSFER_DECK_COLUMN_);
if (id != null && id !== '') {
swapColumn(props.column.id, id);
}
}
</script>
2023-01-10 00:53:01 +00:00
<style lang="scss" module>
.root {
--root-margin: 10px;
2023-04-22 11:22:09 +00:00
--deckColumnHeaderHeight: 38px;
Migrate to Vue3 (#6587) * Update reaction.vue * fix bug * wip * wip * wjio * wip * Revert "wip" This reverts commit e427f2160adf4e8a4147006e25a89854edab0033. * wip * wip * wip * Update init.ts * Update drive-window.vue * wip * wip * Use PascalCase for components * Use PascalCase for components * update dep * wip * wip * wip * Update init.ts * wip * Update paging.ts * Update test.vue * watch deep * wip * lint * wip * wip * wip * wip * wiop * wip * Update webpack.config.ts * alllow null poll * wip * wip * wip * wiop * UI redesign & refactor (#6714) * wip * wip * wip * wip * wip * Update drive.vue * Update word-mute.vue * wip * wip * wip * clean up * wip * Update default.vue * wip * Update notes.vue * Update mfm.ts * Update index.home.vue * Update post-form.vue * Update post-form-attaches.vue * wip * Update post-form.vue * Update sidebar.vue * wip * wip * Update index.vue * wip * Update default.vue * Update index.vue * Update index.vue * wip * Update post-form-attaches.vue * Update note.vue * wip * clean up * Update notes.vue * wip * wip * Update ja-JP.yml * wip * wip * Update index.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update default.vue * wip * Update _dark.json5 * wip * wip * wip * clean up * wip * wip * Update index.vue * Update test.vue * wip * wip * fix * wip * wip * wip * wip * clena yop * wip * wip * Update store.ts * Update messaging-room.vue * Update default.widgets.vue * fix * wip * wip * Update modal.vue * wip * Update os.ts * Update os.ts * Update deck.vue * Update init.ts * wip * Update ja-JP.yml * v-sizeは単にwindowのresizeを監視するだけで良いかもしれない * Update modal.vue * wip * Update tooltip.ts * wip * wip * wip * wip * wip * Update image-viewer.vue * wip * wip * Update style.scss * Update style.scss * Update visitor.vue * wip * Update init.ts * Update init.ts * wip * wip * Update visitor.vue * Update visitor.vue * Update visitor.vue * Update visitor.vue * wip * wip * Update modal.vue * Update header.vue * Update menu.vue * Update about.vue * Update about-misskey.vue * wip * wip * Update visitor.vue * Update tooltip.ts * wip * Update drive.vue * wip * Update style.scss * Update header.vue * wip * wip * Update users.user.vue * Update announcements.vue * wip * wip * wip * Update emojis.vue * wip * Update emojis.vue * Update style.scss * Update users.vue * wip * Update style.scss * wip * Update welcome.entrance.vue * Update radio.vue * Update size.ts * Update emoji-edit-dialog.vue * wip * Update emojis.vue * wip * Update emojis.vue * Update emojis.vue * Update emojis.vue * wip * wip * wip * wip * Update file-dialog.vue * wip * wip * Update token-generate-window.vue * Update notification-setting-window.vue * wip * wip * Update _error_.vue * Update ja-JP.yml * wip * wip * Update store.ts * Update emojis.vue * Update emojis.vue * Update emojis.vue * Update announcements.vue * Update store.ts * wip * Update page-editor.vue * wip * wip * Update modal.vue * wip * Update select-file.ts * Update timeline.vue * Update emojis.vue * Update os.ts * wip * Update user-select.vue * Update mfm.ts * Update get-file-info.ts * Update drive.vue * Update init.ts * Update mfm.ts * wip * wip * Update window.vue * Update note.vue * wip * wip * Update user-info.vue * wip * wip * wip * wip * wip * Update header.vue * Update header.vue * wip * Update explore.vue * wip * wip * wip * Update webpack.config.ts * wip * wip * wip * wip * wip * wip * Update autocomplete.ts * wip * wip * wip * Update toast.vue * wip * Update post-form-dialog.vue * wip * wip * wip * wip * wip * Update users.vue * wip * Update explore.vue * wip * wip * wip * Update package.json * wip * Update icon-dialog.vue * wip * wip * Update user-preview.ts * wip * wip * wip * wip * wip * Update instance.vue * Update user-name.vue * Update federation.vue * Update instance.vue * wip * wip * Update tag.vue * wip * wip * wip * wip * wip * Update instance.vue * wip * Update os.ts * Update os.ts * wip * wip * wip * Update router.ts * wip * Update init.ts * Update note.vue * Update messages.vue * wip * wip * wip * wip * wip * google * wip * wip * wip * wip * Update theme-editor.vue * wip * wip * Update room.vue * Update channel-editor.vue * wip * Update window.vue * Update window.vue * wip * Update window.vue * Update window.vue * wip * Update menu.vue * wip * wip * wip * wip * Update messaging-room.vue * wip * Update post-form.vue * Update default.widgets.vue * Update window.vue * wip
2020-10-17 11:12:00 +00:00
height: 100%;
overflow: clip;
2022-07-03 11:30:58 +00:00
contain: strict;
border-radius: var(--radius);
&.draghover {
&:after {
content: "";
display: block;
position: absolute;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--focus);
}
}
&.dragging {
2022-07-03 11:30:58 +00:00
&:after {
content: "";
display: block;
position: absolute;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: var(--focus);
opacity: 0.5;
}
}
&.dropready {
* {
pointer-events: none;
}
}
&:not(.active) {
2020-12-26 13:41:00 +00:00
flex-basis: var(--deckColumnHeaderHeight);
min-height: var(--deckColumnHeaderHeight);
2023-05-26 02:31:39 +00:00
border-bottom-right-radius: 0;
}
&.naked {
2020-12-20 08:19:18 +00:00
background: var(--acrylicBg) !important;
2021-08-11 13:34:45 +00:00
-webkit-backdrop-filter: var(--blur, blur(10px));
backdrop-filter: var(--blur, blur(10px));
2023-01-10 00:53:01 +00:00
> .header {
background: transparent;
box-shadow: none;
2023-01-10 00:53:01 +00:00
color: var(--fg);
}
2023-05-26 02:31:39 +00:00
> .body {
2023-05-29 10:35:11 +00:00
background: transparent !important;
2023-05-26 02:31:39 +00:00
&::-webkit-scrollbar-track {
2023-05-29 10:35:11 +00:00
background: transparent;
2023-05-26 02:31:39 +00:00
}
scrollbar-color: var(--scrollbarHandle) transparent;
2023-05-26 02:31:39 +00:00
}
}
&.paged {
2020-12-28 08:00:31 +00:00
background: var(--bg) !important;
2023-05-26 02:31:39 +00:00
> .body {
2023-05-29 10:35:11 +00:00
background: var(--bg) !important;
2023-06-11 00:53:07 +00:00
overflow-y: scroll !important;
2023-05-29 10:35:11 +00:00
2023-05-26 02:31:39 +00:00
&::-webkit-scrollbar-track {
background: inherit;
}
scrollbar-color: var(--scrollbarHandle) transparent;
2023-05-26 02:31:39 +00:00
}
}
2023-01-10 00:53:01 +00:00
}
2023-01-10 00:53:01 +00:00
.header {
position: relative;
display: flex;
z-index: 2;
line-height: var(--deckColumnHeaderHeight);
height: var(--deckColumnHeaderHeight);
2023-05-26 04:24:31 +00:00
padding: 0 16px 0 30px;
2023-01-10 00:53:01 +00:00
font-size: 0.9em;
color: var(--panelHeaderFg);
background: var(--panelHeaderBg);
box-shadow: 0 1px 0 0 var(--panelHeaderDivider);
2023-01-10 00:53:01 +00:00
cursor: pointer;
2023-04-21 00:34:36 +00:00
user-select: none;
2023-01-10 00:53:01 +00:00
}
2023-05-26 02:31:39 +00:00
.color {
position: absolute;
2023-05-26 04:24:31 +00:00
top: 12px;
left: 12px;
2023-05-26 02:31:39 +00:00
width: 3px;
2023-05-26 04:24:31 +00:00
height: calc(100% - 24px);
2023-05-26 02:31:39 +00:00
background: var(--accent);
border-radius: var(--radius-ellipse);
2023-05-26 02:31:39 +00:00
}
2023-05-26 01:48:49 +00:00
.tabShape {
position: absolute;
top: 0;
right: -8px;
width: auto;
height: calc(100% - 6px);
}
2023-01-10 00:53:01 +00:00
.title {
display: inline-block;
align-items: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
}
2023-01-10 00:53:01 +00:00
.toggleActive,
.menu {
z-index: 1;
width: var(--deckColumnHeaderHeight);
line-height: var(--deckColumnHeaderHeight);
}
2023-01-10 00:53:01 +00:00
.toggleActive {
margin-left: -16px;
}
2023-06-01 09:07:30 +00:00
.grabber {
2023-01-10 00:53:01 +00:00
margin-left: auto;
2023-06-01 09:07:30 +00:00
margin-right: 10px;
padding: 8px 8px;
box-sizing: border-box;
height: var(--deckColumnHeaderHeight);
cursor: move;
user-select: none;
2023-06-01 10:45:06 +00:00
opacity: 0.5;
2023-06-01 09:07:30 +00:00
}
.menu {
2023-01-10 00:53:01 +00:00
margin-right: -16px;
}
2023-01-10 00:53:01 +00:00
.body {
height: calc(100% - var(--deckColumnHeaderHeight));
overflow-y: auto;
overflow-x: clip;
2023-05-31 03:24:00 +00:00
overscroll-behavior-y: contain;
2023-01-10 00:53:01 +00:00
box-sizing: border-box;
2023-05-08 09:30:40 +00:00
container-type: size;
2023-01-10 00:53:01 +00:00
background-color: var(--bg);
2023-05-26 02:31:39 +00:00
&::-webkit-scrollbar-track {
background: var(--panel);
}
scrollbar-color: var(--scrollbarHandle) var(--panel);
}
</style>