|
| 1 | +export type HrType = { |
| 2 | + type: 'hr'; |
| 3 | +}; |
| 4 | + |
| 5 | +export type LiType = { |
| 6 | + type: 'li'; |
| 7 | + text: string; |
| 8 | + disabled?: boolean; |
| 9 | + // eslint-disable-next-line no-undef |
| 10 | + callback: EventListener; |
| 11 | + close?: boolean; |
| 12 | +}; |
| 13 | + |
| 14 | +export interface AttrsType { |
| 15 | + class?: string; |
| 16 | + style?: string | { [key: string]: string }; |
| 17 | +} |
| 18 | + |
| 19 | +// eslint-disable-next-line no-use-before-define |
| 20 | +export type ItemType = AttrsType & ElementType; |
| 21 | + |
| 22 | +export type UlType = { |
| 23 | + type: 'ul'; |
| 24 | + text: string; |
| 25 | + disabled?: boolean; |
| 26 | + children: ItemType[]; |
| 27 | +}; |
| 28 | +export type ElementType = HrType | LiType | UlType; |
| 29 | + |
| 30 | +type GetKeysType<T> = T extends ElementType ? keyof T : never; |
| 31 | + |
| 32 | +type ElementKeysType = GetKeysType<ElementType>; |
| 33 | + |
| 34 | +export type ConfigType = { |
| 35 | + el: string | HTMLElement; |
| 36 | + mode?: 'context-menu' | 'nav-menu' | 'click'; // 模式, 默认为context-menu |
| 37 | + theme?: string; // 主题样式, 默认为auto |
| 38 | + minWidth?: string | number; // 最小宽度 |
| 39 | + maxWidth?: string | number; // 最大宽度 |
| 40 | + include?: string[] | RegExp; // 包含的元素 |
| 41 | + exclude?: string[] | RegExp; // 排除的元素 |
| 42 | + defaultProps?: { |
| 43 | + // 默认参数配置项 |
| 44 | + [key in ElementKeysType]?: string; |
| 45 | + }; |
| 46 | + beforeInit?: Function; // 初始化前 |
| 47 | + afterInit?: Function; // 初始化后 |
| 48 | + beforeShow?: Function; // 显示菜单前 |
| 49 | + afterShow?: Function; // 显示菜单后 |
| 50 | + beforeHide?: Function; // 隐藏菜单前 |
| 51 | + afterHide?: Function; // 隐藏菜单后 |
| 52 | +}; |
| 53 | + |
| 54 | +export type OptionsType = |
| 55 | + | ItemType[] |
| 56 | + | ((e: Event, config: ConfigType) => ItemType[] | Promise<ItemType[]>); |
| 57 | + |
| 58 | +export interface MenuElement extends HTMLElement { |
| 59 | + direction?: LayoutMenuDirection; |
| 60 | +} |
| 61 | + |
| 62 | +// type RequireKeys = 'el' |
| 63 | +export const ConnectOffset = 5; |
| 64 | + |
| 65 | +export const ATTR_LIST = ['class', 'style']; |
| 66 | + |
| 67 | +export const SPLIT_SYMBOL = { |
| 68 | + class: ' ', |
| 69 | + style: ';', |
| 70 | +}; |
| 71 | + |
| 72 | +export const enum LayoutMenuDirection { |
| 73 | + Left = -1, |
| 74 | + Right = 1, |
| 75 | +} |
0 commit comments