@21stware/rpui-react 0.1.0
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/dist/index.d.ts +15 -0
- package/dist/index.js +47 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface RpmlRendererProps {
|
|
2
|
+
/** RPML source text. Updates trigger incremental re-render with scroll preserved. */
|
|
3
|
+
rpml: string;
|
|
4
|
+
/** Debounce delay in ms before re-rendering (recommended for live editors). Default: 0. */
|
|
5
|
+
debounce?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
/** Called with an error message on parse failure, null when the error clears. */
|
|
9
|
+
onError?: (msg: string | null) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders RPML markup as a live Web Components prototype.
|
|
13
|
+
* Scroll position is preserved across incremental updates.
|
|
14
|
+
*/
|
|
15
|
+
export declare function RpmlRenderer({ rpml, debounce, className, style, onError }: RpmlRendererProps): import("react").JSX.Element;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { createDocRenderer, registerAll } from "@21stware/rpui";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/index.tsx
|
|
5
|
+
let _registered = false;
|
|
6
|
+
/**
|
|
7
|
+
* Renders RPML markup as a live Web Components prototype.
|
|
8
|
+
* Scroll position is preserved across incremental updates.
|
|
9
|
+
*/
|
|
10
|
+
function RpmlRenderer({ rpml, debounce = 0, className, style, onError }) {
|
|
11
|
+
const hostRef = useRef(null);
|
|
12
|
+
const rendererRef = useRef(null);
|
|
13
|
+
const onErrorRef = useRef(onError);
|
|
14
|
+
const timerRef = useRef(void 0);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
onErrorRef.current = onError;
|
|
17
|
+
}, [onError]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!_registered) {
|
|
20
|
+
registerAll();
|
|
21
|
+
_registered = true;
|
|
22
|
+
}
|
|
23
|
+
const renderer = createDocRenderer(hostRef.current, { onError: (msg) => onErrorRef.current?.(msg) });
|
|
24
|
+
rendererRef.current = renderer;
|
|
25
|
+
return () => {
|
|
26
|
+
renderer.destroy();
|
|
27
|
+
rendererRef.current = null;
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const renderer = rendererRef.current;
|
|
32
|
+
if (!renderer) return;
|
|
33
|
+
if (debounce > 0) {
|
|
34
|
+
clearTimeout(timerRef.current);
|
|
35
|
+
timerRef.current = setTimeout(() => renderer.render(rpml), debounce);
|
|
36
|
+
return () => clearTimeout(timerRef.current);
|
|
37
|
+
}
|
|
38
|
+
renderer.render(rpml);
|
|
39
|
+
}, [rpml, debounce]);
|
|
40
|
+
return /* @__PURE__ */ jsx("div", {
|
|
41
|
+
ref: hostRef,
|
|
42
|
+
className,
|
|
43
|
+
style
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { RpmlRenderer };
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@21stware/rpui-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React binding for the RPUI/RPML Web Components runtime — incremental, scroll-preserving RPML rendering",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
20
|
+
"build:js": "rolldown -c rolldown.config.js",
|
|
21
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
22
|
+
"build": "bun run clean && bun run typecheck && bun run build:js && bun run build:types",
|
|
23
|
+
"clean": "rm -rf dist && mkdir -p dist",
|
|
24
|
+
"release": "bun run build"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=18",
|
|
28
|
+
"react-dom": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@21stware/rpui": "workspace:*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^18.3.0",
|
|
35
|
+
"react": "^18.3.0",
|
|
36
|
+
"rolldown": "^1.0.0-beta.0",
|
|
37
|
+
"typescript": "^5.8.3"
|
|
38
|
+
}
|
|
39
|
+
}
|