@prismicio/react 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/PrismicImage.cjs +1 -2
  2. package/dist/PrismicImage.cjs.map +1 -1
  3. package/dist/PrismicImage.js +1 -2
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicText.cjs +4 -2
  6. package/dist/PrismicText.cjs.map +1 -1
  7. package/dist/PrismicText.js +4 -2
  8. package/dist/PrismicText.js.map +1 -1
  9. package/dist/SliceZone.cjs +26 -12
  10. package/dist/SliceZone.cjs.map +1 -1
  11. package/dist/SliceZone.d.ts +62 -1
  12. package/dist/SliceZone.js +26 -12
  13. package/dist/SliceZone.js.map +1 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/lib/pascalCase.cjs +10 -0
  16. package/dist/lib/pascalCase.cjs.map +1 -0
  17. package/dist/lib/pascalCase.js +10 -0
  18. package/dist/lib/pascalCase.js.map +1 -0
  19. package/dist/package.json.cjs +1 -1
  20. package/dist/package.json.js +1 -1
  21. package/dist/react-server/PrismicLink.cjs +1 -2
  22. package/dist/react-server/PrismicLink.cjs.map +1 -1
  23. package/dist/react-server/PrismicLink.js +1 -2
  24. package/dist/react-server/PrismicLink.js.map +1 -1
  25. package/dist/react-server/PrismicRichText.cjs +7 -1
  26. package/dist/react-server/PrismicRichText.cjs.map +1 -1
  27. package/dist/react-server/PrismicRichText.d.ts +1 -1
  28. package/dist/react-server/PrismicRichText.js +7 -1
  29. package/dist/react-server/PrismicRichText.js.map +1 -1
  30. package/dist/usePrismicClient.cjs +3 -2
  31. package/dist/usePrismicClient.cjs.map +1 -1
  32. package/dist/usePrismicClient.js +3 -2
  33. package/dist/usePrismicClient.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/PrismicImage.tsx +1 -2
  36. package/src/PrismicText.tsx +10 -2
  37. package/src/SliceZone.tsx +138 -18
  38. package/src/index.ts +5 -2
  39. package/src/lib/processPolyfill.ts +4 -0
  40. package/src/react-server/PrismicLink.tsx +1 -2
  41. package/src/react-server/PrismicRichText.tsx +13 -0
  42. package/src/usePrismicClient.ts +6 -6
  43. package/dist/lib/__PRODUCTION__.cjs +0 -8
  44. package/dist/lib/__PRODUCTION__.cjs.map +0 -1
  45. package/dist/lib/__PRODUCTION__.d.ts +0 -7
  46. package/dist/lib/__PRODUCTION__.js +0 -8
  47. package/dist/lib/__PRODUCTION__.js.map +0 -1
  48. package/dist/lib/invariant.cjs +0 -15
  49. package/dist/lib/invariant.cjs.map +0 -1
  50. package/dist/lib/invariant.d.ts +0 -24
  51. package/dist/lib/invariant.js +0 -15
  52. package/dist/lib/invariant.js.map +0 -1
  53. package/src/lib/__PRODUCTION__.ts +0 -12
  54. package/src/lib/invariant.ts +0 -49
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
- const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
6
5
  const devMsg = require("./lib/devMsg.cjs");
7
6
  const isFilled = require('./_node_modules/@prismicio/client/dist/helpers/isFilled.cjs');
8
7
  const asImageWidthSrcSet = require('./_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs');
