@react5/dom-jsx 0.1.8 → 0.1.10
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 +12 -2
- package/dist/index.js +1 -1
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ type instead, call the component directly or call `jsx(Modal, null)` /
|
|
|
54
54
|
|
|
55
55
|
## Runtime behavior
|
|
56
56
|
|
|
57
|
-
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.
|
|
57
|
+
Intrinsic JSX tags become DOM elements. Prefer `className` over `class`, while both supported. `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.
|
|
58
58
|
|
|
59
59
|
Compound event props require camel casing, such as `onMouseEnter`, `onMouseLeave`,
|
|
60
60
|
`onFocusIn`, `onFocusOut`, `onKeyDown`, and `onAnimationEnd`.
|
|
@@ -69,6 +69,16 @@ import { jsx, jsxs, jsxDEV, Fragment } from '@react5/dom-jsx/jsx-dev-runtime'
|
|
|
69
69
|
|
|
70
70
|
`@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.
|
|
71
71
|
|
|
72
|
+
### SVG
|
|
73
|
+
|
|
74
|
+
Use `svge()` function to load raw svg. With vite use raw import:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import iconSvg from "./assets/icon.svg?raw"
|
|
78
|
+
const icon = svge(iconSvg)
|
|
79
|
+
<div>{icon}</div>
|
|
80
|
+
```
|
|
81
|
+
|
|
72
82
|
### Refs
|
|
73
83
|
|
|
74
84
|
Capture the created DOM node without a later `querySelector` call using `createRef` or a callback ref:
|
|
@@ -79,7 +89,7 @@ import { createRef } from '@react5/dom-jsx'
|
|
|
79
89
|
const inputRef = createRef<HTMLInputElement>()
|
|
80
90
|
const form = (
|
|
81
91
|
<form>
|
|
82
|
-
<input
|
|
92
|
+
<input className="action-form__input" ref={inputRef} />
|
|
83
93
|
</form>
|
|
84
94
|
) as HTMLFormElement
|
|
85
95
|
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Fragment as r,createContext as m,createRef as o,dispose as t,jsx as e,jsxs as i,onCleanup as j,onDispose as p,useContext as
|
|
1
|
+
import{Fragment as r,createContext as m,createRef as o,dispose as t,jsx as e,jsxs as i,onCleanup as j,onDispose as p,svge as s,useContext as x}from"./jsx-runtime.js";export{r as Fragment,m as createContext,o as createRef,t as dispose,e as jsx,i as jsxs,j as onCleanup,p as onDispose,s as svge,x as useContext};
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type Ref<T> = {
|
|
|
22
22
|
} | ((el: T) => void);
|
|
23
23
|
export type ElementProps<T extends HTMLElement> = Partial<Omit<T, 'children' | 'style' | 'className'>> & EventProps<T> & {
|
|
24
24
|
class?: string;
|
|
25
|
+
className?: string;
|
|
25
26
|
style?: Partial<CSSStyleDeclaration>;
|
|
26
27
|
children?: unknown;
|
|
27
28
|
ref?: Ref<T>;
|
|
@@ -53,4 +54,5 @@ export declare function jsx<P, R extends Node>(tag: (props: P) => R, props: {} e
|
|
|
53
54
|
export declare function jsx(tag: string, props: Props | null, _key?: string | number): Node;
|
|
54
55
|
export declare const jsxs: typeof jsx;
|
|
55
56
|
export declare function Fragment(props: Props): DocumentFragment;
|
|
57
|
+
export declare function svge(markup: string): SVGSVGElement;
|
|
56
58
|
export {};
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(){return{current:null}}var t=/* @__PURE__ */new WeakMap;function n(e){const n=[],
|
|
1
|
+
function e(){return{current:null}}var t=/* @__PURE__ */new WeakMap;function n(e){const n=[],r={Provider({value:e,children:t}){if("function"!=typeof t)throw new TypeError("Context Provider expects a single function child: {() => ...}");n.push(e);try{const e=t();if(e instanceof Node)return e;const n=document.createDocumentFragment();return y(n,e),n}finally{n.pop()}}};return t.set(r,{defaultValue:e,stack:n}),r}function r(e){const n=t.get(e);if(!n)throw new TypeError("useContext expects a context created by createContext");const{defaultValue:r,stack:o}=n;return o.length>0?o[o.length-1]:r}var o=/* @__PURE__ */new WeakMap,c=[];function s(e,t){const n=o.get(e);n?n.push(t):o.set(e,[t])}function i(e,t){s(e,()=>t())}function a(e){const t=c[c.length-1];if(!t)throw new Error("onCleanup must be called while a component is rendering; use onDispose(node, fn) instead");t.cleanups.push(e)}function u(e){const t=[];if(f(e,t),1===t.length)throw t[0];if(t.length>1)throw new AggregateError(t,"Multiple cleanups failed during dispose")}function f(e,t){for(const o of Array.from(e.childNodes))f(o,t);const n=o.get(e);if(n){o.delete(e);for(let e=n.length-1;e>=0;e--)try{n[e](t)}catch(r){t.push(r)}}}function l(e,t){for(let r=e.length-1;r>=0;r--)try{e[r]()}catch(n){t.push(n)}}function d(e,t){if(e instanceof Node)t.push(e);else if(Array.isArray(e))for(const n of e)d(n,t)}function p(e,t){const n={cleanups:[],rendered:[]};let r;c.push(n);try{r=e(t)}catch(a){throw c.pop(),function(e,t){const n=[],r=[...e.rendered];for(const o of Object.values(t))d(o,r);for(const o of r)o.isConnected||f(o,n);l(e.cleanups,n)}(n,t),a}c.pop();let o=[r];if(r instanceof DocumentFragment&&(!r.firstChild&&n.cleanups.length>0&&r.appendChild(document.createComment("")),o=Array.from(r.childNodes)),n.cleanups.length>0)if(1===o.length)for(const c of n.cleanups)i(o[0],c);else{let e=o.length;for(const t of o)s(t,t=>{0===--e&&l(n.cleanups,t)})}return c[c.length-1]?.rendered.push(...o),r}function h(e,t,n){return function(e,t){const n=t??{};if("function"==typeof e)return p(e,n);const r=document.createElement(e);void 0===n.class&&void 0===n.className||(r.className=String(n.className??n.class??""));for(const[c,s]of Object.entries(n))if("children"!==c&&"ref"!==c)if(c.startsWith("on")&&"function"==typeof s)r.addEventListener(c.slice(2).toLowerCase(),s);else if("class"!==c&&"className"!==c)if("style"===c&&s&&"object"==typeof s)Object.assign(r.style,s);else if(null!=s)if(c.includes("-"))r.setAttribute(c,String(s));else{if(c in r){if(!1===s)continue;try{r[c]=s;continue}catch{}}r.setAttribute(c,!0===s?"":String(s))}y(r,n.children);const o=n.ref;"function"==typeof o?o(r):o&&(o.current=r);return r}(e,t)}var g=h;function m(e){const t=document.createDocumentFragment();return y(t,e.children),t}function y(e,t){if(Array.isArray(t))for(const n of t)y(e,n);else t instanceof Node?e.appendChild(t):null!=t&&!1!==t&&!0!==t&&e.appendChild(document.createTextNode(String(t)))}function w(e){const t=(new DOMParser).parseFromString(e,"image/svg+xml").documentElement;if("parsererror"===t.nodeName||"http://www.w3.org/2000/svg"!==t.namespaceURI)throw new Error(`svge: failed to parse SVG markup: ${e}`);const n=document.importNode(t,!0);return n.setAttribute("aria-hidden","true"),n.setAttribute("focusable","false"),n}export{m as Fragment,n as createContext,e as createRef,u as dispose,h as jsx,g as jsxs,a as onCleanup,i as onDispose,w as svge,r as useContext};
|