@react5/dom-jsx 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,6 +21,30 @@ For TypeScript automatic JSX, set these compiler options:
21
21
 
22
22
  The runtime also works with Vite. Vite discovers the package's ESM `jsx-runtime` and `jsx-dev-runtime` exports automatically when compiling TSX.
23
23
 
24
+ Function components may return DOM nodes with an attached API:
25
+
26
+ ```tsx
27
+ type ModalContext = { open(): void; close(): void }
28
+
29
+ function Modal() {
30
+ const element = <dialog /> as HTMLDialogElement
31
+
32
+ return Object.assign(element, {
33
+ open: () => element.showModal(),
34
+ close: () => element.close()
35
+ }) satisfies HTMLDialogElement & ModalContext
36
+ }
37
+
38
+ const modal = <Modal />
39
+ modal.open()
40
+ ```
41
+
42
+ TypeScript represents all JSX expressions with one `JSX.Element` type, so it
43
+ cannot preserve the exact intersection type of an individual component in
44
+ TSX. The library's JSX element type therefore permits component-specific
45
+ properties. Calling the component directly, or calling `jsx(Modal, null)`,
46
+ preserves its exact return type.
47
+
24
48
  ## Runtime behavior
25
49
 
26
50
  Intrinsic JSX tags become DOM elements. `class` sets `className`, `style` accepts a style object, DOM properties are assigned when available, boolean attributes use presence semantics, and `onClick`-style function props become event listeners. Text, nested nodes, arrays, fragments, and function components are supported; `null`, `undefined`, and boolean children are ignored.
@@ -2,18 +2,16 @@ export type Child = Node | string | number | boolean | null | undefined | Child[
2
2
  export type Props = Record<string, unknown> & {
3
3
  children?: Child | Child[];
4
4
  };
5
- export type Component<P = Props> = (props: P) => Node;
5
+ export type Component<P = Props, R extends Node = Node> = (props: P) => R;
6
6
  export type DOMEventHandler<T extends EventTarget, E extends Event> = (event: E & {
7
7
  currentTarget: T;
8
8
  }) => void;
9
- export type EventProps<T extends HTMLElement> = {
10
- onClick?: DOMEventHandler<T, MouseEvent>;
9
+ type MappedEventProps<T extends HTMLElement> = {
10
+ [K in keyof HTMLElementEventMap as `on${Capitalize<K & string>}`]?: DOMEventHandler<T, HTMLElementEventMap[K]>;
11
+ };
12
+ export type EventProps<T extends HTMLElement> = Omit<MappedEventProps<T>, 'onInput' | 'onDblclick'> & {
11
13
  onInput?: DOMEventHandler<T, InputEvent>;
12
- onChange?: DOMEventHandler<T, Event>;
13
- onFocus?: DOMEventHandler<T, FocusEvent>;
14
- onBlur?: DOMEventHandler<T, FocusEvent>;
15
- onKeyDown?: DOMEventHandler<T, KeyboardEvent>;
16
- onKeyUp?: DOMEventHandler<T, KeyboardEvent>;
14
+ onDblClick?: DOMEventHandler<T, MouseEvent>;
17
15
  };
18
16
  export type Ref<T> = {
19
17
  current: T | null;
@@ -28,15 +26,13 @@ export declare function createRef<T>(): {
28
26
  current: T | null;
29
27
  };
30
28
  export declare namespace JSX {
31
- type Element = Node;
29
+ type Element = Node & Record<string, any>;
32
30
  type IntrinsicElements = {
33
31
  [K in keyof HTMLElementTagNameMap]: ElementProps<HTMLElementTagNameMap[K]>;
34
- } & {
35
- form: ElementProps<HTMLFormElement> & {
36
- onSubmit?: DOMEventHandler<HTMLFormElement, SubmitEvent>;
37
- };
38
32
  };
39
33
  }
40
- export declare function jsx(tag: string | ((props: any) => Node), props: Props | null, _key?: string | number): Node;
34
+ export declare function jsx<R extends Node>(tag: (props: any) => R, props: Props | null, _key?: string | number): R;
35
+ export declare function jsx(tag: string, props: Props | null, _key?: string | number): Node;
41
36
  export declare const jsxs: typeof jsx;
42
37
  export declare function Fragment(props: Props): DocumentFragment;
38
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react5/dom-jsx",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "JSX runtime for vanilla TS/JS projects.",
5
5
  "keywords": [
6
6
  "JSX"