diff --git a/packages/jsx/src/index.ts b/packages/jsx/src/index.ts index 8a752d8e4..54da0259d 100644 --- a/packages/jsx/src/index.ts +++ b/packages/jsx/src/index.ts @@ -73,16 +73,13 @@ export const reatomJsx = (ctx: Ctx) => { } else bindProps(element, attrs) } } else if (isAtom(val)) { - if (val.__reatom.isAction) { - ;(element as any)[key] = (...args: any) => - (val as Action)(ctx, ...args) - } else { - // TODO handle unsubscribe! - var un: undefined | Unsubscribe = ctx.subscribe(val, (val) => - !un || element.isConnected ? setProp(element, key, val) : un(), - ) - unlink(element, un) - } + // TODO handle unsubscribe! + var un: undefined | Unsubscribe = ctx.subscribe(val, (val) => + !un || element.isConnected ? setProp(element, key, val) : un(), + ) + unlink(element, un) + } else if (typeof val === 'function') { + ;(element as any)[key] = (event: any) => val(ctx, event) } else setProp(element, key, val) } } diff --git a/packages/jsx/src/jsx.d.ts b/packages/jsx/src/jsx.d.ts index fdcf735ef..6ee7e66bc 100644 --- a/packages/jsx/src/jsx.d.ts +++ b/packages/jsx/src/jsx.d.ts @@ -2,7 +2,7 @@ * stolen from https://github.dev/solidjs/solid/blob/49793e9452ecd034d4d2ef5f95108f5d2ff4134a/packages/solid/h/jsx-runtime/src/jsx.d.ts */ -import { Action, Atom, AtomMaybe } from '@reatom/core' +import { Action, Atom, AtomMaybe, AtomProto, Ctx } from '@reatom/core' import * as csstype from 'csstype' export namespace JSX { @@ -25,18 +25,14 @@ export namespace JSX { interface ElementChildrenAttribute { children: {} } - type BoundEventHandler = Action< - [ - E & { - currentTarget: T - target: globalThis.Element - }, - ], - void - > - type EventHandlerUnion = BoundEventHandler + + type EventHandler = ( + ctx: Ctx, + event: E & { currentTarget: T; target: Element }, + ) => void + interface IntrinsicAttributes { - ref?: unknown | ((e: unknown) => void) + // ref?: unknown | ((e: unknown) => void) } // interface CustomAttributes { // ref?: T | ((el: T) => void) @@ -100,106 +96,106 @@ export namespace JSX { OnAttributes, OnCaptureAttributes, */ extends CustomEventHandlers { - $attrs?: AtomMaybe + $props?: this | Atom | Array | Array> children?: Element innerHTML?: string innerText?: string | number textContent?: string | number [field: `field:${string}`]: any - oncopy?: EventHandlerUnion - oncut?: EventHandlerUnion - onpaste?: EventHandlerUnion - oncompositionend?: EventHandlerUnion - oncompositionstart?: EventHandlerUnion - oncompositionupdate?: EventHandlerUnion - onfocusout?: EventHandlerUnion - onfocusin?: EventHandlerUnion - onencrypted?: EventHandlerUnion - ondragexit?: EventHandlerUnion + oncopy?: EventHandler + oncut?: EventHandler + onpaste?: EventHandler + oncompositionend?: EventHandler + oncompositionstart?: EventHandler + oncompositionupdate?: EventHandler + onfocusout?: EventHandler + onfocusin?: EventHandler + onencrypted?: EventHandler + ondragexit?: EventHandler } /** * @type {GlobalEventHandlers} */ interface CustomEventHandlers { - onabort?: EventHandlerUnion - onanimationend?: EventHandlerUnion - onanimationiteration?: EventHandlerUnion - onanimationstart?: EventHandlerUnion - onauxclick?: EventHandlerUnion - onbeforeinput?: EventHandlerUnion - onblur?: EventHandlerUnion - oncanplay?: EventHandlerUnion - oncanplaythrough?: EventHandlerUnion - onchange?: EventHandlerUnion - onclick?: EventHandlerUnion - oncontextmenu?: EventHandlerUnion - ondblclick?: EventHandlerUnion - ondrag?: EventHandlerUnion - ondragend?: EventHandlerUnion - ondragenter?: EventHandlerUnion - ondragleave?: EventHandlerUnion - ondragover?: EventHandlerUnion - ondragstart?: EventHandlerUnion - ondrop?: EventHandlerUnion - ondurationchange?: EventHandlerUnion - onemptied?: EventHandlerUnion - onended?: EventHandlerUnion - onerror?: EventHandlerUnion - onfocus?: EventHandlerUnion - ongotpointercapture?: EventHandlerUnion - oninput?: EventHandlerUnion - oninvalid?: EventHandlerUnion - onkeydown?: EventHandlerUnion - onkeypress?: EventHandlerUnion - onkeyup?: EventHandlerUnion - onload?: EventHandlerUnion - onloadeddata?: EventHandlerUnion - onloadedmetadata?: EventHandlerUnion - onloadstart?: EventHandlerUnion - onlostpointercapture?: EventHandlerUnion - onmousedown?: EventHandlerUnion - onmouseenter?: EventHandlerUnion - onmouseleave?: EventHandlerUnion - onmousemove?: EventHandlerUnion - onmouseout?: EventHandlerUnion - onmouseover?: EventHandlerUnion - onmouseup?: EventHandlerUnion - onpause?: EventHandlerUnion - onplay?: EventHandlerUnion - onplaying?: EventHandlerUnion - onpointercancel?: EventHandlerUnion - onpointerdown?: EventHandlerUnion - onpointerenter?: EventHandlerUnion - onpointerleave?: EventHandlerUnion - onpointermove?: EventHandlerUnion - onpointerout?: EventHandlerUnion - onpointerover?: EventHandlerUnion - onpointerup?: EventHandlerUnion - onprogress?: EventHandlerUnion - onratechange?: EventHandlerUnion - onreset?: EventHandlerUnion - onscroll?: EventHandlerUnion - onseeked?: EventHandlerUnion - onseeking?: EventHandlerUnion - onselect?: EventHandlerUnion - onstalled?: EventHandlerUnion - onsubmit?: EventHandlerUnion< + onabort?: EventHandler + onanimationend?: EventHandler + onanimationiteration?: EventHandler + onanimationstart?: EventHandler + onauxclick?: EventHandler + onbeforeinput?: EventHandler + onblur?: EventHandler + oncanplay?: EventHandler + oncanplaythrough?: EventHandler + onchange?: EventHandler + onclick?: EventHandler + oncontextmenu?: EventHandler + ondblclick?: EventHandler + ondrag?: EventHandler + ondragend?: EventHandler + ondragenter?: EventHandler + ondragleave?: EventHandler + ondragover?: EventHandler + ondragstart?: EventHandler + ondrop?: EventHandler + ondurationchange?: EventHandler + onemptied?: EventHandler + onended?: EventHandler + onerror?: EventHandler + onfocus?: EventHandler + ongotpointercapture?: EventHandler + oninput?: EventHandler + oninvalid?: EventHandler + onkeydown?: EventHandler + onkeypress?: EventHandler + onkeyup?: EventHandler + onload?: EventHandler + onloadeddata?: EventHandler + onloadedmetadata?: EventHandler + onloadstart?: EventHandler + onlostpointercapture?: EventHandler + onmousedown?: EventHandler + onmouseenter?: EventHandler + onmouseleave?: EventHandler + onmousemove?: EventHandler + onmouseout?: EventHandler + onmouseover?: EventHandler + onmouseup?: EventHandler + onpause?: EventHandler + onplay?: EventHandler + onplaying?: EventHandler + onpointercancel?: EventHandler + onpointerdown?: EventHandler + onpointerenter?: EventHandler + onpointerleave?: EventHandler + onpointermove?: EventHandler + onpointerout?: EventHandler + onpointerover?: EventHandler + onpointerup?: EventHandler + onprogress?: EventHandler + onratechange?: EventHandler + onreset?: EventHandler + onscroll?: EventHandler + onseeked?: EventHandler + onseeking?: EventHandler + onselect?: EventHandler + onstalled?: EventHandler + onsubmit?: EventHandler< T, Event & { submitter: HTMLElement } > - onsuspend?: EventHandlerUnion - ontimeupdate?: EventHandlerUnion - ontouchcancel?: EventHandlerUnion - ontouchend?: EventHandlerUnion - ontouchmove?: EventHandlerUnion - ontouchstart?: EventHandlerUnion - ontransitionend?: EventHandlerUnion - onvolumechange?: EventHandlerUnion - onwaiting?: EventHandlerUnion - onwheel?: EventHandlerUnion + onsuspend?: EventHandler + ontimeupdate?: EventHandler + ontouchcancel?: EventHandler + ontouchend?: EventHandler + ontouchmove?: EventHandler + ontouchstart?: EventHandler + ontransitionend?: EventHandler + onvolumechange?: EventHandler + onwaiting?: EventHandler + onwheel?: EventHandler } interface CSSProperties extends csstype.PropertiesHyphen { @@ -677,8 +673,8 @@ export namespace JSX { } interface DetailsHtmlAttributes extends HTMLAttributes { open?: AtomMaybe - onToggle?: EventHandlerUnion - ontoggle?: EventHandlerUnion + onToggle?: EventHandler + ontoggle?: EventHandler } interface DialogHtmlAttributes extends HTMLAttributes { open?: AtomMaybe