@prismicio/react 3.4.1 → 3.4.2-canary.c2e05c8

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 (42) hide show
  1. package/README.md +6 -0
  2. package/dist/PrismicImage.d.ts +10 -9
  3. package/dist/PrismicImage.d.ts.map +1 -1
  4. package/dist/PrismicImage.js +3 -3
  5. package/dist/PrismicImage.js.map +1 -1
  6. package/dist/PrismicLink.d.ts +6 -7
  7. package/dist/PrismicLink.d.ts.map +1 -1
  8. package/dist/PrismicLink.js +4 -3
  9. package/dist/PrismicLink.js.map +1 -1
  10. package/dist/PrismicRichText.d.ts +8 -9
  11. package/dist/PrismicRichText.d.ts.map +1 -1
  12. package/dist/PrismicRichText.js +1 -1
  13. package/dist/PrismicRichText.js.map +1 -1
  14. package/dist/PrismicTable.d.ts +5 -6
  15. package/dist/PrismicTable.d.ts.map +1 -1
  16. package/dist/PrismicTable.js +1 -1
  17. package/dist/PrismicTable.js.map +1 -1
  18. package/dist/PrismicText.d.ts +7 -7
  19. package/dist/PrismicText.d.ts.map +1 -1
  20. package/dist/PrismicText.js +1 -1
  21. package/dist/PrismicText.js.map +1 -1
  22. package/dist/PrismicToolbar.d.ts +3 -5
  23. package/dist/PrismicToolbar.d.ts.map +1 -1
  24. package/dist/PrismicToolbar.js +5 -3
  25. package/dist/PrismicToolbar.js.map +1 -1
  26. package/dist/SliceZone.d.ts +25 -21
  27. package/dist/SliceZone.d.ts.map +1 -1
  28. package/dist/SliceZone.js +4 -3
  29. package/dist/SliceZone.js.map +1 -1
  30. package/dist/lib/devMsg.js +1 -1
  31. package/dist/lib/devMsg.js.map +1 -1
  32. package/dist/package.js +1 -1
  33. package/package.json +17 -16
  34. package/src/PrismicImage.tsx +34 -34
  35. package/src/PrismicLink.tsx +43 -43
  36. package/src/PrismicRichText.tsx +43 -43
  37. package/src/PrismicTable.tsx +29 -29
  38. package/src/PrismicText.tsx +16 -16
  39. package/src/PrismicToolbar.tsx +32 -30
  40. package/src/SliceZone.tsx +41 -41
  41. package/src/index.ts +15 -15
  42. package/src/lib/devMsg.ts +3 -3
@@ -1,7 +1,7 @@
1
- "use client";
1
+ "use client"
2
2
 
3
- import { getToolbarSrc } from "@prismicio/client";
4
- import { type FC, useEffect, useRef } from "react";
3
+ import { getToolbarSrc } from "@prismicio/client"
4
+ import { type FC, useEffect, useRef } from "react"
5
5
 
6
6
  /** Props for `<PrismicToolbar>`. */
7
7
  export type PrismicToolbarProps = {
@@ -9,7 +9,7 @@ export type PrismicToolbarProps = {
9
9
  * The name of the Prismic repository. For example, `"my-repo"` if the repository URL is
10
10
  * `my-repo.prismic.io`.
11
11
  */
12
- repositoryName: string;
12
+ repositoryName: string
13
13
 
14
14
  /**
15
15
  * Called when the Prismic toolbar triggers a preview update. This happens when the previewed
@@ -19,7 +19,7 @@ export type PrismicToolbarProps = {
19
19
  *
20
20
  * The default page reload behavior can be cancelled with `event.preventDefault()`.
21
21
  */
22
- onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void;
22
+ onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void
23
23
 
24
24
  /**
25
25
  * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is
@@ -27,67 +27,69 @@ export type PrismicToolbarProps = {
27
27
  *
28
28
  * The default page reload behavior can be cancelled with `event.preventDefault()`.
29
29
  */
30
- onPreviewEnd?: (event: CustomEvent<null>) => void;
31
- };
30
+ onPreviewEnd?: (event: CustomEvent<null>) => void
31
+ }
32
32
 
33
33
  /**
34
34
  * Renders the Prismic Toolbar script to support draft previews.
35
35
  *
36
36
  * @example
37
- * ```tsx
37
+ * ;```tsx
38
38
  * <PrismicToolbar repositoryName="my-repo" />;
39
39
  * ```
40
40
  *
41
41
  * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
42
42
  */
43
43
  export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
