From dfbad3e222f9da8efbbf47202b71a9e83c730474 Mon Sep 17 00:00:00 2001 From: TPReal Date: Fri, 18 Oct 2024 22:54:56 +0200 Subject: [PATCH 1/3] Fix in DOMAttributes Added the (possibly forgotten?) BoolAttributes to DOMAttributes. It is never used otherwise. --- packages/dom-expressions/src/jsx-h.d.ts | 1 + packages/dom-expressions/src/jsx.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/dom-expressions/src/jsx-h.d.ts b/packages/dom-expressions/src/jsx-h.d.ts index 52548511..213f0872 100644 --- a/packages/dom-expressions/src/jsx-h.d.ts +++ b/packages/dom-expressions/src/jsx-h.d.ts @@ -136,6 +136,7 @@ export namespace JSX { DirectiveFunctionAttributes, PropAttributes, AttrAttributes, + BoolAttributes, OnAttributes, OnCaptureAttributes, CustomEventHandlersCamelCase, diff --git a/packages/dom-expressions/src/jsx.d.ts b/packages/dom-expressions/src/jsx.d.ts index 3b93d3eb..b2e6a2ef 100644 --- a/packages/dom-expressions/src/jsx.d.ts +++ b/packages/dom-expressions/src/jsx.d.ts @@ -202,6 +202,7 @@ export namespace JSX { DirectiveFunctionAttributes, PropAttributes, AttrAttributes, + BoolAttributes, OnAttributes, OnCaptureAttributes, CustomEventHandlersCamelCase, From 4fbe4db461543314d35f25166041cfede0d85895 Mon Sep 17 00:00:00 2001 From: TPReal Date: Sat, 19 Oct 2024 15:31:07 +0200 Subject: [PATCH 2/3] Fixed the types of on:* attributes. Allow the syntax that specifies the capture, passive and once keys. --- packages/dom-expressions/src/jsx-h.d.ts | 182 ++++++++++----------- packages/dom-expressions/src/jsx.d.ts | 202 ++++++++++++------------ 2 files changed, 193 insertions(+), 191 deletions(-) diff --git a/packages/dom-expressions/src/jsx-h.d.ts b/packages/dom-expressions/src/jsx-h.d.ts index 213f0872..30611c86 100644 --- a/packages/dom-expressions/src/jsx-h.d.ts +++ b/packages/dom-expressions/src/jsx-h.d.ts @@ -62,7 +62,7 @@ export namespace JSX { ) => void; } - type CustomEventHandlerUnion = + type EventHandlerWithOptionsUnion = | EventHandler | EventHandlerWithOptions; @@ -122,7 +122,7 @@ export namespace JSX { [Key in keyof ExplicitBoolAttributes as `bool:${Key}`]?: ExplicitBoolAttributes[Key]; }; type OnAttributes = { - [Key in keyof CustomEvents as `on:${Key}`]?: CustomEventHandlerUnion; + [Key in keyof CustomEvents as `on:${Key}`]?: EventHandlerWithOptionsUnion; }; type OnCaptureAttributes = { [Key in keyof CustomCaptureEvents as `oncapture:${Key}`]?: EventHandler< @@ -169,16 +169,16 @@ export namespace JSX { onencrypted?: EventHandlerUnion; ondragexit?: EventHandlerUnion; // namespaced events - "on:copy"?: EventHandlerUnion; - "on:cut"?: EventHandlerUnion; - "on:paste"?: EventHandlerUnion; - "on:compositionend"?: EventHandlerUnion; - "on:compositionstart"?: EventHandlerUnion; - "on:compositionupdate"?: EventHandlerUnion; - "on:focusout"?: EventHandlerUnion; - "on:focusin"?: EventHandlerUnion; - "on:encrypted"?: EventHandlerUnion; - "on:dragexit"?: EventHandlerUnion; + "on:copy"?: EventHandlerWithOptionsUnion; + "on:cut"?: EventHandlerWithOptionsUnion; + "on:paste"?: EventHandlerWithOptionsUnion; + "on:compositionend"?: EventHandlerWithOptionsUnion; + "on:compositionstart"?: EventHandlerWithOptionsUnion; + "on:compositionupdate"?: EventHandlerWithOptionsUnion; + "on:focusout"?: EventHandlerWithOptionsUnion; + "on:focusin"?: EventHandlerWithOptionsUnion; + "on:encrypted"?: EventHandlerWithOptionsUnion; + "on:dragexit"?: EventHandlerWithOptionsUnion; } interface CustomEventHandlersCamelCase { onAbort?: EventHandlerUnion; @@ -344,85 +344,85 @@ export namespace JSX { onwheel?: EventHandlerUnion; } interface CustomEventHandlersNamespaced { - "on:abort"?: EventHandlerUnion; - "on:animationend"?: EventHandlerUnion; - "on:animationiteration"?: EventHandlerUnion; - "on:animationstart"?: EventHandlerUnion; - "on:auxclick"?: EventHandlerUnion; - "on:beforeinput"?: EventHandlerUnion; - "on:beforetoggle"?: EventHandlerUnion; - "on:blur"?: EventHandlerUnion; - "on:canplay"?: EventHandlerUnion; - "on:canplaythrough"?: EventHandlerUnion; - "on:change"?: EventHandlerUnion; - "on:click"?: EventHandlerUnion; - "on:contextmenu"?: EventHandlerUnion; - "on:dblclick"?: EventHandlerUnion; - "on:drag"?: EventHandlerUnion; - "on:dragend"?: EventHandlerUnion; - "on:dragenter"?: EventHandlerUnion; - "on:dragleave"?: EventHandlerUnion; - "on:dragover"?: EventHandlerUnion; - "on:dragstart"?: EventHandlerUnion; - "on:drop"?: EventHandlerUnion; - "on:durationchange"?: EventHandlerUnion; - "on:emptied"?: EventHandlerUnion; - "on:ended"?: EventHandlerUnion; - "on:error"?: EventHandlerUnion; - "on:focus"?: EventHandlerUnion; - "on:gotpointercapture"?: EventHandlerUnion; - "on:input"?: EventHandlerUnion; - "on:invalid"?: EventHandlerUnion; - "on:keydown"?: EventHandlerUnion; - "on:keypress"?: EventHandlerUnion; - "on:keyup"?: EventHandlerUnion; - "on:load"?: EventHandlerUnion; - "on:loadeddata"?: EventHandlerUnion; - "on:loadedmetadata"?: EventHandlerUnion; - "on:loadstart"?: EventHandlerUnion; - "on:lostpointercapture"?: EventHandlerUnion; - "on:mousedown"?: EventHandlerUnion; - "on:mouseenter"?: EventHandlerUnion; - "on:mouseleave"?: EventHandlerUnion; - "on:mousemove"?: EventHandlerUnion; - "on:mouseout"?: EventHandlerUnion; - "on:mouseover"?: EventHandlerUnion; - "on:mouseup"?: EventHandlerUnion; - "on:pause"?: EventHandlerUnion; - "on:play"?: EventHandlerUnion; - "on:playing"?: EventHandlerUnion; - "on:pointercancel"?: EventHandlerUnion; - "on:pointerdown"?: EventHandlerUnion; - "on:pointerenter"?: EventHandlerUnion; - "on:pointerleave"?: EventHandlerUnion; - "on:pointermove"?: EventHandlerUnion; - "on:pointerout"?: EventHandlerUnion; - "on:pointerover"?: EventHandlerUnion; - "on:pointerup"?: EventHandlerUnion; - "on:progress"?: EventHandlerUnion; - "on:ratechange"?: EventHandlerUnion; - "on:reset"?: EventHandlerUnion; - "on:scroll"?: EventHandlerUnion; - "on:scrollend"?: EventHandlerUnion; - "on:seeked"?: EventHandlerUnion; - "on:seeking"?: EventHandlerUnion; - "on:select"?: EventHandlerUnion; - "on:stalled"?: EventHandlerUnion; - "on:submit"?: EventHandlerUnion; - "on:suspend"?: EventHandlerUnion; - "on:timeupdate"?: EventHandlerUnion; - "on:toggle"?: EventHandlerUnion; - "on:touchcancel"?: EventHandlerUnion; - "on:touchend"?: EventHandlerUnion; - "on:touchmove"?: EventHandlerUnion; - "on:touchstart"?: EventHandlerUnion; - "on:transitionstart"?: EventHandlerUnion; - "on:transitionend"?: EventHandlerUnion; - "on:transitionrun"?: EventHandlerUnion; - "on:transitioncancel"?: EventHandlerUnion; - "on:volumechange"?: EventHandlerUnion; - "on:waiting"?: EventHandlerUnion; - "on:wheel"?: EventHandlerUnion; + "on:abort"?: EventHandlerWithOptionsUnion; + "on:animationend"?: EventHandlerWithOptionsUnion; + "on:animationiteration"?: EventHandlerWithOptionsUnion; + "on:animationstart"?: EventHandlerWithOptionsUnion; + "on:auxclick"?: EventHandlerWithOptionsUnion; + "on:beforeinput"?: EventHandlerWithOptionsUnion; + "on:beforetoggle"?: EventHandlerWithOptionsUnion; + "on:blur"?: EventHandlerWithOptionsUnion; + "on:canplay"?: EventHandlerWithOptionsUnion; + "on:canplaythrough"?: EventHandlerWithOptionsUnion; + "on:change"?: EventHandlerWithOptionsUnion; + "on:click"?: EventHandlerWithOptionsUnion; + "on:contextmenu"?: EventHandlerWithOptionsUnion; + "on:dblclick"?: EventHandlerWithOptionsUnion; + "on:drag"?: EventHandlerWithOptionsUnion; + "on:dragend"?: EventHandlerWithOptionsUnion; + "on:dragenter"?: EventHandlerWithOptionsUnion; + "on:dragleave"?: EventHandlerWithOptionsUnion; + "on:dragover"?: EventHandlerWithOptionsUnion; + "on:dragstart"?: EventHandlerWithOptionsUnion; + "on:drop"?: EventHandlerWithOptionsUnion; + "on:durationchange"?: EventHandlerWithOptionsUnion; + "on:emptied"?: EventHandlerWithOptionsUnion; + "on:ended"?: EventHandlerWithOptionsUnion; + "on:error"?: EventHandlerWithOptionsUnion; + "on:focus"?: EventHandlerWithOptionsUnion; + "on:gotpointercapture"?: EventHandlerWithOptionsUnion; + "on:input"?: EventHandlerWithOptionsUnion; + "on:invalid"?: EventHandlerWithOptionsUnion; + "on:keydown"?: EventHandlerWithOptionsUnion; + "on:keypress"?: EventHandlerWithOptionsUnion; + "on:keyup"?: EventHandlerWithOptionsUnion; + "on:load"?: EventHandlerWithOptionsUnion; + "on:loadeddata"?: EventHandlerWithOptionsUnion; + "on:loadedmetadata"?: EventHandlerWithOptionsUnion; + "on:loadstart"?: EventHandlerWithOptionsUnion; + "on:lostpointercapture"?: EventHandlerWithOptionsUnion; + "on:mousedown"?: EventHandlerWithOptionsUnion; + "on:mouseenter"?: EventHandlerWithOptionsUnion; + "on:mouseleave"?: EventHandlerWithOptionsUnion; + "on:mousemove"?: EventHandlerWithOptionsUnion; + "on:mouseout"?: EventHandlerWithOptionsUnion; + "on:mouseover"?: EventHandlerWithOptionsUnion; + "on:mouseup"?: EventHandlerWithOptionsUnion; + "on:pause"?: EventHandlerWithOptionsUnion; + "on:play"?: EventHandlerWithOptionsUnion; + "on:playing"?: EventHandlerWithOptionsUnion; + "on:pointercancel"?: EventHandlerWithOptionsUnion; + "on:pointerdown"?: EventHandlerWithOptionsUnion; + "on:pointerenter"?: EventHandlerWithOptionsUnion; + "on:pointerleave"?: EventHandlerWithOptionsUnion; + "on:pointermove"?: EventHandlerWithOptionsUnion; + "on:pointerout"?: EventHandlerWithOptionsUnion; + "on:pointerover"?: EventHandlerWithOptionsUnion; + "on:pointerup"?: EventHandlerWithOptionsUnion; + "on:progress"?: EventHandlerWithOptionsUnion; + "on:ratechange"?: EventHandlerWithOptionsUnion; + "on:reset"?: EventHandlerWithOptionsUnion; + "on:scroll"?: EventHandlerWithOptionsUnion; + "on:scrollend"?: EventHandlerWithOptionsUnion; + "on:seeked"?: EventHandlerWithOptionsUnion; + "on:seeking"?: EventHandlerWithOptionsUnion; + "on:select"?: EventHandlerWithOptionsUnion; + "on:stalled"?: EventHandlerWithOptionsUnion; + "on:submit"?: EventHandlerWithOptionsUnion; + "on:suspend"?: EventHandlerWithOptionsUnion; + "on:timeupdate"?: EventHandlerWithOptionsUnion; + "on:toggle"?: EventHandlerWithOptionsUnion; + "on:touchcancel"?: EventHandlerWithOptionsUnion; + "on:touchend"?: EventHandlerWithOptionsUnion; + "on:touchmove"?: EventHandlerWithOptionsUnion; + "on:touchstart"?: EventHandlerWithOptionsUnion; + "on:transitionstart"?: EventHandlerWithOptionsUnion; + "on:transitionend"?: EventHandlerWithOptionsUnion; + "on:transitionrun"?: EventHandlerWithOptionsUnion; + "on:transitioncancel"?: EventHandlerWithOptionsUnion; + "on:volumechange"?: EventHandlerWithOptionsUnion; + "on:waiting"?: EventHandlerWithOptionsUnion; + "on:wheel"?: EventHandlerWithOptionsUnion; } interface CSSProperties extends csstype.PropertiesHyphen { diff --git a/packages/dom-expressions/src/jsx.d.ts b/packages/dom-expressions/src/jsx.d.ts index b2e6a2ef..561ee68d 100644 --- a/packages/dom-expressions/src/jsx.d.ts +++ b/packages/dom-expressions/src/jsx.d.ts @@ -41,18 +41,14 @@ export namespace JSX { } type EventHandlerUnion = EventHandler | BoundEventHandler; - interface EventHandlerWithOptions extends AddEventListenerOptions { - handleEvent: ( - e: E & { - currentTarget: T; - target: Element; - } - ) => void; + interface EventHandlerWithOptions> + extends AddEventListenerOptions { + handleEvent: EHandler; } - type CustomEventHandlerUnion = - | EventHandler - | EventHandlerWithOptions; + type EventHandlerWithOptionsUnion> = + | EHandler + | EventHandlerWithOptions; interface InputEventHandler { ( @@ -188,7 +184,7 @@ export namespace JSX { [Key in keyof ExplicitBoolAttributes as `bool:${Key}`]?: ExplicitBoolAttributes[Key]; }; type OnAttributes = { - [Key in keyof CustomEvents as `on:${Key}`]?: CustomEventHandlerUnion; + [Key in keyof CustomEvents as `on:${Key}`]?: EventHandlerWithOptionsUnion; }; type OnCaptureAttributes = { [Key in keyof CustomCaptureEvents as `oncapture:${Key}`]?: EventHandler< @@ -235,16 +231,18 @@ export namespace JSX { onencrypted?: EventHandlerUnion | undefined; ondragexit?: EventHandlerUnion | undefined; // lower case events - "on:copy"?: EventHandlerUnion | undefined; - "on:cut"?: EventHandlerUnion | undefined; - "on:paste"?: EventHandlerUnion | undefined; - "on:compositionend"?: EventHandlerUnion | undefined; - "on:compositionstart"?: EventHandlerUnion | undefined; - "on:compositionupdate"?: EventHandlerUnion | undefined; - "on:focusout"?: FocusEventHandlerUnion | undefined; - "on:focusin"?: FocusEventHandlerUnion | undefined; - "on:encrypted"?: EventHandlerUnion | undefined; - "on:dragexit"?: EventHandlerUnion | undefined; + "on:copy"?: EventHandlerWithOptionsUnion | undefined; + "on:cut"?: EventHandlerWithOptionsUnion | undefined; + "on:paste"?: EventHandlerWithOptionsUnion | undefined; + "on:compositionend"?: EventHandlerWithOptionsUnion | undefined; + "on:compositionstart"?: EventHandlerWithOptionsUnion | undefined; + "on:compositionupdate"?: EventHandlerWithOptionsUnion | undefined; + "on:focusout"?: + EventHandlerWithOptionsUnion> | undefined; + "on:focusin"?: + EventHandlerWithOptionsUnion> | undefined; + "on:encrypted"?: EventHandlerWithOptionsUnion | undefined; + "on:dragexit"?: EventHandlerWithOptionsUnion | undefined; } interface CustomEventHandlersCamelCase { onAbort?: EventHandlerUnion | undefined; @@ -410,85 +408,89 @@ export namespace JSX { onwheel?: EventHandlerUnion | undefined; } interface CustomEventHandlersNamespaced { - "on:abort"?: EventHandlerUnion | undefined; - "on:animationend"?: EventHandlerUnion | undefined; - "on:animationiteration"?: EventHandlerUnion | undefined; - "on:animationstart"?: EventHandlerUnion | undefined; - "on:auxclick"?: EventHandlerUnion | undefined; - "on:beforeinput"?: InputEventHandlerUnion | undefined; - "on:beforetoggle"?: EventHandlerUnion | undefined; - "on:blur"?: FocusEventHandlerUnion | undefined; - "on:canplay"?: EventHandlerUnion | undefined; - "on:canplaythrough"?: EventHandlerUnion | undefined; - "on:change"?: ChangeEventHandlerUnion | undefined; - "on:click"?: EventHandlerUnion | undefined; - "on:contextmenu"?: EventHandlerUnion | undefined; - "on:dblclick"?: EventHandlerUnion | undefined; - "on:drag"?: EventHandlerUnion | undefined; - "on:dragend"?: EventHandlerUnion | undefined; - "on:dragenter"?: EventHandlerUnion | undefined; - "on:dragleave"?: EventHandlerUnion | undefined; - "on:dragover"?: EventHandlerUnion | undefined; - "on:dragstart"?: EventHandlerUnion | undefined; - "on:drop"?: EventHandlerUnion | undefined; - "on:durationchange"?: EventHandlerUnion | undefined; - "on:emptied"?: EventHandlerUnion | undefined; - "on:ended"?: EventHandlerUnion | undefined; - "on:error"?: EventHandlerUnion | undefined; - "on:focus"?: FocusEventHandlerUnion | undefined; - "on:gotpointercapture"?: EventHandlerUnion | undefined; - "on:input"?: InputEventHandlerUnion | undefined; - "on:invalid"?: EventHandlerUnion | undefined; - "on:keydown"?: EventHandlerUnion | undefined; - "on:keypress"?: EventHandlerUnion | undefined; - "on:keyup"?: EventHandlerUnion | undefined; - "on:load"?: EventHandlerUnion | undefined; - "on:loadeddata"?: EventHandlerUnion | undefined; - "on:loadedmetadata"?: EventHandlerUnion | undefined; - "on:loadstart"?: EventHandlerUnion | undefined; - "on:lostpointercapture"?: EventHandlerUnion | undefined; - "on:mousedown"?: EventHandlerUnion | undefined; - "on:mouseenter"?: EventHandlerUnion | undefined; - "on:mouseleave"?: EventHandlerUnion | undefined; - "on:mousemove"?: EventHandlerUnion | undefined; - "on:mouseout"?: EventHandlerUnion | undefined; - "on:mouseover"?: EventHandlerUnion | undefined; - "on:mouseup"?: EventHandlerUnion | undefined; - "on:pause"?: EventHandlerUnion | undefined; - "on:play"?: EventHandlerUnion | undefined; - "on:playing"?: EventHandlerUnion | undefined; - "on:pointercancel"?: EventHandlerUnion | undefined; - "on:pointerdown"?: EventHandlerUnion | undefined; - "on:pointerenter"?: EventHandlerUnion | undefined; - "on:pointerleave"?: EventHandlerUnion | undefined; - "on:pointermove"?: EventHandlerUnion | undefined; - "on:pointerout"?: EventHandlerUnion | undefined; - "on:pointerover"?: EventHandlerUnion | undefined; - "on:pointerup"?: EventHandlerUnion | undefined; - "on:progress"?: EventHandlerUnion | undefined; - "on:ratechange"?: EventHandlerUnion | undefined; - "on:reset"?: EventHandlerUnion | undefined; - "on:scroll"?: EventHandlerUnion | undefined; - "on:scrollend"?: EventHandlerUnion | undefined; - "on:seeked"?: EventHandlerUnion | undefined; - "on:seeking"?: EventHandlerUnion | undefined; - "on:select"?: EventHandlerUnion | undefined; - "on:stalled"?: EventHandlerUnion | undefined; - "on:submit"?: EventHandlerUnion | undefined; - "on:suspend"?: EventHandlerUnion | undefined; - "on:timeupdate"?: EventHandlerUnion | undefined; - "on:toggle"?: EventHandlerUnion | undefined; - "on:touchcancel"?: EventHandlerUnion | undefined; - "on:touchend"?: EventHandlerUnion | undefined; - "on:touchmove"?: EventHandlerUnion | undefined; - "on:touchstart"?: EventHandlerUnion | undefined; - "on:transitionstart"?: EventHandlerUnion | undefined; - "on:transitionend"?: EventHandlerUnion | undefined; - "on:transitionrun"?: EventHandlerUnion | undefined; - "on:transitioncancel"?: EventHandlerUnion | undefined; - "on:volumechange"?: EventHandlerUnion | undefined; - "on:waiting"?: EventHandlerUnion | undefined; - "on:wheel"?: EventHandlerUnion | undefined; + "on:abort"?: EventHandlerWithOptionsUnion | undefined; + "on:animationend"?: EventHandlerWithOptionsUnion | undefined; + "on:animationiteration"?: EventHandlerWithOptionsUnion | undefined; + "on:animationstart"?: EventHandlerWithOptionsUnion | undefined; + "on:auxclick"?: EventHandlerWithOptionsUnion | undefined; + "on:beforeinput"?: + EventHandlerWithOptionsUnion> | undefined; + "on:beforetoggle"?: EventHandlerWithOptionsUnion | undefined; + "on:blur"?: + EventHandlerWithOptionsUnion> | undefined; + "on:canplay"?: EventHandlerWithOptionsUnion | undefined; + "on:canplaythrough"?: EventHandlerWithOptionsUnion | undefined; + "on:change"?: EventHandlerWithOptionsUnion> | undefined; + "on:click"?: EventHandlerWithOptionsUnion | undefined; + "on:contextmenu"?: EventHandlerWithOptionsUnion | undefined; + "on:dblclick"?: EventHandlerWithOptionsUnion | undefined; + "on:drag"?: EventHandlerWithOptionsUnion | undefined; + "on:dragend"?: EventHandlerWithOptionsUnion | undefined; + "on:dragenter"?: EventHandlerWithOptionsUnion | undefined; + "on:dragleave"?: EventHandlerWithOptionsUnion | undefined; + "on:dragover"?: EventHandlerWithOptionsUnion | undefined; + "on:dragstart"?: EventHandlerWithOptionsUnion | undefined; + "on:drop"?: EventHandlerWithOptionsUnion | undefined; + "on:durationchange"?: EventHandlerWithOptionsUnion | undefined; + "on:emptied"?: EventHandlerWithOptionsUnion | undefined; + "on:ended"?: EventHandlerWithOptionsUnion | undefined; + "on:error"?: EventHandlerWithOptionsUnion | undefined; + "on:focus"?: + EventHandlerWithOptionsUnion> | undefined; + "on:gotpointercapture"?: EventHandlerWithOptionsUnion | undefined; + "on:input"?: + EventHandlerWithOptionsUnion> | undefined; + "on:invalid"?: EventHandlerWithOptionsUnion | undefined; + "on:keydown"?: EventHandlerWithOptionsUnion | undefined; + "on:keypress"?: EventHandlerWithOptionsUnion | undefined; + "on:keyup"?: EventHandlerWithOptionsUnion | undefined; + "on:load"?: EventHandlerWithOptionsUnion | undefined; + "on:loadeddata"?: EventHandlerWithOptionsUnion | undefined; + "on:loadedmetadata"?: EventHandlerWithOptionsUnion | undefined; + "on:loadstart"?: EventHandlerWithOptionsUnion | undefined; + "on:lostpointercapture"?: EventHandlerWithOptionsUnion | undefined; + "on:mousedown"?: EventHandlerWithOptionsUnion | undefined; + "on:mouseenter"?: EventHandlerWithOptionsUnion | undefined; + "on:mouseleave"?: EventHandlerWithOptionsUnion | undefined; + "on:mousemove"?: EventHandlerWithOptionsUnion | undefined; + "on:mouseout"?: EventHandlerWithOptionsUnion | undefined; + "on:mouseover"?: EventHandlerWithOptionsUnion | undefined; + "on:mouseup"?: EventHandlerWithOptionsUnion | undefined; + "on:pause"?: EventHandlerWithOptionsUnion | undefined; + "on:play"?: EventHandlerWithOptionsUnion | undefined; + "on:playing"?: EventHandlerWithOptionsUnion | undefined; + "on:pointercancel"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerdown"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerenter"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerleave"?: EventHandlerWithOptionsUnion | undefined; + "on:pointermove"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerout"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerover"?: EventHandlerWithOptionsUnion | undefined; + "on:pointerup"?: EventHandlerWithOptionsUnion | undefined; + "on:progress"?: EventHandlerWithOptionsUnion | undefined; + "on:ratechange"?: EventHandlerWithOptionsUnion | undefined; + "on:reset"?: EventHandlerWithOptionsUnion | undefined; + "on:scroll"?: EventHandlerWithOptionsUnion | undefined; + "on:scrollend"?: EventHandlerWithOptionsUnion | undefined; + "on:seeked"?: EventHandlerWithOptionsUnion | undefined; + "on:seeking"?: EventHandlerWithOptionsUnion | undefined; + "on:select"?: EventHandlerWithOptionsUnion | undefined; + "on:stalled"?: EventHandlerWithOptionsUnion | undefined; + "on:submit"?: EventHandlerWithOptionsUnion | undefined; + "on:suspend"?: EventHandlerWithOptionsUnion | undefined; + "on:timeupdate"?: EventHandlerWithOptionsUnion | undefined; + "on:toggle"?: EventHandlerWithOptionsUnion | undefined; + "on:touchcancel"?: EventHandlerWithOptionsUnion | undefined; + "on:touchend"?: EventHandlerWithOptionsUnion | undefined; + "on:touchmove"?: EventHandlerWithOptionsUnion | undefined; + "on:touchstart"?: EventHandlerWithOptionsUnion | undefined; + "on:transitionstart"?: EventHandlerWithOptionsUnion | undefined; + "on:transitionend"?: EventHandlerWithOptionsUnion | undefined; + "on:transitionrun"?: EventHandlerWithOptionsUnion | undefined; + "on:transitioncancel"?: EventHandlerWithOptionsUnion | undefined; + "on:volumechange"?: EventHandlerWithOptionsUnion | undefined; + "on:waiting"?: EventHandlerWithOptionsUnion | undefined; + "on:wheel"?: EventHandlerWithOptionsUnion | undefined; } interface CSSProperties extends csstype.PropertiesHyphen { From c9bdad0b32ccc03598eb1936b72183cbf3399b16 Mon Sep 17 00:00:00 2001 From: TPReal Date: Sat, 19 Oct 2024 15:54:07 +0200 Subject: [PATCH 3/3] Further improved the JSX event handler attributes types. --- packages/dom-expressions/src/jsx.d.ts | 67 ++++++--------------------- 1 file changed, 15 insertions(+), 52 deletions(-) diff --git a/packages/dom-expressions/src/jsx.d.ts b/packages/dom-expressions/src/jsx.d.ts index 561ee68d..c211e970 100644 --- a/packages/dom-expressions/src/jsx.d.ts +++ b/packages/dom-expressions/src/jsx.d.ts @@ -29,24 +29,29 @@ export namespace JSX { ): void; } - interface BoundEventHandler { + interface BoundEventHandler< + T, + E extends Event, + EHandler extends EventHandler = EventHandler, + > { 0: ( data: any, - e: E & { - currentTarget: T; - target: DOMElement; - } + ...e: Parameters, ) => void; 1: any; } - type EventHandlerUnion = EventHandler | BoundEventHandler; + type EventHandlerUnion< + T, + E extends Event, + EHandler extends EventHandler = EventHandler, + > = EHandler | BoundEventHandler; interface EventHandlerWithOptions> extends AddEventListenerOptions { handleEvent: EHandler; } - type EventHandlerWithOptionsUnion> = + type EventHandlerWithOptionsUnion = EventHandler> = | EHandler | EventHandlerWithOptions; @@ -60,21 +65,7 @@ export namespace JSX { } ): void; } - interface BoundInputEventHandler { - 0: ( - data: any, - e: E & { - currentTarget: T; - target: T extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement - ? T - : DOMElement; - } - ) => void; - 1: any; - } - type InputEventHandlerUnion = - | InputEventHandler - | BoundInputEventHandler; + type InputEventHandlerUnion = EventHandlerUnion>; interface ChangeEventHandler { ( @@ -86,21 +77,7 @@ export namespace JSX { } ): void; } - interface BoundChangeEventHandler { - 0: ( - data: any, - e: E & { - currentTarget: T; - target: T extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement - ? T - : DOMElement; - } - ) => void; - 1: any; - } - type ChangeEventHandlerUnion = - | ChangeEventHandler - | BoundChangeEventHandler; + type ChangeEventHandlerUnion = EventHandlerUnion>; interface FocusEventHandler { ( @@ -112,21 +89,7 @@ export namespace JSX { } ): void; } - interface BoundFocusEventHandler { - 0: ( - data: any, - e: E & { - currentTarget: T; - target: T extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement - ? T - : DOMElement; - } - ) => void; - 1: any; - } - type FocusEventHandlerUnion = - | FocusEventHandler - | BoundFocusEventHandler; + type FocusEventHandlerUnion = EventHandlerUnion>; const SERIALIZABLE: unique symbol; interface SerializableAttributeValue {