@prismicio/next 1.3.4 → 1.3.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.
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.cjs","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\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\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismic.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tfill,\n\twidth,\n\theight,\n\tfallback = null,\n\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (process.env.NODE_ENV !== \"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 (prismic.isFilled.imageThumbnail(field)) {\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.\n\t\t// `next/image` seems to be affected by a default + named export bundling bug.\n\t\tlet ResolvedImage = Image;\n\t\tif (\"default\" in ResolvedImage) {\n\t\t\tResolvedImage = (ResolvedImage as unknown as { default: typeof Image })\n\t\t\t\t.default;\n\t\t}\n\n\t\treturn (\n\t\t\t<ResolvedImage\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn <>{fallback}</>;\n\t}\n};\n"],"names":[],"mappings":";;;;;;;;;;AAUA;AACC;AACQ;AAAA;AAED;AAEF;AACI;AAAA;AAEA;AAAA;AACP;AAEH;AAsDO;AAWF;AACH;AACC;AAGI;AAIL;AACC;AAGI;AAEJ;AAGF;AACC;AACA;AACK;AACH;AAA6D;AAC7D;AAGF;AAEA;AAEM;AACA;AAEF;AACA;AAEA;AACH;AAA+B;AAE/B;AAA+B;AAM1B;AAEN;AAIS;AAEJ;AAML;AACA;AACC;AACE;AAGH;AASG;AAGH;AAAkB;AAEpB;;"}
1
+ {"version":3,"file":"PrismicNextImage.cjs","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\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\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismic.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\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\tfill,\n\twidth,\n\theight,\n\tfallback = null,\n\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (process.env.NODE_ENV !== \"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 (prismic.isFilled.imageThumbnail(field)) {\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.\n\t\t// `next/image` seems to be affected by a default + named export bundling bug.\n\t\tlet ResolvedImage = Image;\n\t\tif (\"default\" in ResolvedImage) {\n\t\t\tResolvedImage = (ResolvedImage as unknown as { default: typeof Image })\n\t\t\t\t.default;\n\t\t}\n\n\t\treturn (\n\t\t\t<ResolvedImage\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn <>{fallback}</>;\n\t}\n};\n"],"names":[],"mappings":";;;;;;;;;;AAUA;AACC;AACQ;AAAA;AAED;AAEF;AACI;AAAA;AAEA;AAAA;AACP;AAEH;AAuDO;AAWF;AACH;AACC;AAGI;AAIL;AACC;AAGI;AAEJ;AAGF;AACC;AACA;AACK;AACH;AAA6D;AAC7D;AAGF;AAEA;AAEM;AACA;AAEF;AACA;AAEA;AACH;AAA+B;AAE/B;AAA+B;AAM1B;AAEN;AAIS;AAEJ;AAML;AACA;AACC;AACE;AAGH;AASG;AAGH;AAAkB;AAEpB;;"}
@@ -49,6 +49,7 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
49
49
  *
50
50
  * @returns A responsive image component using `next/image` for the given Image
51
51
  * field.
52
+ *
52
53
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
53
54
  */
54
55
  export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, fill, width, height, fallback, ...restProps }: PrismicNextImageProps) => JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicNextImage.js","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\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\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismic.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tfill,\n\twidth,\n\theight,\n\tfallback = null,\n\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (process.env.NODE_ENV !== \"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 (prismic.isFilled.imageThumbnail(field)) {\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.\n\t\t// `next/image` seems to be affected by a default + named export bundling bug.\n\t\tlet ResolvedImage = Image;\n\t\tif (\"default\" in ResolvedImage) {\n\t\t\tResolvedImage = (ResolvedImage as unknown as { default: typeof Image })\n\t\t\t\t.default;\n\t\t}\n\n\t\treturn (\n\t\t\t<ResolvedImage\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn <>{fallback}</>;\n\t}\n};\n"],"names":[],"mappings":";;;;;;;;AAUA;AACC;AACQ;AAAA;AAED;AAEF;AACI;AAAA;AAEA;AAAA;AACP;AAEH;AAsDO;AAWF;AACH;AACC;AAGI;AAIL;AACC;AAGI;AAEJ;AAGF;AACC;AACA;AACK;AACH;AAA6D;AAC7D;AAGF;AAEA;AAEM;AACA;AAEF;AACA;AAEA;AACH;AAA+B;AAE/B;AAA+B;AAM1B;AAEN;AAIS;AAEJ;AAML;AACA;AACC;AACE;AAGH;AASG;AAGH;AAAkB;AAEpB;;;;"}
