@storyblok/astro 5.1.2 → 6.0.0-next.2

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/README.md CHANGED
@@ -52,7 +52,7 @@ Add the following code to `astro.config.mjs` and replace the `accessToken` with
52
52
 
53
53
  ```js
54
54
  import { defineConfig } from "astro/config";
55
- import storyblok from "@storyblok/astro";
55
+ import { storyblok } from "@storyblok/astro";
56
56
 
57
57
  export default defineConfig({
58
58
  integrations: [
@@ -75,6 +75,7 @@ When you initialize the integration, you can pass all [_@storyblok/js_ options](
75
75
  storyblok({
76
76
  accessToken: "<your-access-token>",
77
77
  bridge: true,
78
+ livePreview: false,
78
79
  apiOptions: {}, // storyblok-js-client options
79
80
  components: {},
80
81
  componentsDir: "src",
@@ -174,7 +175,7 @@ const { blok } = Astro.props
174
175
  ---
175
176
 
176
177
  <main {...storyblokEditable(blok)}>
177
- {blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
178
+ {blok.body?.map(blok => {return <StoryblokComponent blok={blok} />})}
178
179
  </main>
179
180
  ```
180
181
 
@@ -214,7 +215,7 @@ const { data } = await storyblokApi.get("cdn/stories/home", {
214
215
  const story = data.story;
215
216
  ---
216
217
 
217
- <StoryblokComponent blok="{story.content}" />
218
+ <StoryblokComponent blok={story.content} />
218
219
  ```
219
220
 
220
221
  > [!NOTE]
@@ -256,16 +257,13 @@ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
256
257
  const story = data.story;
257
258
  ---
258
259
 
259
- <StoryblokComponent blok="{story.content}" />
260
+ <StoryblokComponent blok={story.content} />
260
261
  ```
261
262
 
262
263
  ### Using the Storyblok Bridge
263
264
 
264
265
  The Storyblok Bridge is enabled by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `true` or `false` in `astro.config.mjs`:
265
266
 
266
- > [!NOTE]
267
- > Since Astro is not a reactive JavaScript framework and renders everything as HTML, the Storyblok Bridge will not provide real-time editing as you may know it from other frameworks. However, it automatically refreshes the site for you whenever you save or publish a story.
268
-
269
267
  You can also provide a `StoryblokBridgeConfigV2` configuration object to the `bridge` parameter.
270
268
 
271
269
  ```ts
@@ -306,7 +304,7 @@ const { blok } = Astro.props
306
304
  const renderedRichText = renderRichText(blok.text)
307
305
  ---
308
306
 
309
- <div set:html="{renderedRichText}"></div>
307
+ <div set:html={renderedRichText}></div>
310
308
  ```
311
309
 
312
310
  You can also set a **custom Schema and component resolver** by passing the options as the second parameter of the `renderRichText` function:
@@ -350,9 +348,6 @@ Returns the instance of the `storyblok-js-client`.
350
348
 
351
349
  ## Enabling Live Preview for Storyblok's Visual Editor
352
350
 
353
- > [!WARNING]
354
- > This feature is currently experimental and optional. You may encounters bugs or performance issues.
355
-
356
351
  The Astro SDK now provides a live preview feature, designed to offer real-time editing capabilities for an enhanced user experience in Storyblok's Visual Editor.
357
352
 
358
353
  > [!NOTE]
@@ -375,28 +370,33 @@ export default defineConfig({
375
370
  });
376
371
  ```
377
372
 
378
- 2. Additionally, please use `useStoryblok` on your Astro pages for story fetching. This replaces the previously used `useStoryblokApi` method.
373
+ 2. Additionally, please use `getLiveStory` on your Astro pages for live story fetching.
379
374
 
380
375
  ```jsx
381
376
  //pages/[...slug].astro
382
377
  ---
383
- import { useStoryblok } from "@storyblok/astro";
378
+ import {
379
+ getLiveStory,
380
+ useStoryblokApi,
381
+ type ISbStoryData,
382
+ } from '@storyblok/astro';
384
383
  import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
385
384
 
386
385
  const { slug } = Astro.params;
387
-
388
- const story = await useStoryblok(
389
- // The slug to fetch
390
- `cdn/stories/${slug === undefined ? "home" : slug}`,
391
- // The API options
392
- {
393
- version: "draft",
394
- },
395
- // The Bridge options (optional, if an empty object, null, or false are set, the API options will be considered automatically as far as applicable)
396
- {},
397
- // The Astro object (essential for the live preview functionality)
398
- Astro
399
- );
386
+ let story: ISbStoryData | null = null;
387
+
388
+ const liveStory = await getLiveStory(Astro);
389
+ if (liveStory) {
390
+ story = liveStory;
391
+ } else {
392
+ const sbApi = useStoryblokApi();
393
+ const { data } = await sbApi.get(`cdn/stories/${slug || 'home'}`, {
394
+ version: 'draft',
395
+ resolve_relations: ['featured-articles.posts'],
396
+ });
397
+ story = data?.story;
398
+ }
399
+ // If you are using `resolve_relations` or `resolve_links`, you must also pass them to the Bridge configuration in `astro.config.mjs`.
400
400
  ---
401
401
 
402
402
  <StoryblokComponent blok={story.content} />
package/dist/index.d.ts CHANGED
@@ -1,60 +1,7 @@
1
- import { AstroGlobal, AstroIntegration } from 'astro';
2
- import { ISbConfig, ISbRichtext, ISbStoriesParams, ISbStoryData, SbRichTextOptions, StoryblokBridgeConfigV2, StoryblokClient } from './types';
1
+ import { default as storyblokIntegration } from './lib/storyblok-integration';
2
+ export { getLiveStory, renderRichText, useStoryblokApi } from './lib/helpers';
3
3
  export { handleStoryblokMessage } from './live-preview/handleStoryblokMessage';
4
4
  export * from './types';
5
5
  export { toCamelCase } from './utils/toCamelCase';
6
6
  export { loadStoryblokBridge, RichTextResolver, RichTextSchema, storyblokEditable, } from '@storyblok/js';
7
- export declare function useStoryblokApi(): StoryblokClient;
8
- export declare function useStoryblok(slug: string, apiOptions: ISbStoriesParams | undefined, _: StoryblokBridgeConfigV2 | undefined, Astro: AstroGlobal): Promise<ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
9
- [index: string]: any;
10
- }> | null>;
11
- export declare function renderRichText(data?: ISbRichtext, options?: SbRichTextOptions): string;
12
- export interface IntegrationOptions {
13
- /**
14
- * The access token from your space.
15
- */
16
- accessToken: string;
17
- /**
18
- * If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
19
- */
20
- useCustomApi?: boolean;
21
- /**
22
- * Set custom API options here (cache, region, and more). All options are documented [here](https://github.com/storyblok/storyblok-js-client#class-storyblok).
23
- */
24
- apiOptions?: ISbConfig;
25
- /**
26
- * A boolean to enable/disable the Storyblok JavaScript Bridge or provide a StoryblokBridgeConfigV2 configuration object. Enabled by default.
27
- */
28
- bridge?: boolean | StoryblokBridgeConfigV2;
29
- /**
30
- * An object containing your Astro components to their Storyblok equivalents.
31
- * Example:
32
- * ```js
33
- * components: {
34
- * page: "storyblok/Page",
35
- * feature: "storyblok/Feature",
36
- * grid: "storyblok/Grid",
37
- * teaser: "storyblok/Teaser",
38
- * },
39
- * ```
40
- */
41
- components?: Record<string, string>;
42
- /**
43
- * The directory containing your Astro components are. Defaults to "src".
44
- */
45
- componentsDir?: string;
46
- /**
47
- * Show a fallback component in your frontend if a component is not registered properly.
48
- */
49
- enableFallbackComponent?: boolean;
50
- /**
51
- * Provide a path to a custom fallback component, e.g. "storyblok/customFallback".
52
- * Please note: the path takes into account the `componentsDir` option.
53
- */
54
- customFallbackComponent?: string;
55
- /**
56
- * A boolean to enable/disable the Experimental Live Preview feature. Disabled by default.
57
- */
58
- livePreview?: boolean;
59
- }
60
- export default function storyblokIntegration(options: IntegrationOptions): AstroIntegration;
7
+ export { storyblokIntegration as storyblok };
@@ -0,0 +1,8 @@
1
+ import { ISbRichtext, ISbStoryData, SbRichTextOptions, StoryblokBridgeConfigV2, StoryblokClient } from '../types';
2
+ import { AstroGlobal } from 'astro';
3
+ export declare function useStoryblokApi(): StoryblokClient;
4
+ export declare function getLiveStory(Astro: AstroGlobal): Promise<ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
5
+ [index: string]: any;
6
+ }> | null>;
7
+ export declare function renderRichText(data?: ISbRichtext, options?: SbRichTextOptions): string;
8
+ export declare function initStoryblokBridge(config: boolean | StoryblokBridgeConfigV2): string;
@@ -0,0 +1,51 @@
1
+ import { ISbConfig, StoryblokBridgeConfigV2 } from '@storyblok/js';
2
+ import { AstroIntegration } from 'astro';
3
+ export interface IntegrationOptions {
4
+ /**
5
+ * The access token from your space.
6
+ */
7
+ accessToken: string;
8
+ /**
9
+ * If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
10
+ */
11
+ useCustomApi?: boolean;
12
+ /**
13
+ * Set custom API options here (cache, region, and more). All options are documented [here](https://github.com/storyblok/storyblok-js-client#class-storyblok).
14
+ */
15
+ apiOptions?: ISbConfig;
16
+ /**
17
+ * A boolean to enable/disable the Storyblok JavaScript Bridge or provide a StoryblokBridgeConfigV2 configuration object. Enabled by default.
18
+ */
19
+ bridge?: boolean | StoryblokBridgeConfigV2;
20
+ /**
21
+ * An object containing your Astro components to their Storyblok equivalents.
22
+ * Example:
23
+ * ```js
24
+ * components: {
25
+ * page: "storyblok/Page",
26
+ * feature: "storyblok/Feature",
27
+ * grid: "storyblok/Grid",
28
+ * teaser: "storyblok/Teaser",
29
+ * },
30
+ * ```
31
+ */
32
+ components?: Record<string, string>;
33
+ /**
34
+ * The directory containing your Astro components are. Defaults to "src".
35
+ */
36
+ componentsDir?: string;
37
+ /**
38
+ * Show a fallback component in your frontend if a component is not registered properly.
39
+ */
40
+ enableFallbackComponent?: boolean;
41
+ /**
42
+ * Provide a path to a custom fallback component, e.g. "storyblok/customFallback".
43
+ * Please note: the path takes into account the `componentsDir` option.
44
+ */
45
+ customFallbackComponent?: string;
46
+ /**
47
+ * A boolean to enable/disable the Experimental Live Preview feature. Disabled by default.
48
+ */
49
+ livePreview?: boolean;
50
+ }
51
+ export default function storyblokIntegration(options: IntegrationOptions): AstroIntegration;