@prismicio/next 0.1.6-alpha.1 → 0.1.6

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.
@@ -27,6 +27,18 @@ function _interopNamespace(e) {
27
27
  }
28
28
  const Image__default = /* @__PURE__ */ _interopDefaultLegacy(Image);
29
29
  const prismicH__namespace = /* @__PURE__ */ _interopNamespace(prismicH);
30
+ const castInt = (input) => {
31
+ if (typeof input === "number" || typeof input === "undefined") {
32
+ return input;
33
+ } else {
34
+ const parsed = Number.parseInt(input);
35
+ if (Number.isNaN(parsed)) {
36
+ return void 0;
37
+ } else {
38
+ return parsed;
39
+ }
40
+ }
41
+ };
30
42
  const imgixLoader = (args) => {
31
43
  const url = new URL(args.src);
32
44
  const params = {
@@ -39,7 +51,14 @@ const imgixLoader = (args) => {
39
51
  }
40
52
  return imgixUrlBuilder.buildURL(args.src, params);
41
53
  };
42
- const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, ...restProps }) => {
54
+ const PrismicNextImage = ({
55
+ field,
56
+ imgixParams = {},
57
+ alt,
58
+ fallbackAlt,
59
+ layout = "intrinsic",
60
+ ...restProps
61
+ }) => {
43
62
  if (!__PRODUCTION__.__PRODUCTION__) {
44
63
  if (typeof alt === "string" && alt !== "") {
45
64
  console.warn(`[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.devMsg("alt-must-be-an-empty-string")}`);
@@ -50,7 +69,30 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, .
50
69
  }
51
70
  if (prismicH__namespace.isFilled.imageThumbnail(field)) {
52
71
  const src = imgixUrlBuilder.buildURL(field.url, imgixParams);
53
- return jsxRuntime.jsx(Image__default.default, { src, width: layout === "fill" ? void 0 : field.dimensions.width, height: layout === "fill" ? void 0 : field.dimensions.height, alt: alt != null ? alt : field.alt || fallbackAlt, loader: imgixLoader, layout, ...restProps });
72
+ const ar = field.dimensions.width / field.dimensions.height;
73
+ let resolvedWidth = field.dimensions.width;
74
+ let resolvedHeight = field.dimensions.height;
75
+ if ((layout === "intrinsic" || layout === "fixed") && ("width" in restProps || "height" in restProps)) {
76
+ const castedWidth = castInt(restProps.width);
77
+ const castedHeight = castInt(restProps.height);
78
+ if (castedWidth) {
79
+ resolvedWidth = castedWidth;
80
+ } else {
81
+ if (castedHeight) {
82
+ resolvedWidth = ar * castedHeight;
83
+ }
84
+ }
85
+ resolvedHeight = resolvedWidth / ar;
86
+ }
87
+ return jsxRuntime.jsx(Image__default.default, {
88
+ src,
89
+ width: layout === "fill" ? void 0 : resolvedWidth,
90
+ height: layout === "fill" ? void 0 : resolvedHeight,
91
+ alt: alt != null ? alt : field.alt || fallbackAlt,
92
+ loader: imgixLoader,
93
+ layout,
94
+ ...restProps
95
+ });
54
96
  } else {
55
97
  return null;
56
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport 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 * 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\"\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\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 *\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,\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\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : field.dimensions.width}\n\t\t\t\theight={layout === \"fill\" ? undefined : field.dimensions.height}\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":["buildURL","__PRODUCTION__","devMsg","prismicH","_jsx","Image"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,cAAc,CAAC,SAAkC;AACtD,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAAA,yBAAS,KAAK,KAAK,MAAM;AACjC;AAoDa,MAAA,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,WACG,gBACwB;AAC3B,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQC,OACxQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAySA,OACxS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,oBAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAMH,gBAAA,SAAS,MAAM,KAAK,WAAW;AAE3C,WACCI,WAAC,IAAAC,eAAA,SAAK,EACL,KACA,OAAO,WAAW,SAAS,SAAY,MAAM,WAAW,OACxD,QAAQ,WAAW,SAAS,SAAY,MAAM,WAAW,QACzD,KAAK,oBAAQ,MAAM,OAAO,aAC1B,QAAQ,aACR,QAAc,GACV,UAAS,CAAA;AAAA,EAAA,OAGT;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\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;AAAAA,EAChB;AAEME,SAAAA,yBAASb,KAAKG,KAAKC,MAAM;AACjC;AA0DO,MAAMU,mBAAmB,CAAC;AAAA,EAChCC;AAAAA,EACAC,cAAc,CAAE;AAAA,EAChBC;AAAAA,EACAC;AAAAA,EACAC,SAAS;AAAA,KACNC;AACoB,MAAI;AAC3B,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAOJ,QAAQ,YAAYA,QAAQ,IAAI;AAC1CK,cAAQC,KACkQ,yQAAAC,OACxQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAON,gBAAgB,YAAYA,gBAAgB,IAAI;AAC1DI,cAAQC,KACkS,ySAAAC,OACxS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,oBAASC,SAASC,eAAeZ,KAAK,GAAG;AAC5C,UAAMZ,MAAMU,gBAAAA,SAASE,MAAMd,KAAKe,WAAW;AAC3C,UAAMY,KAAKb,MAAMc,WAAWpB,QAAQM,MAAMc,WAAWC;AAEjDC,QAAAA,gBAAgBhB,MAAMc,WAAWpB;AACjCuB,QAAAA,iBAAiBjB,MAAMc,WAAWC;AAEtC,SACEX,WAAW,eAAeA,WAAW,aACrC,WAAWC,aAAa,YAAYA,YACpC;AACKa,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,WAAAA,IAACC,eAAAA,SACA;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,48 +1,51 @@
1
- /// <reference types="react" />
2
- import { ImageProps } from "next/image";
3
- import { ImgixURLParams } from "imgix-url-builder";
4
- import * as prismicT from "@prismicio/types";
5
- export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "width" | "height"> & {
6
- /**
7
- * The Prismic Image field or thumbnail to render.
8
- */
9
- field: prismicT.ImageFieldImage | null | undefined;
10
- /**
11
- * An object of Imgix URL API parameters to transform the image.
12
- *
13
- * @see https://docs.imgix.com/apis/rendering
14
- */
15
- imgixParams?: ImgixURLParams;
16
- /**
17
- * Declare an image as decorative by providing `alt=""`.
18
- *
19
- * See:
20
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
21
- */
22
- alt?: "";
23
- /**
24
- * Declare an image as decorative only if the Image field does not have
25
- * alternative text by providing `fallbackAlt=""`.
26
- *
27
- * See:
28
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
29
- */
30
- fallbackAlt?: "";
31
- };
32
- /**
33
- * React component that renders an image from a Prismic Image field or one of
34
- * its thumbnails using `next/image`. It will automatically set the `alt`
35
- * attribute using the Image field's `alt` property.
36
- *
37
- * It uses an Imgix URL-based loader by default. A custom loader can be provided
38
- * with the `loader` prop. If you would like to use the Next.js Image
39
- * Optimization API instead, set `loader={undefined}`.
40
- *
41
- * @param props - Props for the component.
42
- *
43
- * @returns A responsive image component using `next/image` for the given Image
44
- * field.
45
- *
46
- * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
47
- */
48
- export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, layout, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
1
+ /// <reference types="react" />
2
+ import { ImageProps } from "next/image";
3
+ import { ImgixURLParams } from "imgix-url-builder";
4
+ import * as prismicT from "@prismicio/types";
5
+ export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "width" | "height" | "layout"> & {
6
+ /**
7
+ * The Prismic Image field or thumbnail to render.
8
+ */
9
+ field: prismicT.ImageFieldImage | null | undefined;
10
+ /**
11
+ * An object of Imgix URL API parameters to transform the image.
12
+ *
13
+ * @see https://docs.imgix.com/apis/rendering
14
+ */
15
+ imgixParams?: ImgixURLParams;
16
+ /**
17
+ * Declare an image as decorative by providing `alt=""`.
18
+ *
19
+ * See:
20
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
21
+ */
22
+ alt?: "";
23
+ /**
24
+ * Declare an image as decorative only if the Image field does not have
25
+ * alternative text by providing `fallbackAlt=""`.
26
+ *
27
+ * See:
28
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
29
+ */
30
+ fallbackAlt?: "";
31
+ } & (({
32
+ layout?: "intrinsic" | "fixed";
33
+ } & Pick<ImageProps, "width" | "height">) | {
34
+ layout: "responsive" | "fill";
35
+ });
36
+ /**
37
+ * React component that renders an image from a Prismic Image field or one of
38
+ * its thumbnails using `next/image`. It will automatically set the `alt`
39
+ * attribute using the Image field's `alt` property.
40
+ *
41
+ * It uses an Imgix URL-based loader by default. A custom loader can be provided
42
+ * with the `loader` prop. If you would like to use the Next.js Image
43
+ * Optimization API instead, set `loader={undefined}`.
44
+ *
45
+ * @param props - Props for the component.
46
+ *
47
+ * @returns A responsive image component using `next/image` for the given Image
48
+ * field.
49
+ * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
50
+ */
51
+ export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, layout, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
@@ -4,6 +4,18 @@ import { buildURL } from "imgix-url-builder";
4
4
  import * as prismicH from "@prismicio/helpers";
5
5
  import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
6
6
  import { devMsg } from "./lib/devMsg.js";
7
+ const castInt = (input) => {
8
+ if (typeof input === "number" || typeof input === "undefined") {
9
+ return input;
10
+ } else {
11
+ const parsed = Number.parseInt(input);
12
+ if (Number.isNaN(parsed)) {
13
+ return void 0;
14
+ } else {
15
+ return parsed;
16
+ }
17
+ }
18
+ };
7
19
  const imgixLoader = (args) => {
8
20
  const url = new URL(args.src);
9
21
  const params = {
@@ -16,7 +28,14 @@ const imgixLoader = (args) => {
16
28
  }
17
29
  return buildURL(args.src, params);
18
30
  };
19
- const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, ...restProps }) => {
31
+ const PrismicNextImage = ({
32
+ field,
33
+ imgixParams = {},
34
+ alt,
35
+ fallbackAlt,
36
+ layout = "intrinsic",
37
+ ...restProps
38
+ }) => {
20
39
  if (!__PRODUCTION__) {
21
40
  if (typeof alt === "string" && alt !== "") {
22
41
  console.warn(`[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("alt-must-be-an-empty-string")}`);
@@ -27,7 +46,30 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, .
27
46
  }
28
47
  if (prismicH.isFilled.imageThumbnail(field)) {
29
48
  const src = buildURL(field.url, imgixParams);
30
- return jsx(Image, { src, width: layout === "fill" ? void 0 : field.dimensions.width, height: layout === "fill" ? void 0 : field.dimensions.height, alt: alt != null ? alt : field.alt || fallbackAlt, loader: imgixLoader, layout, ...restProps });
49
+ const ar = field.dimensions.width / field.dimensions.height;
50
+ let resolvedWidth = field.dimensions.width;
51
+ let resolvedHeight = field.dimensions.height;
52
+ if ((layout === "intrinsic" || layout === "fixed") && ("width" in restProps || "height" in restProps)) {
53
+ const castedWidth = castInt(restProps.width);
54
+ const castedHeight = castInt(restProps.height);
55
+ if (castedWidth) {
56
+ resolvedWidth = castedWidth;
57
+ } else {
58
+ if (castedHeight) {
59
+ resolvedWidth = ar * castedHeight;
60
+ }
61
+ }
62
+ resolvedHeight = resolvedWidth / ar;
63
+ }
64
+ return jsx(Image, {
65
+ src,
66
+ width: layout === "fill" ? void 0 : resolvedWidth,
67
+ height: layout === "fill" ? void 0 : resolvedHeight,
68
+ alt: alt != null ? alt : field.alt || fallbackAlt,
69
+ loader: imgixLoader,
70
+ layout,
71
+ ...restProps
72
+ });
31
73
  } else {
32
74
  return null;
33
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.js","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport 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 * 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\"\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\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 *\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,\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\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : field.dimensions.width}\n\t\t\t\theight={layout === \"fill\" ? undefined : field.dimensions.height}\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":["_jsx"],"mappings":";;;;;;AAgBA,MAAM,cAAc,CAAC,SAAkC;AACtD,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAA,SAAS,KAAK,KAAK,MAAM;AACjC;AAoDa,MAAA,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,WACG,gBACwB;AAC3B,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQ,OACxQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAyS,OACxS,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAI,SAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAM,SAAS,MAAM,KAAK,WAAW;AAE3C,WACCA,IAAC,OAAK,EACL,KACA,OAAO,WAAW,SAAS,SAAY,MAAM,WAAW,OACxD,QAAQ,WAAW,SAAS,SAAY,MAAM,WAAW,QACzD,KAAK,oBAAQ,MAAM,OAAO,aAC1B,QAAQ,aACR,QAAc,GACV,UAAS,CAAA;AAAA,EAAA,OAGT;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\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;AAAAA,EAChB;AAEME,SAAAA,SAASb,KAAKG,KAAKC,MAAM;AACjC;AA0DO,MAAMU,mBAAmB,CAAC;AAAA,EAChCC;AAAAA,EACAC,cAAc,CAAE;AAAA,EAChBC;AAAAA,EACAC;AAAAA,EACAC,SAAS;AAAA,KACNC;AACoB,MAAI;AAC3B,MAAI,CAACC,gBAAgB;AACpB,QAAI,OAAOJ,QAAQ,YAAYA,QAAQ,IAAI;AAC1CK,cAAQC,KACkQ,yQAAAC,OACxQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAON,gBAAgB,YAAYA,gBAAgB,IAAI;AAC1DI,cAAQC,KACkS,ySAAAC,OACxS,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,SAASC,SAASC,eAAeZ,KAAK,GAAG;AAC5C,UAAMZ,MAAMU,SAASE,MAAMd,KAAKe,WAAW;AAC3C,UAAMY,KAAKb,MAAMc,WAAWpB,QAAQM,MAAMc,WAAWC;AAEjDC,QAAAA,gBAAgBhB,MAAMc,WAAWpB;AACjCuB,QAAAA,iBAAiBjB,MAAMc,WAAWC;AAEtC,SACEX,WAAW,eAAeA,WAAW,aACrC,WAAWC,aAAa,YAAYA,YACpC;AACKa,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;"}
@@ -25,7 +25,12 @@ function _interopNamespace(e) {
25
25
  return Object.freeze(n);
26
26
  }
27
27
  const React__namespace = /* @__PURE__ */ _interopNamespace(React);
28
- function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
28
+ function PrismicPreview({
29
+ repositoryName,
30
+ children,
31
+ updatePreviewURL = "/api/preview",
32
+ exitPreviewURL = "/api/exit-preview"
33
+ }) {
29
34
  const router$1 = router.useRouter();
30
35
  const resolvedUpdatePreviewURL = router$1.basePath + updatePreviewURL;
31
36
  const resolvedExitPreviewURL = router$1.basePath + exitPreviewURL;
@@ -68,14 +73,12 @@ function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/pre
68
73
  window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
69
74
  window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
70
75
  };
71
- }, [
72
- repositoryName,
73
- resolvedExitPreviewURL,
74
- resolvedUpdatePreviewURL,
75
- router$1.isPreview,
76
- router$1.basePath
77
- ]);
78
- return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(react.PrismicToolbar, { repositoryName })] });
76
+ }, [repositoryName, resolvedExitPreviewURL, resolvedUpdatePreviewURL, router$1.isPreview, router$1.basePath]);
77
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, {
78
+ children: [children, jsxRuntime.jsx(react.PrismicToolbar, {
79
+ repositoryName
80
+ })]
81
+ });
79
82
  }
