@prismicio/vue 5.3.0-pr.88.ee9acb6 → 5.3.0-pr.89.d0f4ac2

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.
Files changed (134) hide show
  1. package/dist/PrismicImage.vue.d.cts +15 -49
  2. package/dist/PrismicImage.vue.d.cts.map +1 -1
  3. package/dist/PrismicLink.vue.d.cts +57 -52
  4. package/dist/PrismicLink.vue.d.cts.map +1 -1
  5. package/dist/PrismicRichText/PrismicRichText.vue.d.cts +14 -14
  6. package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
  7. package/dist/PrismicRichText/types.d.cts +25 -26
  8. package/dist/PrismicRichText/types.d.cts.map +1 -1
  9. package/dist/PrismicTable/PrismicTable.vue.d.cts +8 -9
  10. package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
  11. package/dist/PrismicTable/types.d.cts +7 -8
  12. package/dist/PrismicTable/types.d.cts.map +1 -1
  13. package/dist/PrismicText.vue.d.cts +2 -6
  14. package/dist/PrismicText.vue.d.cts.map +1 -1
  15. package/dist/SliceZone/SliceZone.vue.d.cts +3 -14
  16. package/dist/SliceZone/SliceZone.vue.d.cts.map +1 -1
  17. package/dist/SliceZone/types.d.cts +3 -9
  18. package/dist/SliceZone/types.d.cts.map +1 -1
  19. package/dist/createPrismic.d.cts +61 -0
  20. package/dist/createPrismic.d.cts.map +1 -0
  21. package/dist/index.cjs +4 -1
  22. package/dist/index.d.cts +4 -2
  23. package/dist/index.d.ts +4 -2
  24. package/dist/index.js +2 -1
  25. package/dist/package.cjs +1 -1
  26. package/dist/package.cjs.map +1 -1
  27. package/dist/package.js +1 -1
  28. package/dist/package.js.map +1 -1
  29. package/dist/src/PrismicImage.cjs.map +1 -1
  30. package/dist/src/PrismicImage.js.map +1 -1
  31. package/dist/src/PrismicImage.vue.d.ts +15 -49
  32. package/dist/src/PrismicImage.vue.d.ts.map +1 -1
  33. package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  34. package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.js.map +1 -1
  35. package/dist/src/PrismicLink.cjs.map +1 -1
  36. package/dist/src/PrismicLink.js.map +1 -1
  37. package/dist/src/PrismicLink.vue.d.ts +57 -52
  38. package/dist/src/PrismicLink.vue.d.ts.map +1 -1
  39. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs +6 -10
  40. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  41. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.js +6 -10
  42. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.js.map +1 -1
  43. package/dist/src/PrismicRichText/PrismicRichText.cjs.map +1 -1
  44. package/dist/src/PrismicRichText/PrismicRichText.js.map +1 -1
  45. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts +18 -18
  46. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts.map +1 -1
  47. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs +11 -5
  48. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  49. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js +11 -5
  50. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js.map +1 -1
  51. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.cjs.map +1 -1
  52. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.js.map +1 -1
  53. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs +2 -2
  54. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  55. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js +2 -2
  56. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js.map +1 -1
  57. package/dist/src/PrismicRichText/PrismicRichTextSerialize.cjs.map +1 -1
  58. package/dist/src/PrismicRichText/PrismicRichTextSerialize.js.map +1 -1
  59. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs +10 -4
  60. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  61. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js +11 -5
  62. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
  63. package/dist/src/PrismicRichText/index.d.ts +1 -1
  64. package/dist/src/PrismicRichText/types.d.ts +25 -26
  65. package/dist/src/PrismicRichText/types.d.ts.map +1 -1
  66. package/dist/src/PrismicTable/PrismicTable.cjs.map +1 -1
  67. package/dist/src/PrismicTable/PrismicTable.js.map +1 -1
  68. package/dist/src/PrismicTable/PrismicTable.vue.d.ts +10 -11
  69. package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
  70. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +18 -10
  71. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  72. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js +19 -11
  73. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
  74. package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs +12 -30
  75. package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
  76. package/dist/src/PrismicTable/PrismicTableDefaultComponents.js +12 -30
  77. package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
  78. package/dist/src/PrismicTable/PrismicTableRow.cjs.map +1 -1
  79. package/dist/src/PrismicTable/PrismicTableRow.js.map +1 -1
  80. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  81. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
  82. package/dist/src/PrismicTable/index.d.ts +1 -0
  83. package/dist/src/PrismicTable/types.d.ts +7 -8
  84. package/dist/src/PrismicTable/types.d.ts.map +1 -1
  85. package/dist/src/PrismicText.cjs.map +1 -1
  86. package/dist/src/PrismicText.js.map +1 -1
  87. package/dist/src/PrismicText.vue.d.ts +2 -6
  88. package/dist/src/PrismicText.vue.d.ts.map +1 -1
  89. package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  90. package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.js.map +1 -1
  91. package/dist/src/SliceZone/SliceZone.cjs.map +1 -1
  92. package/dist/src/SliceZone/SliceZone.js.map +1 -1
  93. package/dist/src/SliceZone/SliceZone.vue.d.ts +3 -14
  94. package/dist/src/SliceZone/SliceZone.vue.d.ts.map +1 -1
  95. package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  96. package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.js.map +1 -1
  97. package/dist/src/SliceZone/types.d.ts +3 -9
  98. package/dist/src/SliceZone/types.d.ts.map +1 -1
  99. package/dist/src/createPrismic.cjs +33 -0
  100. package/dist/src/createPrismic.cjs.map +1 -0
  101. package/dist/src/createPrismic.d.ts +63 -0
  102. package/dist/src/createPrismic.d.ts.map +1 -0
  103. package/dist/src/createPrismic.js +32 -0
  104. package/dist/src/createPrismic.js.map +1 -0
  105. package/dist/src/lib/isInternalURL.cjs +2 -6
  106. package/dist/src/lib/isInternalURL.cjs.map +1 -1
  107. package/dist/src/lib/isInternalURL.js +2 -6
  108. package/dist/src/lib/isInternalURL.js.map +1 -1
  109. package/dist/src/types.cjs.map +1 -1
  110. package/dist/src/types.d.ts +11 -1
  111. package/dist/src/types.d.ts.map +1 -1
  112. package/dist/src/types.js.map +1 -1
  113. package/dist/types.d.cts +11 -1
  114. package/dist/types.d.cts.map +1 -1
  115. package/package.json +1 -3
  116. package/src/PrismicImage.vue +5 -16
  117. package/src/PrismicLink.vue +26 -26
  118. package/src/PrismicRichText/PrismicRichText.vue +33 -23
  119. package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +8 -4
  120. package/src/PrismicRichText/PrismicRichTextSerialize.vue +4 -3
  121. package/src/PrismicRichText/index.ts +1 -1
  122. package/src/PrismicRichText/types.ts +57 -29
  123. package/src/PrismicTable/PrismicTable.vue +31 -23
  124. package/src/PrismicTable/PrismicTableDefaultComponents.ts +14 -39
  125. package/src/PrismicTable/PrismicTableRow.vue +2 -2
  126. package/src/PrismicTable/index.ts +2 -0
  127. package/src/PrismicTable/types.ts +41 -23
  128. package/src/PrismicText.vue +2 -6
  129. package/src/SliceZone/SliceZone.vue +3 -14
  130. package/src/SliceZone/types.ts +3 -9
  131. package/src/createPrismic.ts +86 -0
  132. package/src/index.ts +5 -1
  133. package/src/lib/isInternalURL.ts +2 -6
  134. package/src/types.ts +13 -1
