@prismicio/next 2.2.3 → 2.2.4

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 (161) hide show
  1. package/dist/PrismicNextImage.cjs +9 -11
  2. package/dist/PrismicNextImage.cjs.map +1 -1
  3. package/dist/PrismicNextImage.d.cts +13 -21
  4. package/dist/PrismicNextImage.d.cts.map +1 -0
  5. package/dist/PrismicNextImage.d.ts +13 -21
  6. package/dist/PrismicNextImage.d.ts.map +1 -0
  7. package/dist/PrismicNextImage.js +9 -11
  8. package/dist/PrismicNextImage.js.map +1 -1
  9. package/dist/PrismicNextLink.cjs.map +1 -1
  10. package/dist/PrismicNextLink.d.cts +3 -3
  11. package/dist/PrismicNextLink.d.cts.map +1 -0
  12. package/dist/PrismicNextLink.d.ts +3 -3
  13. package/dist/PrismicNextLink.d.ts.map +1 -0
  14. package/dist/PrismicNextLink.js.map +1 -1
  15. package/dist/PrismicPreview.cjs +6 -7
  16. package/dist/PrismicPreview.cjs.map +1 -1
  17. package/dist/PrismicPreview.d.cts +11 -12
  18. package/dist/PrismicPreview.d.cts.map +1 -0
  19. package/dist/PrismicPreview.d.ts +11 -12
  20. package/dist/PrismicPreview.d.ts.map +1 -0
  21. package/dist/PrismicPreview.js +6 -7
  22. package/dist/PrismicPreview.js.map +1 -1
  23. package/dist/PrismicPreviewClient.cjs +1 -3
  24. package/dist/PrismicPreviewClient.cjs.map +1 -1
  25. package/dist/PrismicPreviewClient.js +1 -3
  26. package/dist/PrismicPreviewClient.js.map +1 -1
  27. package/dist/SliceSimulator.cjs +3 -3
  28. package/dist/SliceSimulator.cjs.map +1 -1
  29. package/dist/SliceSimulator.d.cts +3 -5
  30. package/dist/SliceSimulator.d.cts.map +1 -0
  31. package/dist/SliceSimulator.d.ts +3 -5
  32. package/dist/SliceSimulator.d.ts.map +1 -0
  33. package/dist/SliceSimulator.js +3 -3
  34. package/dist/SliceSimulator.js.map +1 -1
  35. package/dist/SliceSimulatorWrapper.cjs +1 -4
  36. package/dist/SliceSimulatorWrapper.cjs.map +1 -1
  37. package/dist/SliceSimulatorWrapper.js +1 -4
  38. package/dist/SliceSimulatorWrapper.js.map +1 -1
  39. package/dist/createLocaleRedirect.cjs.map +1 -1
  40. package/dist/createLocaleRedirect.d.cts.map +1 -0
  41. package/dist/createLocaleRedirect.d.ts.map +1 -0
  42. package/dist/createLocaleRedirect.js.map +1 -1
  43. package/dist/enableAutoPreviews.cjs +1 -2
  44. package/dist/enableAutoPreviews.cjs.map +1 -1
  45. package/dist/enableAutoPreviews.d.cts +1 -2
  46. package/dist/enableAutoPreviews.d.cts.map +1 -0
  47. package/dist/enableAutoPreviews.d.ts +1 -2
  48. package/dist/enableAutoPreviews.d.ts.map +1 -0
  49. package/dist/enableAutoPreviews.js +1 -2
  50. package/dist/enableAutoPreviews.js.map +1 -1
  51. package/dist/exitPreview.cjs +9 -10
  52. package/dist/exitPreview.cjs.map +1 -1
  53. package/dist/exitPreview.d.cts +9 -10
  54. package/dist/exitPreview.d.cts.map +1 -0
  55. package/dist/exitPreview.d.ts +9 -10
  56. package/dist/exitPreview.d.ts.map +1 -0
  57. package/dist/exitPreview.js +9 -10
  58. package/dist/exitPreview.js.map +1 -1
  59. package/dist/getSlices.cjs.map +1 -1
  60. package/dist/getSlices.d.cts.map +1 -0
  61. package/dist/getSlices.d.ts.map +1 -0
  62. package/dist/getSlices.js.map +1 -1
  63. package/dist/imgixLoader.cjs +2 -2
  64. package/dist/imgixLoader.cjs.map +1 -1
  65. package/dist/imgixLoader.d.cts +2 -2
  66. package/dist/imgixLoader.d.cts.map +1 -0
  67. package/dist/imgixLoader.d.ts +2 -2
  68. package/dist/imgixLoader.d.ts.map +1 -0
  69. package/dist/imgixLoader.js +2 -2
  70. package/dist/imgixLoader.js.map +1 -1
  71. package/dist/lib/devMsg.cjs +6 -8
  72. package/dist/lib/devMsg.cjs.map +1 -1
  73. package/dist/lib/devMsg.js +6 -8
  74. package/dist/lib/devMsg.js.map +1 -1
  75. package/dist/lib/resolveDefaultExport.cjs +8 -12
  76. package/dist/lib/resolveDefaultExport.cjs.map +1 -1
  77. package/dist/lib/resolveDefaultExport.js +8 -12
  78. package/dist/lib/resolveDefaultExport.js.map +1 -1
  79. package/dist/package.cjs +1 -1
  80. package/dist/package.js +1 -1
  81. package/dist/pages/PrismicPreview.cjs +6 -7
  82. package/dist/pages/PrismicPreview.cjs.map +1 -1
  83. package/dist/pages/PrismicPreview.d.cts +11 -12
  84. package/dist/pages/PrismicPreview.d.cts.map +1 -0
  85. package/dist/pages/PrismicPreview.d.ts +11 -12
  86. package/dist/pages/PrismicPreview.d.ts.map +1 -0
  87. package/dist/pages/PrismicPreview.js +6 -7
  88. package/dist/pages/PrismicPreview.js.map +1 -1
  89. package/dist/pages/SliceSimulator.cjs +2 -2
  90. package/dist/pages/SliceSimulator.cjs.map +1 -1
  91. package/dist/pages/SliceSimulator.d.cts +10 -13
  92. package/dist/pages/SliceSimulator.d.cts.map +1 -0
  93. package/dist/pages/SliceSimulator.d.ts +10 -13
  94. package/dist/pages/SliceSimulator.d.ts.map +1 -0
  95. package/dist/pages/SliceSimulator.js +2 -2
  96. package/dist/pages/SliceSimulator.js.map +1 -1
  97. package/dist/pages/enableAutoPreviews.cjs +3 -3
  98. package/dist/pages/enableAutoPreviews.cjs.map +1 -1
  99. package/dist/pages/enableAutoPreviews.d.cts +5 -5
  100. package/dist/pages/enableAutoPreviews.d.cts.map +1 -0
  101. package/dist/pages/enableAutoPreviews.d.ts +5 -5
  102. package/dist/pages/enableAutoPreviews.d.ts.map +1 -0
  103. package/dist/pages/enableAutoPreviews.js +3 -3
  104. package/dist/pages/enableAutoPreviews.js.map +1 -1
  105. package/dist/pages/exitPreview.cjs +9 -10
  106. package/dist/pages/exitPreview.cjs.map +1 -1
  107. package/dist/pages/exitPreview.d.cts +9 -10
  108. package/dist/pages/exitPreview.d.cts.map +1 -0
  109. package/dist/pages/exitPreview.d.ts +9 -10
  110. package/dist/pages/exitPreview.d.ts.map +1 -0
  111. package/dist/pages/exitPreview.js +9 -10
  112. package/dist/pages/exitPreview.js.map +1 -1
  113. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  114. package/dist/pages/redirectToPreviewURL.d.cts +7 -9
  115. package/dist/pages/redirectToPreviewURL.d.cts.map +1 -0
  116. package/dist/pages/redirectToPreviewURL.d.ts +7 -9
  117. package/dist/pages/redirectToPreviewURL.d.ts.map +1 -0
  118. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  119. package/dist/pages/setPreviewData.cjs.map +1 -1
  120. package/dist/pages/setPreviewData.d.cts.map +1 -0
  121. package/dist/pages/setPreviewData.d.ts.map +1 -0
  122. package/dist/pages/setPreviewData.js.map +1 -1
  123. package/dist/pages/types.d.cts +3 -8
  124. package/dist/pages/types.d.cts.map +1 -0
  125. package/dist/pages/types.d.ts +3 -8
  126. package/dist/pages/types.d.ts.map +1 -0
  127. package/dist/redirectToPreviewURL.cjs.map +1 -1
  128. package/dist/redirectToPreviewURL.d.cts +3 -5
  129. package/dist/redirectToPreviewURL.d.cts.map +1 -0
  130. package/dist/redirectToPreviewURL.d.ts +3 -5
  131. package/dist/redirectToPreviewURL.d.ts.map +1 -0
  132. package/dist/redirectToPreviewURL.js.map +1 -1
  133. package/dist/types.d.cts +1 -2
  134. package/dist/types.d.cts.map +1 -0
  135. package/dist/types.d.ts +1 -2
  136. package/dist/types.d.ts.map +1 -0
  137. package/package.json +32 -34
  138. package/src/PrismicNextImage.tsx +113 -134
  139. package/src/PrismicNextLink.tsx +43 -45
  140. package/src/PrismicPreview.tsx +28 -29
  141. package/src/PrismicPreviewClient.tsx +42 -44
  142. package/src/SliceSimulator.tsx +38 -43
  143. package/src/SliceSimulatorWrapper.tsx +15 -25
  144. package/src/createLocaleRedirect.ts +3 -3
  145. package/src/enableAutoPreviews.ts +15 -16
  146. package/src/exitPreview.ts +12 -13
  147. package/src/getSlices.ts +6 -10
  148. package/src/imgixLoader.ts +10 -10
  149. package/src/index.ts +18 -21
  150. package/src/lib/devMsg.ts +9 -11
  151. package/src/lib/resolveDefaultExport.ts +9 -13
  152. package/src/pages/PrismicPreview.tsx +47 -51
  153. package/src/pages/SliceSimulator.tsx +35 -37
  154. package/src/pages/enableAutoPreviews.ts +17 -17
  155. package/src/pages/exitPreview.ts +17 -18
  156. package/src/pages/index.ts +20 -23
  157. package/src/pages/redirectToPreviewURL.ts +22 -33
  158. package/src/pages/setPreviewData.ts +7 -7
  159. package/src/pages/types.ts +16 -20
  160. package/src/redirectToPreviewURL.ts +21 -30
  161. package/src/types.ts +12 -13
