@prismicio/next 1.3.2 → 1.3.4
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.
- package/dist/PrismicNextImage.cjs +5 -1
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.js +5 -1
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/redirectToPreviewURL.cjs +7 -0
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/redirectToPreviewURL.js +7 -0
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/package.json +1 -1
- package/src/PrismicNextImage.tsx +9 -1
- package/src/redirectToPreviewURL.ts +14 -1
- package/src/types.ts +5 -1
|
@@ -51,7 +51,11 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, wid
|
|
|
51
51
|
if (process.env.NODE_ENV !== "production" && typeof resolvedAlt !== "string") {
|
|
52
52
|
console.error(`[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=""\`.`, src);
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
let ResolvedImage = Image;
|
|
55
|
+
if ("default" in ResolvedImage) {
|
|
56
|
+
ResolvedImage = ResolvedImage.default;
|
|
57
|
+
}
|
|
58
|
+
return jsxRuntime.jsx(ResolvedImage, { src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader: imgixLoader.imgixLoader, ...restProps });
|
|
55
59
|
} else {
|
|
56
60
|
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback });
|
|
57
61
|
}
|
|
@@ -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\treturn (\n\t\t\t<
|
|
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;;"}
|
package/dist/PrismicNextImage.js
CHANGED
|
@@ -49,7 +49,11 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, wid
|
|
|
49
49
|
if (process.env.NODE_ENV !== "production" && typeof resolvedAlt !== "string") {
|
|
50
50
|
console.error(`[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=""\`.`, src);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
let ResolvedImage = Image;
|
|
53
|
+
if ("default" in ResolvedImage) {
|
|
54
|
+
ResolvedImage = ResolvedImage.default;
|
|
55
|
+
}
|
|
56
|
+
return jsx(ResolvedImage, { src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader: imgixLoader, ...restProps });
|
|
53
57
|
} else {
|
|
54
58
|
return jsx(Fragment, { children: fallback });
|
|
55
59
|
}
|
|
@@ -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\treturn (\n\t\t\t<
|
|
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;;;;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const navigation = require("next/navigation");
|
|
4
|
+
const headers = require("next/headers");
|
|
5
|
+
const cookie = require('./_node_modules/@prismicio/client/dist/cookie.cjs');
|
|
4
6
|
async function redirectToPreviewURL(config) {
|
|
5
7
|
const basePath = config.basePath || "";
|
|
6
8
|
const request = "request" in config ? config.request : config.req;
|
|
@@ -10,6 +12,11 @@ async function redirectToPreviewURL(config) {
|
|
|
10
12
|
defaultURL: config.defaultURL || "/"
|
|
11
13
|
});
|
|
12
14
|
if ("nextUrl" in request) {
|
|
15
|
+
headers.draftMode().enable();
|
|
16
|
+
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
17
|
+
if (previewCookie) {
|
|
18
|
+
headers.cookies().set(cookie.preview, previewCookie);
|
|
19
|
+
}
|
|
13
20
|
navigation.redirect(basePath + previewUrl);
|
|
14
21
|
} else {
|
|
15
22
|
if (!("res" in config)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport
|
|
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,4 +1,6 @@
|
|
|
1
1
|
import { redirect } from "next/navigation";
|
|
2
|
+
import { draftMode, cookies } from "next/headers";
|
|
3
|
+
import { preview } from './_node_modules/@prismicio/client/dist/cookie.js';
|
|
2
4
|
async function redirectToPreviewURL(config) {
|
|
3
5
|
const basePath = config.basePath || "";
|
|
4
6
|
const request = "request" in config ? config.request : config.req;
|
|
@@ -8,6 +10,11 @@ async function redirectToPreviewURL(config) {
|
|
|
8
10
|
defaultURL: config.defaultURL || "/"
|
|
9
11
|
});
|
|
10
12
|
if ("nextUrl" in request) {
|
|
13
|
+
draftMode().enable();
|
|
14
|
+
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
15
|
+
if (previewCookie) {
|
|
16
|
+
cookies().set(preview, previewCookie);
|
|
17
|
+
}
|
|
11
18
|
redirect(basePath + previewUrl);
|
|
12
19
|
} else {
|
|
13
20
|
if (!("res" in config)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport
|
|
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;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -43,7 +43,11 @@ export type NextRequestLike = {
|
|
|
43
43
|
get(name: string): string | null;
|
|
44
44
|
};
|
|
45
45
|
url: string;
|
|
46
|
-
nextUrl:
|
|
46
|
+
nextUrl: {
|
|
47
|
+
searchParams: {
|
|
48
|
+
get(name: string): string | null;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
47
51
|
};
|
|
48
52
|
/**
|
|
49
53
|
* The minimal set of properties needed from `next`'s `NextApiRequest` type.
|
package/package.json
CHANGED
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -142,8 +142,16 @@ export const PrismicNextImage = ({
|
|
|
142
142
|
);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.
|
|
146
|
+
// `next/image` seems to be affected by a default + named export bundling bug.
|
|
147
|
+
let ResolvedImage = Image;
|
|
148
|
+
if ("default" in ResolvedImage) {
|
|
149
|
+
ResolvedImage = (ResolvedImage as unknown as { default: typeof Image })
|
|
150
|
+
.default;
|
|
151
|
+
}
|
|
152
|
+
|
|
145
153
|
return (
|
|
146
|
-
<
|
|
154
|
+
<ResolvedImage
|
|
147
155
|
src={src}
|
|
148
156
|
width={fill ? undefined : resolvedWidth}
|
|
149
157
|
height={fill ? undefined : resolvedHeight}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { redirect } from "next/navigation";
|
|
2
|
-
import
|
|
2
|
+
import { cookies, draftMode } from "next/headers";
|
|
3
|
+
import * as prismic from "@prismicio/client";
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
NextApiRequestLike,
|
|
@@ -92,6 +93,18 @@ export async function redirectToPreviewURL(
|
|
|
92
93
|
});
|
|
93
94
|
|
|
94
95
|
if ("nextUrl" in request) {
|
|
96
|
+
draftMode().enable();
|
|
97
|
+
|
|
98
|
+
// Set the initial preview cookie, if available.
|
|
99
|
+
// Setting the cookie here is necessary to support unpublished
|
|
100
|
+
// previews. Without setting it here, the page will try to
|
|
101
|
+
// render without the preview cookie, leading to a
|
|
102
|
+
// PrismicNotFound error.
|
|
103
|
+
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
104
|
+
if (previewCookie) {
|
|
105
|
+
cookies().set(prismic.cookie.preview, previewCookie);
|
|
106
|
+
}
|
|
107
|
+
|
|
95
108
|
redirect(basePath + previewUrl);
|
|
96
109
|
} else {
|
|
97
110
|
if (!("res" in config)) {
|