@prismicio/next 1.3.0-alpha.1 → 1.3.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 +7 -7
- package/dist/PrismicPreview.cjs +5 -1
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.js +5 -1
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/exitPreview.cjs +2 -2
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.ts +1 -1
- 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/package.json +15 -15
- package/src/PrismicPreview.tsx +9 -1
- package/src/exitPreview.ts +5 -8
|
@@ -18,7 +18,7 @@ export type PrismicNextLinkProps = Omit<React.ComponentProps<typeof Link>, "fiel
|
|
|
18
18
|
document?: never;
|
|
19
19
|
href: React.ComponentProps<typeof Link>["href"];
|
|
20
20
|
});
|
|
21
|
-
export declare const PrismicNextLink: React.ForwardRefExoticComponent<(
|
|
21
|
+
export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
22
22
|
href: string | import("url").UrlObject;
|
|
23
23
|
as?: (string | import("url").UrlObject) | undefined;
|
|
24
24
|
replace?: boolean | undefined;
|
|
@@ -46,14 +46,14 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Pick<Omit
|
|
|
46
46
|
onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
47
47
|
} & {
|
|
48
48
|
children?: React.ReactNode;
|
|
49
|
-
} & React.RefAttributes<HTMLAnchorElement>, "
|
|
49
|
+
} & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
50
50
|
linkResolver?: prismic.LinkResolverFunction | undefined;
|
|
51
51
|
rel?: string | prismic.AsLinkAttrsConfig["rel"];
|
|
52
52
|
} & {
|
|
53
53
|
field: prismic.LinkField | null | undefined;
|
|
54
54
|
document?: undefined;
|
|
55
55
|
href?: undefined;
|
|
56
|
-
}, "
|
|
56
|
+
}, "ref"> | Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
57
57
|
href: string | import("url").UrlObject;
|
|
58
58
|
as?: (string | import("url").UrlObject) | undefined;
|
|
59
59
|
replace?: boolean | undefined;
|
|
@@ -81,14 +81,14 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Pick<Omit
|
|
|
81
81
|
onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
82
82
|
} & {
|
|
83
83
|
children?: React.ReactNode;
|
|
84
|
-
} & React.RefAttributes<HTMLAnchorElement>, "
|
|
84
|
+
} & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
85
85
|
linkResolver?: prismic.LinkResolverFunction | undefined;
|
|
86
86
|
rel?: string | prismic.AsLinkAttrsConfig["rel"];
|
|
87
87
|
} & {
|
|
88
88
|
field?: undefined;
|
|
89
89
|
document: prismic.PrismicDocument | null | undefined;
|
|
90
90
|
href?: undefined;
|
|
91
|
-
}, "
|
|
91
|
+
}, "ref"> | Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
92
92
|
href: string | import("url").UrlObject;
|
|
93
93
|
as?: (string | import("url").UrlObject) | undefined;
|
|
94
94
|
replace?: boolean | undefined;
|
|
@@ -116,11 +116,11 @@ export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Pick<Omit
|
|
|
116
116
|
onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
117
117
|
} & {
|
|
118
118
|
children?: React.ReactNode;
|
|
119
|
-
} & React.RefAttributes<HTMLAnchorElement>, "
|
|
119
|
+
} & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
120
120
|
linkResolver?: prismic.LinkResolverFunction | undefined;
|
|
121
121
|
rel?: string | prismic.AsLinkAttrsConfig["rel"];
|
|
122
122
|
} & {
|
|
123
123
|
field?: undefined;
|
|
124
124
|
document?: undefined;
|
|
125
125
|
href: React.ComponentProps<typeof Link>["href"];
|
|
126
|
-
}, "
|
|
126
|
+
}, "ref">) & React.RefAttributes<HTMLAnchorElement>>;
|
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -7,7 +7,11 @@ const PrismicPreviewClient = require("./PrismicPreviewClient.cjs");
|
|
|
7
7
|
const getToolbarSrc = require('./_node_modules/@prismicio/client/dist/getToolbarSrc.cjs');
|
|
8
8
|
function PrismicPreview({ repositoryName, children, ...props }) {
|
|
9
9
|
const toolbarSrc = getToolbarSrc.getToolbarSrc(repositoryName);
|
|
10
|
-
|
|
10
|
+
let isDraftMode = false;
|
|
11
|
+
try {
|
|
12
|
+
isDraftMode = headers.draftMode().isEnabled;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
11
15
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(PrismicPreviewClient.PrismicPreviewClient, { repositoryName, isDraftMode, ...props }), jsxRuntime.jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
12
16
|
}
|
|
13
17
|
exports.PrismicPreview = PrismicPreview;
|
|
@@ -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 * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","draftMode","_jsxs","_Fragment","_jsx","PrismicPreviewClient"],"mappings":";;;;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,4BAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAcC,QAAAA,UAAY,EAAA;AAAA,EAAA,QACzB;AAAA,EAID;AAGA,SAAAC,WAAA,KAAAC,qBAAA,EAAA,UAAA,CACE,UACDC,WAAAA,IAACC,qBAAA,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVD,WAAAA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;;"}
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -5,7 +5,11 @@ import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
|
|
|
5
5
|
import { getToolbarSrc } from './_node_modules/@prismicio/client/dist/getToolbarSrc.js';
|
|
6
6
|
function PrismicPreview({ repositoryName, children, ...props }) {
|
|
7
7
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
8
|
-
|
|
8
|
+
let isDraftMode = false;
|
|
9
|
+
try {
|
|
10
|
+
isDraftMode = draftMode().isEnabled;
|
|
11
|
+
} catch {
|
|
12
|
+
}
|
|
9
13
|
return jsxs(Fragment, { children: [children, jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...props }), jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
10
14
|
}
|
|
11
15
|
export {
|
|
@@ -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 * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * **Only used in the Pages Directory (/pages).**\n\t *\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\n\tlet isDraftMode = false;\n\ttry {\n\t\tisDraftMode = draftMode().isEnabled;\n\t} catch {\n\t\t// noop - `requestAsyncStorage` propbably doesn't exist, such as\n\t\t// in the Pages Router, which causes `draftMode()` to throw. We\n\t\t// can ignore this case and assume Draft Mode is disabled.\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx"],"mappings":";;;;;AAgDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,cAAsB,cAAc;AAEvD,MAAI,cAAc;AACd,MAAA;AACH,kBAAc,UAAY,EAAA;AAAA,EAAA,QACzB;AAAA,EAID;AAGA,SAAAC,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBACA,EAAA,gBACA,aAAwB,GACpB,OAAK,GAEVA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAGpD;"}
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const headers = require("next/headers");
|
|
4
|
-
|
|
4
|
+
function exitPreview(config) {
|
|
5
5
|
if (config == null ? void 0 : config.res) {
|
|
6
6
|
config.res.clearPreviewData();
|
|
7
|
-
config.res.json({ success: true });
|
|
8
7
|
config.res.setHeader("Cache-Control", "no-store");
|
|
8
|
+
config.res.json({ success: true });
|
|
9
9
|
return;
|
|
10
10
|
} else {
|
|
11
11
|
headers.draftMode().disable();
|
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 * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(config?: ExitPreviewConfig): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":["draftMode"],"mappings":";;;AA2DM,SAAU,YAAY,QAA0B;AACrD,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGNA,YAAA,UAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;;"}
|
package/dist/exitPreview.d.ts
CHANGED
package/dist/exitPreview.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { draftMode } from "next/headers";
|
|
2
|
-
|
|
2
|
+
function exitPreview(config) {
|
|
3
3
|
if (config == null ? void 0 : config.res) {
|
|
4
4
|
config.res.clearPreviewData();
|
|
5
|
-
config.res.json({ success: true });
|
|
6
5
|
config.res.setHeader("Cache-Control", "no-store");
|
|
6
|
+
config.res.json({ success: true });
|
|
7
7
|
return;
|
|
8
8
|
} else {
|
|
9
9
|
draftMode().disable();
|
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 * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport
|
|
1
|
+
{"version":3,"file":"exitPreview.js","sources":["../../src/exitPreview.ts"],"sourcesContent":["import { draftMode } from \"next/headers\";\n\nimport { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * **Only use this parameter in the Pages Directory (/pages).**\n\t *\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres?: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler or an API Route, depending on which you are using\n * the App Router or Pages Router.\n *\n * `exitPreview()` assumes Draft Mode is being used unless a Pages Router API\n * Route `res` object is provided to the function.\n *\n * @example Usage within an App Router Route Handler.\n *\n * ```typescript\n * // src/app/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \tawait exitPreview();\n * }\n * ```\n *\n * @example Usage within a Pages Router API Route.\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default async function handler(req, res) {\n * \tawait exitPreview({ req, res });\n * }\n * ```\n */\nexport function exitPreview(config?: ExitPreviewConfig): Response | void {\n\tif (config?.res) {\n\t\t// Assume Preview Mode is being used.\n\n\t\tconfig.res.clearPreviewData();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\t\tconfig.res.json({ success: true });\n\n\t\treturn;\n\t} else {\n\t\t// Assume Draft Mode is being used.\n\n\t\tdraftMode().disable();\n\n\t\t// `Cache-Control` header is used to prevent CDN-level caching.\n\t\treturn new Response(JSON.stringify({ success: true }), {\n\t\t\theaders: {\n\t\t\t\t\"Cache-Control\": \"no-store\",\n\t\t\t},\n\t\t});\n\t}\n}\n"],"names":[],"mappings":";AA2DM,SAAU,YAAY,QAA0B;AACrD,MAAI,iCAAQ,KAAK;AAGhB,WAAO,IAAI;AAGJ,WAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,WAAO,IAAI,KAAK,EAAE,SAAS,KAAM,CAAA;AAEjC;AAAA,EAAA,OACM;AAGN,cAAA,EAAY;AAGL,WAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,MACtD,SAAS;AAAA,QACR,iBAAiB;AAAA,MACjB;AAAA,IAAA,CACD;AAAA,EACD;AACF;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -52,25 +52,25 @@
|
|
|
52
52
|
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"imgix-url-builder": "^0.0.
|
|
55
|
+
"imgix-url-builder": "^0.0.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@prismicio/client": "^7.0
|
|
59
|
-
"@prismicio/mock": "^0.
|
|
58
|
+
"@prismicio/client": "^7.1.0",
|
|
59
|
+
"@prismicio/mock": "^0.3.0",
|
|
60
60
|
"@size-limit/preset-small-lib": "^8.2.4",
|
|
61
61
|
"@types/react-test-renderer": "^18.0.0",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^5.59.
|
|
63
|
-
"@typescript-eslint/parser": "^5.59.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.59.11",
|
|
63
|
+
"@typescript-eslint/parser": "^5.59.11",
|
|
64
64
|
"@vitejs/plugin-react": "^4.0.0",
|
|
65
|
-
"@vitest/coverage-
|
|
66
|
-
"eslint": "^8.
|
|
65
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
66
|
+
"eslint": "^8.42.0",
|
|
67
67
|
"eslint-config-prettier": "^8.8.0",
|
|
68
68
|
"eslint-plugin-prettier": "^4.2.1",
|
|
69
69
|
"eslint-plugin-react": "^7.32.2",
|
|
70
70
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
71
71
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
72
|
-
"happy-dom": "^9.
|
|
73
|
-
"memfs": "^3.5.
|
|
72
|
+
"happy-dom": "^9.20.3",
|
|
73
|
+
"memfs": "^3.5.3",
|
|
74
74
|
"next": "^13.4.5-canary.9",
|
|
75
75
|
"node-fetch": "^3.3.1",
|
|
76
76
|
"prettier": "^2.8.8",
|
|
@@ -78,17 +78,17 @@
|
|
|
78
78
|
"react": "^18.1.0",
|
|
79
79
|
"react-dom": "^18.2.0",
|
|
80
80
|
"react-test-renderer": "^18.2.0",
|
|
81
|
-
"rollup-plugin-preserve-directives": "^0.
|
|
81
|
+
"rollup-plugin-preserve-directives": "^0.2.0",
|
|
82
82
|
"size-limit": "^8.2.4",
|
|
83
83
|
"standard-version": "^9.5.0",
|
|
84
|
-
"typescript": "^5.
|
|
85
|
-
"vite": "^4.3.
|
|
84
|
+
"typescript": "^5.1.3",
|
|
85
|
+
"vite": "^4.3.9",
|
|
86
86
|
"vite-plugin-sdk": "^0.1.1",
|
|
87
|
-
"vitest": "^0.
|
|
87
|
+
"vitest": "^0.32.0"
|
|
88
88
|
},
|
|
89
89
|
"peerDependencies": {
|
|
90
90
|
"@prismicio/client": "^6 || ^7",
|
|
91
|
-
"next": "^13",
|
|
91
|
+
"next": "^13.4.5",
|
|
92
92
|
"react": "^18"
|
|
93
93
|
},
|
|
94
94
|
"engines": {
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -52,7 +52,15 @@ export function PrismicPreview({
|
|
|
52
52
|
...props
|
|
53
53
|
}: PrismicPreviewProps): JSX.Element {
|
|
54
54
|
const toolbarSrc = prismic.getToolbarSrc(repositoryName);
|
|
55
|
-
|
|
55
|
+
|
|
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
|
+
}
|
|
56
64
|
|
|
57
65
|
return (
|
|
58
66
|
<>
|
package/src/exitPreview.ts
CHANGED
|
@@ -57,27 +57,24 @@ export type ExitPreviewConfig = {
|
|
|
57
57
|
* }
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
export
|
|
61
|
-
config?: ExitPreviewConfig,
|
|
62
|
-
): Promise<Response | void> {
|
|
60
|
+
export function exitPreview(config?: ExitPreviewConfig): Response | void {
|
|
63
61
|
if (config?.res) {
|
|
64
62
|
// Assume Preview Mode is being used.
|
|
65
63
|
|
|
66
64
|
config.res.clearPreviewData();
|
|
67
65
|
|
|
68
|
-
//
|
|
69
|
-
// status code is typically treated as non-changing and cacheable.
|
|
70
|
-
config.res.json({ success: true });
|
|
66
|
+
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
71
67
|
config.res.setHeader("Cache-Control", "no-store");
|
|
72
68
|
|
|
69
|
+
config.res.json({ success: true });
|
|
70
|
+
|
|
73
71
|
return;
|
|
74
72
|
} else {
|
|
75
73
|
// Assume Draft Mode is being used.
|
|
76
74
|
|
|
77
75
|
draftMode().disable();
|
|
78
76
|
|
|
79
|
-
//
|
|
80
|
-
// status code is typically treated as non-changing and cacheable.
|
|
77
|
+
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
81
78
|
return new Response(JSON.stringify({ success: true }), {
|
|
82
79
|
headers: {
|
|
83
80
|
"Cache-Control": "no-store",
|