@prismicio/next 1.1.0-alpha.0 → 1.1.0-alpha.2
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 +2 -19
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.js +2 -2
- package/dist/PrismicNextLink.cjs +3 -4
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.ts +16 -16
- package/dist/PrismicNextLink.js +3 -3
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.cjs +5 -74
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.ts +8 -11
- package/dist/PrismicPreview.js +5 -57
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +85 -0
- package/dist/PrismicPreviewClient.cjs.map +1 -0
- package/dist/PrismicPreviewClient.d.ts +4 -0
- package/dist/PrismicPreviewClient.js +85 -0
- package/dist/PrismicPreviewClient.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js +5 -0
- package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +19 -0
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +13 -0
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +38 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +38 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +28 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +28 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +26 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +14 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +14 -0
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +7 -0
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +9 -0
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +1 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +10 -0
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +1 -0
- package/dist/enableAutoPreviews.cjs +12 -6
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.ts +11 -12
- package/dist/enableAutoPreviews.js +12 -6
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +1 -1
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.ts +11 -16
- package/dist/exitPreview.js +1 -1
- package/dist/exitPreview.js.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.cjs +4 -21
- package/dist/lib/getPrismicPreviewCookie.cjs.map +1 -1
- package/dist/lib/getPrismicPreviewCookie.js +2 -2
- package/dist/lib/getPrismicPreviewCookie.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/redirectToPreviewURL.cjs +13 -12
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.ts +23 -21
- package/dist/redirectToPreviewURL.js +13 -12
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/setPreviewData.cjs +2 -19
- package/dist/setPreviewData.cjs.map +1 -1
- package/dist/setPreviewData.d.ts +9 -14
- package/dist/setPreviewData.js +2 -2
- package/dist/setPreviewData.js.map +1 -1
- package/dist/types.d.ts +52 -9
- package/package.json +5 -11
- package/src/PrismicNextLink.tsx +10 -10
- package/src/PrismicPreview.tsx +13 -131
- package/src/PrismicPreviewClient.tsx +159 -0
- package/src/enableAutoPreviews.ts +56 -45
- package/src/exitPreview.ts +14 -26
- package/src/redirectToPreviewURL.ts +58 -64
- package/src/setPreviewData.ts +10 -14
- package/src/types.ts +58 -9
- package/dist/react-server/PrismicPreview.d.ts +0 -22
- package/dist/react-server/index.d.ts +0 -2
- package/dist/react-server/unsupported.cjs +0 -26
- package/dist/react-server/unsupported.cjs.map +0 -1
- package/dist/react-server/unsupported.d.ts +0 -6
- package/dist/react-server/unsupported.js +0 -26
- package/dist/react-server/unsupported.js.map +0 -1
- package/dist/react-server.cjs +0 -15
- package/dist/react-server.cjs.map +0 -1
- package/dist/react-server.js +0 -15
- package/dist/react-server.js.map +0 -1
- package/src/react-server/PrismicPreview.tsx +0 -74
- package/src/react-server/index.ts +0 -11
- package/src/react-server/unsupported.ts +0 -26
|
@@ -1,23 +1,8 @@
|
|
|
1
1
|
import { PreviewData } from "next";
|
|
2
|
-
import
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import * as prismic from "@prismicio/client";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
ref: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Determines if a Next.js preview data object contains Prismic preview data.
|
|
10
|
-
*
|
|
11
|
-
* @param previewData - The Next.js preview data object to check.
|
|
12
|
-
*
|
|
13
|
-
* @returns `true` if `previewData` contains Prismic preview data, `false`
|
|
14
|
-
* otherwise.
|
|
15
|
-
*/
|
|
16
|
-
const isPrismicNextPreviewData = (
|
|
17
|
-
previewData: PreviewData,
|
|
18
|
-
): previewData is PrismicNextPreviewData => {
|
|
19
|
-
return typeof previewData === "object" && "ref" in previewData;
|
|
20
|
-
};
|
|
5
|
+
import { NextApiRequestLike } from "./types";
|
|
21
6
|
|
|
22
7
|
/**
|
|
23
8
|
* Configuration for `enableAutoPreviews`.
|
|
@@ -37,27 +22,25 @@ export type EnableAutoPreviewsConfig<
|
|
|
37
22
|
prismic.Client,
|
|
38
23
|
"queryContentFromRef" | "enableAutoPreviewsFromReq"
|
|
39
24
|
>;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* **Only used in the Pages Directory (/pages).**
|
|
28
|
+
*
|
|
29
|
+
* The `previewData` object provided in the `getStaticProps()` or
|
|
30
|
+
* `getServerSideProps()` context object.
|
|
31
|
+
*/
|
|
32
|
+
previewData?: TPreviewData;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* **Only used in the Pages Directory (/pages).**
|
|
36
|
+
*
|
|
37
|
+
* The `req` object from a Next.js API route.
|
|
38
|
+
*
|
|
39
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
40
|
+
*/
|
|
41
|
+
req?: NextApiRequestLike;
|
|
42
|
+
};
|
|
43
|
+
|
|
61
44
|
/**
|
|
62
45
|
* Configures a Prismic client to automatically query draft content during a
|
|
63
46
|
* preview session. It either takes in a Next.js `getStaticProps` context object
|
|
@@ -69,16 +52,44 @@ export const enableAutoPreviews = <TPreviewData extends PreviewData>(
|
|
|
69
52
|
config: EnableAutoPreviewsConfig<TPreviewData>,
|
|
70
53
|
): void => {
|
|
71
54
|
if ("previewData" in config && config.previewData) {
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
const { previewData } = config;
|
|
55
|
+
// Assume we are in `getStaticProps()` or `getServerSideProps()` (`pages` directory).
|
|
75
56
|
|
|
76
|
-
if (
|
|
77
|
-
config.
|
|
57
|
+
if (
|
|
58
|
+
typeof config.previewData === "object" &&
|
|
59
|
+
"ref" in config.previewData &&
|
|
60
|
+
typeof config.previewData.ref === "string"
|
|
61
|
+
) {
|
|
62
|
+
config.client.queryContentFromRef(config.previewData.ref);
|
|
78
63
|
}
|
|
79
64
|
} else if ("req" in config && config.req) {
|
|
80
|
-
//
|
|
65
|
+
// Assume we are in an API Route (`pages` directory).
|
|
81
66
|
|
|
82
67
|
config.client.enableAutoPreviewsFromReq(config.req);
|
|
68
|
+
} else {
|
|
69
|
+
// Assume we are in App Router (`app` directory).
|
|
70
|
+
|
|
71
|
+
// We use a function value so the cookie is checked on every
|
|
72
|
+
// request. We don't have a static value to read from.
|
|
73
|
+
config.client.queryContentFromRef(() => {
|
|
74
|
+
const cookie = cookies().get(prismic.cookie.preview)?.value;
|
|
75
|
+
|
|
76
|
+
// We only return the cookie if a Prismic Preview session is active.
|
|
77
|
+
//
|
|
78
|
+
// An inactive cookie looks like this (URL encoded):
|
|
79
|
+
// {
|
|
80
|
+
// "_tracker": "abc123"
|
|
81
|
+
// }
|
|
82
|
+
//
|
|
83
|
+
// An active cookie looks like this (URL encoded):
|
|
84
|
+
// {
|
|
85
|
+
// "_tracker": "abc123",
|
|
86
|
+
// "example-prismic-repo.prismic.io": {
|
|
87
|
+
// preview: "https://example-prismic-repo.prismic.io/previews/abc:123?websitePreviewId=xyz"
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
if (cookie && /\.prismic\.io/.test(cookie)) {
|
|
91
|
+
return cookie;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
83
94
|
}
|
|
84
95
|
};
|
package/src/exitPreview.ts
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
|
|
3
|
+
import { NextApiRequestLike, NextApiResponseLike } from "./types";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Configuration for `exitPreview`.
|
|
5
7
|
*/
|
|
6
8
|
export type ExitPreviewConfig = {
|
|
7
9
|
/**
|
|
8
|
-
* The `req` object from a Next.js API route.
|
|
9
|
-
* the API route.
|
|
10
|
+
* The `req` object from a Next.js API route.
|
|
10
11
|
*
|
|
11
|
-
* @see Next.js API route docs:
|
|
12
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
// redirect the user to the referring URL, but it no longer has that
|
|
15
|
-
// behavior.
|
|
16
|
-
//
|
|
17
|
-
// `req` is retained as a parameter to make setting up an exit preview
|
|
18
|
-
// API route easier (this eliminates the awkward need to handle an
|
|
19
|
-
// unused `req` param).
|
|
20
|
-
//
|
|
21
|
-
// It is also retained in case it is needed in the future, such as
|
|
22
|
-
// reading headers or metadata about the request.
|
|
23
|
-
req: {
|
|
24
|
-
headers: NextApiRequest["headers"];
|
|
25
|
-
};
|
|
14
|
+
req: NextApiRequestLike;
|
|
26
15
|
|
|
27
16
|
/**
|
|
28
|
-
* The `res` object from a Next.js API route.
|
|
29
|
-
* the API route.
|
|
17
|
+
* The `res` object from a Next.js API route.
|
|
30
18
|
*
|
|
31
|
-
* @see Next.js API route docs:
|
|
19
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
32
20
|
*/
|
|
33
|
-
res:
|
|
34
|
-
clearPreviewData: NextApiResponse["clearPreviewData"];
|
|
35
|
-
status: NextApiResponse["status"];
|
|
36
|
-
json: NextApiResponse["json"];
|
|
37
|
-
};
|
|
21
|
+
res: NextApiResponseLike;
|
|
38
22
|
};
|
|
39
23
|
|
|
40
24
|
/**
|
|
25
|
+
* **Only use this function in the Pages Directory (/pages).**
|
|
26
|
+
*
|
|
41
27
|
* Exits Next.js's Preview Mode from within a Next.js API route.
|
|
42
28
|
*/
|
|
43
|
-
export function exitPreview(
|
|
29
|
+
export async function exitPreview(
|
|
30
|
+
config: ExitPreviewConfig,
|
|
31
|
+
): Promise<NextResponse | void> {
|
|
44
32
|
// Exit the current user from Preview Mode.
|
|
45
33
|
config.res.clearPreviewData();
|
|
46
34
|
|
|
@@ -1,68 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { redirect } from "next/navigation";
|
|
2
2
|
import type * as prismic from "@prismicio/client";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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<
|
|
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?:
|
|
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`
|
|
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
|
|
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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
}
|
package/src/setPreviewData.ts
CHANGED
|
@@ -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.
|
|
10
|
-
* the API route.
|
|
10
|
+
* The `req` object from a Next.js API route.
|
|
11
11
|
*
|
|
12
|
-
* @see Next.js API route docs:
|
|
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.
|
|
21
|
-
* the API route.
|
|
17
|
+
* The `res` object from a Next.js API route.
|
|
22
18
|
*
|
|
23
|
-
* @see Next.js API route docs:
|
|
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
|
|
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
|
-
*
|
|
11
|
-
* from `getStaticProps` or `getServerSideProps`.
|
|
17
|
+
* **Only used in the Pages Directory (/pages).**
|
|
12
18
|
*
|
|
13
|
-
*
|
|
19
|
+
* The `previewData` object provided in the `getStaticProps()` or
|
|
20
|
+
* `getServerSideProps()` context object.
|
|
14
21
|
*/
|
|
15
22
|
previewData?: PreviewData;
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
|
-
*
|
|
25
|
+
* **Only used in the Pages Directory (/pages).**
|
|
26
|
+
*
|
|
27
|
+
* The `req` object from a Next.js API route.
|
|
19
28
|
*
|
|
20
|
-
*
|
|
29
|
+
* @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
|
|
21
30
|
*/
|
|
22
|
-
req?:
|
|
23
|
-
}
|
|
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,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function buildErrorMessage(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(buildErrorMessage("<PrismicPreview>"));
|
|
8
|
-
}
|
|
9
|
-
function enableAutoPreviews() {
|
|
10
|
-
throw new Error(buildErrorMessage("enableAutoPreviews()"));
|
|
11
|
-
}
|
|
12
|
-
function exitPreview() {
|
|
13
|
-
throw new Error(buildErrorMessage("exitPreview()"));
|
|
14
|
-
}
|
|
15
|
-
function redirectToPreviewURL() {
|
|
16
|
-
throw new Error(buildErrorMessage("redirectToPreviewURL()"));
|
|
17
|
-
}
|
|
18
|
-
function setPreviewData() {
|
|
19
|
-
throw new Error(buildErrorMessage("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 buildErrorMessage(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(buildErrorMessage(\"<PrismicPreview>\"));\n}\n\nexport function enableAutoPreviews() {\n\tthrow new Error(buildErrorMessage(\"enableAutoPreviews()\"));\n}\n\nexport function exitPreview() {\n\tthrow new Error(buildErrorMessage(\"exitPreview()\"));\n}\n\nexport function redirectToPreviewURL() {\n\tthrow new Error(buildErrorMessage(\"redirectToPreviewURL()\"));\n}\n\nexport function setPreviewData() {\n\tthrow new Error(buildErrorMessage(\"setPreviewData()\"));\n}\n"],"names":[],"mappings":";;AAGA,SAAS,kBAAkB,QAAc;AACxC,SAAO,GAAG,yIAAyI;AACpJ;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kBAAkB,kBAAkB,CAAC;AACtD;SAEgB,qBAAkB;AACjC,QAAM,IAAI,MAAM,kBAAkB,sBAAsB,CAAC;AAC1D;SAEgB,cAAW;AAC1B,QAAM,IAAI,MAAM,kBAAkB,eAAe,CAAC;AACnD;SAEgB,uBAAoB;AACnC,QAAM,IAAI,MAAM,kBAAkB,wBAAwB,CAAC;AAC5D;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kBAAkB,kBAAkB,CAAC;AACtD;;;;;;"}
|
|
@@ -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 buildErrorMessage(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(buildErrorMessage("<PrismicPreview>"));
|
|
6
|
-
}
|
|
7
|
-
function enableAutoPreviews() {
|
|
8
|
-
throw new Error(buildErrorMessage("enableAutoPreviews()"));
|
|
9
|
-
}
|
|
10
|
-
function exitPreview() {
|
|
11
|
-
throw new Error(buildErrorMessage("exitPreview()"));
|
|
12
|
-
}
|
|
13
|
-
function redirectToPreviewURL() {
|
|
14
|
-
throw new Error(buildErrorMessage("redirectToPreviewURL()"));
|
|
15
|
-
}
|
|
16
|
-
function setPreviewData() {
|
|
17
|
-
throw new Error(buildErrorMessage("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 buildErrorMessage(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(buildErrorMessage(\"<PrismicPreview>\"));\n}\n\nexport function enableAutoPreviews() {\n\tthrow new Error(buildErrorMessage(\"enableAutoPreviews()\"));\n}\n\nexport function exitPreview() {\n\tthrow new Error(buildErrorMessage(\"exitPreview()\"));\n}\n\nexport function redirectToPreviewURL() {\n\tthrow new Error(buildErrorMessage(\"redirectToPreviewURL()\"));\n}\n\nexport function setPreviewData() {\n\tthrow new Error(buildErrorMessage(\"setPreviewData()\"));\n}\n"],"names":[],"mappings":"AAGA,SAAS,kBAAkB,QAAc;AACxC,SAAO,GAAG,yIAAyI;AACpJ;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kBAAkB,kBAAkB,CAAC;AACtD;SAEgB,qBAAkB;AACjC,QAAM,IAAI,MAAM,kBAAkB,sBAAsB,CAAC;AAC1D;SAEgB,cAAW;AAC1B,QAAM,IAAI,MAAM,kBAAkB,eAAe,CAAC;AACnD;SAEgB,uBAAoB;AACnC,QAAM,IAAI,MAAM,kBAAkB,wBAAwB,CAAC;AAC5D;SAEgB,iBAAc;AAC7B,QAAM,IAAI,MAAM,kBAAkB,kBAAkB,CAAC;AACtD;"}
|
package/dist/react-server.cjs
DELETED
|
@@ -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":";;;;;;;;;;;;;;"}
|
package/dist/react-server.js
DELETED
|
@@ -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
|
package/dist/react-server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-server.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|