@prismicio/next 2.0.1-alpha.1 → 2.0.2-canary.6f580fa
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/PrismicNextImage.cjs +66 -56
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +57 -0
- package/dist/PrismicNextLink.cjs +29 -21
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +54 -0
- package/dist/PrismicNextRichText.cjs +34 -0
- package/dist/PrismicNextRichText.cjs.map +1 -0
- package/dist/PrismicNextRichText.d.cts +11 -0
- package/dist/PrismicPreview.cjs +38 -36
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +36 -0
- package/dist/PrismicPreviewClient.cjs +71 -65
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/createLocaleRedirect.cjs +11 -5
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts +14 -0
- package/dist/enableAutoPreviews.cjs +27 -48
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +18 -0
- package/dist/exitPreview.cjs +24 -32
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/{exitPreview.d.ts → exitPreview.d.cts} +5 -1
- package/dist/imgixLoader.cjs +21 -14
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/{imgixLoader.d.ts → imgixLoader.d.cts} +7 -1
- package/dist/index.cjs +19 -19
- package/dist/index.d.cts +11 -0
- package/dist/lib/devMsg.cjs +22 -5
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +26 -0
- package/dist/lib/resolveDefaultExport.cjs.map +1 -0
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/pages/PrismicPreview.cjs +71 -59
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +36 -0
- package/dist/pages/enableAutoPreviews.cjs +21 -14
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +37 -0
- package/dist/pages/exitPreview.cjs +24 -7
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +38 -0
- package/dist/pages/redirectToPreviewURL.cjs +13 -13
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +48 -0
- package/dist/pages/setPreviewData.cjs +10 -8
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts +26 -0
- package/dist/pages/types.d.cts +36 -0
- package/dist/pages.cjs +21 -21
- package/dist/pages.d.cts +12 -0
- package/dist/redirectToPreviewURL.cjs +21 -43
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +33 -0
- package/dist/types.d.cts +31 -0
- package/package.json +34 -49
- package/src/PrismicNextImage.tsx +12 -8
- package/src/PrismicNextLink.tsx +7 -5
- package/src/PrismicNextRichText.tsx +41 -0
- package/src/PrismicPreview.tsx +2 -2
- package/src/PrismicPreviewClient.tsx +2 -3
- package/src/createLocaleRedirect.ts +1 -1
- package/src/imgixLoader.ts +3 -2
- package/src/index.ts +3 -0
- package/src/lib/devMsg.ts +1 -1
- package/src/lib/resolveDefaultExport.ts +21 -0
- package/src/pages/PrismicPreview.tsx +2 -1
- package/src/pages/index.ts +3 -0
- package/src/pages/types.ts +2 -3
- package/src/redirectToPreviewURL.ts +1 -1
- package/dist/PrismicNextImage.d.ts +0 -54
- package/dist/PrismicNextLink.d.ts +0 -125
- package/dist/PrismicPreview.d.ts +0 -31
- package/dist/PrismicPreviewClient.d.ts +0 -9
- package/dist/createLocaleRedirect.d.ts +0 -10
- package/dist/enableAutoPreviews.d.ts +0 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/lib/devMsg.d.ts +0 -16
- package/dist/lib/resolveCJS.cjs +0 -7
- package/dist/lib/resolveCJS.cjs.map +0 -1
- package/dist/lib/resolveCJS.d.ts +0 -9
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/pages/PrismicPreview.d.ts +0 -31
- package/dist/pages/enableAutoPreviews.d.ts +0 -31
- package/dist/pages/exitPreview.d.ts +0 -33
- package/dist/pages/index.d.ts +0 -18
- package/dist/pages/redirectToPreviewURL.d.ts +0 -43
- package/dist/pages/setPreviewData.d.ts +0 -18
- package/dist/pages/types.d.ts +0 -30
- package/dist/pages.cjs.map +0 -1
- package/dist/redirectToPreviewURL.d.ts +0 -28
- package/dist/types.d.ts +0 -26
- package/src/lib/resolveCJS.ts +0 -12
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/lib/resolveDefaultExport.ts
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a module's default export. The module may provide its default export
|
|
5
|
+
* as a `default` property on an object. This happens when named and default
|
|
6
|
+
* exports are mixed in modules.
|
|
7
|
+
*
|
|
8
|
+
* In ES Modules, mixing is fine since the module resolver can distinguish
|
|
9
|
+
* default and named exports. In transpiled modules, however, all exports are
|
|
10
|
+
* put into a single object, and the default export is provided at a property
|
|
11
|
+
* called `default`.
|
|
12
|
+
*
|
|
13
|
+
* This helper is needed by Next.js uses CJS files with named and default
|
|
14
|
+
* exports.
|
|
15
|
+
*
|
|
16
|
+
* This helper _should_ be a temporary hack until Next.js and Node.js resolve
|
|
17
|
+
* their ESM difficulties. This will likely not be removed any time soon,
|
|
18
|
+
* unfortunately.
|
|
19
|
+
*/
|
|
20
|
+
function resolveDefaultExport(mod) {
|
|
21
|
+
return "default" in mod ? mod.default : mod;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.resolveDefaultExport = resolveDefaultExport;
|
|
26
|
+
//# sourceMappingURL=resolveDefaultExport.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultExport.cjs","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.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,64 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let next_script = require("next/script");
|
|
3
|
+
next_script = require_rolldown_runtime.__toESM(next_script);
|
|
4
|
+
let _prismicio_client = require("@prismicio/client");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
let next_router = require("next/router");
|
|
8
|
+
|
|
9
|
+
//#region src/pages/PrismicPreview.tsx
|
|
10
|
+
/**
|
|
11
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
12
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
13
|
+
* and exiting, this component will automatically refresh the page with the
|
|
14
|
+
* changes.
|
|
15
|
+
*
|
|
16
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
17
|
+
* tree. It must be rendered on every page.
|
|
18
|
+
*/
|
|
8
19
|
const PrismicPreview = (props) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
20
|
+
const { repositoryName, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview", children } = props;
|
|
21
|
+
const router = (0, next_router.useRouter)();
|
|
22
|
+
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
|
|
23
|
+
(0, react.useEffect)(() => {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
|
|
26
|
+
window.addEventListener("prismicPreviewEnd", onEnd, { signal: controller.signal });
|
|
27
|
+
if (window.location.href.startsWith(window.location.origin + router.basePath) && getPreviewCookieRepositoryName() === repositoryName && !router.isPreview) start();
|
|
28
|
+
function onEnd(event) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
fetch(router.basePath + exitPreviewURL, { signal: controller.signal }).then((res) => {
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
console.error(`[<PrismicPreview>] Failed to exit Preview Mode using the "${exitPreviewURL}" API endpoint. Does it exist?`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
refresh();
|
|
36
|
+
}).catch(() => {});
|
|
37
|
+
}
|
|
38
|
+
function onUpdate(event) {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
start();
|
|
41
|
+
}
|
|
42
|
+
function start() {
|
|
43
|
+
fetch(router.basePath + updatePreviewURL, {
|
|
44
|
+
redirect: "manual",
|
|
45
|
+
signal: controller.signal
|
|
46
|
+
}).then((res) => {
|
|
47
|
+
if (res.type !== "opaqueredirect") {
|
|
48
|
+
console.error(`[<PrismicPreview>] Failed to start or update the preview using "${updatePreviewURL}". Does it exist?`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
refresh();
|
|
52
|
+
}).catch(() => {});
|
|
53
|
+
}
|
|
54
|
+
function refresh() {
|
|
55
|
+
router.replace(router.asPath, void 0, { scroll: false });
|
|
56
|
+
}
|
|
57
|
+
return () => controller.abort();
|
|
58
|
+
}, [
|
|
59
|
+
exitPreviewURL,
|
|
60
|
+
updatePreviewURL,
|
|
61
|
+
repositoryName,
|
|
62
|
+
router
|
|
63
|
+
]);
|
|
64
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(next_script.default, {
|
|
65
|
+
src: toolbarSrc,
|
|
66
|
+
strategy: "lazyOnload"
|
|
67
|
+
})] });
|
|
57
68
|
};
|
|
58
69
|
function getPreviewCookieRepositoryName() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1];
|
|
70
|
+
const cookie = window.document.cookie.split("; ").find((row) => row.startsWith(`${_prismicio_client.cookie.preview}=`))?.split("=")[1];
|
|
71
|
+
return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1];
|
|
62
72
|
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
63
75
|
exports.PrismicPreview = PrismicPreview;
|
|
64
|
-
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
76
|
+
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { type ReactNode, useEffect
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["Script","prismicCookie"],"sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { type ReactNode, useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport Script from \"next/script\";\nimport { getToolbarSrc, cookie as prismicCookie } from \"@prismicio/client\";\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,qCAAoB;CAE1B,MAAM,kDAA2B,eAAe;AAEhD,4BAAgB;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,qFACE,UACD,2CAACA;EAAO,KAAK;EAAY,UAAS;GAAe,IAC/C;;AAIL,SAAS,iCAAiC;CACzC,MAAM,SAAS,OAAO,SAAS,OAC7B,MAAM,KAAK,CACX,MAAM,QAAQ,IAAI,WAAW,GAAGC,yBAAc,QAAQ,GAAG,CAAC,EACzD,MAAM,IAAI,CAAC;AAEd,SAAQ,mBAAmB,UAAU,GAAG,CAAC,MAAM,yBAAyB,IACvE,EAAE,EAAE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FC, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/PrismicPreview.d.ts
|
|
4
|
+
/** Props for `<PrismicPreview>`. */
|
|
5
|
+
type PrismicPreviewProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
8
|
+
* using this repository.
|
|
9
|
+
*/
|
|
10
|
+
repositoryName: string;
|
|
11
|
+
/**
|
|
12
|
+
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
13
|
+
* This URL will be fetched on preview update events.
|
|
14
|
+
*/
|
|
15
|
+
updatePreviewURL?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
18
|
+
* This URL will be fetched on preview exit events.
|
|
19
|
+
*/
|
|
20
|
+
exitPreviewURL?: string;
|
|
21
|
+
/** Children to render adjacent to the Prismic Toolbar. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
26
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
27
|
+
* and exiting, this component will automatically refresh the page with the
|
|
28
|
+
* changes.
|
|
29
|
+
*
|
|
30
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
31
|
+
* tree. It must be rendered on every page.
|
|
32
|
+
*/
|
|
33
|
+
declare const PrismicPreview: FC<PrismicPreviewProps>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { PrismicPreview, PrismicPreviewProps };
|
|
36
|
+
//# sourceMappingURL=PrismicPreview.d.cts.map
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/pages/enableAutoPreviews.ts
|
|
3
|
+
/**
|
|
4
|
+
* Configures a Prismic client to automatically query draft content during a
|
|
5
|
+
* preview session. It either takes in a Next.js `getStaticProps` context object
|
|
6
|
+
* or a Next.js API endpoint request object.
|
|
7
|
+
*
|
|
8
|
+
* @param config - Configuration for the function.
|
|
9
|
+
*/
|
|
3
10
|
function enableAutoPreviews(config) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
11
|
+
if ("previewData" in config && config.previewData) {
|
|
12
|
+
if (isPrismicPreviewData(config.previewData)) config.client.queryContentFromRef(config.previewData.ref);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if ("req" in config && config.req) {
|
|
16
|
+
config.client.enableAutoPreviewsFromReq(config.req);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
function isPrismicPreviewData(input) {
|
|
16
|
-
|
|
21
|
+
return typeof input === "object" && input !== null && "ref" in input;
|
|
17
22
|
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
18
25
|
exports.enableAutoPreviews = enableAutoPreviews;
|
|
19
|
-
//# sourceMappingURL=enableAutoPreviews.cjs.map
|
|
26
|
+
//# sourceMappingURL=enableAutoPreviews.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.cjs","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"],"
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.cjs","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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NextApiRequestLike } from "./types.cjs";
|
|
2
|
+
import { Client } from "@prismicio/client";
|
|
3
|
+
import { PreviewData } from "next";
|
|
4
|
+
|
|
5
|
+
//#region src/pages/enableAutoPreviews.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for `enableAutoPreviews`.
|
|
9
|
+
*
|
|
10
|
+
* @typeParam TPreviewData - Next.js preview data object.
|
|
11
|
+
*/
|
|
12
|
+
type EnableAutoPreviewsConfig = {
|
|
13
|
+
/** Prismic client with which automatic previews will be enabled. */
|
|
14
|
+
client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq">;
|
|
15
|
+
/**
|
|
16
|
+
* The `previewData` object provided in the `getStaticProps()` or
|
|
17
|
+
* `getServerSideProps()` context object.
|
|
18
|
+
*/
|
|
19
|
+
previewData?: PreviewData;
|
|
20
|
+
/**
|
|
21
|
+
* The `req` object from a Next.js API route.
|
|
22
|
+
*
|
|
23
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
24
|
+
*/
|
|
25
|
+
req?: NextApiRequestLike;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Configures a Prismic client to automatically query draft content during a
|
|
29
|
+
* preview session. It either takes in a Next.js `getStaticProps` context object
|
|
30
|
+
* or a Next.js API endpoint request object.
|
|
31
|
+
*
|
|
32
|
+
* @param config - Configuration for the function.
|
|
33
|
+
*/
|
|
34
|
+
declare function enableAutoPreviews(config: EnableAutoPreviewsConfig): void;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { EnableAutoPreviewsConfig, enableAutoPreviews };
|
|
37
|
+
//# sourceMappingURL=enableAutoPreviews.d.cts.map
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/pages/exitPreview.ts
|
|
3
|
+
/**
|
|
4
|
+
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
5
|
+
* used in an API route.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // src/pages/api/exit-preview.js
|
|
11
|
+
*
|
|
12
|
+
* import { exitPreview } from "@prismicio/next";
|
|
13
|
+
*
|
|
14
|
+
* export default function handler(_req, res) {
|
|
15
|
+
* return exitPreview({ res });
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
function exitPreview(config) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return;
|
|
20
|
+
config.res.clearPreviewData();
|
|
21
|
+
config.res.setHeader("Cache-Control", "no-store");
|
|
22
|
+
config.res.json({ success: true });
|
|
8
23
|
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
9
26
|
exports.exitPreview = exitPreview;
|
|
10
|
-
//# sourceMappingURL=exitPreview.cjs.map
|
|
27
|
+
//# sourceMappingURL=exitPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.cjs","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"],"
|
|
1
|
+
{"version":3,"file":"exitPreview.cjs","names":[],"sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/exitPreview.d.ts
|
|
4
|
+
/** Configuration for `exitPreview()`. */
|
|
5
|
+
type ExitPreviewAPIRouteConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* The `req` object from a Next.js API route.
|
|
8
|
+
*
|
|
9
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
10
|
+
*/
|
|
11
|
+
req?: NextApiRequestLike;
|
|
12
|
+
/**
|
|
13
|
+
* The `res` object from a Next.js API route.
|
|
14
|
+
*
|
|
15
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
16
|
+
*/
|
|
17
|
+
res: NextApiResponseLike;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
21
|
+
* used in an API route.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // src/pages/api/exit-preview.js
|
|
27
|
+
*
|
|
28
|
+
* import { exitPreview } from "@prismicio/next";
|
|
29
|
+
*
|
|
30
|
+
* export default function handler(_req, res) {
|
|
31
|
+
* return exitPreview({ res });
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function exitPreview(config: ExitPreviewAPIRouteConfig): void;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { ExitPreviewAPIRouteConfig, exitPreview };
|
|
38
|
+
//# sourceMappingURL=exitPreview.d.cts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/pages/redirectToPreviewURL.ts
|
|
3
3
|
async function redirectToPreviewURL(config) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
res.redirect(basePath + previewURL);
|
|
13
|
-
return;
|
|
4
|
+
const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
|
|
5
|
+
const previewToken = req.query.token?.toString();
|
|
6
|
+
const previewURL = await client.resolvePreviewURL({
|
|
7
|
+
linkResolver,
|
|
8
|
+
defaultURL,
|
|
9
|
+
previewToken
|
|
10
|
+
});
|
|
11
|
+
res.redirect(basePath + previewURL);
|
|
14
12
|
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
15
|
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
16
|
-
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
16
|
+
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","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"],"
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.cjs";
|
|
2
|
+
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/pages/redirectToPreviewURL.d.ts
|
|
5
|
+
type RedirectToPreviewURLConfig = {
|
|
6
|
+
/** The Prismic client configured for the preview session's repository. */
|
|
7
|
+
client: Pick<Client, "resolvePreviewURL">;
|
|
8
|
+
/**
|
|
9
|
+
* The `req` object from a Next.js API route.
|
|
10
|
+
*
|
|
11
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
|
|
12
|
+
*/
|
|
13
|
+
req: NextApiRequestLike;
|
|
14
|
+
/**
|
|
15
|
+
* The `res` object from a Next.js API route.
|
|
16
|
+
*
|
|
17
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
|
|
18
|
+
*/
|
|
19
|
+
res: NextApiResponseLike;
|
|
20
|
+
/**
|
|
21
|
+
* A Link Resolver used to resolve the previewed document's URL.
|
|
22
|
+
*
|
|
23
|
+
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
24
|
+
*/
|
|
25
|
+
linkResolver?: LinkResolverFunction;
|
|
26
|
+
/**
|
|
27
|
+
* The default redirect URL if a URL cannot be determined for the previewed
|
|
28
|
+
* document.
|
|
29
|
+
*
|
|
30
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
31
|
+
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
32
|
+
* property using the `basePath` option.
|
|
33
|
+
*/
|
|
34
|
+
defaultURL?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
37
|
+
* This option can be omitted if the app does not have a `basePath`.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The Router Handler or API route is unable to detect the app's `basePath`
|
|
41
|
+
* automatically. It must be provided to `redirectToPreviewURL()` manually.
|
|
42
|
+
*/
|
|
43
|
+
basePath?: string;
|
|
44
|
+
};
|
|
45
|
+
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
48
|
+
//# sourceMappingURL=redirectToPreviewURL.d.cts.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
3
|
+
|
|
4
|
+
//#region src/pages/setPreviewData.ts
|
|
5
|
+
/** Set Prismic preview data for Next.js's Preview Mode. */
|
|
4
6
|
function setPreviewData({ req, res }) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
res.setPreviewData({ ref });
|
|
8
|
-
}
|
|
7
|
+
const ref = req.query.token || req.cookies[_prismicio_client.cookie.preview];
|
|
8
|
+
if (ref) res.setPreviewData({ ref });
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
10
12
|
exports.setPreviewData = setPreviewData;
|
|
11
|
-
//# sourceMappingURL=setPreviewData.cjs.map
|
|
13
|
+
//# sourceMappingURL=setPreviewData.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.cjs","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"],"
|
|
1
|
+
{"version":3,"file":"setPreviewData.cjs","names":["cookie"],"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,QAAQA,yBAAO;AAElD,KAAI,IACH,KAAI,eAAe,EAAE,KAAK,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/pages/setPreviewData.d.ts
|
|
4
|
+
/** Configuration for `setPreviewData`. */
|
|
5
|
+
type SetPreviewDataConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* The `req` object from a Next.js API route.
|
|
8
|
+
*
|
|
9
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
10
|
+
*/
|
|
11
|
+
req: NextApiRequestLike;
|
|
12
|
+
/**
|
|
13
|
+
* The `res` object from a Next.js API route.
|
|
14
|
+
*
|
|
15
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
16
|
+
*/
|
|
17
|
+
res: NextApiResponseLike;
|
|
18
|
+
};
|
|
19
|
+
/** Set Prismic preview data for Next.js's Preview Mode. */
|
|
20
|
+
declare function setPreviewData({
|
|
21
|
+
req,
|
|
22
|
+
res
|
|
23
|
+
}: SetPreviewDataConfig): void;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SetPreviewDataConfig, setPreviewData };
|
|
26
|
+
//# sourceMappingURL=setPreviewData.d.cts.map
|