@prismicio/react 2.9.0 → 3.0.0-alpha.0

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 (191) hide show
  1. package/README.md +10 -11
  2. package/dist/PrismicImage.d.ts +18 -633
  3. package/dist/PrismicImage.js +32 -33
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +77 -6
  6. package/dist/PrismicLink.js +42 -7
  7. package/dist/PrismicLink.js.map +1 -1
  8. package/dist/PrismicRichText.d.ts +117 -4
  9. package/dist/PrismicRichText.js +74 -8
  10. package/dist/PrismicRichText.js.map +1 -1
  11. package/dist/PrismicText.d.ts +8 -13
  12. package/dist/PrismicText.js +15 -16
  13. package/dist/PrismicText.js.map +1 -1
  14. package/dist/PrismicToolbar.d.ts +2 -12
  15. package/dist/PrismicToolbar.js +8 -10
  16. package/dist/PrismicToolbar.js.map +1 -1
  17. package/dist/SliceZone.d.ts +16 -70
  18. package/dist/SliceZone.js +16 -37
  19. package/dist/SliceZone.js.map +1 -1
  20. package/dist/index.d.ts +13 -21
  21. package/dist/index.js +2 -29
  22. package/dist/index.js.map +1 -1
  23. package/dist/lib/devMsg.d.ts +2 -2
  24. package/dist/lib/devMsg.js +2 -2
  25. package/dist/lib/devMsg.js.map +1 -1
  26. package/dist/package.json.js +1 -1
  27. package/package.json +53 -70
  28. package/src/PrismicImage.tsx +80 -65
  29. package/src/PrismicLink.tsx +196 -26
  30. package/src/PrismicRichText.tsx +333 -33
  31. package/src/PrismicText.tsx +25 -30
  32. package/src/PrismicToolbar.tsx +10 -30
  33. package/src/SliceZone.tsx +58 -150
  34. package/src/index.ts +17 -53
  35. package/src/lib/devMsg.ts +3 -3
  36. package/dist/PrismicImage.cjs +0 -68
  37. package/dist/PrismicImage.cjs.map +0 -1
  38. package/dist/PrismicLink.cjs +0 -29
  39. package/dist/PrismicLink.cjs.map +0 -1
  40. package/dist/PrismicProvider.cjs +0 -41
  41. package/dist/PrismicProvider.cjs.map +0 -1
  42. package/dist/PrismicProvider.d.ts +0 -83
  43. package/dist/PrismicProvider.js +0 -24
  44. package/dist/PrismicProvider.js.map +0 -1
  45. package/dist/PrismicRichText.cjs +0 -30
  46. package/dist/PrismicRichText.cjs.map +0 -1
  47. package/dist/PrismicText.cjs +0 -44
  48. package/dist/PrismicText.cjs.map +0 -1
  49. package/dist/PrismicToolbar.cjs +0 -43
  50. package/dist/PrismicToolbar.cjs.map +0 -1
  51. package/dist/SliceZone.cjs +0 -53
  52. package/dist/SliceZone.cjs.map +0 -1
  53. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
  54. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
  55. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
  56. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
  57. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
  58. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
  59. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
  60. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
  61. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +0 -22
  62. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +0 -1
  63. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +0 -22
  64. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +0 -1
  65. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +0 -46
  66. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +0 -1
  67. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +0 -46
  68. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +0 -1
  69. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
  70. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
  71. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
  72. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
  73. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
  74. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
  75. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
  76. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
  77. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +0 -21
  78. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +0 -1
  79. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +0 -21
  80. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +0 -1
  81. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
  82. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
  83. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
  84. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
  85. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -24
  86. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
  87. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -24
  88. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
  89. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
  90. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
  91. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
  92. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
  93. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
  94. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
  95. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
  96. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
  97. package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs +0 -13
  98. package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs.map +0 -1
  99. package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js +0 -13
  100. package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js.map +0 -1
  101. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
  102. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
  103. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
  104. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
  105. package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs +0 -10
  106. package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs.map +0 -1
  107. package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js +0 -10
  108. package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js.map +0 -1
  109. package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs +0 -29
  110. package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs.map +0 -1
  111. package/dist/_node_modules/imgix-url-builder/dist/buildURL.js +0 -29
  112. package/dist/_node_modules/imgix-url-builder/dist/buildURL.js.map +0 -1
  113. package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs +0 -10
  114. package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs.map +0 -1
  115. package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js +0 -10
  116. package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js.map +0 -1
  117. package/dist/clientHooks.cjs +0 -40
  118. package/dist/clientHooks.cjs.map +0 -1
  119. package/dist/clientHooks.d.ts +0 -321
  120. package/dist/clientHooks.js +0 -40
  121. package/dist/clientHooks.js.map +0 -1
  122. package/dist/index.cjs +0 -48
  123. package/dist/index.cjs.map +0 -1
  124. package/dist/lib/devMsg.cjs +0 -8
  125. package/dist/lib/devMsg.cjs.map +0 -1
  126. package/dist/lib/isInternalURL.cjs +0 -9
  127. package/dist/lib/isInternalURL.cjs.map +0 -1
  128. package/dist/lib/isInternalURL.d.ts +0 -8
  129. package/dist/lib/isInternalURL.js +0 -9
  130. package/dist/lib/isInternalURL.js.map +0 -1
  131. package/dist/lib/pascalCase.cjs +0 -10
  132. package/dist/lib/pascalCase.cjs.map +0 -1
  133. package/dist/lib/pascalCase.d.ts +0 -26
  134. package/dist/lib/pascalCase.js +0 -10
  135. package/dist/lib/pascalCase.js.map +0 -1
  136. package/dist/package.json.cjs +0 -5
  137. package/dist/package.json.cjs.map +0 -1
  138. package/dist/react-server/PrismicLink.cjs +0 -59
  139. package/dist/react-server/PrismicLink.cjs.map +0 -1
  140. package/dist/react-server/PrismicLink.d.ts +0 -77
  141. package/dist/react-server/PrismicLink.js +0 -42
  142. package/dist/react-server/PrismicLink.js.map +0 -1
  143. package/dist/react-server/PrismicRichText.cjs +0 -97
  144. package/dist/react-server/PrismicRichText.cjs.map +0 -1
  145. package/dist/react-server/PrismicRichText.d.ts +0 -104
  146. package/dist/react-server/PrismicRichText.js +0 -79
  147. package/dist/react-server/PrismicRichText.js.map +0 -1
  148. package/dist/react-server/index.d.ts +0 -4
  149. package/dist/react-server/unsupported.cjs +0 -97
  150. package/dist/react-server/unsupported.cjs.map +0 -1
  151. package/dist/react-server/unsupported.d.ts +0 -22
  152. package/dist/react-server/unsupported.js +0 -97
  153. package/dist/react-server/unsupported.js.map +0 -1
  154. package/dist/react-server.cjs +0 -44
  155. package/dist/react-server.cjs.map +0 -1
  156. package/dist/react-server.js +0 -41
  157. package/dist/react-server.js.map +0 -1
  158. package/dist/types.d.ts +0 -19
  159. package/dist/usePrismicClient.cjs +0 -13
  160. package/dist/usePrismicClient.cjs.map +0 -1
  161. package/dist/usePrismicClient.d.ts +0 -11
  162. package/dist/usePrismicClient.js +0 -13
  163. package/dist/usePrismicClient.js.map +0 -1
  164. package/dist/usePrismicContext.cjs +0 -26
  165. package/dist/usePrismicContext.cjs.map +0 -1
  166. package/dist/usePrismicContext.d.ts +0 -8
  167. package/dist/usePrismicContext.js +0 -9
  168. package/dist/usePrismicContext.js.map +0 -1
  169. package/dist/usePrismicPreviewResolver.cjs +0 -44
  170. package/dist/usePrismicPreviewResolver.cjs.map +0 -1
  171. package/dist/usePrismicPreviewResolver.d.ts +0 -45
  172. package/dist/usePrismicPreviewResolver.js +0 -27
  173. package/dist/usePrismicPreviewResolver.js.map +0 -1
  174. package/dist/useStatefulPrismicClientMethod.cjs +0 -91
  175. package/dist/useStatefulPrismicClientMethod.cjs.map +0 -1
  176. package/dist/useStatefulPrismicClientMethod.d.ts +0 -44
  177. package/dist/useStatefulPrismicClientMethod.js +0 -74
  178. package/dist/useStatefulPrismicClientMethod.js.map +0 -1
  179. package/src/PrismicProvider.tsx +0 -132
  180. package/src/clientHooks.ts +0 -472
  181. package/src/lib/isInternalURL.ts +0 -14
  182. package/src/lib/pascalCase.ts +0 -79
  183. package/src/react-server/PrismicLink.tsx +0 -197
  184. package/src/react-server/PrismicRichText.tsx +0 -283
  185. package/src/react-server/index.ts +0 -38
  186. package/src/react-server/unsupported.ts +0 -184
  187. package/src/types.ts +0 -23
  188. package/src/usePrismicClient.ts +0 -30
  189. package/src/usePrismicContext.ts +0 -13
  190. package/src/usePrismicPreviewResolver.ts +0 -93
  191. package/src/useStatefulPrismicClientMethod.ts +0 -196
