UNPKG

svelte-event

Version:

svelte-event provides a set of wrapper functions for adding modifiers to event handlers and a versatile `event` action for comprehensive event listener management in Svelte.

17 lines (16 loc) 1.56 kB
import type { EventHandler, Modifiers } from '../types'; /** Calls `event.preventDefault()` before running the handler */ export declare function preventDefault<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; /** Calls `event.stopPropagation()`, preventing the event reaching the next element */ export declare function stopPropagation<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; /** Calls `event.stopImmediatePropagation()`, preventing other listeners of the same event from being fired. */ export declare function stopImmediatePropagation<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; /** Only triggers handler if the `event.target` is the element itself */ export declare function self<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; /** Only trigger handler if event.isTrusted is true. I.e. if the event is triggered by a user action. */ export declare function trusted<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; /** Remove the handler after the first time it runs */ export declare function once<T extends Event, U extends HTMLElement>(handler: EventHandler<T>): EventHandler<T>; export type WrappableModifiers = Omit<Modifiers, 'passive' | 'capture'>; /** Wraps the handler with the modifiers specified in the second argument */ export declare function withModifiers<T extends Event>(handler: EventHandler<T>, modifiers: WrappableModifiers): (event: T) => void;