@prismicio/react 3.2.1 → 3.2.2-canary.8d3ad6d

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.
Files changed (47) hide show
  1. package/dist/PrismicImage.d.ts +66 -72
  2. package/dist/PrismicImage.d.ts.map +1 -0
  3. package/dist/PrismicImage.js +54 -47
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +71 -64
  6. package/dist/PrismicLink.d.ts.map +1 -0
  7. package/dist/PrismicLink.js +59 -40
  8. package/dist/PrismicLink.js.map +1 -1
  9. package/dist/PrismicRichText.d.ts +79 -100
  10. package/dist/PrismicRichText.d.ts.map +1 -0
  11. package/dist/PrismicRichText.js +125 -71
  12. package/dist/PrismicRichText.js.map +1 -1
  13. package/dist/PrismicTable.d.ts +58 -76
  14. package/dist/PrismicTable.d.ts.map +1 -0
  15. package/dist/PrismicTable.js +68 -21
  16. package/dist/PrismicTable.js.map +1 -1
  17. package/dist/PrismicText.d.ts +21 -25
  18. package/dist/PrismicText.d.ts.map +1 -0
  19. package/dist/PrismicText.js +30 -23
  20. package/dist/PrismicText.js.map +1 -1
  21. package/dist/PrismicToolbar.d.ts +21 -9
  22. package/dist/PrismicToolbar.d.ts.map +1 -0
  23. package/dist/PrismicToolbar.js +32 -19
  24. package/dist/PrismicToolbar.js.map +1 -1
  25. package/dist/SliceZone.d.ts +84 -83
  26. package/dist/SliceZone.d.ts.map +1 -0
  27. package/dist/SliceZone.js +54 -27
  28. package/dist/SliceZone.js.map +1 -1
  29. package/dist/index.d.ts +9 -15
  30. package/dist/index.js +4 -14
  31. package/dist/lib/devMsg.js +23 -6
  32. package/dist/lib/devMsg.js.map +1 -1
  33. package/dist/package.js +6 -0
  34. package/dist/package.js.map +1 -0
  35. package/package.json +21 -41
  36. package/src/PrismicImage.tsx +17 -25
  37. package/src/PrismicLink.tsx +21 -10
  38. package/src/PrismicRichText.tsx +26 -53
  39. package/src/PrismicTable.tsx +14 -36
  40. package/src/PrismicText.tsx +9 -18
  41. package/src/PrismicToolbar.tsx +10 -3
  42. package/src/SliceZone.tsx +46 -50
  43. package/src/lib/devMsg.ts +1 -1
  44. package/dist/index.js.map +0 -1
  45. package/dist/lib/devMsg.d.ts +0 -16
  46. package/dist/package.json.js +0 -5
  47. package/dist/package.json.js.map +0 -1
@@ -1,16 +1,16 @@
1
- import { ComponentType, FC, ReactNode } from "react";
1
+ import type { ComponentType, FC, ReactNode } from "react";
2
2
  import {
3
3
  isFilled,
4
- TableField,
5
- TableFieldHead,
6
- TableFieldHeadRow,
7
- TableFieldBody,
8
- TableFieldBodyRow,
9
- TableFieldHeaderCell,
10
- TableFieldDataCell,
4
+ type TableField,
5
+ type TableFieldHead,
6
+ type TableFieldHeadRow,
7
+ type TableFieldBody,
8
+ type TableFieldBodyRow,
9
+ type TableFieldHeaderCell,
10
+ type TableFieldDataCell,
11
11
  } from "@prismicio/client";
12
12
 
