@storyblok/nuxt 4.6.0 → 5.0.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/README.md CHANGED
@@ -72,11 +72,12 @@ export default defineNuxtConfig({
72
72
  });
73
73
  ```
74
74
 
75
+ > ⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
76
+
75
77
  #### Options
76
78
 
77
79
  When you initialize the module, you can pass all [_@storyblok/vue_ options](https://github.com/storyblok/storyblok-vue#storyblok-api) plus a `useApiClient` option. For spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
78
80
 
79
-
80
81
  ```js
81
82
  // Defaults
82
83
  ["@storyblok/nuxt", {
@@ -163,7 +164,7 @@ You can easily render rich text by using the `renderRichText` function that come
163
164
  </template>
164
165
 
165
166
  <script setup>
166
- const props = defineProps({ blok: Object })
167
+ const props = defineProps({ blok: Object });
167
168
  const articleContent = computed(() => renderRichText(blok.articleContent));
168
169
  </script>
169
170
  ```
@@ -172,27 +173,27 @@ You can also set a **custom Schema and component resolver** by passing the optio
172
173
 
173
174
  ```html
174
175
  <script setup>
175
- import cloneDeep from 'clone-deep'
176
+ import cloneDeep from "clone-deep";
176
177
 
177
- const mySchema = cloneDeep(RichTextSchema) // you can make a copy of the default RichTextSchema
178
+ const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
178
179
  // ... and edit the nodes and marks, or add your own.
179
180
  // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js
180
181
 
181
- const props = defineProps({ blok: Object })
182
+ const props = defineProps({ blok: Object });
182
183
 
183
184
  const articleContent = computed(() =>
184
185
  renderRichText(props.blok.articleContent, {
185
186
  schema: mySchema,
186
187
  resolver: (component, blok) => {
187
188
  switch (component) {
188
- case 'my-custom-component':
189
- return `<div class="my-component-class">${blok.text}</div>`
189
+ case "my-custom-component":
190
+ return `<div class="my-component-class">${blok.text}</div>`;
190
191
  default:
191
- return 'Resolver not defined'
192
+ return "Resolver not defined";
192
193
  }
193
- },
194
+ }
194
195
  })
195
- )
196
+ );
196
197
  </script>
