@prismicio/react 3.4.0 → 3.4.1-canary.56c63d1

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/dist/PrismicImage.d.ts +20 -28
  2. package/dist/PrismicImage.d.ts.map +1 -1
  3. package/dist/PrismicImage.js +6 -8
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +18 -21
  6. package/dist/PrismicLink.d.ts.map +1 -1
  7. package/dist/PrismicLink.js +6 -9
  8. package/dist/PrismicLink.js.map +1 -1
  9. package/dist/PrismicRichText.d.ts +31 -37
  10. package/dist/PrismicRichText.d.ts.map +1 -1
  11. package/dist/PrismicRichText.js +5 -7
  12. package/dist/PrismicRichText.js.map +1 -1
  13. package/dist/PrismicTable.d.ts +15 -16
  14. package/dist/PrismicTable.d.ts.map +1 -1
  15. package/dist/PrismicTable.js +4 -6
  16. package/dist/PrismicTable.js.map +1 -1
  17. package/dist/PrismicText.d.ts +8 -11
  18. package/dist/PrismicText.d.ts.map +1 -1
  19. package/dist/PrismicText.js +4 -6
  20. package/dist/PrismicText.js.map +1 -1
  21. package/dist/PrismicToolbar.d.ts +11 -14
  22. package/dist/PrismicToolbar.d.ts.map +1 -1
  23. package/dist/PrismicToolbar.js +5 -8
  24. package/dist/PrismicToolbar.js.map +1 -1
  25. package/dist/SliceZone.d.ts +31 -51
  26. package/dist/SliceZone.d.ts.map +1 -1
  27. package/dist/SliceZone.js +7 -10
  28. package/dist/SliceZone.js.map +1 -1
  29. package/dist/index.js +1 -2
  30. package/dist/lib/devMsg.js +7 -10
  31. package/dist/lib/devMsg.js.map +1 -1
  32. package/dist/package.js +2 -2
  33. package/package.json +32 -34
  34. package/src/PrismicImage.tsx +107 -134
  35. package/src/PrismicLink.tsx +66 -76
  36. package/src/PrismicRichText.tsx +77 -85
  37. package/src/PrismicTable.tsx +41 -45
  38. package/src/PrismicText.tsx +20 -21
  39. package/src/PrismicToolbar.tsx +41 -45
  40. package/src/SliceZone.tsx +68 -108
  41. package/src/index.ts +15 -15
  42. package/src/lib/devMsg.ts +8 -10
@@ -1,25 +1,22 @@
1
1
  import { version } from "../package.js";
2
-
3
2
  //#region src/lib/devMsg.ts
4
3
  /**
5
4
  * Returns a `prismic.dev/msg` URL for a given message slug.
6
5
  *
7
6
  * @example
7
+ * ;```ts
8
+ * devMsg("missing-param");
9
+ * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
10
+ * ```
8
11
  *
9
- * ```ts
10
- * devMsg("missing-param");
11
- * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
12
- * ```
13
- *
14
- * @param slug - Slug for the message. This corresponds to a Markdown file in
15
- * the Git repository's `/messages` directory.
16
- *
12
+ * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
13
+ * `/messages` directory.
17
14
  * @returns The `prismic.dev/msg` URL for the given slug.
18
15
  */
19
16
  function devMsg(slug) {
20
17
  return `https://prismic.dev/msg/react/v${version}/${slug}`;
21
18
  }
22
-
23
19
  //#endregion
24
20
  export { devMsg };
21
+
25
22
  //# sourceMappingURL=devMsg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string): string {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,OAAO,MAAsB;AAC5C,QAAO,kCAAkC,QAAQ,GAAG"}
1
+ {"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\"\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n * \t;```ts\n * \tdevMsg(\"missing-param\");\n * \t// => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * \t```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's\n * `/messages` directory.\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string): string {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,OAAO,MAAsB;AAC5C,QAAO,kCAAkC,QAAQ,GAAG"}
package/dist/package.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region package.json
2
- var version = "3.4.0";
3
-
2
+ var version = "3.4.1-canary.56c63d1";
4
3
  //#endregion
5
4
  export { version };
5
+
6
6
  //# sourceMappingURL=package.js.map
