@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,41 +1,40 @@
1
- import { getToolbarSrc, cookie as prismicCookie } from "@prismicio/client";
2
- import { useRouter } from "next/router";
3
- import Script from "next/script";
4
- import type { FC } from "react";
5
- import { type ReactNode, useEffect } from "react";
1
+ import { getToolbarSrc, cookie as prismicCookie } from "@prismicio/client"
2
+ import { useRouter } from "next/router"
3
+ import Script from "next/script"
4
+ import type { FC } from "react"
5
+ import { type ReactNode, useEffect } from "react"
6
6
 
7
7
  /** Props for `<PrismicPreview>`. */
8
8
  export type PrismicPreviewProps = {
9
9
  /**
10
- * The name of your Prismic repository. A Prismic Toolbar will be registered
11
- * using this repository.
10
+ * The name of your Prismic repository. A Prismic Toolbar will be registered using this
11
+ * repository.
12
12
  */
13
- repositoryName: string;
13
+ repositoryName: string
14
14
 
15
15
  /**
16
- * The URL of your app's Prismic preview endpoint (default: `/api/preview`).
17
- * This URL will be fetched on preview update events.
16
+ * The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be
17
+ * fetched on preview update events.
18
18
  */
19
- updatePreviewURL?: string;
19
+ updatePreviewURL?: string
20
20
 
21
21
  /**
22
- * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
23
- * This URL will be fetched on preview exit events.
22
+ * The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be
23
+ * fetched on preview exit events.
24
24
  */
25
- exitPreviewURL?: string;
25
+ exitPreviewURL?: string
26
26
 
27
27
  /** Children to render adjacent to the Prismic Toolbar. */
28
- children?: ReactNode;
29
- };
28
+ children?: ReactNode
29
+ }
30
30
 
31
31
  /**
32
- * React component that sets up Prismic Previews using the Prismic Toolbar. When
33
- * the Prismic Toolbar send events to the browser, such as on preview updates
34
- * and exiting, this component will automatically refresh the page with the
35
- * changes.
32
+ * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
33
+ * send events to the browser, such as on preview updates and exiting, this component will
34
+ * automatically refresh the page with the changes.
36
35
  *
37
- * This component can be wrapped around your app or added anywhere in your app's
38
- * tree. It must be rendered on every page.
36
+ * This component can be wrapped around your app or added anywhere in your app's tree. It must be
37
+ * rendered on every page.
39
38
  */
40
39
  export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
41
40
  const {
@@ -43,21 +42,21 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
43
42
  updatePreviewURL = "/api/preview",
44
43
  exitPreviewURL = "/api/exit-preview",
45
44
  children,
46
- } = props;
45
+ } = props
47
46
 
48
- const router = useRouter();
47
+ const router = useRouter()
49
48
 
50
- const toolbarSrc = getToolbarSrc(repositoryName);
49
+ const toolbarSrc = getToolbarSrc(repositoryName)
51
50
 
52
51
  useEffect(() => {
53
- const controller = new AbortController();
52
+ const controller = new AbortController()
54
53
 
55
54
  window.addEventListener("prismicPreviewUpdate", onUpdate, {
56
55
  signal: controller.signal,
57
- });
56
+ })
58
57
  window.addEventListener("prismicPreviewEnd", onEnd, {
59
58
  signal: controller.signal,
60
- });
59
+ })
61
60
 
62
61
  // Start the preview for preview share links. Previews from
63
62
  // share links do not go to the `updatePreviewURL` like a normal
@@ -66,35 +65,33 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
66
65
  // We check that the current URL is a descendant of the base
67
66
  // path to prevent infinite refrehes.
68
67
  if (
69
- window.location.href.startsWith(
70
- window.location.origin + router.basePath,
71
- ) &&
68
+ window.location.href.startsWith(window.location.origin + router.basePath) &&
72
69
  getPreviewCookieRepositoryName() === repositoryName &&
73
70
  !router.isPreview
74
71
  ) {
75
- start();
72
+ start()
76
73
  }
77
74
 
