@prismicio/vue 4.3.0 → 4.3.1
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.map +1 -1
- package/dist/components/PrismicRichText.d.ts +8 -8
- 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 +64 -63
- 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,6 +15,8 @@ import {
|
|
|
16
15
|
PropType,
|
|
17
16
|
Raw,
|
|
18
17
|
VNodeProps,
|
|
18
|
+
} from "vue"
|
|
19
|
+
import {
|
|
19
20
|
computed,
|
|
20
21
|
defineComponent,
|
|
21
22
|
h,
|
|
@@ -25,20 +26,20 @@ import {
|
|
|
25
26
|
ref,
|
|
26
27
|
unref,
|
|
27
28
|
watch,
|
|
28
|
-
} from "vue"
|
|
29
|
-
import { routerKey } from "vue-router"
|
|
29
|
+
} from "vue"
|
|
30
|
+
import { routerKey } from "vue-router"
|
|
30
31
|
|
|
31
|
-
import { isInternalURL } from "../lib/isInternalURL"
|
|
32
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
32
|
+
import { isInternalURL } from "../lib/isInternalURL"
|
|
33
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
33
34
|
|
|
34
|
-
import { VueUseOptions } from "../types"
|
|
35
|
+
import type { VueUseOptions } from "../types"
|
|
35
36
|
|
|
36
|
-
import { usePrismic } from "../usePrismic"
|
|
37
|
+
import { usePrismic } from "../usePrismic"
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* The default component rendered to wrap the HTML output.
|
|
40
41
|
*/
|
|
41
|
-
const defaultWrapper = "div"
|
|
42
|
+
const defaultWrapper = "div"
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
* Props for `<PrismicRichText />`.
|
|
@@ -47,7 +48,7 @@ export type PrismicRichTextProps = {
|
|
|
47
48
|
/**
|
|
48
49
|
* The Prismic rich text or title field to render.
|
|
49
50
|
*/
|
|
50
|
-
field: RichTextField | null | undefined
|
|
51
|
+
field: RichTextField | null | undefined
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* A link resolver function used to resolve link when not using the route
|
|
@@ -57,7 +58,7 @@ export type PrismicRichTextProps = {
|
|
|
57
58
|
*
|
|
58
59
|
* @see Link resolver documentation {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#link-resolver}
|
|
59
60
|
*/
|
|
60
|
-
linkResolver?: LinkResolverFunction
|
|
61
|
+
linkResolver?: LinkResolverFunction
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* An HTML serializer to customize the way rich text fields are rendered.
|
|
@@ -66,7 +67,7 @@ export type PrismicRichTextProps = {
|
|
|
66
67
|
*
|
|
67
68
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
68
69
|
*/
|
|
69
|
-
serializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
70
|
+
serializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
* An HTML serializer to customize the way rich text fields are rendered.
|
|
@@ -77,7 +78,7 @@ export type PrismicRichTextProps = {
|
|
|
77
78
|
*
|
|
78
79
|
* @see HTML serializer documentation {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
79
80
|
*/
|
|
80
|
-
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
81
|
+
htmlSerializer?: HTMLFunctionSerializer | HTMLMapSerializer
|
|
81
82
|
|
|
82
83
|
/**
|
|
83
84
|
* An HTML tag name, a component, or a functional component used to wrap the
|
|
@@ -85,21 +86,21 @@ export type PrismicRichTextProps = {
|
|
|
85
86
|
*
|
|
86
87
|
* @defaultValue `"div"`
|
|
87
88
|
*/
|
|
88
|
-
wrapper?: string | ConcreteComponent | Raw<DefineComponent
|
|
89
|
+
wrapper?: string | ConcreteComponent | Raw<DefineComponent>
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
92
|
* The HTML value to be rendered when the field is empty. If a fallback is not
|
|
92
93
|
* given, `""` (nothing) will be rendered.
|
|
93
94
|
*/
|
|
94
|
-
fallback?: string
|
|
95
|
-
}
|
|
95
|
+
fallback?: string
|
|
96
|
+
}
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
99
|
* Options for {@link usePrismicRichText}.
|
|
99
100
|
*/
|
|
100
101
|
export type UsePrismicRichTextOptions = VueUseOptions<
|
|
101
102
|
Omit<PrismicRichTextProps, "wrapper">
|
|
102
|
-
|
|
103
|
+
>
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
106
|
* Return type of {@link usePrismicRichText}.
|
|
@@ -108,8 +109,8 @@ export type UsePrismicRichTextReturnType = {
|
|
|
108
109
|
/**
|
|
109
110
|
* Serialized rich text field as HTML.
|
|
110
111
|
*/
|
|
111
|
-
html: ComputedRef<string
|
|
112
|
-
}
|
|
112
|
+
html: ComputedRef<string>
|
|
113
|
+
}
|
|
113
114
|
|
|
114
115
|
/**
|
|
115
116
|
* A low level composable that returns a serialized rich text field as HTML.
|
|
@@ -122,29 +123,29 @@ export type UsePrismicRichTextReturnType = {
|
|
|
122
123
|
export const usePrismicRichText = (
|
|
123
124
|
props: UsePrismicRichTextOptions,
|
|
124
125
|
): UsePrismicRichTextReturnType => {
|
|
125
|
-
const { options } = usePrismic()
|
|
126
|
+
const { options } = usePrismic()
|
|
126
127
|
|
|
127
128
|
const html = computed(() => {
|
|
128
|
-
const field = unref(props.field)
|
|
129
|
+
const field = unref(props.field)
|
|
129
130
|
|
|
130
131
|
if (!isFilled.richText(field)) {
|
|
131
|
-
return unref(props.fallback) ?? ""
|
|
132
|
+
return unref(props.fallback) ?? ""
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
135
|
+
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
135
136
|
const serializer =
|
|
136
137
|
unref(props.serializer) ??
|
|
137
138
|
unref(props.htmlSerializer) ??
|
|
138
139
|
options.richTextSerializer ??
|
|
139
|
-
options.htmlSerializer
|
|
140
|
+
options.htmlSerializer
|
|
140
141
|
|
|
141
|
-
return asHTML(unref(field), linkResolver, serializer)
|
|
142
|
-
})
|
|
142
|
+
return asHTML(unref(field), linkResolver, serializer)
|
|
143
|
+
})
|
|
143
144
|
|
|
144
145
|
return {
|
|
145
146
|
html,
|
|
146
|
-
}
|
|
147
|
-
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* `<PrismicRichText />` implementation.
|
|
@@ -192,77 +193,77 @@ export const PrismicRichTextImpl = /*#__PURE__*/ defineComponent({
|
|
|
192
193
|
},
|
|
193
194
|
},
|
|
194
195
|
setup(props) {
|
|
195
|
-
const { html } = usePrismicRichText(props)
|
|
196
|
+
const { html } = usePrismicRichText(props)
|
|
196
197
|
|
|
197
|
-
const root = ref<HTMLElement | Comment | Component | null>(null)
|
|
198
|
+
const root = ref<HTMLElement | Comment | Component | null>(null)
|
|
198
199
|
|
|
199
|
-
const maybeRouter = inject(routerKey, null)
|
|
200
|
+
const maybeRouter = inject(routerKey, null)
|
|
200
201
|
if (maybeRouter) {
|
|
201
202
|
type InternalLink = {
|
|
202
|
-
element: HTMLAnchorElement
|
|
203
|
-
listener: EventListener
|
|
204
|
-
}
|
|
205
|
-
let links: InternalLink[] = []
|
|
203
|
+
element: HTMLAnchorElement
|
|
204
|
+
listener: EventListener
|
|
205
|
+
}
|
|
206
|
+
let links: InternalLink[] = []
|
|
206
207
|
|
|
207
208
|
const navigate: EventListener = function (
|
|
208
209
|
this: { href: string },
|
|
209
210
|
event: Event,
|
|
210
211
|
) {
|
|
211
|
-
event.preventDefault()
|
|
212
|
-
maybeRouter.push(this.href)
|
|
213
|
-
}
|
|
212
|
+
event.preventDefault()
|
|
213
|
+
maybeRouter.push(this.href)
|
|
214
|
+
}
|
|
214
215
|
|
|
215
216
|
const addListeners = () => {
|
|
216
217
|
const node: HTMLElement | Comment | null =
|
|
217
|
-
root.value && "$el" in root.value ? root.value.$el : root.value
|
|
218
|
+
root.value && "$el" in root.value ? root.value.$el : root.value
|
|
218
219
|
if (node && "querySelectorAll" in node) {
|
|
219
220
|
// Get all internal link tags and add listeners on them
|
|
220
221
|
links = Array.from(node.querySelectorAll("a"))
|
|
221
222
|
.map((element) => {
|
|
222
|
-
const href = element.getAttribute("href")
|
|
223
|
+
const href = element.getAttribute("href")
|
|
223
224
|
|
|
224
225
|
if (href && isInternalURL(href)) {
|
|
225
|
-
const listener = navigate.bind({ href })
|
|
226
|
-
element.addEventListener("click", listener)
|
|
226
|
+
const listener = navigate.bind({ href })
|
|
227
|
+
element.addEventListener("click", listener)
|
|
227
228
|
|
|
228
|
-
return { element, listener }
|
|
229
|
+
return { element, listener }
|
|
229
230
|
} else {
|
|
230
|
-
return false
|
|
231
|
+
return false
|
|
231
232
|
}
|
|
232
233
|
})
|
|
233
|
-
.filter((link): link is InternalLink => link as boolean)
|
|
234
|
+
.filter((link): link is InternalLink => link as boolean)
|
|
234
235
|
}
|
|
235
|
-
}
|
|
236
|
+
}
|
|
236
237
|
|
|
237
238
|
const removeListeners = () => {
|
|
238
239
|
links.forEach(({ element, listener }) =>
|
|
239
240
|
element.removeEventListener("click", listener),
|
|
240
|
-
)
|
|
241
|
-
links = []
|
|
242
|
-
}
|
|
241
|
+
)
|
|
242
|
+
links = []
|
|
243
|
+
}
|
|
243
244
|
|
|
244
245
|
watch(
|
|
245
246
|
html,
|
|
246
247
|
() => {
|
|
247
|
-
removeListeners()
|
|
248
|
-
nextTick(addListeners)
|
|
248
|
+
removeListeners()
|
|
249
|
+
nextTick(addListeners)
|
|
249
250
|
},
|
|
250
251
|
{ immediate: true },
|
|
251
|
-
)
|
|
252
|
+
)
|
|
252
253
|
|
|
253
254
|
onBeforeUnmount(() => {
|
|
254
|
-
removeListeners()
|
|
255
|
-
})
|
|
255
|
+
removeListeners()
|
|
256
|
+
})
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
return () => {
|
|
259
260
|
return h(simplyResolveComponent(props.wrapper || defaultWrapper), {
|
|
260
261
|
innerHTML: html.value,
|
|
261
262
|
ref: root,
|
|
262
|
-
})
|
|
263
|
-
}
|
|
263
|
+
})
|
|
264
|
+
}
|
|
264
265
|
},
|
|
265
|
-
})
|
|
266
|
+
})
|
|
266
267
|
|
|
267
268
|
// export the public type for h/tsx inference
|
|
268
269
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -277,6 +278,6 @@ export const PrismicRichText = PrismicRichTextImpl as unknown as {
|
|
|
277
278
|
$props: AllowedComponentProps &
|
|
278
279
|
ComponentCustomProps &
|
|
279
280
|
VNodeProps &
|
|
280
|
-
PrismicRichTextProps
|
|
281
|
-
}
|
|
282
|
-
}
|
|
281
|
+
PrismicRichTextProps
|
|
282
|
+
}
|
|
283
|
+
}
|