197
198
  ```
198
199
 
package/dist/module.d.ts CHANGED
@@ -1,37 +1,26 @@
1
- import { resolve } from 'path';
2
- import { fileURLToPath } from 'url';
3
- import { defineNuxtModule, addComponentsDir, addPlugin, addImports, addImportsDir } from '@nuxt/kit';
4
-
5
- // -- Unbuild CommonJS Shims --
6
- import __cjs_url__ from 'url';
7
- import __cjs_path__ from 'path';
8
- import __cjs_mod__ from 'module';
9
- const __filename = __cjs_url__.fileURLToPath(import.meta.url);
10
- const __dirname = __cjs_path__.dirname(__filename);
11
- const require = __cjs_mod__.createRequire(import.meta.url);
12
-
1
+ import { defineNuxtModule, createResolver, addComponentsDir, addPlugin, addImports, addImportsDir } from '@nuxt/kit';
13
2
 
14
3
  var module = defineNuxtModule({
15
4
  meta: {
16
5
  name: "@storyblok/nuxt",
17
6
  configKey: "storyblok"
18
7
  },
19
- defaults: {},
8
+ defaults: {
9
+ usePlugin: true
10
+ },
20
11
  setup(options, nuxt) {
21
- const axiosIndex = nuxt.options.build.transpile.indexOf("axios");
22
- if (axiosIndex !== -1) {
23
- nuxt.options.build.transpile.splice(axiosIndex, 1);
24
- }
12
+ const resolver = createResolver(import.meta.url);
25
13
  nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [];
26
- nuxt.options.vite.optimizeDeps.include.push("axios");
14
+ nuxt.options.vite.optimizeDeps.include.push("@storyblok/nuxt");
15
+ nuxt.options.vite.optimizeDeps.include.push("@storyblok/vue");
27
16
  addComponentsDir({ path: "~/storyblok", global: true, pathPrefix: false });
28
- const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
29
- nuxt.options.build.transpile.push(runtimeDir);
17
+ nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
30
18
  nuxt.options.build.transpile.push("@storyblok/nuxt");
31
19
  nuxt.options.build.transpile.push("@storyblok/vue");
32
20
  nuxt.options.runtimeConfig.public.storyblok = options;
33
- if (options.usePlugin !== false)
34
- addPlugin(resolve(__dirname, "runtime", `./plugin`));
21
+ if (options.usePlugin !== false) {
22
+ addPlugin(resolver.resolve("./runtime/plugin"));
23
+ }
35
24
  const names = [
36
25
  "useStoryblok",
37
26
  "useStoryblokApi",
@@ -39,8 +28,10 @@ var module = defineNuxtModule({
39
28
  "renderRichText",
40
29
  "RichTextSchema"
41
30
  ];
42
- names.forEach((name) => addImports({ name, as: name, from: "@storyblok/vue" }));
43
- addImportsDir(resolve(runtimeDir, `./composables`));
31
+ for (const name of names) {
32
+ addImports({ name, as: name, from: "@storyblok/vue" });
33
+ }
34
+ addImportsDir(resolver.resolve("./runtime/composables"));
44
35
  }
45
36
  });
46
37
 
package/dist/module.mjs CHANGED
@@ -1,37 +1,26 @@
1
- import { resolve } from 'path';
2
- import { fileURLToPath } from 'url';
3
- import { defineNuxtModule, addComponentsDir, addPlugin, addImports, addImportsDir } from '@nuxt/kit';
4
-
5
- // -- Unbuild CommonJS Shims --
6
- import __cjs_url__ from 'url';
7
- import __cjs_path__ from 'path';
8
- import __cjs_mod__ from 'module';
9
- const __filename = __cjs_url__.fileURLToPath(import.meta.url);
10
- const __dirname = __cjs_path__.dirname(__filename);
11
- const require = __cjs_mod__.createRequire(import.meta.url);
12
-
1
+ import { defineNuxtModule, createResolver, addComponentsDir, addPlugin, addImports, addImportsDir } from '@nuxt/kit';
13
2
 
14
3
  const module = defineNuxtModule({
15
4
  meta: {
16
5
  name: "@storyblok/nuxt",
17
6
  configKey: "storyblok"
18
7
  },
19
- defaults: {},
8
+ defaults: {
9
+ usePlugin: true
10
+ },
20
11
  setup(options, nuxt) {
21
- const axiosIndex = nuxt.options.build.transpile.indexOf("axios");
22
- if (axiosIndex !== -1) {
23
- nuxt.options.build.transpile.splice(axiosIndex, 1);
24
- }
12
+ const resolver = createResolver(import.meta.url);
25
13
  nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [];
26
- nuxt.options.vite.optimizeDeps.include.push("axios");
14
+ nuxt.options.vite.optimizeDeps.include.push("@storyblok/nuxt");
15
+ nuxt.options.vite.optimizeDeps.include.push("@storyblok/vue");
27
16
  addComponentsDir({ path: "~/storyblok", global: true, pathPrefix: false });
28
- const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
29
- nuxt.options.build.transpile.push(runtimeDir);
17
+ nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
30
18
  nuxt.options.build.transpile.push("@storyblok/nuxt");
31
19
  nuxt.options.build.transpile.push("@storyblok/vue");
32
20
  nuxt.options.runtimeConfig.public.storyblok = options;
33
- if (options.usePlugin !== false)
34
- addPlugin(resolve(__dirname, "runtime", `./plugin`));
21
+ if (options.usePlugin !== false) {
22
+ addPlugin(resolver.resolve("./runtime/plugin"));
23
+ }
35
24
  const names = [
36
25
  "useStoryblok",
37
26
  "useStoryblokApi",
@@ -39,8 +28,10 @@ const module = defineNuxtModule({
39
28
  "renderRichText",
40
29
  "RichTextSchema"
41
30
  ];
42
- names.forEach((name) => addImports({ name, as: name, from: "@storyblok/vue" }));
43
- addImportsDir(resolve(runtimeDir, `./composables`));
31
+ for (const name of names) {
32
+ addImports({ name, as: name, from: "@storyblok/vue" });
33
+ }
34
+ addImportsDir(resolver.resolve("./runtime/composables"));
44
35
  }
45
36
  });
46
37
 
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
- "version": "4.6.0",
4
- "description": "Storyblok Nuxt.js module",
5
- "main": "./src/module.js",
6
- "module": "./src/module.js",
3
+ "version": "5.0.1",
4
+ "description": "Storyblok Nuxt module",
5
+ "type": "module",
7
6
  "exports": {
8
7
  ".": {
9
- "import": "./src/module.js",
10
- "require": "./src/module.js"
8
+ "import": "./dist/module.mjs",
9
+ "require": "./dist/module.cjs"
11
10
  }
12
11
  },
12
+ "main": "./dist/module.cjs",
13
+ "types": "./dist/types.d.ts",
13
14
  "files": [
14
- "src",
15
15
  "dist"
16
16
  ],
17
17
  "repository": "https://github.com/storyblok/storyblok-nuxt",
@@ -27,16 +27,16 @@
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.3.0"
30
+ "@storyblok/vue": "^7.0.0",
31
+ "@nuxt/kit": "^3.0.0"
31
32
  },
32
33
  "devDependencies": {
33
- "@nuxt/kit": "^3.0.0-rc.7",
34
34
  "@babel/core": "^7.15.0",
35
35
  "@nuxt/module-builder": "latest",
36
36
  "babel-jest": "^28.1.3",
37
37
  "cypress": "^8.3.0",
38
38
  "eslint-plugin-cypress": "^2.12.1",
39
- "jest": "^26.6.3",
39
+ "jest": "^29.3.1",
40
40
  "start-server-and-test": "^1.14.0",
41
41
  "vite": "^2.9.14"
42
42
  },
package/src/module.js DELETED
@@ -1,54 +0,0 @@
1
- import { resolve } from "path";
2
- import { fileURLToPath } from "url";
3
-
4
- import {
5
- defineNuxtModule,
6
- addPlugin,
7
- addComponentsDir,
8
- addImports,
9
- addImportsDir
10
- } from "@nuxt/kit";
11
-
12
- export default defineNuxtModule({
13
- meta: {
14
- name: "@storyblok/nuxt",
15
- configKey: "storyblok"
16
- },
17
- defaults: {},
18
- setup(options, nuxt) {
19
- const axiosIndex = nuxt.options.build.transpile.indexOf("axios");
20
- if (axiosIndex !== -1) {
21
- nuxt.options.build.transpile.splice(axiosIndex, 1);
22
- }
23
- nuxt.options.vite.optimizeDeps.include =
24
- nuxt.options.vite.optimizeDeps.include || [];
25
- nuxt.options.vite.optimizeDeps.include.push("axios");
26
-
27
- // Enable dirs
28
- // nuxt.options.components.dirs = ["~/components/storyblok"];
29
- addComponentsDir({ path: "~/storyblok", global: true, pathPrefix: false });
30
-
31
- const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
32
- nuxt.options.build.transpile.push(runtimeDir);
33
- nuxt.options.build.transpile.push("@storyblok/nuxt");
34
- nuxt.options.build.transpile.push("@storyblok/vue");
35
-
36
- // Add plugin
37
- nuxt.options.runtimeConfig.public.storyblok = options;
38
- if (options.usePlugin !== false)
39
- addPlugin(resolve(__dirname, "runtime", `./plugin`));
40
-
41
- // Autoimports
42
- const names = [
43
- "useStoryblok",
44
- "useStoryblokApi",
45
- "useStoryblokBridge",
46
- "renderRichText",
47
- "RichTextSchema"
48
- ];
49
- names.forEach((name) =>
50
- addImports({ name, as: name, from: "@storyblok/vue" })
51
- );
52
- addImportsDir(resolve(runtimeDir, `./composables`));
53
- }
54
- });
@@ -1,30 +0,0 @@
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 uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
10
- const story = useState(`${uniqueKey}-state`, () => null);
11
- const storyblokApiInstance = useStoryblokApi();
12
-
13
- onMounted(() => {
14
- if (story.value && story.value.id) {
15
- useStoryblokBridge(
16
- story.value.id,
17
- (evStory) => (story.value = evStory),
18
- bridgeOptions
19
- );
20
- }
21
- });
22
-
23
- const { data } = await useAsyncData(
24
- `${uniqueKey}-asyncdata`,
25
- async () => await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
26
- );
27
- story.value = data.value.data.story;
28
-
29
- return story;
30
- };
@@ -1,8 +0,0 @@
1
- import { StoryblokVue, apiPlugin } from "@storyblok/vue";
2
- import { defineNuxtPlugin, useRuntimeConfig } from "#app";
3
-
4
- export default defineNuxtPlugin(({ vueApp }) => {
5
- let { storyblok } = useRuntimeConfig();
6
- storyblok = JSON.parse(JSON.stringify(storyblok));
7
- vueApp.use(StoryblokVue, { ...storyblok, use: [apiPlugin] });
8
- });