80
83
  exports.PrismicPreview = PrismicPreview;
81
84
  //# sourceMappingURL=PrismicPreview.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicPreview.cjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["router","useRouter","React","getPrismicPreviewCookie","getPreviewCookieRepositoryName","_jsxs","_Fragment","_jsx","PrismicToolbar"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAMA,WAASC,OAAAA;AAET,QAAA,2BAA2BD,SAAO,WAAW;AAC7C,QAAA,yBAAyBA,SAAO,WAAW;AAEjDE,mBAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAE3D,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAIF,SAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuBG,wBAAA,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAASH,SAAO,QAAQ;AAGnC,cAAA,qCACLI,8DAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACAJ,SAAO;AAAA,IACPA,SAAO;AAAA,EAAA,CACP;AAED,SACCK,gBAAAC,WAAAA,UAAA,EAAA,UAAA,CACE,UACDC,eAACC,MAAAA,gBAAe,EAAA,gBAAkC,CAAA,EAAA,CAAA;AAGrD;;"}
1
+ {"version":3,"file":"PrismicPreview.cjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["PrismicPreview","repositoryName","children","updatePreviewURL","exitPreviewURL","router","useRouter","resolvedUpdatePreviewURL","basePath","resolvedExitPreviewURL","React","useEffect","startPreviewMode","res","globalThis","fetch","ok","location","reload","error","handlePrismicPreviewUpdate","event","preventDefault","handlePrismicPreviewEnd","isPreview","addEventListener","prismicPreviewCookie","getPrismicPreviewCookie","document","cookie","locationIsDescendantOfBasePath","window","href","startsWith","origin","prismicPreviewCookieRepositoryName","getPreviewCookieRepositoryName","removeEventListener","_jsxs","_Fragment","_jsx","PrismicToolbar"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDgB,SAAAA,eAAe;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC,mBAAmB;AAAA,EACnBC,iBAAiB;AACI,GAAA;AACrB,QAAMC,WAASC,OAAAA;AAETC,QAAAA,2BAA2BF,SAAOG,WAAWL;AAC7CM,QAAAA,yBAAyBJ,SAAOG,WAAWJ;AAEjDM,mBAAMC,UAAU,MAAK;AAIpB,UAAMC,mBAAmB,YAAW;AAEnC,YAAMC,MAAM,MAAMC,WAAWC,MAAMR,wBAAwB;AAE3D,UAAIM,IAAIG,IAAI;AACXF,mBAAWG,SAASC;MAAQ,OACtB;AACEC,gBAAAA,8EACiEZ,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGIa,UAAAA,6BAA6B,OAAOC,UAAgB;AAEzDA,YAAMC,eAAgB;AAEtB,YAAMV,iBAAkB;AAAA,IAAA;AAGnBW,UAAAA,0BAA0B,OAAOF,UAAgB;AAEtDA,YAAMC,eAAgB;AAGtB,YAAMT,MAAM,MAAMC,WAAWC,MAAMN,sBAAsB;AAEzD,UAAII,IAAIG,IAAI;AACXF,mBAAWG,SAASC;MAAQ,OACtB;AACEC,gBAAAA,mEACsDV,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAIJ,SAAOmB,WAAW;AAEdC,aAAAA,iBACN,wBACAL,0BAA0B;AAEpBK,aAAAA,iBAAiB,qBAAqBF,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAMG,uBAAuBC,wBAAAA,wBAC5Bb,WAAWc,SAASC,MAAM;AAG3B,UAAIH,sBAAsB;AAiBnBI,cAAAA,iCAAiCC,OAAOd,SAASe,KAAKC,WAC3DF,OAAOd,SAASiB,SAAS7B,SAAOG,QAAQ;AAGnC2B,cAAAA,qCACLC,8DAA+BV,oBAAoB;AAGnDI,YAAAA,kCACAK,uCAAuClC,gBACtC;AACiB;QAClB;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJoC,aAAAA,oBACN,wBACAjB,0BAA0B;AAEpBiB,aAAAA,oBAAoB,qBAAqBd,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE,CACFtB,gBACAQ,wBACAF,0BACAF,SAAOmB,WACPnB,SAAOG,QAAQ,CACf;AAED,SACC8B,WAAAA,KAAAC,WAAAA,UAAA;AAAA,IAAArC,UAAA,CACEA,UACDsC,WAAAA,IAACC,sBAAe;AAAA,MAAAxC;AAAAA,IAAAA,CAAkC,CAAA;AAAA,EAAA,CAAA;AAGrD;;"}
@@ -1,42 +1,42 @@
1
- import * as React from "react";
2
- /**
3
- * Props for `<PrismicPreview>`.
4
- */
5
- export declare type PrismicPreviewProps = {
6
- /**
7
- * The name of your Prismic repository. A Prismic Toolbar will be registered
8
- * using this repository.
9
- */
10
- repositoryName: string;
11
- /**
12
- * The URL of your app's Prismic preview endpoint (default: `/api/preview`).
13
- * This URL will be fetched on preview update events.
14
- *
15
- * **Note**: If your `next.config.js` file contains a `basePath`, it is
16
- * automatically included.
17
- */
18
- updatePreviewURL?: string;
19
- /**
20
- * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
21
- * This URL will be fetched on preview exit events.
22
- *
23
- * **Note**: If your `next.config.js` file contains a `basePath`, it is
24
- * automatically included.
25
- */
26
- exitPreviewURL?: string;
27
- /**
28
- * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar
29
- * will be rendered last.
30
- */
31
- children?: React.ReactNode;
32
- };
33
- /**
34
- * React component that sets up Prismic Previews using the Prismic Toolbar. When
35
- * the Prismic Toolbar send events to the browser, such as on preview updates
36
- * and exiting, this component will automatically update the Next.js preview
37
- * cookie and refresh the page.
38
- *
39
- * This component can be wrapped around your app or added anywhere in your app's
40
- * tree. It must be rendered on every page.
41
- */
42
- export declare function PrismicPreview({ repositoryName, children, updatePreviewURL, exitPreviewURL, }: PrismicPreviewProps): JSX.Element;
1
+ import * as React from "react";
2
+ /**
3
+ * Props for `<PrismicPreview>`.
4
+ */
5
+ export declare type PrismicPreviewProps = {
6
+ /**
7
+ * The name of your Prismic repository. A Prismic Toolbar will be registered
8
+ * using this repository.
9
+ */
10
+ repositoryName: string;
11
+ /**
12
+ * The URL of your app's Prismic preview endpoint (default: `/api/preview`).
13
+ * This URL will be fetched on preview update events.
14
+ *
15
+ * **Note**: If your `next.config.js` file contains a `basePath`, it is
16
+ * automatically included.
17
+ */
18
+ updatePreviewURL?: string;
19
+ /**
20
+ * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
21
+ * This URL will be fetched on preview exit events.
22
+ *
23
+ * **Note**: If your `next.config.js` file contains a `basePath`, it is
24
+ * automatically included.
25
+ */
26
+ exitPreviewURL?: string;
27
+ /**
28
+ * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar
29
+ * will be rendered last.
30
+ */
31
+ children?: React.ReactNode;
32
+ };
33
+ /**
34
+ * React component that sets up Prismic Previews using the Prismic Toolbar. When
35
+ * the Prismic Toolbar send events to the browser, such as on preview updates
36
+ * and exiting, this component will automatically update the Next.js preview
37
+ * cookie and refresh the page.
38
+ *
39
+ * This component can be wrapped around your app or added anywhere in your app's
40
+ * tree. It must be rendered on every page.
41
+ */
42
+ export declare function PrismicPreview({ repositoryName, children, updatePreviewURL, exitPreviewURL, }: PrismicPreviewProps): JSX.Element;
@@ -4,7 +4,12 @@ import { PrismicToolbar } from "@prismicio/react";
4
4
  import { useRouter } from "next/router";
