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

382 lines
8.6 KiB
Vue
Raw Normal View History

<template>
<!-- sectionを利用しているのはdeck.vue側でcolumnに対してfirst-of-typeを効かせるため -->
2022-07-03 11:30:58 +00:00
<section
2023-01-10 00:53:01 +00:00
v-hotkey="keymap"
:class="[$style.root, { [$style.paged]: isMainColumn, [$style.naked]: naked, [$style.active]: active, [$style.isStacked]: isStacked, [$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 00:53:01 +00:00
:class="[$style.header, { [$style.indicated]: indicated }]"
draggable="true"
@click="goTop"
@dragstart="onDragstart"
@dragend="onDragend"
@contextmenu.prevent.stop="onContextmenu"
>
2023-01-10 00:53:01 +00:00
<button v-if="isStacked && !isMainColumn" :class="$style.toggleActive" class="_button" @click="toggleActive">
<template v-if="active"><i class="ti ti-chevron-up"></i></template>
<template v-else><i class="ti ti-chevron-down"></i></template>
</button>
2023-01-10 00:53:01 +00:00
<span :class="$style.title"><slot name="header"></slot></span>
<button v-tooltip="i18n.ts.settings" :class="$style.menu" class="_button" @click.stop="showSettingsMenu"><i class="ti ti-dots"></i></button>
</header>
2023-01-10 00:53:01 +00:00
<div v-show="active" ref="body" :class="$style.body">
<slot></slot>
</div>
</section>
</template>
<script lang="ts" setup>
2022-07-16 20:33:21 +00:00
import { onBeforeUnmount, onMounted, provide, Ref, watch } from 'vue';
import { updateColumn, swapLeftColumn, swapRightColumn, swapUpColumn, swapDownColumn, stackLeftColumn, popRightColumn, removeColumn, swapColumn, Column, deckStore } from './deck-store';
2021-11-11 17:02:25 +00:00
import * as os from '@/os';
import { i18n } from '@/i18n';
2022-07-16 20:33:21 +00:00
import { MenuItem } from '@/types/menu';
provide('shouldHeaderThin', true);
provide('shouldOmitHeaderTitle', true);
provide('forceSpacerMin', true);
const props = withDefaults(defineProps<{
column: Column;
isStacked?: boolean;
naked?: boolean;
indicated?: boolean;
2022-07-16 20:33:21 +00:00
menu?: MenuItem[];
}>(), {
isStacked: false,
naked: false,
indicated: false,
});
const emit = defineEmits<{
(ev: 'parent-focus', direction: 'up' | 'down' | 'left' | 'right'): void;
(ev: 'change-active-state', v: boolean): void;
}>();
let body = $shallowRef<HTMLDivElement>();
let dragging = $ref(false);
watch($$(dragging), v => os.deckGlobalEvents.emit(v ? 'column.dragStart' : 'column.dragEnd'));
let draghover = $ref(false);
let dropready = $ref(false);
const isMainColumn = $computed(() => props.column.type === 'main');
const active = $computed(() => props.column.active !== false);
watch($$(active), v => emit('change-active-state', v));
const keymap = $computed(() => ({
'shift+up': () => emit('parent-focus', 'up'),
'shift+down': () => emit('parent-focus', 'down'),
'shift+left': () => emit('parent-focus', 'left'),
'shift+right': () => emit('parent-focus', 'right'),
}));
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 = true;
}
function onOtherDragEnd() {
dropready = 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() {
2022-07-16 20:33:21 +00:00
let items = [{
icon: 'ti ti-settings',
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,
2022-07-03 11:30:58 +00:00
default: props.column.width,
},
flexible: {
type: 'boolean',
label: i18n.ts.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 + '...',
icon: 'ti ti-arrows-move',
2022-07-17 14:18:05 +00:00
children: [{
icon: 'ti ti-arrow-left',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapLeft,
action: () => {
swapLeftColumn(props.column.id);
},
}, {
icon: 'ti ti-arrow-right',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapRight,
action: () => {
swapRightColumn(props.column.id);
},
}, props.isStacked ? {
icon: 'ti ti-arrow-up',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapUp,
action: () => {
swapUpColumn(props.column.id);
},
} : undefined, props.isStacked ? {
icon: 'ti ti-arrow-down',
2022-07-17 14:18:05 +00:00
text: i18n.ts._deck.swapDown,
action: () => {
swapDownColumn(props.column.id);
},
} : undefined],
}, {
icon: 'ti ti-stack-2',
text: i18n.ts._deck.stackLeft,
action: () => {
stackLeftColumn(props.column.id);
2022-07-03 11:30:58 +00:00
},
}, props.isStacked ? {
icon: 'ti ti-window-maximize',
text: i18n.ts._deck.popRight,
action: () => {
popRightColumn(props.column.id);
2022-07-03 11:30:58 +00:00
},
} : undefined, null, {
icon: 'ti ti-trash',
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) {
2022-07-03 11:30:58 +00:00
items.unshift(null);
2022-07-16 20:33:21 +00:00
items = props.menu.concat(items);
2022-07-03 11:30:58 +00:00
}
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() {
body.scrollTo({
top: 0,
2022-07-03 11:30:58 +00:00
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 = true;
}, 10);
}
function onDragend(ev) {
dragging = false;
}
function onDragover(ev) {
// 自分自身がドラッグされている場合
if (dragging) {
// 自分自身にはドロップさせない
ev.dataTransfer.dropEffect = 'none';
} else {
const isDeckColumn = ev.dataTransfer.types[0] === _DATA_TRANSFER_DECK_COLUMN_;
ev.dataTransfer.dropEffect = isDeckColumn ? 'move' : 'none';
if (isDeckColumn) draghover = true;
}
}
function onDragleave() {
draghover = false;
}
function onDrop(ev) {
draghover = 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;
2022-12-20 07:05:48 +00:00
--deckColumnHeaderHeight: 40px;
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;
&.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-01-10 00:53:01 +00:00
> .header.indicated {
box-shadow: 4px 0px var(--accent) inset;
}
}
&.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);
}
}
&.paged {
2020-12-28 08:00:31 +00:00
background: var(--bg) !important;
}
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);
padding: 0 16px;
font-size: 0.9em;
color: var(--panelHeaderFg);
background: var(--panelHeaderBg);
box-shadow: 0 1px 0 0 var(--panelHeaderDivider);
cursor: pointer;
&, * {
user-select: none;
}
2023-01-10 00:53:01 +00:00
&.indicated {
box-shadow: 0 3px 0 0 var(--accent);
}
}
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);
color: var(--faceTextButton);
2023-01-10 00:53:01 +00:00
&:hover {
color: var(--faceTextButtonHover);
}
2023-01-10 00:53:01 +00:00
&:active {
color: var(--faceTextButtonActive);
}
}
2023-01-10 00:53:01 +00:00
.toggleActive {
margin-left: -16px;
}
2023-01-10 00:53:01 +00:00
.menu {
margin-left: auto;
margin-right: -16px;
}
2023-01-10 00:53:01 +00:00
.body {
height: calc(100% - var(--deckColumnHeaderHeight));
overflow-y: auto;
overflow-x: hidden; // Safari does not supports clip
overflow-x: clip;
-webkit-overflow-scrolling: touch;
box-sizing: border-box;
container-type: inline-size;
background-color: var(--bg);
}
</style>