@prismicio/vue 5.3.0-pr.86.915aa0e → 5.3.0-pr.88.72388e2

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 (107) hide show
  1. package/dist/PrismicImage.vue.d.cts +26 -54
  2. package/dist/PrismicImage.vue.d.cts.map +1 -1
  3. package/dist/PrismicLink.vue.d.cts +56 -48
  4. package/dist/PrismicLink.vue.d.cts.map +1 -1
  5. package/dist/PrismicRichText/PrismicRichText.vue.d.cts +18 -41
  6. package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
  7. package/dist/PrismicRichText/types.d.cts +3 -3
  8. package/dist/PrismicRichText/types.d.cts.map +1 -1
  9. package/dist/PrismicTable/PrismicTable.vue.d.cts +4 -4
  10. package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
  11. package/dist/PrismicTable/types.d.cts +1 -2
  12. package/dist/PrismicTable/types.d.cts.map +1 -1
  13. package/dist/PrismicText.vue.d.cts +1 -3
  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/package.cjs +1 -1
  18. package/dist/package.cjs.map +1 -1
  19. package/dist/package.js +1 -1
  20. package/dist/package.js.map +1 -1
  21. package/dist/src/PrismicImage.cjs.map +1 -1
  22. package/dist/src/PrismicImage.js.map +1 -1
  23. package/dist/src/PrismicImage.vue.d.ts +30 -58
  24. package/dist/src/PrismicImage.vue.d.ts.map +1 -1
  25. package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  26. package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.js.map +1 -1
  27. package/dist/src/PrismicLink.cjs.map +1 -1
  28. package/dist/src/PrismicLink.js.map +1 -1
  29. package/dist/src/PrismicLink.vue.d.ts +60 -52
  30. package/dist/src/PrismicLink.vue.d.ts.map +1 -1
  31. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  32. package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.js.map +1 -1
  33. package/dist/src/PrismicRichText/PrismicRichText.cjs.map +1 -1
  34. package/dist/src/PrismicRichText/PrismicRichText.js.map +1 -1
  35. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts +22 -45
  36. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts.map +1 -1
  37. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs +39 -22
  38. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  39. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js +39 -22
  40. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js.map +1 -1
  41. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.cjs.map +1 -1
  42. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.js.map +1 -1
  43. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs +6 -26
  44. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  45. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js +6 -26
  46. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js.map +1 -1
  47. package/dist/src/PrismicRichText/PrismicRichTextSerialize.cjs.map +1 -1
  48. package/dist/src/PrismicRichText/PrismicRichTextSerialize.js.map +1 -1
  49. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs +7 -48
  50. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  51. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js +7 -48
  52. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
  53. package/dist/src/PrismicRichText/types.d.ts +3 -3
  54. package/dist/src/PrismicRichText/types.d.ts.map +1 -1
  55. package/dist/src/PrismicTable/PrismicTable.cjs.map +1 -1
  56. package/dist/src/PrismicTable/PrismicTable.js.map +1 -1
  57. package/dist/src/PrismicTable/PrismicTable.vue.d.ts +6 -6
  58. package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
  59. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +43 -15
  60. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  61. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js +44 -16
  62. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
  63. package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
  64. package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
  65. package/dist/src/PrismicTable/PrismicTableRow.cjs.map +1 -1
  66. package/dist/src/PrismicTable/PrismicTableRow.js.map +1 -1
  67. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs +13 -10
  68. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  69. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js +14 -11
  70. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
  71. package/dist/src/PrismicTable/types.d.ts +1 -2
  72. package/dist/src/PrismicTable/types.d.ts.map +1 -1
  73. package/dist/src/PrismicText.cjs.map +1 -1
  74. package/dist/src/PrismicText.js.map +1 -1
  75. package/dist/src/PrismicText.vue.d.ts +3 -5
  76. package/dist/src/PrismicText.vue.d.ts.map +1 -1
  77. package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  78. package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.js.map +1 -1
  79. package/dist/src/SliceZone/SliceZone.cjs.map +1 -1
  80. package/dist/src/SliceZone/SliceZone.js.map +1 -1
  81. package/dist/src/SliceZone/SliceZone.vue.d.ts +5 -16
  82. package/dist/src/SliceZone/SliceZone.vue.d.ts.map +1 -1
  83. package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  84. package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.js.map +1 -1
  85. package/dist/src/types.cjs +9 -0
  86. package/dist/src/types.cjs.map +1 -0
  87. package/dist/src/types.d.ts +3 -2
  88. package/dist/src/types.d.ts.map +1 -1
  89. package/dist/src/types.js +8 -0
  90. package/dist/src/types.js.map +1 -0
  91. package/dist/types.d.cts +3 -2
  92. package/dist/types.d.cts.map +1 -1
  93. package/package.json +1 -1
  94. package/src/PrismicImage.vue +8 -16
  95. package/src/PrismicLink.vue +12 -12
  96. package/src/PrismicRichText/PrismicRichText.vue +69 -49
  97. package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +38 -22
  98. package/src/PrismicRichText/PrismicRichTextSerialize.vue +5 -51
  99. package/src/PrismicRichText/types.ts +17 -13
  100. package/src/PrismicTable/PrismicTable.vue +44 -17
  101. package/src/PrismicTable/PrismicTableDefaultComponents.ts +14 -8
  102. package/src/PrismicTable/PrismicTableRow.vue +17 -24
  103. package/src/PrismicTable/types.ts +14 -11
  104. package/src/PrismicText.vue +1 -3
  105. package/src/SliceZone/SliceZone.vue +3 -14
  106. package/src/types.ts +31 -1
  107. package/src/lib/Wrapper.vue +0 -22