@@ -26,7 +25,7 @@ function _interopNamespaceDefault(e) {
26
25
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
26
  const PrismicImage = React__namespace.forwardRef(function PrismicImage2(props, ref) {
28
27
  const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
29
- if (!__PRODUCTION__.__PRODUCTION__) {
28
+ if (process.env.NODE_ENV === "development") {
30
29
  if (typeof alt === "string" && props.alt !== "") {
31
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")}`);
32
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 { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicImage>`.\n */\nexport type PrismicImageProps = Omit<\n\tReact.DetailedHTMLProps<\n\t\tReact.ImgHTMLAttributes<HTMLImageElement>,\n\t\tHTMLImageElement\n\t>,\n\t\"src\" | \"srcset\" | \"alt\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: 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 (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (widths && pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (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","__PRODUCTION__","devMsg","prismic.isFilled.imageThumbnail","prismic.asImageWidthSrcSet","prismic.asImagePixelDensitySrcSet","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyGO,MAAM,eAAeA,iBAAM,WAAW,SAASC,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEJ,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAChD,cAAQ,KACP,qQAAqQC,OACpQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,qSAAqSA,OACpS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,UAAU,gBAAgB;AAC7B,cAAQ,KACP,2MAA2M;AAAA,IAE5M;AAAA,EACD;AAED,MAAIC,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 (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,13 +1,12 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
4
3
  import { devMsg } from "./lib/devMsg.js";
5
4
  import { imageThumbnail } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
6
5
  import { asImageWidthSrcSet } from './_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js';
7
6
  import { asImagePixelDensitySrcSet } from './_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js';
8
7
  const PrismicImage = React.forwardRef(function PrismicImage2(props, ref) {
9
8
  const { field, alt, fallbackAlt, imgixParams, widths, pixelDensities, ...restProps } = props;
10
- if (!__PRODUCTION__) {
9
+ if (process.env.NODE_ENV === "development") {
11
10
  if (typeof alt === "string" && props.alt !== "") {
12
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")}`);
13
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 { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicImage>`.\n */\nexport type PrismicImageProps = Omit<\n\tReact.DetailedHTMLProps<\n\t\tReact.ImgHTMLAttributes<HTMLImageElement>,\n\t\tHTMLImageElement\n\t>,\n\t\"src\" | \"srcset\" | \"alt\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: 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 (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (widths && pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (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":";;;;;;;AAyGO,MAAM,eAAe,MAAM,WAAW,SAASA,cACrD,OACA,KAAyC;AAEnC,QAAA,EACL,OACA,KACA,aACA,aACA,QACA,gBACA,GAAG,UACA,IAAA;AAEJ,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAChD,cAAQ,KACP,qQAAqQ,OACpQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,qSAAqS,OACpS,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,UAAU,gBAAgB;AAC7B,cAAQ,KACP,2MAA2M;AAAA,IAE5M;AAAA,EACD;AAED,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 (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;"}
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
- const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
6
5
  const devMsg = require("./lib/devMsg.cjs");
7
6
  const isFilled = require('./_node_modules/@prismicio/client/dist/helpers/isFilled.cjs');
8
7
  const asText = require('./_node_modules/@prismicio/client/dist/helpers/asText.cjs');
@@ -24,7 +23,10 @@ function _interopNamespaceDefault(e) {
24
23
  }
25
24
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
26
25
  const PrismicText = (props) => {
27
- if (!__PRODUCTION__.__PRODUCTION__) {
26
+ if (process.env.NODE_ENV === "development") {
27
+ if ("className" in props) {
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
+ }
28
30
  if (typeof props.field === "string") {
29
31
  throw new Error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg.devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`);
30
32
  }
@@ -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 { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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 (!__PRODUCTION__) {\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":["__PRODUCTION__","devMsg","React","prismic.isFilled.richText","prismic.asText","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAACA,eAAAA,gBAAgB;AAChB,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoRC,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 (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,11 +1,13 @@
1
1
  import { jsx, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
4
3
  import { devMsg } from "./lib/devMsg.js";
5
4
  import { richText } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
6
5
  import { asText } from './_node_modules/@prismicio/client/dist/helpers/asText.js';
7
6
  const PrismicText = (props) => {
8
- if (!__PRODUCTION__) {
7
+ if (process.env.NODE_ENV === "development") {
8
+ if ("className" in props) {
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
+ }
9
11
  if (typeof props.field === "string") {
10
12
  throw new Error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`);
11
13
  }
@@ -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 { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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 (!__PRODUCTION__) {\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":";;;;;;AA8Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAAC,gBAAgB;AAChB,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 (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;"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
- const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
5
+ const pascalCase = require("./lib/pascalCase.cjs");
6
6
  function _interopNamespaceDefault(e) {
7
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
8
  if (e) {
@@ -20,24 +20,38 @@ function _interopNamespaceDefault(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
23
- const TODOSliceComponent = __PRODUCTION__.__PRODUCTION__ ? () => null : ({ slice }) => {
24
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
25
- console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`);
26
- return /* @__PURE__ */ jsxRuntime.jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
27
- "Could not find a component for Slice type “",
28
- type,
29
- "”"
30
- ] });
23
+ const TODOSliceComponent = ({ slice }) => {
24
+ if (process.env.NODE_ENV === "development") {
25
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
26
+ console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
27
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
28
+ "Could not find a component for Slice type “",
29
+ type,
30
+ "”"
31
+ ] });
32
+ } else {
33
+ return null;
34
+ }
31
35
  };
32
- const SliceZone = ({ slices = [], components = {}, defaultComponent = TODOSliceComponent, context = {} }) => {
36
+ const SliceZone = ({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) => {
33
37
  const renderedSlices = React__namespace.useMemo(() => {
34
38
  return slices.map((slice, index) => {
35
39
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
36
- const Comp = components[type] || defaultComponent;
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
+ }
50
+ }
37
51
  const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
38
52
  return /* @__PURE__ */ jsxRuntime.jsx(Comp, { slice, index, slices, context }, key);
39
53
  });
40
- }, [components, context, defaultComponent, slices]);
54
+ }, [components, context, defaultComponent, slices, resolver]);
41
55
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderedSlices });
42
56
  };
43
57
  exports.SliceZone = SliceZone;
@@ -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 { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type &ldquo;{type}\n\t\t\t\t\t&rdquo;\n\t\t\t\t</section>\n\t\t\t);\n\t };\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 * 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\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\tconst Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\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]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":["__PRODUCTION__","jsxs","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgHO,MAAM,qBAAqBA,eAAAA,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,UAAA,KACP,0DAA0D,OAAO;AAGlE,SACEC,2BAAAA,KAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AAgDI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,IACb,mBAAmB,oBACnB,UAAU,CAAA,QACiC;AACrC,QAAA,iBAAiBC,iBAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAExD,YAAA,OACL,WAAW,IAA+B,KAAK;AAE1C,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,KACC,CAAC,YAAY,SAAS,kBAAkB,MAAM,CAAC;AAElD,+DAAU,UAAe,eAAA,CAAA;AAC1B;;;"}
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,5 +1,12 @@
1
1
  import * as React from "react";