@@ -8,51 +8,54 @@ import { asTree } from "@prismicio/client/richtext"
8
8
  import type { PropType } from "vue"
9
9
  import { computed } from "vue"
10
10
 
11
- import { type ComponentOrTagName, isVueComponent } from "../types"
11
+ import type { ComponentOrTagName, VueComponentShorthand } from "../types"
12
+ import { isVueComponent } from "../types"
12
13
  import type {
13
- InternalVueRichTextComponent,
14
- VueRichTextSerializer,
15
- VueShorthand,
14
+ InternalVueRichTextComponents,
15
+ VueRichTextComponent,
16
+ VueRichTextComponents,
16
17
  } from "./types"
17
18
 
19
+ import { usePrismic } from "../createPrismic"
20
+
18
21
  import PrismicRichTextDefaultComponent from "./PrismicRichTextDefaultComponent.vue"
19
22
  import PrismicRichTextSerialize from "./PrismicRichTextSerialize.vue"
20
23
 
21
- /**
22
- * Props for `<PrismicRichText />`.
23
- */
24
+ /** Props for `<PrismicRichText />`. */
24
25
  export type PrismicRichTextProps = {
25
- /**
26
- * The Prismic rich text or title field to render.
27
- */
26
+ /** The Prismic rich text field to render. */
28
27
  field: RichTextField | null | undefined
29
28
 
30
29
  /**
31
- * A link resolver function used to resolve link when not using the route
32
- * resolver parameter with `@prismicio/client`.
30
+ * The link resolver used to resolve links.
33
31
  *
34
- * @defaultValue The link resolver provided to `@prismicio/vue` plugin if configured.
32
+ * @remarks
33
+ * If your app uses route resolvers when querying for your Prismic
34
+ * repository's content, a link resolver does not need to be provided.
35
35
  *
36
- * @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
36
+ * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
37
37
  */
38
38
  linkResolver?: LinkResolverFunction
39
39
 
40
40
  /**
41
- * An object that maps a rich text block type to a Vue component.
41
+ * An object that maps a rich text block type to a Vue component or a
42
+ * shorthand definition.
42
43
  *
43
44
  * @example
44
45
  *
45
46
  * ```javascript
46
47
  * {
47
48
  * heading1: Heading1,
49
+ * paragraph: { class: 'prose'},
50
+ * strong: { as: 'em', class: 'font-bold' },
48
51
  * }
49
52
  * ```
50
53
  */
51
- components?: VueRichTextSerializer
54
+ components?: VueRichTextComponents
52
55
 
53
56
  /**
54
57
  * The value to be rendered when the field is empty. If a fallback is not
55
- * given, `null` (nothing) will be rendered.
58
+ * given, `null` will be rendered.
56
59
  */
57
60
  fallback?: ComponentOrTagName
58
61
  }
