@storyblok/nuxt 4.2.2 → 4.4.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/README.md CHANGED
@@ -114,11 +114,11 @@ To link your Vue components to their equivalent you created in Storyblok:
114
114
 
115
115
  #### Composition API
116
116
 
117
- The simplest way is by using the `useStoryblok` one-liner composable (it's autoimported) and passing as a first parameter a name of your content page from Storyblok (in this case, our content page name is `vue`, by default you get a content page named `home`):
117
+ The simplest way is by using the `useAsyncStoryblok` one-liner composable (it's autoimported) and passing as a first parameter a name of your content page from Storyblok (in this case, our content page name is `vue`, by default you get a content page named `home`):
118
118
 
119
119
  ```html
120
120
  <script setup>
121
- const story = await useStoryblok("vue", { version: "draft" });
121
+ const story = await useAsyncStoryblok("vue", { version: "draft" });
122
122
  </script>
123
123
 
124
124
  <template>
@@ -126,16 +126,19 @@ The simplest way is by using the `useStoryblok` one-liner composable (it's autoi
126
126
  </template>
127
127
  ```
128
128
 
129
- Which is the short-hand equivalent to using `useStoryblokApi` and `useStoryblokBridge` functions separately:
129
+ Which is the short-hand equivalent to using `useStoryblokApi` inside `useAsyncData` and `useStoryblokBridge` functions separately:
130
130
 
131
131
  ```html
132
132
  <script setup>
133
133
  const story = ref(null);
134
134
  const storyblokApi = useStoryblokApi();
135
- const { data } = await storyblokApi.get("cdn/stories/vue", {
135
+ const { data } = await useAsyncData(
136
+ 'vue',
137
+ async () => await storyblokApi.get(`cdn/stories/vue`, {
136
138
  version: "draft"
137
- });
138
- story.value = data.story;
139
+ })
140
+ );
141
+ story.value = data.value.data.story;
139
142
 
140
143
  onMounted(() => {
141
144
  useStoryblokBridge(story.value.id, (evStory) => (story.value = evStory));
@@ -147,6 +150,8 @@ Which is the short-hand equivalent to using `useStoryblokApi` and `useStoryblokB
147
150
  </template>
148
151
  ```
149
152
 
153
+ > Using `useAsyncData` SSR and SSG capabilities are enabled.
154
+
150
155
  #### Rendering Rich Text
151
156
 
152
157
  You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/nuxt` and a Vue computed property:
@@ -163,8 +168,16 @@ You can easily render rich text by using the `renderRichText` function that come
163
168
 
164
169
  ### API
165
170
 
171
+ #### useAsyncStoryblok(slug, apiOptions, bridgeOptions)
172
+
173
+ (Recommended Option) Use [`useAsyncData`](https://v3.nuxtjs.org/api/composables/use-async-data/) and [`useState`](https://v3.nuxtjs.org/api/composables/use-state) under the hood for generating SSR or SSG applications.
174
+
175
+ Check the available [apiOptions](https://github.com/storyblok/storyblok-js-client#class-storyblok) (passed to `storyblok-js-client`) and [bridgeOptions](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-nuxt) (passed to the Storyblok Bridge).
176
+
166
177
  #### useStoryblok(slug, apiOptions, bridgeOptions)
167
178
 
179
+ It could be helpful to use `useStoryblok` instead of `useAsyncStoryblok` when we need to make client-side requests, for example, getting personalized data for a logged user.
180
+
168
181
  Check the available [apiOptions](https://github.com/storyblok/storyblok-js-client#class-storyblok) (passed to `storyblok-js-client`) and [bridgeOptions](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-nuxt) (passed to the Storyblok Bridge).
169
182
 
170
183
  #### useStoryblokApi()
package/dist/module.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
- import { defineNuxtModule, addComponentsDir, addPlugin, addAutoImport } from '@nuxt/kit';
3
+ import { defineNuxtModule, addComponentsDir, addPlugin, addAutoImport, addAutoImportDir } from '@nuxt/kit';
4
4
 
5
5
  // -- Unbuild CommonJS Shims --
6
6
  import __cjs_url__ from 'url';
@@ -37,6 +37,7 @@ var module = defineNuxtModule({
37
37
  "renderRichText"
38
38
  ];
39
39
  names.forEach((name) => addAutoImport({ name, as: name, from: "@storyblok/vue" }));
40
+ addAutoImportDir(resolve(runtimeDir, `./composables`));
40
41
  }
41
42
  });
42
43
 
package/dist/module.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
- import { defineNuxtModule, addComponentsDir, addPlugin, addAutoImport } from '@nuxt/kit';
3
+ import { defineNuxtModule, addComponentsDir, addPlugin, addAutoImport, addAutoImportDir } from '@nuxt/kit';
4
4
 
5
5
  // -- Unbuild CommonJS Shims --
6
6
  import __cjs_url__ from 'url';
@@ -37,6 +37,7 @@ const module = defineNuxtModule({
37
37
  "renderRichText"
38
38
  ];
39
39
  names.forEach((name) => addAutoImport({ name, as: name, from: "@storyblok/vue" }));
40
+ addAutoImportDir(resolve(runtimeDir, `./composables`));
40
41
  }
41
42
  });
42
43
 
@@ -0,0 +1 @@
1
+ export function useAsyncStoryblok(url: any, apiOptions?: {}, bridgeOptions?: {}): Promise<any>;
@@ -0,0 +1,29 @@
1
+ import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
2
+ import { useAsyncData, useState, onMounted } from "#imports";
3
+
4
+ export const useAsyncStoryblok = async (
5
+ url,
6
+ apiOptions = {},
7
+ bridgeOptions = {}
8
+ ) => {
9
+ const story = useState(url, () => null);
10
+ const storyblokApiInstance = useStoryblokApi();
11
+
12
+ onMounted(() => {
13
+ if (story.value && story.value.id) {
14
+ useStoryblokBridge(
15
+ story.value.id,
16
+ (evStory) => (story.value = evStory),
17
+ bridgeOptions
18
+ );
19
+ }
20
+ });
21
+
22
+ const { data } = await useAsyncData(
23
+ url,
24
+ async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
25
+ );
26
+ story.value = data.value.data.story;
27
+
28
+ return story;
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
- "version": "4.2.2",
3
+ "version": "4.4.0",
4
4
  "description": "Storyblok Nuxt.js module",
5
5
  "main": "./src/module.js",
6
6
  "module": "./src/module.js",
@@ -27,7 +27,7 @@
27
27
  "test:e2e-watch": "start-server-and-test playground:run http://localhost:3000 cy:open"
28
28
  },
29
29
  "dependencies": {
30
- "@storyblok/vue": "^6.2.1"
30
+ "@storyblok/vue": "^6.3.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@nuxt/kit": "^3.0.0-rc.7",
package/src/module.js CHANGED
@@ -5,7 +5,8 @@ import {
5
5
  defineNuxtModule,
6
6
  addPlugin,
7
7
  addComponentsDir,
8
- addAutoImport
8
+ addAutoImport,
9
+ addAutoImportDir
9
10
  } from "@nuxt/kit";
10
11
 
11
12
  export default defineNuxtModule({
@@ -46,5 +47,6 @@ export default defineNuxtModule({
46
47
  names.forEach((name) =>
47
48
  addAutoImport({ name, as: name, from: "@storyblok/vue" })
48
49
  );
50
+ addAutoImportDir(resolve(runtimeDir, `./composables`));
49
51
  }
50
52
  });
@@ -0,0 +1,29 @@
1
+ import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
2
+ import { useAsyncData, useState, onMounted } from "#imports";
3
+
4
+ export const useAsyncStoryblok = async (
5
+ url,
6
+ apiOptions = {},
7
+ bridgeOptions = {}
8
+ ) => {
9
+ const story = useState(url, () => null);
10
+ const storyblokApiInstance = useStoryblokApi();
11
+
12
+ onMounted(() => {
13
+ if (story.value && story.value.id) {
14
+ useStoryblokBridge(
15
+ story.value.id,
16
+ (evStory) => (story.value = evStory),
17
+ bridgeOptions
18
+ );
19
+ }
20
+ });
21
+
22
+ const { data } = await useAsyncData(
23
+ url,
24
+ async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
25
+ );
26
+ story.value = data.value.data.story;
27
+
28
+ return story;
29
+ };