78
75
  function onEnd(event: Event) {
79
- event.preventDefault();
76
+ event.preventDefault()
80
77
  fetch(router.basePath + exitPreviewURL, { signal: controller.signal })
81
78
  .then((res) => {
82
79
  if (!res.ok) {
83
80
  console.error(
84
81
  `[<PrismicPreview>] Failed to exit Preview Mode using the "${exitPreviewURL}" API endpoint. Does it exist?`,
85
- );
82
+ )
86
83
 
87
- return;
84
+ return
88
85
  }
89
86
 
90
- refresh();
87
+ refresh()
91
88
  })
92
- .catch(() => {});
89
+ .catch(() => {})
93
90
  }
94
91
 
95
92
  function onUpdate(event: Event) {
96
- event.preventDefault();
97
- start();
93
+ event.preventDefault()
94
+ start()
98
95
  }
99
96
 
100
97
  function start() {
@@ -110,37 +107,36 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
110
107
  if (res.type !== "opaqueredirect") {
111
108
  console.error(
112
109
  `[<PrismicPreview>] Failed to start or update the preview using "${updatePreviewURL}". Does it exist?`,
113
- );
110
+ )
114
111
 
115
- return;
112
+ return
116
113
  }
117
114
 
118
- refresh();
115
+ refresh()
119
116
  })
120
- .catch(() => {});
117
+ .catch(() => {})
121
118
  }
122
119
 
123
120
  function refresh() {
124
- router.replace(router.asPath, undefined, { scroll: false });
121
+ router.replace(router.asPath, undefined, { scroll: false })
125
122
  }
126
123
 
127
- return () => controller.abort();
128
- }, [exitPreviewURL, updatePreviewURL, repositoryName, router]);
124
+ return () => controller.abort()
125
+ }, [exitPreviewURL, updatePreviewURL, repositoryName, router])
129
126
 
130
127
  return (
131
128
  <>
132
129
  {children}
133
130
  <Script src={toolbarSrc} strategy="lazyOnload" />
134
131
  </>
135
- );
136
- };
132
+ )
133
+ }
137
134
 
138
135
  function getPreviewCookieRepositoryName() {
139
136
  const cookie = window.document.cookie
140
137
  .split("; ")
141
138
  .find((row) => row.startsWith(`${prismicCookie.preview}=`))
142
- ?.split("=")[1];
139
+ ?.split("=")[1]
143
140
 
144
- return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) ||
145
- [])[1];
141
+ return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1]
146
142
  }
@@ -1,49 +1,47 @@
1
- import { SliceSimulatorWrapper } from "../SliceSimulatorWrapper";
2
1
  import {
3
2
  SimulatorManager,
4
3
  StateEventType,
5
4
  getDefaultMessage,
6
5
  getDefaultSlices,
7
- } from "@prismicio/simulator/kit";
6
+ } from "@prismicio/simulator/kit"
8
7
  import type {
9
8
  SliceSimulatorProps as BaseSliceSimulatorProps,
10
9
  SliceSimulatorState,
11
- } from "@prismicio/simulator/kit";
12
- import { useEffect, useState } from "react";
13
- import type { ComponentType, FC } from "react";
10
+ } from "@prismicio/simulator/kit"
11
+ import { useEffect, useState } from "react"
12
+ import type { ComponentType, FC } from "react"
14
13
 
15
- const simulatorManager = new SimulatorManager();
14
+ import { SliceSimulatorWrapper } from "../SliceSimulatorWrapper"
15
+
16
+ const simulatorManager = new SimulatorManager()
16
17
 
17
18
  export type SliceSimulatorSliceZoneProps = {
18
- slices: SliceSimulatorState["slices"];
19
- };
19
+ slices: SliceSimulatorState["slices"]
20
+ }
20
21
 
