@storyblok/astro 7.2.7 → 7.3.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/components/FallbackComponent.astro +1 -1
- package/dist/components/FallbackComponent.d.ts +3 -3
- package/dist/components/StoryblokComponent.astro +13 -12
- package/dist/dev-toolbar/toolbarApp.d.ts +1 -1
- package/dist/dev-toolbar/toolbarApp.ts +20 -30
- package/dist/index.d.ts +2 -0
- package/dist/lib/client.d.ts +2 -0
- package/dist/lib/client.ts +3 -0
- package/dist/lib/helpers.d.ts +35 -3
- package/dist/lib/richTextToHTML.d.ts +27 -0
- package/dist/lib/richTextToHTML.ts +103 -0
- package/dist/public.d.ts +71 -0
- package/dist/storyblok-astro.es.js +430 -340
- package/dist/storyblok-astro.umd.js +49 -19
- package/dist/utils/normalizeAstroExtension.d.ts +5 -0
- package/dist/utils/normalizePath.d.ts +16 -0
- package/dist/vite-plugins/vite-plugin-import-storyblok-components.d.ts +8 -0
- package/dist/vite-plugins/vite-plugin-storyblok-init.d.ts +1 -1
- package/dist/vite-plugins/vite-plugin-storyblok-options.d.ts +2 -1
- package/package.json +4 -7
- package/dist/components/StoryblokComponent.d.ts +0 -6
- package/dist/vite-plugins/vite-plugin-storyblok-components.d.ts +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SbBlokData } from '@storyblok/js';
|
|
2
|
-
declare
|
|
2
|
+
declare function FallbackComponent(_props: Record<string, unknown> & {
|
|
3
|
+
/** The Storyblok blok data for this component (required) */
|
|
3
4
|
blok: SbBlokData;
|
|
4
|
-
|
|
5
|
-
}) => any;
|
|
5
|
+
}): any;
|
|
6
6
|
export default FallbackComponent;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
---
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import type { AstroComponentFactory } from "astro/runtime/server/index.js";
|
|
2
|
+
import options from 'virtual:storyblok-options';
|
|
3
|
+
import { toCamelCase, type SbBlokData } from '@storyblok/astro';
|
|
4
|
+
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
|
5
|
+
import { storyblokComponents } from 'virtual:import-storyblok-components';
|
|
7
6
|
|
|
8
7
|
export interface Props {
|
|
9
8
|
blok: SbBlokData;
|
|
10
9
|
[prop: string]: unknown;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const { blok, ...props } = Astro.props;
|
|
14
12
|
|
|
15
13
|
if (!blok) {
|
|
@@ -17,26 +15,29 @@ if (!blok) {
|
|
|
17
15
|
"Cannot render StoryblokComponent. 'blok' prop is undefined."
|
|
18
16
|
);
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
/**
|
|
22
|
-
* convert blok components to camel case to match vite-plugin-storyblok-components
|
|
19
|
+
* convert blok components to camel case to match vite-plugin-import-storyblok-components
|
|
23
20
|
*/
|
|
24
21
|
let key = toCamelCase(blok.component as string);
|
|
25
22
|
|
|
26
|
-
const componentFound: boolean = key in
|
|
23
|
+
const componentFound: boolean = key in storyblokComponents;
|
|
27
24
|
|
|
28
25
|
let Component: AstroComponentFactory;
|
|
29
26
|
|
|
30
27
|
if (!componentFound) {
|
|
31
28
|
if (!options.enableFallbackComponent)
|
|
32
29
|
throw new Error(
|
|
33
|
-
`
|
|
30
|
+
`No component found for blok "${blok.component}".
|
|
31
|
+
Make sure the component is:
|
|
32
|
+
• Registered in your astro.config.mjs, or
|
|
33
|
+
• Placed in the "/${options.componentsDir}/storyblok" folder, or
|
|
34
|
+
• Enable the "fallbackComponent" option to handle missing components.`
|
|
34
35
|
);
|
|
35
36
|
else {
|
|
36
|
-
Component =
|
|
37
|
+
Component = storyblokComponents['FallbackComponent'];
|
|
37
38
|
}
|
|
38
39
|
} else {
|
|
39
|
-
Component =
|
|
40
|
+
Component = storyblokComponents[key];
|
|
40
41
|
}
|
|
41
42
|
---
|
|
42
43
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const storyblokLogo = "<svg
|
|
1
|
+
export declare const storyblokLogo = "\n<svg class=\"logo-storyblok logo-storyblok--dark\" role=\"img\" aria-label=\"Storyblok Official Logo\" viewBox=\"0 0 19 22\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M29.0287 14.9132C28.2686 14.9132 27.5302 14.8018 26.7918 14.5568C26.0988 14.3265 25.462 13.9468 24.924 13.4432L25.9013 11.7504C26.4443 12.1291 26.9655 12.4186 27.4867 12.6414C27.9862 12.8641 28.4858 12.9532 28.9636 12.9532C29.3111 12.9532 29.5934 12.8864 29.7888 12.7527C29.9843 12.6414 30.0712 12.4409 30.0712 12.1959C30.0712 11.9732 29.9626 11.7504 29.702 11.6168C29.2938 11.4162 28.8636 11.2666 28.4206 11.1714L26.9003 10.6591C26.4877 10.4809 26.1619 10.3027 25.9013 10.1023C25.6407 9.92408 25.4452 9.67908 25.3366 9.43408C25.2184 9.1529 25.1592 8.84935 25.1629 8.54317C25.1502 7.66646 25.5255 6.83107 26.1836 6.27136C26.4877 6.00408 26.8786 5.80363 27.313 5.64772C27.7473 5.49181 28.2251 5.42499 28.7247 5.42499C29.3979 5.42499 30.0277 5.51408 30.6141 5.69226C31.2005 5.89272 31.7652 6.22681 32.3081 6.71681L31.244 8.38726C30.8236 8.07881 30.3722 7.81747 29.8974 7.60772C29.4848 7.42954 29.1156 7.36272 28.7247 7.36272C28.4423 7.36272 28.1817 7.40726 27.9862 7.5409C27.7691 7.65226 27.6822 7.85272 27.6822 8.11999C27.6822 8.38726 27.7908 8.56545 28.008 8.69908C28.2251 8.83272 28.6595 8.96635 29.2459 9.12226C29.7903 9.26289 30.3268 9.4339 30.853 9.63454C31.2874 9.81272 31.6349 10.0132 31.9172 10.2136C32.4511 10.6169 32.7463 11.2726 32.6991 11.9509C32.6991 12.8641 32.3733 13.5768 31.7 14.1114C31.0485 14.6459 30.1798 14.9132 29.0287 14.9132ZM39.7792 14.2673C39.41 14.4232 38.9756 14.5791 38.4978 14.7127C38.02 14.8464 37.5422 14.9354 37.0427 14.9354C36.6952 14.9354 36.3911 14.8909 36.0871 14.8018C35.7915 14.7134 35.5176 14.5616 35.2835 14.3564C35.0663 14.1782 34.8926 13.9109 34.7623 13.6214C34.632 13.3095 34.5451 12.9309 34.5451 12.4854V7.69681H33.4158V5.60317H34.5668V2.68545H37.2599V5.5809H39.0842V7.69681H37.2599V11.5277C37.2599 11.8173 37.325 12.04 37.4771 12.1959C37.6291 12.3073 37.8245 12.3741 38.0417 12.3741C38.2589 12.3741 38.4761 12.3518 38.6715 12.2627C38.8887 12.1959 39.0842 12.1291 39.2362 12.04L39.7575 14.2673H39.7792ZM44.8612 14.9132C44.1701 14.9255 43.4835 14.7968 42.8414 14.5345C41.7112 14.076 40.8261 13.1439 40.409 11.9732C39.9823 10.8102 39.9823 9.52792 40.409 8.36499C40.8261 7.19423 41.7112 6.26214 42.8414 5.80363C43.4278 5.55863 44.1011 5.42499 44.8612 5.42499C46.1833 5.36117 47.4671 5.88947 48.3795 6.87272C48.7922 7.2959 49.0962 7.80817 49.3134 8.36499C49.758 9.5322 49.758 10.8282 49.3134 11.9954C48.8937 13.1518 48.0186 14.0734 46.9027 14.5345C46.2538 14.7998 45.5596 14.9285 44.8612 14.9132ZM42.9066 10.1914C42.9066 10.9041 43.0803 11.4832 43.4495 11.9064C43.8405 12.3518 44.3183 12.5745 44.8829 12.5745C45.4284 12.5853 45.9487 12.3391 46.2946 11.9064C46.4683 11.6836 46.5987 11.4609 46.7072 11.1491C46.8158 10.8595 46.8593 10.5254 46.8593 10.1914C46.8593 9.45636 46.6638 8.87726 46.2946 8.45408C45.9254 8.00863 45.4476 7.78589 44.8829 7.78589C44.3394 7.78464 43.8229 8.02909 43.4712 8.45408C43.2975 8.67681 43.1455 8.89954 43.0369 9.21136C42.939 9.52794 42.8949 9.85944 42.9066 10.1914ZM56.6541 7.98636C56.0026 7.98636 55.3945 8.09772 54.8515 8.32045C54.3736 8.48572 53.9666 8.81646 53.7005 9.2559V14.7573H50.9857V5.60317H53.4833V7.42954C53.7873 6.8059 54.1783 6.3159 54.6778 5.98181C55.1556 5.62545 55.6551 5.44726 56.1981 5.42499H56.4804L56.6541 5.44726V7.96408V7.98636ZM57.8486 16.1159C58.2263 16.2505 58.6217 16.3256 59.0214 16.3386C59.3472 16.3386 59.6078 16.2273 59.8033 16.0045C59.977 15.7818 60.129 15.3364 60.2811 14.7573L56.893 5.60317H59.6947L61.7579 12.3518L63.5605 5.60317H66.1015L62.6918 16.2273C62.1569 18.0318 60.3638 19.1157 58.5653 18.7218C58.3481 18.6773 58.0875 18.6104 57.8486 18.4991V16.1159ZM72.5301 14.9133C71.8568 14.9133 71.2487 14.7795 70.7492 14.4677C70.2417 14.1818 69.8208 13.758 69.533 13.2427V14.7573H67.1657V2.01727H69.9022V7.09545C70.4962 6.02938 71.6157 5.38681 72.8124 5.42499C73.3771 5.42499 73.8983 5.53636 74.3761 5.80363C74.8539 6.02636 75.2448 6.38272 75.614 6.8059C76.6831 8.32739 76.974 10.2831 76.3959 12.0623C76.1787 12.6414 75.8746 13.1536 75.5054 13.5768C74.7429 14.4342 73.6616 14.9198 72.5301 14.9133ZM71.7699 12.5745C72.6515 12.5764 73.4369 12.0037 73.7245 11.1491C74.043 10.2518 73.887 9.24956 73.3119 8.49863C72.9724 8.0401 72.4398 7.7753 71.8785 7.7859C71.4659 7.7859 71.0749 7.94181 70.7057 8.23136C70.3582 8.54317 70.0759 8.92181 69.8805 9.38954V11.305C70.2309 12.0628 70.9738 12.5476 71.7916 12.5523L71.7699 12.5745ZM78.0247 2.01727H80.7395V11.4832C80.7395 12.1959 81.0218 12.53 81.6082 12.53C81.9183 12.5309 82.2239 12.4545 82.4987 12.3073L82.8679 14.3786C82.1072 14.7203 81.2875 14.902 80.4572 14.9132C79.6753 14.9132 79.0672 14.6904 78.6546 14.2895C78.2202 13.8441 78.003 13.265 78.003 12.4632V2.01727H78.0247ZM87.9933 14.9132C87.3023 14.9255 86.6157 14.7968 85.9736 14.5345C84.8367 14.0789 83.9437 13.1469 83.5194 11.9732C82.8914 10.2226 83.2408 8.26037 84.4316 6.85045C84.8659 6.40499 85.3437 6.0709 85.9518 5.80363C86.5382 5.55863 87.2115 5.42499 87.9716 5.42499C89.2937 5.36117 90.5776 5.88947 91.49 6.87272C91.9243 7.2959 92.2066 7.80817 92.4238 8.36499C93.0767 10.1133 92.7249 12.0889 91.5117 13.4877C91.099 13.9332 90.5995 14.2895 89.9914 14.5345C89.3493 14.7968 88.6627 14.9255 87.9716 14.9132H87.9933ZM86.017 10.1914C86.017 10.9041 86.1907 11.4832 86.5599 11.9064C86.9509 12.3518 87.4287 12.5745 87.9933 12.5745C88.5382 12.5821 89.0571 12.3364 89.405 11.9064C89.5788 11.6836 89.7091 11.4609 89.8177 11.1491C89.9262 10.8595 89.9697 10.5254 89.9697 10.1914C89.9697 9.45636 89.7742 8.87726 89.405 8.45408C89.0358 8.00863 88.558 7.78589 87.9933 7.78589C87.4498 7.78464 86.9334 8.02909 86.5817 8.45408C86.4079 8.67681 86.2559 8.89954 86.1473 9.21136C86.0387 9.52317 86.017 9.83499 86.017 10.1914ZM100.112 14.7573L97.7882 11.06L96.8326 12.0845V14.7573H94.1178V2.01727H96.8326V9.38954L99.8514 5.60317H102.74L99.5256 9.54545L103.001 14.7573H100.112Z\" fill=\"currentColor\"></path>\n <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M0 1.71089C0 0.76599 0.76599 0 1.71089 0H17.1089C18.0538 0 18.8198 0.76599 18.8198 1.71089V17.1089C18.8198 18.0538 18.0538 18.8198 17.1089 18.8198H7.13145L4.57616 20.9297C4.24445 21.2036 3.74366 20.9676 3.74366 20.5375V18.8198H1.71089C0.76599 18.8198 0 18.0538 0 17.1089V1.71089ZM3.74233 3.10946H11.9675C13.7438 3.10946 15.1839 4.5495 15.1839 6.32587C15.1839 7.74936 14.2592 8.95687 12.9777 9.38045C14.4761 9.65447 15.6117 10.9667 15.6117 12.5443C15.6117 14.3207 14.1717 15.7607 12.3953 15.7607H3.74247V9.54229H3.74233V3.10946ZM10.583 6.00384H6.73607V7.93369H10.583C11.1159 7.93369 11.5479 7.50168 11.5479 6.96877C11.5479 6.43585 11.1159 6.00384 10.583 6.00384ZM6.73607 10.2925H10.9035C11.4956 10.2925 11.9757 10.7725 11.9757 11.3647C11.9757 11.9568 11.4956 12.4368 10.9035 12.4368H6.73607V10.2925Z\" fill=\"currentColor\"></path>\n</svg>\n";
|
|
2
2
|
declare const _default: import('astro').DevToolbarApp;
|
|
3
3
|
export default _default;
|
|
@@ -4,29 +4,19 @@ import {
|
|
|
4
4
|
} from 'astro/runtime/client/dev-toolbar/ui-library/icons.js';
|
|
5
5
|
import { defineToolbarApp } from 'astro/toolbar';
|
|
6
6
|
|
|
7
|
-
export const storyblokLogo =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
</g>
|
|
14
|
-
</g>
|
|
15
|
-
</g>
|
|
16
|
-
</svg>`;
|
|
7
|
+
export const storyblokLogo = `
|
|
8
|
+
<svg class="logo-storyblok logo-storyblok--dark" role="img" aria-label="Storyblok Official Logo" viewBox="0 0 19 22" xmlns="http://www.w3.org/2000/svg">
|
|
9
|
+
<path d="M29.0287 14.9132C28.2686 14.9132 27.5302 14.8018 26.7918 14.5568C26.0988 14.3265 25.462 13.9468 24.924 13.4432L25.9013 11.7504C26.4443 12.1291 26.9655 12.4186 27.4867 12.6414C27.9862 12.8641 28.4858 12.9532 28.9636 12.9532C29.3111 12.9532 29.5934 12.8864 29.7888 12.7527C29.9843 12.6414 30.0712 12.4409 30.0712 12.1959C30.0712 11.9732 29.9626 11.7504 29.702 11.6168C29.2938 11.4162 28.8636 11.2666 28.4206 11.1714L26.9003 10.6591C26.4877 10.4809 26.1619 10.3027 25.9013 10.1023C25.6407 9.92408 25.4452 9.67908 25.3366 9.43408C25.2184 9.1529 25.1592 8.84935 25.1629 8.54317C25.1502 7.66646 25.5255 6.83107 26.1836 6.27136C26.4877 6.00408 26.8786 5.80363 27.313 5.64772C27.7473 5.49181 28.2251 5.42499 28.7247 5.42499C29.3979 5.42499 30.0277 5.51408 30.6141 5.69226C31.2005 5.89272 31.7652 6.22681 32.3081 6.71681L31.244 8.38726C30.8236 8.07881 30.3722 7.81747 29.8974 7.60772C29.4848 7.42954 29.1156 7.36272 28.7247 7.36272C28.4423 7.36272 28.1817 7.40726 27.9862 7.5409C27.7691 7.65226 27.6822 7.85272 27.6822 8.11999C27.6822 8.38726 27.7908 8.56545 28.008 8.69908C28.2251 8.83272 28.6595 8.96635 29.2459 9.12226C29.7903 9.26289 30.3268 9.4339 30.853 9.63454C31.2874 9.81272 31.6349 10.0132 31.9172 10.2136C32.4511 10.6169 32.7463 11.2726 32.6991 11.9509C32.6991 12.8641 32.3733 13.5768 31.7 14.1114C31.0485 14.6459 30.1798 14.9132 29.0287 14.9132ZM39.7792 14.2673C39.41 14.4232 38.9756 14.5791 38.4978 14.7127C38.02 14.8464 37.5422 14.9354 37.0427 14.9354C36.6952 14.9354 36.3911 14.8909 36.0871 14.8018C35.7915 14.7134 35.5176 14.5616 35.2835 14.3564C35.0663 14.1782 34.8926 13.9109 34.7623 13.6214C34.632 13.3095 34.5451 12.9309 34.5451 12.4854V7.69681H33.4158V5.60317H34.5668V2.68545H37.2599V5.5809H39.0842V7.69681H37.2599V11.5277C37.2599 11.8173 37.325 12.04 37.4771 12.1959C37.6291 12.3073 37.8245 12.3741 38.0417 12.3741C38.2589 12.3741 38.4761 12.3518 38.6715 12.2627C38.8887 12.1959 39.0842 12.1291 39.2362 12.04L39.7575 14.2673H39.7792ZM44.8612 14.9132C44.1701 14.9255 43.4835 14.7968 42.8414 14.5345C41.7112 14.076 40.8261 13.1439 40.409 11.9732C39.9823 10.8102 39.9823 9.52792 40.409 8.36499C40.8261 7.19423 41.7112 6.26214 42.8414 5.80363C43.4278 5.55863 44.1011 5.42499 44.8612 5.42499C46.1833 5.36117 47.4671 5.88947 48.3795 6.87272C48.7922 7.2959 49.0962 7.80817 49.3134 8.36499C49.758 9.5322 49.758 10.8282 49.3134 11.9954C48.8937 13.1518 48.0186 14.0734 46.9027 14.5345C46.2538 14.7998 45.5596 14.9285 44.8612 14.9132ZM42.9066 10.1914C42.9066 10.9041 43.0803 11.4832 43.4495 11.9064C43.8405 12.3518 44.3183 12.5745 44.8829 12.5745C45.4284 12.5853 45.9487 12.3391 46.2946 11.9064C46.4683 11.6836 46.5987 11.4609 46.7072 11.1491C46.8158 10.8595 46.8593 10.5254 46.8593 10.1914C46.8593 9.45636 46.6638 8.87726 46.2946 8.45408C45.9254 8.00863 45.4476 7.78589 44.8829 7.78589C44.3394 7.78464 43.8229 8.02909 43.4712 8.45408C43.2975 8.67681 43.1455 8.89954 43.0369 9.21136C42.939 9.52794 42.8949 9.85944 42.9066 10.1914ZM56.6541 7.98636C56.0026 7.98636 55.3945 8.09772 54.8515 8.32045C54.3736 8.48572 53.9666 8.81646 53.7005 9.2559V14.7573H50.9857V5.60317H53.4833V7.42954C53.7873 6.8059 54.1783 6.3159 54.6778 5.98181C55.1556 5.62545 55.6551 5.44726 56.1981 5.42499H56.4804L56.6541 5.44726V7.96408V7.98636ZM57.8486 16.1159C58.2263 16.2505 58.6217 16.3256 59.0214 16.3386C59.3472 16.3386 59.6078 16.2273 59.8033 16.0045C59.977 15.7818 60.129 15.3364 60.2811 14.7573L56.893 5.60317H59.6947L61.7579 12.3518L63.5605 5.60317H66.1015L62.6918 16.2273C62.1569 18.0318 60.3638 19.1157 58.5653 18.7218C58.3481 18.6773 58.0875 18.6104 57.8486 18.4991V16.1159ZM72.5301 14.9133C71.8568 14.9133 71.2487 14.7795 70.7492 14.4677C70.2417 14.1818 69.8208 13.758 69.533 13.2427V14.7573H67.1657V2.01727H69.9022V7.09545C70.4962 6.02938 71.6157 5.38681 72.8124 5.42499C73.3771 5.42499 73.8983 5.53636 74.3761 5.80363C74.8539 6.02636 75.2448 6.38272 75.614 6.8059C76.6831 8.32739 76.974 10.2831 76.3959 12.0623C76.1787 12.6414 75.8746 13.1536 75.5054 13.5768C74.7429 14.4342 73.6616 14.9198 72.5301 14.9133ZM71.7699 12.5745C72.6515 12.5764 73.4369 12.0037 73.7245 11.1491C74.043 10.2518 73.887 9.24956 73.3119 8.49863C72.9724 8.0401 72.4398 7.7753 71.8785 7.7859C71.4659 7.7859 71.0749 7.94181 70.7057 8.23136C70.3582 8.54317 70.0759 8.92181 69.8805 9.38954V11.305C70.2309 12.0628 70.9738 12.5476 71.7916 12.5523L71.7699 12.5745ZM78.0247 2.01727H80.7395V11.4832C80.7395 12.1959 81.0218 12.53 81.6082 12.53C81.9183 12.5309 82.2239 12.4545 82.4987 12.3073L82.8679 14.3786C82.1072 14.7203 81.2875 14.902 80.4572 14.9132C79.6753 14.9132 79.0672 14.6904 78.6546 14.2895C78.2202 13.8441 78.003 13.265 78.003 12.4632V2.01727H78.0247ZM87.9933 14.9132C87.3023 14.9255 86.6157 14.7968 85.9736 14.5345C84.8367 14.0789 83.9437 13.1469 83.5194 11.9732C82.8914 10.2226 83.2408 8.26037 84.4316 6.85045C84.8659 6.40499 85.3437 6.0709 85.9518 5.80363C86.5382 5.55863 87.2115 5.42499 87.9716 5.42499C89.2937 5.36117 90.5776 5.88947 91.49 6.87272C91.9243 7.2959 92.2066 7.80817 92.4238 8.36499C93.0767 10.1133 92.7249 12.0889 91.5117 13.4877C91.099 13.9332 90.5995 14.2895 89.9914 14.5345C89.3493 14.7968 88.6627 14.9255 87.9716 14.9132H87.9933ZM86.017 10.1914C86.017 10.9041 86.1907 11.4832 86.5599 11.9064C86.9509 12.3518 87.4287 12.5745 87.9933 12.5745C88.5382 12.5821 89.0571 12.3364 89.405 11.9064C89.5788 11.6836 89.7091 11.4609 89.8177 11.1491C89.9262 10.8595 89.9697 10.5254 89.9697 10.1914C89.9697 9.45636 89.7742 8.87726 89.405 8.45408C89.0358 8.00863 88.558 7.78589 87.9933 7.78589C87.4498 7.78464 86.9334 8.02909 86.5817 8.45408C86.4079 8.67681 86.2559 8.89954 86.1473 9.21136C86.0387 9.52317 86.017 9.83499 86.017 10.1914ZM100.112 14.7573L97.7882 11.06L96.8326 12.0845V14.7573H94.1178V2.01727H96.8326V9.38954L99.8514 5.60317H102.74L99.5256 9.54545L103.001 14.7573H100.112Z" fill="currentColor"></path>
|
|
10
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 1.71089C0 0.76599 0.76599 0 1.71089 0H17.1089C18.0538 0 18.8198 0.76599 18.8198 1.71089V17.1089C18.8198 18.0538 18.0538 18.8198 17.1089 18.8198H7.13145L4.57616 20.9297C4.24445 21.2036 3.74366 20.9676 3.74366 20.5375V18.8198H1.71089C0.76599 18.8198 0 18.0538 0 17.1089V1.71089ZM3.74233 3.10946H11.9675C13.7438 3.10946 15.1839 4.5495 15.1839 6.32587C15.1839 7.74936 14.2592 8.95687 12.9777 9.38045C14.4761 9.65447 15.6117 10.9667 15.6117 12.5443C15.6117 14.3207 14.1717 15.7607 12.3953 15.7607H3.74247V9.54229H3.74233V3.10946ZM10.583 6.00384H6.73607V7.93369H10.583C11.1159 7.93369 11.5479 7.50168 11.5479 6.96877C11.5479 6.43585 11.1159 6.00384 10.583 6.00384ZM6.73607 10.2925H10.9035C11.4956 10.2925 11.9757 10.7725 11.9757 11.3647C11.9757 11.9568 11.4956 12.4368 10.9035 12.4368H6.73607V10.2925Z" fill="currentColor"></path>
|
|
11
|
+
</svg>
|
|
12
|
+
`;
|
|
17
13
|
|
|
18
|
-
const storyblokLogoFull =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<path d="M2.32662261,0 C1.03405449,0 0,1.0331384 0,2.27290448 L0,42.8752437 C0,44.1150097 1.03405449,44.8898635 2.27491989,44.8898635 L8.27243596,44.8898635 L8.27243596,53 L15.7176283,44.9415205 L42.9132615,44.9415205 C44.1541269,44.9415205 44.9296678,44.1666667 44.9296678,42.8752437 L44.9296678,2.3245614 C44.9296678,1.08479532 44.2058296,0 42.9132615,0 L2.32662261,0 Z" id="Shape-path-Copy" fill="#0AB3AF"></path>
|
|
25
|
-
<path d="M29.1016723,8.11483254 C30.1351059,8.11483254 31.0135245,8.32132604 31.8402713,8.78593643 C32.6153465,9.19892344 33.33875,9.76678059 33.9071385,10.4378845 C35.0647615,11.8482391 35.6869248,13.6215753 35.6639755,15.445352 C35.6639755,16.7875598 35.3022738,18.0781442 34.630542,19.3171053 C33.9341248,20.5632996 32.8438147,21.5436614 31.5302412,22.1047676 C33.183735,22.569378 34.4755269,23.395352 35.4572888,24.5826897 C36.387379,25.8216507 36.8524241,27.4219754 36.8524241,29.4352871 C36.8524241,30.7258715 36.6168825,31.8756998 36.1290206,32.7391832 C35.6123039,33.668404 34.8372287,34.4427546 33.9071385,35.0106118 C32.9253766,35.6300923 31.8402713,36.1979494 30.600151,36.4560663 C29.3600307,36.7658066 28.0165671,37.0239234 26.6214318,37.0239234 L8.32965751,37.0239234 L8.32965751,8.11483254 L29.1016723,8.11483254 Z M26.1340815,24.271851 L15.77813,24.271851 L15.77813,29.1552028 L25.8851404,29.1552028 C26.4825991,29.1552028 27.0302696,28.9110352 27.4783637,28.5203671 C27.8766695,28.1296989 28.1256107,27.5436967 28.1256107,26.811194 C28.140051,26.1827412 27.948041,25.5663945 27.5779401,25.0531873 C27.1796343,24.5648522 26.7315403,24.271851 26.1340815,24.271851 Z M25.2876816,14.5051475 L15.77813,14.5051475 L15.77813,18.9001641 L25.0885287,18.9001641 C25.586411,18.9001641 26.0842933,18.6559965 26.4825991,18.3629954 C26.9306932,18.0699943 27.1298461,17.4351586 27.1298461,16.6049888 C27.1298461,15.872486 26.9306932,15.3353173 26.5821756,14.9934827 C26.233658,14.7004816 25.7855639,14.5051475 25.2876816,14.5051475 Z" id="Combined-Shape-Copy-3" fill="#FFFFFF"></path>
|
|
26
|
-
</g>
|
|
27
|
-
</g>
|
|
28
|
-
</g>
|
|
29
|
-
</g>
|
|
14
|
+
const storyblokLogoFull = `
|
|
15
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="103" height="22" viewBox="0 0 103 22" fill="none">
|
|
16
|
+
<g id="sb-logo">
|
|
17
|
+
<path id="storyblok-text" d="M29.0285 14.9131C28.2684 14.9131 27.53 14.8018 26.7916 14.5568C26.0986 14.3265 25.4618 13.9468 24.9238 13.4431L25.9011 11.7504C26.4441 12.129 26.9653 12.4186 27.4866 12.6413C27.9861 12.864 28.4856 12.9531 28.9634 12.9531C29.3109 12.9531 29.5932 12.8863 29.7887 12.7527C29.9841 12.6413 30.071 12.4408 30.071 12.1958C30.071 11.9731 29.9624 11.7504 29.7018 11.6168C29.2936 11.4161 28.8634 11.2666 28.4204 11.1713L26.9002 10.659C26.4875 10.4808 26.1618 10.3027 25.9011 10.1022C25.6405 9.92403 25.4451 9.67903 25.3365 9.43403C25.2183 9.15284 25.1591 8.8493 25.1627 8.54312C25.15 7.66641 25.5254 6.83101 26.1835 6.2713C26.4875 6.00403 26.8785 5.80357 27.3128 5.64767C27.7472 5.49176 28.225 5.42494 28.7245 5.42494C29.3978 5.42494 30.0276 5.51403 30.614 5.69221C31.2004 5.89267 31.765 6.22676 32.308 6.71676L31.2438 8.38721C30.8234 8.07876 30.372 7.81742 29.8973 7.60767C29.4846 7.42948 29.1154 7.36267 28.7245 7.36267C28.4422 7.36267 28.1815 7.40721 27.9861 7.54085C27.7689 7.65221 27.682 7.85266 27.682 8.11994C27.682 8.38721 27.7906 8.56539 28.0078 8.69903C28.225 8.83266 28.6593 8.9663 29.2457 9.12221C29.7901 9.26284 30.3266 9.43385 30.8529 9.63448C31.2872 9.81266 31.6347 10.0131 31.9171 10.2136C32.451 10.6168 32.7461 11.2726 32.6989 11.9508C32.6989 12.864 32.3731 13.5768 31.6999 14.1113C31.0483 14.6458 30.1796 14.9131 29.0285 14.9131ZM39.779 14.2672C39.4098 14.4231 38.9754 14.579 38.4976 14.7127C38.0198 14.8463 37.542 14.9354 37.0425 14.9354C36.695 14.9354 36.391 14.8908 36.0869 14.8018C35.7913 14.7134 35.5174 14.5615 35.2834 14.3563C35.0662 14.1781 34.8924 13.9108 34.7621 13.6213C34.6318 13.3095 34.5449 12.9308 34.5449 12.4854V7.69676H33.4156V5.60312H34.5667V2.68539H37.2597V5.58085H39.084V7.69676H37.2597V11.5277C37.2597 11.8172 37.3249 12.0399 37.4769 12.1958C37.6289 12.3072 37.8244 12.374 38.0416 12.374C38.2587 12.374 38.4759 12.3518 38.6714 12.2627C38.8886 12.1958 39.084 12.129 39.2361 12.0399L39.7573 14.2672H39.779ZM44.861 14.9131C44.17 14.9255 43.4834 14.7968 42.8413 14.5345C41.7111 14.076 40.8259 13.1439 40.4088 11.9731C39.9821 10.8102 39.9821 9.52786 40.4088 8.36494C40.8259 7.19418 41.7111 6.26208 42.8413 5.80357C43.4276 5.55857 44.1009 5.42494 44.861 5.42494C46.1831 5.36112 47.467 5.88941 48.3794 6.87267C48.792 7.29585 49.0961 7.80812 49.3132 8.36494C49.7578 9.53215 49.7578 10.8282 49.3132 11.9954C48.8935 13.1517 48.0185 14.0734 46.9025 14.5345C46.2537 14.7997 45.5594 14.9285 44.861 14.9131ZM42.9064 10.1913C42.9064 10.904 43.0802 11.4831 43.4494 11.9063C43.8403 12.3518 44.3181 12.5745 44.8828 12.5745C45.4283 12.5853 45.9485 12.339 46.2944 11.9063C46.4682 11.6836 46.5985 11.4608 46.7071 11.149C46.8157 10.8595 46.8591 10.5254 46.8591 10.1913C46.8591 9.4563 46.6636 8.87721 46.2944 8.45403C45.9252 8.00857 45.4474 7.78584 44.8828 7.78584C44.3392 7.78459 43.8228 8.02903 43.4711 8.45403C43.2973 8.67676 43.1453 8.89948 43.0367 9.2113C42.9388 9.52789 42.8947 9.85939 42.9064 10.1913ZM56.654 7.9863C56.0024 7.9863 55.3943 8.09767 54.8514 8.32039C54.3734 8.48567 53.9664 8.81641 53.7003 9.25585V14.7572H50.9855V5.60312H53.4831V7.42948C53.7872 6.80585 54.1781 6.31585 54.6776 5.98176C55.1554 5.62539 55.6549 5.44721 56.1979 5.42494H56.4802L56.654 5.44721V7.96403V7.9863ZM57.8485 16.1158C58.2262 16.2505 58.6216 16.3256 59.0212 16.3386C59.347 16.3386 59.6076 16.2272 59.8031 16.0045C59.9768 15.7818 60.1289 15.3363 60.2809 14.7572L56.8929 5.60312H59.6945L61.7577 12.3518L63.5603 5.60312H66.1013L62.6916 16.2272C62.1567 18.0317 60.3636 19.1157 58.5652 18.7218C58.348 18.6772 58.0874 18.6104 57.8485 18.499V16.1158ZM72.5299 14.9133C71.8566 14.9133 71.2485 14.7795 70.749 14.4677C70.2415 14.1818 69.8207 13.7579 69.5328 13.2427V14.7572H67.1655V2.01721H69.902V7.09539C70.496 6.02932 71.6155 5.38675 72.8122 5.42494C73.3769 5.42494 73.8981 5.5363 74.3759 5.80357C74.8537 6.0263 75.2446 6.38267 75.6139 6.80585C76.6829 8.32734 76.9738 10.283 76.3957 12.0622C76.1785 12.6413 75.8745 13.1536 75.5053 13.5768C74.7427 14.4341 73.6614 14.9198 72.5299 14.9133ZM71.7698 12.5745C72.6513 12.5764 73.4367 12.0036 73.7244 11.149C74.0428 10.2518 73.8868 9.24951 73.3117 8.49857C72.9722 8.04004 72.4397 7.77525 71.8783 7.78585C71.4657 7.78585 71.0748 7.94176 70.7056 8.2313C70.3581 8.54312 70.0757 8.92176 69.8803 9.38948V11.3049C70.2308 12.0627 70.9737 12.5475 71.7915 12.5522L71.7698 12.5745ZM78.0246 2.01721H80.7393V11.4831C80.7393 12.1958 81.0217 12.5299 81.6081 12.5299C81.9181 12.5309 82.2237 12.4544 82.4985 12.3072L82.8677 14.3786C82.1071 14.7202 81.2873 14.902 80.457 14.9131C79.6751 14.9131 79.067 14.6904 78.6544 14.2895C78.22 13.844 78.0028 13.2649 78.0028 12.4631V2.01721H78.0246ZM87.9932 14.9131C87.3021 14.9255 86.6155 14.7968 85.9734 14.5345C84.8365 14.0788 83.9436 13.1468 83.5192 11.9731C82.8912 10.2226 83.2406 8.26032 84.4314 6.85039C84.8658 6.40494 85.3436 6.07085 85.9517 5.80357C86.5381 5.55857 87.2113 5.42494 87.9715 5.42494C89.2935 5.36112 90.5774 5.88941 91.4898 6.87267C91.9241 7.29585 92.2065 7.80812 92.4237 8.36494C93.0765 10.1132 92.7247 12.0889 91.5115 13.4877C91.0989 13.9331 90.5993 14.2895 89.9912 14.5345C89.3491 14.7968 88.6625 14.9255 87.9715 14.9131H87.9932ZM86.0168 10.1913C86.0168 10.904 86.1906 11.4831 86.5598 11.9063C86.9507 12.3518 87.4285 12.5745 87.9932 12.5745C88.538 12.582 89.0569 12.3364 89.4048 11.9063C89.5786 11.6836 89.7089 11.4608 89.8175 11.149C89.9261 10.8595 89.9695 10.5254 89.9695 10.1913C89.9695 9.4563 89.774 8.87721 89.4048 8.45403C89.0356 8.00857 88.5578 7.78584 87.9932 7.78584C87.4496 7.78459 86.9332 8.02903 86.5815 8.45403C86.4077 8.67676 86.2557 8.89948 86.1471 9.2113C86.0385 9.52312 86.0168 9.83494 86.0168 10.1913ZM100.112 14.7572L97.788 11.0599L96.8324 12.0845V14.7572H94.1177V2.01721H96.8324V9.38948L99.8512 5.60312H102.74L99.5255 9.54539L103 14.7572H100.112Z" fill="#FFFFFF" />
|
|
18
|
+
<path id="b-shape" fill-rule="evenodd" clip-rule="evenodd" d="M0 1.71089C0 0.76599 0.76599 0 1.71089 0H17.1089C18.0538 0 18.8198 0.76599 18.8198 1.71089V17.1089C18.8198 18.0538 18.0538 18.8198 17.1089 18.8198H7.13145L4.57616 20.9297C4.24445 21.2036 3.74366 20.9676 3.74366 20.5375V18.8198H1.71089C0.76599 18.8198 0 18.0538 0 17.1089V1.71089ZM3.74233 3.10946H11.9675C13.7438 3.10946 15.1839 4.5495 15.1839 6.32587C15.1839 7.74936 14.2592 8.95687 12.9777 9.38045C14.4761 9.65447 15.6117 10.9667 15.6117 12.5443C15.6117 14.3207 14.1717 15.7607 12.3953 15.7607H3.74247V9.54229H3.74233V3.10946ZM10.583 6.00384H6.73607V7.93369H10.583C11.1159 7.93369 11.5479 7.50168 11.5479 6.96877C11.5479 6.43585 11.1159 6.00384 10.583 6.00384ZM6.73607 10.2925H10.9035C11.4956 10.2925 11.9757 10.7725 11.9757 11.3647C11.9757 11.9568 11.4956 12.4368 10.9035 12.4368H6.73607V10.2925Z" fill="#FFFFFF" />
|
|
19
|
+
</g>
|
|
30
20
|
</svg>`;
|
|
31
21
|
|
|
32
22
|
function createWindowElement(content: string) {
|
|
@@ -44,9 +34,9 @@ interface LinkItem {
|
|
|
44
34
|
const links: LinkItem[] = [
|
|
45
35
|
{
|
|
46
36
|
icon: 'star',
|
|
47
|
-
name: '
|
|
37
|
+
name: 'Astro Tutorial',
|
|
48
38
|
description: 'Practical step-by-step guide.',
|
|
49
|
-
link: 'https://www.storyblok.com/
|
|
39
|
+
link: 'https://www.storyblok.com/docs/guides/astro/',
|
|
50
40
|
},
|
|
51
41
|
{
|
|
52
42
|
icon: 'lightbulb',
|
|
@@ -56,9 +46,9 @@ const links: LinkItem[] = [
|
|
|
56
46
|
},
|
|
57
47
|
{
|
|
58
48
|
icon: 'file-search',
|
|
59
|
-
name: '
|
|
60
|
-
description: 'Storyblok\'s
|
|
61
|
-
link: 'https://www.storyblok.com/docs
|
|
49
|
+
name: 'Storyblok Docs',
|
|
50
|
+
description: 'Find your way through Storyblok\'s documentation.',
|
|
51
|
+
link: 'https://www.storyblok.com/docs',
|
|
62
52
|
},
|
|
63
53
|
{
|
|
64
54
|
icon: 'astro:logo',
|
|
@@ -76,7 +66,7 @@ const links: LinkItem[] = [
|
|
|
76
66
|
icon: 'bug',
|
|
77
67
|
name: 'Report a Bug',
|
|
78
68
|
description: 'Help us make @storyblok/astro even better.',
|
|
79
|
-
link: 'https://github.com/
|
|
69
|
+
link: 'https://github.com/storyblok/monoblok/issues',
|
|
80
70
|
},
|
|
81
71
|
];
|
|
82
72
|
function createCanvas() {
|
|
@@ -146,8 +136,8 @@ function createCanvas() {
|
|
|
146
136
|
</a>
|
|
147
137
|
<a href="https://github.com/storyblok/storyblok-astro" target="_blank">
|
|
148
138
|
<img
|
|
149
|
-
src="https://img.shields.io/npm/v/@storyblok/astro?color=
|
|
150
|
-
alt="Storyblok Astro Version v.
|
|
139
|
+
src="https://img.shields.io/npm/v/@storyblok/astro?color=FFFFFF&label=Astro&labelColor=1B243F&logo=storyblok&logoColor=FFFFFF"
|
|
140
|
+
alt="Storyblok Astro Version v.7.2.5"
|
|
151
141
|
/>
|
|
152
142
|
</a>
|
|
153
143
|
</header>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference path="./public.d.ts" />
|
|
1
2
|
import { default as storyblokIntegration } from './lib/storyblok-integration';
|
|
2
3
|
export { getLiveStory, useStoryblokApi } from './lib/helpers';
|
|
4
|
+
export type { IntegrationOptions } from './lib/storyblok-integration';
|
|
3
5
|
export { handleStoryblokMessage } from './live-preview/handleStoryblokMessage';
|
|
4
6
|
export * from './types';
|
|
5
7
|
export { toCamelCase } from './utils/toCamelCase';
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
import { ISbStoryData, StoryblokBridgeConfigV2, StoryblokClient } from '../types';
|
|
2
2
|
import { AstroGlobal } from 'astro';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the Storyblok API client instance.
|
|
5
|
+
*
|
|
6
|
+
* This function gives you access to the `StoryblokClient` that is initialized
|
|
7
|
+
* when setting up the Storyblok SDK in your Astro configuration.
|
|
8
|
+
*
|
|
9
|
+
* @throws {Error} If the `storyblokApiInstance` has not been initialized in Astro config.
|
|
10
|
+
* @returns {StoryblokClient} The initialized Storyblok API client instance.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // In an Astro route or integration code:
|
|
15
|
+
* const storyblokApi = useStoryblokApi();
|
|
16
|
+
* const { data } = await storyblokApi.get('cdn/stories/home');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare function useStoryblokApi(): StoryblokClient;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the live Storyblok story from Astro's `locals` during preview mode.
|
|
22
|
+
*
|
|
23
|
+
* This function is primarily useful when working with the Storyblok Visual Editor
|
|
24
|
+
* and live preview updates in an Astro project.
|
|
25
|
+
*
|
|
26
|
+
* @param {Readonly<AstroGlobal>} Astro - The Astro global object.
|
|
27
|
+
* @returns {Promise<ISbStoryData | null>} The Storyblok story data if available,
|
|
28
|
+
* otherwise `null`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const story = await getLiveStory(Astro);
|
|
33
|
+
* if (story) {
|
|
34
|
+
* console.log('Previewing story:', story.name);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function getLiveStory(Astro: Readonly<AstroGlobal>): Promise<ISbStoryData | null>;
|
|
7
39
|
export declare function initStoryblokBridge(config: boolean | StoryblokBridgeConfigV2): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StoryblokRichTextNode, StoryblokRichTextResolvers } 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 {StoryblokRichTextResolvers} [customResolvers] - Optional custom resolvers
|
|
12
|
+
* for customizing how specific nodes or marks are transformed into HTML.
|
|
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, customResolvers?: StoryblokRichTextResolvers) => Promise<string>;
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
};
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type declarations bundled with the Storyblok Astro SDK.
|
|
3
|
+
* Provides IntelliSense, JSDoc, and type safety for SDK consumers.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare module '@storyblok/astro/StoryblokComponent.astro' {
|
|
7
|
+
import type { SbBlokData } from '@storyblok/astro';
|
|
8
|
+
|
|
9
|
+
function StoryblokComponent(
|
|
10
|
+
_props: Record<string, unknown> & {
|
|
11
|
+
/** The Storyblok blok data for this component (required) */
|
|
12
|
+
blok: SbBlokData;
|
|
13
|
+
}
|
|
14
|
+
): any;
|
|
15
|
+
|
|
16
|
+
/** Renders a dynamic Storyblok component */
|
|
17
|
+
export default StoryblokComponent;
|
|
18
|
+
}
|
|
19
|
+
declare module '@storyblok/astro/client' {
|
|
20
|
+
import type {
|
|
21
|
+
StoryblokClient,
|
|
22
|
+
StoryblokRichTextNode,
|
|
23
|
+
StoryblokRichTextResolvers,
|
|
24
|
+
} from '@storyblok/astro';
|
|
25
|
+
/**
|
|
26
|
+
* @experimental Converts a Storyblok RichText field into an HTML string.
|
|
27
|
+
*
|
|
28
|
+
* This API is still under development and may change in future releases.
|
|
29
|
+
* It also relies on Astro’s experimental
|
|
30
|
+
* [experimental_AstroContainer](https://docs.astro.build/en/reference/container-reference/) feature.
|
|
31
|
+
*
|
|
32
|
+
* @async
|
|
33
|
+
* @param {StoryblokRichTextNode} richTextField - The root RichText node to convert.
|
|
34
|
+
* @param {StoryblokRichTextResolvers} [customResolvers] - Optional custom resolvers
|
|
35
|
+
* for customizing how specific nodes or marks are transformed into HTML.
|
|
36
|
+
* @returns {Promise<string>} A promise that resolves to the HTML string representation
|
|
37
|
+
* of the provided RichText content.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```astro
|
|
41
|
+
* ---
|
|
42
|
+
* import { richTextToHTML } from '@storyblok/astro/client';
|
|
43
|
+
* const { blok } = Astro.props;
|
|
44
|
+
* const renderedRichText = await richTextToHTML(blok.text);
|
|
45
|
+
* ---
|
|
46
|
+
*
|
|
47
|
+
* <div set:html={renderedRichText} />
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function richTextToHTML(
|
|
51
|
+
richTextField: StoryblokRichTextNode,
|
|
52
|
+
customResolvers?: StoryblokRichTextResolvers
|
|
53
|
+
): Promise<string>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Provides direct access to the initialized Storyblok API client instance.
|
|
57
|
+
*
|
|
58
|
+
* This is useful when you need to call the Storyblok CDN API directly,
|
|
59
|
+
* for example inside an Astro API route, integration, or page code.
|
|
60
|
+
*
|
|
61
|
+
* @returns {StoryblokClient} The initialized Storyblok API client instance.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { storyblokApi } from '@storyblok/astro/client';
|
|
66
|
+
*
|
|
67
|
+
* const { data } = await storyblokApi.get('cdn/stories/home');
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export const storyblokApi: StoryblokClient;
|
|
71
|
+
}
|