5
5
  import { getPrismicPreviewCookie } from "./lib/getPrismicPreviewCookie.js";
6
6
  import { getPreviewCookieRepositoryName } from "./lib/getPreviewCookieRepositoryName.js";
7
- function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
7
+ function PrismicPreview({
8
+ repositoryName,
9
+ children,
10
+ updatePreviewURL = "/api/preview",
11
+ exitPreviewURL = "/api/exit-preview"
12
+ }) {
8
13
  const router = useRouter();
9
14
  const resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;
10
15
  const resolvedExitPreviewURL = router.basePath + exitPreviewURL;
@@ -47,14 +52,12 @@ function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/pre
47
52
  window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
48
53
  window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
49
54
  };
50
- }, [
51
- repositoryName,
52
- resolvedExitPreviewURL,
53
- resolvedUpdatePreviewURL,
54
- router.isPreview,
55
- router.basePath
56
- ]);
57
- return jsxs(Fragment, { children: [children, jsx(PrismicToolbar, { repositoryName })] });
55
+ }, [repositoryName, resolvedExitPreviewURL, resolvedUpdatePreviewURL, router.isPreview, router.basePath]);
56
+ return jsxs(Fragment, {
57
+ children: [children, jsx(PrismicToolbar, {
58
+ repositoryName
59
+ })]
60
+ });
58
61
  }
