@prismicio/next 2.3.0 → 2.3.1-pr.147.2aebcfe
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/PrismicPreviewClient.cjs +2 -2
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +1 -1
- package/dist/SliceSimulator.cjs +5 -4
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.js +3 -3
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/cacheTagPrismicPages.cjs +3 -2
- package/dist/cacheTagPrismicPages.cjs.map +1 -1
- package/dist/cacheTagPrismicPages.d.cts.map +1 -1
- package/dist/cacheTagPrismicPages.d.ts.map +1 -1
- package/dist/cacheTagPrismicPages.js +2 -2
- package/dist/cacheTagPrismicPages.js.map +1 -1
- package/dist/exitPreview.cjs +5 -5
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.js +5 -4
- package/dist/exitPreview.js.map +1 -1
- package/dist/getSlices.cjs +3 -2
- package/dist/getSlices.cjs.map +1 -1
- package/dist/getSlices.js +2 -2
- package/dist/getSlices.js.map +1 -1
- package/dist/lib/expiredPreviewCookies.cjs +13 -0
- package/dist/lib/expiredPreviewCookies.cjs.map +1 -0
- package/dist/lib/expiredPreviewCookies.js +12 -0
- package/dist/lib/expiredPreviewCookies.js.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/exitPreview.cjs +4 -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 +4 -0
- package/dist/pages/exitPreview.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 +8 -3
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts.map +1 -1
- package/dist/redirectToPreviewURL.d.ts.map +1 -1
- package/dist/redirectToPreviewURL.js +8 -3
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +7 -6
- package/src/SliceSimulator.tsx +2 -2
- package/src/cacheTagPrismicPages.ts +3 -2
- package/src/exitPreview.ts +14 -11
- package/src/getSlices.ts +2 -2
- package/src/lib/expiredPreviewCookies.ts +13 -0
- package/src/pages/exitPreview.ts +21 -0
- package/src/pages/types.ts +1 -0
- package/src/redirectToPreviewURL.ts +16 -3
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
let _prismicio_client = require("@prismicio/client");
|
|
4
|
-
let
|
|
4
|
+
let next_navigation_js = require("next/navigation.js");
|
|
5
5
|
let react = require("react");
|
|
6
6
|
//#region src/PrismicPreviewClient.tsx
|
|
7
7
|
const PrismicPreviewClient = (props) => {
|
|
8
8
|
const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
|
|
9
|
-
const { refresh } = (0,
|
|
9
|
+
const { refresh } = (0, next_navigation_js.useRouter)();
|
|
10
10
|
(0, react.useEffect)(() => {
|
|
11
11
|
const controller = new AbortController();
|
|
12
12
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.cjs","names":["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(\"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 = getPrismicPreviewCookie(window.document.cookie)\n\t\tconst cookieRepositoryName = cookie\n\t\t\t? (decodeURIComponent(cookie).match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n\t\t\t: undefined\n\t\tconst hasCookieForRepository = cookieRepositoryName === repositoryName\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\tif (hasCookieForRepository && !isDraftMode) {\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\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\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\trefresh()\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,GAAA,
|
|
1
|
+
{"version":3,"file":"PrismicPreviewClient.cjs","names":["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(\"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 = getPrismicPreviewCookie(window.document.cookie)\n\t\tconst cookieRepositoryName = cookie\n\t\t\t? (decodeURIComponent(cookie).match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n\t\t\t: undefined\n\t\tconst hasCookieForRepository = cookieRepositoryName === repositoryName\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\tif (hasCookieForRepository && !isDraftMode) {\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\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\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault()\n\t\t\trefresh()\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,GAAA,mBAAA,YAAuB;AAE/B,EAAA,GAAA,MAAA,iBAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,QACnB,CAAC;AACF,SAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,QACnB,CAAC;EAEF,MAAM,SAAS,wBAAwB,OAAO,SAAS,OAAO;AAS9D,OAR6B,UACzB,mBAAmB,OAAO,CAAC,MAAM,yBAAyB,IAAI,EAAE,EAAE,KACnE,KAAA,OACqD,kBAK1B,CAAC,YAK9B,YACE,MAAM,kBAAkB;GACxB,UAAU;GACV,QAAQ,WAAW;GACnB,CAAC,CACD,MAAM,QAAQ;AACd,OAAI,IAAI,SAAS,kBAAkB;AAClC,YAAQ,MACP,yDAAyD,iBAAiB,mBAC1E;AAED;;AAGD,YAAS;IACR,CACD,YAAY,GAEX;EAGJ,SAAS,SAAS,OAAc;AAC/B,SAAM,gBAAgB;AACtB,YAAS;;EAGV,SAAS,MAAM,OAAc;AAC5B,SAAM,gBAAgB;AACtB,cACE,MAAM,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,CAAC,CACpD,MAAM,QAAQ;AACd,QAAI,CAAC,IAAI,IAAI;AACZ,aAAQ,MACP,6DAA6D,eAAe,gCAC5E;AAED;;AAGD,aAAS;KACR,CACD,YAAY,GAEX;;AAGJ,eAAa,WAAW,OAAO;IAC7B;EAAC;EAAgB;EAAa;EAAkB;EAAgB;EAAQ,CAAC;AAE5E,QAAO;;;;;;;;AASR,SAAS,wBAAwB,WAAuC;CACvE,SAAS,UAAU,OAAuB;AACzC,SAAO,MAAM,QAAQ,QAAQ,IAAI;;CAGlC,MAAM,UAAU,UAAU,MAAM,KAAK;CAErC,IAAI;AAEJ,MAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,QAAQ,OAAO,MAAM,IAAI;AAG/B,MAFa,UAAU,MAAM,GAAG,CAAC,QAAQ,QAAQ,IAAI,KAExCA,kBAAAA,OAAc,SAAS;AACnC,WAAQ,UAAU,MAAM,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;AAC3C;;;AAIF,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cookie } from "@prismicio/client";
|
|
3
|
-
import { useRouter } from "next/navigation";
|
|
3
|
+
import { useRouter } from "next/navigation.js";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
5
|
//#region src/PrismicPreviewClient.tsx
|
|
6
6
|
const PrismicPreviewClient = (props) => {
|
package/dist/SliceSimulator.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
const require_getSlices = require("./getSlices.cjs");
|
|
4
4
|
const require_SliceSimulatorWrapper = require("./SliceSimulatorWrapper.cjs");
|
|
5
|
-
let
|
|
5
|
+
let next_navigation_js = require("next/navigation.js");
|
|
6
6
|
let react = require("react");
|
|
7
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
8
|
let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
|
|
9
9
|
let lz_string = require("lz-string");
|
|
10
|
+
lz_string = require_runtime.__toESM(lz_string);
|
|
10
11
|
//#region src/SliceSimulator.tsx
|
|
11
12
|
const STATE_PARAMS_KEY = "state";
|
|
12
13
|
const simulatorManager = new _prismicio_simulator_kit.SimulatorManager();
|
|
@@ -16,12 +17,12 @@ const simulatorManager = new _prismicio_simulator_kit.SimulatorManager();
|
|
|
16
17
|
*/
|
|
17
18
|
const SliceSimulator = ({ children, background, zIndex, className }) => {
|
|
18
19
|
const [message, setMessage] = (0, react.useState)(() => (0, _prismicio_simulator_kit.getDefaultMessage)());
|
|
19
|
-
const router = (0,
|
|
20
|
+
const router = (0, next_navigation_js.useRouter)();
|
|
20
21
|
const hasSlices = require_getSlices.getSlices(typeof window !== "undefined" ? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY) : void 0).length > 0;
|
|
21
22
|
(0, react.useEffect)(() => {
|
|
22
23
|
simulatorManager.state.on(_prismicio_simulator_kit.StateEventType.Slices, (newSlices) => {
|
|
23
24
|
const url = new URL(window.location.href);
|
|
24
|
-
url.searchParams.set(STATE_PARAMS_KEY,
|
|
25
|
+
url.searchParams.set(STATE_PARAMS_KEY, lz_string.default.compressToEncodedURIComponent(JSON.stringify(newSlices)));
|
|
25
26
|
window.history.replaceState(null, "", url);
|
|
26
27
|
setTimeout(() => router.refresh(), 0);
|
|
27
28
|
}, "simulator-slices");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","getSlices","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\"\n\nimport { SimulatorManager, StateEventType, getDefaultMessage } from \"@prismicio/simulator/kit\"\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","getSlices","StateEventType","lzString","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\"\n\nimport { SimulatorManager, StateEventType, getDefaultMessage } from \"@prismicio/simulator/kit\"\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\nimport { useRouter } from \"next/navigation\"\nimport { useEffect, useState } from \"react\"\nimport type { FC, ReactNode } from \"react\"\n\nimport { getSlices } from \"./getSlices\"\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\"\n\nconst STATE_PARAMS_KEY = \"state\"\n\nconst simulatorManager = new SimulatorManager()\n\n/** Parameters provided to the Slice Simulator page. */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string\n\t}>\n}\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode\n\tclassName?: string\n}\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice development in Slice Machine\n * and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(() => getDefaultMessage())\n\tconst router = useRouter()\n\n\tconst state =\n\t\ttypeof window !== \"undefined\"\n\t\t\t? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY)\n\t\t\t: undefined\n\tconst hasSlices = getSlices(state).length > 0\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href)\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tlzString.compressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t)\n\n\t\t\t\twindow.history.replaceState(null, \"\", url)\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => router.refresh(), 0)\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t)\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t)\n\n\t\tsimulatorManager.init()\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\")\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\")\n\t\t}\n\t}, [router])\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\thasSlices={hasSlices}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t)\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,yBAAAA,kBAAkB;;;;;AAkB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,eAAA,GAAA,MAAA,iBAAA,GAAA,yBAAA,oBAAgD,CAAC;CACjE,MAAM,UAAA,GAAA,mBAAA,YAAoB;CAM1B,MAAM,YAAYC,kBAAAA,UAHjB,OAAO,WAAW,cACf,IAAI,IAAI,OAAO,SAAS,KAAK,CAAC,aAAa,IAAI,iBAAiB,GAChE,KAAA,EAC8B,CAAC,SAAS;AAE5C,EAAA,GAAA,MAAA,iBAAgB;AACf,mBAAiB,MAAM,GACtBC,yBAAAA,eAAe,SACd,cAAc;GACd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,OAAI,aAAa,IAChB,kBACAC,UAAAA,QAAS,8BAA8B,KAAK,UAAU,UAAU,CAAC,CACjE;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,OAAO,SAAS,EAAE,EAAE;KAEtC,mBACA;AACD,mBAAiB,MAAM,GACtBD,yBAAAA,eAAe,UACd,eAAe,WAAW,WAAW,EACtC,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAIA,yBAAAA,eAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAIA,yBAAAA,eAAe,SAAS,oBAAoB;;IAEtE,CAAC,OAAO,CAAC;AAEZ,QACC,iBAAA,GAAA,kBAAA,KAACE,8BAAAA,uBAAD;EACU;EACE;EACC;EACJ;EACG;EAEV;EACsB,CAAA"}
|
package/dist/SliceSimulator.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { getSlices } from "./getSlices.js";
|
|
3
3
|
import { SliceSimulatorWrapper } from "./SliceSimulatorWrapper.js";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
4
|
+
import { useRouter } from "next/navigation.js";
|
|
5
5
|
import { useEffect, useState } from "react";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
import { SimulatorManager, StateEventType, getDefaultMessage } from "@prismicio/simulator/kit";
|
|
8
|
-
import
|
|
8
|
+
import lzString from "lz-string";
|
|
9
9
|
//#region src/SliceSimulator.tsx
|
|
10
10
|
const STATE_PARAMS_KEY = "state";
|
|
11
11
|
const simulatorManager = new SimulatorManager();
|
|
@@ -20,7 +20,7 @@ const SliceSimulator = ({ children, background, zIndex, className }) => {
|
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
simulatorManager.state.on(StateEventType.Slices, (newSlices) => {
|
|
22
22
|
const url = new URL(window.location.href);
|
|
23
|
-
url.searchParams.set(STATE_PARAMS_KEY, compressToEncodedURIComponent(JSON.stringify(newSlices)));
|
|
23
|
+
url.searchParams.set(STATE_PARAMS_KEY, lzString.compressToEncodedURIComponent(JSON.stringify(newSlices)));
|
|
24
24
|
window.history.replaceState(null, "", url);
|
|
25
25
|
setTimeout(() => router.refresh(), 0);
|
|
26
26
|
}, "simulator-slices");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.js","names":[],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\"\n\nimport { SimulatorManager, StateEventType, getDefaultMessage } from \"@prismicio/simulator/kit\"\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"SliceSimulator.js","names":[],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\"\n\nimport { SimulatorManager, StateEventType, getDefaultMessage } from \"@prismicio/simulator/kit\"\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\nimport { useRouter } from \"next/navigation\"\nimport { useEffect, useState } from \"react\"\nimport type { FC, ReactNode } from \"react\"\n\nimport { getSlices } from \"./getSlices\"\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\"\n\nconst STATE_PARAMS_KEY = \"state\"\n\nconst simulatorManager = new SimulatorManager()\n\n/** Parameters provided to the Slice Simulator page. */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string\n\t}>\n}\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode\n\tclassName?: string\n}\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice development in Slice Machine\n * and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(() => getDefaultMessage())\n\tconst router = useRouter()\n\n\tconst state =\n\t\ttypeof window !== \"undefined\"\n\t\t\t? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY)\n\t\t\t: undefined\n\tconst hasSlices = getSlices(state).length > 0\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href)\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tlzString.compressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t)\n\n\t\t\t\twindow.history.replaceState(null, \"\", url)\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => router.refresh(), 0)\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t)\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t)\n\n\t\tsimulatorManager.init()\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\")\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\")\n\t\t}\n\t}, [router])\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\thasSlices={hasSlices}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t)\n}\n"],"mappings":";;;;;;;;;AAYA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAI,kBAAkB;;;;;AAkB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,cAAc,eAAe,mBAAmB,CAAC;CACjE,MAAM,SAAS,WAAW;CAM1B,MAAM,YAAY,UAHjB,OAAO,WAAW,cACf,IAAI,IAAI,OAAO,SAAS,KAAK,CAAC,aAAa,IAAI,iBAAiB,GAChE,KAAA,EAC8B,CAAC,SAAS;AAE5C,iBAAgB;AACf,mBAAiB,MAAM,GACtB,eAAe,SACd,cAAc;GACd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,OAAI,aAAa,IAChB,kBACA,SAAS,8BAA8B,KAAK,UAAU,UAAU,CAAC,CACjE;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,OAAO,SAAS,EAAE,EAAE;KAEtC,mBACA;AACD,mBAAiB,MAAM,GACtB,eAAe,UACd,eAAe,WAAW,WAAW,EACtC,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAI,eAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAI,eAAe,SAAS,oBAAoB;;IAEtE,CAAC,OAAO,CAAC;AAEZ,QACC,oBAAC,uBAAD;EACU;EACE;EACC;EACJ;EACG;EAEV;EACsB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
require("./_virtual/_rolldown/runtime.cjs");
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
|
|
3
3
|
let next_cache_js = require("next/cache.js");
|
|
4
|
+
next_cache_js = require_runtime.__toESM(next_cache_js);
|
|
4
5
|
//#region src/cacheTagPrismicPages.ts
|
|
5
6
|
/**
|
|
6
7
|
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
@@ -15,7 +16,7 @@ let next_cache_js = require("next/cache.js");
|
|
|
15
16
|
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
16
17
|
*/
|
|
17
18
|
function cacheTagPrismicPages(pages) {
|
|
18
|
-
|
|
19
|
+
next_cache_js.cacheTag(...require_getPrismicCacheTags.getPrismicCacheTags(pages));
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
|
21
22
|
exports.cacheTagPrismicPages = cacheTagPrismicPages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheTagPrismicPages.cjs","names":["getPrismicCacheTags"],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.cjs","names":["getPrismicCacheTags"],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n// Namespace import: Next.js 15 has no `cacheTag`, and a named import would fail to link.\nimport * as nextCache from \"next/cache\"\n\nimport { getPrismicCacheTags } from \"./getPrismicCacheTags\"\n\n/**\n * Tags the current cache entry with cache tags for a set of Prismic pages so they can be\n * revalidated when their content changes.\n *\n * Linked documents (via content relationships) are tagged as well, so the cache entry is\n * revalidated when any of its nested documents change.\n *\n * @param pages - A set of Prismic pages used to tag the cache entry.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function cacheTagPrismicPages(pages: PrismicDocument[]): void {\n\tnextCache.cacheTag(...getPrismicCacheTags(pages))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,SAAgB,qBAAqB,OAAgC;AACpE,eAAU,SAAS,GAAGA,4BAAAA,oBAAoB,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheTagPrismicPages.d.cts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.d.cts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAkBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheTagPrismicPages.d.ts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.d.ts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAkBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
|
|
2
|
-
import
|
|
2
|
+
import * as nextCache from "next/cache.js";
|
|
3
3
|
//#region src/cacheTagPrismicPages.ts
|
|
4
4
|
/**
|
|
5
5
|
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
@@ -14,7 +14,7 @@ import { cacheTag } from "next/cache.js";
|
|
|
14
14
|
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
15
15
|
*/
|
|
16
16
|
function cacheTagPrismicPages(pages) {
|
|
17
|
-
cacheTag(...getPrismicCacheTags(pages));
|
|
17
|
+
nextCache.cacheTag(...getPrismicCacheTags(pages));
|
|
18
18
|
}
|
|
19
19
|
//#endregion
|
|
20
20
|
export { cacheTagPrismicPages };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheTagPrismicPages.js","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.js","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n// Namespace import: Next.js 15 has no `cacheTag`, and a named import would fail to link.\nimport * as nextCache from \"next/cache\"\n\nimport { getPrismicCacheTags } from \"./getPrismicCacheTags\"\n\n/**\n * Tags the current cache entry with cache tags for a set of Prismic pages so they can be\n * revalidated when their content changes.\n *\n * Linked documents (via content relationships) are tagged as well, so the cache entry is\n * revalidated when any of its nested documents change.\n *\n * @param pages - A set of Prismic pages used to tag the cache entry.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function cacheTagPrismicPages(pages: PrismicDocument[]): void {\n\tnextCache.cacheTag(...getPrismicCacheTags(pages))\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,SAAgB,qBAAqB,OAAgC;AACpE,WAAU,SAAS,GAAG,oBAAoB,MAAM,CAAC"}
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require("./
|
|
2
|
-
let _prismicio_client = require("@prismicio/client");
|
|
1
|
+
const require_expiredPreviewCookies = require("./lib/expiredPreviewCookies.cjs");
|
|
3
2
|
//#region src/exitPreview.ts
|
|
4
3
|
/**
|
|
5
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
@@ -17,10 +16,11 @@ let _prismicio_client = require("@prismicio/client");
|
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
18
|
async function exitPreview() {
|
|
20
|
-
const {
|
|
19
|
+
const { draftMode } = await import("next/headers.js");
|
|
21
20
|
(await draftMode()).disable();
|
|
22
|
-
(
|
|
23
|
-
|
|
21
|
+
const headers = new Headers({ "Cache-Control": "no-store" });
|
|
22
|
+
for (const setCookie of require_expiredPreviewCookies.expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
|
|
23
|
+
return new Response(JSON.stringify({ success: true }), { headers });
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
26
|
exports.exitPreview = exitPreview;
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":["
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"./lib/expiredPreviewCookies\"\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 { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both on the Response. Do not use `cookies().set` / `delete()`:\n\t// ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites\n\t// the first and the Lax leftover survives.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAaA,8BAAAA,6BAA6B,CACpD,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies.js";
|
|
2
2
|
//#region src/exitPreview.ts
|
|
3
3
|
/**
|
|
4
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
@@ -16,10 +16,11 @@ import { cookie } from "@prismicio/client";
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
async function exitPreview() {
|
|
19
|
-
const {
|
|
19
|
+
const { draftMode } = await import("next/headers.js");
|
|
20
20
|
(await draftMode()).disable();
|
|
21
|
-
(
|
|
22
|
-
|
|
21
|
+
const headers = new Headers({ "Cache-Control": "no-store" });
|
|
22
|
+
for (const setCookie of expiredPreviewCookieHeaders()) headers.append("Set-Cookie", setCookie);
|
|
23
|
+
return new Response(JSON.stringify({ success: true }), { headers });
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
export { exitPreview };
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":[
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"./lib/expiredPreviewCookies\"\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 { draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may\n\t// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.\n\t// Expire both on the Response. Do not use `cookies().set` / `delete()`:\n\t// ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites\n\t// the first and the Lax leftover survives.\n\tconst headers = new Headers({\n\t\t\"Cache-Control\": \"no-store\",\n\t})\n\tfor (const setCookie of expiredPreviewCookieHeaders()) {\n\t\theaders.append(\"Set-Cookie\", setCookie)\n\t}\n\n\treturn new Response(JSON.stringify({ success: true }), { headers })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,cAAc,MAAM,OAAO;AAElC,EAAC,MAAM,WAAW,EAAE,SAAS;CAO9B,MAAM,UAAU,IAAI,QAAQ,EAC3B,iBAAiB,YACjB,CAAC;AACF,MAAK,MAAM,aAAa,6BAA6B,CACpD,SAAQ,OAAO,cAAc,UAAU;AAGxC,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC"}
|
package/dist/getSlices.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
require("./_virtual/_rolldown/runtime.cjs");
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
|
|
3
3
|
let lz_string = require("lz-string");
|
|
4
|
+
lz_string = require_runtime.__toESM(lz_string);
|
|
4
5
|
//#region src/getSlices.ts
|
|
5
6
|
const getSlices = (state) => {
|
|
6
|
-
return state ? JSON.parse(
|
|
7
|
+
return state ? JSON.parse(lz_string.default.decompressFromEncodedURIComponent(state)) : (0, _prismicio_simulator_kit.getDefaultSlices)();
|
|
7
8
|
};
|
|
8
9
|
//#endregion
|
|
9
10
|
exports.getSlices = getSlices;
|
package/dist/getSlices.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSlices.cjs","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"getSlices.cjs","names":["lzString"],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\n\nexport const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {\n\treturn state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices()\n}\n"],"mappings":";;;;;AAIA,MAAa,aAAa,UAAyE;AAClG,QAAO,QAAQ,KAAK,MAAMA,UAAAA,QAAS,kCAAkC,MAAM,CAAC,IAAA,GAAA,yBAAA,mBAAqB"}
|
package/dist/getSlices.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getDefaultSlices } from "@prismicio/simulator/kit";
|
|
2
|
-
import
|
|
2
|
+
import lzString from "lz-string";
|
|
3
3
|
//#region src/getSlices.ts
|
|
4
4
|
const getSlices = (state) => {
|
|
5
|
-
return state ? JSON.parse(decompressFromEncodedURIComponent(state)) : getDefaultSlices();
|
|
5
|
+
return state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices();
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
8
8
|
export { getSlices };
|
package/dist/getSlices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSlices.js","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"getSlices.js","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\n\nexport const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {\n\treturn state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices()\n}\n"],"mappings":";;;AAIA,MAAa,aAAa,UAAyE;AAClG,QAAO,QAAQ,KAAK,MAAM,SAAS,kCAAkC,MAAM,CAAC,GAAG,kBAAkB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
3
|
+
//#region src/lib/expiredPreviewCookies.ts
|
|
4
|
+
const epoch = /* @__PURE__ */ new Date(0);
|
|
5
|
+
/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
|
|
6
|
+
function expiredPreviewCookieHeaders(name = _prismicio_client.cookie.preview) {
|
|
7
|
+
const expires = `Expires=${epoch.toUTCString()}`;
|
|
8
|
+
return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.expiredPreviewCookieHeaders = expiredPreviewCookieHeaders;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=expiredPreviewCookies.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiredPreviewCookies.cjs","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;AAGzB,SAAgB,4BAA4B,OAAOA,kBAAAA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
//#region src/lib/expiredPreviewCookies.ts
|
|
3
|
+
const epoch = /* @__PURE__ */ new Date(0);
|
|
4
|
+
/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
|
|
5
|
+
function expiredPreviewCookieHeaders(name = cookie.preview) {
|
|
6
|
+
const expires = `Expires=${epoch.toUTCString()}`;
|
|
7
|
+
return [`${name}=; Path=/; ${expires}; SameSite=Lax`, `${name}=; Path=/; ${expires}; SameSite=None; Secure`];
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { expiredPreviewCookieHeaders };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=expiredPreviewCookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expiredPreviewCookies.js","names":["prismicCookie"],"sources":["../../src/lib/expiredPreviewCookies.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nconst epoch = new Date(0)\n\n/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */\nexport function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {\n\tconst expires = `Expires=${epoch.toUTCString()}`\n\n\treturn [\n\t\t`${name}=; Path=/; ${expires}; SameSite=Lax`,\n\t\t`${name}=; Path=/; ${expires}; SameSite=None; Secure`,\n\t]\n}\n"],"mappings":";;AAEA,MAAM,wBAAQ,IAAI,KAAK,EAAE;;AAGzB,SAAgB,4BAA4B,OAAOA,OAAc,SAAmB;CACnF,MAAM,UAAU,WAAW,MAAM,aAAa;AAE9C,QAAO,CACN,GAAG,KAAK,aAAa,QAAQ,iBAC7B,GAAG,KAAK,aAAa,QAAQ,yBAC7B"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_expiredPreviewCookies = require("../lib/expiredPreviewCookies.cjs");
|
|
1
2
|
//#region src/pages/exitPreview.ts
|
|
2
3
|
/**
|
|
3
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
@@ -16,6 +17,9 @@
|
|
|
16
17
|
*/
|
|
17
18
|
function exitPreview(config) {
|
|
18
19
|
config.res.clearPreviewData();
|
|
20
|
+
const existingSetCookie = config.res.getHeader("Set-Cookie");
|
|
21
|
+
const expiredPreviewCookies = require_expiredPreviewCookies.expiredPreviewCookieHeaders();
|
|
22
|
+
config.res.setHeader("Set-Cookie", existingSetCookie == null ? expiredPreviewCookies : [...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(String), ...expiredPreviewCookies]);
|
|
19
23
|
config.res.setHeader("Cache-Control", "no-store");
|
|
20
24
|
config.res.json({ success: true });
|
|
21
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import 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\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":"
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":["expiredPreviewCookieHeaders"],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"../lib/expiredPreviewCookies\"\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\n\t// `clearPreviewData()` only clears Next.js preview cookies. Expire both\n\t// leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the\n\t// iframe SameSite=None; Secure write). If either survives,\n\t// `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.\n\t// Do not use `cookies().set` — that is the App Router helper. Do not\n\t// replace the existing Set-Cookie header from `clearPreviewData()`.\n\tconst existingSetCookie = config.res.getHeader(\"Set-Cookie\")\n\tconst expiredPreviewCookies = expiredPreviewCookieHeaders()\n\tconfig.res.setHeader(\n\t\t\"Set-Cookie\",\n\t\texistingSetCookie == null\n\t\t\t? expiredPreviewCookies\n\t\t\t: [\n\t\t\t\t\t...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(\n\t\t\t\t\t\tString,\n\t\t\t\t\t),\n\t\t\t\t\t...expiredPreviewCookies,\n\t\t\t\t],\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":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;CAQ7B,MAAM,oBAAoB,OAAO,IAAI,UAAU,aAAa;CAC5D,MAAM,wBAAwBA,8BAAAA,6BAA6B;AAC3D,QAAO,IAAI,UACV,cACA,qBAAqB,OAClB,wBACA,CACA,IAAI,MAAM,QAAQ,kBAAkB,GAAG,oBAAoB,CAAC,kBAAkB,EAAE,IAC/E,OACA,EACD,GAAG,sBACH,CACH;AAGD,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
|
|
@@ -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":";;;;KAIY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../../src/pages/exitPreview.ts"],"mappings":";;;;KAIY,yBAAA;EAAA;;;;;EAMX,GAAA,GAAM,kBAAA;EAON;;;;AAkBD;EAlBC,GAAA,EAAK,mBAAA;AAAA;;;;;;;;;;;;;;;;iBAkBU,WAAA,CAAY,MAAA,EAAQ,yBAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies.js";
|
|
1
2
|
//#region src/pages/exitPreview.ts
|
|
2
3
|
/**
|
|
3
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in an API
|
|
@@ -16,6 +17,9 @@
|
|
|
16
17
|
*/
|
|
17
18
|
function exitPreview(config) {
|
|
18
19
|
config.res.clearPreviewData();
|
|
20
|
+
const existingSetCookie = config.res.getHeader("Set-Cookie");
|
|
21
|
+
const expiredPreviewCookies = expiredPreviewCookieHeaders();
|
|
22
|
+
config.res.setHeader("Set-Cookie", existingSetCookie == null ? expiredPreviewCookies : [...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(String), ...expiredPreviewCookies]);
|
|
19
23
|
config.res.setHeader("Cache-Control", "no-store");
|
|
20
24
|
config.res.json({ success: true });
|
|
21
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import 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\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":"
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import { expiredPreviewCookieHeaders } from \"../lib/expiredPreviewCookies\"\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\n\t// `clearPreviewData()` only clears Next.js preview cookies. Expire both\n\t// leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the\n\t// iframe SameSite=None; Secure write). If either survives,\n\t// `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.\n\t// Do not use `cookies().set` — that is the App Router helper. Do not\n\t// replace the existing Set-Cookie header from `clearPreviewData()`.\n\tconst existingSetCookie = config.res.getHeader(\"Set-Cookie\")\n\tconst expiredPreviewCookies = expiredPreviewCookieHeaders()\n\tconfig.res.setHeader(\n\t\t\"Set-Cookie\",\n\t\texistingSetCookie == null\n\t\t\t? expiredPreviewCookies\n\t\t\t: [\n\t\t\t\t\t...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(\n\t\t\t\t\t\tString,\n\t\t\t\t\t),\n\t\t\t\t\t...expiredPreviewCookies,\n\t\t\t\t],\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":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;CAQ7B,MAAM,oBAAoB,OAAO,IAAI,UAAU,aAAa;CAC5D,MAAM,wBAAwB,6BAA6B;AAC3D,QAAO,IAAI,UACV,cACA,qBAAqB,OAClB,wBACA,CACA,IAAI,MAAM,QAAQ,kBAAkB,GAAG,oBAAoB,CAAC,kBAAkB,EAAE,IAC/E,OACA,EACD,GAAG,sBACH,CACH;AAGD,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
|
package/dist/pages/types.d.cts
CHANGED
|
@@ -21,6 +21,7 @@ type NextApiRequestLike = {
|
|
|
21
21
|
type NextApiResponseLike = {
|
|
22
22
|
redirect(url: string): NextApiResponseLike;
|
|
23
23
|
clearPreviewData(): NextApiResponseLike;
|
|
24
|
+
getHeader(name: string): number | string | string[] | undefined;
|
|
24
25
|
setHeader(name: string, value: string | string[]): NextApiResponseLike;
|
|
25
26
|
json(body: any): void;
|
|
26
27
|
setPreviewData(data: object | string): NextApiResponseLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
package/dist/pages/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ type NextApiRequestLike = {
|
|
|
21
21
|
type NextApiResponseLike = {
|
|
22
22
|
redirect(url: string): NextApiResponseLike;
|
|
23
23
|
clearPreviewData(): NextApiResponseLike;
|
|
24
|
+
getHeader(name: string): number | string | string[] | undefined;
|
|
24
25
|
setHeader(name: string, value: string | string[]): NextApiResponseLike;
|
|
25
26
|
json(body: any): void;
|
|
26
27
|
setPreviewData(data: object | string): NextApiResponseLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/pages/types.ts"],"mappings":";;;;;KAKY,kBAAA,GAAqB,YAAA,GAChC,IAAA,CAAK,wBAAA;AADN;;;;;AAAA,KAQY,kBAAA;EACX,KAAA,EAAO,OAAA,CAAQ,MAAA;EACf,OAAA,EAAS,OAAA,CAAQ,MAAA;AAAA;;;;;AAFlB;KAUY,mBAAA;EACX,QAAA,CAAS,GAAA,WAAc,mBAAA;EACvB,gBAAA,IAAoB,mBAAA;EACpB,SAAA,CAAU,IAAA;EACV,SAAA,CAAU,IAAA,UAAc,KAAA,sBAA2B,mBAAA;EAEnD,IAAA,CAAK,IAAA;EACL,cAAA,CAAe,IAAA,oBAAwB,mBAAA;AAAA"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let _prismicio_client = require("@prismicio/client");
|
|
3
|
-
let next_navigation = require("next/navigation");
|
|
4
3
|
//#region src/redirectToPreviewURL.ts
|
|
5
4
|
async function redirectToPreviewURL(config) {
|
|
6
5
|
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
7
6
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
7
|
+
const { redirect } = await import("next/navigation");
|
|
8
8
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
9
9
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
10
|
-
if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken
|
|
10
|
+
if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken, {
|
|
11
|
+
path: "/",
|
|
12
|
+
sameSite: "none",
|
|
13
|
+
secure: true,
|
|
14
|
+
httpOnly: false
|
|
15
|
+
});
|
|
11
16
|
const previewURL = await client.resolvePreviewURL({
|
|
12
17
|
documentID,
|
|
13
18
|
previewToken,
|
|
@@ -15,7 +20,7 @@ async function redirectToPreviewURL(config) {
|
|
|
15
20
|
linkResolver
|
|
16
21
|
});
|
|
17
22
|
(await draftMode()).enable();
|
|
18
|
-
|
|
23
|
+
return redirect(previewURL);
|
|
19
24
|
}
|
|
20
25
|
//#endregion
|
|
21
26
|
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\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 { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Path=/; SameSite=None; Secure so the cookie is sent when the site is\n\t// embedded in a cross-site iframe (e.g. the Platform editor). Chrome\n\t// defaults omitted SameSite to Lax and strips the cookie from those\n\t// requests. Do not set HttpOnly: the toolbar reads `document.cookie`.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken, {\n\t\t\tpath: \"/\",\n\t\t\tsameSite: \"none\",\n\t\t\tsecure: true,\n\t\t\thttpOnly: false,\n\t\t})\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAWrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAClD,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU;EACV,CAAC;CAGH,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { cookie } from "@prismicio/client";
|
|
2
|
-
import { redirect } from "next/navigation";
|
|
3
2
|
//#region src/redirectToPreviewURL.ts
|
|
4
3
|
async function redirectToPreviewURL(config) {
|
|
5
4
|
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
6
5
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
6
|
+
const { redirect } = await import("next/navigation");
|
|
7
7
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
8
8
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
9
|
-
if (previewToken) (await cookies()).set(cookie.preview, previewToken
|
|
9
|
+
if (previewToken) (await cookies()).set(cookie.preview, previewToken, {
|
|
10
|
+
path: "/",
|
|
11
|
+
sameSite: "none",
|
|
12
|
+
secure: true,
|
|
13
|
+
httpOnly: false
|
|
14
|
+
});
|
|
10
15
|
const previewURL = await client.resolvePreviewURL({
|
|
11
16
|
documentID,
|
|
12
17
|
previewToken,
|
|
@@ -14,7 +19,7 @@ async function redirectToPreviewURL(config) {
|
|
|
14
19
|
linkResolver
|
|
15
20
|
});
|
|
16
21
|
(await draftMode()).enable();
|
|
17
|
-
redirect(previewURL);
|
|
22
|
+
return redirect(previewURL);
|
|
18
23
|
}
|
|
19
24
|
//#endregion
|
|
20
25
|
export { redirectToPreviewURL };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\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 { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Path=/; SameSite=None; Secure so the cookie is sent when the site is\n\t// embedded in a cross-site iframe (e.g. the Platform editor). Chrome\n\t// defaults omitted SameSite to Lax and strips the cookie from those\n\t// requests. Do not set HttpOnly: the toolbar reads `document.cookie`.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies()\n\t\tcookieJar.set(prismicCookie.preview, previewToken, {\n\t\t\tpath: \"/\",\n\t\t\tsameSite: \"none\",\n\t\t\tsecure: true,\n\t\t\thttpOnly: false,\n\t\t})\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAWrE,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,cAAc;EAClD,MAAM;EACN,UAAU;EACV,QAAQ;EACR,UAAU;EACV,CAAC;CAGH,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1-pr.147.2aebcfe",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"next",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"workspaces": [
|
|
19
19
|
".",
|
|
20
|
-
"e2e-projects/*"
|
|
20
|
+
"e2e-projects/*",
|
|
21
|
+
"!e2e-projects/next-15"
|
|
21
22
|
],
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
@@ -29,12 +30,12 @@
|
|
|
29
30
|
"types": "./dist/index.d.ts",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
34
35
|
},
|
|
35
36
|
"./pages": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
37
|
+
"import": "./dist/pages.js",
|
|
38
|
+
"require": "./dist/pages.cjs"
|
|
38
39
|
},
|
|
39
40
|
"./package.json": "./package.json"
|
|
40
41
|
},
|
package/src/SliceSimulator.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SimulatorManager, StateEventType, getDefaultMessage } from "@prismicio/simulator/kit"
|
|
4
4
|
import type { SliceSimulatorProps as BaseSliceSimulatorProps } from "@prismicio/simulator/kit"
|
|
5
|
-
import
|
|
5
|
+
import lzString from "lz-string"
|
|
6
6
|
import { useRouter } from "next/navigation"
|
|
7
7
|
import { useEffect, useState } from "react"
|
|
8
8
|
import type { FC, ReactNode } from "react"
|
|
@@ -52,7 +52,7 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
52
52
|
const url = new URL(window.location.href)
|
|
53
53
|
url.searchParams.set(
|
|
54
54
|
STATE_PARAMS_KEY,
|
|
55
|
-
compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
55
|
+
lzString.compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
window.history.replaceState(null, "", url)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PrismicDocument } from "@prismicio/client"
|
|
2
|
-
import
|
|
2
|
+
// Namespace import: Next.js 15 has no `cacheTag`, and a named import would fail to link.
|
|
3
|
+
import * as nextCache from "next/cache"
|
|
3
4
|
|
|
4
5
|
import { getPrismicCacheTags } from "./getPrismicCacheTags"
|
|
5
6
|
|
|
@@ -16,5 +17,5 @@ import { getPrismicCacheTags } from "./getPrismicCacheTags"
|
|
|
16
17
|
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
17
18
|
*/
|
|
18
19
|
export function cacheTagPrismicPages(pages: PrismicDocument[]): void {
|
|
19
|
-
cacheTag(...getPrismicCacheTags(pages))
|
|
20
|
+
nextCache.cacheTag(...getPrismicCacheTags(pages))
|
|
20
21
|
}
|
package/src/exitPreview.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expiredPreviewCookieHeaders } from "./lib/expiredPreviewCookies"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
@@ -19,18 +19,21 @@ export async function exitPreview(): Promise<Response> {
|
|
|
19
19
|
// Need this to avoid the following Next.js build-time error:
|
|
20
20
|
// You're importing a component that needs next/headers. That only works
|
|
21
21
|
// in a Server Component which is not supported in the pages/ directory.
|
|
22
|
-
const {
|
|
22
|
+
const { draftMode } = await import("next/headers")
|
|
23
23
|
|
|
24
24
|
;(await draftMode()).disable()
|
|
25
25
|
|
|
26
|
-
// `redirectToPreviewURL` writes
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"Cache-Control": "no-store",
|
|
34
|
-
},
|
|
26
|
+
// `redirectToPreviewURL` writes SameSite=None; Secure. The toolbar may
|
|
27
|
+
// leave SameSite=Lax (not Secure). Those are different cookies to Chrome.
|
|
28
|
+
// Expire both on the Response. Do not use `cookies().set` / `delete()`:
|
|
29
|
+
// ResponseCookies is name-keyed, so a second `io.prismic.preview` overwrites
|
|
30
|
+
// the first and the Lax leftover survives.
|
|
31
|
+
const headers = new Headers({
|
|
32
|
+
"Cache-Control": "no-store",
|
|
35
33
|
})
|
|
34
|
+
for (const setCookie of expiredPreviewCookieHeaders()) {
|
|
35
|
+
headers.append("Set-Cookie", setCookie)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return new Response(JSON.stringify({ success: true }), { headers })
|
|
36
39
|
}
|
package/src/getSlices.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDefaultSlices } from "@prismicio/simulator/kit"
|
|
2
2
|
import type { StateEvents, StateEventType } from "@prismicio/simulator/kit"
|
|
3
|
-
import
|
|
3
|
+
import lzString from "lz-string"
|
|
4
4
|
|
|
5
5
|
export const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {
|
|
6
|
-
return state ? JSON.parse(decompressFromEncodedURIComponent(state)) : getDefaultSlices()
|
|
6
|
+
return state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices()
|
|
7
7
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cookie as prismicCookie } from "@prismicio/client"
|
|
2
|
+
|
|
3
|
+
const epoch = new Date(0)
|
|
4
|
+
|
|
5
|
+
/** Expired `Set-Cookie` values for both leftover `io.prismic.preview` shapes. */
|
|
6
|
+
export function expiredPreviewCookieHeaders(name = prismicCookie.preview): string[] {
|
|
7
|
+
const expires = `Expires=${epoch.toUTCString()}`
|
|
8
|
+
|
|
9
|
+
return [
|
|
10
|
+
`${name}=; Path=/; ${expires}; SameSite=Lax`,
|
|
11
|
+
`${name}=; Path=/; ${expires}; SameSite=None; Secure`,
|
|
12
|
+
]
|
|
13
|
+
}
|
package/src/pages/exitPreview.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expiredPreviewCookieHeaders } from "../lib/expiredPreviewCookies"
|
|
1
2
|
import type { NextApiRequestLike, NextApiResponseLike } from "./types"
|
|
2
3
|
|
|
3
4
|
/** Configuration for `exitPreview()`. */
|
|
@@ -35,6 +36,26 @@ export type ExitPreviewAPIRouteConfig = {
|
|
|
35
36
|
export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
|
|
36
37
|
config.res.clearPreviewData()
|
|
37
38
|
|
|
39
|
+
// `clearPreviewData()` only clears Next.js preview cookies. Expire both
|
|
40
|
+
// leftover `io.prismic.preview` shapes (toolbar Lax, not Secure; and the
|
|
41
|
+
// iframe SameSite=None; Secure write). If either survives,
|
|
42
|
+
// `<PrismicPreview>` calls `start()` → `/api/preview` and preview returns.
|
|
43
|
+
// Do not use `cookies().set` — that is the App Router helper. Do not
|
|
44
|
+
// replace the existing Set-Cookie header from `clearPreviewData()`.
|
|
45
|
+
const existingSetCookie = config.res.getHeader("Set-Cookie")
|
|
46
|
+
const expiredPreviewCookies = expiredPreviewCookieHeaders()
|
|
47
|
+
config.res.setHeader(
|
|
48
|
+
"Set-Cookie",
|
|
49
|
+
existingSetCookie == null
|
|
50
|
+
? expiredPreviewCookies
|
|
51
|
+
: [
|
|
52
|
+
...(Array.isArray(existingSetCookie) ? existingSetCookie : [existingSetCookie]).map(
|
|
53
|
+
String,
|
|
54
|
+
),
|
|
55
|
+
...expiredPreviewCookies,
|
|
56
|
+
],
|
|
57
|
+
)
|
|
58
|
+
|
|
38
59
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
39
60
|
config.res.setHeader("Cache-Control", "no-store")
|
|
40
61
|
|
package/src/pages/types.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type NextApiRequestLike = {
|
|
|
24
24
|
export type NextApiResponseLike = {
|
|
25
25
|
redirect(url: string): NextApiResponseLike
|
|
26
26
|
clearPreviewData(): NextApiResponseLike
|
|
27
|
+
getHeader(name: string): number | string | string[] | undefined
|
|
27
28
|
setHeader(name: string, value: string | string[]): NextApiResponseLike
|
|
28
29
|
// oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
|
|
29
30
|
json(body: any): void
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
|
|
2
|
-
import { redirect } from "next/navigation"
|
|
3
2
|
|
|
4
3
|
import type { NextRequestLike } from "./types"
|
|
5
4
|
|
|
@@ -41,16 +40,30 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
41
40
|
// in a Server Component which is not supported in the pages/ directory.
|
|
42
41
|
const { cookies, draftMode } = await import("next/headers")
|
|
43
42
|
|
|
43
|
+
// Dynamic so Node.js can load this module: the bare specifier (kept by
|
|
44
|
+
// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.
|
|
45
|
+
const { redirect } = await import("next/navigation")
|
|
46
|
+
|
|
44
47
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? undefined
|
|
45
48
|
|
|
46
49
|
// Set the initial preview cookie. Setting the cookie here is necessary
|
|
47
50
|
// to support unpublished previews. Without setting it here, the page
|
|
48
51
|
// will try to render without the preview cookie, leading to a
|
|
49
52
|
// PrismicNotFound error.
|
|
53
|
+
//
|
|
54
|
+
// Path=/; SameSite=None; Secure so the cookie is sent when the site is
|
|
55
|
+
// embedded in a cross-site iframe (e.g. the Platform editor). Chrome
|
|
56
|
+
// defaults omitted SameSite to Lax and strips the cookie from those
|
|
57
|
+
// requests. Do not set HttpOnly: the toolbar reads `document.cookie`.
|
|
50
58
|
const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
|
|
51
59
|
if (previewToken) {
|
|
52
60
|
const cookieJar = await cookies()
|
|
53
|
-
cookieJar.set(prismicCookie.preview, previewToken
|
|
61
|
+
cookieJar.set(prismicCookie.preview, previewToken, {
|
|
62
|
+
path: "/",
|
|
63
|
+
sameSite: "none",
|
|
64
|
+
secure: true,
|
|
65
|
+
httpOnly: false,
|
|
66
|
+
})
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
const previewURL = await client.resolvePreviewURL({
|
|
@@ -62,5 +75,5 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
62
75
|
|
|
63
76
|
;(await draftMode()).enable()
|
|
64
77
|
|
|
65
|
-
redirect(previewURL)
|
|
78
|
+
return redirect(previewURL)
|
|
66
79
|
}
|