@prismicio/react 2.6.1 → 2.7.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 (60) hide show
  1. package/dist/PrismicImage.cjs +1 -1
  2. package/dist/PrismicImage.cjs.map +1 -1
  3. package/dist/PrismicImage.js +1 -1
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicRichText.d.ts +1 -1
  6. package/dist/PrismicText.cjs +1 -1
  7. package/dist/PrismicText.cjs.map +1 -1
  8. package/dist/PrismicText.js +1 -1
  9. package/dist/PrismicText.js.map +1 -1
  10. package/dist/PrismicToolbar.cjs +1 -1
  11. package/dist/PrismicToolbar.cjs.map +1 -1
  12. package/dist/PrismicToolbar.js +1 -1
  13. package/dist/PrismicToolbar.js.map +1 -1
  14. package/dist/SliceZone.cjs +27 -37
  15. package/dist/SliceZone.cjs.map +1 -1
  16. package/dist/SliceZone.d.ts +36 -33
  17. package/dist/SliceZone.js +27 -20
  18. package/dist/SliceZone.js.map +1 -1
  19. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +2 -2
  20. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  21. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +2 -2
  22. package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  23. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +2 -2
  24. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  25. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +2 -2
  26. package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  27. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +12 -3
  28. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -1
  29. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +12 -3
  30. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -1
  31. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +11 -2
  32. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +1 -1
  33. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +11 -2
  34. package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +1 -1
  35. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +1 -1
  36. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +1 -1
  37. package/dist/clientHooks.cjs.map +1 -1
  38. package/dist/clientHooks.d.ts +44 -116
  39. package/dist/clientHooks.js.map +1 -1
  40. package/dist/index.d.ts +0 -1
  41. package/dist/package.json.cjs +1 -1
  42. package/dist/package.json.js +1 -1
  43. package/dist/react-server/PrismicLink.cjs +1 -1
  44. package/dist/react-server/PrismicLink.cjs.map +1 -1
  45. package/dist/react-server/PrismicLink.js +1 -1
  46. package/dist/react-server/PrismicLink.js.map +1 -1
  47. package/dist/react-server/PrismicRichText.cjs +1 -1
  48. package/dist/react-server/PrismicRichText.cjs.map +1 -1
  49. package/dist/react-server/PrismicRichText.js +1 -1
  50. package/dist/react-server/PrismicRichText.js.map +1 -1
  51. package/package.json +30 -18
  52. package/src/PrismicImage.tsx +4 -1
  53. package/src/PrismicText.tsx +4 -1
  54. package/src/PrismicToolbar.tsx +1 -1
  55. package/src/SliceZone.tsx +111 -93
  56. package/src/clientHooks.ts +26 -26
  57. package/src/index.ts +0 -2
  58. package/src/react-server/PrismicLink.tsx +4 -1
  59. package/src/react-server/PrismicRichText.tsx +4 -1
  60. package/src/lib/processPolyfill.ts +0 -4