44
- const { repositoryName, onPreviewUpdate, onPreviewEnd } = props;
44
+ const { repositoryName, onPreviewUpdate, onPreviewEnd } = props
45
45
 
46
- const src = getToolbarSrc(repositoryName);
46
+ const src = getToolbarSrc(repositoryName)
47
47
 
48
- const onPreviewUpdateRef = useRef(onPreviewUpdate);
49
- onPreviewUpdateRef.current = onPreviewUpdate;
48
+ const onPreviewUpdateRef = useRef(onPreviewUpdate)
49
+ const onPreviewEndRef = useRef(onPreviewEnd)
50
50
 
51
- const onPreviewEndRef = useRef(onPreviewEnd);
52
- onPreviewEndRef.current = onPreviewEnd;
51
+ useEffect(() => {
52
+ onPreviewUpdateRef.current = onPreviewUpdate
53
+ onPreviewEndRef.current = onPreviewEnd
54
+ })
53
55
 
54
56
  useEffect(() => {
55
- const existingScript = document.querySelector(`script[src="${src}"]`);
57
+ const existingScript = document.querySelector(`script[src="${src}"]`)
56
58
 
57
59
  if (!existingScript) {
58
- const script = document.createElement("script");
59
- script.src = src;
60
- script.defer = true;
60
+ const script = document.createElement("script")
61
+ script.src = src
62
+ script.defer = true
61
63
 
62
64
  // Used to distinguish the toolbar element from other elements.
63
- script.dataset.prismicToolbar = "";
64
- script.dataset.repositoryName = repositoryName;
65
+ script.dataset.prismicToolbar = ""
66
+ script.dataset.repositoryName = repositoryName
65
67
 
66
68
  // Disable Happy DOM `<script>` evaluation during tests.
67
69
  // @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.
68
- script._evaluateScript = false;
70
+ script._evaluateScript = false
69
71
 
70
- document.body.appendChild(script);
72
+ document.body.appendChild(script)
71
73
  }
72
- }, [repositoryName, src]);
74
+ }, [repositoryName, src])
73
75
 
74
76
  useEffect(() => {
75
- const controller = new AbortController();
77
+ const controller = new AbortController()
76
78
 
77
79
  window.addEventListener(
78
80
  "prismicPreviewUpdate",
79
81
  (event) => onPreviewUpdateRef.current?.(event as CustomEvent<{ ref: string }>),
80
82
  { signal: controller.signal },
81
- );
83
+ )
82
84
 
83
85
  window.addEventListener(
84
86
  "prismicPreviewEnd",
85
87
  (event) => onPreviewEndRef.current?.(event as CustomEvent<null>),
86
88
  { signal: controller.signal },
87
- );
89
+ )
88
90
 
89
- return () => controller.abort();
90
- }, []);
91
+ return () => controller.abort()
92
+ }, [])
91
93
 
92
- return null;
93
- };
94
+ return null
95
+ }
package/src/SliceZone.tsx CHANGED
@@ -1,6 +1,6 @@
1
- import type { Slice } from "@prismicio/client";
2
- import { DEV } from "esm-env";
3
- import type { ComponentType, FC, ReactNode } from "react";
1
+ import type { Slice } from "@prismicio/client"
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.
@@ -11,7 +11,7 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
11
11
  ? TSlice["slice_type"]
12
12
  : TSlice extends SliceLikeGraphQL
13
13
  ? TSlice["type"]
14
- : never;
14
+ : never
15
15
 
16
16
  /**
17
17
  * The minimum required properties to represent a Prismic slice from the Prismic Content API for the
@@ -22,7 +22,7 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice
22
22
  export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
23
23
  Slice<TSliceType>,
24
24
  "id" | "slice_type"
25
- >;
25
+ >
26
26
 
27
27
  /**
28
28
  * The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the
@@ -31,8 +31,8 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
31
31
  * @typeParam SliceType - Type name of the slice.
32
32
  */
33
33
  export type SliceLikeGraphQL<TSliceType extends string = string> = {
34
- type: Slice<TSliceType>["slice_type"];
35
- };
34
+ type: Slice<TSliceType>["slice_type"]
35
+ }
36
36
 
37
37
  /**
38
38
  * The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper.
@@ -52,8 +52,8 @@ export type SliceLike<TSliceType extends string = string> = (
52
52
  *
53
53
  * @internal
54
54
  */
55
- __mapped?: true;
56
- };
55
+ __mapped?: true
56
+ }
57
57
 
