2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
2024-02-13 15:59:27 +00:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
<template>
|
2024-09-25 03:31:04 +00:00
|
|
|
<div
|
|
|
|
role="menu"
|
|
|
|
:class="{
|
|
|
|
[$style.root]: true,
|
|
|
|
[$style.center]: align === 'center',
|
|
|
|
[$style.big]: big,
|
|
|
|
[$style.asDrawer]: asDrawer,
|
|
|
|
}"
|
|
|
|
@focusin.passive.stop="() => {}"
|
|
|
|
>
|
2022-07-17 12:06:33 +00:00
|
|
|
<div
|
2024-07-12 07:25:44 +00:00
|
|
|
ref="itemsEl"
|
|
|
|
v-hotkey="keymap"
|
|
|
|
tabindex="0"
|
2023-01-09 21:02:46 +00:00
|
|
|
class="_popup _shadow"
|
2024-09-25 03:31:04 +00:00
|
|
|
:class="$style.menu"
|
2024-07-12 07:25:44 +00:00
|
|
|
:style="{
|
|
|
|
width: (width && !asDrawer) ? `${width}px` : '',
|
2024-07-18 06:44:18 +00:00
|
|
|
maxHeight: maxHeight ? `min(${maxHeight}px, calc(100dvh - 32px))` : 'calc(100dvh - 32px)',
|
2024-07-12 07:25:44 +00:00
|
|
|
}"
|
|
|
|
@keydown.stop="() => {}"
|
|
|
|
@contextmenu.self.prevent="() => {}"
|
2022-07-17 12:06:33 +00:00
|
|
|
>
|
2024-07-12 07:25:44 +00:00
|
|
|
<template v-for="item in (items2 ?? [])">
|
|
|
|
<div v-if="item.type === 'divider'" role="separator" tabindex="-1" :class="$style.divider"></div>
|
|
|
|
<span v-else-if="item.type === 'label'" role="menuitem" tabindex="-1" :class="[$style.label, $style.item]">
|
2023-12-22 11:41:42 +00:00
|
|
|
<span style="opacity: 0.7;">{{ item.text }}</span>
|
2022-07-17 12:06:33 +00:00
|
|
|
</span>
|
2024-07-12 07:25:44 +00:00
|
|
|
<span v-else-if="item.type === 'pending'" role="menuitem" tabindex="0" :class="[$style.pending, $style.item]">
|
2022-07-17 12:06:33 +00:00
|
|
|
<span><MkEllipsis/></span>
|
|
|
|
</span>
|
2024-07-12 07:25:44 +00:00
|
|
|
<MkA
|
|
|
|
v-else-if="item.type === 'link'"
|
|
|
|
role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item]"
|
|
|
|
:to="item.to"
|
|
|
|
@click.passive="close(true)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2023-01-09 21:02:46 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
|
2023-01-16 05:18:11 +00:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" :class="$style.avatar"/>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="$style.item_content_text">{{ item.text }}</span>
|
2024-10-15 04:01:06 +00:00
|
|
|
<span v-if="item.indicate" :class="$style.indicator" class="_blink"><i class="_indicatorCircle"></i></span>
|
2023-12-22 11:41:42 +00:00
|
|
|
</div>
|
2022-07-17 12:06:33 +00:00
|
|
|
</MkA>
|
2024-07-12 07:25:44 +00:00
|
|
|
<a
|
|
|
|
v-else-if="item.type === 'a'"
|
|
|
|
role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item]"
|
|
|
|
:href="item.href"
|
|
|
|
:target="item.target"
|
2024-07-14 05:49:50 +00:00
|
|
|
:rel="item.target === '_blank' ? 'noopener noreferrer' : undefined"
|
2024-07-12 07:25:44 +00:00
|
|
|
:download="item.download"
|
|
|
|
@click.passive="close(true)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2023-01-09 21:02:46 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="$style.item_content_text">{{ item.text }}</span>
|
2024-10-15 04:01:06 +00:00
|
|
|
<span v-if="item.indicate" :class="$style.indicator" class="_blink"><i class="_indicatorCircle"></i></span>
|
2023-12-22 11:41:42 +00:00
|
|
|
</div>
|
2022-07-17 12:06:33 +00:00
|
|
|
</a>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else-if="item.type === 'user'"
|
|
|
|
role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item, { [$style.active]: item.active }]"
|
|
|
|
@click.prevent="item.active ? close(false) : clicked(item.action, $event)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2023-02-08 11:07:19 +00:00
|
|
|
<MkAvatar :user="item.user" :class="$style.avatar"/><MkUserName :user="item.user"/>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div v-if="item.indicate" :class="$style.item_content">
|
2024-10-15 04:01:06 +00:00
|
|
|
<span :class="$style.indicator" class="_blink"><i class="_indicatorCircle"></i></span>
|
2023-12-22 11:41:42 +00:00
|
|
|
</div>
|
2022-07-17 12:06:33 +00:00
|
|
|
</button>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else-if="item.type === 'switch'"
|
|
|
|
role="menuitemcheckbox"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item]"
|
|
|
|
:disabled="unref(item.disabled)"
|
|
|
|
@click.prevent="switchItem(item)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2024-03-30 07:02:03 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
|
|
|
|
<MkSwitchButton v-else :class="$style.switchButton" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)"/>
|
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="[$style.item_content_text, { [$style.switchText]: !item.icon }]">{{ item.text }}</span>
|
|
|
|
<MkSwitchButton v-if="item.icon" :class="[$style.switchButton, $style.caret]" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)"/>
|
|
|
|
</div>
|
|
|
|
</button>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else-if="item.type === 'radio'"
|
|
|
|
role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item, $style.parent, { [$style.active]: childShowingItem === item }]"
|
|
|
|
:disabled="unref(item.disabled)"
|
|
|
|
@mouseenter.prevent="preferClick ? null : showRadioOptions(item, $event)"
|
|
|
|
@keydown.enter.prevent="preferClick ? null : showRadioOptions(item, $event)"
|
|
|
|
@click.prevent="!preferClick ? null : showRadioOptions(item, $event)"
|
|
|
|
>
|
2024-03-30 07:02:03 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]" style="pointer-events: none;"></i>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div :class="$style.item_content">
|
2024-03-30 07:02:03 +00:00
|
|
|
<span :class="$style.item_content_text" style="pointer-events: none;">{{ item.text }}</span>
|
|
|
|
<span :class="$style.caret" style="pointer-events: none;"><i class="ti ti-chevron-right ti-fw"></i></span>
|
|
|
|
</div>
|
|
|
|
</button>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else-if="item.type === 'radioOption'"
|
|
|
|
role="menuitemradio"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item, $style.radio, { [$style.active]: unref(item.active) }]"
|
|
|
|
@click.prevent="unref(item.active) ? null : clicked(item.action, $event, false)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2024-03-30 07:02:03 +00:00
|
|
|
<div :class="$style.icon">
|
2024-07-12 07:25:44 +00:00
|
|
|
<span :class="[$style.radioIcon, { [$style.radioChecked]: unref(item.active) }]"></span>
|
2024-03-30 07:02:03 +00:00
|
|
|
</div>
|
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="$style.item_content_text">{{ item.text }}</span>
|
2023-12-22 11:41:42 +00:00
|
|
|
</div>
|
2023-08-01 06:32:03 +00:00
|
|
|
</button>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else-if="item.type === 'parent'"
|
|
|
|
role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item, $style.parent, { [$style.active]: childShowingItem === item }]"
|
|
|
|
@mouseenter.prevent="preferClick ? null : showChildren(item, $event)"
|
|
|
|
@keydown.enter.prevent="preferClick ? null : showChildren(item, $event)"
|
|
|
|
@click.prevent="!preferClick ? null : showChildren(item, $event)"
|
|
|
|
>
|
2023-09-23 11:35:05 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]" style="pointer-events: none;"></i>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="$style.item_content_text" style="pointer-events: none;">{{ item.text }}</span>
|
|
|
|
<span :class="$style.caret" style="pointer-events: none;"><i class="ti ti-chevron-right ti-fw"></i></span>
|
|
|
|
</div>
|
2023-09-23 03:43:32 +00:00
|
|
|
</button>
|
2024-07-12 07:25:44 +00:00
|
|
|
<button
|
|
|
|
v-else role="menuitem"
|
|
|
|
tabindex="0"
|
|
|
|
:class="['_button', $style.item, { [$style.danger]: item.danger, [$style.active]: unref(item.active) }]"
|
|
|
|
@click.prevent="unref(item.active) ? close(false) : clicked(item.action, $event)"
|
|
|
|
@mouseenter.passive="onItemMouseEnter"
|
|
|
|
@mouseleave.passive="onItemMouseLeave"
|
|
|
|
>
|
2023-01-09 21:02:46 +00:00
|
|
|
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
|
2023-01-16 05:18:11 +00:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" :class="$style.avatar"/>
|
2023-12-22 11:41:42 +00:00
|
|
|
<div :class="$style.item_content">
|
|
|
|
<span :class="$style.item_content_text">{{ item.text }}</span>
|
2024-10-15 04:01:06 +00:00
|
|
|
<span v-if="item.indicate" :class="$style.indicator" class="_blink"><i class="_indicatorCircle"></i></span>
|
2023-12-22 11:41:42 +00:00
|
|
|
</div>
|
2022-07-17 12:06:33 +00:00
|
|
|
</button>
|
|
|
|
</template>
|
2024-07-12 07:25:44 +00:00
|
|
|
<span v-if="items2 == null || items2.length === 0" tabindex="-1" :class="[$style.none, $style.item]">
|
2022-07-20 13:24:26 +00:00
|
|
|
<span>{{ i18n.ts.none }}</span>
|
2020-10-17 11:12:00 +00:00
|
|
|
</span>
|
2022-07-17 12:06:33 +00:00
|
|
|
</div>
|
2023-06-01 08:19:46 +00:00
|
|
|
<div v-if="childMenu">
|
2024-07-12 07:25:44 +00:00
|
|
|
<XChild ref="child" :items="childMenu" :targetElement="childTarget!" :rootElement="itemsEl!" @actioned="childActioned" @closed="closeChild"/>
|
2022-07-17 12:06:33 +00:00
|
|
|
</div>
|
2020-10-17 11:12:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-08-09 00:08:47 +00:00
|
|
|
<script lang="ts">
|
2024-07-12 07:25:44 +00:00
|
|
|
import { computed, defineAsyncComponent, inject, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, unref, watch } from 'vue';
|
2023-08-01 06:32:03 +00:00
|
|
|
import MkSwitchButton from '@/components/MkSwitch.button.vue';
|
2024-03-30 07:02:03 +00:00
|
|
|
import { MenuItem, InnerMenuItem, MenuPending, MenuAction, MenuSwitch, MenuRadio, MenuRadioOption, MenuParent } from '@/types/menu.js';
|
2023-09-19 07:37:43 +00:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { isTouchUsing } from '@/scripts/touch.js';
|
2024-07-09 08:59:15 +00:00
|
|
|
import { type Keymap } from '@/scripts/hotkey.js';
|
2024-07-12 07:25:44 +00:00
|
|
|
import { isFocusable } from '@/scripts/focus.js';
|
|
|
|
import { getNodeOrNull } from '@/scripts/get-dom-node-or-null.js';
|
2023-08-09 00:08:47 +00:00
|
|
|
|
|
|
|
const childrenCache = new WeakMap<MenuParent, MenuItem[]>();
|
|
|
|
</script>
|
2022-07-20 13:24:26 +00:00
|
|
|
|
2023-08-09 00:08:47 +00:00
|
|
|
<script lang="ts" setup>
|
2022-09-06 09:21:49 +00:00
|
|
|
const XChild = defineAsyncComponent(() => import('./MkMenu.child.vue'));
|
2022-01-30 05:11:52 +00:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
items: MenuItem[];
|
|
|
|
asDrawer?: boolean;
|
|
|
|
align?: 'center' | string;
|
|
|
|
width?: number;
|
|
|
|
maxHeight?: number;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2022-07-17 12:06:33 +00:00
|
|
|
(ev: 'close', actioned?: boolean): void;
|
2023-08-09 00:08:47 +00:00
|
|
|
(ev: 'hide'): void;
|
2022-01-30 05:11:52 +00:00
|
|
|
}>();
|
|
|
|
|
2024-09-24 22:55:24 +00:00
|
|
|
const big = isTouchUsing;
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
const isNestingMenu = inject<boolean>('isNestingMenu', false);
|
|
|
|
|
|
|
|
const itemsEl = shallowRef<HTMLElement>();
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2024-01-30 10:53:53 +00:00
|
|
|
const items2 = ref<InnerMenuItem[]>();
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const child = shallowRef<InstanceType<typeof XChild>>();
|
2022-07-17 12:06:33 +00:00
|
|
|
|
2024-07-09 08:59:15 +00:00
|
|
|
const keymap = {
|
|
|
|
'up|k|shift+tab': {
|
|
|
|
allowRepeat: true,
|
|
|
|
callback: () => focusUp(),
|
|
|
|
},
|
|
|
|
'down|j|tab': {
|
|
|
|
allowRepeat: true,
|
|
|
|
callback: () => focusDown(),
|
|
|
|
},
|
|
|
|
'esc': {
|
|
|
|
allowRepeat: true,
|
|
|
|
callback: () => close(false),
|
|
|
|
},
|
|
|
|
} as const satisfies Keymap;
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
const childShowingItem = ref<MenuItem | null>();
|
2022-07-17 12:06:33 +00:00
|
|
|
|
2023-08-09 00:08:47 +00:00
|
|
|
let preferClick = isTouchUsing || props.asDrawer;
|
|
|
|
|
2022-01-30 05:11:52 +00:00
|
|
|
watch(() => props.items, () => {
|
2024-01-30 10:53:53 +00:00
|
|
|
const items = [...props.items].filter(item => item !== undefined) as (NonNullable<MenuItem> | MenuPending)[];
|
2022-01-30 05:11:52 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
const item = items[i];
|
|
|
|
|
2024-01-30 10:53:53 +00:00
|
|
|
if ('then' in item) { // if item is Promise
|
2022-01-30 05:11:52 +00:00
|
|
|
items[i] = { type: 'pending' };
|
|
|
|
item.then(actualItem => {
|
2024-01-30 10:53:53 +00:00
|
|
|
if (items2.value?.[i]) items2.value[i] = actualItem;
|
2020-10-17 11:12:00 +00:00
|
|
|
});
|
|
|
|
}
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2023-12-07 05:42:09 +00:00
|
|
|
items2.value = items as InnerMenuItem[];
|
2022-01-30 05:11:52 +00:00
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2023-08-09 00:08:47 +00:00
|
|
|
const childMenu = ref<MenuItem[] | null>();
|
2023-12-07 05:42:09 +00:00
|
|
|
const childTarget = shallowRef<HTMLElement | null>();
|
2022-07-17 12:06:33 +00:00
|
|
|
|
|
|
|
function closeChild() {
|
2023-02-24 11:48:19 +00:00
|
|
|
childMenu.value = null;
|
2023-12-07 05:42:09 +00:00
|
|
|
childShowingItem.value = null;
|
2022-07-17 12:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function childActioned() {
|
|
|
|
closeChild();
|
|
|
|
close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
let childCloseTimer: null | number = null;
|
2023-10-29 07:09:20 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
function onItemMouseEnter() {
|
2022-07-17 12:06:33 +00:00
|
|
|
childCloseTimer = window.setTimeout(() => {
|
|
|
|
closeChild();
|
|
|
|
}, 300);
|
|
|
|
}
|
2023-10-29 07:09:20 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
function onItemMouseLeave() {
|
2022-07-17 12:06:33 +00:00
|
|
|
if (childCloseTimer) window.clearTimeout(childCloseTimer);
|
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
async function showRadioOptions(item: MenuRadio, ev: Event) {
|
2024-03-30 07:02:03 +00:00
|
|
|
const children: MenuItem[] = Object.keys(item.options).map<MenuRadioOption>(key => {
|
|
|
|
const value = item.options[key];
|
|
|
|
return {
|
|
|
|
type: 'radioOption',
|
|
|
|
text: key,
|
|
|
|
action: () => {
|
|
|
|
item.ref = value;
|
|
|
|
},
|
|
|
|
active: computed(() => item.ref === value),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
if (props.asDrawer) {
|
|
|
|
os.popupMenu(children, ev.currentTarget ?? ev.target).finally(() => {
|
2024-07-12 07:25:44 +00:00
|
|
|
close(false);
|
2024-03-30 07:02:03 +00:00
|
|
|
});
|
|
|
|
emit('hide');
|
|
|
|
} else {
|
|
|
|
childTarget.value = (ev.currentTarget ?? ev.target) as HTMLElement;
|
|
|
|
childMenu.value = children;
|
|
|
|
childShowingItem.value = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
async function showChildren(item: MenuParent, ev: Event) {
|
2024-09-25 03:31:04 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
|
2024-01-30 10:53:53 +00:00
|
|
|
const children: MenuItem[] = await (async () => {
|
2023-08-09 00:08:47 +00:00
|
|
|
if (childrenCache.has(item)) {
|
|
|
|
return childrenCache.get(item)!;
|
2023-02-24 11:48:19 +00:00
|
|
|
} else {
|
2023-08-09 00:08:47 +00:00
|
|
|
if (typeof item.children === 'function') {
|
|
|
|
return Promise.resolve(item.children());
|
|
|
|
} else {
|
|
|
|
return item.children;
|
|
|
|
}
|
2023-02-24 11:48:19 +00:00
|
|
|
}
|
2023-08-09 00:08:47 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
childrenCache.set(item, children);
|
2023-02-24 11:48:19 +00:00
|
|
|
|
2022-07-17 12:06:33 +00:00
|
|
|
if (props.asDrawer) {
|
2023-08-09 00:08:47 +00:00
|
|
|
os.popupMenu(children, ev.currentTarget ?? ev.target).finally(() => {
|
2024-07-12 07:25:44 +00:00
|
|
|
close(false);
|
2023-08-09 00:08:47 +00:00
|
|
|
});
|
|
|
|
emit('hide');
|
2022-07-17 12:06:33 +00:00
|
|
|
} else {
|
2024-01-30 10:53:53 +00:00
|
|
|
childTarget.value = (ev.currentTarget ?? ev.target) as HTMLElement;
|
2023-08-09 00:08:47 +00:00
|
|
|
// これでもリアクティビティは保たれる
|
|
|
|
childMenu.value = children;
|
2023-12-07 05:42:09 +00:00
|
|
|
childShowingItem.value = item;
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
2022-07-17 12:06:33 +00:00
|
|
|
}
|
2022-01-30 05:11:52 +00:00
|
|
|
|
2024-03-30 07:02:03 +00:00
|
|
|
function clicked(fn: MenuAction, ev: MouseEvent, doClose = true) {
|
2022-01-30 05:11:52 +00:00
|
|
|
fn(ev);
|
2024-03-30 07:02:03 +00:00
|
|
|
|
|
|
|
if (!doClose) return;
|
2022-07-17 12:06:33 +00:00
|
|
|
close(true);
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 12:06:33 +00:00
|
|
|
function close(actioned = false) {
|
2024-07-12 07:25:44 +00:00
|
|
|
disposeHandlers();
|
|
|
|
nextTick(() => {
|
|
|
|
closeChild();
|
|
|
|
emit('close', actioned);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchItem(item: MenuSwitch & { ref: any }) {
|
|
|
|
if (item.disabled !== undefined && (typeof item.disabled === 'boolean' ? item.disabled : item.disabled.value)) return;
|
|
|
|
item.ref = !item.ref;
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function focusUp() {
|
2024-07-12 07:25:44 +00:00
|
|
|
if (disposed) return;
|
|
|
|
if (!itemsEl.value?.contains(document.activeElement)) return;
|
|
|
|
|
|
|
|
const focusableElements = Array.from(itemsEl.value.children).filter(isFocusable);
|
|
|
|
const activeIndex = focusableElements.findIndex(el => el === document.activeElement);
|
|
|
|
const targetIndex = (activeIndex !== -1 && activeIndex !== 0) ? (activeIndex - 1) : (focusableElements.length - 1);
|
|
|
|
const targetElement = focusableElements.at(targetIndex) ?? itemsEl.value;
|
|
|
|
|
|
|
|
targetElement.focus();
|
2022-01-30 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function focusDown() {
|
2024-07-12 07:25:44 +00:00
|
|
|
if (disposed) return;
|
|
|
|
if (!itemsEl.value?.contains(document.activeElement)) return;
|
2022-07-17 12:06:33 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
const focusableElements = Array.from(itemsEl.value.children).filter(isFocusable);
|
|
|
|
const activeIndex = focusableElements.findIndex(el => el === document.activeElement);
|
|
|
|
const targetIndex = (activeIndex !== -1 && activeIndex !== (focusableElements.length - 1)) ? (activeIndex + 1) : 0;
|
|
|
|
const targetElement = focusableElements.at(targetIndex) ?? itemsEl.value;
|
2023-08-01 06:32:03 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
targetElement.focus();
|
2024-01-30 10:53:53 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
const onGlobalFocusin = (ev: FocusEvent) => {
|
|
|
|
if (disposed) return;
|
|
|
|
if (itemsEl.value?.parentElement?.contains(getNodeOrNull(ev.target))) return;
|
|
|
|
nextTick(() => {
|
|
|
|
if (itemsEl.value != null && isFocusable(itemsEl.value)) {
|
|
|
|
itemsEl.value.focus({ preventScroll: true });
|
|
|
|
nextTick(() => focusDown());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2022-07-17 12:06:33 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
const onGlobalMousedown = (ev: MouseEvent) => {
|
|
|
|
if (disposed) return;
|
|
|
|
if (childTarget.value?.contains(getNodeOrNull(ev.target))) return;
|
|
|
|
if (child.value?.checkHit(ev)) return;
|
|
|
|
closeChild();
|
|
|
|
};
|
2022-12-08 04:44:38 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
const setupHandlers = () => {
|
|
|
|
if (!isNestingMenu) {
|
|
|
|
document.addEventListener('focusin', onGlobalFocusin, { passive: true });
|
|
|
|
}
|
2022-07-17 12:06:33 +00:00
|
|
|
document.addEventListener('mousedown', onGlobalMousedown, { passive: true });
|
2024-07-12 07:25:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let disposed = false;
|
|
|
|
|
|
|
|
const disposeHandlers = () => {
|
|
|
|
disposed = true;
|
|
|
|
if (!isNestingMenu) {
|
|
|
|
document.removeEventListener('focusin', onGlobalFocusin);
|
|
|
|
}
|
|
|
|
document.removeEventListener('mousedown', onGlobalMousedown);
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
setupHandlers();
|
|
|
|
|
|
|
|
if (!isNestingMenu) {
|
|
|
|
nextTick(() => itemsEl.value?.focus({ preventScroll: true }));
|
|
|
|
}
|
2022-07-17 12:06:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2024-07-12 07:25:44 +00:00
|
|
|
disposeHandlers();
|
2022-07-17 12:06:33 +00:00
|
|
|
});
|
2020-10-17 11:12:00 +00:00
|
|
|
</script>
|
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2021-10-03 06:39:39 +00:00
|
|
|
&.center {
|
2024-09-25 03:31:04 +00:00
|
|
|
> .menu {
|
|
|
|
> .item {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-25 00:39:12 +00:00
|
|
|
&.big:not(.asDrawer) {
|
2024-09-25 03:31:04 +00:00
|
|
|
> .menu {
|
2024-10-05 06:19:07 +00:00
|
|
|
min-width: 230px;
|
|
|
|
|
2024-09-25 03:31:04 +00:00
|
|
|
> .item {
|
|
|
|
padding: 6px 20px;
|
2024-10-05 06:19:07 +00:00
|
|
|
font-size: 0.95em;
|
2024-09-25 03:31:04 +00:00
|
|
|
line-height: 24px;
|
|
|
|
}
|
2024-09-24 22:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
&.asDrawer {
|
2024-09-25 03:31:04 +00:00
|
|
|
max-width: 600px;
|
|
|
|
margin: auto;
|
2022-06-05 03:23:57 +00:00
|
|
|
|
2024-09-25 03:31:04 +00:00
|
|
|
> .menu {
|
|
|
|
padding: 12px 0 max(env(safe-area-inset-bottom, 0px), 12px) 0;
|
|
|
|
width: 100%;
|
|
|
|
border-radius: 24px;
|
|
|
|
border-bottom-right-radius: 0;
|
|
|
|
border-bottom-left-radius: 0;
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
font-size: 1em;
|
|
|
|
padding: 12px 24px;
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
width: calc(100% - 24px);
|
|
|
|
border-radius: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin-right: 14px;
|
|
|
|
width: 24px;
|
|
|
|
}
|
2022-06-05 03:23:57 +00:00
|
|
|
}
|
|
|
|
|
2024-09-25 03:31:04 +00:00
|
|
|
> .divider {
|
|
|
|
margin: 12px 0;
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
|
|
|
}
|
2024-09-25 03:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2024-09-25 03:31:04 +00:00
|
|
|
.menu {
|
|
|
|
padding: 8px 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
max-width: 100vw;
|
|
|
|
min-width: 200px;
|
|
|
|
overflow: auto;
|
|
|
|
overscroll-behavior: contain;
|
|
|
|
|
|
|
|
&:focus-visible {
|
|
|
|
outline: none;
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-03 06:39:39 +00:00
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
.item {
|
2023-12-22 11:41:42 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2023-01-09 21:02:46 +00:00
|
|
|
position: relative;
|
|
|
|
padding: 5px 16px;
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
white-space: nowrap;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 20px;
|
|
|
|
text-align: left;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2024-07-12 07:25:44 +00:00
|
|
|
text-decoration: none !important;
|
2024-10-09 09:08:14 +00:00
|
|
|
color: var(--menuFg, var(--MI_THEME-fg));
|
2023-01-09 21:02:46 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&::before {
|
2023-01-09 21:02:46 +00:00
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
z-index: -1;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: auto;
|
|
|
|
width: calc(100% - 16px);
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 6px;
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&:focus-visible {
|
|
|
|
outline: none;
|
2021-10-03 06:39:39 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&:not(:hover):not(:active)::before {
|
2024-10-09 09:08:14 +00:00
|
|
|
outline: var(--MI_THEME-focus) solid 2px;
|
2024-07-12 07:25:44 +00:00
|
|
|
outline-offset: -2px;
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&:not(:disabled) {
|
|
|
|
&:hover,
|
|
|
|
&:focus-visible:active,
|
|
|
|
&:focus-visible.active {
|
2024-10-09 09:08:14 +00:00
|
|
|
color: var(--menuHoverFg, var(--MI_THEME-accent));
|
2021-10-09 04:12:41 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&::before {
|
2024-10-09 09:08:14 +00:00
|
|
|
background-color: var(--menuHoverBg, var(--MI_THEME-accentedBg));
|
2021-10-09 04:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&:not(:focus-visible):active,
|
|
|
|
&:not(:focus-visible).active {
|
2024-10-09 09:08:14 +00:00
|
|
|
color: var(--menuActiveFg, var(--MI_THEME-fgOnAccent));
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&::before {
|
2024-10-09 09:08:14 +00:00
|
|
|
background-color: var(--menuActiveBg, var(--MI_THEME-accent));
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&:disabled {
|
|
|
|
cursor: not-allowed;
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&.danger {
|
|
|
|
--menuFg: #ff2a2a;
|
|
|
|
--menuHoverFg: #fff;
|
|
|
|
--menuHoverBg: #ff4242;
|
|
|
|
--menuActiveFg: #fff;
|
|
|
|
--menuActiveBg: #d42e2e;
|
|
|
|
}
|
2024-03-30 07:02:03 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&.radio {
|
2024-10-09 09:08:14 +00:00
|
|
|
--menuActiveFg: var(--MI_THEME-accent);
|
|
|
|
--menuActiveBg: var(--MI_THEME-accentedBg);
|
2024-03-30 07:02:03 +00:00
|
|
|
}
|
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
&.parent {
|
2024-10-09 09:08:14 +00:00
|
|
|
--menuActiveFg: var(--MI_THEME-accent);
|
|
|
|
--menuActiveBg: var(--MI_THEME-accentedBg);
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
2022-07-17 12:06:33 +00:00
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
&.label {
|
|
|
|
pointer-events: none;
|
|
|
|
font-size: 0.7em;
|
|
|
|
padding-bottom: 4px;
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
&.pending {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
&.none {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-09 21:02:46 +00:00
|
|
|
|
2023-12-22 11:41:42 +00:00
|
|
|
.item_content {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 100vw;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
gap: 8px;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
|
|
|
|
.item_content_text {
|
|
|
|
max-width: calc(100vw - 4rem);
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
2023-08-01 06:32:03 +00:00
|
|
|
.switchButton {
|
|
|
|
margin-left: -2px;
|
2024-03-30 07:02:03 +00:00
|
|
|
--height: 1.35em;
|
2023-08-01 06:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.switchText {
|
|
|
|
margin-left: 8px;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
|
2023-01-09 21:02:46 +00:00
|
|
|
.icon {
|
2023-01-25 10:49:17 +00:00
|
|
|
margin-right: 8px;
|
2023-12-22 11:41:42 +00:00
|
|
|
line-height: 1;
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.caret {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.avatar {
|
|
|
|
margin-right: 5px;
|
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.indicator {
|
2023-12-22 11:41:42 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2024-10-09 09:08:14 +00:00
|
|
|
color: var(--MI_THEME-indicator);
|
2023-01-09 21:02:46 +00:00
|
|
|
font-size: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.divider {
|
|
|
|
margin: 8px 0;
|
2024-10-09 09:08:14 +00:00
|
|
|
border-top: solid 0.5px var(--MI_THEME-divider);
|
2023-01-09 21:02:46 +00:00
|
|
|
}
|
2024-03-30 07:02:03 +00:00
|
|
|
|
2024-07-12 07:25:44 +00:00
|
|
|
.radioIcon {
|
2024-03-30 07:02:03 +00:00
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
width: 1em;
|
|
|
|
height: 1em;
|
2024-07-12 07:25:44 +00:00
|
|
|
vertical-align: -0.125em;
|
2024-03-30 07:02:03 +00:00
|
|
|
border-radius: 50%;
|
2024-10-09 09:08:14 +00:00
|
|
|
border: solid 2px var(--MI_THEME-divider);
|
|
|
|
background-color: var(--MI_THEME-panel);
|
2024-03-30 07:02:03 +00:00
|
|
|
|
|
|
|
&.radioChecked {
|
2024-10-09 09:08:14 +00:00
|
|
|
border-color: var(--MI_THEME-accent);
|
2024-03-30 07:02:03 +00:00
|
|
|
|
|
|
|
&::after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
width: 50%;
|
|
|
|
height: 50%;
|
|
|
|
border-radius: 50%;
|
2024-10-09 09:08:14 +00:00
|
|
|
background-color: var(--MI_THEME-accent);
|
2024-03-30 07:02:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
</style>
|