@storyblok/nuxt 6.1.0 → 6.2.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/README.md
CHANGED
|
@@ -44,11 +44,11 @@ npx nuxi@latest module add storyblok
|
|
|
44
44
|
Add following code to modules section of `nuxt.config.js` and replace the accessToken with API token from Storyblok space.
|
|
45
45
|
|
|
46
46
|
```js
|
|
47
|
-
import { defineNuxtConfig } from
|
|
47
|
+
import { defineNuxtConfig } from 'nuxt';
|
|
48
48
|
|
|
49
49
|
export default defineNuxtConfig({
|
|
50
50
|
modules: [
|
|
51
|
-
[
|
|
51
|
+
['@storyblok/nuxt', { accessToken: '<your-access-token>' }]
|
|
52
52
|
// ...
|
|
53
53
|
]
|
|
54
54
|
});
|
|
@@ -57,12 +57,12 @@ export default defineNuxtConfig({
|
|
|
57
57
|
You can also use the `storyblok` config if you prefer:
|
|
58
58
|
|
|
59
59
|
```js
|
|
60
|
-
import { defineNuxtConfig } from
|
|
60
|
+
import { defineNuxtConfig } from 'nuxt';
|
|
61
61
|
|
|
62
62
|
export default defineNuxtConfig({
|
|
63
|
-
modules: [
|
|
63
|
+
modules: ['@storyblok/nuxt'],
|
|
64
64
|
storyblok: {
|
|
65
|
-
accessToken:
|
|
65
|
+
accessToken: '<your-access-token>'
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
```
|
|
@@ -97,9 +97,9 @@ While the recommended approach covers most cases, there are specific instances w
|
|
|
97
97
|
// nuxt.config.ts
|
|
98
98
|
modules: [
|
|
99
99
|
[
|
|
100
|
-
|
|
100
|
+
'@storyblok/nuxt',
|
|
101
101
|
{
|
|
102
|
-
accessToken:
|
|
102
|
+
accessToken: '<your-access-token>',
|
|
103
103
|
enableSudoMode: true
|
|
104
104
|
}
|
|
105
105
|
]
|
|
@@ -110,17 +110,17 @@ To include additional functionalities in the SDK's `apiOptions`, such as custom
|
|
|
110
110
|
|
|
111
111
|
```js
|
|
112
112
|
// plugins/storyblok.js
|
|
113
|
-
import {
|
|
113
|
+
import { apiPlugin, StoryblokVue } from '@storyblok/vue';
|
|
114
114
|
|
|
115
115
|
export default defineNuxtPlugin(({ vueApp }) => {
|
|
116
116
|
vueApp.use(StoryblokVue, {
|
|
117
|
-
accessToken:
|
|
117
|
+
accessToken: '<your-access-token>',
|
|
118
118
|
apiOptions: {
|
|
119
119
|
cache: {
|
|
120
|
-
type:
|
|
120
|
+
type: 'custom',
|
|
121
121
|
custom: {
|
|
122
122
|
flush() {
|
|
123
|
-
console.log(
|
|
123
|
+
console.log('all right');
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -271,6 +271,95 @@ Which is the short-hand equivalent to using `useStoryblokApi` inside `useState`
|
|
|
271
271
|
|
|
272
272
|
## Rendering Rich Text
|
|
273
273
|
|
|
274
|
+
You can render rich text fields by using the `StoryblokRichText` component:
|
|
275
|
+
|
|
276
|
+
```html
|
|
277
|
+
<template>
|
|
278
|
+
<StoryblokRichText :doc="blok.articleContent" />
|
|
279
|
+
</template>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Or you can have more control by using the `useStoryblokRichText` composable:
|
|
283
|
+
|
|
284
|
+
```html
|
|
285
|
+
<script setup>
|
|
286
|
+
const { render } = useStoryblokRichText({
|
|
287
|
+
// options like resolvers
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
const root = () => render(blok.articleContent);
|
|
291
|
+
</script>
|
|
292
|
+
|
|
293
|
+
<template>
|
|
294
|
+
<root />
|
|
295
|
+
</template>
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
For more incredible options you can pass to the `useStoryblokRichText`, please consult the [Full options](https://github.com/storyblok/richtext?tab=readme-ov-file#options) documentation.
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
#### Overriding the default resolvers
|
|
302
|
+
|
|
303
|
+
You can override the default resolvers by passing a `resolver` prop to the `StoryblokRichText` component, for example, to use vue-router links or add a custom codeblok component: :
|
|
304
|
+
|
|
305
|
+
```html
|
|
306
|
+
<script setup>
|
|
307
|
+
import { NuxtLink } from '#components';
|
|
308
|
+
import type { StoryblokRichTextNode } from '@storyblok/vue';
|
|
309
|
+
import CodeBlok from "./components/CodeBlok.vue";
|
|
310
|
+
|
|
311
|
+
const resolvers = {
|
|
312
|
+
// NuxtLink example:
|
|
313
|
+
[MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) =>
|
|
314
|
+
h(NuxtLink, {
|
|
315
|
+
to: node.attrs?.href,
|
|
316
|
+
target: node.attrs?.target,
|
|
317
|
+
}, node.text),
|
|
318
|
+
// Custom code block component example:
|
|
319
|
+
[BlockTypes.CODE_BLOCK]: (node: Node) => {
|
|
320
|
+
return h(CodeBlock, {
|
|
321
|
+
class: node?.attrs?.class,
|
|
322
|
+
}, node.children)
|
|
323
|
+
},
|
|
324
|
+
}
|
|
325
|
+
</script>
|
|
326
|
+
|
|
327
|
+
<template>
|
|
328
|
+
<StoryblokRichText :doc="blok.articleContent" :resolvers="resolvers" />
|
|
329
|
+
</template>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
If you want to use the `useStoryblokRichText` composable, you can pass the `resolvers` via the options object:
|
|
333
|
+
|
|
334
|
+
```html
|
|
335
|
+
<script setup>
|
|
336
|
+
import CodeBlok from "./components/CodeBlok.vue";
|
|
337
|
+
|
|
338
|
+
const { render } = useStoryblokRichText({
|
|
339
|
+
resolvers: {
|
|
340
|
+
// NuxtLink example:
|
|
341
|
+
[MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) =>
|
|
342
|
+
h(NuxtLink, {
|
|
343
|
+
to: node.attrs?.href,
|
|
344
|
+
target: node.attrs?.target,
|
|
345
|
+
}, node.text),
|
|
346
|
+
// Custom code block component example:
|
|
347
|
+
[BlockTypes.CODE_BLOCK]: (node: Node) =>
|
|
348
|
+
h(CodeBlock, {
|
|
349
|
+
class: node?.attrs?.class,
|
|
350
|
+
}, node.children)
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const root = () => render(blok.articleContent);
|
|
355
|
+
</script>
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Legacy Rendering Rich Text
|
|
359
|
+
|
|
360
|
+
> [!WARNING]
|
|
361
|
+
> The legacy `richTextResolver` is soon to be deprecated. We recommend migrating to the new approach described above instead.
|
|
362
|
+
|
|
274
363
|
You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/nuxt` and a Vue computed property:
|
|
275
364
|
|
|
276
365
|
```html
|
|
@@ -280,9 +369,7 @@ You can easily render rich text by using the `renderRichText` function that come
|
|
|
280
369
|
|
|
281
370
|
<script setup>
|
|
282
371
|
const props = defineProps({ blok: Object });
|
|
283
|
-
const articleContent = computed(() =>
|
|
284
|
-
renderRichText(props.blok.articleContent)
|
|
285
|
-
);
|
|
372
|
+
const articleContent = computed(() => renderRichText(props.blok.articleContent));
|
|
286
373
|
</script>
|
|
287
374
|
```
|
|
288
375
|
|
|
@@ -290,7 +377,7 @@ You can also set a **custom Schema and component resolver** by passing the optio
|
|
|
290
377
|
|
|
291
378
|
```html
|
|
292
379
|
<script setup>
|
|
293
|
-
import cloneDeep from
|
|
380
|
+
import cloneDeep from 'clone-deep';
|
|
294
381
|
|
|
295
382
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
296
383
|
// ... and edit the nodes and marks, or add your own.
|
|
@@ -303,13 +390,13 @@ You can also set a **custom Schema and component resolver** by passing the optio
|
|
|
303
390
|
schema: mySchema,
|
|
304
391
|
resolver: (component, blok) => {
|
|
305
392
|
switch (component) {
|
|
306
|
-
case
|
|
393
|
+
case 'my-custom-component':
|
|
307
394
|
return `<div class="my-component-class">${blok.text}</div>`;
|
|
308
395
|
default:
|
|
309
|
-
return
|
|
396
|
+
return 'Resolver not defined';
|
|
310
397
|
}
|
|
311
|
-
}
|
|
312
|
-
})
|
|
398
|
+
},
|
|
399
|
+
}),
|
|
313
400
|
);
|
|
314
401
|
</script>
|
|
315
402
|
```
|
|
@@ -333,7 +420,7 @@ In your `nuxt.config.ts`:
|
|
|
333
420
|
export default defineNuxtConfig({
|
|
334
421
|
runtimeConfig: {
|
|
335
422
|
public: {
|
|
336
|
-
storyblokVersion: process.env.STORYBLOK_VERSION ||
|
|
423
|
+
storyblokVersion: process.env.STORYBLOK_VERSION || 'published'
|
|
337
424
|
}
|
|
338
425
|
}
|
|
339
426
|
});
|
|
@@ -345,19 +432,19 @@ Then you can access the runtime config in your components:
|
|
|
345
432
|
const config = useRuntimeConfig();
|
|
346
433
|
|
|
347
434
|
const story = await useAsyncStoryblok(
|
|
348
|
-
|
|
435
|
+
'blog',
|
|
349
436
|
{
|
|
350
437
|
version: config.public.storyblokVersion,
|
|
351
|
-
resolve_relations:
|
|
438
|
+
resolve_relations: 'overview.featured_story'
|
|
352
439
|
},
|
|
353
|
-
{ resolveRelations:
|
|
440
|
+
{ resolveRelations: 'overview.featured_story' }
|
|
354
441
|
);
|
|
355
442
|
|
|
356
|
-
//or
|
|
443
|
+
// or
|
|
357
444
|
|
|
358
|
-
const { data: articles } = await storyblokApi.get(
|
|
445
|
+
const { data: articles } = await storyblokApi.get('cdn/stories', {
|
|
359
446
|
version: config.public.storyblokVersion,
|
|
360
|
-
starts_with:
|
|
447
|
+
starts_with: 'blog',
|
|
361
448
|
is_startpage: false
|
|
362
449
|
});
|
|
363
450
|
```
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -39,7 +39,13 @@ const module = defineNuxtModule({
|
|
|
39
39
|
"useStoryblokApi",
|
|
40
40
|
"useStoryblokBridge",
|
|
41
41
|
"renderRichText",
|
|
42
|
-
"RichTextSchema"
|
|
42
|
+
"RichTextSchema",
|
|
43
|
+
"StoryblokRichText",
|
|
44
|
+
"useStoryblokRichText",
|
|
45
|
+
"MarkTypes",
|
|
46
|
+
"BlockTypes",
|
|
47
|
+
"LinkTypes",
|
|
48
|
+
"AssetTypes"
|
|
43
49
|
];
|
|
44
50
|
for (const name of names) {
|
|
45
51
|
addImports({ name, as: name, from: "@storyblok/vue" });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ISbStoriesParams,
|
|
1
|
+
import type { ISbStoriesParams, ISbStoryData, StoryblokBridgeConfigV2 } from '@storyblok/vue';
|
|
2
2
|
export declare const useAsyncStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<import("vue").Ref<ISbStoryData<import("@storyblok/vue").StoryblokComponentType<string> & {
|
|
3
3
|
[index: string]: any;
|
|
4
4
|
}>, ISbStoryData<import("@storyblok/vue").StoryblokComponentType<string> & {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import {
|
|
2
|
+
import { onMounted, 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}`;
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { apiPlugin, StoryblokVue } from "@storyblok/vue";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
3
|
export default defineNuxtPlugin(({ vueApp }) => {
|
|
4
4
|
let { storyblok } = useRuntimeConfig().public;
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/nuxt",
|
|
3
|
-
"version": "6.1.0",
|
|
4
|
-
"description": "Storyblok Nuxt module",
|
|
5
|
-
"packageManager": "pnpm@9.9.0",
|
|
6
3
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
4
|
+
"version": "6.2.0",
|
|
5
|
+
"packageManager": "pnpm@9.9.0",
|
|
6
|
+
"description": "Storyblok Nuxt module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/storyblok/storyblok-nuxt.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/storyblok/storyblok-nuxt/issues"
|
|
13
|
+
},
|
|
9
14
|
"exports": {
|
|
10
15
|
".": {
|
|
11
16
|
"types": "./dist/types.d.ts",
|
|
@@ -13,6 +18,8 @@
|
|
|
13
18
|
"require": "./dist/module.cjs"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
21
|
+
"main": "./dist/module.cjs",
|
|
22
|
+
"types": "./dist/types.d.ts",
|
|
16
23
|
"files": [
|
|
17
24
|
"dist"
|
|
18
25
|
],
|
|
@@ -24,75 +31,45 @@
|
|
|
24
31
|
"dev:preview": "nuxi preview playground",
|
|
25
32
|
"prepare:playground": "nuxi prepare playground",
|
|
26
33
|
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
|
|
27
|
-
"prepare": "husky install",
|
|
28
34
|
"cy:open": "cypress open",
|
|
29
35
|
"cy:run": "cypress run",
|
|
30
36
|
"test:e2e": "start-server-and-test dev http://localhost:3000 cy:run",
|
|
31
37
|
"test:e2e-watch": "start-server-and-test dev http://localhost:3000 cy:open",
|
|
32
38
|
"pretest:e2e-static": "nuxi generate playground",
|
|
33
39
|
"test:e2e-static": "start-server-and-test dev:preview http://localhost:3000 cy:run",
|
|
34
|
-
"lint": "eslint .
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"lint:fix": "eslint . --fix"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@storyblok/vue": "^8.1.1"
|
|
35
45
|
},
|
|
36
46
|
"devDependencies": {
|
|
37
47
|
"@commitlint/cli": "^19.5.0",
|
|
38
48
|
"@commitlint/config-conventional": "^19.5.0",
|
|
39
49
|
"@cypress/vite-dev-server": "^5.2.0",
|
|
50
|
+
"@nuxt/eslint": "^0.6.1",
|
|
40
51
|
"@nuxt/eslint-config": "^0.5.7",
|
|
41
52
|
"@nuxt/kit": "^3.13.2",
|
|
42
53
|
"@nuxt/module-builder": "^0.8.4",
|
|
43
54
|
"@nuxt/schema": "^3.13.2",
|
|
44
55
|
"@nuxt/test-utils": "^3.14.3",
|
|
45
56
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
57
|
+
"@storyblok/eslint-config": "^0.3.0",
|
|
46
58
|
"@types/node": "^20.8.10",
|
|
47
59
|
"cypress": "^13.15.0",
|
|
48
|
-
"eslint": "^8.
|
|
60
|
+
"eslint": "^8.57.1",
|
|
49
61
|
"eslint-config-prettier": "^9.1.0",
|
|
50
62
|
"eslint-plugin-cypress": "^3.5.0",
|
|
51
63
|
"eslint-plugin-vue": "^9.28.0",
|
|
52
|
-
"husky": "^9.1.6",
|
|
53
|
-
"lint-staged": "^15.2.10",
|
|
54
64
|
"nuxt": "^3.13.2",
|
|
55
65
|
"prettier": "^3.3.3",
|
|
56
66
|
"start-server-and-test": "^2.0.8"
|
|
57
67
|
},
|
|
58
|
-
"dependencies": {
|
|
59
|
-
"@storyblok/vue": "^8.1.1"
|
|
60
|
-
},
|
|
61
|
-
"lint-staged": {
|
|
62
|
-
"*.{vue,js,css}": [
|
|
63
|
-
"prettier --write",
|
|
64
|
-
"eslint"
|
|
65
|
-
],
|
|
66
|
-
"*.md": [
|
|
67
|
-
"prettier --write"
|
|
68
|
-
]
|
|
69
|
-
},
|
|
70
68
|
"commitlint": {
|
|
71
69
|
"extends": [
|
|
72
70
|
"@commitlint/config-conventional"
|
|
73
71
|
]
|
|
74
72
|
},
|
|
75
|
-
"eslintConfig": {
|
|
76
|
-
"extends": [
|
|
77
|
-
"eslint:recommended",
|
|
78
|
-
"@nuxtjs/eslint-config-typescript",
|
|
79
|
-
"plugin:vue/vue3-recommended",
|
|
80
|
-
"prettier"
|
|
81
|
-
],
|
|
82
|
-
"rules": {
|
|
83
|
-
"vue/multi-word-component-names": 1
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"eslintIgnore": [
|
|
87
|
-
"**/templates/plugin.js",
|
|
88
|
-
"playground/app.vue"
|
|
89
|
-
],
|
|
90
|
-
"prettier": {
|
|
91
|
-
"trailingComma": "none",
|
|
92
|
-
"tabWidth": 2,
|
|
93
|
-
"semi": true,
|
|
94
|
-
"singleQuote": false
|
|
95
|
-
},
|
|
96
73
|
"release": {
|
|
97
74
|
"branches": [
|
|
98
75
|
"main",
|