@prismicio/next 0.1.7 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,6 @@ const PrismicNextImage = ({
56
56
  imgixParams = {},
57
57
  alt,
58
58
  fallbackAlt,
59
- layout = "intrinsic",
60
59
  ...restProps
61
60
  }) => {
62
61
  if (!__PRODUCTION__.__PRODUCTION__) {
@@ -72,6 +71,7 @@ const PrismicNextImage = ({
72
71
  const ar = field.dimensions.width / field.dimensions.height;
73
72
  let resolvedWidth = field.dimensions.width;
74
73
  let resolvedHeight = field.dimensions.height;
74
+ const layout = restProps.layout;
75
75
  if ((layout === "intrinsic" || layout === "fixed") && ("width" in restProps || "height" in restProps)) {
76
76
  const castedWidth = castInt(restProps.width);
77
77
  const castedHeight = castInt(restProps.height);
@@ -90,7 +90,6 @@ const PrismicNextImage = ({
90
90
  height: layout === "fill" ? void 0 : resolvedHeight,
91
91
  alt: alt != null ? alt : field.alt || fallbackAlt,
92
92
  loader: imgixLoader,
93
- layout,
94
93
  ...restProps
95
94
  });
96
95
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"width\" | \"height\" | \"layout\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\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\tlayout?: \"intrinsic\" | \"fixed\";\n\t\t } & Pick<ImageProps, \"width\" | \"height\">)\n\t\t| {\n\t\t\t\tlayout: \"responsive\" | \"fill\";\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 using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tlayout = \"intrinsic\",\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] 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`[PrismicNextImage] 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\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tlet resolvedWidth = field.dimensions.width;\n\t\tlet resolvedHeight = field.dimensions.height;\n\n\t\tif (\n\t\t\t(layout === \"intrinsic\" || layout === \"fixed\") &&\n\t\t\t(\"width\" in restProps || \"height\" in restProps)\n\t\t) {\n\t\t\tconst castedWidth = castInt(restProps.width);\n\t\t\tconst castedHeight = castInt(restProps.height);\n\n\t\t\tif (castedWidth) {\n\t\t\t\tresolvedWidth = castedWidth;\n\t\t\t} else {\n\t\t\t\tif (castedHeight) {\n\t\t\t\t\tresolvedWidth = ar * castedHeight;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresolvedHeight = resolvedWidth / ar;\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : resolvedWidth}\n\t\t\t\theight={layout === \"fill\" ? undefined : resolvedHeight}\n\t\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\tlayout={layout}\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":["castInt","input","parsed","Number","parseInt","isNaN","undefined","imgixLoader","args","url","URL","src","params","fit","searchParams","get","w","width","h","quality","q","buildURL","PrismicNextImage","field","imgixParams","alt","fallbackAlt","layout","restProps","__PRODUCTION__","console","warn","devMsg","prismicH","isFilled","imageThumbnail","ar","dimensions","height","resolvedWidth","resolvedHeight","castedWidth","castedHeight","_jsx","Image","loader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAMA,UAAWC,CAA0D,UAAA;AAC1E,MAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,aAAa;AACvDA,WAAAA;AAAAA,EAAAA,OACD;AACAC,UAAAA,SAASC,OAAOC,SAASH,KAAK;AAEhCE,QAAAA,OAAOE,MAAMH,MAAM,GAAG;AAClBI,aAAAA;AAAAA,IAAAA,OACD;AACCJ,aAAAA;AAAAA,IACP;AAAA,EACD;AACF;AASA,MAAMK,cAAeC,CAAkC,SAAA;AACtD,QAAMC,MAAM,IAAIC,IAAIF,KAAKG,GAAG;AAE5B,QAAMC,SAAyB;AAAA,IAC9BC,KAAMJ,IAAIK,aAAaC,IAAI,KAAK,KAA+B;AAAA,IAC/DC,GAAGR,KAAKS;AAAAA,IACRC,GAAGZ;AAAAA,EAAAA;AAGJ,MAAIE,KAAKW,SAAS;AACjBP,WAAOQ,IAAIZ,KAAKW;AAAA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B,QAAQtC;AAAAA,MACRoB;AAAAA,MACI,GAAAC;AAAAA,IAAAA,CACH;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;;"}
1
+ {"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Value for `next/image`'s `layout` prop which existed in Next 12 and lower.\n * `<PrismicNextImage>` is comatible with the current and legacy image\n * components, requiring us to handle both APIs.\n */\ntype LegacyImageLayout = \"intrinsic\" | \"fixed\" | \"responsive\" | \"fill\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\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\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] 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`[PrismicNextImage] 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\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tlet resolvedWidth = field.dimensions.width;\n\t\tlet resolvedHeight = field.dimensions.height;\n\n\t\t// If a layout prop is provied, we can assume this image is\n\t\t// using Next 12. We must handle the `width` and `height` props\n\t\t// in a unique way when using the legacy `next/image` component.\n\t\tconst layout: LegacyImageLayout =\n\t\t\t// @ts-expect-error - Layout does not exist in `next/image` as of Next 13.0.0.\n\t\t\trestProps.layout;\n\n\t\tif (\n\t\t\t(layout === \"intrinsic\" || layout === \"fixed\") &&\n\t\t\t(\"width\" in restProps || \"height\" in restProps)\n\t\t) {\n\t\t\tconst castedWidth = castInt(restProps.width);\n\t\t\tconst castedHeight = castInt(restProps.height);\n\n\t\t\tif (castedWidth) {\n\t\t\t\tresolvedWidth = castedWidth;\n\t\t\t} else {\n\t\t\t\tif (castedHeight) {\n\t\t\t\t\tresolvedWidth = ar * castedHeight;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresolvedHeight = resolvedWidth / ar;\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : resolvedWidth}\n\t\t\t\theight={layout === \"fill\" ? undefined : resolvedHeight}\n\t\t\t\t// A non-null assertion is required since we\n\t\t\t\t// can't statically know if an alt attribute is\n\t\t\t\t// available.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\talt={(alt ?? (field.alt || fallbackAlt))!}\n\t\t\t\tloader={imgixLoader}\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":["castInt","input","parsed","Number","parseInt","isNaN","undefined","imgixLoader","args","url","URL","src","params","fit","searchParams","get","w","width","h","quality","q","buildURL","PrismicNextImage","field","imgixParams","alt","fallbackAlt","restProps","__PRODUCTION__","console","warn","devMsg","prismicH","isFilled","imageThumbnail","ar","dimensions","height","resolvedWidth","resolvedHeight","layout","castedWidth","castedHeight","_jsx","Image","loader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAMA,UAAWC,CAA0D,UAAA;AAC1E,MAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,aAAa;AACvDA,WAAAA;AAAAA,EAAAA,OACD;AACAC,UAAAA,SAASC,OAAOC,SAASH,KAAK;AAEhCE,QAAAA,OAAOE,MAAMH,MAAM,GAAG;AAClBI,aAAAA;AAAAA,IAAAA,OACD;AACCJ,aAAAA;AAAAA,IACP;AAAA,EACD;AACF;AASA,MAAMK,cAAeC,CAAkC,SAAA;AACtD,QAAMC,MAAM,IAAIC,IAAIF,KAAKG,GAAG;AAE5B,QAAMC,SAAyB;AAAA,IAC9BC,KAAMJ,IAAIK,aAAaC,IAAI,KAAK,KAA+B;AAAA,IAC/DC,GAAGR,KAAKS;AAAAA,IACRC,GAAGZ;AAAAA,EAAAA;AAGJ,MAAIE,KAAKW,SAAS;AACjBP,WAAOQ,IAAIZ,KAAKW;AAAAA,EAChB;AAEME,SAAAA,yBAASb,KAAKG,KAAKC,MAAM;AACjC;AAgDO,MAAMU,mBAAmB,CAAC;AAAA,EAChCC;AAAAA,EACAC,cAAc;EACdC;AAAAA,EACAC;AAAAA,KACGC;AAAS,MACe;AAC3B,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAOH,QAAQ,YAAYA,QAAQ,IAAI;AAC1CI,cAAQC,KACkQ,yQAAAC,OACxQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAOL,gBAAgB,YAAYA,gBAAgB,IAAI;AAC1DG,cAAQC,KACkS,ySAAAC,OACxS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,oBAASC,SAASC,eAAeX,KAAK,GAAG;AAC5C,UAAMZ,MAAMU,gBAAAA,SAASE,MAAMd,KAAKe,WAAW;AAC3C,UAAMW,KAAKZ,MAAMa,WAAWnB,QAAQM,MAAMa,WAAWC;AAEjDC,QAAAA,gBAAgBf,MAAMa,WAAWnB;AACjCsB,QAAAA,iBAAiBhB,MAAMa,WAAWC;AAKtC,UAAMG,SAELb,UAAUa;AAEX,SACEA,WAAW,eAAeA,WAAW,aACrC,WAAWb,aAAa,YAAYA,YACpC;AACKc,YAAAA,cAAczC,QAAQ2B,UAAUV,KAAK;AACrCyB,YAAAA,eAAe1C,QAAQ2B,UAAUU,MAAM;AAE7C,UAAII,aAAa;AACAA,wBAAAA;AAAAA,MAAAA,OACV;AACN,YAAIC,cAAc;AACjBJ,0BAAgBH,KAAKO;AAAAA,QACrB;AAAA,MACD;AAEDH,uBAAiBD,gBAAgBH;AAAAA,IACjC;AAED,WACCQ,WAAAA,IAACC,eAAAA,SAAK;AAAA,MACLjC;AAAAA,MACAM,OAAOuB,WAAW,SAASlC,SAAYgC;AAAAA,MACvCD,QAAQG,WAAW,SAASlC,SAAYiC;AAAAA,MAKxCd,KAAMA,oBAAQF,MAAME,OAAOC;AAAAA,MAC3BmB,QAAQtC;AAAAA,SACJoB;AAAAA,IAAAA,CAAS;AAAA,EAAA,OAGT;AACC,WAAA;AAAA,EACP;AACF;;"}
@@ -2,7 +2,7 @@
2
2
  import { ImageProps } from "next/image";
3
3
  import { ImgixURLParams } from "imgix-url-builder";
4
4
  import * as prismicT from "@prismicio/types";
5
- export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "width" | "height" | "layout"> & {
5
+ export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
6
6
  /**
7
7
  * The Prismic Image field or thumbnail to render.
8
8
  */
@@ -28,11 +28,7 @@ export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "wi
28
28
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
29
29
  */
30
30
  fallbackAlt?: "";
31
- } & (({
32
- layout?: "intrinsic" | "fixed";
33
- } & Pick<ImageProps, "width" | "height">) | {
34
- layout: "responsive" | "fill";
35
- });
31
+ };
36
32
  /**
37
33
  * React component that renders an image from a Prismic Image field or one of
38
34
  * its thumbnails using `next/image`. It will automatically set the `alt`
@@ -48,4 +44,4 @@ export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "wi
48
44
  * field.
49
45
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
50
46
  */
51
- export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, layout, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
47
+ export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
@@ -33,7 +33,6 @@ const PrismicNextImage = ({
33
33
  imgixParams = {},
34
34
  alt,
35
35
  fallbackAlt,
36
- layout = "intrinsic",
37
36
  ...restProps
38
37
  }) => {
39
38
  if (!__PRODUCTION__) {
@@ -49,6 +48,7 @@ const PrismicNextImage = ({
49
48
  const ar = field.dimensions.width / field.dimensions.height;
50
49
  let resolvedWidth = field.dimensions.width;
51
50
  let resolvedHeight = field.dimensions.height;
51
+ const layout = restProps.layout;
52
52
  if ((layout === "intrinsic" || layout === "fixed") && ("width" in restProps || "height" in restProps)) {
53
53
  const castedWidth = castInt(restProps.width);
54
54
  const castedHeight = castInt(restProps.height);
@@ -67,7 +67,6 @@ const PrismicNextImage = ({
67
67
  height: layout === "fill" ? void 0 : resolvedHeight,
68
68
  alt: alt != null ? alt : field.alt || fallbackAlt,
69
69
  loader: imgixLoader,
70
- layout,
71
70
  ...restProps
72
71
  });
73
72
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.js","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"width\" | \"height\" | \"layout\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\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\tlayout?: \"intrinsic\" | \"fixed\";\n\t\t } & Pick<ImageProps, \"width\" | \"height\">)\n\t\t| {\n\t\t\t\tlayout: \"responsive\" | \"fill\";\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 using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tlayout = \"intrinsic\",\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] 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`[PrismicNextImage] 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\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tlet resolvedWidth = field.dimensions.width;\n\t\tlet resolvedHeight = field.dimensions.height;\n\n\t\tif (\n\t\t\t(layout === \"intrinsic\" || layout === \"fixed\") &&\n\t\t\t(\"width\" in restProps || \"height\" in restProps)\n\t\t) {\n\t\t\tconst castedWidth = castInt(restProps.width);\n\t\t\tconst castedHeight = castInt(restProps.height);\n\n\t\t\tif (castedWidth) {\n\t\t\t\tresolvedWidth = castedWidth;\n\t\t\t} else {\n\t\t\t\tif (castedHeight) {\n\t\t\t\t\tresolvedWidth = ar * castedHeight;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresolvedHeight = resolvedWidth / ar;\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : resolvedWidth}\n\t\t\t\theight={layout === \"fill\" ? undefined : resolvedHeight}\n\t\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\tlayout={layout}\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":["castInt","input","parsed","Number","parseInt","isNaN","undefined","imgixLoader","args","url","URL","src","params","fit","searchParams","get","w","width","h","quality","q","buildURL","PrismicNextImage","field","imgixParams","alt","fallbackAlt","layout","restProps","__PRODUCTION__","console","warn","devMsg","prismicH","isFilled","imageThumbnail","ar","dimensions","height","resolvedWidth","resolvedHeight","castedWidth","castedHeight","_jsx","Image","loader"],"mappings":";;;;;;AAQA,MAAMA,UAAWC,CAA0D,UAAA;AAC1E,MAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,aAAa;AACvDA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a,YAAAA,cAAczC,QAAQ4B,UAAUX,KAAK;AACrCyB,YAAAA,eAAe1C,QAAQ4B,UAAUU,MAAM;AAE7C,UAAIG,aAAa;AACAA,wBAAAA;AAAAA,MAAAA,OACV;AACN,YAAIC,cAAc;AACjBH,0BAAgBH,KAAKM;AAAAA,QACrB;AAAA,MACD;AAEDF,uBAAiBD,gBAAgBH;AAAAA,IACjC;AAED,WACCO,IAACC,OACA;AAAA,MAAAjC;AAAAA,MACAM,OAAOU,WAAW,SAASrB,SAAYiC;AAAAA,MACvCD,QAAQX,WAAW,SAASrB,SAAYkC;AAAAA,MACxCf,KAAKA,oBAAQF,MAAME,OAAOC;AAAAA,MAC1BmB,QAAQtC;AAAAA,MACRoB;AAAAA,MACI,GAAAC;AAAAA,IAAAA,CACH;AAAA,EAAA,OAEG;AACC,WAAA;AAAA,EACP;AACF;"}
1
+ {"version":3,"file":"PrismicNextImage.js","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Value for `next/image`'s `layout` prop which existed in Next 12 and lower.\n * `<PrismicNextImage>` is comatible with the current and legacy image\n * components, requiring us to handle both APIs.\n */\ntype LegacyImageLayout = \"intrinsic\" | \"fixed\" | \"responsive\" | \"fill\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\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\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] 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`[PrismicNextImage] 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\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tlet resolvedWidth = field.dimensions.width;\n\t\tlet resolvedHeight = field.dimensions.height;\n\n\t\t// If a layout prop is provied, we can assume this image is\n\t\t// using Next 12. We must handle the `width` and `height` props\n\t\t// in a unique way when using the legacy `next/image` component.\n\t\tconst layout: LegacyImageLayout =\n\t\t\t// @ts-expect-error - Layout does not exist in `next/image` as of Next 13.0.0.\n\t\t\trestProps.layout;\n\n\t\tif (\n\t\t\t(layout === \"intrinsic\" || layout === \"fixed\") &&\n\t\t\t(\"width\" in restProps || \"height\" in restProps)\n\t\t) {\n\t\t\tconst castedWidth = castInt(restProps.width);\n\t\t\tconst castedHeight = castInt(restProps.height);\n\n\t\t\tif (castedWidth) {\n\t\t\t\tresolvedWidth = castedWidth;\n\t\t\t} else {\n\t\t\t\tif (castedHeight) {\n\t\t\t\t\tresolvedWidth = ar * castedHeight;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresolvedHeight = resolvedWidth / ar;\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : resolvedWidth}\n\t\t\t\theight={layout === \"fill\" ? undefined : resolvedHeight}\n\t\t\t\t// A non-null assertion is required since we\n\t\t\t\t// can't statically know if an alt attribute is\n\t\t\t\t// available.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\talt={(alt ?? (field.alt || fallbackAlt))!}\n\t\t\t\tloader={imgixLoader}\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":["castInt","input","parsed","Number","parseInt","isNaN","undefined","imgixLoader","args","url","URL","src","params","fit","searchParams","get","w","width","h","quality","q","buildURL","PrismicNextImage","field","imgixParams","alt","fallbackAlt","restProps","__PRODUCTION__","console","warn","devMsg","prismicH","isFilled","imageThumbnail","ar","dimensions","height","resolvedWidth","resolvedHeight","layout","castedWidth","castedHeight","_jsx","Image","loader"],"mappings":";;;;;;AAeA,MAAMA,UAAWC,CAA0D,UAAA;AAC1E,MAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,aAAa;AACvDA,WAAAA;AAAAA,EAAAA,OACD;AACAC,UAAAA,SAASC,OAAOC,SAASH,KAAK;AAEhCE,QAAAA,OAAOE,MAAMH,MAAM,GAAG;AAClBI,aAAAA;AAAAA,IAAAA,OACD;AACCJ,aAAAA;AAAAA,IACP;AAAA,EACD;AACF;AASA,MAAMK,cAAeC,CAAkC,SAAA;AACtD,QAAMC,MAAM,IAAIC,IAAIF,KAAKG,GAAG;AAE5B,QAAMC,SAAyB;AAAA,IAC9BC,KAAMJ,IAAIK,aAAaC,IAAI,KAAK,KAA+B;AAAA,IAC/DC,GAAGR,KAAKS;AAAAA,IACRC,GAAGZ;AAAAA,EAAAA;AAGJ,MAAIE,KAAKW,SAAS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AAAAA,SACJoB;AAAAA,IAAAA,CAAS;AAAA,EAAA,OAGT;AACC,WAAA;AAAA,EACP;AACF;"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const version = "0.1.7";
3
+ const version = "1.0.0-alpha.0";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.cjs.map
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
- const version = "0.1.7";
1
+ const version = "1.0.0-alpha.0";
2
2
  export {
3
3
  version
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "0.1.7",
3
+ "version": "1.0.0-alpha.0",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -66,7 +66,7 @@
66
66
  "eslint-plugin-react-hooks": "^4.6.0",
67
67
  "eslint-plugin-tsdoc": "^0.2.17",
68
68
  "happy-dom": "^7.5.13",
69
- "next": "^12.1.4",
69
+ "next": "^13.0.0",
70
70
  "nyc": "^15.1.0",
71
71
  "prettier": "^2.7.1",
72
72
  "prettier-plugin-jsdoc": "^0.4.2",
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "peerDependencies": {
83
83
  "@prismicio/client": "^6.0.0",
84
- "next": "^11 || ^12",
84
+ "next": "^11 || ^12 | ^13",
85
85
  "react": "^17 || ^18"
86
86
  },
87
87
  "engines": {
@@ -6,6 +6,13 @@ import * as prismicT from "@prismicio/types";
6
6
  import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
7
7
  import { devMsg } from "./lib/devMsg";
8
8
 
9
+ /**
10
+ * Value for `next/image`'s `layout` prop which existed in Next 12 and lower.
11
+ * `<PrismicNextImage>` is comatible with the current and legacy image
12
+ * components, requiring us to handle both APIs.
13
+ */
14
+ type LegacyImageLayout = "intrinsic" | "fixed" | "responsive" | "fill";
15
+
9
16
  const castInt = (input: string | number | undefined): number | undefined => {
10
17
  if (typeof input === "number" || typeof input === "undefined") {
11
18
  return input;
@@ -43,10 +50,7 @@ const imgixLoader = (args: ImageLoaderProps): string => {
43
50
  return buildURL(args.src, params);
44
51
  };
45
52
 
46
- export type PrismicNextImageProps = Omit<
47
- ImageProps,
48
- "src" | "alt" | "width" | "height" | "layout"
49
- > & {
53
+ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
50
54
  /**
51
55
  * The Prismic Image field or thumbnail to render.
52
56
  */
@@ -75,14 +79,7 @@ export type PrismicNextImageProps = Omit<
75
79
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
76
80
  */
77
81
  fallbackAlt?: "";
78
- } & (
79
- | ({
80
- layout?: "intrinsic" | "fixed";
81
- } & Pick<ImageProps, "width" | "height">)
82
- | {
83
- layout: "responsive" | "fill";
84
- }
85
- );
82
+ };
86
83
 
87
84
  /**
88
85
  * React component that renders an image from a Prismic Image field or one of
@@ -104,7 +101,6 @@ export const PrismicNextImage = ({
104
101
  imgixParams = {},
105
102
  alt,
106
103
  fallbackAlt,
107
- layout = "intrinsic",
108
104
  ...restProps
109
105
  }: PrismicNextImageProps) => {
110
106
  if (!__PRODUCTION__) {
@@ -132,6 +128,13 @@ export const PrismicNextImage = ({
132
128
  let resolvedWidth = field.dimensions.width;
133
129
  let resolvedHeight = field.dimensions.height;
134
130
 
131
+ // If a layout prop is provied, we can assume this image is
132
+ // using Next 12. We must handle the `width` and `height` props
133
+ // in a unique way when using the legacy `next/image` component.
134
+ const layout: LegacyImageLayout =
135
+ // @ts-expect-error - Layout does not exist in `next/image` as of Next 13.0.0.
136
+ restProps.layout;
137
+
135
138
  if (
136
139
  (layout === "intrinsic" || layout === "fixed") &&
137
140
  ("width" in restProps || "height" in restProps)
@@ -155,9 +158,12 @@ export const PrismicNextImage = ({
155
158
  src={src}
156
159
  width={layout === "fill" ? undefined : resolvedWidth}
157
160
  height={layout === "fill" ? undefined : resolvedHeight}
158
- alt={alt ?? (field.alt || fallbackAlt)}
161
+ // A non-null assertion is required since we
162
+ // can't statically know if an alt attribute is
163
+ // available.
164
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
165
+ alt={(alt ?? (field.alt || fallbackAlt))!}
159
166
  loader={imgixLoader}
160
- layout={layout}
161
167
  {...restProps}
162
168
  />
163
169
  );