21
22
  export type SliceSimulatorProps = BaseSliceSimulatorProps & {
22
23
  /**
23
24
  * React component to render simulated Slices.
24
25
  *
25
26
  * @example
27
+ * ;```tsx
28
+ * import { SliceSimulator } from "@slicemachine/adapter-next/simulator"
29
+ * import { SliceZone } from "@prismicio/react"
26
30
  *
27
- * ```tsx
28
- * import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
29
- * import { SliceZone } from "@prismicio/react";
30
- *
31
- * import { components } from "../slices";
31
+ * import { components } from "../slices"
32
32
  *
33
- * <SliceSimulator
34
- * sliceZone={({ slices }) => (
35
- * <SliceZone slices={slices} components={components} />
36
- * )}
37
- * />;
38
- * ```
33
+ * ;<SliceSimulator
34
+ * sliceZone={({ slices }) => <SliceZone slices={slices} components={components} />}
35
+ * />
36
+ * ```
39
37
  */
40
- sliceZone: ComponentType<SliceSimulatorSliceZoneProps>;
41
- className?: string;
42
- };
38
+ sliceZone: ComponentType<SliceSimulatorSliceZoneProps>
39
+ className?: string
40
+ }
43
41
 
44
42
  /**
45
- * Simulate slices in isolation. The slice simulator enables live slice
46
- * development in Slice Machine and live previews in the Page Builder.
43
+ * Simulate slices in isolation. The slice simulator enables live slice development in Slice Machine
44
+ * and live previews in the Page Builder.
47
45
  */
48
46
  export const SliceSimulator: FC<SliceSimulatorProps> = ({
49
47
  background,
@@ -51,33 +49,33 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
51
49
  className,
52
50
  sliceZone: SliceZoneComp,
53
51
  }) => {
54
- const [slices, setSlices] = useState(() => getDefaultSlices());
55
- const [message, setMessage] = useState(() => getDefaultMessage());
52
+ const [slices, setSlices] = useState(() => getDefaultSlices())
53
+ const [message, setMessage] = useState(() => getDefaultMessage())
56
54
 
57
55
  useEffect(() => {
58
56
  simulatorManager.state.on(
59
57
  StateEventType.Slices,
60
58
  (_slices) => {
61
- setSlices(_slices);
59
+ setSlices(_slices)
62
60
  },
63
61
  "simulator-slices",
64
- );
62
+ )
65
63
  simulatorManager.state.on(
66
64
  StateEventType.Message,
67
65
  (_message) => {
68
- setMessage(_message);
66
+ setMessage(_message)
69
67
  },
70
68
  "simulator-message",
71
- );
69
+ )
72
70
 
73
- simulatorManager.init();
71
+ simulatorManager.init()
74
72
 
75
73
  return () => {
76
- simulatorManager.state.off(StateEventType.Slices, "simulator-slices");
74
+ simulatorManager.state.off(StateEventType.Slices, "simulator-slices")
77
75
 
78
- simulatorManager.state.off(StateEventType.Message, "simulator-message");
79
- };
80
- }, []);
76
+ simulatorManager.state.off(StateEventType.Message, "simulator-message")
77
+ }
78
+ }, [])
81
79
 
82
80
  return (
83
81
  <SliceSimulatorWrapper
@@ -89,5 +87,5 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
89
87
  >
90
88
  <SliceZoneComp slices={slices} />
91
89
  </SliceSimulatorWrapper>
92
- );
93
- };
90
+ )
91
+ }
@@ -1,7 +1,7 @@
1
- import type { PreviewData } from "next";
2
- import type { Client } from "@prismicio/client";
1
+ import type { Client } from "@prismicio/client"
2
+ import type { PreviewData } from "next"
3
3
 
4
- import type { NextApiRequestLike } from "./types";
4
+ import type { NextApiRequestLike } from "./types"
5
5
 
6
6
  /**
7
7
  * Configuration for `enableAutoPreviews`.
@@ -13,26 +13,26 @@ export type EnableAutoPreviewsConfig = {
13
13
  // `Pick` is used to use the smallest possible subset of
14
14
  // `prismic.Client`. Doing this reduces the surface area for breaking
15
15
  // type changes.
16
- client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq">;
16
+ client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq">
17
17
 
18
18
  /**
19
- * The `previewData` object provided in the `getStaticProps()` or
20
- * `getServerSideProps()` context object.
19
+ * The `previewData` object provided in the `getStaticProps()` or `getServerSideProps()` context
20
+ * object.
21
21
  */
