From 3f690de90d37bda45a38cad98ef7e0b85e8f895b Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 12 Dec 2024 05:52:06 -0600 Subject: [PATCH 1/4] refactor: Assume default targets for HTML attribute interfaces --- src/jsx.d.ts | 100 +++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 848f7dc6ad..387c4540b6 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1533,7 +1533,7 @@ export namespace JSXInternal { | '_top' | (string & {}); - interface AnchorHTMLAttributes + interface AnchorHTMLAttributes extends HTMLAttributes { download?: Signalish; href?: Signalish; @@ -1548,7 +1548,7 @@ export namespace JSXInternal { referrerPolicy?: Signalish; } - interface AreaHTMLAttributes + interface AreaHTMLAttributes extends HTMLAttributes { alt?: Signalish; coords?: Signalish; @@ -1564,21 +1564,21 @@ export namespace JSXInternal { target?: Signalish; } - interface AudioHTMLAttributes + interface AudioHTMLAttributes extends MediaHTMLAttributes {} - interface BaseHTMLAttributes + interface BaseHTMLAttributes extends HTMLAttributes { href?: Signalish; target?: Signalish; } - interface BlockquoteHTMLAttributes + interface BlockquoteHTMLAttributes extends HTMLAttributes { cite?: Signalish; } - interface ButtonHTMLAttributes + interface ButtonHTMLAttributes extends HTMLAttributes { disabled?: Signalish; form?: Signalish; @@ -1601,47 +1601,47 @@ export namespace JSXInternal { value?: Signalish; } - interface CanvasHTMLAttributes + interface CanvasHTMLAttributes extends HTMLAttributes { height?: Signalish; width?: Signalish; } - interface ColHTMLAttributes extends HTMLAttributes { + interface ColHTMLAttributes extends HTMLAttributes { span?: Signalish; width?: Signalish; } - interface ColgroupHTMLAttributes + interface ColgroupHTMLAttributes extends HTMLAttributes { span?: Signalish; } - interface DataHTMLAttributes + interface DataHTMLAttributes extends HTMLAttributes { value?: Signalish; } - interface DelHTMLAttributes extends HTMLAttributes { + interface DelHTMLAttributes extends HTMLAttributes { cite?: Signalish; datetime?: Signalish; dateTime?: Signalish; } - interface DetailsHTMLAttributes + interface DetailsHTMLAttributes extends HTMLAttributes { open?: Signalish; onToggle?: GenericEventHandler | undefined; } - interface DialogHTMLAttributes + interface DialogHTMLAttributes extends HTMLAttributes { onCancel?: GenericEventHandler | undefined; onClose?: GenericEventHandler | undefined; open?: Signalish; } - interface EmbedHTMLAttributes + interface EmbedHTMLAttributes extends HTMLAttributes { height?: Signalish; src?: Signalish; @@ -1649,14 +1649,14 @@ export namespace JSXInternal { width?: Signalish; } - interface FieldsetHTMLAttributes + interface FieldsetHTMLAttributes extends HTMLAttributes { disabled?: Signalish; form?: Signalish; name?: Signalish; } - interface FormHTMLAttributes + interface FormHTMLAttributes extends HTMLAttributes { 'accept-charset'?: Signalish; acceptCharset?: Signalish; @@ -1673,7 +1673,7 @@ export namespace JSXInternal { target?: Signalish; } - interface IframeHTMLAttributes + interface IframeHTMLAttributes extends HTMLAttributes { allow?: Signalish; allowFullScreen?: Signalish; @@ -1703,7 +1703,7 @@ export namespace JSXInternal { type HTMLAttributeCrossOrigin = 'anonymous' | 'use-credentials'; - interface ImgHTMLAttributes extends HTMLAttributes { + interface ImgHTMLAttributes extends HTMLAttributes { alt?: Signalish; crossorigin?: Signalish; crossOrigin?: Signalish; @@ -1746,7 +1746,7 @@ export namespace JSXInternal { | 'week' | (string & {}); - interface InputHTMLAttributes + interface InputHTMLAttributes extends HTMLAttributes { accept?: Signalish; alt?: Signalish; @@ -1803,13 +1803,13 @@ export namespace JSXInternal { onChange?: GenericEventHandler | undefined; } - interface InsHTMLAttributes extends HTMLAttributes { + interface InsHTMLAttributes extends HTMLAttributes { cite?: Signalish; datetime?: Signalish; dateTime?: Signalish; } - interface KeygenHTMLAttributes + interface KeygenHTMLAttributes extends HTMLAttributes { challenge?: Signalish; disabled?: Signalish; @@ -1819,18 +1819,18 @@ export namespace JSXInternal { name?: Signalish; } - interface LabelHTMLAttributes + interface LabelHTMLAttributes extends HTMLAttributes { for?: Signalish; form?: Signalish; htmlFor?: Signalish; } - interface LiHTMLAttributes extends HTMLAttributes { + interface LiHTMLAttributes extends HTMLAttributes { value?: Signalish; } - interface LinkHTMLAttributes + interface LinkHTMLAttributes extends HTMLAttributes { as?: Signalish; crossorigin?: Signalish; @@ -1851,11 +1851,11 @@ export namespace JSXInternal { charSet?: Signalish; } - interface MapHTMLAttributes extends HTMLAttributes { + interface MapHTMLAttributes extends HTMLAttributes { name?: Signalish; } - interface MarqueeHTMLAttributes + interface MarqueeHTMLAttributes extends HTMLAttributes { behavior?: Signalish<'scroll' | 'slide' | 'alternate' | undefined>; bgColor?: Signalish; @@ -1870,7 +1870,7 @@ export namespace JSXInternal { width?: Signalish; } - interface MediaHTMLAttributes + interface MediaHTMLAttributes extends HTMLAttributes { autoplay?: Signalish; autoPlay?: Signalish; @@ -1888,12 +1888,12 @@ export namespace JSXInternal { volume?: Signalish; } - interface MenuHTMLAttributes + interface MenuHTMLAttributes extends HTMLAttributes { type?: Signalish; } - interface MetaHTMLAttributes + interface MetaHTMLAttributes extends HTMLAttributes { charset?: Signalish; charSet?: Signalish; @@ -1904,7 +1904,7 @@ export namespace JSXInternal { media?: Signalish; } - interface MeterHTMLAttributes + interface MeterHTMLAttributes extends HTMLAttributes { form?: Signalish; high?: Signalish; @@ -1915,7 +1915,7 @@ export namespace JSXInternal { value?: Signalish; } - interface ObjectHTMLAttributes + interface ObjectHTMLAttributes extends HTMLAttributes { classID?: Signalish; data?: Signalish; @@ -1929,19 +1929,19 @@ export namespace JSXInternal { wmode?: Signalish; } - interface OlHTMLAttributes extends HTMLAttributes { + interface OlHTMLAttributes extends HTMLAttributes { reversed?: Signalish; start?: Signalish; type?: Signalish<'1' | 'a' | 'A' | 'i' | 'I' | undefined>; } - interface OptgroupHTMLAttributes + interface OptgroupHTMLAttributes extends HTMLAttributes { disabled?: Signalish; label?: Signalish; } - interface OptionHTMLAttributes + interface OptionHTMLAttributes extends HTMLAttributes { disabled?: Signalish; label?: Signalish; @@ -1949,7 +1949,7 @@ export namespace JSXInternal { value?: Signalish; } - interface OutputHTMLAttributes + interface OutputHTMLAttributes extends HTMLAttributes { for?: Signalish; form?: Signalish; @@ -1957,24 +1957,24 @@ export namespace JSXInternal { name?: Signalish; } - interface ParamHTMLAttributes + interface ParamHTMLAttributes extends HTMLAttributes { name?: Signalish; value?: Signalish; } - interface ProgressHTMLAttributes + interface ProgressHTMLAttributes extends HTMLAttributes { max?: Signalish; value?: Signalish; } - interface QuoteHTMLAttributes + interface QuoteHTMLAttributes extends HTMLAttributes { cite?: Signalish; } - interface ScriptHTMLAttributes + interface ScriptHTMLAttributes extends HTMLAttributes { async?: Signalish; /** @deprecated */ @@ -1993,7 +1993,7 @@ export namespace JSXInternal { type?: Signalish; } - interface SelectHTMLAttributes + interface SelectHTMLAttributes extends HTMLAttributes { autocomplete?: Signalish; autoComplete?: Signalish; @@ -2008,12 +2008,12 @@ export namespace JSXInternal { onChange?: GenericEventHandler | undefined; } - interface SlotHTMLAttributes + interface SlotHTMLAttributes extends HTMLAttributes { name?: Signalish; } - interface SourceHTMLAttributes + interface SourceHTMLAttributes extends HTMLAttributes { height?: Signalish; media?: Signalish; @@ -2025,14 +2025,14 @@ export namespace JSXInternal { width?: Signalish; } - interface StyleHTMLAttributes + interface StyleHTMLAttributes extends HTMLAttributes { media?: Signalish; scoped?: Signalish; type?: Signalish; } - interface TableHTMLAttributes + interface TableHTMLAttributes extends HTMLAttributes { cellPadding?: Signalish; cellSpacing?: Signalish; @@ -2040,7 +2040,7 @@ export namespace JSXInternal { width?: Signalish; } - interface TdHTMLAttributes extends HTMLAttributes { + interface TdHTMLAttributes extends HTMLAttributes { align?: Signalish< 'left' | 'center' | 'right' | 'justify' | 'char' | undefined >; @@ -2056,7 +2056,7 @@ export namespace JSXInternal { valign?: Signalish<'top' | 'middle' | 'bottom' | 'baseline' | undefined>; } - interface TextareaHTMLAttributes + interface TextareaHTMLAttributes extends HTMLAttributes { autocomplete?: Signalish; autoComplete?: Signalish; @@ -2079,7 +2079,7 @@ export namespace JSXInternal { onChange?: GenericEventHandler | undefined; } - interface ThHTMLAttributes extends HTMLAttributes { + interface ThHTMLAttributes extends HTMLAttributes { align?: Signalish< 'left' | 'center' | 'right' | 'justify' | 'char' | undefined >; @@ -2092,13 +2092,13 @@ export namespace JSXInternal { abbr?: Signalish; } - interface TimeHTMLAttributes + interface TimeHTMLAttributes extends HTMLAttributes { datetime?: Signalish; dateTime?: Signalish; } - interface TrackHTMLAttributes + interface TrackHTMLAttributes extends MediaHTMLAttributes { default?: Signalish; kind?: Signalish; @@ -2107,7 +2107,7 @@ export namespace JSXInternal { srcLang?: Signalish; } - interface VideoHTMLAttributes + interface VideoHTMLAttributes extends MediaHTMLAttributes { height?: Signalish; poster?: Signalish; From f50580152b1e373ae8c39f656e9f5f1e1decf399 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 12 Dec 2024 05:53:04 -0600 Subject: [PATCH 2/4] chore: Formatting --- src/jsx.d.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/jsx.d.ts b/src/jsx.d.ts index 387c4540b6..f90939e6f2 100644 --- a/src/jsx.d.ts +++ b/src/jsx.d.ts @@ -1607,7 +1607,8 @@ export namespace JSXInternal { width?: Signalish; } - interface ColHTMLAttributes extends HTMLAttributes { + interface ColHTMLAttributes + extends HTMLAttributes { span?: Signalish; width?: Signalish; } @@ -1622,7 +1623,8 @@ export namespace JSXInternal { value?: Signalish; } - interface DelHTMLAttributes extends HTMLAttributes { + interface DelHTMLAttributes + extends HTMLAttributes { cite?: Signalish; datetime?: Signalish; dateTime?: Signalish; @@ -1703,7 +1705,8 @@ export namespace JSXInternal { type HTMLAttributeCrossOrigin = 'anonymous' | 'use-credentials'; - interface ImgHTMLAttributes extends HTMLAttributes { + interface ImgHTMLAttributes + extends HTMLAttributes { alt?: Signalish; crossorigin?: Signalish; crossOrigin?: Signalish; @@ -1803,7 +1806,8 @@ export namespace JSXInternal { onChange?: GenericEventHandler | undefined; } - interface InsHTMLAttributes extends HTMLAttributes { + interface InsHTMLAttributes + extends HTMLAttributes { cite?: Signalish; datetime?: Signalish; dateTime?: Signalish; @@ -1826,7 +1830,8 @@ export namespace JSXInternal { htmlFor?: Signalish; } - interface LiHTMLAttributes extends HTMLAttributes { + interface LiHTMLAttributes + extends HTMLAttributes { value?: Signalish; } @@ -1851,7 +1856,8 @@ export namespace JSXInternal { charSet?: Signalish; } - interface MapHTMLAttributes extends HTMLAttributes { + interface MapHTMLAttributes + extends HTMLAttributes { name?: Signalish; } @@ -1929,7 +1935,8 @@ export namespace JSXInternal { wmode?: Signalish; } - interface OlHTMLAttributes extends HTMLAttributes { + interface OlHTMLAttributes + extends HTMLAttributes { reversed?: Signalish; start?: Signalish; type?: Signalish<'1' | 'a' | 'A' | 'i' | 'I' | undefined>; @@ -2040,7 +2047,8 @@ export namespace JSXInternal { width?: Signalish; } - interface TdHTMLAttributes extends HTMLAttributes { + interface TdHTMLAttributes + extends HTMLAttributes { align?: Signalish< 'left' | 'center' | 'right' | 'justify' | 'char' | undefined >; @@ -2079,7 +2087,8 @@ export namespace JSXInternal { onChange?: GenericEventHandler | undefined; } - interface ThHTMLAttributes extends HTMLAttributes { + interface ThHTMLAttributes + extends HTMLAttributes { align?: Signalish< 'left' | 'center' | 'right' | 'justify' | 'char' | undefined >; From 32ebe36589bec8978cd5db26c5fce30d0c61bdad Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Thu, 12 Dec 2024 05:58:37 -0600 Subject: [PATCH 3/4] test: Add simple test case for `h` & `createElement` --- test/ts/preact.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index ba617452de..437b0032b6 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -383,6 +383,10 @@ h('form', { onSubmit: onSubmit }); h('option', { value: 'foo' }); createElement('option', { value: 'foo' }); +// Should default to correct event target element for the attribute interface +h('input', { onClick: e => e.currentTarget.capture }); +createElement('input', { onClick: e => e.currentTarget.capture }); + function Checkbox({ onChange }: JSX.HTMLAttributes) { function handleChange( this: void, From 779f4a276ce2ede5def16610cb7eb528c5293e63 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Sun, 15 Dec 2024 11:33:55 -0600 Subject: [PATCH 4/4] test: Add simple test case for jsx --- test/ts/preact.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ts/preact.tsx b/test/ts/preact.tsx index 437b0032b6..0272fc3bef 100644 --- a/test/ts/preact.tsx +++ b/test/ts/preact.tsx @@ -386,6 +386,7 @@ createElement('option', { value: 'foo' }); // Should default to correct event target element for the attribute interface h('input', { onClick: e => e.currentTarget.capture }); createElement('input', { onClick: e => e.currentTarget.capture }); + e.currentTarget.capture} />; function Checkbox({ onChange }: JSX.HTMLAttributes) { function handleChange(