diff --git a/packages/frontend/src/types/menu.ts b/packages/frontend/src/types/menu.ts index fae7370341..6f2f08cb6d 100644 --- a/packages/frontend/src/types/menu.ts +++ b/packages/frontend/src/types/menu.ts @@ -4,10 +4,10 @@ */ import * as Misskey from 'misskey-js'; -import type { Component, ComputedRef, Ref } from 'vue'; +import type { Component, ComputedRef, Ref, MaybeRef } from 'vue'; import type { ComponentProps as CP } from 'vue-component-type-helpers'; -type ComponentProps = { [K in keyof CP]: CP[K] | Ref[K]> }; +type ComponentProps = { [K in keyof CP]: MaybeRef[K]> }; type MenuRadioOptionsDef = Record; @@ -15,22 +15,107 @@ type Text = string | ComputedRef; export type MenuAction = (ev: MouseEvent) => void; -export type MenuDivider = { type: 'divider' }; -export type MenuNull = undefined; -export type MenuLabel = { type: 'label', text: Text, caption?: Text }; -export type MenuLink = { type: 'link', to: string, text: Text, caption?: Text, icon?: string, indicate?: boolean, avatar?: Misskey.entities.User }; -export type MenuA = { type: 'a', href: string, target?: string, download?: string, text: Text, caption?: Text, icon?: string, indicate?: boolean }; -export type MenuUser = { type: 'user', user: Misskey.entities.User, active?: boolean, indicate?: boolean, action: MenuAction }; -export type MenuSwitch = { type: 'switch', ref: Ref, text: Text, caption?: Text, icon?: string, disabled?: boolean | Ref }; -export type MenuButton = { type?: 'button', text: Text, caption?: Text, icon?: string, indicate?: boolean, danger?: boolean, active?: boolean | ComputedRef, avatar?: Misskey.entities.User; action: MenuAction }; -export type MenuRadio = { type: 'radio', text: Text, caption?: Text, icon?: string, ref: Ref, options: MenuRadioOptionsDef, disabled?: boolean | Ref }; -export type MenuRadioOption = { type: 'radioOption', text: Text, caption?: Text, action: MenuAction; active?: boolean | ComputedRef }; -export type MenuComponent = { type: 'component', component: T, props?: ComponentProps }; -export type MenuParent = { type: 'parent', text: Text, caption?: Text, icon?: string, children: MenuItem[] | (() => Promise | MenuItem[]) }; +export interface MenuButton { + type?: 'button'; + text: Text; + caption?: Text; + icon?: string; + indicate?: boolean; + danger?: boolean; + active?: boolean | ComputedRef; + avatar?: Misskey.entities.User; + action: MenuAction; +} -export type MenuPending = { type: 'pending' }; +interface MenuBase { + type: string; +} -type OuterMenuItem = MenuDivider | MenuNull | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuRadio | MenuRadioOption | MenuComponent | MenuParent; +export interface MenuDivider extends MenuBase { + type: 'divider'; +} + +export interface MenuLabel extends MenuBase { + type: 'label'; + text: Text; + caption?: Text; +} + +export interface MenuLink extends MenuBase { + type: 'link'; + to: string; + text: Text; + caption?: Text; + icon?: string; + indicate?: boolean; + avatar?: Misskey.entities.User; +} + +export interface MenuA extends MenuBase { + type: 'a'; + href: string; + target?: string; + download?: string; + text: Text; + caption?: Text; + icon?: string; + indicate?: boolean; +} + +export interface MenuUser extends MenuBase { + type: 'user'; + user: Misskey.entities.User; + active?: boolean; + indicate?: boolean; + action: MenuAction; +} + +export interface MenuSwitch extends MenuBase { + type: 'switch'; + ref: Ref; + text: Text; + caption?: Text; + icon?: string; + disabled?: boolean | Ref; +} + +export interface MenuRadio extends MenuBase { + type: 'radio'; + text: Text; + caption?: Text; + icon?: string; + ref: Ref; + options: MenuRadioOptionsDef; + disabled?: boolean | Ref; +} + +export interface MenuRadioOption extends MenuBase { + type: 'radioOption'; + text: Text; + caption?: Text; + action: MenuAction; + active?: boolean | ComputedRef; +} + +export interface MenuComponent extends MenuBase { + type: 'component'; + component: T; + props?: ComponentProps; +} + +export interface MenuParent extends MenuBase { + type: 'parent'; + text: Text; + caption?: Text; + icon?: string; + children: MenuItem[] | (() => Promise | MenuItem[]); +} + +export interface MenuPending extends MenuBase { + type: 'pending'; +} + +type OuterMenuItem = MenuDivider | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuRadio | MenuRadioOption | MenuComponent | MenuParent; type OuterPromiseMenuItem = Promise; export type MenuItem = OuterMenuItem | OuterPromiseMenuItem; export type InnerMenuItem = MenuDivider | MenuPending | MenuLabel | MenuLink | MenuA | MenuUser | MenuSwitch | MenuButton | MenuRadio | MenuRadioOption | MenuComponent | MenuParent;