@nubbin/react 0.1.0-rc.6 → 0.1.0-rc.7
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 +1 -1
- package/dist/index.js +21 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface HoleContext {
|
|
|
32
32
|
nodeId: string;
|
|
33
33
|
block: string;
|
|
34
34
|
path: string;
|
|
35
|
-
/** `
|
|
35
|
+
/** `{ revalidate: n }` — exactly what compile wrote into the artifact. */
|
|
36
36
|
spec: FieldHintData;
|
|
37
37
|
}
|
|
38
38
|
/**
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,11 @@ function defineRegistry(registry) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// src/loadBlocks.ts
|
|
7
|
+
import { NubbinIssueCode, refuse } from "@nubbin/core";
|
|
7
8
|
async function loadBlocks(registry, names) {
|
|
8
9
|
const missing = names.filter((name) => registry[name] === void 0);
|
|
9
10
|
if (missing.length > 0) {
|
|
10
|
-
|
|
11
|
+
refuse(NubbinIssueCode.BlockNotLoaded, `registry has no importer for: ${missing.join(", ")}`);
|
|
11
12
|
}
|
|
12
13
|
const wanted = new Set(names);
|
|
13
14
|
const loaded = await Promise.all(
|
|
@@ -19,13 +20,19 @@ async function loadBlocks(registry, names) {
|
|
|
19
20
|
// src/Renderer.ts
|
|
20
21
|
import { createElement, Fragment } from "react";
|
|
21
22
|
|
|
23
|
+
// src/renderNode.ts
|
|
24
|
+
import { NubbinIssueCode as NubbinIssueCode4, refuse as refuse4 } from "@nubbin/core";
|
|
25
|
+
|
|
22
26
|
// src/invokeBlock.ts
|
|
27
|
+
import { NubbinIssueCode as NubbinIssueCode2, refuse as refuse2 } from "@nubbin/core";
|
|
23
28
|
import { cloneElement, isValidElement } from "react";
|
|
24
29
|
async function invokeBlock(component, props, node) {
|
|
25
30
|
const rendered = await component(props);
|
|
26
31
|
if (!isValidElement(rendered) || typeof rendered.type !== "string") {
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
refuse2(
|
|
33
|
+
NubbinIssueCode2.NotOneHostElement,
|
|
34
|
+
`block "${node.block}" (node ${node.id}) must render exactly one root HTML element`,
|
|
35
|
+
node.id
|
|
29
36
|
);
|
|
30
37
|
}
|
|
31
38
|
return cloneElement(rendered, { "data-nubbin-node": node.id, key: node.id });
|
|
@@ -42,14 +49,18 @@ async function renderSlots(slots, renderChild) {
|
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
// src/resolveNodeHoles.ts
|
|
45
|
-
import { setAtPath } from "@nubbin/core";
|
|
52
|
+
import { NubbinIssueCode as NubbinIssueCode3, refuse as refuse3, setAtPath } from "@nubbin/core";
|
|
46
53
|
async function resolveNodeHoles(node, route, resolveHole) {
|
|
47
54
|
const holes = Object.entries(node.holes ?? {});
|
|
48
55
|
if (holes.length === 0) {
|
|
49
56
|
return node.props;
|
|
50
57
|
}
|
|
51
58
|
if (!resolveHole) {
|
|
52
|
-
|
|
59
|
+
refuse3(
|
|
60
|
+
NubbinIssueCode3.NoHoleResolver,
|
|
61
|
+
`node ${node.id} (${node.block}) declares holes but no resolveHole was given`,
|
|
62
|
+
node.id
|
|
63
|
+
);
|
|
53
64
|
}
|
|
54
65
|
let props = { ...node.props };
|
|
55
66
|
for (const [path, spec] of holes) {
|
|
@@ -63,7 +74,11 @@ async function resolveNodeHoles(node, route, resolveHole) {
|
|
|
63
74
|
async function renderNode(node, context) {
|
|
64
75
|
const component = context.blocks[node.block];
|
|
65
76
|
if (component === void 0) {
|
|
66
|
-
|
|
77
|
+
refuse4(
|
|
78
|
+
NubbinIssueCode4.BlockNotLoaded,
|
|
79
|
+
`artifact for ${context.route} names "${node.block}" but it was not loaded`,
|
|
80
|
+
node.id
|
|
81
|
+
);
|
|
67
82
|
}
|
|
68
83
|
const props = await resolveNodeHoles(node, context.route, context.resolveHole);
|
|
69
84
|
const slotProps = await renderSlots(node.slots, (child) => renderNode(child, context));
|
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.7",
|
|
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.7"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=19.0.0"
|