vue-datocms 8.0.0 → 8.1.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/dist/index.cjs.js CHANGED
@@ -679,6 +679,9 @@ const StructuredText = vue.defineComponent({
679
679
  renderBlock: {
680
680
  type: Function
681
681
  },
682
+ renderInlineBlock: {
683
+ type: Function
684
+ },
682
685
  metaTransformer: { type: Function },
683
686
  renderText: { type: Function },
684
687
  renderNode: { type: Function },
@@ -785,6 +788,33 @@ const StructuredText = vue.defineComponent({
785
788
  key
786
789
  );
787
790
  }),
791
+ datocmsStructuredTextGenericHtmlRenderer.renderNodeRule(datocmsStructuredTextUtils.isInlineBlock, ({ node, key }) => {
792
+ if (!props.renderInlineBlock) {
793
+ throw new datocmsStructuredTextUtils.RenderError(
794
+ `The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`,
795
+ node
796
+ );
797
+ }
798
+ if (!datocmsStructuredTextUtils.isStructuredText(props.data) || !props.data.blocks) {
799
+ throw new datocmsStructuredTextUtils.RenderError(
800
+ `The Structured Text document contains an 'inlineBlock' node, but .blocks is not present!`,
801
+ node
802
+ );
803
+ }
804
+ const item = props.data.blocks.find(
805
+ (item2) => item2.id === node.item
806
+ );
807
+ if (!item) {
808
+ throw new datocmsStructuredTextUtils.RenderError(
809
+ `The Structured Text document contains a 'block' node, but cannot find a record with ID ${node.item} inside .blocks!`,
810
+ node
811
+ );
812
+ }
813
+ return appendKeyToValidElement(
814
+ props.renderInlineBlock({ record: item }),
815
+ key
816
+ );
817
+ }),
788
818
  ...props.customNodeRules || props.customRules || []
789
819
  ]
790
820
  });
