@prismicio/next 2.3.4-pr.175.5f9614e → 2.3.4-pr.175.88bf097
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 +22 -6
- 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 +20 -6
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +1 -11
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +1 -9
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/exitPreview.cjs +1 -2
- 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 +1 -2
- package/dist/exitPreview.js.map +1 -1
- package/dist/lib/getSafePath.cjs +21 -0
- package/dist/lib/getSafePath.cjs.map +1 -0
- package/dist/lib/getSafePath.js +21 -0
- package/dist/lib/getSafePath.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +4 -3
- 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 +5 -4
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/appendCookie.cjs +2 -4
- package/dist/pages/appendCookie.cjs.map +1 -1
- package/dist/pages/appendCookie.js +2 -4
- package/dist/pages/appendCookie.js.map +1 -1
- package/dist/pages/exitPreview.cjs +2 -2
- 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 +2 -2
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs +9 -13
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +1 -1
- package/dist/pages/redirectToPreviewURL.d.ts +1 -1
- package/dist/pages/redirectToPreviewURL.js +9 -13
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/redirectToPreviewURL.cjs +9 -13
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +1 -1
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/redirectToPreviewURL.js +9 -13
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +5 -2
- package/src/PrismicPreview.tsx +10 -1
- package/src/PrismicPreviewClient.tsx +1 -12
- package/src/exitPreview.ts +1 -3
- package/src/lib/getSafePath.ts +22 -0
- package/src/pages/PrismicPreview.tsx +5 -4
- package/src/pages/appendCookie.ts +5 -11
- package/src/pages/exitPreview.ts +5 -2
- package/src/pages/redirectToPreviewURL.ts +14 -15
- package/src/redirectToPreviewURL.ts +19 -15
- package/dist/lib/toolbarV5.cjs +0 -37
- package/dist/lib/toolbarV5.cjs.map +0 -1
- package/dist/lib/toolbarV5.js +0 -34
- package/dist/lib/toolbarV5.js.map +0 -1
- package/src/lib/toolbarV5.ts +0 -54
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
1
3
|
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);
|
|
2
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
8
|
//#region src/PrismicPreview.tsx
|
|
9
|
+
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script_js.default);
|
|
4
10
|
/**
|
|
5
11
|
* React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
|
|
6
12
|
* send events to the browser, such as on preview updates and exiting, this component will
|
|
@@ -10,14 +16,24 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
10
16
|
* rendered on every page.
|
|
11
17
|
*/
|
|
12
18
|
const PrismicPreview = async (props) => {
|
|
13
|
-
const { repositoryName, children, ...otherProps } = props;
|
|
19
|
+
const { repositoryName, updatePreviewURL = "/api/preview", children, ...otherProps } = props;
|
|
14
20
|
const { draftMode } = await import("next/headers.js");
|
|
21
|
+
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName, { version: 5 });
|
|
15
22
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
16
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
24
|
+
children,
|
|
25
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicPreviewClient.PrismicPreviewClient, {
|
|
26
|
+
repositoryName,
|
|
27
|
+
isDraftMode,
|
|
28
|
+
updatePreviewURL,
|
|
29
|
+
...otherProps
|
|
30
|
+
}),
|
|
31
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
|
|
32
|
+
src: toolbarSrc,
|
|
33
|
+
strategy: "lazyOnload",
|
|
34
|
+
"data-preview-url": updatePreviewURL
|
|
35
|
+
})
|
|
36
|
+
] });
|
|
21
37
|
};
|
|
22
38
|
//#endregion
|
|
23
39
|
exports.PrismicPreview = PrismicPreview;
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["resolveDefaultExport","Script","getToolbarSrc","PrismicPreviewClient"],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import { getToolbarSrc } from \"@prismicio/client\"\nimport Script from \"next/script\"\nimport type { FC, ReactNode } from \"react\"\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\"\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\"\n\nconst ResolvedScript = resolveDefaultExport(Script)\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, updatePreviewURL = \"/api/preview\", 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\t// TODO: Bump the `@prismicio/client` peer to `^7.23.0`, which adds `version`, and drop `overrides`.\n\tconst toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })\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\tupdatePreviewURL={updatePreviewURL}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" data-preview-url={updatePreviewURL} />\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,iBAAiBA,6BAAAA,qBAAqBC,eAAAA,OAAM;;;;;;;;;AAkClD,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,mBAAmB,gBAAgB,UAAU,GAAG,eAAe;CAKvF,MAAM,EAAE,cAAc,MAAM,OAAO;CAGnC,MAAM,cAAA,GAAaC,kBAAAA,cAAAA,CAAc,gBAAgB,EAAE,SAAS,EAAE,CAAC;CAC/D,MAAM,eAAe,MAAM,UAAU,EAAA,CAAG;CAExC,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACE;EACD,iBAAA,GAAA,kBAAA,IAAA,CAACC,6BAAAA,sBAAD;GACiB;GACH;GACK;GAClB,GAAI;EACJ,CAAA;EACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,gBAAD;GAAgB,KAAK;GAAY,UAAS;GAAa,oBAAkB;EAAmB,CAAA;CAC3F,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":";;;YAUY;;;;;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":";;;YAUY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport.js";
|
|
1
2
|
import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
|
|
3
|
+
import { getToolbarSrc } from "@prismicio/client";
|
|
4
|
+
import Script from "next/script.js";
|
|
2
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
6
|
//#region src/PrismicPreview.tsx
|
|
7
|
+
const ResolvedScript = resolveDefaultExport(Script);
|
|
4
8
|
/**
|
|
5
9
|
* React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
|
|
6
10
|
* send events to the browser, such as on preview updates and exiting, this component will
|
|
@@ -10,14 +14,24 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
10
14
|
* rendered on every page.
|
|
11
15
|
*/
|
|
12
16
|
const PrismicPreview = async (props) => {
|
|
13
|
-
const { repositoryName, children, ...otherProps } = props;
|
|
17
|
+
const { repositoryName, updatePreviewURL = "/api/preview", children, ...otherProps } = props;
|
|
14
18
|
const { draftMode } = await import("next/headers.js");
|
|
19
|
+
const toolbarSrc = getToolbarSrc(repositoryName, { version: 5 });
|
|
15
20
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
16
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
22
|
+
children,
|
|
23
|
+
/* @__PURE__ */ jsx(PrismicPreviewClient, {
|
|
24
|
+
repositoryName,
|
|
25
|
+
isDraftMode,
|
|
26
|
+
updatePreviewURL,
|
|
27
|
+
...otherProps
|
|
28
|
+
}),
|
|
29
|
+
/* @__PURE__ */ jsx(ResolvedScript, {
|
|
30
|
+
src: toolbarSrc,
|
|
31
|
+
strategy: "lazyOnload",
|
|
32
|
+
"data-preview-url": updatePreviewURL
|
|
33
|
+
})
|
|
34
|
+
] });
|
|
21
35
|
};
|
|
22
36
|
//#endregion
|
|
23
37
|
export { PrismicPreview };
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","names":[],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import { getToolbarSrc } from \"@prismicio/client\"\nimport Script from \"next/script\"\nimport type { FC, ReactNode } from \"react\"\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\"\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\"\n\nconst ResolvedScript = resolveDefaultExport(Script)\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, updatePreviewURL = \"/api/preview\", 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\t// TODO: Bump the `@prismicio/client` peer to `^7.23.0`, which adds `version`, and drop `overrides`.\n\tconst toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })\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\tupdatePreviewURL={updatePreviewURL}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" data-preview-url={updatePreviewURL} />\n\t\t</>\n\t)\n}\n"],"mappings":";;;;;;AAOA,MAAM,iBAAiB,qBAAqB,MAAM;;;;;;;;;AAkClD,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,mBAAmB,gBAAgB,UAAU,GAAG,eAAe;CAKvF,MAAM,EAAE,cAAc,MAAM,OAAO;CAGnC,MAAM,aAAa,cAAc,gBAAgB,EAAE,SAAS,EAAE,CAAC;CAC/D,MAAM,eAAe,MAAM,UAAU,EAAA,CAAG;CAExC,OACC,qBAAA,UAAA,EAAA,UAAA;EACE;EACD,oBAAC,sBAAD;GACiB;GACH;GACK;GAClB,GAAI;EACJ,CAAA;EACD,oBAAC,gBAAD;GAAgB,KAAK;GAAY,UAAS;GAAa,oBAAkB;EAAmB,CAAA;CAC3F,EAAA,CAAA;AAEJ"}
|
|
@@ -1,15 +1,8 @@
|
|
|
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");
|
|
5
2
|
let _prismicio_client = require("@prismicio/client");
|
|
6
3
|
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);
|
|
9
4
|
let react = require("react");
|
|
10
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
5
|
//#region src/PrismicPreviewClient.tsx
|
|
12
|
-
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script_js.default);
|
|
13
6
|
const PrismicPreviewClient = (props) => {
|
|
14
7
|
const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
|
|
15
8
|
const { refresh } = (0, next_navigation_js.useRouter)();
|
|
@@ -56,10 +49,7 @@ const PrismicPreviewClient = (props) => {
|
|
|
56
49
|
exitPreviewURL,
|
|
57
50
|
refresh
|
|
58
51
|
]);
|
|
59
|
-
return
|
|
60
|
-
...require_toolbarV5.getToolbarScriptProps(repositoryName, updatePreviewURL),
|
|
61
|
-
strategy: "lazyOnload"
|
|
62
|
-
});
|
|
52
|
+
return null;
|
|
63
53
|
};
|
|
64
54
|
/**
|
|
65
55
|
* Returns the value of a cookie from a given cookie store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.cjs","names":["
|
|
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 null\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":";;;;;AAcA,MAAa,wBAAuD,UAAU;CAC7E,MAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;CAEJ,MAAM,EAAE,aAAA,GAAYA,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,OAAO;AACR;;;;;;;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,13 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { getToolbarScriptProps } from "./lib/toolbarV5.js";
|
|
3
|
-
import { resolveDefaultExport } from "./lib/resolveDefaultExport.js";
|
|
4
2
|
import { cookie } from "@prismicio/client";
|
|
5
3
|
import { useRouter } from "next/navigation.js";
|
|
6
|
-
import Script from "next/script.js";
|
|
7
4
|
import { useEffect } from "react";
|
|
8
|
-
import { jsx } from "react/jsx-runtime";
|
|
9
5
|
//#region src/PrismicPreviewClient.tsx
|
|
10
|
-
const ResolvedScript = resolveDefaultExport(Script);
|
|
11
6
|
const PrismicPreviewClient = (props) => {
|
|
12
7
|
const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
|
|
13
8
|
const { refresh } = useRouter();
|
|
@@ -54,10 +49,7 @@ const PrismicPreviewClient = (props) => {
|
|
|
54
49
|
exitPreviewURL,
|
|
55
50
|
refresh
|
|
56
51
|
]);
|
|
57
|
-
return
|
|
58
|
-
...getToolbarScriptProps(repositoryName, updatePreviewURL),
|
|
59
|
-
strategy: "lazyOnload"
|
|
60
|
-
});
|
|
52
|
+
return null;
|
|
61
53
|
};
|
|
62
54
|
/**
|
|
63
55
|
* 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
|
|
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 null\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":";;;;;AAcA,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,OAAO;AACR;;;;;;;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,4 +1,3 @@
|
|
|
1
|
-
const require_toolbarV5 = require("./lib/toolbarV5.cjs");
|
|
2
1
|
let _prismicio_client = require("@prismicio/client");
|
|
3
2
|
//#region src/exitPreview.ts
|
|
4
3
|
/**
|
|
@@ -30,7 +29,7 @@ async function exitPreview() {
|
|
|
30
29
|
secure: true
|
|
31
30
|
});
|
|
32
31
|
cookieJar.delete({
|
|
33
|
-
name:
|
|
32
|
+
name: _prismicio_client.cookie.previewSession,
|
|
34
33
|
sameSite: "none",
|
|
35
34
|
secure: true
|
|
36
35
|
});
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":["prismicCookie"
|
|
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\tcookieJar.delete({ name: prismicCookie.previewSession, 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":";;;;;;;;;;;;;;;;;AAiBA,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,MAAMA,kBAAAA,OAAc;EAAgB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAGvF,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":";;;;;;;;;;;;;;;;wBAiBsB,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":";;;;;;;;;;;;;;;;wBAiBsB,eAAe,QAAQ"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { previewSessionCookie } from "./lib/toolbarV5.js";
|
|
2
1
|
import { cookie } from "@prismicio/client";
|
|
3
2
|
//#region src/exitPreview.ts
|
|
4
3
|
/**
|
|
@@ -30,7 +29,7 @@ async function exitPreview() {
|
|
|
30
29
|
secure: true
|
|
31
30
|
});
|
|
32
31
|
cookieJar.delete({
|
|
33
|
-
name:
|
|
32
|
+
name: cookie.previewSession,
|
|
34
33
|
sameSite: "none",
|
|
35
34
|
secure: true
|
|
36
35
|
});
|
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\
|
|
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\tcookieJar.delete({ name: prismicCookie.previewSession, 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":";;;;;;;;;;;;;;;;;AAiBA,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,MAAMA,OAAc;EAAgB,UAAU;EAAQ,QAAQ;CAAK,CAAC;CAGvF,OAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAK,CAAC,GAAG,EACtD,SAAS,EACR,iBAAiB,WAClB,EACD,CAAC;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/lib/getSafePath.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
|
|
4
|
+
* `location`, so it already includes `basePath`.
|
|
5
|
+
*/
|
|
6
|
+
function getSafePath(path) {
|
|
7
|
+
if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) return;
|
|
8
|
+
const origin = "https://placeholder.invalid";
|
|
9
|
+
let url;
|
|
10
|
+
try {
|
|
11
|
+
url = new URL(path, origin);
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const safePath = url.href.slice(27);
|
|
16
|
+
if (url.origin === origin && !safePath.startsWith("//")) return safePath;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.getSafePath = getSafePath;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=getSafePath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSafePath.cjs","names":[],"sources":["../../src/lib/getSafePath.ts"],"sourcesContent":["/**\n * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from\n * `location`, so it already includes `basePath`.\n */\nexport function getSafePath(path: string | null | undefined): string | undefined {\n\tif (!path?.startsWith(\"/\") || path.startsWith(\"//\") || path.startsWith(\"/\\\\\")) {\n\t\treturn\n\t}\n\n\tconst origin = \"https://placeholder.invalid\"\n\tlet url: URL\n\ttry {\n\t\turl = new URL(path, origin)\n\t} catch {\n\t\treturn\n\t}\n\tconst safePath = url.href.slice(origin.length)\n\t// Normalizing can create `//`, like with `/.//example.com`.\n\tif (url.origin === origin && !safePath.startsWith(\"//\")) {\n\t\treturn safePath\n\t}\n}\n"],"mappings":";;;;;AAIA,SAAgB,YAAY,MAAqD;CAChF,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK,GAC3E;CAGD,MAAM,SAAS;CACf,IAAI;CACJ,IAAI;EACH,MAAM,IAAI,IAAI,MAAM,MAAM;CAC3B,QAAQ;EACP;CACD;CACA,MAAM,WAAW,IAAI,KAAK,MAAM,EAAa;CAE7C,IAAI,IAAI,WAAW,UAAU,CAAC,SAAS,WAAW,IAAI,GACrD,OAAO;AAET"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/lib/getSafePath.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from
|
|
4
|
+
* `location`, so it already includes `basePath`.
|
|
5
|
+
*/
|
|
6
|
+
function getSafePath(path) {
|
|
7
|
+
if (!path?.startsWith("/") || path.startsWith("//") || path.startsWith("/\\")) return;
|
|
8
|
+
const origin = "https://placeholder.invalid";
|
|
9
|
+
let url;
|
|
10
|
+
try {
|
|
11
|
+
url = new URL(path, origin);
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const safePath = url.href.slice(27);
|
|
16
|
+
if (url.origin === origin && !safePath.startsWith("//")) return safePath;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getSafePath };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=getSafePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSafePath.js","names":[],"sources":["../../src/lib/getSafePath.ts"],"sourcesContent":["/**\n * Returns `path` if it stays on the current origin, like `/blog?page=2#top`. It comes from\n * `location`, so it already includes `basePath`.\n */\nexport function getSafePath(path: string | null | undefined): string | undefined {\n\tif (!path?.startsWith(\"/\") || path.startsWith(\"//\") || path.startsWith(\"/\\\\\")) {\n\t\treturn\n\t}\n\n\tconst origin = \"https://placeholder.invalid\"\n\tlet url: URL\n\ttry {\n\t\turl = new URL(path, origin)\n\t} catch {\n\t\treturn\n\t}\n\tconst safePath = url.href.slice(origin.length)\n\t// Normalizing can create `//`, like with `/.//example.com`.\n\tif (url.origin === origin && !safePath.startsWith(\"//\")) {\n\t\treturn safePath\n\t}\n}\n"],"mappings":";;;;;AAIA,SAAgB,YAAY,MAAqD;CAChF,IAAI,CAAC,MAAM,WAAW,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK,GAC3E;CAGD,MAAM,SAAS;CACf,IAAI;CACJ,IAAI;EACH,MAAM,IAAI,IAAI,MAAM,MAAM;CAC3B,QAAQ;EACP;CACD;CACA,MAAM,WAAW,IAAI,KAAK,MAAM,EAAa;CAE7C,IAAI,IAAI,WAAW,UAAU,CAAC,SAAS,WAAW,IAAI,GACrD,OAAO;AAET"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_toolbarV5 = require("../lib/toolbarV5.cjs");
|
|
3
2
|
let _prismicio_client = require("@prismicio/client");
|
|
4
3
|
let next_script_js = require("next/script.js");
|
|
5
4
|
next_script_js = require_runtime.__toESM(next_script_js, 1);
|
|
@@ -18,6 +17,7 @@ let next_router_js = require("next/router.js");
|
|
|
18
17
|
const PrismicPreview = (props) => {
|
|
19
18
|
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
20
19
|
const router = (0, next_router_js.useRouter)();
|
|
20
|
+
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName, { version: 5 });
|
|
21
21
|
(0, react.useEffect)(() => {
|
|
22
22
|
const controller = new AbortController();
|
|
23
23
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
@@ -60,8 +60,9 @@ 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
|
-
|
|
64
|
-
strategy: "lazyOnload"
|
|
63
|
+
src: toolbarSrc,
|
|
64
|
+
strategy: "lazyOnload",
|
|
65
|
+
"data-preview-url": router.basePath + updatePreviewURL
|
|
65
66
|
})] });
|
|
66
67
|
};
|
|
67
68
|
function getPreviewCookieRepositoryName() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","names":["useRouter","
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["useRouter","getToolbarSrc","Script","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { getToolbarSrc, 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\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\tconst toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })\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\tsrc={toolbarSrc}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t\tdata-preview-url={router.basePath + updatePreviewURL}\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":";;;;;;;;;;;;;;;;AAsCA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;CAEJ,MAAM,UAAA,GAASA,eAAAA,UAAAA,CAAU;CAEzB,MAAM,cAAA,GAAaC,kBAAAA,cAAAA,CAAc,gBAAgB,EAAE,SAAS,EAAE,CAAC;CAE/D,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,KAAK;EACL,UAAS;EACT,oBAAkB,OAAO,WAAW;CACpC,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":";;;YAOY;;;;;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":";;;YAOY;;;;;EAKX;;;;;EAMA;;;;;EAMA;;EAGA,WAAW;;;;;;;;;;qBAWC,gBAAgB,GAAG"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { cookie } from "@prismicio/client";
|
|
1
|
+
import { cookie, getToolbarSrc } from "@prismicio/client";
|
|
3
2
|
import Script from "next/script.js";
|
|
4
3
|
import { useEffect } from "react";
|
|
5
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -16,6 +15,7 @@ import { useRouter } from "next/router.js";
|
|
|
16
15
|
const PrismicPreview = (props) => {
|
|
17
16
|
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
18
17
|
const router = useRouter();
|
|
18
|
+
const toolbarSrc = getToolbarSrc(repositoryName, { version: 5 });
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
const controller = new AbortController();
|
|
21
21
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
@@ -58,8 +58,9 @@ const PrismicPreview = (props) => {
|
|
|
58
58
|
router
|
|
59
59
|
]);
|
|
60
60
|
return /* @__PURE__ */ jsxs(Fragment, { children: [children, /* @__PURE__ */ jsx(Script, {
|
|
61
|
-
|
|
62
|
-
strategy: "lazyOnload"
|
|
61
|
+
src: toolbarSrc,
|
|
62
|
+
strategy: "lazyOnload",
|
|
63
|
+
"data-preview-url": router.basePath + updatePreviewURL
|
|
63
64
|
})] });
|
|
64
65
|
};
|
|
65
66
|
function getPreviewCookieRepositoryName() {
|
|
@@ -1 +1 @@
|
|
|
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\
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","names":["cookie","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { getToolbarSrc, 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\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\tconst toolbarSrc = getToolbarSrc(repositoryName, { version: 5 })\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\tsrc={toolbarSrc}\n\t\t\t\tstrategy=\"lazyOnload\"\n\t\t\t\tdata-preview-url={router.basePath + updatePreviewURL}\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":";;;;;;;;;;;;;;AAsCA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;CAEJ,MAAM,SAAS,UAAU;CAEzB,MAAM,aAAa,cAAc,gBAAgB,EAAE,SAAS,EAAE,CAAC;CAE/D,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,KAAK;EACL,UAAS;EACT,oBAAkB,OAAO,WAAW;CACpC,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"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
//#region src/pages/appendCookie.ts
|
|
2
2
|
/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */
|
|
3
|
-
function appendCookie(res,
|
|
3
|
+
function appendCookie(res, cookie) {
|
|
4
4
|
const previous = res.getHeader("Set-Cookie") ?? [];
|
|
5
|
-
|
|
6
|
-
if (expires) cookie += `; Expires=${expires.toUTCString()}`;
|
|
7
|
-
res.setHeader("Set-Cookie", [...[previous].flat().map(String), cookie]);
|
|
5
|
+
res.setHeader("Set-Cookie", [...[previous].flat().map(String), `${cookie}; Path=/; SameSite=None; Secure`]);
|
|
8
6
|
}
|
|
9
7
|
//#endregion
|
|
10
8
|
exports.appendCookie = appendCookie;
|
|
@@ -1 +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(
|
|
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(res: NextApiResponseLike, cookie: string): void {\n\tconst previous = res.getHeader(\"Set-Cookie\") ?? []\n\tres.setHeader(\"Set-Cookie\", [\n\t\t...[previous].flat().map(String),\n\t\t`${cookie}; Path=/; SameSite=None; Secure`,\n\t])\n}\n"],"mappings":";;AAGA,SAAgB,aAAa,KAA0B,QAAsB;CAC5E,MAAM,WAAW,IAAI,UAAU,YAAY,KAAK,CAAC;CACjD,IAAI,UAAU,cAAc,CAC3B,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,GAC/B,GAAG,OAAO,gCACX,CAAC;AACF"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
//#region src/pages/appendCookie.ts
|
|
2
2
|
/** Adds a cookie like the App Router's preview cookie, keeping Next.js's preview data cookies. */
|
|
3
|
-
function appendCookie(res,
|
|
3
|
+
function appendCookie(res, cookie) {
|
|
4
4
|
const previous = res.getHeader("Set-Cookie") ?? [];
|
|
5
|
-
|
|
6
|
-
if (expires) cookie += `; Expires=${expires.toUTCString()}`;
|
|
7
|
-
res.setHeader("Set-Cookie", [...[previous].flat().map(String), cookie]);
|
|
5
|
+
res.setHeader("Set-Cookie", [...[previous].flat().map(String), `${cookie}; Path=/; SameSite=None; Secure`]);
|
|
8
6
|
}
|
|
9
7
|
//#endregion
|
|
10
8
|
export { appendCookie };
|
|
@@ -1 +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(
|
|
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(res: NextApiResponseLike, cookie: string): void {\n\tconst previous = res.getHeader(\"Set-Cookie\") ?? []\n\tres.setHeader(\"Set-Cookie\", [\n\t\t...[previous].flat().map(String),\n\t\t`${cookie}; Path=/; SameSite=None; Secure`,\n\t])\n}\n"],"mappings":";;AAGA,SAAgB,aAAa,KAA0B,QAAsB;CAC5E,MAAM,WAAW,IAAI,UAAU,YAAY,KAAK,CAAC;CACjD,IAAI,UAAU,cAAc,CAC3B,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,MAAM,GAC/B,GAAG,OAAO,gCACX,CAAC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_toolbarV5 = require("../lib/toolbarV5.cjs");
|
|
2
1
|
const require_appendCookie = require("./appendCookie.cjs");
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
3
3
|
//#region src/pages/exitPreview.ts
|
|
4
4
|
/**
|
|
5
5
|
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
@@ -18,7 +18,7 @@ const require_appendCookie = require("./appendCookie.cjs");
|
|
|
18
18
|
*/
|
|
19
19
|
function exitPreview(config) {
|
|
20
20
|
config.res.clearPreviewData();
|
|
21
|
-
require_appendCookie.appendCookie(config.res,
|
|
21
|
+
for (const name of [_prismicio_client.cookie.preview, _prismicio_client.cookie.previewSession]) require_appendCookie.appendCookie(config.res, `${name}=; Expires=${(/* @__PURE__ */ new Date(0)).toUTCString()}`);
|
|
22
22
|
config.res.setHeader("Cache-Control", "no-store");
|
|
23
23
|
config.res.json({ success: true });
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":["
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { appendCookie } from \"./appendCookie\"\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\"\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\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 * 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 used in an API\n * route.\n *\n * @example\n * \t;```typescript\n * \t// src/pages/api/exit-preview.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport default function handler(_req, res) {\n * \t\treturn exitPreview({ res })\n * \t}\n * \t```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData()\n\tfor (const name of [prismicCookie.preview, prismicCookie.previewSession]) {\n\t\tappendCookie(config.res, `${name}=; Expires=${new Date(0).toUTCString()}`)\n\t}\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\")\n\n\tconfig.res.json({ success: true })\n\n\treturn\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqCA,SAAgB,YAAY,QAAyC;CACpE,OAAO,IAAI,iBAAiB;CAC5B,KAAK,MAAM,QAAQ,CAACA,kBAAAA,OAAc,SAASA,kBAAAA,OAAc,cAAc,GACtE,qBAAA,aAAa,OAAO,KAAK,GAAG,KAAK,8BAAa,IAAI,KAAK,CAAC,EAAA,CAAE,YAAY,GAAG;CAI1E,OAAO,IAAI,UAAU,iBAAiB,UAAU;CAEhD,OAAO,IAAI,KAAK,EAAE,SAAS,KAAK,CAAC;AAGlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;YAMY;;;;;;EAMX,MAAM;;;;;;EAON,KAAK;;;;;;;;;;;;;;;;;wBAkBU,YAAY,QAAQ"}
|