@prismicio/next 2.2.3-pr.136.19d76d2 → 2.2.3

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 (159) hide show
  1. package/dist/PrismicNextImage.cjs +11 -9
  2. package/dist/PrismicNextImage.cjs.map +1 -1
  3. package/dist/PrismicNextImage.d.cts +21 -13
  4. package/dist/PrismicNextImage.d.ts +21 -13
  5. package/dist/PrismicNextImage.js +11 -9
  6. package/dist/PrismicNextImage.js.map +1 -1
  7. package/dist/PrismicNextLink.cjs.map +1 -1
  8. package/dist/PrismicNextLink.js.map +1 -1
  9. package/dist/PrismicPreview.cjs +7 -6
  10. package/dist/PrismicPreview.cjs.map +1 -1
  11. package/dist/PrismicPreview.d.cts +12 -11
  12. package/dist/PrismicPreview.d.ts +12 -11
  13. package/dist/PrismicPreview.js +7 -6
  14. package/dist/PrismicPreview.js.map +1 -1
  15. package/dist/PrismicPreviewClient.cjs +3 -1
  16. package/dist/PrismicPreviewClient.cjs.map +1 -1
  17. package/dist/PrismicPreviewClient.js +3 -1
  18. package/dist/PrismicPreviewClient.js.map +1 -1
  19. package/dist/SliceSimulator.cjs +3 -3
  20. package/dist/SliceSimulator.cjs.map +1 -1
  21. package/dist/SliceSimulator.d.cts +5 -3
  22. package/dist/SliceSimulator.d.ts +5 -3
  23. package/dist/SliceSimulator.js +3 -3
  24. package/dist/SliceSimulator.js.map +1 -1
  25. package/dist/SliceSimulatorWrapper.cjs +4 -1
  26. package/dist/SliceSimulatorWrapper.cjs.map +1 -1
  27. package/dist/SliceSimulatorWrapper.js +4 -1
  28. package/dist/SliceSimulatorWrapper.js.map +1 -1
  29. package/dist/createLocaleRedirect.cjs.map +1 -1
  30. package/dist/createLocaleRedirect.js.map +1 -1
  31. package/dist/enableAutoPreviews.cjs +2 -1
  32. package/dist/enableAutoPreviews.cjs.map +1 -1
  33. package/dist/enableAutoPreviews.d.cts +2 -1
  34. package/dist/enableAutoPreviews.d.ts +2 -1
  35. package/dist/enableAutoPreviews.js +2 -1
  36. package/dist/enableAutoPreviews.js.map +1 -1
  37. package/dist/exitPreview.cjs +10 -9
  38. package/dist/exitPreview.cjs.map +1 -1
  39. package/dist/exitPreview.d.cts +10 -9
  40. package/dist/exitPreview.d.ts +10 -9
  41. package/dist/exitPreview.js +10 -9
  42. package/dist/exitPreview.js.map +1 -1
  43. package/dist/getSlices.cjs.map +1 -1
  44. package/dist/getSlices.js.map +1 -1
  45. package/dist/imgixLoader.cjs +2 -2
  46. package/dist/imgixLoader.cjs.map +1 -1
  47. package/dist/imgixLoader.d.cts +2 -2
  48. package/dist/imgixLoader.d.ts +2 -2
  49. package/dist/imgixLoader.js +2 -2
  50. package/dist/imgixLoader.js.map +1 -1
  51. package/dist/lib/devMsg.cjs +8 -6
  52. package/dist/lib/devMsg.cjs.map +1 -1
  53. package/dist/lib/devMsg.js +8 -6
  54. package/dist/lib/devMsg.js.map +1 -1
  55. package/dist/lib/resolveDefaultExport.cjs +12 -8
  56. package/dist/lib/resolveDefaultExport.cjs.map +1 -1
  57. package/dist/lib/resolveDefaultExport.js +12 -8
  58. package/dist/lib/resolveDefaultExport.js.map +1 -1
  59. package/dist/package.cjs +1 -1
  60. package/dist/package.js +1 -1
  61. package/dist/pages/PrismicPreview.cjs +7 -6
  62. package/dist/pages/PrismicPreview.cjs.map +1 -1
  63. package/dist/pages/PrismicPreview.d.cts +12 -11
  64. package/dist/pages/PrismicPreview.d.ts +12 -11
  65. package/dist/pages/PrismicPreview.js +7 -6
  66. package/dist/pages/PrismicPreview.js.map +1 -1
  67. package/dist/pages/SliceSimulator.cjs +2 -2
  68. package/dist/pages/SliceSimulator.cjs.map +1 -1
  69. package/dist/pages/SliceSimulator.d.cts +13 -10
  70. package/dist/pages/SliceSimulator.d.ts +13 -10
  71. package/dist/pages/SliceSimulator.js +2 -2
  72. package/dist/pages/SliceSimulator.js.map +1 -1
  73. package/dist/pages/enableAutoPreviews.cjs +3 -3
  74. package/dist/pages/enableAutoPreviews.cjs.map +1 -1
  75. package/dist/pages/enableAutoPreviews.d.cts +5 -5
  76. package/dist/pages/enableAutoPreviews.d.ts +5 -5
  77. package/dist/pages/enableAutoPreviews.js +3 -3
  78. package/dist/pages/enableAutoPreviews.js.map +1 -1
  79. package/dist/pages/exitPreview.cjs +10 -9
  80. package/dist/pages/exitPreview.cjs.map +1 -1
  81. package/dist/pages/exitPreview.d.cts +10 -9
  82. package/dist/pages/exitPreview.d.ts +10 -9
  83. package/dist/pages/exitPreview.js +10 -9
  84. package/dist/pages/exitPreview.js.map +1 -1
  85. package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
  86. package/dist/pages/redirectToPreviewURL.d.cts +9 -7
  87. package/dist/pages/redirectToPreviewURL.d.ts +9 -7
  88. package/dist/pages/redirectToPreviewURL.js.map +1 -1
  89. package/dist/pages/setPreviewData.cjs.map +1 -1
  90. package/dist/pages/setPreviewData.js.map +1 -1
  91. package/dist/pages/types.d.cts +8 -3
  92. package/dist/pages/types.d.ts +8 -3
  93. package/dist/redirectToPreviewURL.cjs.map +1 -1
  94. package/dist/redirectToPreviewURL.d.cts +5 -3
  95. package/dist/redirectToPreviewURL.d.ts +5 -3
  96. package/dist/redirectToPreviewURL.js.map +1 -1
  97. package/dist/types.d.cts +2 -1
  98. package/dist/types.d.ts +2 -1
  99. package/package.json +25 -23
  100. package/src/PrismicNextImage.tsx +134 -113
  101. package/src/PrismicNextLink.tsx +45 -43
  102. package/src/PrismicPreview.tsx +29 -28
  103. package/src/PrismicPreviewClient.tsx +44 -42
  104. package/src/SliceSimulator.tsx +43 -38
  105. package/src/SliceSimulatorWrapper.tsx +25 -15
  106. package/src/createLocaleRedirect.ts +3 -3
  107. package/src/enableAutoPreviews.ts +16 -15
  108. package/src/exitPreview.ts +13 -12
  109. package/src/getSlices.ts +10 -6
  110. package/src/imgixLoader.ts +10 -10
  111. package/src/index.ts +21 -18
  112. package/src/lib/devMsg.ts +11 -9
  113. package/src/lib/resolveDefaultExport.ts +13 -9
  114. package/src/pages/PrismicPreview.tsx +51 -47
  115. package/src/pages/SliceSimulator.tsx +37 -35
  116. package/src/pages/enableAutoPreviews.ts +17 -17
  117. package/src/pages/exitPreview.ts +18 -17
  118. package/src/pages/index.ts +23 -20
  119. package/src/pages/redirectToPreviewURL.ts +33 -22
  120. package/src/pages/setPreviewData.ts +7 -7
  121. package/src/pages/types.ts +20 -16
  122. package/src/redirectToPreviewURL.ts +30 -21
  123. package/src/types.ts +13 -12
  124. package/dist/PrismicNextImage.d.cts.map +0 -1
  125. package/dist/PrismicNextImage.d.ts.map +0 -1
  126. package/dist/PrismicNextLink.d.cts.map +0 -1
  127. package/dist/PrismicNextLink.d.ts.map +0 -1
  128. package/dist/PrismicPreview.d.cts.map +0 -1
  129. package/dist/PrismicPreview.d.ts.map +0 -1
  130. package/dist/SliceSimulator.d.cts.map +0 -1
  131. package/dist/SliceSimulator.d.ts.map +0 -1
  132. package/dist/createLocaleRedirect.d.cts.map +0 -1
  133. package/dist/createLocaleRedirect.d.ts.map +0 -1
  134. package/dist/enableAutoPreviews.d.cts.map +0 -1
  135. package/dist/enableAutoPreviews.d.ts.map +0 -1
  136. package/dist/exitPreview.d.cts.map +0 -1
  137. package/dist/exitPreview.d.ts.map +0 -1
  138. package/dist/getSlices.d.cts.map +0 -1
  139. package/dist/getSlices.d.ts.map +0 -1
  140. package/dist/imgixLoader.d.cts.map +0 -1
  141. package/dist/imgixLoader.d.ts.map +0 -1
  142. package/dist/pages/PrismicPreview.d.cts.map +0 -1
  143. package/dist/pages/PrismicPreview.d.ts.map +0 -1
  144. package/dist/pages/SliceSimulator.d.cts.map +0 -1
  145. package/dist/pages/SliceSimulator.d.ts.map +0 -1
  146. package/dist/pages/enableAutoPreviews.d.cts.map +0 -1
  147. package/dist/pages/enableAutoPreviews.d.ts.map +0 -1
  148. package/dist/pages/exitPreview.d.cts.map +0 -1
  149. package/dist/pages/exitPreview.d.ts.map +0 -1
  150. package/dist/pages/redirectToPreviewURL.d.cts.map +0 -1
  151. package/dist/pages/redirectToPreviewURL.d.ts.map +0 -1
  152. package/dist/pages/setPreviewData.d.cts.map +0 -1
  153. package/dist/pages/setPreviewData.d.ts.map +0 -1
  154. package/dist/pages/types.d.cts.map +0 -1
  155. package/dist/pages/types.d.ts.map +0 -1
  156. package/dist/redirectToPreviewURL.d.cts.map +0 -1
  157. package/dist/redirectToPreviewURL.d.ts.map +0 -1
  158. package/dist/types.d.cts.map +0 -1
  159. package/dist/types.d.ts.map +0 -1