59
62
  export {
60
63
  PrismicPreview
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicPreview.js","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAM,SAAS;AAET,QAAA,2BAA2B,OAAO,WAAW;AAC7C,QAAA,yBAAyB,OAAO,WAAW;AAEjD,QAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAE3D,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAI,OAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuB,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAAS,OAAO,QAAQ;AAGnC,cAAA,qCACL,+BAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EAAA,CACP;AAED,SACCA,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,gBAAe,EAAA,gBAAkC,CAAA,EAAA,CAAA;AAGrD;"}
1
+ {"version":3,"file":"PrismicPreview.js","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["PrismicPreview","repositoryName","children","updatePreviewURL","exitPreviewURL","router","useRouter","resolvedUpdatePreviewURL","basePath","resolvedExitPreviewURL","React","useEffect","startPreviewMode","res","globalThis","fetch","ok","location","reload","error","handlePrismicPreviewUpdate","event","preventDefault","handlePrismicPreviewEnd","isPreview","addEventListener","prismicPreviewCookie","getPrismicPreviewCookie","document","cookie","locationIsDescendantOfBasePath","window","href","startsWith","origin","prismicPreviewCookieRepositoryName","getPreviewCookieRepositoryName","removeEventListener","_jsxs","_Fragment","_jsx","PrismicToolbar"],"mappings":";;;;;;AAmDgB,SAAAA,eAAe;AAAA,EAC9BC;AAAAA,EACAC;AAAAA,EACAC,mBAAmB;AAAA,EACnBC,iBAAiB;AACI,GAAA;AACrB,QAAMC,SAASC;AAETC,QAAAA,2BAA2BF,OAAOG,WAAWL;AAC7CM,QAAAA,yBAAyBJ,OAAOG,WAAWJ;AAEjDM,QAAMC,UAAU,MAAK;AAIpB,UAAMC,mBAAmB,YAAW;AAEnC,YAAMC,MAAM,MAAMC,WAAWC,MAAMR,wBAAwB;AAE3D,UAAIM,IAAIG,IAAI;AACXF,mBAAWG,SAASC;MAAQ,OACtB;AACEC,gBAAAA,8EACiEZ,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGIa,UAAAA,6BAA6B,OAAOC,UAAgB;AAEzDA,YAAMC,eAAgB;AAEtB,YAAMV,iBAAkB;AAAA,IAAA;AAGnBW,UAAAA,0BAA0B,OAAOF,UAAgB;AAEtDA,YAAMC,eAAgB;AAGtB,YAAMT,MAAM,MAAMC,WAAWC,MAAMN,sBAAsB;AAEzD,UAAII,IAAIG,IAAI;AACXF,mBAAWG,SAASC;MAAQ,OACtB;AACEC,gBAAAA,mEACsDV,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAIJ,OAAOmB,WAAW;AAEdC,aAAAA,iBACN,wBACAL,0BAA0B;AAEpBK,aAAAA,iBAAiB,qBAAqBF,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAMG,uBAAuBC,wBAC5Bb,WAAWc,SAASC,MAAM;AAG3B,UAAIH,sBAAsB;AAiBnBI,cAAAA,iCAAiCC,OAAOd,SAASe,KAAKC,WAC3DF,OAAOd,SAASiB,SAAS7B,OAAOG,QAAQ;AAGnC2B,cAAAA,qCACLC,+BAA+BV,oBAAoB;AAGnDI,YAAAA,kCACAK,uCAAuClC,gBACtC;AACiB;QAClB;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJoC,aAAAA,oBACN,wBACAjB,0BAA0B;AAEpBiB,aAAAA,oBAAoB,qBAAqBd,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE,CACFtB,gBACAQ,wBACAF,0BACAF,OAAOmB,WACPnB,OAAOG,QAAQ,CACf;AAED,SACC8B,KAAAC,UAAA;AAAA,IAAArC,UAAA,CACEA,UACDsC,IAACC,gBAAe;AAAA,MAAAxC;AAAAA,IAAAA,CAAkC,CAAA;AAAA,EAAA,CAAA;AAGrD;"}
@@ -1,38 +1,38 @@
1
- import { PreviewData } from "next";
2
- import { Client, HttpRequestLike } from "@prismicio/client";
3
- /**
4
- * Configuration for `enableAutoPreviews`.
5
- *
6
- * @typeParam TPreviewData - Next.js preview data object.
7
- */
8
- export declare type EnableAutoPreviewsConfig<TPreviewData extends PreviewData = PreviewData> = {
9
- /**
10
- * Prismic client with which automatic previews will be enabled.
11
- */
12
- client: Client;
13
- } & ({
14
- /**
15
- * A Next.js context object (such as the context object from
16
- * `getStaticProps` or `getServerSideProps`).
17
- *
18
- * Pass a `context` object when using `enableAutoPreviews` outside a
19
- * Next.js API endpoint.
20
- */
21
- previewData?: TPreviewData;
22
- } | {
23
- /**
24
- * A Next.js API endpoint request object.
25
- *
26
- * Pass a `req` object when using `enableAutoPreviews` in a Next.js API
27
- * endpoint.
28
- */
29
- req?: HttpRequestLike;
30
- });
31
- /**
32
- * Configures a Prismic client to automatically query draft content during a
33
- * preview session. It either takes in a Next.js `getStaticProps` context object
34
- * or a Next.js API endpoint request object.
35
- *
36
- * @param config - Configuration for the function.
37
- */
38
- export declare const enableAutoPreviews: <TPreviewData extends PreviewData>(config: EnableAutoPreviewsConfig<TPreviewData>) => void;
1
+ import { PreviewData } from "next";
2
+ import { Client, HttpRequestLike } from "@prismicio/client";
3
+ /**
4
+ * Configuration for `enableAutoPreviews`.
5
+ *
6
+ * @typeParam TPreviewData - Next.js preview data object.
7
+ */
8
+ export declare type EnableAutoPreviewsConfig<TPreviewData extends PreviewData = PreviewData> = {
9
+ /**
10
+ * Prismic client with which automatic previews will be enabled.
11
+ */
12
+ client: Client;
13
+ } & ({
14
+ /**
15
+ * A Next.js context object (such as the context object from
16
+ * `getStaticProps` or `getServerSideProps`).
17
+ *
18
+ * Pass a `context` object when using `enableAutoPreviews` outside a
19
+ * Next.js API endpoint.
20
+ */
21
+ previewData?: TPreviewData;
22
+ } | {
23
+ /**
24
+ * A Next.js API endpoint request object.
25
+ *
26
+ * Pass a `req` object when using `enableAutoPreviews` in a Next.js API
27
+ * endpoint.
28
+ */
29
+ req?: HttpRequestLike;
30
+ });
31
+ /**
32
+ * Configures a Prismic client to automatically query draft content during a
33
+ * preview session. It either takes in a Next.js `getStaticProps` context object
34
+ * or a Next.js API endpoint request object.
35
+ *
36
+ * @param config - Configuration for the function.
37
+ */
38
+ export declare const enableAutoPreviews: <TPreviewData extends PreviewData>(config: EnableAutoPreviewsConfig<TPreviewData>) => void;
@@ -1,34 +1,34 @@
1
- import type { NextApiResponse, NextApiRequest } from "next";
2
- /**
3
- * Configuration for `exitPreview`.
4
- */
5
- export declare type ExitPreviewConfig = {
6
- /**
7
- * The `req` object from a Next.js API route. This is given as a parameter to
8
- * the API route.
9
- *
10
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
11
- */
12
- req: {
13
- headers: NextApiRequest["headers"];
14
- };
15
- /**
16
- * The `res` object from a Next.js API route. This is given as a parameter to
17
- * the API route.
18
- *
19
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
20
- */
21
- res: {
22
- clearPreviewData: NextApiResponse["clearPreviewData"];
23
- status: NextApiResponse["status"];
24
- json: NextApiResponse["json"];
25
- };
26
- /**
27
- * @deprecated - This property is no longer used. It can be deleted safely.
28
- */
29
- exitPreviewURL?: string;
30
- };
31
- /**
32
- * Exits Next.js's Preview Mode from within a Next.js API route.
33
- */
34
- export declare function exitPreview(config: ExitPreviewConfig): void;
1
+ import type { NextApiResponse, NextApiRequest } from "next";
2
+ /**
3
+ * Configuration for `exitPreview`.
4
+ */
5
+ export declare type ExitPreviewConfig = {
6
+ /**
7
+ * The `req` object from a Next.js API route. This is given as a parameter to
8
+ * the API route.
9
+ *
10
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
11
+ */
12
+ req: {
13
+ headers: NextApiRequest["headers"];
14
+ };
15
+ /**
16
+ * The `res` object from a Next.js API route. This is given as a parameter to
17
+ * the API route.
18
+ *
19
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
20
+ */
21
+ res: {
22
+ clearPreviewData: NextApiResponse["clearPreviewData"];
23
+ status: NextApiResponse["status"];
24
+ json: NextApiResponse["json"];
25
+ };
26
+ /**
27
+ * @deprecated - This property is no longer used. It can be deleted safely.
28
+ */
29
+ exitPreviewURL?: string;
30
+ };
31
+ /**
32
+ * Exits Next.js's Preview Mode from within a Next.js API route.
33
+ */
34
+ export declare function exitPreview(config: ExitPreviewConfig): void;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export { setPreviewData } from "./setPreviewData";
2
- export type { SetPreviewDataConfig } from "./setPreviewData";
3
- export { exitPreview } from "./exitPreview";
4
- export type { ExitPreviewConfig } from "./exitPreview";
5
- export { PrismicPreview } from "./PrismicPreview";
6
- export type { PrismicPreviewProps } from "./PrismicPreview";
7
- export { enableAutoPreviews } from "./enableAutoPreviews";
8
- export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
9
- export { redirectToPreviewURL } from "./redirectToPreviewURL";
10
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
11
- export { PrismicNextImage } from "./PrismicNextImage";
12
- export type { PrismicNextImageProps } from "./PrismicNextImage";
13
- export type { CreateClientConfig } from "./types";
1
+ export { setPreviewData } from "./setPreviewData";
2
+ export type { SetPreviewDataConfig } from "./setPreviewData";
3
+ export { exitPreview } from "./exitPreview";
4
+ export type { ExitPreviewConfig } from "./exitPreview";
5
+ export { PrismicPreview } from "./PrismicPreview";
6
+ export type { PrismicPreviewProps } from "./PrismicPreview";
7
+ export { enableAutoPreviews } from "./enableAutoPreviews";
8
+ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
9
+ export { redirectToPreviewURL } from "./redirectToPreviewURL";
10
+ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
11
+ export { PrismicNextImage } from "./PrismicNextImage";
12
+ export type { PrismicNextImageProps } from "./PrismicNextImage";
13
+ export type { CreateClientConfig } from "./types";
@@ -1,7 +1,7 @@
1
- /**
2
- * `true` if in the production environment, `false` otherwise.
3
- *
4
- * This boolean can be used to perform actions only in development environments,
5
- * such as logging.
6
- */
7
- export declare const __PRODUCTION__: boolean;
1
+ /**
2
+ * `true` if in the production environment, `false` otherwise.
3
+ *
4
+ * This boolean can be used to perform actions only in development environments,
5
+ * such as logging.
6
+ */
7
+ export declare const __PRODUCTION__: boolean;
@@ -1,16 +1,16 @@
1
- /**
2
- * Returns a `prismic.dev/msg` URL for a given message slug.
3
- *
4
- * @example
5
- *
6
- * ```ts
7
- * devMsg("missing-param");
8
- * // => "https://prismic.dev/msg/next/v1.2.3/missing-param.md"
9
- * ```
10
- *
11
- * @param slug - Slug for the message. This corresponds to a Markdown file in
12
- * the Git repository's `/messages` directory.
13
- *
14
- * @returns The `prismic.dev/msg` URL for the given slug.
15
- */
16
- export declare const devMsg: (slug: string) => string;
1
+ /**
2
+ * Returns a `prismic.dev/msg` URL for a given message slug.
3
+ *
4
+ * @example
5
+ *
6
+ * ```ts
7
+ * devMsg("missing-param");
8
+ * // => "https://prismic.dev/msg/next/v1.2.3/missing-param.md"
9
+ * ```
10
+ *
11
+ * @param slug - Slug for the message. This corresponds to a Markdown file in
12
+ * the Git repository's `/messages` directory.
13
+ *
14
+ * @returns The `prismic.dev/msg` URL for the given slug.
15
+ */
16
+ export declare const devMsg: (slug: string) => string;
@@ -1,9 +1,9 @@
1
- /**
2
- * Extracts preview reference repo name from stringified Prismic preview cookie
3
- *
4
- * @param previewCookie - The Prismic preview cookie.
5
- *
6
- * @returns The repository name for the Prismic preview cookie. If the cookie
7
- * represents an inactive preview session, `undefined` will be returned.
8
- */
9
- export declare const getPreviewCookieRepositoryName: (previewCookie: string) => string | undefined;
1
+ /**
2
+ * Extracts preview reference repo name from stringified Prismic preview cookie
3
+ *
4
+ * @param previewCookie - The Prismic preview cookie.
5
+ *
6
+ * @returns The repository name for the Prismic preview cookie. If the cookie
7
+ * represents an inactive preview session, `undefined` will be returned.
8
+ */
9
+ export declare const getPreviewCookieRepositoryName: (previewCookie: string) => string | undefined;
@@ -1,9 +1,9 @@
1
- /**
2
- * Returns the value of a cookie from a given cookie store.
3
- *
4
- * @param cookieJar - The stringified cookie store from which to read the
5
- * cookie.
6
- *
7
- * @returns The value of the cookie, if it exists.
8
- */
9
- export declare const getPrismicPreviewCookie: (cookieJar: string) => string | undefined;
1
+ /**
2
+ * Returns the value of a cookie from a given cookie store.
3
+ *
4
+ * @param cookieJar - The stringified cookie store from which to read the
5
+ * cookie.
6
+ *
7
+ * @returns The value of the cookie, if it exists.
8
+ */
9
+ export declare const getPrismicPreviewCookie: (cookieJar: string) => string | undefined;
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.6-alpha.1";
3
+ const version = "0.1.6";
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.6-alpha.1";
1
+ const version = "0.1.6";
2
2
  export {
3
3
  version
4
4
  };
@@ -1,59 +1,59 @@
1
- import type { Client } from "@prismicio/client";
2
- import type { NextApiRequest, NextApiResponse } from "next";
3
- import type { LinkResolverFunction } from "@prismicio/helpers";
4
- /**
5
- * Preview config for enabling previews with redirectToPreviewURL
6
- */
7
- export declare type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
8
- /**
9
- * The `req` object from a Next.js API route. This is given as a parameter to
10
- * the API route.
11
- *
12
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
13
- */
14
- req: {
15
- query: NextApiRequest["query"];
16
- };
17
- /**
18
- * The `res` object from a Next.js API route. This is given as a parameter to
19
- * the API route.
20
- *
21
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
22
- */
23
- res: {
24
- redirect: NextApiResponse["redirect"];
25
- };
26
- /**
27
- * The Prismic client configured for the preview session's repository.
28
- */
29
- client: Client;
30
- /**
31
- * A Link Resolver used to resolve the previewed document's URL.
32
- *
33
- * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
34
- */
35
- linkResolver?: TLinkResolverFunction;
36
- /**
37
- * The default redirect URL if a URL cannot be determined for the previewed
38
- * document.
39
- *
40
- * **Note**: If you `next.config.js` file contains a `basePath`, the
41
- * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
42
- * property using the `basePath` option.
43
- */
44
- defaultURL?: string;
45
- /**
46
- * The `basePath` for the Next.js app as it is defined in `next.config.js`.
47
- * This option can be omitted if the app does not have a `basePath`.
48
- *
49
- * @remarks
50
- * The API route is unable to detect the app's `basePath` automatically. It
51
- * must be provided to `redirectToPreviewURL()` manually.
52
- */
53
- basePath?: string;
54
- };
55
- /**
56
- * Redirects a user to the URL of a previewed Prismic document from within a
57
- * Next.js API route.
58
- */
59
- export declare function redirectToPreviewURL<TLinkResolverFunction extends LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
1
+ import type { Client } from "@prismicio/client";
2
+ import type { NextApiRequest, NextApiResponse } from "next";
3
+ import type { LinkResolverFunction } from "@prismicio/helpers";
4
+ /**
5
+ * Preview config for enabling previews with redirectToPreviewURL
6
+ */
7
+ export declare type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
8
+ /**
9
+ * The `req` object from a Next.js API route. This is given as a parameter to
10
+ * the API route.
11
+ *
12
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
13
+ */
14
+ req: {
15
+ query: NextApiRequest["query"];
16
+ };
17
+ /**
18
+ * The `res` object from a Next.js API route. This is given as a parameter to
19
+ * the API route.
20
+ *
21
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
22
+ */
23
+ res: {
24
+ redirect: NextApiResponse["redirect"];
25
+ };
26
+ /**
27
+ * The Prismic client configured for the preview session's repository.
28
+ */
29
+ client: Client;
30
+ /**
31
+ * A Link Resolver used to resolve the previewed document's URL.
32
+ *
33
+ * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
34
+ */
35
+ linkResolver?: TLinkResolverFunction;
36
+ /**
37
+ * The default redirect URL if a URL cannot be determined for the previewed
38
+ * document.
39
+ *
40
+ * **Note**: If you `next.config.js` file contains a `basePath`, the
41
+ * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
42
+ * property using the `basePath` option.
43
+ */
44
+ defaultURL?: string;
45
+ /**
46
+ * The `basePath` for the Next.js app as it is defined in `next.config.js`.
47
+ * This option can be omitted if the app does not have a `basePath`.
48
+ *
49
+ * @remarks
50
+ * The API route is unable to detect the app's `basePath` automatically. It
51
+ * must be provided to `redirectToPreviewURL()` manually.
52
+ */
53
+ basePath?: string;
54
+ };
55
+ /**
56
+ * Redirects a user to the URL of a previewed Prismic document from within a
57
+ * Next.js API route.
58
+ */
59
+ export declare function redirectToPreviewURL<TLinkResolverFunction extends LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
@@ -1,29 +1,29 @@
1
- import { NextApiResponse, NextApiRequest } from "next";
2
- /**
3
- * Configuration for `setPreviewData`.
4
- */
5
- export declare type SetPreviewDataConfig = {
6
- /**
7
- * The `req` object from a Next.js API route. This is given as a parameter to
8
- * the API route.
9
- *
10
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
11
- */
12
- req: {
13
- query: NextApiRequest["query"];
14
- cookies: NextApiRequest["cookies"];
15
- };
16
- /**
17
- * The `res` object from a Next.js API route. This is given as a parameter to
18
- * the API route.
19
- *
20
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
21
- */
22
- res: {
23
- setPreviewData: NextApiResponse["setPreviewData"];
24
- };
25
- };
26
- /**
27
- * Set Prismic preview data for Next.js's Preview Mode.
28
- */
29
- export declare function setPreviewData({ req, res }: SetPreviewDataConfig): void;
1
+ import { NextApiResponse, NextApiRequest } from "next";
2
+ /**
3
+ * Configuration for `setPreviewData`.
4
+ */
5
+ export declare type SetPreviewDataConfig = {
6
+ /**
7
+ * The `req` object from a Next.js API route. This is given as a parameter to
8
+ * the API route.
9
+ *
10
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
11
+ */
12
+ req: {
13
+ query: NextApiRequest["query"];
14
+ cookies: NextApiRequest["cookies"];
15
+ };
16
+ /**
17
+ * The `res` object from a Next.js API route. This is given as a parameter to
18
+ * the API route.
19
+ *
20
+ * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
21
+ */
22
+ res: {
23
+ setPreviewData: NextApiResponse["setPreviewData"];
24
+ };
25
+ };
26
+ /**
27
+ * Set Prismic preview data for Next.js's Preview Mode.
28
+ */
29
+ export declare function setPreviewData({ req, res }: SetPreviewDataConfig): void;
package/dist/types.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- import type { PreviewData, NextApiRequest } from "next";
2
- import type { ClientConfig } from "@prismicio/client";
3
- /**
4
- * Configuration for creating a Prismic client with automatic preview support in
5
- * Next.js apps.
6
- */
7
- export declare type CreateClientConfig = {
8
- /**
9
- * Preview data coming from Next.js context object. This context object comes
10
- * from `getStaticProps` or `getServerSideProps`.
11
- *
12
- * Pass `previewData` when using outside a Next.js API endpoint.
13
- */
14
- previewData?: PreviewData;
15
- /**
16
- * A Next.js API endpoint request object.
17
- *
18
- * Pass a `req` object when using in a Next.js API endpoint.
19
- */
20
- req?: NextApiRequest;
21
- } & ClientConfig;
1
+ import type { PreviewData, NextApiRequest } from "next";
2
+ import type { ClientConfig } from "@prismicio/client";
3
+ /**
4
+ * Configuration for creating a Prismic client with automatic preview support in
5
+ * Next.js apps.
6
+ */
7
+ export declare type CreateClientConfig = {
8
+ /**
9
+ * Preview data coming from Next.js context object. This context object comes
10
+ * from `getStaticProps` or `getServerSideProps`.
11
+ *
12
+ * Pass `previewData` when using outside a Next.js API endpoint.
13
+ */
14
+ previewData?: PreviewData;
15
+ /**
16
+ * A Next.js API endpoint request object.
17
+ *
18
+ * Pass a `req` object when using in a Next.js API endpoint.
19
+ */
20
+ req?: NextApiRequest;
21
+ } & ClientConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "0.1.6-alpha.1",
3
+ "version": "0.1.6",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -46,8 +46,8 @@
46
46
  "unit:watch": "vitest watch"