13
- import { JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js";
13
+ import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js";
14
14
 
15
15
  type TableComponents = {
16
16
  table?: ComponentType<{ table: TableField<"filled">; children: ReactNode }>;
@@ -60,37 +60,15 @@ export type PrismicTableProps = {
60
60
  };
61
61
 
62
62
  /**
63
- * React component that renders content from a Prismic table field. By default,
64
- * HTML elements are rendered for each piece of content. A `tbody` block will
65
- * render a `<tbody>` HTML element, for example.
63
+ * Renders content from a Prismic table field as React components.
66
64
  *
67
- * To customize the components that are rendered, provide a map serializer to
68
- * the `components` prop.
65
+ * @example
69
66
  *
70
- * @example Rendering a table field using the default HTMl elements.
71
- *
72
- * ```jsx
73
- * <PrismicTable field={document.data.my_table} />;
74
- * ```
75
- *
76
- * @example Rendering a table field using a custom set of React components.
77
- *
78
- * ```jsx
79
- * <PrismicTable
80
- * field={document.data.my_table}
81
- * components={{
82
- * tbody: ({ children }) => (
83
- * <tbody className="my-class">{children}</tbody>
84
- * ),
85
- * }}
86
- * />;
67
+ * ```tsx
68
+ * <PrismicTable field={slice.primary.pricing_table} />;
87
69
  * ```
88
70
  *
89
- * @param props - Props for the component.
90
- *
91
- * @returns The table field's content as React components.
92
- *
93
- * @see Learn about table fields {@link https://prismic.io/docs/core-concepts/table}
71
+ * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
94
72
  */
95
73
  export const PrismicTable: FC<PrismicTableProps> = (props) => {
96
74
  const { field, components, fallback = null } = props;
@@ -1,12 +1,12 @@
1
- import { FC } from "react";
2
- import { asText, isFilled, RichTextField } from "@prismicio/client";
1
+ import type { FC } from "react";
2
+ import { asText, isFilled, type RichTextField } from "@prismicio/client";
3
3
  import { DEV } from "esm-env";
4
4
 
5
5
  import { devMsg } from "./lib/devMsg.js";
6
6
 
7
7
  /** Props for `<PrismicText>`. */
8
8
  export type PrismicTextProps = {
9
- /** The Prismic Rich Text field to render. */
9
+ /** The Prismic rich text field to render. */
10
10
  field: RichTextField | null | undefined;
11
11
 
12
12
  /**
@@ -20,24 +20,15 @@ export type PrismicTextProps = {
20
20
  };
21
21
 
22
22
  /**
23
- * React component that renders content from a Prismic Rich Text field as plain
24
- * text.
23
+ * Renders content from a Prismic rich text field as plain text (no HTML).
25
24
  *
26
- * @remarks
27
- * This component returns a React fragment with no wrapping element around the
28
- * content. If you need a wrapper, add a component around `<PrismicText>`.
25
+ * @example
29
26
  *
30
- * @example Rendering a Rich Text field as plain text.
31
- *
32
- * ```jsx
33
- * <PrismicText field={document.data.content} />;
27
+ * ```tsx
28
+ * <PrismicText field={slice.primary.text} />;
34
29
  * ```
35
30
  *
36
- * @param props - Props for the component.
37
- *
38
- * @returns The Rich Text field's content as plain text.
39
- *
40
- * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
31
+ * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
41
32
  */
42
33
  export const PrismicText: FC<PrismicTextProps> = (props) => {
43
34
  const { field, fallback, separator } = props;
@@ -56,7 +47,7 @@ export const PrismicText: FC<PrismicTextProps> = (props) => {
56
47
  if (typeof props.field === "string") {
57
48
  if (DEV) {
58
49
  console.error(
59
- `[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
50
+ `[PrismicText] The "field" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
60
51
  "prismictext-works-only-with-rich-text-and-title-fields",
61
52
  )}`,
62
53
  props.field,
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { FC, useEffect } from "react";
3
+ import { type FC, useEffect } from "react";
4
4
  import { getToolbarSrc } from "@prismicio/client";
5
5
 
6
6
  /** Props for `<PrismicToolbar>`. */
@@ -13,8 +13,15 @@ export type PrismicToolbarProps = {
13
13
  };
14
14
 
15
15
  /**
16
- * React component that injects the Prismic Toolbar into the app. This component
17
- * can be placed anywhere in the React tree.
16
+ * Renders the Prismic Toolbar script to support draft previews.
17
+ *
18
+ * @example
19
+ *
20
+ * ```tsx
21
+ * <PrismicToolbar repositoryName="my-repo" />;
22
+ * ```
23
+ *
24
+ * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
18
25
  */
19
26
  export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
20
27
  const { repositoryName } = props;
package/src/SliceZone.tsx CHANGED
@@ -1,11 +1,11 @@
1
- import type { ComponentType, FC } from "react";
1
+ import type { ComponentType, FC, ReactNode } from "react";
2
2
  import type { Slice } from "@prismicio/client";
3
3
  import { DEV } from "esm-env";
4
4
 
5
5
  /**
6
6
  * Returns the type of a `SliceLike` type.
7
7
  *
8
- * @typeParam Slice - The Slice from which the type will be extracted.
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 Slice from the Prismic
18
- * Rest API V2 for the `unstable_mapSliceZone()` helper.
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 Slice.
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 Slice from the Prismic
29
- * GraphQL API for the `unstable_mapSliceZone()` helper.
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 Slice.
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 Slice for the
39
- * `unstable_mapSliceZone()` helper.
38
+ * The minimum required properties to represent a Prismic slice for the
39
+ * `mapSliceZone()` helper.
40
40
  *
41
- * If using Prismic's Rest API V2, use the `Slice` export from
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 Slice.
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 Slice has been modified from its original value using a
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 Rest API V2, use the `SliceZone` export from
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 Slice in the Slice Zone.
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 Slice using the
72
+ * React props for a component rendering content from a Prismic slice using the
73
73
  * `<SliceZone>` component.
74
74
  *
75
- * @typeParam TSlice - The Slice passed as a prop.
75
+ * @typeParam TSlice - The slice passed as a prop.
76
76
  * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
77
- * available to all Slice components.
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 Slice in the Slice Zone. */
86
+ /** The index of the slice in the slice zone. */
87
87
  index: number;
88
88
 
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
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 Slice types, it would include TSlice. This causes TypeScript to
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 Slice
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 Slice.
106
+ * A React component to be rendered for each instance of its slice.
107
107
  *
108
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
109
- * @typeParam TContext - Arbitrary data made available to all Slice components.
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 Slice types mapped to a React component. The component will be
119
- * rendered for each instance of its Slice.
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 Slice in the Slice Zone.
125
- * @typeParam TContext - Arbitrary data made available to all Slice components.
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 Slice types. <SliceZone> will render a default component if one is
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 Slice in the Slice Zone.
153
- * @typeParam TContext - Arbitrary data made available to all Slice components.
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 Slice data from the Slice Zone. */
156
+ /** List of slice data from the slice zone. */
157
157
  slices?: SliceZoneLike;
158
158
 
159
- /** A record mapping Slice types to React components. */
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 Slice components. */
170
+ /** Arbitrary data made available to all slice components. */
171
171
  context?: TContext;
172
172
  };
173
173
 
174
174
  /**
175
- * This Slice component can be used as a reminder to provide a proper
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
@@ -182,7 +182,7 @@ export const TODOSliceComponent = <TSlice extends SliceLike>({
182
182
  slice,
183
183
  }: {
184
184
  slice: TSlice;
185
- }) => {
185
+ }): ReactNode => {
186
186
  if (!DEV) {
187
187
  return null;
188
188
  }
@@ -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 Slice type "${type}"`,
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 Slice type &ldquo;{type}
199
+ Could not find a component for slice type &ldquo;{type}
200
200
  &rdquo;
201
201
  </section>
202
202
  );
203
203
  };
204
204
 
205
205
  /**
206
- * Renders content from a Prismic Slice Zone using React components for each
207
- * type of Slice.
206
+ * Renders slices in a slice zone as React components.
208
207
  *
209
- * If a component is not provided for a type of Slice, a default component can
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
- * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
214
- * @typeParam TContext - Arbitrary data made available to all Slice components.
210
+ * ```tsx
211
+ * <SliceZone slices={page.data.slices} components={components} />;
212
+ * ```
215
213
  *
216
- * @returns The Slice Zone's content as React components.
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 {
package/src/lib/devMsg.ts CHANGED
@@ -15,6 +15,6 @@ import { version } from "../../package.json";
15
15
  *
16
16
  * @returns The `prismic.dev/msg` URL for the given slug.
17
17
  */
18
- export function devMsg(slug: string) {
18
+ export function devMsg(slug: string): string {
19
19
  return `https://prismic.dev/msg/react/v${version}/${slug}`;
20
20
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Returns a `prismic.dev/msg` URL for a given message slug.
3
- *
4
- * @example
5
- *
6
- * ```ts
7
- * devMsg("missing-param");
8
- * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
9
- * ```
10
- *
11
- * @param slug - Slug for the message. This corresponds to a Markdown file in
12
- * the Git repository's `/messages` directory.
13
- *
14
- * @returns The `prismic.dev/msg` URL for the given slug.
15
- */
16
- export declare function devMsg(slug: string): string;
@@ -1,5 +0,0 @@
1
- const version = "3.2.1";
2
- export {
3
- version
4
- };
5
- //# sourceMappingURL=package.json.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}