@@ -1,40 +1,41 @@
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 using this
11
- * repository.
10
+ * The name of your Prismic repository. A Prismic Toolbar will be registered
11
+ * using this 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`). This URL will be
17
- * fetched on preview update events.
16
+ * The URL of your app's Prismic preview endpoint (default: `/api/preview`).
17
+ * This URL will be 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`). This URL will be
23
- * fetched on preview exit events.
22
+ * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
23
+ * This URL will be 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 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.
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.
35
36
  *
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.
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.
38
39
  */
39
40
  export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
40
41
  const {
@@ -42,21 +43,21 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
42
43
  updatePreviewURL = "/api/preview",
43
44
  exitPreviewURL = "/api/exit-preview",
44
45
  children,
45
- } = props
46
+ } = props;
46
47
 
47
- const router = useRouter()
48
+ const router = useRouter();
48
49
 
49
- const toolbarSrc = getToolbarSrc(repositoryName)
50
+ const toolbarSrc = getToolbarSrc(repositoryName);
50
51
 
51
52
  useEffect(() => {
52
- const controller = new AbortController()
53
+ const controller = new AbortController();
53
54
 
54
55
  window.addEventListener("prismicPreviewUpdate", onUpdate, {
55
56
  signal: controller.signal,
56
- })
57
+ });
57
58
  window.addEventListener("prismicPreviewEnd", onEnd, {
58
59
  signal: controller.signal,
59
- })
60
+ });
60
61
 
