next-sanity 13.1.0 → 13.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js.map +1 -1
- package/dist/draft-mode/index.d.ts +25 -25
- package/dist/draft-mode/index.d.ts.map +1 -1
- package/dist/draft-mode/index.js.map +1 -1
- package/dist/image/index.d.ts +10 -10
- package/dist/image/index.d.ts.map +1 -1
- package/dist/isCorsOriginError.d.ts.map +1 -1
- package/dist/live/cache-life.d.ts +17 -20
- package/dist/live/cache-life.d.ts.map +1 -1
- package/dist/live/cache-life.js.map +1 -1
- package/dist/live/client-components/index.d.ts +2 -2
- package/dist/live/client-components/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.d.ts +286 -286
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts +228 -228
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +228 -228
- package/dist/live/conditions/react-server/index.d.ts.map +1 -1
- package/dist/live/server-actions/index.d.ts +2 -2
- package/dist/live/server-actions/index.d.ts.map +1 -1
- package/dist/parseTags.d.ts +80 -82
- package/dist/parseTags.d.ts.map +1 -1
- package/dist/studio/client-component/index.d.ts +9 -9
- package/dist/studio/client-component/index.d.ts.map +1 -1
- package/dist/studio/index.d.ts +36 -38
- package/dist/studio/index.d.ts.map +1 -1
- package/dist/studio/index.js.map +1 -1
- package/dist/types.d.ts +189 -189
- package/dist/types.d.ts.map +1 -1
- package/dist/visual-editing/client-component/index.d.ts +16 -16
- package/dist/visual-editing/client-component/index.d.ts.map +1 -1
- package/dist/visual-editing/index.d.ts +2 -2
- package/dist/visual-editing/index.d.ts.map +1 -1
- package/dist/visual-editing/server-actions/index.d.ts +2 -2
- package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
- package/dist/webhook/index.d.ts +6 -6
- package/dist/webhook/index.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -2,154 +2,154 @@ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
|
2
2
|
import { c as SanityLiveOnError, d as SanityLiveOnRestart, f as SanityLiveOnWelcome, i as LivePerspective, l as SanityLiveOnGoaway, m as StrictDefinedLiveProps, n as DefinedFetchType, o as SanityLiveAction, p as StrictDefinedFetchType, r as DefinedLiveProps, s as SanityLiveContext, t as DefineLiveOptions, u as SanityLiveOnReconnect } from "../../../types.js";
|
|
3
3
|
import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../parseTags.js";
|
|
4
4
|
/**
|
|
5
|
-
* Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`
|
|
6
|
-
* and `<SanityLive />`, which connect your Sanity client to the Live Content API
|
|
7
|
-
* so cached pages can update in response to fine-grained content changes.
|
|
8
|
-
*
|
|
9
|
-
* With `strict: true`, `perspective` and `stega` become required
|
|
10
|
-
* `sanityFetch` options, and `includeDrafts` becomes required on
|
|
11
|
-
* `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`
|
|
12
|
-
* outside `'use cache'` boundaries, then pass them into cached components.
|
|
13
|
-
*
|
|
14
|
-
* @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
|
|
15
|
-
* @see [Sanity Live](https://www.sanity.io/live)
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* // sanity/live.ts
|
|
20
|
-
* import {cookies, draftMode} from 'next/headers'
|
|
21
|
-
* import {createClient} from 'next-sanity'
|
|
22
|
-
* import {
|
|
23
|
-
* defineLive,
|
|
24
|
-
* resolvePerspectiveFromCookies,
|
|
25
|
-
* type LivePerspective,
|
|
26
|
-
* } from 'next-sanity/live'
|
|
27
|
-
*
|
|
28
|
-
* const client = createClient({
|
|
29
|
-
* projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
|
|
30
|
-
* dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
|
|
31
|
-
* useCdn: true,
|
|
32
|
-
* perspective: 'published',
|
|
33
|
-
* })
|
|
34
|
-
* const token = process.env.SANITY_API_READ_TOKEN
|
|
35
|
-
*
|
|
36
|
-
* export const {sanityFetch, SanityLive} = defineLive({
|
|
37
|
-
* client,
|
|
38
|
-
* browserToken: token,
|
|
39
|
-
* serverToken: token,
|
|
40
|
-
* strict: true,
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* export interface DynamicFetchOptions {
|
|
44
|
-
* perspective: LivePerspective
|
|
45
|
-
* stega: boolean
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* // Resolve dynamic values outside 'use cache' boundaries.
|
|
49
|
-
* export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {
|
|
50
|
-
* const {isEnabled: isDraftMode} = await draftMode()
|
|
51
|
-
* if (!isDraftMode) {
|
|
52
|
-
* return {perspective: 'published', stega: false}
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* const jar = await cookies()
|
|
56
|
-
* const perspective = await resolvePerspectiveFromCookies({cookies: jar})
|
|
57
|
-
* return {perspective: perspective ?? 'drafts', stega: true}
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```tsx
|
|
63
|
-
* // app/layout.tsx
|
|
64
|
-
* import {draftMode} from 'next/headers'
|
|
65
|
-
*
|
|
66
|
-
* import {SanityLive} from '@/sanity/live'
|
|
67
|
-
*
|
|
68
|
-
* export default async function RootLayout({children}: {children: React.ReactNode}) {
|
|
69
|
-
* const {isEnabled: isDraftMode} = await draftMode()
|
|
70
|
-
*
|
|
71
|
-
* return (
|
|
72
|
-
* <html lang="en">
|
|
73
|
-
* <body>
|
|
74
|
-
* {children}
|
|
75
|
-
* <SanityLive includeDrafts={isDraftMode} />
|
|
76
|
-
* </body>
|
|
77
|
-
* </html>
|
|
78
|
-
* )
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```tsx
|
|
84
|
-
* // app/[slug]/page.tsx
|
|
85
|
-
* import {draftMode} from 'next/headers'
|
|
86
|
-
* import {Suspense} from 'react'
|
|
87
|
-
* import {defineQuery} from 'next-sanity'
|
|
88
|
-
*
|
|
89
|
-
* import {
|
|
90
|
-
* getDynamicFetchOptions,
|
|
91
|
-
* sanityFetch,
|
|
92
|
-
* type DynamicFetchOptions,
|
|
93
|
-
* } from '@/sanity/live'
|
|
94
|
-
*
|
|
95
|
-
* const POSTS_SLUGS_QUERY = defineQuery(`
|
|
96
|
-
* *[_type == "post" && slug.current]{"slug": slug.current}
|
|
97
|
-
* `)
|
|
98
|
-
* const POST_QUERY = defineQuery(`
|
|
99
|
-
* *[_type == "post" && slug.current == $slug][0]
|
|
100
|
-
* `)
|
|
101
|
-
*
|
|
102
|
-
* export async function generateStaticParams() {
|
|
103
|
-
* const {data} = await sanityFetch({
|
|
104
|
-
* query: POSTS_SLUGS_QUERY,
|
|
105
|
-
* perspective: 'published',
|
|
106
|
-
* stega: false,
|
|
107
|
-
* })
|
|
108
|
-
*
|
|
109
|
-
* return data
|
|
110
|
-
* }
|
|
111
|
-
*
|
|
112
|
-
* export default async function Page(props: PageProps<'/[slug]'>) {
|
|
113
|
-
* const {isEnabled: isDraftMode} = await draftMode()
|
|
114
|
-
* if (isDraftMode) {
|
|
115
|
-
* return (
|
|
116
|
-
* <Suspense fallback={<div>Loading...</div>}>
|
|
117
|
-
* <DynamicPage params={props.params} />
|
|
118
|
-
* </Suspense>
|
|
119
|
-
* )
|
|
120
|
-
* }
|
|
121
|
-
*
|
|
122
|
-
* const {slug} = await props.params
|
|
123
|
-
* return <CachedPage slug={slug} perspective="published" stega={false} />
|
|
124
|
-
* }
|
|
125
|
-
*
|
|
126
|
-
* async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {
|
|
127
|
-
* const {slug} = await props.params
|
|
128
|
-
* const {perspective, stega} = await getDynamicFetchOptions()
|
|
129
|
-
*
|
|
130
|
-
* return <CachedPage slug={slug} perspective={perspective} stega={stega} />
|
|
131
|
-
* }
|
|
132
|
-
*
|
|
133
|
-
* async function CachedPage({
|
|
134
|
-
* slug,
|
|
135
|
-
* perspective,
|
|
136
|
-
* stega,
|
|
137
|
-
* }: {slug: string} & DynamicFetchOptions) {
|
|
138
|
-
* 'use cache'
|
|
139
|
-
*
|
|
140
|
-
* const {data} = await sanityFetch({
|
|
141
|
-
* query: POST_QUERY,
|
|
142
|
-
* params: {slug},
|
|
143
|
-
* perspective,
|
|
144
|
-
* stega,
|
|
145
|
-
* })
|
|
146
|
-
*
|
|
147
|
-
* return <pre>{JSON.stringify(data, null, 2)}</pre>
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*
|
|
151
|
-
* @public
|
|
152
|
-
*/
|
|
5
|
+
* Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`
|
|
6
|
+
* and `<SanityLive />`, which connect your Sanity client to the Live Content API
|
|
7
|
+
* so cached pages can update in response to fine-grained content changes.
|
|
8
|
+
*
|
|
9
|
+
* With `strict: true`, `perspective` and `stega` become required
|
|
10
|
+
* `sanityFetch` options, and `includeDrafts` becomes required on
|
|
11
|
+
* `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`
|
|
12
|
+
* outside `'use cache'` boundaries, then pass them into cached components.
|
|
13
|
+
*
|
|
14
|
+
* @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
|
|
15
|
+
* @see [Sanity Live](https://www.sanity.io/live)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* // sanity/live.ts
|
|
20
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
21
|
+
* import {createClient} from 'next-sanity'
|
|
22
|
+
* import {
|
|
23
|
+
* defineLive,
|
|
24
|
+
* resolvePerspectiveFromCookies,
|
|
25
|
+
* type LivePerspective,
|
|
26
|
+
* } from 'next-sanity/live'
|
|
27
|
+
*
|
|
28
|
+
* const client = createClient({
|
|
29
|
+
* projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
|
|
30
|
+
* dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
|
|
31
|
+
* useCdn: true,
|
|
32
|
+
* perspective: 'published',
|
|
33
|
+
* })
|
|
34
|
+
* const token = process.env.SANITY_API_READ_TOKEN
|
|
35
|
+
*
|
|
36
|
+
* export const {sanityFetch, SanityLive} = defineLive({
|
|
37
|
+
* client,
|
|
38
|
+
* browserToken: token,
|
|
39
|
+
* serverToken: token,
|
|
40
|
+
* strict: true,
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* export interface DynamicFetchOptions {
|
|
44
|
+
* perspective: LivePerspective
|
|
45
|
+
* stega: boolean
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // Resolve dynamic values outside 'use cache' boundaries.
|
|
49
|
+
* export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {
|
|
50
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
51
|
+
* if (!isDraftMode) {
|
|
52
|
+
* return {perspective: 'published', stega: false}
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const jar = await cookies()
|
|
56
|
+
* const perspective = await resolvePerspectiveFromCookies({cookies: jar})
|
|
57
|
+
* return {perspective: perspective ?? 'drafts', stega: true}
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* // app/layout.tsx
|
|
64
|
+
* import {draftMode} from 'next/headers'
|
|
65
|
+
*
|
|
66
|
+
* import {SanityLive} from '@/sanity/live'
|
|
67
|
+
*
|
|
68
|
+
* export default async function RootLayout({children}: {children: React.ReactNode}) {
|
|
69
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
70
|
+
*
|
|
71
|
+
* return (
|
|
72
|
+
* <html lang="en">
|
|
73
|
+
* <body>
|
|
74
|
+
* {children}
|
|
75
|
+
* <SanityLive includeDrafts={isDraftMode} />
|
|
76
|
+
* </body>
|
|
77
|
+
* </html>
|
|
78
|
+
* )
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* // app/[slug]/page.tsx
|
|
85
|
+
* import {draftMode} from 'next/headers'
|
|
86
|
+
* import {Suspense} from 'react'
|
|
87
|
+
* import {defineQuery} from 'next-sanity'
|
|
88
|
+
*
|
|
89
|
+
* import {
|
|
90
|
+
* getDynamicFetchOptions,
|
|
91
|
+
* sanityFetch,
|
|
92
|
+
* type DynamicFetchOptions,
|
|
93
|
+
* } from '@/sanity/live'
|
|
94
|
+
*
|
|
95
|
+
* const POSTS_SLUGS_QUERY = defineQuery(`
|
|
96
|
+
* *[_type == "post" && slug.current]{"slug": slug.current}
|
|
97
|
+
* `)
|
|
98
|
+
* const POST_QUERY = defineQuery(`
|
|
99
|
+
* *[_type == "post" && slug.current == $slug][0]
|
|
100
|
+
* `)
|
|
101
|
+
*
|
|
102
|
+
* export async function generateStaticParams() {
|
|
103
|
+
* const {data} = await sanityFetch({
|
|
104
|
+
* query: POSTS_SLUGS_QUERY,
|
|
105
|
+
* perspective: 'published',
|
|
106
|
+
* stega: false,
|
|
107
|
+
* })
|
|
108
|
+
*
|
|
109
|
+
* return data
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* export default async function Page(props: PageProps<'/[slug]'>) {
|
|
113
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
114
|
+
* if (isDraftMode) {
|
|
115
|
+
* return (
|
|
116
|
+
* <Suspense fallback={<div>Loading...</div>}>
|
|
117
|
+
* <DynamicPage params={props.params} />
|
|
118
|
+
* </Suspense>
|
|
119
|
+
* )
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* const {slug} = await props.params
|
|
123
|
+
* return <CachedPage slug={slug} perspective="published" stega={false} />
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {
|
|
127
|
+
* const {slug} = await props.params
|
|
128
|
+
* const {perspective, stega} = await getDynamicFetchOptions()
|
|
129
|
+
*
|
|
130
|
+
* return <CachedPage slug={slug} perspective={perspective} stega={stega} />
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* async function CachedPage({
|
|
134
|
+
* slug,
|
|
135
|
+
* perspective,
|
|
136
|
+
* stega,
|
|
137
|
+
* }: {slug: string} & DynamicFetchOptions) {
|
|
138
|
+
* 'use cache'
|
|
139
|
+
*
|
|
140
|
+
* const {data} = await sanityFetch({
|
|
141
|
+
* query: POST_QUERY,
|
|
142
|
+
* params: {slug},
|
|
143
|
+
* perspective,
|
|
144
|
+
* stega,
|
|
145
|
+
* })
|
|
146
|
+
*
|
|
147
|
+
* return <pre>{JSON.stringify(data, null, 2)}</pre>
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
153
|
declare function defineLive(config: DefineLiveOptions & {
|
|
154
154
|
strict: true;
|
|
155
155
|
}): {
|
|
@@ -157,86 +157,86 @@ declare function defineLive(config: DefineLiveOptions & {
|
|
|
157
157
|
SanityLive: React.ComponentType<StrictDefinedLiveProps>;
|
|
158
158
|
};
|
|
159
159
|
/**
|
|
160
|
-
* Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,
|
|
161
|
-
* which connect your Sanity client to the Live Content API so pages can serve
|
|
162
|
-
* cached content and update in response to fine-grained content changes.
|
|
163
|
-
*
|
|
164
|
-
* @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
|
|
165
|
-
* @see [Sanity Live](https://www.sanity.io/live)
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```tsx
|
|
169
|
-
* import {createClient} from 'next-sanity'
|
|
170
|
-
* import {defineLive} from 'next-sanity/live'
|
|
171
|
-
*
|
|
172
|
-
* const client = createClient({
|
|
173
|
-
* projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
|
|
174
|
-
* dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
|
|
175
|
-
* useCdn: true,
|
|
176
|
-
* perspective: 'published',
|
|
177
|
-
* })
|
|
178
|
-
* const token = process.env.SANITY_API_READ_TOKEN
|
|
179
|
-
*
|
|
180
|
-
* export const {sanityFetch, SanityLive} = defineLive({
|
|
181
|
-
* client,
|
|
182
|
-
* browserToken: token,
|
|
183
|
-
* serverToken: token,
|
|
184
|
-
* })
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```tsx
|
|
189
|
-
* // app/layout.tsx
|
|
190
|
-
* import {SanityLive} from '@/sanity/live'
|
|
191
|
-
*
|
|
192
|
-
* export default function RootLayout({children}: {children: React.ReactNode}) {
|
|
193
|
-
* return (
|
|
194
|
-
* <html lang="en">
|
|
195
|
-
* <body>
|
|
196
|
-
* {children}
|
|
197
|
-
* <SanityLive />
|
|
198
|
-
* </body>
|
|
199
|
-
* </html>
|
|
200
|
-
* )
|
|
201
|
-
* }
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```tsx
|
|
206
|
-
* // app/[slug]/page.tsx
|
|
207
|
-
* import {defineQuery} from 'next-sanity'
|
|
208
|
-
* import {sanityFetch} from '@/sanity/live'
|
|
209
|
-
*
|
|
210
|
-
* const POSTS_SLUGS_QUERY = defineQuery(`
|
|
211
|
-
* *[_type == "post" && slug.current]{"slug": slug.current}
|
|
212
|
-
* `)
|
|
213
|
-
* const POST_QUERY = defineQuery(`
|
|
214
|
-
* *[_type == "post" && slug.current == $slug][0]
|
|
215
|
-
* `)
|
|
216
|
-
*
|
|
217
|
-
* export async function generateStaticParams() {
|
|
218
|
-
* const {data} = await sanityFetch({
|
|
219
|
-
* query: POSTS_SLUGS_QUERY,
|
|
220
|
-
* perspective: 'published',
|
|
221
|
-
* stega: false,
|
|
222
|
-
* })
|
|
223
|
-
*
|
|
224
|
-
* return data
|
|
225
|
-
* }
|
|
226
|
-
*
|
|
227
|
-
* export default async function Page(props: PageProps<'/[slug]'>) {
|
|
228
|
-
* const {slug} = await props.params
|
|
229
|
-
* const {data} = await sanityFetch({
|
|
230
|
-
* query: POST_QUERY,
|
|
231
|
-
* params: {slug},
|
|
232
|
-
* })
|
|
233
|
-
*
|
|
234
|
-
* return <pre>{JSON.stringify(data, null, 2)}</pre>
|
|
235
|
-
* }
|
|
236
|
-
* ```
|
|
237
|
-
*
|
|
238
|
-
* @public
|
|
239
|
-
*/
|
|
160
|
+
* Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,
|
|
161
|
+
* which connect your Sanity client to the Live Content API so pages can serve
|
|
162
|
+
* cached content and update in response to fine-grained content changes.
|
|
163
|
+
*
|
|
164
|
+
* @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)
|
|
165
|
+
* @see [Sanity Live](https://www.sanity.io/live)
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```tsx
|
|
169
|
+
* import {createClient} from 'next-sanity'
|
|
170
|
+
* import {defineLive} from 'next-sanity/live'
|
|
171
|
+
*
|
|
172
|
+
* const client = createClient({
|
|
173
|
+
* projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
|
|
174
|
+
* dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
|
|
175
|
+
* useCdn: true,
|
|
176
|
+
* perspective: 'published',
|
|
177
|
+
* })
|
|
178
|
+
* const token = process.env.SANITY_API_READ_TOKEN
|
|
179
|
+
*
|
|
180
|
+
* export const {sanityFetch, SanityLive} = defineLive({
|
|
181
|
+
* client,
|
|
182
|
+
* browserToken: token,
|
|
183
|
+
* serverToken: token,
|
|
184
|
+
* })
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```tsx
|
|
189
|
+
* // app/layout.tsx
|
|
190
|
+
* import {SanityLive} from '@/sanity/live'
|
|
191
|
+
*
|
|
192
|
+
* export default function RootLayout({children}: {children: React.ReactNode}) {
|
|
193
|
+
* return (
|
|
194
|
+
* <html lang="en">
|
|
195
|
+
* <body>
|
|
196
|
+
* {children}
|
|
197
|
+
* <SanityLive />
|
|
198
|
+
* </body>
|
|
199
|
+
* </html>
|
|
200
|
+
* )
|
|
201
|
+
* }
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```tsx
|
|
206
|
+
* // app/[slug]/page.tsx
|
|
207
|
+
* import {defineQuery} from 'next-sanity'
|
|
208
|
+
* import {sanityFetch} from '@/sanity/live'
|
|
209
|
+
*
|
|
210
|
+
* const POSTS_SLUGS_QUERY = defineQuery(`
|
|
211
|
+
* *[_type == "post" && slug.current]{"slug": slug.current}
|
|
212
|
+
* `)
|
|
213
|
+
* const POST_QUERY = defineQuery(`
|
|
214
|
+
* *[_type == "post" && slug.current == $slug][0]
|
|
215
|
+
* `)
|
|
216
|
+
*
|
|
217
|
+
* export async function generateStaticParams() {
|
|
218
|
+
* const {data} = await sanityFetch({
|
|
219
|
+
* query: POSTS_SLUGS_QUERY,
|
|
220
|
+
* perspective: 'published',
|
|
221
|
+
* stega: false,
|
|
222
|
+
* })
|
|
223
|
+
*
|
|
224
|
+
* return data
|
|
225
|
+
* }
|
|
226
|
+
*
|
|
227
|
+
* export default async function Page(props: PageProps<'/[slug]'>) {
|
|
228
|
+
* const {slug} = await props.params
|
|
229
|
+
* const {data} = await sanityFetch({
|
|
230
|
+
* query: POST_QUERY,
|
|
231
|
+
* params: {slug},
|
|
232
|
+
* })
|
|
233
|
+
*
|
|
234
|
+
* return <pre>{JSON.stringify(data, null, 2)}</pre>
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
240
|
declare function defineLive(config: DefineLiveOptions & {
|
|
241
241
|
strict?: false;
|
|
242
242
|
}): {
|
|
@@ -244,64 +244,64 @@ declare function defineLive(config: DefineLiveOptions & {
|
|
|
244
244
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
245
245
|
};
|
|
246
246
|
/**
|
|
247
|
-
* This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
|
|
248
|
-
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
249
|
-
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```tsx
|
|
253
|
-
* import {cookies, draftMode} from 'next/headers'
|
|
254
|
-
* import {defineQuery} from 'next-sanity'
|
|
255
|
-
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
256
|
-
* import {sanityFetch, sanityFetchStaticParams} from '#sanity/live'
|
|
257
|
-
*
|
|
258
|
-
* export async function generateStaticParams() {
|
|
259
|
-
* const query = defineQuery(`*[_type == "page" && defined(slug.current)]{"slug": slug.current}`)
|
|
260
|
-
* return await sanityFetchStaticParams({query})
|
|
261
|
-
* }
|
|
262
|
-
*
|
|
263
|
-
* export default async function Page({params}: PageProps<'/[slug]'>) {
|
|
264
|
-
* const {isEnabled: isDraftMode} = await draftMode()
|
|
265
|
-
*
|
|
266
|
-
* if (isDraftMode) {
|
|
267
|
-
* return (
|
|
268
|
-
* <Suspense>
|
|
269
|
-
* <DynamicPage params={params} />
|
|
270
|
-
* </Suspense>
|
|
271
|
-
* )
|
|
272
|
-
* }
|
|
273
|
-
*
|
|
274
|
-
* const {slug} = await params
|
|
275
|
-
*
|
|
276
|
-
* return <CachedPage slug={slug} perspective="published" stega={false} />
|
|
277
|
-
* }
|
|
278
|
-
*
|
|
279
|
-
* async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {
|
|
280
|
-
* const {slug} = await params
|
|
281
|
-
* const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
282
|
-
*
|
|
283
|
-
* return <CachedPage slug={slug} perspective={perspective} stega />
|
|
284
|
-
* }
|
|
285
|
-
*
|
|
286
|
-
* async function CachedPage({
|
|
287
|
-
* slug,
|
|
288
|
-
* perspective,
|
|
289
|
-
* stega,
|
|
290
|
-
* }: Awaited<PageProps<'/[slug]'>['params']> & {
|
|
291
|
-
* perspective: LivePerspective
|
|
292
|
-
* stega: boolean
|
|
293
|
-
* }) {
|
|
294
|
-
* 'use cache'
|
|
295
|
-
*
|
|
296
|
-
* const query = defineQuery(`*[_type == "page" && slug.current == $slug][0]`)
|
|
297
|
-
* const {data} = await sanityFetch({query, params: {slug}, perspective, stega})
|
|
298
|
-
*
|
|
299
|
-
* return <article>...</article>
|
|
300
|
-
* }
|
|
301
|
-
* ```
|
|
302
|
-
*
|
|
303
|
-
* @public
|
|
304
|
-
*/
|
|
247
|
+
* This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
|
|
248
|
+
* where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
|
|
249
|
+
* Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```tsx
|
|
253
|
+
* import {cookies, draftMode} from 'next/headers'
|
|
254
|
+
* import {defineQuery} from 'next-sanity'
|
|
255
|
+
* import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
|
|
256
|
+
* import {sanityFetch, sanityFetchStaticParams} from '#sanity/live'
|
|
257
|
+
*
|
|
258
|
+
* export async function generateStaticParams() {
|
|
259
|
+
* const query = defineQuery(`*[_type == "page" && defined(slug.current)]{"slug": slug.current}`)
|
|
260
|
+
* return await sanityFetchStaticParams({query})
|
|
261
|
+
* }
|
|
262
|
+
*
|
|
263
|
+
* export default async function Page({params}: PageProps<'/[slug]'>) {
|
|
264
|
+
* const {isEnabled: isDraftMode} = await draftMode()
|
|
265
|
+
*
|
|
266
|
+
* if (isDraftMode) {
|
|
267
|
+
* return (
|
|
268
|
+
* <Suspense>
|
|
269
|
+
* <DynamicPage params={params} />
|
|
270
|
+
* </Suspense>
|
|
271
|
+
* )
|
|
272
|
+
* }
|
|
273
|
+
*
|
|
274
|
+
* const {slug} = await params
|
|
275
|
+
*
|
|
276
|
+
* return <CachedPage slug={slug} perspective="published" stega={false} />
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {
|
|
280
|
+
* const {slug} = await params
|
|
281
|
+
* const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
282
|
+
*
|
|
283
|
+
* return <CachedPage slug={slug} perspective={perspective} stega />
|
|
284
|
+
* }
|
|
285
|
+
*
|
|
286
|
+
* async function CachedPage({
|
|
287
|
+
* slug,
|
|
288
|
+
* perspective,
|
|
289
|
+
* stega,
|
|
290
|
+
* }: Awaited<PageProps<'/[slug]'>['params']> & {
|
|
291
|
+
* perspective: LivePerspective
|
|
292
|
+
* stega: boolean
|
|
293
|
+
* }) {
|
|
294
|
+
* 'use cache'
|
|
295
|
+
*
|
|
296
|
+
* const query = defineQuery(`*[_type == "page" && slug.current == $slug][0]`)
|
|
297
|
+
* const {data} = await sanityFetch({query, params: {slug}, perspective, stega})
|
|
298
|
+
*
|
|
299
|
+
* return <article>...</article>
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
305
|
declare const resolvePerspectiveFromCookies: typeof resolvePerspectiveFromCookies$1;
|
|
306
306
|
export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
|
|
307
307
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8JgB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoFrB,sCAAsC"}
|