@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,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
3
  "configKey": "storyblok",
4
- "version": "7.2.0",
4
+ "version": "8.0.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
@@ -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 { onMounted, useAsyncData, useState } from "#imports";
3
- export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
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 uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
6
- const story = useState(`${uniqueKey}-state`);
7
- onMounted(() => {
8
- if (story.value && story.value.id) {
9
- useStoryblokBridge(
10
- story.value.id,
11
- (evStory) => story.value = evStory,
12
- bridgeOptions
13
- );
14
- }
15
- });
16
- if (!story.value) {
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 story;
27
+ return {
28
+ ...result,
29
+ story: computed(() => result.data.value?.data.story)
30
+ };
28
31
  };
@@ -1,2 +1,2 @@
1
- declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
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": "7.2.0",
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",