2
2
  import * as prismic from "@prismicio/client";
3
+ import { PascalCase } from "./lib/pascalCase";
4
+ /**
5
+ * Returns the type of a `SliceLike` type.
6
+ *
7
+ * @typeParam Slice - The Slice from which the type will be extracted.
8
+ */
9
+ type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
3
10
  /**
4
11
  * The minimum required properties to represent a Prismic Slice from the Prismic
5
12
  * Rest API V2 for the `<SliceZone>` component.
@@ -76,6 +83,18 @@ export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unkno
76
83
  * @typeParam TContext - Arbitrary data made available to all Slice components.
77
84
  */
78
85
  export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
86
+ /**
87
+ * A record of Slice types mapped to a React component. The component will be
88
+ * rendered for each instance of its Slice.
89
+ *
90
+ * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
91
+ * `Record<string, SliceComponentType<any>>` instead.
92
+ * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
93
+ * @typeParam TContext - Arbitrary data made available to all Slice components.
94
+ */
95
+ export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
96
+ [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
97
+ };
79
98
  /**
80
99
  * This Slice component can be used as a reminder to provide a proper
81
100
  * implementation.
@@ -84,6 +103,36 @@ export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknow
84
103
  * cannot be found in `<SliceZone>`.
85
104
  */
86
105
  export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
106
+ /**
107
+ * Arguments for a `<SliceZone>` `resolver` function.
108
+ */
109
+ type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
110
+ /**
111
+ * The Slice to resolve to a React component.
112
+ */
113
+ slice: TSlice;
114
+ /**
115
+ * The name of the Slice.
116
+ */
117
+ sliceName: PascalCase<ExtractSliceType<TSlice>>;
118
+ /**
119
+ * The index of the Slice in the Slice Zone.
120
+ */
121
+ i: number;
122
+ };
123
+ /**
124
+ * A function that determines the rendered React component for each Slice in the
125
+ * Slice Zone. If a nullish value is returned, the component will fallback to
126
+ * the `components` or `defaultComponent` props to determine the rendered
127
+ * component.
128
+ *
129
+ * @deprecated Use the `components` prop instead.
130
+ *
131
+ * @param args - Arguments for the resolver function.
132
+ *
133
+ * @returns The React component to render for a Slice.
134
+ */
135
+ export type SliceZoneResolver<TSlice extends SliceLike = any, TContext = unknown> = (args: SliceZoneResolverArgs<TSlice>) => SliceComponentType<any, TContext> | undefined | null;
87
136
  /**
88
137
  * React props for the `<SliceZone>` component.
89
138
  *
@@ -99,6 +148,17 @@ export type SliceZoneProps<TContext = unknown> = {
99
148
  * A record mapping Slice types to React components.
100
149
  */