58
58
  /**
59
59
  * A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.
@@ -63,7 +63,7 @@ export type SliceLike<TSliceType extends string = string> = (
63
63
  *
64
64
  * @typeParam TSlice - The type(s) of a slice in the slice zone.
65
65
  */
66
- export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
66
+ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[]
67
67
 
68
68
  /**
69
69
  * React props for a component rendering content from a Prismic slice using the `<SliceZone>`
@@ -75,21 +75,21 @@ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlic
75
75
  */
76
76
  export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
77
77
  /** Slice data for this component. */
78
- slice: TSlice;
78
+ slice: TSlice
79
79
 
80
80
  /** The index of the slice in the slice zone. */
81
- index: number;
81
+ index: number
82
82
 
83
83
  /** All slices from the slice zone to which the slice belongs. */
84
84
  // TODO: We have to keep this list of slices general due to circular
85
85
  // reference limtiations. If we had another generic to determine the full
86
86
  // union of slice types, it would include TSlice. This causes TypeScript to
87
87
  // throw a compilation error.
88
- slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
88
+ slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>
89
89
 
90
90
  /** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
91
- context: TContext;
92
- };
91
+ context: TContext
92
+ }
93
93
 
94
94
  /**
95
95
  * A React component to be rendered for each instance of its slice.
@@ -101,7 +101,7 @@ export type SliceComponentType<
101
101
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
102
  TSlice extends SliceLike = any,
103
103
  TContext = unknown,
104
- > = ComponentType<SliceComponentProps<TSlice, TContext>>;
104
+ > = ComponentType<SliceComponentProps<TSlice, TContext>>
105
105
 
106
106
  /**
107
107
  * A record of slice types mapped to a React component. The component will be rendered for each
@@ -128,8 +128,8 @@ export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext =
128
128
  ? SliceLike
129
129
  : Extract<TSlice, SliceLike<SliceType>>,
130
130
  TContext
131
- >;
132
- };
131
+ >
132
+ }
133
133
 
134
134
  /**
135
135
  * React props for the `<SliceZone>` component.
@@ -139,19 +139,19 @@ export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext =
139
139
  */
140
140
  export type SliceZoneProps<TContext = unknown> = {
141
141
  /** List of slice data from the slice zone. */
142
- slices?: SliceZoneLike;
142
+ slices?: SliceZoneLike
143
143
 
144
144
  /** A record mapping slice types to React components. */
145
145
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
- components?: Record<string, ComponentType<any>>;
146
+ components?: Record<string, ComponentType<any>>
147
147
 
148
148
  /** The React component rendered if a component mapping from the `components` prop cannot be found. */
149
149
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
- defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
150
+ defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>
151
151
 
152
152
  /** Arbitrary data made available to all slice components. */
153
- context?: TContext;
154
- };
153
+ context?: TContext
154
+ }
155
155
 
156
156
  /**
157
157
  * This slice component can be used as a reminder to provide a proper implementation.
@@ -162,56 +162,56 @@ export type SliceZoneProps<TContext = unknown> = {
162
162
  export const TODOSliceComponent = <TSlice extends SliceLike>({
163
163
  slice,
164
164
  }: {
165
- slice: TSlice;
165
+ slice: TSlice
166
166
  }): ReactNode => {
167
167
  if (!DEV) {
168
- return null;
168
+ return null
169
169
  }
170
170
 
171
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
171
+ const type = "slice_type" in slice ? slice.slice_type : slice.type
172
172
 
173
- console.warn(`[SliceZone] Could not find a component for slice type "${type}"`, slice);
173
+ console.warn(`[SliceZone] Could not find a component for slice type "${type}"`, slice)
174
174
 
175
175
  return (
176
176
  <section data-slice-zone-todo-component="" data-slice-type={type}>
177
177
  Could not find a component for slice type &ldquo;{type}
178
178
  &rdquo;
179
179
  </section>
180
- );
181
- };
180
+ )
181
+ }
182
182
 
183
183
  /**
184
184
  * Renders slices in a slice zone as React components.
185
185
  *
186
186
  * @example
187
- * ```tsx
187
+ * ;```tsx
188
188
  * <SliceZone slices={page.data.slices} components={components} />;
189
189
  * ```
190
190
  *
191
191
  * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
192
192
  */