22
- previewData?: PreviewData;
22
+ previewData?: PreviewData
23
23
 
24
24
  /**
25
25
  * The `req` object from a Next.js API route.
26
26
  *
27
27
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
28
28
  */
29
- req?: NextApiRequestLike;
30
- };
29
+ req?: NextApiRequestLike
30
+ }
31
31
 
32
32
  /**
33
- * Configures a Prismic client to automatically query draft content during a
34
- * preview session. It either takes in a Next.js `getStaticProps` context object
35
- * or a Next.js API endpoint request object.
33
+ * Configures a Prismic client to automatically query draft content during a preview session. It
34
+ * either takes in a Next.js `getStaticProps` context object or a Next.js API endpoint request
35
+ * object.
36
36
  *
37
37
  * @param config - Configuration for the function.
38
38
  */
@@ -42,21 +42,21 @@ export function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {
42
42
  // `getServerSideProps()` with active Preview Mode.
43
43
 
44
44
  if (isPrismicPreviewData(config.previewData)) {
45
- config.client.queryContentFromRef(config.previewData.ref);
45
+ config.client.queryContentFromRef(config.previewData.ref)
46
46
  }
47
47
 
48
- return;
48
+ return
49
49
  }
50
50
 
51
51
  if ("req" in config && config.req) {
52
52
  // Assume we are in an API Route.
53
53
 
54
- config.client.enableAutoPreviewsFromReq(config.req);
54
+ config.client.enableAutoPreviewsFromReq(config.req)
55
55
 
56
- return;
56
+ return
57
57
  }
58
58
  }
59
59
 
60
60
  function isPrismicPreviewData(input: unknown): input is { ref: string } {
61
- return typeof input === "object" && input !== null && "ref" in input;
61
+ return typeof input === "object" && input !== null && "ref" in input
62
62
  }
@@ -1,4 +1,4 @@
1
- import type { NextApiRequestLike, NextApiResponseLike } from "./types";
1
+ import type { NextApiRequestLike, NextApiResponseLike } from "./types"
2
2
 
3
3
  /** Configuration for `exitPreview()`. */
4
4
  export type ExitPreviewAPIRouteConfig = {
@@ -7,39 +7,38 @@ export type ExitPreviewAPIRouteConfig = {
7
7
  *
8
8
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
9
9
  */
10
- req?: NextApiRequestLike;
10
+ req?: NextApiRequestLike
11
11
 
12
12
  /**
13
13
  * The `res` object from a Next.js API route.
14
14
  *
15
15
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
16
16
  */
17
- res: NextApiResponseLike;
18
- };
17
+ res: NextApiResponseLike
18
+ }
19
19
 
20
20
  /**
21
- * Ends a Prismic preview session within a Next.js app. This function should be
22
- * used in an API route.
21
+ * Ends a Prismic preview session within a Next.js app. This function should be used in an API
22
+ * route.
23
23
  *
24
24
  * @example
25
+ * ;```typescript
26
+ * // src/pages/api/exit-preview.js
25
27
  *
26
- * ```typescript
27
- * // src/pages/api/exit-preview.js
28
- *
29
- * import { exitPreview } from "@prismicio/next";
28
+ * import { exitPreview } from "@prismicio/next"
30
29
  *
31
- * export default function handler(_req, res) {
32
- * return exitPreview({ res });
33
- * }
34
- * ```
30
+ * export default function handler(_req, res) {
31
+ * return exitPreview({ res })
32
+ * }
33
+ * ```
35
34
  */
36
35
  export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
37
- config.res.clearPreviewData();
36
+ config.res.clearPreviewData()
38
37
 
39
38
  // `Cache-Control` header is used to prevent CDN-level caching.
