@prismicio/next 1.1.0-alpha.1 → 1.1.0

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.
Files changed (66) hide show
  1. package/dist/PrismicNextLink.d.ts +3 -3
  2. package/dist/PrismicPreview.cjs +5 -74
  3. package/dist/PrismicPreview.cjs.map +1 -1
  4. package/dist/PrismicPreview.d.ts +8 -11
  5. package/dist/PrismicPreview.js +5 -57
  6. package/dist/PrismicPreview.js.map +1 -1
  7. package/dist/PrismicPreviewClient.cjs +85 -0
  8. package/dist/PrismicPreviewClient.cjs.map +1 -0
  9. package/dist/PrismicPreviewClient.d.ts +4 -0
  10. package/dist/PrismicPreviewClient.js +85 -0
  11. package/dist/PrismicPreviewClient.js.map +1 -0
  12. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +19 -0
  13. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -0
  14. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +19 -0
  15. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -0
  16. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +13 -0
  17. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +1 -0
  18. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +13 -0
  19. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +1 -0
  20. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +7 -0
  21. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +1 -0
  22. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +7 -0
  23. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +1 -0
  24. package/dist/enableAutoPreviews.cjs +17 -6
  25. package/dist/enableAutoPreviews.cjs.map +1 -1
  26. package/dist/enableAutoPreviews.d.ts +11 -12
  27. package/dist/enableAutoPreviews.js +17 -6
  28. package/dist/enableAutoPreviews.js.map +1 -1
  29. package/dist/exitPreview.cjs +1 -1
  30. package/dist/exitPreview.cjs.map +1 -1
  31. package/dist/exitPreview.d.ts +11 -16
  32. package/dist/exitPreview.js +1 -1
  33. package/dist/exitPreview.js.map +1 -1
  34. package/dist/package.json.cjs +1 -1
  35. package/dist/package.json.js +1 -1
  36. package/dist/redirectToPreviewURL.cjs +13 -12
  37. package/dist/redirectToPreviewURL.cjs.map +1 -1
  38. package/dist/redirectToPreviewURL.d.ts +23 -21
  39. package/dist/redirectToPreviewURL.js +13 -12
  40. package/dist/redirectToPreviewURL.js.map +1 -1
  41. package/dist/setPreviewData.cjs.map +1 -1
  42. package/dist/setPreviewData.d.ts +9 -14
  43. package/dist/setPreviewData.js.map +1 -1
  44. package/dist/types.d.ts +52 -9
  45. package/package.json +5 -10
  46. package/src/PrismicPreview.tsx +13 -131
  47. package/src/PrismicPreviewClient.tsx +159 -0
  48. package/src/enableAutoPreviews.ts +73 -45
  49. package/src/exitPreview.ts +14 -26
  50. package/src/redirectToPreviewURL.ts +58 -64
  51. package/src/setPreviewData.ts +10 -14
  52. package/src/types.ts +58 -9
  53. package/dist/react-server/PrismicPreview.d.ts +0 -22
  54. package/dist/react-server/index.d.ts +0 -2
  55. package/dist/react-server/unsupported.cjs +0 -26
  56. package/dist/react-server/unsupported.cjs.map +0 -1
  57. package/dist/react-server/unsupported.d.ts +0 -6
  58. package/dist/react-server/unsupported.js +0 -26
  59. package/dist/react-server/unsupported.js.map +0 -1
  60. package/dist/react-server.cjs +0 -15
  61. package/dist/react-server.cjs.map +0 -1
  62. package/dist/react-server.js +0 -15
  63. package/dist/react-server.js.map +0 -1
  64. package/src/react-server/PrismicPreview.tsx +0 -74
  65. package/src/react-server/index.ts +0 -11
  66. package/src/react-server/unsupported.ts +0 -26
@@ -1,68 +1,57 @@
1
- import type { NextApiRequest, NextApiResponse } from "next";
1
+ import { redirect } from "next/navigation";
2
2
  import type * as prismic from "@prismicio/client";
3
3
 
