@prismicio/react 3.2.1-alpha.0 → 3.2.2-pr.236.d65a0c3
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/PrismicImage.d.ts +14 -22
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +16 -5
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +17 -44
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +5 -27
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +6 -15
- package/dist/PrismicText.js +1 -1
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +9 -2
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +39 -43
- package/dist/SliceZone.js +2 -2
- package/dist/SliceZone.js.map +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +6 -6
- package/src/PrismicImage.tsx +14 -22
- package/src/PrismicLink.tsx +16 -5
- package/src/PrismicRichText.tsx +17 -44
- package/src/PrismicTable.tsx +5 -27
- package/src/PrismicText.tsx +7 -16
- package/src/PrismicToolbar.tsx +9 -2
- package/src/SliceZone.tsx +44 -48
package/src/SliceZone.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { DEV } from "esm-env";
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the type of a `SliceLike` type.
|
|
7
7
|
*
|
|
8
|
-
* @typeParam
|
|
8
|
+
* @typeParam TSlice - The slice from which the type will be extracted.
|
|
9
9
|
*/
|
|
10
10
|
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
|
|
11
11
|
? TSlice["slice_type"]
|
|
@@ -14,10 +14,10 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
|
|
|
14
14
|
: never;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* The minimum required properties to represent a Prismic
|
|
18
|
-
*
|
|
17
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
18
|
+
* Content API for the `mapSliceZone()` helper.
|
|
19
19
|
*
|
|
20
|
-
* @typeParam SliceType - Type name of the
|
|
20
|
+
* @typeParam SliceType - Type name of the slice.
|
|
21
21
|
*/
|
|
22
22
|
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
23
23
|
Slice<TSliceType>,
|
|
@@ -25,30 +25,30 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
|
25
25
|
>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* The minimum required properties to represent a Prismic
|
|
29
|
-
* GraphQL API for the `
|
|
28
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
29
|
+
* GraphQL API for the `mapSliceZone()` helper.
|
|
30
30
|
*
|
|
31
|
-
* @typeParam SliceType - Type name of the
|
|
31
|
+
* @typeParam SliceType - Type name of the slice.
|
|
32
32
|
*/
|
|
33
33
|
export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
34
34
|
type: Slice<TSliceType>["slice_type"];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* The minimum required properties to represent a Prismic
|
|
39
|
-
* `
|
|
38
|
+
* The minimum required properties to represent a Prismic slice for the
|
|
39
|
+
* `mapSliceZone()` helper.
|
|
40
40
|
*
|
|
41
|
-
* If using Prismic's
|
|
41
|
+
* If using Prismic's Content API, use the `Slice` export from
|
|
42
42
|
* `@prismicio/client` for a full interface.
|
|
43
43
|
*
|
|
44
|
-
* @typeParam SliceType - Type name of the
|
|
44
|
+
* @typeParam SliceType - Type name of the slice.
|
|
45
45
|
*/
|
|
46
46
|
export type SliceLike<TSliceType extends string = string> = (
|
|
47
47
|
| SliceLikeRestV2<TSliceType>
|
|
48
48
|
| SliceLikeGraphQL<TSliceType>
|
|
49
49
|
) & {
|
|
50
50
|
/**
|
|
51
|
-
* If `true`, this
|
|
51
|
+
* If `true`, this slice has been modified from its original value using a
|
|
52
52
|
* mapper and `@prismicio/client`'s `mapSliceZone()`.
|
|
53
53
|
*
|
|
54
54
|
* @internal
|
|
@@ -60,21 +60,21 @@ export type SliceLike<TSliceType extends string = string> = (
|
|
|
60
60
|
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
61
61
|
* `SliceLike`.
|
|
62
62
|
*
|
|
63
|
-
* If using Prismic's
|
|
63
|
+
* If using Prismic's Content API, use the `SliceZone` export from
|
|
64
64
|
* `@prismicio/client` for the full type.
|
|
65
65
|
*
|
|
66
|
-
* @typeParam TSlice - The type(s) of a
|
|
66
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
67
67
|
*/
|
|
68
68
|
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
|
|
69
69
|
readonly TSlice[];
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
|
-
* React props for a component rendering content from a Prismic
|
|
72
|
+
* React props for a component rendering content from a Prismic slice using the
|
|
73
73
|
* `<SliceZone>` component.
|
|
74
74
|
*
|
|
75
|
-
* @typeParam TSlice - The
|
|
75
|
+
* @typeParam TSlice - The slice passed as a prop.
|
|
76
76
|
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
|
|
77
|
-
* available to all
|
|
77
|
+
* available to all slice components.
|
|
78
78
|
*/
|
|
79
79
|
export type SliceComponentProps<
|
|
80
80
|
TSlice extends SliceLike = SliceLike,
|
|
@@ -83,30 +83,30 @@ export type SliceComponentProps<
|
|
|
83
83
|
/** Slice data for this component. */
|
|
84
84
|
slice: TSlice;
|
|
85
85
|
|
|
86
|
-
/** The index of the
|
|
86
|
+
/** The index of the slice in the slice zone. */
|
|
87
87
|
index: number;
|
|
88
88
|
|
|
89
|
-
/** All
|
|
90
|
-
// TODO: We have to keep this list of
|
|
89
|
+
/** All slices from the slice zone to which the slice belongs. */
|
|
90
|
+
// TODO: We have to keep this list of slices general due to circular
|
|
91
91
|
// reference limtiations. If we had another generic to determine the full
|
|
92
|
-
// union of
|
|
92
|
+
// union of slice types, it would include TSlice. This causes TypeScript to
|
|
93
93
|
// throw a compilation error.
|
|
94
94
|
slices: SliceZoneLike<
|
|
95
95
|
TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
|
|
96
96
|
>;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* Arbitrary data passed to `<SliceZone>` and made available to all
|
|
99
|
+
* Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
100
100
|
* components.
|
|
101
101
|
*/
|
|
102
102
|
context: TContext;
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* A React component to be rendered for each instance of its
|
|
106
|
+
* A React component to be rendered for each instance of its slice.
|
|
107
107
|
*
|
|
108
|
-
* @typeParam TSlice - The type(s) of a
|
|
109
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
108
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
109
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
110
110
|
*/
|
|
111
111
|
export type SliceComponentType<
|
|
112
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -115,21 +115,21 @@ export type SliceComponentType<
|
|
|
115
115
|
> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* A record of
|
|
119
|
-
* rendered for each instance of its
|
|
118
|
+
* A record of slice types mapped to a React component. The component will be
|
|
119
|
+
* rendered for each instance of its slice.
|
|
120
120
|
*
|
|
121
121
|
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
122
122
|
* `Record<string, SliceComponentType<any>>` instead.
|
|
123
123
|
*
|
|
124
|
-
* @typeParam TSlice - The type(s) of a
|
|
125
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
124
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
125
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
126
126
|
*/
|
|
127
127
|
export type SliceZoneComponents<
|
|
128
128
|
TSlice extends SliceLike = SliceLike,
|
|
129
129
|
TContext = unknown,
|
|
130
130
|
> =
|
|
131
131
|
// This is purposely not wrapped in Partial to ensure a component is provided
|
|
132
|
-
// for all
|
|
132
|
+
// for all slice types. <SliceZone> will render a default component if one is
|
|
133
133
|
// not provided, but it *should* be a type error if an explicit component is
|
|
134
134
|
// missing.
|
|
135
135
|
//
|
|
@@ -149,14 +149,14 @@ export type SliceZoneComponents<
|
|
|
149
149
|
/**
|
|
150
150
|
* React props for the `<SliceZone>` component.
|
|
151
151
|
*
|
|
152
|
-
* @typeParam TSlice - The type(s) of a
|
|
153
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
152
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
153
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
154
154
|
*/
|
|
155
155
|
export type SliceZoneProps<TContext = unknown> = {
|
|
156
|
-
/** List of
|
|
156
|
+
/** List of slice data from the slice zone. */
|
|
157
157
|
slices?: SliceZoneLike;
|
|
158
158
|
|
|
159
|
-
/** A record mapping
|
|
159
|
+
/** A record mapping slice types to React components. */
|
|
160
160
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
161
|
components?: Record<string, ComponentType<any>>;
|
|
162
162
|
|
|
@@ -167,12 +167,12 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
169
169
|
|
|
170
|
-
/** Arbitrary data made available to all
|
|
170
|
+
/** Arbitrary data made available to all slice components. */
|
|
171
171
|
context?: TContext;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
-
* This
|
|
175
|
+
* This slice component can be used as a reminder to provide a proper
|
|
176
176
|
* implementation.
|
|
177
177
|
*
|
|
178
178
|
* This is also the default React component rendered when a component mapping
|
|
@@ -190,32 +190,28 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
|
|
|
190
190
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
191
191
|
|
|
192
192
|
console.warn(
|
|
193
|
-
`[SliceZone] Could not find a component for
|
|
193
|
+
`[SliceZone] Could not find a component for slice type "${type}"`,
|
|
194
194
|
slice,
|
|
195
195
|
);
|
|
196
196
|
|
|
197
197
|
return (
|
|
198
198
|
<section data-slice-zone-todo-component="" data-slice-type={type}>
|
|
199
|
-
Could not find a component for
|
|
199
|
+
Could not find a component for slice type “{type}
|
|
200
200
|
”
|
|
201
201
|
</section>
|
|
202
202
|
);
|
|
203
203
|
};
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
* Renders
|
|
207
|
-
* type of Slice.
|
|
206
|
+
* Renders slices in a slice zone as React components.
|
|
208
207
|
*
|
|
209
|
-
*
|
|
210
|
-
* be provided. A fallback component is provided by default that will not be
|
|
211
|
-
* rendered in a production build of your app.
|
|
208
|
+
* @example
|
|
212
209
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
210
|
+
* ```tsx
|
|
211
|
+
* <SliceZone slices={page.data.slices} components={components} />;
|
|
212
|
+
* ```
|
|
215
213
|
*
|
|
216
|
-
* @
|
|
217
|
-
*
|
|
218
|
-
* @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
|
|
214
|
+
* @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
|
|
219
215
|
*/
|
|
220
216
|
export const SliceZone: FC<SliceZoneProps> = (props) => {
|
|
221
217
|
const {
|