@@ -77,12 +80,21 @@ const props = defineProps({
77
80
  })
78
81
  defineOptions({ name: "PrismicRichText" })
79
82
 
83
+ const { componentsConfig } = usePrismic()
84
+
85
+ const resolvedComponents = computed<VueRichTextComponents>(() => {
86
+ return { ...componentsConfig?.defaultComponents, ...props.components }
87
+ })
88
+
80
89
  const children = computed(() => {
81
90
  return asTree(props.field || []).children
82
91
  })
83
92
 
84
93
  function getInternalComponent(type: keyof typeof RichTextNodeType) {
85
- const maybeComponentOrShorthand = props.components?.[type]
94
+ const maybeComponentOrShorthand = resolvedComponents.value?.[type] as
95
+ | VueRichTextComponent
96
+ | VueComponentShorthand
97
+ | undefined
86
98
 
87
99
  if (isVueComponent(maybeComponentOrShorthand)) {
88
100
  return { is: maybeComponentOrShorthand }
@@ -90,14 +102,12 @@ function getInternalComponent(type: keyof typeof RichTextNodeType) {
90
102
 
91
103
  return {
92
104
  is: PrismicRichTextDefaultComponent,
93
- props: {
94
- linkResolver: props.linkResolver,
95
- shorthand: maybeComponentOrShorthand as VueShorthand,
96
- },
105
+ linkResolver: props.linkResolver,
106
+ shorthand: maybeComponentOrShorthand,
97
107
  }
98
108
  }
99
109
 
100
- const internalComponents = computed<InternalVueRichTextComponent>(() => {
110
+ const internalComponents = computed<InternalVueRichTextComponents>(() => {
101
111
  return {
102
112
  heading1: getInternalComponent("heading1"),
103
113
  heading2: getInternalComponent("heading2"),
@@ -2,7 +2,8 @@
2
2
  import type { LinkResolverFunction } from "@prismicio/client"
3
3
  import { computed } from "vue"
4
4
 
5
- import type { RichTextComponentProps, VueShorthand } from "./types"
5
+ import type { VueComponentShorthand } from "../types"
6
+ import type { RichTextComponentProps } from "./types"
6
7
 
7
8
  import PrismicImage from "../PrismicImage.vue"
8
9
  import PrismicLink from "../PrismicLink.vue"
@@ -10,13 +11,16 @@ import PrismicLink from "../PrismicLink.vue"
10
11
  const props = defineProps<
11
12
  RichTextComponentProps & {
12
13
  linkResolver?: LinkResolverFunction
13
- shorthand?: VueShorthand
14
+ shorthand?: VueComponentShorthand
14
15
  }
15
16
  >()
16
17
  defineOptions({ name: "PrismicRichTextDefaultComponent" })
17
18
 
18
19
  const as = computed(() => {
19
- return props.node.type !== "image" && props.node.type !== "span"
20
+ return props.node.type !== "image" &&
21
+ props.node.type !== "hyperlink" &&
22
+ props.node.type !== "label" &&
23
+ props.node.type !== "span"
20
24
  ? props.shorthand?.as
21
25
  : undefined
22
26
  })
@@ -74,7 +78,7 @@ const dir = computed(() => {
74
78
  </ol>
75
79
  <p class="block-img" v-else-if="node.type === 'image'">
76
80
  <PrismicLink v-if="node.linkTo" :field="node.linkTo"
77
- ><PrismicImage :field="node"
81
+ ><PrismicImage :field="node" v-bind="attrs"
78
82
  /></PrismicLink>
79
83
  <PrismicImage v-else :field="node" v-bind="attrs" />
80
84
  </p>
@@ -1,11 +1,11 @@
1
1
  <script lang="ts" setup>
2
2
  import type { asTree } from "@prismicio/client/richtext"
3
3
 
4
- import type { InternalVueRichTextComponent } from "./types"
4
+ import type { InternalVueRichTextComponents } from "./types"
5
5
 
6
6
  type PrismicRichTextSerializeProps = {
7
7
  children: ReturnType<typeof asTree>["children"]
8
- internalComponents: InternalVueRichTextComponent
8
+ internalComponents: InternalVueRichTextComponents
9
9
  }
10
10
 
11
11
  const props = defineProps<PrismicRichTextSerializeProps>()
@@ -18,7 +18,8 @@ defineOptions({ name: "PrismicRichTextSerialize" })
18
18
  :key="JSON.stringify(child)"
19
19
  :is="internalComponents[child.type].is"
20
20
  :node="child.node"
21
- v-bind="internalComponents[child.type].props"
21
+ :link-resolver="internalComponents[child.type].linkResolver"
22
+ :shorthand="internalComponents[child.type].shorthand"
22
23
  ><PrismicRichTextSerialize
23
24
  v-if="child.children.length"
24
25
  :children="child.children"
@@ -1,3 +1,3 @@
1
1
  export { getRichTextComponentProps } from "./getRichTextComponentProps"
2
2
 
3
- export type { VueRichTextSerializer, RichTextComponentProps } from "./types"
3
+ export type { VueRichTextComponents, RichTextComponentProps } from "./types"
@@ -1,10 +1,29 @@
1
1
  import type {
2
2
  LinkResolverFunction,
3
3
  RTAnyNode,
4
- RichTextNodeType,
4
+ RTEmNode,
5
+ RTEmbedNode,
6
+ RTHeading1Node,
7
+ RTHeading2Node,
8
+ RTHeading3Node,
9
+ RTHeading4Node,
10
+ RTHeading5Node,
11
+ RTHeading6Node,
12
+ RTImageNode,
13
+ RTLabelNode,
14
+ RTLinkNode,
15
+ RTListItemNode,
16
+ RTListNode,
17
+ RTOListItemNode,
18
+ RTOListNode,
19
+ RTParagraphNode,
20
+ RTPreformattedNode,
21
+ RTSpanNode,
22
+ RTStrongNode,
23
+ RichTextNodeTypes,
5
24
  } from "@prismicio/client"
6
25
 
7
- import type { VueComponent } from "../types"
26
+ import type { VueComponent, VueComponentShorthand } from "../types"
8
27
 
9
28
  /**
10
29
  * A map of Rich Text block types to Vue Components. It is used to render Rich
@@ -12,13 +31,37 @@ import type { VueComponent } from "../types"
12
31
  *
13
32
  * @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/rich-text}
14
33
  */
15
- export type VueRichTextSerializer = Partial<
16
- Record<keyof typeof RichTextNodeType, VueRichTextComponent | VueShorthand>
17
- >
34
+ export type VueRichTextComponents = {
35
+ heading1?: RichTextComponentProps<RTHeading1Node> | VueComponentShorthand
36
+ heading2?: RichTextComponentProps<RTHeading2Node> | VueComponentShorthand
37
+ heading3?: RichTextComponentProps<RTHeading3Node> | VueComponentShorthand
38
+ heading4?: RichTextComponentProps<RTHeading4Node> | VueComponentShorthand
39
+ heading5?: RichTextComponentProps<RTHeading5Node> | VueComponentShorthand
40
+ heading6?: RichTextComponentProps<RTHeading6Node> | VueComponentShorthand
41
+ paragraph?: RichTextComponentProps<RTParagraphNode> | VueComponentShorthand
42
+ preformatted?:
43
+ | RichTextComponentProps<RTPreformattedNode>
44
+ | VueComponentShorthand
45
+ strong?: RichTextComponentProps<RTStrongNode> | VueComponentShorthand
46
+ em?: RichTextComponentProps<RTEmNode> | VueComponentShorthand
47
+ listItem?: RichTextComponentProps<RTListItemNode> | VueComponentShorthand
48
+ oListItem?: RichTextComponentProps<RTOListItemNode> | VueComponentShorthand
49
+ list?: RichTextComponentProps<RTListNode> | VueComponentShorthand
50
+ oList?: RichTextComponentProps<RTOListNode> | VueComponentShorthand
51
+ image?:
52
+ | RichTextComponentProps<RTImageNode>
53
+ | Omit<VueComponentShorthand, "as">
54
+ embed?: RichTextComponentProps<RTEmbedNode> | VueComponentShorthand
55
+ hyperlink?:
56
+ | RichTextComponentProps<RTLinkNode>
57
+ | Omit<VueComponentShorthand, "as">
58
+ label?:
59
+ | RichTextComponentProps<RTLabelNode>
60
+ | Omit<VueComponentShorthand, "as">
61
+ span?: RichTextComponentProps<RTSpanNode>
62
+ }
18
63
 
19
- /**
20
- * Props for a component rendering nodes from a Prismic rich text field.
21
- */
64
+ /** Props for a component rendering nodes from a Prismic rich text field. */
22
65
  export type RichTextComponentProps<TRTNode extends RTAnyNode = RTAnyNode> = {
23
66
  node: TRTNode
24
67
  }
@@ -28,29 +71,14 @@ export type RichTextComponentProps<TRTNode extends RTAnyNode = RTAnyNode> = {
28
71
  *
29
72
  * @typeParam TRTNode - The type of rich text node(s) this component handles
30
73
  */
31
- type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> = VueComponent<
32
- RichTextComponentProps<TRTNode>
33
- >
34
-
35
- /**
36
- * A shorthand definition for {@link VueRichTextSerializer} component types.
37
- */
38
- export type VueShorthand = {
39
- /**
40
- * The HTML element type rendered for this node type.
41
- */
42
- as?: string
43
-
44
- /**
45
- * Other attributes to apply to the element type.
46
- */
47
- [Attribute: string]: string | boolean | null | undefined
48
- }
74
+ export type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> =
75
+ VueComponent<RichTextComponentProps<TRTNode>>
49
76
 
50
- export type InternalVueRichTextComponent = Record<
51
- (typeof RichTextNodeType)[keyof typeof RichTextNodeType],
77
+ export type InternalVueRichTextComponents = Record<
78
+ RichTextNodeTypes,
52
79
  {
53
80
  is: VueRichTextComponent
54
- props?: { linkResolver?: LinkResolverFunction; shorthand?: VueShorthand }
81
+ linkResolver?: LinkResolverFunction
82
+ shorthand?: VueComponentShorthand
55
83
  }
56
84
  >
@@ -2,36 +2,36 @@
2
2
  import { type TableField, isFilled } from "@prismicio/client"
3
3
  import { computed } from "vue"
4
4
 
5
- import type { VueShorthand } from "../PrismicRichText/types"
6
- import { type ComponentOrTagName, isVueComponent } from "../types"
5
+ import type { ComponentOrTagName, VueComponentShorthand } from "../types"
6
+ import { isVueComponent } from "../types"
7
7
  import type { InternalVueTableComponents, VueTableComponents } from "./types"
8
8
 
9
- import type { VueRichTextSerializer } from "../PrismicRichText"
9
+ import type { VueRichTextComponents } from "../PrismicRichText"
10
+ import { usePrismic } from "../createPrismic"
10
11
 
11
12
  import { defaultTableComponents } from "./PrismicTableDefaultComponents"
12
13
  import PrismicTableRow from "./PrismicTableRow.vue"
13
14
 
14
- /**
15
- * Props for `<PrismicTable />`.
16
- */
15
+ /** Props for `<PrismicTable />`. */
17
16
  export type PrismicTableProps = {
18
- /**
19
- * The Prismic table field to render.
20
- */
17
+ /** The Prismic table field to render. */
21
18
  field: TableField | undefined
22
19
 
23
20
  /**
24
- * An object that maps a table block type to a Vue component.
21
+ * An object that maps a table block type to a Vue component or a shorthand
22
+ * definition.
25
23
  *
26
24
  * @example
27
25
  *
28
26
  * ```javascript
29
27
  * {
30
28
  * table: Table,
29
+ * thead: { class: 'bg-black text-white' },
30
+ * th: { as: 'td', class: 'font-bold' },
31
31
  * }
32
32
  * ```
33
33
  */
34
- components?: VueTableComponents & VueRichTextSerializer
34
+ components?: VueTableComponents & VueRichTextComponents
35
35
 
36
36
  /**
37
37
  * The value to be rendered when the field is empty. If a fallback is not
@@ -43,8 +43,16 @@ export type PrismicTableProps = {
43
43
  const props = defineProps<PrismicTableProps>()
44
44
  defineOptions({ name: "PrismicTable" })
45
45
 
46
+ const { componentsConfig } = usePrismic()
47
+
48
+ const resolvedComponents = computed<VueTableComponents & VueRichTextComponents>(
49
+ () => {
50
+ return { ...componentsConfig?.defaultComponents, ...props.components }
51
+ },
52
+ )
53
+
46
54
  function getInternalComponent(type: keyof VueTableComponents) {
47
- const maybeComponentOrShorthand = props.components?.[type]
55
+ const maybeComponentOrShorthand = resolvedComponents.value?.[type]
48
56
 
49
57
  if (isVueComponent(maybeComponentOrShorthand)) {
50
58
  return { is: maybeComponentOrShorthand }
@@ -52,11 +60,11 @@ function getInternalComponent(type: keyof VueTableComponents) {
52
60
 
53
61
  return {
54
62
  is: defaultTableComponents[type],
55
- shorthand: maybeComponentOrShorthand as VueShorthand,
63
+ shorthand: maybeComponentOrShorthand as VueComponentShorthand,
56
64
  }
57
65
  }
58
66
 
59
- const tableComponents = computed<InternalVueTableComponents>(() => {
67
+ const internalTableComponents = computed<InternalVueTableComponents>(() => {
60
68
  return {
61
69
  table: getInternalComponent("table"),
62
70
  thead: getInternalComponent("thead"),
@@ -71,37 +79,37 @@ const tableComponents = computed<InternalVueTableComponents>(() => {
71
79
  <template>
72
80
  <component
73
81
  v-if="isFilled.table(field)"
74
- :is="tableComponents.table.is"
82
+ :is="internalTableComponents.table.is"
75
83
  :table="field"
76
- v-bind="{ ...$attrs, ...tableComponents.table.shorthand }"
84
+ v-bind="{ ...$attrs, ...internalTableComponents.table.shorthand }"
77
85
  >
78
86
  <component
79
87
  v-if="field.head"
80
- :is="tableComponents.thead.is"
88
+ :is="internalTableComponents.thead.is"
81
89
  :head="field.head"
82
- v-bind="tableComponents.thead.shorthand"
90
+ v-bind="internalTableComponents.thead.shorthand"
83
91
  >
84
92
  <PrismicTableRow
85
93
  v-for="row in field.head.rows"
86
94
  :key="row.key"
87
95
  :row="row"
88
- :internalTableComponents="tableComponents"
96
+ :internalTableComponents="internalTableComponents"
89
97
  :components="components"
90
98
  />
91
99
  </component>
92
100
  <component
93
- :is="tableComponents.tbody.is"
101
+ :is="internalTableComponents.tbody.is"
94
102
  :body="field.body"
95
- v-bind="tableComponents.tbody.shorthand"
103
+ v-bind="internalTableComponents.tbody.shorthand"
96
104
  >
97
105
  <PrismicTableRow
98
106
  v-for="row in field.body.rows"
99
107
  :key="row.key"
100
108
  :row="row"
101
- :internalTableComponents="tableComponents"
109
+ :internalTableComponents="internalTableComponents"
102
110
  :components="components"
103
111
  />
104
112
  </component>
105
113
  </component>
106
- <component v-else-if="fallback" :is="fallback" />
114
+ <component v-else-if="fallback" :is="fallback" v-bind="$attrs" />
107
115
  </template>
@@ -1,69 +1,44 @@
1
1
  import { defineComponent, h } from "vue"
2
- import type { PropType } from "vue"
3
2
 
4
- import type { DefaultVueTableComponents } from "./types"
3
+ import type { VueTableComponents } from "./types"
5
4
 
6
5
  import * as getTableComponentProps from "./getTableComponentProps"
7
6
 
8
- export const defaultTableComponents: DefaultVueTableComponents = {
7
+ export const defaultTableComponents: Required<VueTableComponents> = {
9
8
  table: defineComponent({
10
- props: {
11
- ...getTableComponentProps.table(),
12
- as: { type: String as PropType<string | undefined> },
13
- },
9
+ props: getTableComponentProps.table(),
14
10
  setup(props, { attrs, slots }) {
15
- return () =>
16
- h(props.as ?? "table", attrs, slots.default ? slots.default() : [])
11
+ return () => h("table", attrs, slots.default ? slots.default() : [])
17
12
  },
18
13
  }),
19
14
  thead: defineComponent({
20
- props: {
21
- ...getTableComponentProps.thead(),
22
- as: { type: String as PropType<string | undefined> },
23
- },
15
+ props: getTableComponentProps.thead(),
24
16
  setup(props, { attrs, slots }) {
25
- return () =>
26
- h(props.as ?? "thead", attrs, slots.default ? slots.default() : [])
17
+ return () => h("thead", attrs, slots.default ? slots.default() : [])
27
18
  },
28
19
  }),
29
20
  tbody: defineComponent({
30
- props: {
31
- ...getTableComponentProps.tbody(),
32
- as: { type: String as PropType<string | undefined> },
33
- },
21
+ props: getTableComponentProps.tbody(),
34
22
  setup(props, { attrs, slots }) {
35
- return () =>
36
- h(props.as ?? "tbody", attrs, slots.default ? slots.default() : [])
23
+ return () => h("tbody", attrs, slots.default ? slots.default() : [])
37
24
  },
38
25
  }),
39
26
  tr: defineComponent({
40
- props: {
41
- ...getTableComponentProps.tr(),
42
- as: { type: String as PropType<string | undefined> },
43
- },
27
+ props: getTableComponentProps.tr(),
44
28
  setup(props, { attrs, slots }) {
45
- return () =>
46
- h(props.as ?? "tr", attrs, slots.default ? slots.default() : [])
29
+ return () => h("tr", attrs, slots.default ? slots.default() : [])
47
30
  },
48
31
  }),
49
32
  th: defineComponent({
50
- props: {
51
- ...getTableComponentProps.th(),
52
- as: { type: String as PropType<string | undefined> },
53
- },
33
+ props: getTableComponentProps.th(),
54
34
  setup(props, { attrs, slots }) {
55
- return () =>
56
- h(props.as ?? "th", attrs, slots.default ? slots.default() : [])
35
+ return () => h("th", attrs, slots.default ? slots.default() : [])
57
36
  },
58
37
  }),
59
38
  td: defineComponent({
60
- props: {
61
- ...getTableComponentProps.td(),
62
- as: { type: String as PropType<string | undefined> },
63
- },
39
+ props: getTableComponentProps.td(),
64
40
  setup(props, { attrs, slots }) {
65
- return () =>
66
- h(props.as ?? "td", attrs, slots.default ? slots.default() : [])
41
+ return () => h("td", attrs, slots.default ? slots.default() : [])
67
42
  },
68
43
  }),
69
44
  }
@@ -3,13 +3,13 @@ import type { TableFieldBodyRow, TableFieldHeadRow } from "@prismicio/client"
3
3
 
4
4
  import type { InternalVueTableComponents } from "./types"
5
5
 
6
- import type { VueRichTextSerializer } from "../PrismicRichText"
6
+ import type { VueRichTextComponents } from "../PrismicRichText"
7
7
  import PrismicRichText from "../PrismicRichText/PrismicRichText.vue"
8
8
 
9
9
  export type PrismicTableRowProps = {
10
10
  row: TableFieldHeadRow | TableFieldBodyRow
11
11
  internalTableComponents: InternalVueTableComponents
12
- components?: VueRichTextSerializer
12
+ components?: VueRichTextComponents
13
13
  }
14
14
 
15
15
  const props = defineProps<PrismicTableRowProps>()
@@ -1 +1,3 @@
1
1
  export * as getTableComponentProps from "./getTableComponentProps"
2
+
3
+ export type { VueTableComponents } from "./types"
@@ -8,8 +8,7 @@ import type {
8
8
  TableFieldHeaderCell,
9
9
  } from "@prismicio/client"
10
10
 
11
- import type { VueShorthand } from "../PrismicRichText/types"
12
- import type { VueComponent } from "../types"
11
+ import type { VueComponent, VueComponentShorthand } from "../types"
13
12
 
14
13
  /**
15
14
  * A map of Table block types to Vue Components. It is used to render table
@@ -18,30 +17,49 @@ import type { VueComponent } from "../types"
18
17
  * @see Templating Table fields from Prismic {@link https://prismic.io/docs/table}
19
18
  */
20
19
  export type VueTableComponents = {
21
- table?: VueComponent<{ table: TableField<"filled"> }> | VueShorthand
22
- thead?: VueComponent<{ head: TableFieldHead }> | VueShorthand
23
- tbody?: VueComponent<{ body: TableFieldBody }> | VueShorthand
20
+ table?:
21
+ | VueComponent<{ table: TableField<"filled"> }>
22
+ | Omit<VueComponentShorthand, "as">
23
+ thead?:
24
+ | VueComponent<{ head: TableFieldHead }>
25
+ | Omit<VueComponentShorthand, "as">
26
+ tbody?:
27
+ | VueComponent<{ body: TableFieldBody }>
28
+ | Omit<VueComponentShorthand, "as">
24
29
  tr?:
25
30
  | VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }>
26
- | VueShorthand
27
- th?: VueComponent<{ cell: TableFieldHeaderCell }> | VueShorthand
28
- td?: VueComponent<{ cell: TableFieldDataCell }> | VueShorthand
29
- }
30
-
31
- export type DefaultVueTableComponents = {
32
- table: VueComponent<{ table: TableField<"filled">; as?: string }>
33
- thead: VueComponent<{ head: TableFieldHead; as?: string }>
34
- tbody: VueComponent<{ body: TableFieldBody; as?: string }>
35
- tr: VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow; as?: string }>
36
- th: VueComponent<{ cell: TableFieldHeaderCell; as?: string }>
37
- td: VueComponent<{ cell: TableFieldDataCell; as?: string }>
31
+ | Omit<VueComponentShorthand, "as">
32
+ th?:
33
+ | VueComponent<{ cell: TableFieldHeaderCell }>
34
+ | Omit<VueComponentShorthand, "as">
35
+ td?:
36
+ | VueComponent<{ cell: TableFieldDataCell }>
37
+ | Omit<VueComponentShorthand, "as">
38
38
  }
39
39
 
40
40
  export type InternalVueTableComponents = {
41
- table: { is: VueTableComponents["table"]; shorthand?: VueShorthand }
42
- thead: { is: VueTableComponents["thead"]; shorthand?: VueShorthand }
43
- tbody: { is: VueTableComponents["tbody"]; shorthand?: VueShorthand }
44
- tr: { is: VueTableComponents["tr"]; shorthand?: VueShorthand }
45
- th: { is: VueTableComponents["th"]; shorthand?: VueShorthand }
46
- td: { is: VueTableComponents["td"]; shorthand?: VueShorthand }
41
+ table: {
42
+ is: VueTableComponents["table"]
43
+ shorthand?: Omit<VueComponentShorthand, "as">
44
+ }
45
+ thead: {
46
+ is: VueTableComponents["thead"]
47
+ shorthand?: Omit<VueComponentShorthand, "as">
48
+ }
49
+ tbody: {
50
+ is: VueTableComponents["tbody"]
51
+ shorthand?: Omit<VueComponentShorthand, "as">
52
+ }
53
+ tr: {
54
+ is: VueTableComponents["tr"]
55
+ shorthand?: Omit<VueComponentShorthand, "as">
56
+ }
57
+ th: {
58
+ is: VueTableComponents["th"]
59
+ shorthand?: Omit<VueComponentShorthand, "as">
60
+ }
61
+ td: {
62
+ is: VueTableComponents["td"]
63
+ shorthand?: Omit<VueComponentShorthand, "as">
64
+ }
47
65
  }
@@ -6,13 +6,9 @@ import { watchEffect } from "vue"
6
6
 
7
7
  import { devMsg } from "./lib/devMsg"
8
8
 
9
- /**
10
- * Props for `<PrismicText />`.
11
- */
9
+ /** Props for `<PrismicText />`. */
12
10
  export type PrismicTextProps = {
13
- /**
14
- * The Prismic rich text field to render.
15
- */
11
+ /** The Prismic rich text field to render. */
16
12
  field: RichTextField | null | undefined
17
13
 
18
14
  /**
@@ -16,31 +16,20 @@ import { TODOSliceComponent } from "./TODOSliceComponent"
16
16
  * @typeParam TContext - Arbitrary data made available to all Slice components
17
17
  */
18
18
  export type SliceZoneProps<TContext = unknown> = {
19
- /**
20
- * List of Slice data from the Slice Zone.
21
- */
19
+ /** List of slice data from the slice zone. */
22
20
  slices: SliceZoneLike<SliceLike | (SliceLike & Record<string, unknown>)>
23
21
 
24
- /**
25
- * A record mapping Slice types to Vue components.
26
- */
22
+ /** A record mapping slice types to React components. */
27
23
  components?: SliceZoneComponents
28
24
 
29
25
  /**
30
26
  * The Vue component rendered if a component mapping from the `components`
31
27
  * prop cannot be found.
32
- *
33
- * @remarks
34
- * Components will be rendered using the {@link SliceComponentProps} interface.
35
- *
36
- * @defaultValue The Slice Zone default component provided to `@prismicio/vue` plugin if configured, otherwise `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}.
37
28
  */
38
29
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
30
  defaultComponent?: SliceComponentType<any, TContext>
40
31
 
41
- /**
42
- * Arbitrary data made available to all Slice components.
43
- */
32
+ /** Arbitrary data made available to all slice components. */
44
33
  context?: TContext
45
34
  }
46
35