@prismicio/next 2.0.1-alpha.0 → 2.0.1-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.mjs → PrismicNextImage.cjs} +22 -21
- package/dist/PrismicNextImage.cjs.map +1 -0
- package/dist/PrismicNextLink.cjs +23 -0
- package/dist/PrismicNextLink.cjs.map +1 -0
- package/dist/PrismicPreview.cjs +39 -0
- package/dist/PrismicPreview.cjs.map +1 -0
- package/dist/{PrismicPreviewClient.mjs → PrismicPreviewClient.cjs} +14 -14
- package/dist/{PrismicPreviewClient.mjs.map → PrismicPreviewClient.cjs.map} +1 -1
- package/dist/createLocaleRedirect.cjs +8 -0
- package/dist/{createLocaleRedirect.mjs.map → createLocaleRedirect.cjs.map} +1 -1
- package/dist/enableAutoPreviews.cjs +51 -0
- package/dist/{enableAutoPreviews.mjs.map → enableAutoPreviews.cjs.map} +1 -1
- package/dist/exitPreview.cjs +35 -0
- package/dist/{exitPreview.mjs.map → exitPreview.cjs.map} +1 -1
- package/dist/imgixLoader.cjs +17 -0
- package/dist/{imgixLoader.mjs.map → imgixLoader.cjs.map} +1 -1
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/{devMsg.mjs.map → devMsg.cjs.map} +1 -1
- package/dist/lib/resolveCJS.cjs +7 -0
- package/dist/lib/resolveCJS.cjs.map +1 -0
- package/dist/lib/resolveCJS.d.ts +9 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/pages/{PrismicPreview.mjs → PrismicPreview.cjs} +20 -20
- package/dist/pages/{PrismicPreview.mjs.map → PrismicPreview.cjs.map} +1 -1
- package/dist/pages/{enableAutoPreviews.mjs → enableAutoPreviews.cjs} +4 -4
- package/dist/pages/{enableAutoPreviews.mjs.map → enableAutoPreviews.cjs.map} +1 -1
- package/dist/pages/{exitPreview.mjs → exitPreview.cjs} +4 -4
- package/dist/pages/{exitPreview.mjs.map → exitPreview.cjs.map} +1 -1
- package/dist/pages/{redirectToPreviewURL.mjs → redirectToPreviewURL.cjs} +4 -4
- package/dist/pages/{redirectToPreviewURL.mjs.map → redirectToPreviewURL.cjs.map} +1 -1
- package/dist/pages/setPreviewData.cjs +11 -0
- package/dist/pages/{setPreviewData.mjs.map → setPreviewData.cjs.map} +1 -1
- package/dist/pages.cjs +21 -0
- package/dist/pages.cjs.map +1 -0
- package/dist/redirectToPreviewURL.cjs +46 -0
- package/dist/{redirectToPreviewURL.mjs.map → redirectToPreviewURL.cjs.map} +1 -1
- package/package.json +3 -4
- package/src/PrismicNextImage.tsx +9 -4
- package/src/PrismicNextLink.tsx +6 -2
- package/src/PrismicPreview.tsx +4 -1
- package/src/lib/resolveCJS.ts +12 -0
- package/dist/PrismicNextImage.mjs.map +0 -1
- package/dist/PrismicNextLink.mjs +0 -21
- package/dist/PrismicNextLink.mjs.map +0 -1
- package/dist/PrismicPreview.mjs +0 -15
- package/dist/PrismicPreview.mjs.map +0 -1
- package/dist/createLocaleRedirect.mjs +0 -8
- package/dist/enableAutoPreviews.mjs +0 -29
- package/dist/exitPreview.mjs +0 -13
- package/dist/imgixLoader.mjs +0 -17
- package/dist/index.mjs +0 -19
- package/dist/index.mjs.map +0 -1
- package/dist/lib/devMsg.mjs +0 -8
- package/dist/package.json.mjs +0 -5
- package/dist/package.json.mjs.map +0 -1
- package/dist/pages/setPreviewData.mjs +0 -11
- package/dist/pages.mjs +0 -21
- package/dist/pages.mjs.map +0 -1
- package/dist/redirectToPreviewURL.mjs +0 -24
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
3
|
function enableAutoPreviews(config) {
|
|
2
4
|
if ("previewData" in config && config.previewData) {
|
|
3
5
|
if (isPrismicPreviewData(config.previewData)) {
|
|
@@ -13,7 +15,5 @@ function enableAutoPreviews(config) {
|
|
|
13
15
|
function isPrismicPreviewData(input) {
|
|
14
16
|
return typeof input === "object" && input !== null && "ref" in input;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=enableAutoPreviews.mjs.map
|
|
18
|
+
exports.enableAutoPreviews = enableAutoPreviews;
|
|
19
|
+
//# sourceMappingURL=enableAutoPreviews.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enableAutoPreviews.
|
|
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"],"names":[],"mappings":";;AAsCM,SAAU,mBAAmB,QAAgC;AAC9D,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAI9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IAAA;AAGzD;AAAA,EAAA;AAGG,MAAA,SAAS,UAAU,OAAO,KAAK;AAG3B,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAElD;AAAA,EAAA;AAEF;AAEA,SAAS,qBAAqB,OAAc;AAC3C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;;"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
3
|
function exitPreview(config) {
|
|
2
4
|
config.res.clearPreviewData();
|
|
3
5
|
config.res.setHeader("Cache-Control", "no-store");
|
|
4
6
|
config.res.json({ success: true });
|
|
5
7
|
return;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=exitPreview.mjs.map
|
|
9
|
+
exports.exitPreview = exitPreview;
|
|
10
|
+
//# sourceMappingURL=exitPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exitPreview.
|
|
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"],"names":[],"mappings":";;AAmCM,SAAU,YAAY,QAAiC;AAC5D,SAAO,IAAI;AAGJ,SAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,SAAO,IAAI,KAAK,EAAE,SAAS,MAAM;AAEjC;AACD;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
1
3
|
async function redirectToPreviewURL(config) {
|
|
2
4
|
var _a;
|
|
3
5
|
const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config;
|
|
@@ -10,7 +12,5 @@ async function redirectToPreviewURL(config) {
|
|
|
10
12
|
res.redirect(basePath + previewURL);
|
|
11
13
|
return;
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=redirectToPreviewURL.mjs.map
|
|
15
|
+
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
16
|
+
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.
|
|
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"],"names":[],"mappings":";;AAqDA,eAAsB,qBACrB,QAAkC;;AAE5B,QAAA,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,GAAA,IACR;AAEJ,QAAM,gBAAe,SAAI,MAAM,UAAV,mBAAiB;AAEhC,QAAA,aAAa,MAAM,OAAO,kBAAkB;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAEG,MAAA,SAAS,WAAW,UAAU;AAElC;AACD;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const client = require("@prismicio/client");
|
|
4
|
+
function setPreviewData({ req, res }) {
|
|
5
|
+
const ref = req.query.token || req.cookies[client.cookie.preview];
|
|
6
|
+
if (ref) {
|
|
7
|
+
res.setPreviewData({ ref });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.setPreviewData = setPreviewData;
|
|
11
|
+
//# sourceMappingURL=setPreviewData.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.
|
|
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"],"names":["cookie"],"mappings":";;;SAsBgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,cAAO,OAAO;AAEzD,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,KAAK;AAAA,EAAA;AAE5B;;"}
|
package/dist/pages.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const PrismicNextLink = require("./PrismicNextLink.cjs");
|
|
4
|
+
const PrismicNextImage = require("./PrismicNextImage.cjs");
|
|
5
|
+
const imgixLoader = require("./imgixLoader.cjs");
|
|
6
|
+
const PrismicPreview = require("./pages/PrismicPreview.cjs");
|
|
7
|
+
const enableAutoPreviews = require("./pages/enableAutoPreviews.cjs");
|
|
8
|
+
const redirectToPreviewURL = require("./pages/redirectToPreviewURL.cjs");
|
|
9
|
+
const exitPreview = require("./pages/exitPreview.cjs");
|
|
10
|
+
const setPreviewData = require("./pages/setPreviewData.cjs");
|
|
11
|
+
const createLocaleRedirect = require("./createLocaleRedirect.cjs");
|
|
12
|
+
exports.PrismicNextLink = PrismicNextLink.PrismicNextLink;
|
|
13
|
+
exports.PrismicNextImage = PrismicNextImage.PrismicNextImage;
|
|
14
|
+
exports.imgixLoader = imgixLoader.imgixLoader;
|
|
15
|
+
exports.PrismicPreview = PrismicPreview.PrismicPreview;
|
|
16
|
+
exports.enableAutoPreviews = enableAutoPreviews.enableAutoPreviews;
|
|
17
|
+
exports.redirectToPreviewURL = redirectToPreviewURL.redirectToPreviewURL;
|
|
18
|
+
exports.exitPreview = exitPreview.exitPreview;
|
|
19
|
+
exports.setPreviewData = setPreviewData.setPreviewData;
|
|
20
|
+
exports.createLocaleRedirect = createLocaleRedirect.createLocaleRedirect;
|
|
21
|
+
//# sourceMappingURL=pages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
+
const navigation = require("next/navigation");
|
|
26
|
+
const client = require("@prismicio/client");
|
|
27
|
+
async function redirectToPreviewURL(config) {
|
|
28
|
+
const { client: client$1, request, linkResolver, defaultURL = "/" } = config;
|
|
29
|
+
const { cookies, draftMode } = await import("next/headers");
|
|
30
|
+
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
31
|
+
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
32
|
+
if (previewToken) {
|
|
33
|
+
const cookieJar = await cookies();
|
|
34
|
+
cookieJar.set(client.cookie.preview, previewToken);
|
|
35
|
+
}
|
|
36
|
+
const previewURL = await client$1.resolvePreviewURL({
|
|
37
|
+
documentID,
|
|
38
|
+
previewToken,
|
|
39
|
+
defaultURL,
|
|
40
|
+
linkResolver
|
|
41
|
+
});
|
|
42
|
+
(await draftMode()).enable();
|
|
43
|
+
navigation.redirect(previewURL);
|
|
44
|
+
}
|
|
45
|
+
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
46
|
+
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","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 { 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"],"names":["client","prismicCookie","redirect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,eAAsB,qBACrB,QAAkC;AAElC,QAAM,EAAA,QAAEA,UAAQ,SAAS,cAAc,aAAa,QAAQ;AAK5D,QAAM,EAAE,SAAS,cAAc,MAAM,OAAO,cAAc;AAE1D,QAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,YAAY,KAAK;AAMnD,QAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,OAAO,KAAK;AAClE,MAAI,cAAc;AACX,UAAA,YAAY,MAAM;AACd,cAAA,IAAIC,cAAc,SAAS,YAAY;AAAA,EAAA;AAG5C,QAAA,aAAa,MAAMD,SAAO,kBAAkB;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAEA,GAAA,MAAM,UAAS,GAAI;AAEpBE,aAAAA,SAAS,UAAU;AACpB;;"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"e2e-projects/*"
|
|
5
5
|
],
|
|
6
6
|
"name": "@prismicio/next",
|
|
7
|
-
"version": "2.0.1-alpha.
|
|
7
|
+
"version": "2.0.1-alpha.1",
|
|
8
8
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"typescript",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"default": "./dist/index.
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
28
|
},
|
|
29
29
|
"./pages": {
|
|
30
30
|
"types": "./dist/pages/index.d.ts",
|
|
31
|
-
"default": "./dist/pages.
|
|
31
|
+
"default": "./dist/pages.cjs"
|
|
32
32
|
},
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
"e2e:ui": "npm run e2e -- --ui"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"esm-env": "^1.2.1",
|
|
67
66
|
"imgix-url-builder": "^0.0.5"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
import Image, { ImageProps } from "next/image";
|
|
10
10
|
import { buildURL, ImgixURLParams } from "imgix-url-builder";
|
|
11
11
|
import { ImageFieldImage, isFilled } from "@prismicio/client";
|
|
12
|
-
import { DEV } from "esm-env";
|
|
13
12
|
|
|
14
13
|
import { devMsg } from "./lib/devMsg";
|
|
14
|
+
import { resolveCJS } from "./lib/resolveCJS";
|
|
15
15
|
|
|
16
16
|
import { imgixLoader } from "./imgixLoader";
|
|
17
17
|
|
|
@@ -104,7 +104,7 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
104
104
|
},
|
|
105
105
|
ref,
|
|
106
106
|
) {
|
|
107
|
-
if (
|
|
107
|
+
if (process.env.NODE_ENV === "development") {
|
|
108
108
|
if (typeof alt === "string" && alt !== "") {
|
|
109
109
|
console.warn(
|
|
110
110
|
`[PrismicNextImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
|
|
@@ -153,15 +153,20 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
153
153
|
// know if an alt attribute is available.
|
|
154
154
|
const resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;
|
|
155
155
|
|
|
156
|
-
if (
|
|
156
|
+
if (
|
|
157
|
+
process.env.NODE_ENV === "development" &&
|
|
158
|
+
typeof resolvedAlt !== "string"
|
|
159
|
+
) {
|
|
157
160
|
console.error(
|
|
158
161
|
`[PrismicNextImage] The following image is missing an "alt" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \`alt=""\` or \`fallbackAlt=""\`.`,
|
|
159
162
|
src,
|
|
160
163
|
);
|
|
161
164
|
}
|
|
162
165
|
|
|
166
|
+
const ResolvedImage = resolveCJS(Image);
|
|
167
|
+
|
|
163
168
|
return (
|
|
164
|
-
<
|
|
169
|
+
<ResolvedImage
|
|
165
170
|
ref={ref}
|
|
166
171
|
src={src}
|
|
167
172
|
width={fill ? undefined : resolvedWidth}
|
package/src/PrismicNextLink.tsx
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
asLinkAttrs,
|
|
9
9
|
} from "@prismicio/client";
|
|
10
10
|
|
|
11
|
+
import { resolveCJS } from "./lib/resolveCJS";
|
|
12
|
+
|
|
11
13
|
export type PrismicNextLinkProps = Omit<
|
|
12
14
|
ComponentProps<typeof Link>,
|
|
13
15
|
"field" | "document" | "href" | "rel"
|
|
@@ -53,9 +55,11 @@ export const PrismicNextLink = forwardRef<
|
|
|
53
55
|
rel = restProps.rel;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
const ResolvedLink = resolveCJS(Link);
|
|
59
|
+
|
|
56
60
|
return (
|
|
57
|
-
<
|
|
61
|
+
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
58
62
|
{"children" in props ? children : field?.text}
|
|
59
|
-
</
|
|
63
|
+
</ResolvedLink>
|
|
60
64
|
);
|
|
61
65
|
});
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { FC, ReactNode } from "react";
|
|
|
2
2
|
import Script from "next/script";
|
|
3
3
|
import { getToolbarSrc } from "@prismicio/client";
|
|
4
4
|
|
|
5
|
+
import { resolveCJS } from "./lib/resolveCJS";
|
|
5
6
|
import { PrismicPreviewClient } from "./PrismicPreviewClient";
|
|
6
7
|
|
|
7
8
|
/** Props for `<PrismicPreview>`. */
|
|
@@ -48,6 +49,8 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
48
49
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
49
50
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
50
51
|
|
|
52
|
+
const ResolvedScript = resolveCJS(Script);
|
|
53
|
+
|
|
51
54
|
return (
|
|
52
55
|
<>
|
|
53
56
|
{children}
|
|
@@ -56,7 +59,7 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
56
59
|
isDraftMode={isDraftMode}
|
|
57
60
|
{...otherProps}
|
|
58
61
|
/>
|
|
59
|
-
<
|
|
62
|
+
<ResolvedScript src={toolbarSrc} strategy="lazyOnload" />
|
|
60
63
|
</>
|
|
61
64
|
);
|
|
62
65
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a CommonJS import that might have a `default` property. This happens
|
|
3
|
+
* when named and default exports are mixed in modules. Next.js seems to do this
|
|
4
|
+
* in the exact set up `@prismicio/next` uses.
|
|
5
|
+
*
|
|
6
|
+
* This is _should_ be a temporary hack until Next.js and Node.js resolve their
|
|
7
|
+
* ESM difficulties. This will likely not be removed any time soon.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveCJS<T>(mod: T): T {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
return "default" in (mod as any) ? (mod as any).default : mod;
|
|
12
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.mjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n\tforwardRef,\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport { ImageFieldImage, isFilled } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"loader\"\n> & {\n\t/** The Prismic Image field or thumbnail to render. */\n\tfield: ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\n\n\tloader?: ImageProps[\"loader\"] | null;\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n *\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\n// The type annotation is necessary to avoid a type reference issue.\nexport const PrismicNextImage: ForwardRefExoticComponent<\n\tPropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>\n> = forwardRef<HTMLImageElement, PrismicNextImageProps>(\n\tfunction PrismicNextImage(\n\t\t{\n\t\t\tfield,\n\t\t\timgixParams = {},\n\t\t\talt,\n\t\t\tfallbackAlt,\n\t\t\tfill,\n\t\t\twidth,\n\t\t\theight,\n\t\t\tfallback = null,\n\t\t\tloader = imgixLoader,\n\t\t\t...restProps\n\t\t},\n\t\tref,\n\t) {\n\t\tif (DEV) {\n\t\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!isFilled.imageThumbnail(field)) {\n\t\t\treturn <>{fallback}</>;\n\t\t}\n\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (DEV && typeof resolvedAlt !== \"string\") {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tref={ref}\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={loader === null ? undefined : loader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["PrismicNextImage","_jsx","_Fragment"],"mappings":";;;;;;;;;AAiBA,MAAM,UAAU,CAAC,UAA0D;AAC1E,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,WAAA;AAAA,EAAA,OACD;AACA,UAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,QAAA,OAAO,MAAM,MAAM,GAAG;AAClB,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IAAA;AAAA,EACR;AAEF;AA2Da,MAAA,mBAET,WACH,SAASA,kBACR,EACC,OACA,cAAc,CAAA,GACd,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAAS,aACT,GAAG,UAAS,GAEb,KAAG;AAEH,MAAI,KAAK;AACR,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQ,OACxQ,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAIL,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAyS,OACxS,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAAA,EAEL;AAGD,MAAI,CAAC,SAAS,eAAe,KAAK,GAAG;AACpC,WAAOC,IAAAC,UAAA,EAAA,UAAG,UAAQ;AAAA,EAAA;AAGnB,QAAM,sBAAsB;AAC5B,aAAW,KAAK,aAAa;AACxB,QAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,0BAAoB,CAAqC,IAAI;AAAA,IAAA;AAAA,EAC9D;AAGD,QAAM,MAAM,SAAS,MAAM,KAAK,WAA6B;AAE7D,QAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,QAAA,cAAc,QAAQ,KAAK;AAC3B,QAAA,eAAe,QAAQ,MAAM;AAE/B,MAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,MAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,MAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,qBAAiB,cAAc;AAAA,EACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,oBAAgB,eAAe;AAAA,EAAA;AAK1B,QAAA,cAAe,QAAQ,MAAM,OAAO;AAEtC,MAAA,OAAO,OAAO,gBAAgB,UAAU;AACnC,YAAA,MACP,mNACA,GAAG;AAAA,EAAA;AAKJ,SAAAD,IAAC,OAAK,EACL,KACA,KACA,OAAO,OAAO,SAAY,eAC1B,QAAQ,OAAO,SAAY,gBAC3B,KAAK,aACL,MACA,QAAQ,WAAW,OAAO,SAAY,QAAM,GACxC,UAAA,CAAS;AAGhB,CAAC;"}
|
package/dist/PrismicNextLink.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import Link from "next/link";
|
|
4
|
-
import { asLinkAttrs } from "@prismicio/client";
|
|
5
|
-
const PrismicNextLink = forwardRef(function PrismicNextLink2(props, ref) {
|
|
6
|
-
const { field, document, linkResolver, children, ...restProps } = props;
|
|
7
|
-
const { href: computedHref, rel: computedRel, ...attrs } = asLinkAttrs(field ?? document, {
|
|
8
|
-
linkResolver,
|
|
9
|
-
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
10
|
-
});
|
|
11
|
-
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
12
|
-
let rel = computedRel;
|
|
13
|
-
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
14
|
-
rel = restProps.rel;
|
|
15
|
-
}
|
|
16
|
-
return jsx(Link, { ref, ...attrs, ...restProps, href, rel, children: "children" in props ? children : field == null ? void 0 : field.text });
|
|
17
|
-
});
|
|
18
|
-
export {
|
|
19
|
-
PrismicNextLink
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=PrismicNextLink.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextLink.mjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps, forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\";\n\nexport type PrismicNextLinkProps = Omit<\n\tComponentProps<typeof Link>,\n\t\"field\" | \"document\" | \"href\" | \"rel\"\n> & {\n\tlinkResolver?: LinkResolverFunction;\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n} & (\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument?: never;\n\t\t\t\thref: ComponentProps<typeof Link>[\"href\"];\n\t\t }\n\t);\n\nexport const PrismicNextLink = forwardRef<\n\tHTMLAnchorElement,\n\tPrismicNextLinkProps\n>(function PrismicNextLink(props, ref) {\n\tconst { field, document, linkResolver, children, ...restProps } = props;\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? document, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tlet rel = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\treturn (\n\t\t<Link ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Link>\n\t);\n});\n"],"names":["PrismicNextLink","_jsx"],"mappings":";;;;AAkCO,MAAM,kBAAkB,WAG7B,SAASA,iBAAgB,OAAO,KAAG;AACpC,QAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;AAC5D,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,UAAU;AAAA,IAClC;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,MAAI,MAAM;AACV,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGjB,SACCC,IAAC,MAAI,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eACpD,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;"}
|
package/dist/PrismicPreview.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import Script from "next/script";
|
|
3
|
-
import { getToolbarSrc } from "@prismicio/client";
|
|
4
|
-
import { PrismicPreviewClient } from "./PrismicPreviewClient.mjs";
|
|
5
|
-
const PrismicPreview = async (props) => {
|
|
6
|
-
const { repositoryName, children, ...otherProps } = props;
|
|
7
|
-
const { draftMode } = await import("next/headers");
|
|
8
|
-
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
9
|
-
const isDraftMode = (await draftMode()).isEnabled;
|
|
10
|
-
return jsxs(Fragment, { children: [children, jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...otherProps }), jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
11
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
PrismicPreview
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=PrismicPreview.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.mjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\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> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props;\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 { draftMode } = await import(\"next/headers\");\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\tconst isDraftMode = (await draftMode()).isEnabled;\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;AAuCa,MAAA,iBAA0C,OAAO,UAAS;AACtE,QAAM,EAAE,gBAAgB,UAAU,GAAG,WAAe,IAAA;AAKpD,QAAM,EAAE,UAAA,IAAc,MAAM,OAAO,cAAc;AAE3C,QAAA,aAAa,cAAc,cAAc;AACzC,QAAA,eAAe,MAAM,UAAA,GAAa;AAGvC,SAAAA,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBACA,EAAA,gBACA,aAAwB,GACpB,YAAU,GAEfA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,cAAe,CAAA,GAAA;AAGpD;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { devMsg } from "./lib/devMsg.mjs";
|
|
2
|
-
function createLocaleRedirect() {
|
|
3
|
-
throw new Error(`createLocaleRedirect() has been removed due to performance issues. See ${devMsg("replace-createLocaleRedirect")} for more details.`);
|
|
4
|
-
}
|
|
5
|
-
export {
|
|
6
|
-
createLocaleRedirect
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=createLocaleRedirect.mjs.map
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { cookie } from "@prismicio/client";
|
|
2
|
-
function enableAutoPreviews(config) {
|
|
3
|
-
config.client.queryContentFromRef(async () => {
|
|
4
|
-
var _a;
|
|
5
|
-
const { cookies, draftMode } = await import("next/headers");
|
|
6
|
-
let isDraftModeEnabled = false;
|
|
7
|
-
try {
|
|
8
|
-
isDraftModeEnabled = (await draftMode()).isEnabled;
|
|
9
|
-
} catch {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (!isDraftModeEnabled) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const cookie$1 = (_a = (await cookies()).get(cookie.preview)) == null ? void 0 : _a.value;
|
|
16
|
-
if (!cookie$1) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const isActiveCookie = cookie$1.includes("websitePreviewId=");
|
|
20
|
-
if (!isActiveCookie) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
return cookie$1;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
enableAutoPreviews
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=enableAutoPreviews.mjs.map
|
package/dist/exitPreview.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
async function exitPreview() {
|
|
2
|
-
const { draftMode } = await import("next/headers");
|
|
3
|
-
(await draftMode()).disable();
|
|
4
|
-
return new Response(JSON.stringify({ success: true }), {
|
|
5
|
-
headers: {
|
|
6
|
-
"Cache-Control": "no-store"
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
exitPreview
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=exitPreview.mjs.map
|
package/dist/imgixLoader.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { buildURL } from "imgix-url-builder";
|
|
2
|
-
const imgixLoader = (args) => {
|
|
3
|
-
const url = new URL(args.src);
|
|
4
|
-
const params = {
|
|
5
|
-
fit: url.searchParams.get("fit") || "max",
|
|
6
|
-
w: args.width,
|
|
7
|
-
h: void 0
|
|
8
|
-
};
|
|
9
|
-
if (args.quality) {
|
|
10
|
-
params.q = args.quality;
|
|
11
|
-
}
|
|
12
|
-
return buildURL(args.src, params);
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
imgixLoader
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=imgixLoader.mjs.map
|
package/dist/index.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { exitPreview } from "./exitPreview.mjs";
|
|
2
|
-
import { PrismicPreview } from "./PrismicPreview.mjs";
|
|
3
|
-
import { PrismicNextLink } from "./PrismicNextLink.mjs";
|
|
4
|
-
import { enableAutoPreviews } from "./enableAutoPreviews.mjs";
|
|
5
|
-
import { redirectToPreviewURL } from "./redirectToPreviewURL.mjs";
|
|
6
|
-
import { PrismicNextImage } from "./PrismicNextImage.mjs";
|
|
7
|
-
import { imgixLoader } from "./imgixLoader.mjs";
|
|
8
|
-
import { createLocaleRedirect } from "./createLocaleRedirect.mjs";
|
|
9
|
-
export {
|
|
10
|
-
PrismicNextImage,
|
|
11
|
-
PrismicNextLink,
|
|
12
|
-
PrismicPreview,
|
|
13
|
-
createLocaleRedirect,
|
|
14
|
-
enableAutoPreviews,
|
|
15
|
-
exitPreview,
|
|
16
|
-
imgixLoader,
|
|
17
|
-
redirectToPreviewURL
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/lib/devMsg.mjs
DELETED
package/dist/package.json.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { cookie } from "@prismicio/client";
|
|
2
|
-
function setPreviewData({ req, res }) {
|
|
3
|
-
const ref = req.query.token || req.cookies[cookie.preview];
|
|
4
|
-
if (ref) {
|
|
5
|
-
res.setPreviewData({ ref });
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
setPreviewData
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=setPreviewData.mjs.map
|
package/dist/pages.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PrismicNextLink } from "./PrismicNextLink.mjs";
|
|
2
|
-
import { PrismicNextImage } from "./PrismicNextImage.mjs";
|
|
3
|
-
import { imgixLoader } from "./imgixLoader.mjs";
|
|
4
|
-
import { PrismicPreview } from "./pages/PrismicPreview.mjs";
|
|
5
|
-
import { enableAutoPreviews } from "./pages/enableAutoPreviews.mjs";
|
|
6
|
-
import { redirectToPreviewURL } from "./pages/redirectToPreviewURL.mjs";
|
|
7
|
-
import { exitPreview } from "./pages/exitPreview.mjs";
|
|
8
|
-
import { setPreviewData } from "./pages/setPreviewData.mjs";
|
|
9
|
-
import { createLocaleRedirect } from "./createLocaleRedirect.mjs";
|
|
10
|
-
export {
|
|
11
|
-
PrismicNextImage,
|
|
12
|
-
PrismicNextLink,
|
|
13
|
-
PrismicPreview,
|
|
14
|
-
createLocaleRedirect,
|
|
15
|
-
enableAutoPreviews,
|
|
16
|
-
exitPreview,
|
|
17
|
-
imgixLoader,
|
|
18
|
-
redirectToPreviewURL,
|
|
19
|
-
setPreviewData
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=pages.mjs.map
|
package/dist/pages.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pages.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { redirect } from "next/navigation";
|
|
2
|
-
import { cookie } from "@prismicio/client";
|
|
3
|
-
async function redirectToPreviewURL(config) {
|
|
4
|
-
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
5
|
-
const { cookies, draftMode } = await import("next/headers");
|
|
6
|
-
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
7
|
-
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
8
|
-
if (previewToken) {
|
|
9
|
-
const cookieJar = await cookies();
|
|
10
|
-
cookieJar.set(cookie.preview, previewToken);
|
|
11
|
-
}
|
|
12
|
-
const previewURL = await client.resolvePreviewURL({
|
|
13
|
-
documentID,
|
|
14
|
-
previewToken,
|
|
15
|
-
defaultURL,
|
|
16
|
-
linkResolver
|
|
17
|
-
});
|
|
18
|
-
(await draftMode()).enable();
|
|
19
|
-
redirect(previewURL);
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
redirectToPreviewURL
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=redirectToPreviewURL.mjs.map
|