@prismicio/react 3.4.0-canary.e2a0168 → 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 +20 -28
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +6 -8
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +18 -21
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +6 -9
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +31 -37
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js +5 -7
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +15 -16
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js +4 -6
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +8 -11
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js +4 -6
- 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 +5 -8
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +31 -51
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +7 -10
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/lib/devMsg.js +7 -10
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +2 -2
- package/package.json +32 -34
- 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/PrismicRichText.tsx
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { type LinkProps, PrismicLink } from "./PrismicLink.js";
|
|
2
|
-
import { devMsg } from "./lib/devMsg.js";
|
|
3
1
|
import {
|
|
4
2
|
isFilled,
|
|
5
3
|
type LinkResolverFunction,
|
|
@@ -23,25 +21,25 @@ import {
|
|
|
23
21
|
type ReactNode,
|
|
24
22
|
} from "react";
|
|
25
23
|
|
|
24
|
+
import { devMsg } from "./lib/devMsg.js";
|
|
25
|
+
import { type LinkProps, PrismicLink } from "./PrismicLink.js";
|
|
26
|
+
|
|
26
27
|
/**
|
|
27
|
-
* A function mapping rich text block types to React Components. It is used to
|
|
28
|
-
*
|
|
28
|
+
* A function mapping rich text block types to React Components. It is used to render rich text
|
|
29
|
+
* fields.
|
|
29
30
|
*
|
|
30
31
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
31
32
|
*/
|
|
32
33
|
export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
|
-
* A map of rich text block types to React Components. It is used to render rich
|
|
36
|
-
* text fields.
|
|
36
|
+
* A map of rich text block types to React Components. It is used to render rich text fields.
|
|
37
37
|
*
|
|
38
38
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
39
39
|
*/
|
|
40
40
|
export type RichTextComponents = RichTextMapSerializer<ReactNode>;
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* @deprecated Use `RichTextComponents` instead.
|
|
44
|
-
*/
|
|
42
|
+
/** @deprecated Use `RichTextComponents` instead. */
|
|
45
43
|
export type JSXMapSerializer = RichTextComponents;
|
|
46
44
|
|
|
47
45
|
/** Props for `<PrismicRichText>`. */
|
|
@@ -53,9 +51,8 @@ export type PrismicRichTextProps = {
|
|
|
53
51
|
* The link resolver used to resolve links.
|
|
54
52
|
*
|
|
55
53
|
* @remarks
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
54
|
+
* If your app uses route resolvers when querying for your Prismic repository's content, a link
|
|
55
|
+
* resolver does not need to be provided.
|
|
59
56
|
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
|
|
60
57
|
*/
|
|
61
58
|
linkResolver?: LinkResolverFunction;
|
|
@@ -64,28 +61,29 @@ export type PrismicRichTextProps = {
|
|
|
64
61
|
* A map or function that maps a rich text block to a React component.
|
|
65
62
|
*
|
|
66
63
|
* @remarks
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
64
|
+
* Prefer using a map serializer over the function serializer when possible. The map serializer
|
|
65
|
+
* is simpler to maintain.
|
|
66
|
+
* @example
|
|
67
|
+
* A map serializer.
|
|
71
68
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
69
|
+
* ```jsx
|
|
70
|
+
* {
|
|
71
|
+
* heading1: ({children}) => <Heading>{children}</Heading>
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
77
74
|
*
|
|
78
|
-
* @example
|
|
75
|
+
* @example
|
|
76
|
+
* A function serializer.
|
|
79
77
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
78
|
+
* ```jsx
|
|
79
|
+
* (type, node, content, children) => {
|
|
82
80
|
* switch (type) {
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
81
|
+
* case "heading1": {
|
|
82
|
+
* return <Heading>{children}</Heading>;
|
|
83
|
+
* }
|
|
86
84
|
* }
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* };
|
|
86
|
+
* ```
|
|
89
87
|
*/
|
|
90
88
|
components?: RichTextComponents | JSXFunctionSerializer;
|
|
91
89
|
|
|
@@ -104,8 +102,8 @@ export type PrismicRichTextProps = {
|
|
|
104
102
|
externalLinkComponent?: ComponentType<LinkProps>;
|
|
105
103
|
|
|
106
104
|
/**
|
|
107
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
108
|
-
*
|
|
105
|
+
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
106
|
+
* rendered.
|
|
109
107
|
*/
|
|
110
108
|
fallback?: ReactNode;
|
|
111
109
|
};
|
|
@@ -122,9 +120,7 @@ const getDir = (node: RTAnyNode): "rtl" | undefined => {
|
|
|
122
120
|
}
|
|
123
121
|
};
|
|
124
122
|
|
|
125
|
-
const createDefaultSerializer = (
|
|
126
|
-
args: CreateDefaultSerializerArgs,
|
|
127
|
-
): JSXFunctionSerializer =>
|
|
123
|
+
const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunctionSerializer =>
|
|
128
124
|
wrapMapSerializer<ReactNode>({
|
|
129
125
|
heading1: ({ node, children, key }) => (
|
|
130
126
|
<h1 key={key} dir={getDir(node)}>
|
|
@@ -249,10 +245,9 @@ const createDefaultSerializer = (
|
|
|
249
245
|
* Renders content from a Prismic rich text field as React components.
|
|
250
246
|
*
|
|
251
247
|
* @example
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* ```
|
|
248
|
+
* ```tsx
|
|
249
|
+
* <PrismicRichText field={slice.primary.text} />;
|
|
250
|
+
* ```
|
|
256
251
|
*
|
|
257
252
|
* @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
|
|
258
253
|
*/
|
|
@@ -294,18 +289,15 @@ export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
|
|
|
294
289
|
// The serializer is wrapped in a higher-order function that
|
|
295
290
|
// automatically applies a key to React Elements if one is not already
|
|
296
291
|
// given.
|
|
297
|
-
const serialized = serialize<ReactNode>(
|
|
298
|
-
|
|
299
|
-
(type, node, text, children, key) => {
|
|
300
|
-
const result = serializer(type, node, text, children, key);
|
|
292
|
+
const serialized = serialize<ReactNode>(field, (type, node, text, children, key) => {
|
|
293
|
+
const result = serializer(type, node, text, children, key);
|
|
301
294
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
);
|
|
295
|
+
if (isValidElement(result) && result.key == null) {
|
|
296
|
+
return cloneElement(result, { key });
|
|
297
|
+
} else {
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
309
301
|
|
|
310
302
|
if (!serialized) {
|
|
311
303
|
return fallback != null ? <>{fallback}</> : null;
|
package/src/PrismicTable.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ComponentType, FC, ReactNode } from "react";
|
|
2
1
|
import {
|
|
3
2
|
isFilled,
|
|
4
3
|
type TableField,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
type TableFieldHeaderCell,
|
|
10
9
|
type TableFieldDataCell,
|
|
11
10
|
} from "@prismicio/client";
|
|
11
|
+
import type { ComponentType, FC, ReactNode } from "react";
|
|
12
12
|
|
|
13
13
|
import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js";
|
|
14
14
|
|
|
@@ -41,20 +41,21 @@ export type PrismicTableProps = {
|
|
|
41
41
|
/**
|
|
42
42
|
* An object that maps a table block to a React component.
|
|
43
43
|
*
|
|
44
|
-
* @example
|
|
44
|
+
* @example
|
|
45
|
+
* A map serializer.
|
|
45
46
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
47
|
+
* ```jsx
|
|
48
|
+
* {
|
|
49
|
+
* table: ({children}) => <table>{children}</table>
|
|
50
|
+
* thead: ({children}) => <thead>{children}</thead>
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
52
53
|
*/
|
|
53
54
|
components?: JSXMapSerializer & TableComponents;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
57
|
-
*
|
|
57
|
+
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
58
|
+
* rendered.
|
|
58
59
|
*/
|
|
59
60
|
fallback?: ReactNode;
|
|
60
61
|
};
|
|
@@ -63,10 +64,9 @@ export type PrismicTableProps = {
|
|
|
63
64
|
* Renders content from a Prismic table field as React components.
|
|
64
65
|
*
|
|
65
66
|
* @example
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* ```
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <PrismicTable field={slice.primary.pricing_table} />;
|
|
69
|
+
* ```
|
|
70
70
|
*
|
|
71
71
|
* @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
|
|
72
72
|
*/
|
|
@@ -77,11 +77,7 @@ export const PrismicTable: FC<PrismicTableProps> = (props) => {
|
|
|
77
77
|
return fallback;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const {
|
|
81
|
-
table: Table,
|
|
82
|
-
thead: Thead,
|
|
83
|
-
tbody: Tbody,
|
|
84
|
-
} = { ...defaultComponents, ...components };
|
|
80
|
+
const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components };
|
|
85
81
|
|
|
86
82
|
return (
|
|
87
83
|
<Table table={field}>
|
package/src/PrismicText.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { FC } from "react";
|
|
2
1
|
import { asText, isFilled, type RichTextField } from "@prismicio/client";
|
|
3
2
|
import { DEV } from "esm-env";
|
|
3
|
+
import type { FC } from "react";
|
|
4
4
|
|
|
5
5
|
import { devMsg } from "./lib/devMsg.js";
|
|
6
6
|
|
|
@@ -10,8 +10,8 @@ export type PrismicTextProps = {
|
|
|
10
10
|
field: RichTextField | null | undefined;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* The string rendered when the field is empty. If a fallback is not given,
|
|
14
|
-
*
|
|
13
|
+
* The string rendered when the field is empty. If a fallback is not given, `null` will be
|
|
14
|
+
* rendered.
|
|
15
15
|
*/
|
|
16
16
|
fallback?: string;
|
|
17
17
|
|
|
@@ -23,10 +23,9 @@ export type PrismicTextProps = {
|
|
|
23
23
|
* Renders content from a Prismic rich text field as plain text (no HTML).
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <PrismicText field={slice.primary.text} />;
|
|
28
|
+
* ```
|
|
30
29
|
*
|
|
31
30
|
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
|
|
32
31
|
*/
|
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 {
|