@@ -25,7 +25,7 @@ function _interopNamespaceDefault(e) {
25
25
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
26
26
  const PrismicImage = React__namespace.forwardRef(function PrismicImage2(props, ref) {
27
27
  const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
28
- if (process.env.NODE_ENV === "development") {
28
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
29
29
  if (typeof alt === "string" && props.alt !== "") {
30
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
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicImage.cjs","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\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?: Parameters<typeof prismic.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 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\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 (process.env.NODE_ENV === \"development\") {\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 (prismic.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 = prismic.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 = prismic.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"],"names":["React","PrismicImage","devMsg","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwGO,MAAM,eAAeA,iBAAM,WAAW,SAASC,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEA,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,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,SAAAA,eAAgC,KAAK,GAAG;AACvC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMC,mBAAQ,mBAAmB,OAAO;AAAA,QAC7C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMC,0BAAQ,0BAA0B,OAAO;AAAA,QACpD,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,CAAC;;"}
1
+ {"version":3,"file":"PrismicImage.cjs","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\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?: Parameters<typeof prismic.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 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\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 (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\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 (prismic.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 = prismic.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 = prismic.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"],"names":["React","PrismicImage","devMsg","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwGO,MAAM,eAAeA,iBAAM,WAAW,SAASC,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEJ,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,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,SAAAA,eAAgC,KAAK,GAAG;AACvC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMC,mBAAQ,mBAAmB,OAAO;AAAA,QAC7C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMC,0BAAQ,0BAA0B,OAAO;AAAA,QACpD,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,CAAC;;"}
@@ -6,7 +6,7 @@ import { asImageWidthSrcSet } from './_node_modules/@prismicio/client/dist/helpe
6
6
  import { asImagePixelDensitySrcSet } from './_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js';
7
7
  const PrismicImage = React.forwardRef(function PrismicImage2(props, ref) {
8
8
  const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
9
- if (process.env.NODE_ENV === "development") {
9
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
10
10
  if (typeof alt === "string" && props.alt !== "") {
11
11
  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")}`);
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicImage.js","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\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?: Parameters<typeof prismic.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 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\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 (process.env.NODE_ENV === \"development\") {\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 (prismic.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 = prismic.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 = prismic.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"],"names":["PrismicImage","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet"],"mappings":";;;;;;AAwGO,MAAM,eAAe,MAAM,WAAW,SAASA,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEA,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,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,MAAIC,eAAgC,KAAK,GAAG;AACvC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMC,mBAA2B,OAAO;AAAA,QAC7C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMC,0BAAkC,OAAO;AAAA,QACpD,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,CAAC;"}
1
+ {"version":3,"file":"PrismicImage.js","sources":["../../src/PrismicImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\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?: Parameters<typeof prismic.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 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\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 (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\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 (prismic.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 = prismic.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 = prismic.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"],"names":["PrismicImage","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet"],"mappings":";;;;;;AAwGO,MAAM,eAAe,MAAM,WAAW,SAASA,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEJ,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,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,MAAIC,eAAgC,KAAK,GAAG;AACvC,QAAA;AACA,QAAA;AAEA,QAAA,UAAU,CAAC,gBAAgB;AACxB,YAAA,MAAMC,mBAA2B,OAAO;AAAA,QAC7C,GAAG;AAAA,QACH,QAAQ,WAAW,aAAa,SAAY;AAAA,MAAA,CAC5C;AAED,YAAM,IAAI;AACV,eAAS,IAAI;AAAA,eACH,gBAAgB;AACpB,YAAA,MAAMC,0BAAkC,OAAO;AAAA,QACpD,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,CAAC;"}
@@ -1,4 +1,4 @@
1
1
  import * as prismic from "@prismicio/client";
2
2
  import { PrismicRichTextProps } from "./react-server/PrismicRichText";
3
3
  export { PrismicRichTextProps };
4
- export declare const PrismicRichText: <LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) => JSX.Element;
4
+ export declare const PrismicRichText: <LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) => import("react").JSX.Element;
@@ -23,7 +23,7 @@ function _interopNamespaceDefault(e) {
23
23
  }
24
24
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
25
25
  const PrismicText = (props) => {
26
- if (process.env.NODE_ENV === "development") {
26
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
27
27
  if ("className" in props) {
28
28
  console.warn(`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg.devMsg("classname-is-not-a-valid-prop")}.`, props.field);
29
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.cjs","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\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 `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[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(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["devMsg","React","prismic.isFilled.richText","prismic.asText","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6Ca,MAAA,cAAc,CAAC,UAA+C;AACtE,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,QAAI,eAAe,OAAO;AACzB,cAAQ,KACP,6IAA6IA,OAAA,OAC5I,+BAA+B,MAEhC,MAAM,KAAK;AAAA,IAEZ;AAEG,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoRA,OAAA,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAAC,iBAAM,QAAQ,MAAK;AACzB,QAAIC,SAA0B,SAAA,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAOC,OAAAA,OAAe,MAAM,OAAO,MAAM,SAAS;AAExD,mEAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAUC,+BAAAC,WAAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;;"}
1
+ {"version":3,"file":"PrismicText.cjs","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\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 `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[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(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["devMsg","React","prismic.isFilled.richText","prismic.asText","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,QAAI,eAAe,OAAO;AACzB,cAAQ,KACP,6IAA6IA,OAAA,OAC5I,+BAA+B,MAEhC,MAAM,KAAK;AAAA,IAEZ;AAEG,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoRA,OAAA,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAAC,iBAAM,QAAQ,MAAK;AACzB,QAAIC,SAA0B,SAAA,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAOC,OAAAA,OAAe,MAAM,OAAO,MAAM,SAAS;AAExD,mEAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAUC,+BAAAC,WAAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;;"}
@@ -4,7 +4,7 @@ import { devMsg } from "./lib/devMsg.js";
4
4
  import { richText } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
5
5
  import { asText } from './_node_modules/@prismicio/client/dist/helpers/asText.js';
6
6
  const PrismicText = (props) => {
7
- if (process.env.NODE_ENV === "development") {
7
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.js","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\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 `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[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(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["prismic.isFilled.richText","prismic.asText"],"mappings":";;;;;AA6Ca,MAAA,cAAc,CAAC,UAA+C;AACtE,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,QAAI,eAAe,OAAO;AACzB,cAAQ,KACP,6IAA6I,OAC5I,+BAA+B,MAEhC,MAAM,KAAK;AAAA,IAEZ;AAEG,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoR,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAA,MAAM,QAAQ,MAAK;AACzB,QAAIA,SAA0B,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAOC,OAAe,MAAM,OAAO,MAAM,SAAS;AAExD,6CAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAU,oBAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;"}
1
+ {"version":3,"file":"PrismicText.js","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\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 `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[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(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["prismic.isFilled.richText","prismic.asText"],"mappings":";;;;;AA6Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,QAAI,eAAe,OAAO;AACzB,cAAQ,KACP,6IAA6I,OAC5I,+BAA+B,MAEhC,MAAM,KAAK;AAAA,IAEZ;AAEG,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoR,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAA,MAAM,QAAQ,MAAK;AACzB,QAAIA,SAA0B,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAOC,OAAe,MAAM,OAAO,MAAM,SAAS;AAExD,6CAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAU,oBAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;"}
@@ -32,7 +32,7 @@ const PrismicToolbar = ({ repositoryName }) => {
32
32
  script.defer = true;
33
33
  script.dataset.prismicToolbar = "";
34
34
  script.dataset.repositoryName = repositoryName;
35
- if (process.env.NODE_ENV === "test") {
35
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
36
36
  script._evaluateScript = false;
37
37
  }
38
38
  document.body.appendChild(script);
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BO;AAGA;AAENA;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;"}
1
+ {"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (typeof process !== \"undefined\" && process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BO;AAGA;AAENA;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUA;AAEC;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;"}
@@ -13,7 +13,7 @@ const PrismicToolbar = ({ repositoryName }) => {
13
13
  script.defer = true;
14
14
  script.dataset.prismicToolbar = "";
15
15
  script.dataset.repositoryName = repositoryName;
16
- if (process.env.NODE_ENV === "test") {
16
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "test") {
17
17
  script._evaluateScript = false;
18
18
  }
19
19
  document.body.appendChild(script);
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";;;;;AA6BO;AAGA;AAEN;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;;;"}
1
+ {"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (typeof process !== \"undefined\" && process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";;;;;AA6BO;AAGA;AAEN;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUA;AAEC;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;;;"}
@@ -1,27 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
- const React = require("react");
5
4
  const pascalCase = require("./lib/pascalCase.cjs");
6
- function _interopNamespaceDefault(e) {
7
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
- if (e) {
9
- for (const k in e) {
10
- if (k !== "default") {
11
- const d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: () => e[k]
15
- });
16
- }
17
- }
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
- const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
23
5
  const TODOSliceComponent = ({ slice }) => {
24
- if (process.env.NODE_ENV === "development") {
6
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
25
7
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
26
8
  console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
27
9
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
@@ -33,27 +15,35 @@ const TODOSliceComponent = ({ slice }) => {
33
15
  return null;
34
16
  }
35
17
  };
36
- const SliceZone = ({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) => {
37
- const renderedSlices = React__namespace.useMemo(() => {
38
- return slices.map((slice, index) => {
39
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
40
- let Comp = components[type] || defaultComponent;
41
- if (resolver) {
42
- const resolvedComp = resolver({
43
- slice,
44
- sliceName: pascalCase.pascalCase(type),
45
- i: index
46
- });
47
- if (resolvedComp) {
48
- Comp = resolvedComp;
49
- }
18
+ function SliceZone({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) {
19
+ if (process.env.NODE_ENV === "development") {
20
+ if (resolver) {
21
+ console.warn("The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.");
22
+ }
23
+ }
24
+ const renderedSlices = slices.map((slice, index) => {
25
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
26
+ let Comp = components[type] || defaultComponent;
27
+ if (resolver) {
28
+ const resolvedComp = resolver({
29
+ slice,
30
+ sliceName: pascalCase.pascalCase(type),
31
+ i: index
32
+ });
33
+ if (resolvedComp) {
34
+ Comp = resolvedComp;
50
35
  }
51
- const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
36
+ }
37
+ const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
38
+ if (slice.__mapped) {
39
+ const { __mapped, ...mappedProps } = slice;
40
+ return /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...mappedProps }, key);
41
+ } else {
52
42
  return /* @__PURE__ */ jsxRuntime.jsx(Comp, { slice, index, slices, context }, key);
53
- });
54
- }, [components, context, defaultComponent, slices, resolver]);
43
+ }
44
+ });
55
45
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderedSlices });
56
- };
46
+ }
57
47
  exports.SliceZone = SliceZone;
58
48
  exports.TODOSliceComponent = TODOSliceComponent;
59
49
  //# sourceMappingURL=SliceZone.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SliceZone.cjs","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { pascalCase, PascalCase } from \"./lib/pascalCase\";\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2\n\t? Slice[\"slice_type\"]\n\t: Slice extends SliceLikeGraphQL\n\t? Slice[\"type\"]\n\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<SliceType extends string = string> = {\n\tslice_type: prismic.Slice<SliceType>[\"slice_type\"];\n\tid?: string;\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `<SliceZone>` component.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<SliceType extends string = string> = {\n\ttype: prismic.Slice<SliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<SliceType extends string = string> =\n\t| SliceLikeRestV2<SliceType>\n\t| SliceLikeGraphQL<SliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/types` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/types` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> =\n\treadonly TSlice[];\n\n/**\n * React props for a component rendering content from a Prismic Slice using the\n * `<SliceZone>` component.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made\n * available to all Slice components.\n */\nexport type SliceComponentProps<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = {\n\t/**\n\t * Slice data for this component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\tindex: number;\n\n\t/**\n\t * All Slices from the Slice Zone to which the Slice belongs.\n\t */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<SliceLike>;\n\n\t/**\n\t * Arbitrary data passed to `<SliceZone>` and made available to all Slice\n\t * components.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A React component to be rendered for each instance of its Slice.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceComponentType<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;\n\n/**\n * A record of Slice types mapped to a React component. The component will be\n * rendered for each instance of its Slice.\n *\n * @deprecated This type is no longer used by `@prismicio/react`. Prefer using\n * `Record<string, SliceComponentType<any>>` instead.\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneComponents<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> =\n\t// This is purposely not wrapped in Partial to ensure a component is provided\n\t// for all Slice types. <SliceZone> will render a default component if one is\n\t// not provided, but it *should* be a type error if an explicit component is\n\t// missing.\n\t//\n\t// If a developer purposely does not want to provide a component, they can\n\t// assign it to the TODOSliceComponent exported from this package. This\n\t// signals to future developers that it is a placeholder and should be\n\t// implemented.\n\t{\n\t\t[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<\n\t\t\tExtract<TSlice, SliceLike<SliceType>> extends never\n\t\t\t\t? SliceLike\n\t\t\t\t: Extract<TSlice, SliceLike<SliceType>>,\n\t\t\tTContext\n\t\t>;\n\t};\n\n/**\n * This Slice component can be used as a reminder to provide a proper\n * implementation.\n *\n * This is also the default React component rendered when a component mapping\n * cannot be found in `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike, TContext>({\n\tslice,\n}: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tconsole.warn(\n\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\tslice,\n\t\t);\n\n\t\treturn (\n\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\tCould not find a component for Slice type &ldquo;{type}\n\t\t\t\t&rdquo;\n\t\t\t</section>\n\t\t);\n\t} else {\n\t\treturn null;\n\t}\n};\n\n/**\n * Arguments for a `<SliceZone>` `resolver` function.\n */\ntype SliceZoneResolverArgs<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n> = {\n\t/**\n\t * The Slice to resolve to a React component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The name of the Slice.\n\t */\n\tsliceName: PascalCase<ExtractSliceType<TSlice>>;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\ti: number;\n};\n\n/**\n * A function that determines the rendered React component for each Slice in the\n * Slice Zone. If a nullish value is returned, the component will fallback to\n * the `components` or `defaultComponent` props to determine the rendered\n * component.\n *\n * @deprecated Use the `components` prop instead.\n *\n * @param args - Arguments for the resolver function.\n *\n * @returns The React component to render for a Slice.\n */\nexport type SliceZoneResolver<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = (args: SliceZoneResolverArgs<TSlice>) =>\n\t| SliceComponentType<\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tany,\n\t\t\tTContext\n\t >\n\t| undefined\n\t| null;\n\n/**\n * React props for the `<SliceZone>` component.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneProps<TContext = unknown> = {\n\t/**\n\t * List of Slice data from the Slice Zone.\n\t */\n\tslices?: SliceZoneLike;\n\n\t/**\n\t * A record mapping Slice types to React components.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcomponents?: Record<string, SliceComponentType<any, TContext>>;\n\n\t/**\n\t * A function that determines the rendered React component for each Slice in\n\t * the Slice Zone.\n\t *\n\t * @deprecated Use the `components` prop instead.\n\t *\n\t * @param args - Arguments for the resolver function.\n\t *\n\t * @returns The React component to render for a Slice.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tresolver?: SliceZoneResolver<any, TContext>;\n\n\t/**\n\t * The React component rendered if a component mapping from the `components`\n\t * prop cannot be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdefaultComponent?: SliceComponentType<any, TContext>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\n};\n\n/**\n * Renders content from a Prismic Slice Zone using React components for each\n * type of Slice.\n *\n * If a component is not provided for a type of Slice, a default component can\n * be provided. A fallback component is provided by default that will not be\n * rendered in a production build of your app.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n *\n * @returns The Slice Zone's content as React components.\n *\n * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}\n */\nexport const SliceZone = <TContext,>({\n\tslices = [],\n\tcomponents = {},\n\tresolver,\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>): JSX.Element => {\n\tconst renderedSlices = React.useMemo(() => {\n\t\treturn slices.map((slice, index) => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tlet Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\t\t// TODO: Remove `resolver` in v3 in favor of `components`.\n\t\t\tif (resolver) {\n\t\t\t\tconst resolvedComp = resolver({\n\t\t\t\t\tslice,\n\t\t\t\t\tsliceName: pascalCase(type),\n\t\t\t\t\ti: index,\n\t\t\t\t});\n\n\t\t\t\tif (resolvedComp) {\n\t\t\t\t\tComp = resolvedComp as typeof Comp;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst key =\n\t\t\t\t\"id\" in slice && slice.id\n\t\t\t\t\t? slice.id\n\t\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t});\n\t}, [components, context, defaultComponent, slices, resolver]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":["jsxs","React","pascalCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0JO,MAAM,qBAAqB,CAAqC,EACtE,YAC+D;AAC3D,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,YAAA,KACP,0DAA0D,SAC1D,KAAK;AAGN,WACEA,2BAAAA,KAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,MAAA;AAAA,MAAkD;AAAA,MAClD;AAAA,IACD,EAAA,CAAA;AAAA,EAAA,OAEK;AACC,WAAA;AAAA,EACP;AACF;AA6GO,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,CAAA,GACb,UACA,mBAAmB,oBACnB,UAAU,SACiC;AACrC,QAAA,iBAAiBC,iBAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE1D,UAAA,OACH,WAAW,IAA+B,KAAK;AAGhD,UAAI,UAAU;AACb,cAAM,eAAe,SAAS;AAAA,UAC7B;AAAA,UACA,WAAWC,sBAAW,IAAI;AAAA,UAC1B,GAAG;AAAA,QAAA,CACH;AAED,YAAI,cAAc;AACV,iBAAA;AAAA,QACP;AAAA,MACD;AAEK,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,4CACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,EAAA,GACC,CAAC,YAAY,SAAS,kBAAkB,QAAQ,QAAQ,CAAC;AAE5D,+DAAU,UAAe,eAAA,CAAA;AAC1B;;;"}
1
+ {"version":3,"file":"SliceZone.cjs","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import { ComponentType } from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { pascalCase, PascalCase } from \"./lib/pascalCase\";\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends prismic.Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceLikeGraphQL\n\t? TSlice[\"type\"]\n\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<TSliceType extends string = string> = Pick<\n\tprismic.Slice<TSliceType>,\n\t\"id\" | \"slice_type\"\n>;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<TSliceType extends string = string> = {\n\ttype: prismic.Slice<TSliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `unstable_mapSliceZone()` helper.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/client` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<TSliceType extends string = string> = (\n\t| SliceLikeRestV2<TSliceType>\n\t| SliceLikeGraphQL<TSliceType>\n) & {\n\t/**\n\t * If `true`, this Slice has been modified from its original value using a\n\t * mapper and `@prismicio/client`'s `mapSliceZone()`.\n\t *\n\t * @internal\n\t */\n\t__mapped?: true;\n};\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> =\n\treadonly TSlice[];\n\n/**\n * React props for a component rendering content from a Prismic Slice using the\n * `<SliceZone>` component.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made\n * available to all Slice components.\n */\nexport type SliceComponentProps<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t/**\n\t * Slice data for this component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\tindex: number;\n\n\t/**\n\t * All Slices from the Slice Zone to which the Slice belongs.\n\t */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<\n\t\tTSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `<SliceZone>` and made available to all Slice\n\t * components.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A React component to be rendered for each instance of its Slice.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceComponentType<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;\n\n/**\n * A record of Slice types mapped to a React component. The component will be\n * rendered for each instance of its Slice.\n *\n * @deprecated This type is no longer used by `@prismicio/react`. Prefer using\n * `Record<string, SliceComponentType<any>>` instead.\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneComponents<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> =\n\t// This is purposely not wrapped in Partial to ensure a component is provided\n\t// for all Slice types. <SliceZone> will render a default component if one is\n\t// not provided, but it *should* be a type error if an explicit component is\n\t// missing.\n\t//\n\t// If a developer purposely does not want to provide a component, they can\n\t// assign it to the TODOSliceComponent exported from this package. This\n\t// signals to future developers that it is a placeholder and should be\n\t// implemented.\n\t{\n\t\t[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<\n\t\t\tExtract<TSlice, SliceLike<SliceType>> extends never\n\t\t\t\t? SliceLike\n\t\t\t\t: Extract<TSlice, SliceLike<SliceType>>,\n\t\t\tTContext\n\t\t>;\n\t};\n\n/**\n * Arguments for a `<SliceZone>` `resolver` function.\n */\ntype SliceZoneResolverArgs<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n> = {\n\t/**\n\t * The Slice to resolve to a React component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The name of the Slice.\n\t */\n\tsliceName: PascalCase<ExtractSliceType<TSlice>>;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\ti: number;\n};\n\n/**\n * A function that determines the rendered React component for each Slice in the\n * Slice Zone. If a nullish value is returned, the component will fallback to\n * the `components` or `defaultComponent` props to determine the rendered\n * component.\n *\n * @deprecated Use the `components` prop instead.\n *\n * @param args - Arguments for the resolver function.\n *\n * @returns The React component to render for a Slice.\n */\nexport type SliceZoneResolver<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n> = (\n\targs: SliceZoneResolverArgs<TSlice>,\n) => // eslint-disable-next-line @typescript-eslint/no-explicit-any\nComponentType<any> | undefined | null;\n\n/**\n * React props for the `<SliceZone>` component.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneProps<TContext = unknown> = {\n\t/**\n\t * List of Slice data from the Slice Zone.\n\t */\n\tslices?: SliceZoneLike;\n\n\t/**\n\t * A record mapping Slice types to React components.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcomponents?: Record<string, ComponentType<any>>;\n\n\t/**\n\t * A function that determines the rendered React component for each Slice in\n\t * the Slice Zone.\n\t *\n\t * @deprecated Use the `components` prop instead.\n\t *\n\t * @param args - Arguments for the resolver function.\n\t *\n\t * @returns The React component to render for a Slice.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tresolver?: SliceZoneResolver<any>;\n\n\t/**\n\t * The React component rendered if a component mapping from the `components`\n\t * prop cannot be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdefaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\n};\n\n/**\n * This Slice component can be used as a reminder to provide a proper\n * implementation.\n *\n * This is also the default React component rendered when a component mapping\n * cannot be found in `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike, TContext>({\n\tslice,\n}: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tconsole.warn(\n\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\tslice,\n\t\t);\n\n\t\treturn (\n\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\tCould not find a component for Slice type &ldquo;{type}\n\t\t\t\t&rdquo;\n\t\t\t</section>\n\t\t);\n\t} else {\n\t\treturn null;\n\t}\n};\n\n/**\n * Renders content from a Prismic Slice Zone using React components for each\n * type of Slice.\n *\n * If a component is not provided for a type of Slice, a default component can\n * be provided. A fallback component is provided by default that will not be\n * rendered in a production build of your app.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n *\n * @returns The Slice Zone's content as React components.\n *\n * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}\n */\nexport function SliceZone<TContext>({\n\tslices = [],\n\tcomponents = {},\n\tresolver,\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>) {\n\t// TODO: Remove in v3 when the `resolver` prop is removed.\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (resolver) {\n\t\t\tconsole.warn(\n\t\t\t\t\"The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tconst renderedSlices = slices.map((slice, index) => {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tlet Comp = components[type as keyof typeof components] || defaultComponent;\n\n\t\t// TODO: Remove `resolver` in v3 in favor of `components`.\n\t\tif (resolver) {\n\t\t\tconst resolvedComp = resolver({\n\t\t\t\tslice,\n\t\t\t\tsliceName: pascalCase(type),\n\t\t\t\ti: index,\n\t\t\t});\n\n\t\t\tif (resolvedComp) {\n\t\t\t\tComp = resolvedComp as typeof Comp;\n\t\t\t}\n\t\t}\n\n\t\tconst key =\n\t\t\t\"id\" in slice && slice.id\n\t\t\t\t? slice.id\n\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\tif (slice.__mapped) {\n\t\t\tconst { __mapped, ...mappedProps } = slice;\n\n\t\t\treturn <Comp key={key} {...mappedProps} />;\n\t\t} else {\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t});\n\n\treturn <>{renderedSlices}</>;\n}\n"],"names":["jsxs","pascalCase","jsx"],"mappings":";;;;AAyPO,MAAM,qBAAqB,CAAqC,EACtE,YAC+D;AAC/D,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,YAAA,KACP,0DAA0D,SAC1D,KAAK;AAGN,WACEA,2BAAAA,KAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,MAAA;AAAA,MAAkD;AAAA,MAClD;AAAA,IACD,EAAA,CAAA;AAAA,EAAA,OAEK;AACC,WAAA;AAAA,EACP;AACF;AAiBM,SAAU,UAAoB,EACnC,SAAS,IACT,aAAa,CAAA,GACb,UACA,mBAAmB,oBACnB,UAAU,MACgB;AAEtB,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,QAAI,UAAU;AACb,cAAQ,KACP,yGAAyG;AAAA,IAE1G;AAAA,EACD;AAED,QAAM,iBAAiB,OAAO,IAAI,CAAC,OAAO,UAAS;AAClD,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE1D,QAAA,OAAO,WAAW,IAA+B,KAAK;AAG1D,QAAI,UAAU;AACb,YAAM,eAAe,SAAS;AAAA,QAC7B;AAAA,QACA,WAAWC,sBAAW,IAAI;AAAA,QAC1B,GAAG;AAAA,MAAA,CACH;AAED,UAAI,cAAc;AACV,eAAA;AAAA,MACP;AAAA,IACD;AAEK,UAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,QAAI,MAAM,UAAU;AACnB,YAAM,EAAE,UAAU,GAAG,YAAA,IAAgB;AAErC,aAAQC,2BAAAA,IAAA,MAAA,EAAe,GAAI,YAAA,GAAT,GAAqB;AAAA,IAAA,OACjC;AACN,4CACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAGnB;AAAA,EAAA,CACD;AAED,+DAAU,UAAe,eAAA,CAAA;AAC1B;;;"}
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import { ComponentType } from "react";
2
2
  import * as prismic from "@prismicio/client";
3
3
  import { PascalCase } from "./lib/pascalCase";
4
4
  /**
@@ -6,45 +6,47 @@ import { PascalCase } from "./lib/pascalCase";
6
6
  *
7
7
  * @typeParam Slice - The Slice from which the type will be extracted.
8
8
  */
9
- type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
9
+ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends prismic.Slice ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never;
10
10
  /**
11
11
  * The minimum required properties to represent a Prismic Slice from the Prismic
12
- * Rest API V2 for the `<SliceZone>` component.
13
- *
14
- * If using Prismic's Rest API V2, use the `Slice` export from
15
- * `@prismicio/types` for a full interface.
12
+ * Rest API V2 for the `unstable_mapSliceZone()` helper.
16
13
  *
17
14
  * @typeParam SliceType - Type name of the Slice.
18
15
  */
19
- export type SliceLikeRestV2<SliceType extends string = string> = {
20
- slice_type: prismic.Slice<SliceType>["slice_type"];
21
- id?: string;
22
- };
16
+ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<prismic.Slice<TSliceType>, "id" | "slice_type">;
23
17
  /**
24
18
  * The minimum required properties to represent a Prismic Slice from the Prismic
25
- * GraphQL API for the `<SliceZone>` component.
19
+ * GraphQL API for the `unstable_mapSliceZone()` helper.
26
20
  *
27
21
  * @typeParam SliceType - Type name of the Slice.
28
22
  */
29
- export type SliceLikeGraphQL<SliceType extends string = string> = {
30
- type: prismic.Slice<SliceType>["slice_type"];
23
+ export type SliceLikeGraphQL<TSliceType extends string = string> = {
24
+ type: prismic.Slice<TSliceType>["slice_type"];
31
25
  };
32
26
  /**
33
27
  * The minimum required properties to represent a Prismic Slice for the
34
- * `<SliceZone>` component.
28
+ * `unstable_mapSliceZone()` helper.
35
29
  *
36
30
  * If using Prismic's Rest API V2, use the `Slice` export from
37
- * `@prismicio/types` for a full interface.
31
+ * `@prismicio/client` for a full interface.
38
32
  *
39
33
  * @typeParam SliceType - Type name of the Slice.
40
34
  */
41
- export type SliceLike<SliceType extends string = string> = SliceLikeRestV2<SliceType> | SliceLikeGraphQL<SliceType>;
35
+ export type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
36
+ /**
37
+ * If `true`, this Slice has been modified from its original value using a
38
+ * mapper and `@prismicio/client`'s `mapSliceZone()`.
39
+ *
40
+ * @internal
41
+ */
42
+ __mapped?: true;
43
+ };
42
44
  /**
43
- * A looser version of the `SliceZone` type from `@prismicio/types` using
45
+ * A looser version of the `SliceZone` type from `@prismicio/client` using
44
46
  * `SliceLike`.
45
47
  *
46
48
  * If using Prismic's Rest API V2, use the `SliceZone` export from
47
- * `@prismicio/types` for the full type.
49
+ * `@prismicio/client` for the full type.
48
50
  *
49
51
  * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
50
52
  */
@@ -57,7 +59,7 @@ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlic
57
59
  * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
58
60
  * available to all Slice components.
59
61
  */
60
- export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unknown> = {
62
+ export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
61
63
  /**
62
64
  * Slice data for this component.
63
65
  */
@@ -69,7 +71,7 @@ export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unkno
69
71
  /**
70
72
  * All Slices from the Slice Zone to which the Slice belongs.
71
73
  */
72
- slices: SliceZoneLike<SliceLike>;
74
+ slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
73
75
  /**
74
76
  * Arbitrary data passed to `<SliceZone>` and made available to all Slice
75
77
  * components.
@@ -95,14 +97,6 @@ export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknow
95
97
  export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
96
98
  [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
97
99
  };
98
- /**
99
- * This Slice component can be used as a reminder to provide a proper
100
- * implementation.
101
- *
102
- * This is also the default React component rendered when a component mapping
103
- * cannot be found in `<SliceZone>`.
104
- */
105
- export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
106
100
  /**
107
101
  * Arguments for a `<SliceZone>` `resolver` function.
108
102
  */
@@ -132,7 +126,8 @@ type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
132
126
  *
133
127
  * @returns The React component to render for a Slice.
134
128
  */
135
- export type SliceZoneResolver<TSlice extends SliceLike = any, TContext = unknown> = (args: SliceZoneResolverArgs<TSlice>) => SliceComponentType<any, TContext> | undefined | null;
129
+ export type SliceZoneResolver<TSlice extends SliceLike = any> = (args: SliceZoneResolverArgs<TSlice>) => // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ ComponentType<any> | undefined | null;
136
131
  /**
137
132
  * React props for the `<SliceZone>` component.
138
133
  *
@@ -147,7 +142,7 @@ export type SliceZoneProps<TContext = unknown> = {
147
142
  /**
148
143
  * A record mapping Slice types to React components.
149
144
  */
150
- components?: Record<string, SliceComponentType<any, TContext>>;
145
+ components?: Record<string, ComponentType<any>>;
151
146
  /**
152
147
  * A function that determines the rendered React component for each Slice in
153
148
  * the Slice Zone.
@@ -158,17 +153,25 @@ export type SliceZoneProps<TContext = unknown> = {
158
153
  *
159
154
  * @returns The React component to render for a Slice.
160
155
  */
161
- resolver?: SliceZoneResolver<any, TContext>;
156
+ resolver?: SliceZoneResolver<any>;
162
157
  /**
163
158
  * The React component rendered if a component mapping from the `components`
164
159
  * prop cannot be found.
165
160
  */
166
- defaultComponent?: SliceComponentType<any, TContext>;
161
+ defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
167
162
  /**
168
163
  * Arbitrary data made available to all Slice components.
169
164
  */
170
165
  context?: TContext;
171
166
  };
167
+ /**
168
+ * This Slice component can be used as a reminder to provide a proper
169
+ * implementation.
170
+ *
171
+ * This is also the default React component rendered when a component mapping
172
+ * cannot be found in `<SliceZone>`.
173
+ */
174
+ export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
172
175
  /**
173
176
  * Renders content from a Prismic Slice Zone using React components for each
174
177
  * type of Slice.
@@ -184,5 +187,5 @@ export type SliceZoneProps<TContext = unknown> = {
184
187
  *
185
188
  * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
186
189
  */
187
- export declare const SliceZone: <TContext>({ slices, components, resolver, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
190
+ export declare function SliceZone<TContext>({ slices, components, resolver, defaultComponent, context, }: SliceZoneProps<TContext>): import("react").JSX.Element;
188
191
  export {};
package/dist/SliceZone.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
3
2
  import { pascalCase } from "./lib/pascalCase.js";
4
3
  const TODOSliceComponent = ({ slice }) => {
5
- if (process.env.NODE_ENV === "development") {
4
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
6
5
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
7
6
  console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
8
7
  return /* @__PURE__ */ jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
@@ -14,27 +13,35 @@ const TODOSliceComponent = ({ slice }) => {
14
13
  return null;
15
14
  }
16
15
  };
17
- const SliceZone = ({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) => {
18
- const renderedSlices = React.useMemo(() => {
19
- return slices.map((slice, index) => {
20
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
21
- let Comp = components[type] || defaultComponent;
22
- if (resolver) {
23
- const resolvedComp = resolver({
24
- slice,
25
- sliceName: pascalCase(type),
26
- i: index
27
- });
28
- if (resolvedComp) {
29
- Comp = resolvedComp;
30
- }
16
+ function SliceZone({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) {
17
+ if (process.env.NODE_ENV === "development") {
18
+ if (resolver) {
19
+ console.warn("The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.");
20
+ }
21
+ }
22
+ const renderedSlices = slices.map((slice, index) => {
23
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
24
+ let Comp = components[type] || defaultComponent;
25
+ if (resolver) {
26
+ const resolvedComp = resolver({
27
+ slice,
28
+ sliceName: pascalCase(type),
29
+ i: index
30
+ });
31
+ if (resolvedComp) {
32
+ Comp = resolvedComp;
31
33
  }
32
- const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
34
+ }
35
+ const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
36
+ if (slice.__mapped) {
37
+ const { __mapped, ...mappedProps } = slice;
38
+ return /* @__PURE__ */ jsx(Comp, { ...mappedProps }, key);
39
+ } else {
33
40
  return /* @__PURE__ */ jsx(Comp, { slice, index, slices, context }, key);
34
- });
35
- }, [components, context, defaultComponent, slices, resolver]);
41
+ }
42
+ });
36
43
  return /* @__PURE__ */ jsx(Fragment, { children: renderedSlices });
37
- };
44
+ }
38
45
  export {
39
46
  SliceZone,
40
47
  TODOSliceComponent