@prismicio/vue 5.3.0-pr.86.81afa1a → 5.3.0-pr.88.ee9acb6

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 (83) hide show
  1. package/dist/PrismicImage.vue.d.cts +4 -4
  2. package/dist/PrismicImage.vue.d.cts.map +1 -1
  3. package/dist/PrismicLink.vue.d.cts +4 -4
  4. package/dist/PrismicRichText/PrismicRichText.vue.d.cts +12 -36
  5. package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
  6. package/dist/PrismicRichText/types.d.cts +3 -3
  7. package/dist/PrismicRichText/types.d.cts.map +1 -1
  8. package/dist/PrismicTable/PrismicTable.vue.d.cts +2 -2
  9. package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
  10. package/dist/PrismicTable/types.d.cts +1 -2
  11. package/dist/PrismicTable/types.d.cts.map +1 -1
  12. package/dist/PrismicText.vue.d.cts +2 -2
  13. package/dist/SliceZone/SliceZone.vue.d.cts +2 -2
  14. package/dist/package.cjs +1 -1
  15. package/dist/package.cjs.map +1 -1
  16. package/dist/package.js +1 -1
  17. package/dist/package.js.map +1 -1
  18. package/dist/src/PrismicImage.vue.d.ts +4 -4
  19. package/dist/src/PrismicImage.vue.d.ts.map +1 -1
  20. package/dist/src/PrismicLink.vue.d.ts +4 -4
  21. package/dist/src/PrismicLink.vue.d.ts.map +1 -1
  22. package/dist/src/PrismicRichText/PrismicRichText.cjs.map +1 -1
  23. package/dist/src/PrismicRichText/PrismicRichText.js.map +1 -1
  24. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts +16 -40
  25. package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts.map +1 -1
  26. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs +39 -22
  27. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  28. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js +39 -22
  29. package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js.map +1 -1
  30. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.cjs.map +1 -1
  31. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.js.map +1 -1
  32. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs +6 -26
  33. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  34. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js +6 -26
  35. package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js.map +1 -1
  36. package/dist/src/PrismicRichText/PrismicRichTextSerialize.cjs.map +1 -1
  37. package/dist/src/PrismicRichText/PrismicRichTextSerialize.js.map +1 -1
  38. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs +7 -48
  39. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  40. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js +7 -48
  41. package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
  42. package/dist/src/PrismicRichText/types.d.ts +3 -3
  43. package/dist/src/PrismicRichText/types.d.ts.map +1 -1
  44. package/dist/src/PrismicTable/PrismicTable.cjs.map +1 -1
  45. package/dist/src/PrismicTable/PrismicTable.js.map +1 -1
  46. package/dist/src/PrismicTable/PrismicTable.vue.d.ts +2 -2
  47. package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
  48. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +42 -14
  49. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  50. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js +42 -14
  51. package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
  52. package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
  53. package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
  54. package/dist/src/PrismicTable/PrismicTableRow.cjs.map +1 -1
  55. package/dist/src/PrismicTable/PrismicTableRow.js.map +1 -1
  56. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs +13 -10
  57. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
  58. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js +14 -11
  59. package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
  60. package/dist/src/PrismicTable/types.d.ts +1 -2
  61. package/dist/src/PrismicTable/types.d.ts.map +1 -1
  62. package/dist/src/PrismicText.vue.d.ts +2 -2
  63. package/dist/src/PrismicText.vue.d.ts.map +1 -1
  64. package/dist/src/SliceZone/SliceZone.vue.d.ts +2 -2
  65. package/dist/src/types.cjs +9 -0
  66. package/dist/src/types.cjs.map +1 -0
  67. package/dist/src/types.d.ts +3 -2
  68. package/dist/src/types.d.ts.map +1 -1
  69. package/dist/src/types.js +8 -0
  70. package/dist/src/types.js.map +1 -0
  71. package/dist/types.d.cts +3 -2
  72. package/dist/types.d.cts.map +1 -1
  73. package/package.json +1 -1
  74. package/src/PrismicRichText/PrismicRichText.vue +62 -43
  75. package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +38 -22
  76. package/src/PrismicRichText/PrismicRichTextSerialize.vue +5 -51
  77. package/src/PrismicRichText/types.ts +17 -13
  78. package/src/PrismicTable/PrismicTable.vue +39 -12
  79. package/src/PrismicTable/PrismicTableDefaultComponents.ts +14 -8
  80. package/src/PrismicTable/PrismicTableRow.vue +17 -24
  81. package/src/PrismicTable/types.ts +14 -11
  82. package/src/types.ts +31 -1
  83. package/src/lib/Wrapper.vue +0 -22
@@ -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
 
@@ -42,37 +43,63 @@ 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>
@@ -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
+ }
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>