@prismicio/next 2.2.4 → 2.3.0-canary.d1640ef
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.ts +3 -3
- 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 +24 -0
- package/dist/cacheTagPrismicPages.cjs.map +1 -0
- package/dist/cacheTagPrismicPages.d.cts +19 -0
- package/dist/cacheTagPrismicPages.d.cts.map +1 -0
- package/dist/cacheTagPrismicPages.d.ts +19 -0
- package/dist/cacheTagPrismicPages.d.ts.map +1 -0
- package/dist/cacheTagPrismicPages.js +22 -0
- package/dist/cacheTagPrismicPages.js.map +1 -0
- package/dist/enableAutoPreviews.cjs +2 -16
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts.map +1 -1
- package/dist/enableAutoPreviews.d.ts.map +1 -1
- package/dist/enableAutoPreviews.js +2 -15
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +4 -1
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts.map +1 -1
- package/dist/exitPreview.d.ts.map +1 -1
- package/dist/exitPreview.js +3 -1
- package/dist/exitPreview.js.map +1 -1
- package/dist/getPreviewRef.cjs +38 -0
- package/dist/getPreviewRef.cjs.map +1 -0
- package/dist/getPreviewRef.d.cts +22 -0
- package/dist/getPreviewRef.d.cts.map +1 -0
- package/dist/getPreviewRef.d.ts +22 -0
- package/dist/getPreviewRef.d.ts.map +1 -0
- package/dist/getPreviewRef.js +37 -0
- package/dist/getPreviewRef.js.map +1 -0
- package/dist/getPrismicCacheTags.cjs +31 -0
- package/dist/getPrismicCacheTags.cjs.map +1 -0
- package/dist/getPrismicCacheTags.d.cts +16 -0
- package/dist/getPrismicCacheTags.d.cts.map +1 -0
- package/dist/getPrismicCacheTags.d.ts +16 -0
- package/dist/getPrismicCacheTags.d.ts.map +1 -0
- package/dist/getPrismicCacheTags.js +30 -0
- package/dist/getPrismicCacheTags.js.map +1 -0
- 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/index.cjs +8 -0
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/redirectToPreviewURL.cjs +2 -2
- 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 +2 -2
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/revalidatePrismicPages.cjs +20 -0
- package/dist/revalidatePrismicPages.cjs.map +1 -0
- package/dist/revalidatePrismicPages.d.cts +14 -0
- package/dist/revalidatePrismicPages.d.cts.map +1 -0
- package/dist/revalidatePrismicPages.d.ts +14 -0
- package/dist/revalidatePrismicPages.d.ts.map +1 -0
- package/dist/revalidatePrismicPages.js +19 -0
- package/dist/revalidatePrismicPages.js.map +1 -0
- package/package.json +7 -6
- package/src/SliceSimulator.tsx +2 -2
- package/src/cacheTagPrismicPages.ts +21 -0
- package/src/enableAutoPreviews.ts +4 -33
- package/src/exitPreview.ts +7 -1
- package/src/getPreviewRef.ts +51 -0
- package/src/getPrismicCacheTags.ts +46 -0
- package/src/getSlices.ts +2 -2
- package/src/index.ts +8 -0
- package/src/redirectToPreviewURL.ts +5 -2
- package/src/revalidatePrismicPages.ts +19 -0
|
@@ -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>, "
|
|
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>, "
|
|
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>, "
|
|
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>, "
|
|
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>, "
|
|
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>, "
|
|
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
|
|
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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
|
|
3
|
+
let next_cache_js = require("next/cache.js");
|
|
4
|
+
next_cache_js = require_runtime.__toESM(next_cache_js);
|
|
5
|
+
//#region src/cacheTagPrismicPages.ts
|
|
6
|
+
/**
|
|
7
|
+
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
8
|
+
* revalidated when their content changes.
|
|
9
|
+
*
|
|
10
|
+
* Linked documents (via content relationships) are tagged as well, so the cache entry is
|
|
11
|
+
* revalidated when any of its nested documents change.
|
|
12
|
+
*
|
|
13
|
+
* @param pages - A set of Prismic pages used to tag the cache entry.
|
|
14
|
+
* @experimental
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
17
|
+
*/
|
|
18
|
+
function cacheTagPrismicPages(pages) {
|
|
19
|
+
next_cache_js.cacheTag(...require_getPrismicCacheTags.getPrismicCacheTags(pages));
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.cacheTagPrismicPages = cacheTagPrismicPages;
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=cacheTagPrismicPages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PrismicDocument } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/cacheTagPrismicPages.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
6
|
+
* revalidated when their content changes.
|
|
7
|
+
*
|
|
8
|
+
* Linked documents (via content relationships) are tagged as well, so the cache entry is
|
|
9
|
+
* revalidated when any of its nested documents change.
|
|
10
|
+
*
|
|
11
|
+
* @param pages - A set of Prismic pages used to tag the cache entry.
|
|
12
|
+
* @experimental
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
15
|
+
*/
|
|
16
|
+
declare function cacheTagPrismicPages(pages: PrismicDocument[]): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { cacheTagPrismicPages };
|
|
19
|
+
//# sourceMappingURL=cacheTagPrismicPages.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.d.cts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAkBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PrismicDocument } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/cacheTagPrismicPages.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
6
|
+
* revalidated when their content changes.
|
|
7
|
+
*
|
|
8
|
+
* Linked documents (via content relationships) are tagged as well, so the cache entry is
|
|
9
|
+
* revalidated when any of its nested documents change.
|
|
10
|
+
*
|
|
11
|
+
* @param pages - A set of Prismic pages used to tag the cache entry.
|
|
12
|
+
* @experimental
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
15
|
+
*/
|
|
16
|
+
declare function cacheTagPrismicPages(pages: PrismicDocument[]): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { cacheTagPrismicPages };
|
|
19
|
+
//# sourceMappingURL=cacheTagPrismicPages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheTagPrismicPages.d.ts","names":[],"sources":["../src/cacheTagPrismicPages.ts"],"mappings":";;;;;AAkBA;;;;;;;;;;iBAAgB,oBAAA,CAAqB,KAAA,EAAO,eAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
|
|
2
|
+
import * as nextCache from "next/cache.js";
|
|
3
|
+
//#region src/cacheTagPrismicPages.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
6
|
+
* revalidated when their content changes.
|
|
7
|
+
*
|
|
8
|
+
* Linked documents (via content relationships) are tagged as well, so the cache entry is
|
|
9
|
+
* revalidated when any of its nested documents change.
|
|
10
|
+
*
|
|
11
|
+
* @param pages - A set of Prismic pages used to tag the cache entry.
|
|
12
|
+
* @experimental
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
15
|
+
*/
|
|
16
|
+
function cacheTagPrismicPages(pages) {
|
|
17
|
+
nextCache.cacheTag(...getPrismicCacheTags(pages));
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { cacheTagPrismicPages };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=cacheTagPrismicPages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
require("./
|
|
2
|
-
let _prismicio_client = require("@prismicio/client");
|
|
1
|
+
const require_getPreviewRef = require("./getPreviewRef.cjs");
|
|
3
2
|
//#region src/enableAutoPreviews.ts
|
|
4
3
|
/**
|
|
5
4
|
* Configures a Prismic client to automatically query draft content during a preview session.
|
|
@@ -7,20 +6,7 @@ let _prismicio_client = require("@prismicio/client");
|
|
|
7
6
|
* @param config - Configuration for the function.
|
|
8
7
|
*/
|
|
9
8
|
function enableAutoPreviews(config) {
|
|
10
|
-
config.client.queryContentFromRef(
|
|
11
|
-
const { cookies, draftMode } = await import("next/headers.js");
|
|
12
|
-
let isDraftModeEnabled = false;
|
|
13
|
-
try {
|
|
14
|
-
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
15
|
-
} catch {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (!isDraftModeEnabled) return;
|
|
19
|
-
const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
|
|
20
|
-
if (!cookie) return;
|
|
21
|
-
if (!cookie.includes("websitePreviewId=")) return;
|
|
22
|
-
return cookie;
|
|
23
|
-
});
|
|
9
|
+
config.client.queryContentFromRef(() => require_getPreviewRef.getPreviewRef());
|
|
24
10
|
}
|
|
25
11
|
//#endregion
|
|
26
12
|
exports.enableAutoPreviews = enableAutoPreviews;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.cjs","names":["
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.cjs","names":["getPreviewRef"],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\"\n\nimport { getPreviewRef } from \"./getPreviewRef\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(() => getPreviewRef())\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,0BAA0BA,sBAAAA,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.d.cts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.d.cts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAKY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.d.ts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.d.ts","names":[],"sources":["../src/enableAutoPreviews.ts"],"mappings":";;;;KAKY,wBAAA;EAAA,oEAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;AAAA;;;;;;iBAQE,kBAAA,CAAmB,MAAA,EAAQ,wBAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPreviewRef } from "./getPreviewRef.js";
|
|
2
2
|
//#region src/enableAutoPreviews.ts
|
|
3
3
|
/**
|
|
4
4
|
* Configures a Prismic client to automatically query draft content during a preview session.
|
|
@@ -6,20 +6,7 @@ import { cookie } from "@prismicio/client";
|
|
|
6
6
|
* @param config - Configuration for the function.
|
|
7
7
|
*/
|
|
8
8
|
function enableAutoPreviews(config) {
|
|
9
|
-
config.client.queryContentFromRef(
|
|
10
|
-
const { cookies, draftMode } = await import("next/headers.js");
|
|
11
|
-
let isDraftModeEnabled = false;
|
|
12
|
-
try {
|
|
13
|
-
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
14
|
-
} catch {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (!isDraftModeEnabled) return;
|
|
18
|
-
const cookie$1 = (await cookies()).get(cookie.preview)?.value;
|
|
19
|
-
if (!cookie$1) return;
|
|
20
|
-
if (!cookie$1.includes("websitePreviewId=")) return;
|
|
21
|
-
return cookie$1;
|
|
22
|
-
});
|
|
9
|
+
config.client.queryContentFromRef(() => getPreviewRef());
|
|
23
10
|
}
|
|
24
11
|
//#endregion
|
|
25
12
|
export { enableAutoPreviews };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.js","names":[
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.js","names":[],"sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\"\n\nimport { getPreviewRef } from \"./getPreviewRef\"\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\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, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">\n}\n\n/**\n * Configures a Prismic client to automatically query draft content during a preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(() => getPreviewRef())\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,mBAAmB,QAAwC;AAG1E,QAAO,OAAO,0BAA0B,eAAe,CAAC"}
|
package/dist/exitPreview.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
1
3
|
//#region src/exitPreview.ts
|
|
2
4
|
/**
|
|
3
5
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
@@ -15,8 +17,9 @@
|
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
19
|
async function exitPreview() {
|
|
18
|
-
const { draftMode } = await import("next/headers.js");
|
|
20
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
19
21
|
(await draftMode()).disable();
|
|
22
|
+
(await cookies()).delete(_prismicio_client.cookie.preview);
|
|
20
23
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
21
24
|
}
|
|
22
25
|
//#endregion
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["/**\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// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,kBAAAA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
1
2
|
//#region src/exitPreview.ts
|
|
2
3
|
/**
|
|
3
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
@@ -15,8 +16,9 @@
|
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
18
|
async function exitPreview() {
|
|
18
|
-
const { draftMode } = await import("next/headers.js");
|
|
19
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
19
20
|
(await draftMode()).disable();
|
|
21
|
+
(await cookies()).delete(cookie.preview);
|
|
20
22
|
return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
|
|
21
23
|
}
|
|
22
24
|
//#endregion
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.js","names":[],"sources":["../src/exitPreview.ts"],"sourcesContent":["/**\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// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`\n\t// clears it to close the preview-cookie loop.\n\t;(await cookies()).delete(prismicCookie.preview)\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;AAI7B,EAAC,MAAM,SAAS,EAAE,OAAOA,OAAc,QAAQ;AAGhD,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
3
|
+
//#region src/getPreviewRef.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads the Prismic preview ref for the current request when an active preview session exists.
|
|
6
|
+
*
|
|
7
|
+
* This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
|
|
8
|
+
* it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
|
|
9
|
+
* an argument so it becomes part of the cache key:
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ;```typescript
|
|
13
|
+
* import { getPreviewRef } from "@prismicio/next"
|
|
14
|
+
*
|
|
15
|
+
* const page = await fetchPage(uid, await getPreviewRef())
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @returns The active preview ref, or `undefined` if no preview session is active.
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
async function getPreviewRef() {
|
|
22
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
23
|
+
let isDraftModeEnabled = false;
|
|
24
|
+
try {
|
|
25
|
+
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!isDraftModeEnabled) return;
|
|
30
|
+
const cookie = (await cookies()).get(_prismicio_client.cookie.preview)?.value;
|
|
31
|
+
if (!cookie) return;
|
|
32
|
+
if (!cookie.includes("websitePreviewId=")) return;
|
|
33
|
+
return cookie;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.getPreviewRef = getPreviewRef;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=getPreviewRef.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPreviewRef.cjs","names":["prismicCookie"],"sources":["../src/getPreviewRef.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Reads the Prismic preview ref for the current request when an active preview session exists.\n *\n * This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use\n * it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as\n * an argument so it becomes part of the cache key:\n *\n * @example\n * \t;```typescript\n * \timport { getPreviewRef } from \"@prismicio/next\"\n *\n * \tconst page = await fetchPage(uid, await getPreviewRef())\n * \t```\n *\n * @returns The active preview ref, or `undefined` if no preview session is active.\n * @experimental\n */\nexport async function getPreviewRef(): Promise<string | undefined> {\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\tlet isDraftModeEnabled = false\n\ttry {\n\t\tisDraftModeEnabled = (await draftMode()).isEnabled\n\t} catch {\n\t\t// `draftMode()` may have been called in a place that\n\t\t// does not have access to its async storage. This\n\t\t// occurs in places like `generateStaticParams()`. We\n\t\t// can ignore this case.\n\t\treturn\n\t}\n\tif (!isDraftModeEnabled) {\n\t\treturn\n\t}\n\n\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value\n\tif (!cookie) {\n\t\treturn\n\t}\n\n\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\")\n\tif (!isActiveCookie) {\n\t\treturn\n\t}\n\n\treturn cookie\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,gBAA6C;CAIlE,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,IAAI,qBAAqB;AACzB,KAAI;AACH,wBAAsB,MAAM,WAAW,EAAE;SAClC;AAKP;;AAED,KAAI,CAAC,mBACJ;CAGD,MAAM,UAAU,MAAM,SAAS,EAAE,IAAIA,kBAAAA,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAAC,OACJ;AAID,KAAI,CADmB,OAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAO"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/getPreviewRef.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Reads the Prismic preview ref for the current request when an active preview session exists.
|
|
4
|
+
*
|
|
5
|
+
* This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
|
|
6
|
+
* it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
|
|
7
|
+
* an argument so it becomes part of the cache key:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ;```typescript
|
|
11
|
+
* import { getPreviewRef } from "@prismicio/next"
|
|
12
|
+
*
|
|
13
|
+
* const page = await fetchPage(uid, await getPreviewRef())
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns The active preview ref, or `undefined` if no preview session is active.
|
|
17
|
+
* @experimental
|
|
18
|
+
*/
|
|
19
|
+
declare function getPreviewRef(): Promise<string | undefined>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getPreviewRef };
|
|
22
|
+
//# sourceMappingURL=getPreviewRef.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPreviewRef.d.cts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/getPreviewRef.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Reads the Prismic preview ref for the current request when an active preview session exists.
|
|
4
|
+
*
|
|
5
|
+
* This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
|
|
6
|
+
* it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
|
|
7
|
+
* an argument so it becomes part of the cache key:
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ;```typescript
|
|
11
|
+
* import { getPreviewRef } from "@prismicio/next"
|
|
12
|
+
*
|
|
13
|
+
* const page = await fetchPage(uid, await getPreviewRef())
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @returns The active preview ref, or `undefined` if no preview session is active.
|
|
17
|
+
* @experimental
|
|
18
|
+
*/
|
|
19
|
+
declare function getPreviewRef(): Promise<string | undefined>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getPreviewRef };
|
|
22
|
+
//# sourceMappingURL=getPreviewRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPreviewRef.d.ts","names":[],"sources":["../src/getPreviewRef.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;;;iBAAsB,aAAA,CAAA,GAAiB,OAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
//#region src/getPreviewRef.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reads the Prismic preview ref for the current request when an active preview session exists.
|
|
5
|
+
*
|
|
6
|
+
* This is the read-side counterpart to `redirectToPreviewURL`, which writes the preview cookie. Use
|
|
7
|
+
* it with Next.js Cache Components to read the ref _outside_ a cached function and pass it _in_ as
|
|
8
|
+
* an argument so it becomes part of the cache key:
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ;```typescript
|
|
12
|
+
* import { getPreviewRef } from "@prismicio/next"
|
|
13
|
+
*
|
|
14
|
+
* const page = await fetchPage(uid, await getPreviewRef())
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @returns The active preview ref, or `undefined` if no preview session is active.
|
|
18
|
+
* @experimental
|
|
19
|
+
*/
|
|
20
|
+
async function getPreviewRef() {
|
|
21
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
22
|
+
let isDraftModeEnabled = false;
|
|
23
|
+
try {
|
|
24
|
+
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!isDraftModeEnabled) return;
|
|
29
|
+
const cookie$1 = (await cookies()).get(cookie.preview)?.value;
|
|
30
|
+
if (!cookie$1) return;
|
|
31
|
+
if (!cookie$1.includes("websitePreviewId=")) return;
|
|
32
|
+
return cookie$1;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { getPreviewRef };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=getPreviewRef.js.map
|