@prismicio/vue 5.3.0-pr.86.915aa0e → 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.
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts +12 -36
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
- package/dist/PrismicRichText/types.d.cts +3 -3
- package/dist/PrismicRichText/types.d.cts.map +1 -1
- package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
- package/dist/PrismicTable/types.d.cts +1 -2
- package/dist/PrismicTable/types.d.cts.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts +12 -36
- package/dist/src/PrismicRichText/PrismicRichText.vue.d.ts.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs +39 -22
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js +39 -22
- package/dist/src/PrismicRichText/PrismicRichText.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs +6 -26
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js +6 -26
- package/dist/src/PrismicRichText/PrismicRichTextDefaultComponent.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.js.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs +7 -48
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js +7 -48
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/types.d.ts +3 -3
- package/dist/src/PrismicRichText/types.d.ts.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +42 -14
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js +42 -14
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs +13 -10
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js +14 -11
- package/dist/src/PrismicTable/PrismicTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicTable/types.d.ts +1 -2
- package/dist/src/PrismicTable/types.d.ts.map +1 -1
- package/dist/src/types.cjs +9 -0
- package/dist/src/types.cjs.map +1 -0
- package/dist/src/types.d.ts +3 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -0
- package/dist/types.d.cts +3 -2
- package/dist/types.d.cts.map +1 -1
- package/package.json +1 -1
- package/src/PrismicRichText/PrismicRichText.vue +62 -43
- package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +38 -22
- package/src/PrismicRichText/PrismicRichTextSerialize.vue +5 -51
- package/src/PrismicRichText/types.ts +17 -13
- package/src/PrismicTable/PrismicTable.vue +39 -12
- package/src/PrismicTable/PrismicTableDefaultComponents.ts +14 -8
- package/src/PrismicTable/PrismicTableRow.vue +17 -24
- package/src/PrismicTable/types.ts +14 -11
- package/src/types.ts +31 -1
- package/src/lib/Wrapper.vue +0 -22
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type {
|
|
3
|
+
LinkResolverFunction,
|
|
4
|
+
RichTextField,
|
|
5
|
+
RichTextNodeType,
|
|
5
6
|
} from "@prismicio/client"
|
|
6
7
|
import { asTree } from "@prismicio/client/richtext"
|
|
7
8
|
import type { PropType } from "vue"
|
|
8
9
|
import { computed } from "vue"
|
|
9
10
|
|
|
10
|
-
import type
|
|
11
|
-
import type {
|
|
11
|
+
import { type ComponentOrTagName, isVueComponent } from "../types"
|
|
12
|
+
import type {
|
|
13
|
+
InternalVueRichTextComponent,
|
|
14
|
+
VueRichTextSerializer,
|
|
15
|
+
VueShorthand,
|
|
16
|
+
} from "./types"
|
|
12
17
|
|
|
18
|
+
import PrismicRichTextDefaultComponent from "./PrismicRichTextDefaultComponent.vue"
|
|
13
19
|
import PrismicRichTextSerialize from "./PrismicRichTextSerialize.vue"
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -21,19 +27,6 @@ export type PrismicRichTextProps = {
|
|
|
21
27
|
*/
|
|
22
28
|
field: RichTextField | null | undefined
|
|
23
29
|
|
|
24
|
-
/**
|
|
25
|
-
* An object that maps a rich text block type to a Vue component.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
*
|
|
29
|
-
* ```javascript
|
|
30
|
-
* {
|
|
31
|
-
* heading1: Heading1,
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
components?: VueRichTextSerializer
|
|
36
|
-
|
|
37
30
|
/**
|
|
38
31
|
* A link resolver function used to resolve link when not using the route
|
|
39
32
|
* resolver parameter with `@prismicio/client`.
|
|
@@ -45,18 +38,17 @@ export type PrismicRichTextProps = {
|
|
|
45
38
|
linkResolver?: LinkResolverFunction
|
|
46
39
|
|
|
47
40
|
/**
|
|
48
|
-
*
|
|
41
|
+
* An object that maps a rich text block type to a Vue component.
|
|
49
42
|
*
|
|
50
|
-
* @
|
|
51
|
-
*/
|
|
52
|
-
internalLinkComponent?: ComponentOrTagName
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The Vue component rendered for links when the URL is external.
|
|
43
|
+
* @example
|
|
56
44
|
*
|
|
57
|
-
*
|
|
45
|
+
* ```javascript
|
|
46
|
+
* {
|
|
47
|
+
* heading1: Heading1,
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
58
50
|
*/
|
|
59
|
-
|
|
51
|
+
components?: VueRichTextSerializer
|
|
60
52
|
|
|
61
53
|
/**
|
|
62
54
|
* The value to be rendered when the field is empty. If a fallback is not
|
|
@@ -71,21 +63,11 @@ const props = defineProps({
|
|
|
71
63
|
field: {
|
|
72
64
|
type: Array as unknown as PropType<PrismicRichTextProps["field"]>,
|
|
73
65
|
},
|
|
74
|
-
components: {
|
|
75
|
-
type: Object as PropType<PrismicRichTextProps["components"]>,
|
|
76
|
-
},
|
|
77
66
|
linkResolver: {
|
|
78
67
|
type: Function as PropType<PrismicRichTextProps["linkResolver"]>,
|
|
79
68
|
},
|
|
80
|
-
|
|
81
|
-
type:
|
|
82
|
-
PrismicRichTextProps["internalLinkComponent"]
|
|
83
|
-
>,
|
|
84
|
-
},
|
|
85
|
-
externalLinkComponent: {
|
|
86
|
-
type: [String, Object, Function] as PropType<
|
|
87
|
-
PrismicRichTextProps["externalLinkComponent"]
|
|
88
|
-
>,
|
|
69
|
+
components: {
|
|
70
|
+
type: Object as PropType<PrismicRichTextProps["components"]>,
|
|
89
71
|
},
|
|
90
72
|
fallback: {
|
|
91
73
|
type: [String, Object, Function] as PropType<
|
|
@@ -98,16 +80,53 @@ defineOptions({ name: "PrismicRichText" })
|
|
|
98
80
|
const children = computed(() => {
|
|
99
81
|
return asTree(props.field || []).children
|
|
100
82
|
})
|
|
83
|
+
|
|
84
|
+
function getInternalComponent(type: keyof typeof RichTextNodeType) {
|
|
85
|
+
const maybeComponentOrShorthand = props.components?.[type]
|
|
86
|
+
|
|
87
|
+
if (isVueComponent(maybeComponentOrShorthand)) {
|
|
88
|
+
return { is: maybeComponentOrShorthand }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
is: PrismicRichTextDefaultComponent,
|
|
93
|
+
props: {
|
|
94
|
+
linkResolver: props.linkResolver,
|
|
95
|
+
shorthand: maybeComponentOrShorthand as VueShorthand,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const internalComponents = computed<InternalVueRichTextComponent>(() => {
|
|
101
|
+
return {
|
|
102
|
+
heading1: getInternalComponent("heading1"),
|
|
103
|
+
heading2: getInternalComponent("heading2"),
|
|
104
|
+
heading3: getInternalComponent("heading3"),
|
|
105
|
+
heading4: getInternalComponent("heading4"),
|
|
106
|
+
heading5: getInternalComponent("heading5"),
|
|
107
|
+
heading6: getInternalComponent("heading6"),
|
|
108
|
+
paragraph: getInternalComponent("paragraph"),
|
|
109
|
+
preformatted: getInternalComponent("preformatted"),
|
|
110
|
+
strong: getInternalComponent("strong"),
|
|
111
|
+
em: getInternalComponent("em"),
|
|
112
|
+
"list-item": getInternalComponent("listItem"),
|
|
113
|
+
"o-list-item": getInternalComponent("oListItem"),
|
|
114
|
+
"group-list-item": getInternalComponent("list"),
|
|
115
|
+
"group-o-list-item": getInternalComponent("oList"),
|
|
116
|
+
image: getInternalComponent("image"),
|
|
117
|
+
embed: getInternalComponent("embed"),
|
|
118
|
+
hyperlink: getInternalComponent("hyperlink"),
|
|
119
|
+
label: getInternalComponent("label"),
|
|
120
|
+
span: getInternalComponent("span"),
|
|
121
|
+
}
|
|
122
|
+
})
|
|
101
123
|
</script>
|
|
102
124
|
|
|
103
125
|
<template>
|
|
104
126
|
<PrismicRichTextSerialize
|
|
105
127
|
v-if="children.length"
|
|
106
128
|
:children="children"
|
|
107
|
-
:components="
|
|
108
|
-
:link-resolver="linkResolver"
|
|
109
|
-
:internal-link-component="internalLinkComponent"
|
|
110
|
-
:external-link-component="externalLinkComponent"
|
|
129
|
+
:internal-components="internalComponents"
|
|
111
130
|
/>
|
|
112
131
|
<component v-else-if="fallback" :is="fallback" />
|
|
113
132
|
</template>
|
|
@@ -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"
|
|
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
|
-
|
|
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"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<
|
|
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"
|
|
49
|
-
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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="
|
|
19
|
+
:is="internalComponents[child.type].is"
|
|
63
20
|
:node="child.node"
|
|
64
|
-
v-bind="
|
|
21
|
+
v-bind="internalComponents[child.type].props"
|
|
65
22
|
><PrismicRichTextSerialize
|
|
66
23
|
v-if="child.children.length"
|
|
67
24
|
:children="child.children"
|
|
68
|
-
: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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
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
|
-
|
|
32
|
-
|
|
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 {
|
|
6
|
-
import type
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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="
|
|
74
|
+
:is="tableComponents.table.is"
|
|
55
75
|
:table="field"
|
|
56
|
-
v-bind="
|
|
76
|
+
v-bind="{ ...$attrs, ...tableComponents.table.shorthand }"
|
|
57
77
|
>
|
|
58
78
|
<component
|
|
59
79
|
v-if="field.head"
|
|
60
|
-
:is="
|
|
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
|
-
:
|
|
88
|
+
:internalTableComponents="tableComponents"
|
|
89
|
+
:components="components"
|
|
68
90
|
/>
|
|
69
91
|
</component>
|
|
70
|
-
<component
|
|
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
|
-
:
|
|
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 {
|
|
4
|
+
import type { DefaultVueTableComponents } from "./types"
|
|
5
5
|
|
|
6
6
|
import * as getTableComponentProps from "./getTableComponentProps"
|
|
7
7
|
|
|
8
|
-
export const defaultTableComponents:
|
|
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 () =>
|
|
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 () =>
|
|
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 () =>
|
|
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 () =>
|
|
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 () =>
|
|
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 () =>
|
|
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 {
|
|
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
|
|
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="
|
|
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
|
|
47
|
-
|
|
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
|
-
|
|
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?:
|
|
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
|
|
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
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
}
|