@prismicio/react 3.2.2-pr.241.0f293b1 → 3.2.2-pr.242.afe79ea

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 (70) hide show
  1. package/dist/index.d.ts +9 -15
  2. package/dist/index.js +9 -19
  3. package/dist/package.js +6 -0
  4. package/dist/package.js.map +1 -0
  5. package/dist/src/PrismicImage.d.ts +76 -0
  6. package/dist/src/PrismicImage.d.ts.map +1 -0
  7. package/dist/src/PrismicImage.js +57 -0
  8. package/dist/src/PrismicImage.js.map +1 -0
  9. package/dist/src/PrismicLink.d.ts +84 -0
  10. package/dist/src/PrismicLink.d.ts.map +1 -0
  11. package/dist/src/PrismicLink.js +66 -0
  12. package/dist/src/PrismicLink.js.map +1 -0
  13. package/dist/src/PrismicRichText.d.ts +96 -0
  14. package/dist/src/PrismicRichText.d.ts.map +1 -0
  15. package/dist/src/PrismicRichText.js +133 -0
  16. package/dist/src/PrismicRichText.js.map +1 -0
  17. package/dist/src/PrismicTable.d.ts +69 -0
  18. package/dist/src/PrismicTable.d.ts.map +1 -0
  19. package/dist/src/PrismicTable.js +75 -0
  20. package/dist/src/PrismicTable.js.map +1 -0
  21. package/dist/src/PrismicText.d.ts +31 -0
  22. package/dist/src/PrismicText.d.ts.map +1 -0
  23. package/dist/src/PrismicText.js +33 -0
  24. package/dist/src/PrismicText.js.map +1 -0
  25. package/dist/src/PrismicToolbar.d.ts +26 -0
  26. package/dist/src/PrismicToolbar.d.ts.map +1 -0
  27. package/dist/src/PrismicToolbar.js +37 -0
  28. package/dist/src/PrismicToolbar.js.map +1 -0
  29. package/dist/{SliceZone.d.ts → src/SliceZone.d.ts} +52 -47
  30. package/dist/src/SliceZone.d.ts.map +1 -0
  31. package/dist/src/SliceZone.js +59 -0
  32. package/dist/src/SliceZone.js.map +1 -0
  33. package/dist/src/lib/devMsg.js +25 -0
  34. package/dist/src/lib/devMsg.js.map +1 -0
  35. package/package.json +17 -35
  36. package/src/PrismicImage.tsx +3 -3
  37. package/src/PrismicLink.tsx +5 -5
  38. package/src/PrismicRichText.tsx +11 -16
  39. package/src/PrismicTable.tsx +9 -9
  40. package/src/PrismicText.tsx +2 -2
  41. package/src/PrismicToolbar.tsx +1 -1
  42. package/src/SliceZone.tsx +2 -2
  43. package/src/index.ts +0 -1
  44. package/src/lib/devMsg.ts +1 -1
  45. package/dist/PrismicImage.d.ts +0 -74
  46. package/dist/PrismicImage.js +0 -50
  47. package/dist/PrismicImage.js.map +0 -1
  48. package/dist/PrismicLink.d.ts +0 -88
  49. package/dist/PrismicLink.js +0 -47
  50. package/dist/PrismicLink.js.map +0 -1
  51. package/dist/PrismicRichText.d.ts +0 -94
  52. package/dist/PrismicRichText.js +0 -79
  53. package/dist/PrismicRichText.js.map +0 -1
  54. package/dist/PrismicTable.d.ts +0 -65
  55. package/dist/PrismicTable.js +0 -28
  56. package/dist/PrismicTable.js.map +0 -1
  57. package/dist/PrismicText.d.ts +0 -26
  58. package/dist/PrismicText.js +0 -26
  59. package/dist/PrismicText.js.map +0 -1
  60. package/dist/PrismicToolbar.d.ts +0 -21
  61. package/dist/PrismicToolbar.js +0 -24
  62. package/dist/PrismicToolbar.js.map +0 -1
  63. package/dist/SliceZone.js +0 -32
  64. package/dist/SliceZone.js.map +0 -1
  65. package/dist/index.js.map +0 -1
  66. package/dist/lib/devMsg.d.ts +0 -16
  67. package/dist/lib/devMsg.js +0 -8
  68. package/dist/lib/devMsg.js.map +0 -1
  69. package/dist/package.json.js +0 -5
  70. package/dist/package.json.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,15 +1,9 @@