package/package.json CHANGED
@@ -1,24 +1,28 @@
1
1
  {
2
2
  "name": "@prismicio/react",
3
- "version": "3.4.0",
3
+ "version": "3.4.1-canary.56c63d1",
4
4
  "description": "React components and hooks to fetch and present Prismic content",
5
5
  "keywords": [
6
- "typescript",
7
6
  "prismic",
8
- "react"
7
+ "react",
8
+ "typescript"
9
9
  ],
10
+ "license": "Apache-2.0",
11
+ "author": "Prismic <contact@prismic.io> (https://prismic.io)",
10
12
  "repository": {
11
13
  "type": "git",
12
14
  "url": "git+https://github.com/prismicio/prismic-react.git"
13
15
  },
14
- "license": "Apache-2.0",
15
- "author": "Prismic <contact@prismic.io> (https://prismic.io)",
16
- "sideEffects": false,
16
+ "workspaces": [
17
+ ".",
18
+ "e2e-projects/*"
19
+ ],
20
+ "files": [
21
+ "./dist",
22
+ "./src"
23
+ ],
17
24
  "type": "module",
18
- "exports": {
19
- ".": "./dist/index.js",
20
- "./package.json": "./package.json"
21
- },
25
+ "sideEffects": false,
22
26
  "types": "./dist/index.d.ts",
23
27
  "typesVersions": {
24
28
  "*": {
@@ -27,20 +31,19 @@
27
31
  ]
28
32
  }
29
33
  },
30
- "files": [
31
- "dist",
32
- "src"
33
- ],
34
- "workspaces": [
35
- ".",
36
- "e2e-projects/*"
37
- ],
34
+ "exports": {
35
+ ".": "./dist/index.js",
36
+ "./package.json": "./package.json"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
38
41
  "scripts": {
39
42
  "build": "tsdown",
40
43
  "dev": "tsdown --watch",
41
44
  "e2e": "playwright test",
42
45
  "e2e:ui": "npm run e2e -- --ui",
43
- "format": "prettier --write .",
46
+ "format": "oxfmt",
44
47
  "lint": "oxlint --deny-warnings",
45
48
  "prepare": "npm run build",
46
49
  "test": "npm run lint && npm run types && npm run build && npm run e2e",
@@ -50,20 +53,18 @@
50
53
  "esm-env": "^1.2.2"
51
54
  },
52
55
  "devDependencies": {
53
- "@playwright/test": "^1.57.0",
56
+ "@playwright/test": "^1.59.1",
54
57
  "@prismicio/client": "^7.17.0",
55
- "@trivago/prettier-plugin-sort-imports": "^6.0.2",
56
- "@types/react": "^19.2.8",
58
+ "@types/react": "^19.2.14",
57
59
  "@types/react-dom": "^19.2.3",
58
- "dotenv": "^17.2.3",
59
- "oxlint": "^1.39.0",
60
- "playwright": "^1.57.0",
61
- "prettier": "^3.7.4",
62
- "prettier-plugin-jsdoc": "^1.8.0",
63
- "react": "^19.2.1",
64
- "react-dom": "^19.2.3",
65
- "tsdown": "^0.19.0",
66
- "typescript": "^5.9.3"
60
+ "dotenv": "^17.4.0",
61
+ "oxfmt": "^0.43.0",
62
+ "oxlint": "^1.58.0",
63
+ "playwright": "^1.59.1",
64
+ "react": "^19.2.4",
65
+ "react-dom": "^19.2.4",
66
+ "tsdown": "^0.21.7",
67
+ "typescript": "^6.0.2"
67
68
  },
68
69
  "peerDependencies": {
69
70
  "@prismicio/client": "^7",
@@ -71,8 +72,5 @@
71
72
  },
72
73
  "engines": {
73
74
  "node": ">=20"
74
- },
75
- "publishConfig": {
76
- "access": "public"
77
75
  }
78
76
  }
