@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 +22 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/jsx-runtime.d.ts +7 -0
- package/dist/jsx-runtime.js +1 -1
- package/package.json +7 -1
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
|
|
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
|
package/dist/index.d.ts
ADDED
|
@@ -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};
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -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;
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -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,
|
|
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.
|
|
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"
|