@react5/dom-jsx 0.1.4 → 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
@@ -28,22 +28,29 @@ type ModalContext = { open(): void; close(): void }
28
28
 
29
29
  function Modal() {
30
30
  const element = <dialog /> as HTMLDialogElement
31
-
32
- return Object.assign(element, {
31
+ const context: ModalContext = {
33
32
  open: () => element.showModal(),
34
33
  close: () => element.close()
35
- }) satisfies HTMLDialogElement & ModalContext
34
+ }
35
+
36
+ return Object.assign(element, { context }) satisfies
37
+ HTMLDialogElement & { context: ModalContext }
36
38
  }
37
39
 
38
40
  const modal = <Modal />
39
- modal.open()
41
+ modal.context?.open()
40
42
  ```
41
43
 
42
44
  TypeScript represents all JSX expressions with one `JSX.Element` type, so it
43
45
  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.
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)`.
47
54
 
48
55
  ## Runtime behavior
49
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.4",
3
+ "version": "0.1.5",
4
4
  "description": "JSX runtime for vanilla TS/JS projects.",
5
5
  "keywords": [
6
6
  "JSX"