@storyblok/vue 8.1.6 → 8.1.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Storyblok GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -128,161 +128,6 @@ The simplest way is by using the `useStoryblok` one-liner composable. Where you
128
128
 
129
129
  Check the available [apiOptions](https://www.storyblok.com/docs/api/content-delivery/v2#core-resources/stories/retrieve-one-story?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-vue) in our API docs and [bridgeOptions](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-vue) passed to the Storyblok Bridge.
130
130
 
131
- ### Rendering Rich Text
132
-
133
- You can render rich-text fields by using the `StoryblokRichText` component:
134
-
135
- ```html
136
- <script setup>
137
- import { StoryblokRichText } from "@storyblok/vue";
138
- </script>
139
-
140
- <template>
141
- <StoryblokRichText :doc="blok.articleContent" />
142
- </template>
143
- ```
144
-
145
- #### Overriding the default resolvers
146
-
147
- 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: :
148
-
149
- ```html
150
- <script setup>
151
- import { type VNode, h } from "vue";
152
- import { StoryblokRichText, BlockTypes, MarkTypes, type StoryblokRichTextNode } from "@storyblok/vue";
153
- import { RouterLink } from "vue-router";
154
- import CodeBlok from "./components/CodeBlok.vue";
155
-
156
- const resolvers = {
157
- // RouterLink example:
158
- [MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => {
159
- return node.attrs?.linktype === 'STORY'
160
- ? h(RouterLink, {
161
- to: node.attrs?.href,
162
- target: node.attrs?.target,
163
- }, node.text)
164
- : h('a', {
165
- href: node.attrs?.href,
166
- target: node.attrs?.target,
167
- }, node.text)
168
- },
169
- // Custom code block component example:
170
- [BlockTypes.CODE_BLOCK]: (node: Node) => {
171
- return h(CodeBlock, {
172
- class: node?.attrs?.class,
173
- }, node.children)
174
- },
175
- }
176
- </script>
177
-
178
- <template>
179
- <StoryblokRichText :doc="blok.articleContent" :resolvers="resolvers" />
180
- </template>
181
- ```
182
-
183
- Or you can have more control by using the `useStoryblokRichText` composable:
184
-
185
- ```html
186
- <script setup>
187
- import { type VNode, h } from "vue";
188
- import { useStoryblokRichText, BlockTypes, MarkTypes, type StoryblokRichTextNode } from "@storyblok/vue";
189
- import { RouterLink } from "vue-router";
190
-
191
- const resolvers = {
192
- // RouterLink example:
193
- [MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => {
194
- return node.attrs?.linktype === 'STORY'
195
- ? h(RouterLink, {
196
- to: node.attrs?.href,
197
- target: node.attrs?.target,
198
- }, node.text)
199
- : h('a', {
200
- href: node.attrs?.href,
201
- target: node.attrs?.target,
202
- }, node.text)
203
- },
204
- }
205
-
206
- const { render } = useStoryblokRichText({
207
- resolvers,
208
- })
209
-
210
- const html = render(blok.articleContent);
211
- </script>
212
-
213
- <template>
214
- <div v-html="html"></div>
215
- </template>
216
- ```
217
-
218
- 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.
219
-
220
- ### Legacy Rich Text Resolver
221
-
222
- > [!WARNING]
223
- > The legacy `richTextResolver` is soon to be deprecated. We recommend migrating to the new `useRichText` composable described above instead.
224
-
225
- You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/vue` and a Vue computed property:
226
-
227
- ```html
228
- <template>
229
- <div v-html="articleContent"></div>
230
- </template>
231
-
232
- <script setup>
233
- import { computed } from "vue";
234
- import { renderRichText } from "@storyblok/vue";
235
-
236
- const articleContent = computed(() => renderRichText(blok.articleContent));
237
- </script>
238
- ```
239
-
240
- You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
241
-
242
- ```js
243
- import { RichTextSchema, StoryblokVue } from "@storyblok/vue";
244
- import cloneDeep from "clone-deep";
245
-
246
- const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
247
- // ... and edit the nodes and marks, or add your own.
248
- // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
249
-
250
- app.use(StoryblokVue, {
251
- accessToken: "YOUR_ACCESS_TOKEN",
252
- use: [apiPlugin],
253
- richText: {
254
- schema: mySchema,
255
- resolver: (component, blok) => {
256
- switch (component) {
257
- case "my-custom-component":
258
- return `<div class="my-component-class">${blok.text}</div>`;
259
- default:
260
- return "Resolver not defined";
261
- }
262
- },
263
- },
264
- });
265
- ```
266
-
267
- You can also set a **custom Schema and component resolver only once** by passing the options as the second parameter to `renderRichText` function:
268
-
269
- ```js
270
- import { renderRichText } from "@storyblok/vue";
271
-
272
- renderRichText(blok.richTextField, {
273
- schema: mySchema,
274
- resolver: (component, blok) => {
275
- switch (component) {
276
- case "my-custom-component":
277
- return `<div class="my-component-class">${blok.text}</div>`;
278
- break;
279
- default:
280
- return `Component ${component} not found`;
281
- }
282
- },
283
- });
284
- ```
285
-
286
131
  ### Long Form
287
132
 
288
133
  #### 1. Fetching Content
@@ -495,6 +340,177 @@ app.use(StoryblokVue, {
495
340
  app.component("MyCustomFallback", MyCustomFallback);
496
341
  ```
497
342
 
343
+ ## Rendering Rich Text
344
+
345
+ You can render rich text fields by using the `StoryblokRichText` component:
346
+
347
+ ```html
348
+ <script setup>
349
+ import { StoryblokRichText } from "@storyblok/vue";
350
+ </script>
351
+
352
+ <template>
353
+ <StoryblokRichText :doc="blok.articleContent" />
354
+ </template>
355
+ ```
356
+
357
+ Or you can have more control by using the `useStoryblokRichText` composable:
358
+
359
+ ```html
360
+ <script setup>
361
+ import { useStoryblokRichText } from "@storyblok/vue";
362
+ const { render } = useStoryblokRichText({
363
+ // options like resolvers
364
+ });
365
+
366
+ const root = () => render(blok.articleContent);
367
+ </script>
368
+
369
+ <template>
370
+ <root />
371
+ </template>
372
+ ```
373
+
374
+ 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.
375
+
376
+ ### Overriding the default resolvers
377
+
378
+ 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: :
379
+
380
+ ```html
381
+ <script setup>
382
+ import { type VNode, h } from "vue";
383
+ import { StoryblokRichText, BlockTypes, MarkTypes, type StoryblokRichTextNode } from "@storyblok/vue";
384
+ import { RouterLink } from "vue-router";
385
+ import CodeBlok from "./components/CodeBlok.vue";
386
+
387
+ const resolvers = {
388
+ // RouterLink example:
389
+ [MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => {
390
+ return node.attrs?.linktype === 'STORY'
391
+ ? h(RouterLink, {
392
+ to: node.attrs?.href,
393
+ target: node.attrs?.target,
394
+ }, node.text)
395
+ : h('a', {
396
+ href: node.attrs?.href,
397
+ target: node.attrs?.target,
398
+ }, node.text)
399
+ },
400
+ // Custom code block component example:
401
+ [BlockTypes.CODE_BLOCK]: (node: Node) => {
402
+ return h(CodeBlock, {
403
+ class: node?.attrs?.class,
404
+ }, node.children)
405
+ },
406
+ }
407
+ </script>
408
+
409
+ <template>
410
+ <StoryblokRichText :doc="blok.articleContent" :resolvers="resolvers" />
411
+ </template>
412
+ ```
413
+
414
+ If you want to use the `useStoryblokRichText` composable, you can pass the `resolvers` via the options object:
415
+
416
+ ```html
417
+ <script setup>
418
+ import { type VNode, h } from "vue";
419
+ import { useStoryblokRichText, BlockTypes, MarkTypes, type StoryblokRichTextNode } from "@storyblok/vue";
420
+ import { RouterLink } from "vue-router";
421
+
422
+ const resolvers = {
423
+ // RouterLink example:
424
+ [MarkTypes.LINK]: (node: StoryblokRichTextNode<VNode>) => {
425
+ return node.attrs?.linktype === 'STORY'
426
+ ? h(RouterLink, {
427
+ to: node.attrs?.href,
428
+ target: node.attrs?.target,
429
+ }, node.text)
430
+ : h('a', {
431
+ href: node.attrs?.href,
432
+ target: node.attrs?.target,
433
+ }, node.text)
434
+ },
435
+ }
436
+
437
+ const { render } = useStoryblokRichText({
438
+ resolvers,
439
+ })
440
+ const root = () => render(blok.articleContent);
441
+ </script>
442
+
443
+ <template>
444
+ <root />
445
+ </template>
446
+ ```
447
+
448
+ ### Legacy Rich Text Resolver
449
+
450
+ > [!WARNING]
451
+ > The legacy `richTextResolver` is soon to be deprecated. We recommend migrating to the new approach described above instead.
452
+
453
+ You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/vue` and a Vue computed property:
454
+
455
+ ```html
456
+ <template>
457
+ <div v-html="articleContent"></div>
458
+ </template>
459
+
460
+ <script setup>
461
+ import { computed } from "vue";
462
+ import { renderRichText } from "@storyblok/vue";
463
+
464
+ const articleContent = computed(() => renderRichText(blok.articleContent));
465
+ </script>
466
+ ```
467
+
468
+ You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
469
+
470
+ ```js
471
+ import { RichTextSchema, StoryblokVue } from "@storyblok/vue";
472
+ import cloneDeep from "clone-deep";
473
+
474
+ const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
475
+ // ... and edit the nodes and marks, or add your own.
476
+ // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
477
+
478
+ app.use(StoryblokVue, {
479
+ accessToken: "YOUR_ACCESS_TOKEN",
480
+ use: [apiPlugin],
481
+ richText: {
482
+ schema: mySchema,
483
+ resolver: (component, blok) => {
484
+ switch (component) {
485
+ case "my-custom-component":
486
+ return `<div class="my-component-class">${blok.text}</div>`;
487
+ default:
488
+ return "Resolver not defined";
489
+ }
490
+ },
491
+ },
492
+ });
493
+ ```
494
+
495
+ You can also set a **custom Schema and component resolver only once** by passing the options as the second parameter to `renderRichText` function:
496
+
497
+ ```js
498
+ import { renderRichText } from "@storyblok/vue";
499
+
500
+ renderRichText(blok.richTextField, {
501
+ schema: mySchema,
502
+ resolver: (component, blok) => {
503
+ switch (component) {
504
+ case "my-custom-component":
505
+ return `<div class="my-component-class">${blok.text}</div>`;
506
+ break;
507
+ default:
508
+ return `Component ${component} not found`;
509
+ }
510
+ },
511
+ });
512
+ ```
513
+
498
514
  ## Compatibility
499
515
 
500
516
  This plugin is for Vue 3. Thus, it supports the [same browsers as Vue 3](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0038-vue3-ie11-support.md). In short: all modern browsers, dropping IE support.
@@ -1,14 +1,20 @@
1
- import { defineComponent as r, openBlock as p, createElementBlock as a, createElementVNode as n, createTextVNode as c, toDisplayString as m } from "vue";
2
- const _ = { class: "fallback-component" }, d = { class: "component" }, f = /* @__PURE__ */ r({
1
+ /**
2
+ * name: @storyblok/vue
3
+ * (c) 2024
4
+ * description: SDK to integrate Storyblok into your project using Vue.
5
+ * author: Storyblok
6
+ */
7
+ import { defineComponent as r, openBlock as p, createElementBlock as a, createElementVNode as n, createTextVNode as c, toDisplayString as d } from "vue";
8
+ const m = { class: "fallback-component" }, _ = { class: "component" }, f = /* @__PURE__ */ r({
3
9
  __name: "FallbackComponent",
4
10
  props: {
5
11
  blok: {}
6
12
  },
7
13
  setup(t) {
8
- return (e, o) => (p(), a("div", _, [
14
+ return (e, o) => (p(), a("div", m, [
9
15
  n("p", null, [
10
16
  o[0] || (o[0] = c(" Component could not be found for blok ")),
11
- n("span", d, m(e.blok.component), 1),
17
+ n("span", _, d(e.blok.component), 1),
12
18
  o[1] || (o[1] = c("! Is it configured correctly? "))
13
19
  ])
14
20
  ]));
@@ -18,7 +24,7 @@ const _ = { class: "fallback-component" }, d = { class: "component" }, f = /* @_
18
24
  for (const [s, l] of e)
19
25
  o[s] = l;
20
26
  return o;
21
- }, u = /* @__PURE__ */ i(f, [["__scopeId", "data-v-93c770c0"]]);
27
+ }, u = /* @__PURE__ */ i(f, [["__scopeId", "data-v-9abcd1f2"]]);
22
28
  export {
23
29
  u as default
24
30
  };
@@ -0,0 +1,6 @@
1
+ import { SbBlokData } from '../types';
2
+ export interface SbComponentProps {
3
+ blok: SbBlokData;
4
+ }
5
+ declare const _default: import('vue').DefineComponent<SbComponentProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbComponentProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
6
+ export default _default;
@@ -0,0 +1,5 @@
1
+ import { SbComponentProps } from '../types';
2
+ declare const _default: import('vue').DefineComponent<SbComponentProps, {
3
+ value: import('vue').Ref<any, any>;
4
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<SbComponentProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
5
+ export default _default;
@@ -1,12 +1,3 @@
1
- import type { StoryblokRichTextProps } from "../types";
2
- declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<StoryblokRichTextProps>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<StoryblokRichTextProps>>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ import { StoryblokRichTextProps } from '../types';
2
+ declare const _default: import('vue').DefineComponent<StoryblokRichTextProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<StoryblokRichTextProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
3
3
  export default _default;
4
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
5
- type __VLS_TypePropsToRuntimeProps<T> = {
6
- [K in keyof T]-?: {} extends Pick<T, K> ? {
7
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
8
- } : {
9
- type: import('vue').PropType<T[K]>;
10
- required: true;
11
- };
12
- };
@@ -1,9 +1,9 @@
1
- import type { VNode } from "vue";
2
- import type { StoryblokRichTextNode, StoryblokRichTextOptions } from "@storyblok/js";
1
+ import { VNode } from 'vue';
2
+ import { StoryblokRichTextNode, StoryblokRichTextOptions } from '@storyblok/js';
3
3
  export declare function useStoryblokRichText(options: StoryblokRichTextOptions<VNode>): {
4
- render: (node: StoryblokRichTextNode<VNode<import("vue").RendererNode, import("vue").RendererElement, {
4
+ render: (node: StoryblokRichTextNode<VNode<import('vue').RendererNode, import('vue').RendererElement, {
5
5
  [key: string]: any;
6
- }>>) => VNode<import("vue").RendererNode, import("vue").RendererElement, {
6
+ }>>) => VNode<import('vue').RendererNode, import('vue').RendererElement, {
7
7
  [key: string]: any;
8
8
  }>;
9
9
  };
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import type { Ref, Plugin } from "vue";
2
- import type { StoryblokClient, StoryblokBridgeConfigV2, ISbStoryData, ISbStoriesParams } from "./types";
3
- export { useStoryblokBridge, apiPlugin, renderRichText, RichTextSchema, RichTextResolver, BlockTypes, MarkTypes, richTextResolver, TextTypes, type StoryblokRichTextOptions, type StoryblokRichTextDocumentNode, type StoryblokRichTextNodeTypes, type StoryblokRichTextNode, type StoryblokRichTextResolvers, type StoryblokRichTextNodeResolver, type StoryblokRichTextImageOptimizationOptions, } from "@storyblok/js";
4
- export { default as StoryblokComponent } from "./StoryblokComponent.vue";
5
- export { default as StoryblokRichText } from "./components/StoryblokRichText.vue";
6
- export * from "./composables/useStoryblokRichText";
1
+ import { Plugin, Ref } from 'vue';
2
+ import { ISbStoriesParams, ISbStoryData, StoryblokBridgeConfigV2, StoryblokClient } from './types';
3
+ export { default as StoryblokComponent } from './components/StoryblokComponent.vue';
4
+ export { default as StoryblokRichText } from './components/StoryblokRichText.vue';
5
+ export * from './composables/useStoryblokRichText';
6
+ export * from './types';
7
+ export { apiPlugin, BlockTypes, MarkTypes, renderRichText, RichTextResolver, richTextResolver, RichTextSchema, type StoryblokRichTextDocumentNode, type StoryblokRichTextImageOptimizationOptions, type StoryblokRichTextNode, type StoryblokRichTextNodeResolver, type StoryblokRichTextNodeTypes, type StoryblokRichTextOptions, type StoryblokRichTextResolvers, TextTypes, useStoryblokBridge, } from '@storyblok/js';
7
8
  export declare const useStoryblokApi: () => StoryblokClient;
8
- export declare const useStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<ISbStoryData<import("@storyblok/js").StoryblokComponentType<string> & {
9
+ export declare const useStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
9
10
  [index: string]: any;
10
- }>, ISbStoryData<import("@storyblok/js").StoryblokComponentType<string> & {
11
+ }> | null, ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
11
12
  [index: string]: any;
12
- }>>>;
13
+ }> | null>>;
13
14
  export declare const StoryblokVue: Plugin;
14
- export * from "./types";