@storyblok/nuxt 10.1.9 → 11.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.
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -54,17 +54,15 @@ const module$1 = defineNuxtModule({
|
|
|
54
54
|
"renderRichText",
|
|
55
55
|
"StoryblokRichText",
|
|
56
56
|
"useStoryblokRichText",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"StoryblokRichTextNodeTypes",
|
|
67
|
-
"StoryblokRichTextOptions"
|
|
57
|
+
"SbRichTextDoc",
|
|
58
|
+
"SbRichTextImageOptions",
|
|
59
|
+
"SbRichTextMark",
|
|
60
|
+
"SbRichTextNode",
|
|
61
|
+
"SbRichTextProps",
|
|
62
|
+
"SbRichTextRenderContext",
|
|
63
|
+
"SbVueRichTextComponentMap",
|
|
64
|
+
"SbVueRichTextProps",
|
|
65
|
+
"SbVueRichTextRenderContext"
|
|
68
66
|
];
|
|
69
67
|
for (const name of names) {
|
|
70
68
|
addImports({ name, as: name, from: "@storyblok/vue" });
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { type ISbResult, type ISbStoriesParams, type StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
2
|
-
import { type ComputedRef, type Ref } from 'vue';
|
|
3
1
|
import type { AsyncDataOptions, NuxtError } from '#app';
|
|
2
|
+
import { type ISbResult, type ISbStoriesParams, type StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
3
|
+
import { type ComputedRef, type MaybeRefOrGetter, type Ref } from 'vue';
|
|
4
4
|
/**
|
|
5
5
|
* Options for the useAsyncStoryblok composable.
|
|
6
6
|
* Extends Nuxt's AsyncDataOptions with Storyblok-specific configuration.
|
|
7
7
|
*/
|
|
8
8
|
export interface UseAsyncStoryblokOptions extends AsyncDataOptions<ISbResult> {
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Storyblok API parameters for fetching stories.
|
|
11
|
+
*
|
|
12
|
+
* Accepts a plain object, a ref, a computed, or a getter. The current value
|
|
13
|
+
* is read (via `toValue`) on every fetch, so reactive params stay in sync.
|
|
14
|
+
* Note that changing a reactive value does not auto-refetch on its own —
|
|
15
|
+
* trigger a re-fetch by calling `refresh()` or by passing a `watch` option
|
|
16
|
+
* (e.g. `watch: [version]`), which Nuxt's `useAsyncData` re-runs on.
|
|
17
|
+
*/
|
|
18
|
+
api: MaybeRefOrGetter<ISbStoriesParams>;
|
|
11
19
|
/** Storyblok Bridge configuration for live preview */
|
|
12
20
|
bridge: StoryblokBridgeConfigV2;
|
|
13
21
|
}
|
|
@@ -63,6 +71,20 @@ export interface UseAsyncStoryblokResult {
|
|
|
63
71
|
* </template>
|
|
64
72
|
* ```
|
|
65
73
|
*
|
|
74
|
+
* @example
|
|
75
|
+
* Reactive params: pass a getter/computed and refetch when it changes.
|
|
76
|
+
* ```vue
|
|
77
|
+
* <script setup>
|
|
78
|
+
* const version = ref('draft')
|
|
79
|
+
* const { story, refresh } = await useAsyncStoryblok('home', {
|
|
80
|
+
* api: () => ({ version: version.value }),
|
|
81
|
+
* bridge: {},
|
|
82
|
+
* // re-fetch automatically when `version` changes
|
|
83
|
+
* watch: [version],
|
|
84
|
+
* })
|
|
85
|
+
* // ...or trigger manually: version.value = 'published'; await refresh()
|
|
86
|
+
* </script>
|
|
87
|
+
* ```
|
|
66
88
|
*/
|
|
67
89
|
export declare function useAsyncStoryblok(url: string, options: UseAsyncStoryblokOptions): Promise<UseAsyncStoryblokResult>;
|
|
68
90
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import { computed, watch } from "vue";
|
|
3
1
|
import { useAsyncData } from "#app";
|
|
2
|
+
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
3
|
+
import { computed, toValue, watch } from "vue";
|
|
4
4
|
const stableStringify = (obj) => {
|
|
5
5
|
const sortedKeys = Object.keys(obj).sort();
|
|
6
6
|
const sortedObj = sortedKeys.reduce((acc, key) => {
|
|
@@ -12,41 +12,34 @@ const stableStringify = (obj) => {
|
|
|
12
12
|
export async function useAsyncStoryblok(url, options) {
|
|
13
13
|
const storyblokApiInstance = useStoryblokApi();
|
|
14
14
|
const { api, bridge = {}, ...rest } = options;
|
|
15
|
-
const uniqueKey = `${stableStringify(api)}${url}`;
|
|
15
|
+
const uniqueKey = () => `${stableStringify(toValue(api))}${url}`;
|
|
16
16
|
const bridgeOptions = {
|
|
17
17
|
...bridge,
|
|
18
|
-
resolveRelations: bridge.resolveRelations ?? api.resolve_relations,
|
|
19
|
-
resolveLinks: bridge.resolveLinks ?? api.resolve_links
|
|
18
|
+
resolveRelations: bridge.resolveRelations ?? toValue(api).resolve_relations,
|
|
19
|
+
resolveLinks: bridge.resolveLinks ?? toValue(api).resolve_links
|
|
20
20
|
};
|
|
21
|
-
const result = await useAsyncData(uniqueKey, () => storyblokApiInstance.get(`cdn/stories/${url}`, api), rest);
|
|
21
|
+
const result = await useAsyncData(uniqueKey, () => storyblokApiInstance.get(`cdn/stories/${url}`, { ...toValue(api) }), rest);
|
|
22
22
|
if (import.meta.client) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
let registeredId;
|
|
24
|
+
watch(
|
|
25
|
+
() => result.data.value?.data?.story?.id,
|
|
26
|
+
(storyId) => {
|
|
27
|
+
if (!storyId || storyId === registeredId) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
registeredId = storyId;
|
|
31
|
+
useStoryblokBridge(storyId, (evStory) => {
|
|
32
|
+
if (!result.data.value) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
26
35
|
result.data.value = {
|
|
27
36
|
...result.data.value,
|
|
28
|
-
data: {
|
|
29
|
-
...result.data.value.data,
|
|
30
|
-
story: evStory
|
|
31
|
-
}
|
|
37
|
+
data: { ...result.data.value.data, story: evStory }
|
|
32
38
|
};
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (id) {
|
|
38
|
-
registerBridge(id);
|
|
39
|
-
} else {
|
|
40
|
-
const stopWatch = watch(
|
|
41
|
-
() => result.data.value?.data?.story?.id,
|
|
42
|
-
(storyId) => {
|
|
43
|
-
if (storyId) {
|
|
44
|
-
stopWatch();
|
|
45
|
-
registerBridge(storyId);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
}
|
|
39
|
+
}, bridgeOptions);
|
|
40
|
+
},
|
|
41
|
+
{ immediate: true }
|
|
42
|
+
);
|
|
50
43
|
}
|
|
51
44
|
return {
|
|
52
45
|
data: result.data,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "11.0.0",
|
|
5
5
|
"description": "Storyblok Nuxt module",
|
|
6
6
|
"homepage": "https://github.com/storyblok/monoblok/tree/main/packages/nuxt#readme",
|
|
7
7
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"nuxt": "^3.15.0 || ^4.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@storyblok/vue": "
|
|
33
|
+
"@storyblok/vue": "11.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@cypress/vite-dev-server": "^6.0.3",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"nuxt": "^4.2.2",
|
|
50
50
|
"prettier": "^3.4.2",
|
|
51
51
|
"start-server-and-test": "^2.0.11",
|
|
52
|
-
"@storyblok/eslint-config": "0.5.
|
|
52
|
+
"@storyblok/eslint-config": "0.5.1"
|
|
53
53
|
},
|
|
54
54
|
"release": {
|
|
55
55
|
"branches": [
|