@prismicio/next 2.2.0-pr.123.1c009e2 → 2.2.0-pr.125.afe01f5
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/{PrismicImage.d.cts → PrismicNextImage.d.ts} +7 -8
- package/dist/PrismicNextImage.js +69 -0
- package/dist/PrismicNextImage.js.map +1 -0
- package/dist/{PrismicLink.d.cts → PrismicNextLink.d.ts} +6 -7
- package/dist/PrismicNextLink.js +29 -0
- package/dist/PrismicNextLink.js.map +1 -0
- package/dist/{PrismicPreview.d.cts → PrismicPreview.d.ts} +1 -1
- package/dist/PrismicPreview.js +39 -0
- package/dist/PrismicPreview.js.map +1 -0
- package/dist/{PrismicPreviewClient.cjs → PrismicPreviewClient.js} +12 -13
- package/dist/PrismicPreviewClient.js.map +1 -0
- package/dist/{SliceSimulator.d.cts → SliceSimulator.d.ts} +1 -1
- package/dist/SliceSimulator.js +48 -0
- package/dist/SliceSimulator.js.map +1 -0
- package/dist/SliceSimulatorWrapper.js +35 -0
- package/dist/SliceSimulatorWrapper.js.map +1 -0
- package/dist/{createLocaleRedirect.d.cts → createLocaleRedirect.d.ts} +1 -1
- package/dist/createLocaleRedirect.js +14 -0
- package/dist/createLocaleRedirect.js.map +1 -0
- package/dist/{enableAutoPreviews.d.cts → enableAutoPreviews.d.ts} +1 -1
- package/dist/{enableAutoPreviews.cjs → enableAutoPreviews.js} +7 -8
- package/dist/enableAutoPreviews.js.map +1 -0
- package/dist/{exitPreview.d.cts → exitPreview.d.ts} +1 -1
- package/dist/{exitPreview.cjs → exitPreview.js} +2 -3
- package/dist/exitPreview.js.map +1 -0
- package/dist/{getSlices.d.cts → getSlices.d.ts} +1 -1
- package/dist/getSlices.js +11 -0
- package/dist/getSlices.js.map +1 -0
- package/dist/{imgixLoader.d.cts → imgixLoader.d.ts} +1 -1
- package/dist/{imgixLoader.cjs → imgixLoader.js} +4 -5
- package/dist/imgixLoader.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/lib/{devMsg.cjs → devMsg.js} +4 -4
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/{resolveDefaultExport.cjs → resolveDefaultExport.js} +2 -3
- package/dist/lib/resolveDefaultExport.js.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/pages/{PrismicPreview.d.cts → PrismicPreview.d.ts} +1 -1
- package/dist/pages/{PrismicPreview.cjs → PrismicPreview.js} +13 -15
- package/dist/pages/PrismicPreview.js.map +1 -0
- package/dist/pages/{SliceSimulator.d.cts → SliceSimulator.d.ts} +1 -1
- package/dist/pages/SliceSimulator.js +40 -0
- package/dist/pages/SliceSimulator.js.map +1 -0
- package/dist/pages/{enableAutoPreviews.d.cts → enableAutoPreviews.d.ts} +2 -2
- package/dist/pages/{enableAutoPreviews.cjs → enableAutoPreviews.js} +2 -3
- package/dist/pages/enableAutoPreviews.js.map +1 -0
- package/dist/pages/{exitPreview.d.cts → exitPreview.d.ts} +2 -2
- package/dist/pages/{exitPreview.cjs → exitPreview.js} +2 -3
- package/dist/pages/exitPreview.js.map +1 -0
- package/dist/pages/{redirectToPreviewURL.d.cts → redirectToPreviewURL.d.ts} +2 -2
- package/dist/pages/{redirectToPreviewURL.cjs → redirectToPreviewURL.js} +2 -3
- package/dist/pages/redirectToPreviewURL.js.map +1 -0
- package/dist/pages/{setPreviewData.d.cts → setPreviewData.d.ts} +2 -2
- package/dist/pages/setPreviewData.js +12 -0
- package/dist/pages/setPreviewData.js.map +1 -0
- package/dist/pages/{types.d.cts → types.d.ts} +2 -2
- package/dist/pages.d.ts +12 -0
- package/dist/pages.js +12 -0
- package/dist/{redirectToPreviewURL.d.cts → redirectToPreviewURL.d.ts} +2 -2
- package/dist/{redirectToPreviewURL.cjs → redirectToPreviewURL.js} +6 -7
- package/dist/redirectToPreviewURL.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +1 -1
- package/package.json +5 -18
- package/src/PrismicNextImage.tsx +185 -0
- package/src/PrismicNextLink.tsx +67 -0
- package/src/index.ts +5 -21
- package/src/pages/index.ts +4 -20
- package/dist/PrismicImage.cjs +0 -71
- package/dist/PrismicImage.cjs.map +0 -1
- package/dist/PrismicLink.cjs +0 -31
- package/dist/PrismicLink.cjs.map +0 -1
- package/dist/PrismicPreview.cjs +0 -41
- package/dist/PrismicPreview.cjs.map +0 -1
- package/dist/PrismicPreviewClient.cjs.map +0 -1
- package/dist/PrismicRichText.cjs +0 -50
- package/dist/PrismicRichText.cjs.map +0 -1
- package/dist/PrismicRichText.d.cts +0 -27
- package/dist/PrismicTable.cjs +0 -34
- package/dist/PrismicTable.cjs.map +0 -1
- package/dist/PrismicTable.d.cts +0 -22
- package/dist/SliceSimulator.cjs +0 -49
- package/dist/SliceSimulator.cjs.map +0 -1
- package/dist/SliceSimulatorWrapper.cjs +0 -36
- package/dist/SliceSimulatorWrapper.cjs.map +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/createLocaleRedirect.cjs +0 -14
- package/dist/createLocaleRedirect.cjs.map +0 -1
- package/dist/enableAutoPreviews.cjs.map +0 -1
- package/dist/exitPreview.cjs.map +0 -1
- package/dist/getSlices.cjs +0 -12
- package/dist/getSlices.cjs.map +0 -1
- package/dist/imgixLoader.cjs.map +0 -1
- package/dist/index.cjs +0 -47
- package/dist/index.d.cts +0 -15
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/resolveDefaultExport.cjs.map +0 -1
- package/dist/package.cjs +0 -12
- package/dist/package.cjs.map +0 -1
- package/dist/pages/PrismicPreview.cjs.map +0 -1
- package/dist/pages/SliceSimulator.cjs +0 -41
- package/dist/pages/SliceSimulator.cjs.map +0 -1
- package/dist/pages/enableAutoPreviews.cjs.map +0 -1
- package/dist/pages/exitPreview.cjs.map +0 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +0 -1
- package/dist/pages/setPreviewData.cjs +0 -13
- package/dist/pages/setPreviewData.cjs.map +0 -1
- package/dist/pages.cjs +0 -47
- package/dist/pages.d.cts +0 -15
- package/dist/redirectToPreviewURL.cjs.map +0 -1
- package/src/PrismicImage.tsx +0 -187
- package/src/PrismicLink.tsx +0 -74
- package/src/PrismicRichText.tsx +0 -63
- package/src/PrismicTable.tsx +0 -33
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { version } from "../package.js";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/devMsg.ts
|
|
4
4
|
/**
|
|
@@ -17,9 +17,9 @@ const require_package = require('../package.cjs');
|
|
|
17
17
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
18
18
|
*/
|
|
19
19
|
const devMsg = (slug) => {
|
|
20
|
-
return `https://prismic.dev/msg/next/v${
|
|
20
|
+
return `https://prismic.dev/msg/next/v${version}/${slug}`;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=devMsg.
|
|
24
|
+
export { devMsg };
|
|
25
|
+
//# sourceMappingURL=devMsg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string): string => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,UAAU,SAAyB;AAC/C,QAAO,iCAAiC,QAAQ,GAAG"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/lib/resolveDefaultExport.ts
|
|
3
2
|
/**
|
|
4
3
|
* Resolves a module's default export. The module may provide its default export
|
|
@@ -22,5 +21,5 @@ function resolveDefaultExport(mod) {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
//#endregion
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=resolveDefaultExport.
|
|
24
|
+
export { resolveDefaultExport };
|
|
25
|
+
//# sourceMappingURL=resolveDefaultExport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultExport.js","names":[],"sources":["../../src/lib/resolveDefaultExport.ts"],"sourcesContent":["/**\n * Resolves a module's default export. The module may provide its default export\n * as a `default` property on an object. This happens when named and default\n * exports are mixed in modules.\n *\n * In ES Modules, mixing is fine since the module resolver can distinguish\n * default and named exports. In transpiled modules, however, all exports are\n * put into a single object, and the default export is provided at a property\n * called `default`.\n *\n * This helper is needed by Next.js uses CJS files with named and default\n * exports.\n *\n * This helper _should_ be a temporary hack until Next.js and Node.js resolve\n * their ESM difficulties. This will likely not be removed any time soon,\n * unfortunately.\n */\nexport function resolveDefaultExport<T>(mod: T): T {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treturn \"default\" in (mod as any) ? (mod as any).default : mod;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,qBAAwB,KAAW;AAElD,QAAO,aAAc,MAAe,IAAY,UAAU"}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let next_router = require("next/router");
|
|
1
|
+
import Script from "next/script";
|
|
2
|
+
import { cookie, getToolbarSrc } from "@prismicio/client";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useRouter } from "next/router";
|
|
8
6
|
|
|
9
7
|
//#region src/pages/PrismicPreview.tsx
|
|
10
8
|
/**
|
|
@@ -18,9 +16,9 @@ let next_router = require("next/router");
|
|
|
18
16
|
*/
|
|
19
17
|
const PrismicPreview = (props) => {
|
|
20
18
|
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
21
|
-
const router =
|
|
22
|
-
const toolbarSrc =
|
|
23
|
-
|
|
19
|
+
const router = useRouter();
|
|
20
|
+
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
21
|
+
useEffect(() => {
|
|
24
22
|
const controller = new AbortController();
|
|
25
23
|
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
26
24
|
window.addEventListener("prismicPreviewEnd", onEnd, { signal: controller.signal });
|
|
@@ -61,16 +59,16 @@ const PrismicPreview = (props) => {
|
|
|
61
59
|
repositoryName,
|
|
62
60
|
router
|
|
63
61
|
]);
|
|
64
|
-
return /* @__PURE__ */
|
|
62
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [children, /* @__PURE__ */ jsx(Script, {
|
|
65
63
|
src: toolbarSrc,
|
|
66
64
|
strategy: "lazyOnload"
|
|
67
65
|
})] });
|
|
68
66
|
};
|
|
69
67
|
function getPreviewCookieRepositoryName() {
|
|
70
|
-
const cookie = window.document.cookie.split("; ").find((row) => row.startsWith(`${
|
|
71
|
-
return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1];
|
|
68
|
+
const cookie$1 = window.document.cookie.split("; ").find((row) => row.startsWith(`${cookie.preview}=`))?.split("=")[1];
|
|
69
|
+
return (decodeURIComponent(cookie$1 ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1];
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
//#endregion
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=PrismicPreview.
|
|
73
|
+
export { PrismicPreview };
|
|
74
|
+
//# sourceMappingURL=PrismicPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","names":["cookie","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { getToolbarSrc, cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/router\";\nimport Script from \"next/script\";\nimport type { FC } from \"react\";\nimport { type ReactNode, useEffect } from \"react\";\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t\tchildren,\n\t} = props;\n\n\tconst router = useRouter();\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\t//\n\t\t// We check that the current URL is a descendant of the base\n\t\t// path to prevent infinite refrehes.\n\t\tif (\n\t\t\twindow.location.href.startsWith(\n\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t) &&\n\t\t\tgetPreviewCookieRepositoryName() === repositoryName &&\n\t\t\t!router.isPreview\n\t\t) {\n\t\t\tstart();\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tfetch(router.basePath + exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tstart();\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and at least\n\t\t\t// attempted to set preview data.\n\t\t\tfetch(router.basePath + updatePreviewURL, {\n\t\t\t\tredirect: \"manual\",\n\t\t\t\tsignal: controller.signal,\n\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start or update the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\tfunction refresh() {\n\t\t\trouter.replace(router.asPath, undefined, { scroll: false });\n\t\t}\n\n\t\treturn () => controller.abort();\n\t}, [exitPreviewURL, updatePreviewURL, repositoryName, router]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n\nfunction getPreviewCookieRepositoryName() {\n\tconst cookie = window.document.cookie\n\t\t.split(\"; \")\n\t\t.find((row) => row.startsWith(`${prismicCookie.preview}=`))\n\t\t?.split(\"=\")[1];\n\n\treturn (decodeURIComponent(cookie ?? \"\").match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;CAEJ,MAAM,SAAS,WAAW;CAE1B,MAAM,aAAa,cAAc,eAAe;AAEhD,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;AAQF,MACC,OAAO,SAAS,KAAK,WACpB,OAAO,SAAS,SAAS,OAAO,SAChC,IACD,gCAAgC,KAAK,kBACrC,CAAC,OAAO,UAER,QAAO;EAGR,SAAS,MAAM,OAAc;AAC5B,SAAM,gBAAgB;AACtB,SAAM,OAAO,WAAW,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,CAAC,CACpE,MAAM,QAAQ;AACd,QAAI,CAAC,IAAI,IAAI;AACZ,aAAQ,MACP,6DAA6D,eAAe,gCAC5E;AAED;;AAGD,aAAS;KACR,CACD,YAAY,GAAG;;EAGlB,SAAS,SAAS,OAAc;AAC/B,SAAM,gBAAgB;AACtB,UAAO;;EAGR,SAAS,QAAQ;AAKhB,SAAM,OAAO,WAAW,kBAAkB;IACzC,UAAU;IACV,QAAQ,WAAW;IACnB,CAAC,CACA,MAAM,QAAQ;AACd,QAAI,IAAI,SAAS,kBAAkB;AAClC,aAAQ,MACP,mEAAmE,iBAAiB,mBACpF;AAED;;AAGD,aAAS;KACR,CACD,YAAY,GAAG;;EAGlB,SAAS,UAAU;AAClB,UAAO,QAAQ,OAAO,QAAQ,QAAW,EAAE,QAAQ,OAAO,CAAC;;AAG5D,eAAa,WAAW,OAAO;IAC7B;EAAC;EAAgB;EAAkB;EAAgB;EAAO,CAAC;AAE9D,QACC,4CACE,UACD,oBAAC;EAAO,KAAK;EAAY,UAAS;GAAe,IAC/C;;AAIL,SAAS,iCAAiC;CACzC,MAAMA,WAAS,OAAO,SAAS,OAC7B,MAAM,KAAK,CACX,MAAM,QAAQ,IAAI,WAAW,GAAGC,OAAc,QAAQ,GAAG,CAAC,EACzD,MAAM,IAAI,CAAC;AAEd,SAAQ,mBAAmBD,YAAU,GAAG,CAAC,MAAM,yBAAyB,IACvE,EAAE,EAAE"}
|
|
@@ -34,4 +34,4 @@ type SliceSimulatorProps$1 = SliceSimulatorProps & {
|
|
|
34
34
|
declare const SliceSimulator: FC<SliceSimulatorProps$1>;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { SliceSimulator, SliceSimulatorProps$1 as SliceSimulatorProps, SliceSimulatorSliceZoneProps };
|
|
37
|
-
//# sourceMappingURL=SliceSimulator.d.
|
|
37
|
+
//# sourceMappingURL=SliceSimulator.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SliceSimulatorWrapper } from "../SliceSimulatorWrapper.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { SimulatorManager, StateEventType, getDefaultMessage, getDefaultSlices } from "@prismicio/simulator/kit";
|
|
5
|
+
|
|
6
|
+
//#region src/pages/SliceSimulator.tsx
|
|
7
|
+
const simulatorManager = new SimulatorManager();
|
|
8
|
+
/**
|
|
9
|
+
* Simulate slices in isolation. The slice simulator enables live slice
|
|
10
|
+
* development in Slice Machine and live previews in the Page Builder.
|
|
11
|
+
*/
|
|
12
|
+
const SliceSimulator = ({ background, zIndex, className, sliceZone: SliceZoneComp }) => {
|
|
13
|
+
const [slices, setSlices] = useState(() => getDefaultSlices());
|
|
14
|
+
const [message, setMessage] = useState(() => getDefaultMessage());
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
simulatorManager.state.on(StateEventType.Slices, (_slices) => {
|
|
17
|
+
setSlices(_slices);
|
|
18
|
+
}, "simulator-slices");
|
|
19
|
+
simulatorManager.state.on(StateEventType.Message, (_message) => {
|
|
20
|
+
setMessage(_message);
|
|
21
|
+
}, "simulator-message");
|
|
22
|
+
simulatorManager.init();
|
|
23
|
+
return () => {
|
|
24
|
+
simulatorManager.state.off(StateEventType.Slices, "simulator-slices");
|
|
25
|
+
simulatorManager.state.off(StateEventType.Message, "simulator-message");
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return /* @__PURE__ */ jsx(SliceSimulatorWrapper, {
|
|
29
|
+
message,
|
|
30
|
+
hasSlices: slices.length > 0,
|
|
31
|
+
background,
|
|
32
|
+
zIndex,
|
|
33
|
+
className,
|
|
34
|
+
children: /* @__PURE__ */ jsx(SliceZoneComp, { slices })
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { SliceSimulator };
|
|
40
|
+
//# sourceMappingURL=SliceSimulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliceSimulator.js","names":[],"sources":["../../src/pages/SliceSimulator.tsx"],"sourcesContent":["import { SliceSimulatorWrapper } from \"../SliceSimulatorWrapper\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n\tgetDefaultSlices,\n} from \"@prismicio/simulator/kit\";\nimport type {\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n} from \"@prismicio/simulator/kit\";\nimport { useEffect, useState } from \"react\";\nimport type { ComponentType, FC } from \"react\";\n\nconst simulatorManager = new SimulatorManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: ComponentType<SliceSimulatorSliceZoneProps>;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tbackground,\n\tzIndex,\n\tclassName,\n\tsliceZone: SliceZoneComp,\n}) => {\n\tconst [slices, setSlices] = useState(() => getDefaultSlices());\n\tconst [message, setMessage] = useState(() => getDefaultMessage());\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\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(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\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}, []);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\thasSlices={slices.length > 0}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t<SliceZoneComp slices={slices} />\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;AAcA,MAAM,mBAAmB,IAAI,kBAAkB;;;;;AAiC/C,MAAa,kBAA2C,EACvD,YACA,QACA,WACA,WAAW,oBACN;CACL,MAAM,CAAC,QAAQ,aAAa,eAAe,kBAAkB,CAAC;CAC9D,MAAM,CAAC,SAAS,cAAc,eAAe,mBAAmB,CAAC;AAEjE,iBAAgB;AACf,mBAAiB,MAAM,GACtB,eAAe,SACd,YAAY;AACZ,aAAU,QAAQ;KAEnB,mBACA;AACD,mBAAiB,MAAM,GACtB,eAAe,UACd,aAAa;AACb,cAAW,SAAS;KAErB,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAI,eAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAI,eAAe,SAAS,oBAAoB;;IAEtE,EAAE,CAAC;AAEN,QACC,oBAAC;EACS;EACT,WAAW,OAAO,SAAS;EACf;EACJ;EACG;YAEX,oBAAC,iBAAsB,SAAU;GACV"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextApiRequestLike } from "./types.
|
|
1
|
+
import { NextApiRequestLike } from "./types.js";
|
|
2
2
|
import { Client } from "@prismicio/client";
|
|
3
3
|
import { PreviewData } from "next";
|
|
4
4
|
|
|
@@ -34,4 +34,4 @@ type EnableAutoPreviewsConfig = {
|
|
|
34
34
|
declare function enableAutoPreviews(config: EnableAutoPreviewsConfig): void;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { EnableAutoPreviewsConfig, enableAutoPreviews };
|
|
37
|
-
//# sourceMappingURL=enableAutoPreviews.d.
|
|
37
|
+
//# sourceMappingURL=enableAutoPreviews.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/pages/enableAutoPreviews.ts
|
|
3
2
|
/**
|
|
4
3
|
* Configures a Prismic client to automatically query draft content during a
|
|
@@ -22,5 +21,5 @@ function isPrismicPreviewData(input) {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
//#endregion
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=enableAutoPreviews.
|
|
24
|
+
export { enableAutoPreviews };
|
|
25
|
+
//# sourceMappingURL=enableAutoPreviews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.js","names":[],"sources":["../../src/pages/enableAutoPreviews.ts"],"sourcesContent":["import type { PreviewData } from \"next\";\nimport type { Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\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\t/**\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: PreviewData;\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode.\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route.\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\n\t\treturn;\n\t}\n}\n\nfunction isPrismicPreviewData(input: unknown): input is { ref: string } {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n}\n"],"mappings":";;;;;;;;AAsCA,SAAgB,mBAAmB,QAAwC;AAC1E,KAAI,iBAAiB,UAAU,OAAO,aAAa;AAIlD,MAAI,qBAAqB,OAAO,YAAY,CAC3C,QAAO,OAAO,oBAAoB,OAAO,YAAY,IAAI;AAG1D;;AAGD,KAAI,SAAS,UAAU,OAAO,KAAK;AAGlC,SAAO,OAAO,0BAA0B,OAAO,IAAI;AAEnD;;;AAIF,SAAS,qBAAqB,OAA0C;AACvE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextApiRequestLike, NextApiResponseLike } from "./types.
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/pages/exitPreview.d.ts
|
|
4
4
|
/** Configuration for `exitPreview()`. */
|
|
@@ -35,4 +35,4 @@ type ExitPreviewAPIRouteConfig = {
|
|
|
35
35
|
declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
|
|
36
36
|
//#endregion
|
|
37
37
|
export { ExitPreviewAPIRouteConfig, exitPreview };
|
|
38
|
-
//# sourceMappingURL=exitPreview.d.
|
|
38
|
+
//# sourceMappingURL=exitPreview.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/pages/exitPreview.ts
|
|
3
2
|
/**
|
|
4
3
|
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
@@ -23,5 +22,5 @@ function exitPreview(config) {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
//#endregion
|
|
26
|
-
|
|
27
|
-
//# sourceMappingURL=exitPreview.
|
|
25
|
+
export { exitPreview };
|
|
26
|
+
//# sourceMappingURL=exitPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.js","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in an API route.\n *\n * @example\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(_req, res) {\n * \treturn exitPreview({ res });\n * }\n * ```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData();\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\tconfig.res.json({ success: true });\n\n\treturn;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmCA,SAAgB,YAAY,QAAyC;AACpE,QAAO,IAAI,kBAAkB;AAG7B,QAAO,IAAI,UAAU,iBAAiB,WAAW;AAEjD,QAAO,IAAI,KAAK,EAAE,SAAS,MAAM,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextApiRequestLike, NextApiResponseLike } from "./types.
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.js";
|
|
2
2
|
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
//#region src/pages/redirectToPreviewURL.d.ts
|
|
@@ -45,4 +45,4 @@ type RedirectToPreviewURLConfig = {
|
|
|
45
45
|
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void>;
|
|
46
46
|
//#endregion
|
|
47
47
|
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
48
|
-
//# sourceMappingURL=redirectToPreviewURL.d.
|
|
48
|
+
//# sourceMappingURL=redirectToPreviewURL.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/pages/redirectToPreviewURL.ts
|
|
3
2
|
async function redirectToPreviewURL(config) {
|
|
4
3
|
const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
|
|
@@ -12,5 +11,5 @@ async function redirectToPreviewURL(config) {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
//#endregion
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=redirectToPreviewURL.
|
|
14
|
+
export { redirectToPreviewURL };
|
|
15
|
+
//# sourceMappingURL=redirectToPreviewURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":[],"sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } 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 `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst {\n\t\tclient,\n\t\treq,\n\t\tres,\n\t\tlinkResolver,\n\t\tdefaultURL = \"/\",\n\t\tbasePath = \"\",\n\t} = config;\n\n\tconst previewToken = req.query.token?.toString();\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t});\n\n\tres.redirect(basePath + previewURL);\n\n\treturn;\n}\n"],"mappings":";AAqDA,eAAsB,qBACrB,QACgB;CAChB,MAAM,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,OACR;CAEJ,MAAM,eAAe,IAAI,MAAM,OAAO,UAAU;CAEhD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA,CAAC;AAEF,KAAI,SAAS,WAAW,WAAW"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextApiRequestLike, NextApiResponseLike } from "./types.
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/pages/setPreviewData.d.ts
|
|
4
4
|
/** Configuration for `setPreviewData`. */
|
|
@@ -23,4 +23,4 @@ declare function setPreviewData({
|
|
|
23
23
|
}: SetPreviewDataConfig): void;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { SetPreviewDataConfig, setPreviewData };
|
|
26
|
-
//# sourceMappingURL=setPreviewData.d.
|
|
26
|
+
//# sourceMappingURL=setPreviewData.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/setPreviewData.ts
|
|
4
|
+
/** Set Prismic preview data for Next.js's Preview Mode. */
|
|
5
|
+
function setPreviewData({ req, res }) {
|
|
6
|
+
const ref = req.query.token || req.cookies[cookie.preview];
|
|
7
|
+
if (ref) res.setPreviewData({ ref });
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { setPreviewData };
|
|
12
|
+
//# sourceMappingURL=setPreviewData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","names":[],"sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"mappings":";;;;AAsBA,SAAgB,eAAe,EAAE,KAAK,OAAmC;CACxE,MAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.
|
|
1
|
+
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.js";
|
|
2
2
|
import { ClientConfig } from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
//#region src/pages/types.d.ts
|
|
@@ -33,4 +33,4 @@ type NextApiResponseLike = {
|
|
|
33
33
|
};
|
|
34
34
|
//#endregion
|
|
35
35
|
export { CreateClientConfig, NextApiRequestLike, NextApiResponseLike };
|
|
36
|
-
//# sourceMappingURL=types.d.
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/pages.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.js";
|
|
2
|
+
import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.js";
|
|
3
|
+
import { imgixLoader } from "./imgixLoader.js";
|
|
4
|
+
import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
5
|
+
import { SliceSimulator, SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./pages/SliceSimulator.js";
|
|
6
|
+
import { PrismicPreview, PrismicPreviewProps } from "./pages/PrismicPreview.js";
|
|
7
|
+
import { CreateClientConfig } from "./pages/types.js";
|
|
8
|
+
import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./pages/enableAutoPreviews.js";
|
|
9
|
+
import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./pages/redirectToPreviewURL.js";
|
|
10
|
+
import { ExitPreviewAPIRouteConfig, exitPreview } from "./pages/exitPreview.js";
|
|
11
|
+
import { SetPreviewDataConfig, setPreviewData } from "./pages/setPreviewData.js";
|
|
12
|
+
export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, type ExitPreviewAPIRouteConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, type SetPreviewDataConfig, SliceSimulator, type SliceSimulatorProps, type SliceSimulatorSliceZoneProps, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
|
package/dist/pages.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismicNextLink } from "./PrismicNextLink.js";
|
|
2
|
+
import { imgixLoader } from "./imgixLoader.js";
|
|
3
|
+
import { PrismicNextImage } from "./PrismicNextImage.js";
|
|
4
|
+
import { createLocaleRedirect } from "./createLocaleRedirect.js";
|
|
5
|
+
import { SliceSimulator } from "./pages/SliceSimulator.js";
|
|
6
|
+
import { PrismicPreview } from "./pages/PrismicPreview.js";
|
|
7
|
+
import { enableAutoPreviews } from "./pages/enableAutoPreviews.js";
|
|
8
|
+
import { redirectToPreviewURL } from "./pages/redirectToPreviewURL.js";
|
|
9
|
+
import { exitPreview } from "./pages/exitPreview.js";
|
|
10
|
+
import { setPreviewData } from "./pages/setPreviewData.js";
|
|
11
|
+
|
|
12
|
+
export { PrismicNextImage, PrismicNextLink, PrismicPreview, SliceSimulator, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextRequestLike } from "./types.
|
|
1
|
+
import { NextRequestLike } from "./types.js";
|
|
2
2
|
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
//#region src/redirectToPreviewURL.d.ts
|
|
@@ -30,4 +30,4 @@ type RedirectToPreviewURLConfig = {
|
|
|
30
30
|
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never>;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
33
|
-
//# sourceMappingURL=redirectToPreviewURL.d.
|
|
33
|
+
//# sourceMappingURL=redirectToPreviewURL.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let next_navigation = require("next/navigation");
|
|
1
|
+
import { cookie } from "@prismicio/client";
|
|
2
|
+
import { redirect } from "next/navigation";
|
|
4
3
|
|
|
5
4
|
//#region src/redirectToPreviewURL.ts
|
|
6
5
|
async function redirectToPreviewURL(config) {
|
|
@@ -8,7 +7,7 @@ async function redirectToPreviewURL(config) {
|
|
|
8
7
|
const { cookies, draftMode } = await import("next/headers");
|
|
9
8
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
10
9
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
11
|
-
if (previewToken) (await cookies()).set(
|
|
10
|
+
if (previewToken) (await cookies()).set(cookie.preview, previewToken);
|
|
12
11
|
const previewURL = await client.resolvePreviewURL({
|
|
13
12
|
documentID,
|
|
14
13
|
previewToken,
|
|
@@ -16,9 +15,9 @@ async function redirectToPreviewURL(config) {
|
|
|
16
15
|
linkResolver
|
|
17
16
|
});
|
|
18
17
|
(await draftMode()).enable();
|
|
19
|
-
|
|
18
|
+
redirect(previewURL);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
//#endregion
|
|
23
|
-
|
|
24
|
-
//# sourceMappingURL=redirectToPreviewURL.
|
|
22
|
+
export { redirectToPreviewURL };
|
|
23
|
+
//# sourceMappingURL=redirectToPreviewURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} from \"@prismicio/client\";\n\nimport type { NextRequestLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\");\n\n\tconst documentID =\n\t\trequest.nextUrl.searchParams.get(\"documentId\") ?? undefined;\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined;\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies();\n\t\tcookieJar.set(prismicCookie.preview, previewToken);\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t});\n\n\t(await draftMode()).enable();\n\n\tredirect(previewURL);\n}\n"],"mappings":";;;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,OAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,UAAS,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.2.0-pr.
|
|
3
|
+
"version": "2.2.0-pr.125.afe01f5",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,23 +18,11 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"type": "module",
|
|
20
20
|
"exports": {
|
|
21
|
-
".": "./dist/index.
|
|
22
|
-
"./pages": "./dist/pages.
|
|
21
|
+
".": "./dist/index.js",
|
|
22
|
+
"./pages": "./dist/pages.js",
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
|
-
"
|
|
26
|
-
"module": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.cts",
|
|
28
|
-
"typesVersions": {
|
|
29
|
-
"*": {
|
|
30
|
-
"*": [
|
|
31
|
-
"./dist/index.d.ts"
|
|
32
|
-
],
|
|
33
|
-
"pages": [
|
|
34
|
-
"./dist/pages/index.d.ts"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
},
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
38
26
|
"files": [
|
|
39
27
|
"dist",
|
|
40
28
|
"src"
|
|
@@ -55,14 +43,13 @@
|
|
|
55
43
|
"types": "tsc --noEmit"
|
|
56
44
|
},
|
|
57
45
|
"dependencies": {
|
|
58
|
-
"@prismicio/react": "^3.3.0",
|
|
59
46
|
"@prismicio/simulator": "^0.2.0",
|
|
60
47
|
"imgix-url-builder": "^0.0.5",
|
|
61
48
|
"lz-string": "^1.5.0"
|
|
62
49
|
},
|
|
63
50
|
"devDependencies": {
|
|
64
51
|
"@playwright/test": "^1.49.1",
|
|
65
|
-
"@prismicio/client": "^7.
|
|
52
|
+
"@prismicio/client": "^7.12.0",
|
|
66
53
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
67
54
|
"@types/node": "^22.10.2",
|
|
68
55
|
"@types/react": "^19.2.3",
|