@@ -2,7 +2,6 @@
2
2
  import type { LinkResolverFunction } from "@prismicio/client"
3
3
  import { computed } from "vue"
4
4
 
5
- import type { ComponentOrTagName } from "../types"
6
5
  import type { RichTextComponentProps, VueShorthand } from "./types"
7
6
 
8
7
  import PrismicImage from "../PrismicImage.vue"
@@ -11,19 +10,21 @@ import PrismicLink from "../PrismicLink.vue"
11
10
  const props = defineProps<
12
11
  RichTextComponentProps & {
13
12
  linkResolver?: LinkResolverFunction
14
- internalLinkComponent?: ComponentOrTagName
15
- externalLinkComponent?: ComponentOrTagName
16
13
  shorthand?: VueShorthand
17
14
  }
18
15
  >()
19
16
  defineOptions({ name: "PrismicRichTextDefaultComponent" })
20
17
 
21
18
  const as = computed(() => {
22
- return props.node.type !== "image" && props.node.type !== "span" ? props.shorthand?.as : undefined
19
+ return props.node.type !== "image" && props.node.type !== "span"
20
+ ? props.shorthand?.as
21
+ : undefined
23
22
  })
24
23
 
25
24
  const attrs = computed(() => {
26
- return props.shorthand?.attrs ?? {}
25
+ const { as, ...attrs } = props.shorthand ?? {}
26
+
27
+ return attrs
27
28
  })
28
29
 