101
150
  components?: Record<string, SliceComponentType<any, TContext>>;
151
+ /**
152
+ * A function that determines the rendered React component for each Slice in
153
+ * the Slice Zone.
154
+ *
155
+ * @deprecated Use the `components` prop instead.
156
+ *
157
+ * @param args - Arguments for the resolver function.
158
+ *
159
+ * @returns The React component to render for a Slice.
160
+ */
161
+ resolver?: SliceZoneResolver<any, TContext>;
102
162
  /**
103
163
  * The React component rendered if a component mapping from the `components`
104
164
  * prop cannot be found.
@@ -124,4 +184,5 @@ export type SliceZoneProps<TContext = unknown> = {
124
184
  *
125
185
  * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
126
186
  */
127
- export declare const SliceZone: <TContext>({ slices, components, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
187
+ export declare const SliceZone: <TContext>({ slices, components, resolver, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
188
+ export {};
package/dist/SliceZone.js CHANGED
@@ -1,24 +1,38 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
4
- const TODOSliceComponent = __PRODUCTION__ ? () => null : ({ slice }) => {
5
- const type = "slice_type" in slice ? slice.slice_type : slice.type;
6
- console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`);
7
- return /* @__PURE__ */ jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
8
- "Could not find a component for Slice type “",
9
- type,
10
- "”"
11
- ] });
3
+ import { pascalCase } from "./lib/pascalCase.js";
4
+ const TODOSliceComponent = ({ slice }) => {
5
+ if (process.env.NODE_ENV === "development") {
6
+ const type = "slice_type" in slice ? slice.slice_type : slice.type;
7
+ console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
8
+ return /* @__PURE__ */ jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
9
+ "Could not find a component for Slice type “",
10
+ type,
11
+ "”"
12
+ ] });
13
+ } else {
14
+ return null;
15
+ }
12
16
  };
13
- const SliceZone = ({ slices = [], components = {}, defaultComponent = TODOSliceComponent, context = {} }) => {
17
+ const SliceZone = ({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) => {
14
18
  const renderedSlices = React.useMemo(() => {
15
19
  return slices.map((slice, index) => {
16
20
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
17
- const Comp = components[type] || defaultComponent;
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
+ }
31
+ }
18
32
  const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
19
33
  return /* @__PURE__ */ jsx(Comp, { slice, index, slices, context }, key);
20
34
  });
21
- }, [components, context, defaultComponent, slices]);
35
+ }, [components, context, defaultComponent, slices, resolver]);
22
36
  return /* @__PURE__ */ jsx(Fragment, { children: renderedSlices });
23
37
  };
24
38
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"SliceZone.js","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type &ldquo;{type}\n\t\t\t\t\t&rdquo;\n\t\t\t\t</section>\n\t\t\t);\n\t };\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 * 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\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\tconst Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\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]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":[],"mappings":";;;AAgHO,MAAM,qBAAqB,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,UAAA,KACP,0DAA0D,OAAO;AAGlE,SACE,qBAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AAgDI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,IACb,mBAAmB,oBACnB,UAAU,CAAA,QACiC;AACrC,QAAA,iBAAiB,MAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAExD,YAAA,OACL,WAAW,IAA+B,KAAK;AAE1C,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,iCACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,KACC,CAAC,YAAY,SAAS,kBAAkB,MAAM,CAAC;AAElD,yCAAU,UAAe,eAAA,CAAA;AAC1B;"}
1
+ {"version":3,"file":"SliceZone.js","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":[],"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,WACE,qBAAA,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,iBAAiB,MAAM,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,WAAW,WAAW,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,iCACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,EAAA,GACC,CAAC,YAAY,SAAS,kBAAkB,QAAQ,QAAQ,CAAC;AAE5D,yCAAU,UAAe,eAAA,CAAA;AAC1B;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import "./lib/processPolyfill";
1
2
  export { PrismicProvider } from "./PrismicProvider";
2
3
  export type { PrismicProviderProps, PrismicContextValue, } from "./PrismicProvider";
3
4
  export { usePrismicContext } from "./usePrismicContext";
@@ -12,7 +13,7 @@ export { Element } from "@prismicio/richtext";
12
13
  export { PrismicImage } from "./PrismicImage";
13
14
  export type { PrismicImageProps } from "./PrismicImage";
14
15
  export { SliceZone, TODOSliceComponent } from "./SliceZone";
15
- export type { SliceComponentProps, SliceComponentType, SliceLikeRestV2, SliceLikeGraphQL, SliceLike, SliceZoneLike, SliceZoneProps, } from "./SliceZone";
16
+ export type { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZoneComponents, SliceZoneLike, SliceZoneProps, } from "./SliceZone";
16
17
  export { PrismicToolbar } from "./PrismicToolbar";
17
18
  export type { PrismicToolbarProps } from "./PrismicToolbar";
18
19
  export { usePrismicPreviewResolver } from "./usePrismicPreviewResolver";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const pascalCase = (input) => {
4
+ const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
5
+ return c ? c.toUpperCase() : "";
6
+ });
7
+ return camelCased[0].toUpperCase() + camelCased.slice(1);
8
+ };
9
+ exports.pascalCase = pascalCase;
10
+ //# sourceMappingURL=pascalCase.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pascalCase.cjs","sources":["../../../src/lib/pascalCase.ts"],"sourcesContent":["// `PascalCase`-related types have been taken from the `type-fest` package.\n//\n// They are copied here to mininize dependencies in this project.\n//\n// See: https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/camel-case.d.ts\n\ntype WordSeparators = \"-\" | \"_\" | \" \";\n\ntype Split<\n\tS extends string,\n\tDelimiter extends string,\n> = S extends `${infer Head}${Delimiter}${infer Tail}`\n\t? [Head, ...Split<Tail, Delimiter>]\n\t: S extends Delimiter\n\t? []\n\t: [S];\n\ntype InnerCamelCaseStringArray<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tParts extends readonly any[],\n\tPreviousPart,\n> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts]\n\t? FirstPart extends undefined\n\t\t? \"\"\n\t\t: FirstPart extends \"\"\n\t\t? InnerCamelCaseStringArray<RemainingParts, PreviousPart>\n\t\t: `${PreviousPart extends \"\"\n\t\t\t\t? FirstPart\n\t\t\t\t: Capitalize<FirstPart>}${InnerCamelCaseStringArray<\n\t\t\t\tRemainingParts,\n\t\t\t\tFirstPart\n\t\t >}`\n\t: \"\";\n\ntype CamelCaseStringArray<Parts extends readonly string[]> = Parts extends [\n\t`${infer FirstPart}`,\n\t...infer RemainingParts,\n]\n\t? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<\n\t\t\tRemainingParts,\n\t\t\tFirstPart\n\t >}`>\n\t: never;\n\ntype CamelCase<K> = K extends string\n\t? CamelCaseStringArray<\n\t\t\tSplit<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>\n\t >\n\t: K;\n\n/**\n * Converts a string literal to Pascal case.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/pascal-case.d.ts\n */\nexport type PascalCase<Value> = CamelCase<Value> extends string\n\t? Capitalize<CamelCase<Value>>\n\t: CamelCase<Value>;\n\n/**\n * Converts a string to Pascal case.\n *\n * @param input - The string to convert.\n *\n * @returns `input` as Pascal case.\n */\nexport const pascalCase = <Input extends string>(\n\tinput: Input,\n): PascalCase<Input> => {\n\tconst camelCased = input.replace(/(?:-|_)(\\w)/g, (_, c) => {\n\t\treturn c ? c.toUpperCase() : \"\";\n\t});\n\n\treturn (camelCased[0].toUpperCase() +\n\t\tcamelCased.slice(1)) as PascalCase<Input>;\n};\n"],"names":[],"mappings":";;AAqEa,MAAA,aAAa,CACzB,UACsB;AACtB,QAAM,aAAa,MAAM,QAAQ,gBAAgB,CAAC,GAAG,MAAK;AAClD,WAAA,IAAI,EAAE,YAAA,IAAgB;AAAA,EAAA,CAC7B;AAED,SAAQ,WAAW,CAAC,EAAE,YACrB,IAAA,WAAW,MAAM,CAAC;AACpB;;"}
@@ -0,0 +1,10 @@
1
+ const pascalCase = (input) => {
2
+ const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
3
+ return c ? c.toUpperCase() : "";
4
+ });
5
+ return camelCased[0].toUpperCase() + camelCased.slice(1);
6
+ };
7
+ export {
8
+ pascalCase
9
+ };
10
+ //# sourceMappingURL=pascalCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pascalCase.js","sources":["../../../src/lib/pascalCase.ts"],"sourcesContent":["// `PascalCase`-related types have been taken from the `type-fest` package.\n//\n// They are copied here to mininize dependencies in this project.\n//\n// See: https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/camel-case.d.ts\n\ntype WordSeparators = \"-\" | \"_\" | \" \";\n\ntype Split<\n\tS extends string,\n\tDelimiter extends string,\n> = S extends `${infer Head}${Delimiter}${infer Tail}`\n\t? [Head, ...Split<Tail, Delimiter>]\n\t: S extends Delimiter\n\t? []\n\t: [S];\n\ntype InnerCamelCaseStringArray<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tParts extends readonly any[],\n\tPreviousPart,\n> = Parts extends [`${infer FirstPart}`, ...infer RemainingParts]\n\t? FirstPart extends undefined\n\t\t? \"\"\n\t\t: FirstPart extends \"\"\n\t\t? InnerCamelCaseStringArray<RemainingParts, PreviousPart>\n\t\t: `${PreviousPart extends \"\"\n\t\t\t\t? FirstPart\n\t\t\t\t: Capitalize<FirstPart>}${InnerCamelCaseStringArray<\n\t\t\t\tRemainingParts,\n\t\t\t\tFirstPart\n\t\t >}`\n\t: \"\";\n\ntype CamelCaseStringArray<Parts extends readonly string[]> = Parts extends [\n\t`${infer FirstPart}`,\n\t...infer RemainingParts,\n]\n\t? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<\n\t\t\tRemainingParts,\n\t\t\tFirstPart\n\t >}`>\n\t: never;\n\ntype CamelCase<K> = K extends string\n\t? CamelCaseStringArray<\n\t\t\tSplit<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>\n\t >\n\t: K;\n\n/**\n * Converts a string literal to Pascal case.\n *\n * Taken from the `type-fest` package.\n *\n * See:\n * https://github.com/sindresorhus/type-fest/blob/61c35052f09caa23de5eef96d95196375d8ed498/source/pascal-case.d.ts\n */\nexport type PascalCase<Value> = CamelCase<Value> extends string\n\t? Capitalize<CamelCase<Value>>\n\t: CamelCase<Value>;\n\n/**\n * Converts a string to Pascal case.\n *\n * @param input - The string to convert.\n *\n * @returns `input` as Pascal case.\n */\nexport const pascalCase = <Input extends string>(\n\tinput: Input,\n): PascalCase<Input> => {\n\tconst camelCased = input.replace(/(?:-|_)(\\w)/g, (_, c) => {\n\t\treturn c ? c.toUpperCase() : \"\";\n\t});\n\n\treturn (camelCased[0].toUpperCase() +\n\t\tcamelCased.slice(1)) as PascalCase<Input>;\n};\n"],"names":[],"mappings":"AAqEa,MAAA,aAAa,CACzB,UACsB;AACtB,QAAM,aAAa,MAAM,QAAQ,gBAAgB,CAAC,GAAG,MAAK;AAClD,WAAA,IAAI,EAAE,YAAA,IAAgB;AAAA,EAAA,CAC7B;AAED,SAAQ,WAAW,CAAC,EAAE,YACrB,IAAA,WAAW,MAAM,CAAC;AACpB;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "2.6.0";
3
+ const version = "2.6.1";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.json.cjs.map
@@ -1,4 +1,4 @@
1
- const version = "2.6.0";
1
+ const version = "2.6.1";
2
2
  export {
3
3
  version
4
4
  };
@@ -4,7 +4,6 @@ const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const asLinkAttrs = require('./../_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs');
6
6
  require("@prismicio/richtext");
7
- const __PRODUCTION__ = require("../lib/__PRODUCTION__.cjs");
8
7
  const devMsg = require("../lib/devMsg.cjs");
9
8
  const isInternalURL = require("../lib/isInternalURL.cjs");
10
9
  function _interopNamespaceDefault(e) {
@@ -26,7 +25,7 @@ function _interopNamespaceDefault(e) {
26
25
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
26
  const defaultComponent = "a";
28
27
  const PrismicLink = React__namespace.forwardRef(function PrismicLink2({ field, document: doc, linkResolver, internalComponent, externalComponent, ...restProps }, ref) {
29
- if (!__PRODUCTION__.__PRODUCTION__) {
28
+ if (process.env.NODE_ENV === "development") {
30
29
  if (field) {
31
30
  if (!field.link_type) {
32
31
  console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.