@storyblok/nuxt 7.1.0 → 7.1.1
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 +1,8 @@
|
|
|
1
1
|
import type { ISbStoriesParams, ISbStoryData, StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
2
|
+
interface StoryblokAsyncResult<T = ISbStoryData> {
|
|
3
|
+
value: T;
|
|
4
|
+
status?: number;
|
|
5
|
+
response?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<StoryblokAsyncResult>;
|
|
8
|
+
export {};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import { onMounted, useAsyncData, useState } from "#imports";
|
|
2
|
+
import { onMounted, reactive, useAsyncData, useState } from "#imports";
|
|
3
3
|
export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
|
|
4
4
|
const storyblokApiInstance = useStoryblokApi();
|
|
5
5
|
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
|
|
6
6
|
const story = useState(`${uniqueKey}-state`);
|
|
7
|
+
const error = useState(`${uniqueKey}-error`);
|
|
7
8
|
onMounted(() => {
|
|
8
9
|
if (story.value && story.value.id) {
|
|
9
10
|
useStoryblokBridge(
|
|
@@ -14,15 +15,43 @@ export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}
|
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
17
|
if (!story.value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
try {
|
|
19
|
+
const { data } = await useAsyncData(uniqueKey, () => {
|
|
20
|
+
return storyblokApiInstance.get(
|
|
21
|
+
`cdn/stories/${url}`,
|
|
22
|
+
apiOptions
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
if (data) {
|
|
26
|
+
story.value = data.value?.data.story;
|
|
27
|
+
error.value = null;
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (typeof err === "object" && err !== null && "status" in err && "response" in err) {
|
|
31
|
+
error.value = {
|
|
32
|
+
status: err.status || err.response?.status,
|
|
33
|
+
response: err.message || err.response?.statusText
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
error.value = {
|
|
37
|
+
status: void 0,
|
|
38
|
+
response: "An unknown error occurred"
|
|
39
|
+
};
|
|
40
|
+
}
|
|
25
41
|
}
|
|
26
42
|
}
|
|
27
|
-
return
|
|
43
|
+
return reactive({
|
|
44
|
+
get value() {
|
|
45
|
+
return story.value;
|
|
46
|
+
},
|
|
47
|
+
set value(newValue) {
|
|
48
|
+
story.value = newValue;
|
|
49
|
+
},
|
|
50
|
+
get status() {
|
|
51
|
+
return error.value?.status;
|
|
52
|
+
},
|
|
53
|
+
get response() {
|
|
54
|
+
return error.value?.response;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
28
57
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/nuxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.1.
|
|
4
|
+
"version": "7.1.1",
|
|
5
5
|
"description": "Storyblok Nuxt module",
|
|
6
6
|
"homepage": "https://github.com/storyblok/monoblok/tree/main/packages/nuxt#readme",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@storyblok/vue": "9.1.
|
|
28
|
+
"@storyblok/vue": "9.1.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@cypress/vite-dev-server": "^6.0.3",
|