@prismicio/next 0.1.5 → 0.1.6-alpha.1
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 +59 -0
- package/dist/{PrismicNextImage.mjs.map → PrismicNextImage.cjs.map} +1 -1
- package/dist/PrismicNextImage.d.ts +48 -0
- package/dist/PrismicNextImage.js +38 -0
- package/dist/PrismicNextImage.js.map +1 -0
- package/dist/PrismicPreview.cjs +81 -0
- package/dist/{PrismicPreview.mjs.map → PrismicPreview.cjs.map} +1 -1
- package/dist/PrismicPreview.d.ts +42 -0
- package/dist/{PrismicPreview.mjs → PrismicPreview.js} +18 -44
- package/dist/PrismicPreview.js.map +1 -0
- package/dist/enableAutoPreviews.cjs +17 -0
- package/dist/{enableAutoPreviews.mjs.map → enableAutoPreviews.cjs.map} +1 -1
- package/dist/enableAutoPreviews.d.ts +38 -0
- package/dist/{enableAutoPreviews.mjs → enableAutoPreviews.js} +4 -3
- package/dist/enableAutoPreviews.js.map +1 -0
- package/dist/exitPreview.cjs +8 -0
- package/dist/{exitPreview.mjs.map → exitPreview.cjs.map} +1 -1
- package/dist/exitPreview.d.ts +34 -0
- package/dist/{exitPreview.mjs → exitPreview.js} +4 -3
- package/dist/exitPreview.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -273
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/__PRODUCTION__.cjs +5 -0
- package/dist/lib/{__PRODUCTION__.mjs.map → __PRODUCTION__.cjs.map} +1 -1
- package/dist/lib/__PRODUCTION__.d.ts +7 -0
- package/dist/lib/__PRODUCTION__.js +5 -0
- package/dist/lib/__PRODUCTION__.js.map +1 -0
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/{devMsg.mjs.map → devMsg.cjs.map} +1 -1
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +8 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/getPreviewCookieRepositoryName.cjs +7 -0
- package/dist/lib/{getPreviewCookieRepositoryName.mjs.map → getPreviewCookieRepositoryName.cjs.map} +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.d.ts +9 -0
- package/dist/lib/{getPreviewCookieRepositoryName.mjs → getPreviewCookieRepositoryName.js} +4 -3
- package/dist/lib/getPreviewCookieRepositoryName.js.map +1 -0
- package/dist/lib/getPrismicPreviewCookie.cjs +40 -0
- package/dist/lib/{getPrismicPreviewCookie.mjs.map → getPrismicPreviewCookie.cjs.map} +1 -1
- package/dist/lib/getPrismicPreviewCookie.d.ts +9 -0
- package/dist/lib/{getPrismicPreviewCookie.mjs → getPrismicPreviewCookie.js} +5 -5
- package/dist/lib/getPrismicPreviewCookie.js.map +1 -0
- package/dist/package.cjs +5 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/dist/redirectToPreviewURL.cjs +22 -0
- package/dist/{redirectToPreviewURL.mjs.map → redirectToPreviewURL.cjs.map} +1 -1
- package/dist/redirectToPreviewURL.d.ts +59 -0
- package/dist/{redirectToPreviewURL.mjs → redirectToPreviewURL.js} +4 -3
- package/dist/redirectToPreviewURL.js.map +1 -0
- package/dist/setPreviewData.cjs +30 -0
- package/dist/{setPreviewData.mjs.map → setPreviewData.cjs.map} +1 -1
- package/dist/setPreviewData.d.ts +29 -0
- package/dist/{setPreviewData.mjs → setPreviewData.js} +5 -5
- package/dist/setPreviewData.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/package.json +17 -15
- package/dist/PrismicNextImage.mjs +0 -61
- package/dist/index.mjs +0 -7
- package/dist/index.mjs.map +0 -1
- package/dist/lib/__PRODUCTION__.mjs +0 -4
- package/dist/lib/devMsg.mjs +0 -8
- package/dist/package.mjs +0 -4
- package/dist/package.mjs.map +0 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const Image = require("next/image");
|
|
5
|
+
const imgixUrlBuilder = require("imgix-url-builder");
|
|
6
|
+
const prismicH = require("@prismicio/helpers");
|
|
7
|
+
const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
|
|
8
|
+
const devMsg = require("./lib/devMsg.cjs");
|
|
9
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule)
|
|
12
|
+
return e;
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== "default") {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
const Image__default = /* @__PURE__ */ _interopDefaultLegacy(Image);
|
|
29
|
+
const prismicH__namespace = /* @__PURE__ */ _interopNamespace(prismicH);
|
|
30
|
+
const imgixLoader = (args) => {
|
|
31
|
+
const url = new URL(args.src);
|
|
32
|
+
const params = {
|
|
33
|
+
fit: url.searchParams.get("fit") || "max",
|
|
34
|
+
w: args.width,
|
|
35
|
+
h: void 0
|
|
36
|
+
};
|
|
37
|
+
if (args.quality) {
|
|
38
|
+
params.q = args.quality;
|
|
39
|
+
}
|
|
40
|
+
return imgixUrlBuilder.buildURL(args.src, params);
|
|
41
|
+
};
|
|
42
|
+
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, ...restProps }) => {
|
|
43
|
+
if (!__PRODUCTION__.__PRODUCTION__) {
|
|
44
|
+
if (typeof alt === "string" && alt !== "") {
|
|
45
|
+
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")}`);
|
|
46
|
+
}
|
|
47
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
48
|
+
console.warn(`[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.devMsg("alt-must-be-an-empty-string")}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (prismicH__namespace.isFilled.imageThumbnail(field)) {
|
|
52
|
+
const src = imgixUrlBuilder.buildURL(field.url, imgixParams);
|
|
53
|
+
return jsxRuntime.jsx(Image__default.default, { src, width: layout === "fill" ? void 0 : field.dimensions.width, height: layout === "fill" ? void 0 : field.dimensions.height, alt: alt != null ? alt : field.alt || fallbackAlt, loader: imgixLoader, layout, ...restProps });
|
|
54
|
+
} else {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.PrismicNextImage = PrismicNextImage;
|
|
59
|
+
//# sourceMappingURL=PrismicNextImage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"width\" | \"height\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n *\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tlayout,\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : field.dimensions.width}\n\t\t\t\theight={layout === \"fill\" ? undefined : field.dimensions.height}\n\t\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\tlayout={layout}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn null;\n\t}\n};\n"],"names":["buildURL","__PRODUCTION__","devMsg","prismicH","_jsx","Image"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,cAAc,CAAC,SAAkC;AACtD,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAAA,yBAAS,KAAK,KAAK,MAAM;AACjC;AAoDa,MAAA,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,WACG,gBACwB;AAC3B,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQC,OACxQ,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAySA,OACxS,OAAA,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAIC,oBAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAMH,gBAAA,SAAS,MAAM,KAAK,WAAW;AAE3C,WACCI,WAAC,IAAAC,eAAA,SAAK,EACL,KACA,OAAO,WAAW,SAAS,SAAY,MAAM,WAAW,OACxD,QAAQ,WAAW,SAAS,SAAY,MAAM,WAAW,QACzD,KAAK,oBAAQ,MAAM,OAAO,aAC1B,QAAQ,aACR,QAAc,GACV,UAAS,CAAA;AAAA,EAAA,OAGT;AACC,WAAA;AAAA,EACP;AACF;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ImageProps } from "next/image";
|
|
3
|
+
import { ImgixURLParams } from "imgix-url-builder";
|
|
4
|
+
import * as prismicT from "@prismicio/types";
|
|
5
|
+
export declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "width" | "height"> & {
|
|
6
|
+
/**
|
|
7
|
+
* The Prismic Image field or thumbnail to render.
|
|
8
|
+
*/
|
|
9
|
+
field: prismicT.ImageFieldImage | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.imgix.com/apis/rendering
|
|
14
|
+
*/
|
|
15
|
+
imgixParams?: ImgixURLParams;
|
|
16
|
+
/**
|
|
17
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
18
|
+
*
|
|
19
|
+
* See:
|
|
20
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
21
|
+
*/
|
|
22
|
+
alt?: "";
|
|
23
|
+
/**
|
|
24
|
+
* Declare an image as decorative only if the Image field does not have
|
|
25
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
26
|
+
*
|
|
27
|
+
* See:
|
|
28
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
|
+
*/
|
|
30
|
+
fallbackAlt?: "";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* React component that renders an image from a Prismic Image field or one of
|
|
34
|
+
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
35
|
+
* attribute using the Image field's `alt` property.
|
|
36
|
+
*
|
|
37
|
+
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
38
|
+
* with the `loader` prop. If you would like to use the Next.js Image
|
|
39
|
+
* Optimization API instead, set `loader={undefined}`.
|
|
40
|
+
*
|
|
41
|
+
* @param props - Props for the component.
|
|
42
|
+
*
|
|
43
|
+
* @returns A responsive image component using `next/image` for the given Image
|
|
44
|
+
* field.
|
|
45
|
+
*
|
|
46
|
+
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
47
|
+
*/
|
|
48
|
+
export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, layout, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import Image from "next/image";
|
|
3
|
+
import { buildURL } from "imgix-url-builder";
|
|
4
|
+
import * as prismicH from "@prismicio/helpers";
|
|
5
|
+
import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
|
|
6
|
+
import { devMsg } from "./lib/devMsg.js";
|
|
7
|
+
const imgixLoader = (args) => {
|
|
8
|
+
const url = new URL(args.src);
|
|
9
|
+
const params = {
|
|
10
|
+
fit: url.searchParams.get("fit") || "max",
|
|
11
|
+
w: args.width,
|
|
12
|
+
h: void 0
|
|
13
|
+
};
|
|
14
|
+
if (args.quality) {
|
|
15
|
+
params.q = args.quality;
|
|
16
|
+
}
|
|
17
|
+
return buildURL(args.src, params);
|
|
18
|
+
};
|
|
19
|
+
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, layout, ...restProps }) => {
|
|
20
|
+
if (!__PRODUCTION__) {
|
|
21
|
+
if (typeof alt === "string" && alt !== "") {
|
|
22
|
+
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")}`);
|
|
23
|
+
}
|
|
24
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
25
|
+
console.warn(`[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("alt-must-be-an-empty-string")}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (prismicH.isFilled.imageThumbnail(field)) {
|
|
29
|
+
const src = buildURL(field.url, imgixParams);
|
|
30
|
+
return jsx(Image, { src, width: layout === "fill" ? void 0 : field.dimensions.width, height: layout === "fill" ? void 0 : field.dimensions.height, alt: alt != null ? alt : field.alt || fallbackAlt, loader: imgixLoader, layout, ...restProps });
|
|
31
|
+
} else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
PrismicNextImage
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=PrismicNextImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.js","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["import * as React from \"react\";\nimport Image, { ImageProps, ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Creates a `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nconst imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"width\" | \"height\"\n> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismicT.ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: ImgixURLParams;\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n *\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tlayout,\n\t...restProps\n}: PrismicNextImageProps) => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (prismicH.isFilled.imageThumbnail(field)) {\n\t\tconst src = buildURL(field.url, imgixParams);\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tsrc={src}\n\t\t\t\twidth={layout === \"fill\" ? undefined : field.dimensions.width}\n\t\t\t\theight={layout === \"fill\" ? undefined : field.dimensions.height}\n\t\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t\tloader={imgixLoader}\n\t\t\t\tlayout={layout}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t} else {\n\t\treturn null;\n\t}\n};\n"],"names":["_jsx"],"mappings":";;;;;;AAgBA,MAAM,cAAc,CAAC,SAAkC;AACtD,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAChB;AAEM,SAAA,SAAS,KAAK,KAAK,MAAM;AACjC;AAoDa,MAAA,mBAAmB,CAAC,EAChC,OACA,cAAc,CAAA,GACd,KACA,aACA,WACG,gBACwB;AAC3B,MAAI,CAAC,gBAAgB;AACpB,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQ,OACxQ,6BAA6B,GAC3B;AAAA,IAEJ;AAED,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAyS,OACxS,6BAA6B,GAC3B;AAAA,IAEJ;AAAA,EACD;AAED,MAAI,SAAS,SAAS,eAAe,KAAK,GAAG;AAC5C,UAAM,MAAM,SAAS,MAAM,KAAK,WAAW;AAE3C,WACCA,IAAC,OAAK,EACL,KACA,OAAO,WAAW,SAAS,SAAY,MAAM,WAAW,OACxD,QAAQ,WAAW,SAAS,SAAY,MAAM,WAAW,QACzD,KAAK,oBAAQ,MAAM,OAAO,aAC1B,QAAQ,aACR,QAAc,GACV,UAAS,CAAA;AAAA,EAAA,OAGT;AACC,WAAA;AAAA,EACP;AACF;"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const react = require("@prismicio/react");
|
|
6
|
+
const router = require("next/router");
|
|
7
|
+
const getPrismicPreviewCookie = require("./lib/getPrismicPreviewCookie.cjs");
|
|
8
|
+
const getPreviewCookieRepositoryName = require("./lib/getPreviewCookieRepositoryName.cjs");
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule)
|
|
11
|
+
return e;
|
|
12
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
|
+
if (e) {
|
|
14
|
+
for (const k in e) {
|
|
15
|
+
if (k !== "default") {
|
|
16
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: () => e[k]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
28
|
+
function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
|
|
29
|
+
const router$1 = router.useRouter();
|
|
30
|
+
const resolvedUpdatePreviewURL = router$1.basePath + updatePreviewURL;
|
|
31
|
+
const resolvedExitPreviewURL = router$1.basePath + exitPreviewURL;
|
|
32
|
+
React__namespace.useEffect(() => {
|
|
33
|
+
const startPreviewMode = async () => {
|
|
34
|
+
const res = await globalThis.fetch(resolvedUpdatePreviewURL);
|
|
35
|
+
if (res.ok) {
|
|
36
|
+
globalThis.location.reload();
|
|
37
|
+
} else {
|
|
38
|
+
console.error(`[<PrismicPreview>] Failed to start or update Preview Mode using the "${resolvedUpdatePreviewURL}" API endpoint. Does it exist?`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const handlePrismicPreviewUpdate = async (event) => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
await startPreviewMode();
|
|
44
|
+
};
|
|
45
|
+
const handlePrismicPreviewEnd = async (event) => {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
const res = await globalThis.fetch(resolvedExitPreviewURL);
|
|
48
|
+
if (res.ok) {
|
|
49
|
+
globalThis.location.reload();
|
|
50
|
+
} else {
|
|
51
|
+
console.error(`[<PrismicPreview>] Failed to exit Preview Mode using the "${resolvedExitPreviewURL}" API endpoint. Does it exist?`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (router$1.isPreview) {
|
|
55
|
+
window.addEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
56
|
+
window.addEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
57
|
+
} else {
|
|
58
|
+
const prismicPreviewCookie = getPrismicPreviewCookie.getPrismicPreviewCookie(globalThis.document.cookie);
|
|
59
|
+
if (prismicPreviewCookie) {
|
|
60
|
+
const locationIsDescendantOfBasePath = window.location.href.startsWith(window.location.origin + router$1.basePath);
|
|
61
|
+
const prismicPreviewCookieRepositoryName = getPreviewCookieRepositoryName.getPreviewCookieRepositoryName(prismicPreviewCookie);
|
|
62
|
+
if (locationIsDescendantOfBasePath && prismicPreviewCookieRepositoryName === repositoryName) {
|
|
63
|
+
startPreviewMode();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return () => {
|
|
68
|
+
window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
69
|
+
window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
70
|
+
};
|
|
71
|
+
}, [
|
|
72
|
+
repositoryName,
|
|
73
|
+
resolvedExitPreviewURL,
|
|
74
|
+
resolvedUpdatePreviewURL,
|
|
75
|
+
router$1.isPreview,
|
|
76
|
+
router$1.basePath
|
|
77
|
+
]);
|
|
78
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(react.PrismicToolbar, { repositoryName })] });
|
|
79
|
+
}
|
|
80
|
+
exports.PrismicPreview = PrismicPreview;
|
|
81
|
+
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["router","useRouter","React","getPrismicPreviewCookie","getPreviewCookieRepositoryName","_jsxs","_Fragment","_jsx","PrismicToolbar"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAMA,WAASC,OAAAA;AAET,QAAA,2BAA2BD,SAAO,WAAW;AAC7C,QAAA,yBAAyBA,SAAO,WAAW;AAEjDE,mBAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAE3D,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAIF,SAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuBG,wBAAA,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAASH,SAAO,QAAQ;AAGnC,cAAA,qCACLI,8DAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACAJ,SAAO;AAAA,IACPA,SAAO;AAAA,EAAA,CACP;AAED,SACCK,gBAAAC,WAAAA,UAAA,EAAA,UAAA,CACE,UACDC,eAACC,MAAAA,gBAAe,EAAA,gBAAkC,CAAA,EAAA,CAAA;AAGrD;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Props for `<PrismicPreview>`.
|
|
4
|
+
*/
|
|
5
|
+
export declare type PrismicPreviewProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
8
|
+
* using this repository.
|
|
9
|
+
*/
|
|
10
|
+
repositoryName: string;
|
|
11
|
+
/**
|
|
12
|
+
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
13
|
+
* This URL will be fetched on preview update events.
|
|
14
|
+
*
|
|
15
|
+
* **Note**: If your `next.config.js` file contains a `basePath`, it is
|
|
16
|
+
* automatically included.
|
|
17
|
+
*/
|
|
18
|
+
updatePreviewURL?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
21
|
+
* This URL will be fetched on preview exit events.
|
|
22
|
+
*
|
|
23
|
+
* **Note**: If your `next.config.js` file contains a `basePath`, it is
|
|
24
|
+
* automatically included.
|
|
25
|
+
*/
|
|
26
|
+
exitPreviewURL?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar
|
|
29
|
+
* will be rendered last.
|
|
30
|
+
*/
|
|
31
|
+
children?: React.ReactNode;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
35
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
36
|
+
* and exiting, this component will automatically update the Next.js preview
|
|
37
|
+
* cookie and refresh the page.
|
|
38
|
+
*
|
|
39
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
40
|
+
* tree. It must be rendered on every page.
|
|
41
|
+
*/
|
|
42
|
+
export declare function PrismicPreview({ repositoryName, children, updatePreviewURL, exitPreviewURL, }: PrismicPreviewProps): JSX.Element;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { jsxs, Fragment, jsx } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { PrismicToolbar } from
|
|
4
|
-
import { useRouter } from
|
|
5
|
-
import { getPrismicPreviewCookie } from
|
|
6
|
-
import { getPreviewCookieRepositoryName } from
|
|
7
|
-
|
|
8
|
-
function PrismicPreview({
|
|
9
|
-
repositoryName,
|
|
10
|
-
children,
|
|
11
|
-
updatePreviewURL = "/api/preview",
|
|
12
|
-
exitPreviewURL = "/api/exit-preview"
|
|
13
|
-
}) {
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { PrismicToolbar } from "@prismicio/react";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
5
|
+
import { getPrismicPreviewCookie } from "./lib/getPrismicPreviewCookie.js";
|
|
6
|
+
import { getPreviewCookieRepositoryName } from "./lib/getPreviewCookieRepositoryName.js";
|
|
7
|
+
function PrismicPreview({ repositoryName, children, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" }) {
|
|
14
8
|
const router = useRouter();
|
|
15
9
|
const resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;
|
|
16
10
|
const resolvedExitPreviewURL = router.basePath + exitPreviewURL;
|
|
@@ -20,9 +14,7 @@ function PrismicPreview({
|
|
|
20
14
|
if (res.ok) {
|
|
21
15
|
globalThis.location.reload();
|
|
22
16
|
} else {
|
|
23
|
-
console.error(
|
|
24
|
-
`[<PrismicPreview>] Failed to start or update Preview Mode using the "${resolvedUpdatePreviewURL}" API endpoint. Does it exist?`
|
|
25
|
-
);
|
|
17
|
+
console.error(`[<PrismicPreview>] Failed to start or update Preview Mode using the "${resolvedUpdatePreviewURL}" API endpoint. Does it exist?`);
|
|
26
18
|
}
|
|
27
19
|
};
|
|
28
20
|
const handlePrismicPreviewUpdate = async (event) => {
|
|
@@ -35,25 +27,16 @@ function PrismicPreview({
|
|
|
35
27
|
if (res.ok) {
|
|
36
28
|
globalThis.location.reload();
|
|
37
29
|
} else {
|
|
38
|
-
console.error(
|
|
39
|
-
`[<PrismicPreview>] Failed to exit Preview Mode using the "${resolvedExitPreviewURL}" API endpoint. Does it exist?`
|
|
40
|
-
);
|
|
30
|
+
console.error(`[<PrismicPreview>] Failed to exit Preview Mode using the "${resolvedExitPreviewURL}" API endpoint. Does it exist?`);
|
|
41
31
|
}
|
|
42
32
|
};
|
|
43
33
|
if (router.isPreview) {
|
|
44
|
-
window.addEventListener(
|
|
45
|
-
"prismicPreviewUpdate",
|
|
46
|
-
handlePrismicPreviewUpdate
|
|
47
|
-
);
|
|
34
|
+
window.addEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
48
35
|
window.addEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
49
36
|
} else {
|
|
50
|
-
const prismicPreviewCookie = getPrismicPreviewCookie(
|
|
51
|
-
globalThis.document.cookie
|
|
52
|
-
);
|
|
37
|
+
const prismicPreviewCookie = getPrismicPreviewCookie(globalThis.document.cookie);
|
|
53
38
|
if (prismicPreviewCookie) {
|
|
54
|
-
const locationIsDescendantOfBasePath = window.location.href.startsWith(
|
|
55
|
-
window.location.origin + router.basePath
|
|
56
|
-
);
|
|
39
|
+
const locationIsDescendantOfBasePath = window.location.href.startsWith(window.location.origin + router.basePath);
|
|
57
40
|
const prismicPreviewCookieRepositoryName = getPreviewCookieRepositoryName(prismicPreviewCookie);
|
|
58
41
|
if (locationIsDescendantOfBasePath && prismicPreviewCookieRepositoryName === repositoryName) {
|
|
59
42
|
startPreviewMode();
|
|
@@ -61,10 +44,7 @@ function PrismicPreview({
|
|
|
61
44
|
}
|
|
62
45
|
}
|
|
63
46
|
return () => {
|
|
64
|
-
window.removeEventListener(
|
|
65
|
-
"prismicPreviewUpdate",
|
|
66
|
-
handlePrismicPreviewUpdate
|
|
67
|
-
);
|
|
47
|
+
window.removeEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
68
48
|
window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
69
49
|
};
|
|
70
50
|
}, [
|
|
@@ -74,15 +54,9 @@ function PrismicPreview({
|
|
|
74
54
|
router.isPreview,
|
|
75
55
|
router.basePath
|
|
76
56
|
]);
|
|
77
|
-
return
|
|
78
|
-
children: [
|
|
79
|
-
children,
|
|
80
|
-
/* @__PURE__ */ jsx(PrismicToolbar, {
|
|
81
|
-
repositoryName
|
|
82
|
-
})
|
|
83
|
-
]
|
|
84
|
-
});
|
|
57
|
+
return jsxs(Fragment, { children: [children, jsx(PrismicToolbar, { repositoryName })] });
|
|
85
58
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
export {
|
|
60
|
+
PrismicPreview
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=PrismicPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PrismicToolbar } from \"@prismicio/react\";\nimport { useRouter } from \"next/router\";\n\nimport { getPrismicPreviewCookie } from \"./lib/getPrismicPreviewCookie\";\nimport { getPreviewCookieRepositoryName } from \"./lib/getPreviewCookieRepositoryName\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t *\n\t * **Note**: If your `next.config.js` file contains a `basePath`, it is\n\t * automatically included.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar\n\t * will be rendered last.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically update the Next.js preview\n * cookie and refresh the page.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\tupdatePreviewURL = \"/api/preview\",\n\texitPreviewURL = \"/api/exit-preview\",\n}: PrismicPreviewProps): JSX.Element {\n\tconst router = useRouter();\n\n\tconst resolvedUpdatePreviewURL = router.basePath + updatePreviewURL;\n\tconst resolvedExitPreviewURL = router.basePath + exitPreviewURL;\n\n\tReact.useEffect(() => {\n\t\t/**\n\t\t * Starts Preview Mode and refreshes the page's props.\n\t\t */\n\t\tconst startPreviewMode = async () => {\n\t\t\t// Start Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedUpdatePreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to start or update Preview Mode using the \"${resolvedUpdatePreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst handlePrismicPreviewUpdate = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\tawait startPreviewMode();\n\t\t};\n\n\t\tconst handlePrismicPreviewEnd = async (event: Event) => {\n\t\t\t// Prevent the toolbar from reloading the page.\n\t\t\tevent.preventDefault();\n\n\t\t\t// Exit Next.js Preview Mode via the given preview API endpoint.\n\t\t\tconst res = await globalThis.fetch(resolvedExitPreviewURL);\n\n\t\t\tif (res.ok) {\n\t\t\t\tglobalThis.location.reload();\n\t\t\t} else {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${resolvedExitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tif (router.isPreview) {\n\t\t\t// Register Prismic Toolbar event handlers.\n\t\t\twindow.addEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.addEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t} else {\n\t\t\tconst prismicPreviewCookie = getPrismicPreviewCookie(\n\t\t\t\tglobalThis.document.cookie,\n\t\t\t);\n\n\t\t\tif (prismicPreviewCookie) {\n\t\t\t\t// If a Prismic preview cookie is present, but Next.js Preview\n\t\t\t\t// Mode is not active, we must activate Preview Mode manually.\n\t\t\t\t//\n\t\t\t\t// This will happen when a visitor accesses the page using a\n\t\t\t\t// Prismic preview share link.\n\n\t\t\t\t/**\n\t\t\t\t * Determines if the current location is a descendant of the app's base\n\t\t\t\t * path.\n\t\t\t\t *\n\t\t\t\t * This is used to prevent infinite refrehes; when\n\t\t\t\t * `isDescendantOfBasePath` is `false`, `router.isPreview` is also\n\t\t\t\t * `false`.\n\t\t\t\t *\n\t\t\t\t * If the app does not have a base path, this should always be `true`.\n\t\t\t\t */\n\t\t\t\tconst locationIsDescendantOfBasePath = window.location.href.startsWith(\n\t\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t\t);\n\n\t\t\t\tconst prismicPreviewCookieRepositoryName =\n\t\t\t\t\tgetPreviewCookieRepositoryName(prismicPreviewCookie);\n\n\t\t\t\tif (\n\t\t\t\t\tlocationIsDescendantOfBasePath &&\n\t\t\t\t\tprismicPreviewCookieRepositoryName === repositoryName\n\t\t\t\t) {\n\t\t\t\t\tstartPreviewMode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// On cleanup, unregister Prismic Toolbar event handlers.\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\n\t\t\t\t\"prismicPreviewUpdate\",\n\t\t\t\thandlePrismicPreviewUpdate,\n\t\t\t);\n\t\t\twindow.removeEventListener(\"prismicPreviewEnd\", handlePrismicPreviewEnd);\n\t\t};\n\t}, [\n\t\trepositoryName,\n\t\tresolvedExitPreviewURL,\n\t\tresolvedUpdatePreviewURL,\n\t\trouter.isPreview,\n\t\trouter.basePath,\n\t]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicToolbar repositoryName={repositoryName} />\n\t\t</>\n\t);\n}\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;AAmDgB,SAAA,eAAe,EAC9B,gBACA,UACA,mBAAmB,gBACnB,iBAAiB,uBACI;AACrB,QAAM,SAAS;AAET,QAAA,2BAA2B,OAAO,WAAW;AAC7C,QAAA,yBAAyB,OAAO,WAAW;AAEjD,QAAM,UAAU,MAAK;AAIpB,UAAM,mBAAmB,YAAW;AAEnC,YAAM,MAAM,MAAM,WAAW,MAAM,wBAAwB;AAE3D,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,wEAAwE,wDAAwD;AAAA,MAEjI;AAAA,IAAA;AAGI,UAAA,6BAA6B,OAAO,UAAgB;AAEzD,YAAM,eAAc;AAEpB,YAAM;;AAGD,UAAA,0BAA0B,OAAO,UAAgB;AAEtD,YAAM,eAAc;AAGpB,YAAM,MAAM,MAAM,WAAW,MAAM,sBAAsB;AAEzD,UAAI,IAAI,IAAI;AACX,mBAAW,SAAS;aACd;AACE,gBAAA,MACP,6DAA6D,sDAAsD;AAAA,MAEpH;AAAA,IAAA;AAGF,QAAI,OAAO,WAAW;AAEd,aAAA,iBACN,wBACA,0BAA0B;AAEpB,aAAA,iBAAiB,qBAAqB,uBAAuB;AAAA,IAAA,OAC9D;AACN,YAAM,uBAAuB,wBAC5B,WAAW,SAAS,MAAM;AAG3B,UAAI,sBAAsB;AAiBnB,cAAA,iCAAiC,OAAO,SAAS,KAAK,WAC3D,OAAO,SAAS,SAAS,OAAO,QAAQ;AAGnC,cAAA,qCACL,+BAA+B,oBAAoB;AAGnD,YAAA,kCACA,uCAAuC,gBACtC;;QAED;AAAA,MACD;AAAA,IACD;AAGD,WAAO,MAAK;AACJ,aAAA,oBACN,wBACA,0BAA0B;AAEpB,aAAA,oBAAoB,qBAAqB,uBAAuB;AAAA,IAAA;AAAA,EACxE,GACE;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EAAA,CACP;AAED,SACCA,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,gBAAe,EAAA,gBAAkC,CAAA,EAAA,CAAA;AAGrD;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const isPrismicNextPreviewData = (previewData) => {
|
|
4
|
+
return typeof previewData === "object" && "ref" in previewData;
|
|
5
|
+
};
|
|
6
|
+
const enableAutoPreviews = (config) => {
|
|
7
|
+
if ("previewData" in config && config.previewData) {
|
|
8
|
+
const { previewData } = config;
|
|
9
|
+
if (isPrismicNextPreviewData(previewData) && previewData.ref) {
|
|
10
|
+
config.client.queryContentFromRef(previewData.ref);
|
|
11
|
+
}
|
|
12
|
+
} else if ("req" in config && config.req) {
|
|
13
|
+
config.client.enableAutoPreviewsFromReq(config.req);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
exports.enableAutoPreviews = enableAutoPreviews;
|
|
17
|
+
//# sourceMappingURL=enableAutoPreviews.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.
|
|
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;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PreviewData } from "next";
|
|
2
|
+
import { Client, HttpRequestLike } from "@prismicio/client";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for `enableAutoPreviews`.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam TPreviewData - Next.js preview data object.
|
|
7
|
+
*/
|
|
8
|
+
export declare type EnableAutoPreviewsConfig<TPreviewData extends PreviewData = PreviewData> = {
|
|
9
|
+
/**
|
|
10
|
+
* Prismic client with which automatic previews will be enabled.
|
|
11
|
+
*/
|
|
12
|
+
client: Client;
|
|
13
|
+
} & ({
|
|
14
|
+
/**
|
|
15
|
+
* A Next.js context object (such as the context object from
|
|
16
|
+
* `getStaticProps` or `getServerSideProps`).
|
|
17
|
+
*
|
|
18
|
+
* Pass a `context` object when using `enableAutoPreviews` outside a
|
|
19
|
+
* Next.js API endpoint.
|
|
20
|
+
*/
|
|
21
|
+
previewData?: TPreviewData;
|
|
22
|
+
} | {
|
|
23
|
+
/**
|
|
24
|
+
* A Next.js API endpoint request object.
|
|
25
|
+
*
|
|
26
|
+
* Pass a `req` object when using `enableAutoPreviews` in a Next.js API
|
|
27
|
+
* endpoint.
|
|
28
|
+
*/
|
|
29
|
+
req?: HttpRequestLike;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Configures a Prismic client to automatically query draft content during a
|
|
33
|
+
* preview session. It either takes in a Next.js `getStaticProps` context object
|
|
34
|
+
* or a Next.js API endpoint request object.
|
|
35
|
+
*
|
|
36
|
+
* @param config - Configuration for the function.
|
|
37
|
+
*/
|
|
38
|
+
export declare const enableAutoPreviews: <TPreviewData extends PreviewData>(config: EnableAutoPreviewsConfig<TPreviewData>) => void;
|
|
@@ -11,6 +11,7 @@ const enableAutoPreviews = (config) => {
|
|
|
11
11
|
config.client.enableAutoPreviewsFromReq(config.req);
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export {
|
|
15
|
+
enableAutoPreviews
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=enableAutoPreviews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
function exitPreview(config) {
|
|
4
|
+
config.res.clearPreviewData();
|
|
5
|
+
config.res.status(205).json({ success: true });
|
|
6
|
+
}
|
|
7
|
+
exports.exitPreview = exitPreview;
|
|
8
|
+
//# sourceMappingURL=exitPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.
|
|
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\t/**\n\t * @deprecated - This property is no longer used. It can be deleted safely.\n\t */\n\texitPreviewURL?: string;\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":";;AA+CM,SAAU,YAAY,QAAyB;AAEpD,SAAO,IAAI;AAIJ,SAAA,IAAI,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,MAAM;AAC9C;;"}
|