@prismicio/next 2.2.2-pr.133.b4cce33 → 2.2.2-pr.133.c3369fc

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.
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -23,7 +23,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
23
23
  });
24
24
  declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
25
25
  children?: React.ReactNode | undefined;
26
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
26
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
27
27
  linkResolver?: LinkResolverFunction;
28
28
  rel?: string | AsLinkAttrsConfig["rel"];
29
29
  } & {
@@ -32,7 +32,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
32
32
  href?: never;
33
33
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
34
34
  children?: React.ReactNode | undefined;
35
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
35
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
36
36
  linkResolver?: LinkResolverFunction;
37
37
  rel?: string | AsLinkAttrsConfig["rel"];
38
38
  } & {
@@ -41,7 +41,7 @@ declare const PrismicNextLink: _$react.ForwardRefExoticComponent<(Omit<Omit<Omit
41
41
  href?: never;
42
42
  }, "ref"> | Omit<Omit<Omit<_$react.AnchorHTMLAttributes<HTMLAnchorElement>, keyof _$next_link0.LinkProps<any>> & _$next_link0.LinkProps<any> & {
43
43
  children?: React.ReactNode | undefined;
44
- } & _$react.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
44
+ } & _$react.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
45
45
  linkResolver?: LinkResolverFunction;
46
46
  rel?: string | AsLinkAttrsConfig["rel"];
