@prismicio/vue 4.3.0 → 4.3.2
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/components/PrismicEmbed.cjs.map +1 -1
- package/dist/components/PrismicEmbed.d.ts +7 -7
- package/dist/components/PrismicEmbed.js.map +1 -1
- package/dist/components/PrismicImage.cjs.map +1 -1
- package/dist/components/PrismicImage.d.ts +10 -8
- package/dist/components/PrismicImage.js.map +1 -1
- package/dist/components/PrismicLink.cjs.map +1 -1
- package/dist/components/PrismicLink.d.ts +10 -8
- package/dist/components/PrismicLink.js.map +1 -1
- package/dist/components/PrismicRichText.cjs +5 -1
- package/dist/components/PrismicRichText.cjs.map +1 -1
- package/dist/components/PrismicRichText.d.ts +8 -8
- package/dist/components/PrismicRichText.js +6 -2
- package/dist/components/PrismicRichText.js.map +1 -1
- package/dist/components/PrismicText.cjs.map +1 -1
- package/dist/components/PrismicText.d.ts +8 -8
- package/dist/components/PrismicText.js.map +1 -1
- package/dist/components/SliceZone.cjs.map +1 -1
- package/dist/components/SliceZone.d.ts +14 -12
- package/dist/components/SliceZone.js.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/composables.cjs.map +1 -1
- package/dist/composables.d.ts +20 -2
- package/dist/composables.js.map +1 -1
- package/dist/createPrismic.cjs.map +1 -1
- package/dist/createPrismic.js.map +1 -1
- package/dist/injectionSymbols.cjs.map +1 -1
- package/dist/injectionSymbols.js.map +1 -1
- package/dist/lib/__PRODUCTION__.cjs.map +1 -1
- package/dist/lib/__PRODUCTION__.js.map +1 -1
- package/dist/lib/getSlots.cjs +7 -5
- package/dist/lib/getSlots.cjs.map +1 -1
- package/dist/lib/getSlots.d.ts +2 -2
- package/dist/lib/getSlots.js +7 -5
- package/dist/lib/getSlots.js.map +1 -1
- package/dist/lib/isInternalURL.cjs.map +1 -1
- package/dist/lib/isInternalURL.js.map +1 -1
- package/dist/lib/simplyResolveComponent.cjs.map +1 -1
- package/dist/lib/simplyResolveComponent.d.ts +1 -1
- package/dist/lib/simplyResolveComponent.js.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/usePrismic.cjs.map +1 -1
- package/dist/usePrismic.d.ts +5 -5
- package/dist/usePrismic.js.map +1 -1
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +4 -3
- package/dist/useStatefulPrismicClientMethod.js.map +1 -1
- package/package.json +27 -28
- package/src/components/PrismicEmbed.ts +16 -17
- package/src/components/PrismicImage.ts +57 -59
- package/src/components/PrismicLink.ts +68 -70
- package/src/components/PrismicRichText.ts +71 -68
- package/src/components/PrismicText.ts +30 -32
- package/src/components/SliceZone.ts +94 -96
- package/src/components/index.ts +12 -16
- package/src/composables.ts +41 -23
- package/src/createPrismic.ts +40 -34
- package/src/globalExtensions.ts +2 -2
- package/src/index.ts +10 -10
- package/src/injectionSymbols.ts +4 -4
- package/src/lib/__PRODUCTION__.ts +2 -2
- package/src/lib/getSlots.ts +18 -12
- package/src/lib/isInternalURL.ts +4 -4
- package/src/lib/simplyResolveComponent.ts +4 -9
- package/src/types.ts +61 -52
- package/src/usePrismic.ts +9 -9
- package/src/useStatefulPrismicClientMethod.ts +42 -40
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
LinkField,
|
|
3
3
|
LinkResolverFunction,
|
|
4
4
|
PrismicDocument,
|
|
5
|
-
|
|
6
|
-
} from "@prismicio/client"
|
|
7
|
-
import {
|
|
5
|
+
} from "@prismicio/client"
|
|
6
|
+
import { asLink } from "@prismicio/client"
|
|
7
|
+
import type {
|
|
8
8
|
AllowedComponentProps,
|
|
9
9
|
ComponentCustomProps,
|
|
10
10
|
ComputedRef,
|
|
@@ -13,35 +13,31 @@ import {
|
|
|
13
13
|
PropType,
|
|
14
14
|
Raw,
|
|
15
15
|
VNodeProps,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
h,
|
|
19
|
-
reactive,
|
|
20
|
-
unref,
|
|
21
|
-
} from "vue";
|
|
16
|
+
} from "vue"
|
|
17
|
+
import { computed, defineComponent, h, reactive, unref } from "vue"
|
|
22
18
|
|
|
23
|
-
import { getSlots } from "../lib/getSlots"
|
|
24
|
-
import { isInternalURL } from "../lib/isInternalURL"
|
|
25
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
19
|
+
import { getSlots } from "../lib/getSlots"
|
|
20
|
+
import { isInternalURL } from "../lib/isInternalURL"
|
|
21
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
26
22
|
|
|
27
|
-
import { VueUseOptions } from "../types"
|
|
23
|
+
import type { VueUseOptions } from "../types"
|
|
28
24
|
|
|
29
|
-
import { usePrismic } from "../usePrismic"
|
|
25
|
+
import { usePrismic } from "../usePrismic"
|
|
30
26
|
|
|
31
27
|
/**
|
|
32
28
|
* The default component rendered for internal URLs.
|
|
33
29
|
*/
|
|
34
|
-
const defaultInternalComponent = "router-link"
|
|
30
|
+
const defaultInternalComponent = "router-link"
|
|
35
31
|
|
|
36
32
|
/**
|
|
37
33
|
* The default component rendered for external URLs.
|
|
38
34
|
*/
|
|
39
|
-
const defaultExternalComponent = "a"
|
|
35
|
+
const defaultExternalComponent = "a"
|
|
40
36
|
|
|
41
37
|
/**
|
|
42
38
|
* The default rel attribute rendered for blank target URLs.
|
|
43
39
|
*/
|
|
44
|
-
const defaultBlankTargetRelAttribute = "noopener noreferrer"
|
|
40
|
+
const defaultBlankTargetRelAttribute = "noopener noreferrer"
|
|
45
41
|
|
|
46
42
|
/**
|
|
47
43
|
* Props for `<PrismicLink />`.
|
|
@@ -50,7 +46,7 @@ export type PrismicLinkProps = {
|
|
|
50
46
|
/**
|
|
51
47
|
* The Prismic link field or document to render.
|
|
52
48
|
*/
|
|
53
|
-
field: LinkField | PrismicDocument
|
|
49
|
+
field: LinkField | PrismicDocument
|
|
54
50
|
|
|
55
51
|
/**
|
|
56
52
|
* A link resolver function used to resolve links when not using the route
|
|
@@ -60,17 +56,17 @@ export type PrismicLinkProps = {
|
|
|
60
56
|
*
|
|
61
57
|
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
62
58
|
*/
|
|
63
|
-
linkResolver?: LinkResolverFunction
|
|
59
|
+
linkResolver?: LinkResolverFunction
|
|
64
60
|
|
|
65
61
|
/**
|
|
66
62
|
* An explicit `target` attribute to apply to the rendered link.
|
|
67
63
|
*/
|
|
68
|
-
target?: string | null
|
|
64
|
+
target?: string | null
|
|
69
65
|
|
|
70
66
|
/**
|
|
71
67
|
* An explicit `rel` attribute to apply to the rendered link.
|
|
72
68
|
*/
|
|
73
|
-
rel?: string | null
|
|
69
|
+
rel?: string | null
|
|
74
70
|
|
|
75
71
|
/**
|
|
76
72
|
* Value of the `rel` attribute to use on links rendered with
|
|
@@ -78,7 +74,7 @@ export type PrismicLinkProps = {
|
|
|
78
74
|
*
|
|
79
75
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"noopener noreferrer"` otherwise.
|
|
80
76
|
*/
|
|
81
|
-
blankTargetRelAttribute?: string | null
|
|
77
|
+
blankTargetRelAttribute?: string | null
|
|
82
78
|
|
|
83
79
|
/**
|
|
84
80
|
* An HTML tag name, a component, or a functional component used to render
|
|
@@ -90,9 +86,10 @@ export type PrismicLinkProps = {
|
|
|
90
86
|
* @remarks
|
|
91
87
|
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
92
88
|
* (`to` props).
|
|
89
|
+
*
|
|
93
90
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, {@link RouterLink} otherwise.
|
|
94
91
|
*/
|
|
95
|
-
internalComponent?: string | ConcreteComponent | Raw<DefineComponent
|
|
92
|
+
internalComponent?: string | ConcreteComponent | Raw<DefineComponent>
|
|
96
93
|
|
|
97
94
|
/**
|
|
98
95
|
* An HTML tag name, a component, or a functional component used to render
|
|
@@ -104,15 +101,16 @@ export type PrismicLinkProps = {
|
|
|
104
101
|
* @remarks
|
|
105
102
|
* Components will be rendered using Vue Router {@link RouterLink} interface
|
|
106
103
|
* (`to` props).
|
|
104
|
+
*
|
|
107
105
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"a"` otherwise.
|
|
108
106
|
*/
|
|
109
|
-
externalComponent?: string | ConcreteComponent | Raw<DefineComponent
|
|
110
|
-
}
|
|
107
|
+
externalComponent?: string | ConcreteComponent | Raw<DefineComponent>
|
|
108
|
+
}
|
|
111
109
|
|
|
112
110
|
/**
|
|
113
111
|
* Options for {@link usePrismicLink}.
|
|
114
112
|
*/
|
|
115
|
-
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps
|
|
113
|
+
export type UsePrismicLinkOptions = VueUseOptions<PrismicLinkProps>
|
|
116
114
|
|
|
117
115
|
/**
|
|
118
116
|
* Return type of {@link usePrismicLink}.
|
|
@@ -121,28 +119,28 @@ export type UsePrismicLinkReturnType = {
|
|
|
121
119
|
/**
|
|
122
120
|
* Suggested component to render for provided link field.
|
|
123
121
|
*/
|
|
124
|
-
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent
|
|
122
|
+
type: ComputedRef<string | ConcreteComponent | Raw<DefineComponent>>
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
125
|
* Resolved anchor `href` value.
|
|
128
126
|
*/
|
|
129
|
-
href: ComputedRef<string
|
|
127
|
+
href: ComputedRef<string>
|
|
130
128
|
|
|
131
129
|
/**
|
|
132
130
|
* Resolved anchor `target` value.
|
|
133
131
|
*/
|
|
134
|
-
target: ComputedRef<string | null
|
|
132
|
+
target: ComputedRef<string | null>
|
|
135
133
|
|
|
136
134
|
/**
|
|
137
135
|
* Resolved anchor `rel` value.
|
|
138
136
|
*/
|
|
139
|
-
rel: ComputedRef<string | null
|
|
137
|
+
rel: ComputedRef<string | null>
|
|
140
138
|
|
|
141
139
|
/**
|
|
142
140
|
* Resolved link text.
|
|
143
141
|
*/
|
|
144
|
-
text: ComputedRef<string | undefined
|
|
145
|
-
}
|
|
142
|
+
text: ComputedRef<string | undefined>
|
|
143
|
+
}
|
|
146
144
|
|
|
147
145
|
/**
|
|
148
146
|
* A low level composable that returns resolved information about a Prismic link
|
|
@@ -155,65 +153,65 @@ export type UsePrismicLinkReturnType = {
|
|
|
155
153
|
export const usePrismicLink = (
|
|
156
154
|
props: UsePrismicLinkOptions,
|
|
157
155
|
): UsePrismicLinkReturnType => {
|
|
158
|
-
const { options } = usePrismic()
|
|
156
|
+
const { options } = usePrismic()
|
|
159
157
|
|
|
160
158
|
const type = computed(() => {
|
|
161
159
|
const internalComponent =
|
|
162
160
|
unref(props.internalComponent) ||
|
|
163
161
|
options.components?.linkInternalComponent ||
|
|
164
|
-
defaultInternalComponent
|
|
162
|
+
defaultInternalComponent
|
|
165
163
|
|
|
166
164
|
const externalComponent =
|
|
167
165
|
unref(props.externalComponent) ||
|
|
168
166
|
options.components?.linkExternalComponent ||
|
|
169
|
-
defaultExternalComponent
|
|
167
|
+
defaultExternalComponent
|
|
170
168
|
|
|
171
169
|
return href.value && isInternalURL(href.value) && !target.value
|
|
172
170
|
? internalComponent
|
|
173
|
-
: externalComponent
|
|
174
|
-
})
|
|
171
|
+
: externalComponent
|
|
172
|
+
})
|
|
175
173
|
const href = computed(() => {
|
|
176
|
-
const field = unref(props.field)
|
|
177
|
-
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
174
|
+
const field = unref(props.field)
|
|
175
|
+
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
178
176
|
|
|
179
|
-
return asLink(field, linkResolver) ?? ""
|
|
180
|
-
})
|
|
177
|
+
return asLink(field, linkResolver) ?? ""
|
|
178
|
+
})
|
|
181
179
|
const target = computed(() => {
|
|
182
|
-
const field = unref(props.field)
|
|
183
|
-
const target = unref(props.target)
|
|
180
|
+
const field = unref(props.field)
|
|
181
|
+
const target = unref(props.target)
|
|
184
182
|
|
|
185
183
|
if (typeof target !== "undefined") {
|
|
186
|
-
return target
|
|
184
|
+
return target
|
|
187
185
|
} else {
|
|
188
|
-
return field && "target" in field && field.target ? field.target : null
|
|
186
|
+
return field && "target" in field && field.target ? field.target : null
|
|
189
187
|
}
|
|
190
|
-
})
|
|
188
|
+
})
|
|
191
189
|
const rel = computed(() => {
|
|
192
|
-
const rel = unref(props.rel)
|
|
190
|
+
const rel = unref(props.rel)
|
|
193
191
|
|
|
194
192
|
if (typeof rel !== "undefined") {
|
|
195
|
-
return rel
|
|
193
|
+
return rel
|
|
196
194
|
} else if (target.value === "_blank") {
|
|
197
|
-
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute)
|
|
195
|
+
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute)
|
|
198
196
|
|
|
199
197
|
if (typeof blankTargetRelAttribute !== "undefined") {
|
|
200
|
-
return blankTargetRelAttribute
|
|
198
|
+
return blankTargetRelAttribute
|
|
201
199
|
} else {
|
|
202
200
|
return typeof options.components?.linkBlankTargetRelAttribute !==
|
|
203
201
|
"undefined"
|
|
204
202
|
? options.components.linkBlankTargetRelAttribute
|
|
205
|
-
: defaultBlankTargetRelAttribute
|
|
203
|
+
: defaultBlankTargetRelAttribute
|
|
206
204
|
}
|
|
207
205
|
} else {
|
|
208
|
-
return null
|
|
206
|
+
return null
|
|
209
207
|
}
|
|
210
|
-
})
|
|
208
|
+
})
|
|
211
209
|
|
|
212
210
|
const text = computed(() => {
|
|
213
|
-
const field = unref(props.field)
|
|
211
|
+
const field = unref(props.field)
|
|
214
212
|
|
|
215
|
-
return field && "text" in field ? field.text : undefined
|
|
216
|
-
})
|
|
213
|
+
return field && "text" in field ? field.text : undefined
|
|
214
|
+
})
|
|
217
215
|
|
|
218
216
|
return {
|
|
219
217
|
type,
|
|
@@ -221,8 +219,8 @@ export const usePrismicLink = (
|
|
|
221
219
|
target,
|
|
222
220
|
rel,
|
|
223
221
|
text,
|
|
224
|
-
}
|
|
225
|
-
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
226
224
|
|
|
227
225
|
/**
|
|
228
226
|
* `<PrismicLink />` implementation.
|
|
@@ -274,20 +272,20 @@ export const PrismicLinkImpl = /*#__PURE__*/ defineComponent({
|
|
|
274
272
|
setup(props, { slots }) {
|
|
275
273
|
// Prevent fatal if user didn't check for field, throws `Invalid prop` warn
|
|
276
274
|
if (!props.field) {
|
|
277
|
-
return () => null
|
|
275
|
+
return () => null
|
|
278
276
|
}
|
|
279
277
|
|
|
280
|
-
const { type, href, target, rel, text } = usePrismicLink(props)
|
|
278
|
+
const { type, href, target, rel, text } = usePrismicLink(props)
|
|
281
279
|
|
|
282
280
|
return () => {
|
|
283
281
|
const parent =
|
|
284
|
-
type.value === "a" ? "a" : simplyResolveComponent(type.value)
|
|
282
|
+
type.value === "a" ? "a" : simplyResolveComponent(type.value)
|
|
285
283
|
const computedSlots = getSlots(
|
|
286
284
|
parent,
|
|
287
285
|
slots,
|
|
288
286
|
reactive({ href: href.value, text: text.value }),
|
|
289
287
|
text.value,
|
|
290
|
-
)
|
|
288
|
+
)
|
|
291
289
|
|
|
292
290
|
if (typeof parent === "string") {
|
|
293
291
|
// Fitting anchor tag interface
|
|
@@ -295,18 +293,18 @@ export const PrismicLinkImpl = /*#__PURE__*/ defineComponent({
|
|
|
295
293
|
parent,
|
|
296
294
|
{ href: href.value, target: target.value, rel: rel.value },
|
|
297
295
|
computedSlots,
|
|
298
|
-
)
|
|
296
|
+
)
|
|
299
297
|
} else {
|
|
300
298
|
// Fitting Vue Router Link interface
|
|
301
299
|
return h(
|
|
302
300
|
parent,
|
|
303
301
|
{ to: href.value, target: target.value, rel: rel.value },
|
|
304
302
|
computedSlots,
|
|
305
|
-
)
|
|
303
|
+
)
|
|
306
304
|
}
|
|
307
|
-
}
|
|
305
|
+
}
|
|
308
306
|
},
|
|
309
|
-
})
|
|
307
|
+
})
|
|
310
308
|
|
|
311
309
|
// export the public type for h/tsx inference
|
|
312
310
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -321,6 +319,6 @@ export const PrismicLink = PrismicLinkImpl as unknown as {
|
|
|
321
319
|
$props: AllowedComponentProps &
|
|
322
320
|
ComponentCustomProps &
|
|
323
321
|
VNodeProps &
|
|
324
|
-
PrismicLinkProps
|
|
325
|
-
}
|
|
326
|
-
}
|
|
322
|
+
PrismicLinkProps
|
|
323
|
+
}
|
|
324
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
HTMLFunctionSerializer,
|
|
3
3
|
HTMLMapSerializer,
|
|
4
4
|
LinkResolverFunction,
|
|
5
5
|
RichTextField,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
6
|
+
} from "@prismicio/client"
|
|
7
|
+
import { asHTML, isFilled } from "@prismicio/client"
|
|
8
|
+
import type {
|
|
10
9
|
AllowedComponentProps,
|
|
11
10
|
Component,
|
|
12
11
|
ComponentCustomProps,
|
|
@@ -16,29 +15,32 @@ import {
|
|
|
16
15
|
PropType,
|
|
17
16
|
Raw,
|
|
18
17
|
VNodeProps,
|
|
18
|
+
} from "vue"
|
|
19
|
+
import {
|
|
19
20
|
computed,
|
|
20
21
|
defineComponent,
|
|
21
22
|
h,
|
|
22
23
|
inject,
|
|
23
24
|
nextTick,
|
|
24
25
|
onBeforeUnmount,
|
|
26
|
+
onMounted,
|
|
25
27
|
ref,
|
|
26
28
|
unref,
|
|
27
29
|
watch,
|
|
28
|
-
} from "vue"
|
|
29
|
-
import { routerKey } from "vue-router"
|
|
30
|
+
} from "vue"
|
|
31
|
+
import { routerKey } from "vue-router"
|
|
30
32
|
|
|
31
|
-
import { isInternalURL } from "../lib/isInternalURL"
|
|
32
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
33
|
+
import { isInternalURL } from "../lib/isInternalURL"
|
|
34
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
33
35
|
|
|
34
|
-
import { VueUseOptions } from "../types"
|
|
36
|
+
import type { VueUseOptions } from "../types"
|
|
35
37
|
|
|
36
|
-
import { usePrismic } from "../usePrismic"
|
|
38
|
+
import { usePrismic } from "../usePrismic"
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* The default component rendered to wrap the HTML output.
|
|
40
42
|
*/
|
|
41
|
-
const defaultWrapper = "div"
|
|
43
|
+
const defaultWrapper = "div"
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Props for `<PrismicRichText />`.
|
|
@@ -47,7 +49,7 @@ export type PrismicRichTextProps = {
|
|
|
47
49
|
/**
|
|
48
50
|
* The Prismic rich text or title field to render.
|
|
49
51
|
*/
|
|
50
|
-
field: RichTextField | null | undefined
|
|
52
|
+
field: RichTextField | null | undefined
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* A link resolver function used to resolve link when not using the route
|
|
@@ -57,7 +59,7 @@ export type PrismicRichTextProps = {
|
|
|
57
59
|
*
|
|
58
60
|
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
59
61
|
*/
|
|
60
|
-
linkResolver?: LinkResolverFunction
|
|
62
|
+
linkResolver?: LinkResolverFunction
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* An HTML serializer to customize the way rich text fields are rendered.
|
|
@@ -66,7 +68,7 @@ export type PrismicRichTextProps = {
|
|
|
66
68
|
*
|
|
67
69
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
68
70
|
*/
|
|
69
|
-
serializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
71
|
+
serializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
70
72
|
|
|
71
73
|
/**
|
|
72
74
|
* An HTML serializer to customize the way rich text fields are rendered.
|
|
@@ -77,7 +79,7 @@ export type PrismicRichTextProps = {
|
|
|
77
79
|
*
|
|
78
80
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
79
81
|
*/
|
|
80
|
-
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
82
|
+
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
81
83
|
|
|
82
84
|
/**
|
|
83
85
|
* An HTML tag name, a component, or a functional component used to wrap the
|
|
@@ -85,21 +87,21 @@ export type PrismicRichTextProps = {
|
|
|
85
87
|
*
|
|
86
88
|
* @defaultValue `"div"`
|
|
87
89
|
*/
|
|
88
|
-
wrapper?: string | ConcreteComponent | Raw<DefineComponent
|
|
90
|
+
wrapper?: string | ConcreteComponent | Raw<DefineComponent>
|
|
89
91
|
|
|
90
92
|
/**
|
|
91
93
|
* The HTML value to be rendered when the field is empty. If a fallback is not
|
|
92
94
|
* given, `""` (nothing) will be rendered.
|
|
93
95
|
*/
|
|
94
|
-
fallback?: string
|
|
95
|
-
}
|
|
96
|
+
fallback?: string
|
|
97
|
+
}
|
|
96
98
|
|
|
97
99
|
/**
|
|
98
100
|
* Options for {@link usePrismicRichText}.
|
|
99
101
|
*/
|
|
100
102
|
export type UsePrismicRichTextOptions = VueUseOptions<
|
|
101
103
|
Omit<PrismicRichTextProps, "wrapper">
|
|
102
|
-
|
|
104
|
+
>
|
|
103
105
|
|
|
104
106
|
/**
|
|
105
107
|
* Return type of {@link usePrismicRichText}.
|
|
@@ -108,8 +110,8 @@ export type UsePrismicRichTextReturnType = {
|
|
|
108
110
|
/**
|
|
109
111
|
* Serialized rich text field as HTML.
|
|
110
112
|
*/
|
|
111
|
-
html: ComputedRef<string
|
|
112
|
-
}
|
|
113
|
+
html: ComputedRef<string>
|
|
114
|
+
}
|
|
113
115
|
|
|
114
116
|
/**
|
|
115
117
|
* A low level composable that returns a serialized rich text field as HTML.
|
|
@@ -122,29 +124,29 @@ export type UsePrismicRichTextReturnType = {
|
|
|
122
124
|
export const usePrismicRichText = (
|
|
123
125
|
props: UsePrismicRichTextOptions,
|
|
124
126
|
): UsePrismicRichTextReturnType => {
|
|
125
|
-
const { options } = usePrismic()
|
|
127
|
+
const { options } = usePrismic()
|
|
126
128
|
|
|
127
129
|
const html = computed(() => {
|
|
128
|
-
const field = unref(props.field)
|
|
130
|
+
const field = unref(props.field)
|
|
129
131
|
|
|
130
132
|
if (!isFilled.richText(field)) {
|
|
131
|
-
return unref(props.fallback) ?? ""
|
|
133
|
+
return unref(props.fallback) ?? ""
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
136
|
+
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
135
137
|
const serializer =
|
|
136
138
|
unref(props.serializer) ??
|
|
137
139
|
unref(props.htmlSerializer) ??
|
|
138
140
|
options.richTextSerializer ??
|
|
139
|
-
options.htmlSerializer
|
|
141
|
+
options.htmlSerializer
|
|
140
142
|
|
|
141
|
-
return asHTML(unref(field), linkResolver, serializer)
|
|
142
|
-
})
|
|
143
|
+
return asHTML(unref(field), linkResolver, serializer)
|
|
144
|
+
})
|
|
143
145
|
|
|
144
146
|
return {
|
|
145
147
|
html,
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
148
150
|
|
|
149
151
|
/**
|
|
150
152
|
* `<PrismicRichText />` implementation.
|
|
@@ -192,77 +194,78 @@ export const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({
|
|
|
192
194
|
},
|
|
193
195
|
},
|
|
194
196
|
setup(props) {
|
|
195
|
-
const { html } = usePrismicRichText(props)
|
|
197
|
+
const { html } = usePrismicRichText(props)
|
|
196
198
|
|
|
197
|
-
const root = ref<HTMLElement | Comment | Component | null>(null)
|
|
199
|
+
const root = ref<HTMLElement | Comment | Component | null>(null)
|
|
198
200
|
|
|
199
|
-
const maybeRouter = inject(routerKey, null)
|
|
201
|
+
const maybeRouter = inject(routerKey, null)
|
|
200
202
|
if (maybeRouter) {
|
|
201
203
|
type InternalLink = {
|
|
202
|
-
element: HTMLAnchorElement
|
|
203
|
-
listener: EventListener
|
|
204
|
-
}
|
|
205
|
-
let links: InternalLink[] = []
|
|
204
|
+
element: HTMLAnchorElement
|
|
205
|
+
listener: EventListener
|
|
206
|
+
}
|
|
207
|
+
let links: InternalLink[] = []
|
|
206
208
|
|
|
207
209
|
const navigate: EventListener = function (
|
|
208
210
|
this: { href: string },
|
|
209
211
|
event: Event,
|
|
210
212
|
) {
|
|
211
|
-
event.preventDefault()
|
|
212
|
-
maybeRouter.push(this.href)
|
|
213
|
-
}
|
|
213
|
+
event.preventDefault()
|
|
214
|
+
maybeRouter.push(this.href)
|
|
215
|
+
}
|
|
214
216
|
|
|
215
217
|
const addListeners = () => {
|
|
216
218
|
const node: HTMLElement | Comment | null =
|
|
217
|
-
root.value && "$el" in root.value ? root.value.$el : root.value
|
|
219
|
+
root.value && "$el" in root.value ? root.value.$el : root.value
|
|
218
220
|
if (node && "querySelectorAll" in node) {
|
|
219
221
|
// Get all internal link tags and add listeners on them
|
|
220
222
|
links = Array.from(node.querySelectorAll("a"))
|
|
221
223
|
.map((element) => {
|
|
222
|
-
const href = element.getAttribute("href")
|
|
224
|
+
const href = element.getAttribute("href")
|
|
223
225
|
|
|
224
226
|
if (href && isInternalURL(href)) {
|
|
225
|
-
const listener = navigate.bind({ href })
|
|
226
|
-
element.addEventListener("click", listener)
|
|
227
|
+
const listener = navigate.bind({ href })
|
|
228
|
+
element.addEventListener("click", listener)
|
|
227
229
|
|
|
228
|
-
return { element, listener }
|
|
230
|
+
return { element, listener }
|
|
229
231
|
} else {
|
|
230
|
-
return false
|
|
232
|
+
return false
|
|
231
233
|
}
|
|
232
234
|
})
|
|
233
|
-
.filter((link): link is InternalLink => link as boolean)
|
|
235
|
+
.filter((link): link is InternalLink => link as boolean)
|
|
234
236
|
}
|
|
235
|
-
}
|
|
237
|
+
}
|
|
236
238
|
|
|
237
239
|
const removeListeners = () => {
|
|
238
240
|
links.forEach(({ element, listener }) =>
|
|
239
241
|
element.removeEventListener("click", listener),
|
|
240
|
-
)
|
|
241
|
-
links = []
|
|
242
|
-
}
|
|
242
|
+
)
|
|
243
|
+
links = []
|
|
244
|
+
}
|
|
243
245
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
()
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
246
|
+
onMounted(() => {
|
|
247
|
+
removeListeners()
|
|
248
|
+
nextTick(addListeners)
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
watch(html, () => {
|
|
252
|
+
removeListeners()
|
|
253
|
+
nextTick(addListeners)
|
|
254
|
+
})
|
|
252
255
|
|
|
253
256
|
onBeforeUnmount(() => {
|
|
254
|
-
removeListeners()
|
|
255
|
-
})
|
|
257
|
+
removeListeners()
|
|
258
|
+
})
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
return () => {
|
|
259
262
|
return h(simplyResolveComponent(props.wrapper || defaultWrapper), {
|
|
260
263
|
innerHTML: html.value,
|
|
261
264
|
ref: root,
|
|
262
|
-
})
|
|
263
|
-
}
|
|
265
|
+
})
|
|
266
|
+
}
|
|
264
267
|
},
|
|
265
|
-
})
|
|
268
|
+
})
|
|
266
269
|
|
|
267
270
|
// export the public type for h/tsx inference
|
|
268
271
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -277,6 +280,6 @@ export const PrismicRichText = PrismicRichTextImpl as unknown as {
|
|
|
277
280
|
$props: AllowedComponentProps &
|
|
278
281
|
ComponentCustomProps &
|
|
279
282
|
VNodeProps &
|
|
280
|
-
PrismicRichTextProps
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
+
PrismicRichTextProps
|
|
284
|
+
}
|
|
285
|
+
}
|