1
- export { PrismicLink } from "./PrismicLink.js";
2
- export type { PrismicLinkProps, LinkProps } from "./PrismicLink.js";
3
- export { PrismicTable } from "./PrismicTable.js";
4
- export type { PrismicTableProps } from "./PrismicTable.js";
5
- export { PrismicText } from "./PrismicText.js";
6
- export type { PrismicTextProps } from "./PrismicText.js";
7
- export { PrismicRichText } from "./PrismicRichText.js";
8
- export type { PrismicRichTextProps, RichTextComponents, JSXMapSerializer, JSXFunctionSerializer, } from "./PrismicRichText.js";
9
- export { Element } from "@prismicio/client/richtext";
10
- export { PrismicImage } from "./PrismicImage.js";
11
- export type { PrismicImageProps } from "./PrismicImage.js";
12
- export { SliceZone, TODOSliceComponent } from "./SliceZone.js";
13
- export type { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZoneComponents, SliceZoneLike, SliceZoneProps, } from "./SliceZone.js";
14
- export { PrismicToolbar } from "./PrismicToolbar.js";
15
- export type { PrismicToolbarProps } from "./PrismicToolbar.js";
1
+ import { LinkProps, PrismicLink, PrismicLinkProps } from "./src/PrismicLink.js";
2
+ import { JSXFunctionSerializer, JSXMapSerializer, PrismicRichText, PrismicRichTextProps } from "./src/PrismicRichText.js";
3
+ import { PrismicTable, PrismicTableProps } from "./src/PrismicTable.js";
4
+ import { PrismicText, PrismicTextProps } from "./src/PrismicText.js";
5
+ import { PrismicImage, PrismicImageProps } from "./src/PrismicImage.js";
6
+ import { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, TODOSliceComponent } from "./src/SliceZone.js";
7
+ import { PrismicToolbar, PrismicToolbarProps } from "./src/PrismicToolbar.js";
8
+ import { Element } from "@prismicio/client/richtext";
9
+ export { Element, type JSXFunctionSerializer, type JSXMapSerializer, type LinkProps, PrismicImage, type PrismicImageProps, PrismicLink, type PrismicLinkProps, PrismicRichText, type PrismicRichTextProps, PrismicTable, type PrismicTableProps, PrismicText, type PrismicTextProps, PrismicToolbar, type PrismicToolbarProps, type SliceComponentProps, type SliceComponentType, type SliceLike, type SliceLikeGraphQL, type SliceLikeRestV2, SliceZone, type SliceZoneComponents, type SliceZoneLike, type SliceZoneProps, TODOSliceComponent };
package/dist/index.js CHANGED
@@ -1,20 +1,10 @@
1
- import { PrismicLink } from "./PrismicLink.js";
2
- import { PrismicTable } from "./PrismicTable.js";
3
- import { PrismicText } from "./PrismicText.js";
4
- import { PrismicRichText } from "./PrismicRichText.js";
1
+ import { PrismicLink } from "./src/PrismicLink.js";
2
+ import { PrismicRichText } from "./src/PrismicRichText.js";
3
+ import { PrismicTable } from "./src/PrismicTable.js";
4
+ import { PrismicText } from "./src/PrismicText.js";
5
+ import { PrismicImage } from "./src/PrismicImage.js";
6
+ import { SliceZone, TODOSliceComponent } from "./src/SliceZone.js";
7
+ import { PrismicToolbar } from "./src/PrismicToolbar.js";
5
8
  import { Element } from "@prismicio/client/richtext";
