@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPreviewRef.js","names":["cookie","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,MAAMA,YAAU,MAAM,SAAS,EAAE,IAAIC,OAAc,QAAQ,EAAE;AAC7D,KAAI,CAACD,SACJ;AAID,KAAI,CADmBA,SAAO,SAAS,oBAAoB,CAE1D;AAGD,QAAOA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/getPrismicCacheTags.ts
|
|
2
|
+
const CACHE_TAG_PREFIX = "prismic/";
|
|
3
|
+
/**
|
|
4
|
+
* Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
|
|
5
|
+
* relationship) are included to ensure all related content can be revalidated.
|
|
6
|
+
*
|
|
7
|
+
* @param pages - A set of Prismic pages used to tag the function.
|
|
8
|
+
* @experimental
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
11
|
+
*/
|
|
12
|
+
function getPrismicCacheTags(pages) {
|
|
13
|
+
return [...new Set(getPrismicDocumentIDs(pages))].map((id) => buildPrismicCacheTag(id));
|
|
14
|
+
}
|
|
15
|
+
function buildPrismicCacheTag(id) {
|
|
16
|
+
return `${CACHE_TAG_PREFIX}${id}`;
|
|
17
|
+
}
|
|
18
|
+
function getPrismicDocumentIDs(input) {
|
|
19
|
+
if (typeof input !== "object" || input == null) return [];
|
|
20
|
+
if (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item));
|
|
21
|
+
if ("id" in input && typeof input.id === "string") {
|
|
22
|
+
if ("href" in input && typeof input.href === "string" && input.href.includes("/api/v2/documents/search?") || "link_type" in input && input.link_type === "Document") if ("data" in input && typeof input.data === "object" && input.data !== null) return [input.id, ...getPrismicDocumentIDs(input.data)];
|
|
23
|
+
else return [input.id];
|
|
24
|
+
}
|
|
25
|
+
return Object.values(input).flatMap((input) => getPrismicDocumentIDs(input));
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.buildPrismicCacheTag = buildPrismicCacheTag;
|
|
29
|
+
exports.getPrismicCacheTags = getPrismicCacheTags;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=getPrismicCacheTags.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPrismicCacheTags.cjs","names":[],"sources":["../src/getPrismicCacheTags.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n\nconst CACHE_TAG_PREFIX = \"prismic/\"\n\n/**\n * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content\n * relationship) are included to ensure all related content can be revalidated.\n *\n * @param pages - A set of Prismic pages used to tag the function.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function getPrismicCacheTags(pages: PrismicDocument[]): string[] {\n\tconst ids = [...new Set(getPrismicDocumentIDs(pages))]\n\treturn ids.map((id) => buildPrismicCacheTag(id))\n}\n\nexport function buildPrismicCacheTag(id: string): string {\n\treturn `${CACHE_TAG_PREFIX}${id}`\n}\n\nfunction getPrismicDocumentIDs(input: unknown): string[] {\n\tif (typeof input !== \"object\" || input == null) return []\n\n\tif (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item))\n\n\tif (\"id\" in input && typeof input.id === \"string\") {\n\t\t// Document\n\t\t// Content relationship or link\n\t\tif (\n\t\t\t(\"href\" in input &&\n\t\t\t\ttypeof input.href === \"string\" &&\n\t\t\t\tinput.href.includes(\"/api/v2/documents/search?\")) ||\n\t\t\t(\"link_type\" in input && input.link_type === \"Document\")\n\t\t) {\n\t\t\tif (\"data\" in input && typeof input.data === \"object\" && input.data !== null) {\n\t\t\t\treturn [input.id, ...getPrismicDocumentIDs(input.data)]\n\t\t\t} else {\n\t\t\t\treturn [input.id]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.values(input).flatMap((input) => getPrismicDocumentIDs(input))\n}\n"],"mappings":";AAEA,MAAM,mBAAmB;;;;;;;;;;AAWzB,SAAgB,oBAAoB,OAAoC;AAEvE,QADY,CAAC,GAAG,IAAI,IAAI,sBAAsB,MAAM,CAAC,CAAC,CAC3C,KAAK,OAAO,qBAAqB,GAAG,CAAC;;AAGjD,SAAgB,qBAAqB,IAAoB;AACxD,QAAO,GAAG,mBAAmB;;AAG9B,SAAS,sBAAsB,OAA0B;AACxD,KAAI,OAAO,UAAU,YAAY,SAAS,KAAM,QAAO,EAAE;AAEzD,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,SAAS,SAAS,sBAAsB,KAAK,CAAC;AAErF,KAAI,QAAQ,SAAS,OAAO,MAAM,OAAO;MAItC,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,SAAS,4BAA4B,IAChD,eAAe,SAAS,MAAM,cAAc,WAE7C,KAAI,UAAU,SAAS,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,KACvE,QAAO,CAAC,MAAM,IAAI,GAAG,sBAAsB,MAAM,KAAK,CAAC;MAEvD,QAAO,CAAC,MAAM,GAAG;;AAKpB,QAAO,OAAO,OAAO,MAAM,CAAC,SAAS,UAAU,sBAAsB,MAAM,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PrismicDocument } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/getPrismicCacheTags.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
|
|
6
|
+
* relationship) are included to ensure all related content can be revalidated.
|
|
7
|
+
*
|
|
8
|
+
* @param pages - A set of Prismic pages used to tag the function.
|
|
9
|
+
* @experimental
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
12
|
+
*/
|
|
13
|
+
declare function getPrismicCacheTags(pages: PrismicDocument[]): string[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getPrismicCacheTags };
|
|
16
|
+
//# sourceMappingURL=getPrismicCacheTags.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPrismicCacheTags.d.cts","names":[],"sources":["../src/getPrismicCacheTags.ts"],"mappings":";;;;;AAaA;;;;;;;iBAAgB,mBAAA,CAAoB,KAAA,EAAO,eAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PrismicDocument } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/getPrismicCacheTags.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
|
|
6
|
+
* relationship) are included to ensure all related content can be revalidated.
|
|
7
|
+
*
|
|
8
|
+
* @param pages - A set of Prismic pages used to tag the function.
|
|
9
|
+
* @experimental
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
12
|
+
*/
|
|
13
|
+
declare function getPrismicCacheTags(pages: PrismicDocument[]): string[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getPrismicCacheTags };
|
|
16
|
+
//# sourceMappingURL=getPrismicCacheTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPrismicCacheTags.d.ts","names":[],"sources":["../src/getPrismicCacheTags.ts"],"mappings":";;;;;AAaA;;;;;;;iBAAgB,mBAAA,CAAoB,KAAA,EAAO,eAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/getPrismicCacheTags.ts
|
|
2
|
+
const CACHE_TAG_PREFIX = "prismic/";
|
|
3
|
+
/**
|
|
4
|
+
* Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content
|
|
5
|
+
* relationship) are included to ensure all related content can be revalidated.
|
|
6
|
+
*
|
|
7
|
+
* @param pages - A set of Prismic pages used to tag the function.
|
|
8
|
+
* @experimental
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
11
|
+
*/
|
|
12
|
+
function getPrismicCacheTags(pages) {
|
|
13
|
+
return [...new Set(getPrismicDocumentIDs(pages))].map((id) => buildPrismicCacheTag(id));
|
|
14
|
+
}
|
|
15
|
+
function buildPrismicCacheTag(id) {
|
|
16
|
+
return `${CACHE_TAG_PREFIX}${id}`;
|
|
17
|
+
}
|
|
18
|
+
function getPrismicDocumentIDs(input) {
|
|
19
|
+
if (typeof input !== "object" || input == null) return [];
|
|
20
|
+
if (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item));
|
|
21
|
+
if ("id" in input && typeof input.id === "string") {
|
|
22
|
+
if ("href" in input && typeof input.href === "string" && input.href.includes("/api/v2/documents/search?") || "link_type" in input && input.link_type === "Document") if ("data" in input && typeof input.data === "object" && input.data !== null) return [input.id, ...getPrismicDocumentIDs(input.data)];
|
|
23
|
+
else return [input.id];
|
|
24
|
+
}
|
|
25
|
+
return Object.values(input).flatMap((input) => getPrismicDocumentIDs(input));
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { buildPrismicCacheTag, getPrismicCacheTags };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=getPrismicCacheTags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPrismicCacheTags.js","names":[],"sources":["../src/getPrismicCacheTags.ts"],"sourcesContent":["import type { PrismicDocument } from \"@prismicio/client\"\n\nconst CACHE_TAG_PREFIX = \"prismic/\"\n\n/**\n * Generates cache tags for a set of Prismic pages. Tags for linked pages (e.g. a content\n * relationship) are included to ensure all related content can be revalidated.\n *\n * @param pages - A set of Prismic pages used to tag the function.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}\n */\nexport function getPrismicCacheTags(pages: PrismicDocument[]): string[] {\n\tconst ids = [...new Set(getPrismicDocumentIDs(pages))]\n\treturn ids.map((id) => buildPrismicCacheTag(id))\n}\n\nexport function buildPrismicCacheTag(id: string): string {\n\treturn `${CACHE_TAG_PREFIX}${id}`\n}\n\nfunction getPrismicDocumentIDs(input: unknown): string[] {\n\tif (typeof input !== \"object\" || input == null) return []\n\n\tif (Array.isArray(input)) return input.flatMap((item) => getPrismicDocumentIDs(item))\n\n\tif (\"id\" in input && typeof input.id === \"string\") {\n\t\t// Document\n\t\t// Content relationship or link\n\t\tif (\n\t\t\t(\"href\" in input &&\n\t\t\t\ttypeof input.href === \"string\" &&\n\t\t\t\tinput.href.includes(\"/api/v2/documents/search?\")) ||\n\t\t\t(\"link_type\" in input && input.link_type === \"Document\")\n\t\t) {\n\t\t\tif (\"data\" in input && typeof input.data === \"object\" && input.data !== null) {\n\t\t\t\treturn [input.id, ...getPrismicDocumentIDs(input.data)]\n\t\t\t} else {\n\t\t\t\treturn [input.id]\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Object.values(input).flatMap((input) => getPrismicDocumentIDs(input))\n}\n"],"mappings":";AAEA,MAAM,mBAAmB;;;;;;;;;;AAWzB,SAAgB,oBAAoB,OAAoC;AAEvE,QADY,CAAC,GAAG,IAAI,IAAI,sBAAsB,MAAM,CAAC,CAAC,CAC3C,KAAK,OAAO,qBAAqB,GAAG,CAAC;;AAGjD,SAAgB,qBAAqB,IAAoB;AACxD,QAAO,GAAG,mBAAmB;;AAG9B,SAAS,sBAAsB,OAA0B;AACxD,KAAI,OAAO,UAAU,YAAY,SAAS,KAAM,QAAO,EAAE;AAEzD,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,SAAS,SAAS,sBAAsB,KAAK,CAAC;AAErF,KAAI,QAAQ,SAAS,OAAO,MAAM,OAAO;MAItC,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,MAAM,KAAK,SAAS,4BAA4B,IAChD,eAAe,SAAS,MAAM,cAAc,WAE7C,KAAI,UAAU,SAAS,OAAO,MAAM,SAAS,YAAY,MAAM,SAAS,KACvE,QAAO,CAAC,MAAM,IAAI,GAAG,sBAAsB,MAAM,KAAK,CAAC;MAEvD,QAAO,CAAC,MAAM,GAAG;;AAKpB,QAAO,OAAO,OAAO,MAAM,CAAC,SAAS,UAAU,sBAAsB,MAAM,CAAC"}
|
package/dist/getSlices.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
require("./_virtual/_rolldown/runtime.cjs");
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
|
|
3
3
|
let lz_string = require("lz-string");
|
|
4
|
+
lz_string = require_runtime.__toESM(lz_string);
|
|
4
5
|
//#region src/getSlices.ts
|
|
5
6
|
const getSlices = (state) => {
|
|
6
|
-
return state ? JSON.parse(
|
|
7
|
+
return state ? JSON.parse(lz_string.default.decompressFromEncodedURIComponent(state)) : (0, _prismicio_simulator_kit.getDefaultSlices)();
|
|
7
8
|
};
|
|
8
9
|
//#endregion
|
|
9
10
|
exports.getSlices = getSlices;
|
package/dist/getSlices.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSlices.cjs","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"getSlices.cjs","names":["lzString"],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\n\nexport const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {\n\treturn state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices()\n}\n"],"mappings":";;;;;AAIA,MAAa,aAAa,UAAyE;AAClG,QAAO,QAAQ,KAAK,MAAMA,UAAAA,QAAS,kCAAkC,MAAM,CAAC,IAAA,GAAA,yBAAA,mBAAqB"}
|
package/dist/getSlices.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getDefaultSlices } from "@prismicio/simulator/kit";
|
|
2
|
-
import
|
|
2
|
+
import lzString from "lz-string";
|
|
3
3
|
//#region src/getSlices.ts
|
|
4
4
|
const getSlices = (state) => {
|
|
5
|
-
return state ? JSON.parse(decompressFromEncodedURIComponent(state)) : getDefaultSlices();
|
|
5
|
+
return state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices();
|
|
6
6
|
};
|
|
7
7
|
//#endregion
|
|
8
8
|
export { getSlices };
|
package/dist/getSlices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSlices.js","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport
|
|
1
|
+
{"version":3,"file":"getSlices.js","names":[],"sources":["../src/getSlices.ts"],"sourcesContent":["import { getDefaultSlices } from \"@prismicio/simulator/kit\"\nimport type { StateEvents, StateEventType } from \"@prismicio/simulator/kit\"\nimport lzString from \"lz-string\"\n\nexport const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {\n\treturn state ? JSON.parse(lzString.decompressFromEncodedURIComponent(state)) : getDefaultSlices()\n}\n"],"mappings":";;;AAIA,MAAa,aAAa,UAAyE;AAClG,QAAO,QAAQ,KAAK,MAAM,SAAS,kCAAkC,MAAM,CAAC,GAAG,kBAAkB"}
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_exitPreview = require("./exitPreview.cjs");
|
|
3
3
|
const require_PrismicPreview = require("./PrismicPreview.cjs");
|
|
4
4
|
const require_PrismicNextLink = require("./PrismicNextLink.cjs");
|
|
5
|
+
const require_getPreviewRef = require("./getPreviewRef.cjs");
|
|
5
6
|
const require_enableAutoPreviews = require("./enableAutoPreviews.cjs");
|
|
6
7
|
const require_redirectToPreviewURL = require("./redirectToPreviewURL.cjs");
|
|
7
8
|
const require_imgixLoader = require("./imgixLoader.cjs");
|
|
@@ -9,13 +10,20 @@ const require_PrismicNextImage = require("./PrismicNextImage.cjs");
|
|
|
9
10
|
const require_getSlices = require("./getSlices.cjs");
|
|
10
11
|
const require_SliceSimulator = require("./SliceSimulator.cjs");
|
|
11
12
|
const require_createLocaleRedirect = require("./createLocaleRedirect.cjs");
|
|
13
|
+
const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
|
|
14
|
+
const require_cacheTagPrismicPages = require("./cacheTagPrismicPages.cjs");
|
|
15
|
+
const require_revalidatePrismicPages = require("./revalidatePrismicPages.cjs");
|
|
12
16
|
exports.PrismicNextImage = require_PrismicNextImage.PrismicNextImage;
|
|
13
17
|
exports.PrismicNextLink = require_PrismicNextLink.PrismicNextLink;
|
|
14
18
|
exports.PrismicPreview = require_PrismicPreview.PrismicPreview;
|
|
15
19
|
exports.SliceSimulator = require_SliceSimulator.SliceSimulator;
|
|
20
|
+
exports.cacheTagPrismicPages = require_cacheTagPrismicPages.cacheTagPrismicPages;
|
|
16
21
|
exports.createLocaleRedirect = require_createLocaleRedirect.createLocaleRedirect;
|
|
17
22
|
exports.enableAutoPreviews = require_enableAutoPreviews.enableAutoPreviews;
|
|
18
23
|
exports.exitPreview = require_exitPreview.exitPreview;
|
|
24
|
+
exports.getPreviewRef = require_getPreviewRef.getPreviewRef;
|
|
25
|
+
exports.getPrismicCacheTags = require_getPrismicCacheTags.getPrismicCacheTags;
|
|
19
26
|
exports.getSlices = require_getSlices.getSlices;
|
|
20
27
|
exports.imgixLoader = require_imgixLoader.imgixLoader;
|
|
21
28
|
exports.redirectToPreviewURL = require_redirectToPreviewURL.redirectToPreviewURL;
|
|
29
|
+
exports.revalidatePrismicPages = require_revalidatePrismicPages.revalidatePrismicPages;
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import { exitPreview } from "./exitPreview.cjs";
|
|
|
2
2
|
import { PrismicPreview, PrismicPreviewProps } from "./PrismicPreview.cjs";
|
|
3
3
|
import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.cjs";
|
|
4
4
|
import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./enableAutoPreviews.cjs";
|
|
5
|
+
import { getPreviewRef } from "./getPreviewRef.cjs";
|
|
5
6
|
import { CreateClientConfig } from "./types.cjs";
|
|
6
7
|
import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./redirectToPreviewURL.cjs";
|
|
7
8
|
import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.cjs";
|
|
@@ -9,4 +10,7 @@ import { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps } from "./Sli
|
|
|
9
10
|
import { getSlices } from "./getSlices.cjs";
|
|
10
11
|
import { imgixLoader } from "./imgixLoader.cjs";
|
|
11
12
|
import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.cjs";
|
|
12
|
-
|
|
13
|
+
import { getPrismicCacheTags } from "./getPrismicCacheTags.cjs";
|
|
14
|
+
import { cacheTagPrismicPages } from "./cacheTagPrismicPages.cjs";
|
|
15
|
+
import { revalidatePrismicPages } from "./revalidatePrismicPages.cjs";
|
|
16
|
+
export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { exitPreview } from "./exitPreview.js";
|
|
|
2
2
|
import { PrismicPreview, PrismicPreviewProps } from "./PrismicPreview.js";
|
|
3
3
|
import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.js";
|
|
4
4
|
import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./enableAutoPreviews.js";
|
|
5
|
+
import { getPreviewRef } from "./getPreviewRef.js";
|
|
5
6
|
import { CreateClientConfig } from "./types.js";
|
|
6
7
|
import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./redirectToPreviewURL.js";
|
|
7
8
|
import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.js";
|
|
@@ -9,4 +10,7 @@ import { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps } from "./Sli
|
|
|
9
10
|
import { getSlices } from "./getSlices.js";
|
|
10
11
|
import { imgixLoader } from "./imgixLoader.js";
|
|
11
12
|
import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
12
|
-
|
|
13
|
+
import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
|
|
14
|
+
import { cacheTagPrismicPages } from "./cacheTagPrismicPages.js";
|
|
15
|
+
import { revalidatePrismicPages } from "./revalidatePrismicPages.js";
|
|
16
|
+
export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { exitPreview } from "./exitPreview.js";
|
|
2
2
|
import { PrismicPreview } from "./PrismicPreview.js";
|
|
3
3
|
import { PrismicNextLink } from "./PrismicNextLink.js";
|
|
4
|
+
import { getPreviewRef } from "./getPreviewRef.js";
|
|
4
5
|
import { enableAutoPreviews } from "./enableAutoPreviews.js";
|
|
5
6
|
import { redirectToPreviewURL } from "./redirectToPreviewURL.js";
|
|
6
7
|
import { imgixLoader } from "./imgixLoader.js";
|
|
@@ -8,4 +9,7 @@ import { PrismicNextImage } from "./PrismicNextImage.js";
|
|
|
8
9
|
import { getSlices } from "./getSlices.js";
|
|
9
10
|
import { SliceSimulator } from "./SliceSimulator.js";
|
|
10
11
|
import { createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
11
|
-
|
|
12
|
+
import { getPrismicCacheTags } from "./getPrismicCacheTags.js";
|
|
13
|
+
import { cacheTagPrismicPages } from "./cacheTagPrismicPages.js";
|
|
14
|
+
import { revalidatePrismicPages } from "./revalidatePrismicPages.js";
|
|
15
|
+
export { PrismicNextImage, PrismicNextLink, PrismicPreview, SliceSimulator, cacheTagPrismicPages, createLocaleRedirect, enableAutoPreviews, exitPreview, getPreviewRef, getPrismicCacheTags, getSlices, imgixLoader, redirectToPreviewURL, revalidatePrismicPages };
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let _prismicio_client = require("@prismicio/client");
|
|
3
|
-
let next_navigation = require("next/navigation");
|
|
4
3
|
//#region src/redirectToPreviewURL.ts
|
|
5
4
|
async function redirectToPreviewURL(config) {
|
|
6
5
|
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
7
6
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
7
|
+
const { redirect } = await import("next/navigation");
|
|
8
8
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
9
9
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
10
10
|
if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken);
|
|
@@ -15,7 +15,7 @@ async function redirectToPreviewURL(config) {
|
|
|
15
15
|
linkResolver
|
|
16
16
|
});
|
|
17
17
|
(await draftMode()).enable();
|
|
18
|
-
|
|
18
|
+
return redirect(previewURL);
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
21
|
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\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 redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,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;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { cookie } from "@prismicio/client";
|
|
2
|
-
import { redirect } from "next/navigation";
|
|
3
2
|
//#region src/redirectToPreviewURL.ts
|
|
4
3
|
async function redirectToPreviewURL(config) {
|
|
5
4
|
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
6
5
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
6
|
+
const { redirect } = await import("next/navigation");
|
|
7
7
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
8
8
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
9
9
|
if (previewToken) (await cookies()).set(cookie.preview, previewToken);
|
|
@@ -14,7 +14,7 @@ async function redirectToPreviewURL(config) {
|
|
|
14
14
|
linkResolver
|
|
15
15
|
});
|
|
16
16
|
(await draftMode()).enable();
|
|
17
|
-
redirect(previewURL);
|
|
17
|
+
return redirect(previewURL);
|
|
18
18
|
}
|
|
19
19
|
//#endregion
|
|
20
20
|
export { redirectToPreviewURL };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\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 redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,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;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE7B,QAAO,SAAS,WAAW"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_getPrismicCacheTags = require("./getPrismicCacheTags.cjs");
|
|
3
|
+
let next_cache_js = require("next/cache.js");
|
|
4
|
+
//#region src/revalidatePrismicPages.ts
|
|
5
|
+
/**
|
|
6
|
+
* Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
|
|
7
|
+
* typically comes from a Prismic webhook triggered when publishing content.
|
|
8
|
+
*
|
|
9
|
+
* @param ids - A list of Prismic page IDs to revalidate.
|
|
10
|
+
* @experimental
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
|
|
13
|
+
*/
|
|
14
|
+
function revalidatePrismicPages(ids) {
|
|
15
|
+
for (const id of ids) (0, next_cache_js.revalidateTag)(require_getPrismicCacheTags.buildPrismicCacheTag(id), { expire: 0 });
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.revalidatePrismicPages = revalidatePrismicPages;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=revalidatePrismicPages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidatePrismicPages.cjs","names":["buildPrismicCacheTag"],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;AAC3D,MAAK,MAAM,MAAM,IAEhB,EAAA,GAAA,cAAA,eADYA,4BAAAA,qBAAqB,GAAG,EACjB,EAAE,QAAQ,GAAG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/revalidatePrismicPages.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
|
|
4
|
+
* typically comes from a Prismic webhook triggered when publishing content.
|
|
5
|
+
*
|
|
6
|
+
* @param ids - A list of Prismic page IDs to revalidate.
|
|
7
|
+
* @experimental
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
|
|
10
|
+
*/
|
|
11
|
+
declare function revalidatePrismicPages(ids: string[]): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { revalidatePrismicPages };
|
|
14
|
+
//# sourceMappingURL=revalidatePrismicPages.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidatePrismicPages.d.cts","names":[],"sources":["../src/revalidatePrismicPages.ts"],"mappings":";;AAaA;;;;;;;;iBAAgB,sBAAA,CAAuB,GAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/revalidatePrismicPages.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
|
|
4
|
+
* typically comes from a Prismic webhook triggered when publishing content.
|
|
5
|
+
*
|
|
6
|
+
* @param ids - A list of Prismic page IDs to revalidate.
|
|
7
|
+
* @experimental
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
|
|
10
|
+
*/
|
|
11
|
+
declare function revalidatePrismicPages(ids: string[]): void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { revalidatePrismicPages };
|
|
14
|
+
//# sourceMappingURL=revalidatePrismicPages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidatePrismicPages.d.ts","names":[],"sources":["../src/revalidatePrismicPages.ts"],"mappings":";;AAaA;;;;;;;;iBAAgB,sBAAA,CAAuB,GAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { buildPrismicCacheTag } from "./getPrismicCacheTags.js";
|
|
2
|
+
import { revalidateTag } from "next/cache.js";
|
|
3
|
+
//#region src/revalidatePrismicPages.ts
|
|
4
|
+
/**
|
|
5
|
+
* Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs
|
|
6
|
+
* typically comes from a Prismic webhook triggered when publishing content.
|
|
7
|
+
*
|
|
8
|
+
* @param ids - A list of Prismic page IDs to revalidate.
|
|
9
|
+
* @experimental
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}
|
|
12
|
+
*/
|
|
13
|
+
function revalidatePrismicPages(ids) {
|
|
14
|
+
for (const id of ids) revalidateTag(buildPrismicCacheTag(id), { expire: 0 });
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { revalidatePrismicPages };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=revalidatePrismicPages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidatePrismicPages.js","names":[],"sources":["../src/revalidatePrismicPages.ts"],"sourcesContent":["import { revalidateTag } from \"next/cache\"\n\nimport { buildPrismicCacheTag } from \"./getPrismicCacheTags\"\n\n/**\n * Immediately revalidates a set of Prismic pages given a list of their IDs. The list of IDs\n * typically comes from a Prismic webhook triggered when publishing content.\n *\n * @param ids - A list of Prismic page IDs to revalidate.\n * @experimental\n *\n * @see {@link https://nextjs.org/docs/app/api-reference/functions/revalidateTag}\n */\nexport function revalidatePrismicPages(ids: string[]): void {\n\tfor (const id of ids) {\n\t\tconst tag = buildPrismicCacheTag(id)\n\t\trevalidateTag(tag, { expire: 0 })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,uBAAuB,KAAqB;AAC3D,MAAK,MAAM,MAAM,IAEhB,eADY,qBAAqB,GAAG,EACjB,EAAE,QAAQ,GAAG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-canary.d1640ef",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"next",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"workspaces": [
|
|
19
19
|
".",
|
|
20
|
-
"e2e-projects/*"
|
|
20
|
+
"e2e-projects/*",
|
|
21
|
+
"!e2e-projects/next-15"
|
|
21
22
|
],
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
@@ -29,12 +30,12 @@
|
|
|
29
30
|
"types": "./dist/index.d.ts",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
34
35
|
},
|
|
35
36
|
"./pages": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
37
|
+
"import": "./dist/pages.js",
|
|
38
|
+
"require": "./dist/pages.cjs"
|
|
38
39
|
},
|
|
39
40
|
"./package.json": "./package.json"
|
|
40
41
|
},
|
package/src/SliceSimulator.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SimulatorManager, StateEventType, getDefaultMessage } from "@prismicio/simulator/kit"
|
|
4
4
|
import type { SliceSimulatorProps as BaseSliceSimulatorProps } from "@prismicio/simulator/kit"
|
|
5
|
-
import
|
|
5
|
+
import lzString from "lz-string"
|
|
6
6
|
import { useRouter } from "next/navigation"
|
|
7
7
|
import { useEffect, useState } from "react"
|
|
8
8
|
import type { FC, ReactNode } from "react"
|
|
@@ -52,7 +52,7 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
52
52
|
const url = new URL(window.location.href)
|
|
53
53
|
url.searchParams.set(
|
|
54
54
|
STATE_PARAMS_KEY,
|
|
55
|
-
compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
55
|
+
lzString.compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
window.history.replaceState(null, "", url)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PrismicDocument } from "@prismicio/client"
|
|
2
|
+
// Namespace import: Next.js 15 has no `cacheTag`, and a named import would fail to link.
|
|
3
|
+
import * as nextCache from "next/cache"
|
|
4
|
+
|
|
5
|
+
import { getPrismicCacheTags } from "./getPrismicCacheTags"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Tags the current cache entry with cache tags for a set of Prismic pages so they can be
|
|
9
|
+
* revalidated when their content changes.
|
|
10
|
+
*
|
|
11
|
+
* Linked documents (via content relationships) are tagged as well, so the cache entry is
|
|
12
|
+
* revalidated when any of its nested documents change.
|
|
13
|
+
*
|
|
14
|
+
* @param pages - A set of Prismic pages used to tag the cache entry.
|
|
15
|
+
* @experimental
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://nextjs.org/docs/app/api-reference/functions/cacheTag}
|
|
18
|
+
*/
|
|
19
|
+
export function cacheTagPrismicPages(pages: PrismicDocument[]): void {
|
|
20
|
+
nextCache.cacheTag(...getPrismicCacheTags(pages))
|
|
21
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Client } from "@prismicio/client"
|
|
2
|
+
|
|
3
|
+
import { getPreviewRef } from "./getPreviewRef"
|
|
2
4
|
|
|
3
5
|
/** Configuration for `enableAutoPreviews`. */
|
|
4
6
|
export type EnableAutoPreviewsConfig = {
|
|
@@ -17,36 +19,5 @@ export type EnableAutoPreviewsConfig = {
|
|
|
17
19
|
export function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {
|
|
18
20
|
// We use a function value so the cookie is checked on every
|
|
19
21
|
// request. We don't have a static value to read from.
|
|
20
|
-
config.client.queryContentFromRef(
|
|
21
|
-
// Need this to avoid the following Next.js build-time error:
|
|
22
|
-
// You're importing a component that needs next/headers. That only works
|
|
23
|
-
// in a Server Component which is not supported in the pages/ directory.
|
|
24
|
-
const { cookies, draftMode } = await import("next/headers")
|
|
25
|
-
|
|
26
|
-
let isDraftModeEnabled = false
|
|
27
|
-
try {
|
|
28
|
-
isDraftModeEnabled = (await draftMode()).isEnabled
|
|
29
|
-
} catch {
|
|
30
|
-
// `draftMode()` may have been called in a palce that
|
|
31
|
-
// does not have access to its async storage. This
|
|
32
|
-
// occurs in places like `generateStaticParams()`. We
|
|
33
|
-
// can ignore this case.
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
if (!isDraftModeEnabled) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const cookie = (await cookies()).get(prismicCookie.preview)?.value
|
|
41
|
-
if (!cookie) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const isActiveCookie = cookie.includes("websitePreviewId=")
|
|
46
|
-
if (!isActiveCookie) {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return cookie
|
|
51
|
-
})
|
|
22
|
+
config.client.queryContentFromRef(() => getPreviewRef())
|
|
52
23
|
}
|
package/src/exitPreview.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { cookie as prismicCookie } from "@prismicio/client"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
3
5
|
* Handler.
|
|
@@ -17,10 +19,14 @@ export async function exitPreview(): Promise<Response> {
|
|
|
17
19
|
// Need this to avoid the following Next.js build-time error:
|
|
18
20
|
// You're importing a component that needs next/headers. That only works
|
|
19
21
|
// in a Server Component which is not supported in the pages/ directory.
|
|
20
|
-
const { draftMode } = await import("next/headers")
|
|
22
|
+
const { cookies, draftMode } = await import("next/headers")
|
|
21
23
|
|
|
22
24
|
;(await draftMode()).disable()
|
|
23
25
|
|
|
26
|
+
// `redirectToPreviewURL` writes the preview cookie, so `exitPreview`
|
|
27
|
+
// clears it to close the preview-cookie loop.
|
|
28
|
+
;(await cookies()).delete(prismicCookie.preview)
|
|
29
|
+
|
|
24
30
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
25
31
|
return new Response(JSON.stringify({ success: true }), {
|
|
26
32
|
headers: {
|