61
62
  // Start the preview for preview share links. Previews from
62
63
  // share links do not go to the `updatePreviewURL` like a normal
@@ -65,33 +66,35 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
65
66
  // We check that the current URL is a descendant of the base
66
67
  // path to prevent infinite refrehes.
67
68
  if (
68
- window.location.href.startsWith(window.location.origin + router.basePath) &&
69
+ window.location.href.startsWith(
70
+ window.location.origin + router.basePath,
71
+ ) &&
69
72
  getPreviewCookieRepositoryName() === repositoryName &&
70
73
  !router.isPreview
71
74
  ) {
72
- start()
75
+ start();
73
76
  }
74
77
 
75
78
  function onEnd(event: Event) {
76
- event.preventDefault()
79
+ event.preventDefault();
77
80
  fetch(router.basePath + exitPreviewURL, { signal: controller.signal })
78
81
  .then((res) => {
79
82
  if (!res.ok) {
80
83
  console.error(
81
84
  `[<PrismicPreview>] Failed to exit Preview Mode using the "${exitPreviewURL}" API endpoint. Does it exist?`,
82
- )
85
+ );
83
86
 
84
- return
87
+ return;
85
88
  }
86
89
 
87
- refresh()
90
+ refresh();
88
91
  })
89
- .catch(() => {})
92
+ .catch(() => {});
90
93
  }