6
- import { PrismicImage } from "./PrismicImage.js";
7
- import { SliceZone, TODOSliceComponent } from "./SliceZone.js";
8
- import { PrismicToolbar } from "./PrismicToolbar.js";
9
- export {
10
- Element,
11
- PrismicImage,
12
- PrismicLink,
13
- PrismicRichText,
14
- PrismicTable,
15
- PrismicText,
16
- PrismicToolbar,
17
- SliceZone,
18
- TODOSliceComponent
19
- };
20
- //# sourceMappingURL=index.js.map
9
+
10
+ export { Element, PrismicImage, PrismicLink, PrismicRichText, PrismicTable, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent };
@@ -0,0 +1,6 @@
1
+ //#region package.json
2
+ var version = "3.2.2-pr.242.afe79ea";
3
+
4
+ //#endregion
5
+ export { version };
6
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":["{\n\t\"name\": \"@prismicio/react\",\n\t\"version\": \"3.2.2-pr.242.afe79ea\",\n\t\"description\": \"React components and hooks to fetch and present Prismic content\",\n\t\"keywords\": [\n\t\t\"typescript\",\n\t\t\"prismic\",\n\t\t\"react\"\n\t],\n\t\"repository\": {\n\t\t\"type\": \"git\",\n\t\t\"url\": \"git+https://github.com/prismicio/prismic-react.git\"\n\t},\n\t\"license\": \"Apache-2.0\",\n\t\"author\": \"Prismic <contact@prismic.io> (https://prismic.io)\",\n\t\"sideEffects\": false,\n\t\"type\": \"module\",\n\t\"exports\": {\n\t\t\".\": \"./dist/index.js\",\n\t\t\"./package.json\": \"./package.json\"\n\t},\n\t\"typesVersions\": {\n\t\t\"*\": {\n\t\t\t\"*\": [\n\t\t\t\t\"./dist/index.d.ts\"\n\t\t\t]\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\"\n\t],\n\t\"workspaces\": [\n\t\t\".\",\n\t\t\"e2e-projects/*\"\n\t],\n\t\"scripts\": {\n\t\t\"build\": \"tsdown\",\n\t\t\"dev\": \"tsdown --watch\",\n\t\t\"e2e\": \"playwright test\",\n\t\t\"e2e:ui\": \"npm run e2e -- --ui\",\n\t\t\"format\": \"prettier --write .\",\n\t\t\"lint\": \"oxlint --deny-warnings\",\n\t\t\"prepare\": \"npm run build\",\n\t\t\"test\": \"npm run lint && npm run types && npm run build && npm run e2e\",\n\t\t\"types\": \"tsc --noEmit\"\n\t},\n\t\"dependencies\": {\n\t\t\"esm-env\": \"^1.2.2\"\n\t},\n\t\"devDependencies\": {\n\t\t\"@playwright/test\": \"^1.50.0\",\n\t\t\"@prismicio/client\": \"^7.17.0\",\n\t\t\"@trivago/prettier-plugin-sort-imports\": \"^6.0.0\",\n\t\t\"@types/react\": \"^19.2.7\",\n\t\t\"@types/react-dom\": \"^19.2.3\",\n\t\t\"dotenv\": \"^16.4.7\",\n\t\t\"oxlint\": \"^1.31.0\",\n\t\t\"playwright\": \"^1.50.0\",\n\t\t\"prettier\": \"^3.7.4\",\n\t\t\"prettier-plugin-jsdoc\": \"^1.7.0\",\n\t\t\"react\": \"^19.2.1\",\n\t\t\"react-dom\": \"^19.2.1\",\n\t\t\"tsdown\": \"^0.16.8\",\n\t\t\"typescript\": \"^5.9.3\"\n\t},\n\t\"peerDependencies\": {\n\t\t\"@prismicio/client\": \"^7\",\n\t\t\"react\": \"^18 || ^19\"\n\t},\n\t\"engines\": {\n\t\t\"node\": \">=20\"\n\t},\n\t\"publishConfig\": {\n\t\t\"access\": \"public\"\n\t},\n\t\"main\": \"./dist/index.js\",\n\t\"module\": \"./dist/index.js\",\n\t\"types\": \"./dist/index.d.ts\"\n}\n"],"mappings":";cAEY"}
@@ -0,0 +1,76 @@
1
+ import { ComponentProps, FC, ReactNode } from "react";
2
+ import { ImageFieldImage, asImagePixelDensitySrcSet, asImageWidthSrcSet } from "@prismicio/client";
3
+
4
+ //#region src/PrismicImage.d.ts
5
+ type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> & Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">;
6
+ /** Props for `<PrismicImage>`. */
7
+ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
8
+ /** The Prismic image field or thumbnail to render. */
9
+ field: ImageFieldImage | null | undefined;
10
+ /**
11
+ * An object of Imgix URL API parameters to transform the image.
12
+ *
13
+ * See: https://docs.imgix.com/apis/rendering
14
+ */
15
+ imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
16
+ /**
17
+ * Declare an image as decorative by providing `alt=""`.
18
+ *
19
+ * See:
20
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
21
+ */
22
+ alt?: "";
23
+ /**
24
+ * Declare an image as decorative only if the image field does not have
25
+ * alternative text by providing `fallbackAlt=""`.
26
+ *
27
+ * See:
28
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
29
+ */
30
+ fallbackAlt?: "";
31
+ /**
32
+ * The value to be rendered when the field is empty. If a fallback is not
33
+ * given, `null` will be rendered.
34
+ */
35
+ fallback?: ReactNode;
36
+ } & ({
37
+ /**
38
+ * Widths (in pixels) used to build a `srcset` value for the image
39
+ * field.
40
+ *
41
+ * If omitted or set to `"defaults"`, the following widths will be used:
42
+ * 640, 750, 828, 1080, 1200, 1920, 2048, 3840.
43
+ *
44
+ * If the image field contains responsive views, each responsive view
45
+ * can be used as a width in the resulting `srcset` by passing
46
+ * `"thumbnails"` as the `widths` prop.
47
+ */
48
+ widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
49
+ /** Not used when the `widths` prop is used. */
50
+ pixelDensities?: never;
51
+ } | {
52
+ /** Not used when the `widths` prop is used. */
53
+ widths?: never;
54
+ /**
55
+ * Pixel densities used to build a `srcset` value for the image field.
56
+ *
57
+ * If a `pixelDensities` prop is passed `"defaults"`, the following
58
+ * pixel densities will be used: 1, 2, 3.
59
+ */
60
+ pixelDensities: NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
61
+ });
62
+ /**
63
+ * Renders an optimized image from a Prismic image field.
64
+ *
65
+ * @example
66
+ *
67
+ * ```tsx
68
+ * <PrismicImage field={slice.primary.photo} />;
69
+ * ```
70
+ *
71
+ * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
72
+ */
73
+ declare const PrismicImage: FC<PrismicImageProps>;
74
+ //#endregion
75
+ export { PrismicImage, PrismicImageProps };
76
+ //# sourceMappingURL=PrismicImage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicImage.d.ts","names":[],"sources":["../../src/PrismicImage.tsx"],"sourcesContent":[],"mappings":";;;;KAiBK,cAAA,GAAiB,KACrB,YAAY,kBAAkB,qCAG9B,KACC,YAAY,kBAAkB;;AAL3B,KAUO,iBAAA,GAAoB,IAVb,CAWlB,cAXkB,CAAA,KAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,KAAA,CAAA,GAAA;EACY;EAAlB,KAAA,EAcL,eAdK,GAAA,IAAA,GAAA,SAAA;EAAZ;;;;;EAGA,WAAA,CAAA,EAAA,QAAI,MAkBwB,cAlBxB,GAkByC,cAlBzC,CAkBwD,CAlBxD,CAAA,GAAA,IAAA,EAMO;EACX;;;;;;EAkCW,GAAA,CAAA,EAAA,EAAA;EAeyB;;;;;;;EAiCxB,WAAA,CAAA,EAAA,EAmFZ;;;;;aAnIW;;;;;;;;;;;;;WAeL,YAAY,kBAAkB;;;;;;;;;;;;kBAe9B,YACA,kBAAkB;;;;;;;;;;;;;cAiBZ,cAAc,GAAG"}
@@ -0,0 +1,57 @@
1
+ import { devMsg } from "./lib/devMsg.js";
2
+ import { forwardRef } from "react";
3
+ import { asImagePixelDensitySrcSet, asImageWidthSrcSet, isFilled } from "@prismicio/client";
4
+ import { DEV } from "esm-env";
5
+ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/PrismicImage.tsx
8
+ /**
9
+ * Renders an optimized image from a Prismic image field.
10
+ *
11
+ * @example
12
+ *
13
+ * ```tsx
14
+ * <PrismicImage field={slice.primary.photo} />;
15
+ * ```
16
+ *
17
+ * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
18
+ */
19
+ const PrismicImage = forwardRef(function PrismicImage$1(props, ref) {
20
+ const { field, alt, fallbackAlt, imgixParams = {}, widths, pixelDensities, fallback, ...restProps } = props;
21
+ if (DEV) {
22
+ if (typeof alt === "string" && alt !== "") console.warn(`[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("alt-must-be-an-empty-string")}`);
23
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") console.warn(`[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("alt-must-be-an-empty-string")}`);
24
+ if (widths && pixelDensities) console.warn(`[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.`);
25
+ }
26
+ if (!isFilled.imageThumbnail(field)) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback });
27
+ const resolvedImgixParams = imgixParams;
28
+ for (const x in imgixParams) if (resolvedImgixParams[x] === null) resolvedImgixParams[x] = void 0;
29
+ let src;
30
+ let srcSet;
31
+ if (widths || !pixelDensities) {
32
+ const res = asImageWidthSrcSet(field, {
33
+ ...resolvedImgixParams,
34
+ widths: widths === "defaults" ? void 0 : widths
35
+ });
36
+ src = res.src;
37
+ srcSet = res.srcset;
38
+ } else if (pixelDensities) {
39
+ const res = asImagePixelDensitySrcSet(field, {
40
+ ...resolvedImgixParams,
41
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
42
+ });
43
+ src = res.src;
44
+ srcSet = res.srcset;
45
+ }
46
+ return /* @__PURE__ */ jsx("img", {
47
+ ref,
48
+ src,
49
+ srcSet,
50
+ alt: alt ?? (field.alt || fallbackAlt),
51
+ ...restProps
52
+ });
53
+ });
54
+
55
+ //#endregion
56
+ export { PrismicImage };
57
+ //# sourceMappingURL=PrismicImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicImage.js","names":["PrismicImage: FC<PrismicImageProps>","PrismicImage","src: string | undefined","srcSet: string | undefined"],"sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import {\n\ttype ForwardedRef,\n\tforwardRef,\n\ttype ComponentProps,\n\ttype FC,\n\ttype ReactNode,\n} from \"react\";\nimport {\n\ttype ImageFieldImage,\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\ntype ImgixURLParams = Omit<\n\tNonNullable<Parameters<typeof asImageWidthSrcSet>[1]>,\n\t\"widths\"\n> &\n\tOmit<\n\t\tNonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>,\n\t\t\"pixelDensities\"\n\t>;\n\n/** Props for `<PrismicImage>`. */\nexport type PrismicImageProps = Omit<\n\tComponentProps<\"img\">,\n\t\"src\" | \"srcset\" | \"alt\"\n> & {\n\t/** The Prismic image field or thumbnail to render. */\n\tfield: ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * See: https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Widths (in pixels) used to build a `srcset` value for the image\n\t\t\t\t * field.\n\t\t\t\t *\n\t\t\t\t * If omitted or set to `\"defaults\"`, the following widths will be used:\n\t\t\t\t * 640, 750, 828, 1080, 1200, 1920, 2048, 3840.\n\t\t\t\t *\n\t\t\t\t * If the image field contains responsive views, each responsive view\n\t\t\t\t * can be used as a width in the resulting `srcset` by passing\n\t\t\t\t * `\"thumbnails\"` as the `widths` prop.\n\t\t\t\t */\n\t\t\t\twidths?:\n\t\t\t\t\t| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"]\n\t\t\t\t\t| \"defaults\";\n\t\t\t\t/** Not used when the `widths` prop is used. */\n\t\t\t\tpixelDensities?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Not used when the `widths` prop is used. */\n\t\t\t\twidths?: never;\n\t\t\t\t/**\n\t\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t\t *\n\t\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following\n\t\t\t\t * pixel densities will be used: 1, 2, 3.\n\t\t\t\t */\n\t\t\t\tpixelDensities:\n\t\t\t\t\t| NonNullable<\n\t\t\t\t\t\t\tParameters<typeof asImagePixelDensitySrcSet>[1]\n\t\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t\t| \"defaults\";\n\t\t }\n\t);\n\n/**\n * Renders an optimized image from a Prismic image field.\n *\n * @example\n *\n * ```tsx\n * <PrismicImage field={slice.primary.photo} />;\n * ```\n *\n * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}\n */\nexport const PrismicImage: FC<PrismicImageProps> = forwardRef(\n\tfunction PrismicImage(\n\t\tprops: PrismicImageProps,\n\t\tref: ForwardedRef<HTMLImageElement>,\n\t) {\n\t\tconst {\n\t\t\tfield,\n\t\t\talt,\n\t\t\tfallbackAlt,\n\t\t\timgixParams = {},\n\t\t\twidths,\n\t\t\tpixelDensities,\n\t\t\tfallback,\n\t\t\t...restProps\n\t\t} = props;\n\n\t\tif (DEV) {\n\t\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[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(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[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(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (widths && pixelDensities) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[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.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!isFilled.imageThumbnail(field)) {\n\t\t\treturn <>{fallback}</>;\n\t\t}\n\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tlet src: string | undefined;\n\t\tlet srcSet: string | undefined;\n\n\t\tif (widths || !pixelDensities) {\n\t\t\tconst res = asImageWidthSrcSet(field, {\n\t\t\t\t...resolvedImgixParams,\n\t\t\t\twidths: widths === \"defaults\" ? undefined : widths,\n\t\t\t} as ImgixURLParams);\n\n\t\t\tsrc = res.src;\n\t\t\tsrcSet = res.srcset;\n\t\t} else if (pixelDensities) {\n\t\t\tconst res = asImagePixelDensitySrcSet(field, {\n\t\t\t\t...resolvedImgixParams,\n\t\t\t\tpixelDensities:\n\t\t\t\t\tpixelDensities === \"defaults\" ? undefined : pixelDensities,\n\t\t\t} as ImgixURLParams);\n\n\t\t\tsrc = res.src;\n\t\t\tsrcSet = res.srcset;\n\t\t}\n\n\t\treturn (\n\t\t\t<img\n\t\t\t\tref={ref}\n\t\t\t\tsrc={src}\n\t\t\t\tsrcSet={srcSet}\n\t\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8GA,MAAaA,eAAsC,WAClD,SAASC,eACR,OACA,KACC;CACD,MAAM,EACL,OACA,KACA,aACA,cAAc,EAAE,EAChB,QACA,gBACA,UACA,GAAG,cACA;AAEJ,KAAI,KAAK;AACR,MAAI,OAAO,QAAQ,YAAY,QAAQ,GACtC,SAAQ,KACP,qQAAqQ,OACpQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,qSAAqS,OACpS,8BACA,GACD;AAGF,MAAI,UAAU,eACb,SAAQ,KACP,4MACA;;AAIH,KAAI,CAAC,SAAS,eAAe,MAAM,CAClC,QAAO,4CAAG,WAAY;CAGvB,MAAM,sBAAsB;AAC5B,MAAK,MAAM,KAAK,YACf,KAAI,oBAAoB,OAA2C,KAClE,qBAAoB,KAAyC;CAI/D,IAAIC;CACJ,IAAIC;AAEJ,KAAI,UAAU,CAAC,gBAAgB;EAC9B,MAAM,MAAM,mBAAmB,OAAO;GACrC,GAAG;GACH,QAAQ,WAAW,aAAa,SAAY;GAC5C,CAAmB;AAEpB,QAAM,IAAI;AACV,WAAS,IAAI;YACH,gBAAgB;EAC1B,MAAM,MAAM,0BAA0B,OAAO;GAC5C,GAAG;GACH,gBACC,mBAAmB,aAAa,SAAY;GAC7C,CAAmB;AAEpB,QAAM,IAAI;AACV,WAAS,IAAI;;AAGd,QACC,oBAAC;EACK;EACA;EACG;EACR,KAAK,QAAQ,MAAM,OAAO;EAC1B,GAAI;GACH;EAGJ"}
@@ -0,0 +1,84 @@
1
+ import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
2
+ import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
3
+
4
+ //#region src/PrismicLink.d.ts
5
+ /** The default component rendered for internal and external links. */
6
+ declare const defaultComponent = "a";
7
+ /** Props provided to a component when rendered with `<PrismicLink>`. */
8
+ interface LinkProps {
9
+ /** The URL to link. */
10
+ href: string;
11
+ /**
12
+ * The `target` attribute for anchor elements. If the Prismic field is
13
+ * configured to open in a new window, this prop defaults to `_blank`.
14
+ */
15
+ target?: HTMLAttributeAnchorTarget;
16
+ /**
17
+ * The `rel` attribute for anchor elements. If the `target` prop is set to
18
+ * `"_blank"`, this prop defaults to `"noopener noreferrer"`.
19
+ */
20
+ rel?: string;
21
+ /** Children for the component. */
22
+ children?: ReactNode;
23
+ }
24
+ type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
25
+ /**
26
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
27
+ * the link's URL is external. This prop can be provided a function to use the
28
+ * link's metadata to determine the `rel` value.
29
+ */
30
+ rel?: string | AsLinkAttrsConfig["rel"];
31
+ /**
32
+ * The link resolver used to resolve links.
33
+ *
34
+ * @remarks
35
+ * If your app uses route resolvers when querying for your Prismic
36
+ * repository's content, a link resolver does not need to be provided.
37
+ *
38
+ * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
39
+ */
40
+ linkResolver?: LinkResolverFunction;
41
+ /**
42
+ * The component rendered for internal URLs. Defaults to `<a>`.
43
+ *
44
+ * If your app uses a client-side router that requires a special Link
45
+ * component, provide the Link component to this prop.
46
+ */
47
+ internalComponent?: ComponentType<InternalComponentProps>;
48
+ /** The component rendered for external URLs. Defaults to `<a>`. */
49
+ externalComponent?: ComponentType<ExternalComponentProps>;
50
+ /**
51
+ * The children to render for the link. If no children are provided, the
52
+ * link's `text` property will be used.
53
+ */
54
+ children?: ReactNode;
55
+ } & ({
56
+ document: PrismicDocument | null | undefined;
57
+ href?: never;
58
+ field?: never;
59
+ } | {
60
+ field: LinkField | null | undefined;
61
+ href?: never;
62
+ document?: never;
63
+ } | {
64
+ href: LinkProps["href"];
65
+ field?: LinkField | null | undefined;
66
+ document?: never;
67
+ });
68
+ /**
69
+ * Renders a link from a Prismic link field or page.
70
+ *
71
+ * @example
72
+ *
73
+ * ```tsx
74
+ * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
75
+ * ```
76
+ *
77
+ * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
78
+ */
79
+ declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
80
+ ref?: ForwardedRef<Element>;
81
+ }) => ReactNode;
82
+ //#endregion
83
+ export { LinkProps, PrismicLink, PrismicLinkProps };
84
+ //# sourceMappingURL=PrismicLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.d.ts","names":[],"sources":["../../src/PrismicLink.tsx"],"sourcesContent":[],"mappings":";;;;;cAoBM,gBAAA;AANqB;AASV,UAAA,SAAA,CAAS;EAoBd;EACoC,IAAA,EAAA,MAAA;EAAtB;;;;EAGA,MAAA,CAAA,EAhBhB,yBAgBgB;EADtB;;;;EA4BiB,GAAA,CAAA,EAAA,MAAA;EAGc;EAAd,QAAA,CAAA,EArCT,SAqCS;;AASP,KA3CF,gBA2CE,CAAA,yBA1CY,cA0CZ,CAAA,OA1CkC,gBA0ClC,CAAA,EAAA,yBAzCY,cAyCZ,CAAA,OAzCkC,gBAyClC,CAAA,CAAA,GAxCV,IAwCU,CAvCb,sBAuCa,GAvCY,sBAuCZ,EAAA,KAAA,GAAA,MAAA,GAAA,UAAA,CAAA,GAAA;EAKH;;;;AAsBX;EAsFgD,GAAA,CAAA,EAAA,MAAA,GAhJhC,iBAgJgC,CAAA,KAAA,CAAA;EAAtB;;;;;;;;;EAMZ,YAAA,CAAA,EA3IE,oBA2IF;;;;;;;sBAnIO,cAAc;;sBAGd,cAAc;;;;;aAMvB;;YAGE;;;;SAKH;;;;QAKD;UACE;;;;;;;;;;;;;;cAgBC,uCAsFa,sBAAsB,4CACtB,sBAAsB,0BAExC,iBAAiB,wBAAwB;QACzC,aAAa;MAEhB"}
@@ -0,0 +1,66 @@
1
+ import { devMsg } from "./lib/devMsg.js";
2
+ import { forwardRef } from "react";
3
+ import { asLinkAttrs } from "@prismicio/client";
4
+ import { DEV } from "esm-env";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/PrismicLink.tsx
8
+ /** The default component rendered for internal and external links. */
9
+ const defaultComponent = "a";
10
+ /**
11
+ * Renders a link from a Prismic link field or page.
12
+ *
13
+ * @example
14
+ *
15
+ * ```tsx
16
+ * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
17
+ * ```
18
+ *
19
+ * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
20
+ */
21
+ const PrismicLink = forwardRef(function PrismicLink$1(props, ref) {
22
+ const { field, document: doc, linkResolver, internalComponent, externalComponent, children, ...restProps } = props;
23
+ if (DEV) {
24
+ if (field) {
25
+ if (!field.link_type) {
26
+ console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.\n`, field);
27
+ throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg("missing-link-properties")}`);
28
+ } else if (("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) && !("url" in field || "uid" in field || "id" in field)) console.warn(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, field);
29
+ } else if (doc) {
30
+ if (!("url" in doc || "id" in doc)) console.warn(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, doc);
31
+ }
32
+ }
33
+ const { href: computedHref, rel: computedRel, ...attrs } = asLinkAttrs(field ?? doc, {
34
+ linkResolver,
35
+ rel: typeof restProps.rel === "function" ? restProps.rel : void 0
36
+ });
37
+ let rel = computedRel;
38
+ if ("rel" in restProps && typeof restProps.rel !== "function") rel = restProps.rel;
39
+ const href = ("href" in restProps ? restProps.href : computedHref) || "";
40
+ const InternalComponent = internalComponent || defaultComponent;
41
+ const ExternalComponent = externalComponent || defaultComponent;
42
+ return /* @__PURE__ */ jsx(href ? isInternalURL(href) ? InternalComponent : ExternalComponent : InternalComponent, {
43
+ ref,
44
+ ...attrs,
45
+ ...restProps,
46
+ href,
47
+ rel,
48
+ children: "children" in props ? children : field?.text
49
+ });
50
+ });
51
+ /**
52
+ * Determines if a URL is internal or external.
53
+ *
54
+ * @param url - The URL to check if internal or external.
55
+ *
56
+ * @returns `true` if `url` is internal, `false` otherwise.
57
+ */
58
+ function isInternalURL(url) {
59
+ const isInternal = /^(\/(?!\/)|#)/.test(url);
60
+ const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
61
+ return isInternal && !isSpecialLink;
62
+ }
63
+
64
+ //#endregion
65
+ export { PrismicLink };
66
+ //# sourceMappingURL=PrismicLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.js","names":["PrismicLink","rel: string | undefined"],"sources":["../../src/PrismicLink.tsx"],"sourcesContent":["import {\n\ttype ComponentProps,\n\ttype ComponentType,\n\ttype ForwardedRef,\n\ttype HTMLAttributeAnchorTarget,\n\ttype ReactNode,\n\tforwardRef,\n} from \"react\";\nimport {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n\ttype AsLinkAttrsConfig,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\n/** The default component rendered for internal and external links. */\nconst defaultComponent = \"a\";\n\n/** Props provided to a component when rendered with `<PrismicLink>`. */\nexport interface LinkProps {\n\t/** The URL to link. */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/** Children for the component. */\n\tchildren?: ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n> = Omit<\n\tInternalComponentProps & ExternalComponentProps,\n\t\"rel\" | \"href\" | \"children\"\n> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: ComponentType<InternalComponentProps>;\n\n\t/** The component rendered for external URLs. Defaults to `<a>`. */\n\texternalComponent?: ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the\n\t * link's `text` property will be used.\n\t */\n\tchildren?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\n/**\n * Renders a link from a Prismic link field or page.\n *\n * @example\n *\n * ```tsx\n * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;\n * ```\n *\n * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}\n */\nexport const PrismicLink = forwardRef(function PrismicLink<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: ForwardedRef<Element>,\n) {\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field\n\t\t\t\t\t? Object.keys(field).length > 2\n\t\t\t\t\t: Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as ComponentType<LinkProps>;\n\tconst Component = href\n\t\t? isInternalURL(href)\n\t\t\t? InternalComponent\n\t\t\t: ExternalComponent\n\t\t: InternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: ForwardedRef<Element>;\n\t},\n) => ReactNode;\n\n/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n *\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport function isInternalURL(url: string): boolean {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url);\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url);\n\n\treturn isInternal && !isSpecialLink;\n}\n"],"mappings":";;;;;;;;AAoBA,MAAM,mBAAmB;;;;;;;;;;;;AA6FzB,MAAa,cAAc,WAAW,SAASA,cAI9C,OACA,KACC;CACD,MAAM,EACL,OACA,UAAU,KACV,cACA,mBACA,mBACA,UACA,GAAG,cACA;AAEJ,KAAI,KACH;MAAI,OACH;OAAI,CAAC,MAAM,WAAW;AACrB,YAAQ,MACP,yEACA,MACA;AACD,UAAM,IAAI,MACT,8IAA8I,OAC7I,0BACA,GACD;eAEA,UAAU,QACR,OAAO,KAAK,MAAM,CAAC,SAAS,IAC5B,OAAO,KAAK,MAAM,CAAC,SAAS,MAC/B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,OAE9C,SAAQ,KACP,uJAAuJ,OACtJ,0BACA,IACD,MACA;aAEQ,KACV;OAAI,EAAE,SAAS,OAAO,QAAQ,KAC7B,SAAQ,KACP,0JAA0J,OACzJ,0BACA,IACD,IACA;;;CAKJ,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;EAC7B;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;EAC3D,CAAC;CAEF,IAAIC,MAA0B;AAC9B,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;CAGjB,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,MAAM,oBAAqB,qBAC1B;CACD,MAAM,oBAAqB,qBAC1B;AAOD,QACC,oBAPiB,OACf,cAAc,KAAK,GAClB,oBACA,oBACD;EAGc;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YAC9D,cAAc,QAAQ,WAAW,OAAO;GAC9B;EAEZ;;;;;;;;AAiBF,SAAgB,cAAc,KAAsB;CACnD,MAAM,aAAa,gBAAgB,KAAK,IAAI;CAC5C,MAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,IAAI;AAE9D,QAAO,cAAc,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { LinkProps } from "./PrismicLink.js";
2
+ import { ComponentType, FC, ReactNode } from "react";
3
+ import { LinkResolverFunction, RichTextField } from "@prismicio/client";
4
+ import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext";
5
+
6
+ //#region src/PrismicRichText.d.ts
7
+
8
+ /**
9
+ * A function mapping rich text block types to React Components. It is used to
10
+ * render rich text fields.
11
+ *
12
+ * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
13
+ */
14
+ type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
15
+ /**
16
+ * A map of rich text block types to React Components. It is used to render rich
17
+ * text fields.
18
+ *
19
+ * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
20
+ */
21
+ type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
22
+ /** Props for `<PrismicRichText>`. */
23
+ type PrismicRichTextProps = {
24
+ /** The Prismic rich text field to render. */
25
+ field: RichTextField | null | undefined;
26
+ /**
27
+ * The link resolver used to resolve links.
28
+ *
29
+ * @remarks
30
+ * If your app uses route resolvers when querying for your Prismic
31
+ * repository's content, a link resolver does not need to be provided.
32
+ *
33
+ * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
34
+ */
35
+ linkResolver?: LinkResolverFunction;
36
+ /**
37
+ * A map or function that maps a rich text block to a React component.
38
+ *
39
+ * @remarks
40
+ * Prefer using a map serializer over the function serializer when possible.
41
+ * The map serializer is simpler to maintain.
42
+ *
43
+ * @example A map serializer.
44
+ *
45
+ * ```jsx
46
+ * {
47
+ * heading1: ({children}) => <Heading>{children}</Heading>
48
+ * }
49
+ * ```
50
+ *
51
+ * @example A function serializer.
52
+ *
53
+ * ```jsx
54
+ * (type, node, content, children) => {
55
+ * switch (type) {
56
+ * case "heading1": {
57
+ * return <Heading>{children}</Heading>;
58
+ * }
59
+ * }
60
+ * };
61
+ * ```
62
+ */
63
+ components?: JSXMapSerializer | JSXFunctionSerializer;
64
+ /**
65
+ * The React component rendered for links when the URL is internal.
66
+ *
67
+ * @defaultValue `<a>`
68
+ */
69
+ internalLinkComponent?: ComponentType<LinkProps>;
70
+ /**
71
+ * The React component rendered for links when the URL is external.
72
+ *
73
+ * @defaultValue `<a>`
74
+ */
75
+ externalLinkComponent?: ComponentType<LinkProps>;
76
+ /**
77
+ * The value to be rendered when the field is empty. If a fallback is not
78
+ * given, `null` will be rendered.
79
+ */
80
+ fallback?: ReactNode;
81
+ };
82
+ /**
83
+ * Renders content from a Prismic rich text field as React components.
84
+ *
85
+ * @example
86
+ *
87
+ * ```tsx
88
+ * <PrismicRichText field={slice.primary.text} />;
89
+ * ```
90
+ *
91
+ * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
92
+ */
93
+ declare const PrismicRichText: FC<PrismicRichTextProps>;
94
+ //#endregion
95
+ export { JSXFunctionSerializer, JSXMapSerializer, PrismicRichText, PrismicRichTextProps };
96
+ //# sourceMappingURL=PrismicRichText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../../src/PrismicRichText.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;AAiCA;AAQA;AAGA;;AAagB,KAxBJ,qBAAA,GAAwB,0BAwBpB,CAxB+C,SAwB/C,CAAA;;;;;;;AAiDJ,KAjEA,gBAAA,GAAmB,qBAiEnB,CAjEyC,SAiEzC,CAAA;;AAqJC,KAnND,oBAAA,GAmNqB;;SAjNzB;;;;;;;;;;iBAWQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA6BF,mBAAmB;;;;;;0BAOR,cAAc;;;;;;0BAOd,cAAc;;;;;aAM3B;;;;;;;;;;;;;cAqJC,iBAAiB,GAAG"}
@@ -0,0 +1,133 @@
1
+ import { devMsg } from "./lib/devMsg.js";
2
+ import { PrismicLink } from "./PrismicLink.js";
3
+ import { Fragment, cloneElement, isValidElement } from "react";
4
+ import { isFilled } from "@prismicio/client";
5
+ import { DEV } from "esm-env";
6
+ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
7
+ import { composeSerializers, serialize, wrapMapSerializer } from "@prismicio/client/richtext";
8
+
9
+ //#region src/PrismicRichText.tsx
10
+ const getDir = (node) => {
11
+ if ("direction" in node && node.direction === "rtl") return "rtl";
12
+ };
13
+ const createDefaultSerializer = (args) => wrapMapSerializer({
14
+ heading1: ({ node, children, key }) => /* @__PURE__ */ jsx("h1", {
15
+ dir: getDir(node),
16
+ children
17
+ }, key),
18
+ heading2: ({ node, children, key }) => /* @__PURE__ */ jsx("h2", {
19
+ dir: getDir(node),
20
+ children
21
+ }, key),
22
+ heading3: ({ node, children, key }) => /* @__PURE__ */ jsx("h3", {
23
+ dir: getDir(node),
24
+ children
25
+ }, key),
26
+ heading4: ({ node, children, key }) => /* @__PURE__ */ jsx("h4", {
27
+ dir: getDir(node),
28
+ children
29
+ }, key),
30
+ heading5: ({ node, children, key }) => /* @__PURE__ */ jsx("h5", {
31
+ dir: getDir(node),
32
+ children
33
+ }, key),
34
+ heading6: ({ node, children, key }) => /* @__PURE__ */ jsx("h6", {
35
+ dir: getDir(node),
36
+ children
37
+ }, key),
38
+ paragraph: ({ node, children, key }) => /* @__PURE__ */ jsx("p", {
39
+ dir: getDir(node),
40
+ children
41
+ }, key),
42
+ preformatted: ({ node, key }) => /* @__PURE__ */ jsx("pre", { children: node.text }, key),
43
+ strong: ({ children, key }) => /* @__PURE__ */ jsx("strong", { children }, key),
44
+ em: ({ children, key }) => /* @__PURE__ */ jsx("em", { children }, key),
45
+ listItem: ({ node, children, key }) => /* @__PURE__ */ jsx("li", {
46
+ dir: getDir(node),
47
+ children
48
+ }, key),
49
+ oListItem: ({ node, children, key }) => /* @__PURE__ */ jsx("li", {
50
+ dir: getDir(node),
51
+ children
52
+ }, key),
53
+ list: ({ children, key }) => /* @__PURE__ */ jsx("ul", { children }, key),
54
+ oList: ({ children, key }) => /* @__PURE__ */ jsx("ol", { children }, key),
55
+ image: ({ node, key }) => {
56
+ const img = /* @__PURE__ */ jsx("img", {
57
+ src: node.url,
58
+ alt: node.alt ?? void 0,
59
+ "data-copyright": node.copyright ? node.copyright : void 0
60
+ });
61
+ return /* @__PURE__ */ jsx("p", {
62
+ className: "block-img",
63
+ children: node.linkTo ? /* @__PURE__ */ jsx(PrismicLink, {
64
+ linkResolver: args.linkResolver,
65
+ internalComponent: args.internalLinkComponent,
66
+ externalComponent: args.externalLinkComponent,
67
+ field: node.linkTo,
68
+ children: img
69
+ }) : img
70
+ }, key);
71
+ },
72
+ embed: ({ node, key }) => /* @__PURE__ */ jsx("div", {
73
+ "data-oembed": node.oembed.embed_url,
74
+ "data-oembed-type": node.oembed.type,
75
+ "data-oembed-provider": node.oembed.provider_name,
76
+ dangerouslySetInnerHTML: { __html: node.oembed.html ?? "" }
77
+ }, key),
78
+ hyperlink: ({ node, children, key }) => /* @__PURE__ */ jsx(PrismicLink, {
79
+ field: node.data,
80
+ linkResolver: args.linkResolver,
81
+ internalComponent: args.internalLinkComponent,
82
+ externalComponent: args.externalLinkComponent,
83
+ children
84
+ }, key),
85
+ label: ({ node, children, key }) => /* @__PURE__ */ jsx("span", {
86
+ className: node.data.label,
87
+ children
88
+ }, key),
89
+ span: ({ text, key }) => {
90
+ const result = [];
91
+ let i = 0;
92
+ for (const line of text.split("\n")) {
93
+ if (i > 0) result.push(/* @__PURE__ */ jsx("br", {}, `${i}__break`));
94
+ result.push(/* @__PURE__ */ jsx(Fragment, { children: line }, `${i}__line`));
95
+ i++;
96
+ }
97
+ return /* @__PURE__ */ jsx(Fragment, { children: result }, key);
98
+ }
99
+ });
100
+ /**
101
+ * Renders content from a Prismic rich text field as React components.
102
+ *
103
+ * @example
104
+ *
105
+ * ```tsx
106
+ * <PrismicRichText field={slice.primary.text} />;
107
+ * ```
108
+ *
109
+ * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
110
+ */
111
+ const PrismicRichText = (props) => {
112
+ const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent, ...restProps } = props;
113
+ if (DEV) {
114
+ if ("className" in restProps) console.warn(`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, field);
115
+ }
116
+ if (!isFilled.richText(field)) return fallback != null ? /* @__PURE__ */ jsx(Fragment$1, { children: fallback }) : null;
117
+ const serializer = composeSerializers(typeof components === "object" ? wrapMapSerializer(components) : components, createDefaultSerializer({
118
+ linkResolver,
119
+ internalLinkComponent,
120
+ externalLinkComponent
121
+ }));
122
+ const serialized = serialize(field, (type, node, text, children, key) => {
123
+ const result = serializer(type, node, text, children, key);
124
+ if (isValidElement(result) && result.key == null) return cloneElement(result, { key });
125
+ else return result;
126
+ });
127
+ if (!serialized) return fallback != null ? /* @__PURE__ */ jsx(Fragment$1, { children: fallback }) : null;
128
+ return /* @__PURE__ */ jsx(Fragment$1, { children: serialized });
129
+ };
130
+
131
+ //#endregion
132
+ export { PrismicRichText };
133
+ //# sourceMappingURL=PrismicRichText.js.map