types(runtime-dom): cast to the correct eventType instead of any (#292)
This commit is contained in:
parent
a3032b9b39
commit
0b2573f3d1
@ -1,5 +1,7 @@
|
|||||||
const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
|
const systemModifiers = new Set(['ctrl', 'shift', 'alt', 'meta'])
|
||||||
|
|
||||||
|
type KeyedEvent = KeyboardEvent | MouseEvent | TouchEvent;
|
||||||
|
|
||||||
const modifierGuards: Record<
|
const modifierGuards: Record<
|
||||||
string,
|
string,
|
||||||
(e: Event, modifiers?: string[]) => void | boolean
|
(e: Event, modifiers?: string[]) => void | boolean
|
||||||
@ -7,13 +9,13 @@ const modifierGuards: Record<
|
|||||||
stop: e => e.stopPropagation(),
|
stop: e => e.stopPropagation(),
|
||||||
prevent: e => e.preventDefault(),
|
prevent: e => e.preventDefault(),
|
||||||
self: e => e.target !== e.currentTarget,
|
self: e => e.target !== e.currentTarget,
|
||||||
ctrl: e => !(e as any).ctrlKey,
|
ctrl: e => !(e as KeyedEvent).ctrlKey,
|
||||||
shift: e => !(e as any).shiftKey,
|
shift: e => !(e as KeyedEvent).shiftKey,
|
||||||
alt: e => !(e as any).altKey,
|
alt: e => !(e as KeyedEvent).altKey,
|
||||||
meta: e => !(e as any).metaKey,
|
meta: e => !(e as KeyedEvent).metaKey,
|
||||||
left: e => 'button' in e && (e as any).button !== 0,
|
left: e => 'button' in e && (e as MouseEvent).button !== 0,
|
||||||
middle: e => 'button' in e && (e as any).button !== 1,
|
middle: e => 'button' in e && (e as MouseEvent).button !== 1,
|
||||||
right: e => 'button' in e && (e as any).button !== 2,
|
right: e => 'button' in e && (e as MouseEvent).button !== 2,
|
||||||
exact: (e, modifiers) =>
|
exact: (e, modifiers) =>
|
||||||
modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
|
modifiers!.some(m => systemModifiers.has(m) && (e as any)[`${m}Key`])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user