@storyblok/astro 10.1.0 → 10.2.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/dist/components/StoryblokRichText.astro +2 -3
- package/dist/components/richtext/RenderLinkGroup.astro +1 -1
- package/dist/components/richtext/RenderNode.astro +12 -6
- package/dist/components/richtext/RenderTextNodeWithMarks.astro +1 -1
- package/dist/index.js +20 -9
- package/dist/utils/richtext-helpers.d.ts +1 -0
- package/package.json +3 -3
|
@@ -6,9 +6,8 @@ interface Props extends SbAstroRichTextRenderContext {
|
|
|
6
6
|
document: SbRichTextInput;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const { document, components, optimizeImage } = Astro.props;
|
|
10
|
-
|
|
9
|
+
const { document, components, optimizeImage, data } = Astro.props;
|
|
11
10
|
const nodes = normalizeNodes(document);
|
|
12
11
|
---
|
|
13
12
|
|
|
14
|
-
<RenderChildren nodes={nodes} options={{ components, optimizeImage }} />
|
|
13
|
+
<RenderChildren nodes={nodes} options={{ components, optimizeImage, data }} />
|
|
@@ -19,16 +19,22 @@ interface Props {
|
|
|
19
19
|
}
|
|
20
20
|
const { node, options } = Astro.props;
|
|
21
21
|
const components = options.components;
|
|
22
|
-
const Custom = components
|
|
22
|
+
const Custom = components ? components[node.type] : undefined;
|
|
23
|
+
|
|
24
|
+
// When passing context to a custom component, exclude that component type
|
|
25
|
+
// to prevent infinite loops if the custom component uses StoryblokRichText internally
|
|
26
|
+
const contextForCustom = Custom
|
|
27
|
+
? { ...options, components: { ...components, [node.type]: undefined } }
|
|
28
|
+
: options;
|
|
23
29
|
---
|
|
24
30
|
|
|
25
31
|
{
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
<Custom {...node} context={options}>
|
|
30
|
-
{node.content && <RenderChildren nodes={node.content} options={options} />}
|
|
32
|
+
isValidAstroComponent(Custom) ? (
|
|
33
|
+
<Custom {...node} context={contextForCustom}>
|
|
34
|
+
{node.type !== 'text' && node.content && <RenderChildren nodes={node.content} options={options} />}
|
|
31
35
|
</Custom>
|
|
36
|
+
) : node.type === 'text' ? (
|
|
37
|
+
<RenderTextNodeWithMarks node={node} marks={node.marks} options={options} />
|
|
32
38
|
) : node.type === 'image' ? (
|
|
33
39
|
<RenderImage node={node} options={options} />
|
|
34
40
|
) : node.type === 'blok' ? (
|
|
@@ -23,7 +23,7 @@ const MarkComponent = mark && components ? components[mark.type] : undefined;
|
|
|
23
23
|
reversedMarks.length === 0 ? (
|
|
24
24
|
node.text
|
|
25
25
|
) : isValidAstroComponent(MarkComponent) ? (
|
|
26
|
-
<MarkComponent {...mark}>
|
|
26
|
+
<MarkComponent {...mark} context={options}>
|
|
27
27
|
<Astro.self node={node} marks={rest} options={options} />
|
|
28
28
|
</MarkComponent>
|
|
29
29
|
) : (
|
package/dist/index.js
CHANGED
|
@@ -952,13 +952,22 @@ function dt(e, t) {
|
|
|
952
952
|
return n?.length ? pt(n, t) : "";
|
|
953
953
|
}
|
|
954
954
|
function q(e, t) {
|
|
955
|
+
let n = e.type !== "text" && e.content ? pt(e.content, t) : "", r = t?.renderers?.[e.type];
|
|
956
|
+
if (r) {
|
|
957
|
+
let i = t?.renderers?.[e.type] ? {
|
|
958
|
+
...t,
|
|
959
|
+
renderers: {
|
|
960
|
+
...t.renderers,
|
|
961
|
+
[e.type]: void 0
|
|
962
|
+
}
|
|
963
|
+
} : t;
|
|
964
|
+
return r({
|
|
965
|
+
...e,
|
|
966
|
+
children: n,
|
|
967
|
+
context: i
|
|
968
|
+
});
|
|
969
|
+
}
|
|
955
970
|
if (e.type === "text") return mt(e, e.marks, t);
|
|
956
|
-
let n = e.content ? pt(e.content, t) : "", r = t?.renderers?.[e.type];
|
|
957
|
-
if (r) return r({
|
|
958
|
-
...e,
|
|
959
|
-
children: n,
|
|
960
|
-
context: t
|
|
961
|
-
});
|
|
962
971
|
if (e.type === "blok") return console.warn("\"blok\" nodes require a custom renderer in renderRichText."), "";
|
|
963
972
|
let i = G(e);
|
|
964
973
|
if (!i) return n;
|
|
@@ -1004,7 +1013,8 @@ function ht(e, t, n) {
|
|
|
1004
1013
|
let r = n?.renderers?.[t.type];
|
|
1005
1014
|
if (r) return r({
|
|
1006
1015
|
...t,
|
|
1007
|
-
children: e
|
|
1016
|
+
children: e,
|
|
1017
|
+
context: n
|
|
1008
1018
|
});
|
|
1009
1019
|
let i = G(t);
|
|
1010
1020
|
return i ? `<${i}${J(t.type, t.attrs)}>${e}</${i}>` : e;
|
|
@@ -1018,7 +1028,8 @@ function gt(e, t, n, r, i) {
|
|
|
1018
1028
|
let o = i?.renderers?.[r.type];
|
|
1019
1029
|
if (o) return o({
|
|
1020
1030
|
...r,
|
|
1021
|
-
children: a
|
|
1031
|
+
children: a,
|
|
1032
|
+
context: i
|
|
1022
1033
|
});
|
|
1023
1034
|
let s = G(r);
|
|
1024
1035
|
return s ? `<${s}${J(r.type, r.attrs)}>${a}</${s}>` : a;
|
|
@@ -1614,7 +1625,7 @@ var Ht = class {
|
|
|
1614
1625
|
}
|
|
1615
1626
|
return { storyblokApi: new Ut(t) };
|
|
1616
1627
|
}, Jt = (e) => {
|
|
1617
|
-
if (typeof e != "object" || typeof e._editable
|
|
1628
|
+
if (typeof e != "object" || typeof e._editable != "string") return {};
|
|
1618
1629
|
try {
|
|
1619
1630
|
let t = JSON.parse(e._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
1620
1631
|
return t ? {
|
|
@@ -6,6 +6,7 @@ export type SbAstroRichTextComponentMap = {
|
|
|
6
6
|
export interface SbAstroRichTextRenderContext {
|
|
7
7
|
optimizeImage?: boolean | SbRichTextImageOptions;
|
|
8
8
|
components?: SbAstroRichTextComponentMap;
|
|
9
|
+
data?: unknown;
|
|
9
10
|
}
|
|
10
11
|
export type SbAstroRichTextProps<T extends SbRichTextElement> = SbRichTextElementByType<SbAstroRichTextRenderContext>[T];
|
|
11
12
|
export declare function isValidAstroComponent(component: unknown): component is AstroComponentFactory;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "10.1
|
|
4
|
+
"version": "10.2.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
7
7
|
"author": "Storyblok",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"camelcase": "^8.0.0",
|
|
53
53
|
"morphdom": "^2.7.8",
|
|
54
|
-
"@storyblok/
|
|
55
|
-
"@storyblok/
|
|
54
|
+
"@storyblok/js": "6.2.1",
|
|
55
|
+
"@storyblok/richtext": "5.2.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@cypress/vite-dev-server": "^6.0.3",
|