@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.
- package/dist/PrismicNextImage.cjs +9 -11
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +13 -21
- package/dist/PrismicNextImage.d.cts.map +1 -0
- package/dist/PrismicNextImage.d.ts +13 -21
- package/dist/PrismicNextImage.d.ts.map +1 -0
- package/dist/PrismicNextImage.js +9 -11
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.cts.map +1 -0
- package/dist/PrismicNextLink.d.ts +3 -3
- package/dist/PrismicNextLink.d.ts.map +1 -0
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.cjs +6 -7
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +11 -12
- package/dist/PrismicPreview.d.cts.map +1 -0
- package/dist/PrismicPreview.d.ts +11 -12
- package/dist/PrismicPreview.d.ts.map +1 -0
- package/dist/PrismicPreview.js +6 -7
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +1 -3
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +1 -3
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/SliceSimulator.cjs +3 -3
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.cts +3 -5
- package/dist/SliceSimulator.d.cts.map +1 -0
- package/dist/SliceSimulator.d.ts +3 -5
- package/dist/SliceSimulator.d.ts.map +1 -0
- package/dist/SliceSimulator.js +3 -3
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/SliceSimulatorWrapper.cjs +1 -4
- package/dist/SliceSimulatorWrapper.cjs.map +1 -1
- package/dist/SliceSimulatorWrapper.js +1 -4
- package/dist/SliceSimulatorWrapper.js.map +1 -1
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts.map +1 -0
- package/dist/createLocaleRedirect.d.ts.map +1 -0
- package/dist/createLocaleRedirect.js.map +1 -1
- package/dist/enableAutoPreviews.cjs +1 -2
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +1 -2
- package/dist/enableAutoPreviews.d.cts.map +1 -0
- package/dist/enableAutoPreviews.d.ts +1 -2
- package/dist/enableAutoPreviews.d.ts.map +1 -0
- package/dist/enableAutoPreviews.js +1 -2
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +9 -10
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts +9 -10
- package/dist/exitPreview.d.cts.map +1 -0
- package/dist/exitPreview.d.ts +9 -10
- package/dist/exitPreview.d.ts.map +1 -0
- package/dist/exitPreview.js +9 -10
- package/dist/exitPreview.js.map +1 -1
- package/dist/getSlices.cjs.map +1 -1
- package/dist/getSlices.d.cts.map +1 -0
- package/dist/getSlices.d.ts.map +1 -0
- package/dist/getSlices.js.map +1 -1
- package/dist/imgixLoader.cjs +2 -2
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/imgixLoader.d.cts +2 -2
- package/dist/imgixLoader.d.cts.map +1 -0
- package/dist/imgixLoader.d.ts +2 -2
- package/dist/imgixLoader.d.ts.map +1 -0
- package/dist/imgixLoader.js +2 -2
- package/dist/imgixLoader.js.map +1 -1
- package/dist/lib/devMsg.cjs +6 -8
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js +6 -8
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +8 -12
- package/dist/lib/resolveDefaultExport.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.js +8 -12
- package/dist/lib/resolveDefaultExport.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +6 -7
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +11 -12
- package/dist/pages/PrismicPreview.d.cts.map +1 -0
- package/dist/pages/PrismicPreview.d.ts +11 -12
- package/dist/pages/PrismicPreview.d.ts.map +1 -0
- package/dist/pages/PrismicPreview.js +6 -7
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/SliceSimulator.cjs +2 -2
- package/dist/pages/SliceSimulator.cjs.map +1 -1
- package/dist/pages/SliceSimulator.d.cts +10 -13
- package/dist/pages/SliceSimulator.d.cts.map +1 -0
- package/dist/pages/SliceSimulator.d.ts +10 -13
- package/dist/pages/SliceSimulator.d.ts.map +1 -0
- package/dist/pages/SliceSimulator.js +2 -2
- package/dist/pages/SliceSimulator.js.map +1 -1
- package/dist/pages/enableAutoPreviews.cjs +3 -3
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +5 -5
- package/dist/pages/enableAutoPreviews.d.cts.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +5 -5
- package/dist/pages/enableAutoPreviews.d.ts.map +1 -0
- package/dist/pages/enableAutoPreviews.js +3 -3
- package/dist/pages/enableAutoPreviews.js.map +1 -1
- package/dist/pages/exitPreview.cjs +9 -10
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +9 -10
- package/dist/pages/exitPreview.d.cts.map +1 -0
- package/dist/pages/exitPreview.d.ts +9 -10
- package/dist/pages/exitPreview.d.ts.map +1 -0
- package/dist/pages/exitPreview.js +9 -10
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +7 -9
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/pages/redirectToPreviewURL.d.ts +7 -9
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts.map +1 -0
- package/dist/pages/setPreviewData.d.ts.map +1 -0
- package/dist/pages/setPreviewData.js.map +1 -1
- package/dist/pages/types.d.cts +3 -8
- package/dist/pages/types.d.cts.map +1 -0
- package/dist/pages/types.d.ts +3 -8
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +3 -5
- package/dist/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/redirectToPreviewURL.d.ts +3 -5
- package/dist/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -0
- package/package.json +32 -34
- package/src/PrismicNextImage.tsx +113 -134
- package/src/PrismicNextLink.tsx +43 -45
- package/src/PrismicPreview.tsx +28 -29
- package/src/PrismicPreviewClient.tsx +42 -44
- package/src/SliceSimulator.tsx +38 -43
- package/src/SliceSimulatorWrapper.tsx +15 -25
- package/src/createLocaleRedirect.ts +3 -3
- package/src/enableAutoPreviews.ts +15 -16
- package/src/exitPreview.ts +12 -13
- package/src/getSlices.ts +6 -10
- package/src/imgixLoader.ts +10 -10
- package/src/index.ts +18 -21
- package/src/lib/devMsg.ts +9 -11
- package/src/lib/resolveDefaultExport.ts +9 -13
- package/src/pages/PrismicPreview.tsx +47 -51
- package/src/pages/SliceSimulator.tsx +35 -37
- package/src/pages/enableAutoPreviews.ts +17 -17
- package/src/pages/exitPreview.ts +17 -18
- package/src/pages/index.ts +20 -23
- package/src/pages/redirectToPreviewURL.ts +22 -33
- package/src/pages/setPreviewData.ts +7 -7
- package/src/pages/types.ts +16 -20
- package/src/redirectToPreviewURL.ts +21 -30
- package/src/types.ts +12 -13
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use client"
|
|
1
|
+
"use client"
|
|
2
2
|
|
|
3
|
-
import { cookie as prismicCookie } from "@prismicio/client"
|
|
4
|
-
import { useRouter } from "next/navigation"
|
|
5
|
-
import type { FC } from "react"
|
|
6
|
-
import { useEffect } from "react"
|
|
3
|
+
import { cookie as prismicCookie } from "@prismicio/client"
|
|
4
|
+
import { useRouter } from "next/navigation"
|
|
5
|
+
import type { FC } from "react"
|
|
6
|
+
import { useEffect } from "react"
|
|
7
7
|
|
|
8
8
|
type PrismicPreviewClientProps = {
|
|
9
|
-
repositoryName: string
|
|
10
|
-
isDraftMode: boolean
|
|
11
|
-
updatePreviewURL?: string
|
|
12
|
-
exitPreviewURL?: string
|
|
13
|
-
}
|
|
9
|
+
repositoryName: string
|
|
10
|
+
isDraftMode: boolean
|
|
11
|
+
updatePreviewURL?: string
|
|
12
|
+
exitPreviewURL?: string
|
|
13
|
+
}
|
|
14
14
|
|
|
15
15
|
export const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {
|
|
16
16
|
const {
|
|
@@ -18,25 +18,25 @@ export const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {
|
|
|
18
18
|
isDraftMode,
|
|
19
19
|
updatePreviewURL = "/api/preview",
|
|
20
20
|
exitPreviewURL = "/api/exit-preview",
|
|
21
|
-
} = props
|
|
21
|
+
} = props
|
|
22
22
|
|
|
23
|
-
const { refresh } = useRouter()
|
|
23
|
+
const { refresh } = useRouter()
|
|
24
24
|
|
|
25
25
|
useEffect(() => {
|
|
26
|
-
const controller = new AbortController()
|
|
26
|
+
const controller = new AbortController()
|
|
27
27
|
|
|
28
28
|
window.addEventListener("prismicPreviewUpdate", onUpdate, {
|
|
29
29
|
signal: controller.signal,
|
|
30
|
-
})
|
|
30
|
+
})
|
|
31
31
|
window.addEventListener("prismicPreviewEnd", onEnd, {
|
|
32
32
|
signal: controller.signal,
|
|
33
|
-
})
|
|
33
|
+
})
|
|
34
34
|
|
|
35
|
-
const cookie = getPrismicPreviewCookie(window.document.cookie)
|
|
35
|
+
const cookie = getPrismicPreviewCookie(window.document.cookie)
|
|
36
36
|
const cookieRepositoryName = cookie
|
|
37
37
|
? (decodeURIComponent(cookie).match(/"([^"]+)\.prismic\.io"/) || [])[1]
|
|
38
|
-
: undefined
|
|
39
|
-
const hasCookieForRepository = cookieRepositoryName === repositoryName
|
|
38
|
+
: undefined
|
|
39
|
+
const hasCookieForRepository = cookieRepositoryName === repositoryName
|
|
40
40
|
|
|
41
41
|
// Start the preview for preview share links. Previews from
|
|
42
42
|
// share links do not go to the `updatePreviewURL` like a normal
|
|
@@ -55,75 +55,73 @@ export const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {
|
|
|
55
55
|
if (res.type !== "opaqueredirect") {
|
|
56
56
|
console.error(
|
|
57
57
|
`[<PrismicPreview>] Failed to start the preview using "${updatePreviewURL}". Does it exist?`,
|
|
58
|
-
)
|
|
58
|
+
)
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
refresh()
|
|
63
|
+
refresh()
|
|
64
64
|
})
|
|
65
65
|
.catch(() => {
|
|
66
66
|
// noop
|
|
67
|
-
})
|
|
67
|
+
})
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function onUpdate(event: Event) {
|
|
71
|
-
event.preventDefault()
|
|
72
|
-
refresh()
|
|
71
|
+
event.preventDefault()
|
|
72
|
+
refresh()
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function onEnd(event: Event) {
|
|
76
|
-
event.preventDefault()
|
|
76
|
+
event.preventDefault()
|
|
77
77
|
globalThis
|
|
78
78
|
.fetch(exitPreviewURL, { signal: controller.signal })
|
|
79
79
|
.then((res) => {
|
|
80
80
|
if (!res.ok) {
|
|
81
81
|
console.error(
|
|
82
82
|
`[<PrismicPreview>] Failed to exit Preview Mode using the "${exitPreviewURL}" API endpoint. Does it exist?`,
|
|
83
|
-
)
|
|
83
|
+
)
|
|
84
84
|
|
|
85
|
-
return
|
|
85
|
+
return
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
refresh()
|
|
88
|
+
refresh()
|
|
89
89
|
})
|
|
90
90
|
.catch(() => {
|
|
91
91
|
// noop
|
|
92
|
-
})
|
|
92
|
+
})
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
return () => controller.abort()
|
|
96
|
-
}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])
|
|
95
|
+
return () => controller.abort()
|
|
96
|
+
}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh])
|
|
97
97
|
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
98
|
+
return null
|
|
99
|
+
}
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Returns the value of a cookie from a given cookie store.
|
|
103
103
|
*
|
|
104
|
-
* @param cookieJar - The stringified cookie store from which to read the
|
|
105
|
-
* cookie.
|
|
106
|
-
*
|
|
104
|
+
* @param cookieJar - The stringified cookie store from which to read the cookie.
|
|
107
105
|
* @returns The value of the cookie, if it exists.
|
|
108
106
|
*/
|
|
109
107
|
function getPrismicPreviewCookie(cookieJar: string): string | undefined {
|
|
110
108
|
function readValue(value: string): string {
|
|
111
|
-
return value.replace(/%3B/g, ";")
|
|
109
|
+
return value.replace(/%3B/g, ";")
|
|
112
110
|
}
|
|
113
111
|
|
|
114
|
-
const cookies = cookieJar.split("; ")
|
|
112
|
+
const cookies = cookieJar.split("; ")
|
|
115
113
|
|
|
116
|
-
let value: string | undefined
|
|
114
|
+
let value: string | undefined
|
|
117
115
|
|
|
118
116
|
for (const cookie of cookies) {
|
|
119
|
-
const parts = cookie.split("=")
|
|
120
|
-
const name = readValue(parts[0]).replace(/%3D/g, "=")
|
|
117
|
+
const parts = cookie.split("=")
|
|
118
|
+
const name = readValue(parts[0]).replace(/%3D/g, "=")
|
|
121
119
|
|
|
122
120
|
if (name === prismicCookie.preview) {
|
|
123
|
-
value = readValue(parts.slice(1).join("="))
|
|
124
|
-
continue
|
|
121
|
+
value = readValue(parts.slice(1).join("="))
|
|
122
|
+
continue
|
|
125
123
|
}
|
|
126
124
|
}
|
|
127
125
|
|
|
128
|
-
return value
|
|
126
|
+
return value
|
|
129
127
|
}
|
package/src/SliceSimulator.tsx
CHANGED
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
"use client"
|
|
1
|
+
"use client"
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "@prismicio/simulator/kit";
|
|
10
|
-
import type { SliceSimulatorProps as BaseSliceSimulatorProps } from "@prismicio/simulator/kit";
|
|
11
|
-
import { compressToEncodedURIComponent } from "lz-string";
|
|
12
|
-
import { useRouter } from "next/navigation";
|
|
13
|
-
import { useEffect, useState } from "react";
|
|
14
|
-
import type { FC, ReactNode } from "react";
|
|
3
|
+
import { SimulatorManager, StateEventType, getDefaultMessage } from "@prismicio/simulator/kit"
|
|
4
|
+
import type { SliceSimulatorProps as BaseSliceSimulatorProps } from "@prismicio/simulator/kit"
|
|
5
|
+
import { compressToEncodedURIComponent } from "lz-string"
|
|
6
|
+
import { useRouter } from "next/navigation"
|
|
7
|
+
import { useEffect, useState } from "react"
|
|
8
|
+
import type { FC, ReactNode } from "react"
|
|
15
9
|
|
|
16
|
-
|
|
10
|
+
import { getSlices } from "./getSlices"
|
|
11
|
+
import { SliceSimulatorWrapper } from "./SliceSimulatorWrapper"
|
|
17
12
|
|
|
18
|
-
const
|
|
13
|
+
const STATE_PARAMS_KEY = "state"
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
15
|
+
const simulatorManager = new SimulatorManager()
|
|
16
|
+
|
|
17
|
+
/** Parameters provided to the Slice Simulator page. */
|
|
23
18
|
export type SliceSimulatorParams = {
|
|
24
19
|
searchParams: Promise<{
|
|
25
|
-
state?: string
|
|
26
|
-
}
|
|
27
|
-
}
|
|
20
|
+
state?: string
|
|
21
|
+
}>
|
|
22
|
+
}
|
|
28
23
|
|
|
29
24
|
export type SliceSimulatorProps = BaseSliceSimulatorProps & {
|
|
30
|
-
children: ReactNode
|
|
31
|
-
className?: string
|
|
32
|
-
}
|
|
25
|
+
children: ReactNode
|
|
26
|
+
className?: string
|
|
27
|
+
}
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
|
-
* Simulate slices in isolation. The slice simulator enables live slice
|
|
36
|
-
*
|
|
30
|
+
* Simulate slices in isolation. The slice simulator enables live slice development in Slice Machine
|
|
31
|
+
* and live previews in the Page Builder.
|
|
37
32
|
*/
|
|
38
33
|
export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
39
34
|
children,
|
|
@@ -41,45 +36,45 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
41
36
|
zIndex,
|
|
42
37
|
className,
|
|
43
38
|
}) => {
|
|
44
|
-
const [message, setMessage] = useState(() => getDefaultMessage())
|
|
45
|
-
const router = useRouter()
|
|
39
|
+
const [message, setMessage] = useState(() => getDefaultMessage())
|
|
40
|
+
const router = useRouter()
|
|
46
41
|
|
|
47
42
|
const state =
|
|
48
43
|
typeof window !== "undefined"
|
|
49
44
|
? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY)
|
|
50
|
-
: undefined
|
|
51
|
-
const hasSlices = getSlices(state).length > 0
|
|
45
|
+
: undefined
|
|
46
|
+
const hasSlices = getSlices(state).length > 0
|
|
52
47
|
|
|
53
48
|
useEffect(() => {
|
|
54
49
|
simulatorManager.state.on(
|
|
55
50
|
StateEventType.Slices,
|
|
56
51
|
(newSlices) => {
|
|
57
|
-
const url = new URL(window.location.href)
|
|
52
|
+
const url = new URL(window.location.href)
|
|
58
53
|
url.searchParams.set(
|
|
59
54
|
STATE_PARAMS_KEY,
|
|
60
55
|
compressToEncodedURIComponent(JSON.stringify(newSlices)),
|
|
61
|
-
)
|
|
56
|
+
)
|
|
62
57
|
|
|
63
|
-
window.history.replaceState(null, "", url)
|
|
58
|
+
window.history.replaceState(null, "", url)
|
|
64
59
|
// Wait until the next tick to prevent URL state race conditions.
|
|
65
|
-
setTimeout(() => router.refresh(), 0)
|
|
60
|
+
setTimeout(() => router.refresh(), 0)
|
|
66
61
|
},
|
|
67
62
|
"simulator-slices",
|
|
68
|
-
)
|
|
63
|
+
)
|
|
69
64
|
simulatorManager.state.on(
|
|
70
65
|
StateEventType.Message,
|
|
71
66
|
(newMessage) => setMessage(newMessage),
|
|
72
67
|
"simulator-message",
|
|
73
|
-
)
|
|
68
|
+
)
|
|
74
69
|
|
|
75
|
-
simulatorManager.init()
|
|
70
|
+
simulatorManager.init()
|
|
76
71
|
|
|
77
72
|
return () => {
|
|
78
|
-
simulatorManager.state.off(StateEventType.Slices, "simulator-slices")
|
|
73
|
+
simulatorManager.state.off(StateEventType.Slices, "simulator-slices")
|
|
79
74
|
|
|
80
|
-
simulatorManager.state.off(StateEventType.Message, "simulator-message")
|
|
81
|
-
}
|
|
82
|
-
}, [router])
|
|
75
|
+
simulatorManager.state.off(StateEventType.Message, "simulator-message")
|
|
76
|
+
}
|
|
77
|
+
}, [router])
|
|
83
78
|
|
|
84
79
|
return (
|
|
85
80
|
<SliceSimulatorWrapper
|
|
@@ -91,5 +86,5 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
91
86
|
>
|
|
92
87
|
{children}
|
|
93
88
|
</SliceSimulatorWrapper>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -4,21 +4,18 @@ import {
|
|
|
4
4
|
onClickHandler,
|
|
5
5
|
simulatorClass,
|
|
6
6
|
simulatorRootClass,
|
|
7
|
-
} from "@prismicio/simulator/kit"
|
|
8
|
-
import type { SliceSimulatorProps } from "@prismicio/simulator/kit"
|
|
9
|
-
import type { FC, ReactNode } from "react"
|
|
7
|
+
} from "@prismicio/simulator/kit"
|
|
8
|
+
import type { SliceSimulatorProps } from "@prismicio/simulator/kit"
|
|
9
|
+
import type { FC, ReactNode } from "react"
|
|
10
10
|
|
|
11
11
|
type SliceSimulatorWrapperProps = SliceSimulatorProps & {
|
|
12
|
-
children: ReactNode
|
|
13
|
-
className?: string
|
|
14
|
-
message?: string
|
|
15
|
-
hasSlices: boolean
|
|
16
|
-
}
|
|
12
|
+
children: ReactNode
|
|
13
|
+
className?: string
|
|
14
|
+
message?: string
|
|
15
|
+
hasSlices: boolean
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* A wrapper for the slice simulator that isolates the given children from the
|
|
20
|
-
* page's layout.
|
|
21
|
-
*/
|
|
18
|
+
/** A wrapper for the slice simulator that isolates the given children from the page's layout. */
|
|
22
19
|
export const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({
|
|
23
20
|
className,
|
|
24
21
|
children,
|
|
@@ -27,16 +24,13 @@ export const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({
|
|
|
27
24
|
message,
|
|
28
25
|
hasSlices,
|
|
29
26
|
}) => {
|
|
30
|
-
const defaultProps = getDefaultProps()
|
|
27
|
+
const defaultProps = getDefaultProps()
|
|
31
28
|
|
|
32
29
|
return (
|
|
33
30
|
<div
|
|
34
31
|
className={[simulatorClass, className].filter(Boolean).join(" ")}
|
|
35
32
|
style={{
|
|
36
|
-
zIndex:
|
|
37
|
-
typeof zIndex === "undefined"
|
|
38
|
-
? defaultProps.zIndex
|
|
39
|
-
: (zIndex ?? undefined),
|
|
33
|
+
zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : (zIndex ?? undefined),
|
|
40
34
|
position: "fixed",
|
|
41
35
|
top: 0,
|
|
42
36
|
left: 0,
|
|
@@ -44,9 +38,7 @@ export const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({
|
|
|
44
38
|
height: "100vh",
|
|
45
39
|
overflow: "auto",
|
|
46
40
|
background:
|
|
47
|
-
typeof background === "undefined"
|
|
48
|
-
? defaultProps.background
|
|
49
|
-
: (background ?? undefined),
|
|
41
|
+
typeof background === "undefined" ? defaultProps.background : (background ?? undefined),
|
|
50
42
|
}}
|
|
51
43
|
>
|
|
52
44
|
{message ? (
|
|
@@ -56,13 +48,11 @@ export const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({
|
|
|
56
48
|
id="root"
|
|
57
49
|
className={simulatorRootClass}
|
|
58
50
|
onClickCapture={onClickHandler as unknown as React.MouseEventHandler}
|
|
59
|
-
onSubmitCapture={
|
|
60
|
-
disableEventHandler as unknown as React.FormEventHandler
|
|
61
|
-
}
|
|
51
|
+
onSubmitCapture={disableEventHandler as unknown as React.FormEventHandler}
|
|
62
52
|
>
|
|
63
53
|
{children}
|
|
64
54
|
</div>
|
|
65
55
|
) : null}
|
|
66
56
|
</div>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { devMsg } from "./lib/devMsg"
|
|
1
|
+
import { devMsg } from "./lib/devMsg"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @deprecated `createLocaleRedirect()` has been removed due to performance
|
|
@@ -9,10 +9,10 @@ export function createLocaleRedirect(): never {
|
|
|
9
9
|
`createLocaleRedirect() has been removed due to performance issues. See ${devMsg(
|
|
10
10
|
"replace-createLocaleRedirect",
|
|
11
11
|
)} for more details.`,
|
|
12
|
-
)
|
|
12
|
+
)
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @deprecated `createLocaleRedirect()` has been removed due to performance
|
|
16
16
|
* issues.
|
|
17
17
|
*/
|
|
18
|
-
export type CreateLocaleRedirectConfig = never
|
|
18
|
+
export type CreateLocaleRedirectConfig = never
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Client, cookie as prismicCookie } from "@prismicio/client"
|
|
1
|
+
import { type Client, cookie as prismicCookie } from "@prismicio/client"
|
|
2
2
|
|
|
3
3
|
/** Configuration for `enableAutoPreviews`. */
|
|
4
4
|
export type EnableAutoPreviewsConfig = {
|
|
@@ -6,12 +6,11 @@ export type EnableAutoPreviewsConfig = {
|
|
|
6
6
|
// `Pick` is used to use the smallest possible subset of
|
|
7
7
|
// `prismic.Client`. Doing this reduces the surface area for breaking
|
|
8
8
|
// type changes.
|
|
9
|
-
client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq"
|
|
10
|
-
}
|
|
9
|
+
client: Pick<Client, "queryContentFromRef" | "enableAutoPreviewsFromReq">
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
14
|
-
* preview session.
|
|
13
|
+
* Configures a Prismic client to automatically query draft content during a preview session.
|
|
15
14
|
*
|
|
16
15
|
* @param config - Configuration for the function.
|
|
17
16
|
*/
|
|
@@ -22,32 +21,32 @@ export function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {
|
|
|
22
21
|
// Need this to avoid the following Next.js build-time error:
|
|
23
22
|
// You're importing a component that needs next/headers. That only works
|
|
24
23
|
// in a Server Component which is not supported in the pages/ directory.
|
|
25
|
-
const { cookies, draftMode } = await import("next/headers")
|
|
24
|
+
const { cookies, draftMode } = await import("next/headers")
|
|
26
25
|
|
|
27
|
-
let isDraftModeEnabled = false
|
|
26
|
+
let isDraftModeEnabled = false
|
|
28
27
|
try {
|
|
29
|
-
isDraftModeEnabled = (await draftMode()).isEnabled
|
|
28
|
+
isDraftModeEnabled = (await draftMode()).isEnabled
|
|
30
29
|
} catch {
|
|
31
30
|
// `draftMode()` may have been called in a palce that
|
|
32
31
|
// does not have access to its async storage. This
|
|
33
32
|
// occurs in places like `generateStaticParams()`. We
|
|
34
33
|
// can ignore this case.
|
|
35
|
-
return
|
|
34
|
+
return
|
|
36
35
|
}
|
|
37
36
|
if (!isDraftModeEnabled) {
|
|
38
|
-
return
|
|
37
|
+
return
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
const cookie = (await cookies()).get(prismicCookie.preview)?.value
|
|
40
|
+
const cookie = (await cookies()).get(prismicCookie.preview)?.value
|
|
42
41
|
if (!cookie) {
|
|
43
|
-
return
|
|
42
|
+
return
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
const isActiveCookie = cookie.includes("websitePreviewId=")
|
|
45
|
+
const isActiveCookie = cookie.includes("websitePreviewId=")
|
|
47
46
|
if (!isActiveCookie) {
|
|
48
|
-
return
|
|
47
|
+
return
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
return cookie
|
|
52
|
-
})
|
|
50
|
+
return cookie
|
|
51
|
+
})
|
|
53
52
|
}
|
package/src/exitPreview.ts
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Ends a Prismic preview session within a Next.js app. This function should be
|
|
3
|
-
*
|
|
2
|
+
* Ends a Prismic preview session within a Next.js app. This function should be used in a Router
|
|
3
|
+
* Handler.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
+
* ;```typescript
|
|
7
|
+
* // src/app/api/exit-preview/route.js
|
|
6
8
|
*
|
|
7
|
-
*
|
|
8
|
-
* // src/app/api/exit-preview/route.js
|
|
9
|
+
* import { exitPreview } from "@prismicio/next"
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
11
|
+
* export async function GET() {
|
|
12
|
+
* return await exitPreview()
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
16
15
|
*/
|
|
17
16
|
export async function exitPreview(): Promise<Response> {
|
|
18
17
|
// Need this to avoid the following Next.js build-time error:
|
|
19
18
|
// You're importing a component that needs next/headers. That only works
|
|
20
19
|
// in a Server Component which is not supported in the pages/ directory.
|
|
21
|
-
const { draftMode } = await import("next/headers")
|
|
20
|
+
const { draftMode } = await import("next/headers")
|
|
22
21
|
|
|
23
|
-
(await draftMode()).disable()
|
|
22
|
+
;(await draftMode()).disable()
|
|
24
23
|
|
|
25
24
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
26
25
|
return new Response(JSON.stringify({ success: true }), {
|
|
27
26
|
headers: {
|
|
28
27
|
"Cache-Control": "no-store",
|
|
29
28
|
},
|
|
30
|
-
})
|
|
29
|
+
})
|
|
31
30
|
}
|
package/src/getSlices.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { getDefaultSlices } from "@prismicio/simulator/kit"
|
|
2
|
-
import type { StateEvents, StateEventType } from "@prismicio/simulator/kit"
|
|
3
|
-
import { decompressFromEncodedURIComponent } from "lz-string"
|
|
1
|
+
import { getDefaultSlices } from "@prismicio/simulator/kit"
|
|
2
|
+
import type { StateEvents, StateEventType } from "@prismicio/simulator/kit"
|
|
3
|
+
import { decompressFromEncodedURIComponent } from "lz-string"
|
|
4
4
|
|
|
5
|
-
export const getSlices = (
|
|
6
|
-
state
|
|
7
|
-
|
|
8
|
-
return state
|
|
9
|
-
? JSON.parse(decompressFromEncodedURIComponent(state))
|
|
10
|
-
: getDefaultSlices();
|
|
11
|
-
};
|
|
5
|
+
export const getSlices = (state: string | null | undefined): StateEvents[StateEventType.Slices] => {
|
|
6
|
+
return state ? JSON.parse(decompressFromEncodedURIComponent(state)) : getDefaultSlices()
|
|
7
|
+
}
|
package/src/imgixLoader.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { ImgixURLParams } from "imgix-url-builder"
|
|
2
|
+
import { buildURL } from "imgix-url-builder"
|
|
3
|
+
import type { ImageLoaderProps } from "next/image"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* A `next/image` loader for Imgix, which Prismic uses, with an optional
|
|
7
|
-
*
|
|
6
|
+
* A `next/image` loader for Imgix, which Prismic uses, with an optional collection of default Imgix
|
|
7
|
+
* parameters.
|
|
8
8
|
*
|
|
9
9
|
* @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader
|
|
10
10
|
* @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering
|
|
11
11
|
*/
|
|
12
12
|
export const imgixLoader = (args: ImageLoaderProps): string => {
|
|
13
|
-
const url = new URL(args.src)
|
|
13
|
+
const url = new URL(args.src)
|
|
14
14
|
|
|
15
15
|
const params: ImgixURLParams = {
|
|
16
16
|
fit: (url.searchParams.get("fit") as ImgixURLParams["fit"]) || "max",
|
|
17
17
|
w: args.width,
|
|
18
18
|
h: undefined,
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
if (args.quality) {
|
|
22
|
-
params.q = args.quality
|
|
22
|
+
params.q = args.quality
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
return buildURL(args.src, params)
|
|
26
|
-
}
|
|
25
|
+
return buildURL(args.src, params)
|
|
26
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
export { exitPreview } from "./exitPreview"
|
|
1
|
+
export { exitPreview } from "./exitPreview"
|
|
2
2
|
|
|
3
|
-
export { PrismicPreview } from "./PrismicPreview"
|
|
4
|
-
export type { PrismicPreviewProps } from "./PrismicPreview"
|
|
3
|
+
export { PrismicPreview } from "./PrismicPreview"
|
|
4
|
+
export type { PrismicPreviewProps } from "./PrismicPreview"
|
|
5
5
|
|
|
6
|
-
export { PrismicNextLink } from "./PrismicNextLink"
|
|
7
|
-
export type { PrismicNextLinkProps } from "./PrismicNextLink"
|
|
6
|
+
export { PrismicNextLink } from "./PrismicNextLink"
|
|
7
|
+
export type { PrismicNextLinkProps } from "./PrismicNextLink"
|
|
8
8
|
|
|
9
|
-
export { enableAutoPreviews } from "./enableAutoPreviews"
|
|
10
|
-
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
|
|
9
|
+
export { enableAutoPreviews } from "./enableAutoPreviews"
|
|
10
|
+
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews"
|
|
11
11
|
|
|
12
|
-
export { redirectToPreviewURL } from "./redirectToPreviewURL"
|
|
13
|
-
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
|
|
12
|
+
export { redirectToPreviewURL } from "./redirectToPreviewURL"
|
|
13
|
+
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL"
|
|
14
14
|
|
|
15
|
-
export { PrismicNextImage } from "./PrismicNextImage"
|
|
16
|
-
export type { PrismicNextImageProps } from "./PrismicNextImage"
|
|
15
|
+
export { PrismicNextImage } from "./PrismicNextImage"
|
|
16
|
+
export type { PrismicNextImageProps } from "./PrismicNextImage"
|
|
17
17
|
|
|
18
|
-
export { SliceSimulator } from "./SliceSimulator"
|
|
19
|
-
export type {
|
|
20
|
-
SliceSimulatorProps,
|
|
21
|
-
SliceSimulatorParams,
|
|
22
|
-
} from "./SliceSimulator";
|
|
18
|
+
export { SliceSimulator } from "./SliceSimulator"
|
|
19
|
+
export type { SliceSimulatorProps, SliceSimulatorParams } from "./SliceSimulator"
|
|
23
20
|
|
|
24
|
-
export { getSlices } from "./getSlices"
|
|
21
|
+
export { getSlices } from "./getSlices"
|
|
25
22
|
|
|
26
|
-
export { imgixLoader } from "./imgixLoader"
|
|
23
|
+
export { imgixLoader } from "./imgixLoader"
|
|
27
24
|
|
|
28
|
-
export type { CreateClientConfig } from "./types"
|
|
25
|
+
export type { CreateClientConfig } from "./types"
|
|
29
26
|
|
|
30
|
-
export { createLocaleRedirect } from "./createLocaleRedirect"
|
|
31
|
-
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect"
|
|
27
|
+
export { createLocaleRedirect } from "./createLocaleRedirect"
|
|
28
|
+
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect"
|
package/src/lib/devMsg.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { version } from "../../package.json"
|
|
1
|
+
import { version } from "../../package.json"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
+
* ;```ts
|
|
8
|
+
* devMsg("missing-param")
|
|
9
|
+
* // => "https://prismic.dev/msg/next/v1.2.3/missing-param"
|
|
10
|
+
* ```
|
|
7
11
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* // => "https://prismic.dev/msg/next/v1.2.3/missing-param"
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
14
|
-
* the Git repository's `/messages` directory.
|
|
15
|
-
*
|
|
12
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
|
|
13
|
+
* `/messages` directory.
|
|
16
14
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
17
15
|
*/
|
|
18
16
|
export const devMsg = (slug: string): string => {
|
|
19
|
-
return `https://prismic.dev/msg/next/v${version}/${slug}
|
|
20
|
-
}
|
|
17
|
+
return `https://prismic.dev/msg/next/v${version}/${slug}`
|
|
18
|
+
}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolves a module's default export. The module may provide its default export
|
|
3
|
-
*
|
|
4
|
-
* exports are mixed in modules.
|
|
2
|
+
* Resolves a module's default export. The module may provide its default export as a `default`
|
|
3
|
+
* property on an object. This happens when named and default exports are mixed in modules.
|
|
5
4
|
*
|
|
6
|
-
* In ES Modules, mixing is fine since the module resolver can distinguish
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* called `default`.
|
|
5
|
+
* In ES Modules, mixing is fine since the module resolver can distinguish default and named
|
|
6
|
+
* exports. In transpiled modules, however, all exports are put into a single object, and the
|
|
7
|
+
* default export is provided at a property called `default`.
|
|
10
8
|
*
|
|
11
|
-
* This helper is needed by Next.js uses CJS files with named and default
|
|
12
|
-
* exports.
|
|
9
|
+
* This helper is needed by Next.js uses CJS files with named and default exports.
|
|
13
10
|
*
|
|
14
|
-
* This helper _should_ be a temporary hack until Next.js and Node.js resolve
|
|
15
|
-
*
|
|
16
|
-
* unfortunately.
|
|
11
|
+
* This helper _should_ be a temporary hack until Next.js and Node.js resolve their ESM
|
|
12
|
+
* difficulties. This will likely not be removed any time soon, unfortunately.
|
|
17
13
|
*/
|
|
18
14
|
export function resolveDefaultExport<T>(mod: T): T {
|
|
19
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
return "default" in (mod as any) ? (mod as any).default : mod
|
|
16
|
+
return "default" in (mod as any) ? (mod as any).default : mod
|
|
21
17
|
}
|