@nubbin/react 0.1.0-rc.4 → 0.1.0-rc.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/dist/index.js +8 -19
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -17,14 +17,16 @@ async function loadBlocks(registry, names) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// src/Renderer.ts
|
|
20
|
-
import { createElement, Fragment
|
|
20
|
+
import { createElement, Fragment } from "react";
|
|
21
21
|
|
|
22
22
|
// src/invokeBlock.ts
|
|
23
|
-
import { cloneElement,
|
|
23
|
+
import { cloneElement, isValidElement } from "react";
|
|
24
24
|
async function invokeBlock(component, props, node) {
|
|
25
25
|
const rendered = await component(props);
|
|
26
|
-
if (!isValidElement(rendered) || rendered.type
|
|
27
|
-
throw new Error(
|
|
26
|
+
if (!isValidElement(rendered) || typeof rendered.type !== "string") {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`block "${node.block}" (node ${node.id}) must render exactly one root HTML element`
|
|
29
|
+
);
|
|
28
30
|
}
|
|
29
31
|
return cloneElement(rendered, { "data-nubbin-node": node.id, key: node.id });
|
|
30
32
|
}
|
|
@@ -39,21 +41,8 @@ async function renderSlots(slots, renderChild) {
|
|
|
39
41
|
return Object.fromEntries(rendered);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
// src/setAtPath.ts
|
|
43
|
-
function setAtPath(target, path, value) {
|
|
44
|
-
const [head, ...rest] = path.split(".");
|
|
45
|
-
if (head === void 0 || head === "" || head.includes("[]")) {
|
|
46
|
-
throw new Error(`hole path "${path}" is not addressable`);
|
|
47
|
-
}
|
|
48
|
-
if (rest.length === 0) {
|
|
49
|
-
return { ...target, [head]: value };
|
|
50
|
-
}
|
|
51
|
-
const child = target[head];
|
|
52
|
-
const base = typeof child === "object" && child !== null ? child : {};
|
|
53
|
-
return { ...target, [head]: setAtPath(base, rest.join("."), value) };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
44
|
// src/resolveNodeHoles.ts
|
|
45
|
+
import { setAtPath } from "@nubbin/core";
|
|
57
46
|
async function resolveNodeHoles(node, route, resolveHole) {
|
|
58
47
|
const holes = Object.entries(node.holes ?? {});
|
|
59
48
|
if (holes.length === 0) {
|
|
@@ -90,7 +79,7 @@ async function Renderer({
|
|
|
90
79
|
const blocks = await loadBlocks(registry, Object.keys(artifact.blockVersions));
|
|
91
80
|
const context = { route: artifact.route, blocks, resolveHole };
|
|
92
81
|
const children = await Promise.all(artifact.tree.map((node) => renderNode(node, context)));
|
|
93
|
-
return createElement(
|
|
82
|
+
return createElement(Fragment, null, children);
|
|
94
83
|
}
|
|
95
84
|
export {
|
|
96
85
|
Renderer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubbin/react",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.5",
|
|
4
4
|
"description": "The React render path for Nubbin: render a compiled artifact against a block registry.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nubbin",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nubbin/core": "0.1.0-rc.
|
|
35
|
+
"@nubbin/core": "0.1.0-rc.5"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=19.0.0"
|