@storyblok/astro 9.0.12 → 10.0.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/FallbackComponent.astro +1 -1
- package/dist/components/StoryblokComponent.astro +1 -1
- package/dist/components/StoryblokRichText.astro +14 -0
- package/dist/components/StoryblokServerData.astro +1 -1
- package/dist/components/richtext/ElementTag.astro +32 -0
- package/dist/components/richtext/RenderChildren.astro +26 -0
- package/dist/components/richtext/RenderImage.astro +24 -0
- package/dist/components/richtext/RenderLinkGroup.astro +31 -0
- package/dist/components/richtext/RenderLinkInner.astro +18 -0
- package/dist/components/richtext/RenderNode.astro +46 -0
- package/dist/components/richtext/RenderStaticChildren.astro +23 -0
- package/dist/components/richtext/RenderStaticStructure.astro +35 -0
- package/dist/components/richtext/RenderTable.astro +20 -0
- package/dist/components/richtext/RenderTextNodeWithMarks.astro +34 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1641 -0
- package/dist/lib/client.d.ts +0 -1
- package/dist/lib/client.ts +0 -1
- package/dist/public.d.ts +16 -34
- package/dist/types.d.ts +2 -2
- package/dist/utils/richtext-helpers.d.ts +12 -0
- package/package.json +12 -15
- package/dist/components/FallbackComponent.d.ts +0 -6
- package/dist/lib/richTextToHTML.d.ts +0 -27
- package/dist/lib/richTextToHTML.ts +0 -94
- package/dist/storyblok-astro.es.js +0 -39004
- package/dist/storyblok-astro.umd.js +0 -143
package/dist/lib/client.d.ts
CHANGED
package/dist/lib/client.ts
CHANGED
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,
|
|
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
|
-
|
|
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": "
|
|
4
|
+
"version": "10.0.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
7
7
|
"author": "Storyblok",
|
|
@@ -24,45 +24,42 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"import": "./dist/
|
|
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",
|
|
50
46
|
"dist"
|
|
51
47
|
],
|
|
52
48
|
"peerDependencies": {
|
|
53
|
-
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
49
|
+
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
54
50
|
},
|
|
55
51
|
"dependencies": {
|
|
56
52
|
"camelcase": "^8.0.0",
|
|
57
53
|
"morphdom": "^2.7.8",
|
|
58
|
-
"@storyblok/
|
|
54
|
+
"@storyblok/richtext": "5.0.1",
|
|
55
|
+
"@storyblok/js": "6.0.1"
|
|
59
56
|
},
|
|
60
57
|
"devDependencies": {
|
|
61
58
|
"@cypress/vite-dev-server": "^6.0.3",
|
|
62
59
|
"@rollup/plugin-dynamic-import-vars": "^2.1.5",
|
|
63
60
|
"@types/lodash.mergewith": "^4.6.9",
|
|
64
61
|
"@types/node": "^24.11.0",
|
|
65
|
-
"astro": "^
|
|
62
|
+
"astro": "^7.0.0",
|
|
66
63
|
"cypress": "^14.3.3",
|
|
67
64
|
"eslint": "^9.26.0",
|
|
68
65
|
"eslint-config-prettier": "^10.0.1",
|
|
@@ -72,9 +69,9 @@
|
|
|
72
69
|
"prettier-plugin-astro": "^0.13.0",
|
|
73
70
|
"start-server-and-test": "^2.0.11",
|
|
74
71
|
"typescript": "5.8.3",
|
|
75
|
-
"vite": "^
|
|
72
|
+
"vite": "^8.0.0",
|
|
76
73
|
"vite-plugin-dts": "^4.5.3",
|
|
77
|
-
"vite-plugin-static-copy": "^
|
|
74
|
+
"vite-plugin-static-copy": "^4.1.1",
|
|
78
75
|
"vitest": "^3.1.3",
|
|
79
76
|
"@storyblok/eslint-config": "0.5.1"
|
|
80
77
|
},
|
|
@@ -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
|
-
};
|