mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
21 lines
607 B
TypeScript
21 lines
607 B
TypeScript
|
export const composeEventHandlers = <E>(
|
||
|
theirsHandler?: (event: E) => boolean | void,
|
||
|
oursHandler?: (event: E) => void,
|
||
|
{ checkForDefaultPrevented = true } = {}
|
||
|
) => {
|
||
|
const handleEvent = (event: E) => {
|
||
|
const shouldPrevent = theirsHandler?.(event)
|
||
|
|
||
|
if (checkForDefaultPrevented === false || !shouldPrevent) {
|
||
|
return oursHandler?.(event)
|
||
|
}
|
||
|
}
|
||
|
return handleEvent
|
||
|
}
|
||
|
|
||
|
type WhenMouseHandler = (e: PointerEvent) => any
|
||
|
export const whenMouse = (handler: WhenMouseHandler): WhenMouseHandler => {
|
||
|
return (e: PointerEvent) =>
|
||
|
e.pointerType === 'mouse' ? handler(e) : undefined
|
||
|
}
|