@prismicio/react 2.4.0 → 2.4.3

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/src/SliceZone.tsx CHANGED
@@ -59,7 +59,8 @@ export type SliceLike<SliceType extends string = string> =
59
59
  *
60
60
  * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
61
61
  */
62
- export type SliceZoneLike<TSlice extends SliceLike> = readonly TSlice[];
62
+ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
63
+ readonly TSlice[];
63
64
 
64
65
  /**
65
66
  * React props for a component rendering content from a Prismic Slice using the
@@ -70,7 +71,8 @@ export type SliceZoneLike<TSlice extends SliceLike> = readonly TSlice[];
70
71
  * available to all Slice components.
71
72
  */
72
73
  export type SliceComponentProps<
73
- TSlice extends SliceLike = SliceLike,
74
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
+ TSlice extends SliceLike = any,
74
76
  TContext = unknown,
75
77
  > = {
76
78
  /**
@@ -105,7 +107,8 @@ export type SliceComponentProps<
105
107
  * @typeParam TContext - Arbitrary data made available to all Slice components.
106
108
  */
107
109
  export type SliceComponentType<
108
- TSlice extends SliceLike = SliceLike,
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ TSlice extends SliceLike = any,
109
112
  TContext = unknown,
110
113
  > = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
111
114
 
@@ -113,6 +116,8 @@ export type SliceComponentType<
113
116
  * A record of Slice types mapped to a React component. The component will be
114
117
  * rendered for each instance of its Slice.
115
118
  *
119
+ * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
120
+ * `Record<string, SliceComponentType<any>>` instead.
116
121
  * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
117
122
  * @typeParam TContext - Arbitrary data made available to all Slice components.
118
123
  */
@@ -169,7 +174,10 @@ export const TODOSliceComponent = __PRODUCTION__
169
174
  /**
170
175
  * Arguments for a `<SliceZone>` `resolver` function.
171
176
  */
172
- type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
177
+ type SliceZoneResolverArgs<
178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
179
+ TSlice extends SliceLike = any,
180
+ > = {
173
181
  /**
174
182
  * The Slice to resolve to a React component.
175
183
  */
@@ -198,11 +206,17 @@ type SliceZoneResolverArgs<TSlice extends SliceLike = SliceLike> = {
198
206
  * @returns The React component to render for a Slice.
199
207
  */
200
208
  export type SliceZoneResolver<
201
- TSlice extends SliceLike = SliceLike,
209
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
210
+ TSlice extends SliceLike = any,
202
211
  TContext = unknown,
203
- > = (
204
- args: SliceZoneResolverArgs<TSlice>,
205
- ) => SliceComponentType<TSlice, TContext> | undefined | null;
212
+ > = (args: SliceZoneResolverArgs<TSlice>) =>
213
+ | SliceComponentType<
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ any,
216
+ TContext
217
+ >
218
+ | undefined
219
+ | null;
206
220
 
207
221
  /**
208
222
  * React props for the `<SliceZone>` component.
@@ -210,19 +224,17 @@ export type SliceZoneResolver<
210
224
  * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
211
225
  * @typeParam TContext - Arbitrary data made available to all Slice components.
212
226
  */
213
- export type SliceZoneProps<
214
- TSlice extends SliceLike = SliceLike,
215
- TContext = unknown,
216
- > = {
227
+ export type SliceZoneProps<TContext = unknown> = {
217
228
  /**
218
229
  * List of Slice data from the Slice Zone.
219
230
  */
220
- slices?: SliceZoneLike<TSlice>;
231
+ slices?: SliceZoneLike;
221
232
 
222
233
  /**
223
234
  * A record mapping Slice types to React components.
224
235
  */
225
- components?: SliceZoneComponents<TSlice, TContext>;
236
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
+ components?: Record<string, SliceComponentType<any, TContext>>;
226
238
 
227
239
  /**
228
240
  * A function that determines the rendered React component for each Slice in
@@ -234,13 +246,15 @@ export type SliceZoneProps<
234
246
  *
235
247
  * @returns The React component to render for a Slice.
236
248
  */
237
- resolver?: SliceZoneResolver<TSlice, TContext>;
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
+ resolver?: SliceZoneResolver<any, TContext>;
238
251
 
239
252
  /**
240
253
  * The React component rendered if a component mapping from the `components`
241
254
  * prop cannot be found.
242
255
  */
243
- defaultComponent?: SliceComponentType<TSlice, TContext>;
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
257
+ defaultComponent?: SliceComponentType<any, TContext>;
244
258
 
245
259
  /**
246
260
  * Arbitrary data made available to all Slice components.
@@ -263,19 +277,19 @@ export type SliceZoneProps<
263
277
  *
264
278
  * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
265
279
  */
266
- export const SliceZone = <TSlice extends SliceLike, TContext>({
280
+ export const SliceZone = <TContext,>({
267
281
  slices = [],
268
- components = {} as SliceZoneComponents<TSlice, TContext>,
282
+ components = {},
269
283
  resolver,
270
284
  defaultComponent = TODOSliceComponent,
271
285
  context = {} as TContext,
272
- }: SliceZoneProps<TSlice, TContext>): JSX.Element => {
286
+ }: SliceZoneProps<TContext>): JSX.Element => {
273
287
  const renderedSlices = React.useMemo(() => {
274
288
  return slices.map((slice, index) => {
275
289
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
276
290
 
277
- let Comp = (components[type as keyof typeof components] ||
278
- defaultComponent) as SliceComponentType<TSlice, TContext>;
291
+ let Comp =
292
+ components[type as keyof typeof components] || defaultComponent;
279
293
 
280
294
  // TODO: Remove `resolver` in v3 in favor of `components`.
281
295
  if (resolver) {
@@ -286,7 +300,7 @@ export const SliceZone = <TSlice extends SliceLike, TContext>({
286
300
  });
287
301
 
288
302
  if (resolvedComp) {
289
- Comp = resolvedComp;
303
+ Comp = resolvedComp as typeof Comp;
290
304
  }
291
305
  }
292
306
 
package/src/index.ts CHANGED
@@ -32,6 +32,8 @@ export { SliceZone, TODOSliceComponent } from "./SliceZone";
32
32
  export type {
33
33
  SliceComponentProps,
34
34
  SliceComponentType,
35
+ SliceLikeRestV2,
36
+ SliceLikeGraphQL,
35
37
  SliceLike,
36
38
  SliceZoneComponents,
37
39
  SliceZoneLike,