91
94
 
92
95
  function onUpdate(event: Event) {
93
- event.preventDefault()
94
- start()
96
+ event.preventDefault();
97
+ start();
95
98
  }
96
99
 
97
100
  function start() {
@@ -107,36 +110,37 @@ export const PrismicPreview: FC<PrismicPreviewProps> = (props) => {
107
110
  if (res.type !== "opaqueredirect") {
108
111
  console.error(
109
112
  `[<PrismicPreview>] Failed to start or update the preview using "${updatePreviewURL}". Does it exist?`,
110
- )
113
+ );
111
114
 
112
- return
115
+ return;
113
116
  }
114
117
 
115
- refresh()
118
+ refresh();
116
119
  })
117
- .catch(() => {})
120
+ .catch(() => {});
118
121
  }
119
122
 
120
123
  function refresh() {
121
- router.replace(router.asPath, undefined, { scroll: false })
124
+ router.replace(router.asPath, undefined, { scroll: false });
122
125
  }
123
126
 
124
- return () => controller.abort()
125
- }, [exitPreviewURL, updatePreviewURL, repositoryName, router])
127
+ return () => controller.abort();
128
+ }, [exitPreviewURL, updatePreviewURL, repositoryName, router]);
126
129
 
127
130
  return (
128
131
  <>
129
132
  {children}
130
133
  <Script src={toolbarSrc} strategy="lazyOnload" />
131
134
  </>
132
- )
133
- }
135
+ );
136
+ };
134
137
 
135
138
  function getPreviewCookieRepositoryName() {
136
139
  const cookie = window.document.cookie
137
140
  .split("; ")
138
141
  .find((row) => row.startsWith(`${prismicCookie.preview}=`))
139
- ?.split("=")[1]
142
+ ?.split("=")[1];
140
143
 
141
- return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) || [])[1]
144
+ return (decodeURIComponent(cookie ?? "").match(/"([^"]+)\.prismic\.io"/) ||
145
+ [])[1];
142
146
  }
@@ -1,47 +1,49 @@
1
+ import { SliceSimulatorWrapper } from "../SliceSimulatorWrapper";
1
2
  import {
2
3
  SimulatorManager,
3
4
  StateEventType,
4
5
  getDefaultMessage,
5
6
  getDefaultSlices,
6
- } from "@prismicio/simulator/kit"
7
+ } from "@prismicio/simulator/kit";
7
8
  import type {
8
9
  SliceSimulatorProps as BaseSliceSimulatorProps,
9
10
  SliceSimulatorState,
10
- } from "@prismicio/simulator/kit"
11
- import { useEffect, useState } from "react"
12
- import type { ComponentType, FC } from "react"
11
+ } from "@prismicio/simulator/kit";
12
+ import { useEffect, useState } from "react";
13
+ import type { ComponentType, FC } from "react";
13
14
 
14
- import { SliceSimulatorWrapper } from "../SliceSimulatorWrapper"
15
-
16
- const simulatorManager = new SimulatorManager()
15
+ const simulatorManager = new SimulatorManager();
17
16
 
18
17
  export type SliceSimulatorSliceZoneProps = {
19
- slices: SliceSimulatorState["slices"]
20
- }
18
+ slices: SliceSimulatorState["slices"];
19
+ };
21
20
 
