@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,36 @@
|
|
|
1
|
+
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews.cjs";
|
|
2
|
+
import { ClientConfig } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/pages/types.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for creating a Prismic client with automatic preview support in
|
|
8
|
+
* Next.js apps.
|
|
9
|
+
*/
|
|
10
|
+
type CreateClientConfig = ClientConfig & Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
|
|
11
|
+
/**
|
|
12
|
+
* The minimal set of properties needed from `next`'s `NextApiRequest` type.
|
|
13
|
+
*
|
|
14
|
+
* This request type is only compatible with API routes defined in the `pages`
|
|
15
|
+
* directory.
|
|
16
|
+
*/
|
|
17
|
+
type NextApiRequestLike = {
|
|
18
|
+
query: Partial<Record<string, string | string[]>>;
|
|
19
|
+
cookies: Partial<Record<string, string>>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The minimal set of properties needed from `next`'s `NextApiResponse` type.
|
|
23
|
+
*
|
|
24
|
+
* This request type is only compatible with API routes defined in the `pages`
|
|
25
|
+
* directory.
|
|
26
|
+
*/
|
|
27
|
+
type NextApiResponseLike = {
|
|
28
|
+
redirect(url: string): NextApiResponseLike;
|
|
29
|
+
clearPreviewData(): NextApiResponseLike;
|
|
30
|
+
setHeader(name: string, value: string | string[]): NextApiResponseLike;
|
|
31
|
+
json(body: any): void;
|
|
32
|
+
setPreviewData(data: object | string): NextApiResponseLike;
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { CreateClientConfig, NextApiRequestLike, NextApiResponseLike };
|
|
36
|
+
//# sourceMappingURL=types.d.cts.map
|
package/dist/pages.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.PrismicPreview =
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.exitPreview =
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
|
|
1
|
+
const require_PrismicNextLink = require('./PrismicNextLink.cjs');
|
|
2
|
+
const require_imgixLoader = require('./imgixLoader.cjs');
|
|
3
|
+
const require_PrismicNextImage = require('./PrismicNextImage.cjs');
|
|
4
|
+
const require_PrismicNextRichText = require('./PrismicNextRichText.cjs');
|
|
5
|
+
const require_createLocaleRedirect = require('./createLocaleRedirect.cjs');
|
|
6
|
+
const require_PrismicPreview = require('./pages/PrismicPreview.cjs');
|
|
7
|
+
const require_enableAutoPreviews = require('./pages/enableAutoPreviews.cjs');
|
|
8
|
+
const require_redirectToPreviewURL = require('./pages/redirectToPreviewURL.cjs');
|
|
9
|
+
const require_exitPreview = require('./pages/exitPreview.cjs');
|
|
10
|
+
const require_setPreviewData = require('./pages/setPreviewData.cjs');
|
|
11
|
+
|
|
12
|
+
exports.PrismicNextImage = require_PrismicNextImage.PrismicNextImage;
|
|
13
|
+
exports.PrismicNextLink = require_PrismicNextLink.PrismicNextLink;
|
|
14
|
+
exports.PrismicNextRichText = require_PrismicNextRichText.PrismicNextRichText;
|
|
15
|
+
exports.PrismicPreview = require_PrismicPreview.PrismicPreview;
|
|
16
|
+
exports.createLocaleRedirect = require_createLocaleRedirect.createLocaleRedirect;
|
|
17
|
+
exports.enableAutoPreviews = require_enableAutoPreviews.enableAutoPreviews;
|
|
18
|
+
exports.exitPreview = require_exitPreview.exitPreview;
|
|
19
|
+
exports.imgixLoader = require_imgixLoader.imgixLoader;
|
|
20
|
+
exports.redirectToPreviewURL = require_redirectToPreviewURL.redirectToPreviewURL;
|
|
21
|
+
exports.setPreviewData = require_setPreviewData.setPreviewData;
|
package/dist/pages.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.cjs";
|
|
2
|
+
import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.cjs";
|
|
3
|
+
import { PrismicNextRichText, PrismicNextRichTextProps } from "./PrismicNextRichText.cjs";
|
|
4
|
+
import { imgixLoader } from "./imgixLoader.cjs";
|
|
5
|
+
import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.cjs";
|
|
6
|
+
import { PrismicPreview, PrismicPreviewProps } from "./pages/PrismicPreview.cjs";
|
|
7
|
+
import { CreateClientConfig } from "./pages/types.cjs";
|
|
8
|
+
import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./pages/enableAutoPreviews.cjs";
|
|
9
|
+
import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./pages/redirectToPreviewURL.cjs";
|
|
10
|
+
import { ExitPreviewAPIRouteConfig, exitPreview } from "./pages/exitPreview.cjs";
|
|
11
|
+
import { SetPreviewDataConfig, setPreviewData } from "./pages/setPreviewData.cjs";
|
|
12
|
+
export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, type ExitPreviewAPIRouteConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicNextRichText, type PrismicNextRichTextProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, type SetPreviewDataConfig, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
|
|
@@ -1,46 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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");
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _prismicio_client = require("@prismicio/client");
|
|
3
|
+
let next_navigation = require("next/navigation");
|
|
4
|
+
|
|
5
|
+
//#region src/redirectToPreviewURL.ts
|
|
27
6
|
async function redirectToPreviewURL(config) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
(await draftMode()).enable();
|
|
43
|
-
navigation.redirect(previewURL);
|
|
7
|
+
const { client, request, linkResolver, defaultURL = "/" } = config;
|
|
8
|
+
const { cookies, draftMode } = await import("next/headers");
|
|
9
|
+
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
10
|
+
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
11
|
+
if (previewToken) (await cookies()).set(_prismicio_client.cookie.preview, previewToken);
|
|
12
|
+
const previewURL = await client.resolvePreviewURL({
|
|
13
|
+
documentID,
|
|
14
|
+
previewToken,
|
|
15
|
+
defaultURL,
|
|
16
|
+
linkResolver
|
|
17
|
+
});
|
|
18
|
+
(await draftMode()).enable();
|
|
19
|
+
(0, next_navigation.redirect)(previewURL);
|
|
44
20
|
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
45
23
|
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
46
|
-
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
24
|
+
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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"],"
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} from \"@prismicio/client\";\n\nimport type { NextRequestLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\");\n\n\tconst documentID =\n\t\trequest.nextUrl.searchParams.get(\"documentId\") ?? undefined;\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined;\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies();\n\t\tcookieJar.set(prismicCookie.preview, previewToken);\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t});\n\n\t(await draftMode()).enable();\n\n\tredirect(previewURL);\n}\n"],"mappings":";;;;;AAyCA,eAAsB,qBACrB,QACiB;CACjB,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAE5C,MAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI;CAMnD,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI;AAClE,KAAI,aAEH,EADkB,MAAM,SAAS,EACvB,IAAIA,yBAAc,SAAS,aAAa;CAGnD,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAEF,EAAC,MAAM,WAAW,EAAE,QAAQ;AAE5B,+BAAS,WAAW"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NextRequestLike } from "./types.cjs";
|
|
2
|
+
import { Client, LinkResolverFunction } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/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 `request` object from a Next.js Route Handler.
|
|
10
|
+
*
|
|
11
|
+
* @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
|
|
12
|
+
*/
|
|
13
|
+
request: NextRequestLike;
|
|
14
|
+
/**
|
|
15
|
+
* A Link Resolver used to resolve the previewed document's URL.
|
|
16
|
+
*
|
|
17
|
+
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
18
|
+
*/
|
|
19
|
+
linkResolver?: LinkResolverFunction;
|
|
20
|
+
/**
|
|
21
|
+
* The default redirect URL if a URL cannot be determined for the previewed
|
|
22
|
+
* document.
|
|
23
|
+
*
|
|
24
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
25
|
+
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
26
|
+
* property using the `basePath` option.
|
|
27
|
+
*/
|
|
28
|
+
defaultURL?: string;
|
|
29
|
+
};
|
|
30
|
+
declare function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never>;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { RedirectToPreviewURLConfig, redirectToPreviewURL };
|
|
33
|
+
//# sourceMappingURL=redirectToPreviewURL.d.cts.map
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ClientConfig } from "@prismicio/client";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
declare module "@prismicio/client" {
|
|
5
|
+
interface RequestInitLike {
|
|
6
|
+
next?: RequestInit["next"];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
|
|
10
|
+
type CreateClientConfig = ClientConfig;
|
|
11
|
+
/**
|
|
12
|
+
* The minimal set of properties needed from `next`'s `NextRequest` type.
|
|
13
|
+
*
|
|
14
|
+
* This request type is only compatible with Route Handlers defined in the `app`
|
|
15
|
+
* directory.
|
|
16
|
+
*/
|
|
17
|
+
type NextRequestLike = {
|
|
18
|
+
headers: {
|
|
19
|
+
get(name: string): string | null;
|
|
20
|
+
};
|
|
21
|
+
url: string;
|
|
22
|
+
nextUrl: {
|
|
23
|
+
pathname: string;
|
|
24
|
+
searchParams: {
|
|
25
|
+
get(name: string): string | null;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { CreateClientConfig, NextRequestLike };
|
|
31
|
+
//# sourceMappingURL=types.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"workspaces": [
|
|
3
|
-
".",
|
|
4
|
-
"e2e-projects/*"
|
|
5
|
-
],
|
|
6
2
|
"name": "@prismicio/next",
|
|
7
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-canary.6f580fa",
|
|
8
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
9
5
|
"keywords": [
|
|
10
6
|
"typescript",
|
|
@@ -22,16 +18,13 @@
|
|
|
22
18
|
"sideEffects": false,
|
|
23
19
|
"type": "module",
|
|
24
20
|
"exports": {
|
|
25
|
-
".":
|
|
26
|
-
|
|
27
|
-
"default": "./dist/index.cjs"
|
|
28
|
-
},
|
|
29
|
-
"./pages": {
|
|
30
|
-
"types": "./dist/pages/index.d.ts",
|
|
31
|
-
"default": "./dist/pages.cjs"
|
|
32
|
-
},
|
|
21
|
+
".": "./dist/index.cjs",
|
|
22
|
+
"./pages": "./dist/pages.cjs",
|
|
33
23
|
"./package.json": "./package.json"
|
|
34
24
|
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
35
28
|
"typesVersions": {
|
|
36
29
|
"*": {
|
|
37
30
|
"*": [
|
|
@@ -46,62 +39,54 @@
|
|
|
46
39
|
"dist",
|
|
47
40
|
"src"
|
|
48
41
|
],
|
|
42
|
+
"workspaces": [
|
|
43
|
+
".",
|
|
44
|
+
"e2e-projects/*"
|
|
45
|
+
],
|
|
49
46
|
"scripts": {
|
|
50
|
-
"build": "
|
|
51
|
-
"dev": "
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"dev": "tsdown --watch",
|
|
49
|
+
"e2e": "playwright test",
|
|
50
|
+
"e2e:ui": "npm run e2e -- --ui",
|
|
52
51
|
"format": "prettier --write .",
|
|
53
|
-
"lint": "
|
|
52
|
+
"lint": "oxlint --deny-warnings",
|
|
54
53
|
"prepare": "npm run build",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"release:alpha:dry": "standard-version --prerelease alpha --dry-run",
|
|
58
|
-
"release:dry": "standard-version --dry-run",
|
|
59
|
-
"size": "size-limit",
|
|
60
|
-
"test": "npm run lint && npm run types && npm run build && npm run e2e && npm run size && npm run e2e",
|
|
61
|
-
"types": "tsc --noEmit",
|
|
62
|
-
"e2e": "playwright test",
|
|
63
|
-
"e2e:ui": "npm run e2e -- --ui"
|
|
54
|
+
"test": "npm run lint && npm run types && npm run build && npm run e2e",
|
|
55
|
+
"types": "tsc --noEmit"
|
|
64
56
|
},
|
|
65
57
|
"dependencies": {
|
|
66
58
|
"imgix-url-builder": "^0.0.5"
|
|
67
59
|
},
|
|
68
60
|
"devDependencies": {
|
|
69
|
-
"@eslint/js": "^9.17.0",
|
|
70
61
|
"@playwright/test": "^1.49.1",
|
|
71
62
|
"@prismicio/client": "^7.12.0",
|
|
72
|
-
"@prismicio/
|
|
73
|
-
"@
|
|
74
|
-
"@size-limit/preset-small-lib": "^11.1.6",
|
|
63
|
+
"@prismicio/react": "^3.2.2",
|
|
64
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
75
65
|
"@types/node": "^22.10.2",
|
|
76
|
-
"@types/react": "^19.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"eslint": "^9.17.0",
|
|
80
|
-
"eslint-config-prettier": "^9.1.0",
|
|
81
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
82
|
-
"eslint-plugin-react": "^7.37.2",
|
|
83
|
-
"eslint-plugin-react-hooks": "^5.1.0",
|
|
84
|
-
"eslint-plugin-tsdoc": "^0.4.0",
|
|
85
|
-
"next": "^15.1.0",
|
|
66
|
+
"@types/react": "^19.2.3",
|
|
67
|
+
"next": "16.0.8",
|
|
68
|
+
"oxlint": "^1.38.0",
|
|
86
69
|
"playwright": "^1.49.1",
|
|
87
70
|
"prettier": "^3.4.2",
|
|
88
71
|
"prettier-plugin-jsdoc": "^1.3.0",
|
|
89
|
-
"react": "^19.
|
|
90
|
-
"react-dom": "^19.
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"standard-version": "^9.5.0",
|
|
94
|
-
"typescript": "^5.7.2",
|
|
95
|
-
"typescript-eslint": "^8.18.1",
|
|
96
|
-
"vite": "^6.0.4"
|
|
72
|
+
"react": "^19.2.1",
|
|
73
|
+
"react-dom": "^19.2.1",
|
|
74
|
+
"tsdown": "^0.19.0-beta.5",
|
|
75
|
+
"typescript": "^5.7.2"
|
|
97
76
|
},
|
|
98
77
|
"peerDependencies": {
|
|
99
78
|
"@prismicio/client": "^7",
|
|
100
|
-
"
|
|
79
|
+
"@prismicio/react": "^3",
|
|
80
|
+
"next": "^13.4.5 || ^14 || ^15 || ^16",
|
|
101
81
|
"react": "^18 || ^19"
|
|
102
82
|
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@prismicio/react": {
|
|
85
|
+
"optional": true
|
|
86
|
+
}
|
|
87
|
+
},
|
|
103
88
|
"engines": {
|
|
104
|
-
"node": ">=
|
|
89
|
+
"node": ">=20"
|
|
105
90
|
},
|
|
106
91
|
"publishConfig": {
|
|
107
92
|
"access": "public"
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
forwardRef,
|
|
3
|
+
import type {
|
|
5
4
|
ForwardRefExoticComponent,
|
|
6
5
|
PropsWithoutRef,
|
|
7
|
-
RefAttributes
|
|
6
|
+
RefAttributes} from "react";
|
|
7
|
+
import {
|
|
8
|
+
forwardRef
|
|
8
9
|
} from "react";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
10
|
+
import type { ImageProps } from "next/image";
|
|
11
|
+
import Image from "next/image";
|
|
12
|
+
import type { ImgixURLParams } from "imgix-url-builder";
|
|
13
|
+
import { buildURL } from "imgix-url-builder";
|
|
14
|
+
import type { ImageFieldImage} from "@prismicio/client";
|
|
15
|
+
import { isFilled } from "@prismicio/client";
|
|
12
16
|
|
|
13
17
|
import { devMsg } from "./lib/devMsg";
|
|
14
|
-
import {
|
|
18
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
15
19
|
|
|
16
20
|
import { imgixLoader } from "./imgixLoader";
|
|
17
21
|
|
|
@@ -163,7 +167,7 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
163
167
|
);
|
|
164
168
|
}
|
|
165
169
|
|
|
166
|
-
const ResolvedImage =
|
|
170
|
+
const ResolvedImage = resolveDefaultExport(Image);
|
|
167
171
|
|
|
168
172
|
return (
|
|
169
173
|
<ResolvedImage
|
package/src/PrismicNextLink.tsx
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ComponentProps
|
|
1
|
+
import type { ComponentProps} from "react";
|
|
2
|
+
import { forwardRef } from "react";
|
|
2
3
|
import Link from "next/link";
|
|
3
|
-
import {
|
|
4
|
+
import type {
|
|
4
5
|
AsLinkAttrsConfig,
|
|
5
6
|
LinkField,
|
|
6
7
|
LinkResolverFunction,
|
|
7
|
-
PrismicDocument
|
|
8
|
+
PrismicDocument} from "@prismicio/client";
|
|
9
|
+
import {
|
|
8
10
|
asLinkAttrs,
|
|
9
11
|
} from "@prismicio/client";
|
|
10
12
|
|
|
11
|
-
import {
|
|
13
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
12
14
|
|
|
13
15
|
export type PrismicNextLinkProps = Omit<
|
|
14
16
|
ComponentProps<typeof Link>,
|
|
@@ -55,7 +57,7 @@ export const PrismicNextLink = forwardRef<
|
|
|
55
57
|
rel = restProps.rel;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
const ResolvedLink =
|
|
60
|
+
const ResolvedLink = resolveDefaultExport(Link);
|
|
59
61
|
|
|
60
62
|
return (
|
|
61
63
|
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
import { PrismicRichText } from "@prismicio/react";
|
|
3
|
+
import type { PrismicRichTextProps, JSXMapSerializer } from "@prismicio/react";
|
|
4
|
+
|
|
5
|
+
import { PrismicNextImage } from "./PrismicNextImage";
|
|
6
|
+
import { PrismicNextLink } from "./PrismicNextLink";
|
|
7
|
+
|
|
8
|
+
export type PrismicNextRichTextProps = Omit<
|
|
9
|
+
PrismicRichTextProps,
|
|
10
|
+
"components"
|
|
11
|
+
> & {
|
|
12
|
+
components?: JSXMapSerializer;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const defaultComponents: JSXMapSerializer = {
|
|
16
|
+
image: ({ node }) => (
|
|
17
|
+
<p className="block-img">
|
|
18
|
+
{node.linkTo ? (
|
|
19
|
+
<PrismicNextLink field={node.linkTo}>
|
|
20
|
+
<PrismicNextImage field={node} />
|
|
21
|
+
</PrismicNextLink>
|
|
22
|
+
) : (
|
|
23
|
+
<PrismicNextImage field={node} />
|
|
24
|
+
)}
|
|
25
|
+
</p>
|
|
26
|
+
),
|
|
27
|
+
hyperlink: ({ node, children }) => (
|
|
28
|
+
<PrismicNextLink field={node.data}>{children}</PrismicNextLink>
|
|
29
|
+
),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const PrismicNextRichText: FC<PrismicNextRichTextProps> = (props) => {
|
|
33
|
+
const { components, ...restProps } = props;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<PrismicRichText
|
|
37
|
+
components={{ ...defaultComponents, ...components }}
|
|
38
|
+
{...restProps}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
};
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -2,7 +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 {
|
|
5
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
6
6
|
import { PrismicPreviewClient } from "./PrismicPreviewClient";
|
|
7
7
|
|
|
8
8
|
/** Props for `<PrismicPreview>`. */
|
|
@@ -49,7 +49,7 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
49
49
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
50
50
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
51
51
|
|
|
52
|
-
const ResolvedScript =
|
|
52
|
+
const ResolvedScript = resolveDefaultExport(Script);
|
|
53
53
|
|
|
54
54
|
return (
|
|
55
55
|
<>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { FC, useEffect } from "react";
|
|
4
3
|
import { cookie as prismicCookie } from "@prismicio/client";
|
|
5
4
|
import { useRouter } from "next/navigation";
|
|
5
|
+
import type { FC } from "react";
|
|
6
|
+
import { useEffect } from "react";
|
|
6
7
|
|
|
7
8
|
type PrismicPreviewClientProps = {
|
|
8
9
|
repositoryName: string;
|
|
@@ -41,8 +42,6 @@ export const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {
|
|
|
41
42
|
// share links do not go to the `updatePreviewURL` like a normal
|
|
42
43
|
// preview.
|
|
43
44
|
if (hasCookieForRepository && !isDraftMode) {
|
|
44
|
-
console.log("starting preview link");
|
|
45
|
-
|
|
46
45
|
// We check `opaqueredirect` because we don't care if
|
|
47
46
|
// the redirect was successful or not. As long as it
|
|
48
47
|
// redirects, we know the endpoint exists and draft mode
|
|
@@ -4,7 +4,7 @@ import { devMsg } from "./lib/devMsg";
|
|
|
4
4
|
* @deprecated `createLocaleRedirect()` has been removed due to performance
|
|
5
5
|
* issues.
|
|
6
6
|
*/
|
|
7
|
-
export function createLocaleRedirect() {
|
|
7
|
+
export function createLocaleRedirect(): never {
|
|
8
8
|
throw new Error(
|
|
9
9
|
`createLocaleRedirect() has been removed due to performance issues. See ${devMsg(
|
|
10
10
|
"replace-createLocaleRedirect",
|
package/src/imgixLoader.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ImageLoaderProps } from "next/image";
|
|
2
|
-
import {
|
|
1
|
+
import type { ImageLoaderProps } from "next/image";
|
|
2
|
+
import type { ImgixURLParams } from "imgix-url-builder";
|
|
3
|
+
import { buildURL } from "imgix-url-builder";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A `next/image` loader for Imgix, which Prismic uses, with an optional
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,9 @@ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
|
15
15
|
export { PrismicNextImage } from "./PrismicNextImage";
|
|
16
16
|
export type { PrismicNextImageProps } from "./PrismicNextImage";
|
|
17
17
|
|
|
18
|
+
export { PrismicNextRichText } from "./PrismicNextRichText";
|
|
19
|
+
export type { PrismicNextRichTextProps } from "./PrismicNextRichText";
|
|
20
|
+
|
|
18
21
|
export { imgixLoader } from "./imgixLoader";
|
|
19
22
|
|
|
20
23
|
export type { CreateClientConfig } from "./types";
|
package/src/lib/devMsg.ts
CHANGED
|
@@ -15,6 +15,6 @@ import { version } from "../../package.json";
|
|
|
15
15
|
*
|
|
16
16
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
17
|
*/
|
|
18
|
-
export const devMsg = (slug: string) => {
|
|
18
|
+
export const devMsg = (slug: string): string => {
|
|
19
19
|
return `https://prismic.dev/msg/next/v${version}/${slug}`;
|
|
20
20
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a module's default export. The module may provide its default export
|
|
3
|
+
* as a `default` property on an object. This happens when named and default
|
|
4
|
+
* exports are mixed in modules.
|
|
5
|
+
*
|
|
6
|
+
* In ES Modules, mixing is fine since the module resolver can distinguish
|
|
7
|
+
* default and named exports. In transpiled modules, however, all exports are
|
|
8
|
+
* put into a single object, and the default export is provided at a property
|
|
9
|
+
* called `default`.
|
|
10
|
+
*
|
|
11
|
+
* This helper is needed by Next.js uses CJS files with named and default
|
|
12
|
+
* exports.
|
|
13
|
+
*
|
|
14
|
+
* This helper _should_ be a temporary hack until Next.js and Node.js resolve
|
|
15
|
+
* their ESM difficulties. This will likely not be removed any time soon,
|
|
16
|
+
* unfortunately.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveDefaultExport<T>(mod: T): T {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return "default" in (mod as any) ? (mod as any).default : mod;
|
|
21
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
import { type ReactNode, useEffect } from "react";
|
|
2
3
|
import { useRouter } from "next/router";
|
|
3
4
|
import Script from "next/script";
|
|
4
5
|
import { getToolbarSrc, cookie as prismicCookie } from "@prismicio/client";
|
package/src/pages/index.ts
CHANGED
|
@@ -4,6 +4,9 @@ export { type PrismicNextLinkProps } from "../PrismicNextLink";
|
|
|
4
4
|
export { PrismicNextImage } from "../PrismicNextImage";
|
|
5
5
|
export { type PrismicNextImageProps } from "../PrismicNextImage";
|
|
6
6
|
|
|
7
|
+
export { PrismicNextRichText } from "../PrismicNextRichText";
|
|
8
|
+
export { type PrismicNextRichTextProps } from "../PrismicNextRichText";
|
|
9
|
+
|
|
7
10
|
export { imgixLoader } from "../imgixLoader";
|
|
8
11
|
|
|
9
12
|
export { PrismicPreview } from "./PrismicPreview";
|
package/src/pages/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
1
2
|
import type { ClientConfig } from "@prismicio/client";
|
|
2
3
|
|
|
3
|
-
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Configuration for creating a Prismic client with automatic preview support in
|
|
7
6
|
* Next.js apps.
|
|
@@ -30,7 +29,7 @@ export type NextApiResponseLike = {
|
|
|
30
29
|
redirect(url: string): NextApiResponseLike;
|
|
31
30
|
clearPreviewData(): NextApiResponseLike;
|
|
32
31
|
setHeader(name: string, value: string | string[]): NextApiResponseLike;
|
|
33
|
-
//
|
|
32
|
+
// oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
|
|
34
33
|
json(body: any): void;
|
|
35
34
|
setPreviewData(data: object | string): NextApiResponseLike;
|
|
36
35
|
};
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type LinkResolverFunction,
|
|
6
6
|
} from "@prismicio/client";
|
|
7
7
|
|
|
8
|
-
import { NextRequestLike } from "./types";
|
|
8
|
+
import type { NextRequestLike } from "./types";
|
|
9
9
|
|
|
10
10
|
export type RedirectToPreviewURLConfig = {
|
|
11
11
|
/** The Prismic client configured for the preview session's repository. */
|