@prismicio/next 1.0.1 → 1.0.3
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 -17
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.ts +1 -1
- package/dist/PrismicNextImage.js +5 -17
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicPreview.cjs +10 -14
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.ts +1 -1
- package/dist/PrismicPreview.js +10 -14
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.ts +1 -1
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.ts +1 -1
- package/dist/exitPreview.js.map +1 -1
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/imgixLoader.js.map +1 -1
- package/dist/lib/__PRODUCTION__.cjs.map +1 -1
- package/dist/lib/__PRODUCTION__.js.map +1 -1
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.cjs.map +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.js.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/setPreviewData.cjs.map +1 -1
- package/dist/setPreviewData.d.ts +1 -1
- package/dist/setPreviewData.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +16 -16
- package/src/PrismicNextImage.tsx +1 -1
- package/src/PrismicPreview.tsx +6 -1
|
@@ -36,17 +36,7 @@ const castInt = (input) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
const PrismicNextImage = ({
|
|
40
|
-
field,
|
|
41
|
-
imgixParams = {},
|
|
42
|
-
alt,
|
|
43
|
-
fallbackAlt,
|
|
44
|
-
fill,
|
|
45
|
-
width,
|
|
46
|
-
height,
|
|
47
|
-
fallback = null,
|
|
48
|
-
...restProps
|
|
49
|
-
}) => {
|
|
39
|
+
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, ...restProps }) => {
|
|
50
40
|
if (!__PRODUCTION__.__PRODUCTION__) {
|
|
51
41
|
if (typeof alt === "string" && alt !== "") {
|
|
52
42
|
console.warn(`[PrismicNextImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg.devMsg("alt-must-be-an-empty-string")}`);
|
|
@@ -60,8 +50,8 @@ const PrismicNextImage = ({
|
|
|
60
50
|
const ar = field.dimensions.width / field.dimensions.height;
|
|
61
51
|
const castedWidth = castInt(width);
|
|
62
52
|
const castedHeight = castInt(height);
|
|
63
|
-
let resolvedWidth = castedWidth
|
|
64
|
-
let resolvedHeight = castedHeight
|
|
53
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
54
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
65
55
|
if (castedWidth != null && castedHeight == null) {
|
|
66
56
|
resolvedHeight = castedWidth / ar;
|
|
67
57
|
} else if (castedWidth == null && castedHeight != null) {
|
|
@@ -71,15 +61,13 @@ const PrismicNextImage = ({
|
|
|
71
61
|
src,
|
|
72
62
|
width: fill ? void 0 : resolvedWidth,
|
|
73
63
|
height: fill ? void 0 : resolvedHeight,
|
|
74
|
-
alt: alt
|
|
64
|
+
alt: alt ?? (field.alt || fallbackAlt),
|
|
75
65
|
fill,
|
|
76
66
|
loader: imgixLoader.imgixLoader,
|
|
77
67
|
...restProps
|
|
78
68
|
});
|
|
79
69
|
} else {
|
|
80
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
81
|
-
children: fallback
|
|
82
|
-
});
|
|
70
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback });
|
|
83
71
|
}
|
|
84
72
|
};
|
|
85
73
|
exports.PrismicNextImage = PrismicNextImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.cjs","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\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: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\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 (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\n\t\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\treturn (\n\t\t\t<Image\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\t// A non-null assertion is required since we\n\t\t\t\t// can't statically know if an alt attribute is\n\t\t\t\t// available.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\talt={(alt ?? (field.alt || fallbackAlt))!}\n\t\t\t\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":["__PRODUCTION__","devMsg","prismicH","buildURL","_jsx","imgixLoader","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,UAAU,CAAC,UAA0D;AAC1E,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,WAAA;AAAA,EAAA,OACD;AACA,UAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,QAAA,OAAO,MAAM,MAAM,GAAG;AAClB,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IACP;AAAA,EACD;AACF;AAsDO,MAAM,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,MACA,OACA,QACA,WAAW,SACR,gBACqC;AACxC,MAAI,CAACA,eAAAA,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQC,OACxQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAySA,OACxS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,oBAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAMC,gBAAA,SAAS,MAAM,KAAK,WAAW;AAE3C,UAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,UAAA,cAAc,QAAQ,KAAK;AAC3B,UAAA,eAAe,QAAQ,MAAM;AAE/B,QAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,QAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,QAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,uBAAiB,cAAc;AAAA,IACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,sBAAgB,eAAe;AAAA,IAC/B;AAED,WACCC,WAAAA,IAAC,OAAK;AAAA,MACL;AAAA,MACA,OAAO,OAAO,SAAY;AAAA,MAC1B,QAAQ,OAAO,SAAY;AAAA,MAK3B,KAAM,QAAQ,MAAM,OAAO;AAAA,MAC3B;AAAA,MACA,QAAQC,YAAA;AAAA,MACJ,GAAA;AAAA,IAAA,CACH;AAAA,EAAA,OAEG;AACN,WAAOD,WAAA,IAAAE,WAAA,UAAA,EAAA,UAAG,SAAQ,CAAA;AAAA,EAClB;AACF;;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ImageProps } from "next/image";
|
|
3
3
|
import { ImgixURLParams } from "imgix-url-builder";
|
|
4
4
|
import * as prismicT from "@prismicio/types";
|
|
5
|
-
export
|
|
5
|
+
export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
|
|
6
6
|
/**
|
|
7
7
|
* The Prismic Image field or thumbnail to render.
|
|
8
8
|
*/
|
package/dist/PrismicNextImage.js
CHANGED
|
@@ -17,17 +17,7 @@ const castInt = (input) => {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
const PrismicNextImage = ({
|
|
21
|
-
field,
|
|
22
|
-
imgixParams = {},
|
|
23
|
-
alt,
|
|
24
|
-
fallbackAlt,
|
|
25
|
-
fill,
|
|
26
|
-
width,
|
|
27
|
-
height,
|
|
28
|
-
fallback = null,
|
|
29
|
-
...restProps
|
|
30
|
-
}) => {
|
|
20
|
+
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, ...restProps }) => {
|
|
31
21
|
if (!__PRODUCTION__) {
|
|
32
22
|
if (typeof alt === "string" && alt !== "") {
|
|
33
23
|
console.warn(`[PrismicNextImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
|
|
@@ -41,8 +31,8 @@ const PrismicNextImage = ({
|
|
|
41
31
|
const ar = field.dimensions.width / field.dimensions.height;
|
|
42
32
|
const castedWidth = castInt(width);
|
|
43
33
|
const castedHeight = castInt(height);
|
|
44
|
-
let resolvedWidth = castedWidth
|
|
45
|
-
let resolvedHeight = castedHeight
|
|
34
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
35
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
46
36
|
if (castedWidth != null && castedHeight == null) {
|
|
47
37
|
resolvedHeight = castedWidth / ar;
|
|
48
38
|
} else if (castedWidth == null && castedHeight != null) {
|
|
@@ -52,15 +42,13 @@ const PrismicNextImage = ({
|
|
|
52
42
|
src,
|
|
53
43
|
width: fill ? void 0 : resolvedWidth,
|
|
54
44
|
height: fill ? void 0 : resolvedHeight,
|
|
55
|
-
alt: alt
|
|
45
|
+
alt: alt ?? (field.alt || fallbackAlt),
|
|
56
46
|
fill,
|
|
57
47
|
loader: imgixLoader,
|
|
58
48
|
...restProps
|
|
59
49
|
});
|
|
60
50
|
} else {
|
|
61
|
-
return jsx(Fragment, {
|
|
62
|
-
children: fallback
|
|
63
|
-
});
|
|
51
|
+
return jsx(Fragment, { children: fallback });
|
|
64
52
|
}
|
|
65
53
|
};
|
|
66
54
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.js","sources":["../../src/PrismicNextImage.tsx"],"sourcesContent":["import Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\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: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\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 (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\n\t\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\treturn (\n\t\t\t<Image\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\t// A non-null assertion is required since we\n\t\t\t\t// can't statically know if an alt attribute is\n\t\t\t\t// available.\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\talt={(alt ?? (field.alt || fallbackAlt))!}\n\t\t\t\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":["_jsx","_Fragment"],"mappings":";;;;;;;AAUA,MAAM,UAAU,CAAC,UAA0D;AAC1E,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,WAAA;AAAA,EAAA,OACD;AACA,UAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,QAAA,OAAO,MAAM,MAAM,GAAG;AAClB,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IACP;AAAA,EACD;AACF;AAsDO,MAAM,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,MACA,OACA,QACA,WAAW,SACR,gBACqC;AACxC,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQ,OACxQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAyS,OACxS,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAI,SAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAM,SAAS,MAAM,KAAK,WAAW;AAE3C,UAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,UAAA,cAAc,QAAQ,KAAK;AAC3B,UAAA,eAAe,QAAQ,MAAM;AAE/B,QAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,QAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,QAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,uBAAiB,cAAc;AAAA,IACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,sBAAgB,eAAe;AAAA,IAC/B;AAED,WACCA,IAAC,OAAK;AAAA,MACL;AAAA,MACA,OAAO,OAAO,SAAY;AAAA,MAC1B,QAAQ,OAAO,SAAY;AAAA,MAK3B,KAAM,QAAQ,MAAM,OAAO;AAAA,MAC3B;AAAA,MACA,QAAQ;AAAA,MACJ,GAAA;AAAA,IAAA,CACH;AAAA,EAAA,OAEG;AACN,WAAOA,IAAAC,UAAA,EAAA,UAAG,SAAQ,CAAA;AAAA,EAClB;AACF;"}
|
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -23,19 +23,14 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
|
-
function PrismicPreview({
|
|
27
|
-
repositoryName,
|
|
28
|
-
children,
|
|
29
|
-
updatePreviewURL = "/api/preview",
|
|
30
|
-
exitPreviewURL = "/api/exit-preview"
|
|
31
|
-
}) {
|
|
26
|
+
function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
|
|
32
27
|
const router$1 = router.useRouter();
|
|
33
28
|
const resolvedUpdatePreviewURL = router$1.basePath + updatePreviewURL;
|
|
34
29
|
const resolvedExitPreviewURL = router$1.basePath + exitPreviewURL;
|
|
35
30
|
React__namespace.useEffect(() => {
|
|
36
31
|
const startPreviewMode = async () => {
|
|
37
32
|
const res = await globalThis.fetch(resolvedUpdatePreviewURL);
|
|
38
|
-
if (res.
|
|
33
|
+
if (res.redirected) {
|
|
39
34
|
globalThis.location.reload();
|
|
40
35
|
} else {
|
|
41
36
|
console.error(`[<PrismicPreview>] Failed to start or update Preview Mode using the "${resolvedUpdatePreviewURL}" API endpoint. Does it exist?`);
|
|
@@ -71,13 +66,14 @@ function PrismicPreview({
|
|
|
71
66
|
window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
72
67
|
window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
73
68
|
};
|
|
74
|
-
}, [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
}, [
|
|
70
|
+
repositoryName,
|
|
71
|
+
resolvedExitPreviewURL,
|
|
72
|
+
resolvedUpdatePreviewURL,
|
|
73
|
+
router$1.isPreview,
|
|
74
|
+
router$1.basePath
|
|
75
|
+
]);
|
|
76
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(Script, { src: `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}&new=true`, strategy: "lazyOnload" })] });
|
|
81
77
|
}
|
|
82
78
|
exports.PrismicPreview = PrismicPreview;
|
|
83
79
|
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useRouter } from \"next/router\";\nimport Script from \"next/script\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\t// We check for `res.redirected` rather than `res.ok`\n\t\t\t// since the update preview endpoint may redirect to a\n\t\t\t// 404 page. As long as it redirects, we know the\n\t\t\t// endpoint exists and at least attempted to set\n\t\t\t// preview data.\n\t\t\tif (res.redirected) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script\n\t\t\t\tsrc={`https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}&new=true`}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"names":["router","useRouter","React","getPrismicPreviewCookie","getPreviewCookieRepositoryName","_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAMA,WAASC,OAAAA;AAET,QAAA,2BAA2BD,SAAO,WAAW;AAC7C,QAAA,yBAAyBA,SAAO,WAAW;AAEjDE,mBAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAO3D,UAAI,IAAI,YAAY;AACnB,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAIF,SAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuBG,wBAAA,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAASH,SAAO,QAAQ;AAGnC,cAAA,qCACLI,8DAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACAJ,SAAO;AAAA,IACPA,SAAO;AAAA,EAAA,CACP;AAED,SACCK,WAAAA,KACEC,WAAAA,UAAA,EAAA,UAAA,CAAA,UACDC,WAAAA,IAAC,UACA,KAAK,iDAAiD,2BACtD,UAAS,aACR,CAAA,CAAA,GAAA;AAGL;;"}
|
package/dist/PrismicPreview.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* Props for `<PrismicPreview>`.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type PrismicPreviewProps = {
|
|
6
6
|
/**
|
|
7
7
|
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
8
8
|
* using this repository.
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -4,19 +4,14 @@ import { useRouter } from "next/router";
|
|
|
4
4
|
import Script from "next/script";
|
|
5
5
|
import { getPrismicPreviewCookie } from "./lib/getPrismicPreviewCookie.js";
|
|
6
6
|
import { getPreviewCookieRepositoryName } from "./lib/getPreviewCookieRepositoryName.js";
|
|
7
|
-
function PrismicPreview({
|
|
8
|
-
repositoryName,
|
|
9
|
-
children,
|
|
10
|
-
updatePreviewURL = "/api/preview",
|
|
11
|
-
exitPreviewURL = "/api/exit-preview"
|
|
12
|
-
}) {
|
|
7
|
+
function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
|
|
13
8
|
const router = useRouter();
|
|
14
9
|
const resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;
|
|
15
10
|
const resolvedExitPreviewURL = router.basePath + exitPreviewURL;
|
|
16
11
|
React.useEffect(() => {
|
|
17
12
|
const startPreviewMode = async () => {
|
|
18
13
|
const res = await globalThis.fetch(resolvedUpdatePreviewURL);
|
|
19
|
-
if (res.
|
|
14
|
+
if (res.redirected) {
|
|
20
15
|
globalThis.location.reload();
|
|
21
16
|
} else {
|
|
22
17
|
console.error(`[<PrismicPreview>] Failed to start or update Preview Mode using the "${resolvedUpdatePreviewURL}" API endpoint. Does it exist?`);
|
|
@@ -52,13 +47,14 @@ function PrismicPreview({
|
|
|
52
47
|
window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
53
48
|
window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
54
49
|
};
|
|
55
|
-
}, [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
}, [
|
|
51
|
+
repositoryName,
|
|
52
|
+
resolvedExitPreviewURL,
|
|
53
|
+
resolvedUpdatePreviewURL,
|
|
54
|
+
router.isPreview,
|
|
55
|
+
router.basePath
|
|
56
|
+
]);
|
|
57
|
+
return jsxs(Fragment, { children: [children, jsx(Script, { src: `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}&new=true`, strategy: "lazyOnload" })] });
|
|
62
58
|
}
|
|
63
59
|
export {
|
|
64
60
|
PrismicPreview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { useRouter } from \"next/router\";\nimport Script from \"next/script\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\t// We check for `res.redirected` rather than `res.ok`\n\t\t\t// since the update preview endpoint may redirect to a\n\t\t\t// 404 page. As long as it redirects, we know the\n\t\t\t// endpoint exists and at least attempted to set\n\t\t\t// preview data.\n\t\t\tif (res.redirected) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script\n\t\t\t\tsrc={`https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}&new=true`}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAM,SAAS;AAET,QAAA,2BAA2B,OAAO,WAAW;AAC7C,QAAA,yBAAyB,OAAO,WAAW;AAEjD,QAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAO3D,UAAI,IAAI,YAAY;AACnB,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAI,OAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuB,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAAS,OAAO,QAAQ;AAGnC,cAAA,qCACL,+BAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EAAA,CACP;AAED,SACCA,KACEC,UAAA,EAAA,UAAA,CAAA,UACDC,IAAC,UACA,KAAK,iDAAiD,2BACtD,UAAS,aACR,CAAA,CAAA,GAAA;AAGL;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { Client, HttpRequestLike } from \"@prismicio/client\";\n\ninterface PrismicNextPreviewData {\n\tref: string;\n}\n\n/**\n * Determines if a Next.js preview data object contains Prismic preview data.\n *\n * @param previewData - The Next.js preview data object to check.\n *\n * @returns `true` if `previewData` contains Prismic preview data, `false`\n * otherwise.\n */\nconst isPrismicNextPreviewData = (\n\tpreviewData: PreviewData,\n): previewData is PrismicNextPreviewData => {\n\treturn typeof previewData === \"object\" && \"ref\" in previewData;\n};\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\tclient: Client;\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * A Next.js context object (such as the context object from\n\t\t\t * `getStaticProps` or `getServerSideProps`).\n\t\t\t *\n\t\t\t * Pass a `context` object when using `enableAutoPreviews` outside a\n\t\t\t * Next.js API endpoint.\n\t\t\t */\n\t\t\tpreviewData?: TPreviewData;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * A Next.js API endpoint request object.\n\t\t\t *\n\t\t\t * Pass a `req` object when using `enableAutoPreviews` in a Next.js API\n\t\t\t * endpoint.\n\t\t\t */\n\t\t\treq?: HttpRequestLike;\n\t }\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// If preview data is being passed from Next Context then use queryContentFromRef\n\n\t\tconst { previewData } = config;\n\n\t\tif (isPrismicNextPreviewData(previewData) && previewData.ref) {\n\t\t\tconfig.client.queryContentFromRef(previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// If the req object is passed then use enableAutoPreviewsFromReq\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t}\n};\n"],"names":[],"mappings":";;AAeA,MAAM,2BAA2B,CAChC,gBAC0C;AACnC,SAAA,OAAO,gBAAgB,YAAY,SAAS;AACpD;AA0Ca,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAG5C,UAAA,EAAE,YAAgB,IAAA;AAExB,QAAI,yBAAyB,WAAW,KAAK,YAAY,KAAK;AACtD,aAAA,OAAO,oBAAoB,YAAY,GAAG;AAAA,IACjD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAClD;AACF;;"}
|
|
@@ -5,7 +5,7 @@ import { Client, HttpRequestLike } from "@prismicio/client";
|
|
|
5
5
|
*
|
|
6
6
|
* @typeParam TPreviewData - Next.js preview data object.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type EnableAutoPreviewsConfig<TPreviewData extends PreviewData = PreviewData> = {
|
|
9
9
|
/**
|
|
10
10
|
* Prismic client with which automatic previews will be enabled.
|
|
11
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.js","sources":["
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { PreviewData } from \"next\";\nimport { Client, HttpRequestLike } from \"@prismicio/client\";\n\ninterface PrismicNextPreviewData {\n\tref: string;\n}\n\n/**\n * Determines if a Next.js preview data object contains Prismic preview data.\n *\n * @param previewData - The Next.js preview data object to check.\n *\n * @returns `true` if `previewData` contains Prismic preview data, `false`\n * otherwise.\n */\nconst isPrismicNextPreviewData = (\n\tpreviewData: PreviewData,\n): previewData is PrismicNextPreviewData => {\n\treturn typeof previewData === \"object\" && \"ref\" in previewData;\n};\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\tclient: Client;\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * A Next.js context object (such as the context object from\n\t\t\t * `getStaticProps` or `getServerSideProps`).\n\t\t\t *\n\t\t\t * Pass a `context` object when using `enableAutoPreviews` outside a\n\t\t\t * Next.js API endpoint.\n\t\t\t */\n\t\t\tpreviewData?: TPreviewData;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * A Next.js API endpoint request object.\n\t\t\t *\n\t\t\t * Pass a `req` object when using `enableAutoPreviews` in a Next.js API\n\t\t\t * endpoint.\n\t\t\t */\n\t\t\treq?: HttpRequestLike;\n\t }\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// If preview data is being passed from Next Context then use queryContentFromRef\n\n\t\tconst { previewData } = config;\n\n\t\tif (isPrismicNextPreviewData(previewData) && previewData.ref) {\n\t\t\tconfig.client.queryContentFromRef(previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// If the req object is passed then use enableAutoPreviewsFromReq\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t}\n};\n"],"names":[],"mappings":"AAeA,MAAM,2BAA2B,CAChC,gBAC0C;AACnC,SAAA,OAAO,gBAAgB,YAAY,SAAS;AACpD;AA0Ca,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAG5C,UAAA,EAAE,YAAgB,IAAA;AAExB,QAAI,yBAAyB,WAAW,KAAK,YAAY,KAAK;AACtD,aAAA,OAAO,oBAAoB,YAAY,GAAG;AAAA,IACjD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAClD;AACF;"}
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import type { NextApiResponse, NextApiRequest } from \"next\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\t// `req` is no longer used in `exitPreview()`. It previously would\n\t// redirect the user to the referring URL, but it no longer has that\n\t// behavior.\n\t//\n\t// `req` is retained as a parameter to make setting up an exit preview\n\t// API route easier (this eliminates the awkward need to handle an\n\t// unused `req` param).\n\t//\n\t// It is also retained in case it is needed in the future, such as\n\t// reading headers or metadata about the request.\n\treq: {\n\t\theaders: NextApiRequest[\"headers\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tclearPreviewData: NextApiResponse[\"clearPreviewData\"];\n\t\tstatus: NextApiResponse[\"status\"];\n\t\tjson: NextApiResponse[\"json\"];\n\t};\n};\n\n/**\n * Exits Next.js's Preview Mode from within a Next.js API route.\n */\nexport function exitPreview(config: ExitPreviewConfig): void {\n\t// Exit the current user from Preview Mode.\n\tconfig.res.clearPreviewData();\n\n\t// 205 status is used to prevent CDN-level caching. The default 200\n\t// status code is typically treated as non-changing and cacheable.\n\tconfig.res.status(205).json({ success: true });\n}\n"],"names":[],"mappings":";;AA0CM,SAAU,YAAY,QAAyB;AAEpD,SAAO,IAAI;AAIJ,SAAA,IAAI,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,MAAM;AAC9C;;"}
|
package/dist/exitPreview.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { NextApiResponse, NextApiRequest } from "next";
|
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for `exitPreview`.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type ExitPreviewConfig = {
|
|
6
6
|
/**
|
|
7
7
|
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
8
8
|
* the API route.
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","sources":["
|
|
1
|
+
{"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import type { NextApiResponse, NextApiRequest } from \"next\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\t// `req` is no longer used in `exitPreview()`. It previously would\n\t// redirect the user to the referring URL, but it no longer has that\n\t// behavior.\n\t//\n\t// `req` is retained as a parameter to make setting up an exit preview\n\t// API route easier (this eliminates the awkward need to handle an\n\t// unused `req` param).\n\t//\n\t// It is also retained in case it is needed in the future, such as\n\t// reading headers or metadata about the request.\n\treq: {\n\t\theaders: NextApiRequest[\"headers\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tclearPreviewData: NextApiResponse[\"clearPreviewData\"];\n\t\tstatus: NextApiResponse[\"status\"];\n\t\tjson: NextApiResponse[\"json\"];\n\t};\n};\n\n/**\n * Exits Next.js's Preview Mode from within a Next.js API route.\n */\nexport function exitPreview(config: ExitPreviewConfig): void {\n\t// Exit the current user from Preview Mode.\n\tconfig.res.clearPreviewData();\n\n\t// 205 status is used to prevent CDN-level caching. The default 200\n\t// status code is typically treated as non-changing and cacheable.\n\tconfig.res.status(205).json({ success: true });\n}\n"],"names":[],"mappings":"AA0CM,SAAU,YAAY,QAAyB;AAEpD,SAAO,IAAI;AAIJ,SAAA,IAAI,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,MAAM;AAC9C;"}
|
package/dist/imgixLoader.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imgixLoader.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"imgixLoader.cjs","sources":["../../src/imgixLoader.ts"],"sourcesContent":["import { ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\n\n/**\n * A `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nexport const imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n"],"names":["buildURL"],"mappings":";;;AAUa,MAAA,cAAc,CAAC,SAAkC;AAC7D,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAAA,yBAAS,KAAK,KAAK,MAAM;AACjC;;"}
|
package/dist/imgixLoader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imgixLoader.js","sources":["
|
|
1
|
+
{"version":3,"file":"imgixLoader.js","sources":["../../src/imgixLoader.ts"],"sourcesContent":["import { ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\n\n/**\n * A `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nexport const imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n"],"names":[],"mappings":";AAUa,MAAA,cAAc,CAAC,SAAkC;AAC7D,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAA,SAAS,KAAK,KAAK,MAAM;AACjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__PRODUCTION__.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"__PRODUCTION__.cjs","sources":["../../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":";;AAMa,MAAA,iBAAiB,QAAQ,IAAI,aAAa;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__PRODUCTION__.js","sources":["
|
|
1
|
+
{"version":3,"file":"__PRODUCTION__.js","sources":["../../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":"AAMa,MAAA,iBAAiB,QAAQ,IAAI,aAAa;"}
|
package/dist/lib/devMsg.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.cjs","sources":["
|
|
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;;"}
|
package/dist/lib/devMsg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.js","sources":["
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviewCookieRepositoryName.cjs","sources":["
|
|
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;AACvB,UAAQ,mBAAmB,aAAa,EAAE,MAAM,mBAAmB,KAClE,CAAA,GAAI;AACN;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviewCookieRepositoryName.js","sources":["
|
|
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;AACvB,UAAQ,mBAAmB,aAAa,EAAE,MAAM,mBAAmB,KAClE,CAAA,GAAI;AACN;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrismicPreviewCookie.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"getPrismicPreviewCookie.cjs","sources":["../../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismic.cookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n};\n"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AAC9B,UAAM,OAAO,UAAU,MAAM,EAAE,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASA,mBAAQ,OAAO,SAAS;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrismicPreviewCookie.js","sources":["
|
|
1
|
+
{"version":3,"file":"getPrismicPreviewCookie.js","sources":["../../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismic.cookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n};\n"],"names":[],"mappings":";AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AAC9B,UAAM,OAAO,UAAU,MAAM,EAAE,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAAS,QAAQ,OAAO,SAAS;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\";\nimport type { NextApiRequest, NextApiResponse } from \"next\";\nimport type { LinkResolverFunction } from \"@prismicio/helpers\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction,\n> = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\tclient: Client;\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?: TLinkResolverFunction;\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 API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":";;AAiBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAkEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;;"}
|
|
@@ -4,7 +4,7 @@ import type { LinkResolverFunction } from "@prismicio/helpers";
|
|
|
4
4
|
/**
|
|
5
5
|
* Preview config for enabling previews with redirectToPreviewURL
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
|
|
8
8
|
/**
|
|
9
9
|
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
10
10
|
* the API route.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","sources":["
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\";\nimport type { NextApiRequest, NextApiResponse } from \"next\";\nimport type { LinkResolverFunction } from \"@prismicio/helpers\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction,\n> = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\tclient: Client;\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?: TLinkResolverFunction;\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 API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":"AAiBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAkEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"setPreviewData.cjs","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,mBAAQ,OAAO;AAE1D,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;;"}
|
package/dist/setPreviewData.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { NextApiResponse, NextApiRequest } from "next";
|
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for `setPreviewData`.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type SetPreviewDataConfig = {
|
|
6
6
|
/**
|
|
7
7
|
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
8
8
|
* the API route.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.js","sources":["
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":[],"mappings":";SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,QAAQ,OAAO;AAE1D,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ClientConfig } from "@prismicio/client";
|
|
|
4
4
|
* Configuration for creating a Prismic client with automatic preview support in
|
|
5
5
|
* Next.js apps.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type CreateClientConfig = {
|
|
8
8
|
/**
|
|
9
9
|
* Preview data coming from Next.js context object. This context object comes
|
|
10
10
|
* from `getStaticProps` or `getServerSideProps`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"main": "./dist/index.cjs",
|
|
27
27
|
"module": "./dist/index.js",
|
|
28
|
-
"types": "dist/index.d.ts",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
|
31
31
|
"src"
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"unit:watch": "vitest watch"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@prismicio/helpers": "^2.3.
|
|
50
|
-
"@prismicio/types": "^0.2.
|
|
49
|
+
"@prismicio/helpers": "^2.3.6",
|
|
50
|
+
"@prismicio/types": "^0.2.4",
|
|
51
51
|
"imgix-url-builder": "^0.0.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -55,29 +55,29 @@
|
|
|
55
55
|
"@prismicio/mock": "^0.1.1",
|
|
56
56
|
"@size-limit/preset-small-lib": "^8.1.0",
|
|
57
57
|
"@types/react-test-renderer": "^18.0.0",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"@vitejs/plugin-react": "^
|
|
61
|
-
"@vitest/coverage-c8": "^0.
|
|
62
|
-
"eslint": "^8.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
59
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
60
|
+
"@vitejs/plugin-react": "^3.0.0",
|
|
61
|
+
"@vitest/coverage-c8": "^0.25.8",
|
|
62
|
+
"eslint": "^8.29.0",
|
|
63
63
|
"eslint-config-prettier": "^8.5.0",
|
|
64
64
|
"eslint-plugin-prettier": "^4.2.1",
|
|
65
|
-
"eslint-plugin-react": "^7.31.
|
|
65
|
+
"eslint-plugin-react": "^7.31.11",
|
|
66
66
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
67
67
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
68
|
-
"happy-dom": "^
|
|
68
|
+
"happy-dom": "^8.1.0",
|
|
69
69
|
"next": "^13.0.0",
|
|
70
|
-
"prettier": "^2.
|
|
70
|
+
"prettier": "^2.8.1",
|
|
71
71
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
72
72
|
"react": "^18.1.0",
|
|
73
73
|
"react-dom": "^18.2.0",
|
|
74
74
|
"react-test-renderer": "^18.2.0",
|
|
75
75
|
"size-limit": "^8.1.0",
|
|
76
76
|
"standard-version": "^9.5.0",
|
|
77
|
-
"typescript": "^4.
|
|
78
|
-
"vite": "^
|
|
79
|
-
"vite-plugin-sdk": "^0.0
|
|
80
|
-
"vitest": "^0.
|
|
77
|
+
"typescript": "^4.9.4",
|
|
78
|
+
"vite": "^4.0.1",
|
|
79
|
+
"vite-plugin-sdk": "^0.1.0",
|
|
80
|
+
"vitest": "^0.25.8"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@prismicio/client": "^6",
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -112,7 +112,7 @@ export const PrismicNextImage = ({
|
|
|
112
112
|
const castedHeight = castInt(height);
|
|
113
113
|
|
|
114
114
|
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
115
|
-
let resolvedHeight = castedHeight ?? field.dimensions.
|
|
115
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
116
116
|
|
|
117
117
|
if (castedWidth != null && castedHeight == null) {
|
|
118
118
|
resolvedHeight = castedWidth / ar;
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -68,7 +68,12 @@ export function PrismicPreview({
|
|
|
68
68
|
// Start Next.js Preview Mode via the given preview API endpoint.
|
|
69
69
|
const res = await globalThis.fetch(resolvedUpdatePreviewURL);
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
// We check for `res.redirected` rather than `res.ok`
|
|
72
|
+
// since the update preview endpoint may redirect to a
|
|
73
|
+
// 404 page. As long as it redirects, we know the
|
|
74
|
+
// endpoint exists and at least attempted to set
|
|
75
|
+
// preview data.
|
|
76
|
+
if (res.redirected) {
|
|
72
77
|
globalThis.location.reload();
|
|
73
78
|
} else {
|
|
74
79
|
console.error(
|