22
21
  export type SliceSimulatorProps = BaseSliceSimulatorProps & {
23
22
  /**
24
23
  * React component to render simulated Slices.
25
24
  *
26
25
  * @example
27
- * ```tsx
28
- * import { SliceSimulator } from "@slicemachine/adapter-next/simulator"
29
- * import { SliceZone } from "@prismicio/react"
30
26
  *
31
- * import { components } from "../slices"
27
+ * ```tsx
28
+ * import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
29
+ * import { SliceZone } from "@prismicio/react";
30
+ *
31
+ * import { components } from "../slices";
32
32
  *
33
- * ;<SliceSimulator
34
- * sliceZone={({ slices }) => <SliceZone slices={slices} components={components} />}
35
- * />
36
- * ```
33
+ * <SliceSimulator
34
+ * sliceZone={({ slices }) => (
35
+ * <SliceZone slices={slices} components={components} />
36
+ * )}
37
+ * />;
38
+ * ```
37
39
  */
38
- sliceZone: ComponentType<SliceSimulatorSliceZoneProps>
39
- className?: string
40
- }
40
+ sliceZone: ComponentType<SliceSimulatorSliceZoneProps>;
41
+ className?: string;
42
+ };
41
43
 
42
44
  /**
43
- * Simulate slices in isolation. The slice simulator enables live slice development in Slice Machine
44
- * and live previews in the Page Builder.
45
+ * Simulate slices in isolation. The slice simulator enables live slice
46
+ * development in Slice Machine and live previews in the Page Builder.
45
47
  */
46
48
  export const SliceSimulator: FC<SliceSimulatorProps> = ({
47
49
  background,
@@ -49,33 +51,33 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
49
51
  className,
50
52
  sliceZone: SliceZoneComp,
51
53
  }) => {
52
- const [slices, setSlices] = useState(() => getDefaultSlices())
53
- const [message, setMessage] = useState(() => getDefaultMessage())
54
+ const [slices, setSlices] = useState(() => getDefaultSlices());
55
+ const [message, setMessage] = useState(() => getDefaultMessage());
54
56
 
55
57
  useEffect(() => {
56
58
  simulatorManager.state.on(
57
59
  StateEventType.Slices,
58
60
  (_slices) => {
59
- setSlices(_slices)
61
+ setSlices(_slices);
60
62
  },
61
63
  "simulator-slices",
62
- )
64
+ );
63
65
  simulatorManager.state.on(
64
66
  StateEventType.Message,
65
67
  (_message) => {
66
- setMessage(_message)
68
+ setMessage(_message);
67
69
  },
68
70
  "simulator-message",
69
- )
71
+ );
70
72
 
71
- simulatorManager.init()
73
+ simulatorManager.init();
72
74
 
73
75
  return () => {
74
- simulatorManager.state.off(StateEventType.Slices, "simulator-slices")
76
+ simulatorManager.state.off(StateEventType.Slices, "simulator-slices");
75
77
 
76
- simulatorManager.state.off(StateEventType.Message, "simulator-message")
77
- }
78
- }, [])
78
+ simulatorManager.state.off(StateEventType.Message, "simulator-message");
79
+ };
80
+ }, []);
79
81
 
80
82
  return (
81
83
  <SliceSimulatorWrapper
@@ -87,5 +89,5 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
87
89
  >
88
90
  <SliceZoneComp slices={slices} />
89
91
  </SliceSimulatorWrapper>
90
- )
91
- }
92
+ );
93
+ };
@@ -1,7 +1,7 @@
1
- import type { Client } from "@prismicio/client"
2
- import type { PreviewData } from "next"
1
+ import type { PreviewData } from "next";
2
+ import type { Client } from "@prismicio/client";
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 `getServerSideProps()` context
20
- * object.
19
+ * The `previewData` object provided in the `getStaticProps()` or
20
+ * `getServerSideProps()` context 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 preview session. It
34
- * either takes in a Next.js `getStaticProps` context object or a Next.js API endpoint request
35
- * object.
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.
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,38 +7,39 @@ 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 used in an API
22
- * route.
21
+ * Ends a Prismic preview session within a Next.js app. This function should be
22
+ * used in an API route.
23
23
  *
24
24
  * @example
25
- * ```typescript
26
- * // src/pages/api/exit-preview.js
27
25
  *
28
- * import { exitPreview } from "@prismicio/next"
26
+ * ```typescript
27
+ * // src/pages/api/exit-preview.js
28
+ *
29
+ * import { exitPreview } from "@prismicio/next";
29
30
  *
