From cfe753fbf1ecca59ac85df166d84d881042d92c5 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Fri, 25 Oct 2024 11:55:10 -0700 Subject: [PATCH] fix(writer): use `WindowEventMap` for cut/copy/paste events (#143) Fixes #139 --- src/writer/writer-ts-definitions.ts | 9 +++------ tests/__snapshots__/fixtures.test.ts.snap | 6 +----- tests/fixtures/input-events/output.d.ts | 6 +----- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/writer/writer-ts-definitions.ts b/src/writer/writer-ts-definitions.ts index 34e4d40..33d3750 100644 --- a/src/writer/writer-ts-definitions.ts +++ b/src/writer/writer-ts-definitions.ts @@ -124,11 +124,8 @@ function genSlotDef(def: Pick) { .join("\n"); } -const mapEvent = (name: string) => { - if (["cut", "copy", "paste"].includes(name)) { - return "DocumentAndElementEventHandlersEventMap"; - } - +const mapEvent = () => { + // lib.dom.d.ts should map event types by name. return "WindowEventMap"; }; @@ -147,7 +144,7 @@ function genEventDef(def: Pick) { description = "/** " + event.description + " */\n"; } return `${description}${clampKey(event.name)}: ${ - event.type === "dispatched" ? createDispatchedEvent(event.detail) : `${mapEvent(event.name)}["${event.name}"]` + event.type === "dispatched" ? createDispatchedEvent(event.detail) : `${mapEvent()}["${event.name}"]` };\n`; }) .join(""); diff --git a/tests/__snapshots__/fixtures.test.ts.snap b/tests/__snapshots__/fixtures.test.ts.snap index 61245f1..ccc951a 100644 --- a/tests/__snapshots__/fixtures.test.ts.snap +++ b/tests/__snapshots__/fixtures.test.ts.snap @@ -1553,11 +1553,7 @@ export interface InputEventsProps {} export default class InputEvents extends SvelteComponentTyped< InputEventsProps, - { - input: WindowEventMap["input"]; - change: WindowEventMap["change"]; - paste: DocumentAndElementEventHandlersEventMap["paste"]; - }, + { input: WindowEventMap["input"]; change: WindowEventMap["change"]; paste: WindowEventMap["paste"] }, {} > {} " diff --git a/tests/fixtures/input-events/output.d.ts b/tests/fixtures/input-events/output.d.ts index 4bce624..76d075e 100644 --- a/tests/fixtures/input-events/output.d.ts +++ b/tests/fixtures/input-events/output.d.ts @@ -4,10 +4,6 @@ export interface InputEventsProps {} export default class InputEvents extends SvelteComponentTyped< InputEventsProps, - { - input: WindowEventMap["input"]; - change: WindowEventMap["change"]; - paste: DocumentAndElementEventHandlersEventMap["paste"]; - }, + { input: WindowEventMap["input"]; change: WindowEventMap["change"]; paste: WindowEventMap["paste"] }, {} > {}