@prismicio/vue 4.2.3 → 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 +8 -3
- package/dist/components/PrismicLink.cjs.map +1 -1
- package/dist/components/PrismicLink.d.ts +14 -8
- package/dist/components/PrismicLink.js +8 -3
- 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 +38 -74
- 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 +6 -4
- package/dist/lib/getSlots.cjs.map +1 -1
- package/dist/lib/getSlots.d.ts +2 -2
- package/dist/lib/getSlots.js +6 -4
- 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 +28 -29
- package/src/components/PrismicEmbed.ts +16 -17
- package/src/components/PrismicImage.ts +57 -59
- package/src/components/PrismicLink.ts +78 -67
- 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 +17 -8
- 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,11 +1,11 @@
|
|
|
1
|
+
import type { ImageField } from "@prismicio/client"
|
|
1
2
|
import {
|
|
2
|
-
ImageField,
|
|
3
3
|
asImagePixelDensitySrcSet,
|
|
4
4
|
asImageSrc,
|
|
5
5
|
asImageWidthSrcSet,
|
|
6
6
|
isFilled,
|
|
7
|
-
} from "@prismicio/client"
|
|
8
|
-
import {
|
|
7
|
+
} from "@prismicio/client"
|
|
8
|
+
import type {
|
|
9
9
|
AllowedComponentProps,
|
|
10
10
|
ComponentCustomProps,
|
|
11
11
|
ComputedRef,
|
|
@@ -14,23 +14,20 @@ import {
|
|
|
14
14
|
PropType,
|
|
15
15
|
Raw,
|
|
16
16
|
VNodeProps,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
h,
|
|
20
|
-
unref,
|
|
21
|
-
} from "vue";
|
|
17
|
+
} from "vue"
|
|
18
|
+
import { computed, defineComponent, h, unref } from "vue"
|
|
22
19
|
|
|
23
|
-
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
|
|
24
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
20
|
+
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
|
|
21
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
25
22
|
|
|
26
|
-
import { VueUseOptions } from "../types"
|
|
23
|
+
import type { VueUseOptions } from "../types"
|
|
27
24
|
|
|
28
|
-
import { usePrismic } from "../usePrismic"
|
|
25
|
+
import { usePrismic } from "../usePrismic"
|
|
29
26
|
|
|
30
27
|
/**
|
|
31
28
|
* The default component rendered for images.
|
|
32
29
|
*/
|
|
33
|
-
const defaultImageComponent = "img"
|
|
30
|
+
const defaultImageComponent = "img"
|
|
34
31
|
|
|
35
32
|
/**
|
|
36
33
|
* Props for `<PrismicImage />`.
|
|
@@ -39,7 +36,7 @@ export type PrismicImageProps = {
|
|
|
39
36
|
/**
|
|
40
37
|
* The Prismic image field to render.
|
|
41
38
|
*/
|
|
42
|
-
field: ImageField | ImageField<string
|
|
39
|
+
field: ImageField | ImageField<string>
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
42
|
* An HTML tag name, a component, or a functional component used to render
|
|
@@ -49,16 +46,17 @@ export type PrismicImageProps = {
|
|
|
49
46
|
* HTML tag names and components will be rendered using the `img` tag
|
|
50
47
|
* interface (`src`, `srcset`, and `alt` attribute). Components will also
|
|
51
48
|
* receive an additional `copyright` props.
|
|
49
|
+
*
|
|
52
50
|
* @defaultValue The one provided to `@prismicio/vue` plugin if configured, `"img"` otherwise.
|
|
53
51
|
*/
|
|
54
|
-
imageComponent?: string | ConcreteComponent | Raw<DefineComponent
|
|
52
|
+
imageComponent?: string | ConcreteComponent | Raw<DefineComponent>
|
|
55
53
|
|
|
56
54
|
/**
|
|
57
55
|
* An object of Imgix URL API parameters.
|
|
58
56
|
*
|
|
59
57
|
* @see Imgix URL parameters reference: https://docs.imgix.com/apis/rendering
|
|
60
58
|
*/
|
|
61
|
-
imgixParams?: Parameters<typeof asImageSrc>[1]
|
|
59
|
+
imgixParams?: Parameters<typeof asImageSrc>[1]
|
|
62
60
|
|
|
63
61
|
/**
|
|
64
62
|
* Adds an additional `srcset` attribute to the image following given widths.
|
|
@@ -76,7 +74,7 @@ export type PrismicImageProps = {
|
|
|
76
74
|
widths?:
|
|
77
75
|
| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"]
|
|
78
76
|
| "thumbnails"
|
|
79
|
-
| "defaults"
|
|
77
|
+
| "defaults"
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
80
|
* Adds an additional `srcset` attribute to the image following giving pixel
|
|
@@ -93,15 +91,15 @@ export type PrismicImageProps = {
|
|
|
93
91
|
| NonNullable<
|
|
94
92
|
Parameters<typeof asImagePixelDensitySrcSet>[1]
|
|
95
93
|
>["pixelDensities"]
|
|
96
|
-
| "defaults"
|
|
97
|
-
}
|
|
94
|
+
| "defaults"
|
|
95
|
+
}
|
|
98
96
|
|
|
99
97
|
/**
|
|
100
98
|
* Options for {@link usePrismicImage}.
|
|
101
99
|
*/
|
|
102
100
|
export type UsePrismicImageOptions = VueUseOptions<
|
|
103
101
|
Omit<PrismicImageProps, "imageComponent">
|
|
104
|
-
|
|
102
|
+
>
|
|
105
103
|
|
|
106
104
|
/**
|
|
107
105
|
* Return type of {@link usePrismicImage}.
|
|
@@ -110,23 +108,23 @@ export type UsePrismicImageReturnType = {
|
|
|
110
108
|
/**
|
|
111
109
|
* Resolved image `src` value.
|
|
112
110
|
*/
|
|
113
|
-
src: ComputedRef<string | null
|
|
111
|
+
src: ComputedRef<string | null>
|
|
114
112
|
|
|
115
113
|
/**
|
|
116
114
|
* Resolved image `srcset` value.
|
|
117
115
|
*/
|
|
118
|
-
srcset: ComputedRef<string | null
|
|
116
|
+
srcset: ComputedRef<string | null>
|
|
119
117
|
|
|
120
118
|
/**
|
|
121
119
|
* Resolved image `alt` value.
|
|
122
120
|
*/
|
|
123
|
-
alt: ComputedRef<string
|
|
121
|
+
alt: ComputedRef<string>
|
|
124
122
|
|
|
125
123
|
/**
|
|
126
124
|
* Resolved image `copyright` value.
|
|
127
125
|
*/
|
|
128
|
-
copyright: ComputedRef<string | null
|
|
129
|
-
}
|
|
126
|
+
copyright: ComputedRef<string | null>
|
|
127
|
+
}
|
|
130
128
|
|
|
131
129
|
/**
|
|
132
130
|
* A low level composable that returns a resolved information about a Prismic
|
|
@@ -139,28 +137,28 @@ export type UsePrismicImageReturnType = {
|
|
|
139
137
|
export const usePrismicImage = (
|
|
140
138
|
props: UsePrismicImageOptions,
|
|
141
139
|
): UsePrismicImageReturnType => {
|
|
142
|
-
const { options } = usePrismic()
|
|
140
|
+
const { options } = usePrismic()
|
|
143
141
|
|
|
144
142
|
const asImage = computed(() => {
|
|
145
|
-
const field = unref(props.field)
|
|
143
|
+
const field = unref(props.field)
|
|
146
144
|
|
|
147
145
|
if (!isFilled.image(field)) {
|
|
148
146
|
return {
|
|
149
147
|
src: null,
|
|
150
148
|
srcset: null,
|
|
151
|
-
}
|
|
149
|
+
}
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
const imgixParams = unref(props.imgixParams)
|
|
155
|
-
const widths = unref(props.widths)
|
|
156
|
-
const pixelDensities = unref(props.pixelDensities)
|
|
152
|
+
const imgixParams = unref(props.imgixParams)
|
|
153
|
+
const widths = unref(props.widths)
|
|
154
|
+
const pixelDensities = unref(props.pixelDensities)
|
|
157
155
|
|
|
158
156
|
if (widths) {
|
|
159
157
|
if (!__PRODUCTION__ && pixelDensities) {
|
|
160
158
|
console.warn(
|
|
161
159
|
"[PrismicImage] Only one of `widths` or `pixelDensities` props can be provided. You can resolve this warning by removing either the `widths` or `pixelDensities` prop. `widths` will be used in this case.",
|
|
162
160
|
props,
|
|
163
|
-
)
|
|
161
|
+
)
|
|
164
162
|
}
|
|
165
163
|
|
|
166
164
|
return asImageWidthSrcSet(field, {
|
|
@@ -169,7 +167,7 @@ export const usePrismicImage = (
|
|
|
169
167
|
widths === "defaults"
|
|
170
168
|
? options.components?.imageWidthSrcSetDefaults
|
|
171
169
|
: widths,
|
|
172
|
-
})
|
|
170
|
+
})
|
|
173
171
|
} else if (pixelDensities) {
|
|
174
172
|
return asImagePixelDensitySrcSet(field, {
|
|
175
173
|
...imgixParams,
|
|
@@ -177,35 +175,35 @@ export const usePrismicImage = (
|
|
|
177
175
|
pixelDensities === "defaults"
|
|
178
176
|
? options.components?.imagePixelDensitySrcSetDefaults
|
|
179
177
|
: pixelDensities,
|
|
180
|
-
})
|
|
178
|
+
})
|
|
181
179
|
} else {
|
|
182
180
|
return {
|
|
183
181
|
src: asImageSrc(field, imgixParams),
|
|
184
182
|
srcset: null,
|
|
185
|
-
}
|
|
183
|
+
}
|
|
186
184
|
}
|
|
187
|
-
})
|
|
185
|
+
})
|
|
188
186
|
|
|
189
187
|
const src = computed(() => {
|
|
190
|
-
return asImage.value.src
|
|
191
|
-
})
|
|
188
|
+
return asImage.value.src
|
|
189
|
+
})
|
|
192
190
|
const srcset = computed(() => {
|
|
193
|
-
return asImage.value.srcset
|
|
194
|
-
})
|
|
191
|
+
return asImage.value.srcset
|
|
192
|
+
})
|
|
195
193
|
const alt = computed(() => {
|
|
196
|
-
return unref(props.field).alt || ""
|
|
197
|
-
})
|
|
194
|
+
return unref(props.field).alt || ""
|
|
195
|
+
})
|
|
198
196
|
const copyright = computed(() => {
|
|
199
|
-
return unref(props.field).copyright || null
|
|
200
|
-
})
|
|
197
|
+
return unref(props.field).copyright || null
|
|
198
|
+
})
|
|
201
199
|
|
|
202
200
|
return {
|
|
203
201
|
src,
|
|
204
202
|
srcset,
|
|
205
203
|
alt,
|
|
206
204
|
copyright,
|
|
207
|
-
}
|
|
208
|
-
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
209
207
|
|
|
210
208
|
/**
|
|
211
209
|
* `<PrismicImage />` implementation.
|
|
@@ -254,42 +252,42 @@ export const PrismicImageImpl = /*#__PURE__*/ defineComponent({
|
|
|
254
252
|
setup(props) {
|
|
255
253
|
// Prevent fatal if user didn't check for field, throws `Invalid prop` warn
|
|
256
254
|
if (!props.field) {
|
|
257
|
-
return () => null
|
|
255
|
+
return () => null
|
|
258
256
|
}
|
|
259
257
|
|
|
260
|
-
const { options } = usePrismic()
|
|
258
|
+
const { options } = usePrismic()
|
|
261
259
|
|
|
262
260
|
const type = computed(() => {
|
|
263
261
|
return (
|
|
264
262
|
props.imageComponent ||
|
|
265
263
|
options.components?.imageComponent ||
|
|
266
264
|
defaultImageComponent
|
|
267
|
-
)
|
|
268
|
-
})
|
|
265
|
+
)
|
|
266
|
+
})
|
|
269
267
|
|
|
270
|
-
const { src, srcset, alt, copyright } = usePrismicImage(props)
|
|
268
|
+
const { src, srcset, alt, copyright } = usePrismicImage(props)
|
|
271
269
|
|
|
272
270
|
return () => {
|
|
273
271
|
const attributes = {
|
|
274
272
|
src: src.value,
|
|
275
273
|
srcset: srcset.value,
|
|
276
274
|
alt: alt.value,
|
|
277
|
-
}
|
|
275
|
+
}
|
|
278
276
|
|
|
279
277
|
switch (type.value) {
|
|
280
278
|
case "img":
|
|
281
279
|
// Fitting img tag interface
|
|
282
|
-
return h("img", attributes)
|
|
280
|
+
return h("img", attributes)
|
|
283
281
|
|
|
284
282
|
default:
|
|
285
283
|
return h(simplyResolveComponent(type.value), {
|
|
286
284
|
...attributes,
|
|
287
285
|
copyright: copyright.value,
|
|
288
|
-
})
|
|
286
|
+
})
|
|
289
287
|
}
|
|
290
|
-
}
|
|
288
|
+
}
|
|
291
289
|
},
|
|
292
|
-
})
|
|
290
|
+
})
|
|
293
291
|
|
|
294
292
|
// export the public type for h/tsx inference
|
|
295
293
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -304,6 +302,6 @@ export const PrismicImage = PrismicImageImpl as unknown as {
|
|
|
304
302
|
$props: AllowedComponentProps &
|
|
305
303
|
ComponentCustomProps &
|
|
306
304
|
VNodeProps &
|
|
307
|
-
PrismicImageProps
|
|
308
|
-
}
|
|
309
|
-
}
|
|
305
|
+
PrismicImageProps
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -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,23 +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
|
|
140
|
-
|
|
137
|
+
rel: ComputedRef<string | null>
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Resolved link text.
|
|
141
|
+
*/
|
|
142
|
+
text: ComputedRef<string | undefined>
|
|
143
|
+
}
|
|
141
144
|
|
|
142
145
|
/**
|
|
143
146
|
* A low level composable that returns resolved information about a Prismic link
|
|
@@ -150,67 +153,74 @@ export type UsePrismicLinkReturnType = {
|
|
|
150
153
|
export const usePrismicLink = (
|
|
151
154
|
props: UsePrismicLinkOptions,
|
|
152
155
|
): UsePrismicLinkReturnType => {
|
|
153
|
-
const { options } = usePrismic()
|
|
156
|
+
const { options } = usePrismic()
|
|
154
157
|
|
|
155
158
|
const type = computed(() => {
|
|
156
159
|
const internalComponent =
|
|
157
160
|
unref(props.internalComponent) ||
|
|
158
161
|
options.components?.linkInternalComponent ||
|
|
159
|
-
defaultInternalComponent
|
|
162
|
+
defaultInternalComponent
|
|
160
163
|
|
|
161
164
|
const externalComponent =
|
|
162
165
|
unref(props.externalComponent) ||
|
|
163
166
|
options.components?.linkExternalComponent ||
|
|
164
|
-
defaultExternalComponent
|
|
167
|
+
defaultExternalComponent
|
|
165
168
|
|
|
166
169
|
return href.value && isInternalURL(href.value) && !target.value
|
|
167
170
|
? internalComponent
|
|
168
|
-
: externalComponent
|
|
169
|
-
})
|
|
171
|
+
: externalComponent
|
|
172
|
+
})
|
|
170
173
|
const href = computed(() => {
|
|
171
|
-
const field = unref(props.field)
|
|
172
|
-
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
174
|
+
const field = unref(props.field)
|
|
175
|
+
const linkResolver = unref(props.linkResolver) ?? options.linkResolver
|
|
173
176
|
|
|
174
|
-
return asLink(field, linkResolver) ?? ""
|
|
175
|
-
})
|
|
177
|
+
return asLink(field, linkResolver) ?? ""
|
|
178
|
+
})
|
|
176
179
|
const target = computed(() => {
|
|
177
|
-
const field = unref(props.field)
|
|
178
|
-
const target = unref(props.target)
|
|
180
|
+
const field = unref(props.field)
|
|
181
|
+
const target = unref(props.target)
|
|
179
182
|
|
|
180
183
|
if (typeof target !== "undefined") {
|
|
181
|
-
return target
|
|
184
|
+
return target
|
|
182
185
|
} else {
|
|
183
|
-
return field && "target" in field && field.target ? field.target : null
|
|
186
|
+
return field && "target" in field && field.target ? field.target : null
|
|
184
187
|
}
|
|
185
|
-
})
|
|
188
|
+
})
|
|
186
189
|
const rel = computed(() => {
|
|
187
|
-
const rel = unref(props.rel)
|
|
190
|
+
const rel = unref(props.rel)
|
|
188
191
|
|
|
189
192
|
if (typeof rel !== "undefined") {
|
|
190
|
-
return rel
|
|
193
|
+
return rel
|
|
191
194
|
} else if (target.value === "_blank") {
|
|
192
|
-
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute)
|
|
195
|
+
const blankTargetRelAttribute = unref(props.blankTargetRelAttribute)
|
|
193
196
|
|
|
194
197
|
if (typeof blankTargetRelAttribute !== "undefined") {
|
|
195
|
-
return blankTargetRelAttribute
|
|
198
|
+
return blankTargetRelAttribute
|
|
196
199
|
} else {
|
|
197
200
|
return typeof options.components?.linkBlankTargetRelAttribute !==
|
|
198
201
|
"undefined"
|
|
199
202
|
? options.components.linkBlankTargetRelAttribute
|
|
200
|
-
: defaultBlankTargetRelAttribute
|
|
203
|
+
: defaultBlankTargetRelAttribute
|
|
201
204
|
}
|
|
202
205
|
} else {
|
|
203
|
-
return null
|
|
206
|
+
return null
|
|
204
207
|
}
|
|
205
|
-
})
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
const text = computed(() => {
|
|
211
|
+
const field = unref(props.field)
|
|
212
|
+
|
|
213
|
+
return field && "text" in field ? field.text : undefined
|
|
214
|
+
})
|
|
206
215
|
|
|
207
216
|
return {
|
|
208
217
|
type,
|
|
209
218
|
href,
|
|
210
219
|
target,
|
|
211
220
|
rel,
|
|
212
|
-
|
|
213
|
-
}
|
|
221
|
+
text,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
214
224
|
|
|
215
225
|
/**
|
|
216
226
|
* `<PrismicLink />` implementation.
|
|
@@ -262,19 +272,20 @@ export const PrismicLinkImpl = /*#__PURE__*/ defineComponent({
|
|
|
262
272
|
setup(props, { slots }) {
|
|
263
273
|
// Prevent fatal if user didn't check for field, throws `Invalid prop` warn
|
|
264
274
|
if (!props.field) {
|
|
265
|
-
return () => null
|
|
275
|
+
return () => null
|
|
266
276
|
}
|
|
267
277
|
|
|
268
|
-
const { type, href, target, rel } = usePrismicLink(props)
|
|
278
|
+
const { type, href, target, rel, text } = usePrismicLink(props)
|
|
269
279
|
|
|
270
280
|
return () => {
|
|
271
281
|
const parent =
|
|
272
|
-
type.value === "a" ? "a" : simplyResolveComponent(type.value)
|
|
282
|
+
type.value === "a" ? "a" : simplyResolveComponent(type.value)
|
|
273
283
|
const computedSlots = getSlots(
|
|
274
284
|
parent,
|
|
275
285
|
slots,
|
|
276
|
-
reactive({ href: href.value }),
|
|
277
|
-
|
|
286
|
+
reactive({ href: href.value, text: text.value }),
|
|
287
|
+
text.value,
|
|
288
|
+
)
|
|
278
289
|
|
|
279
290
|
if (typeof parent === "string") {
|
|
280
291
|
// Fitting anchor tag interface
|
|
@@ -282,18 +293,18 @@ export const PrismicLinkImpl = /*#__PURE__*/ defineComponent({
|
|
|
282
293
|
parent,
|
|
283
294
|
{ href: href.value, target: target.value, rel: rel.value },
|
|
284
295
|
computedSlots,
|
|
285
|
-
)
|
|
296
|
+
)
|
|
286
297
|
} else {
|
|
287
298
|
// Fitting Vue Router Link interface
|
|
288
299
|
return h(
|
|
289
300
|
parent,
|
|
290
301
|
{ to: href.value, target: target.value, rel: rel.value },
|
|
291
302
|
computedSlots,
|
|
292
|
-
)
|
|
303
|
+
)
|
|
293
304
|
}
|
|
294
|
-
}
|
|
305
|
+
}
|
|
295
306
|
},
|
|
296
|
-
})
|
|
307
|
+
})
|
|
297
308
|
|
|
298
309
|
// export the public type for h/tsx inference
|
|
299
310
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -308,6 +319,6 @@ export const PrismicLink = PrismicLinkImpl as unknown as {
|
|
|
308
319
|
$props: AllowedComponentProps &
|
|
309
320
|
ComponentCustomProps &
|
|
310
321
|
VNodeProps &
|
|
311
|
-
PrismicLinkProps
|
|
312
|
-
}
|
|
313
|
-
}
|
|
322
|
+
PrismicLinkProps
|
|
323
|
+
}
|
|
324
|
+
}
|