@storyblok/nuxt 7.2.0 → 8.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
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ISbStoriesParams, ISbStoryData, StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
2
|
-
export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<import("vue").Ref<ISbStoryData<import("storyblok-js-client").ISbComponentType<string> & {
|
|
3
|
-
[index: string]: any;
|
|
4
|
-
}>, ISbStoryData<import("storyblok-js-client").ISbComponentType<string> & {
|
|
5
|
-
[index: string]: any;
|
|
6
|
-
}>>>;
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { computed, useAsyncData, watch } from "#imports";
|
|
3
|
+
const stableStringify = (obj) => {
|
|
4
|
+
const sortedKeys = Object.keys(obj).sort();
|
|
5
|
+
const sortedObj = sortedKeys.reduce((acc, key) => {
|
|
6
|
+
acc[key] = obj[key];
|
|
7
|
+
return acc;
|
|
8
|
+
}, {});
|
|
9
|
+
return JSON.stringify(sortedObj);
|
|
10
|
+
};
|
|
11
|
+
export const useAsyncStoryblok = async (url, options) => {
|
|
4
12
|
const storyblokApiInstance = useStoryblokApi();
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(evStory) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { data } = await useAsyncData(uniqueKey, () => {
|
|
18
|
-
return storyblokApiInstance.get(
|
|
19
|
-
`cdn/stories/${url}`,
|
|
20
|
-
apiOptions
|
|
21
|
-
);
|
|
13
|
+
const { api, bridge, ...rest } = options;
|
|
14
|
+
const uniqueKey = `${stableStringify(api)}${url}`;
|
|
15
|
+
const result = await useAsyncData(uniqueKey, () => storyblokApiInstance.get(`cdn/stories/${url}`, api), rest);
|
|
16
|
+
if (import.meta.client) {
|
|
17
|
+
watch(result.data, (newData) => {
|
|
18
|
+
if (newData?.data.story && newData.data.story.id) {
|
|
19
|
+
useStoryblokBridge(newData.data.story.id, (evStory) => {
|
|
20
|
+
newData.data.story = evStory;
|
|
21
|
+
}, bridge);
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
immediate: true
|
|
22
25
|
});
|
|
23
|
-
if (data) {
|
|
24
|
-
story.value = data.value?.data.story;
|
|
25
|
-
}
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return {
|
|
28
|
+
...result,
|
|
29
|
+
story: computed(() => result.data.value?.data.story)
|
|
30
|
+
};
|
|
28
31
|
};
|
package/dist/runtime/plugin.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "8.0.0",
|
|
5
5
|
"description": "Storyblok Nuxt module",
|
|
6
6
|
"homepage": "https://github.com/storyblok/monoblok/tree/main/packages/nuxt#readme",
|
|
7
7
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "nuxt-module-build prepare && nuxt-module-build build",
|
|
69
|
-
"dev": "nuxi dev playground",
|
|
69
|
+
"dev": "nuxi dev playground-e2e",
|
|
70
70
|
"dev:build": "nuxi build playground",
|
|
71
71
|
"dev:preview": "nuxi preview playground",
|
|
72
72
|
"prepare:playground": "nuxi prepare playground",
|