1
+ {"version":3,"file":"PrismicNextImage.js","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\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\nexport type PrismicNextImageProps = Omit<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismic.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\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\tfill,\n\twidth,\n\theight,\n\tfallback = null,\n\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (process.env.NODE_ENV !== \"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 (prismic.isFilled.imageThumbnail(field)) {\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\t// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.\n\t\t// `next/image` seems to be affected by a default + named export bundling bug.\n\t\tlet ResolvedImage = Image;\n\t\tif (\"default\" in ResolvedImage) {\n\t\t\tResolvedImage = (ResolvedImage as unknown as { default: typeof Image })\n\t\t\t\t.default;\n\t\t}\n\n\t\treturn (\n\t\t\t<ResolvedImage\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn <>{fallback}</>;\n\t}\n};\n"],"names":[],"mappings":";;;;;;;;AAUA;AACC;AACQ;AAAA;AAED;AAEF;AACI;AAAA;AAEA;AAAA;AACP;AAEH;AAuDO;AAWF;AACH;AACC;AAGI;AAIL;AACC;AAGI;AAEJ;AAGF;AACC;AACA;AACK;AACH;AAA6D;AAC7D;AAGF;AAEA;AAEM;AACA;AAEF;AACA;AAEA;AACH;AAA+B;AAE/B;AAA+B;AAM1B;AAEN;AAIS;AAEJ;AAML;AACA;AACC;AACE;AAGH;AASG;AAGH;AAAkB;AAEpB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicPreview.cjs","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\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 * **Only used in the Pages Directory (/pages).**\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\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\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\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\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 refresh the page with the\n * changes.\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\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","draftMode","_jsxs","_Fragment","_jsx","PrismicPreviewClient"],"mappings":";;;;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,4BAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAcC,QAAAA,UAAY,EAAA;AAAA,EAAA,QACzB;AAAA,EAID;AAGA,SAAAC,WAAA,KAAAC,qBAAA,EAAA,UAAA,CACE,UACDC,WAAAA,IAACC,qBAAA,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVD,WAAAA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;;"}
1
+ {"version":3,"file":"PrismicPreview.cjs","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\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 * **Only used in the Pages Directory (/pages).**\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\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\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\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\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 refresh the page with the\n * changes.\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\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","draftMode","_jsxs","_Fragment","_jsx","PrismicPreviewClient"],"mappings":";;;;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,4BAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAcC,QAAAA,UAAY,EAAA;AAAA,EAAA,QACnB;AAAA,EAIP;AAGA,SAAAC,WAAA,KAAAC,qBAAA,EAAA,UAAA,CACE,UACDC,WAAAA,IAACC,qBAAA,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVD,WAAAA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicPreview.js","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\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 * **Only used in the Pages Directory (/pages).**\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\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\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\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\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 refresh the page with the\n * changes.\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\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx"],"mappings":";;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,cAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAc,UAAY,EAAA;AAAA,EAAA,QACzB;AAAA,EAID;AAGA,SAAAC,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;"}
1
+ {"version":3,"file":"PrismicPreview.js","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\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 * **Only used in the Pages Directory (/pages).**\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\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\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\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\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 refresh the page with the\n * changes.\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\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx"],"mappings":";;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,cAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAc,UAAY,EAAA;AAAA,EAAA,QACnB;AAAA,EAIP;AAGA,SAAAC,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.cjs","sources":["../../../../../node_modules/@prismicio/client/dist/getToolbarSrc.js"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError.js\";\nimport { isRepositoryName } from \"./isRepositoryName.js\";\nconst getToolbarSrc = (repositoryName) => {\n if (isRepositoryName(repositoryName)) {\n return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;\n } else {\n throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);\n }\n};\nexport {\n getToolbarSrc\n};\n//# sourceMappingURL=getToolbarSrc.js.map\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAEK,MAAC,gBAAgB,CAAC,mBAAmB;AACxC,MAAIA,iBAAAA,iBAAiB,cAAc,GAAG;AACpC,WAAO,0DAA0D;AAAA,EACrE,OAAS;AACL,UAAM,IAAIC,aAAAA,aAAa,iDAAiD,kBAAkB,QAAQ,MAAM;AAAA,EACzG;AACH;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"getToolbarSrc.cjs","sources":["../../../../../node_modules/@prismicio/client/dist/getToolbarSrc.js"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError.js\";\nimport { isRepositoryName } from \"./isRepositoryName.js\";\nconst getToolbarSrc = (repositoryName) => {\n if (isRepositoryName(repositoryName)) {\n return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;\n } else {\n throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);\n }\n};\nexport {\n getToolbarSrc\n};\n//# sourceMappingURL=getToolbarSrc.js.map\n"],"names":["isRepositoryName","PrismicError"],"mappings":";;;;AAEK,MAAC,gBAAgB,CAAC,mBAAmB;AACxC,MAAIA,iBAAAA,iBAAiB,cAAc,GAAG;AACpC,WAAO,0DAA0D,cAAc;AAAA,EACnF,OAAS;AACL,UAAM,IAAIC,aAAAA,aAAa,iDAAiD,cAAc,IAAI,QAAQ,MAAM;AAAA,EACzG;AACH;;","x_google_ignoreList":[0]}
@@ -1 +1 @@
1
- {"version":3,"file":"getToolbarSrc.js","sources":["../../../../../node_modules/@prismicio/client/dist/getToolbarSrc.js"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError.js\";\nimport { isRepositoryName } from \"./isRepositoryName.js\";\nconst getToolbarSrc = (repositoryName) => {\n if (isRepositoryName(repositoryName)) {\n return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;\n } else {\n throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);\n }\n};\nexport {\n getToolbarSrc\n};\n//# sourceMappingURL=getToolbarSrc.js.map\n"],"names":[],"mappings":";;AAEK,MAAC,gBAAgB,CAAC,mBAAmB;AACxC,MAAI,iBAAiB,cAAc,GAAG;AACpC,WAAO,0DAA0D;AAAA,EACrE,OAAS;AACL,UAAM,IAAI,aAAa,iDAAiD,kBAAkB,QAAQ,MAAM;AAAA,EACzG;AACH;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"getToolbarSrc.js","sources":["../../../../../node_modules/@prismicio/client/dist/getToolbarSrc.js"],"sourcesContent":["import { PrismicError } from \"./errors/PrismicError.js\";\nimport { isRepositoryName } from \"./isRepositoryName.js\";\nconst getToolbarSrc = (repositoryName) => {\n if (isRepositoryName(repositoryName)) {\n return `https://static.cdn.prismic.io/prismic.js?new=true&repo=${repositoryName}`;\n } else {\n throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);\n }\n};\nexport {\n getToolbarSrc\n};\n//# sourceMappingURL=getToolbarSrc.js.map\n"],"names":[],"mappings":";;AAEK,MAAC,gBAAgB,CAAC,mBAAmB;AACxC,MAAI,iBAAiB,cAAc,GAAG;AACpC,WAAO,0DAA0D,cAAc;AAAA,EACnF,OAAS;AACL,UAAM,IAAI,aAAa,iDAAiD,cAAc,IAAI,QAAQ,MAAM;AAAA,EACzG;AACH;","x_google_ignoreList":[0]}
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["draftMode","cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,UAAI,qBAAqB;AACrB,UAAA;AACH,6BAAqBA,QAAAA,UAAY,EAAA;AAAA,MAAA,QAChC;AAMD;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAAC;AACA,UAAA;AACHA,oBAASC,aAAAA,QAAU,EAAA,IAAIC,OAAsB,OAAA,MAApCD,mBAAuC;AAAA,MAAA,QAC/C;AAMD;AAAA,MACA;AAgBD,UAAID,YAAU,gBAAgB,KAAKA,QAAM,GAAG;AACpC,eAAAA;AAAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
1
+ {"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["draftMode","cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,UAAI,qBAAqB;AACrB,UAAA;AACH,6BAAqBA,QAAAA,UAAY,EAAA;AAAA,MAAA,QAC1B;AAMP;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAAC;AACA,UAAA;AACHA,oBAASC,aAAAA,QAAU,EAAA,IAAIC,OAAsB,OAAA,MAApCD,mBAAuC;AAAA,MAAA,QACzC;AAMP;AAAA,MACA;AAgBD,UAAID,YAAU,gBAAgB,KAAKA,QAAM,GAAG;AACpC,eAAAA;AAAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,UAAI,qBAAqB;AACrB,UAAA;AACH,6BAAqB,UAAY,EAAA;AAAA,MAAA,QAChC;AAMD;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAA;AACA,UAAA;AACH,kBAAS,aAAU,EAAA,IAAIA,OAAsB,MAApC,mBAAuC;AAAA,MAAA,QAC/C;AAMD;AAAA,MACA;AAgBD,UAAI,UAAU,gBAAgB,KAAK,MAAM,GAAG;AACpC,eAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
1
+ {"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,MAAK;;AACtC,UAAI,qBAAqB;AACrB,UAAA;AACH,6BAAqB,UAAY,EAAA;AAAA,MAAA,QAC1B;AAMP;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAA;AACA,UAAA;AACH,kBAAS,aAAU,EAAA,IAAIA,OAAsB,MAApC,mBAAuC;AAAA,MAAA,QACzC;AAMP;AAAA,MACA;AAgBD,UAAI,UAAU,gBAAgB,KAAK,MAAM,GAAG;AACpC,eAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(config?: ExitPreviewConfig): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["draftMode"],"mappings":";;;AA2DM,SAAU,YAAY,QAA0B;AACrD,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGNA,YAAA,UAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
1
+ {"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(): Response;\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void;\nexport function exitPreview(\n\tconfig?: ExitPreviewAPIRouteConfig,\n): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["draftMode"],"mappings":";;;AAiEM,SAAU,YACf,QAAkC;AAElC,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGNA,YAAA,UAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
@@ -1,8 +1,14 @@
1
1
  import { NextApiRequestLike, NextApiResponseLike } from "./types";
2
2
  /**
3
- * Configuration for `exitPreview`.
3
+ * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is
4
+ * used in a Pages Router API endpoint. `exitPreview()` does not require any
5
+ * configuration when used in an App Router Route Handler.
4
6
  */
5
- export type ExitPreviewConfig = {
7
+ export type ExitPreviewConfig = ExitPreviewAPIRouteConfig;
8
+ /**
9
+ * Configuration for `exitPreview()` when used in a Pages Router API route.
10
+ */
11
+ export type ExitPreviewAPIRouteConfig = {
6
12
  /**
7
13
  * **Only use this parameter in the Pages Directory (/pages).**
8
14
  *
@@ -22,21 +28,18 @@ export type ExitPreviewConfig = {
22
28
  };
23
29
  /**
24
30
  * Ends a Prismic preview session within a Next.js app. This function should be
25
- * used in a Router Handler or an API Route, depending on which you are using
31
+ * used in a Router Handler or an API route, depending on whether you are using
26
32
  * the App Router or Pages Router.
27
33
  *
28
- * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API
29
- * Route `res` object is provided to the function.
30
- *
31
34
  * @example Usage within an App Router Route Handler.
32
35
  *
33
36
  * ```typescript
34
- * // src/app/exit-preview/route.js
37
+ * // src/app/api/exit-preview/route.js
35
38
  *
36
39
  * import { exitPreview } from "@prismicio/next";
37
40
  *
38
- * export async function GET() {
39
- * await exitPreview();
41
+ * export function GET() {
42
+ * return exitPreview();
40
43
  * }
41
44
  * ```
42
45
  *
@@ -47,9 +50,10 @@ export type ExitPreviewConfig = {
47
50
  *
48
51
  * import { exitPreview } from "@prismicio/next";
49
52
  *
50
- * export default async function handler(req, res) {
51
- * await exitPreview({ req, res });
53
+ * export default function handler(req, res) {
54
+ * exitPreview({ req, res });
52
55
  * }
53
56
  * ```
54
57
  */
55
- export declare function exitPreview(config?: ExitPreviewConfig): Response | void;
58
+ export declare function exitPreview(): Response;
59
+ export declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(config?: ExitPreviewConfig): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";AA2DM,SAAU,YAAY,QAA0B;AACrD,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGN,cAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
1
+ {"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(): Response;\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void;\nexport function exitPreview(\n\tconfig?: ExitPreviewAPIRouteConfig,\n): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";AAiEM,SAAU,YACf,QAAkC;AAElC,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGN,cAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { setPreviewData } from "./setPreviewData";
2
2
  export type { SetPreviewDataConfig } from "./setPreviewData";
3
3
  export { exitPreview } from "./exitPreview";
4
- export type { ExitPreviewConfig } from "./exitPreview";
4
+ export type { ExitPreviewConfig, ExitPreviewAPIRouteConfig, } from "./exitPreview";
5
5
  export { PrismicPreview } from "./PrismicPreview";
6
6
  export type { PrismicPreviewProps } from "./PrismicPreview";
7
7
  export { PrismicNextLink } from "./PrismicNextLink";
@@ -9,7 +9,7 @@ export type { PrismicNextLinkProps } from "./PrismicNextLink";
9
9
  export { enableAutoPreviews } from "./enableAutoPreviews";
10
10
  export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
11
11
  export { redirectToPreviewURL } from "./redirectToPreviewURL";
12
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
12
+ export type { RedirectToPreviewURLConfig, RedirectToPreviewURLRouteHandlerConfig, RedirectToPreviewURLAPIEndpointConfig, } from "./redirectToPreviewURL";
13
13
  export { PrismicNextImage } from "./PrismicNextImage";
14
14
  export type { PrismicNextImageProps } from "./PrismicNextImage";
15
15
  export { imgixLoader } from "./imgixLoader";
@@ -1 +1 @@
1
- {"version":3,"file":"devMsg.cjs","sources":["../../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":["version"],"mappings":";;;AAiBa,MAAA,SAAS,CAAC,SAAgB;AACtC,SAAO,iCAAiCA,SAAAA,WAAW;AACpD;;"}
1
+ {"version":3,"file":"devMsg.cjs","sources":["../../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":["version"],"mappings":";;;AAiBa,MAAA,SAAS,CAAC,SAAgB;AAC/B,SAAA,iCAAiCA,SAAAA,OAAO,IAAI,IAAI;AACxD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"devMsg.js","sources":["../../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":[],"mappings":";AAiBa,MAAA,SAAS,CAAC,SAAgB;AACtC,SAAO,iCAAiC,WAAW;AACpD;"}
1
+ {"version":3,"file":"devMsg.js","sources":["../../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":[],"mappings":";AAiBa,MAAA,SAAS,CAAC,SAAgB;AAC/B,SAAA,iCAAiC,OAAO,IAAI,IAAI;AACxD;"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const getPreviewCookieRepositoryName = (previewCookie) => {
4
- return (decodeURIComponent(previewCookie).match(/,"(.+).prismic.io"/) || [])[1];
4
+ return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) || [])[1];
5
5
  };
6
6
  exports.getPreviewCookieRepositoryName = getPreviewCookieRepositoryName;
7
7
  //# sourceMappingURL=getPreviewCookieRepositoryName.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewCookieRepositoryName.cjs","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/,\"(.+).prismic.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":";;AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,oBAAoB,KACnE,CAAA,GAAI,CAAC;AACP;;"}
1
+ {"version":3,"file":"getPreviewCookieRepositoryName.cjs","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":";;AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,wBAAwB,KACvE,CAAA,GAAI,CAAC;AACP;;"}
@@ -1,5 +1,5 @@
1
1
  const getPreviewCookieRepositoryName = (previewCookie) => {
2
- return (decodeURIComponent(previewCookie).match(/,"(.+).prismic.io"/) || [])[1];
2
+ return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) || [])[1];
3
3
  };
4
4
  export {
5
5
  getPreviewCookieRepositoryName
@@ -1 +1 @@
1
- {"version":3,"file":"getPreviewCookieRepositoryName.js","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/,\"(.+).prismic.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":"AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,oBAAoB,KACnE,CAAA,GAAI,CAAC;AACP;"}
1
+ {"version":3,"file":"getPreviewCookieRepositoryName.js","sources":["../../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":"AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACf,UAAA,mBAAmB,aAAa,EAAE,MAAM,wBAAwB,KACvE,CAAA,GAAI,CAAC;AACP;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const version = "1.3.4";
3
+ const version = "1.3.6";
4
4
  exports.version = version;
5
5
  //# sourceMappingURL=package.json.cjs.map
@@ -1,4 +1,4 @@
1
- const version = "1.3.4";
1
+ const version = "1.3.6";
2
2
  export {
3
3
  version
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig = (\n\t| {\n\t\t\t/**\n\t\t\t * The `request` object from a Next.js Route Handler.\n\t\t\t *\n\t\t\t * @see Next.js Route Handler docs: \\<https://beta.nextjs.org/docs/routing/route-handlers\\>\n\t\t\t */\n\t\t\trequest: NextRequestLike;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * The `req` object from a Next.js API route.\n\t\t\t *\n\t\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t\t\t */\n\t\t\treq: NextApiRequestLike;\n\n\t\t\t/**\n\t\t\t * The `res` object from a Next.js API route.\n\t\t\t *\n\t\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t\t\t */\n\t\t\tres: NextApiResponseLike;\n\t }\n) & {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a visitor to the URL of a previewed Prismic document from within a\n * Next.js Route Handler or API route.\n */\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\tdraftMode().enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\tcookies().set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["draftMode","cookies","prismic.cookie.preview","redirect"],"mappings":";;;;;AAiFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACzBA,YAAA,UAAA,EAAY;AAOZ,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClBC,cAAAA,UAAU,IAAIC,gBAAwB,aAAa;AAAA,IACnD;AAEDC,wBAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;;"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\tdraftMode().enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\tcookies().set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["draftMode","cookies","prismic.cookie.preview","redirect"],"mappings":";;;;;AAuFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACzBA,YAAA,UAAA,EAAY;AAOZ,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClBC,cAAAA,UAAU,IAAIC,gBAAwB,aAAa;AAAA,IACnD;AAEDC,wBAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;;"}
@@ -1,29 +1,6 @@
1
1
  import * as prismic from "@prismicio/client";
2
2
  import { NextApiRequestLike, NextApiResponseLike, NextRequestLike } from "./types";
3
- /**
4
- * Preview config for enabling previews with redirectToPreviewURL
5
- */
6
- export type RedirectToPreviewURLConfig = ({
7
- /**
8
- * The `request` object from a Next.js Route Handler.
9
- *
10
- * @see Next.js Route Handler docs: \<https://beta.nextjs.org/docs/routing/route-handlers\>
11
- */
12
- request: NextRequestLike;
13
- } | {
14
- /**
15
- * The `req` object from a Next.js API route.
16
- *
17
- * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
18
- */
19
- req: NextApiRequestLike;
20
- /**
21
- * The `res` object from a Next.js API route.
22
- *
23
- * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
24
- */
25
- res: NextApiResponseLike;
26
- }) & {
3
+ type RedirectToPreviewURLConfigBase = {
27
4
  /**
28
5
  * The Prismic client configured for the preview session's repository.
29
6
  */
@@ -53,8 +30,29 @@ export type RedirectToPreviewURLConfig = ({
53
30
  */
54
31
  basePath?: string;
55
32
  };
56
- /**
57
- * Redirects a visitor to the URL of a previewed Prismic document from within a
58
- * Next.js Route Handler or API route.
59
- */
60
- export declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void>;
33
+ export type RedirectToPreviewURLRouteHandlerConfig = RedirectToPreviewURLConfigBase & {
34
+ /**
35
+ * The `request` object from a Next.js Route Handler.
36
+ *
37
+ * @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
38
+ */
39
+ request: NextRequestLike;
40
+ };
41
+ export type RedirectToPreviewURLAPIEndpointConfig = RedirectToPreviewURLConfigBase & {
42
+ /**
43
+ * The `req` object from a Next.js API route.
44
+ *
45
+ * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
46
+ */
47
+ req: NextApiRequestLike;
48
+ /**
49
+ * The `res` object from a Next.js API route.
50
+ *
51
+ * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
52
+ */
53
+ res: NextApiResponseLike;
54
+ };
55
+ export type RedirectToPreviewURLConfig = RedirectToPreviewURLRouteHandlerConfig | RedirectToPreviewURLAPIEndpointConfig;
56
+ export declare function redirectToPreviewURL(config: RedirectToPreviewURLRouteHandlerConfig): Promise<never>;
57
+ export declare function redirectToPreviewURL(config: RedirectToPreviewURLAPIEndpointConfig): Promise<void>;
58
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig = (\n\t| {\n\t\t\t/**\n\t\t\t * The `request` object from a Next.js Route Handler.\n\t\t\t *\n\t\t\t * @see Next.js Route Handler docs: \\<https://beta.nextjs.org/docs/routing/route-handlers\\>\n\t\t\t */\n\t\t\trequest: NextRequestLike;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * The `req` object from a Next.js API route.\n\t\t\t *\n\t\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t\t\t */\n\t\t\treq: NextApiRequestLike;\n\n\t\t\t/**\n\t\t\t * The `res` object from a Next.js API route.\n\t\t\t *\n\t\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t\t\t */\n\t\t\tres: NextApiResponseLike;\n\t }\n) & {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a visitor to the URL of a previewed Prismic document from within a\n * Next.js Route Handler or API route.\n */\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\tdraftMode().enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\tcookies().set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";;;AAiFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACzB,cAAA,EAAY;AAOZ,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClB,gBAAU,IAAIA,SAAwB,aAAa;AAAA,IACnD;AAED,aAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\tdraftMode().enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\tcookies().set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";;;AAuFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACzB,cAAA,EAAY;AAOZ,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClB,gBAAU,IAAIA,SAAwB,aAAa;AAAA,IACnD;AAED,aAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -55,36 +55,36 @@
55
55
  "imgix-url-builder": "^0.0.4"
56
56
  },
57
57
  "devDependencies": {
58
- "@prismicio/client": "^7.1.0",
59
- "@prismicio/mock": "^0.3.0",
60
- "@size-limit/preset-small-lib": "^8.2.4",
61
- "@types/react-test-renderer": "^18.0.0",
62
- "@typescript-eslint/eslint-plugin": "^5.59.11",
63
- "@typescript-eslint/parser": "^5.59.11",
64
- "@vitejs/plugin-react": "^4.0.0",
65
- "@vitest/coverage-v8": "^0.32.0",
66
- "eslint": "^8.42.0",
67
- "eslint-config-prettier": "^8.8.0",
68
- "eslint-plugin-prettier": "^4.2.1",
69
- "eslint-plugin-react": "^7.32.2",
58
+ "@prismicio/client": "^7.2.0",
59
+ "@prismicio/mock": "^0.3.1",
60
+ "@size-limit/preset-small-lib": "^9.0.0",
61
+ "@types/react-test-renderer": "^18.0.2",
62
+ "@typescript-eslint/eslint-plugin": "^6.7.2",
63
+ "@typescript-eslint/parser": "^6.7.2",
64
+ "@vitejs/plugin-react": "^4.0.4",
65
+ "@vitest/coverage-v8": "^0.34.5",
66
+ "eslint": "^8.49.0",
67
+ "eslint-config-prettier": "^9.0.0",
68
+ "eslint-plugin-prettier": "^5.0.0",
69
+ "eslint-plugin-react": "^7.33.2",
70
70
  "eslint-plugin-react-hooks": "^4.6.0",
71
71
  "eslint-plugin-tsdoc": "^0.2.17",
72
- "happy-dom": "^9.20.3",
73
- "memfs": "^3.5.3",
74
- "next": "^13.4.5-canary.9",
75
- "node-fetch": "^3.3.1",
76
- "prettier": "^2.8.8",
77
- "prettier-plugin-jsdoc": "^0.4.2",
72
+ "happy-dom": "^12.1.6",
73
+ "memfs": "^4.4.0",
74
+ "next": "^13.5.2",
75
+ "node-fetch": "^3.3.2",
76
+ "prettier": "^3.0.3",
77
+ "prettier-plugin-jsdoc": "^1.0.2",
78
78
  "react": "^18.1.0",
79
79
  "react-dom": "^18.2.0",
80
80
  "react-test-renderer": "^18.2.0",
81
81
  "rollup-plugin-preserve-directives": "^0.2.0",
82
- "size-limit": "^8.2.4",
82
+ "size-limit": "^9.0.0",
83
83
  "standard-version": "^9.5.0",
84
- "typescript": "^5.1.3",
85
- "vite": "^4.3.9",
84
+ "typescript": "^5.2.2",
85
+ "vite": "^4.4.9",
86
86
  "vite-plugin-sdk": "^0.1.1",
87
- "vitest": "^0.32.0"
87
+ "vitest": "^0.34.5"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "@prismicio/client": "^6 || ^7",
@@ -72,6 +72,7 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
72
72
  *
73
73
  * @returns A responsive image component using `next/image` for the given Image
74
74
  * field.
75
+ *
75
76
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
76
77
  */
77
78
  export const PrismicNextImage = ({
@@ -3,9 +3,16 @@ import { draftMode } from "next/headers";
3
3
  import { NextApiRequestLike, NextApiResponseLike } from "./types";
4
4
 
5
5
  /**
6
- * Configuration for `exitPreview`.
6
+ * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is
7
+ * used in a Pages Router API endpoint. `exitPreview()` does not require any
8
+ * configuration when used in an App Router Route Handler.
7
9
  */
8
- export type ExitPreviewConfig = {
10
+ export type ExitPreviewConfig = ExitPreviewAPIRouteConfig;
11
+
12
+ /**
13
+ * Configuration for `exitPreview()` when used in a Pages Router API route.
14
+ */
15
+ export type ExitPreviewAPIRouteConfig = {
9
16
  /**
10
17
  * **Only use this parameter in the Pages Directory (/pages).**
11
18
  *
@@ -27,21 +34,18 @@ export type ExitPreviewConfig = {
27
34
 
28
35
  /**
29
36
  * Ends a Prismic preview session within a Next.js app. This function should be
30
- * used in a Router Handler or an API Route, depending on which you are using
37
+ * used in a Router Handler or an API route, depending on whether you are using
31
38
  * the App Router or Pages Router.
32
39
  *
33
- * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API
34
- * Route `res` object is provided to the function.
35
- *
36
40
  * @example Usage within an App Router Route Handler.
37
41
  *
38
42
  * ```typescript
39
- * // src/app/exit-preview/route.js
43
+ * // src/app/api/exit-preview/route.js
40
44
  *
41
45
  * import { exitPreview } from "@prismicio/next";
42
46
  *
43
- * export async function GET() {
44
- * await exitPreview();
47
+ * export function GET() {
48
+ * return exitPreview();
45
49
  * }
46
50
  * ```
47
51
  *
@@ -52,12 +56,16 @@ export type ExitPreviewConfig = {
52
56
  *
53
57
  * import { exitPreview } from "@prismicio/next";
54
58
  *
55
- * export default async function handler(req, res) {
56
- * await exitPreview({ req, res });
59
+ * export default function handler(req, res) {
60
+ * exitPreview({ req, res });
57
61
  * }
58
62
  * ```
59
63
  */
60
- export function exitPreview(config?: ExitPreviewConfig): Response | void {
64
+ export function exitPreview(): Response;
65
+ export function exitPreview(config: ExitPreviewAPIRouteConfig): void;
66
+ export function exitPreview(
67
+ config?: ExitPreviewAPIRouteConfig,
68
+ ): Response | void {
61
69
  if (config?.res) {
62
70
  // Assume Preview Mode is being used.
63
71
 
package/src/index.ts CHANGED
@@ -2,7 +2,10 @@ export { setPreviewData } from "./setPreviewData";
2
2
  export type { SetPreviewDataConfig } from "./setPreviewData";
3
3
 
4
4
  export { exitPreview } from "./exitPreview";
5
- export type { ExitPreviewConfig } from "./exitPreview";
5
+ export type {
6
+ ExitPreviewConfig,
7
+ ExitPreviewAPIRouteConfig,
8
+ } from "./exitPreview";
6
9
 
7
10
  export { PrismicPreview } from "./PrismicPreview";
8
11
  export type { PrismicPreviewProps } from "./PrismicPreview";
@@ -14,7 +17,11 @@ export { enableAutoPreviews } from "./enableAutoPreviews";
14
17
  export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
15
18
 
16
19
  export { redirectToPreviewURL } from "./redirectToPreviewURL";
17
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
20
+ export type {
21
+ RedirectToPreviewURLConfig,
22
+ RedirectToPreviewURLRouteHandlerConfig,
23
+ RedirectToPreviewURLAPIEndpointConfig,
24
+ } from "./redirectToPreviewURL";
18
25
 
19
26
  export { PrismicNextImage } from "./PrismicNextImage";
20
27
  export type { PrismicNextImageProps } from "./PrismicNextImage";
@@ -9,6 +9,6 @@
9
9
  export const getPreviewCookieRepositoryName = (
10
10
  previewCookie: string,
11
11
  ): string | undefined => {
12
- return (decodeURIComponent(previewCookie).match(/,"(.+).prismic.io"/) ||
12
+ return (decodeURIComponent(previewCookie).match(/"([^"]+)\.prismic\.io"/) ||
13
13
  [])[1];
14
14
  };
@@ -8,34 +8,7 @@ import {
8
8
  NextRequestLike,
9
9
  } from "./types";
10
10
 
11
- /**
12
- * Preview config for enabling previews with redirectToPreviewURL
13
- */
14
- export type RedirectToPreviewURLConfig = (
15
- | {
16
- /**
17
- * The `request` object from a Next.js Route Handler.
18
- *
19
- * @see Next.js Route Handler docs: \<https://beta.nextjs.org/docs/routing/route-handlers\>
20
- */
21
- request: NextRequestLike;
22
- }
23
- | {
24
- /**
25
- * The `req` object from a Next.js API route.
26
- *
27
- * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
28
- */
29
- req: NextApiRequestLike;
30
-
31
- /**
32
- * The `res` object from a Next.js API route.
33
- *
34
- * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
35
- */
36
- res: NextApiResponseLike;
37
- }
38
- ) & {
11
+ type RedirectToPreviewURLConfigBase = {
39
12
  /**
40
13
  * The Prismic client configured for the preview session's repository.
41
14
  */
@@ -75,13 +48,46 @@ export type RedirectToPreviewURLConfig = (
75
48
  basePath?: string;
76
49
  };
77
50
 
78
- /**
79
- * Redirects a visitor to the URL of a previewed Prismic document from within a
80
- * Next.js Route Handler or API route.
81
- */
51
+ export type RedirectToPreviewURLRouteHandlerConfig =
52
+ RedirectToPreviewURLConfigBase & {
53
+ /**
54
+ * The `request` object from a Next.js Route Handler.
55
+ *
56
+ * @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
57
+ */
58
+ request: NextRequestLike;
59
+ };
60
+
61
+ export type RedirectToPreviewURLAPIEndpointConfig =
62
+ RedirectToPreviewURLConfigBase & {
63
+ /**
64
+ * The `req` object from a Next.js API route.
65
+ *
66
+ * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
67
+ */
68
+ req: NextApiRequestLike;
69
+
70
+ /**
71
+ * The `res` object from a Next.js API route.
72
+ *
73
+ * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
74
+ */
75
+ res: NextApiResponseLike;
76
+ };
77
+
78
+ export type RedirectToPreviewURLConfig =
79
+ | RedirectToPreviewURLRouteHandlerConfig
80
+ | RedirectToPreviewURLAPIEndpointConfig;
81
+
82
+ export async function redirectToPreviewURL(
83
+ config: RedirectToPreviewURLRouteHandlerConfig,
84
+ ): Promise<never>;
85
+ export async function redirectToPreviewURL(
86
+ config: RedirectToPreviewURLAPIEndpointConfig,
87
+ ): Promise<void>;
82
88
  export async function redirectToPreviewURL(
83
89
  config: RedirectToPreviewURLConfig,
84
- ): Promise<void> {
90
+ ): Promise<never | void> {
85
91
  const basePath = config.basePath || "";
86
92
  const request = "request" in config ? config.request : config.req;
87
93