@@ -1,35 +1,31 @@
1
- import type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
2
- import type { ClientConfig } from "@prismicio/client";
1
+ import type { ClientConfig } from "@prismicio/client"
3
2
 
4
- /**
5
- * Configuration for creating a Prismic client with automatic preview support in
6
- * Next.js apps.
7
- */
3
+ import type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
4
+
5
+ /** Configuration for creating a Prismic client with automatic preview support in Next.js apps. */
8
6
  export type CreateClientConfig = ClientConfig &
9
- Pick<EnableAutoPreviewsConfig, "previewData" | "req">;
7
+ Pick<EnableAutoPreviewsConfig, "previewData" | "req">
10
8
 
11
9
  /**
12
10
  * The minimal set of properties needed from `next`'s `NextApiRequest` type.
13
11
  *
14
- * This request type is only compatible with API routes defined in the `pages`
15
- * directory.
12
+ * This request type is only compatible with API routes defined in the `pages` directory.
16
13
  */
17
14
  export type NextApiRequestLike = {
18
- query: Partial<Record<string, string | string[]>>;
19
- cookies: Partial<Record<string, string>>;
20
- };
15
+ query: Partial<Record<string, string | string[]>>
16
+ cookies: Partial<Record<string, string>>
17
+ }
21
18
 
