element-plus/packages/utils/dom/event.ts

21 lines
607 B
TypeScript
Raw Normal View History

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
}