@react5/dom-jsx 0.1.3 → 0.1.5

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
@@ -24,22 +24,33 @@ The runtime also works with Vite. Vite discovers the package's ESM `jsx-runtime`
24
24
  Function components may return DOM nodes with an attached API:
25
25
 
26
26
  ```tsx
27
- type ModalContext = { open?(): void; close?(): void }
27
+ type ModalContext = { open(): void; close(): void }
28
28
 
29
29
  function Modal() {
30
- const element = <dialog />
31
- return element as HTMLDialogElement & { context: ModalContext }
30
+ const element = <dialog /> as HTMLDialogElement
31
+ const context: ModalContext = {
32
+ open: () => element.showModal(),
33
+ close: () => element.close()
34
+ }
35
+
36
+ return Object.assign(element, { context }) satisfies
37
+ HTMLDialogElement & { context: ModalContext }
32
38
  }
33
39
 
34
40
  const modal = <Modal />
35
- modal.context.open?.()
41
+ modal.context?.open()
36
42
  ```
37
43
 
38
44
  TypeScript represents all JSX expressions with one `JSX.Element` type, so it
39
45
  cannot preserve the exact intersection type of an individual component in
40
- TSX. The library's JSX element type therefore permits component-specific
41
- properties. Calling the component directly, or calling `jsx(Modal, null)`,
42
- preserves its exact return type.
46
+ TSX. The library's JSX element type therefore allows an optional `context`
47
+ property, typed loosely as `Record<string, any>`, on every JSX result.
48
+ Accessing any other property directly on the node (e.g. a typo'd DOM
49
+ property) is still checked normally. `context` is optional because plain
50
+ intrinsic elements don't have one, so calling through it via `<Tag />` JSX
51
+ syntax needs `?.`. To get the component's exact, non-optional `context`
52
+ type instead, call the component directly or call `jsx(Modal, null)` /
53
+ `jsxDEV(Modal, null)`.
43
54
 
44
55
  ## Runtime behavior
45
56
 
@@ -26,7 +26,9 @@ export declare function createRef<T>(): {
26
26
  current: T | null;
27
27
  };
28
28
  export declare namespace JSX {
29
- type Element = Node & Record<string, any>;
29
+ type Element = Node & {
30
+ context?: Record<string, any>;
31
+ };
30
32
  type IntrinsicElements = {
31
33
  [K in keyof HTMLElementTagNameMap]: ElementProps<HTMLElementTagNameMap[K]>;
32
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react5/dom-jsx",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "JSX runtime for vanilla TS/JS projects.",
5
5
  "keywords": [
6
6
  "JSX"