4
- type PrismicNextQuery = {
5
- documentId: string;
6
- token: string;
7
- };
8
-
9
- /**
10
- * Determines if a query object from a Next.js API route request contains
11
- * Prismic preview data.
12
- *
13
- * @param query - Query object to check.
14
- *
15
- * @returns `true` if `query` contains Prismic preview data, `false` otherwise.
16
- */
17
- const isPrismicNextQuery = (
18
- query: NextApiRequest["query"],
19
- ): query is PrismicNextQuery => {
20
- return (
21
- typeof query.documentId === "string" && typeof query.token === "string"
22
- );
23
- };
4
+ import {
5
+ NextApiRequestLike,
6
+ NextApiResponseLike,
7
+ NextRequestLike,
8
+ } from "./types";
24
9
 
25
10
  /**
26
11
  * Preview config for enabling previews with redirectToPreviewURL
27
12
  */
28
- export type RedirectToPreviewURLConfig<
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- TLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,
31
- > = {
32
- /**
33
- * The `req` object from a Next.js API route. This is given as a parameter to
34
- * the API route.
35
- *
36
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
37
- */
38
- req: {
39
- query: NextApiRequest["query"];
40
- };
41
-
42
- /**
43
- * The `res` object from a Next.js API route. This is given as a parameter to
44
- * the API route.
45
- *
46
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
47
- */
48
- res: {
49
- redirect: NextApiResponse["redirect"];
50
- };
13
+ export type RedirectToPreviewURLConfig = (
14
+ | {
15
+ /**
16
+ * The `request` object from a Next.js Route Handler.
17
+ *
18
+ * @see Next.js Route Handler docs: \<https://beta.nextjs.org/docs/routing/route-handlers\>
19
+ */
20
+ request: NextRequestLike;
21
+ }
22
+ | {
23
+ /**
24
+ * The `req` object from a Next.js API route.
25
+ *
26
+ * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
27
+ */
28
+ req: NextApiRequestLike;
51
29
 
30
+ /**
31
+ * The `res` object from a Next.js API route.
32
+ *
33
+ * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
34
+ */
35
+ res: NextApiResponseLike;
36
+ }
37
+ ) & {
52
38
  /**
53
39
  * The Prismic client configured for the preview session's repository.
54
40
  */
55
41
  // `Pick` is used to use the smallest possible subset of
56
42
  // `prismic.Client`. Doing this reduces the surface area for breaking
57
43
  // type changes.
58
- client: Pick<prismic.Client, "resolvePreviewURL">;
44
+ client: Pick<
45
+ prismic.Client,
46
+ "enableAutoPreviewsFromReq" | "resolvePreviewURL"
47
+ >;
59
48
 
60
49
  /**
61
50
  * A Link Resolver used to resolve the previewed document's URL.
62
51
  *
63
52
  * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
64
53
  */
65
- linkResolver?: TLinkResolverFunction;
54
+ linkResolver?: prismic.LinkResolverFunction;
66
55
 
67
56
  /**
68
57
  * The default redirect URL if a URL cannot be determined for the previewed
@@ -79,35 +68,40 @@ export type RedirectToPreviewURLConfig<
79
68
  * This option can be omitted if the app does not have a `basePath`.
80
69
  *
81
70
  * @remarks
82
- * The API route is unable to detect the app's `basePath` automatically. It
83
- * must be provided to `redirectToPreviewURL()` manually.
71
+ * The Router Handler or API route is unable to detect the app's `basePath`
72
+ * automatically. It must be provided to `redirectToPreviewURL()` manually.
84
73
  */
85
74
  basePath?: string;
86
75
  };
87
76
 
88
77
  /**
89
- * Redirects a user to the URL of a previewed Prismic document from within a
90
- * Next.js API route.
78
+ * Redirects a visitor to the URL of a previewed Prismic document from within a
79
+ * Next.js Route Handler or API route.
91
80
  */
92
- export async function redirectToPreviewURL<
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- TLinkResolverFunction extends prismic.LinkResolverFunction<any>,
95
- >(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {
96
- const defaultURL = config.defaultURL || "/";
81
+ export async function redirectToPreviewURL(
82
+ config: RedirectToPreviewURLConfig,
83
+ ): Promise<void> {
97
84
  const basePath = config.basePath || "";
85
+ const request = "request" in config ? config.request : config.req;
98
86
 
99
- if (isPrismicNextQuery(config.req.query)) {
100
- const previewUrl = await config.client.resolvePreviewURL({
101
- linkResolver: config.linkResolver,
102
- defaultURL,
103
- documentID: config.req.query.documentId,
104
- previewToken: config.req.query.token,
105
- });
87
+ config.client.enableAutoPreviewsFromReq(request);
88
+
89
+ const previewUrl = await config.client.resolvePreviewURL({
90
+ linkResolver: config.linkResolver,
91
+ defaultURL: config.defaultURL || "/",
92
+ });
93
+
94
+ if ("nextUrl" in request) {
95
+ redirect(basePath + previewUrl);
96
+ } else {
97
+ if (!("res" in config)) {
98
+ throw new Error(
99
+ "[redirectToPreviewURL] The `res` object from the API route must be provided to `redirectToPreviewURL()`.",
100
+ );
101
+ }
106
102
 
107
103
  config.res.redirect(basePath + previewUrl);
108
104
 
109
105
  return;
110
106
  }
111
-
112
- config.res.redirect(basePath + defaultURL);
113
107
  }
@@ -1,33 +1,29 @@
1
- import { NextApiResponse, NextApiRequest } from "next";
2
1
  import * as prismic from "@prismicio/client";
3
2
 
3
+ import { NextApiRequestLike, NextApiResponseLike } from "./types";
4
+
4
5
  /**
5
6
  * Configuration for `setPreviewData`.
6
7
  */
7
8
  export type SetPreviewDataConfig = {
8
9
  /**
9
- * The `req` object from a Next.js API route. This is given as a parameter to
10
- * the API route.
10
+ * The `req` object from a Next.js API route.
11
11
  *
12
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
12
+ * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
13
13
  */
14
- req: {
15
- query: NextApiRequest["query"];
16
- cookies: NextApiRequest["cookies"];
17
- };
14
+ req: NextApiRequestLike;
18
15
 
19
16
  /**
20
- * The `res` object from a Next.js API route. This is given as a parameter to
21
- * the API route.
17
+ * The `res` object from a Next.js API route.
22
18
  *
23
- * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
19
+ * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
24
20
  */
25
- res: {
26
- setPreviewData: NextApiResponse["setPreviewData"];
27
- };
21
+ res: NextApiResponseLike;
28
22
  };
29
23
 
30
24
  /**
25
+ * **Only use this function in the Pages Directory (/pages).**
26
+ *
31
27
  * Set Prismic preview data for Next.js's Preview Mode.
32
28
  */
33
29
  export function setPreviewData({ req, res }: SetPreviewDataConfig): void {
package/src/types.ts CHANGED
@@ -1,23 +1,72 @@
1
- import type { PreviewData, NextApiRequest } from "next";
1
+ import type { PreviewData } from "next";
2
2
  import type { ClientConfig } from "@prismicio/client";
3
3
 
4
+ // Add Next.js-specific fetchOptions to `@prismicio/client`.
5
+ declare module "@prismicio/client" {
6
+ interface RequestInitLike {
7
+ next?: RequestInit["next"];
8
+ }
9
+ }
10
+
4
11
  /**
5
12
  * Configuration for creating a Prismic client with automatic preview support in
6
13
  * Next.js apps.
7
14
  */
8
- export type CreateClientConfig = {
15
+ export type CreateClientConfig = ClientConfig & {
9
16
  /**
10
- * Preview data coming from Next.js context object. This context object comes
11
- * from `getStaticProps` or `getServerSideProps`.
17
+ * **Only used in the Pages Directory (/pages).**
12
18
  *
13
- * Pass `previewData` when using outside a Next.js API endpoint.
19
+ * The `previewData` object provided in the `getStaticProps()` or
20
+ * `getServerSideProps()` context object.
14
21
  */
15
22
  previewData?: PreviewData;
16
23
 
17
24
  /**
18
- * A Next.js API endpoint request object.
25
+ * **Only used in the Pages Directory (/pages).**
26
+ *
27
+ * The `req` object from a Next.js API route.
19
28
  *
20
- * Pass a `req` object when using in a Next.js API endpoint.
29
+ * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
21
30
  */
22
- req?: NextApiRequest;
23
- } & ClientConfig;
31
+ req?: NextApiRequestLike;
32
+ };
33
+
34
+ /**
35
+ * The minimal set of properties needed from `next`'s `NextRequest` type.
36
+ *
37
+ * This request type is only compatible with Route Handlers defined in the `app`
38
+ * directory.
39
+ */
40
+ export type NextRequestLike = {
41
+ headers: {
42
+ get(name: string): string | null;
43
+ };
44
+ url: string;
45
+ nextUrl: unknown;
46
+ };
47
+
48
+ /**
49
+ * The minimal set of properties needed from `next`'s `NextApiRequest` type.
50
+ *
51
+ * This request type is only compatible with API routes defined in the `pages`
52
+ * directory.
53
+ */
54
+ export type NextApiRequestLike = {
55
+ query: Partial<Record<string, string | string[]>>;
56
+ cookies: Partial<Record<string, string>>;
57
+ };
58
+
59
+ /**
60
+ * The minimal set of properties needed from `next`'s `NextApiResponse` type.
61
+ *
62
+ * This request type is only compatible with API routes defined in the `pages`
63
+ * directory.
64
+ */
65
+ export type NextApiResponseLike = {
66
+ redirect(url: string): NextApiResponseLike;
67
+ clearPreviewData(): NextApiResponseLike;
68
+ status(statusCode: number): NextApiResponseLike;
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
+ json(body: any): void;
71
+ setPreviewData(data: object | string): NextApiResponseLike;
72
+ };
@@ -1,22 +0,0 @@
1
- import * as React from "react";
2
- /**
3
- * Props for `<PrismicPreview>`.
4
- */
5
- export type PrismicPreviewProps = {
6
- /**
7
- * The name of your Prismic repository. A Prismic Toolbar will be registered
8
- * using this repository.
9
- */
10
- repositoryName: string;
11
- children?: React.ReactNode;
12
- };
13
- /**
14
- * React component that sets up Prismic Previews using the Prismic Toolbar. When
15
- * the Prismic Toolbar send events to the browser, such as on preview updates
16
- * and exiting, this component will automatically update Next.js Preview Mode
17
- * and refresh the page.
18
- *
19
- * This component can be wrapped around your app or added anywhere in your app's
20
- * tree. It must be rendered on every page.
21
- */
22
- export declare function PrismicPreview({ repositoryName, children, }: PrismicPreviewProps): JSX.Element;
@@ -1,2 +0,0 @@
1
- export { PrismicPreview, enableAutoPreviews, redirectToPreviewURL, exitPreview, setPreviewData, } from "./unsupported";
2
- export { PrismicNextImage, imgixLoader, PrismicNextLink } from "..";
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- function buildIncompatiblePreviewModeError(fnName) {
4
- 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}.`;
5
- }
6
- function PrismicPreview() {
7
- throw new Error(buildIncompatiblePreviewModeError("<PrismicPreview>"));
8
- }
9
- function enableAutoPreviews() {
10
- throw new Error(buildIncompatiblePreviewModeError("enableAutoPreviews()"));
11
- }
12
- function exitPreview() {
13
- throw new Error(buildIncompatiblePreviewModeError("exitPreview()"));
14
- }
15
- function redirectToPreviewURL() {
16
- throw new Error(buildIncompatiblePreviewModeError("redirectToPreviewURL()"));
17
- }
18
- function setPreviewData() {
19
- throw new Error(buildIncompatiblePreviewModeError("setPreviewData()"));
20
- }
21
- exports.PrismicPreview = PrismicPreview;
22
- exports.enableAutoPreviews = enableAutoPreviews;
23
- exports.exitPreview = exitPreview;
24
- exports.redirectToPreviewURL = redirectToPreviewURL;
25
- exports.setPreviewData = setPreviewData;
26
- //# sourceMappingURL=unsupported.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unsupported.cjs","sources":["../../../src/react-server/unsupported.ts"],"sourcesContent":["// Exports in this file are unsupported in the react-server environment.\n// All environments should export the same functions to maintian API compatability.\n\nfunction buildIncompatiblePreviewModeError(fnName: string) {\n\treturn `${fnName} is currently incompatible with App Router. Preview Mode is not supported in App Router at this time. Please remove all uses of ${fnName}.`;\n}\n\nexport function PrismicPreview(): JSX.Element {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"<PrismicPreview>\"));\n}\n\nexport function enableAutoPreviews() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"enableAutoPreviews()\"));\n}\n\nexport function exitPreview() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"exitPreview()\"));\n}\n\nexport function redirectToPreviewURL() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"redirectToPreviewURL()\"));\n}\n\nexport function setPreviewData() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"setPreviewData()\"));\n}\n"],"names":[],"mappings":";;AAGA,SAAS,kCAAkC,QAAc;AACxD,SAAO,GAAG,yIAAyI;AACpJ;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kCAAkC,kBAAkB,CAAC;AACtE;SAEgB,qBAAkB;AACjC,QAAM,IAAI,MAAM,kCAAkC,sBAAsB,CAAC;AAC1E;SAEgB,cAAW;AAC1B,QAAM,IAAI,MAAM,kCAAkC,eAAe,CAAC;AACnE;SAEgB,uBAAoB;AACnC,QAAM,IAAI,MAAM,kCAAkC,wBAAwB,CAAC;AAC5E;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kCAAkC,kBAAkB,CAAC;AACtE;;;;;;"}
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function PrismicPreview(): JSX.Element;
3
- export declare function enableAutoPreviews(): void;
4
- export declare function exitPreview(): void;
5
- export declare function redirectToPreviewURL(): void;
6
- export declare function setPreviewData(): void;
@@ -1,26 +0,0 @@
1
- function buildIncompatiblePreviewModeError(fnName) {
2
- 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}.`;
3
- }
4
- function PrismicPreview() {
5
- throw new Error(buildIncompatiblePreviewModeError("<PrismicPreview>"));
6
- }
7
- function enableAutoPreviews() {
8
- throw new Error(buildIncompatiblePreviewModeError("enableAutoPreviews()"));
9
- }
10
- function exitPreview() {
11
- throw new Error(buildIncompatiblePreviewModeError("exitPreview()"));
12
- }
13
- function redirectToPreviewURL() {
14
- throw new Error(buildIncompatiblePreviewModeError("redirectToPreviewURL()"));
15
- }
16
- function setPreviewData() {
17
- throw new Error(buildIncompatiblePreviewModeError("setPreviewData()"));
18
- }
19
- export {
20
- PrismicPreview,
21
- enableAutoPreviews,
22
- exitPreview,
23
- redirectToPreviewURL,
24
- setPreviewData
25
- };
26
- //# sourceMappingURL=unsupported.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unsupported.js","sources":["../../../src/react-server/unsupported.ts"],"sourcesContent":["// Exports in this file are unsupported in the react-server environment.\n// All environments should export the same functions to maintian API compatability.\n\nfunction buildIncompatiblePreviewModeError(fnName: string) {\n\treturn `${fnName} is currently incompatible with App Router. Preview Mode is not supported in App Router at this time. Please remove all uses of ${fnName}.`;\n}\n\nexport function PrismicPreview(): JSX.Element {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"<PrismicPreview>\"));\n}\n\nexport function enableAutoPreviews() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"enableAutoPreviews()\"));\n}\n\nexport function exitPreview() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"exitPreview()\"));\n}\n\nexport function redirectToPreviewURL() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"redirectToPreviewURL()\"));\n}\n\nexport function setPreviewData() {\n\tthrow new Error(buildIncompatiblePreviewModeError(\"setPreviewData()\"));\n}\n"],"names":[],"mappings":"AAGA,SAAS,kCAAkC,QAAc;AACxD,SAAO,GAAG,yIAAyI;AACpJ;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kCAAkC,kBAAkB,CAAC;AACtE;SAEgB,qBAAkB;AACjC,QAAM,IAAI,MAAM,kCAAkC,sBAAsB,CAAC;AAC1E;SAEgB,cAAW;AAC1B,QAAM,IAAI,MAAM,kCAAkC,eAAe,CAAC;AACnE;SAEgB,uBAAoB;AACnC,QAAM,IAAI,MAAM,kCAAkC,wBAAwB,CAAC;AAC5E;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kCAAkC,kBAAkB,CAAC;AACtE;"}
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-server.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -1,74 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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 "..";
@@ -1,26 +0,0 @@
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
- }