47
47
  },
48
48
  "dependencies": {
49
- "@prismicio/client": "^6.0.0",
50
- "@prismicio/helpers": "^2.3.3",
49
+ "@prismicio/client": "^6.7.1",
50
+ "@prismicio/helpers": "^2.3.5",
51
51
  "@prismicio/react": "^2.5.0",
52
52
  "@prismicio/types": "^0.2.3",
53
53
  "imgix-url-builder": "^0.0.3"
@@ -56,16 +56,17 @@
56
56
  "@prismicio/mock": "^0.1.1",
57
57
  "@size-limit/preset-small-lib": "^8.1.0",
58
58
  "@types/react-test-renderer": "^18.0.0",
59
- "@typescript-eslint/eslint-plugin": "^5.36.2",
60
- "@typescript-eslint/parser": "^5.36.2",
61
- "@vitest/coverage-c8": "^0.23.1",
62
- "eslint": "^8.23.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.40.0",
60
+ "@typescript-eslint/parser": "^5.40.0",
61
+ "@vitejs/plugin-react": "^2.1.0",
62
+ "@vitest/coverage-c8": "^0.24.1",
63
+ "eslint": "^8.25.0",
63
64
  "eslint-config-prettier": "^8.5.0",
64
65
  "eslint-plugin-prettier": "^4.2.1",
65
- "eslint-plugin-react": "^7.31.7",
66
+ "eslint-plugin-react": "^7.31.10",
66
67
  "eslint-plugin-react-hooks": "^4.6.0",
67
- "eslint-plugin-tsdoc": "^0.2.16",
68
- "happy-dom": "^6.0.4",
68
+ "eslint-plugin-tsdoc": "^0.2.17",
69
+ "happy-dom": "^7.5.6",
69
70
  "next": "^12.1.4",
70
71
  "nyc": "^15.1.0",
71
72
  "prettier": "^2.7.1",
@@ -74,10 +75,10 @@
74
75
  "react-test-renderer": "^18.2.0",
75
76
  "size-limit": "^8.1.0",
76
77
  "standard-version": "^9.5.0",
77
- "typescript": "^4.8.3",
78
- "vite": "^3.1.1",
79
- "vite-plugin-sdk": "^0.0.2",
80
- "vitest": "^0.23.1"
78
+ "typescript": "^4.8.4",
79
+ "vite": "^3.1.7",
80
+ "vite-plugin-sdk": "^0.0.3",
81
+ "vitest": "^0.24.1"
81
82
  },