47
47
  } & {
@@ -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 next_navigation_js = require("next/navigation.js");
4
+ let next_navigation = require("next/navigation");
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, next_navigation_js.useRouter)();
9
+ const { refresh } = (0, next_navigation.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\n * cookie.\n *\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;;;;;;;;;;AAWR,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
+ {"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\n * cookie.\n *\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,gBAAA,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;;;;;;;;;;AAWR,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.js";
3
+ import { useRouter } from "next/navigation";
4
4
  import { useEffect } from "react";
5
5
  //#region src/PrismicPreviewClient.tsx
6
6
  const PrismicPreviewClient = (props) => {
@@ -2,7 +2,7 @@
2
2
  require("./_virtual/_rolldown/runtime.cjs");
3
3
  const require_SliceSimulatorWrapper = require("./SliceSimulatorWrapper.cjs");
4
4
  const require_getSlices = require("./getSlices.cjs");
5
- let next_navigation_js = require("next/navigation.js");
5
+ let next_navigation = require("next/navigation");
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");
@@ -16,7 +16,7 @@ const simulatorManager = new _prismicio_simulator_kit.SimulatorManager();
16
16
  */
17
17
  const SliceSimulator = ({ children, background, zIndex, className }) => {
18
18
  const [message, setMessage] = (0, react.useState)(() => (0, _prismicio_simulator_kit.getDefaultMessage)());
19
- const router = (0, next_navigation_js.useRouter)();
19
+ const router = (0, next_navigation.useRouter)();
20
20
  const hasSlices = require_getSlices.getSlices(typeof window !== "undefined" ? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY) : void 0).length > 0;
21
21
  (0, react.useEffect)(() => {
22
22
  simulatorManager.state.on(_prismicio_simulator_kit.StateEventType.Slices, (newSlices) => {
@@ -1 +1 @@
1
- {"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","getSlices","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport { getSlices } from \"./getSlices\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\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\n * development in Slice Machine 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\tcompressToEncodedURIComponent(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":";;;;;;;;;;AAeA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,yBAAAA,kBAAkB;;;;;AAoB/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,mBAAA,GAAA,UAAA,+BAC8B,KAAK,UAAU,UAAU,CAAC,CACxD;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,OAAO,SAAS,EAAE,EAAE;KAEtC,mBACA;AACD,mBAAiB,MAAM,GACtBA,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,KAACC,8BAAAA,uBAAD;EACU;EACE;EACC;EACJ;EACG;EAEV;EACsB,CAAA"}
1
+ {"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","getSlices","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport { getSlices } from \"./getSlices\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\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\n * development in Slice Machine 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\tcompressToEncodedURIComponent(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":";;;;;;;;;;AAeA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,yBAAAA,kBAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,eAAA,GAAA,MAAA,iBAAA,GAAA,yBAAA,oBAAgD,CAAC;CACjE,MAAM,UAAA,GAAA,gBAAA,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,mBAAA,GAAA,UAAA,+BAC8B,KAAK,UAAU,UAAU,CAAC,CACxD;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,OAAO,SAAS,EAAE,EAAE;KAEtC,mBACA;AACD,mBAAiB,MAAM,GACtBA,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,KAACC,8BAAAA,uBAAD;EACU;EACE;EACC;EACJ;EACG;EAEV;EACsB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { SliceSimulatorWrapper } from "./SliceSimulatorWrapper.js";
3
3
  import { getSlices } from "./getSlices.js";
4
- import { useRouter } from "next/navigation.js";
4
+ import { useRouter } from "next/navigation";
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";
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.2.2-pr.133.b4cce33";
2
+ var version = "2.2.2-pr.133.c3369fc";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.2.2-pr.133.b4cce33";
2
+ var version = "2.2.2-pr.133.c3369fc";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1,5 +1,6 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
2
  let _prismicio_client = require("@prismicio/client");
3
+ let next_navigation = require("next/navigation");
3
4
  //#region src/redirectToPreviewURL.ts
4
5
  async function redirectToPreviewURL(config) {
5
6
  const { client, request, linkResolver, defaultURL = "/" } = config;
@@ -14,7 +15,7 @@ async function redirectToPreviewURL(config) {
14
15
  linkResolver
15
16
  });
16
17
  (await draftMode()).enable();
17
- return Response.redirect(new URL(previewURL, request.url), 307);
18
+ (0, next_navigation.redirect)(previewURL);
18
19
  }
19
20
  //#endregion
20
21
  exports.redirectToPreviewURL = redirectToPreviewURL;
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<Response> {\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\tconst documentID =\n\t\trequest.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\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}\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 Response.redirect(new URL(previewURL, request.url), 307);\n}\n"],"mappings":";;;AAwCA,eAAsB,qBACrB,QACoB;CACpB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,QAAO,SAAS,SAAS,IAAI,IAAI,YAAY,QAAQ,IAAI,EAAE,IAAI"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): 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\tconst documentID =\n\t\trequest.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\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}\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\tredirect(previewURL);\n}\n"],"mappings":";;;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,kBAAAA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,EAAA,GAAA,gBAAA,UAAS,WAAW"}
@@ -26,7 +26,7 @@ type RedirectToPreviewURLConfig = {
26
26
  */
27
27
  defaultURL?: string;
28
28
  };
29
- declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<Response>;
29
+ declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never>;
30
30
  //#endregion
31
31
  export { RedirectToPreviewURLConfig, redirectToPreviewURL };
32
32
  //# sourceMappingURL=redirectToPreviewURL.d.cts.map
@@ -26,7 +26,7 @@ type RedirectToPreviewURLConfig = {
26
26
  */
27
27
  defaultURL?: string;
28
28
  };
29
- declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<Response>;
29
+ declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never>;
30
30
  //#endregion
31
31
  export { RedirectToPreviewURLConfig, redirectToPreviewURL };
32
32
  //# sourceMappingURL=redirectToPreviewURL.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { cookie } from "@prismicio/client";
2
+ import { redirect } from "next/navigation";
2
3
  //#region src/redirectToPreviewURL.ts
3
4
  async function redirectToPreviewURL(config) {
4
5
  const { client, request, linkResolver, defaultURL = "/" } = config;
@@ -13,7 +14,7 @@ async function redirectToPreviewURL(config) {
13
14
  linkResolver
14
15
  });
15
16
  (await draftMode()).enable();
16
- return Response.redirect(new URL(previewURL, request.url), 307);
17
+ redirect(previewURL);
17
18
  }
18
19
  //#endregion
19
20
  export { redirectToPreviewURL };
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<Response> {\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\tconst documentID =\n\t\trequest.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\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}\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 Response.redirect(new URL(previewURL, request.url), 307);\n}\n"],"mappings":";;AAwCA,eAAsB,qBACrB,QACoB;CACpB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,QAAO,SAAS,SAAS,IAAI,IAAI,YAAY,QAAQ,IAAI,EAAE,IAAI"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} 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\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): 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\tconst documentID =\n\t\trequest.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\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}\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\tredirect(previewURL);\n}\n"],"mappings":";;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,UAAS,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.2.2-pr.133.b4cce33",
3
+ "version": "2.2.2-pr.133.c3369fc",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,3 +1,4 @@
1
+ import { redirect } from "next/navigation";
1
2
  import {
2
3
  cookie as prismicCookie,
3
4
  type Client,
@@ -40,7 +41,7 @@ export type RedirectToPreviewURLConfig = {
40
41
 
41
42
  export async function redirectToPreviewURL(
42
43
  config: RedirectToPreviewURLConfig,
43
- ): Promise<Response> {
44
+ ): Promise<never> {
44
45
  const { client, request, linkResolver, defaultURL = "/" } = config;
45
46
 
46
47
  // Need this to avoid the following Next.js build-time error:
@@ -70,5 +71,5 @@ export async function redirectToPreviewURL(
70
71
 
71
72
  (await draftMode()).enable();
72
73
 
73
- return Response.redirect(new URL(previewURL, request.url), 307);
74
+ redirect(previewURL);
74
75
  }