@prismicio/next 1.0.3 → 1.1.0-alpha.1
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 +8 -19
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.ts +2 -2
- package/dist/PrismicNextImage.js +8 -2
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.cjs +39 -0
- package/dist/PrismicNextLink.cjs.map +1 -0
- package/dist/PrismicNextLink.d.ts +126 -0
- package/dist/PrismicNextLink.js +22 -0
- package/dist/PrismicNextLink.js.map +1 -0
- package/dist/PrismicPreview.cjs +2 -0
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.js +2 -0
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +38 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +38 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +28 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +28 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +14 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +14 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +1 -0
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.ts +3 -3
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.cjs.map +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.js.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.cjs +4 -21
- package/dist/lib/getPrismicPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.js +2 -2
- package/dist/lib/getPrismicPreviewCookie.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/react-server/PrismicPreview.d.ts +22 -0
- package/dist/react-server/index.d.ts +2 -0
- package/dist/react-server/unsupported.cjs +26 -0
- package/dist/react-server/unsupported.cjs.map +1 -0
- package/dist/react-server/unsupported.d.ts +6 -0
- package/dist/react-server/unsupported.js +26 -0
- package/dist/react-server/unsupported.js.map +1 -0
- package/dist/react-server.cjs +15 -0
- package/dist/react-server.cjs.map +1 -0
- package/dist/react-server.js +15 -0
- package/dist/react-server.js.map +1 -0
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +4 -5
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/setPreviewData.cjs +2 -19
- package/dist/setPreviewData.cjs.map +1 -1
- package/dist/setPreviewData.js +2 -2
- package/dist/setPreviewData.js.map +1 -1
- package/package.json +37 -32
- package/src/PrismicNextImage.tsx +5 -4
- package/src/PrismicNextLink.tsx +55 -0
- package/src/PrismicPreview.tsx +2 -0
- package/src/enableAutoPreviews.ts +9 -3
- package/src/index.ts +16 -13
- package/src/react-server/PrismicPreview.tsx +74 -0
- package/src/react-server/index.ts +11 -0
- package/src/react-server/unsupported.ts +26 -0
- package/src/redirectToPreviewURL.ts +7 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const unsupported = require("./react-server/unsupported.cjs");
|
|
4
|
+
const PrismicNextLink = require("./PrismicNextLink.cjs");
|
|
5
|
+
const PrismicNextImage = require("./PrismicNextImage.cjs");
|
|
6
|
+
const imgixLoader = require("./imgixLoader.cjs");
|
|
7
|
+
exports.PrismicPreview = unsupported.PrismicPreview;
|
|
8
|
+
exports.enableAutoPreviews = unsupported.enableAutoPreviews;
|
|
9
|
+
exports.exitPreview = unsupported.exitPreview;
|
|
10
|
+
exports.redirectToPreviewURL = unsupported.redirectToPreviewURL;
|
|
11
|
+
exports.setPreviewData = unsupported.setPreviewData;
|
|
12
|
+
exports.PrismicNextLink = PrismicNextLink.PrismicNextLink;
|
|
13
|
+
exports.PrismicNextImage = PrismicNextImage.PrismicNextImage;
|
|
14
|
+
exports.imgixLoader = imgixLoader.imgixLoader;
|
|
15
|
+
//# sourceMappingURL=react-server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-server.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PrismicPreview, enableAutoPreviews, exitPreview, redirectToPreviewURL, setPreviewData } from "./react-server/unsupported.js";
|
|
2
|
+
import { PrismicNextLink } from "./PrismicNextLink.js";
|
|
3
|
+
import { PrismicNextImage } from "./PrismicNextImage.js";
|
|
4
|
+
import { imgixLoader } from "./imgixLoader.js";
|
|
5
|
+
export {
|
|
6
|
+
PrismicNextImage,
|
|
7
|
+
PrismicNextLink,
|
|
8
|
+
PrismicPreview,
|
|
9
|
+
enableAutoPreviews,
|
|
10
|
+
exitPreview,
|
|
11
|
+
imgixLoader,
|
|
12
|
+
redirectToPreviewURL,
|
|
13
|
+
setPreviewData
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=react-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { NextApiRequest, NextApiResponse } from \"next\";\nimport type * as prismic from \"@prismicio/client\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,\n> = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\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<prismic.Client, \"resolvePreviewURL\">;\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?: TLinkResolverFunction;\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 API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends prismic.LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":";;AAgBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAqEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;;"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { Client } from "@prismicio/client";
|
|
2
1
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
3
|
-
import type
|
|
2
|
+
import type * as prismic from "@prismicio/client";
|
|
4
3
|
/**
|
|
5
4
|
* Preview config for enabling previews with redirectToPreviewURL
|
|
6
5
|
*/
|
|
7
|
-
export type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
|
|
6
|
+
export type RedirectToPreviewURLConfig<TLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction> = {
|
|
8
7
|
/**
|
|
9
8
|
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
10
9
|
* the API route.
|
|
@@ -26,7 +25,7 @@ export type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolve
|
|
|
26
25
|
/**
|
|
27
26
|
* The Prismic client configured for the preview session's repository.
|
|
28
27
|
*/
|
|
29
|
-
client: Client
|
|
28
|
+
client: Pick<prismic.Client, "resolvePreviewURL">;
|
|
30
29
|
/**
|
|
31
30
|
* A Link Resolver used to resolve the previewed document's URL.
|
|
32
31
|
*
|
|
@@ -56,4 +55,4 @@ export type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolve
|
|
|
56
55
|
* Redirects a user to the URL of a previewed Prismic document from within a
|
|
57
56
|
* Next.js API route.
|
|
58
57
|
*/
|
|
59
|
-
export declare function redirectToPreviewURL<TLinkResolverFunction extends LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
|
|
58
|
+
export declare function redirectToPreviewURL<TLinkResolverFunction extends prismic.LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","sources":["../../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { NextApiRequest, NextApiResponse } from \"next\";\nimport type * as prismic from \"@prismicio/client\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,\n> = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\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<prismic.Client, \"resolvePreviewURL\">;\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?: TLinkResolverFunction;\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 API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends prismic.LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":"AAgBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAqEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;"}
|
package/dist/setPreviewData.cjs
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
function _interopNamespaceDefault(e) {
|
|
5
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
|
-
if (e) {
|
|
7
|
-
for (const k in e) {
|
|
8
|
-
if (k !== "default") {
|
|
9
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
10
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: () => e[k]
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
n.default = e;
|
|
18
|
-
return Object.freeze(n);
|
|
19
|
-
}
|
|
20
|
-
const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
|
|
3
|
+
const cookie = require('./_node_modules/@prismicio/client/dist/cookie.cjs');
|
|
21
4
|
function setPreviewData({ req, res }) {
|
|
22
|
-
const ref = req.query.token || req.cookies[
|
|
5
|
+
const ref = req.query.token || req.cookies[cookie.preview];
|
|
23
6
|
if (ref) {
|
|
24
7
|
res.setPreviewData({ ref });
|
|
25
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.cjs","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic"],"mappings":"
|
|
1
|
+
{"version":3,"file":"setPreviewData.cjs","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";;;SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAC1D,QAAA,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,OAAAA,OAAsB;AAEjE,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;;"}
|
package/dist/setPreviewData.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { preview } from './_node_modules/@prismicio/client/dist/cookie.js';
|
|
2
2
|
function setPreviewData({ req, res }) {
|
|
3
|
-
const ref = req.query.token || req.cookies[
|
|
3
|
+
const ref = req.query.token || req.cookies[preview];
|
|
4
4
|
if (ref) {
|
|
5
5
|
res.setPreviewData({ ref });
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.js","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":[],"mappings":";SAgCgB,eAAe,EAAE,KAAK,OAA2B;
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","sources":["../../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic.cookie.preview"],"mappings":";SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAC1D,QAAA,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,OAAsB;AAEjE,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.1",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -18,13 +18,18 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"
|
|
22
|
-
|
|
21
|
+
"react-server": {
|
|
22
|
+
"import": "./dist/react-server.js",
|
|
23
|
+
"require": "./dist/react-server.cjs"
|
|
24
|
+
},
|
|
25
|
+
"default": {
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
}
|
|
23
29
|
},
|
|
24
30
|
"./package.json": "./package.json"
|
|
25
31
|
},
|
|
26
|
-
"main": "./dist/index.
|
|
27
|
-
"module": "./dist/index.js",
|
|
32
|
+
"main": "./dist/index.js",
|
|
28
33
|
"types": "./dist/index.d.ts",
|
|
29
34
|
"files": [
|
|
30
35
|
"dist",
|
|
@@ -34,53 +39,53 @@
|
|
|
34
39
|
"build": "vite build",
|
|
35
40
|
"dev": "vite build --watch",
|
|
36
41
|
"format": "prettier --write .",
|
|
37
|
-
"lint": "eslint --ext .js,.ts .",
|
|
42
|
+
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
|
|
43
|
+
"types": "tsc --noEmit",
|
|
38
44
|
"prepare": "npm run build",
|
|
39
|
-
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
40
|
-
"release:alpha": "npm run test && standard-version --release-as
|
|
41
|
-
"release:alpha:dry": "standard-version --release-as
|
|
45
|
+
"release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
46
|
+
"release:alpha": "npm run build && npm run test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
47
|
+
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
|
|
42
48
|
"release:dry": "standard-version --dry-run",
|
|
43
|
-
"size": "size-limit",
|
|
44
|
-
"test": "npm run lint && npm run unit && npm run build && npm run size",
|
|
45
49
|
"unit": "vitest run --coverage",
|
|
46
|
-
"unit:watch": "vitest watch"
|
|
50
|
+
"unit:watch": "vitest watch",
|
|
51
|
+
"size": "size-limit",
|
|
52
|
+
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
47
53
|
},
|
|
48
54
|
"dependencies": {
|
|
49
|
-
"@prismicio/helpers": "^2.3.6",
|
|
50
|
-
"@prismicio/types": "^0.2.4",
|
|
51
55
|
"imgix-url-builder": "^0.0.3"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
54
|
-
"@prismicio/client": "^
|
|
55
|
-
"@prismicio/mock": "^0.
|
|
56
|
-
"@size-limit/preset-small-lib": "^8.
|
|
58
|
+
"@prismicio/client": "^7.0.0-alpha.3",
|
|
59
|
+
"@prismicio/mock": "^0.2.0",
|
|
60
|
+
"@size-limit/preset-small-lib": "^8.2.4",
|
|
57
61
|
"@types/react-test-renderer": "^18.0.0",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
60
|
-
"@vitejs/plugin-react": "^
|
|
61
|
-
"@vitest/coverage-c8": "^0.
|
|
62
|
-
"eslint": "^8.
|
|
63
|
-
"eslint-config-prettier": "^8.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.59.1",
|
|
63
|
+
"@typescript-eslint/parser": "^5.59.1",
|
|
64
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
65
|
+
"@vitest/coverage-c8": "^0.30.1",
|
|
66
|
+
"eslint": "^8.39.0",
|
|
67
|
+
"eslint-config-prettier": "^8.8.0",
|
|
64
68
|
"eslint-plugin-prettier": "^4.2.1",
|
|
65
|
-
"eslint-plugin-react": "^7.
|
|
69
|
+
"eslint-plugin-react": "^7.32.2",
|
|
66
70
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
67
71
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
68
|
-
"happy-dom": "^
|
|
72
|
+
"happy-dom": "^9.9.2",
|
|
69
73
|
"next": "^13.0.0",
|
|
70
|
-
"prettier": "^2.8.
|
|
74
|
+
"prettier": "^2.8.8",
|
|
71
75
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
72
76
|
"react": "^18.1.0",
|
|
73
77
|
"react-dom": "^18.2.0",
|
|
74
78
|
"react-test-renderer": "^18.2.0",
|
|
75
|
-
"
|
|
79
|
+
"rollup-plugin-preserve-directives": "^0.1.0",
|
|
80
|
+
"size-limit": "^8.2.4",
|
|
76
81
|
"standard-version": "^9.5.0",
|
|
77
|
-
"typescript": "^
|
|
78
|
-
"vite": "^4.
|
|
79
|
-
"vite-plugin-sdk": "^0.1.
|
|
80
|
-
"vitest": "^0.
|
|
82
|
+
"typescript": "^5.0.4",
|
|
83
|
+
"vite": "^4.3.1",
|
|
84
|
+
"vite-plugin-sdk": "^0.1.1",
|
|
85
|
+
"vitest": "^0.30.1"
|
|
81
86
|
},
|
|
82
87
|
"peerDependencies": {
|
|
83
|
-
"@prismicio/client": "^6",
|
|
88
|
+
"@prismicio/client": "^6 || ^7",
|
|
84
89
|
"next": "^13",
|
|
85
90
|
"react": "^18"
|
|
86
91
|
},
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
import Image, { ImageProps } from "next/image";
|
|
2
4
|
import { buildURL, ImgixURLParams } from "imgix-url-builder";
|
|
3
|
-
import * as
|
|
4
|
-
import * as prismicT from "@prismicio/types";
|
|
5
|
+
import * as prismic from "@prismicio/client";
|
|
5
6
|
|
|
6
7
|
import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
|
|
7
8
|
import { devMsg } from "./lib/devMsg";
|
|
@@ -26,7 +27,7 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
|
|
|
26
27
|
/**
|
|
27
28
|
* The Prismic Image field or thumbnail to render.
|
|
28
29
|
*/
|
|
29
|
-
field:
|
|
30
|
+
field: prismic.ImageFieldImage | null | undefined;
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* An object of Imgix URL API parameters to transform the image.
|
|
@@ -103,7 +104,7 @@ export const PrismicNextImage = ({
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
if (
|
|
107
|
+
if (prismic.isFilled.imageThumbnail(field)) {
|
|
107
108
|
const src = buildURL(field.url, imgixParams);
|
|
108
109
|
|
|
109
110
|
const ar = field.dimensions.width / field.dimensions.height;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as prismic from "@prismicio/client";
|
|
5
|
+
import Link from "next/link";
|
|
6
|
+
|
|
7
|
+
export type PrismicNextLinkProps = Omit<
|
|
8
|
+
React.ComponentProps<typeof Link>,
|
|
9
|
+
"field" | "document" | "href" | "rel"
|
|
10
|
+
> & {
|
|
11
|
+
linkResolver?: prismic.LinkResolverFunction;
|
|
12
|
+
rel?: string | prismic.AsLinkAttrsConfig["rel"];
|
|
13
|
+
} & (
|
|
14
|
+
| {
|
|
15
|
+
field: prismic.LinkField | null | undefined;
|
|
16
|
+
document?: never;
|
|
17
|
+
href?: never;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
field?: never;
|
|
21
|
+
document: prismic.PrismicDocument | null | undefined;
|
|
22
|
+
href?: never;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
field?: never;
|
|
26
|
+
document?: never;
|
|
27
|
+
href: React.ComponentProps<typeof Link>["href"];
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const PrismicNextLink = React.forwardRef<
|
|
32
|
+
HTMLAnchorElement,
|
|
33
|
+
PrismicNextLinkProps
|
|
34
|
+
>(function PrismicNextLink(
|
|
35
|
+
{ field, document, linkResolver, ...restProps },
|
|
36
|
+
ref,
|
|
37
|
+
): JSX.Element | null {
|
|
38
|
+
const {
|
|
39
|
+
href: computedHref,
|
|
40
|
+
rel: computedRel,
|
|
41
|
+
...attrs
|
|
42
|
+
} = prismic.asLinkAttrs(field ?? document, {
|
|
43
|
+
linkResolver,
|
|
44
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
48
|
+
|
|
49
|
+
let rel = computedRel;
|
|
50
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
51
|
+
rel = restProps.rel;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return <Link ref={ref} {...attrs} {...restProps} href={href} rel={rel} />;
|
|
55
|
+
});
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PreviewData } from "next";
|
|
2
|
-
import
|
|
2
|
+
import type * as prismic from "@prismicio/client";
|
|
3
3
|
|
|
4
4
|
interface PrismicNextPreviewData {
|
|
5
5
|
ref: string;
|
|
@@ -30,7 +30,13 @@ export type EnableAutoPreviewsConfig<
|
|
|
30
30
|
/**
|
|
31
31
|
* Prismic client with which automatic previews will be enabled.
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
// `Pick` is used to use the smallest possible subset of
|
|
34
|
+
// `prismic.Client`. Doing this reduces the surface area for breaking
|
|
35
|
+
// type changes.
|
|
36
|
+
client: Pick<
|
|
37
|
+
prismic.Client,
|
|
38
|
+
"queryContentFromRef" | "enableAutoPreviewsFromReq"
|
|
39
|
+
>;
|
|
34
40
|
} & (
|
|
35
41
|
| {
|
|
36
42
|
/**
|
|
@@ -49,7 +55,7 @@ export type EnableAutoPreviewsConfig<
|
|
|
49
55
|
* Pass a `req` object when using `enableAutoPreviews` in a Next.js API
|
|
50
56
|
* endpoint.
|
|
51
57
|
*/
|
|
52
|
-
req?: HttpRequestLike;
|
|
58
|
+
req?: prismic.HttpRequestLike;
|
|
53
59
|
}
|
|
54
60
|
);
|
|
55
61
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
export { setPreviewData
|
|
1
|
+
export { setPreviewData } from "./setPreviewData";
|
|
2
|
+
export type { SetPreviewDataConfig } from "./setPreviewData";
|
|
2
3
|
|
|
3
|
-
export { exitPreview
|
|
4
|
+
export { exitPreview } from "./exitPreview";
|
|
5
|
+
export type { ExitPreviewConfig } from "./exitPreview";
|
|
4
6
|
|
|
5
|
-
export { PrismicPreview
|
|
7
|
+
export { PrismicPreview } from "./PrismicPreview";
|
|
8
|
+
export type { PrismicPreviewProps } from "./PrismicPreview";
|
|
6
9
|
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
enableAutoPreviews,
|
|
10
|
-
} from "./enableAutoPreviews";
|
|
10
|
+
export { PrismicNextLink } from "./PrismicNextLink";
|
|
11
|
+
export type { PrismicNextLinkProps } from "./PrismicNextLink";
|
|
11
12
|
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
redirectToPreviewURL,
|
|
15
|
-
} from "./redirectToPreviewURL";
|
|
13
|
+
export { enableAutoPreviews } from "./enableAutoPreviews";
|
|
14
|
+
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
16
15
|
|
|
17
|
-
export {
|
|
16
|
+
export { redirectToPreviewURL } from "./redirectToPreviewURL";
|
|
17
|
+
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
18
|
+
|
|
19
|
+
export { PrismicNextImage } from "./PrismicNextImage";
|
|
20
|
+
export type { PrismicNextImageProps } from "./PrismicNextImage";
|
|
18
21
|
|
|
19
22
|
export { imgixLoader } from "./imgixLoader";
|
|
20
23
|
|
|
21
|
-
export { CreateClientConfig } from "./types";
|
|
24
|
+
export type { CreateClientConfig } from "./types";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Script from "next/script";
|
|
5
|
+
import * as prismic from "@prismicio/client";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for `<PrismicPreview>`.
|
|
9
|
+
*/
|
|
10
|
+
export type PrismicPreviewProps = {
|
|
11
|
+
/**
|
|
12
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
13
|
+
* using this repository.
|
|
14
|
+
*/
|
|
15
|
+
repositoryName: string;
|
|
16
|
+
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
22
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
23
|
+
* and exiting, this component will automatically update Next.js Preview Mode
|
|
24
|
+
* and refresh the page.
|
|
25
|
+
*
|
|
26
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
27
|
+
* tree. It must be rendered on every page.
|
|
28
|
+
*/
|
|
29
|
+
export function PrismicPreview({
|
|
30
|
+
repositoryName,
|
|
31
|
+
children,
|
|
32
|
+
}: PrismicPreviewProps): JSX.Element {
|
|
33
|
+
const prismicToolbarSrc = prismic.getToolbarSrc(repositoryName);
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const handlePrismicPreviewUpdate = async (event: Event) => {
|
|
37
|
+
// Prevent the toolbar from reloading the page.
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
|
|
40
|
+
// TODO: Handle preview updates.
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.log("[PrismicPreview]: Update event called.");
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handlePrismicPreviewEnd = async (event: Event) => {
|
|
47
|
+
// Prevent the toolbar from reloading the page.
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
|
|
50
|
+
// TODO: Handle preview exit.
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.log("[PrismicPreview]: End event called.");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
window.addEventListener("prismicPreviewUpdate", handlePrismicPreviewUpdate);
|
|
57
|
+
window.addEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
window.removeEventListener(
|
|
61
|
+
"prismicPreviewUpdate",
|
|
62
|
+
handlePrismicPreviewUpdate,
|
|
63
|
+
);
|
|
64
|
+
window.removeEventListener("prismicPreviewEnd", handlePrismicPreviewEnd);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
{children}
|
|
71
|
+
<Script src={prismicToolbarSrc} strategy="lazyOnload" />
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {
|
|
2
|
+
PrismicPreview,
|
|
3
|
+
enableAutoPreviews,
|
|
4
|
+
redirectToPreviewURL,
|
|
5
|
+
exitPreview,
|
|
6
|
+
setPreviewData,
|
|
7
|
+
} from "./unsupported";
|
|
8
|
+
|
|
9
|
+
// These exports do not have RSC-specific implementations.
|
|
10
|
+
// They are aliases for the root-level exports.
|
|
11
|
+
export { PrismicNextImage, imgixLoader, PrismicNextLink } from "..";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Exports in this file are unsupported in the react-server environment.
|
|
2
|
+
// All environments should export the same functions to maintian API compatability.
|
|
3
|
+
|
|
4
|
+
function buildIncompatiblePreviewModeError(fnName: string) {
|
|
5
|
+
return `${fnName} is currently incompatible with App Router. Preview Mode is not supported in App Router at this time. Please remove all uses of ${fnName}.`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function PrismicPreview(): JSX.Element {
|
|
9
|
+
throw new Error(buildIncompatiblePreviewModeError("<PrismicPreview>"));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function enableAutoPreviews() {
|
|
13
|
+
throw new Error(buildIncompatiblePreviewModeError("enableAutoPreviews()"));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function exitPreview() {
|
|
17
|
+
throw new Error(buildIncompatiblePreviewModeError("exitPreview()"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function redirectToPreviewURL() {
|
|
21
|
+
throw new Error(buildIncompatiblePreviewModeError("redirectToPreviewURL()"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setPreviewData() {
|
|
25
|
+
throw new Error(buildIncompatiblePreviewModeError("setPreviewData()"));
|
|
26
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Client } from "@prismicio/client";
|
|
2
1
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
3
|
-
import type
|
|
2
|
+
import type * as prismic from "@prismicio/client";
|
|
4
3
|
|
|
5
4
|
type PrismicNextQuery = {
|
|
6
5
|
documentId: string;
|
|
@@ -28,7 +27,7 @@ const isPrismicNextQuery = (
|
|
|
28
27
|
*/
|
|
29
28
|
export type RedirectToPreviewURLConfig<
|
|
30
29
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction,
|
|
30
|
+
TLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,
|
|
32
31
|
> = {
|
|
33
32
|
/**
|
|
34
33
|
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
@@ -53,7 +52,10 @@ export type RedirectToPreviewURLConfig<
|
|
|
53
52
|
/**
|
|
54
53
|
* The Prismic client configured for the preview session's repository.
|
|
55
54
|
*/
|
|
56
|
-
|
|
55
|
+
// `Pick` is used to use the smallest possible subset of
|
|
56
|
+
// `prismic.Client`. Doing this reduces the surface area for breaking
|
|
57
|
+
// type changes.
|
|
58
|
+
client: Pick<prismic.Client, "resolvePreviewURL">;
|
|
57
59
|
|
|
58
60
|
/**
|
|
59
61
|
* A Link Resolver used to resolve the previewed document's URL.
|
|
@@ -89,7 +91,7 @@ export type RedirectToPreviewURLConfig<
|
|
|
89
91
|
*/
|
|
90
92
|
export async function redirectToPreviewURL<
|
|
91
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
TLinkResolverFunction extends LinkResolverFunction<any>,
|
|
94
|
+
TLinkResolverFunction extends prismic.LinkResolverFunction<any>,
|
|
93
95
|
>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {
|
|
94
96
|
const defaultURL = config.defaultURL || "/";
|
|
95
97
|
const basePath = config.basePath || "";
|