22
19
  /**
23
20
  * The minimal set of properties needed from `next`'s `NextApiResponse` type.
24
21
  *
25
- * This request type is only compatible with API routes defined in the `pages`
26
- * directory.
22
+ * This request type is only compatible with API routes defined in the `pages` directory.
27
23
  */
28
24
  export type NextApiResponseLike = {
29
- redirect(url: string): NextApiResponseLike;
30
- clearPreviewData(): NextApiResponseLike;
31
- setHeader(name: string, value: string | string[]): NextApiResponseLike;
25
+ redirect(url: string): NextApiResponseLike
26
+ clearPreviewData(): NextApiResponseLike
27
+ setHeader(name: string, value: string | string[]): NextApiResponseLike
32
28
  // oxlint-disable-next-line no-explicit-any explicit-module-boundary-types
33
- json(body: any): void;
34
- setPreviewData(data: object | string): NextApiResponseLike;
35
- };
29
+ json(body: any): void
30
+ setPreviewData(data: object | string): NextApiResponseLike
31
+ }
@@ -1,65 +1,56 @@
1
- import { redirect } from "next/navigation";
2
- import {
3
- cookie as prismicCookie,
4
- type Client,
5
- type LinkResolverFunction,
6
- } from "@prismicio/client";
1
+ import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
2
+ import { redirect } from "next/navigation"
7
3
 
8
- import type { NextRequestLike } from "./types";
4
+ import type { NextRequestLike } from "./types"
9
5
 
