This commit is contained in:
tamaina 2023-08-01 11:24:37 +00:00
parent d60aa72c63
commit 39d686ad11
2 changed files with 7 additions and 7 deletions

View File

@ -62,14 +62,14 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'; import { Ref, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { focusPrev, focusNext } from '@/scripts/focus'; import { focusPrev, focusNext } from '@/scripts/focus';
import MkSwitchButton from '@/components/MkSwitch.button.vue'; import MkSwitchButton from '@/components/MkSwitch.button.vue';
import { MenuItem, InnerMenuItem, OuterMenuItem, MenuPending, MenuAction, MenuSwitch, MenuParent } from '@/types/menu'; import { MenuItem, InnerMenuItem, MenuPending, MenuAction, MenuSwitch, MenuParent } from '@/types/menu';
import * as os from '@/os'; import * as os from '@/os';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
const childrenCache = new WeakMap<MenuParent, OuterMenuItem[]>(); const childrenCache = new WeakMap<MenuParent, MenuItem[]>();
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
@ -152,7 +152,7 @@ function onItemMouseLeave(item) {
} }
async function showChildren(item: MenuParent, ev: MouseEvent) { async function showChildren(item: MenuParent, ev: MouseEvent) {
const children = ref<OuterMenuItem[]>([]); const children: Ref<(MenuItem | MenuPending)[]> = ref([]);
if (!item.noCache && childrenCache.has(item)) { if (!item.noCache && childrenCache.has(item)) {
children.value = childrenCache.get(item)!; children.value = childrenCache.get(item)!;
} else { } else {
@ -170,7 +170,7 @@ async function showChildren(item: MenuParent, ev: MouseEvent) {
} }
if (props.asDrawer) { if (props.asDrawer) {
os.popupMenu(children, ev.currentTarget ?? ev.target, { os.popupMenu(children.value as MenuItem[], ev.currentTarget ?? ev.target, {
onClosing: () => { onClosing: () => {
close(); close();
} }

View File

@ -16,11 +16,11 @@ export type MenuA = { type: 'a', href: string, target?: string, download?: strin
export type MenuUser = { type: 'user', user: Misskey.entities.User, active?: boolean, indicate?: boolean, action: MenuAction }; export type MenuUser = { type: 'user', user: Misskey.entities.User, active?: boolean, indicate?: boolean, action: MenuAction };
export type MenuSwitch = { type: 'switch', ref: Ref<boolean>, text: string, disabled?: boolean }; export type MenuSwitch = { type: 'switch', ref: Ref<boolean>, text: string, disabled?: boolean };
export type MenuButton = { type?: 'button', text: string, icon?: string, indicate?: boolean, danger?: boolean, active?: boolean, avatar?: Misskey.entities.User; action: MenuAction }; export type MenuButton = { type?: 'button', text: string, icon?: string, indicate?: boolean, danger?: boolean, active?: boolean, avatar?: Misskey.entities.User; action: MenuAction };
export type MenuParent = { type: 'parent', text: string, icon?: string, noCache?: boolean, children: OuterMenuItem[] | (() => Promise<OuterMenuItem[]> | OuterMenuItem[]) }; export type MenuParent = { type: 'parent', text: string, icon?: string, noCache?: boolean, children: MenuItem[] | (() => Promise<MenuItem[]> | MenuItem[]) };
export type MenuPending = { type: 'pending' }; export type MenuPending = { type: 'pending' };
export type OuterMenuItem = MenuDivider | MenuNull | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent; type OuterMenuItem = MenuDivider | MenuNull | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent;
type OuterPromiseMenuItem = Promise<MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent>; type OuterPromiseMenuItem = Promise<MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent>;
export type MenuItem = OuterMenuItem | OuterPromiseMenuItem; export type MenuItem = OuterMenuItem | OuterPromiseMenuItem;
export type InnerMenuItem = MenuDivider | MenuPending | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent; export type InnerMenuItem = MenuDivider | MenuPending | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuParent;