From 06d28f9872b45d727e10431bda3e59a390502afc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 22 Sep 2024 19:57:14 -0400 Subject: [PATCH] re-export event modifier substitutes --- .../client/dom/legacy/event-modifiers.js | 12 +++ packages/svelte/src/legacy/legacy-client.js | 78 ++----------------- packages/svelte/types/index.d.ts | 30 ++++--- 3 files changed, 38 insertions(+), 82 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/legacy/event-modifiers.js b/packages/svelte/src/internal/client/dom/legacy/event-modifiers.js index f41a74090370..d6de1759f819 100644 --- a/packages/svelte/src/internal/client/dom/legacy/event-modifiers.js +++ b/packages/svelte/src/internal/client/dom/legacy/event-modifiers.js @@ -1,4 +1,6 @@ /** + * Substitute for the `trusted` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ @@ -13,6 +15,8 @@ export function trusted(fn) { } /** + * Substitute for the `self` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ @@ -28,6 +32,8 @@ export function self(fn) { } /** + * Substitute for the `stopPropagation` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ @@ -41,6 +47,8 @@ export function stopPropagation(fn) { } /** + * Substitute for the `once` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ @@ -57,6 +65,8 @@ export function once(fn) { } /** + * Substitute for the `stopImmediatePropagation` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ @@ -70,6 +80,8 @@ export function stopImmediatePropagation(fn) { } /** + * Substitute for the `preventDefault` event modifier + * @deprecated * @param {(event: Event, ...args: Array) => void} fn * @returns {(event: Event, ...args: unknown[]) => void} */ diff --git a/packages/svelte/src/legacy/legacy-client.js b/packages/svelte/src/legacy/legacy-client.js index d3d59ad1ed34..aa62b0f8adab 100644 --- a/packages/svelte/src/legacy/legacy-client.js +++ b/packages/svelte/src/legacy/legacy-client.js @@ -209,73 +209,11 @@ export function handlers(...handlers) { }; } -/** - * Migration helper to substitute the `stopImmediatePropagation` event modifier - * @param {EventListener} fn - */ -export function stopImmediatePropagation(fn) { - return (/**@type {Event}*/ e) => { - e.stopImmediatePropagation(); - fn(e); - }; -} - -/** - * Migration helper to substitute the `preventDefault` event modifier - * @param {EventListener} fn - */ -export function preventDefault(fn) { - return (/**@type {Event}*/ e) => { - e.preventDefault(); - fn(e); - }; -} - -/** - * Migration helper to substitute the `stopPropagation` event modifier - * @param {EventListener} fn - */ -export function stopPropagation(fn) { - return (/**@type {Event}*/ e) => { - e.stopPropagation(); - fn(e); - }; -} - -/** - * Migration helper to substitute the `trusted` event modifier - * @param {EventListener} fn - */ -export function trusted(fn) { - return (/**@type {Event}*/ e) => { - if (e.isTrusted) { - fn(e); - } - }; -} - -/** - * Migration helper to substitute the `self` event modifier - * @param {EventListener} fn - */ -export function self(fn) { - return (/**@type {Event}*/ e) => { - if (e.target === e.currentTarget) { - fn(e); - } - }; -} - -/** - * Migration helper to substitute the `once` event modifier - * @param {EventListener} fn - */ -export function once(fn) { - let executed = false; - return (/**@type {Event}*/ e) => { - if (!executed) { - executed = true; - fn(e); - } - }; -} +export { + once, + preventDefault, + self, + stopImmediatePropagation, + stopPropagation, + trusted +} from '../internal/client/dom/legacy/event-modifiers.js'; diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index dd32c1172271..66633a909926 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -1637,29 +1637,35 @@ declare module 'svelte/legacy' { * */ export function handlers(...handlers: EventListener[]): EventListener; /** - * Migration helper to substitute the `stopImmediatePropagation` event modifier + * Substitute for the `trusted` event modifier + * @deprecated * */ - export function stopImmediatePropagation(fn: EventListener): (e: Event) => void; + export function trusted(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; /** - * Migration helper to substitute the `preventDefault` event modifier + * Substitute for the `self` event modifier + * @deprecated * */ - export function preventDefault(fn: EventListener): (e: Event) => void; + export function self(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; /** - * Migration helper to substitute the `stopPropagation` event modifier + * Substitute for the `stopPropagation` event modifier + * @deprecated * */ - export function stopPropagation(fn: EventListener): (e: Event) => void; + export function stopPropagation(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; /** - * Migration helper to substitute the `trusted` event modifier + * Substitute for the `once` event modifier + * @deprecated * */ - export function trusted(fn: EventListener): (e: Event) => void; + export function once(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; /** - * Migration helper to substitute the `self` event modifier + * Substitute for the `stopImmediatePropagation` event modifier + * @deprecated * */ - export function self(fn: EventListener): (e: Event) => void; + export function stopImmediatePropagation(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; /** - * Migration helper to substitute the `once` event modifier + * Substitute for the `preventDefault` event modifier + * @deprecated * */ - export function once(fn: EventListener): (e: Event) => void; + export function preventDefault(fn: (event: Event, ...args: Array) => void): (event: Event, ...args: unknown[]) => void; export {}; }