@@ -1,11 +1,11 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import * as React from "react";
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { isFilled, asImageWidthSrcSet, asImagePixelDensitySrcSet } from "@prismicio/client";
4
+ import { DEV } from "esm-env";
3
5
  import { devMsg } from "./lib/devMsg.js";
4
- import { imageThumbnail } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
5
- import { asImageWidthSrcSet } from './_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js';
6
- import { asImagePixelDensitySrcSet } from './_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js';
7
- const PrismicImage = React.forwardRef(function PrismicImage2({ field, alt, fallbackAlt, imgixParams = {}, widths, pixelDensities, ...restProps }, ref) {
8
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
6
+ const PrismicImage = forwardRef(function PrismicImage2(props, ref) {
7
+ const { field, alt, fallbackAlt, imgixParams = {}, widths, pixelDensities, fallback, ...restProps } = props;
8
+ if (DEV) {
9
9
  if (typeof alt === "string" && alt !== "") {
10
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
11
  }
@@ -16,34 +16,33 @@ const PrismicImage = React.forwardRef(function PrismicImage2({ field, alt, fallb
16
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
17
  }
18
18
  }
19
- if (imageThumbnail(field)) {
20
- const resolvedImgixParams = imgixParams;
21
- for (const x in imgixParams) {
22
- if (resolvedImgixParams[x] === null) {
23
- resolvedImgixParams[x] = void 0;
24
- }
25
- }
26
- let src;
27
- let srcSet;
28
- if (widths || !pixelDensities) {
29
- const res = asImageWidthSrcSet(field, {
30
- ...resolvedImgixParams,
31
- widths: widths === "defaults" ? void 0 : widths
32
- });
33
- src = res.src;
34
- srcSet = res.srcset;
35
- } else if (pixelDensities) {
36
- const res = asImagePixelDensitySrcSet(field, {
37
- ...resolvedImgixParams,
38
- pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
39
- });
40
- src = res.src;
41
- srcSet = res.srcset;
19
+ if (!isFilled.imageThumbnail(field)) {
20
+ return jsx(Fragment, { children: fallback });
21
+ }
22
+ const resolvedImgixParams = imgixParams;
23
+ for (const x in imgixParams) {
24
+ if (resolvedImgixParams[x] === null) {
25
+ resolvedImgixParams[x] = void 0;
42
26
  }
43
- return /* @__PURE__ */ jsx("img", { ref, src, srcSet, alt: alt ?? (field.alt || fallbackAlt), ...restProps });
44
- } else {
45
- return null;
46
27
  }
28
+ let src;
29
+ let srcSet;
30
+ if (widths || !pixelDensities) {
31
+ const res = asImageWidthSrcSet(field, {
32
+ ...resolvedImgixParams,
33
+ widths: widths === "defaults" ? void 0 : widths
34
+ });
35
+ src = res.src;
36
+ srcSet = res.srcset;
37
+ } else if (pixelDensities) {
38
+ const res = asImagePixelDensitySrcSet(field, {
39
+ ...resolvedImgixParams,
40
+ pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
41
+ });
42
+ src = res.src;
43
+ srcSet = res.srcset;
44
+ }
45
+ return jsx("img", { ref, src, srcSet, alt: alt ?? (field.alt || fallbackAlt), ...restProps });
47
46
  });
48
47
  export {
49
48
  PrismicImage
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicImage.js","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\nimport { ImgixURLParams } from \"imgix-url-builder\";\n\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: prismic.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\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 prismic.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 prismic.asImagePixelDensitySrcSet>[1]\n\t\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t\t| \"defaults\";\n\t\t }\n\t);\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(function PrismicImage(\n\t{\n\t\tfield,\n\t\talt,\n\t\tfallbackAlt,\n\t\timgixParams = {},\n\t\twidths,\n\t\tpixelDensities,\n\t\t...restProps\n\t}: PrismicImageProps,\n\tref: React.ForwardedRef<HTMLImageElement>,\n): JSX.Element | null {\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tif (typeof alt === \"string\" && 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 (prismic.isFilled.imageThumbnail(field)) {\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 = prismic.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 = prismic.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} else {\n\t\treturn null;\n\t}\n});\n"],"names":["PrismicImage","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet"],"mappings":";;;;;;AAyGO,MAAM,eAAe,MAAM,WAAW,SAASA,cACrD,EACC,OACA,KACA,aACA,cAAc,CACd,GAAA,QACA,gBACA,GAAG,aAEJ,KAAyC;AAEzC,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,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,MAAIC,eAAgC,KAAK,GAAG;AAC3C,UAAM,sBAAsB;AAC5B,eAAW,KAAK,aAAa;AACxB,UAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,4BAAoB,CAAqC,IAAI;AAAA,MAC7D;AAAA,IACD;AAEG,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMC,mBAA2B,OAAO;AAAA,QAC7C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC1B;AAEnB,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMC,0BAAkC,OAAO;AAAA,QACpD,GAAG;AAAA,QACH,gBACC,mBAAmB,aAAa,SAAY;AAAA,MAAA,CAC3B;AAEnB,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,CAAC;"}
1
+ {"version":3,"file":"PrismicImage.js","sources":["../src/PrismicImage.tsx"],"sourcesContent":["import {\n\tForwardedRef,\n\tforwardRef,\n\ttype ComponentProps,\n\tFC,\n\tReactNode,\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 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<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 * 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: 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"],"names":["PrismicImage","_jsx","_Fragment"],"mappings":";;;;;AAsHO,MAAM,eAAsC,WAClD,SAASA,cACR,OACA,KAAmC;AAEnC,QAAM,EACL,OACA,KACA,aACA,cAAc,CAAA,GACd,QACA,gBACA,UACA,GAAG,UACA,IAAA;AAEJ,MAAI,KAAK;AACR,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,qQAAqQ,OACpQ,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAIL,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,qSAAqS,OACpS,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAIL,QAAI,UAAU,gBAAgB;AAC7B,cAAQ,KACP,2MAA2M;AAAA,IAAA;AAAA,EAE7M;AAGD,MAAI,CAAC,SAAS,eAAe,KAAK,GAAG;AACpC,WAAOC,IAAAC,UAAA,EAAA,UAAG,UAAQ;AAAA,EAAA;AAGnB,QAAM,sBAAsB;AAC5B,aAAW,KAAK,aAAa;AACxB,QAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,0BAAoB,CAAqC,IAAI;AAAA,IAAA;AAAA,EAC9D;AAGG,MAAA;AACA,MAAA;AAEA,MAAA,UAAU,CAAC,gBAAgB;AACxB,UAAA,MAAM,mBAAmB,OAAO;AAAA,MACrC,GAAG;AAAA,MACH,QAAQ,WAAW,aAAa,SAAY;AAAA,IAAA,CAC1B;AAEnB,UAAM,IAAI;AACV,aAAS,IAAI;AAAA,aACH,gBAAgB;AACpB,UAAA,MAAM,0BAA0B,OAAO;AAAA,MAC5C,GAAG;AAAA,MACH,gBACC,mBAAmB,aAAa,SAAY;AAAA,IAAA,CAC3B;AAEnB,UAAM,IAAI;AACV,aAAS,IAAI;AAAA,EAAA;AAGd,SACCD,IAAA,OAAA,EACC,KACA,KACA,QACA,KAAK,QAAQ,MAAM,OAAO,cAAY,GAClC,WAAS;AAGhB,CAAC;"}
@@ -1,6 +1,77 @@
1
- import * as React from "react";
2
- import { LinkProps, PrismicLinkProps } from "./react-server/PrismicLink";
3
- export type { LinkProps, PrismicLinkProps };
4
- export declare const PrismicLink: <InternalComponentProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, ExternalComponentProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
5
- ref?: React.ForwardedRef<Element> | undefined;
6
- }) => JSX.Element;
1
+ import { ComponentProps, ComponentType, ElementType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
2
+ import { type LinkField, type LinkResolverFunction, type PrismicDocument, type AsLinkAttrsConfig } from "@prismicio/client";
3
+ /** The default component rendered for internal and external links. */
4
+ declare const defaultComponent = "a";
5
+ /** Props provided to a component when rendered with `<PrismicLink>`. */
6
+ export interface LinkProps {
7
+ /** The URL to link. */
8
+ href: string;
9
+ /**
10
+ * The `target` attribute for anchor elements. If the Prismic field is
11
+ * configured to open in a new window, this prop defaults to `_blank`.
12
+ */
13
+ target?: HTMLAttributeAnchorTarget;
14
+ /**
15
+ * The `rel` attribute for anchor elements. If the `target` prop is set to
16
+ * `"_blank"`, this prop defaults to `"noopener noreferrer"`.
17
+ */
18
+ rel?: string;
19
+ /** Children for the component. * */
20
+ children?: ReactNode;
21
+ }
22
+ export type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
23
+ /**
24
+ * The `rel` attribute for the link. By default, `"noreferrer"` is provided if
25
+ * the link's URL is external. This prop can be provided a function to use the
26
+ * link's metadata to determine the `rel` value.
27
+ */
28
+ rel?: string | AsLinkAttrsConfig["rel"];
29
+ /**
30
+ * The Link Resolver used to resolve links.
31
+ *
32
+ * @remarks
33
+ * If your app uses Route Resolvers when querying for your Prismic
34
+ * repository's content, a Link Resolver does not need to be provided.
35
+ *
36
+ * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
37
+ */
38
+ linkResolver?: LinkResolverFunction;
39
+ /**
40
+ * The component rendered for internal URLs. Defaults to `<a>`.
41
+ *
42
+ * If your app uses a client-side router that requires a special Link
43
+ * component, provide the Link component to this prop.
44
+ */
45
+ internalComponent?: ElementType<InternalComponentProps>;
46
+ /** The component rendered for external URLs. Defaults to `<a>`. */
47
+ externalComponent?: ComponentType<ExternalComponentProps>;
48
+ /**
49
+ * The children to render for the link. If no children are provided, the
50
+ * link's `text` property will be used.
51
+ */
52
+ children?: ReactNode;
53
+ } & ({
54
+ document: PrismicDocument | null | undefined;
55
+ href?: never;
56
+ field?: never;
57
+ } | {
58
+ field: LinkField | null | undefined;
59
+ href?: never;
60
+ document?: never;
61
+ } | {
62
+ href: LinkProps["href"];
63
+ field?: LinkField | null | undefined;
64
+ document?: never;
65
+ });
66
+ export declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
67
+ ref?: ForwardedRef<Element>;
68
+ }) => ReactNode;
69
+ /**
70
+ * Determines if a URL is internal or external.
71
+ *
72
+ * @param url - The URL to check if internal or external.
73
+ *
74
+ * @returns `true` if `url` is internal, `false` otherwise.
75
+ */
76
+ export declare function isInternalURL(url: string): boolean;
77
+ export {};
@@ -1,12 +1,47 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { PrismicLink as PrismicLink$1 } from "./react-server/PrismicLink.js";
4
- import { usePrismicContext } from "./usePrismicContext.js";
5
- const PrismicLink = React.forwardRef(function PrismicLink2(props, ref) {
6
- const context = usePrismicContext();
7
- return /* @__PURE__ */ jsx(PrismicLink$1, { ref, linkResolver: context.linkResolver, internalComponent: context.internalLinkComponent, externalComponent: context.externalLinkComponent, ...props });
2
+ import { forwardRef } from "react";
3
+ import { asLinkAttrs } from "@prismicio/client";
4
+ import { DEV } from "esm-env";
5
+ import { devMsg } from "./lib/devMsg.js";
6
+ const defaultComponent = "a";
7
+ const PrismicLink = forwardRef(function PrismicLink2(props, ref) {
8
+ const { field, document: doc, linkResolver, internalComponent, externalComponent, children, ...restProps } = props;
9
+ if (DEV) {
10
+ if (field) {
11
+ if (!field.link_type) {
12
+ console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
13
+ `, field);
14
+ 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")}`);
15
+ } else if (("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) && !("url" in field || "uid" in field || "id" in field)) {
16
+ 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);
17
+ }
18
+ } else if (doc) {
19
+ if (!("url" in doc || "id" in doc)) {
20
+ 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);
21
+ }
22
+ }
23
+ }
24
+ const { href: computedHref, rel: computedRel, ...attrs } = asLinkAttrs(field ?? doc, {
25
+ linkResolver,
26
+ rel: typeof restProps.rel === "function" ? restProps.rel : void 0
27
+ });
28
+ let rel = computedRel;
29
+ if ("rel" in restProps && typeof restProps.rel !== "function") {
30
+ rel = restProps.rel;
31
+ }
32
+ const href = ("href" in restProps ? restProps.href : computedHref) || "";
33
+ const InternalComponent = internalComponent || defaultComponent;
34
+ const ExternalComponent = externalComponent || defaultComponent;
35
+ const Component = href ? isInternalURL(href) ? InternalComponent : ExternalComponent : InternalComponent;
36
+ return jsx(Component, { ref, ...attrs, ...restProps, href, rel, children: "children" in props ? children : field == null ? void 0 : field.text });
8
37
  });
38
+ function isInternalURL(url) {
39
+ const isInternal = /^(\/(?!\/)|#)/.test(url);
40
+ const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
41
+ return isInternal && !isSpecialLink;
42
+ }
9
43
  export {
10
- PrismicLink
44
+ PrismicLink,
45
+ isInternalURL
11
46
  };
12
47
  //# sourceMappingURL=PrismicLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicLink.js","sources":["../../src/PrismicLink.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport {\n\tPrismicLink as ServerPrismicLink,\n\tLinkProps,\n\tPrismicLinkProps,\n\tdefaultComponent,\n} from \"./react-server/PrismicLink\";\n\nimport { usePrismicContext } from \"./usePrismicContext\";\n\nexport type { LinkProps, PrismicLinkProps };\n\nexport const PrismicLink = React.forwardRef(function PrismicLink<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n) {\n\tconst context = usePrismicContext();\n\n\treturn (\n\t\t<ServerPrismicLink\n\t\t\tref={ref}\n\t\t\tlinkResolver={context.linkResolver}\n\t\t\tinternalComponent={context.internalLinkComponent}\n\t\t\texternalComponent={context.externalLinkComponent}\n\t\t\t{...props}\n\t\t/>\n\t);\n}) as <\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: React.ForwardedRef<Element>;\n\t},\n) => JSX.Element;\n"],"names":["PrismicLink","ServerPrismicLink"],"mappings":";;;;AAeO,MAAM,cAAc,MAAM,WAAW,SAASA,aAIpD,OACA,KAAgC;AAEhC,QAAM,UAAU;AAEhB,SACE,oBAAAC,eAAA,EACA,KACA,cAAc,QAAQ,cACtB,mBAAmB,QAAQ,uBAC3B,mBAAmB,QAAQ,uBAC3B,GAAI,MAAM,CAAA;AAGb,CAAC;"}
1
+ {"version":3,"file":"PrismicLink.js","sources":["../src/PrismicLink.tsx"],"sourcesContent":["import {\n\tComponentProps,\n\tComponentType,\n\tElementType,\n\tForwardedRef,\n\tHTMLAttributeAnchorTarget,\n\tReactNode,\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/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?: ElementType<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\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"],"names":["PrismicLink","_jsx"],"mappings":";;;;;AAqBA,MAAM,mBAAmB;AAkFlB,MAAM,cAAc,WAAW,SAASA,aAI9C,OACA,KAA0B;AAEpB,QAAA,EACL,OACA,UAAU,KACV,cACA,mBACA,mBACA,UACA,GAAG,UAAA,IACA;AAEJ,MAAI,KAAK;AACR,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8I,OAC7I,yBAAyB,CACzB,EAAE;AAAA,MAAA,YAGH,UAAU,QACR,OAAO,KAAK,KAAK,EAAE,SAAS,IAC5B,OAAO,KAAK,KAAK,EAAE,SAAS,MAC/B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAC7C;AACD,gBAAQ,KACP,uJAAuJ,OACtJ,yBAAyB,CACzB,IACD,KAAK;AAAA,MAAA;AAAA,eAGG,KAAK;AACf,UAAI,EAAE,SAAS,OAAO,QAAQ,MAAM;AACnC,gBAAQ,KACP,0JAA0J,OACzJ,yBAAyB,CACzB,IACD,GAAG;AAAA,MAAA;AAAA,IAEL;AAAA,EACD;AAGK,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,MAAI,MAA0B;AAC9B,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGjB,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,QAAM,oBAAqB,qBAC1B;AACD,QAAM,oBAAqB,qBAC1B;AACD,QAAM,YAAY,OACf,cAAc,IAAI,IACjB,oBACA,oBACD;AAEH,SACCC,IAAC,WAAS,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eACzD,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;AAiBK,SAAU,cAAc,KAAW;AAClC,QAAA,aAAa,gBAAgB,KAAK,GAAG;AAC3C,QAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;AAE7D,SAAO,cAAc,CAAC;AACvB;"}
@@ -1,4 +1,117 @@
1
- import * as prismic from "@prismicio/client";
2
- import { PrismicRichTextProps } from "./react-server/PrismicRichText";
3
- export type { PrismicRichTextProps };
4
- export declare const PrismicRichText: <LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) => import("react").JSX.Element;
1
+ import { ComponentType, ReactNode } from "react";
2
+ import { LinkResolverFunction, RichTextField } from "@prismicio/client";
3
+ import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext";
4
+ import { LinkProps } from "./PrismicLink.js";
5
+ /**
6
+ * A function mapping Rich Text block types to React Components. It is used to
7
+ * render Rich Text or Title fields.
8
+ *
9
+ * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
10
+ */
11
+ export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
12
+ /**
13
+ * A map of Rich Text block types to React Components. It is used to render Rich
14
+ * Text or Title fields.
15
+ *
16
+ * @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
17
+ */
18
+ export type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
19
+ /** Props for `<PrismicRichText>`. */
20
+ export type PrismicRichTextProps = {
21
+ /** The Prismic Rich Text field to render. */
22
+ field: RichTextField | null | undefined;
23
+ /**
24
+ * The Link Resolver used to resolve links.
25
+ *
26
+ * @remarks
27
+ * If your app uses Route Resolvers when querying for your Prismic
28
+ * repository's content, a Link Resolver does not need to be provided.
29
+ *
30
+ * @see Learn about Link Resolvers and Route Resolvers {@link https://io/docs/core-concepts/link-resolver-route-resolver}
31
+ */
32
+ linkResolver?: LinkResolverFunction;
33
+ /**
34
+ * A map or function that maps a Rich Text block to a React component.
35
+ *
36
+ * @remarks
37
+ * Prefer using a map serializer over the function serializer when possible.
38
+ * The map serializer is simpler to maintain.
39
+ *
40
+ * @example A map serializer.
41
+ *
42
+ * ```jsx
43
+ * {
44
+ * heading1: ({children}) => <Heading>{children}</Heading>
45
+ * }
46
+ * ```
47
+ *
48
+ * @example A function serializer.
49
+ *
50
+ * ```jsx
51
+ * (type, node, content, children) => {
52
+ * switch (type) {
53
+ * case "heading1": {
54
+ * return <Heading>{children}</Heading>;
55
+ * }
56
+ * }
57
+ * };
58
+ * ```
59
+ */
60
+ components?: JSXMapSerializer | JSXFunctionSerializer;
61
+ /**
62
+ * The React component rendered for links when the URL is internal.
63
+ *
64
+ * @defaultValue `<a>`
65
+ */
66
+ internalLinkComponent?: ComponentType<LinkProps>;
67
+ /**
68
+ * The React component rendered for links when the URL is external.
69
+ *
70
+ * @defaultValue `<a>`
71
+ */
72
+ externalLinkComponent?: ComponentType<LinkProps>;
73
+ /**
74
+ * The value to be rendered when the field is empty. If a fallback is not
75
+ * given, `null` will be rendered.
76
+ */
77
+ fallback?: ReactNode;
78
+ };
79
+ /**
80
+ * React component that renders content from a Prismic Rich Text field. By
81
+ * default, HTML elements are rendered for each piece of content. A `heading1`
82
+ * block will render an `<h1>` HTML element, for example. Links will use
83
+ * `<PrismicLink>` by default which can be customized using the
84
+ * `internalLinkComponent` and `externalLinkComponent` props.
85
+ *
86
+ * To customize the components that are rendered, provide a map or function
87
+ * serializer to the `components` prop.
88
+ *
89
+ * @remarks
90
+ * This component returns a React fragment with no wrapping element around the
91
+ * content. If you need a wrapper, add a component around `<PrismicRichText>`.
92
+ *
93
+ * @example Rendering a Rich Text field using the default HTMl elements.
94
+ *
95
+ * ```jsx
96
+ * <PrismicRichText field={document.data.content} />;
97
+ * ```
98
+ *
99
+ * @example Rendering a Rich Text field using a custom set of React components.
100
+ *
101
+ * ```jsx
102
+ * <PrismicRichText
103
+ * field={document.data.content}
104
+ * components={{
105
+ * heading1: ({ children }) => <Heading>{children}</Heading>,
106
+ * }}
107
+ * />;
108
+ * ```
109
+ *
110
+ * @param props - Props for the component.
111
+ *
112
+ * @returns The Rich Text field's content as React components.
113
+ *
114
+ * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
115
+ * @see Learn about Rich Text serializers {@link https://io/docs/core-concepts/html-serializer}
116
+ */
117
+ export declare function PrismicRichText(props: PrismicRichTextProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,12 +1,78 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import * as prismicR from "@prismicio/richtext";
3
- import { PrismicRichText as PrismicRichText$1 } from "./react-server/PrismicRichText.js";
4
- import { usePrismicContext } from "./usePrismicContext.js";
5
- const PrismicRichText = function PrismicRichText2({ components, ...restProps }) {
6
- const context = usePrismicContext();
7
- const serializer = prismicR.composeSerializers(typeof components === "object" ? prismicR.wrapMapSerializer(components) : components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents);
8
- return /* @__PURE__ */ jsx(PrismicRichText$1, { components: serializer, internalLinkComponent: context.internalLinkComponent, externalLinkComponent: context.externalLinkComponent, ...restProps });
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { isValidElement, cloneElement, Fragment as Fragment$1 } from "react";
3
+ import { isFilled } from "@prismicio/client";
4
+ import { composeSerializers, wrapMapSerializer, serialize } from "@prismicio/client/richtext";
5
+ import { DEV } from "esm-env";
6
+ import { devMsg } from "./lib/devMsg.js";
7
+ import { PrismicLink } from "./PrismicLink.js";
8
+ const getDir = (node) => {
9
+ if ("direction" in node && node.direction === "rtl") {
10
+ return "rtl";
11
+ }
9
12
  };
13
+ const createDefaultSerializer = (args) => wrapMapSerializer({
14
+ heading1: ({ node, children, key }) => jsx("h1", { dir: getDir(node), children }, key),
15
+ heading2: ({ node, children, key }) => jsx("h2", { dir: getDir(node), children }, key),
16
+ heading3: ({ node, children, key }) => jsx("h3", { dir: getDir(node), children }, key),
17
+ heading4: ({ node, children, key }) => jsx("h4", { dir: getDir(node), children }, key),
18
+ heading5: ({ node, children, key }) => jsx("h5", { dir: getDir(node), children }, key),
19
+ heading6: ({ node, children, key }) => jsx("h6", { dir: getDir(node), children }, key),
20
+ paragraph: ({ node, children, key }) => jsx("p", { dir: getDir(node), children }, key),
21
+ preformatted: ({ node, key }) => jsx("pre", { children: node.text }, key),
22
+ strong: ({ children, key }) => jsx("strong", { children }, key),
23
+ em: ({ children, key }) => jsx("em", { children }, key),
24
+ listItem: ({ node, children, key }) => jsx("li", { dir: getDir(node), children }, key),
25
+ oListItem: ({ node, children, key }) => jsx("li", { dir: getDir(node), children }, key),
26
+ list: ({ children, key }) => jsx("ul", { children }, key),
27
+ oList: ({ children, key }) => jsx("ol", { children }, key),
28
+ image: ({ node, key }) => {
29
+ const img = jsx("img", { src: node.url, alt: node.alt ?? void 0, "data-copyright": node.copyright ? node.copyright : void 0 });
30
+ return jsx("p", { className: "block-img", children: node.linkTo ? jsx(PrismicLink, { linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, field: node.linkTo, children: img }) : img }, key);
31
+ },
32
+ embed: ({ node, key }) => jsx("div", { "data-oembed": node.oembed.embed_url, "data-oembed-type": node.oembed.type, "data-oembed-provider": node.oembed.provider_name, dangerouslySetInnerHTML: { __html: node.oembed.html ?? "" } }, key),
33
+ hyperlink: ({ node, children, key }) => jsx(PrismicLink, { field: node.data, linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, children }, key),
34
+ label: ({ node, children, key }) => jsx("span", { className: node.data.label, children }, key),
35
+ span: ({ text, key }) => {
36
+ const result = [];
37
+ let i = 0;
38
+ for (const line of text.split("\n")) {
39
+ if (i > 0) {
40
+ result.push(jsx("br", {}, `${i}__break`));
41
+ }
42
+ result.push(jsx(Fragment$1, { children: line }, `${i}__line`));
43
+ i++;
44
+ }
45
+ return jsx(Fragment$1, { children: result }, key);
46
+ }
47
+ });
48
+ function PrismicRichText(props) {
49
+ const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent, ...restProps } = props;
50
+ if (DEV) {
51
+ if ("className" in restProps) {
52
+ 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);
53
+ }
54
+ }
55
+ if (!isFilled.richText(field)) {
56
+ return fallback != null ? jsx(Fragment, { children: fallback }) : null;
57
+ }
58
+ const serializer = composeSerializers(typeof components === "object" ? wrapMapSerializer(components) : components, createDefaultSerializer({
59
+ linkResolver,
60
+ internalLinkComponent,
61
+ externalLinkComponent
62
+ }));
63
+ const serialized = serialize(field, (type, node, text, children, key) => {
64
+ const result = serializer(type, node, text, children, key);
65
+ if (isValidElement(result) && result.key == null) {
66
+ return cloneElement(result, { key });
67
+ } else {
68
+ return result;
69
+ }
70
+ });
71
+ if (!serialized) {
72
+ return fallback != null ? jsx(Fragment, { children: fallback }) : null;
73
+ }
74
+ return jsx(Fragment, { children: serialized });
75
+ }
10
76
  export {
11
77
  PrismicRichText
12
78
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichText.js","sources":["../../src/PrismicRichText.tsx"],"sourcesContent":["\"use client\";\n\nimport * as prismic from \"@prismicio/client\";\nimport * as prismicR from \"@prismicio/richtext\";\n\nimport {\n\tPrismicRichText as ServerPrismicRichText,\n\tPrismicRichTextProps,\n} from \"./react-server/PrismicRichText\";\n\nimport { usePrismicContext } from \"./usePrismicContext\";\n\nexport type { PrismicRichTextProps };\n\nexport const PrismicRichText = function PrismicRichText<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,\n>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) {\n\tconst context = usePrismicContext();\n\n\tconst serializer = prismicR.composeSerializers(\n\t\ttypeof components === \"object\"\n\t\t\t? prismicR.wrapMapSerializer(components)\n\t\t\t: components,\n\t\ttypeof context.richTextComponents === \"object\"\n\t\t\t? prismicR.wrapMapSerializer(context.richTextComponents)\n\t\t\t: context.richTextComponents,\n\t);\n\n\treturn (\n\t\t<ServerPrismicRichText\n\t\t\tcomponents={serializer}\n\t\t\tinternalLinkComponent={context.internalLinkComponent}\n\t\t\texternalLinkComponent={context.externalLinkComponent}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"names":["PrismicRichText","ServerPrismicRichText"],"mappings":";;;;AAcO,MAAM,kBAAkB,SAASA,iBAGtC,EAAE,YAAY,GAAG,aAAuD;AACzE,QAAM,UAAU;AAEV,QAAA,aAAa,SAAS,mBAC3B,OAAO,eAAe,WACnB,SAAS,kBAAkB,UAAU,IACrC,YACH,OAAO,QAAQ,uBAAuB,WACnC,SAAS,kBAAkB,QAAQ,kBAAkB,IACrD,QAAQ,kBAAkB;AAI7B,SAAA,oBAACC,mBACA,EAAA,YAAY,YACZ,uBAAuB,QAAQ,uBAC/B,uBAAuB,QAAQ,uBAC3B,GAAA,UAAU,CAAA;AAGjB;"}
1
+ {"version":3,"file":"PrismicRichText.js","sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tcloneElement,\n\tComponentType,\n\tFragment,\n\tisValidElement,\n\tReactNode,\n} from \"react\";\nimport {\n\tisFilled,\n\tLinkResolverFunction,\n\tRichTextField,\n\tRTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping Rich Text block types to React Components. It is used to\n * render Rich Text or Title fields.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of Rich Text block types to React Components. It is used to render Rich\n * Text or Title fields.\n *\n * @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type JSXMapSerializer = RichTextMapSerializer<ReactNode>;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic Rich Text field to render. */\n\tfield: RichTextField | null | undefined;\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://io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a Rich Text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: JSXMapSerializer | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\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\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * React component that renders content from a Prismic Rich Text field. By\n * default, HTML elements are rendered for each piece of content. A `heading1`\n * block will render an `<h1>` HTML element, for example. Links will use\n * `<PrismicLink>` by default which can be customized using the\n * `internalLinkComponent` and `externalLinkComponent` props.\n *\n * To customize the components that are rendered, provide a map or function\n * serializer to the `components` prop.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicRichText>`.\n *\n * @example Rendering a Rich Text field using the default HTMl elements.\n *\n * ```jsx\n * <PrismicRichText field={document.data.content} />;\n * ```\n *\n * @example Rendering a Rich Text field using a custom set of React components.\n *\n * ```jsx\n * <PrismicRichText\n * \tfield={document.data.content}\n * \tcomponents={{\n * \t\theading1: ({ children }) => <Heading>{children}</Heading>,\n * \t}}\n * />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as React components.\n *\n * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}\n * @see Learn about Rich Text serializers {@link https://io/docs/core-concepts/html-serializer}\n */\nexport function PrismicRichText(props: PrismicRichTextProps) {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\n}\n"],"names":["_jsx","Fragment","_Fragment"],"mappings":"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"}
@@ -1,20 +1,14 @@
1
- import * as prismic from "@prismicio/client";
2
- /**
3
- * Props for `<PrismicText>`.
4
- */
1
+ import { RichTextField } from "@prismicio/client";
2
+ /** Props for `<PrismicText>`. */
5
3
  export type PrismicTextProps = {
6
- /**
7
- * The Prismic Rich Text field to render.
8
- */
9
- field: prismic.RichTextField | null | undefined;
4
+ /** The Prismic Rich Text field to render. */
5
+ field: RichTextField | null | undefined;
10
6
  /**
11
7
  * The string rendered when the field is empty. If a fallback is not given,
12
8
  * `null` will be rendered.
13
9
  */
14
10
  fallback?: string;
15
- /**
16
- * The separator used between blocks. Defaults to `\n`.
17
- */
11
+ /** The separator used between blocks. Defaults to `\n`. */
18
12
  separator?: string;
19
13
  };
20
14
  /**
@@ -24,6 +18,7 @@ export type PrismicTextProps = {
24
18
  * @remarks
25
19
  * This component returns a React fragment with no wrapping element around the
26
20
  * content. If you need a wrapper, add a component around `<PrismicText>`.
21
+ *
27
22
  * @example Rendering a Rich Text field as plain text.
28
23
  *
29
24
  * ```jsx
@@ -34,6 +29,6 @@ export type PrismicTextProps = {
34
29
  *
35
30
  * @returns The Rich Text field's content as plain text.
36
31
  *
37
- * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
32
+ * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
38
33
  */
39
- export declare const PrismicText: (props: PrismicTextProps) => JSX.Element | null;
34
+ export declare function PrismicText(props: PrismicTextProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,26 +1,25 @@
1
1
  import { jsx, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
2
+ import { isFilled, asText } from "@prismicio/client";
3
+ import { DEV } from "esm-env";
3
4
  import { devMsg } from "./lib/devMsg.js";
4
- import { richText } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
5
- import { asText } from './_node_modules/@prismicio/client/dist/helpers/asText.js';
6
- const PrismicText = (props) => {
7
- if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
5
+ function PrismicText(props) {
6
+ const { field, fallback, separator } = props;
7
+ if (DEV) {
8
8
  if ("className" in props) {
9
9
  console.warn(`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, props.field);
10
10
  }
11
- if (typeof props.field === "string") {
12
- throw new Error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`);
13
- }
14
11
  }
15
- return React.useMemo(() => {
16
- if (richText(props.field)) {
17
- const text = asText(props.field, props.separator);
18
- return /* @__PURE__ */ jsx(Fragment, { children: text });
19
- } else {
20
- return props.fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: props.fallback }) : null;
12
+ if (typeof props.field === "string") {
13
+ if (DEV) {
14
+ console.error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`, props.field);
21
15
  }
22
- }, [props.field, props.fallback, props.separator]);
23
- };
16
+ return null;
17
+ }
18
+ if (!isFilled.richText(field)) {
19
+ return fallback != null ? jsx(Fragment, { children: fallback }) : null;
20
+ }
21
+ return jsx(Fragment, { children: asText(field, { separator }) });
22
+ }
24
23
  export {
25
24
  PrismicText
26
25
  };