Skip to content

Commit

Permalink
fix(writer): use WindowEventMap for cut/copy/paste events (#143)
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
metonym authored Oct 25, 2024
1 parent 3826acb commit cfe753f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/writer/writer-ts-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ function genSlotDef(def: Pick<ComponentDocApi, "slots">) {
.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";
};

Expand All @@ -147,7 +144,7 @@ function genEventDef(def: Pick<ComponentDocApi, "events">) {
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("");
Expand Down
6 changes: 1 addition & 5 deletions tests/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
{}
> {}
"
Expand Down
6 changes: 1 addition & 5 deletions tests/fixtures/input-events/output.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
{}
> {}

0 comments on commit cfe753f

Please sign in to comment.