30
- * export default function handler(_req, res) {
31
- * return exitPreview({ res })
32
- * }
33
- * ```
31
+ * export default function handler(_req, res) {
32
+ * return exitPreview({ res });
33
+ * }
34
+ * ```
34
35
  */
35
36
  export function exitPreview(config: ExitPreviewAPIRouteConfig): void {
36
- config.res.clearPreviewData()
37
+ config.res.clearPreviewData();
37
38
 
38
39
  // `Cache-Control` header is used to prevent CDN-level caching.
39
- config.res.setHeader("Cache-Control", "no-store")
40
+ config.res.setHeader("Cache-Control", "no-store");
40
41
 
41
- config.res.json({ success: true })
42
+ config.res.json({ success: true });
42
43
 
43
- return
44
+ return;
44
45
  }
@@ -1,30 +1,33 @@
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 { SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./SliceSimulator"
7
+ export { SliceSimulator } from "./SliceSimulator";
8
+ export type {
9
+ SliceSimulatorProps,
10
+ SliceSimulatorSliceZoneProps,
11
+ } from "./SliceSimulator";
9
12
 
10
- export { imgixLoader } from "../imgixLoader"
13
+ export { imgixLoader } from "../imgixLoader";
11
14
 
12
- export { PrismicPreview } from "./PrismicPreview"
13
- export type { PrismicPreviewProps } from "./PrismicPreview"
15
+ export { PrismicPreview } from "./PrismicPreview";
16
+ export type { PrismicPreviewProps } from "./PrismicPreview";
14
17
 
15
- export { enableAutoPreviews } from "./enableAutoPreviews"
16
- export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
18
+ export { enableAutoPreviews } from "./enableAutoPreviews";
19
+ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
17
20
 
18
- export { redirectToPreviewURL } from "./redirectToPreviewURL"
19
- export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
21
+ export { redirectToPreviewURL } from "./redirectToPreviewURL";
22
+ export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
20
23
 
21
- export { exitPreview } from "./exitPreview"
22
- export type { ExitPreviewAPIRouteConfig } from "./exitPreview"
24
+ export { exitPreview } from "./exitPreview";
25
+ export type { ExitPreviewAPIRouteConfig } from "./exitPreview";
23
26
 
24
- export { setPreviewData } from "./setPreviewData"
25
- export type { SetPreviewDataConfig } from "./setPreviewData"
27
+ export { setPreviewData } from "./setPreviewData";
28
+ export type { SetPreviewDataConfig } from "./setPreviewData";
26
29
 
27
- export type { CreateClientConfig } from "./types"
30
+ export type { CreateClientConfig } from "./types";
28
31
 
29
- export { createLocaleRedirect } from "../createLocaleRedirect"
30
- export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect"
32
+ export { createLocaleRedirect } from "../createLocaleRedirect";
33
+ export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
@@ -1,66 +1,77 @@
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 document.
34
+ * The default redirect URL if a URL cannot be determined for the previewed
35
+ * document.
35
36
  *
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.
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.
38
40
  */
39
- defaultURL?: string
41
+ defaultURL?: string;
40
42
 
41
43
  /**
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`.
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`.
44
46
  *
45
47
  * @remarks
46
- * The Router Handler or API route is unable to detect the app's `basePath` automatically. It
47
- * must be provided to `redirectToPreviewURL()` manually.
48
+ * The Router Handler or API route is unable to detect the app's `basePath`
49
+ * automatically. It must be provided to `redirectToPreviewURL()` manually.
48
50
  */
49
- basePath?: string
50
- }
51
+ basePath?: string;
52
+ };
51
53
 
52
- export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<void> {
53
- const { client, req, res, linkResolver, defaultURL = "/", basePath = "" } = config
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;
54
65
 
55
- const previewToken = req.query.token?.toString()
66
+ const previewToken = req.query.token?.toString();
56
67
 
57
68
  const previewURL = await client.resolvePreviewURL({
58
69
  linkResolver,
59
70
  defaultURL,
60
71
  previewToken,
61
- })
72
+ });
62
73
 
63
- res.redirect(basePath + previewURL)
74
+ res.redirect(basePath + previewURL);
64
75
 
65
- return
76
+ return;
66
77
  }
@@ -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
  }