10
6
  export type RedirectToPreviewURLConfig = {
11
7
  /** The Prismic client configured for the preview session's repository. */
12
8
  // `Pick` is used to use the smallest possible subset of
13
9
  // `prismic.Client`. Doing this reduces the surface area for breaking
14
10
  // type changes.
15
- client: Pick<Client, "resolvePreviewURL">;
11
+ client: Pick<Client, "resolvePreviewURL">
16
12
 
17
13
  /**
18
14
  * The `request` object from a Next.js Route Handler.
19
15
  *
20
16
  * @see Next.js Route Handler docs: \<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\>
21
17
  */
22
- request: NextRequestLike;
18
+ request: NextRequestLike
23
19
 
24
20
  /**
25
21
  * A Link Resolver used to resolve the previewed document's URL.
26
22
  *
27
23
  * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
28
24
  */
29
- linkResolver?: LinkResolverFunction;
25
+ linkResolver?: LinkResolverFunction
30
26
 
31
27
  /**
32
- * The default redirect URL if a URL cannot be determined for the previewed
33
- * document.
28
+ * The default redirect URL if a URL cannot be determined for the previewed document.
34
29
  *
35
- * **Note**: If you `next.config.js` file contains a `basePath`, the
36
- * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
37
- * property using the `basePath` option.
30
+ * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
31
+ * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
38
32
  */
39
- defaultURL?: string;
40
- };
33
+ defaultURL?: string
34
+ }
41
35
 
42
- export async function redirectToPreviewURL(
43
- config: RedirectToPreviewURLConfig,
44
- ): Promise<never> {
45
- const { client, request, linkResolver, defaultURL = "/" } = config;
36
+ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {
37
+ const { client, request, linkResolver, defaultURL = "/" } = config
46
38
 
47
39
  // Need this to avoid the following Next.js build-time error:
48
40
  // You're importing a component that needs next/headers. That only works
49
41
  // in a Server Component which is not supported in the pages/ directory.
50
- const { cookies, draftMode } = await import("next/headers");
42
+ const { cookies, draftMode } = await import("next/headers")
51
43
 
52
- const documentID =
53
- request.nextUrl.searchParams.get("documentId") ?? undefined;
44
+ const documentID = request.nextUrl.searchParams.get("documentId") ?? undefined
54
45
 
55
46
  // Set the initial preview cookie. Setting the cookie here is necessary
56
47
  // to support unpublished previews. Without setting it here, the page
57
48
  // will try to render without the preview cookie, leading to a
58
49
  // PrismicNotFound error.
59
- const previewToken = request.nextUrl.searchParams.get("token") ?? undefined;
50
+ const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
60
51
  if (previewToken) {
61
- const cookieJar = await cookies();
62
- cookieJar.set(prismicCookie.preview, previewToken);
52
+ const cookieJar = await cookies()
53
+ cookieJar.set(prismicCookie.preview, previewToken)
63
54
  }
64
55
 
65
56
  const previewURL = await client.resolvePreviewURL({
@@ -67,9 +58,9 @@ export async function redirectToPreviewURL(
67
58
  previewToken,
68
59
  defaultURL,
69
60
  linkResolver,
70
- });
61
+ })
71
62
 
72
- (await draftMode()).enable();
63
+ ;(await draftMode()).enable()
73
64
 
74
- redirect(previewURL);
65
+ redirect(previewURL)
75
66
  }
package/src/types.ts CHANGED
@@ -1,30 +1,29 @@
1
- import type { ClientConfig } from "@prismicio/client";
1
+ import type { ClientConfig } from "@prismicio/client"
2
2
 
3
3
  // Add Next.js-specific fetchOptions to `@prismicio/client`.
4
4
  declare module "@prismicio/client" {
5
5
  interface RequestInitLike {
6
- next?: RequestInit["next"];
6
+ next?: RequestInit["next"]
7
7
  }
8
8
  }
9
9
 
10
10
  /** @deprecated Use `@prismicio/client`'s `ClientConfig`. */
11
- export type CreateClientConfig = ClientConfig;
11
+ export type CreateClientConfig = ClientConfig
12
12
 
13
13
  /**
14
14
  * The minimal set of properties needed from `next`'s `NextRequest` type.
15
15
  *
16
- * This request type is only compatible with Route Handlers defined in the `app`
17
- * directory.
16
+ * This request type is only compatible with Route Handlers defined in the `app` directory.
18
17
  */
19
18
  export type NextRequestLike = {
20
19
  headers: {
21
- get(name: string): string | null;
22
- };
23
- url: string;
20
+ get(name: string): string | null
21
+ }
22
+ url: string
24
23
  nextUrl: {
25
- pathname: string;
24
+ pathname: string
26
25
  searchParams: {
27
- get(name: string): string | null;
28
- };
29
- };
30
- };
26
+ get(name: string): string | null
27
+ }
28
+ }
29
+ }