@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,5 +1,6 @@
|
|
|
1
|
-
import { RichTextField
|
|
2
|
-
import {
|
|
1
|
+
import type { RichTextField } from "@prismicio/client"
|
|
2
|
+
import { asText, isFilled } from "@prismicio/client"
|
|
3
|
+
import type {
|
|
3
4
|
AllowedComponentProps,
|
|
4
5
|
ComponentCustomProps,
|
|
5
6
|
ComputedRef,
|
|
@@ -9,20 +10,17 @@ import {
|
|
|
9
10
|
Raw,
|
|
10
11
|
VNode,
|
|
11
12
|
VNodeProps,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
h,
|
|
15
|
-
unref,
|
|
16
|
-
} from "vue";
|
|
13
|
+
} from "vue"
|
|
14
|
+
import { computed, defineComponent, h, unref } from "vue"
|
|
17
15
|
|
|
18
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
16
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
19
17
|
|
|
20
|
-
import { VueUseOptions } from "../types"
|
|
18
|
+
import type { VueUseOptions } from "../types"
|
|
21
19
|
|
|
22
20
|
/**
|
|
23
21
|
* The default component rendered to wrap the text output.
|
|
24
22
|
*/
|
|
25
|
-
const defaultWrapper = "div"
|
|
23
|
+
const defaultWrapper = "div"
|
|
26
24
|
/**
|
|
27
25
|
* Props for `<PrismicText />`.
|
|
28
26
|
*/
|
|
@@ -30,14 +28,14 @@ export type PrismicTextProps = {
|
|
|
30
28
|
/**
|
|
31
29
|
* The Prismic rich text or title field to render.
|
|
32
30
|
*/
|
|
33
|
-
field: RichTextField | null | undefined
|
|
31
|
+
field: RichTextField | null | undefined
|
|
34
32
|
|
|
35
33
|
/**
|
|
36
34
|
* Separator used to join each element.
|
|
37
35
|
*
|
|
38
36
|
* @defaultValue `" "` (a space)
|
|
39
37
|
*/
|
|
40
|
-
separator?: string
|
|
38
|
+
separator?: string
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
41
|
* An HTML tag name, a component, or a functional component used to wrap the
|
|
@@ -45,21 +43,21 @@ export type PrismicTextProps = {
|
|
|
45
43
|
*
|
|
46
44
|
* @defaultValue `"div"`
|
|
47
45
|
*/
|
|
48
|
-
wrapper?: string | ConcreteComponent | Raw<DefineComponent
|
|
46
|
+
wrapper?: string | ConcreteComponent | Raw<DefineComponent>
|
|
49
47
|
|
|
50
48
|
/**
|
|
51
49
|
* The string value to be rendered when the field is empty. If a fallback is
|
|
52
50
|
* not given, `""` (nothing) will be rendered.
|
|
53
51
|
*/
|
|
54
|
-
fallback?: string
|
|
55
|
-
}
|
|
52
|
+
fallback?: string
|
|
53
|
+
}
|
|
56
54
|
|
|
57
55
|
/**
|
|
58
56
|
* Options for {@link usePrismicText}.
|
|
59
57
|
*/
|
|
60
58
|
export type UsePrismicTextOptions = VueUseOptions<
|
|
61
59
|
Omit<PrismicTextProps, "wrapper">
|
|
62
|
-
|
|
60
|
+
>
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Return type of {@link usePrismicText}.
|
|
@@ -68,8 +66,8 @@ export type UsePrismicTextReturnType = {
|
|
|
68
66
|
/**
|
|
69
67
|
* Serialized rich text field as plain text.
|
|
70
68
|
*/
|
|
71
|
-
text: ComputedRef<string
|
|
72
|
-
}
|
|
69
|
+
text: ComputedRef<string>
|
|
70
|
+
}
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
73
|
* A low level composable that returns a serialized rich text field as plain
|
|
@@ -84,19 +82,19 @@ export const usePrismicText = (
|
|
|
84
82
|
props: UsePrismicTextOptions,
|
|
85
83
|
): UsePrismicTextReturnType => {
|
|
86
84
|
const text = computed(() => {
|
|
87
|
-
const field = unref(props.field)
|
|
85
|
+
const field = unref(props.field)
|
|
88
86
|
|
|
89
87
|
if (!isFilled.richText(field)) {
|
|
90
|
-
return unref(props.fallback) ?? ""
|
|
88
|
+
return unref(props.fallback) ?? ""
|
|
91
89
|
}
|
|
92
90
|
|
|
93
|
-
return asText(unref(field), unref(props.separator))
|
|
94
|
-
})
|
|
91
|
+
return asText(unref(field), unref(props.separator))
|
|
92
|
+
})
|
|
95
93
|
|
|
96
94
|
return {
|
|
97
95
|
text,
|
|
98
|
-
}
|
|
99
|
-
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
100
98
|
|
|
101
99
|
/**
|
|
102
100
|
* `<PrismicText />` implementation.
|
|
@@ -130,10 +128,10 @@ export const PrismicTextImpl = /*#__PURE__*/ defineComponent({
|
|
|
130
128
|
},
|
|
131
129
|
},
|
|
132
130
|
setup(props) {
|
|
133
|
-
const { text } = usePrismicText(props)
|
|
131
|
+
const { text } = usePrismicText(props)
|
|
134
132
|
|
|
135
133
|
return () => {
|
|
136
|
-
const parent = simplyResolveComponent(props.wrapper || defaultWrapper)
|
|
134
|
+
const parent = simplyResolveComponent(props.wrapper || defaultWrapper)
|
|
137
135
|
|
|
138
136
|
// This works but is absurd
|
|
139
137
|
// if (typeof parent === "string") {
|
|
@@ -144,10 +142,10 @@ export const PrismicTextImpl = /*#__PURE__*/ defineComponent({
|
|
|
144
142
|
|
|
145
143
|
return h(parent as VNode, null, {
|
|
146
144
|
default: () => text.value,
|
|
147
|
-
})
|
|
148
|
-
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
149
147
|
},
|
|
150
|
-
})
|
|
148
|
+
})
|
|
151
149
|
|
|
152
150
|
// export the public type for h/tsx inference
|
|
153
151
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -162,6 +160,6 @@ export const PrismicText = PrismicTextImpl as unknown as {
|
|
|
162
160
|
$props: AllowedComponentProps &
|
|
163
161
|
ComponentCustomProps &
|
|
164
162
|
VNodeProps &
|
|
165
|
-
PrismicTextProps
|
|
166
|
-
}
|
|
167
|
-
}
|
|
163
|
+
PrismicTextProps
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Slice } from "@prismicio/client"
|
|
2
|
-
import {
|
|
1
|
+
import type { Slice } from "@prismicio/client"
|
|
2
|
+
import type {
|
|
3
3
|
AllowedComponentProps,
|
|
4
4
|
ComponentCustomProps,
|
|
5
5
|
ConcreteComponent,
|
|
@@ -8,18 +8,14 @@ import {
|
|
|
8
8
|
PropType,
|
|
9
9
|
Raw,
|
|
10
10
|
VNodeProps,
|
|
11
|
-
computed,
|
|
12
11
|
defineAsyncComponent,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
markRaw,
|
|
16
|
-
watchEffect,
|
|
17
|
-
} from "vue";
|
|
12
|
+
} from "vue"
|
|
13
|
+
import { computed, defineComponent, h, markRaw, watchEffect } from "vue"
|
|
18
14
|
|
|
19
|
-
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
|
|
20
|
-
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
15
|
+
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
|
|
16
|
+
import { simplyResolveComponent } from "../lib/simplyResolveComponent"
|
|
21
17
|
|
|
22
|
-
import { usePrismic } from "../usePrismic"
|
|
18
|
+
import { usePrismic } from "../usePrismic"
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* Returns the type of a `SliceLike` type.
|
|
@@ -29,8 +25,8 @@ import { usePrismic } from "../usePrismic";
|
|
|
29
25
|
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends SliceLikeRestV2
|
|
30
26
|
? TSlice["slice_type"]
|
|
31
27
|
: TSlice extends SliceLikeGraphQL
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
? TSlice["type"]
|
|
29
|
+
: never
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
@@ -44,7 +40,7 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends SliceLikeRestV2
|
|
|
44
40
|
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
45
41
|
Slice<TSliceType>,
|
|
46
42
|
"id" | "slice_type"
|
|
47
|
-
|
|
43
|
+
>
|
|
48
44
|
|
|
49
45
|
/**
|
|
50
46
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
@@ -53,8 +49,8 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
|
53
49
|
* @typeParam TSliceType - Type name of the Slice.
|
|
54
50
|
*/
|
|
55
51
|
export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
56
|
-
type: Slice<TSliceType>["slice_type"]
|
|
57
|
-
}
|
|
52
|
+
type: Slice<TSliceType>["slice_type"]
|
|
53
|
+
}
|
|
58
54
|
|
|
59
55
|
/**
|
|
60
56
|
* The minimum required properties to represent a Prismic Slice for the
|
|
@@ -75,8 +71,8 @@ export type SliceLike<TSliceType extends string = string> = (
|
|
|
75
71
|
*
|
|
76
72
|
* @internal
|
|
77
73
|
*/
|
|
78
|
-
__mapped?: true
|
|
79
|
-
}
|
|
74
|
+
__mapped?: true
|
|
75
|
+
}
|
|
80
76
|
|
|
81
77
|
/**
|
|
82
78
|
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
@@ -88,7 +84,7 @@ export type SliceLike<TSliceType extends string = string> = (
|
|
|
88
84
|
* @typeParam TSlice - The type(s) of slices in the Slice Zone
|
|
89
85
|
*/
|
|
90
86
|
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
|
|
91
|
-
readonly TSlice[]
|
|
87
|
+
readonly TSlice[]
|
|
92
88
|
|
|
93
89
|
/**
|
|
94
90
|
* Vue props for a component rendering content from a Prismic Slice using the
|
|
@@ -105,12 +101,12 @@ export type SliceComponentProps<
|
|
|
105
101
|
/**
|
|
106
102
|
* Slice data for this component.
|
|
107
103
|
*/
|
|
108
|
-
slice: TSlice
|
|
104
|
+
slice: TSlice
|
|
109
105
|
|
|
110
106
|
/**
|
|
111
107
|
* The index of the Slice in the Slice Zone.
|
|
112
108
|
*/
|
|
113
|
-
index: number
|
|
109
|
+
index: number
|
|
114
110
|
|
|
115
111
|
/**
|
|
116
112
|
* All Slices from the Slice Zone to which the Slice belongs.
|
|
@@ -121,14 +117,14 @@ export type SliceComponentProps<
|
|
|
121
117
|
// throw a compilation error.
|
|
122
118
|
slices: SliceZoneLike<
|
|
123
119
|
TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
|
|
124
|
-
|
|
120
|
+
>
|
|
125
121
|
|
|
126
122
|
/**
|
|
127
123
|
* Arbitrary data passed to `<SliceZone />` and made available to all Slice
|
|
128
124
|
* components.
|
|
129
125
|
*/
|
|
130
|
-
context: TContext
|
|
131
|
-
}
|
|
126
|
+
context: TContext
|
|
127
|
+
}
|
|
132
128
|
|
|
133
129
|
/**
|
|
134
130
|
* Native Vue props for a component rendering content from a Prismic Slice using
|
|
@@ -144,22 +140,22 @@ export type DefineComponentSliceComponentProps<
|
|
|
144
140
|
TContext = unknown,
|
|
145
141
|
> = {
|
|
146
142
|
slice: {
|
|
147
|
-
type: PropType<SliceComponentProps<TSlice, TContext>["slice"]
|
|
148
|
-
required: true
|
|
149
|
-
}
|
|
143
|
+
type: PropType<SliceComponentProps<TSlice, TContext>["slice"]>
|
|
144
|
+
required: true
|
|
145
|
+
}
|
|
150
146
|
index: {
|
|
151
|
-
type: PropType<SliceComponentProps<TSlice, TContext>["index"]
|
|
152
|
-
required: true
|
|
153
|
-
}
|
|
147
|
+
type: PropType<SliceComponentProps<TSlice, TContext>["index"]>
|
|
148
|
+
required: true
|
|
149
|
+
}
|
|
154
150
|
slices: {
|
|
155
|
-
type: PropType<SliceComponentProps<TSlice, TContext>["slices"]
|
|
156
|
-
required: true
|
|
157
|
-
}
|
|
151
|
+
type: PropType<SliceComponentProps<TSlice, TContext>["slices"]>
|
|
152
|
+
required: true
|
|
153
|
+
}
|
|
158
154
|
context: {
|
|
159
|
-
type: PropType<SliceComponentProps<TSlice, TContext>["context"]
|
|
160
|
-
required: true
|
|
161
|
-
}
|
|
162
|
-
}
|
|
155
|
+
type: PropType<SliceComponentProps<TSlice, TContext>["context"]>
|
|
156
|
+
required: true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
163
159
|
|
|
164
160
|
/**
|
|
165
161
|
* Gets native Vue props for a component rendering content from a Prismic Slice
|
|
@@ -171,27 +167,28 @@ export type DefineComponentSliceComponentProps<
|
|
|
171
167
|
*
|
|
172
168
|
* ```javascript
|
|
173
169
|
* // Defining a new slice component
|
|
174
|
-
* import { getSliceComponentProps } from "@prismicio/vue"
|
|
170
|
+
* import { getSliceComponentProps } from "@prismicio/vue"
|
|
175
171
|
*
|
|
176
172
|
* export default {
|
|
177
173
|
* props: getSliceComponentProps(),
|
|
178
|
-
* }
|
|
174
|
+
* }
|
|
179
175
|
* ```
|
|
180
176
|
*
|
|
181
177
|
* @example
|
|
182
178
|
*
|
|
183
179
|
* ```javascript
|
|
184
180
|
* // Defining a new slice component with visual hint
|
|
185
|
-
* import { getSliceComponentProps } from "@prismicio/vue"
|
|
181
|
+
* import { getSliceComponentProps } from "@prismicio/vue"
|
|
186
182
|
*
|
|
187
183
|
* export default {
|
|
188
184
|
* props: getSliceComponentProps(["slice", "index", "slices", "context"]),
|
|
189
|
-
* }
|
|
185
|
+
* }
|
|
190
186
|
* ```
|
|
191
187
|
*
|
|
192
188
|
* @typeParam TSlice - The Slice type
|
|
193
189
|
* @typeParam TContext - Arbitrary data passed to `<SliceZone />` and made
|
|
194
190
|
* available to all Slice components
|
|
191
|
+
*
|
|
195
192
|
* @param propsHint - An optional array of prop names used for the sole purpose
|
|
196
193
|
* of having a visual hint of which props are made available to the slice,
|
|
197
194
|
* this parameters doesn't have any effect
|
|
@@ -224,7 +221,7 @@ export const getSliceComponentProps = <
|
|
|
224
221
|
>,
|
|
225
222
|
required: true,
|
|
226
223
|
},
|
|
227
|
-
})
|
|
224
|
+
})
|
|
228
225
|
|
|
229
226
|
/**
|
|
230
227
|
* A Vue component to be rendered for each instance of its Slice.
|
|
@@ -238,12 +235,12 @@ export type SliceComponentType<
|
|
|
238
235
|
TContext = unknown,
|
|
239
236
|
> =
|
|
240
237
|
// For reference within TypeScript files when `*.vue` type cannot be inferred
|
|
241
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type, @typescript-eslint/no-explicit-any
|
|
242
239
|
| DefineComponent<{}, {}, any>
|
|
243
240
|
// Likewise, for reference with TypeScript files.
|
|
244
241
|
| ReturnType<typeof defineAsyncComponent>
|
|
245
242
|
| DefineComponent<SliceComponentProps<TSlice, TContext>>
|
|
246
|
-
| FunctionalComponent<SliceComponentProps<TSlice, TContext
|
|
243
|
+
| FunctionalComponent<SliceComponentProps<TSlice, TContext>>
|
|
247
244
|
|
|
248
245
|
/**
|
|
249
246
|
* This Slice component can be used as a reminder to provide a proper
|
|
@@ -254,8 +251,8 @@ export type SliceComponentType<
|
|
|
254
251
|
*/
|
|
255
252
|
export const TODOSliceComponent = __PRODUCTION__
|
|
256
253
|
? ((() => null) as FunctionalComponent<{
|
|
257
|
-
slice: SliceLike
|
|
258
|
-
|
|
254
|
+
slice: SliceLike
|
|
255
|
+
}>)
|
|
259
256
|
: /*#__PURE__*/ (defineComponent({
|
|
260
257
|
name: "TODOSliceComponent",
|
|
261
258
|
props: {
|
|
@@ -268,15 +265,15 @@ export const TODOSliceComponent = __PRODUCTION__
|
|
|
268
265
|
const type = computed(() => {
|
|
269
266
|
return "slice_type" in props.slice
|
|
270
267
|
? props.slice.slice_type
|
|
271
|
-
: props.slice.type
|
|
272
|
-
})
|
|
268
|
+
: props.slice.type
|
|
269
|
+
})
|
|
273
270
|
|
|
274
271
|
watchEffect(() => {
|
|
275
272
|
console.warn(
|
|
276
273
|
`[SliceZone] Could not find a component for Slice type "${type.value}"`,
|
|
277
274
|
props.slice,
|
|
278
|
-
)
|
|
279
|
-
})
|
|
275
|
+
)
|
|
276
|
+
})
|
|
280
277
|
|
|
281
278
|
return () => {
|
|
282
279
|
return h(
|
|
@@ -286,10 +283,10 @@ export const TODOSliceComponent = __PRODUCTION__
|
|
|
286
283
|
"data-slice-type": type.value,
|
|
287
284
|
},
|
|
288
285
|
[`Could not find a component for Slice type "${type.value}"`],
|
|
289
|
-
)
|
|
290
|
-
}
|
|
286
|
+
)
|
|
287
|
+
}
|
|
291
288
|
},
|
|
292
|
-
|
|
289
|
+
}) as SliceComponentType)
|
|
293
290
|
|
|
294
291
|
/**
|
|
295
292
|
* A record of Slice types mapped to Vue components. Each components will be
|
|
@@ -314,8 +311,8 @@ export type SliceZoneComponents<
|
|
|
314
311
|
{
|
|
315
312
|
[SliceType in ExtractSliceType<TSlice>]:
|
|
316
313
|
| SliceComponentType<Extract<TSlice, SliceLike<SliceType>>, TContext>
|
|
317
|
-
| string
|
|
318
|
-
}
|
|
314
|
+
| string
|
|
315
|
+
}
|
|
319
316
|
|
|
320
317
|
/**
|
|
321
318
|
* Gets an optimized record of Slice types mapped to Vue components. Each
|
|
@@ -324,6 +321,7 @@ export type SliceZoneComponents<
|
|
|
324
321
|
* @remarks
|
|
325
322
|
* This is essentially an helper function to ensure {@link markRaw} is correctly
|
|
326
323
|
* applied on each components, improving performances.
|
|
324
|
+
*
|
|
327
325
|
* @example
|
|
328
326
|
*
|
|
329
327
|
* ```javascript
|
|
@@ -357,11 +355,11 @@ export const defineSliceZoneComponents = <
|
|
|
357
355
|
>(
|
|
358
356
|
components: SliceZoneComponents<TSlice, TContext>,
|
|
359
357
|
): SliceZoneComponents<TSlice, TContext> => {
|
|
360
|
-
const result = {} as SliceZoneComponents<TSlice, TContext
|
|
358
|
+
const result = {} as SliceZoneComponents<TSlice, TContext>
|
|
361
359
|
|
|
362
|
-
let type: keyof typeof components
|
|
360
|
+
let type: keyof typeof components
|
|
363
361
|
for (type in components) {
|
|
364
|
-
const component = components[type]
|
|
362
|
+
const component = components[type]
|
|
365
363
|
result[type] =
|
|
366
364
|
typeof component === "string"
|
|
367
365
|
? component
|
|
@@ -370,11 +368,11 @@ export const defineSliceZoneComponents = <
|
|
|
370
368
|
Extract<TSlice, SliceLike<typeof type>>,
|
|
371
369
|
TContext
|
|
372
370
|
>,
|
|
373
|
-
|
|
371
|
+
)
|
|
374
372
|
}
|
|
375
373
|
|
|
376
|
-
return result
|
|
377
|
-
}
|
|
374
|
+
return result
|
|
375
|
+
}
|
|
378
376
|
|
|
379
377
|
/**
|
|
380
378
|
* Arguments for a `<SliceZone>` `resolver` function.
|
|
@@ -383,18 +381,18 @@ export type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
|
|
|
383
381
|
/**
|
|
384
382
|
* The Slice to resolve to a Vue component..
|
|
385
383
|
*/
|
|
386
|
-
slice: TSlice
|
|
384
|
+
slice: TSlice
|
|
387
385
|
|
|
388
386
|
/**
|
|
389
387
|
* The name of the Slice.
|
|
390
388
|
*/
|
|
391
|
-
sliceName: ExtractSliceType<TSlice
|
|
389
|
+
sliceName: ExtractSliceType<TSlice>
|
|
392
390
|
|
|
393
391
|
/**
|
|
394
392
|
* The index of the Slice in the Slice Zone.
|
|
395
393
|
*/
|
|
396
|
-
i: number
|
|
397
|
-
}
|
|
394
|
+
i: number
|
|
395
|
+
}
|
|
398
396
|
|
|
399
397
|
/**
|
|
400
398
|
* A function that determines the rendered Vue component for each Slice in the
|
|
@@ -415,7 +413,7 @@ export type SliceZoneResolver<
|
|
|
415
413
|
> = (
|
|
416
414
|
args: SliceZoneResolverArgs<TSlice>,
|
|
417
415
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
418
|
-
) => SliceComponentType<any, TContext> | string | undefined | null
|
|
416
|
+
) => SliceComponentType<any, TContext> | string | undefined | null
|
|
419
417
|
|
|
420
418
|
/**
|
|
421
419
|
* Props for `<SliceZone />`.
|
|
@@ -426,12 +424,12 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
426
424
|
/**
|
|
427
425
|
* List of Slice data from the Slice Zone.
|
|
428
426
|
*/
|
|
429
|
-
slices: SliceZoneLike
|
|
427
|
+
slices: SliceZoneLike
|
|
430
428
|
|
|
431
429
|
/**
|
|
432
430
|
* A record mapping Slice types to Vue components.
|
|
433
431
|
*/
|
|
434
|
-
components?: SliceZoneComponents
|
|
432
|
+
components?: SliceZoneComponents
|
|
435
433
|
|
|
436
434
|
/**
|
|
437
435
|
* A function that determines the rendered Vue component for each Slice in the
|
|
@@ -445,12 +443,12 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
445
443
|
*/
|
|
446
444
|
// TODO: Remove in v5 when the `resolver` prop is removed.
|
|
447
445
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
448
|
-
resolver?: SliceZoneResolver<any, TContext
|
|
446
|
+
resolver?: SliceZoneResolver<any, TContext>
|
|
449
447
|
|
|
450
448
|
/**
|
|
451
449
|
* Arbitrary data made available to all Slice components.
|
|
452
450
|
*/
|
|
453
|
-
context?: TContext
|
|
451
|
+
context?: TContext
|
|
454
452
|
|
|
455
453
|
/**
|
|
456
454
|
* A component or a functional component rendered if a component mapping from
|
|
@@ -462,14 +460,14 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
462
460
|
* @defaultValue The Slice Zone default component provided to `@prismicio/vue` plugin if configured, otherwise `null` when `process.env.NODE_ENV === "production"` else {@link TODOSliceComponent}.
|
|
463
461
|
*/
|
|
464
462
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
465
|
-
defaultComponent?: SliceComponentType<any, TContext
|
|
463
|
+
defaultComponent?: SliceComponentType<any, TContext>
|
|
466
464
|
|
|
467
465
|
/**
|
|
468
466
|
* An HTML tag name, a component, or a functional component used to wrap the
|
|
469
467
|
* output. The Slice Zone is not wrapped by default.
|
|
470
468
|
*/
|
|
471
|
-
wrapper?: string | ConcreteComponent | Raw<DefineComponent
|
|
472
|
-
}
|
|
469
|
+
wrapper?: string | ConcreteComponent | Raw<DefineComponent>
|
|
470
|
+
}
|
|
473
471
|
|
|
474
472
|
/**
|
|
475
473
|
* `<SliceZone />` implementation.
|
|
@@ -516,7 +514,7 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
516
514
|
setup(props) {
|
|
517
515
|
// Prevent fatal if user didn't check for field, throws `Invalid prop` warn
|
|
518
516
|
if (!props.slices) {
|
|
519
|
-
return () => null
|
|
517
|
+
return () => null
|
|
520
518
|
}
|
|
521
519
|
|
|
522
520
|
// TODO: Remove in v3 when the `resolver` prop is removed.
|
|
@@ -524,22 +522,22 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
524
522
|
if (props.resolver) {
|
|
525
523
|
console.warn(
|
|
526
524
|
"The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.",
|
|
527
|
-
)
|
|
525
|
+
)
|
|
528
526
|
}
|
|
529
527
|
}
|
|
530
528
|
|
|
531
|
-
const { options } = usePrismic()
|
|
529
|
+
const { options } = usePrismic()
|
|
532
530
|
|
|
533
531
|
const renderedSlices = computed(() => {
|
|
534
532
|
return props.slices.map((slice, index) => {
|
|
535
533
|
const type =
|
|
536
|
-
"slice_type" in slice ? (slice.slice_type as string) : slice.type
|
|
534
|
+
"slice_type" in slice ? (slice.slice_type as string) : slice.type
|
|
537
535
|
|
|
538
536
|
let component =
|
|
539
537
|
props.components && type in props.components
|
|
540
538
|
? props.components[type]
|
|
541
539
|
: props.defaultComponent ||
|
|
542
|
-
|
|
540
|
+
options.components?.sliceZoneDefaultComponent
|
|
543
541
|
|
|
544
542
|
// TODO: Remove `resolver` in v5 in favor of `components`.
|
|
545
543
|
if (props.resolver) {
|
|
@@ -547,26 +545,26 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
547
545
|
slice,
|
|
548
546
|
sliceName: type,
|
|
549
547
|
i: index,
|
|
550
|
-
})
|
|
548
|
+
})
|
|
551
549
|
|
|
552
550
|
if (resolvedComponent) {
|
|
553
|
-
component = resolvedComponent
|
|
551
|
+
component = resolvedComponent
|
|
554
552
|
}
|
|
555
553
|
}
|
|
556
554
|
|
|
557
555
|
const key =
|
|
558
556
|
"id" in slice && typeof slice.id === "string"
|
|
559
557
|
? slice.id
|
|
560
|
-
: `${index}-${JSON.stringify(slice)}
|
|
558
|
+
: `${index}-${JSON.stringify(slice)}`
|
|
561
559
|
|
|
562
560
|
if (component) {
|
|
563
561
|
if (slice.__mapped) {
|
|
564
|
-
const { __mapped, ...mappedProps } = slice
|
|
562
|
+
const { __mapped, ...mappedProps } = slice
|
|
565
563
|
|
|
566
564
|
return h(simplyResolveComponent(component as ConcreteComponent), {
|
|
567
565
|
key,
|
|
568
566
|
...mappedProps,
|
|
569
|
-
})
|
|
567
|
+
})
|
|
570
568
|
}
|
|
571
569
|
|
|
572
570
|
return h(simplyResolveComponent(component as ConcreteComponent), {
|
|
@@ -575,31 +573,31 @@ export const SliceZoneImpl = /*#__PURE__*/ defineComponent({
|
|
|
575
573
|
index,
|
|
576
574
|
context: props.context,
|
|
577
575
|
slices: props.slices,
|
|
578
|
-
})
|
|
576
|
+
})
|
|
579
577
|
} else {
|
|
580
578
|
return h(
|
|
581
579
|
simplyResolveComponent(TODOSliceComponent as ConcreteComponent),
|
|
582
580
|
{ key, slice },
|
|
583
|
-
)
|
|
581
|
+
)
|
|
584
582
|
}
|
|
585
|
-
})
|
|
586
|
-
})
|
|
583
|
+
})
|
|
584
|
+
})
|
|
587
585
|
|
|
588
586
|
return () => {
|
|
589
587
|
if (props.wrapper) {
|
|
590
|
-
const parent = simplyResolveComponent(props.wrapper)
|
|
588
|
+
const parent = simplyResolveComponent(props.wrapper)
|
|
591
589
|
|
|
592
590
|
if (typeof parent === "string") {
|
|
593
|
-
return h(parent, null, renderedSlices.value)
|
|
591
|
+
return h(parent, null, renderedSlices.value)
|
|
594
592
|
} else {
|
|
595
|
-
return h(parent, null, { default: () => renderedSlices.value })
|
|
593
|
+
return h(parent, null, { default: () => renderedSlices.value })
|
|
596
594
|
}
|
|
597
595
|
} else {
|
|
598
|
-
return renderedSlices.value
|
|
596
|
+
return renderedSlices.value
|
|
599
597
|
}
|
|
600
|
-
}
|
|
598
|
+
}
|
|
601
599
|
},
|
|
602
|
-
})
|
|
600
|
+
})
|
|
603
601
|
|
|
604
602
|
// export the public type for h/tsx inference
|
|
605
603
|
// also to avoid inline import() in generated d.ts files
|
|
@@ -614,6 +612,6 @@ export const SliceZone = SliceZoneImpl as unknown as {
|
|
|
614
612
|
$props: AllowedComponentProps &
|
|
615
613
|
ComponentCustomProps &
|
|
616
614
|
VNodeProps &
|
|
617
|
-
SliceZoneProps
|
|
618
|
-
}
|
|
619
|
-
}
|
|
615
|
+
SliceZoneProps
|
|
616
|
+
}
|
|
617
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
export { PrismicEmbedImpl, PrismicEmbed } from "./PrismicEmbed"
|
|
2
|
-
export type { PrismicEmbedProps } from "./PrismicEmbed"
|
|
1
|
+
export { PrismicEmbedImpl, PrismicEmbed } from "./PrismicEmbed"
|
|
2
|
+
export type { PrismicEmbedProps } from "./PrismicEmbed"
|
|
3
3
|
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
PrismicImageImpl,
|
|
7
|
-
PrismicImage,
|
|
8
|
-
} from "./PrismicImage";
|
|
9
|
-
export type { UsePrismicImageOptions, PrismicImageProps } from "./PrismicImage";
|
|
4
|
+
export { usePrismicImage, PrismicImageImpl, PrismicImage } from "./PrismicImage"
|
|
5
|
+
export type { UsePrismicImageOptions, PrismicImageProps } from "./PrismicImage"
|
|
10
6
|
|
|
11
|
-
export { usePrismicLink, PrismicLinkImpl, PrismicLink } from "./PrismicLink"
|
|
12
|
-
export type { UsePrismicLinkOptions, PrismicLinkProps } from "./PrismicLink"
|
|
7
|
+
export { usePrismicLink, PrismicLinkImpl, PrismicLink } from "./PrismicLink"
|
|
8
|
+
export type { UsePrismicLinkOptions, PrismicLinkProps } from "./PrismicLink"
|
|
13
9
|
|
|
14
|
-
export { usePrismicText, PrismicTextImpl, PrismicText } from "./PrismicText"
|
|
15
|
-
export type { UsePrismicTextOptions, PrismicTextProps } from "./PrismicText"
|
|
10
|
+
export { usePrismicText, PrismicTextImpl, PrismicText } from "./PrismicText"
|
|
11
|
+
export type { UsePrismicTextOptions, PrismicTextProps } from "./PrismicText"
|
|
16
12
|
|
|
17
13
|
export {
|
|
18
14
|
usePrismicRichText,
|
|
19
15
|
PrismicRichTextImpl,
|
|
20
16
|
PrismicRichText,
|
|
21
|
-
} from "./PrismicRichText"
|
|
17
|
+
} from "./PrismicRichText"
|
|
22
18
|
export type {
|
|
23
19
|
UsePrismicRichTextOptions,
|
|
24
20
|
PrismicRichTextProps,
|
|
25
|
-
} from "./PrismicRichText"
|
|
21
|
+
} from "./PrismicRichText"
|
|
26
22
|
|
|
27
23
|
export {
|
|
28
24
|
getSliceComponentProps,
|
|
@@ -30,7 +26,7 @@ export {
|
|
|
30
26
|
defineSliceZoneComponents,
|
|
31
27
|
SliceZoneImpl,
|
|
32
28
|
SliceZone,
|
|
33
|
-
} from "./SliceZone"
|
|
29
|
+
} from "./SliceZone"
|
|
34
30
|
export type {
|
|
35
31
|
DefineComponentSliceComponentProps,
|
|
36
32
|
SliceComponentProps,
|
|
@@ -43,4 +39,4 @@ export type {
|
|
|
43
39
|
SliceZoneResolver,
|
|
44
40
|
SliceZoneLike,
|
|
45
41
|
SliceZoneProps,
|
|
46
|
-
} from "./SliceZone"
|
|
42
|
+
} from "./SliceZone"
|