generated from mengxinssfd/lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
54 lines (51 loc) · 1.28 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* 需要注册的快捷键绑定参数对象
*/
export interface KeyOptions {
/**
* 单个组合快捷键或多个组合快捷键
* @example
* 'MetaOrControl+a'
* 'MetaOrCtrl+a'
* 'CmdOrCtrl+a'
* 'CommandOrCtrl+a'
* 'Ctrl+a'
* 'Meta+a'
*/
keys: string[] | string;
/**
* 快捷键触发时调用的函数
*/
handler: (this: HandledKeyOptions, e?: KeyboardEvent) => any;
/**
* 描述
*/
desc?: string;
}
/**
* 处理后的快捷键参数对象
*/
export type HandledKeyOptions = Omit<KeyOptions, 'keys'> & {
keys: string;
rawKeys: string[] | string;
keyList: string[];
};
/**
* 按键绑定策略类型
*
* recordAll 记忆全部按下的按键
*
* recordCompose 只记组合键,如果是复合普通键的话是无效的,可以使用recordAll
*
* 为什么要分两种策略,因为recordAll是通过keyup去移除已经按下的按键,在mac里面按下meta键后普通键keyup无效,所以分为了两种策略
*
* 默认使用recordCompose不会漏键,如果没有meta键的系统可以使用recordAll,组合更加随意
*/
export type StrategyType = 'recordAll' | 'recordCompose';
/**
* 策略声明类型
*/
export type Strategy = <T extends HTMLElement | Window>(
el: T,
maps: HandledKeyOptions[],
) => () => void;