@@ -1,194 +1,167 @@
1
- import {
2
- type ForwardedRef,
3
- forwardRef,
4
- type ComponentProps,
5
- type FC,
6
- type ReactNode,
7
- } from "react";
8
1
  import {
9
2
  type ImageFieldImage,
10
3
  asImagePixelDensitySrcSet,
11
4
  asImageWidthSrcSet,
12
5
  isFilled,
13
- } from "@prismicio/client";
14
- import { DEV } from "esm-env";
6
+ } from "@prismicio/client"
7
+ import { DEV } from "esm-env"
8
+ import { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from "react"
15
9
 
16
- import { devMsg } from "./lib/devMsg.js";
10
+ import { devMsg } from "./lib/devMsg.js"
17
11
 
18
- type ImgixURLParams = Omit<
19
- NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>,
20
- "widths"
21
- > &
22
- Omit<
23
- NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>,
24
- "pixelDensities"
25
- >;
12
+ type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> &
13
+ Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">
26
14
 
27
15
  /** Props for `<PrismicImage>`. */
28
- export type PrismicImageProps = Omit<
29
- ComponentProps<"img">,
30
- "src" | "srcset" | "alt"
31
- > & {
16
+ export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
32
17
  /** The Prismic image field or thumbnail to render. */
33
- field: ImageFieldImage | null | undefined;
18
+ field: ImageFieldImage | null | undefined
34
19
 
35
20
  /**
36
21
  * An object of Imgix URL API parameters to transform the image.
37
22
  *
38
23
  * See: https://docs.imgix.com/apis/rendering
39
24
  */
40
- imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
25
+ imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }
41
26
 
42
27
  /**
43
28
  * Declare an image as decorative by providing `alt=""`.
44
29
  *
45
- * See:
46
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
30
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
47
31
  */
48
- alt?: "";
32
+ alt?: ""
49
33
 
50
34
  /**
51
- * Declare an image as decorative only if the image field does not have
52
- * alternative text by providing `fallbackAlt=""`.
35
+ * Declare an image as decorative only if the image field does not have alternative text by
36
+ * providing `fallbackAlt=""`.
53
37
  *
54
- * See:
55
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
38
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
56
39
  */
57
- fallbackAlt?: "";
40
+ fallbackAlt?: ""
58
41
 
59
42
  /**
60
- * The value to be rendered when the field is empty. If a fallback is not
61
- * given, `null` will be rendered.
43
+ * The value to be rendered when the field is empty. If a fallback is not given, `null` will be
44
+ * rendered.
62
45
  */
63
- fallback?: ReactNode;
46
+ fallback?: ReactNode
64
47
  } & (
65
48
  | {
66
49
  /**
67
- * Widths (in pixels) used to build a `srcset` value for the image
68
- * field.
50
+ * Widths (in pixels) used to build a `srcset` value for the image field.
69
51
  *
70
- * If omitted or set to `"defaults"`, the following widths will be used:
71
- * 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
52
+ * If omitted or set to `"defaults"`, the following widths will be used: 640, 750, 828,
53
+ * 1080, 1200, 1920, 2048, 3840.
72
54
  *
73
- * If the image field contains responsive views, each responsive view
74
- * can be used as a width in the resulting `srcset` by passing
75
- * `"thumbnails"` as the `widths` prop.
55
+ * If the image field contains responsive views, each responsive view can be used as a width
56
+ * in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop.
76
57
  */
77
- widths?:
78
- | NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"]
79
- | "defaults";
58
+ widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"
80
59
  /** Not used when the `widths` prop is used. */
81
- pixelDensities?: never;
60
+ pixelDensities?: never
82
61
  }
83
62
  | {
84
63
  /** Not used when the `widths` prop is used. */
85
- widths?: never;
64
+ widths?: never
86
65
  /**
87
66
  * Pixel densities used to build a `srcset` value for the image field.
88
67
  *
89
- * If a `pixelDensities` prop is passed `"defaults"`, the following
90
- * pixel densities will be used: 1, 2, 3.
68
+ * If a `pixelDensities` prop is passed `"defaults"`, the following pixel densities will be
69
+ * used: 1, 2, 3.
91
70
  */
92
71
  pixelDensities:
93
- | NonNullable<
94
- Parameters<typeof asImagePixelDensitySrcSet>[1]
95
- >["pixelDensities"]
96
- | "defaults";
72
+ | NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"]
73
+ | "defaults"
97
74
  }
98
- );
75
+ )
99
76
 
100
77
  /**
101
78
  * Renders an optimized image from a Prismic image field.
102
79
  *
103
80
  * @example
104
- *
105
- * ```tsx
106
- * <PrismicImage field={slice.primary.photo} />;
107
- * ```
81
+ * ;```tsx
82
+ * <PrismicImage field={slice.primary.photo} />;
83
+ * ```
108
84
  *
109
85
  * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
110
86
  */
