vue-datocms 2.0.0 → 3.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/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # vue-datocms
2
2
 
3
- ![MIT](https://img.shields.io/npm/l/vue-datocms?style=for-the-badge) ![MIT](https://img.shields.io/npm/v/vue-datocms?style=for-the-badge) [![Build Status](https://img.shields.io/travis/datocms/vue-datocms?style=for-the-badge)](https://travis-ci.org/datocms/vue-datocms)
3
+ ![MIT](https://img.shields.io/npm/l/vue-datocms?style=for-the-badge) ![NPM](https://img.shields.io/npm/v/vue-datocms?style=for-the-badge) [![Build Status](https://img.shields.io/github/workflow/status/datocms/vue-datocms/Node.js%20CI?style=for-the-badge)](https://github.com/datocms/vue-datocms/actions/workflows/node.js.yml)
4
4
 
5
5
  A set of components and utilities to work faster with [DatoCMS](https://www.datocms.com/) in Vue.js environments. Integrates seamlessy with [DatoCMS's GraphQL Content Delivery API](https://www.datocms.com/docs/content-delivery-api).
6
6
 
7
- - Works with Vue 3;
7
+ - Works with Vue 3 and Vue 2;
8
8
  - TypeScript ready;
9
9
  - Compatible with any data-fetching library (axios, Apollo);
10
10
  - Usable both client and server side;
11
- - Compatible with vanilla Vue, Nuxt.js and pretty much any other Vue-based solution;
11
+ - Compatible with vanilla Vue and pretty much any other Vue-based solution.
12
12
 
13
13
  <br /><br />
14
14
  <a href="https://www.datocms.com/">
@@ -18,645 +18,50 @@ A set of components and utilities to work faster with [DatoCMS](https://www.dato
18
18
 
19
19
  ## Table of Contents
20
20
 
21
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
22
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
23
-
24
- - [Demos](#demos)
21
+ - [Features](#features)
25
22
  - [Installation](#installation)
26
- - [Live real-time updates](#live-real-time-updates)
27
- - [Progressive/responsive image](#progressiveresponsive-image)
28
- - [Out-of-the-box features](#out-of-the-box-features)
29
- - [Setup](#setup)
30
- - [Usage](#usage)
31
- - [Example](#example)
32
- - [Props](#props)
33
- - [The `ResponsiveImage` object](#the-responsiveimage-object)
34
- - [Social share, SEO and Favicon meta tags](#social-share-seo-and-favicon-meta-tags)
35
- - [Usage](#usage-1)
36
- - [Example](#example-1)
37
- - [Structured text](#structured-text)
38
- - [Setup](#setup-1)
39
- - [Basic usage](#basic-usage)
40
- - [Custom renderers](#custom-renderers)
41
- - [Props](#props-1)
42
-
43
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
44
-
45
- ## Demos
46
-
47
- - Pure Vue: [https://vue-datocms-example.netlify.com/](https://vue-datocms-example.netlify.com/)
48
- - Server side rendering with Nuxt.js: [https://vue-datocms-components.now.sh](https://vue-datocms-components.now.sh)
49
-
50
- ## Installation
51
-
52
- ```
53
- npm install vue-datocms
54
- ```
55
-
56
- If you want to use this package with Vue 2, please, install `vue-datocms@1`. The latest versions are only compatible with Vue 3.
57
-
58
- ## Live real-time updates
59
-
60
- Thanks to the `subscribeToQuery` helper provided by the [datocms-listen](https://www.npmjs.com/package/datocms-listen) package you can get real-time updates for the page when the content changes. This helper connects to the DatoCMS's [Real-time Updates API](https://www.datocms.com/docs/real-time-updates-api/api-reference) to receive the updated query results in real-time, and is able to reconnect in case of network failures.
61
-
62
- Live updates are great both to get instant previews of your content while editing it inside DatoCMS, or to offer real-time updates of content to your visitors (ie. news site).
63
-
64
- ### Reference
65
-
66
- `subscribeToQuery` provides a way to create a subscription to DatoCMS's [Real-time Updates API](https://www.datocms.com/docs/real-time-updates-api/api-reference).
67
-
68
- Please consult the [datocms-listen package documentation](https://www.npmjs.com/package/datocms-listen) to learn more about how to configure `subscribeToQuery`.
69
-
70
- In Vue.js v3, `subscribeToQuery` can be used to implement a custom hook. Please take a look at the [React.js one](https://github.com/datocms/react-datocms/blob/master/src/useQuerySubscription/index.ts) for a sample implementation.
71
-
72
- ## Progressive/responsive image
73
-
74
- `<datocms-image>` is a Vue component specially designed to work seamlessly with DatoCMS’s [`responsiveImage` GraphQL query](https://www.datocms.com/docs/content-delivery-api/uploads#responsive-images) that optimizes image loading for your sites.
75
-
76
- ![](docs/image-component.gif?raw=true)
77
-
78
- ### Out-of-the-box features
79
-
80
- - Offers WebP version of images for browsers that support the format
81
- - Generates multiple smaller images so smartphones and tablets don’t download desktop-sized images
82
- - Efficiently lazy loads images to speed initial page load and save bandwidth
83
- - Holds the image position so your page doesn’t jump while images load
84
- - Uses either blur-up or background color techniques to show a preview of the image while it loads
23
+ - [Development](#development)
85
24
 
86
- ## Intersection Observer
25
+ ## Features
87
26
 
88
- Intersection Observer is the API used to determine if the image is inside the viewport or not. [Browser support is really good](https://caniuse.com/intersectionobserver) - With Safari adding support in 12.1, all major browsers now support Intersection Observers natively.
27
+ `vue-datocms` contains Vue components ready to use, helpers functions and usage examples.
89
28
 
90
- If the IntersectionObserver object is not available, the component treats the image as it's always visible in the viewport. Feel free to add a [polyfill](https://www.npmjs.com/package/intersection-observer) so that it will also 100% work on older versions of iOS and IE11.
91
-
92
- ### Setup
93
-
94
- You can register the component globally so it's available in all your apps:
95
-
96
- ```js
97
- import Vue from 'vue';
98
- import { DatocmsImagePlugin } from 'vue-datocms';
99
-
100
- Vue.use(DatocmsImagePlugin);
101
- ```
102
-
103
- Or use it locally in any of your components:
104
-
105
- ```js
106
- import { Image } from 'vue-datocms';
107
-
108
- export default {
109
- components: {
110
- 'datocms-image': Image,
111
- },
112
- };
113
- ```
114
-
115
- ### Usage
116
-
117
- 1. Use `<datocms-image>` it in place of the regular `<img />` tag
118
- 2. Write a GraphQL query to your DatoCMS project using the [`responsiveImage` query](https://www.datocms.com/docs/content-delivery-api/images-and-videos#responsive-images)
119
-
120
- The GraphQL query returns multiple thumbnails with optimized compression. The `<datocms-image>` component automatically sets up the "blur-up" effect as well as lazy loading of images further down the screen.
121
-
122
- ### Example
123
-
124
- For a fully working example take a look at our [examples directory](https://github.com/datocms/vue-datocms/tree/master/examples).
125
-
126
- ```vue
127
- <template>
128
- <article>
129
- <div v-if="data">
130
- <h1>{{ data.blogPost.title }}</h1>
131
- <datocms-image :data="data.blogPost.cover.responsiveImage" />
132
- </div>
133
- </article>
134
- </template>
135
-
136
- <script>
137
- import { request } from './lib/datocms';
138
- import { Image } from 'vue-datocms';
139
-
140
- const query = gql`
141
- query {
142
- blogPost {
143
- title
144
- cover {
145
- responsiveImage(
146
- imgixParams: { fit: crop, w: 300, h: 300, auto: format }
147
- ) {
148
- # HTML5 src/srcset/sizes attributes
149
- srcSet
150
- webpSrcSet
151
- sizes
152
- src
153
-
154
- # size information (post-transformations)
155
- width
156
- height
157
- aspectRatio
158
-
159
- # SEO attributes
160
- alt
161
- title
162
-
163
- # background color placeholder or...
164
- bgColor
165
-
166
- # blur-up placeholder, JPEG format, base64-encoded
167
- base64
168
- }
169
- }
170
- }
171
- }
172
- `;
173
-
174
- export default {
175
- components: {
176
- 'datocms-image': Image,
177
- },
178
- data() {
179
- return {
180
- data: null,
181
- };
182
- },
183
- async mounted() {
184
- this.data = await request({ query });
185
- },
186
- };
187
- </script>
188
- ```
29
+ [Components](https://vuejs.org/guide/essentials/component-basics.html):
189
30
 
190
- ### Props
31
+ - [`<DatocmsImage />`](src/components/Image)
32
+ - [`<DatocmsStructuredText />`](src/components/StructuredText)
191
33
 
192
- | prop | type | default | required | description |
193
- | --------------------- | ------------------------ | ----------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
194
- | data | `ResponsiveImage` object | | :white_check_mark: | The actual response you get from a DatoCMS `responsiveImage` GraphQL query. |
195
- | class | string | null | :x: | Additional CSS class of root node |
196
- | root-style | CSS properties | null | :x: | Additional CSS rules to add to the root node |
197
- | picture-class | string | null | :x: | Additional CSS class for the inner `<picture />` tag |
198
- | picture-style | CSS properties | null | :x: | Additional CSS rules to add to the inner `<picture />` tag |
199
- | fade-in-duration | integer | 500 | :x: | Duration (in ms) of the fade-in transition effect upoad image loading |
200
- | intersection-treshold | float | 0 | :x: | Indicate at what percentage of the placeholder visibility the loading of the image should be triggered. A value of 0 means that as soon as even one pixel is visible, the callback will be run. A value of 1.0 means that the threshold isn't considered passed until every pixel is visible. |
201
- | intersection-tmargin | string | "0px 0px 0px 0px" | :x: | Margin around the placeholder. Can have values similar to the CSS margin property (top, right, bottom, left). The values can be percentages. This set of values serves to grow or shrink each side of the placeholder element's bounding box before computing intersections. |
202
- | lazy-load | Boolean | true | :x: | Wheter enable lazy loading or not |
203
- | explicitWidth | Boolean | false | :x: | Wheter the image wrapper should explicitely declare the width of the image or keep it fluid |
34
+ [Composables](https://vuejs.org/guide/reusability/composables.html):
204
35
 
205
- #### The `ResponsiveImage` object
36
+ - [`useQuerySubscription`](src/composables/useQuerySubscription)
37
+ - [`useSiteSearch`](src/composables/useSiteSearch)
206
38
 
207
- The `data` prop expects an object with the same shape as the one returned by `responsiveImage` GraphQL call. It's up to you to make a GraphQL query that will return the properties you need for a specific use of the `<datocms-image>` component.
39
+ Helpers:
208
40
 
209
- - The minimum required properties for `data` are: `aspectRatio`, `width`, `sizes`, `srcSet` and `src`;
210
- - `alt` and `title`, while not mandatory, are all highly suggested, so remember to use them!
211
- - You either want to add the `webpSrcSet` field or specify `{ auto: format }` in your `imgixParams`, to automatically use WebP images in browsers that support the format;
212
- - If you provide both the `bgColor` and `base64` property, the latter will take precedence, so just avoiding querying both fields at the same time, it will only make the response bigger :wink:
41
+ - [`toHead`](src/lib/toHead)
213
42
 
214
- Here's a complete recap of what `responsiveImage` offers:
215
-
216
- | property | type | required | description |
217
- | ----------- | ------- | ------------------ | ----------------------------------------------------------------------------------------------- |
218
- | aspectRatio | float | :white_check_mark: | The aspect ratio (width/height) of the image |
219
- | width | integer | :white_check_mark: | The width of the image |
220
- | sizes | string | :white_check_mark: | The HTML5 `sizes` attribute for the image |
221
- | srcSet | string | :white_check_mark: | The HTML5 `srcSet` attribute for the image |
222
- | src | string | :white_check_mark: | The fallback `src` attribute for the image |
223
- | webpSrcSet | string | :x: | The HTML5 `srcSet` attribute for the image in WebP format, for browsers that support the format |
224
- | alt | string | :x: | Alternate text (`alt`) for the image |
225
- | title | string | :x: | Title attribute (`title`) for the image |
226
- | bgColor | string | :x: | The background color for the image placeholder |
227
- | base64 | string | :x: | A base64-encoded thumbnail to offer during image loading |
228
-
229
- ## Social share, SEO and Favicon meta tags
230
-
231
- Just like the image component, `toHead()` is a helper specially designed to work seamlessly with DatoCMS’s [`_seoMetaTags` and `faviconMetaTags` GraphQL queries](https://www.datocms.com/docs/content-delivery-api/seo) so that you can handle proper SEO in your pages.
232
-
233
- You can use `toHead()` inside the `metaInfo` (or `head`, in Nuxt.js) property of your components, and it will return meta tags as required by the [`vue-meta`](https://vue-meta.nuxtjs.org/guide/metainfo.html) package.
234
-
235
- ### Usage
236
-
237
- `toHead()` takes an array of `Tag`s in the exact form they're returned by the following [DatoCMS GraphQL API](https://www.datocms.com/docs/content-delivery-api/seo) queries:
238
-
239
- - `_seoMetaTags` query on any record, or
240
- - `faviconMetaTags` on the global `_site` object.
241
-
242
- You can pass multiple arrays of `Tag`s together and pass them to a single `toHead()` call.
243
-
244
- ### Example
245
-
246
- For a working example take a look at our [examples directory](https://github.com/datocms/vue-datocms/tree/master/examples).
247
-
248
- ```vue
249
- <template>
250
- <article>
251
- <h1 v-if="data">{{ data.page.title }}</h1>
252
- </article>
253
- </template>
254
-
255
- <script>
256
- import { request } from './lib/datocms';
257
- import { toHead } from 'vue-datocms';
258
-
259
- const query = gql`
260
- query {
261
- page: homepage {
262
- title
263
- seo: _seoMetaTags {
264
- attributes
265
- content
266
- tag
267
- }
268
- }
269
-
270
- site: _site {
271
- favicon: faviconMetaTags {
272
- attributes
273
- content
274
- tag
275
- }
276
- }
277
- }
278
- `;
279
-
280
- export default {
281
- data() {
282
- return {
283
- data: null,
284
- };
285
- },
286
- async mounted() {
287
- this.data = await request({ query });
288
- },
289
- metaInfo() {
290
- if (!this || !this.data) {
291
- return;
292
- }
293
- return toHead(this.data.page.seo, this.data.site.favicon);
294
- },
295
- };
296
- </script>
297
- ```
298
-
299
- # Structured text
300
-
301
- `<datocms-structured-text />` is a Vue component that you can use to render the value contained inside a DatoCMS [Structured Text field type](https://www.datocms.com/docs/structured-text/dast).
302
-
303
- ### Setup
304
-
305
- You can register the component globally so it's available in all your apps:
306
-
307
- ```js
308
- import Vue from 'vue';
309
- import { DatocmsStructuredTextPlugin } from 'vue-datocms';
310
-
311
- Vue.use(DatocmsStructuredTextPlugin);
312
- ```
313
-
314
- Or use it locally in any of your components:
315
-
316
- ```js
317
- import { StructuredText } from 'vue-datocms';
318
-
319
- export default {
320
- components: {
321
- 'datocms-structured-text': StructuredText,
322
- },
323
- };
324
- ```
325
-
326
- ## Basic usage
327
-
328
- ```vue
329
- <template>
330
- <article>
331
- <div v-if="data">
332
- <h1>{{ data.blogPost.title }}</h1>
333
- <datocms-structured-text :data="data.blogPost.content" />
334
- <!--
335
- Final result:
336
- <h1>Hello <strong>world!</strong></h1>
337
- -->
338
- </div>
339
- </article>
340
- </template>
341
-
342
- <script>
343
- import { request } from './lib/datocms';
344
- import { StructuredText } from 'vue-datocms';
345
-
346
- const query = gql`
347
- query {
348
- blogPost {
349
- title
350
- content {
351
- value
352
- }
353
- }
354
- }
355
- `;
43
+ ## Installation
356
44
 
357
- export default {
358
- components: {
359
- 'datocms-structured-text': StructuredText,
360
- },
361
- data() {
362
- return {
363
- data: null,
364
- };
365
- },
366
- async mounted() {
367
- this.data = await request({ query });
368
- // data.blogPost.content ->
369
- // {
370
- // value: {
371
- // schema: "dast",
372
- // document: {
373
- // type: "root",
374
- // children: [
375
- // {
376
- // type: "heading",
377
- // level: 1,
378
- // children: [
379
- // {
380
- // type: "span",
381
- // value: "Hello ",
382
- // },
383
- // {
384
- // type: "span",
385
- // marks: ["strong"],
386
- // value: "world!",
387
- // },
388
- // ],
389
- // },
390
- // ],
391
- // },
392
- // },
393
- // }
394
- },
395
- };
396
- </script>
397
45
  ```
398
-
399
- ## Custom renderers
400
-
401
- You can also pass custom renderers for special nodes (inline records, record links and blocks) as an optional parameter like so:
402
-
403
- ```vue
404
- <template>
405
- <article>
406
- <div v-if="data">
407
- <h1>{{ data.blogPost.title }}</h1>
408
- <datocms-structured-text
409
- :data="data.blogPost.content"
410
- :renderInlineRecord="renderInlineRecord"
411
- :renderLinkToRecord="renderLinkToRecord"
412
- :renderBlock="renderBlock"
413
- />
414
- <!--
415
- Final result:
416
-
417
- <h1>Welcome onboard <a href="/team/mark-smith">Mark</a></h1>
418
- <p>
419
- So happy to have
420
- <a href="/team/mark-smith">this awesome humang being</a> in our team!
421
- </p>
422
- <img
423
- src="https://www.datocms-assets.com/205/1597757278-austin-distel-wd1lrb9oeeo-unsplash.jpg"
424
- alt="Our team at work"
425
- />
426
- -->
427
- </div>
428
- </article>
429
- </template>
430
-
431
- <script>
432
- import { request } from './lib/datocms';
433
- import { StructuredText, Image } from 'vue-datocms';
434
- import { h } from 'vue';
435
-
436
- const query = gql`
437
- query {
438
- blogPost {
439
- title
440
- content {
441
- value
442
- links {
443
- __typename
444
- ... on TeamMemberRecord {
445
- id
446
- firstName
447
- slug
448
- }
449
- }
450
- blocks {
451
- __typename
452
- ... on ImageRecord {
453
- id
454
- image {
455
- responsiveImage(
456
- imgixParams: { fit: crop, w: 300, h: 300, auto: format }
457
- ) {
458
- srcSet
459
- webpSrcSet
460
- sizes
461
- src
462
- width
463
- height
464
- aspectRatio
465
- alt
466
- title
467
- base64
468
- }
469
- }
470
- }
471
- }
472
- }
473
- }
474
- }
475
- `;
476
-
477
- export default {
478
- components: {
479
- 'datocms-structured-text': StructuredText,
480
- 'datocms-image': Image,
481
- },
482
- data() {
483
- return {
484
- data: null,
485
- };
486
- },
487
- methods: {
488
- renderInlineRecord: ({ record }) => {
489
- switch (record.__typename) {
490
- case 'TeamMemberRecord':
491
- return h('a', { href: `/team/${record.slug}` }, record.firstName);
492
- default:
493
- return null;
494
- }
495
- },
496
- renderLinkToRecord: ({ record, children, transformedMeta }) => {
497
- switch (record.__typename) {
498
- case 'TeamMemberRecord':
499
- return h(
500
- 'a',
501
- { ...transformedMeta, href: `/team/${record.slug}` },
502
- children,
503
- );
504
- default:
505
- return null;
506
- }
507
- },
508
- renderBlock: ({ record }) => {
509
- switch (record.__typename) {
510
- case 'ImageRecord':
511
- return h('datocms-image', {
512
- data: record.image.responsiveImage,
513
- });
514
- default:
515
- return null;
516
- }
517
- },
518
- },
519
- async mounted() {
520
- this.data = await request({ query });
521
- // data.blogPost.content ->
522
- // {
523
- // value: {
524
- // schema: "dast",
525
- // document: {
526
- // type: "root",
527
- // children: [
528
- // {
529
- // type: "heading",
530
- // level: 1,
531
- // children: [
532
- // { type: "span", value: "Welcome onboard " },
533
- // { type: "inlineItem", item: "324321" },
534
- // ],
535
- // },
536
- // {
537
- // type: "paragraph",
538
- // children: [
539
- // { type: "span", value: "So happy to have " },
540
- // {
541
- // type: "itemLink",
542
- // item: "324321",
543
- // children: [
544
- // {
545
- // type: "span",
546
- // marks: ["strong"],
547
- // value: "this awesome humang being",
548
- // },
549
- // ]
550
- // },
551
- // { type: "span", value: " in our team!" },
552
- // ]
553
- // },
554
- // { type: "block", item: "1984559" }
555
- // ],
556
- // },
557
- // },
558
- // links: [
559
- // {
560
- // id: "324321",
561
- // __typename: "TeamMemberRecord",
562
- // firstName: "Mark",
563
- // slug: "mark-smith",
564
- // },
565
- // ],
566
- // blocks: [
567
- // {
568
- // id: "324321",
569
- // __typename: "ImageRecord",
570
- // image: {
571
- // responsiveImage: { ... },
572
- // },
573
- // },
574
- // ],
575
- // }
576
- },
577
- };
578
- </script>
46
+ npm install vue-datocms
579
47
  ```
580
48
 
581
- ## Override default rendering of nodes
49
+ ## Development
582
50
 
583
- This component automatically renders all nodes except for `inline_item`, `item_link` and `block` using a set of default rules, but you might want to customize those. For example:
51
+ This repository contains a number of examples. You can use them to locally test your changes to the package:
584
52
 
585
- - For `heading` nodes, you might want to add an anchor;
586
- - For `code` nodes, you might want to use a custom sytax highlighting component;
53
+ - [Vue 3 + TypeScript + Vite](examples/vite-typescript-vue3/) ([running demo](https://vue-datocms-vite-typescript-vue3-example.vercel.app/))
54
+ - [Vue 2 + Javacript + Vue CLI](examples/vue-cli-babel-javascript-vue2/) ([running demo](https://vue-datocms-vue-cli-babel-javascript-vue2-example.vercel.app/))
55
+ - [Query subscription](examples/query-subscription/) ([running demo](https://vue-datocms-query-subscription-example.vercel.app/))
56
+ - [Site search](examples/site-search/) ([running demo](https://vue-datocms-site-search-example.vercel.app/))
587
57
 
588
- In this case, you can easily override default rendering rules with the `customNodeRules` and `customMarkRules` props.
58
+ To use them, follow this recipe starting from the vue-datocms folder:
589
59
 
590
- ```vue
591
- <template>
592
- <datocms-structured-text
593
- :data="data.blogPost.content"
594
- :customNodeRules="customNodeRules"
595
- :customMarkRules="customMarkRules"
596
- />
597
- </template>
598
-
599
- <script>
600
- import { StructuredText, renderNodeRule, renderMarkRule } from "vue-datocms";
601
- import { isHeading, isCode } from "datocms-structured-text-utils";
602
- import { render as toPlainText } from 'datocms-structured-text-to-plain-text';
603
- import SyntaxHighlight from './components/SyntaxHighlight';
604
-
605
- export default {
606
- components: {
607
- "datocms-structured-text": StructuredText,
608
- "syntax-highlight": SyntaxHighlight,
609
- },
610
- data() {
611
- return {
612
- data: /* ... */,
613
- customNodeRules: [
614
- renderNodeRule(isHeading, ({ adapter: { renderNode: h }, node, children, key }) => {
615
- const anchor = toPlainText(node)
616
- .toLowerCase()
617
- .replace(/ /g, '-')
618
- .replace(/[^\w-]+/g, '');
619
-
620
- return h(
621
- `h${node.level}`, { key }, [
622
- ...children,
623
- h('a', { attrs: { id: anchor } }, []),
624
- h('a', { attrs: { href: `#${anchor}` } }, []),
625
- ]
626
- );
627
- }),
628
- renderNodeRule(isCode, ({ adapter: { renderNode: h }, node, key }) => {
629
- return h('syntax-highlight', {
630
- key,
631
- code: node.code,
632
- language: node.language,
633
- linesToBeHighlighted: node.highlight,
634
- }, []);
635
- }),
636
- ],
637
- customMarkRules: [
638
- // convert "strong" marks into <b> tags
639
- renderMarkRule('strong', ({ adapter: { renderNode: h }, mark, children, key }) => {
640
- return h('b', {key}, children);
641
- }),
642
- ],
643
- };
644
- },
645
- };
646
- </script>
60
+ ```bash
61
+ npm install
62
+ cd examples/vite-typescript-vue3
63
+ npm run setup
64
+ npm run dev
647
65
  ```
648
66
 
649
- Note: if you override the rules for `inline_item`, `item_link` or `block` nodes, then the `renderInlineRecord`, `renderLinkToRecord` and `renderBlock` props won't be considered!
650
-
651
- ## Props
652
-
653
- | prop | type | required | description | default |
654
- | ------------------ | ---------------------------------------------------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
655
- | data | `StructuredTextGraphQlResponse \| DastNode` | :white_check_mark: | The actual [field value](https://www.datocms.com/docs/structured-text/dast) you get from DatoCMS | |
656
- | renderInlineRecord | `({ record }) => VNode \| null` | Only required if document contains `inlineItem` nodes | Convert an `inlineItem` DAST node into a VNode | `[]` |
657
- | renderLinkToRecord | `({ record, children, transformedMeta }) => VNode \| null` | Only required if document contains `itemLink` nodes | Convert an `itemLink` DAST node into a VNode | `null` |
658
- | renderBlock | `({ record }) => VNode \| null` | Only required if document contains `block` nodes | Convert a `block` DAST node into a VNode | `null` |
659
- | metaTransformer | `({ node, meta }) => Object \| null` | :x: | Transform `link` and `itemLink` meta property into HTML props | [See function](https://github.com/datocms/structured-text/blob/main/packages/generic-html-renderer/src/index.ts#L61) |
660
- | customNodeRules | `Array<RenderRule>` | :x: | Customize how nodes are converted in JSX (use `renderNodeRule()` to generate) | `null` |
661
- | customMarkRules | `Array<RenderMarkRule>` | :x: | Customize how marks are converted in JSX (use `renderMarkRule()` to generate) | `null` |
662
- | renderText | `(text: string, key: string) => VNode \| string \| null` | :x: | Convert a simple string text into a VNode | `(text) => text` |
67
+ Due to the way Vue and VueDemi work, it's not recommended to leverage `npm link` to use the working copy from the examples: that would complicate the structure of each example and it would not replicate a real-world installation. Therefore the `npm run setup` available in each example packs and installs the local copy of `vue-datocms` via a `.tgz` compressed tarball.