29
30
  const dir = computed(() => {
@@ -35,18 +36,36 @@ const dir = computed(() => {
35
36
 
36
37
  <template>
37
38
  <component v-if="as" :is="as" :dir="dir" v-bind="attrs"><slot /></component>
38
- <h1 v-else-if="node.type === 'heading1'" :dir="dir" v-bind="attrs"><slot /></h1>
39
- <h2 v-else-if="node.type === 'heading2'" :dir="dir" v-bind="attrs"><slot /></h2>
40
- <h3 v-else-if="node.type === 'heading3'" :dir="dir" v-bind="attrs"><slot /></h3>
41
- <h4 v-else-if="node.type === 'heading4'" :dir="dir" v-bind="attrs"><slot /></h4>
42
- <h5 v-else-if="node.type === 'heading5'" :dir="dir" v-bind="attrs"><slot /></h5>
43
- <h6 v-else-if="node.type === 'heading6'" :dir="dir" v-bind="attrs"><slot /></h6>
44
- <p v-else-if="node.type === 'paragraph'" :dir="dir" v-bind="attrs"><slot /></p>
39
+ <h1 v-else-if="node.type === 'heading1'" :dir="dir" v-bind="attrs">
40
+ <slot />
41
+ </h1>
42
+ <h2 v-else-if="node.type === 'heading2'" :dir="dir" v-bind="attrs">
43
+ <slot />
44
+ </h2>
45
+ <h3 v-else-if="node.type === 'heading3'" :dir="dir" v-bind="attrs">
46
+ <slot />
47
+ </h3>
48
+ <h4 v-else-if="node.type === 'heading4'" :dir="dir" v-bind="attrs">
49
+ <slot />
50
+ </h4>
51
+ <h5 v-else-if="node.type === 'heading5'" :dir="dir" v-bind="attrs">
52
+ <slot />
53
+ </h5>
54
+ <h6 v-else-if="node.type === 'heading6'" :dir="dir" v-bind="attrs">
55
+ <slot />
56
+ </h6>
57
+ <p v-else-if="node.type === 'paragraph'" :dir="dir" v-bind="attrs">
58
+ <slot />
59
+ </p>
45
60
  <pre v-else-if="node.type === 'preformatted'" v-bind="attrs"><slot /></pre>
46
61
  <strong v-else-if="node.type === 'strong'" v-bind="attrs"><slot /></strong>
47
62
  <em v-else-if="node.type === 'em'" v-bind="attrs"><slot /></em>
48
- <li v-else-if="node.type === 'list-item'" :dir="dir" v-bind="attrs"><slot /></li>
49
- <li v-else-if="node.type === 'o-list-item'" :dir="dir" v-bind="attrs"><slot /></li>
63
+ <li v-else-if="node.type === 'list-item'" :dir="dir" v-bind="attrs">
64
+ <slot />
65
+ </li>
66
+ <li v-else-if="node.type === 'o-list-item'" :dir="dir" v-bind="attrs">
67
+ <slot />
68
+ </li>
50
69
  <ul v-else-if="node.type === 'group-list-item'" v-bind="attrs">
51
70
  <slot />
52
71
  </ul>
@@ -54,11 +73,7 @@ const dir = computed(() => {
54
73
  <slot />
55
74
  </ol>
56
75
  <p class="block-img" v-else-if="node.type === 'image'">
57
- <PrismicLink
58
- v-if="node.linkTo"
59
- :field="node.linkTo"
60
- :internal-component="internalLinkComponent"
61
- :external-component="externalLinkComponent"
76
+ <PrismicLink v-if="node.linkTo" :field="node.linkTo"
62
77
  ><PrismicImage :field="node"
63
78
  /></PrismicLink>
64
79
  <PrismicImage v-else :field="node" v-bind="attrs" />
@@ -75,12 +90,13 @@ const dir = computed(() => {
75
90
  v-else-if="node.type === 'hyperlink'"
76
91
  :field="node.data"
77
92
  :link-resolver="linkResolver"
78
- :internal-component="internalLinkComponent"
79
- :external-component="externalLinkComponent"
80
93
  v-bind="attrs"
81
94
  ><slot
82
95
  /></PrismicLink>
83
- <span v-else-if="node.type === 'label'" :class="node.data.label" v-bind="attrs"
96
+ <span
97
+ v-else-if="node.type === 'label'"
98
+ :class="node.data.label"
99
+ v-bind="attrs"
84
100
  ><slot
85
101
  /></span>
86
102
  <template v-else v-for="(line, index) in node.text.split('\n')" :key="line"
@@ -1,73 +1,27 @@
1
1
  <script lang="ts" setup>
2
- import type { LinkResolverFunction } from "@prismicio/client"
3
2
  import type { asTree } from "@prismicio/client/richtext"
4
3
 
5
- import type { ComponentOrTagName } from "../types"
6
- import type { VueRichTextSerializer, VueShorthand } from "./types"
7
-
8
- import PrismicRichTextDefaultComponent from "./PrismicRichTextDefaultComponent.vue"
9
-
10
- const CHILD_TYPE_RENAMES = {
11
- "list-item": "listItem",
12
- "o-list-item": "oListItem",
13
- "group-list-item": "list",
14
- "group-o-list-item": "oList",
15
- } as const
4
+ import type { InternalVueRichTextComponent } from "./types"
16
5
 
17
6
  type PrismicRichTextSerializeProps = {
18
- components?: VueRichTextSerializer
19
7
  children: ReturnType<typeof asTree>["children"]
20
- linkResolver?: LinkResolverFunction
21
- internalLinkComponent?: ComponentOrTagName
22
- externalLinkComponent?: ComponentOrTagName
8
+ internalComponents: InternalVueRichTextComponent
23
9
  }
24
10
 
25
11
  const props = defineProps<PrismicRichTextSerializeProps>()
26
12
  defineOptions({ name: "PrismicRichTextSerialize" })
27
-
28
- function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
29
- const maybeComponentOrShorthand =
30
- props.components?.[
31
- CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
32
- (child.type as keyof typeof props.components)
33
- ]
34
-
35
- if (
36
- typeof maybeComponentOrShorthand === "function" ||
37
- (typeof maybeComponentOrShorthand === "object" &&
38
- (typeof maybeComponentOrShorthand.render === "function" ||
39
- typeof maybeComponentOrShorthand.setup === "function" ||
40
- !!maybeComponentOrShorthand.__file ||
41
- !!maybeComponentOrShorthand.__name) || typeof maybeComponentOrShorthand?.props === "object")
42
- ) {
43
- return { is: maybeComponentOrShorthand }
44
- }
45
-
46
- return {
47
- is: PrismicRichTextDefaultComponent,
48
- props: {
49
- linkResolver: props.linkResolver,
50
- internalLinkComponent: props.internalLinkComponent,
51
- externalLinkComponent: props.externalLinkComponent,
52
- shorthand: maybeComponentOrShorthand,
53
- },
54
- }
55
- }
56
13
  </script>
57
14
 
58
15
  <template>
59
16
  <component
60
17
  v-for="child in props.children"
61
18
  :key="JSON.stringify(child)"
62
- :is="getComponent(child).is"
19
+ :is="internalComponents[child.type].is"
63
20
  :node="child.node"
64
- v-bind="getComponent(child).props"
21
+ v-bind="internalComponents[child.type].props"
65
22
  ><PrismicRichTextSerialize
66
23
  v-if="child.children.length"
67
24
  :children="child.children"
68
- :components="components"
69
- :link-resolver="linkResolver"
70
- :internal-link-component="internalLinkComponent"
71
- :external-link-component="externalLinkComponent"
25
+ :internal-components="internalComponents"
72
26
  /></component>
73
27
  </template>
@@ -1,9 +1,10 @@
1
- import type { RTAnyNode, RichTextNodeType } from "@prismicio/client"
2
1
  import type {
3
- DefineComponent,
4
- FunctionalComponent,
5
- defineAsyncComponent,
6
- } from "vue"
2
+ LinkResolverFunction,
3
+ RTAnyNode,
4
+ RichTextNodeType,
5
+ } from "@prismicio/client"
6
+
7
+ import type { VueComponent } from "../types"
7
8
 
8
9
  /**
9
10
  * A map of Rich Text block types to Vue Components. It is used to render Rich
@@ -27,14 +28,9 @@ export type RichTextComponentProps<TRTNode extends RTAnyNode = RTAnyNode> = {
27
28
  *
28
29
  * @typeParam TRTNode - The type of rich text node(s) this component handles
29
30
  */
30
- type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> =
31
- // For reference within TypeScript files when `*.vue` type cannot be inferred
32
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
33
- | DefineComponent<{}, {}, any>
34
- // Likewise, for reference with TypeScript files.
35
- | ReturnType<typeof defineAsyncComponent>
36
- | DefineComponent<RichTextComponentProps<TRTNode>>
37
- | FunctionalComponent<RichTextComponentProps<TRTNode>>
31
+ type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> = VueComponent<
32
+ RichTextComponentProps<TRTNode>
33
+ >
38
34
 
39
35
  /**
40
36
  * A shorthand definition for {@link VueRichTextSerializer} component types.
@@ -50,3 +46,11 @@ export type VueShorthand = {
50
46
  */
51
47
  [Attribute: string]: string | boolean | null | undefined
52
48
  }
49
+
50
+ export type InternalVueRichTextComponent = Record<
51
+ (typeof RichTextNodeType)[keyof typeof RichTextNodeType],
52
+ {
53
+ is: VueRichTextComponent
54
+ props?: { linkResolver?: LinkResolverFunction; shorthand?: VueShorthand }
55
+ }
56
+ >
@@ -2,8 +2,9 @@
2
2
  import { type TableField, isFilled } from "@prismicio/client"
3
3
  import { computed } from "vue"
4
4
 
5
- import type { ComponentOrTagName } from "../types"
6
- import type { VueTableComponents } from "./types"
5
+ import type { VueShorthand } from "../PrismicRichText/types"
6
+ import { type ComponentOrTagName, isVueComponent } from "../types"
7
+ import type { InternalVueTableComponents, VueTableComponents } from "./types"
7
8
 
8
9
  import type { VueRichTextSerializer } from "../PrismicRichText"
9
10
 
@@ -14,19 +15,19 @@ import PrismicTableRow from "./PrismicTableRow.vue"
14
15
  * Props for `<PrismicTable />`.
15
16
  */
16
17
  export type PrismicTableProps = {
17
- /**
18
- * The Prismic table field to render.
19
- */
18
+ /** The Prismic table field to render. */
20
19
  field: TableField | undefined
21
20
 
22
21
  /**
23
- * An object that maps a table block type to a Vue component.
22
+ * An object that maps a table block type to a Vue component or a shorthand definition.
24
23
  *
25
24
  * @example
26
25
  *
27
26
  * ```javascript
28
27
  * {
29
28
  * table: Table,
29
+ * thead: { class: 'bg-black text-white' },
30
+ * th: { as: 'td', class: 'font-bold' },
30
31
  * }
31
32
  * ```
32
33
  */
@@ -42,39 +43,65 @@ export type PrismicTableProps = {
42
43
  const props = defineProps<PrismicTableProps>()
43
44
  defineOptions({ name: "PrismicTable" })
44
45
 
45
- const mergedComponents = computed(() => ({
46
- ...defaultTableComponents,
47
- ...props.components,
48
- }))
46
+ function getInternalComponent(type: keyof VueTableComponents) {
47
+ const maybeComponentOrShorthand = props.components?.[type]
48
+
49
+ if (isVueComponent(maybeComponentOrShorthand)) {
50
+ return { is: maybeComponentOrShorthand }
51
+ }
52
+
53
+ return {
54
+ is: defaultTableComponents[type],
55
+ shorthand: maybeComponentOrShorthand as VueShorthand,
56
+ }
57
+ }
58
+
59
+ const tableComponents = computed<InternalVueTableComponents>(() => {
60
+ return {
61
+ table: getInternalComponent("table"),
62
+ thead: getInternalComponent("thead"),
63
+ tbody: getInternalComponent("tbody"),
64
+ tr: getInternalComponent("tr"),
65
+ th: getInternalComponent("th"),
66
+ td: getInternalComponent("td"),
67
+ }
68
+ })
49
69
  </script>
50
70
 
51
71
  <template>
52
72
  <component
53
73
  v-if="isFilled.table(field)"
54
- :is="mergedComponents.table"
74
+ :is="tableComponents.table.is"
55
75
  :table="field"
56
- v-bind="$attrs"
76
+ v-bind="{ ...$attrs, ...tableComponents.table.shorthand }"
57
77
  >
58
78
  <component
59
79
  v-if="field.head"
60
- :is="mergedComponents.thead"
80
+ :is="tableComponents.thead.is"
61
81
  :head="field.head"
82
+ v-bind="tableComponents.thead.shorthand"
62
83
  >
63
84
  <PrismicTableRow
64
85
  v-for="row in field.head.rows"
65
86
  :key="row.key"
66
87
  :row="row"
67
- :components="mergedComponents"
88
+ :internalTableComponents="tableComponents"
89
+ :components="components"
68
90
  />
69
91
  </component>
70
- <component :is="mergedComponents.tbody" :body="field.body">
92
+ <component
93
+ :is="tableComponents.tbody.is"
94
+ :body="field.body"
95
+ v-bind="tableComponents.tbody.shorthand"
96
+ >
71
97
  <PrismicTableRow
72
98
  v-for="row in field.body.rows"
73
99
  :key="row.key"
74
100
  :row="row"
75
- :components="mergedComponents"
101
+ :internalTableComponents="tableComponents"
102
+ :components="components"
76
103
  />
77
104
  </component>
78
105
  </component>
79
- <component v-else-if="fallback" :is="fallback" />
106
+ <component v-else-if="fallback" :is="fallback" v-bind="$attrs" />
80
107
  </template>
@@ -1,18 +1,19 @@
1
1
  import { defineComponent, h } from "vue"
2
2
  import type { PropType } from "vue"
3
3
 
4
- import type { InternalVueTableComponents } from "./types"
4
+ import type { DefaultVueTableComponents } from "./types"
5
5
 
6
6
  import * as getTableComponentProps from "./getTableComponentProps"
7
7
 
8
- export const defaultTableComponents: InternalVueTableComponents = {
8
+ export const defaultTableComponents: DefaultVueTableComponents = {
9
9
  table: defineComponent({
10
10
  props: {
11
11
  ...getTableComponentProps.table(),
12
12
  as: { type: String as PropType<string | undefined> },
13
13
  },
14
14
  setup(props, { attrs, slots }) {
15
- return () => h(props.as ?? "table", attrs, slots.default ? slots.default() : [])
15
+ return () =>
16
+ h(props.as ?? "table", attrs, slots.default ? slots.default() : [])
16
17
  },
17
18
  }),
18
19
  thead: defineComponent({
@@ -21,7 +22,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
21
22
  as: { type: String as PropType<string | undefined> },
22
23
  },
23
24
  setup(props, { attrs, slots }) {
24
- return () => h(props.as ?? "thead", attrs, slots.default ? slots.default() : [])
25
+ return () =>
26
+ h(props.as ?? "thead", attrs, slots.default ? slots.default() : [])
25
27
  },
26
28
  }),
27
29
  tbody: defineComponent({
@@ -30,7 +32,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
30
32
  as: { type: String as PropType<string | undefined> },
31
33
  },
32
34
  setup(props, { attrs, slots }) {
33
- return () => h(props.as ?? "tbody", attrs, slots.default ? slots.default() : [])
35
+ return () =>
36
+ h(props.as ?? "tbody", attrs, slots.default ? slots.default() : [])
34
37
  },
35
38
  }),
36
39
  tr: defineComponent({
@@ -39,7 +42,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
39
42
  as: { type: String as PropType<string | undefined> },
40
43
  },
41
44
  setup(props, { attrs, slots }) {
42
- return () => h(props.as ?? "tr", attrs, slots.default ? slots.default() : [])
45
+ return () =>
46
+ h(props.as ?? "tr", attrs, slots.default ? slots.default() : [])
43
47
  },
44
48
  }),
45
49
  th: defineComponent({
@@ -48,7 +52,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
48
52
  as: { type: String as PropType<string | undefined> },
49
53
  },
50
54
  setup(props, { attrs, slots }) {
51
- return () => h(props.as ?? "th", attrs, slots.default ? slots.default() : [])
55
+ return () =>
56
+ h(props.as ?? "th", attrs, slots.default ? slots.default() : [])
52
57
  },
53
58
  }),
54
59
  td: defineComponent({
@@ -57,7 +62,8 @@ export const defaultTableComponents: InternalVueTableComponents = {
57
62
  as: { type: String as PropType<string | undefined> },
58
63
  },
59
64
  setup(props, { attrs, slots }) {
60
- return () => h(props.as ?? "td", attrs, slots.default ? slots.default() : [])
65
+ return () =>
66
+ h(props.as ?? "td", attrs, slots.default ? slots.default() : [])
61
67
  },
62
68
  }),
63
69
  }
@@ -1,32 +1,15 @@
1
1
  <script lang="ts" setup>
2
2
  import type { TableFieldBodyRow, TableFieldHeadRow } from "@prismicio/client"
3
3
 
4
- import type { VueTableComponents } from "./types"
4
+ import type { InternalVueTableComponents } from "./types"
5
5
 
6
6
  import type { VueRichTextSerializer } from "../PrismicRichText"
7
7
  import PrismicRichText from "../PrismicRichText/PrismicRichText.vue"
8
8
 
9
- /**
10
- * Props for `<PrismicRowTable />`.
11
- */
12
9
  export type PrismicTableRowProps = {
13
- /**
14
- * The Prismic table row to render.
15
- */
16
10
  row: TableFieldHeadRow | TableFieldBodyRow
17
-
18
- /**
19
- * An object that maps a table block type to a Vue component.
20
- *
21
- * @example
22
- *
23
- * ```javascript
24
- * {
25
- * tr: TableRow,
26
- * }
27
- * ```
28
- */
29
- components: VueTableComponents & VueRichTextSerializer
11
+ internalTableComponents: InternalVueTableComponents
12
+ components?: VueRichTextSerializer
30
13
  }
31
14
 
32
15
  const props = defineProps<PrismicTableRowProps>()
@@ -34,17 +17,27 @@ defineOptions({ name: "PrismicTableRow" })
34
17
  </script>
35
18
 
36
19
  <template>
37
- <component :is="props.components.tr" :row="row">
20
+ <component
21
+ :is="internalTableComponents.tr.is"
22
+ :row="row"
23
+ v-bind="internalTableComponents.tr.shorthand"
24
+ >
38
25
  <template v-for="cell in row.cells" :key="cell.key">
39
26
  <component
40
27
  v-if="cell.type === 'header'"
41
- :is="props.components.th"
28
+ :is="internalTableComponents.th.is"
42
29
  :cell="cell"
30
+ v-bind="internalTableComponents.th.shorthand"
43
31
  >
44
32
  <PrismicRichText :field="cell.content" :components="components" />
45
33
  </component>
46
- <component v-else :is="props.components.td" :cell="cell">
47
- <PrismicRichText :field="cell.content" :components="props.components" />
34
+ <component
35
+ v-else
36
+ :is="internalTableComponents.td.is"
37
+ :cell="cell"
38
+ v-bind="internalTableComponents.td.shorthand"
39
+ >
40
+ <PrismicRichText :field="cell.content" :components="components" />
48
41
  </component>
49
42
  </template>
50
43
  </component>
@@ -7,12 +7,9 @@ import type {
7
7
  TableFieldHeadRow,
8
8
  TableFieldHeaderCell,
9
9
  } from "@prismicio/client"
10
- import type {
11
- DefineComponent,
12
- FunctionalComponent,
13
- defineAsyncComponent,
14
- } from "vue"
10
+
15
11
  import type { VueShorthand } from "../PrismicRichText/types"
12
+ import type { VueComponent } from "../types"
16
13
 
17
14
  /**
18
15
  * A map of Table block types to Vue Components. It is used to render table
@@ -24,12 +21,14 @@ export type VueTableComponents = {
24
21
  table?: VueComponent<{ table: TableField<"filled"> }> | VueShorthand
25
22
  thead?: VueComponent<{ head: TableFieldHead }> | VueShorthand
26
23
  tbody?: VueComponent<{ body: TableFieldBody }> | VueShorthand
27
- tr?: VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }> | VueShorthand
24
+ tr?:
25
+ | VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }>
26
+ | VueShorthand
28
27
  th?: VueComponent<{ cell: TableFieldHeaderCell }> | VueShorthand
29
28
  td?: VueComponent<{ cell: TableFieldDataCell }> | VueShorthand
30
29
  }
31
30
 
32
- export type InternalVueTableComponents = {
31
+ export type DefaultVueTableComponents = {
33
32
  table: VueComponent<{ table: TableField<"filled">; as?: string }>
34
33
  thead: VueComponent<{ head: TableFieldHead; as?: string }>
35
34
  tbody: VueComponent<{ body: TableFieldBody; as?: string }>
@@ -38,7 +37,11 @@ export type InternalVueTableComponents = {
38
37
  td: VueComponent<{ cell: TableFieldDataCell; as?: string }>
39
38
  }
40
39
 
41
- type VueComponent<TProps> =
42
- | ReturnType<typeof defineAsyncComponent>
43
- | DefineComponent<TProps>
44
- | FunctionalComponent<TProps>
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 }
47
+ }
@@ -10,9 +10,7 @@ import { devMsg } from "./lib/devMsg"
10
10
  * Props for `<PrismicText />`.
11
11
  */
12
12
  export type PrismicTextProps = {
13
- /**
14
- * The Prismic rich text field to render.
15
- */
13
+ /** The Prismic rich text field to render. */
16
14
  field: RichTextField | null | undefined
17
15
 
18
16
  /**
@@ -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
 
package/src/types.ts CHANGED
@@ -1,6 +1,36 @@
1
- import type { ConcreteComponent, DefineComponent, Raw } from "vue"
1
+ import type {
2
+ ConcreteComponent,
3
+ DefineComponent,
4
+ FunctionalComponent,
5
+ Raw,
6
+ defineAsyncComponent,
7
+ } from "vue"
2
8
 
3
9
  export type ComponentOrTagName =
4
10
  | string
5
11
  | ConcreteComponent
6
12
  | Raw<DefineComponent>
13
+
14
+ export type VueComponent<TProps> =
15
+ // For reference within TypeScript files when `*.vue` type cannot be inferred
16
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
17
+ | DefineComponent<{}, {}, any>
18
+ // Likewise, for reference with TypeScript files.
19
+ | ReturnType<typeof defineAsyncComponent>
20
+ | DefineComponent<TProps>
21
+ | FunctionalComponent<TProps>
22
+
23
+ export const isVueComponent = <T>(
24
+ component: VueComponent<T> | unknown,
25
+ ): component is VueComponent<T> => {
26
+ return (
27
+ !!component &&
28
+ (typeof component === "function" ||
29
+ (typeof component === "object" &&
30
+ (("render" in component && typeof component.render === "function") ||
31
+ ("setup" in component && typeof component.setup === "function") ||
32
+ ("__file" in component && !!component.__file) ||
33
+ ("__name" in component && !!component.__name) ||
34
+ ("props" in component && typeof component.props === "object"))))
35
+ )
36
+ }
@@ -1,22 +0,0 @@
1
- <script lang="ts" setup>
2
- import type { ComponentOrTagName } from "../types"
3
-
4
- defineProps<{
5
- /**
6
- * An HTML tag name or a component used to wrap the output. Output is not
7
- * wrapped by default.
8
- *
9
- * @defaultValue `"template"` (no wrapper)
10
- */
11
- wrapper?: ComponentOrTagName
12
- }>()
13
- </script>
14
-
15
- <template>
16
- <component v-if="wrapper" :is="wrapper" v-bind="$attrs">
17
- <slot />
18
- </component>
19
- <template v-else>
20
- <slot />
21
- </template>
22
- </template>