111
- export const PrismicImage: FC<PrismicImageProps> = forwardRef(
112
- function PrismicImage(
113
- props: PrismicImageProps,
114
- ref: ForwardedRef<HTMLImageElement>,
115
- ) {
116
- const {
117
- field,
118
- alt,
119
- fallbackAlt,
120
- imgixParams = {},
121
- widths,
122
- pixelDensities,
123
- fallback,
124
- ...restProps
125
- } = props;
126
-
127
- if (DEV) {
128
- if (typeof alt === "string" && alt !== "") {
129
- console.warn(
130
- `[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
131
- "alt-must-be-an-empty-string",
132
- )}`,
133
- );
134
- }
135
-
136
- if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
137
- console.warn(
138
- `[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg(
139
- "alt-must-be-an-empty-string",
140
- )}`,
141
- );
142
- }
143
-
144
- if (widths && pixelDensities) {
145
- console.warn(
146
- `[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`,
147
- );
148
- }
87
+ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicImage(
88
+ props: PrismicImageProps,
89
+ ref: ForwardedRef<HTMLImageElement>,
90
+ ) {
91
+ const {
92
+ field,
93
+ alt,
94
+ fallbackAlt,
95
+ imgixParams = {},
96
+ widths,
97
+ pixelDensities,
98
+ fallback,
99
+ ...restProps
100
+ } = props
101
+
102
+ if (DEV) {
103
+ if (typeof alt === "string" && alt !== "") {
104
+ console.warn(
105
+ `[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
106
+ "alt-must-be-an-empty-string",
107
+ )}`,
108
+ )
149
109
  }
150
110
 
151
- if (!isFilled.imageThumbnail(field)) {
152
- return <>{fallback}</>;
111
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
112
+ console.warn(
113
+ `[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg(
114
+ "alt-must-be-an-empty-string",
115
+ )}`,
116
+ )
153
117
  }
154
118
 
155
- const resolvedImgixParams = imgixParams;
156
- for (const x in imgixParams) {
157
- if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
158
- resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;
159
- }
119
+ if (widths && pixelDensities) {
120
+ console.warn(
121
+ `[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`,
122
+ )
160
123
  }
124
+ }
161
125
 
162
- let src: string | undefined;
163
- let srcSet: string | undefined;
164
-
165
- if (widths || !pixelDensities) {
166
- const res = asImageWidthSrcSet(field, {
167
- ...resolvedImgixParams,
168
- widths: widths === "defaults" ? undefined : widths,
169
- } as ImgixURLParams);
126
+ if (!isFilled.imageThumbnail(field)) {
127
+ return <>{fallback}</>
128
+ }
170
129
 
171
- src = res.src;
172
- srcSet = res.srcset;
173
- } else if (pixelDensities) {
174
- const res = asImagePixelDensitySrcSet(field, {
175
- ...resolvedImgixParams,
176
- pixelDensities:
177
- pixelDensities === "defaults" ? undefined : pixelDensities,
178
- } as ImgixURLParams);
179
-
180
- src = res.src;
181
- srcSet = res.srcset;
130
+ const resolvedImgixParams = imgixParams
131
+ for (const x in imgixParams) {
132
+ if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
133
+ resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
182
134
  }
183
-
184
- return (
185
- <img
186
- ref={ref}
187
- src={src}
188
- srcSet={srcSet}
189
- alt={alt ?? (field.alt || fallbackAlt)}
190
- {...restProps}
191
- />
192
- );
193
- },
194
- );
135
+ }
136
+
137
+ let src: string | undefined
138
+ let srcSet: string | undefined
139
+
140
+ if (widths || !pixelDensities) {
141
+ const res = asImageWidthSrcSet(field, {
142
+ ...resolvedImgixParams,
143
+ widths: widths === "defaults" ? undefined : widths,
144
+ } as ImgixURLParams)
145
+
146
+ src = res.src
147
+ srcSet = res.srcset
148
+ } else if (pixelDensities) {
149
+ const res = asImagePixelDensitySrcSet(field, {
150
+ ...resolvedImgixParams,
151
+ pixelDensities: pixelDensities === "defaults" ? undefined : pixelDensities,
152
+ } as ImgixURLParams)
153
+
154
+ src = res.src
155
+ srcSet = res.srcset
156
+ }
157
+
158
+ return (
159
+ <img
160
+ ref={ref}
161
+ src={src}
162
+ srcSet={srcSet}
163
+ alt={alt ?? (field.alt || fallbackAlt)}
164
+ {...restProps}
165
+ />
166
+ )
167
+ })