@prismicio/next 1.7.0-alpha.0 → 1.7.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/PrismicNextLink.d.ts +6 -6
- package/dist/PrismicPreview.cjs +12 -2
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.ts +1 -1
- package/dist/PrismicPreview.js +12 -2
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/enableAutoPreviews.cjs +3 -3
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.js +3 -3
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +2 -2
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.ts +2 -2
- package/dist/exitPreview.js +2 -2
- package/dist/exitPreview.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/redirectToPreviewURL.cjs +2 -2
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.js +2 -2
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +4 -8
- package/src/PrismicPreview.tsx +28 -10
- package/src/enableAutoPreviews.ts +3 -3
- package/src/exitPreview.ts +7 -5
- package/src/redirectToPreviewURL.ts +2 -2
|
@@ -25,7 +25,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
25
25
|
scroll?: boolean | undefined;
|
|
26
26
|
shallow?: boolean | undefined;
|
|
27
27
|
passHref?: boolean | undefined;
|
|
28
|
-
prefetch?: boolean | undefined;
|
|
28
|
+
prefetch?: boolean | null | undefined;
|
|
29
29
|
locale?: string | false | undefined;
|
|
30
30
|
legacyBehavior?: boolean | undefined;
|
|
31
31
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
@@ -38,7 +38,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
38
38
|
scroll?: boolean | undefined;
|
|
39
39
|
shallow?: boolean | undefined;
|
|
40
40
|
passHref?: boolean | undefined;
|
|
41
|
-
prefetch?: boolean | undefined;
|
|
41
|
+
prefetch?: boolean | null | undefined;
|
|
42
42
|
locale?: string | false | undefined;
|
|
43
43
|
legacyBehavior?: boolean | undefined;
|
|
44
44
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
@@ -60,7 +60,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
60
60
|
scroll?: boolean | undefined;
|
|
61
61
|
shallow?: boolean | undefined;
|
|
62
62
|
passHref?: boolean | undefined;
|
|
63
|
-
prefetch?: boolean | undefined;
|
|
63
|
+
prefetch?: boolean | null | undefined;
|
|
64
64
|
locale?: string | false | undefined;
|
|
65
65
|
legacyBehavior?: boolean | undefined;
|
|
66
66
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
@@ -73,7 +73,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
73
73
|
scroll?: boolean | undefined;
|
|
74
74
|
shallow?: boolean | undefined;
|
|
75
75
|
passHref?: boolean | undefined;
|
|
76
|
-
prefetch?: boolean | undefined;
|
|
76
|
+
prefetch?: boolean | null | undefined;
|
|
77
77
|
locale?: string | false | undefined;
|
|
78
78
|
legacyBehavior?: boolean | undefined;
|
|
79
79
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
@@ -95,7 +95,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
95
95
|
scroll?: boolean | undefined;
|
|
96
96
|
shallow?: boolean | undefined;
|
|
97
97
|
passHref?: boolean | undefined;
|
|
98
|
-
prefetch?: boolean | undefined;
|
|
98
|
+
prefetch?: boolean | null | undefined;
|
|
99
99
|
locale?: string | false | undefined;
|
|
100
100
|
legacyBehavior?: boolean | undefined;
|
|
101
101
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
@@ -108,7 +108,7 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit
|
|
|
108
108
|
scroll?: boolean | undefined;
|
|
109
109
|
shallow?: boolean | undefined;
|
|
110
110
|
passHref?: boolean | undefined;
|
|
111
|
-
prefetch?: boolean | undefined;
|
|
111
|
+
prefetch?: boolean | null | undefined;
|
|
112
112
|
locale?: string | false | undefined;
|
|
113
113
|
legacyBehavior?: boolean | undefined;
|
|
114
114
|
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -3,16 +3,26 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const Script = require("next/script");
|
|
5
5
|
const headers = require("next/headers");
|
|
6
|
+
const router = require("next/router");
|
|
6
7
|
const PrismicPreviewClient = require("./PrismicPreviewClient.cjs");
|
|
7
8
|
const getToolbarSrc = require('./_node_modules/@prismicio/client/dist/getToolbarSrc.cjs');
|
|
8
9
|
function PrismicPreview({ repositoryName, children, ...props }) {
|
|
9
10
|
const toolbarSrc = getToolbarSrc.getToolbarSrc(repositoryName);
|
|
10
11
|
let isDraftMode = false;
|
|
12
|
+
const result = jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(PrismicPreviewClient.PrismicPreviewClient, { repositoryName, isDraftMode, ...props }), jsxRuntime.jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
13
|
+
let isAppRouter = true;
|
|
11
14
|
try {
|
|
12
|
-
|
|
15
|
+
router.useRouter();
|
|
16
|
+
isAppRouter = false;
|
|
13
17
|
} catch {
|
|
14
18
|
}
|
|
15
|
-
|
|
19
|
+
if (isAppRouter) {
|
|
20
|
+
return new Promise(async (res) => {
|
|
21
|
+
isDraftMode = (await headers.draftMode()).isEnabled;
|
|
22
|
+
res(result);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
16
26
|
}
|
|
17
27
|
exports.PrismicPreview = PrismicPreview;
|
|
18
28
|
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport { useRouter as usePagesRouter } from \"next/router\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element | Promise<JSX.Element> {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\tlet isDraftMode = false;\n\n\tconst result = (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n\n\t// We need to check `draftMode()`, an async method, when running in the\n\t// App Router. The Pages Router does not support async components, so we\n\t// need to do some trickery to return a Promise in the App Router and\n\t// unwrapped JSX in the Pages Router.\n\t//\n\t// Alternatively, we could serve a special server-only\n\t// `<PrismicPreview>`, but that requires extra set up and depends on the\n\t// compiler to recognize the `react-server` entry point. It is an\n\t// undocumented feature that could be removed.\n\tlet isAppRouter = true;\n\ttry {\n\t\tusePagesRouter();\n\t\tisAppRouter = false;\n\t} catch {}\n\n\tif (isAppRouter) {\n\t\treturn new Promise(async (res) => {\n\t\t\tisDraftMode = (await draftMode()).isEnabled;\n\n\t\t\tres(result);\n\t\t});\n\t}\n\n\treturn result;\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx","PrismicPreviewClient","draftMode"],"mappings":";;;;;;;;AAiDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,4BAAsB,cAAc;AACvD,MAAI,cAAc;AAEZ,QAAA,SACLC,WAAAA,KAAAC,WAAA,UAAA,EAAA,UAAA,CACE,UACDC,eAACC,qBAAAA,sBAAoB,EACpB,gBACA,aACI,GAAA,OACH,GACFD,WAAAA,IAAC,UAAO,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAanD,MAAI,cAAc;AACd,MAAA;;AAEW,kBAAA;AAAA,EAAA,QACP;AAAA,EAAE;AAEV,MAAI,aAAa;AACT,WAAA,IAAI,QAAQ,OAAO,QAAO;AACjB,qBAAA,MAAME,kBAAa,GAAA;AAElC,UAAI,MAAM;AAAA,IAAA,CACV;AAAA,EACD;AAEM,SAAA;AACR;;"}
|
package/dist/PrismicPreview.d.ts
CHANGED
|
@@ -36,4 +36,4 @@ export type PrismicPreviewProps = {
|
|
|
36
36
|
* This component can be wrapped around your app or added anywhere in your app's
|
|
37
37
|
* tree. It must be rendered on every page.
|
|
38
38
|
*/
|
|
39
|
-
export declare function PrismicPreview({ repositoryName, children, ...props }: PrismicPreviewProps): JSX.Element
|
|
39
|
+
export declare function PrismicPreview({ repositoryName, children, ...props }: PrismicPreviewProps): JSX.Element | Promise<JSX.Element>;
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import Script from "next/script";
|
|
3
3
|
import { draftMode } from "next/headers";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
4
5
|
import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
|
|
5
6
|
import { getToolbarSrc } from './_node_modules/@prismicio/client/dist/getToolbarSrc.js';
|
|
6
7
|
function PrismicPreview({ repositoryName, children, ...props }) {
|
|
7
8
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
8
9
|
let isDraftMode = false;
|
|
10
|
+
const result = jsxs(Fragment, { children: [children, jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...props }), jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
11
|
+
let isAppRouter = true;
|
|
9
12
|
try {
|
|
10
|
-
|
|
13
|
+
useRouter();
|
|
14
|
+
isAppRouter = false;
|
|
11
15
|
} catch {
|
|
12
16
|
}
|
|
13
|
-
|
|
17
|
+
if (isAppRouter) {
|
|
18
|
+
return new Promise(async (res) => {
|
|
19
|
+
isDraftMode = (await draftMode()).isEnabled;
|
|
20
|
+
res(result);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
14
24
|
}
|
|
15
25
|
export {
|
|
16
26
|
PrismicPreview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.js","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","sources":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport { useRouter as usePagesRouter } from \"next/router\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element | Promise<JSX.Element> {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\tlet isDraftMode = false;\n\n\tconst result = (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n\n\t// We need to check `draftMode()`, an async method, when running in the\n\t// App Router. The Pages Router does not support async components, so we\n\t// need to do some trickery to return a Promise in the App Router and\n\t// unwrapped JSX in the Pages Router.\n\t//\n\t// Alternatively, we could serve a special server-only\n\t// `<PrismicPreview>`, but that requires extra set up and depends on the\n\t// compiler to recognize the `react-server` entry point. It is an\n\t// undocumented feature that could be removed.\n\tlet isAppRouter = true;\n\ttry {\n\t\tusePagesRouter();\n\t\tisAppRouter = false;\n\t} catch {}\n\n\tif (isAppRouter) {\n\t\treturn new Promise(async (res) => {\n\t\t\tisDraftMode = (await draftMode()).isEnabled;\n\n\t\t\tres(result);\n\t\t});\n\t}\n\n\treturn result;\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx"],"mappings":";;;;;;AAiDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,cAAsB,cAAc;AACvD,MAAI,cAAc;AAEZ,QAAA,SACLC,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBAAoB,EACpB,gBACA,aACI,GAAA,OACH,GACFA,IAAC,UAAO,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAanD,MAAI,cAAc;AACd,MAAA;;AAEW,kBAAA;AAAA,EAAA,QACP;AAAA,EAAE;AAEV,MAAI,aAAa;AACT,WAAA,IAAI,QAAQ,OAAO,QAAO;AACjB,qBAAA,MAAM,UAAa,GAAA;AAElC,UAAI,MAAM;AAAA,IAAA,CACV;AAAA,EACD;AAEM,SAAA;AACR;"}
|
|
@@ -13,11 +13,11 @@ const enableAutoPreviews = (config) => {
|
|
|
13
13
|
} else if ("req" in config && config.req) {
|
|
14
14
|
config.client.enableAutoPreviewsFromReq(config.req);
|
|
15
15
|
} else {
|
|
16
|
-
config.client.queryContentFromRef(() => {
|
|
16
|
+
config.client.queryContentFromRef(async () => {
|
|
17
17
|
var _a;
|
|
18
18
|
let isDraftModeEnabled = false;
|
|
19
19
|
try {
|
|
20
|
-
isDraftModeEnabled = headers.draftMode().isEnabled;
|
|
20
|
+
isDraftModeEnabled = (await headers.draftMode()).isEnabled;
|
|
21
21
|
} catch {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
@@ -26,7 +26,7 @@ const enableAutoPreviews = (config) => {
|
|
|
26
26
|
}
|
|
27
27
|
let cookie$1;
|
|
28
28
|
try {
|
|
29
|
-
cookie$1 = (_a = headers.cookies().get(cookie.preview)) == null ? void 0 : _a.value;
|
|
29
|
+
cookie$1 = (_a = (await headers.cookies()).get(cookie.preview)) == null ? void 0 : _a.value;
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["draftMode","cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.cjs","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(async () => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = (await draftMode()).isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = (await cookies()).get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["draftMode","cookie","cookies","prismic.cookie.preview"],"mappings":";;;;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,YAAW;;AAC5C,UAAI,qBAAqB;AACrB,UAAA;AACmB,8BAAA,MAAMA,kBAAa,GAAA;AAAA,MAAA,QAClC;AAMP;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAAC;AACA,UAAA;AACHA,oBAAU,YAAMC,QAAO,QAAA,GAAI,IAAIC,OAAAA,OAAsB,MAA3C,mBAA8C;AAAA,MAAA,QACjD;AAMP;AAAA,MACA;AAgBD,UAAIF,YAAU,gBAAgB,KAAKA,QAAM,GAAG;AACpC,eAAAA;AAAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
|
|
@@ -11,11 +11,11 @@ const enableAutoPreviews = (config) => {
|
|
|
11
11
|
} else if ("req" in config && config.req) {
|
|
12
12
|
config.client.enableAutoPreviewsFromReq(config.req);
|
|
13
13
|
} else {
|
|
14
|
-
config.client.queryContentFromRef(() => {
|
|
14
|
+
config.client.queryContentFromRef(async () => {
|
|
15
15
|
var _a;
|
|
16
16
|
let isDraftModeEnabled = false;
|
|
17
17
|
try {
|
|
18
|
-
isDraftModeEnabled = draftMode().isEnabled;
|
|
18
|
+
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
19
19
|
} catch {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
@@ -24,7 +24,7 @@ const enableAutoPreviews = (config) => {
|
|
|
24
24
|
}
|
|
25
25
|
let cookie;
|
|
26
26
|
try {
|
|
27
|
-
cookie = (_a = cookies().get(preview)) == null ? void 0 : _a.value;
|
|
27
|
+
cookie = (_a = (await cookies()).get(preview)) == null ? void 0 : _a.value;
|
|
28
28
|
} catch {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(() => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = draftMode().isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = cookies().get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.js","sources":["../../src/enableAutoPreviews.ts"],"sourcesContent":["import { draftMode, cookies } from \"next/headers\";\nimport { PreviewData } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { NextApiRequestLike, PrismicPreviewData } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig<\n\tTPreviewData extends PreviewData = PreviewData,\n> = {\n\t/**\n\t * Prismic client with which automatic previews will be enabled.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"queryContentFromRef\" | \"enableAutoPreviewsFromReq\"\n\t>;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: TPreviewData;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\nconst isPrismicPreviewData = (input: unknown): input is PrismicPreviewData => {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport const enableAutoPreviews = <TPreviewData extends PreviewData>(\n\tconfig: EnableAutoPreviewsConfig<TPreviewData>,\n): void => {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode (`pages`\n\t\t// directory).\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\t} else if (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route (`pages` directory).\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\t} else {\n\t\t// Assume we are in App Router (`app` directory) OR\n\t\t// `getStaticProps()`/`getServerSideProps()` with an inactive\n\t\t// Preview Mode (`pages` directory).\n\n\t\t// We use a function value so the cookie is checked on every\n\t\t// request. We don't have a static value to read from.\n\t\tconfig.client.queryContentFromRef(async () => {\n\t\t\tlet isDraftModeEnabled = false;\n\t\t\ttry {\n\t\t\t\tisDraftModeEnabled = (await draftMode()).isEnabled;\n\t\t\t} catch {\n\t\t\t\t// This catch block may be reached if\n\t\t\t\t// `draftMode()` is called in a place that does\n\t\t\t\t// not have access to its async storage. We can\n\t\t\t\t// ignore this case.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (!isDraftModeEnabled) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cookie: string | undefined;\n\t\t\ttry {\n\t\t\t\tcookie = (await cookies()).get(prismic.cookie.preview)?.value;\n\t\t\t} catch {\n\t\t\t\t// We are probably in `getStaticProps()` or\n\t\t\t\t// `getServerSideProps()` with inactive Preview\n\t\t\t\t// Mode where `cookies()` does not work. We\n\t\t\t\t// don't need to do any preview handling.\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We only return the cookie if a Prismic Preview session is active.\n\t\t\t//\n\t\t\t// An inactive cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\"\n\t\t\t// \t}\n\t\t\t//\n\t\t\t// An active cookie looks like this (URL encoded):\n\t\t\t// \t{\n\t\t\t// \t\t\"_tracker\": \"abc123\",\n\t\t\t// \t\t\"example-prismic-repo.prismic.io\": {\n\t\t\t// \t\t\tpreview: \"https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz\"\n\t\t\t// \t\t}\n\t\t\t// \t}\n\t\t\tif (cookie && /\\.prismic\\.io/.test(cookie)) {\n\t\t\t\treturn cookie;\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["prismic.cookie.preview"],"mappings":";;AA2CA,MAAM,uBAAuB,CAAC,UAA+C;AAC5E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;AASa,MAAA,qBAAqB,CACjC,WACS;AACL,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAK9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IACxD;AAAA,EACS,WAAA,SAAS,UAAU,OAAO,KAAK;AAGlC,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAAA,EAAA,OAC5C;AAOC,WAAA,OAAO,oBAAoB,YAAW;;AAC5C,UAAI,qBAAqB;AACrB,UAAA;AACmB,8BAAA,MAAM,UAAa,GAAA;AAAA,MAAA,QAClC;AAMP;AAAA,MACA;AAED,UAAI,CAAC,oBAAoB;AACxB;AAAA,MACA;AAEG,UAAA;AACA,UAAA;AACH,kBAAU,YAAM,QAAO,GAAI,IAAIA,OAAsB,MAA3C,mBAA8C;AAAA,MAAA,QACjD;AAMP;AAAA,MACA;AAgBD,UAAI,UAAU,gBAAgB,KAAK,MAAM,GAAG;AACpC,eAAA;AAAA,MACP;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const headers = require("next/headers");
|
|
4
|
-
function exitPreview(config) {
|
|
4
|
+
async function exitPreview(config) {
|
|
5
5
|
if (config == null ? void 0 : config.res) {
|
|
6
6
|
config.res.clearPreviewData();
|
|
7
7
|
config.res.setHeader("Cache-Control", "no-store");
|
|
8
8
|
config.res.json({ success: true });
|
|
9
9
|
return;
|
|
10
10
|
} else {
|
|
11
|
-
headers.draftMode().disable();
|
|
11
|
+
(await headers.draftMode()).disable();
|
|
12
12
|
return new Response(JSON.stringify({ success: true }), {
|
|
13
13
|
headers: {
|
|
14
14
|
"Cache-Control": "no-store"
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(): Response
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport async function exitPreview(): Promise<Response>;\nexport async function exitPreview(\n\tconfig: ExitPreviewAPIRouteConfig,\n): Promise<void>;\nexport async function exitPreview(\n\tconfig?: ExitPreviewAPIRouteConfig,\n): Promise<Response | void> {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\t(await draftMode()).disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["draftMode"],"mappings":";;;AAmEA,eAAsB,YACrB,QAAkC;AAElC,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGL,KAAA,MAAMA,QAAAA,aAAa;AAGb,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
|
package/dist/exitPreview.d.ts
CHANGED
|
@@ -55,5 +55,5 @@ export type ExitPreviewAPIRouteConfig = {
|
|
|
55
55
|
* }
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
export declare function exitPreview(): Response
|
|
59
|
-
export declare function exitPreview(config: ExitPreviewAPIRouteConfig): void
|
|
58
|
+
export declare function exitPreview(): Promise<Response>;
|
|
59
|
+
export declare function exitPreview(config: ExitPreviewAPIRouteConfig): Promise<void>;
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { draftMode } from "next/headers";
|
|
2
|
-
function exitPreview(config) {
|
|
2
|
+
async function exitPreview(config) {
|
|
3
3
|
if (config == null ? void 0 : config.res) {
|
|
4
4
|
config.res.clearPreviewData();
|
|
5
5
|
config.res.setHeader("Cache-Control", "no-store");
|
|
6
6
|
config.res.json({ success: true });
|
|
7
7
|
return;
|
|
8
8
|
} else {
|
|
9
|
-
draftMode().disable();
|
|
9
|
+
(await draftMode()).disable();
|
|
10
10
|
return new Response(JSON.stringify({ success: true }), {
|
|
11
11
|
headers: {
|
|
12
12
|
"Cache-Control": "no-store"
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(): Response
|
|
1
|
+
{"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * @deprecated Use `ExitPreviewAPIRouteConfig` instead when `exitPreview()` is\n * used in a Pages Router API endpoint. `exitPreview()` does not require any\n * configuration when used in an App Router Route Handler.\n */\nexport type ExitPreviewConfig = ExitPreviewAPIRouteConfig;\n\n/**\n * Configuration for `exitPreview()` when used in a Pages Router API route.\n */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API route, depending on whether you are using\n * the App Router or Pages Router.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export function GET() {\n * \treturn exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(req, res) {\n * \texitPreview({ req, res });\n * }\n * ```\n */\nexport async function exitPreview(): Promise<Response>;\nexport async function exitPreview(\n\tconfig: ExitPreviewAPIRouteConfig,\n): Promise<void>;\nexport async function exitPreview(\n\tconfig?: ExitPreviewAPIRouteConfig,\n): Promise<Response | void> {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\t(await draftMode()).disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";AAmEA,eAAsB,YACrB,QAAkC;AAElC,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGL,KAAA,MAAM,aAAa;AAGb,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -12,10 +12,10 @@ async function redirectToPreviewURL(config) {
|
|
|
12
12
|
defaultURL: config.defaultURL || "/"
|
|
13
13
|
});
|
|
14
14
|
if ("nextUrl" in request) {
|
|
15
|
-
headers.draftMode().enable();
|
|
15
|
+
(await headers.draftMode()).enable();
|
|
16
16
|
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
17
17
|
if (previewCookie) {
|
|
18
|
-
headers.cookies().set(cookie.preview, previewCookie);
|
|
18
|
+
(await headers.cookies()).set(cookie.preview, previewCookie);
|
|
19
19
|
}
|
|
20
20
|
navigation.redirect(basePath + previewUrl);
|
|
21
21
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\t(await draftMode()).enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\t(await cookies()).set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["draftMode","cookies","prismic.cookie.preview","redirect"],"mappings":";;;;;AAuFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACxB,KAAA,MAAMA,QAAAA,aAAa;AAOpB,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClB,OAAC,MAAMC,QAAAA,QAAS,GAAE,IAAIC,gBAAwB,aAAa;AAAA,IAC3D;AAEDC,wBAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;;"}
|
|
@@ -10,10 +10,10 @@ async function redirectToPreviewURL(config) {
|
|
|
10
10
|
defaultURL: config.defaultURL || "/"
|
|
11
11
|
});
|
|
12
12
|
if ("nextUrl" in request) {
|
|
13
|
-
draftMode().enable();
|
|
13
|
+
(await draftMode()).enable();
|
|
14
14
|
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
15
15
|
if (previewCookie) {
|
|
16
|
-
cookies().set(preview, previewCookie);
|
|
16
|
+
(await cookies()).set(preview, previewCookie);
|
|
17
17
|
}
|
|
18
18
|
redirect(basePath + previewUrl);
|
|
19
19
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport { cookies, draftMode } from \"next/headers\";\nimport * as prismic from \"@prismicio/client\";\n\nimport {\n\tNextApiRequestLike,\n\tNextApiResponseLike,\n\tNextRequestLike,\n} from \"./types\";\n\ntype RedirectToPreviewURLConfigBase = {\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<\n\t\tprismic.Client,\n\t\t\"enableAutoPreviewsFromReq\" | \"resolvePreviewURL\"\n\t>;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: prismic.LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport type RedirectToPreviewURLRouteHandlerConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `request` object from a Next.js Route Handler.\n\t\t *\n\t\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t\t */\n\t\trequest: NextRequestLike;\n\t};\n\nexport type RedirectToPreviewURLAPIEndpointConfig =\n\tRedirectToPreviewURLConfigBase & {\n\t\t/**\n\t\t * The `req` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\treq: NextApiRequestLike;\n\n\t\t/**\n\t\t * The `res` object from a Next.js API route.\n\t\t *\n\t\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t\t */\n\t\tres: NextApiResponseLike;\n\t};\n\nexport type RedirectToPreviewURLConfig =\n\t| RedirectToPreviewURLRouteHandlerConfig\n\t| RedirectToPreviewURLAPIEndpointConfig;\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLRouteHandlerConfig,\n): Promise<never>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLAPIEndpointConfig,\n): Promise<void>;\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never | void> {\n\tconst basePath = config.basePath || \"\";\n\tconst request = \"request\" in config ? config.request : config.req;\n\n\tconfig.client.enableAutoPreviewsFromReq(request);\n\n\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\tlinkResolver: config.linkResolver,\n\t\tdefaultURL: config.defaultURL || \"/\",\n\t});\n\n\tif (\"nextUrl\" in request) {\n\t\t(await draftMode()).enable();\n\n\t\t// Set the initial preview cookie, if available.\n\t\t// Setting the cookie here is necessary to support unpublished\n\t\t// previews. Without setting it here, the page will try to\n\t\t// render without the preview cookie, leading to a\n\t\t// PrismicNotFound error.\n\t\tconst previewCookie = request.nextUrl.searchParams.get(\"token\");\n\t\tif (previewCookie) {\n\t\t\t(await cookies()).set(prismic.cookie.preview, previewCookie);\n\t\t}\n\n\t\tredirect(basePath + previewUrl);\n\t} else {\n\t\tif (!(\"res\" in config)) {\n\t\t\tthrow new Error(\n\t\t\t\t\"[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.\",\n\t\t\t);\n\t\t}\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";;;AAuFA,eAAsB,qBACrB,QAAkC;AAE5B,QAAA,WAAW,OAAO,YAAY;AACpC,QAAM,UAAU,aAAa,SAAS,OAAO,UAAU,OAAO;AAEvD,SAAA,OAAO,0BAA0B,OAAO;AAE/C,QAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,IACxD,cAAc,OAAO;AAAA,IACrB,YAAY,OAAO,cAAc;AAAA,EAAA,CACjC;AAED,MAAI,aAAa,SAAS;AACxB,KAAA,MAAM,aAAa;AAOpB,UAAM,gBAAgB,QAAQ,QAAQ,aAAa,IAAI,OAAO;AAC9D,QAAI,eAAe;AAClB,OAAC,MAAM,QAAS,GAAE,IAAIA,SAAwB,aAAa;AAAA,IAC3D;AAED,aAAS,WAAW,UAAU;AAAA,EAAA,OACxB;AACF,QAAA,EAAE,SAAS,SAAS;AACjB,YAAA,IAAI,MACT,0GAA0G;AAAA,IAE3G;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"negotiator": "^0.6.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@prismicio/client": "7.
|
|
61
|
-
"@prismicio/mock": "0.
|
|
60
|
+
"@prismicio/client": "^7.11.0",
|
|
61
|
+
"@prismicio/mock": "^0.4.0",
|
|
62
62
|
"@size-limit/preset-small-lib": "^9.0.0",
|
|
63
63
|
"@types/negotiator": "^0.6.3",
|
|
64
64
|
"@types/react-test-renderer": "^18.0.2",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
75
75
|
"happy-dom": "^12.1.6",
|
|
76
76
|
"memfs": "^4.4.0",
|
|
77
|
-
"next": "^
|
|
77
|
+
"next": "^15.0.1",
|
|
78
78
|
"node-fetch": "^3.3.2",
|
|
79
79
|
"prettier": "^3.0.3",
|
|
80
80
|
"prettier-plugin-jsdoc": "^1.0.2",
|
|
@@ -99,9 +99,5 @@
|
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": {
|
|
101
101
|
"access": "public"
|
|
102
|
-
},
|
|
103
|
-
"overrides": {
|
|
104
|
-
"@prismicio/client": "7.9.0-alpha.3",
|
|
105
|
-
"@prismicio/mock": "0.3.8-alpha.2"
|
|
106
102
|
}
|
|
107
103
|
}
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Script from "next/script";
|
|
2
2
|
import { draftMode } from "next/headers";
|
|
3
|
+
import { useRouter as usePagesRouter } from "next/router";
|
|
3
4
|
import * as React from "react";
|
|
4
5
|
import * as prismic from "@prismicio/client";
|
|
5
6
|
|
|
@@ -50,19 +51,11 @@ export function PrismicPreview({
|
|
|
50
51
|
repositoryName,
|
|
51
52
|
children,
|
|
52
53
|
...props
|
|
53
|
-
}: PrismicPreviewProps): JSX.Element {
|
|
54
|
+
}: PrismicPreviewProps): JSX.Element | Promise<JSX.Element> {
|
|
54
55
|
const toolbarSrc = prismic.getToolbarSrc(repositoryName);
|
|
55
|
-
|
|
56
56
|
let isDraftMode = false;
|
|
57
|
-
try {
|
|
58
|
-
isDraftMode = draftMode().isEnabled;
|
|
59
|
-
} catch {
|
|
60
|
-
// noop - `requestAsyncStorage` propbably doesn't exist, such as
|
|
61
|
-
// in the Pages Router, which causes `draftMode()` to throw. We
|
|
62
|
-
// can ignore this case and assume Draft Mode is disabled.
|
|
63
|
-
}
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
const result = (
|
|
66
59
|
<>
|
|
67
60
|
{children}
|
|
68
61
|
<PrismicPreviewClient
|
|
@@ -73,4 +66,29 @@ export function PrismicPreview({
|
|
|
73
66
|
<Script src={toolbarSrc} strategy="lazyOnload" />
|
|
74
67
|
</>
|
|
75
68
|
);
|
|
69
|
+
|
|
70
|
+
// We need to check `draftMode()`, an async method, when running in the
|
|
71
|
+
// App Router. The Pages Router does not support async components, so we
|
|
72
|
+
// need to do some trickery to return a Promise in the App Router and
|
|
73
|
+
// unwrapped JSX in the Pages Router.
|
|
74
|
+
//
|
|
75
|
+
// Alternatively, we could serve a special server-only
|
|
76
|
+
// `<PrismicPreview>`, but that requires extra set up and depends on the
|
|
77
|
+
// compiler to recognize the `react-server` entry point. It is an
|
|
78
|
+
// undocumented feature that could be removed.
|
|
79
|
+
let isAppRouter = true;
|
|
80
|
+
try {
|
|
81
|
+
usePagesRouter();
|
|
82
|
+
isAppRouter = false;
|
|
83
|
+
} catch {}
|
|
84
|
+
|
|
85
|
+
if (isAppRouter) {
|
|
86
|
+
return new Promise(async (res) => {
|
|
87
|
+
isDraftMode = (await draftMode()).isEnabled;
|
|
88
|
+
|
|
89
|
+
res(result);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result;
|
|
76
94
|
}
|
|
@@ -74,10 +74,10 @@ export const enableAutoPreviews = <TPreviewData extends PreviewData>(
|
|
|
74
74
|
|
|
75
75
|
// We use a function value so the cookie is checked on every
|
|
76
76
|
// request. We don't have a static value to read from.
|
|
77
|
-
config.client.queryContentFromRef(() => {
|
|
77
|
+
config.client.queryContentFromRef(async () => {
|
|
78
78
|
let isDraftModeEnabled = false;
|
|
79
79
|
try {
|
|
80
|
-
isDraftModeEnabled = draftMode().isEnabled;
|
|
80
|
+
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
81
81
|
} catch {
|
|
82
82
|
// This catch block may be reached if
|
|
83
83
|
// `draftMode()` is called in a place that does
|
|
@@ -93,7 +93,7 @@ export const enableAutoPreviews = <TPreviewData extends PreviewData>(
|
|
|
93
93
|
|
|
94
94
|
let cookie: string | undefined;
|
|
95
95
|
try {
|
|
96
|
-
cookie = cookies().get(prismic.cookie.preview)?.value;
|
|
96
|
+
cookie = (await cookies()).get(prismic.cookie.preview)?.value;
|
|
97
97
|
} catch {
|
|
98
98
|
// We are probably in `getStaticProps()` or
|
|
99
99
|
// `getServerSideProps()` with inactive Preview
|
package/src/exitPreview.ts
CHANGED
|
@@ -61,11 +61,13 @@ export type ExitPreviewAPIRouteConfig = {
|
|
|
61
61
|
* }
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
|
-
export function exitPreview(): Response
|
|
65
|
-
export function exitPreview(
|
|
66
|
-
|
|
64
|
+
export async function exitPreview(): Promise<Response>;
|
|
65
|
+
export async function exitPreview(
|
|
66
|
+
config: ExitPreviewAPIRouteConfig,
|
|
67
|
+
): Promise<void>;
|
|
68
|
+
export async function exitPreview(
|
|
67
69
|
config?: ExitPreviewAPIRouteConfig,
|
|
68
|
-
): Response | void {
|
|
70
|
+
): Promise<Response | void> {
|
|
69
71
|
if (config?.res) {
|
|
70
72
|
// Assume Preview Mode is being used.
|
|
71
73
|
|
|
@@ -80,7 +82,7 @@ export function exitPreview(
|
|
|
80
82
|
} else {
|
|
81
83
|
// Assume Draft Mode is being used.
|
|
82
84
|
|
|
83
|
-
draftMode().disable();
|
|
85
|
+
(await draftMode()).disable();
|
|
84
86
|
|
|
85
87
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
86
88
|
return new Response(JSON.stringify({ success: true }), {
|
|
@@ -99,7 +99,7 @@ export async function redirectToPreviewURL(
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
if ("nextUrl" in request) {
|
|
102
|
-
draftMode().enable();
|
|
102
|
+
(await draftMode()).enable();
|
|
103
103
|
|
|
104
104
|
// Set the initial preview cookie, if available.
|
|
105
105
|
// Setting the cookie here is necessary to support unpublished
|
|
@@ -108,7 +108,7 @@ export async function redirectToPreviewURL(
|
|
|
108
108
|
// PrismicNotFound error.
|
|
109
109
|
const previewCookie = request.nextUrl.searchParams.get("token");
|
|
110
110
|
if (previewCookie) {
|
|
111
|
-
cookies().set(prismic.cookie.preview, previewCookie);
|
|
111
|
+
(await cookies()).set(prismic.cookie.preview, previewCookie);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
redirect(basePath + previewUrl);
|