193
193
  export const SliceZone: FC<SliceZoneProps> = (props) => {
194
- const { slices = [], components = {}, defaultComponent, context = {} } = props;
194
+ const { slices = [], components = {}, defaultComponent, context = {} } = props
195
195
 
196
196
  const renderedSlices = slices.map((slice, index) => {
197
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
197
+ const type = "slice_type" in slice ? slice.slice_type : slice.type
198
198
 
199
- const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
199
+ const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`
200
200
 
201
- const Comp = components[type as keyof typeof components] || defaultComponent;
201
+ const Comp = components[type as keyof typeof components] || defaultComponent
202
202
 
203
203
  if (!Comp) {
204
- return <TODOSliceComponent key={key} slice={slice} />;
204
+ return <TODOSliceComponent key={key} slice={slice} />
205
205
  }
206
206
 
207
207
  if (slice.__mapped) {
208
- const { __mapped, ...mappedProps } = slice;
208
+ const { __mapped, ...mappedProps } = slice
209
209
 
210
- return <Comp key={key} {...mappedProps} />;
210
+ return <Comp key={key} {...mappedProps} />
211
211
  }
212
212
 
213
- return <Comp key={key} slice={slice} index={index} slices={slices} context={context} />;
214
- });
213
+ return <Comp key={key} slice={slice} index={index} slices={slices} context={context} />
214
+ })
215
215
 
216
- return <>{renderedSlices}</>;
217
- };
216
+ return <>{renderedSlices}</>
217
+ }
package/src/index.ts CHANGED
@@ -1,26 +1,26 @@
1
- export { PrismicLink } from "./PrismicLink.js";
2
- export type { PrismicLinkProps, LinkProps } from "./PrismicLink.js";
1
+ export { PrismicLink } from "./PrismicLink.js"
2
+ export type { PrismicLinkProps, LinkProps } from "./PrismicLink.js"
3
3
 
4
- export { PrismicTable } from "./PrismicTable.js";
5
- export type { PrismicTableProps } from "./PrismicTable.js";
4
+ export { PrismicTable } from "./PrismicTable.js"
5
+ export type { PrismicTableProps } from "./PrismicTable.js"
6
6
 
7
- export { PrismicText } from "./PrismicText.js";
8
- export type { PrismicTextProps } from "./PrismicText.js";
7
+ export { PrismicText } from "./PrismicText.js"
8
+ export type { PrismicTextProps } from "./PrismicText.js"
9
9
 
10
- export { PrismicRichText } from "./PrismicRichText.js";
10
+ export { PrismicRichText } from "./PrismicRichText.js"
11
11
  export type {
12
12
  PrismicRichTextProps,
13
13
  RichTextComponents,
14
14
  JSXMapSerializer,
15
15
  JSXFunctionSerializer,
16
- } from "./PrismicRichText.js";
16
+ } from "./PrismicRichText.js"
17
17
 
18
- export { Element } from "@prismicio/client/richtext";
18
+ export { Element } from "@prismicio/client/richtext"
19
19
 
20
- export { PrismicImage } from "./PrismicImage.js";
21
- export type { PrismicImageProps } from "./PrismicImage.js";
20
+ export { PrismicImage } from "./PrismicImage.js"
21
+ export type { PrismicImageProps } from "./PrismicImage.js"
22
22
 
23
- export { SliceZone, TODOSliceComponent } from "./SliceZone.js";
23
+ export { SliceZone, TODOSliceComponent } from "./SliceZone.js"
24
24
  export type {
25
25
  SliceComponentProps,
26
26
  SliceComponentType,
@@ -30,7 +30,7 @@ export type {
30
30
  SliceZoneComponents,
31
31
  SliceZoneLike,
32
32
  SliceZoneProps,
33
- } from "./SliceZone.js";
33
+ } from "./SliceZone.js"
34
34
 
35
- export { PrismicToolbar } from "./PrismicToolbar.js";
36
- export type { PrismicToolbarProps } from "./PrismicToolbar.js";
35
+ export { PrismicToolbar } from "./PrismicToolbar.js"
36
+ export type { PrismicToolbarProps } from "./PrismicToolbar.js"
package/src/lib/devMsg.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { version } from "../../package.json";
1
+ import { version } from "../../package.json"
2
2
 
3
3
  /**
4
4
  * Returns a `prismic.dev/msg` URL for a given message slug.
5
5
  *
6
6
  * @example
7
- * ```ts
7
+ * ;```ts
8
8
  * devMsg("missing-param");
9
9
  * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
10
10
  * ```
@@ -14,5 +14,5 @@ import { version } from "../../package.json";
14
14
  * @returns The `prismic.dev/msg` URL for the given slug.
15
15
  */
16
16
  export function devMsg(slug: string): string {
17
- return `https://prismic.dev/msg/react/v${version}/${slug}`;
17
+ return `https://prismic.dev/msg/react/v${version}/${slug}`
18
18
  }