40
- config.res.setHeader("Cache-Control", "no-store");
39
+ config.res.setHeader("Cache-Control", "no-store")
41
40
 
42
- config.res.json({ success: true });
41
+ config.res.json({ success: true })
43
42
 
44
- return;
43
+ return
45
44
  }
@@ -1,33 +1,30 @@
1
- export { PrismicNextLink } from "../PrismicNextLink";
2
- export { type PrismicNextLinkProps } from "../PrismicNextLink";
1
+ export { PrismicNextLink } from "../PrismicNextLink"
2
+ export { type PrismicNextLinkProps } from "../PrismicNextLink"
3
3
 
4
- export { PrismicNextImage } from "../PrismicNextImage";
5
- export { type PrismicNextImageProps } from "../PrismicNextImage";
4
+ export { PrismicNextImage } from "../PrismicNextImage"
5
+ export { type PrismicNextImageProps } from "../PrismicNextImage"
6
6
 
7
- export { SliceSimulator } from "./SliceSimulator";
8
- export type {
9
- SliceSimulatorProps,
10
- SliceSimulatorSliceZoneProps,
11
- } from "./SliceSimulator";
7
+ export { SliceSimulator } from "./SliceSimulator"
8
+ export type { SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./SliceSimulator"
12
9
 
13
- export { imgixLoader } from "../imgixLoader";
10
+ export { imgixLoader } from "../imgixLoader"
14
11
 
15
- export { PrismicPreview } from "./PrismicPreview";
16
- export type { PrismicPreviewProps } from "./PrismicPreview";
12
+ export { PrismicPreview } from "./PrismicPreview"
13
+ export type { PrismicPreviewProps } from "./PrismicPreview"
17
14
 
18
- export { enableAutoPreviews } from "./enableAutoPreviews";
19
- export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
15
+ export { enableAutoPreviews } from "./enableAutoPreviews"
16
+ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
20
17
 
21
- export { redirectToPreviewURL } from "./redirectToPreviewURL";
22
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
18
+ export { redirectToPreviewURL } from "./redirectToPreviewURL"
19
+ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
23
20
 
24
- export { exitPreview } from "./exitPreview";
25
- export type { ExitPreviewAPIRouteConfig } from "./exitPreview";
21
+ export { exitPreview } from "./exitPreview"
22
+ export type { ExitPreviewAPIRouteConfig } from "./exitPreview"
26
23
 
27
- export { setPreviewData } from "./setPreviewData";
28
- export type { SetPreviewDataConfig } from "./setPreviewData";
24
+ export { setPreviewData } from "./setPreviewData"
25
+ export type { SetPreviewDataConfig } from "./setPreviewData"
29
26
 
30
- export type { CreateClientConfig } from "./types";
27
+ export type { CreateClientConfig } from "./types"
31
28
 
32
- export { createLocaleRedirect } from "../createLocaleRedirect";
33
- export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
29
+ export { createLocaleRedirect } from "../createLocaleRedirect"
30
+ export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect"
@@ -1,77 +1,66 @@
1
- import type { LinkResolverFunction, Client } from "@prismicio/client";
1
+ import type { LinkResolverFunction, Client } from "@prismicio/client"
2
2
 
3
- import type { NextApiRequestLike, NextApiResponseLike } from "./types";
3
+ import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
4
 
5
5
  export type RedirectToPreviewURLConfig = {
6
6
  /** The Prismic client configured for the preview session's repository. */
7
7
  // `Pick` is used to use the smallest possible subset of
8
8
  // `prismic.Client`. Doing this reduces the surface area for breaking
9
9
  // type changes.
10
- client: Pick<Client, "resolvePreviewURL">;
10
+ client: Pick<Client, "resolvePreviewURL">
11
11
 
12
12
  /**
13
13
  * The `req` object from a Next.js API route.
14
14
  *
15
15
  * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
16
16
  */
17
- req: NextApiRequestLike;
17
+ req: NextApiRequestLike
18
18
 
19
19
  /**
20
20
  * The `res` object from a Next.js API route.
21
21
  *
22
22
  * @see Next.js API route docs: \<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\>
23
23
  */
24
- res: NextApiResponseLike;
24
+ res: NextApiResponseLike
25
25
 
26
26
  /**
27
27
  * A Link Resolver used to resolve the previewed document's URL.
28
28
  *
29
29
  * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
30
30
  */
31
- linkResolver?: LinkResolverFunction;
31
+ linkResolver?: LinkResolverFunction
32
32
 
33
33
  /**
34
- * The default redirect URL if a URL cannot be determined for the previewed
35
- * document.
34
+ * The default redirect URL if a URL cannot be determined for the previewed document.
36
35
  *
37
- * **Note**: If you `next.config.js` file contains a `basePath`, the
38
- * `defaultURL` option must _not_ include it. Instead, provide the `basePath`
39
- * property using the `basePath` option.
36
+ * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must
37
+ * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.
40
38
  */
41
- defaultURL?: string;
39
+ defaultURL?: string
42
40
 
43
41
  /**
44
- * The `basePath` for the Next.js app as it is defined in `next.config.js`.
45
- * This option can be omitted if the app does not have a `basePath`.
42
+ * The `basePath` for the Next.js app as it is defined in `next.config.js`. This option can be
43
+ * omitted if the app does not have a `basePath`.
46
44
  *
47
45
  * @remarks
48
- * The Router Handler or API route is unable to detect the app's `basePath`
49
- * automatically. It must be provided to `redirectToPreviewURL()` manually.
46
+ * The Router Handler or API route is unable to detect the app's `basePath` automatically. It
47
+ * must be provided to `redirectToPreviewURL()` manually.
50
48
  */
51
- basePath?: string;
52
- };
49
+ basePath?: string
50
+ }
53
51
 