82
83
  "peerDependencies": {
83
84
  "@prismicio/client": "^6.0.0",
@@ -1,4 +1,3 @@
1
- import * as React from "react";
2
1
  import Image, { ImageProps, ImageLoaderProps } from "next/image";
3
2
  import { buildURL, ImgixURLParams } from "imgix-url-builder";
4
3
  import * as prismicH from "@prismicio/helpers";
@@ -7,6 +6,20 @@ import * as prismicT from "@prismicio/types";
7
6
  import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
8
7
  import { devMsg } from "./lib/devMsg";
9
8
 
9
+ const castInt = (input: string | number | undefined): number | undefined => {
10
+ if (typeof input === "number" || typeof input === "undefined") {
11
+ return input;
12
+ } else {
13
+ const parsed = Number.parseInt(input);
14
+
15
+ if (Number.isNaN(parsed)) {
16
+ return undefined;
17
+ } else {
18
+ return parsed;
19
+ }
20
+ }
21
+ };
22
+
10
23
  /**
11
24
  * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional
12
25
  * collection of default Imgix parameters.
@@ -32,7 +45,7 @@ const imgixLoader = (args: ImageLoaderProps): string => {
32
45
 
33
46
  export type PrismicNextImageProps = Omit<
34
47
  ImageProps,
35
- "src" | "alt" | "width" | "height"
48
+ "src" | "alt" | "width" | "height" | "layout"
36
49
  > & {
37
50
  /**
38
51
  * The Prismic Image field or thumbnail to render.
@@ -62,7 +75,14 @@ export type PrismicNextImageProps = Omit<
62
75
  * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
63
76
  */
64
77
  fallbackAlt?: "";
65
- };
78
+ } & (
79
+ | ({
80
+ layout?: "intrinsic" | "fixed";
81
+ } & Pick<ImageProps, "width" | "height">)
82
+ | {
83
+ layout: "responsive" | "fill";
84
+ }
85
+ );
66
86
 
