|
1 | 1 | const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
|
2 | 2 |
|
| 3 | +type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent; |
| 4 | + |
3 | 5 | const modifierGuards: Record<
|
4 | 6 | string,
|
5 | 7 | (e: Event, modifiers?: string[]) => void | boolean
|
6 | 8 | > = {
|
7 | 9 | stop: e => e.stopPropagation(),
|
8 | 10 | prevent: e => e.preventDefault(),
|
9 | 11 | self: e => e.target !== e.currentTarget,
|
10 |
| - ctrl: e => !(e as any).ctrlKey, |
11 |
| - shift: e => !(e as any).shiftKey, |
12 |
| - alt: e => !(e as any).altKey, |
13 |
| - meta: e => !(e as any).metaKey, |
14 |
| - left: e => 'button' in e && (e as any).button !== 0, |
15 |
| - middle: e => 'button' in e && (e as any).button !== 1, |
16 |
| - right: e => 'button' in e && (e as any).button !== 2, |
| 12 | + ctrl: e => !(e as KeyedEvent).ctrlKey, |
| 13 | + shift: e => !(e as KeyedEvent).shiftKey, |
| 14 | + alt: e => !(e as KeyedEvent).altKey, |
| 15 | + meta: e => !(e as KeyedEvent).metaKey, |
| 16 | + left: e => 'button' in e && (e as MouseEvent).button !== 0, |
| 17 | + middle: e => 'button' in e && (e as MouseEvent).button !== 1, |
| 18 | + right: e => 'button' in e && (e as MouseEvent).button !== 2, |
17 | 19 | exact: (e, modifiers) =>
|
18 | 20 | modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
|
19 | 21 | }
|
|
0 commit comments