@react5/dom-jsx 0.1.0 → 0.1.1

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,10 +28,31 @@ Intrinsic JSX tags become DOM elements. `class` sets `className`, `style` accept
28
28
  The public entry points are:
29
29
 
30
30
  ```ts
31
- import { jsx, jsxs, Fragment } from '@react5/dom-jsx/jsx-runtime'
31
+ import { createRef, jsx, jsxs, Fragment } from '@react5/dom-jsx'
32
32
  import { jsx, jsxs, jsxDEV, Fragment } from '@react5/dom-jsx/jsx-dev-runtime'
33
33
  ```
34
34
 
35
+ `@react5/dom-jsx/jsx-runtime` also re-exports the same names and is what the TypeScript/Vite JSX transform imports automatically; `@react5/dom-jsx` is the shorter path for importing helpers like `createRef` directly in your own code.
36
+
37
+ ### Refs
38
+
39
+ Capture the created DOM node without a later `querySelector` call using `createRef` or a callback ref:
40
+
41
+ ```tsx
42
+ import { createRef } from '@react5/dom-jsx'
43
+
44
+ const inputRef = createRef<HTMLInputElement>()
45
+ const form = (
46
+ <form>
47
+ <input class="action-form__input" ref={inputRef} />
48
+ </form>
49
+ ) as HTMLFormElement
50
+
51
+ inputRef.current // HTMLInputElement
52
+ ```
53
+
54
+ A callback ref (`ref={(el) => ...}`) is also supported and is invoked with the element once it's created.
55
+
35
56
  ## Development
36
57
 
37
58
  ```sh
@@ -0,0 +1 @@
1
+ export * from './jsx-runtime';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{Fragment as r,createRef as m,jsx as o,jsxs as t}from"./jsx-runtime.js";export{r as Fragment,m as createRef,o as jsx,t as jsxs};
@@ -15,10 +15,17 @@ export type EventProps<T extends HTMLElement> = {
15
15
  onKeyDown?: DOMEventHandler<T, KeyboardEvent>;
16
16
  onKeyUp?: DOMEventHandler<T, KeyboardEvent>;
17
17
  };
18
+ export type Ref<T> = {
19
+ current: T | null;
20
+ } | ((el: T) => void);
18
21
  export type ElementProps<T extends HTMLElement> = Partial<Omit<T, 'children' | 'style' | 'className'>> & EventProps<T> & {
19
22
  class?: string;
20
23
  style?: Partial<CSSStyleDeclaration>;
21
24
  children?: unknown;
25
+ ref?: Ref<T>;
26
+ };
27
+ export declare function createRef<T>(): {
28
+ current: T | null;
22
29
  };
23
30
  export declare namespace JSX {
24
31
  type Element = Node;
@@ -1 +1 @@
1
- function e(e,t,n){return function(e,t){const n=t??{};if("function"==typeof e)return e(n);const r=document.createElement(e);for(const[i,c]of Object.entries(n))if("children"!==i)if(i.startsWith("on")&&"function"==typeof c)r.addEventListener(i.slice(2).toLowerCase(),c);else if("class"!==i){if("style"===i&&c&&"object"==typeof c)Object.assign(r.style,c);else if(null!=c)if(i.includes("-"))r.setAttribute(i,String(c));else if(!1!==c){if(i in r)try{r[i]=c;continue}catch{}r.setAttribute(i,!0===c?"":String(c))}}else r.className=String(c??"");return i(r,n.children),r}(e,t)}var t=e;function n(e){const t=document.createDocumentFragment();return i(t,e.children),t}function i(e,t){if(Array.isArray(t))for(const n of t)i(e,n);else t instanceof Node?e.appendChild(t):null!=t&&!1!==t&&!0!==t&&e.appendChild(document.createTextNode(String(t)))}export{n as Fragment,e as jsx,t as jsxs};
1
+ function e(){return{current:null}}function t(e,t,n){return function(e,t){const n=t??{};if("function"==typeof e)return e(n);const r=document.createElement(e);for(const[i,o]of Object.entries(n))if("children"!==i&&"ref"!==i)if(i.startsWith("on")&&"function"==typeof o)r.addEventListener(i.slice(2).toLowerCase(),o);else if("class"!==i){if("style"===i&&o&&"object"==typeof o)Object.assign(r.style,o);else if(null!=o)if(i.includes("-"))r.setAttribute(i,String(o));else{if(i in r){if(!1===o)continue;try{r[i]=o;continue}catch{}}r.setAttribute(i,!0===o?"":String(o))}}else r.className=String(o??"");i(r,n.children);const c=n.ref;"function"==typeof c?c(r):c&&(c.current=r);return r}(e,t)}var n=t;function r(e){const t=document.createDocumentFragment();return i(t,e.children),t}function i(e,t){if(Array.isArray(t))for(const n of t)i(e,n);else t instanceof Node?e.appendChild(t):null!=t&&!1!==t&&!0!==t&&e.appendChild(document.createTextNode(String(t)))}export{r as Fragment,e as createRef,t as jsx,n as jsxs};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react5/dom-jsx",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "JSX runtime for vanilla TS/JS projects.",
5
5
  "keywords": [
6
6
  "JSX"
@@ -21,7 +21,13 @@
21
21
  "README.md",
22
22
  "LICENSE"
23
23
  ],
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
24
26
  "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ },
25
31
  "./jsx-runtime": {
26
32
  "types": "./dist/jsx-runtime.d.ts",
27
33
  "import": "./dist/jsx-runtime.js"