@storyblok/astro 7.3.9 → 8.0.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/types.d.ts CHANGED
@@ -8,4 +8,4 @@ ISbStoriesParams, // previously StoriesParams
8
8
  ISbStory, // previously Story
9
9
  ISbStoryData, // previously StoryData
10
10
  ISbStoryParams, // previously StoryParams
11
- MarkTypes, SbBlokData, SbBlokKeyDataTypes, SbPluginFactory, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, StoryblokRichTextDocumentNode, StoryblokRichTextImageOptimizationOptions, StoryblokRichTextNode, StoryblokRichTextNodeResolver, StoryblokRichTextNodeTypes, StoryblokRichTextOptions, StoryblokRichTextResolvers, TextTypes, } from '@storyblok/js';
11
+ MarkTypes, SbBlokData, SbBlokKeyDataTypes, SbPluginFactory, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, StoryblokRichTextDocumentNode, StoryblokRichTextImageOptimizationOptions, StoryblokRichTextNode, StoryblokRichTextNodeTypes, StoryblokRichTextOptions, TextTypes, } from '@storyblok/js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
3
  "type": "module",
4
- "version": "7.3.9",
4
+ "version": "8.0.0",
5
5
  "private": false,
6
6
  "description": "Official Astro integration for the Storyblok Headless CMS",
7
7
  "author": "Storyblok",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "camelcase": "^8.0.0",
56
- "@storyblok/js": "4.4.5"
56
+ "@storyblok/js": "5.0.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@cypress/vite-dev-server": "^6.0.3",
@@ -74,7 +74,7 @@
74
74
  "vite-plugin-dts": "^4.5.3",
75
75
  "vite-plugin-static-copy": "^2.2.0",
76
76
  "vitest": "^3.1.3",
77
- "@storyblok/eslint-config": "0.4.1"
77
+ "@storyblok/eslint-config": "0.4.2"
78
78
  },
79
79
  "eslintConfig": {
80
80
  "env": {
@@ -1,103 +0,0 @@
1
- import {
2
- richTextResolver,
3
- type StoryblokRichTextNode,
4
- type StoryblokRichTextResolvers,
5
- } from '@storyblok/js';
6
- import { experimental_AstroContainer } from 'astro/container';
7
- import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
8
-
9
- // Lazily initialized Astro container (for rendering blok components)
10
- let container: null | experimental_AstroContainer = null;
11
-
12
- /**
13
- * @experimental Converts a Storyblok RichText field into an HTML string.
14
- *
15
- * This API is still under development and may change in future releases.
16
- * It also relies on Astro’s experimental
17
- * [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
18
- *
19
- * @async
20
- * @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
21
- * @param {StoryblokRichTextResolvers} [customResolvers] - Optional custom resolvers
22
- * for customizing how specific nodes or marks are transformed into HTML.
23
- * @returns {Promise<string>} A promise that resolves to the HTML string representation
24
- * of the provided RichText content.
25
- *
26
- * @example
27
- * ```astro
28
- * ---
29
- * import { richTextToHTML } from '@storyblok/astro/client';
30
- * const { blok } = Astro.props;
31
- * const renderedRichText = await richTextToHTML(blok.text);
32
- * ---
33
- *
34
- * <div set:html={renderedRichText} />
35
- * ```
36
- */
37
- export const richTextToHTML = async (
38
- richTextField: StoryblokRichTextNode,
39
- customResolvers?: StoryblokRichTextResolvers,
40
- ): Promise<string> => {
41
- // Create Astro container only once
42
- if (!container) {
43
- container = await experimental_AstroContainer.create();
44
- }
45
-
46
- // Collect async render results keyed by placeholder ID
47
- const asyncReplacements: Promise<{ id: string; result: string }>[] = [];
48
- // Build the resolvers object
49
- const resolvers: StoryblokRichTextResolvers = {
50
- // Handle async components
51
- blok: (node) => {
52
- const componentBody = node.attrs?.body;
53
- if (!Array.isArray(componentBody)) {
54
- return '';
55
- }
56
-
57
- return componentBody
58
- .map((blok) => {
59
- if (!blok || typeof blok !== 'object' || !container) {
60
- return '';
61
- }
62
-
63
- // Generate unique placeholder ID
64
- const id = crypto.randomUUID();
65
- const placeholder = `<!--ASYNC-${id}-->`;
66
-
67
- // Queue async render
68
- const promise = container
69
- .renderToString(StoryblokComponent, {
70
- props: { blok },
71
- })
72
- .then(result => ({ id, result }))
73
- .catch((err) => {
74
- console.error('Component rendering failed:', err);
75
- return { id, result: '<!-- Component render error -->' };
76
- });
77
-
78
- asyncReplacements.push(promise);
79
- return placeholder;
80
- })
81
- .join('\n');
82
- },
83
-
84
- // Add custom resolvers if provided
85
- ...customResolvers,
86
- };
87
-
88
- const resolver = richTextResolver({ resolvers });
89
-
90
- let html = resolver.render(richTextField);
91
- // Wait for all async renders
92
- const results = await Promise.all(asyncReplacements);
93
- const replacements = new Map(
94
- results.map(({ id, result }) => [id, result ?? '']),
95
- );
96
-
97
- // Single-pass replacement using regex
98
- html = html.replace(/<!--ASYNC-([\w-]+)-->/g, (_, id: string) => {
99
- return replacements.get(id) ?? '';
100
- });
101
-
102
- return html;
103
- };