@prismicio/react 2.5.0 → 2.5.1

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 (102) hide show
  1. package/dist/PrismicImage.cjs +67 -0
  2. package/dist/PrismicImage.cjs.map +1 -0
  3. package/dist/PrismicImage.d.ts +163 -0
  4. package/dist/PrismicImage.js +49 -0
  5. package/dist/PrismicImage.js.map +1 -0
  6. package/dist/PrismicLink.cjs +91 -0
  7. package/dist/PrismicLink.cjs.map +1 -0
  8. package/dist/PrismicLink.d.ts +105 -0
  9. package/dist/PrismicLink.js +73 -0
  10. package/dist/PrismicLink.js.map +1 -0
  11. package/dist/PrismicProvider.cjs +41 -0
  12. package/dist/PrismicProvider.cjs.map +1 -0
  13. package/dist/PrismicProvider.d.ts +84 -0
  14. package/dist/PrismicProvider.js +24 -0
  15. package/dist/PrismicProvider.js.map +1 -0
  16. package/dist/PrismicRichText.cjs +97 -0
  17. package/dist/PrismicRichText.cjs.map +1 -0
  18. package/dist/PrismicRichText.d.ts +116 -0
  19. package/dist/PrismicRichText.js +78 -0
  20. package/dist/PrismicRichText.js.map +1 -0
  21. package/dist/PrismicText.cjs +42 -0
  22. package/dist/PrismicText.cjs.map +1 -0
  23. package/dist/PrismicText.d.ts +39 -0
  24. package/dist/PrismicText.js +24 -0
  25. package/dist/PrismicText.js.map +1 -0
  26. package/dist/PrismicToolbar.cjs +41 -0
  27. package/dist/PrismicToolbar.cjs.map +1 -0
  28. package/dist/PrismicToolbar.d.ts +21 -0
  29. package/dist/PrismicToolbar.js +24 -0
  30. package/dist/PrismicToolbar.js.map +1 -0
  31. package/dist/SliceZone.cjs +58 -0
  32. package/dist/SliceZone.cjs.map +1 -0
  33. package/dist/SliceZone.d.ts +188 -0
  34. package/dist/SliceZone.js +41 -0
  35. package/dist/SliceZone.js.map +1 -0
  36. package/dist/clientHooks.cjs +40 -0
  37. package/dist/clientHooks.cjs.map +1 -0
  38. package/dist/clientHooks.d.ts +357 -0
  39. package/dist/clientHooks.js +40 -0
  40. package/dist/clientHooks.js.map +1 -0
  41. package/dist/index.cjs +46 -574
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +46 -1290
  44. package/dist/index.js +46 -519
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/__PRODUCTION__.cjs +8 -0
  47. package/dist/lib/__PRODUCTION__.cjs.map +1 -0
  48. package/dist/lib/__PRODUCTION__.d.ts +7 -0
  49. package/dist/lib/__PRODUCTION__.js +8 -0
  50. package/dist/lib/__PRODUCTION__.js.map +1 -0
  51. package/dist/lib/devMsg.cjs +8 -0
  52. package/dist/lib/devMsg.cjs.map +1 -0
  53. package/dist/lib/devMsg.d.ts +16 -0
  54. package/dist/lib/devMsg.js +8 -0
  55. package/dist/lib/devMsg.js.map +1 -0
  56. package/dist/lib/invariant.cjs +15 -0
  57. package/dist/lib/invariant.cjs.map +1 -0
  58. package/dist/lib/invariant.d.ts +24 -0
  59. package/dist/lib/invariant.js +15 -0
  60. package/dist/lib/invariant.js.map +1 -0
  61. package/dist/lib/isInternalURL.cjs +9 -0
  62. package/dist/lib/isInternalURL.cjs.map +1 -0
  63. package/dist/lib/isInternalURL.d.ts +8 -0
  64. package/dist/lib/isInternalURL.js +9 -0
  65. package/dist/lib/isInternalURL.js.map +1 -0
  66. package/dist/lib/pascalCase.cjs +10 -0
  67. package/dist/lib/pascalCase.cjs.map +1 -0
  68. package/dist/lib/pascalCase.d.ts +26 -0
  69. package/dist/lib/pascalCase.js +10 -0
  70. package/dist/lib/pascalCase.js.map +1 -0
  71. package/dist/package.json.cjs +5 -0
  72. package/dist/package.json.cjs.map +1 -0
  73. package/dist/package.json.js +5 -0
  74. package/dist/package.json.js.map +1 -0
  75. package/dist/types.d.ts +19 -0
  76. package/dist/usePrismicClient.cjs +12 -0
  77. package/dist/usePrismicClient.cjs.map +1 -0
  78. package/dist/usePrismicClient.d.ts +11 -0
  79. package/dist/usePrismicClient.js +12 -0
  80. package/dist/usePrismicClient.js.map +1 -0
  81. package/dist/usePrismicContext.cjs +26 -0
  82. package/dist/usePrismicContext.cjs.map +1 -0
  83. package/dist/usePrismicContext.d.ts +8 -0
  84. package/dist/usePrismicContext.js +9 -0
  85. package/dist/usePrismicContext.js.map +1 -0
  86. package/dist/usePrismicPreviewResolver.cjs +44 -0
  87. package/dist/usePrismicPreviewResolver.cjs.map +1 -0
  88. package/dist/usePrismicPreviewResolver.d.ts +45 -0
  89. package/dist/usePrismicPreviewResolver.js +27 -0
  90. package/dist/usePrismicPreviewResolver.js.map +1 -0
  91. package/dist/useStatefulPrismicClientMethod.cjs +89 -0
  92. package/dist/useStatefulPrismicClientMethod.cjs.map +1 -0
  93. package/dist/useStatefulPrismicClientMethod.d.ts +44 -0
  94. package/dist/useStatefulPrismicClientMethod.js +72 -0
  95. package/dist/useStatefulPrismicClientMethod.js.map +1 -0
  96. package/package.json +43 -41
  97. package/src/PrismicImage.tsx +2 -1
  98. package/src/PrismicProvider.tsx +6 -3
  99. package/src/PrismicText.tsx +2 -1
  100. package/src/SliceZone.tsx +8 -4
  101. package/src/clientHooks.ts +52 -44
  102. package/src/useStatefulPrismicClientMethod.ts +2 -1
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const prismicH = require("@prismicio/helpers");
6
+ const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
7
+ const devMsg = require("./lib/devMsg.cjs");
8
+ function _interopNamespaceDefault(e) {
9
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
+ if (e) {
11
+ for (const k in e) {
12
+ if (k !== "default") {
13
+ const d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: () => e[k]
17
+ });
18
+ }
19
+ }
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
25
+ const prismicH__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicH);
26
+ const _PrismicImage = (props, ref) => {
27
+ const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
28
+ if (!__PRODUCTION__.__PRODUCTION__) {
29
+ if (typeof alt === "string" && props.alt !== "") {
30
+ 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.devMsg("alt-must-be-an-empty-string")}`);
31
+ }
32
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
33
+ 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.devMsg("alt-must-be-an-empty-string")}`);
34
+ }
35
+ if (widths && pixelDensities) {
36
+ 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.`);
37
+ }
38
+ }
39
+ if (prismicH__namespace.isFilled.imageThumbnail(field)) {
40
+ let src;
41
+ let srcSet;
42
+ if (widths || !pixelDensities) {
43
+ const res = prismicH__namespace.asImageWidthSrcSet(field, {
44
+ ...imgixParams,
45
+ widths: widths === "defaults" ? void 0 : widths
46
+ });
47
+ src = res.src;
48
+ srcSet = res.srcset;
49
+ } else if (pixelDensities) {
50
+ const res = prismicH__namespace.asImagePixelDensitySrcSet(field, {
51
+ ...imgixParams,
52
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
53
+ });
54
+ src = res.src;
55
+ srcSet = res.srcset;
56
+ }
57
+ return /* @__PURE__ */ jsxRuntime.jsx("img", { ref, src, srcSet, alt: alt ?? (field.alt || fallbackAlt), ...restProps });
58
+ } else {
59
+ return null;
60
+ }
61
+ };
62
+ if (!__PRODUCTION__.__PRODUCTION__) {
63
+ _PrismicImage.displayName = "PrismicImage";
64
+ }
65
+ const PrismicImage = React__namespace.forwardRef(_PrismicImage);
66
+ exports.PrismicImage = PrismicImage;
67
+ //# sourceMappingURL=PrismicImage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicImage.cjs","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicImage>`.\n */\nexport type PrismicImageProps = Omit<\n\tReact.DetailedHTMLProps<\n\t\tReact.ImgHTMLAttributes<HTMLImageElement>,\n\t\tHTMLImageElement\n\t>,\n\t\"src\" | \"srcset\" | \"alt\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.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?: Parameters<typeof prismicH.asImageSrc>[1];\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\t| {\n\t\t\t\t/**\n\t\t\t\t * Widths used to build a `srcset` value for the Image field.\n\t\t\t\t *\n\t\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t\t * 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<\n\t\t\t\t\t\t\tParameters<typeof prismicH.asImageWidthSrcSet>[1]\n\t\t\t\t\t >[\"widths\"]\n\t\t\t\t\t| \"defaults\";\n\t\t\t\t/**\n\t\t\t\t * Not used when the `widths` prop is used.\n\t\t\t\t */\n\t\t\t\tpixelDensities?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Not used when the `widths` prop is used.\n\t\t\t\t */\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 prismicH.asImagePixelDensitySrcSet>[1]\n\t\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t\t| \"defaults\";\n\t\t }\n\t);\n\nconst _PrismicImage = (\n\tprops: PrismicImageProps,\n\tref: React.ForwardedRef<HTMLImageElement>,\n): JSX.Element | null => {\n\tconst {\n\t\tfield,\n\t\talt,\n\t\tfallbackAlt,\n\t\timgixParams,\n\t\twidths,\n\t\tpixelDensities,\n\t\t...restProps\n\t} = props;\n\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (widths && pixelDensities) {\n\t\t\tconsole.warn(\n\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);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tlet src: string | undefined;\n\t\tlet srcSet: string | undefined;\n\n\t\tif (widths || !pixelDensities) {\n\t\t\tconst res = prismicH.asImageWidthSrcSet(field, {\n\t\t\t\t...imgixParams,\n\t\t\t\twidths: widths === \"defaults\" ? undefined : widths,\n\t\t\t});\n\n\t\t\tsrc = res.src;\n\t\t\tsrcSet = res.srcset;\n\t\t} else if (pixelDensities) {\n\t\t\tconst res = prismicH.asImagePixelDensitySrcSet(field, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities:\n\t\t\t\t\tpixelDensities === \"defaults\" ? undefined : pixelDensities,\n\t\t\t});\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} else {\n\t\treturn null;\n\t}\n};\n\nif (!__PRODUCTION__) {\n\t_PrismicImage.displayName = \"PrismicImage\";\n}\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails. It will automatically set the `alt` attribute using the Image\n * field's `alt` property.\n *\n * By default, a widths-based srcset will be used to support responsive images.\n * This ensures only the smallest image needed for a browser is downloaded.\n *\n * To use a pixel-density-based srcset, use the `pixelDensities` prop. Default\n * pixel densities can be used by using `pixelDensities=\"defaults\"`.\n *\n * **Note**: If you are using a framework that has a native image component,\n * such as Next.js and Gatsby, prefer using those image components instead. They\n * can provide deeper framework integration than `<PrismicImage>`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component for the given Image field.\n */\nexport const PrismicImage = React.forwardRef(_PrismicImage);\n"],"names":["__PRODUCTION__","devMsg","prismicH","jsx","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,MAAM,gBAAgB,CACrB,OACA,QACuB;AACjB,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,mBACG,UACA,IAAA;AAEJ,MAAI,CAACA,eAAAA,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAChD,cAAQ,KACP,qQAAqQC,OACpQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,qSAAqSA,OACpS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,UAAU,gBAAgB;AAC7B,cAAQ,KACP,2MAA2M;AAAA,IAE5M;AAAA,EACD;AAED,MAAIC,oBAAS,SAAS,eAAe,KAAK,GAAG;AACxC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMA,oBAAS,mBAAmB,OAAO;AAAA,QAC9C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMA,oBAAS,0BAA0B,OAAO;AAAA,QACrD,GAAG;AAAA,QACH,gBACC,mBAAmB,aAAa,SAAY;AAAA,MAAA,CAC7C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,IACb;AAGA,WAAAC,2BAAA,IAAC,OACA,EAAA,KACA,KACA,QACA,KAAK,QAAQ,MAAM,OAAO,cAC1B,GAAI,UAAU,CAAA;AAAA,EAAA,OAGV;AACC,WAAA;AAAA,EACP;AACF;AAEA,IAAI,CAACH,+BAAgB;AACpB,gBAAc,cAAc;AAC5B;AAqBY,MAAA,eAAeI,iBAAM,WAAW,aAAa;;"}
@@ -0,0 +1,163 @@
1
+ import * as React from "react";
2
+ import * as prismicT from "@prismicio/types";
3
+ import * as prismicH from "@prismicio/helpers";
4
+ /**
5
+ * Props for `<PrismicImage>`.
6
+ */
7
+ export type PrismicImageProps = Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcset" | "alt"> & {
8
+ /**
9
+ * The Prismic Image field or thumbnail to render.
10
+ */
11
+ field: prismicT.ImageFieldImage | null | undefined;
12
+ /**
13
+ * An object of Imgix URL API parameters to transform the image.
14
+ *
15
+ * See: https://docs.imgix.com/apis/rendering
16
+ */
17
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
18
+ /**
19
+ * Declare an image as decorative by providing `alt=""`.
20
+ *
21
+ * See:
22
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
23
+ */
24
+ alt?: "";
25
+ /**
26
+ * Declare an image as decorative only if the Image field does not have
27
+ * alternative text by providing `fallbackAlt=""`.
28
+ *
29
+ * See:
30
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
31
+ */
32
+ fallbackAlt?: "";
33
+ } & ({
34
+ /**
35
+ * Widths used to build a `srcset` value for the Image field.
36
+ *
37
+ * If a `widths` prop is not given or `"defaults"` is passed, the
38
+ * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,
39
+ * 3840.
40
+ *
41
+ * If the Image field contains responsive views, each responsive view
42
+ * can be used as a width in the resulting `srcset` by passing
43
+ * `"thumbnails"` as the `widths` prop.
44
+ */
45
+ widths?: NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"] | "defaults";
46
+ /**
47
+ * Not used when the `widths` prop is used.
48
+ */
49
+ pixelDensities?: never;
50
+ } | {
51
+ /**
52
+ * Not used when the `widths` prop is used.
53
+ */
54
+ widths?: never;
55
+ /**
56
+ * Pixel densities used to build a `srcset` value for the Image field.
57
+ *
58
+ * If a `pixelDensities` prop is passed `"defaults"`, the following
59
+ * pixel densities will be used: 1, 2, 3.
60
+ */
61
+ pixelDensities: NonNullable<Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
62
+ });
63
+ /**
64
+ * React component that renders an image from a Prismic Image field or one of
65
+ * its thumbnails. It will automatically set the `alt` attribute using the Image
66
+ * field's `alt` property.
67
+ *
68
+ * By default, a widths-based srcset will be used to support responsive images.
69
+ * This ensures only the smallest image needed for a browser is downloaded.
70
+ *
71
+ * To use a pixel-density-based srcset, use the `pixelDensities` prop. Default
72
+ * pixel densities can be used by using `pixelDensities="defaults"`.
73
+ *
74
+ * **Note**: If you are using a framework that has a native image component,
75
+ * such as Next.js and Gatsby, prefer using those image components instead. They
76
+ * can provide deeper framework integration than `<PrismicImage>`.
77
+ *
78
+ * @param props - Props for the component.
79
+ *
80
+ * @returns A responsive image component for the given Image field.
81
+ */
82
+ export declare const PrismicImage: React.ForwardRefExoticComponent<(Pick<Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "alt" | "srcset"> & {
83
+ /**
84
+ * The Prismic Image field or thumbnail to render.
85
+ */
86
+ field: prismicT.ImageFieldImage | null | undefined;
87
+ /**
88
+ * An object of Imgix URL API parameters to transform the image.
89
+ *
90
+ * See: https://docs.imgix.com/apis/rendering
91
+ */
92
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
93
+ /**
94
+ * Declare an image as decorative by providing `alt=""`.
95
+ *
96
+ * See:
97
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
98
+ */
99
+ alt?: "" | undefined;
100
+ /**
101
+ * Declare an image as decorative only if the Image field does not have
102
+ * alternative text by providing `fallbackAlt=""`.
103
+ *
104
+ * See:
105
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
106
+ */
107
+ fallbackAlt?: "" | undefined;
108
+ } & {
109
+ /**
110
+ * Widths used to build a `srcset` value for the Image field.
111
+ *
112
+ * If a `widths` prop is not given or `"defaults"` is passed, the
113
+ * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,
114
+ * 3840.
115
+ *
116
+ * If the Image field contains responsive views, each responsive view
117
+ * can be used as a width in the resulting `srcset` by passing
118
+ * `"thumbnails"` as the `widths` prop.
119
+ */
120
+ widths?: NonNullable<Parameters<typeof prismicH.asImageWidthSrcSet>[1]>["widths"] | "defaults";
121
+ /**
122
+ * Not used when the `widths` prop is used.
123
+ */
124
+ pixelDensities?: undefined;
125
+ }, "alt" | "crossOrigin" | "decoding" | "height" | "loading" | "referrerPolicy" | "sizes" | "srcSet" | "useMap" | "width" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "widths" | "pixelDensities" | "field" | "imgixParams" | "fallbackAlt"> | Pick<Omit<React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "alt" | "srcset"> & {
126
+ /**
127
+ * The Prismic Image field or thumbnail to render.
128
+ */
129
+ field: prismicT.ImageFieldImage | null | undefined;
130
+ /**
131
+ * An object of Imgix URL API parameters to transform the image.
132
+ *
133
+ * See: https://docs.imgix.com/apis/rendering
134
+ */
135
+ imgixParams?: Parameters<typeof prismicH.asImageSrc>[1];
136
+ /**
137
+ * Declare an image as decorative by providing `alt=""`.
138
+ *
139
+ * See:
140
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
141
+ */
142
+ alt?: "" | undefined;
143
+ /**
144
+ * Declare an image as decorative only if the Image field does not have
145
+ * alternative text by providing `fallbackAlt=""`.
146
+ *
147
+ * See:
148
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
149
+ */
150
+ fallbackAlt?: "" | undefined;
151
+ } & {
152
+ /**
153
+ * Not used when the `widths` prop is used.
154
+ */
155
+ widths?: undefined;
156
+ /**
157
+ * Pixel densities used to build a `srcset` value for the Image field.
158
+ *
159
+ * If a `pixelDensities` prop is passed `"defaults"`, the following
160
+ * pixel densities will be used: 1, 2, 3.
161
+ */
162
+ pixelDensities: NonNullable<Parameters<typeof prismicH.asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
163
+ }, "alt" | "crossOrigin" | "decoding" | "height" | "loading" | "referrerPolicy" | "sizes" | "srcSet" | "useMap" | "width" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "widths" | "pixelDensities" | "field" | "imgixParams" | "fallbackAlt">) & React.RefAttributes<HTMLImageElement>>;
@@ -0,0 +1,49 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import * as prismicH from "@prismicio/helpers";
4
+ import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
5
+ import { devMsg } from "./lib/devMsg.js";
6
+ const _PrismicImage = (props, ref) => {
7
+ const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
8
+ if (!__PRODUCTION__) {
9
+ if (typeof alt === "string" && props.alt !== "") {
10
+ 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")}`);
11
+ }
12
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
13
+ 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")}`);
14
+ }
15
+ if (widths && pixelDensities) {
16
+ 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.`);
17
+ }
18
+ }
19
+ if (prismicH.isFilled.imageThumbnail(field)) {
20
+ let src;
21
+ let srcSet;
22
+ if (widths || !pixelDensities) {
23
+ const res = prismicH.asImageWidthSrcSet(field, {
24
+ ...imgixParams,
25
+ widths: widths === "defaults" ? void 0 : widths
26
+ });
27
+ src = res.src;
28
+ srcSet = res.srcset;
29
+ } else if (pixelDensities) {
30
+ const res = prismicH.asImagePixelDensitySrcSet(field, {
31
+ ...imgixParams,
32
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
33
+ });
34
+ src = res.src;
35
+ srcSet = res.srcset;
36
+ }
37
+ return /* @__PURE__ */ jsx("img", { ref, src, srcSet, alt: alt ?? (field.alt || fallbackAlt), ...restProps });
38
+ } else {
39
+ return null;
40
+ }
41
+ };
42
+ if (!__PRODUCTION__) {
43
+ _PrismicImage.displayName = "PrismicImage";
44
+ }
45
+ const PrismicImage = React.forwardRef(_PrismicImage);
46
+ export {
47
+ PrismicImage
48
+ };
49
+ //# sourceMappingURL=PrismicImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicImage.js","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicImage>`.\n */\nexport type PrismicImageProps = Omit<\n\tReact.DetailedHTMLProps<\n\t\tReact.ImgHTMLAttributes<HTMLImageElement>,\n\t\tHTMLImageElement\n\t>,\n\t\"src\" | \"srcset\" | \"alt\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.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?: Parameters<typeof prismicH.asImageSrc>[1];\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\t| {\n\t\t\t\t/**\n\t\t\t\t * Widths used to build a `srcset` value for the Image field.\n\t\t\t\t *\n\t\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t\t * 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<\n\t\t\t\t\t\t\tParameters<typeof prismicH.asImageWidthSrcSet>[1]\n\t\t\t\t\t >[\"widths\"]\n\t\t\t\t\t| \"defaults\";\n\t\t\t\t/**\n\t\t\t\t * Not used when the `widths` prop is used.\n\t\t\t\t */\n\t\t\t\tpixelDensities?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Not used when the `widths` prop is used.\n\t\t\t\t */\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 prismicH.asImagePixelDensitySrcSet>[1]\n\t\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t\t| \"defaults\";\n\t\t }\n\t);\n\nconst _PrismicImage = (\n\tprops: PrismicImageProps,\n\tref: React.ForwardedRef<HTMLImageElement>,\n): JSX.Element | null => {\n\tconst {\n\t\tfield,\n\t\talt,\n\t\tfallbackAlt,\n\t\timgixParams,\n\t\twidths,\n\t\tpixelDensities,\n\t\t...restProps\n\t} = props;\n\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (widths && pixelDensities) {\n\t\t\tconsole.warn(\n\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);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tlet src: string | undefined;\n\t\tlet srcSet: string | undefined;\n\n\t\tif (widths || !pixelDensities) {\n\t\t\tconst res = prismicH.asImageWidthSrcSet(field, {\n\t\t\t\t...imgixParams,\n\t\t\t\twidths: widths === \"defaults\" ? undefined : widths,\n\t\t\t});\n\n\t\t\tsrc = res.src;\n\t\t\tsrcSet = res.srcset;\n\t\t} else if (pixelDensities) {\n\t\t\tconst res = prismicH.asImagePixelDensitySrcSet(field, {\n\t\t\t\t...imgixParams,\n\t\t\t\tpixelDensities:\n\t\t\t\t\tpixelDensities === \"defaults\" ? undefined : pixelDensities,\n\t\t\t});\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} else {\n\t\treturn null;\n\t}\n};\n\nif (!__PRODUCTION__) {\n\t_PrismicImage.displayName = \"PrismicImage\";\n}\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails. It will automatically set the `alt` attribute using the Image\n * field's `alt` property.\n *\n * By default, a widths-based srcset will be used to support responsive images.\n * This ensures only the smallest image needed for a browser is downloaded.\n *\n * To use a pixel-density-based srcset, use the `pixelDensities` prop. Default\n * pixel densities can be used by using `pixelDensities=\"defaults\"`.\n *\n * **Note**: If you are using a framework that has a native image component,\n * such as Next.js and Gatsby, prefer using those image components instead. They\n * can provide deeper framework integration than `<PrismicImage>`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component for the given Image field.\n */\nexport const PrismicImage = React.forwardRef(_PrismicImage);\n"],"names":[],"mappings":";;;;;AAuFA,MAAM,gBAAgB,CACrB,OACA,QACuB;AACjB,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,mBACG,UACA,IAAA;AAEJ,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAChD,cAAQ,KACP,qQAAqQ,OACpQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,qSAAqS,OACpS,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,UAAU,gBAAgB;AAC7B,cAAQ,KACP,2MAA2M;AAAA,IAE5M;AAAA,EACD;AAED,MAAI,SAAS,SAAS,eAAe,KAAK,GAAG;AACxC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAM,SAAS,mBAAmB,OAAO;AAAA,QAC9C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAM,SAAS,0BAA0B,OAAO;AAAA,QACrD,GAAG;AAAA,QACH,gBACC,mBAAmB,aAAa,SAAY;AAAA,MAAA,CAC7C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,IACb;AAGA,WAAA,oBAAC,OACA,EAAA,KACA,KACA,QACA,KAAK,QAAQ,MAAM,OAAO,cAC1B,GAAI,UAAU,CAAA;AAAA,EAAA,OAGV;AACC,WAAA;AAAA,EACP;AACF;AAEA,IAAI,CAAC,gBAAgB;AACpB,gBAAc,cAAc;AAC5B;AAqBY,MAAA,eAAe,MAAM,WAAW,aAAa;"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const prismicH = require("@prismicio/helpers");
6
+ const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
7
+ const devMsg = require("./lib/devMsg.cjs");
8
+ const isInternalURL = require("./lib/isInternalURL.cjs");
9
+ const usePrismicContext = require("./usePrismicContext.cjs");
10
+ function _interopNamespaceDefault(e) {
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== "default") {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
+ const prismicH__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicH);
28
+ const defaultInternalComponent = "a";
29
+ const defaultExternalComponent = "a";
30
+ const _PrismicLink = (props, ref) => {
31
+ const context = usePrismicContext.usePrismicContext();
32
+ if (!__PRODUCTION__.__PRODUCTION__) {
33
+ if ("field" in props && props.field) {
34
+ if (!props.field.link_type) {
35
+ console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
36
+ `, props.field);
37
+ 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.devMsg("missing-link-properties")}`);
38
+ } else if (Object.keys(props.field).length > 1 && !("url" in props.field || "uid" in props.field || "id" in props.field)) {
39
+ 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.devMsg("missing-link-properties")}`, props.field);
40
+ }
41
+ } else if ("document" in props && props.document) {
42
+ if (!("url" in props.document || "id" in props.document)) {
43
+ 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.devMsg("missing-link-properties")}`, props.document);
44
+ }
45
+ }
46
+ }
47
+ const linkResolver = props.linkResolver || context.linkResolver;
48
+ let href;
49
+ if ("href" in props) {
50
+ href = props.href;
51
+ } else if ("document" in props && props.document) {
52
+ href = prismicH__namespace.asLink(props.document, linkResolver);
53
+ } else if ("field" in props && props.field) {
54
+ href = prismicH__namespace.asLink(props.field, linkResolver);
55
+ }
56
+ const isInternal = href && isInternalURL.isInternalURL(href);
57
+ const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || !isInternal && "_blank" || void 0;
58
+ const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
59
+ const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
60
+ const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
61
+ const Component = isInternal ? InternalComponent : ExternalComponent;
62
+ const passthroughProps = Object.assign({}, props);
63
+ delete passthroughProps.linkResolver;
64
+ delete passthroughProps.internalComponent;
65
+ delete passthroughProps.externalComponent;
66
+ delete passthroughProps.rel;
67
+ delete passthroughProps.target;
68
+ if ("field" in passthroughProps) {
69
+ delete passthroughProps.field;
70
+ } else if ("document" in passthroughProps) {
71
+ delete passthroughProps.document;
72
+ } else if ("href" in passthroughProps) {
73
+ delete passthroughProps.href;
74
+ }
75
+ return href ? /* @__PURE__ */ jsxRuntime.jsx(
76
+ Component,
77
+ {
78
+ ...passthroughProps,
79
+ ref,
80
+ href,
81
+ target,
82
+ rel
83
+ }
84
+ ) : null;
85
+ };
86
+ if (!__PRODUCTION__.__PRODUCTION__) {
87
+ _PrismicLink.displayName = "PrismicLink";
88
+ }
89
+ const PrismicLink = React__namespace.forwardRef(_PrismicLink);
90
+ exports.PrismicLink = PrismicLink;
91
+ //# sourceMappingURL=PrismicLink.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.cjs","sources":["../../src/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\nimport { isInternalURL } from \"./lib/isInternalURL\";\n\nimport { usePrismicContext } from \"./usePrismicContext\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\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?: string;\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/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\n/**\n * Props for `<PrismicLink>`.\n */\nexport type PrismicLinkProps<\n\tInternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent,\n\tExternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n> = Omit<\n\tReact.ComponentPropsWithoutRef<InternalComponent> &\n\t\tReact.ComponentPropsWithoutRef<ExternalComponent>,\n\tkeyof LinkProps\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 * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\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?: InternalComponent;\n\n\t/**\n\t * The component rendered for external URLs. Defaults to `<a>`.\n\t */\n\texternalComponent?: ExternalComponent;\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?: string | null;\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 | null;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n} & (\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * The Prismic Link field containing the URL or document to link.\n\t\t\t\t *\n\t\t\t\t * @see Learn about Prismic Link fields {@link https://prismic.io/docs/core-concepts/link-content-relationship}\n\t\t\t\t */\n\t\t\t\tfield: prismicT.LinkField | null | undefined;\n\t\t }\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * The Prismic document to link.\n\t\t\t\t */\n\t\t\t\tdocument: prismicT.PrismicDocument | null | undefined;\n\t\t }\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * The URL to link.\n\t\t\t\t */\n\t\t\t\thref: string | null | undefined;\n\t\t }\n\t);\n\n/**\n * The default component rendered for internal URLs.\n */\nconst defaultInternalComponent = \"a\";\n\n/**\n * The default component rendered for external URLs.\n */\nconst defaultExternalComponent = \"a\";\n\nconst _PrismicLink = <\n\tInternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent,\n\tExternalComponent extends React.ElementType<LinkProps> = typeof defaultExternalComponent,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n>(\n\tprops: PrismicLinkProps<\n\t\tInternalComponent,\n\t\tExternalComponent,\n\t\tLinkResolverFunction\n\t>,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tref: React.Ref<any>,\n): JSX.Element | null => {\n\tconst context = usePrismicContext();\n\n\tif (!__PRODUCTION__) {\n\t\tif (\"field\" in props && props.field) {\n\t\t\tif (!props.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\tprops.field,\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\tObject.keys(props.field).length > 1 &&\n\t\t\t\t!(\"url\" in props.field || \"uid\" in props.field || \"id\" in props.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\tprops.field,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (\"document\" in props && props.document) {\n\t\t\tif (!(\"url\" in props.document || \"id\" in props.document)) {\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\tprops.document,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst linkResolver = props.linkResolver || context.linkResolver;\n\n\tlet href: string | null | undefined;\n\tif (\"href\" in props) {\n\t\thref = props.href;\n\t} else if (\"document\" in props && props.document) {\n\t\thref = prismicH.asLink(props.document, linkResolver);\n\t} else if (\"field\" in props && props.field) {\n\t\thref = prismicH.asLink(props.field, linkResolver);\n\t}\n\n\tconst isInternal = href && isInternalURL(href);\n\n\tconst target =\n\t\tprops.target ||\n\t\t(\"field\" in props &&\n\t\t\tprops.field &&\n\t\t\t\"target\" in props.field &&\n\t\t\tprops.field.target) ||\n\t\t(!isInternal && \"_blank\") ||\n\t\tundefined;\n\n\tconst rel =\n\t\tprops.rel || (target === \"_blank\" ? \"noopener noreferrer\" : undefined);\n\n\tconst InternalComponent: React.ElementType<LinkProps> =\n\t\tprops.internalComponent ||\n\t\tcontext.internalLinkComponent ||\n\t\tdefaultInternalComponent;\n\n\tconst ExternalComponent: React.ElementType<LinkProps> =\n\t\tprops.externalComponent ||\n\t\tcontext.externalLinkComponent ||\n\t\tdefaultExternalComponent;\n\n\tconst Component = isInternal ? InternalComponent : ExternalComponent;\n\n\tconst passthroughProps: typeof props = Object.assign({}, props);\n\tdelete passthroughProps.linkResolver;\n\tdelete passthroughProps.internalComponent;\n\tdelete passthroughProps.externalComponent;\n\tdelete passthroughProps.rel;\n\tdelete passthroughProps.target;\n\tif (\"field\" in passthroughProps) {\n\t\tdelete passthroughProps.field;\n\t} else if (\"document\" in passthroughProps) {\n\t\tdelete passthroughProps.document;\n\t} else if (\"href\" in passthroughProps) {\n\t\tdelete passthroughProps.href;\n\t}\n\n\treturn href ? (\n\t\t<Component\n\t\t\t// @ts-expect-error - Expression produces a union type\n\t\t\t// that is too complex to represent. This most likely\n\t\t\t// happens due to the polymorphic nature of this\n\t\t\t// component, passing of \"extra\" props, and ref\n\t\t\t// forwarding support.\n\t\t\t{...passthroughProps}\n\t\t\tref={ref}\n\t\t\thref={href}\n\t\t\ttarget={target}\n\t\t\trel={rel}\n\t\t/>\n\t) : null;\n};\n\nif (!__PRODUCTION__) {\n\t_PrismicLink.displayName = \"PrismicLink\";\n}\n\n/**\n * React component that renders a link from a Prismic Link field.\n *\n * Different components can be rendered depending on whether the link is\n * internal or external. This is helpful when integrating with client-side\n * routers, such as a router-specific Link component.\n *\n * If a link is configured to open in a new window using `target=\"_blank\"`,\n * `rel=\"noopener noreferrer\"` is set by default.\n *\n * @param props - Props for the component.\n *\n * @returns The internal or external link component depending on whether the\n * link is internal or external.\n */\nexport const PrismicLink = React.forwardRef(_PrismicLink) as <\n\tInternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent,\n\tExternalComponent extends React.ElementType<LinkProps> = typeof defaultExternalComponent,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n>(\n\tprops: PrismicLinkProps<\n\t\tInternalComponent,\n\t\tExternalComponent,\n\t\tLinkResolverFunction\n\t> & { ref?: React.Ref<Element> },\n) => JSX.Element | null;\n"],"names":["usePrismicContext","__PRODUCTION__","devMsg","prismicH","isInternalURL","jsx","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmHA,MAAM,2BAA2B;AAKjC,MAAM,2BAA2B;AAEjC,MAAM,eAAe,CAMpB,OAMA,QACuB;AACvB,QAAM,UAAUA,kBAAAA;AAEhB,MAAI,CAACC,eAAAA,gBAAgB;AAChB,QAAA,WAAW,SAAS,MAAM,OAAO;AAChC,UAAA,CAAC,MAAM,MAAM,WAAW;AAC3B,gBAAQ,MACP;AAAA,GACA,MAAM,KAAK;AAEZ,cAAM,IAAI,MACT,8IAA8IC,OAAA,OAC7I,yBAAyB,GACvB;AAAA,MAAA,WAGJ,OAAO,KAAK,MAAM,KAAK,EAAE,SAAS,KAClC,EAAE,SAAS,MAAM,SAAS,SAAS,MAAM,SAAS,QAAQ,MAAM,QAC/D;AACD,gBAAQ,KACP,uJAAuJA,OAAA,OACtJ,yBAAyB,KAE1B,MAAM,KAAK;AAAA,MAEZ;AAAA,IACS,WAAA,cAAc,SAAS,MAAM,UAAU;AACjD,UAAI,EAAE,SAAS,MAAM,YAAY,QAAQ,MAAM,WAAW;AACzD,gBAAQ,KACP,0JAA0JA,OAAA,OACzJ,yBAAyB,KAE1B,MAAM,QAAQ;AAAA,MAEf;AAAA,IACD;AAAA,EACD;AAEK,QAAA,eAAe,MAAM,gBAAgB,QAAQ;AAE/C,MAAA;AACJ,MAAI,UAAU,OAAO;AACpB,WAAO,MAAM;AAAA,EACH,WAAA,cAAc,SAAS,MAAM,UAAU;AACjD,WAAOC,oBAAS,OAAO,MAAM,UAAU,YAAY;AAAA,EACzC,WAAA,WAAW,SAAS,MAAM,OAAO;AAC3C,WAAOA,oBAAS,OAAO,MAAM,OAAO,YAAY;AAAA,EAChD;AAEK,QAAA,aAAa,QAAQC,cAAA,cAAc,IAAI;AAE7C,QAAM,SACL,MAAM,UACL,WAAW,SACX,MAAM,SACN,YAAY,MAAM,SAClB,MAAM,MAAM,UACZ,CAAC,cAAc,YAChB;AAED,QAAM,MACL,MAAM,QAAQ,WAAW,WAAW,wBAAwB;AAE7D,QAAM,oBACL,MAAM,qBACN,QAAQ,yBACR;AAED,QAAM,oBACL,MAAM,qBACN,QAAQ,yBACR;AAEK,QAAA,YAAY,aAAa,oBAAoB;AAEnD,QAAM,mBAAiC,OAAO,OAAO,IAAI,KAAK;AAC9D,SAAO,iBAAiB;AACxB,SAAO,iBAAiB;AACxB,SAAO,iBAAiB;AACxB,SAAO,iBAAiB;AACxB,SAAO,iBAAiB;AACxB,MAAI,WAAW,kBAAkB;AAChC,WAAO,iBAAiB;AAAA,EAAA,WACd,cAAc,kBAAkB;AAC1C,WAAO,iBAAiB;AAAA,EAAA,WACd,UAAU,kBAAkB;AACtC,WAAO,iBAAiB;AAAA,EACxB;AAED,SAAO,OACNC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MAMA,GAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEE,IAAA;AACL;AAEA,IAAI,CAACJ,+BAAgB;AACpB,eAAa,cAAc;AAC3B;AAiBY,MAAA,cAAcK,iBAAM,WAAW,YAAY;;"}
@@ -0,0 +1,105 @@
1
+ import * as React from "react";
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import * as prismicT from "@prismicio/types";
4
+ /**
5
+ * Props provided to a component when rendered with `<PrismicLink>`.
6
+ */
7
+ export interface LinkProps {
8
+ /**
9
+ * The URL to link.
10
+ */
11
+ href: string;
12
+ /**
13
+ * The `target` attribute for anchor elements. If the Prismic field is
14
+ * configured to open in a new window, this prop defaults to `_blank`.
15
+ */
16
+ target?: string;
17
+ /**
18
+ * The `rel` attribute for anchor elements. If the `target` prop is set to
19
+ * `"_blank"`, this prop defaults to `"noopener noreferrer"`.
20
+ */
21
+ rel?: string;
22
+ /**
23
+ * Children for the component. *
24
+ */
25
+ children?: React.ReactNode;
26
+ }
27
+ /**
28
+ * Props for `<PrismicLink>`.
29
+ */
30
+ export type PrismicLinkProps<InternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent, ExternalComponent extends React.ElementType<LinkProps> = typeof defaultInternalComponent, LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction> = Omit<React.ComponentPropsWithoutRef<InternalComponent> & React.ComponentPropsWithoutRef<ExternalComponent>, keyof LinkProps> & {
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
+ * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
38
+ */
39
+ linkResolver?: LinkResolverFunction;
40
+ /**
41
+ * The component rendered for internal URLs. Defaults to `<a>`.
42
+ *
43
+ * If your app uses a client-side router that requires a special Link
44
+ * component, provide the Link component to this prop.
45
+ */
46
+ internalComponent?: InternalComponent;
47
+ /**
48
+ * The component rendered for external URLs. Defaults to `<a>`.
49
+ */
50
+ externalComponent?: ExternalComponent;
51
+ /**
52
+ * The `target` attribute for anchor elements. If the Prismic field is
53
+ * configured to open in a new window, this prop defaults to `_blank`.
54
+ */
55
+ target?: string | null;
56
+ /**
57
+ * The `rel` attribute for anchor elements. If the `target` prop is set to
58
+ * `"_blank"`, this prop defaults to `"noopener noreferrer"`.
59
+ */
60
+ rel?: string | null;
61
+ /**
62
+ * Children for the component. *
63
+ */
64
+ children?: React.ReactNode;
65
+ } & ({
66
+ /**
67
+ * The Prismic Link field containing the URL or document to link.
68
+ *
69
+ * @see Learn about Prismic Link fields {@link https://prismic.io/docs/core-concepts/link-content-relationship}
70
+ */
71
+ field: prismicT.LinkField | null | undefined;
72
+ } | {
73
+ /**
74
+ * The Prismic document to link.
75
+ */
76
+ document: prismicT.PrismicDocument | null | undefined;
77
+ } | {
78
+ /**
79
+ * The URL to link.
80
+ */
81
+ href: string | null | undefined;
82
+ });
83
+ /**
84
+ * The default component rendered for internal URLs.
85
+ */
86
+ declare const defaultInternalComponent = "a";
87
+ /**
88
+ * React component that renders a link from a Prismic Link field.
89
+ *
90
+ * Different components can be rendered depending on whether the link is
91
+ * internal or external. This is helpful when integrating with client-side
92
+ * routers, such as a router-specific Link component.
93
+ *
94
+ * If a link is configured to open in a new window using `target="_blank"`,
95
+ * `rel="noopener noreferrer"` is set by default.
96
+ *
97
+ * @param props - Props for the component.
98
+ *
99
+ * @returns The internal or external link component depending on whether the
100
+ * link is internal or external.
101
+ */
102
+ export declare const PrismicLink: <InternalComponent extends React.ElementType<LinkProps> = "a", ExternalComponent extends React.ElementType<LinkProps> = "a", LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction<string>>(props: PrismicLinkProps<InternalComponent, ExternalComponent, LinkResolverFunction> & {
103
+ ref?: React.Ref<Element> | undefined;
104
+ }) => JSX.Element | null;
105
+ export {};
@@ -0,0 +1,73 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import * as prismicH from "@prismicio/helpers";
4
+ import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
5
+ import { devMsg } from "./lib/devMsg.js";
6
+ import { isInternalURL } from "./lib/isInternalURL.js";
7
+ import { usePrismicContext } from "./usePrismicContext.js";
8
+ const defaultInternalComponent = "a";
9
+ const defaultExternalComponent = "a";
10
+ const _PrismicLink = (props, ref) => {
11
+ const context = usePrismicContext();
12
+ if (!__PRODUCTION__) {
13
+ if ("field" in props && props.field) {
14
+ if (!props.field.link_type) {
15
+ console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
16
+ `, props.field);
17
+ 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")}`);
18
+ } else if (Object.keys(props.field).length > 1 && !("url" in props.field || "uid" in props.field || "id" in props.field)) {
19
+ 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")}`, props.field);
20
+ }
21
+ } else if ("document" in props && props.document) {
22
+ if (!("url" in props.document || "id" in props.document)) {
23
+ 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")}`, props.document);
24
+ }
25
+ }
26
+ }
27
+ const linkResolver = props.linkResolver || context.linkResolver;
28
+ let href;
29
+ if ("href" in props) {
30
+ href = props.href;
31
+ } else if ("document" in props && props.document) {
32
+ href = prismicH.asLink(props.document, linkResolver);
33
+ } else if ("field" in props && props.field) {
34
+ href = prismicH.asLink(props.field, linkResolver);
35
+ }
36
+ const isInternal = href && isInternalURL(href);
37
+ const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || !isInternal && "_blank" || void 0;
38
+ const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
39
+ const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
40
+ const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
41
+ const Component = isInternal ? InternalComponent : ExternalComponent;
42
+ const passthroughProps = Object.assign({}, props);
43
+ delete passthroughProps.linkResolver;
44
+ delete passthroughProps.internalComponent;
45
+ delete passthroughProps.externalComponent;
46
+ delete passthroughProps.rel;
47
+ delete passthroughProps.target;
48
+ if ("field" in passthroughProps) {
49
+ delete passthroughProps.field;
50
+ } else if ("document" in passthroughProps) {
51
+ delete passthroughProps.document;
52
+ } else if ("href" in passthroughProps) {
53
+ delete passthroughProps.href;
54
+ }
55
+ return href ? /* @__PURE__ */ jsx(
56
+ Component,
57
+ {
58
+ ...passthroughProps,
59
+ ref,
60
+ href,
61
+ target,
62
+ rel
63
+ }
64
+ ) : null;
65
+ };
66
+ if (!__PRODUCTION__) {
67
+ _PrismicLink.displayName = "PrismicLink";
68
+ }
69
+ const PrismicLink = React.forwardRef(_PrismicLink);
70
+ export {
71
+ PrismicLink
72
+ };
73
+ //# sourceMappingURL=PrismicLink.js.map