@prismicio/react 3.4.0-pr.257.68f2f80 → 3.4.0-pr.257.71ee28e

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