UNPKG

@dfinity/gix-components

Version:
29 lines (28 loc) 1.39 kB
/** * In Svelte 5, event modifiers are no longer part of the framework. * This module contains wrapper functions that replicate modifier behavior for Svelte 5. * * @see {@link https://svelte.dev/docs/svelte/v5-migration-guide#Event-changes-Event-modifiers} */ /** * A wrapper function to stop event propagation of a mouse event before executing a callback function. * * @param {OnEventCallback<T extends EventTarget>} fn - The function to be executed after stopping the event propagation. It can be a synchronous or asynchronous function. * * @returns {MouseEventHandler<T extends EventTarget>} - A function that takes an event and stop its propagation, before executing the provided function. */ export const stopPropagation = (fn) => async ($event) => { $event?.stopPropagation(); await fn($event); }; /** * A wrapper function to prevent the default action of a mouse event before executing a callback function. * * @param {OnEventCallback<T extends EventTarget>} fn - The function to be executed after preventing the default action. It can be a synchronous or asynchronous function. * * @returns {MouseEventHandler<T extends EventTarget>} - A function that takes an event and prevents its default action, before executing the provided function. */ export const preventDefault = (fn) => async ($event) => { $event?.preventDefault(); await fn($event); };