@storyblok/astro 9.0.12 → 10.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.
@@ -1,2 +1 @@
1
- export { richTextToHTML } from './richTextToHTML';
2
1
  export { storyblokApiInstance as storyblokApi } from 'virtual:storyblok-init';
@@ -1,4 +1,3 @@
1
1
  import '../public.d.ts';
2
2
 
3
- export { richTextToHTML } from './richTextToHTML';
4
3
  export { storyblokApiInstance as storyblokApi } from 'virtual:storyblok-init';
package/dist/public.d.ts CHANGED
@@ -30,41 +30,23 @@ declare module '@storyblok/astro/StoryblokServerData.astro' {
30
30
  /** Renders a dynamic Storyblok component */
31
31
  export default StoryblokServerData;
32
32
  }
33
+ declare module '@storyblok/astro/StoryblokRichText.astro' {
34
+ import type { SbAstroRichTextComponentMap, SbRichTextImageOptions, SbRichTextInput } from '@storyblok/astro';
35
+
36
+ function StoryblokRichText(
37
+ _props: Record<string, unknown> & {
38
+ /** The Storyblok rich text document for this component (required) */
39
+ document: SbRichTextInput;
40
+ optimizeImage?: boolean | SbRichTextImageOptions;
41
+ components?: SbAstroRichTextComponentMap;
42
+ }
43
+ ): any;
44
+
45
+ /** Renders a dynamic Storyblok component */
46
+ export default StoryblokRichText;
47
+ }
33
48
  declare module '@storyblok/astro/client' {
34
- import type {
35
- StoryblokClient,
36
- StoryblokRichTextNode,
37
- StoryblokRichTextOptions,
38
- } from '@storyblok/astro';
39
- /**
40
- * @experimental Converts a Storyblok RichText field into an HTML string.
41
- *
42
- * This API is still under development and may change in future releases.
43
- * It also relies on Astro’s experimental
44
- * [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
45
- *
46
- * @async
47
- * @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
48
- * @param {StoryblokRichTextOptions['tiptapExtensions']} [tiptapExtensions] - Optional custom resolvers
49
- * for customizing how specific nodes or marks are transformed into HTML.
50
- * @returns {Promise<string>} A promise that resolves to the HTML string representation
51
- * of the provided RichText content.
52
- *
53
- * @example
54
- * ```astro
55
- * ---
56
- * import { richTextToHTML } from '@storyblok/astro/client';
57
- * const { blok } = Astro.props;
58
- * const renderedRichText = await richTextToHTML(blok.text);
59
- * ---
60
- *
61
- * <div set:html={renderedRichText} />
62
- * ```
63
- */
64
- export function richTextToHTML(
65
- richTextField: StoryblokRichTextNode,
66
- tiptapExtensions?: StoryblokRichTextOptions['tiptapExtensions'],
67
- ): Promise<string>;
49
+ import type { StoryblokClient } from '@storyblok/astro';
68
50
 
69
51
  /**
70
52
  * Provides direct access to the initialized Storyblok API client instance.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { ArrayFn, AsyncFn, BlockTypes, ISbAlternateObject, // previously AlternateObject
1
+ export type { ArrayFn, AsyncFn, ISbAlternateObject, // previously AlternateObject
2
2
  ISbCache, // previously StoryblokCache
3
3
  ISbConfig, // previously StoryblokConfig
4
4
  ISbContentMangmntAPI, ISbDimensions, ISbError, ISbEventPayload, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
@@ -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, StoryblokRichTextNodeTypes, StoryblokRichTextOptions, TextTypes, } from '@storyblok/js';
11
+ SbBlokData, SbBlokKeyDataTypes, SbPluginFactory, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, } from '@storyblok/js';
@@ -0,0 +1,12 @@
1
+ import { SbRichTextElement, SbRichTextElementByType, SbRichTextImageOptions } from '@storyblok/richtext';
2
+ import { AstroComponentFactory } from 'astro/runtime/server/render/astro/index.js';
3
+ export type SbAstroRichTextComponentMap = {
4
+ [K in SbRichTextElement]?: AstroComponentFactory;
5
+ };
6
+ export interface SbAstroRichTextRenderContext {
7
+ optimizeImage?: boolean | SbRichTextImageOptions;
8
+ components?: SbAstroRichTextComponentMap;
9
+ }
10
+ export type SbAstroRichTextProps<T extends SbRichTextElement> = SbRichTextElementByType<SbAstroRichTextRenderContext>[T];
11
+ export declare function isValidAstroComponent(component: unknown): component is AstroComponentFactory;
12
+ export declare function buildAstroAttrs(type: SbRichTextElement, attrs: Record<string, unknown>): Record<string, unknown>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
3
  "type": "module",
4
- "version": "9.0.12",
4
+ "version": "10.0.0",
5
5
  "private": false,
6
6
  "description": "Official Astro integration for the Storyblok Headless CMS",
7
7
  "author": "Storyblok",
@@ -24,26 +24,22 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
- "import": "./dist/storyblok-astro.es.js",
28
- "require": "./dist/storyblok-astro.umd.js"
27
+ "import": "./dist/index.js"
29
28
  },
30
29
  "./middleware.ts": {
31
30
  "types": "./dist/live-preview/middleware.d.ts",
32
- "import": "./dist/live-preview/middleware.ts",
33
- "require": "./dist/live-preview/middleware.ts"
31
+ "import": "./dist/live-preview/middleware.ts"
34
32
  },
35
33
  "./toolbarApp.ts": {
36
34
  "types": "./dist/dev-toolbar/toolbarApp.d.ts",
37
- "import": "./dist/dev-toolbar/toolbarApp.ts",
38
- "require": "./dist/dev-toolbar/toolbarApp.ts"
35
+ "import": "./dist/dev-toolbar/toolbarApp.ts"
39
36
  },
40
37
  "./client": "./dist/lib/client.ts",
41
38
  "./FallbackComponent.astro": "./dist/components/FallbackComponent.astro",
42
39
  "./StoryblokComponent.astro": "./dist/components/StoryblokComponent.astro",
43
- "./StoryblokServerData.astro": "./dist/components/StoryblokServerData.astro"
40
+ "./StoryblokServerData.astro": "./dist/components/StoryblokServerData.astro",
41
+ "./StoryblokRichText.astro": "./dist/components/StoryblokRichText.astro"
44
42
  },
45
- "main": "./dist/storyblok-astro.es.js",
46
- "module": "./dist/storyblok-astro.js",
47
43
  "types": "./dist/index.d.ts",
48
44
  "files": [
49
45
  "*.d.ts",
@@ -55,7 +51,8 @@
55
51
  "dependencies": {
56
52
  "camelcase": "^8.0.0",
57
53
  "morphdom": "^2.7.8",
58
- "@storyblok/js": "5.1.10"
54
+ "@storyblok/js": "6.0.0",
55
+ "@storyblok/richtext": "5.0.0"
59
56
  },
60
57
  "devDependencies": {
61
58
  "@cypress/vite-dev-server": "^6.0.3",
@@ -1,6 +0,0 @@
1
- import { SbBlokData } from '@storyblok/js';
2
- declare function FallbackComponent(_props: Record<string, unknown> & {
3
- /** The Storyblok blok data for this component (required) */
4
- blok: SbBlokData;
5
- }): any;
6
- export default FallbackComponent;
@@ -1,27 +0,0 @@
1
- import { StoryblokRichTextNode, StoryblokRichTextOptions } from '@storyblok/js';
2
- /**
3
- * @experimental Converts a Storyblok RichText field into an HTML string.
4
- *
5
- * This API is still under development and may change in future releases.
6
- * It also relies on Astro's experimental
7
- * [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
8
- *
9
- * @async
10
- * @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
11
- * @param {StoryblokRichTextOptions['tiptapExtensions']} [tiptapExtensions] - Optional custom
12
- * tiptap extensions for customizing how specific nodes or marks are rendered.
13
- * @returns {Promise<string>} A promise that resolves to the HTML string representation
14
- * of the provided RichText content.
15
- *
16
- * @example
17
- * ```astro
18
- * ---
19
- * import { richTextToHTML } from '@storyblok/astro/client';
20
- * const { blok } = Astro.props;
21
- * const renderedRichText = await richTextToHTML(blok.text);
22
- * ---
23
- *
24
- * <div set:html={renderedRichText} />
25
- * ```
26
- */
27
- export declare const richTextToHTML: (richTextField: StoryblokRichTextNode, tiptapExtensions?: StoryblokRichTextOptions["tiptapExtensions"]) => Promise<string>;
@@ -1,94 +0,0 @@
1
- import {
2
- ComponentBlok,
3
- richTextResolver,
4
- type StoryblokRichTextNode,
5
- type StoryblokRichTextOptions,
6
- } from '@storyblok/js';
7
- import { experimental_AstroContainer } from 'astro/container';
8
- import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
9
-
10
- // Lazily initialized Astro container (for rendering blok components)
11
- let container: null | experimental_AstroContainer = null;
12
-
13
- /**
14
- * @experimental Converts a Storyblok RichText field into an HTML string.
15
- *
16
- * This API is still under development and may change in future releases.
17
- * It also relies on Astro's experimental
18
- * [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
19
- *
20
- * @async
21
- * @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
22
- * @param {StoryblokRichTextOptions['tiptapExtensions']} [tiptapExtensions] - Optional custom
23
- * tiptap extensions for customizing how specific nodes or marks are rendered.
24
- * @returns {Promise<string>} A promise that resolves to the HTML string representation
25
- * of the provided RichText content.
26
- *
27
- * @example
28
- * ```astro
29
- * ---
30
- * import { richTextToHTML } from '@storyblok/astro/client';
31
- * const { blok } = Astro.props;
32
- * const renderedRichText = await richTextToHTML(blok.text);
33
- * ---
34
- *
35
- * <div set:html={renderedRichText} />
36
- * ```
37
- */
38
- export const richTextToHTML = async (
39
- richTextField: StoryblokRichTextNode,
40
- tiptapExtensions?: StoryblokRichTextOptions['tiptapExtensions'],
41
- ): Promise<string> => {
42
- // Create Astro container only once
43
- if (!container) {
44
- container = await experimental_AstroContainer.create();
45
- }
46
-
47
- // Collect async render results keyed by placeholder ID
48
- const asyncReplacements: Promise<{ id: string; result: string }>[] = [];
49
-
50
- const resolver = richTextResolver<string>({
51
- tiptapExtensions: {
52
- blok: ComponentBlok.configure({
53
- renderComponent: (blok: Record<string, unknown>, _id?: string) => {
54
- if (!blok || typeof blok !== 'object' || !container) {
55
- return '';
56
- }
57
-
58
- // Generate unique placeholder ID
59
- const id = crypto.randomUUID();
60
- const placeholder = `<!--ASYNC-${id}-->`;
61
-
62
- // Queue async render
63
- const promise = container
64
- .renderToString(StoryblokComponent, {
65
- props: { blok },
66
- })
67
- .then(result => ({ id, result }))
68
- .catch((err) => {
69
- console.error('Component rendering failed:', err);
70
- return { id, result: '<!-- Component render error -->' };
71
- });
72
-
73
- asyncReplacements.push(promise);
74
- return placeholder;
75
- },
76
- }),
77
- ...tiptapExtensions,
78
- },
79
- });
80
-
81
- let html = resolver.render(richTextField);
82
- // Wait for all async renders
83
- const results = await Promise.all(asyncReplacements);
84
- const replacements = new Map(
85
- results.map(({ id, result }) => [id, result ?? '']),
86
- );
87
-
88
- // Single-pass replacement using regex
89
- html = html.replace(/<!--ASYNC-([\w-]+)-->/g, (_, id: string) => {
90
- return replacements.get(id) ?? '';
91
- });
92
-
93
- return html;
94
- };