@prismicio/next 2.3.4-pr.174.890bc09 → 2.3.4-pr.175.5f9614e
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/PrismicPreview.cjs +5 -19
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts.map +1 -1
- package/dist/PrismicPreview.d.ts.map +1 -1
- package/dist/PrismicPreview.js +5 -17
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +11 -1
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +9 -1
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/exitPreview.cjs +6 -0
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts.map +1 -1
- package/dist/exitPreview.d.ts.map +1 -1
- package/dist/exitPreview.js +6 -0
- package/dist/exitPreview.js.map +1 -1
- package/dist/lib/toolbarV5.cjs +37 -0
- package/dist/lib/toolbarV5.cjs.map +1 -0
- package/dist/lib/toolbarV5.js +34 -0
- package/dist/lib/toolbarV5.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +2 -2
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts.map +1 -1
- package/dist/pages/PrismicPreview.d.ts.map +1 -1
- package/dist/pages/PrismicPreview.js +3 -3
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/appendCookie.cjs +12 -0
- package/dist/pages/appendCookie.cjs.map +1 -0
- package/dist/pages/appendCookie.js +12 -0
- package/dist/pages/appendCookie.js.map +1 -0
- package/dist/pages/exitPreview.cjs +3 -0
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts.map +1 -1
- package/dist/pages/exitPreview.d.ts.map +1 -1
- package/dist/pages/exitPreview.js +3 -0
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs +18 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/pages/redirectToPreviewURL.js +18 -1
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/types.d.cts +1 -0
- package/dist/pages/types.d.cts.map +1 -1
- package/dist/pages/types.d.ts +1 -0
- package/dist/pages/types.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.cjs +13 -3
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +1 -1
- package/dist/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.js +13 -3
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +8 -8
- package/src/PrismicPreview.tsx +0 -7
- package/src/PrismicPreviewClient.tsx +12 -1
- package/src/exitPreview.ts +3 -0
- package/src/lib/toolbarV5.ts +54 -0
- package/src/pages/PrismicPreview.tsx +7 -4
- package/src/pages/appendCookie.ts +16 -0
- package/src/pages/exitPreview.ts +3 -0
- package/src/pages/redirectToPreviewURL.ts +24 -3
- package/src/pages/types.ts +1 -0
- package/src/redirectToPreviewURL.ts +16 -10
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
3
1
|
const require_PrismicPreviewClient = require("./PrismicPreviewClient.cjs");
|
|
4
|
-
let _prismicio_client = require("@prismicio/client");
|
|
5
|
-
let next_script_js = require("next/script.js");
|
|
6
|
-
next_script_js = require_runtime.__toESM(next_script_js, 1);
|
|
7
2
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
3
|
//#region src/PrismicPreview.tsx
|
|
9
|
-
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script_js.default);
|
|
10
4
|
/**
|
|
11
5
|
* React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
|
|
12
6
|
* send events to the browser, such as on preview updates and exiting, this component will
|
|
@@ -18,20 +12,12 @@ const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_sc
|
|
|
18
12
|
const PrismicPreview = async (props) => {
|
|
19
13
|
const { repositoryName, children, ...otherProps } = props;
|
|
20
14
|
const { draftMode } = await import("next/headers.js");
|
|
21
|
-
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
|
|
22
15
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
23
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...otherProps
|
|
29
|
-
}),
|
|
30
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
|
|
31
|
-
src: toolbarSrc,
|
|
32
|
-
strategy: "lazyOnload"
|
|
33
|
-
})
|
|
34
|
-
] });
|
|
16
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicPreviewClient.PrismicPreviewClient, {
|
|
17
|
+
repositoryName,
|
|
18
|
+
isDraftMode,
|
|
19
|
+
...otherProps
|
|
20
|
+
})] });
|
|
35
21
|
};
|
|
36
22
|
//#endregion
|
|
37
23
|
exports.PrismicPreview = PrismicPreview;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","names":["
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["PrismicPreviewClient"],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\"\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\"\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered using this\n\t * repository.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be\n\t * fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be\n\t * fetched on preview exit events.\n\t */\n\texitPreviewURL?: string\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode\n}\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar\n * send events to the browser, such as on preview updates and exiting, this component will\n * automatically refresh the page with the changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's tree. It must be\n * rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\")\n\n\tconst isDraftMode = (await draftMode()).isEnabled\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{...otherProps}\n\t\t\t/>\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAoCA,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,UAAU,GAAG,eAAe;CAKpD,MAAM,EAAE,cAAc,MAAM,OAAO;CAEnC,MAAM,eAAe,MAAM,UAAU,EAAA,CAAG;CAExC,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACE,UACD,iBAAA,GAAA,kBAAA,IAAA,CAACA,6BAAAA,sBAAD;EACiB;EACH;EACb,GAAI;CACJ,CAAA,CACA,EAAA,CAAA;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.d.cts","names":[],"sources":["../src/PrismicPreview.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PrismicPreview.d.cts","names":[],"sources":["../src/PrismicPreview.tsx"],"mappings":";;;YAKY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.d.ts","names":[],"sources":["../src/PrismicPreview.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PrismicPreview.d.ts","names":[],"sources":["../src/PrismicPreview.tsx"],"mappings":";;;YAKY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { resolveDefaultExport } from "./lib/resolveDefaultExport.js";
|
|
2
1
|
import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
|
|
3
|
-
import { getToolbarSrc } from "@prismicio/client";
|
|
4
|
-
import Script from "next/script.js";
|
|
5
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
3
|
//#region src/PrismicPreview.tsx
|
|
7
|
-
const ResolvedScript = resolveDefaultExport(Script);
|
|
8
4
|
/**
|
|
9
5
|
* React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
|
|
10
6
|
* send events to the browser, such as on preview updates and exiting, this component will
|
|
@@ -16,20 +12,12 @@ const ResolvedScript = resolveDefaultExport(Script);
|
|
|
16
12
|
const PrismicPreview = async (props) => {
|
|
17
13
|
const { repositoryName, children, ...otherProps } = props;
|
|
18
14
|
const { draftMode } = await import("next/headers.js");
|
|
19
|
-
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
20
15
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
21
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
...otherProps
|
|
27
|
-
}),
|
|
28
|
-
/* @__PURE__ */ jsx(ResolvedScript, {
|
|
29
|
-
src: toolbarSrc,
|
|
30
|
-
strategy: "lazyOnload"
|
|
31
|
-
})
|
|
32
|
-
] });
|
|
16
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children, /* @__PURE__ */ jsx(PrismicPreviewClient, {
|
|
17
|
+
repositoryName,
|
|
18
|
+
isDraftMode,
|
|
19
|
+
...otherProps
|
|
20
|
+
})] });
|
|
33
21
|
};
|
|
34
22
|
//#endregion
|
|
35
23
|
export { PrismicPreview };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.js","names":[],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","names":[],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\"\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\"\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered using this\n\t * repository.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be\n\t * fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be\n\t * fetched on preview exit events.\n\t */\n\texitPreviewURL?: string\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode\n}\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar\n * send events to the browser, such as on preview updates and exiting, this component will\n * automatically refresh the page with the changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's tree. It must be\n * rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\")\n\n\tconst isDraftMode = (await draftMode()).isEnabled\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{...otherProps}\n\t\t\t/>\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAoCA,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,UAAU,GAAG,eAAe;CAKpD,MAAM,EAAE,cAAc,MAAM,OAAO;CAEnC,MAAM,eAAe,MAAM,UAAU,EAAA,CAAG;CAExC,OACC,qBAAA,UAAA,EAAA,UAAA,CACE,UACD,oBAAC,sBAAD;EACiB;EACH;EACb,GAAI;CACJ,CAAA,CACA,EAAA,CAAA;AAEJ"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_toolbarV5 = require("./lib/toolbarV5.cjs");
|
|
4
|
+
const require_resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
2
5
|
let _prismicio_client = require("@prismicio/client");
|
|
3
6
|
let next_navigation_js = require("next/navigation.js");
|
|
7
|
+
let next_script_js = require("next/script.js");
|
|
8
|
+
next_script_js = require_runtime.__toESM(next_script_js, 1);
|
|
4
9
|
let react = require("react");
|
|
10
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
11
|
//#region src/PrismicPreviewClient.tsx
|
|
12
|
+
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script_js.default);
|
|
6
13
|
const PrismicPreviewClient = (props) => {
|
|
7
14
|
const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
|
|
8
15
|
const { refresh } = (0, next_navigation_js.useRouter)();
|
|
@@ -49,7 +56,10 @@ const PrismicPreviewClient = (props) => {
|
|
|
49
56
|
exitPreviewURL,
|
|
50
57
|
refresh
|
|
51
58
|
]);
|
|
52
|
-
return
|
|
59
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
|
|
60
|
+
...require_toolbarV5.getToolbarScriptProps(repositoryName, updatePreviewURL),
|
|
61
|
+
strategy: "lazyOnload"
|
|
62
|
+
});
|
|
53
63
|
};
|
|
54
64
|
/**
|
|
55
65
|
* Returns the value of a cookie from a given cookie store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.cjs","names":["useRouter","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\"\n\nimport { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/navigation\"\nimport type { FC } from \"react\"\nimport { useEffect } from \"react\"\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string\n\tisDraftMode: boolean\n\tupdatePreviewURL?: string\n\texitPreviewURL?: string\n}\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props\n\n\tconst { refresh } = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewStart\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\tconst cookie = decodeURIComponent(getPrismicPreviewCookie(window.document.cookie) ?? \"\")\n\t\t// A raw ref, or the toolbar's JSON cookie with a preview for this repository.\n\t\tconst hasActiveCookie =\n\t\t\tcookie !== \"\" &&\n\t\t\t(!cookie.startsWith(\"{\") || cookie.includes(`\"${repositoryName}.prismic.io\"`))\n\n\t\t// Start previews that did not go through `updatePreviewURL`, like\n\t\t// share links, and restart after a preview ended in another tab.\n\t\tif (hasActiveCookie && !isDraftMode) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// A soft refresh cannot leave Next.js's not-found boundary, which renders this tag.\n\t\t\t\t\tif (document.querySelector('meta[name=\"robots\"][content=\"noindex\"]')) {\n\t\t\t\t\t\twindow.location.reload()\n\t\t\t\t\t} else {\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tif (isDraftMode) {\n\t\t\t\trefresh()\n\t\t\t} else {\n\t\t\t\tstart()\n\t\t\t}\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])\n\n\treturn
|
|
1
|
+
{"version":3,"file":"PrismicPreviewClient.cjs","names":["resolveDefaultExport","Script","useRouter","getToolbarScriptProps","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\"\n\nimport { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/navigation\"\nimport Script from \"next/script\"\nimport type { FC } from \"react\"\nimport { useEffect } from \"react\"\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\"\nimport { getToolbarScriptProps } from \"./lib/toolbarV5\"\n\nconst ResolvedScript = resolveDefaultExport(Script)\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string\n\tisDraftMode: boolean\n\tupdatePreviewURL?: string\n\texitPreviewURL?: string\n}\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props\n\n\tconst { refresh } = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewStart\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\tconst cookie = decodeURIComponent(getPrismicPreviewCookie(window.document.cookie) ?? \"\")\n\t\t// A raw ref, or the toolbar's JSON cookie with a preview for this repository.\n\t\tconst hasActiveCookie =\n\t\t\tcookie !== \"\" &&\n\t\t\t(!cookie.startsWith(\"{\") || cookie.includes(`\"${repositoryName}.prismic.io\"`))\n\n\t\t// Start previews that did not go through `updatePreviewURL`, like\n\t\t// share links, and restart after a preview ended in another tab.\n\t\tif (hasActiveCookie && !isDraftMode) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// A soft refresh cannot leave Next.js's not-found boundary, which renders this tag.\n\t\t\t\t\tif (document.querySelector('meta[name=\"robots\"][content=\"noindex\"]')) {\n\t\t\t\t\t\twindow.location.reload()\n\t\t\t\t\t} else {\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tif (isDraftMode) {\n\t\t\t\trefresh()\n\t\t\t} else {\n\t\t\t\tstart()\n\t\t\t}\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])\n\n\treturn (\n\t\t<ResolvedScript\n\t\t\t{...getToolbarScriptProps(repositoryName, updatePreviewURL)}\n\t\t\tstrategy=\"lazyOnload\"\n\t\t/>\n\t)\n}\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the cookie.\n * @returns The value of the cookie, if it exists.\n */\nfunction getPrismicPreviewCookie(cookieJar: string): string | undefined {\n\tfunction readValue(value: string): string {\n\t\treturn value.replace(/%3B/g, \";\")\n\t}\n\n\tconst cookies = cookieJar.split(\"; \")\n\n\tlet value: string | undefined\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\")\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\")\n\n\t\tif (name === prismicCookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"))\n\t\t\tcontinue\n\t\t}\n\t}\n\n\treturn value\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,iBAAiBA,6BAAAA,qBAAqBC,eAAAA,OAAM;AASlD,MAAa,wBAAuD,UAAU;CAC7E,MAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;CAEJ,MAAM,EAAE,aAAA,GAAYC,mBAAAA,UAAAA,CAAU;CAE9B,CAAA,GAAA,MAAA,UAAA,OAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBAAiB,uBAAuB,UAAU,EACxD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,OACpB,CAAC;EAED,MAAM,SAAS,mBAAmB,wBAAwB,OAAO,SAAS,MAAM,KAAK,EAAE;EAQvF,IALC,WAAW,OACV,CAAC,OAAO,WAAW,GAAG,KAAK,OAAO,SAAS,IAAI,eAAe,aAAa,MAItD,CAAC,aACvB,MAAM;EAGP,SAAS,QAAQ;GAKhB,WACE,MAAM,kBAAkB;IACxB,UAAU;IACV,QAAQ,WAAW;GACpB,CAAC,CAAC,CACD,MAAM,QAAQ;IACd,IAAI,IAAI,SAAS,kBAAkB;KAClC,QAAQ,MACP,yDAAyD,iBAAiB,kBAC3E;KAEA;IACD;IAGA,IAAI,SAAS,cAAc,4CAAwC,GAClE,OAAO,SAAS,OAAO;SAEvB,QAAQ;GAEV,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EACH;EAEA,SAAS,SAAS,OAAc;GAC/B,MAAM,eAAe;GACrB,IAAI,aACH,QAAQ;QAER,MAAM;EAER;EAEA,SAAS,MAAM,OAAc;GAC5B,MAAM,eAAe;GACrB,WACE,MAAM,gBAAgB,EAAE,QAAQ,WAAW,OAAO,CAAC,CAAC,CACpD,MAAM,QAAQ;IACd,IAAI,CAAC,IAAI,IAAI;KACZ,QAAQ,MACP,6DAA6D,eAAe,+BAC7E;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EACH;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG;EAAC;EAAgB;EAAa;EAAkB;EAAgB;CAAO,CAAC;CAE3E,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD;EACC,GAAIC,kBAAAA,sBAAsB,gBAAgB,gBAAgB;EAC1D,UAAS;CACT,CAAA;AAEH;;;;;;;AAQA,SAAS,wBAAwB,WAAuC;CACvE,SAAS,UAAU,OAAuB;EACzC,OAAO,MAAM,QAAQ,QAAQ,GAAG;CACjC;CAEA,MAAM,UAAU,UAAU,MAAM,IAAI;CAEpC,IAAI;CAEJ,KAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,QAAQ,OAAO,MAAM,GAAG;EAG9B,IAFa,UAAU,MAAM,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAE1C,MAAMC,kBAAAA,OAAc,SAAS;GACnC,QAAQ,UAAU,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;GAC1C;EACD;CACD;CAEA,OAAO;AACR"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { getToolbarScriptProps } from "./lib/toolbarV5.js";
|
|
3
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport.js";
|
|
2
4
|
import { cookie } from "@prismicio/client";
|
|
3
5
|
import { useRouter } from "next/navigation.js";
|
|
6
|
+
import Script from "next/script.js";
|
|
4
7
|
import { useEffect } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
9
|
//#region src/PrismicPreviewClient.tsx
|
|
10
|
+
const ResolvedScript = resolveDefaultExport(Script);
|
|
6
11
|
const PrismicPreviewClient = (props) => {
|
|
7
12
|
const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
|
|
8
13
|
const { refresh } = useRouter();
|
|
@@ -49,7 +54,10 @@ const PrismicPreviewClient = (props) => {
|
|
|
49
54
|
exitPreviewURL,
|
|
50
55
|
refresh
|
|
51
56
|
]);
|
|
52
|
-
return
|
|
57
|
+
return /* @__PURE__ */ jsx(ResolvedScript, {
|
|
58
|
+
...getToolbarScriptProps(repositoryName, updatePreviewURL),
|
|
59
|
+
strategy: "lazyOnload"
|
|
60
|
+
});
|
|
53
61
|
};
|
|
54
62
|
/**
|
|
55
63
|
* Returns the value of a cookie from a given cookie store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.js","names":["cookie","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\"\n\nimport { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/navigation\"\nimport type { FC } from \"react\"\nimport { useEffect } from \"react\"\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string\n\tisDraftMode: boolean\n\tupdatePreviewURL?: string\n\texitPreviewURL?: string\n}\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props\n\n\tconst { refresh } = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewStart\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\tconst cookie = decodeURIComponent(getPrismicPreviewCookie(window.document.cookie) ?? \"\")\n\t\t// A raw ref, or the toolbar's JSON cookie with a preview for this repository.\n\t\tconst hasActiveCookie =\n\t\t\tcookie !== \"\" &&\n\t\t\t(!cookie.startsWith(\"{\") || cookie.includes(`\"${repositoryName}.prismic.io\"`))\n\n\t\t// Start previews that did not go through `updatePreviewURL`, like\n\t\t// share links, and restart after a preview ended in another tab.\n\t\tif (hasActiveCookie && !isDraftMode) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// A soft refresh cannot leave Next.js's not-found boundary, which renders this tag.\n\t\t\t\t\tif (document.querySelector('meta[name=\"robots\"][content=\"noindex\"]')) {\n\t\t\t\t\t\twindow.location.reload()\n\t\t\t\t\t} else {\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tif (isDraftMode) {\n\t\t\t\trefresh()\n\t\t\t} else {\n\t\t\t\tstart()\n\t\t\t}\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])\n\n\treturn
|
|
1
|
+
{"version":3,"file":"PrismicPreviewClient.js","names":["cookie","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\"\n\nimport { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/navigation\"\nimport Script from \"next/script\"\nimport type { FC } from \"react\"\nimport { useEffect } from \"react\"\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\"\nimport { getToolbarScriptProps } from \"./lib/toolbarV5\"\n\nconst ResolvedScript = resolveDefaultExport(Script)\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string\n\tisDraftMode: boolean\n\tupdatePreviewURL?: string\n\texitPreviewURL?: string\n}\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props\n\n\tconst { refresh } = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewStart\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\tconst cookie = decodeURIComponent(getPrismicPreviewCookie(window.document.cookie) ?? \"\")\n\t\t// A raw ref, or the toolbar's JSON cookie with a preview for this repository.\n\t\tconst hasActiveCookie =\n\t\t\tcookie !== \"\" &&\n\t\t\t(!cookie.startsWith(\"{\") || cookie.includes(`\"${repositoryName}.prismic.io\"`))\n\n\t\t// Start previews that did not go through `updatePreviewURL`, like\n\t\t// share links, and restart after a preview ended in another tab.\n\t\tif (hasActiveCookie && !isDraftMode) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\t// A soft refresh cannot leave Next.js's not-found boundary, which renders this tag.\n\t\t\t\t\tif (document.querySelector('meta[name=\"robots\"][content=\"noindex\"]')) {\n\t\t\t\t\t\twindow.location.reload()\n\t\t\t\t\t} else {\n\t\t\t\t\t\trefresh()\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tif (isDraftMode) {\n\t\t\t\trefresh()\n\t\t\t} else {\n\t\t\t\tstart()\n\t\t\t}\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t})\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])\n\n\treturn (\n\t\t<ResolvedScript\n\t\t\t{...getToolbarScriptProps(repositoryName, updatePreviewURL)}\n\t\t\tstrategy=\"lazyOnload\"\n\t\t/>\n\t)\n}\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the cookie.\n * @returns The value of the cookie, if it exists.\n */\nfunction getPrismicPreviewCookie(cookieJar: string): string | undefined {\n\tfunction readValue(value: string): string {\n\t\treturn value.replace(/%3B/g, \";\")\n\t}\n\n\tconst cookies = cookieJar.split(\"; \")\n\n\tlet value: string | undefined\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\")\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\")\n\n\t\tif (name === prismicCookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"))\n\t\t\tcontinue\n\t\t}\n\t}\n\n\treturn value\n}\n"],"mappings":";;;;;;;;;AAWA,MAAM,iBAAiB,qBAAqB,MAAM;AASlD,MAAa,wBAAuD,UAAU;CAC7E,MAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;CAEJ,MAAM,EAAE,YAAY,UAAU;CAE9B,gBAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBAAiB,uBAAuB,UAAU,EACxD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,OACpB,CAAC;EAED,MAAM,SAAS,mBAAmB,wBAAwB,OAAO,SAAS,MAAM,KAAK,EAAE;EAQvF,IALC,WAAW,OACV,CAAC,OAAO,WAAW,GAAG,KAAK,OAAO,SAAS,IAAI,eAAe,aAAa,MAItD,CAAC,aACvB,MAAM;EAGP,SAAS,QAAQ;GAKhB,WACE,MAAM,kBAAkB;IACxB,UAAU;IACV,QAAQ,WAAW;GACpB,CAAC,CAAC,CACD,MAAM,QAAQ;IACd,IAAI,IAAI,SAAS,kBAAkB;KAClC,QAAQ,MACP,yDAAyD,iBAAiB,kBAC3E;KAEA;IACD;IAGA,IAAI,SAAS,cAAc,4CAAwC,GAClE,OAAO,SAAS,OAAO;SAEvB,QAAQ;GAEV,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EACH;EAEA,SAAS,SAAS,OAAc;GAC/B,MAAM,eAAe;GACrB,IAAI,aACH,QAAQ;QAER,MAAM;EAER;EAEA,SAAS,MAAM,OAAc;GAC5B,MAAM,eAAe;GACrB,WACE,MAAM,gBAAgB,EAAE,QAAQ,WAAW,OAAO,CAAC,CAAC,CACpD,MAAM,QAAQ;IACd,IAAI,CAAC,IAAI,IAAI;KACZ,QAAQ,MACP,6DAA6D,eAAe,+BAC7E;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EACH;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG;EAAC;EAAgB;EAAa;EAAkB;EAAgB;CAAO,CAAC;CAE3E,OACC,oBAAC,gBAAD;EACC,GAAI,sBAAsB,gBAAgB,gBAAgB;EAC1D,UAAS;CACT,CAAA;AAEH;;;;;;;AAQA,SAAS,wBAAwB,WAAuC;CACvE,SAAS,UAAU,OAAuB;EACzC,OAAO,MAAM,QAAQ,QAAQ,GAAG;CACjC;CAEA,MAAM,UAAU,UAAU,MAAM,IAAI;CAEpC,IAAI;CAEJ,KAAK,MAAMA,YAAU,SAAS;EAC7B,MAAM,QAAQA,SAAO,MAAM,GAAG;EAG9B,IAFa,UAAU,MAAM,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAE1C,MAAMC,OAAc,SAAS;GACnC,QAAQ,UAAU,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;GAC1C;EACD;CACD;CAEA,OAAO;AACR"}
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_toolbarV5 = require("./lib/toolbarV5.cjs");
|
|
1
2
|
let _prismicio_client = require("@prismicio/client");
|
|
2
3
|
//#region src/exitPreview.ts
|
|
3
4
|
/**
|
|
@@ -28,6 +29,11 @@ async function exitPreview() {
|
|
|
28
29
|
sameSite: "none",
|
|
29
30
|
secure: true
|
|
30
31
|
});
|
|
32
|
+
cookieJar.delete({
|
|
33
|
+
name: require_toolbarV5.previewSessionCookie,
|
|
34
|
+
sameSite: "none",
|
|
35
|
+
secure: true
|
|
36
|
+
});
|
|
31
37
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
32
38
|
}
|
|
33
39
|
//#endregion
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":["prismicCookie","previewSessionCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewSessionCookie } from \"./lib/toolbarV5\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: previewSessionCookie, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAEjC,MAAM,YAAY,MAAM,QAAQ;CAChC,UAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAC/E,UAAU,OAAO;EAAE,MAAMA,kBAAAA,OAAc;EAAS,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAChF,UAAU,OAAO;EAAE,MAAMC,kBAAAA;EAAsB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAG/E,OAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAK,CAAC,GAAG,EACtD,SAAS,EACR,iBAAiB,WAClB,EACD,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;;;;;;;;;;;;;;;wBAmBsB,eAAe,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;;;;;;;;;;;;;;;wBAmBsB,eAAe,QAAQ"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { previewSessionCookie } from "./lib/toolbarV5.js";
|
|
1
2
|
import { cookie } from "@prismicio/client";
|
|
2
3
|
//#region src/exitPreview.ts
|
|
3
4
|
/**
|
|
@@ -28,6 +29,11 @@ async function exitPreview() {
|
|
|
28
29
|
sameSite: "none",
|
|
29
30
|
secure: true
|
|
30
31
|
});
|
|
32
|
+
cookieJar.delete({
|
|
33
|
+
name: previewSessionCookie,
|
|
34
|
+
sameSite: "none",
|
|
35
|
+
secure: true
|
|
36
|
+
});
|
|
31
37
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
32
38
|
}
|
|
33
39
|
//#endregion
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewSessionCookie } from \"./lib/toolbarV5\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: previewSessionCookie, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAEjC,MAAM,YAAY,MAAM,QAAQ;CAChC,UAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAC/E,UAAU,OAAO;EAAE,MAAMA,OAAc;EAAS,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAChF,UAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAG/E,OAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAK,CAAC,GAAG,EACtD,SAAS,EACR,iBAAiB,WAClB,EACD,CAAC;AACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
let _prismicio_client = require("@prismicio/client");
|
|
2
|
+
//#region src/lib/toolbarV5.ts
|
|
3
|
+
/** The cookie storing the preview session ID. The toolbar's v5 flow follows this session. */
|
|
4
|
+
const previewSessionCookie = "io.prismic.previewSession";
|
|
5
|
+
/**
|
|
6
|
+
* Props for the toolbar's `<script>`, opting into its v5 flow.
|
|
7
|
+
*
|
|
8
|
+
* @param previewURL - The app's preview route, as passed to `fetch()`.
|
|
9
|
+
*/
|
|
10
|
+
function getToolbarScriptProps(repositoryName, previewURL) {
|
|
11
|
+
return {
|
|
12
|
+
src: `${(0, _prismicio_client.getToolbarSrc)(repositoryName)}&v=5`,
|
|
13
|
+
"data-preview-url": typeof window === "undefined" ? void 0 : new URL(previewURL, document.baseURI).href
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Fetches the current ref of a preview session, for share links that only carry the session. */
|
|
17
|
+
async function getPreviewSessionRef(client, session) {
|
|
18
|
+
const url = new URL(`/previews/token/${encodeURIComponent(session)}`, client.documentAPIEndpoint);
|
|
19
|
+
url.hostname = url.hostname.replace(".cdn.", ".");
|
|
20
|
+
const json = await (await fetch(url, { cache: "no-store" })).json();
|
|
21
|
+
if (!json.ref) throw new _prismicio_client.PreviewTokenExpiredError("This preview session has expired", url.href, json);
|
|
22
|
+
return json.ref;
|
|
23
|
+
}
|
|
24
|
+
/** Returns `path` if it is a path on the same origin, like `/blog?page=2`. */
|
|
25
|
+
function getSafePath(path) {
|
|
26
|
+
if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) return;
|
|
27
|
+
const origin = "https://placeholder.invalid";
|
|
28
|
+
const url = new URL(path, origin);
|
|
29
|
+
if (url.origin === origin) return url.href.slice(27);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.getPreviewSessionRef = getPreviewSessionRef;
|
|
33
|
+
exports.getSafePath = getSafePath;
|
|
34
|
+
exports.getToolbarScriptProps = getToolbarScriptProps;
|
|
35
|
+
exports.previewSessionCookie = previewSessionCookie;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=toolbarV5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbarV5.cjs","names":["getToolbarSrc","PreviewTokenExpiredError"],"sources":["../../src/lib/toolbarV5.ts"],"sourcesContent":["import { getToolbarSrc, PreviewTokenExpiredError, type Client } from \"@prismicio/client\"\n\n/** The cookie storing the preview session ID. The toolbar's v5 flow follows this session. */\nexport const previewSessionCookie = \"io.prismic.previewSession\"\n\n/**\n * Props for the toolbar's `<script>`, opting into its v5 flow.\n *\n * @param previewURL - The app's preview route, as passed to `fetch()`.\n */\nexport function getToolbarScriptProps(\n\trepositoryName: string,\n\tpreviewURL: string,\n): { src: string; \"data-preview-url\"?: string } {\n\treturn {\n\t\t// TODO: Use `getToolbarSrc()` once `@prismicio/client` adds `v=5`.\n\t\tsrc: `${getToolbarSrc(repositoryName)}&v=5`,\n\t\t// The toolbar builds share links with this URL. `next/script` adds `lazyOnload` scripts in\n\t\t// the browser, where the URL is known.\n\t\t\"data-preview-url\":\n\t\t\ttypeof window === \"undefined\" ? undefined : new URL(previewURL, document.baseURI).href,\n\t}\n}\n\n/** Fetches the current ref of a preview session, for share links that only carry the session. */\nexport async function getPreviewSessionRef(\n\tclient: Pick<Client, \"documentAPIEndpoint\">,\n\tsession: string,\n): Promise<string> {\n\tconst url = new URL(`/previews/token/${encodeURIComponent(session)}`, client.documentAPIEndpoint)\n\t// The endpoint is on the repository host, not on its CDN.\n\turl.hostname = url.hostname.replace(\".cdn.\", \".\")\n\tconst res = await fetch(url, { cache: \"no-store\" })\n\tconst json = await res.json()\n\tif (!json.ref) {\n\t\t// Like the Content API's response to an expired preview token.\n\t\tthrow new PreviewTokenExpiredError(\"This preview session has expired\", url.href, json)\n\t}\n\n\treturn json.ref\n}\n\n/** Returns `path` if it is a path on the same origin, like `/blog?page=2`. */\nexport function getSafePath(path: string | undefined | null): string | undefined {\n\tif (!path?.startsWith(\"/\") || path.startsWith(\"//\") || path.startsWith(\"/\\\\\")) {\n\t\treturn\n\t}\n\n\tconst origin = \"https://placeholder.invalid\"\n\tconst url = new URL(path, origin)\n\tif (url.origin === origin) {\n\t\treturn url.href.slice(origin.length)\n\t}\n}\n"],"mappings":";;;AAGA,MAAa,uBAAuB;;;;;;AAOpC,SAAgB,sBACf,gBACA,YAC+C;CAC/C,OAAO;EAEN,KAAK,IAAA,GAAGA,kBAAAA,cAAAA,CAAc,cAAc,EAAE;EAGtC,oBACC,OAAO,WAAW,cAAc,KAAA,IAAY,IAAI,IAAI,YAAY,SAAS,OAAO,CAAC,CAAC;CACpF;AACD;;AAGA,eAAsB,qBACrB,QACA,SACkB;CAClB,MAAM,MAAM,IAAI,IAAI,mBAAmB,mBAAmB,OAAO,KAAK,OAAO,mBAAmB;CAEhG,IAAI,WAAW,IAAI,SAAS,QAAQ,SAAS,GAAG;CAEhD,MAAM,OAAO,OAAM,MADD,MAAM,KAAK,EAAE,OAAO,WAAW,CAAC,EAAA,CAC3B,KAAK;CAC5B,IAAI,CAAC,KAAK,KAET,MAAM,IAAIC,kBAAAA,yBAAyB,oCAAoC,IAAI,MAAM,IAAI;CAGtF,OAAO,KAAK;AACb;;AAGA,SAAgB,YAAY,MAAqD;CAChF,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK,GAC3E;CAGD,MAAM,SAAS;CACf,MAAM,MAAM,IAAI,IAAI,MAAM,MAAM;CAChC,IAAI,IAAI,WAAW,QAClB,OAAO,IAAI,KAAK,MAAM,EAAa;AAErC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PreviewTokenExpiredError, getToolbarSrc } from "@prismicio/client";
|
|
2
|
+
//#region src/lib/toolbarV5.ts
|
|
3
|
+
/** The cookie storing the preview session ID. The toolbar's v5 flow follows this session. */
|
|
4
|
+
const previewSessionCookie = "io.prismic.previewSession";
|
|
5
|
+
/**
|
|
6
|
+
* Props for the toolbar's `<script>`, opting into its v5 flow.
|
|
7
|
+
*
|
|
8
|
+
* @param previewURL - The app's preview route, as passed to `fetch()`.
|
|
9
|
+
*/
|
|
10
|
+
function getToolbarScriptProps(repositoryName, previewURL) {
|
|
11
|
+
return {
|
|
12
|
+
src: `${getToolbarSrc(repositoryName)}&v=5`,
|
|
13
|
+
"data-preview-url": typeof window === "undefined" ? void 0 : new URL(previewURL, document.baseURI).href
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Fetches the current ref of a preview session, for share links that only carry the session. */
|
|
17
|
+
async function getPreviewSessionRef(client, session) {
|
|
18
|
+
const url = new URL(`/previews/token/${encodeURIComponent(session)}`, client.documentAPIEndpoint);
|
|
19
|
+
url.hostname = url.hostname.replace(".cdn.", ".");
|
|
20
|
+
const json = await (await fetch(url, { cache: "no-store" })).json();
|
|
21
|
+
if (!json.ref) throw new PreviewTokenExpiredError("This preview session has expired", url.href, json);
|
|
22
|
+
return json.ref;
|
|
23
|
+
}
|
|
24
|
+
/** Returns `path` if it is a path on the same origin, like `/blog?page=2`. */
|
|
25
|
+
function getSafePath(path) {
|
|
26
|
+
if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) return;
|
|
27
|
+
const origin = "https://placeholder.invalid";
|
|
28
|
+
const url = new URL(path, origin);
|
|
29
|
+
if (url.origin === origin) return url.href.slice(27);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { getPreviewSessionRef, getSafePath, getToolbarScriptProps, previewSessionCookie };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=toolbarV5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolbarV5.js","names":[],"sources":["../../src/lib/toolbarV5.ts"],"sourcesContent":["import { getToolbarSrc, PreviewTokenExpiredError, type Client } from \"@prismicio/client\"\n\n/** The cookie storing the preview session ID. The toolbar's v5 flow follows this session. */\nexport const previewSessionCookie = \"io.prismic.previewSession\"\n\n/**\n * Props for the toolbar's `<script>`, opting into its v5 flow.\n *\n * @param previewURL - The app's preview route, as passed to `fetch()`.\n */\nexport function getToolbarScriptProps(\n\trepositoryName: string,\n\tpreviewURL: string,\n): { src: string; \"data-preview-url\"?: string } {\n\treturn {\n\t\t// TODO: Use `getToolbarSrc()` once `@prismicio/client` adds `v=5`.\n\t\tsrc: `${getToolbarSrc(repositoryName)}&v=5`,\n\t\t// The toolbar builds share links with this URL. `next/script` adds `lazyOnload` scripts in\n\t\t// the browser, where the URL is known.\n\t\t\"data-preview-url\":\n\t\t\ttypeof window === \"undefined\" ? undefined : new URL(previewURL, document.baseURI).href,\n\t}\n}\n\n/** Fetches the current ref of a preview session, for share links that only carry the session. */\nexport async function getPreviewSessionRef(\n\tclient: Pick<Client, \"documentAPIEndpoint\">,\n\tsession: string,\n): Promise<string> {\n\tconst url = new URL(`/previews/token/${encodeURIComponent(session)}`, client.documentAPIEndpoint)\n\t// The endpoint is on the repository host, not on its CDN.\n\turl.hostname = url.hostname.replace(\".cdn.\", \".\")\n\tconst res = await fetch(url, { cache: \"no-store\" })\n\tconst json = await res.json()\n\tif (!json.ref) {\n\t\t// Like the Content API's response to an expired preview token.\n\t\tthrow new PreviewTokenExpiredError(\"This preview session has expired\", url.href, json)\n\t}\n\n\treturn json.ref\n}\n\n/** Returns `path` if it is a path on the same origin, like `/blog?page=2`. */\nexport function getSafePath(path: string | undefined | null): string | undefined {\n\tif (!path?.startsWith(\"/\") || path.startsWith(\"//\") || path.startsWith(\"/\\\\\")) {\n\t\treturn\n\t}\n\n\tconst origin = \"https://placeholder.invalid\"\n\tconst url = new URL(path, origin)\n\tif (url.origin === origin) {\n\t\treturn url.href.slice(origin.length)\n\t}\n}\n"],"mappings":";;;AAGA,MAAa,uBAAuB;;;;;;AAOpC,SAAgB,sBACf,gBACA,YAC+C;CAC/C,OAAO;EAEN,KAAK,GAAG,cAAc,cAAc,EAAE;EAGtC,oBACC,OAAO,WAAW,cAAc,KAAA,IAAY,IAAI,IAAI,YAAY,SAAS,OAAO,CAAC,CAAC;CACpF;AACD;;AAGA,eAAsB,qBACrB,QACA,SACkB;CAClB,MAAM,MAAM,IAAI,IAAI,mBAAmB,mBAAmB,OAAO,KAAK,OAAO,mBAAmB;CAEhG,IAAI,WAAW,IAAI,SAAS,QAAQ,SAAS,GAAG;CAEhD,MAAM,OAAO,OAAM,MADD,MAAM,KAAK,EAAE,OAAO,WAAW,CAAC,EAAA,CAC3B,KAAK;CAC5B,IAAI,CAAC,KAAK,KAET,MAAM,IAAI,yBAAyB,oCAAoC,IAAI,MAAM,IAAI;CAGtF,OAAO,KAAK;AACb;;AAGA,SAAgB,YAAY,MAAqD;CAChF,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK,GAC3E;CAGD,MAAM,SAAS;CACf,MAAM,MAAM,IAAI,IAAI,MAAM,MAAM;CAChC,IAAI,IAAI,WAAW,QAClB,OAAO,IAAI,KAAK,MAAM,EAAa;AAErC"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_toolbarV5 = require("../lib/toolbarV5.cjs");
|
|
2
3
|
let _prismicio_client = require("@prismicio/client");
|
|
3
4
|
let next_script_js = require("next/script.js");
|
|
4
5
|
next_script_js = require_runtime.__toESM(next_script_js, 1);
|
|
@@ -17,7 +18,6 @@ let next_router_js = require("next/router.js");
|
|
|
17
18
|
const PrismicPreview = (props) => {
|
|
18
19
|
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
19
20
|
const router = (0, next_router_js.useRouter)();
|
|
20
|
-
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
|
|
21
21
|
(0, react.useEffect)(() => {
|
|
22
22
|
const controller = new AbortController();
|
|
23
23
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
@@ -60,7 +60,7 @@ const PrismicPreview = (props) => {
|
|
|
60
60
|
router
|
|
61
61
|
]);
|
|
62
62
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_script_js.default, {
|
|
63
|
-
|
|
63
|
+
...require_toolbarV5.getToolbarScriptProps(repositoryName, router.basePath + updatePreviewURL),
|
|
64
64
|
strategy: "lazyOnload"
|
|
65
65
|
})] });
|
|
66
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","names":["useRouter","
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["useRouter","Script","getToolbarScriptProps","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/router\"\nimport Script from \"next/script\"\nimport type { FC } from \"react\"\nimport { type ReactNode, useEffect } from \"react\"\n\nimport { getToolbarScriptProps } from \"../lib/toolbarV5\"\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered using this\n\t * repository.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be\n\t * fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be\n\t * fetched on preview exit events.\n\t */\n\texitPreviewURL?: string\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode\n}\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar\n * send events to the browser, such as on preview updates and exiting, this component will\n * automatically refresh the page with the changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's tree. It must be\n * rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t\tchildren,\n\t} = props\n\n\tconst router = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\t//\n\t\t// We check that the current URL is a descendant of the base\n\t\t// path to prevent infinite refrehes.\n\t\tif (\n\t\t\twindow.location.href.startsWith(window.location.origin + router.basePath) &&\n\t\t\tgetPreviewCookieRepositoryName() === repositoryName &&\n\t\t\t!router.isPreview\n\t\t) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tfetch(router.basePath + exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and at least\n\t\t\t// attempted to set preview data.\n\t\t\tfetch(router.basePath + updatePreviewURL, {\n\t\t\t\tredirect: \"manual\",\n\t\t\t\tsignal: controller.signal,\n\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start or update the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\n\t\tfunction refresh() {\n\t\t\trouter.replace(router.asPath, undefined, { scroll: false })\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [exitPreviewURL, updatePreviewURL, repositoryName, router])\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script\n\t\t\t\t{...getToolbarScriptProps(repositoryName, router.basePath + updatePreviewURL)}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t/>\n\t\t</>\n\t)\n}\n\nfunction getPreviewCookieRepositoryName() {\n\tconst cookie = window.document.cookie\n\t\t.split(\"; \")\n\t\t.find((row) => row.startsWith(`${prismicCookie.preview}=`))\n\t\t?.split(\"=\")[1]\n\n\treturn (decodeURIComponent(cookie ?? \"\").match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwCA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;CAEJ,MAAM,UAAA,GAASA,eAAAA,UAAAA,CAAU;CAEzB,CAAA,GAAA,MAAA,UAAA,OAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,OACpB,CAAC;EAQD,IACC,OAAO,SAAS,KAAK,WAAW,OAAO,SAAS,SAAS,OAAO,QAAQ,KACxE,+BAA+B,MAAM,kBACrC,CAAC,OAAO,WAER,MAAM;EAGP,SAAS,MAAM,OAAc;GAC5B,MAAM,eAAe;GACrB,MAAM,OAAO,WAAW,gBAAgB,EAAE,QAAQ,WAAW,OAAO,CAAC,CAAC,CACpE,MAAM,QAAQ;IACd,IAAI,CAAC,IAAI,IAAI;KACZ,QAAQ,MACP,6DAA6D,eAAe,+BAC7E;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACjB;EAEA,SAAS,SAAS,OAAc;GAC/B,MAAM,eAAe;GACrB,MAAM;EACP;EAEA,SAAS,QAAQ;GAKhB,MAAM,OAAO,WAAW,kBAAkB;IACzC,UAAU;IACV,QAAQ,WAAW;GACpB,CAAC,CAAC,CACA,MAAM,QAAQ;IACd,IAAI,IAAI,SAAS,kBAAkB;KAClC,QAAQ,MACP,mEAAmE,iBAAiB,kBACrF;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACjB;EAEA,SAAS,UAAU;GAClB,OAAO,QAAQ,OAAO,QAAQ,KAAA,GAAW,EAAE,QAAQ,MAAM,CAAC;EAC3D;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG;EAAC;EAAgB;EAAkB;EAAgB;CAAM,CAAC;CAE7D,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACE,UACD,iBAAA,GAAA,kBAAA,IAAA,CAACC,eAAAA,SAAD;EACC,GAAIC,kBAAAA,sBAAsB,gBAAgB,OAAO,WAAW,gBAAgB;EAC5E,UAAS;CACT,CAAA,CACA,EAAA,CAAA;AAEJ;AAEA,SAAS,iCAAiC;CACzC,MAAM,SAAS,OAAO,SAAS,OAC7B,MAAM,IAAI,CAAC,CACX,MAAM,QAAQ,IAAI,WAAW,GAAGC,kBAAAA,OAAc,QAAQ,EAAE,CAAC,CAAC,EACzD,MAAM,GAAG,CAAC,CAAC;CAEd,QAAQ,mBAAmB,UAAU,EAAE,CAAC,CAAC,MAAM,wBAAwB,KAAK,CAAC,EAAA,CAAG;AACjF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.d.cts","names":[],"sources":["../../src/pages/PrismicPreview.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PrismicPreview.d.cts","names":[],"sources":["../../src/pages/PrismicPreview.tsx"],"mappings":";;;YASY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.d.ts","names":[],"sources":["../../src/pages/PrismicPreview.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PrismicPreview.d.ts","names":[],"sources":["../../src/pages/PrismicPreview.tsx"],"mappings":";;;YASY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getToolbarScriptProps } from "../lib/toolbarV5.js";
|
|
2
|
+
import { cookie } from "@prismicio/client";
|
|
2
3
|
import Script from "next/script.js";
|
|
3
4
|
import { useEffect } from "react";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -15,7 +16,6 @@ import { useRouter } from "next/router.js";
|
|
|
15
16
|
const PrismicPreview = (props) => {
|
|
16
17
|
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
17
18
|
const router = useRouter();
|
|
18
|
-
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
const controller = new AbortController();
|
|
21
21
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
@@ -58,7 +58,7 @@ const PrismicPreview = (props) => {
|
|
|
58
58
|
router
|
|
59
59
|
]);
|
|
60
60
|
return /* @__PURE__ */ jsxs(Fragment, { children: [children, /* @__PURE__ */ jsx(Script, {
|
|
61
|
-
|
|
61
|
+
...getToolbarScriptProps(repositoryName, router.basePath + updatePreviewURL),
|
|
62
62
|
strategy: "lazyOnload"
|
|
63
63
|
})] });
|
|
64
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.js","names":["cookie","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","names":["cookie","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\nimport { useRouter } from \"next/router\"\nimport Script from \"next/script\"\nimport type { FC } from \"react\"\nimport { type ReactNode, useEffect } from \"react\"\n\nimport { getToolbarScriptProps } from \"../lib/toolbarV5\"\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered using this\n\t * repository.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be\n\t * fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be\n\t * fetched on preview exit events.\n\t */\n\texitPreviewURL?: string\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode\n}\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar\n * send events to the browser, such as on preview updates and exiting, this component will\n * automatically refresh the page with the changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's tree. It must be\n * rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t\tchildren,\n\t} = props\n\n\tconst router = useRouter()\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t})\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\t//\n\t\t// We check that the current URL is a descendant of the base\n\t\t// path to prevent infinite refrehes.\n\t\tif (\n\t\t\twindow.location.href.startsWith(window.location.origin + router.basePath) &&\n\t\t\tgetPreviewCookieRepositoryName() === repositoryName &&\n\t\t\t!router.isPreview\n\t\t) {\n\t\t\tstart()\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tfetch(router.basePath + exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\tstart()\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and at least\n\t\t\t// attempted to set preview data.\n\t\t\tfetch(router.basePath + updatePreviewURL, {\n\t\t\t\tredirect: \"manual\",\n\t\t\t\tsignal: controller.signal,\n\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start or update the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh()\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t}\n\n\t\tfunction refresh() {\n\t\t\trouter.replace(router.asPath, undefined, { scroll: false })\n\t\t}\n\n\t\treturn () => controller.abort()\n\t}, [exitPreviewURL, updatePreviewURL, repositoryName, router])\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script\n\t\t\t\t{...getToolbarScriptProps(repositoryName, router.basePath + updatePreviewURL)}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t/>\n\t\t</>\n\t)\n}\n\nfunction getPreviewCookieRepositoryName() {\n\tconst cookie = window.document.cookie\n\t\t.split(\"; \")\n\t\t.find((row) => row.startsWith(`${prismicCookie.preview}=`))\n\t\t?.split(\"=\")[1]\n\n\treturn (decodeURIComponent(cookie ?? \"\").match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n}\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;CAEJ,MAAM,SAAS,UAAU;CAEzB,gBAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,OACpB,CAAC;EACD,OAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,OACpB,CAAC;EAQD,IACC,OAAO,SAAS,KAAK,WAAW,OAAO,SAAS,SAAS,OAAO,QAAQ,KACxE,+BAA+B,MAAM,kBACrC,CAAC,OAAO,WAER,MAAM;EAGP,SAAS,MAAM,OAAc;GAC5B,MAAM,eAAe;GACrB,MAAM,OAAO,WAAW,gBAAgB,EAAE,QAAQ,WAAW,OAAO,CAAC,CAAC,CACpE,MAAM,QAAQ;IACd,IAAI,CAAC,IAAI,IAAI;KACZ,QAAQ,MACP,6DAA6D,eAAe,+BAC7E;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACjB;EAEA,SAAS,SAAS,OAAc;GAC/B,MAAM,eAAe;GACrB,MAAM;EACP;EAEA,SAAS,QAAQ;GAKhB,MAAM,OAAO,WAAW,kBAAkB;IACzC,UAAU;IACV,QAAQ,WAAW;GACpB,CAAC,CAAC,CACA,MAAM,QAAQ;IACd,IAAI,IAAI,SAAS,kBAAkB;KAClC,QAAQ,MACP,mEAAmE,iBAAiB,kBACrF;KAEA;IACD;IAEA,QAAQ;GACT,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACjB;EAEA,SAAS,UAAU;GAClB,OAAO,QAAQ,OAAO,QAAQ,KAAA,GAAW,EAAE,QAAQ,MAAM,CAAC;EAC3D;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG;EAAC;EAAgB;EAAkB;EAAgB;CAAM,CAAC;CAE7D,OACC,qBAAA,UAAA,EAAA,UAAA,CACE,UACD,oBAAC,QAAD;EACC,GAAI,sBAAsB,gBAAgB,OAAO,WAAW,gBAAgB;EAC5E,UAAS;CACT,CAAA,CACA,EAAA,CAAA;AAEJ;AAEA,SAAS,iCAAiC;CACzC,MAAMA,WAAS,OAAO,SAAS,OAC7B,MAAM,IAAI,CAAC,CACX,MAAM,QAAQ,IAAI,WAAW,GAAGC,OAAc,QAAQ,EAAE,CAAC,CAAC,EACzD,MAAM,GAAG,CAAC,CAAC;CAEd,QAAQ,mBAAmBD,YAAU,EAAE,CAAC,CAAC,MAAM,wBAAwB,KAAK,CAAC,EAAA,CAAG;AACjF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/pages/appendCookie.ts
|
|
2
|
+
/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */
|
|
3
|
+
function appendCookie(res, name, value, expires) {
|
|
4
|
+
const previous = res.getHeader("Set-Cookie") ?? [];
|
|
5
|
+
let cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=None; Secure`;
|
|
6
|
+
if (expires) cookie += `; Expires=${expires.toUTCString()}`;
|
|
7
|
+
res.setHeader("Set-Cookie", [...[previous].flat().map(String), cookie]);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.appendCookie = appendCookie;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=appendCookie.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendCookie.cjs","names":[],"sources":["../../src/pages/appendCookie.ts"],"sourcesContent":["import type { NextApiResponseLike } from \"./types\"\n\n/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */\nexport function appendCookie(\n\tres: NextApiResponseLike,\n\tname: string,\n\tvalue: string,\n\texpires?: Date,\n): void {\n\tconst previous = res.getHeader(\"Set-Cookie\") ?? []\n\tlet cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=None; Secure`\n\tif (expires) {\n\t\tcookie += `; Expires=${expires.toUTCString()}`\n\t}\n\tres.setHeader(\"Set-Cookie\", [...[previous].flat().map(String), cookie])\n}\n"],"mappings":";;AAGA,SAAgB,aACf,KACA,MACA,OACA,SACO;CACP,MAAM,WAAW,IAAI,UAAU,YAAY,KAAK,CAAC;CACjD,IAAI,SAAS,GAAG,KAAK,GAAG,mBAAmB,KAAK,EAAE;CAClD,IAAI,SACH,UAAU,aAAa,QAAQ,YAAY;CAE5C,IAAI,UAAU,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,GAAG,MAAM,CAAC;AACvE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/pages/appendCookie.ts
|
|
2
|
+
/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */
|
|
3
|
+
function appendCookie(res, name, value, expires) {
|
|
4
|
+
const previous = res.getHeader("Set-Cookie") ?? [];
|
|
5
|
+
let cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=None; Secure`;
|
|
6
|
+
if (expires) cookie += `; Expires=${expires.toUTCString()}`;
|
|
7
|
+
res.setHeader("Set-Cookie", [...[previous].flat().map(String), cookie]);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { appendCookie };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=appendCookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendCookie.js","names":[],"sources":["../../src/pages/appendCookie.ts"],"sourcesContent":["import type { NextApiResponseLike } from \"./types\"\n\n/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */\nexport function appendCookie(\n\tres: NextApiResponseLike,\n\tname: string,\n\tvalue: string,\n\texpires?: Date,\n): void {\n\tconst previous = res.getHeader(\"Set-Cookie\") ?? []\n\tlet cookie = `${name}=${encodeURIComponent(value)}; Path=/; SameSite=None; Secure`\n\tif (expires) {\n\t\tcookie += `; Expires=${expires.toUTCString()}`\n\t}\n\tres.setHeader(\"Set-Cookie\", [...[previous].flat().map(String), cookie])\n}\n"],"mappings":";;AAGA,SAAgB,aACf,KACA,MACA,OACA,SACO;CACP,MAAM,WAAW,IAAI,UAAU,YAAY,KAAK,CAAC;CACjD,IAAI,SAAS,GAAG,KAAK,GAAG,mBAAmB,KAAK,EAAE;CAClD,IAAI,SACH,UAAU,aAAa,QAAQ,YAAY;CAE5C,IAAI,UAAU,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,GAAG,MAAM,CAAC;AACvE"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const require_toolbarV5 = require("../lib/toolbarV5.cjs");
|
|
2
|
+
const require_appendCookie = require("./appendCookie.cjs");
|
|
1
3
|
//#region src/pages/exitPreview.ts
|
|
2
4
|
/**
|
|
3
5
|
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
@@ -16,6 +18,7 @@
|
|
|
16
18
|
*/
|
|
17
19
|
function exitPreview(config) {
|
|
18
20
|
config.res.clearPreviewData();
|
|
21
|
+
require_appendCookie.appendCookie(config.res, require_toolbarV5.previewSessionCookie, "", /* @__PURE__ */ new Date(0));
|
|
19
22
|
config.res.setHeader("Cache-Control", "no-store");
|
|
20
23
|
config.res.json({ success: true });
|
|
21
24
|
}
|