2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2023-01-06 05:40:17 +01:00
|
|
|
<div class="_gaps_m">
|
2023-03-20 12:21:54 +01:00
|
|
|
<FormSlot>
|
2022-07-14 10:42:12 +02:00
|
|
|
<template #label>{{ i18n.ts.navbar }}</template>
|
2023-05-19 13:52:15 +02:00
|
|
|
<MkContainer :showHeader="false">
|
2023-07-08 00:08:16 +02:00
|
|
|
<Sortable
|
2023-03-20 12:21:54 +01:00
|
|
|
v-model="items"
|
2023-05-19 13:52:15 +02:00
|
|
|
itemKey="id"
|
2023-03-20 12:21:54 +01:00
|
|
|
:animation="150"
|
2023-03-20 12:35:49 +01:00
|
|
|
:handle="'.' + $style.itemHandle"
|
|
|
|
@start="e => e.item.classList.add('active')"
|
|
|
|
@end="e => e.item.classList.remove('active')"
|
2023-03-20 12:21:54 +01:00
|
|
|
>
|
|
|
|
<template #item="{element,index}">
|
|
|
|
<div
|
2023-03-20 12:35:49 +01:00
|
|
|
v-if="element.type === '-' || navbarItemDef[element.type]"
|
|
|
|
:class="$style.item"
|
2023-03-20 12:21:54 +01:00
|
|
|
>
|
2023-03-20 12:35:49 +01:00
|
|
|
<button class="_button" :class="$style.itemHandle"><i class="ti ti-menu"></i></button>
|
|
|
|
<i class="ti-fw" :class="[$style.itemIcon, navbarItemDef[element.type]?.icon]"></i><span :class="$style.itemText">{{ navbarItemDef[element.type]?.title ?? i18n.ts.divider }}</span>
|
|
|
|
<button class="_button" :class="$style.itemRemove" @click="removeItem(index)"><i class="ti ti-x"></i></button>
|
2023-03-20 12:21:54 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Sortable>
|
|
|
|
</MkContainer>
|
|
|
|
</FormSlot>
|
|
|
|
<div class="_buttons">
|
2023-03-20 12:35:49 +01:00
|
|
|
<MkButton @click="addItem"><i class="ti ti-plus"></i> {{ i18n.ts.addItem }}</MkButton>
|
2023-03-20 12:21:54 +01:00
|
|
|
<MkButton danger @click="reset"><i class="ti ti-reload"></i> {{ i18n.ts.default }}</MkButton>
|
|
|
|
<MkButton primary class="save" @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
</div>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-01-07 07:09:46 +01:00
|
|
|
<MkRadios v-model="menuDisplay">
|
2022-05-04 03:12:40 +02:00
|
|
|
<template #label>{{ i18n.ts.display }}</template>
|
|
|
|
<option value="sideFull">{{ i18n.ts._menuDisplay.sideFull }}</option>
|
|
|
|
<option value="sideIcon">{{ i18n.ts._menuDisplay.sideIcon }}</option>
|
|
|
|
<option value="top">{{ i18n.ts._menuDisplay.top }}</option>
|
|
|
|
<!-- <MkRadio v-model="menuDisplay" value="hide" disabled>{{ i18n.ts._menuDisplay.hide }}</MkRadio>--> <!-- TODO: サイドバーを完全に隠せるようにすると、別途ハンバーガーボタンのようなものをUIに表示する必要があり面倒 -->
|
2023-01-07 07:09:46 +01:00
|
|
|
</MkRadios>
|
2021-11-28 12:07:37 +01:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
<script lang="ts" setup>
|
2023-03-20 12:21:54 +01:00
|
|
|
import { computed, defineAsyncComponent, ref, watch } from 'vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
2023-01-06 01:41:14 +01:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-03-20 12:21:54 +01:00
|
|
|
import FormSlot from '@/components/form/slot.vue';
|
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
2023-12-24 08:16:58 +01:00
|
|
|
import { navbarItemDef } from '@/navbar.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { unisonReload } from '@/scripts/unison-reload.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
2023-03-20 12:21:54 +01:00
|
|
|
|
|
|
|
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-03-20 12:35:49 +01:00
|
|
|
const items = ref(defaultStore.state.menu.map(x => ({
|
|
|
|
id: Math.random().toString(),
|
|
|
|
type: x,
|
|
|
|
})));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
const menuDisplay = computed(defaultStore.makeGetterSetter('menuDisplay'));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function reloadAsk() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'info',
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.reloadToApplySetting,
|
2022-05-04 03:12:40 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
unisonReload();
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function addItem() {
|
2022-07-14 10:42:12 +02:00
|
|
|
const menu = Object.keys(navbarItemDef).filter(k => !defaultStore.state.menu.includes(k));
|
2022-05-04 03:12:40 +02:00
|
|
|
const { canceled, result: item } = await os.select({
|
|
|
|
title: i18n.ts.addItem,
|
|
|
|
items: [...menu.map(k => ({
|
2023-01-05 05:59:48 +01:00
|
|
|
value: k, text: navbarItemDef[k].title,
|
2022-05-04 03:12:40 +02:00
|
|
|
})), {
|
2022-06-20 10:38:49 +02:00
|
|
|
value: '-', text: i18n.ts.divider,
|
|
|
|
}],
|
2022-05-04 03:12:40 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2023-03-20 12:35:49 +01:00
|
|
|
items.value = [...items.value, {
|
|
|
|
id: Math.random().toString(),
|
|
|
|
type: item,
|
|
|
|
}];
|
2023-03-20 12:21:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeItem(index: number) {
|
|
|
|
items.value.splice(index, 1);
|
2022-05-04 03:12:40 +02:00
|
|
|
}
|
2021-07-19 04:36:35 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function save() {
|
2023-03-20 12:35:49 +01:00
|
|
|
defaultStore.set('menu', items.value.map(x => x.type));
|
2022-05-04 03:12:40 +02:00
|
|
|
await reloadAsk();
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
function reset() {
|
2023-03-20 12:35:49 +01:00
|
|
|
items.value = defaultStore.def.menu.default.map(x => ({
|
|
|
|
id: Math.random().toString(),
|
|
|
|
type: x,
|
|
|
|
}));
|
2022-05-04 03:12:40 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
watch(menuDisplay, async () => {
|
|
|
|
await reloadAsk();
|
|
|
|
});
|
2020-12-29 13:08:16 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerActions = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const headerTabs = computed(() => []);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
2024-02-16 08:17:09 +01:00
|
|
|
definePageMetadata(() => ({
|
2022-07-14 10:42:12 +02:00
|
|
|
title: i18n.ts.navbar,
|
2022-12-19 11:01:30 +01:00
|
|
|
icon: 'ti ti-list',
|
2024-02-16 08:17:09 +01:00
|
|
|
}));
|
2020-10-17 13:12:00 +02:00
|
|
|
</script>
|
2023-03-20 12:35:49 +01:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.item {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
line-height: 2.85rem;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
color: var(--navFg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.itemIcon {
|
|
|
|
position: relative;
|
|
|
|
width: 32px;
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.itemText {
|
|
|
|
position: relative;
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.itemRemove {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10000;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
color: #ff2a2a;
|
|
|
|
right: 8px;
|
|
|
|
opacity: 0.8;
|
|
|
|
}
|
|
|
|
|
|
|
|
.itemHandle {
|
|
|
|
cursor: move;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
margin: 0 8px;
|
|
|
|
opacity: 0.5;
|
2023-03-20 12:21:54 +01:00
|
|
|
}
|
|
|
|
</style>
|