67
87
  /**
68
88
  * React component that renders an image from a Prismic Image field or one of
@@ -77,7 +97,6 @@ export type PrismicNextImageProps = Omit<
77
97
  *
78
98
  * @returns A responsive image component using `next/image` for the given Image
79
99
  * field.
80
- *
81
100
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
82
101
  */
83
102
  export const PrismicNextImage = ({
@@ -85,7 +104,7 @@ export const PrismicNextImage = ({
85
104
  imgixParams = {},
86
105
  alt,
87
106
  fallbackAlt,
88
- layout,
107
+ layout = "intrinsic",
89
108
  ...restProps
90
109
  }: PrismicNextImageProps) => {
91
110
  if (!__PRODUCTION__) {
@@ -108,12 +127,34 @@ export const PrismicNextImage = ({
108
127
 
109
128
  if (prismicH.isFilled.imageThumbnail(field)) {
110
129
  const src = buildURL(field.url, imgixParams);
130
+ const ar = field.dimensions.width / field.dimensions.height;
131
+
132
+ let resolvedWidth = field.dimensions.width;
133
+ let resolvedHeight = field.dimensions.height;
134
+
135
+ if (
136
+ (layout === "intrinsic" || layout === "fixed") &&
137
+ ("width" in restProps || "height" in restProps)
138
+ ) {
139
+ const castedWidth = castInt(restProps.width);
140
+ const castedHeight = castInt(restProps.height);
141
+
142
+ if (castedWidth) {
143
+ resolvedWidth = castedWidth;
144
+ } else {
145
+ if (castedHeight) {
146
+ resolvedWidth = ar * castedHeight;
147
+ }
148
+ }
149
+
150
+ resolvedHeight = resolvedWidth / ar;
151
+ }
111
152
 
112
153
  return (
113
154
  <Image
114
155
  src={src}
115
- width={layout === "fill" ? undefined : field.dimensions.width}
116
- height={layout === "fill" ? undefined : field.dimensions.height}
156
+ width={layout === "fill" ? undefined : resolvedWidth}
157
+ height={layout === "fill" ? undefined : resolvedHeight}
117
158
  alt={alt ?? (field.alt || fallbackAlt)}
118
159
  loader={imgixLoader}
119
160
  layout={layout}