@prismicio/react 3.4.0-pr.257.5417830 → 3.4.0-pr.257.68f2f80
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 +17 -22
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +4 -5
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +17 -19
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +4 -6
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +30 -34
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js +4 -5
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +14 -14
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js +3 -4
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +6 -7
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js +3 -4
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +11 -14
- package/dist/PrismicToolbar.d.ts.map +1 -1
- package/dist/PrismicToolbar.js +4 -5
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +27 -40
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +6 -8
- package/dist/SliceZone.js.map +1 -1
- package/dist/lib/devMsg.js +6 -8
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +1 -1
- package/package.json +27 -29
- package/src/PrismicImage.tsx +95 -122
- package/src/PrismicLink.tsx +28 -38
- package/src/PrismicRichText.tsx +41 -49
- package/src/PrismicTable.tsx +15 -19
- package/src/PrismicText.tsx +6 -7
- package/src/PrismicToolbar.tsx +12 -16
- package/src/SliceZone.tsx +36 -76
- package/src/lib/devMsg.ts +6 -8
package/src/PrismicToolbar.tsx
CHANGED
|
@@ -6,28 +6,26 @@ import { type FC, useEffect, useRef } from "react";
|
|
|
6
6
|
/** Props for `<PrismicToolbar>`. */
|
|
7
7
|
export type PrismicToolbarProps = {
|
|
8
8
|
/**
|
|
9
|
-
* The name of the Prismic repository. For example, `"my-repo"` if the
|
|
10
|
-
*
|
|
9
|
+
* The name of the Prismic repository. For example, `"my-repo"` if the repository URL is
|
|
10
|
+
* `my-repo.prismic.io`.
|
|
11
11
|
*/
|
|
12
12
|
repositoryName: string;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Called when the Prismic toolbar triggers a preview update. This happens
|
|
16
|
-
*
|
|
15
|
+
* Called when the Prismic toolbar triggers a preview update. This happens when the previewed
|
|
16
|
+
* content changes.
|
|
17
17
|
*
|
|
18
18
|
* The new ref can be read from `event.detail.ref`.
|
|
19
19
|
*
|
|
20
|
-
* The default page reload behavior can be cancelled with
|
|
21
|
-
* `event.preventDefault()`.
|
|
20
|
+
* The default page reload behavior can be cancelled with `event.preventDefault()`.
|
|
22
21
|
*/
|
|
23
22
|
onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void;
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
* Called when the Prismic toolbar triggers a preview end. This happens when
|
|
27
|
-
*
|
|
25
|
+
* Called when the Prismic toolbar triggers a preview end. This happens when a preview session is
|
|
26
|
+
* closed.
|
|
28
27
|
*
|
|
29
|
-
* The default page reload behavior can be cancelled with
|
|
30
|
-
* `event.preventDefault()`.
|
|
28
|
+
* The default page reload behavior can be cancelled with `event.preventDefault()`.
|
|
31
29
|
*/
|
|
32
30
|
onPreviewEnd?: (event: CustomEvent<null>) => void;
|
|
33
31
|
};
|
|
@@ -36,10 +34,9 @@ export type PrismicToolbarProps = {
|
|
|
36
34
|
* Renders the Prismic Toolbar script to support draft previews.
|
|
37
35
|
*
|
|
38
36
|
* @example
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* ```
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <PrismicToolbar repositoryName="my-repo" />;
|
|
39
|
+
* ```
|
|
43
40
|
*
|
|
44
41
|
* @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
|
|
45
42
|
*/
|
|
@@ -79,8 +76,7 @@ export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
|
|
|
79
76
|
|
|
80
77
|
window.addEventListener(
|
|
81
78
|
"prismicPreviewUpdate",
|
|
82
|
-
(event) =>
|
|
83
|
-
onPreviewUpdateRef.current?.(event as CustomEvent<{ ref: string }>),
|
|
79
|
+
(event) => onPreviewUpdateRef.current?.(event as CustomEvent<{ ref: string }>),
|
|
84
80
|
{ signal: controller.signal },
|
|
85
81
|
);
|
|
86
82
|
|
package/src/SliceZone.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ComponentType, FC, ReactNode } from "react";
|
|
2
1
|
import type { Slice } from "@prismicio/client";
|
|
3
2
|
import { DEV } from "esm-env";
|
|
3
|
+
import type { ComponentType, FC, ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the type of a `SliceLike` type.
|
|
@@ -14,8 +14,8 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
|
|
|
14
14
|
: never;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
18
|
-
*
|
|
17
|
+
* The minimum required properties to represent a Prismic slice from the Prismic Content API for the
|
|
18
|
+
* `mapSliceZone()` helper.
|
|
19
19
|
*
|
|
20
20
|
* @typeParam SliceType - Type name of the slice.
|
|
21
21
|
*/
|
|
@@ -25,8 +25,8 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
|
25
25
|
>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
29
|
-
*
|
|
28
|
+
* The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the
|
|
29
|
+
* `mapSliceZone()` helper.
|
|
30
30
|
*
|
|
31
31
|
* @typeParam SliceType - Type name of the slice.
|
|
32
32
|
*/
|
|
@@ -35,11 +35,10 @@ export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* The minimum required properties to represent a Prismic slice for the
|
|
39
|
-
* `mapSliceZone()` helper.
|
|
38
|
+
* The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper.
|
|
40
39
|
*
|
|
41
|
-
* If using Prismic's Content API, use the `Slice` export from
|
|
42
|
-
*
|
|
40
|
+
* If using Prismic's Content API, use the `Slice` export from `@prismicio/client` for a full
|
|
41
|
+
* interface.
|
|
43
42
|
*
|
|
44
43
|
* @typeParam SliceType - Type name of the slice.
|
|
45
44
|
*/
|
|
@@ -48,8 +47,8 @@ export type SliceLike<TSliceType extends string = string> = (
|
|
|
48
47
|
| SliceLikeGraphQL<TSliceType>
|
|
49
48
|
) & {
|
|
50
49
|
/**
|
|
51
|
-
* If `true`, this slice has been modified from its original value using a
|
|
52
|
-
*
|
|
50
|
+
* If `true`, this slice has been modified from its original value using a mapper and
|
|
51
|
+
* `@prismicio/client`'s `mapSliceZone()`.
|
|
53
52
|
*
|
|
54
53
|
* @internal
|
|
55
54
|
*/
|
|
@@ -57,29 +56,24 @@ export type SliceLike<TSliceType extends string = string> = (
|
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
/**
|
|
60
|
-
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
61
|
-
* `SliceLike`.
|
|
59
|
+
* A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.
|
|
62
60
|
*
|
|
63
|
-
* If using Prismic's Content API, use the `SliceZone` export from
|
|
64
|
-
*
|
|
61
|
+
* If using Prismic's Content API, use the `SliceZone` export from `@prismicio/client` for the full
|
|
62
|
+
* type.
|
|
65
63
|
*
|
|
66
64
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
67
65
|
*/
|
|
68
|
-
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> =
|
|
69
|
-
readonly TSlice[];
|
|
66
|
+
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
70
67
|
|
|
71
68
|
/**
|
|
72
|
-
* React props for a component rendering content from a Prismic slice using the
|
|
73
|
-
*
|
|
69
|
+
* React props for a component rendering content from a Prismic slice using the `<SliceZone>`
|
|
70
|
+
* component.
|
|
74
71
|
*
|
|
75
72
|
* @typeParam TSlice - The slice passed as a prop.
|
|
76
|
-
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
|
|
77
|
-
*
|
|
73
|
+
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
74
|
+
* components.
|
|
78
75
|
*/
|
|
79
|
-
export type SliceComponentProps<
|
|
80
|
-
TSlice extends SliceLike = SliceLike,
|
|
81
|
-
TContext = unknown,
|
|
82
|
-
> = {
|
|
76
|
+
export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
83
77
|
/** Slice data for this component. */
|
|
84
78
|
slice: TSlice;
|
|
85
79
|
|
|
@@ -91,14 +85,9 @@ export type SliceComponentProps<
|
|
|
91
85
|
// reference limtiations. If we had another generic to determine the full
|
|
92
86
|
// union of slice types, it would include TSlice. This causes TypeScript to
|
|
93
87
|
// throw a compilation error.
|
|
94
|
-
slices: SliceZoneLike<
|
|
95
|
-
TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2
|
|
96
|
-
>;
|
|
88
|
+
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
97
89
|
|
|
98
|
-
/**
|
|
99
|
-
* Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
100
|
-
* components.
|
|
101
|
-
*/
|
|
90
|
+
/** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
|
|
102
91
|
context: TContext;
|
|
103
92
|
};
|
|
104
93
|
|
|
@@ -115,19 +104,15 @@ export type SliceComponentType<
|
|
|
115
104
|
> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
116
105
|
|
|
117
106
|
/**
|
|
118
|
-
* A record of slice types mapped to a React component. The component will be
|
|
119
|
-
*
|
|
107
|
+
* A record of slice types mapped to a React component. The component will be rendered for each
|
|
108
|
+
* instance of its slice.
|
|
120
109
|
*
|
|
121
110
|
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
122
111
|
* `Record<string, SliceComponentType<any>>` instead.
|
|
123
|
-
*
|
|
124
112
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
125
113
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
126
114
|
*/
|
|
127
|
-
export type SliceZoneComponents<
|
|
128
|
-
TSlice extends SliceLike = SliceLike,
|
|
129
|
-
TContext = unknown,
|
|
130
|
-
> =
|
|
115
|
+
export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> =
|
|
131
116
|
// This is purposely not wrapped in Partial to ensure a component is provided
|
|
132
117
|
// for all slice types. <SliceZone> will render a default component if one is
|
|
133
118
|
// not provided, but it *should* be a type error if an explicit component is
|
|
@@ -160,10 +145,7 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
160
145
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
146
|
components?: Record<string, ComponentType<any>>;
|
|
162
147
|
|
|
163
|
-
/**
|
|
164
|
-
* The React component rendered if a component mapping from the `components`
|
|
165
|
-
* prop cannot be found.
|
|
166
|
-
*/
|
|
148
|
+
/** The React component rendered if a component mapping from the `components` prop cannot be found. */
|
|
167
149
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
150
|
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
169
151
|
|
|
@@ -172,11 +154,10 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
172
154
|
};
|
|
173
155
|
|
|
174
156
|
/**
|
|
175
|
-
* This slice component can be used as a reminder to provide a proper
|
|
176
|
-
* implementation.
|
|
157
|
+
* This slice component can be used as a reminder to provide a proper implementation.
|
|
177
158
|
*
|
|
178
|
-
* This is also the default React component rendered when a component mapping
|
|
179
|
-
*
|
|
159
|
+
* This is also the default React component rendered when a component mapping cannot be found in
|
|
160
|
+
* `<SliceZone>`.
|
|
180
161
|
*/
|
|
181
162
|
export const TODOSliceComponent = <TSlice extends SliceLike>({
|
|
182
163
|
slice,
|
|
@@ -189,10 +170,7 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
|
|
|
189
170
|
|
|
190
171
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
191
172
|
|
|
192
|
-
console.warn(
|
|
193
|
-
`[SliceZone] Could not find a component for slice type "${type}"`,
|
|
194
|
-
slice,
|
|
195
|
-
);
|
|
173
|
+
console.warn(`[SliceZone] Could not find a component for slice type "${type}"`, slice);
|
|
196
174
|
|
|
197
175
|
return (
|
|
198
176
|
<section data-slice-zone-todo-component="" data-slice-type={type}>
|
|
@@ -206,31 +184,21 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
|
|
|
206
184
|
* Renders slices in a slice zone as React components.
|
|
207
185
|
*
|
|
208
186
|
* @example
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* ```
|
|
187
|
+
* ```tsx
|
|
188
|
+
* <SliceZone slices={page.data.slices} components={components} />;
|
|
189
|
+
* ```
|
|
213
190
|
*
|
|
214
191
|
* @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
|
|
215
192
|
*/
|
|
216
193
|
export const SliceZone: FC<SliceZoneProps> = (props) => {
|
|
217
|
-
const {
|
|
218
|
-
slices = [],
|
|
219
|
-
components = {},
|
|
220
|
-
defaultComponent,
|
|
221
|
-
context = {},
|
|
222
|
-
} = props;
|
|
194
|
+
const { slices = [], components = {}, defaultComponent, context = {} } = props;
|
|
223
195
|
|
|
224
196
|
const renderedSlices = slices.map((slice, index) => {
|
|
225
197
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
226
198
|
|
|
227
|
-
const key =
|
|
228
|
-
"id" in slice && slice.id
|
|
229
|
-
? slice.id
|
|
230
|
-
: `${index}-${JSON.stringify(slice)}`;
|
|
199
|
+
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
231
200
|
|
|
232
|
-
const Comp =
|
|
233
|
-
components[type as keyof typeof components] || defaultComponent;
|
|
201
|
+
const Comp = components[type as keyof typeof components] || defaultComponent;
|
|
234
202
|
|
|
235
203
|
if (!Comp) {
|
|
236
204
|
return <TODOSliceComponent key={key} slice={slice} />;
|
|
@@ -242,15 +210,7 @@ export const SliceZone: FC<SliceZoneProps> = (props) => {
|
|
|
242
210
|
return <Comp key={key} {...mappedProps} />;
|
|
243
211
|
}
|
|
244
212
|
|
|
245
|
-
return
|
|
246
|
-
<Comp
|
|
247
|
-
key={key}
|
|
248
|
-
slice={slice}
|
|
249
|
-
index={index}
|
|
250
|
-
slices={slices}
|
|
251
|
-
context={context}
|
|
252
|
-
/>
|
|
253
|
-
);
|
|
213
|
+
return <Comp key={key} slice={slice} index={index} slices={slices} context={context} />;
|
|
254
214
|
});
|
|
255
215
|
|
|
256
216
|
return <>{renderedSlices}</>;
|
package/src/lib/devMsg.ts
CHANGED
|
@@ -4,15 +4,13 @@ import { version } from "../../package.json";
|
|
|
4
4
|
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* devMsg("missing-param");
|
|
9
|
+
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
|
|
10
|
+
* ```
|
|
7
11
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
14
|
-
* the Git repository's `/messages` directory.
|
|
15
|
-
*
|
|
12
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
|
|
13
|
+
* `/messages` directory.
|
|
16
14
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
15
|
*/
|
|
18
16
|
export function devMsg(slug: string): string {
|