@storyblok/nuxt 6.1.1 → 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
@@ -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
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
3
  "configKey": "storyblok",
4
- "version": "6.1.1",
4
+ "version": "6.2.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
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" });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/nuxt",
3
3
  "type": "module",
4
- "version": "6.1.1",
4
+ "version": "6.2.0",
5
5
  "packageManager": "pnpm@9.9.0",
6
6
  "description": "Storyblok Nuxt module",
7
7
  "repository": {