@prismicio/vue 5.3.0-canary.5d9ea4c → 5.3.0-canary.aa89de6
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/PrismicImage.vue.d.cts.map +1 -1
- package/dist/PrismicLink.vue.d.cts +24 -104
- package/dist/PrismicLink.vue.d.cts.map +1 -1
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts +31 -36
- package/dist/PrismicRichText/PrismicRichText.vue.d.cts.map +1 -1
- package/dist/PrismicRichText/types.d.cts +15 -2
- package/dist/PrismicRichText/types.d.cts.map +1 -1
- package/dist/PrismicTable/PrismicTable.vue.d.cts +8 -8
- package/dist/PrismicTable/PrismicTable.vue.d.cts.map +1 -1
- package/dist/PrismicTable/types.d.cts +7 -6
- package/dist/PrismicTable/types.d.cts.map +1 -1
- package/dist/PrismicText.vue.d.cts +2 -10
- package/dist/PrismicText.vue.d.cts.map +1 -1
- package/dist/SliceZone/SliceZone.vue.d.cts +2 -10
- package/dist/SliceZone/SliceZone.vue.d.cts.map +1 -1
- package/dist/index.cjs +3 -10
- package/dist/index.d.cts +9 -13
- package/dist/index.d.ts +11 -15
- package/dist/index.js +3 -6
- 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/PrismicImage.cjs.map +1 -1
- package/dist/src/PrismicImage.js.map +1 -1
- package/dist/src/PrismicImage.vue.d.ts +4 -4
- package/dist/src/PrismicImage.vue.d.ts.map +1 -1
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.cjs +2 -4
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.js +2 -4
- package/dist/src/PrismicImage.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicLink.cjs.map +1 -1
- package/dist/src/PrismicLink.js.map +1 -1
- package/dist/src/PrismicLink.vue.d.ts +24 -104
- package/dist/src/PrismicLink.vue.d.ts.map +1 -1
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs +3 -6
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.js +3 -6
- package/dist/src/PrismicLink.vue_vue_type_script_setup_true_lang.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 +31 -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 +19 -52
- 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 +20 -53
- 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 +75 -35
- 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 +76 -36
- 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 +29 -8
- 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 +30 -9
- package/dist/src/PrismicRichText/PrismicRichTextSerialize.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicRichText/types.d.ts +15 -2
- 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 +7 -7
- package/dist/src/PrismicTable/PrismicTable.vue.d.ts.map +1 -1
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.cjs +5 -5
- 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 +5 -5
- package/dist/src/PrismicTable/PrismicTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs +36 -18
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.cjs.map +1 -1
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.js +36 -18
- package/dist/src/PrismicTable/PrismicTableDefaultComponents.js.map +1 -1
- package/dist/src/PrismicTable/types.d.ts +7 -6
- package/dist/src/PrismicTable/types.d.ts.map +1 -1
- package/dist/src/PrismicText.cjs.map +1 -1
- package/dist/src/PrismicText.js.map +1 -1
- package/dist/src/PrismicText.vue.d.ts +2 -10
- package/dist/src/PrismicText.vue.d.ts.map +1 -1
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.cjs +1 -12
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.js +3 -14
- package/dist/src/PrismicText.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/SliceZone/SliceZone.cjs.map +1 -1
- package/dist/src/SliceZone/SliceZone.js.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue.d.ts +2 -10
- package/dist/src/SliceZone/SliceZone.vue.d.ts.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.cjs +5 -17
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.js +6 -18
- package/dist/src/SliceZone/SliceZone.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/src/types.d.ts +2 -352
- package/dist/src/types.d.ts.map +1 -1
- package/dist/types.d.cts +2 -352
- package/dist/types.d.cts.map +1 -1
- package/package.json +6 -5
- package/src/PrismicImage.vue +2 -11
- package/src/PrismicLink.vue +9 -34
- package/src/PrismicRichText/PrismicRichText.vue +31 -101
- package/src/PrismicRichText/PrismicRichTextDefaultComponent.vue +46 -20
- package/src/PrismicRichText/PrismicRichTextSerialize.vue +31 -10
- package/src/PrismicRichText/types.ts +16 -1
- package/src/PrismicTable/PrismicTable.vue +7 -7
- package/src/PrismicTable/PrismicTableDefaultComponents.ts +39 -20
- package/src/PrismicTable/types.ts +16 -6
- package/src/PrismicText.vue +2 -15
- package/src/SliceZone/SliceZone.vue +9 -27
- package/src/index.ts +13 -21
- package/src/types.ts +1 -439
- package/dist/PrismicEmbed.vue.d.cts +0 -25
- package/dist/PrismicEmbed.vue.d.cts.map +0 -1
- package/dist/createPrismic.d.cts +0 -29
- package/dist/createPrismic.d.cts.map +0 -1
- package/dist/src/PrismicEmbed.cjs +0 -8
- package/dist/src/PrismicEmbed.cjs.map +0 -1
- package/dist/src/PrismicEmbed.js +0 -8
- package/dist/src/PrismicEmbed.js.map +0 -1
- package/dist/src/PrismicEmbed.vue.d.ts +0 -25
- package/dist/src/PrismicEmbed.vue.d.ts.map +0 -1
- package/dist/src/PrismicEmbed.vue_vue_type_script_setup_true_lang.cjs +0 -42
- package/dist/src/PrismicEmbed.vue_vue_type_script_setup_true_lang.cjs.map +0 -1
- package/dist/src/PrismicEmbed.vue_vue_type_script_setup_true_lang.js +0 -42
- package/dist/src/PrismicEmbed.vue_vue_type_script_setup_true_lang.js.map +0 -1
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.cjs +0 -8
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.cjs.map +0 -1
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.js +0 -8
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.js.map +0 -1
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.vue_vue_type_script_setup_true_lang.cjs +0 -92
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.vue_vue_type_script_setup_true_lang.cjs.map +0 -1
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.vue_vue_type_script_setup_true_lang.js +0 -92
- package/dist/src/PrismicRichText/DeprecatedPrismicRichText.vue_vue_type_script_setup_true_lang.js.map +0 -1
- package/dist/src/createPrismic.cjs +0 -85
- package/dist/src/createPrismic.cjs.map +0 -1
- package/dist/src/createPrismic.d.ts +0 -29
- package/dist/src/createPrismic.d.ts.map +0 -1
- package/dist/src/createPrismic.js +0 -85
- package/dist/src/createPrismic.js.map +0 -1
- package/dist/src/lib/Wrapper.cjs +0 -8
- package/dist/src/lib/Wrapper.cjs.map +0 -1
- package/dist/src/lib/Wrapper.js +0 -8
- package/dist/src/lib/Wrapper.js.map +0 -1
- package/dist/src/lib/Wrapper.vue_vue_type_script_setup_true_lang.cjs +0 -22
- package/dist/src/lib/Wrapper.vue_vue_type_script_setup_true_lang.cjs.map +0 -1
- package/dist/src/lib/Wrapper.vue_vue_type_script_setup_true_lang.js +0 -22
- package/dist/src/lib/Wrapper.vue_vue_type_script_setup_true_lang.js.map +0 -1
- package/dist/src/usePrismic.cjs +0 -38
- package/dist/src/usePrismic.cjs.map +0 -1
- package/dist/src/usePrismic.d.ts +0 -36
- package/dist/src/usePrismic.d.ts.map +0 -1
- package/dist/src/usePrismic.js +0 -37
- package/dist/src/usePrismic.js.map +0 -1
- package/dist/usePrismic.d.cts +0 -36
- package/dist/usePrismic.d.cts.map +0 -1
- package/src/PrismicEmbed.vue +0 -42
- package/src/PrismicRichText/DeprecatedPrismicRichText.vue +0 -146
- package/src/createPrismic.ts +0 -154
- package/src/usePrismic.ts +0 -36
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import {
|
|
3
|
-
type HTMLRichTextFunctionSerializer,
|
|
4
|
-
type HTMLRichTextMapSerializer,
|
|
5
3
|
type LinkResolverFunction,
|
|
6
4
|
type RichTextField,
|
|
7
|
-
isFilled,
|
|
8
5
|
} from "@prismicio/client"
|
|
9
6
|
import { asTree } from "@prismicio/client/richtext"
|
|
10
|
-
import { DEV } from "esm-env"
|
|
11
7
|
import type { PropType } from "vue"
|
|
12
|
-
import { computed
|
|
13
|
-
|
|
14
|
-
import Wrapper from "../lib/Wrapper.vue"
|
|
8
|
+
import { computed } from "vue"
|
|
15
9
|
|
|
16
10
|
import type { ComponentOrTagName } from "../types"
|
|
17
11
|
import type { VueRichTextSerializer } from "./types"
|
|
18
12
|
|
|
19
|
-
import { usePrismic } from "../usePrismic"
|
|
20
|
-
|
|
21
|
-
import DeprecatedPrismicRichText from "./DeprecatedPrismicRichText.vue"
|
|
22
13
|
import PrismicRichTextSerialize from "./PrismicRichTextSerialize.vue"
|
|
23
14
|
|
|
24
15
|
/**
|
|
@@ -30,12 +21,6 @@ export type PrismicRichTextProps = {
|
|
|
30
21
|
*/
|
|
31
22
|
field: RichTextField | null | undefined
|
|
32
23
|
|
|
33
|
-
/**
|
|
34
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
35
|
-
* given, `null` (nothing) will be rendered.
|
|
36
|
-
*/
|
|
37
|
-
fallback?: ComponentOrTagName
|
|
38
|
-
|
|
39
24
|
/**
|
|
40
25
|
* An object that maps a rich text block type to a Vue component.
|
|
41
26
|
*
|
|
@@ -60,24 +45,24 @@ export type PrismicRichTextProps = {
|
|
|
60
45
|
linkResolver?: LinkResolverFunction
|
|
61
46
|
|
|
62
47
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @deprecated Use `components` instead.
|
|
48
|
+
* The Vue component rendered for links when the URL is internal.
|
|
66
49
|
*
|
|
67
|
-
* @defaultValue
|
|
68
|
-
*
|
|
69
|
-
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
50
|
+
* @defaultValue `<RouterLink>`
|
|
70
51
|
*/
|
|
71
|
-
|
|
72
|
-
serializer?: HTMLRichTextFunctionSerializer | HTMLRichTextMapSerializer
|
|
52
|
+
internalLinkComponent?: ComponentOrTagName
|
|
73
53
|
|
|
74
54
|
/**
|
|
75
|
-
*
|
|
76
|
-
* is not wrapped by default.
|
|
55
|
+
* The Vue component rendered for links when the URL is external.
|
|
77
56
|
*
|
|
78
|
-
* @defaultValue
|
|
57
|
+
* @defaultValue `<a>`
|
|
79
58
|
*/
|
|
80
|
-
|
|
59
|
+
externalLinkComponent?: ComponentOrTagName
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The value to be rendered when the field is empty. If a fallback is not
|
|
63
|
+
* given, `null` (nothing) will be rendered.
|
|
64
|
+
*/
|
|
65
|
+
fallback?: ComponentOrTagName
|
|
81
66
|
}
|
|
82
67
|
|
|
83
68
|
// We're forced to declare props using the JavaScript syntax because `@vue/compiler-sfc`
|
|
@@ -86,98 +71,43 @@ const props = defineProps({
|
|
|
86
71
|
field: {
|
|
87
72
|
type: Array as unknown as PropType<PrismicRichTextProps["field"]>,
|
|
88
73
|
},
|
|
89
|
-
fallback: {
|
|
90
|
-
type: [String, Object, Function] as PropType<
|
|
91
|
-
PrismicRichTextProps["fallback"]
|
|
92
|
-
>,
|
|
93
|
-
},
|
|
94
74
|
components: {
|
|
95
75
|
type: Object as PropType<PrismicRichTextProps["components"]>,
|
|
96
76
|
},
|
|
97
77
|
linkResolver: {
|
|
98
78
|
type: Function as PropType<PrismicRichTextProps["linkResolver"]>,
|
|
99
79
|
},
|
|
100
|
-
|
|
101
|
-
type: [Object, Function] as PropType<
|
|
80
|
+
internalLinkComponent: {
|
|
81
|
+
type: [String, Object, Function] as PropType<
|
|
82
|
+
PrismicRichTextProps["internalLinkComponent"]
|
|
83
|
+
>,
|
|
84
|
+
},
|
|
85
|
+
externalLinkComponent: {
|
|
86
|
+
type: [String, Object, Function] as PropType<
|
|
87
|
+
PrismicRichTextProps["externalLinkComponent"]
|
|
88
|
+
>,
|
|
102
89
|
},
|
|
103
|
-
|
|
90
|
+
fallback: {
|
|
104
91
|
type: [String, Object, Function] as PropType<
|
|
105
|
-
PrismicRichTextProps["
|
|
92
|
+
PrismicRichTextProps["fallback"]
|
|
106
93
|
>,
|
|
107
94
|
},
|
|
108
95
|
})
|
|
109
96
|
defineOptions({ name: "PrismicRichText" })
|
|
110
97
|
|
|
111
|
-
const { options } = usePrismic()
|
|
112
|
-
|
|
113
|
-
const resolvedComponents = computed(() => {
|
|
114
|
-
return props.components || options.components?.richTextComponents
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const resolvedLinkResolver = computed(() => {
|
|
118
|
-
return props.linkResolver || options.linkResolver
|
|
119
|
-
})
|
|
120
|
-
|
|
121
98
|
const children = computed(() => {
|
|
122
99
|
return asTree(props.field || []).children
|
|
123
100
|
})
|
|
124
|
-
|
|
125
|
-
const isModern = computed(() => {
|
|
126
|
-
// Explicit components prop
|
|
127
|
-
if (props.components) {
|
|
128
|
-
return true
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Explicit serializer prop
|
|
132
|
-
if (props.serializer) {
|
|
133
|
-
return false
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Global components option
|
|
137
|
-
if (options.components?.richTextComponents) {
|
|
138
|
-
return true
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Global serializer option
|
|
142
|
-
if (options.richTextSerializer) {
|
|
143
|
-
return false
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Default to modern
|
|
147
|
-
return true
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
if (DEV) {
|
|
151
|
-
watchEffect(() => {
|
|
152
|
-
// TODO: Remove in v6
|
|
153
|
-
if (props.components && props.serializer) {
|
|
154
|
-
console.warn(
|
|
155
|
-
`[PrismicRichText] Only one of "components" or "serializer" (deprecated) props can be provided. You can resolve this warning by removing either the "components" or "serializer" prop. "components" will be used in this case.`,
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
101
|
</script>
|
|
161
102
|
|
|
162
103
|
<template>
|
|
163
|
-
<
|
|
164
|
-
v-if="
|
|
165
|
-
:
|
|
166
|
-
|
|
167
|
-
<PrismicRichTextSerialize
|
|
168
|
-
v-if="children.length"
|
|
169
|
-
:children="children"
|
|
170
|
-
:components="resolvedComponents"
|
|
171
|
-
:link-resolver="resolvedLinkResolver"
|
|
172
|
-
/>
|
|
173
|
-
<component v-else :is="fallback" />
|
|
174
|
-
</Wrapper>
|
|
175
|
-
<DeprecatedPrismicRichText
|
|
176
|
-
v-else-if="!isModern"
|
|
177
|
-
:field="field"
|
|
178
|
-
:fallback="typeof fallback === 'string' ? fallback : undefined"
|
|
104
|
+
<PrismicRichTextSerialize
|
|
105
|
+
v-if="children.length"
|
|
106
|
+
:children="children"
|
|
107
|
+
:components="components"
|
|
179
108
|
:link-resolver="linkResolver"
|
|
180
|
-
:
|
|
181
|
-
:
|
|
109
|
+
:internal-link-component="internalLinkComponent"
|
|
110
|
+
:external-link-component="externalLinkComponent"
|
|
182
111
|
/>
|
|
112
|
+
<component v-else-if="fallback" :is="fallback" />
|
|
183
113
|
</template>
|
|
@@ -2,19 +2,30 @@
|
|
|
2
2
|
import type { LinkResolverFunction } from "@prismicio/client"
|
|
3
3
|
import { computed } from "vue"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { ComponentOrTagName } from "../types"
|
|
6
|
+
import type { RichTextComponentProps, VueShorthand } from "./types"
|
|
6
7
|
|
|
7
|
-
import PrismicEmbed from "../PrismicEmbed.vue"
|
|
8
8
|
import PrismicImage from "../PrismicImage.vue"
|
|
9
9
|
import PrismicLink from "../PrismicLink.vue"
|
|
10
10
|
|
|
11
11
|
const props = defineProps<
|
|
12
12
|
RichTextComponentProps & {
|
|
13
13
|
linkResolver?: LinkResolverFunction
|
|
14
|
+
internalLinkComponent?: ComponentOrTagName
|
|
15
|
+
externalLinkComponent?: ComponentOrTagName
|
|
16
|
+
shorthand?: VueShorthand
|
|
14
17
|
}
|
|
15
18
|
>()
|
|
16
19
|
defineOptions({ name: "PrismicRichTextDefaultComponent" })
|
|
17
20
|
|
|
21
|
+
const as = computed(() => {
|
|
22
|
+
return props.node.type !== "image" && props.node.type !== "span" ? props.shorthand?.as : undefined
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const attrs = computed(() => {
|
|
26
|
+
return props.shorthand?.attrs ?? {}
|
|
27
|
+
})
|
|
28
|
+
|
|
18
29
|
const dir = computed(() => {
|
|
19
30
|
return "direction" in props.node && props.node.direction === "rtl"
|
|
20
31
|
? "rtl"
|
|
@@ -23,38 +34,53 @@ const dir = computed(() => {
|
|
|
23
34
|
</script>
|
|
24
35
|
|
|
25
36
|
<template>
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
<
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
<
|
|
37
|
-
<li v-else-if="node.type === '
|
|
38
|
-
<
|
|
37
|
+
<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>
|
|
45
|
+
<pre v-else-if="node.type === 'preformatted'" v-bind="attrs"><slot /></pre>
|
|
46
|
+
<strong v-else-if="node.type === 'strong'" v-bind="attrs"><slot /></strong>
|
|
47
|
+
<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>
|
|
50
|
+
<ul v-else-if="node.type === 'group-list-item'" v-bind="attrs">
|
|
39
51
|
<slot />
|
|
40
52
|
</ul>
|
|
41
|
-
<ol v-else-if="node.type === 'group-o-list-item'">
|
|
53
|
+
<ol v-else-if="node.type === 'group-o-list-item'" v-bind="attrs">
|
|
42
54
|
<slot />
|
|
43
55
|
</ol>
|
|
44
56
|
<p class="block-img" v-else-if="node.type === 'image'">
|
|
45
|
-
<PrismicLink
|
|
57
|
+
<PrismicLink
|
|
58
|
+
v-if="node.linkTo"
|
|
59
|
+
:field="node.linkTo"
|
|
60
|
+
:internal-component="internalLinkComponent"
|
|
61
|
+
:external-component="externalLinkComponent"
|
|
46
62
|
><PrismicImage :field="node"
|
|
47
63
|
/></PrismicLink>
|
|
48
|
-
<PrismicImage v-else :field="node" />
|
|
64
|
+
<PrismicImage v-else :field="node" v-bind="attrs" />
|
|
49
65
|
</p>
|
|
50
|
-
<
|
|
66
|
+
<div
|
|
67
|
+
v-else-if="node.type === 'embed'"
|
|
68
|
+
:data-oembed="node.oembed.embed_url"
|
|
69
|
+
:data-oembed-type="node.oembed.type"
|
|
70
|
+
:data-oembed-provider="node.oembed.provider_name"
|
|
71
|
+
v-html="node.oembed.html"
|
|
72
|
+
v-bind="attrs"
|
|
73
|
+
/>
|
|
51
74
|
<PrismicLink
|
|
52
75
|
v-else-if="node.type === 'hyperlink'"
|
|
53
76
|
:field="node.data"
|
|
54
77
|
:link-resolver="linkResolver"
|
|
78
|
+
:internal-component="internalLinkComponent"
|
|
79
|
+
:external-component="externalLinkComponent"
|
|
80
|
+
v-bind="attrs"
|
|
55
81
|
><slot
|
|
56
82
|
/></PrismicLink>
|
|
57
|
-
<span v-else-if="node.type === 'label'" :class="node.data.label"
|
|
83
|
+
<span v-else-if="node.type === 'label'" :class="node.data.label" v-bind="attrs"
|
|
58
84
|
><slot
|
|
59
85
|
/></span>
|
|
60
86
|
<template v-else v-for="(line, index) in node.text.split('\n')" :key="line"
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import type { LinkResolverFunction } from "@prismicio/client"
|
|
3
3
|
import type { asTree } from "@prismicio/client/richtext"
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { ComponentOrTagName } from "../types"
|
|
6
|
+
import type { VueRichTextSerializer, VueShorthand } from "./types"
|
|
6
7
|
|
|
7
8
|
import PrismicRichTextDefaultComponent from "./PrismicRichTextDefaultComponent.vue"
|
|
8
9
|
|
|
@@ -17,18 +18,40 @@ type PrismicRichTextSerializeProps = {
|
|
|
17
18
|
components?: VueRichTextSerializer
|
|
18
19
|
children: ReturnType<typeof asTree>["children"]
|
|
19
20
|
linkResolver?: LinkResolverFunction
|
|
21
|
+
internalLinkComponent?: ComponentOrTagName
|
|
22
|
+
externalLinkComponent?: ComponentOrTagName
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
const props = defineProps<PrismicRichTextSerializeProps>()
|
|
23
26
|
defineOptions({ name: "PrismicRichTextSerialize" })
|
|
24
27
|
|
|
25
28
|
function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
|
|
26
|
-
|
|
29
|
+
const maybeComponentOrShorthand =
|
|
27
30
|
props.components?.[
|
|
28
31
|
CHILD_TYPE_RENAMES[child.type as keyof typeof CHILD_TYPE_RENAMES] ||
|
|
29
32
|
(child.type as keyof typeof props.components)
|
|
30
|
-
]
|
|
31
|
-
|
|
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
|
+
}
|
|
32
55
|
}
|
|
33
56
|
</script>
|
|
34
57
|
|
|
@@ -36,17 +59,15 @@ function getComponent(child: ReturnType<typeof asTree>["children"][number]) {
|
|
|
36
59
|
<component
|
|
37
60
|
v-for="child in props.children"
|
|
38
61
|
:key="JSON.stringify(child)"
|
|
39
|
-
:is="getComponent(child)"
|
|
62
|
+
:is="getComponent(child).is"
|
|
40
63
|
:node="child.node"
|
|
41
|
-
|
|
42
|
-
getComponent(child) === PrismicRichTextDefaultComponent
|
|
43
|
-
? props.linkResolver
|
|
44
|
-
: undefined
|
|
45
|
-
"
|
|
64
|
+
v-bind="getComponent(child).props"
|
|
46
65
|
><PrismicRichTextSerialize
|
|
47
66
|
v-if="child.children.length"
|
|
48
67
|
:children="child.children"
|
|
49
68
|
:components="components"
|
|
50
69
|
:link-resolver="linkResolver"
|
|
70
|
+
:internal-link-component="internalLinkComponent"
|
|
71
|
+
:external-link-component="externalLinkComponent"
|
|
51
72
|
/></component>
|
|
52
73
|
</template>
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
* @see Templating Rich Text and title fields from Prismic {@link https://prismic.io/docs/rich-text}
|
|
13
13
|
*/
|
|
14
14
|
export type VueRichTextSerializer = Partial<
|
|
15
|
-
Record<keyof typeof RichTextNodeType, VueRichTextComponent>
|
|
15
|
+
Record<keyof typeof RichTextNodeType, VueRichTextComponent | VueShorthand>
|
|
16
16
|
>
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -35,3 +35,18 @@ type VueRichTextComponent<TRTNode extends RTAnyNode = RTAnyNode> =
|
|
|
35
35
|
| ReturnType<typeof defineAsyncComponent>
|
|
36
36
|
| DefineComponent<RichTextComponentProps<TRTNode>>
|
|
37
37
|
| FunctionalComponent<RichTextComponentProps<TRTNode>>
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A shorthand definition for {@link VueRichTextSerializer} component types.
|
|
41
|
+
*/
|
|
42
|
+
export type VueShorthand = {
|
|
43
|
+
/**
|
|
44
|
+
* The HTML element type rendered for this node type.
|
|
45
|
+
*/
|
|
46
|
+
as?: string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Other attributes to apply to the element type.
|
|
50
|
+
*/
|
|
51
|
+
[Attribute: string]: string | boolean | null | undefined
|
|
52
|
+
}
|
|
@@ -19,12 +19,6 @@ export type PrismicTableProps = {
|
|
|
19
19
|
*/
|
|
20
20
|
field: TableField | undefined
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
24
|
-
* given, `null` (nothing) will be rendered.
|
|
25
|
-
*/
|
|
26
|
-
fallback?: ComponentOrTagName
|
|
27
|
-
|
|
28
22
|
/**
|
|
29
23
|
* An object that maps a table block type to a Vue component.
|
|
30
24
|
*
|
|
@@ -37,6 +31,12 @@ export type PrismicTableProps = {
|
|
|
37
31
|
* ```
|
|
38
32
|
*/
|
|
39
33
|
components?: VueTableComponents & VueRichTextSerializer
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The value to be rendered when the field is empty. If a fallback is not
|
|
37
|
+
* given, `null` (nothing) will be rendered.
|
|
38
|
+
*/
|
|
39
|
+
fallback?: ComponentOrTagName
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const props = defineProps<PrismicTableProps>()
|
|
@@ -76,5 +76,5 @@ const mergedComponents = computed(() => ({
|
|
|
76
76
|
/>
|
|
77
77
|
</component>
|
|
78
78
|
</component>
|
|
79
|
-
<component v-else :is="fallback" />
|
|
79
|
+
<component v-else-if="fallback" :is="fallback" />
|
|
80
80
|
</template>
|
|
@@ -1,44 +1,63 @@
|
|
|
1
1
|
import { defineComponent, h } from "vue"
|
|
2
|
+
import type { PropType } from "vue"
|
|
2
3
|
|
|
3
|
-
import type {
|
|
4
|
+
import type { InternalVueTableComponents } from "./types"
|
|
4
5
|
|
|
5
6
|
import * as getTableComponentProps from "./getTableComponentProps"
|
|
6
7
|
|
|
7
|
-
export const defaultTableComponents:
|
|
8
|
+
export const defaultTableComponents: InternalVueTableComponents = {
|
|
8
9
|
table: defineComponent({
|
|
9
|
-
props:
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
props: {
|
|
11
|
+
...getTableComponentProps.table(),
|
|
12
|
+
as: { type: String as PropType<string | undefined> },
|
|
13
|
+
},
|
|
14
|
+
setup(props, { attrs, slots }) {
|
|
15
|
+
return () => h(props.as ?? "table", attrs, slots.default ? slots.default() : [])
|
|
12
16
|
},
|
|
13
17
|
}),
|
|
14
18
|
thead: defineComponent({
|
|
15
|
-
props:
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
props: {
|
|
20
|
+
...getTableComponentProps.thead(),
|
|
21
|
+
as: { type: String as PropType<string | undefined> },
|
|
22
|
+
},
|
|
23
|
+
setup(props, { attrs, slots }) {
|
|
24
|
+
return () => h(props.as ?? "thead", attrs, slots.default ? slots.default() : [])
|
|
18
25
|
},
|
|
19
26
|
}),
|
|
20
27
|
tbody: defineComponent({
|
|
21
|
-
props:
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
props: {
|
|
29
|
+
...getTableComponentProps.tbody(),
|
|
30
|
+
as: { type: String as PropType<string | undefined> },
|
|
31
|
+
},
|
|
32
|
+
setup(props, { attrs, slots }) {
|
|
33
|
+
return () => h(props.as ?? "tbody", attrs, slots.default ? slots.default() : [])
|
|
24
34
|
},
|
|
25
35
|
}),
|
|
26
36
|
tr: defineComponent({
|
|
27
|
-
props:
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
props: {
|
|
38
|
+
...getTableComponentProps.tr(),
|
|
39
|
+
as: { type: String as PropType<string | undefined> },
|
|
40
|
+
},
|
|
41
|
+
setup(props, { attrs, slots }) {
|
|
42
|
+
return () => h(props.as ?? "tr", attrs, slots.default ? slots.default() : [])
|
|
30
43
|
},
|
|
31
44
|
}),
|
|
32
45
|
th: defineComponent({
|
|
33
|
-
props:
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
props: {
|
|
47
|
+
...getTableComponentProps.th(),
|
|
48
|
+
as: { type: String as PropType<string | undefined> },
|
|
49
|
+
},
|
|
50
|
+
setup(props, { attrs, slots }) {
|
|
51
|
+
return () => h(props.as ?? "th", attrs, slots.default ? slots.default() : [])
|
|
36
52
|
},
|
|
37
53
|
}),
|
|
38
54
|
td: defineComponent({
|
|
39
|
-
props:
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
props: {
|
|
56
|
+
...getTableComponentProps.td(),
|
|
57
|
+
as: { type: String as PropType<string | undefined> },
|
|
58
|
+
},
|
|
59
|
+
setup(props, { attrs, slots }) {
|
|
60
|
+
return () => h(props.as ?? "td", attrs, slots.default ? slots.default() : [])
|
|
42
61
|
},
|
|
43
62
|
}),
|
|
44
63
|
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
FunctionalComponent,
|
|
13
13
|
defineAsyncComponent,
|
|
14
14
|
} from "vue"
|
|
15
|
+
import type { VueShorthand } from "../PrismicRichText/types"
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* A map of Table block types to Vue Components. It is used to render table
|
|
@@ -20,12 +21,21 @@ import type {
|
|
|
20
21
|
* @see Templating Table fields from Prismic {@link https://prismic.io/docs/table}
|
|
21
22
|
*/
|
|
22
23
|
export type VueTableComponents = {
|
|
23
|
-
table?: VueComponent<{ table: TableField<"filled"> }>
|
|
24
|
-
thead?: VueComponent<{ head: TableFieldHead }>
|
|
25
|
-
tbody?: VueComponent<{ body: TableFieldBody }>
|
|
26
|
-
tr?: VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }>
|
|
27
|
-
th?: VueComponent<{ cell: TableFieldHeaderCell }>
|
|
28
|
-
td?: VueComponent<{ cell: TableFieldDataCell }>
|
|
24
|
+
table?: VueComponent<{ table: TableField<"filled"> }> | VueShorthand
|
|
25
|
+
thead?: VueComponent<{ head: TableFieldHead }> | VueShorthand
|
|
26
|
+
tbody?: VueComponent<{ body: TableFieldBody }> | VueShorthand
|
|
27
|
+
tr?: VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow }> | VueShorthand
|
|
28
|
+
th?: VueComponent<{ cell: TableFieldHeaderCell }> | VueShorthand
|
|
29
|
+
td?: VueComponent<{ cell: TableFieldDataCell }> | VueShorthand
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type InternalVueTableComponents = {
|
|
33
|
+
table: VueComponent<{ table: TableField<"filled">; as?: string }>
|
|
34
|
+
thead: VueComponent<{ head: TableFieldHead; as?: string }>
|
|
35
|
+
tbody: VueComponent<{ body: TableFieldBody; as?: string }>
|
|
36
|
+
tr: VueComponent<{ row: TableFieldBodyRow | TableFieldHeadRow; as?: string }>
|
|
37
|
+
th: VueComponent<{ cell: TableFieldHeaderCell; as?: string }>
|
|
38
|
+
td: VueComponent<{ cell: TableFieldDataCell; as?: string }>
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
type VueComponent<TProps> =
|
package/src/PrismicText.vue
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import type { RichTextField } from "@prismicio/client"
|
|
3
|
-
import { asText
|
|
3
|
+
import { asText } from "@prismicio/client"
|
|
4
4
|
import { DEV } from "esm-env"
|
|
5
5
|
import { watchEffect } from "vue"
|
|
6
6
|
|
|
7
|
-
import Wrapper from "./lib/Wrapper.vue"
|
|
8
7
|
import { devMsg } from "./lib/devMsg"
|
|
9
8
|
|
|
10
|
-
import type { ComponentOrTagName } from "./types"
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Props for `<PrismicText />`.
|
|
14
11
|
*/
|
|
@@ -30,14 +27,6 @@ export type PrismicTextProps = {
|
|
|
30
27
|
* @defaultValue `" "` (a whitespace)
|
|
31
28
|
*/
|
|
32
29
|
separator?: string
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* An HTML tag name or a component used to wrap the output. `<PrismicText />`
|
|
36
|
-
* is not wrapped by default.
|
|
37
|
-
*
|
|
38
|
-
* @defaultValue `"template"` (no wrapper)
|
|
39
|
-
*/
|
|
40
|
-
wrapper?: ComponentOrTagName
|
|
41
30
|
}
|
|
42
31
|
|
|
43
32
|
const props = defineProps<PrismicTextProps>()
|
|
@@ -57,7 +46,5 @@ if (DEV) {
|
|
|
57
46
|
</script>
|
|
58
47
|
|
|
59
48
|
<template>
|
|
60
|
-
|
|
61
|
-
{{ asText(field) || fallback }}
|
|
62
|
-
</Wrapper>
|
|
49
|
+
{{ asText(field) || fallback || "" }}
|
|
63
50
|
</template>
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { computed } from "vue"
|
|
3
3
|
|
|
4
|
-
import Wrapper from "../lib/Wrapper.vue"
|
|
5
|
-
|
|
6
|
-
import type { ComponentOrTagName } from "../types"
|
|
7
4
|
import type {
|
|
8
5
|
SliceComponentType,
|
|
9
6
|
SliceLike,
|
|
@@ -11,8 +8,6 @@ import type {
|
|
|
11
8
|
SliceZoneLike,
|
|
12
9
|
} from "./types"
|
|
13
10
|
|
|
14
|
-
import { usePrismic } from "../usePrismic"
|
|
15
|
-
|
|
16
11
|
import { TODOSliceComponent } from "./TODOSliceComponent"
|
|
17
12
|
|
|
18
13
|
/**
|
|
@@ -47,22 +42,14 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
47
42
|
* Arbitrary data made available to all Slice components.
|
|
48
43
|
*/
|
|
49
44
|
context?: TContext
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* An HTML tag name or a component used to wrap the output. `<SliceZone />` is
|
|
53
|
-
* not wrapped by default.
|
|
54
|
-
*
|
|
55
|
-
* @defaultValue `"template"` (no wrapper)
|
|
56
|
-
*/
|
|
57
|
-
wrapper?: ComponentOrTagName
|
|
58
45
|
}
|
|
59
46
|
|
|
60
47
|
const props = defineProps<SliceZoneProps>()
|
|
61
48
|
defineOptions({ name: "SliceZone" })
|
|
62
49
|
|
|
63
|
-
const { options } = usePrismic()
|
|
64
|
-
|
|
65
50
|
const renderedSlices = computed(() => {
|
|
51
|
+
if (!props.slices) return []
|
|
52
|
+
|
|
66
53
|
return props.slices.map((slice, index) => {
|
|
67
54
|
const type =
|
|
68
55
|
"slice_type" in slice ? (slice.slice_type as string) : slice.type
|
|
@@ -72,10 +59,7 @@ const renderedSlices = computed(() => {
|
|
|
72
59
|
? slice.id
|
|
73
60
|
: `${index}-${JSON.stringify(slice)}`
|
|
74
61
|
|
|
75
|
-
const is =
|
|
76
|
-
props.components?.[type] ||
|
|
77
|
-
props.defaultComponent ||
|
|
78
|
-
options.components?.sliceZoneDefaultComponent
|
|
62
|
+
const is = props.components?.[type] || props.defaultComponent
|
|
79
63
|
|
|
80
64
|
if (!is) {
|
|
81
65
|
return { is: TODOSliceComponent, key, props: { slice } }
|
|
@@ -102,12 +86,10 @@ const renderedSlices = computed(() => {
|
|
|
102
86
|
</script>
|
|
103
87
|
|
|
104
88
|
<template>
|
|
105
|
-
<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/>
|
|
112
|
-
</Wrapper>
|
|
89
|
+
<component
|
|
90
|
+
v-for="renderedSlice in renderedSlices"
|
|
91
|
+
:is="renderedSlice.is"
|
|
92
|
+
:key="renderedSlice.key"
|
|
93
|
+
v-bind="renderedSlice.props"
|
|
94
|
+
/>
|
|
113
95
|
</template>
|