package/dist/index.d.ts CHANGED
@@ -443,31 +443,35 @@ declare const StructuredText: vue.DefineComponent<{
443
443
  customMarkRules: {
444
444
  type: PropType<RenderMarkRule<typeof h, (text: string, _key: string) => AdapterReturn, (children: AdapterReturn[], _key: string) => AdapterReturn>[]>;
445
445
  };
446
- /** Fuction that converts an 'inlineItem' node into React **/
446
+ /** Fuction that converts an 'inlineItem' node into a Vue component **/
447
447
  renderInlineRecord: {
448
448
  type: PropType<(context: RenderInlineRecordContext<any>) => AdapterReturn>;
449
449
  };
450
- /** Fuction that converts an 'itemLink' node into React **/
450
+ /** Fuction that converts an 'itemLink' node into a Vue component **/
451
451
  renderLinkToRecord: {
452
452
  type: PropType<(context: RenderRecordLinkContext<any>) => AdapterReturn>;
453
453
  };
454
- /** Fuction that converts a 'block' node into React **/
454
+ /** Fuction that converts a 'block' node into a Vue component **/
455
455
  renderBlock: {
456
456
  type: PropType<(context: RenderBlockContext<any>) => AdapterReturn>;
457
457
  };
458
+ /** Fuction that converts an 'inlineBlock' node into a Vue component **/
459
+ renderInlineBlock: {
460
+ type: PropType<(context: RenderBlockContext<any>) => AdapterReturn>;
461
+ };
458
462
  /** Function that converts 'link' and 'itemLink' `meta` into HTML props */
459
463
  metaTransformer: {
460
464
  type: PropType<TransformMetaFn>;
461
465
  };
462
- /** Fuction that converts a simple string text into React **/
466
+ /** Fuction that converts a simple string text into a Vue component **/
463
467
  renderText: {
464
468
  type: PropType<(text: string, _key: string) => AdapterReturn>;
465
469
  };
466
- /** React.createElement-like function to use to convert a node into React **/
470
+ /** React.createElement-like function to use to convert a node into a Vue component **/
467
471
  renderNode: {
468
472
  type: PropType<typeof h>;
469
473
  };
470
- /** Function to use to generate a React.Fragment **/
474
+ /** Function to use to generate a Vue.Fragment **/
471
475
  renderFragment: {
472
476
  type: PropType<(children: AdapterReturn[], _key: string) => AdapterReturn>;
473
477
  };
@@ -488,31 +492,35 @@ declare const StructuredText: vue.DefineComponent<{
488
492
  customMarkRules: {
489
493
  type: PropType<RenderMarkRule<typeof h, (text: string, _key: string) => AdapterReturn, (children: AdapterReturn[], _key: string) => AdapterReturn>[]>;
490
494
  };
491
- /** Fuction that converts an 'inlineItem' node into React **/
495
+ /** Fuction that converts an 'inlineItem' node into a Vue component **/
492
496
  renderInlineRecord: {
493
497
  type: PropType<(context: RenderInlineRecordContext<any>) => AdapterReturn>;
494
498
  };
495
- /** Fuction that converts an 'itemLink' node into React **/
499
+ /** Fuction that converts an 'itemLink' node into a Vue component **/
496
500
  renderLinkToRecord: {
497
501
  type: PropType<(context: RenderRecordLinkContext<any>) => AdapterReturn>;
498
502
  };
499
- /** Fuction that converts a 'block' node into React **/
503
+ /** Fuction that converts a 'block' node into a Vue component **/
500
504
  renderBlock: {
501
505
  type: PropType<(context: RenderBlockContext<any>) => AdapterReturn>;
502
506
  };
507
+ /** Fuction that converts an 'inlineBlock' node into a Vue component **/
508
+ renderInlineBlock: {
509
+ type: PropType<(context: RenderBlockContext<any>) => AdapterReturn>;
510
+ };
503
511
  /** Function that converts 'link' and 'itemLink' `meta` into HTML props */
504
512
  metaTransformer: {
505
513
  type: PropType<TransformMetaFn>;
506
514
  };
507
- /** Fuction that converts a simple string text into React **/
515
+ /** Fuction that converts a simple string text into a Vue component **/
508
516
  renderText: {
509
517
  type: PropType<(text: string, _key: string) => AdapterReturn>;
510
518
  };
511
- /** React.createElement-like function to use to convert a node into React **/
519
+ /** React.createElement-like function to use to convert a node into a Vue component **/
512
520
  renderNode: {
513
521
  type: PropType<typeof h>;
514
522
  };
515
- /** Function to use to generate a React.Fragment **/
523
+ /** Function to use to generate a Vue.Fragment **/
516
524
  renderFragment: {
517
525
  type: PropType<(children: AdapterReturn[], _key: string) => AdapterReturn>;
518
526
  };
@@ -2,7 +2,7 @@ import { ref, onMounted, onBeforeUnmount, defineComponent, h, watchEffect, unref
2
2
  import hypenateStyleName from 'hyphenate-style-name';
3
3
  import { render, renderNodeRule, defaultMetaTransformer } from 'datocms-structured-text-generic-html-renderer';
4
4
  export { renderMarkRule, renderNodeRule, renderNodeRule as renderRule } from 'datocms-structured-text-generic-html-renderer';
5
- import { isRoot, isInlineItem, RenderError, isStructuredText, isItemLink, isBlock } from 'datocms-structured-text-utils';
5
+ import { isRoot, isInlineItem, RenderError, isStructuredText, isItemLink, isBlock, isInlineBlock } from 'datocms-structured-text-utils';
6
6
  export { RenderError } from 'datocms-structured-text-utils';
7
7
  import { subscribeToQuery } from 'datocms-listen';
8
8
 
@@ -655,6 +655,9 @@ const StructuredText = defineComponent({
655
655
  renderBlock: {
656
656
  type: Function
657
657
  },
658
+ renderInlineBlock: {
659
+ type: Function
660
+ },
658
661
  metaTransformer: { type: Function },
659
662
  renderText: { type: Function },
660
663
  renderNode: { type: Function },
@@ -761,6 +764,33 @@ const StructuredText = defineComponent({
761
764
  key
762
765
  );
763
766
  }),
767
+ renderNodeRule(isInlineBlock, ({ node, key }) => {
768
+ if (!props.renderInlineBlock) {
769
+ throw new RenderError(
770
+ `The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`,
771
+ node
772
+ );
773
+ }
774
+ if (!isStructuredText(props.data) || !props.data.blocks) {
775
+ throw new RenderError(
776
+ `The Structured Text document contains an 'inlineBlock' node, but .blocks is not present!`,
777
+ node
778
+ );
779
+ }
780
+ const item = props.data.blocks.find(
781
+ (item2) => item2.id === node.item
782
+ );
783
+ if (!item) {
784
+ throw new RenderError(
785
+ `The Structured Text document contains a 'block' node, but cannot find a record with ID ${node.item} inside .blocks!`,
786
+ node
787
+ );
788
+ }
789
+ return appendKeyToValidElement(
790
+ props.renderInlineBlock({ record: item }),
791
+ key
792
+ );
793
+ }),
764
794
  ...props.customNodeRules || props.customRules || []
765
795
  ]
766
796
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-datocms",
3
- "version": "8.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "A set of components and utilities to work faster with DatoCMS in Vue.js environments",
5
5
  "keywords": [
6
6
  "datocms",
@@ -42,9 +42,9 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "datocms-listen": "^0.1.15",
45
- "datocms-structured-text-generic-html-renderer": "^4.0.1",
46
- "datocms-structured-text-utils": "^4.0.1",
47
45
  "hls.js": "^1.5.17",
46
+ "datocms-structured-text-generic-html-renderer": "^4.1.2",
47
+ "datocms-structured-text-utils": "^4.1.2",
48
48
  "hyphenate-style-name": "^1.0.4"
49
49
  },
50
50
  "peerDependencies": {