54
- export async function redirectToPreviewURL(
55
- config: RedirectToPreviewURLConfig,
56
- ): Promise<void> {
57
- const {
58
- client,
59
- req,
60
- res,
61
- linkResolver,
62
- defaultURL = "/",
63
- basePath = "",
64
- } = config;
52
+ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {
53
+ const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config
65
54
 
66
- const previewToken = req.query.token?.toString();
55
+ const previewToken = req.query.token?.toString()
67
56
 
68
57
  const previewURL = await client.resolvePreviewURL({
69
58
  linkResolver,
70
59
  defaultURL,
71
60
  previewToken,
72
- });
61
+ })
73
62
 
74
- res.redirect(basePath + previewURL);
63
+ res.redirect(basePath + previewURL)
75
64
 
76
- return;
65
+ return
77
66
  }
@@ -1,6 +1,6 @@
1
- import { cookie } from "@prismicio/client";
1
+ import { cookie } from "@prismicio/client"
2
2
 
3
- import type { NextApiRequestLike, NextApiResponseLike } from "./types";
3
+ import type { NextApiRequestLike, NextApiResponseLike } from "./types"
4
4
 
5
5
  /** Configuration for `setPreviewData`. */
6
6
  export type SetPreviewDataConfig = {
@@ -9,21 +9,21 @@ export type SetPreviewDataConfig = {
9
9
  *
10
10
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
11
11
  */
12
- req: NextApiRequestLike;
12
+ req: NextApiRequestLike
13
13
 
14
14
  /**
15
15
  * The `res` object from a Next.js API route.
16
16
  *
17
17
  * @see Next.js API route docs: \<https://nextjs.org/docs/api-routes/introduction\>
18
18
  */
19
- res: NextApiResponseLike;
20
- };
19
+ res: NextApiResponseLike
20
+ }
21
21
 
22
22
  /** Set Prismic preview data for Next.js's Preview Mode. */
23
23
  export function setPreviewData({ req, res }: SetPreviewDataConfig): void {
24
- const ref = req.query.token || req.cookies[cookie.preview];
24
+ const ref = req.query.token || req.cookies[cookie.preview]
25
25
 
26
26
  if (ref) {
27
- res.setPreviewData({ ref });
27
+ res.setPreviewData({ ref })
28
28
  }
29
29
  }