@sanity/sdk-react 0.0.1 → 0.0.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 (31) hide show
  1. package/README.md +3 -3
  2. package/dist/index.d.ts +364 -287
  3. package/dist/index.js +125 -149
  4. package/dist/index.js.map +1 -1
  5. package/package.json +5 -5
  6. package/src/_exports/sdk-react.ts +10 -10
  7. package/src/hooks/comlink/useWindowConnection.test.tsx +145 -0
  8. package/src/hooks/comlink/useWindowConnection.ts +32 -30
  9. package/src/hooks/{comlink → dashboard}/useManageFavorite.test.ts +84 -134
  10. package/src/hooks/{comlink → dashboard}/useManageFavorite.ts +4 -39
  11. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +2 -73
  12. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +20 -27
  13. package/src/hooks/dashboard/useRecordDocumentHistoryEvent.test.ts +69 -0
  14. package/src/hooks/{comlink → dashboard}/useRecordDocumentHistoryEvent.ts +17 -10
  15. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +14 -85
  16. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +33 -8
  17. package/src/hooks/document/useApplyDocumentActions.ts +4 -4
  18. package/src/hooks/document/useDocument.test.ts +8 -10
  19. package/src/hooks/document/useDocument.ts +50 -33
  20. package/src/hooks/document/useDocumentEvent.ts +2 -2
  21. package/src/hooks/document/useDocumentSyncStatus.ts +1 -1
  22. package/src/hooks/document/useEditDocument.ts +15 -15
  23. package/src/hooks/documents/useDocuments.ts +5 -5
  24. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +5 -5
  25. package/src/hooks/preview/{usePreview.test.tsx → useDocumentPreview.test.tsx} +5 -5
  26. package/src/hooks/preview/{usePreview.tsx → useDocumentPreview.tsx} +11 -8
  27. package/src/hooks/projection/{useProjection.test.tsx → useDocumentProjection.test.tsx} +5 -5
  28. package/src/hooks/projection/{useProjection.ts → useDocumentProjection.ts} +22 -17
  29. package/src/hooks/query/useQuery.ts +5 -5
  30. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +0 -85
  31. package/src/hooks/comlink/useWindowConnection.test.ts +0 -135
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ import {ReleaseDocument} from '@sanity/sdk'
27
27
  import {SanityClient} from '@sanity/client'
28
28
  import {SanityConfig} from '@sanity/sdk'
29
29
  import {SanityDocument} from '@sanity/types'
30
- import {SanityDocumentResult} from 'groq'
30
+ import {SanityDocument as SanityDocument_2} from 'groq'
31
31
  import {SanityInstance} from '@sanity/sdk'
32
32
  import {SanityProject} from '@sanity/sdk'
33
33
  import {SanityProject as SanityProject_2} from '@sanity/client'
@@ -133,13 +133,12 @@ export {DatasetsResponse}
133
133
 
134
134
  declare interface DocumentInteractionHistory {
135
135
  recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
136
- isConnected: boolean
137
136
  }
138
137
 
139
138
  /**
140
139
  * Configuration options for the useDocuments hook
141
140
  *
142
- * @beta
141
+ * @public
143
142
  * @category Types
144
143
  */
145
144
  export declare interface DocumentsOptions<
@@ -173,7 +172,7 @@ export declare interface DocumentsOptions<
173
172
  /**
174
173
  * Return value from the useDocuments hook
175
174
  *
176
- * @beta
175
+ * @public
177
176
  * @category Types
178
177
  */
179
178
  export declare interface DocumentsResponse<
@@ -237,7 +236,6 @@ declare interface ManageFavorite extends FavoriteStatusResponse {
237
236
  favorite: () => Promise<void>
238
237
  unfavorite: () => Promise<void>
239
238
  isFavorited: boolean
240
- isConnected: boolean
241
239
  }
242
240
 
243
241
  /**
@@ -258,13 +256,12 @@ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
258
256
  */
259
257
  export declare interface NavigateToStudioResult {
260
258
  navigateToStudioDocument: () => void
261
- isConnected: boolean
262
259
  }
263
260
 
264
261
  /**
265
262
  * Configuration options for the usePaginatedDocuments hook
266
263
  *
267
- * @beta
264
+ * @public
268
265
  * @category Types
269
266
  */
270
267
  export declare interface PaginatedDocumentsOptions<
@@ -294,7 +291,7 @@ export declare interface PaginatedDocumentsOptions<
294
291
  /**
295
292
  * Return value from the usePaginatedDocuments hook
296
293
  *
297
- * @beta
294
+ * @public
298
295
  * @category Types
299
296
  */
300
297
  export declare interface PaginatedDocumentsResponse<
@@ -559,7 +556,6 @@ export {SortOrderingItem}
559
556
  declare interface StudioWorkspacesResult {
560
557
  workspacesByProjectIdAndDataset: WorkspacesByProjectIdDataset
561
558
  error: string | null
562
- isConnected: boolean
563
559
  }
564
560
 
565
561
  declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
@@ -589,7 +585,7 @@ declare type UseActiveReleases = {
589
585
  export declare const useActiveReleases: UseActiveReleases
590
586
 
591
587
  /**
592
- * @beta
588
+ * @public
593
589
  */
594
590
  declare interface UseApplyDocumentActions {
595
591
  (): <
@@ -601,11 +597,11 @@ declare interface UseApplyDocumentActions {
601
597
  | DocumentAction<TDocumentType, TDataset, TProjectId>
602
598
  | DocumentAction<TDocumentType, TDataset, TProjectId>[],
603
599
  options?: ApplyDocumentActionsOptions,
604
- ) => Promise<ActionsResult<SanityDocumentResult<TDocumentType, TDataset, TProjectId>>>
600
+ ) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
605
601
  }
606
602
 
607
603
  /**
608
- * @beta
604
+ * @public
609
605
  *
610
606
  * Provides a stable callback function for applying one or more document actions.
611
607
  *
@@ -844,7 +840,9 @@ declare interface UseDocument {
844
840
  /** @internal */
845
841
  <TDocumentType extends string, TDataset extends string, TProjectId extends string = string>(
846
842
  options: DocumentOptions<undefined, TDocumentType, TDataset, TProjectId>,
847
- ): SanityDocumentResult<TDocumentType, TDataset, TProjectId> | null
843
+ ): {
844
+ data: SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`> | null
845
+ }
848
846
  /** @internal */
849
847
  <
850
848
  TPath extends string,
@@ -853,15 +851,21 @@ declare interface UseDocument {
853
851
  TProjectId extends string = string,
854
852
  >(
855
853
  options: DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
856
- ): JsonMatch<SanityDocumentResult<TDocumentType, TDataset, TProjectId>, TPath> | undefined
854
+ ): {
855
+ data: JsonMatch<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>, TPath> | undefined
856
+ }
857
857
  /** @internal */
858
- <TData>(options: DocumentOptions<undefined>): TData | null
858
+ <TData>(options: DocumentOptions<undefined>): {
859
+ data: TData | null
860
+ }
859
861
  /** @internal */
860
- <TData>(options: DocumentOptions<string>): TData | undefined
862
+ <TData>(options: DocumentOptions<string>): {
863
+ data: TData | undefined
864
+ }
861
865
  /**
862
866
  * ## useDocument via Type Inference (Recommended)
863
867
  *
864
- * @beta
868
+ * @public
865
869
  *
866
870
  * The preferred way to use this hook when working with Sanity Typegen.
867
871
  *
@@ -896,7 +900,7 @@ declare interface UseDocument {
896
900
  * }
897
901
  *
898
902
  * function ProductView({doc}: ProductViewProps) {
899
- * const product = useDocument({...doc}) // Fully typed product
903
+ * const {data: product} = useDocument({...doc}) // Fully typed product
900
904
  * return <h1>{product.title ?? 'Untitled'}</h1>
901
905
  * }
902
906
  * ```
@@ -910,7 +914,7 @@ declare interface UseDocument {
910
914
  * }
911
915
  *
912
916
  * function ProductTitle({doc}: ProductTitleProps) {
913
- * const title = useDocument({
917
+ * const {data: title} = useDocument({
914
918
  * ...doc,
915
919
  * path: 'title' // Returns just the title field
916
920
  * })
@@ -928,10 +932,16 @@ declare interface UseDocument {
928
932
  >(
929
933
  options: DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
930
934
  ): TPath extends string
931
- ? JsonMatch<SanityDocumentResult<TDocumentType, TDataset, TProjectId>, TPath> | undefined
932
- : SanityDocumentResult<TDocumentType, TDataset, TProjectId> | null
935
+ ? {
936
+ data:
937
+ | JsonMatch<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>, TPath>
938
+ | undefined
939
+ }
940
+ : {
941
+ data: SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`> | null
942
+ }
933
943
  /**
934
- * @beta
944
+ * @public
935
945
  *
936
946
  * ## useDocument via Explicit Types
937
947
  *
@@ -969,7 +979,7 @@ declare interface UseDocument {
969
979
  * }
970
980
  *
971
981
  * function BookView({doc}: BookViewProps) {
972
- * const book = useDocument<Book>({...doc})
982
+ * const {data: book} = useDocument<Book>({...doc})
973
983
  * return <h1>{book?.title ?? 'Untitled'} by {book?.author ?? 'Unknown'}</h1>
974
984
  * }
975
985
  * ```
@@ -983,7 +993,7 @@ declare interface UseDocument {
983
993
  * }
984
994
  *
985
995
  * function BookTitle({doc}: BookTitleProps) {
986
- * const title = useDocument<string>({...doc, path: 'title'})
996
+ * const {data: title} = useDocument<string>({...doc, path: 'title'})
987
997
  * return <h1>{title ?? 'Untitled'}</h1>
988
998
  * }
989
999
  * ```
@@ -992,15 +1002,23 @@ declare interface UseDocument {
992
1002
  */
993
1003
  <TData, TPath extends string>(
994
1004
  options: DocumentOptions<TPath>,
995
- ): TPath extends string ? TData | undefined : TData | null
1005
+ ): TPath extends string
1006
+ ? {
1007
+ data: TData | undefined
1008
+ }
1009
+ : {
1010
+ data: TData | null
1011
+ }
996
1012
  /**
997
1013
  * @internal
998
1014
  */
999
- (options: DocumentOptions): unknown
1015
+ (options: DocumentOptions): {
1016
+ data: unknown
1017
+ }
1000
1018
  }
1001
1019
 
1002
1020
  /**
1003
- * @beta
1021
+ * @public
1004
1022
  * Reads and subscribes to a document's realtime state, incorporating both local and remote changes.
1005
1023
  *
1006
1024
  * This hook comes in two main flavors to suit your needs:
@@ -1017,7 +1035,7 @@ declare interface UseDocument {
1017
1035
  * - Realtime updates aren't critical
1018
1036
  * - You want better performance
1019
1037
  *
1020
- * …consider using {@link useProjection} or {@link useQuery} instead. These hooks are more efficient
1038
+ * …consider using {@link useDocumentProjection} or {@link useQuery} instead. These hooks are more efficient
1021
1039
  * for read-heavy applications.
1022
1040
  *
1023
1041
  * @function
@@ -1026,7 +1044,7 @@ export declare const useDocument: UseDocument
1026
1044
 
1027
1045
  /**
1028
1046
  *
1029
- * @beta
1047
+ * @public
1030
1048
  *
1031
1049
  * Subscribes an event handler to events in your application's document store.
1032
1050
  *
@@ -1085,7 +1103,7 @@ export declare function useDocumentEvent<
1085
1103
  >(options: UseDocumentEventOptions<TDataset, TProjectId>): void
1086
1104
 
1087
1105
  /**
1088
- * @beta
1106
+ * @public
1089
1107
  */
1090
1108
  declare interface UseDocumentEventOptions<
1091
1109
  TDataset extends string = string,
@@ -1175,12 +1193,246 @@ export declare function useDocumentPermissions(
1175
1193
  actionOrActions: DocumentAction | DocumentAction[],
1176
1194
  ): DocumentPermissionsResult
1177
1195
 
1196
+ /**
1197
+ * @public
1198
+ *
1199
+ * Returns the preview values of a document (specified via a `DocumentHandle`),
1200
+ * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
1201
+ * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
1202
+ * resolution will only occur if the `ref` is intersecting the current viewport.
1203
+ *
1204
+ * @category Documents
1205
+ * @param options - The document handle for the document you want to resolve preview values for, and an optional ref
1206
+ * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
1207
+ *
1208
+ * @example Combining with useDocuments to render a collection of document previews
1209
+ * ```
1210
+ * // PreviewComponent.jsx
1211
+ * export default function PreviewComponent({ document }) {
1212
+ * const { data: { title, subtitle, media }, isPending } = useDocumentPreview({ document })
1213
+ * return (
1214
+ * <article style={{ opacity: isPending ? 0.5 : 1}}>
1215
+ * {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
1216
+ * <h2>{title}</h2>
1217
+ * <p>{subtitle}</p>
1218
+ * </article>
1219
+ * )
1220
+ * }
1221
+ *
1222
+ * // DocumentList.jsx
1223
+ * const { data } = useDocuments({ filter: '_type == "movie"' })
1224
+ * return (
1225
+ * <div>
1226
+ * <h1>Movies</h1>
1227
+ * <ul>
1228
+ * {data.map(movie => (
1229
+ * <li key={movie._id}>
1230
+ * <Suspense fallback='Loading…'>
1231
+ * <PreviewComponent document={movie} />
1232
+ * </Suspense>
1233
+ * </li>
1234
+ * ))}
1235
+ * </ul>
1236
+ * </div>
1237
+ * )
1238
+ * ```
1239
+ */
1240
+ export declare function useDocumentPreview({
1241
+ ref,
1242
+ ...docHandle
1243
+ }: useDocumentPreviewOptions): useDocumentPreviewResults
1244
+
1245
+ /**
1246
+ * @public
1247
+ * @category Types
1248
+ */
1249
+ export declare interface useDocumentPreviewOptions extends DocumentHandle {
1250
+ /**
1251
+ * Optional ref object to track visibility. When provided, preview resolution
1252
+ * only occurs when the referenced element is visible in the viewport.
1253
+ */
1254
+ ref?: React.RefObject<unknown>
1255
+ }
1256
+
1257
+ /**
1258
+ * @public
1259
+ * @category Types
1260
+ */
1261
+ export declare interface useDocumentPreviewResults {
1262
+ /** The results of resolving the document’s preview values */
1263
+ data: PreviewValue
1264
+ /** True when preview values are being refreshed */
1265
+ isPending: boolean
1266
+ }
1267
+
1268
+ /**
1269
+ * @public
1270
+ *
1271
+ * Returns the projected values of a document based on the provided projection string.
1272
+ * These values are live and will update in realtime.
1273
+ * To optimize network requests, an optional `ref` can be passed to only resolve the projection
1274
+ * when the referenced element is intersecting the viewport.
1275
+ *
1276
+ * @category Documents
1277
+ * @remarks
1278
+ * This hook has multiple signatures allowing for fine-grained control over type inference:
1279
+ * - Using Typegen: Infers the return type based on the `documentType`, `dataset`, `projectId`, and `projection`.
1280
+ * - Using explicit type parameter: Allows specifying a custom return type `TData`.
1281
+ *
1282
+ * @param options - An object containing the `DocumentHandle` properties (`documentId`, `documentType`, etc.), the `projection` string, optional `params`, and an optional `ref`.
1283
+ * @returns An object containing the projection results (`data`) and a boolean indicating whether the resolution is pending (`isPending`). Note: Suspense handles initial loading states; `data` being `undefined` after initial loading means the document doesn't exist or the projection yielded no result.
1284
+ */
1285
+ /**
1286
+ * @public
1287
+ * Fetch a projection, relying on Typegen for the return type based on the handle and projection.
1288
+ *
1289
+ * @category Documents
1290
+ * @param options - Options including the document handle properties (`documentId`, `documentType`, etc.) and the `projection`.
1291
+ * @returns The projected data, typed based on Typegen.
1292
+ *
1293
+ * @example Using Typegen for a book preview
1294
+ * ```tsx
1295
+ * // ProjectionComponent.tsx
1296
+ * import {useDocumentProjection, type DocumentHandle} from '@sanity/sdk-react'
1297
+ * import {useRef} from 'react'
1298
+ * import {defineProjection} from 'groq'
1299
+ *
1300
+ * // Define props using DocumentHandle with the specific document type
1301
+ * type ProjectionComponentProps = {
1302
+ * doc: DocumentHandle<'book'> // Typegen knows 'book'
1303
+ * }
1304
+ *
1305
+ * // This is required for typegen to generate the correct return type
1306
+ * const myProjection = defineProjection(`{
1307
+ * title,
1308
+ * 'coverImage': cover.asset->url,
1309
+ * 'authors': array::join(authors[]->{'name': firstName + ' ' + lastName}.name, ', ')
1310
+ * }`)
1311
+ *
1312
+ * export default function ProjectionComponent({ doc }: ProjectionComponentProps) {
1313
+ * const ref = useRef(null) // Optional ref to track viewport intersection for lazy loading
1314
+ *
1315
+ * // Spread the doc handle into the options
1316
+ * // Typegen infers the return type based on 'book' and the projection
1317
+ * const { data } = useDocumentProjection({
1318
+ * ...doc, // Pass the handle properties
1319
+ * ref,
1320
+ * projection: myProjection,
1321
+ * })
1322
+ *
1323
+ * // Suspense handles initial load, check for data existence after
1324
+ * return (
1325
+ * <article ref={ref}>
1326
+ * <h2>{data.title ?? 'Untitled'}</h2>
1327
+ * {data.coverImage && <img src={data.coverImage} alt={data.title} />}
1328
+ * <p>{data.authors ?? 'Unknown authors'}</p>
1329
+ * </article>
1330
+ * )
1331
+ * }
1332
+ *
1333
+ * // Usage:
1334
+ * // import {createDocumentHandle} from '@sanity/sdk-react'
1335
+ * // const myDocHandle = createDocumentHandle({ documentId: 'book123', documentType: 'book' })
1336
+ * // <Suspense fallback='Loading preview...'>
1337
+ * // <ProjectionComponent doc={myDocHandle} />
1338
+ * // </Suspense>
1339
+ * ```
1340
+ */
1341
+ export declare function useDocumentProjection<
1342
+ TProjection extends ValidProjection = ValidProjection,
1343
+ TDocumentType extends string = string,
1344
+ TDataset extends string = string,
1345
+ TProjectId extends string = string,
1346
+ >(
1347
+ options: useDocumentProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>,
1348
+ ): useDocumentProjectionResults<
1349
+ SanityProjectionResult<TProjection, TDocumentType, `${TProjectId}.${TDataset}`>
1350
+ >
1351
+
1352
+ /**
1353
+ * @public
1354
+ * Fetch a projection with an explicitly defined return type `TData`.
1355
+ *
1356
+ * @param options - Options including the document handle properties (`documentId`, etc.) and the `projection`.
1357
+ * @returns The projected data, cast to the explicit type `TData`.
1358
+ *
1359
+ * @example Explicitly typing the projection result
1360
+ * ```tsx
1361
+ * import {useDocumentProjection, type DocumentHandle} from '@sanity/sdk-react'
1362
+ * import {useRef} from 'react'
1363
+ *
1364
+ * interface SimpleBookPreview {
1365
+ * title?: string;
1366
+ * authorName?: string;
1367
+ * }
1368
+ *
1369
+ * type BookPreviewProps = {
1370
+ * doc: DocumentHandle
1371
+ * }
1372
+ *
1373
+ * function BookPreview({ doc }: BookPreviewProps) {
1374
+ * const ref = useRef(null)
1375
+ * const { data } = useDocumentProjection<SimpleBookPreview>({
1376
+ * ...doc,
1377
+ * ref,
1378
+ * projection: `{ title, 'authorName': author->name }`
1379
+ * })
1380
+ *
1381
+ * return (
1382
+ * <div ref={ref}>
1383
+ * <h3>{data.title ?? 'No Title'}</h3>
1384
+ * <p>By: {data.authorName ?? 'Unknown'}</p>
1385
+ * </div>
1386
+ * )
1387
+ * }
1388
+ *
1389
+ * // Usage:
1390
+ * // import {createDocumentHandle} from '@sanity/sdk-react'
1391
+ * // const doc = createDocumentHandle({ documentId: 'abc', documentType: 'book' })
1392
+ * // <Suspense fallback='Loading...'>
1393
+ * // <BookPreview doc={doc} />
1394
+ * // </Suspense>
1395
+ * ```
1396
+ */
1397
+ export declare function useDocumentProjection<TData extends object>(
1398
+ options: useDocumentProjectionOptions,
1399
+ ): useDocumentProjectionResults<TData>
1400
+
1401
+ /**
1402
+ * @public
1403
+ * @category Types
1404
+ */
1405
+ export declare interface useDocumentProjectionOptions<
1406
+ TProjection extends ValidProjection = ValidProjection,
1407
+ TDocumentType extends string = string,
1408
+ TDataset extends string = string,
1409
+ TProjectId extends string = string,
1410
+ > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1411
+ /** The GROQ projection string */
1412
+ projection: TProjection
1413
+ /** Optional parameters for the projection query */
1414
+ params?: Record<string, unknown>
1415
+ /** Optional ref to track viewport intersection for lazy loading */
1416
+ ref?: React.RefObject<unknown>
1417
+ }
1418
+
1419
+ /**
1420
+ * @public
1421
+ * @category Types
1422
+ */
1423
+ export declare interface useDocumentProjectionResults<TData> {
1424
+ /** The projected data */
1425
+ data: TData
1426
+ /** True if the projection is currently being resolved */
1427
+ isPending: boolean
1428
+ }
1429
+
1178
1430
  /**
1179
1431
  * Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
1180
1432
  * with infinite scrolling support. The number of document handles returned per batch is customizable,
1181
1433
  * and additional batches can be loaded using the supplied `loadMore` function.
1182
1434
  *
1183
- * @beta
1435
+ * @public
1184
1436
  * @category Documents
1185
1437
  * @param options - Configuration options for the infinite list
1186
1438
  * @returns An object containing the list of document handles, the loading state, the total count of retrieved document handles, and a function to load more
@@ -1201,9 +1453,9 @@ export declare function useDocumentPermissions(
1201
1453
  * } from '@sanity/sdk-react'
1202
1454
  * import {Suspense} from 'react'
1203
1455
  *
1204
- * // Define a component to display a single document (using useProjection for efficiency)
1456
+ * // Define a component to display a single document (using useDocumentProjection for efficiency)
1205
1457
  * function MyDocumentComponent({doc}: {doc: DocumentHandle}) {
1206
- * const {data} = useProjection<{title?: string}>({
1458
+ * const {data} = useDocumentProjection<{title?: string}>({
1207
1459
  * ...doc, // Pass the full handle
1208
1460
  * projection: '{title}'
1209
1461
  * })
@@ -1339,13 +1591,13 @@ declare type UseDocumentSyncStatus = {
1339
1591
  }
1340
1592
 
1341
1593
  /**
1342
- * @beta
1594
+ * @public
1343
1595
  * @function
1344
1596
  */
1345
1597
  export declare const useDocumentSyncStatus: UseDocumentSyncStatus
1346
1598
 
1347
1599
  /**
1348
- * @beta
1600
+ * @public
1349
1601
  * Edit an entire document, relying on Typegen for the type.
1350
1602
  *
1351
1603
  * @param options - Document options including `documentId`, `documentType`, and optionally `projectId`/`dataset`.
@@ -1359,11 +1611,11 @@ export declare function useEditDocument<
1359
1611
  >(
1360
1612
  options: DocumentOptions<undefined, TDocumentType, TDataset, TProjectId>,
1361
1613
  ): (
1362
- nextValue: Updater<SanityDocumentResult<TDocumentType, TDataset, TProjectId>>,
1363
- ) => Promise<ActionsResult<SanityDocumentResult<TDocumentType, TDataset, TProjectId>>>
1614
+ nextValue: Updater<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>,
1615
+ ) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
1364
1616
 
1365
1617
  /**
1366
- * @beta
1618
+ * @public
1367
1619
  * Edit a specific path within a document, relying on Typegen for the type.
1368
1620
  *
1369
1621
  * @param options - Document options including `documentId`, `documentType`, `path`, and optionally `projectId`/`dataset`.
@@ -1378,11 +1630,13 @@ export declare function useEditDocument<
1378
1630
  >(
1379
1631
  options: DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
1380
1632
  ): (
1381
- nextValue: Updater<JsonMatch<SanityDocumentResult<TDocumentType, TDataset, TProjectId>, TPath>>,
1382
- ) => Promise<ActionsResult<SanityDocumentResult<TDocumentType, TDataset, TProjectId>>>
1633
+ nextValue: Updater<
1634
+ JsonMatch<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>, TPath>
1635
+ >,
1636
+ ) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
1383
1637
 
1384
1638
  /**
1385
- * @beta
1639
+ * @public
1386
1640
  * Edit an entire document with an explicit type `TData`.
1387
1641
  *
1388
1642
  * @param options - Document options including `documentId` and optionally `projectId`/`dataset`.
@@ -1394,7 +1648,7 @@ export declare function useEditDocument<TData>(
1394
1648
  ): (nextValue: Updater<TData>) => Promise<ActionsResult>
1395
1649
 
1396
1650
  /**
1397
- * @beta
1651
+ * @public
1398
1652
  * Edit a specific path within a document with an explicit type `TData`.
1399
1653
  *
1400
1654
  * @param options - Document options including `documentId`, `path`, and optionally `projectId`/`dataset`.
@@ -1577,16 +1831,28 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
1577
1831
  * - `isConnected` - Boolean indicating if connection to Dashboard is established
1578
1832
  *
1579
1833
  * @example
1580
- * ```ts
1834
+ * ```tsx
1581
1835
  * import {useNavigateToStudioDocument, type DocumentHandle} from '@sanity/sdk-react'
1836
+ * import {Button} from '@sanity/ui'
1837
+ * import {Suspense} from 'react'
1582
1838
  *
1583
- * function MyComponent({documentHandle}: {documentHandle: DocumentHandle}) {
1839
+ * function NavigateButton({documentHandle}: {documentHandle: DocumentHandle}) {
1584
1840
  * const {navigateToStudioDocument, isConnected} = useNavigateToStudioDocument(documentHandle)
1841
+ * return (
1842
+ * <Button
1843
+ * disabled={!isConnected}
1844
+ * onClick={navigateToStudioDocument}
1845
+ * text="Navigate to Studio Document"
1846
+ * />
1847
+ * )
1848
+ * }
1585
1849
  *
1850
+ * // Wrap the component with Suspense since the hook may suspend
1851
+ * function MyDocumentAction({documentHandle}: {documentHandle: DocumentHandle}) {
1586
1852
  * return (
1587
- * <button onClick={navigateToStudioDocument} disabled={!isConnected}>
1588
- * Navigate to Studio Document
1589
- * </button>
1853
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
1854
+ * <NavigateButton documentHandle={documentHandle} />
1855
+ * </Suspense>
1590
1856
  * )
1591
1857
  * }
1592
1858
  * ```
@@ -1601,7 +1867,7 @@ export declare function useNavigateToStudioDocument(
1601
1867
  * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
1602
1868
  * while page navigation is handled via the included navigation functions.
1603
1869
  *
1604
- * @beta
1870
+ * @public
1605
1871
  * @category Documents
1606
1872
  * @param options - Configuration options for the paginated list
1607
1873
  * @returns An object containing the list of document handles, pagination details, and functions to navigate between pages
@@ -1619,14 +1885,14 @@ export declare function useNavigateToStudioDocument(
1619
1885
  * type DatasetHandle,
1620
1886
  * type DocumentHandle,
1621
1887
  * type SortOrderingItem,
1622
- * useProjection
1888
+ * useDocumentProjection
1623
1889
  * } from '@sanity/sdk-react'
1624
1890
  * import {Suspense} from 'react'
1625
1891
  * import {ErrorBoundary} from 'react-error-boundary'
1626
1892
  *
1627
1893
  * // Define a component to display a single document row
1628
1894
  * function MyTableRowComponent({doc}: {doc: DocumentHandle}) {
1629
- * const {data} = useProjection<{title?: string}>({
1895
+ * const {data} = useDocumentProjection<{title?: string}>({
1630
1896
  * ...doc,
1631
1897
  * projection: '{title}',
1632
1898
  * })
@@ -1740,75 +2006,6 @@ declare type UsePerspective = {
1740
2006
  */
1741
2007
  export declare const usePerspective: UsePerspective
1742
2008
 
1743
- /**
1744
- * @beta
1745
- *
1746
- * Returns the preview values of a document (specified via a `DocumentHandle`),
1747
- * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
1748
- * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
1749
- * resolution will only occur if the `ref` is intersecting the current viewport.
1750
- *
1751
- * @category Documents
1752
- * @param options - The document handle for the document you want to resolve preview values for, and an optional ref
1753
- * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
1754
- *
1755
- * @example Combining with useDocuments to render a collection of document previews
1756
- * ```
1757
- * // PreviewComponent.jsx
1758
- * export default function PreviewComponent({ document }) {
1759
- * const { data: { title, subtitle, media }, isPending } = usePreview({ document })
1760
- * return (
1761
- * <article style={{ opacity: isPending ? 0.5 : 1}}>
1762
- * {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
1763
- * <h2>{title}</h2>
1764
- * <p>{subtitle}</p>
1765
- * </article>
1766
- * )
1767
- * }
1768
- *
1769
- * // DocumentList.jsx
1770
- * const { data } = useDocuments({ filter: '_type == "movie"' })
1771
- * return (
1772
- * <div>
1773
- * <h1>Movies</h1>
1774
- * <ul>
1775
- * {data.map(movie => (
1776
- * <li key={movie._id}>
1777
- * <Suspense fallback='Loading…'>
1778
- * <PreviewComponent document={movie} />
1779
- * </Suspense>
1780
- * </li>
1781
- * ))}
1782
- * </ul>
1783
- * </div>
1784
- * )
1785
- * ```
1786
- */
1787
- export declare function usePreview({ref, ...docHandle}: UsePreviewOptions): UsePreviewResults
1788
-
1789
- /**
1790
- * @beta
1791
- * @category Types
1792
- */
1793
- export declare interface UsePreviewOptions extends DocumentHandle {
1794
- /**
1795
- * Optional ref object to track visibility. When provided, preview resolution
1796
- * only occurs when the referenced element is visible in the viewport.
1797
- */
1798
- ref?: React.RefObject<unknown>
1799
- }
1800
-
1801
- /**
1802
- * @beta
1803
- * @category Types
1804
- */
1805
- export declare interface UsePreviewResults {
1806
- /** The results of resolving the document’s preview values */
1807
- data: PreviewValue
1808
- /** True when preview values are being refreshed */
1809
- isPending: boolean
1810
- }
1811
-
1812
2009
  declare type UseProject = {
1813
2010
  /**
1814
2011
  *
@@ -1839,166 +2036,6 @@ declare type UseProject = {
1839
2036
  */
1840
2037
  export declare const useProject: UseProject
1841
2038
 
1842
- /**
1843
- * @public
1844
- *
1845
- * Returns the projected values of a document based on the provided projection string.
1846
- * These values are live and will update in realtime.
1847
- * To optimize network requests, an optional `ref` can be passed to only resolve the projection
1848
- * when the referenced element is intersecting the viewport.
1849
- *
1850
- * @category Documents
1851
- * @remarks
1852
- * This hook has multiple signatures allowing for fine-grained control over type inference:
1853
- * - Using Typegen: Infers the return type based on the `documentType`, `dataset`, `projectId`, and `projection`.
1854
- * - Using explicit type parameter: Allows specifying a custom return type `TData`.
1855
- *
1856
- * @param options - An object containing the `DocumentHandle` properties (`documentId`, `documentType`, etc.), the `projection` string, optional `params`, and an optional `ref`.
1857
- * @returns An object containing the projection results (`data`) and a boolean indicating whether the resolution is pending (`isPending`). Note: Suspense handles initial loading states; `data` being `undefined` after initial loading means the document doesn't exist or the projection yielded no result.
1858
- */
1859
- /**
1860
- * @beta
1861
- * Fetch a projection, relying on Typegen for the return type based on the handle and projection.
1862
- *
1863
- * @category Documents
1864
- * @param options - Options including the document handle properties (`documentId`, `documentType`, etc.) and the `projection`.
1865
- * @returns The projected data, typed based on Typegen.
1866
- *
1867
- * @example Using Typegen for a book preview
1868
- * ```tsx
1869
- * // ProjectionComponent.tsx
1870
- * import {useProjection, type DocumentHandle} from '@sanity/sdk-react'
1871
- * import {useRef} from 'react'
1872
- * import {defineProjection} from 'groq'
1873
- *
1874
- * // Define props using DocumentHandle with the specific document type
1875
- * type ProjectionComponentProps = {
1876
- * doc: DocumentHandle<'book'> // Typegen knows 'book'
1877
- * }
1878
- *
1879
- * // This is required for typegen to generate the correct return type
1880
- * const myProjection = defineProjection(`{
1881
- * title,
1882
- * 'coverImage': cover.asset->url,
1883
- * 'authors': array::join(authors[]->{'name': firstName + ' ' + lastName}.name, ', ')
1884
- * }`)
1885
- *
1886
- * export default function ProjectionComponent({ doc }: ProjectionComponentProps) {
1887
- * const ref = useRef(null) // Optional ref to track viewport intersection for lazy loading
1888
- *
1889
- * // Spread the doc handle into the options
1890
- * // Typegen infers the return type based on 'book' and the projection
1891
- * const { data } = useProjection({
1892
- * ...doc, // Pass the handle properties
1893
- * ref,
1894
- * projection: myProjection,
1895
- * })
1896
- *
1897
- * // Suspense handles initial load, check for data existence after
1898
- * return (
1899
- * <article ref={ref}>
1900
- * <h2>{data.title ?? 'Untitled'}</h2>
1901
- * {data.coverImage && <img src={data.coverImage} alt={data.title} />}
1902
- * <p>{data.authors ?? 'Unknown authors'}</p>
1903
- * </article>
1904
- * )
1905
- * }
1906
- *
1907
- * // Usage:
1908
- * // import {createDocumentHandle} from '@sanity/sdk-react'
1909
- * // const myDocHandle = createDocumentHandle({ documentId: 'book123', documentType: 'book' })
1910
- * // <Suspense fallback='Loading preview...'>
1911
- * // <ProjectionComponent doc={myDocHandle} />
1912
- * // </Suspense>
1913
- * ```
1914
- */
1915
- export declare function useProjection<
1916
- TProjection extends ValidProjection = ValidProjection,
1917
- TDocumentType extends string = string,
1918
- TDataset extends string = string,
1919
- TProjectId extends string = string,
1920
- >(
1921
- options: UseProjectionOptions<TProjection, TDocumentType, TDataset, TProjectId>,
1922
- ): UseProjectionResults<SanityProjectionResult<TProjection, TDocumentType, TDataset, TProjectId>>
1923
-
1924
- /**
1925
- * @beta
1926
- * Fetch a projection with an explicitly defined return type `TData`.
1927
- *
1928
- * @param options - Options including the document handle properties (`documentId`, etc.) and the `projection`.
1929
- * @returns The projected data, cast to the explicit type `TData`.
1930
- *
1931
- * @example Explicitly typing the projection result
1932
- * ```tsx
1933
- * import {useProjection, type DocumentHandle} from '@sanity/sdk-react'
1934
- * import {useRef} from 'react'
1935
- *
1936
- * interface SimpleBookPreview {
1937
- * title?: string;
1938
- * authorName?: string;
1939
- * }
1940
- *
1941
- * type BookPreviewProps = {
1942
- * doc: DocumentHandle
1943
- * }
1944
- *
1945
- * function BookPreview({ doc }: BookPreviewProps) {
1946
- * const ref = useRef(null)
1947
- * const { data } = useProjection<SimpleBookPreview>({
1948
- * ...doc,
1949
- * ref,
1950
- * projection: `{ title, 'authorName': author->name }`
1951
- * })
1952
- *
1953
- * return (
1954
- * <div ref={ref}>
1955
- * <h3>{data.title ?? 'No Title'}</h3>
1956
- * <p>By: {data.authorName ?? 'Unknown'}</p>
1957
- * </div>
1958
- * )
1959
- * }
1960
- *
1961
- * // Usage:
1962
- * // import {createDocumentHandle} from '@sanity/sdk-react'
1963
- * // const doc = createDocumentHandle({ documentId: 'abc', documentType: 'book' })
1964
- * // <Suspense fallback='Loading...'>
1965
- * // <BookPreview doc={doc} />
1966
- * // </Suspense>
1967
- * ```
1968
- */
1969
- export declare function useProjection<TData extends object>(
1970
- options: UseProjectionOptions,
1971
- ): UseProjectionResults<TData>
1972
-
1973
- /**
1974
- * @public
1975
- * @category Types
1976
- */
1977
- export declare interface UseProjectionOptions<
1978
- TProjection extends ValidProjection = ValidProjection,
1979
- TDocumentType extends string = string,
1980
- TDataset extends string = string,
1981
- TProjectId extends string = string,
1982
- > extends DocumentHandle<TDocumentType, TDataset, TProjectId> {
1983
- /** The GROQ projection string */
1984
- projection: TProjection
1985
- /** Optional parameters for the projection query */
1986
- params?: Record<string, unknown>
1987
- /** Optional ref to track viewport intersection for lazy loading */
1988
- ref?: React.RefObject<unknown>
1989
- }
1990
-
1991
- /**
1992
- * @public
1993
- * @category Types
1994
- */
1995
- export declare interface UseProjectionResults<TData> {
1996
- /** The projected data */
1997
- data: TData
1998
- /** True if the projection is currently being resolved */
1999
- isPending: boolean
2000
- }
2001
-
2002
2039
  declare type UseProjects = {
2003
2040
  /**
2004
2041
  *
@@ -2029,7 +2066,7 @@ declare type UseProjects = {
2029
2066
  export declare const useProjects: UseProjects
2030
2067
 
2031
2068
  /**
2032
- * @beta
2069
+ * @public
2033
2070
  * Executes a GROQ query, inferring the result type from the query string and options.
2034
2071
  * Leverages Sanity Typegen if configured for enhanced type safety.
2035
2072
  *
@@ -2091,13 +2128,13 @@ export declare function useQuery<
2091
2128
  options: QueryOptions<TQuery, TDataset, TProjectId>,
2092
2129
  ): {
2093
2130
  /** The query result, typed based on the GROQ query string */
2094
- data: SanityQueryResult<TQuery, TDataset, TProjectId>
2131
+ data: SanityQueryResult<TQuery, `${TProjectId}.${TDataset}`>
2095
2132
  /** True if a query transition is in progress */
2096
2133
  isPending: boolean
2097
2134
  }
2098
2135
 
2099
2136
  /**
2100
- * @beta
2137
+ * @public
2101
2138
  * Executes a GROQ query with an explicitly provided result type `TData`.
2102
2139
  *
2103
2140
  * @param options - Configuration for the query, including `query`, optional `params`, `projectId`, `dataset`, etc.
@@ -2143,7 +2180,11 @@ export declare function useQuery<TData>(options: QueryOptions): {
2143
2180
  *
2144
2181
  * @example
2145
2182
  * ```tsx
2146
- * function MyDocumentAction(props: DocumentActionProps) {
2183
+ * import {useRecordDocumentHistoryEvent} from '@sanity/sdk-react'
2184
+ * import {Button} from '@sanity/ui'
2185
+ * import {Suspense} from 'react'
2186
+ *
2187
+ * function RecordEventButton(props: DocumentActionProps) {
2147
2188
  * const {documentId, documentType, resourceType, resourceId} = props
2148
2189
  * const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
2149
2190
  * documentId,
@@ -2151,15 +2192,23 @@ export declare function useQuery<TData>(options: QueryOptions): {
2151
2192
  * resourceType,
2152
2193
  * resourceId,
2153
2194
  * })
2154
- *
2155
2195
  * return (
2156
2196
  * <Button
2157
2197
  * disabled={!isConnected}
2158
2198
  * onClick={() => recordEvent('viewed')}
2159
- * text={'Viewed'}
2199
+ * text="Viewed"
2160
2200
  * />
2161
2201
  * )
2162
2202
  * }
2203
+ *
2204
+ * // Wrap the component with Suspense since the hook may suspend
2205
+ * function MyDocumentAction(props: DocumentActionProps) {
2206
+ * return (
2207
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
2208
+ * <RecordEventButton {...props} />
2209
+ * </Suspense>
2210
+ * )
2211
+ * }
2163
2212
  * ```
2164
2213
  */
2165
2214
  export declare function useRecordDocumentHistoryEvent({
@@ -2265,6 +2314,36 @@ export declare const useSanityInstance: (config?: SanityConfig) => SanityInstanc
2265
2314
  /**
2266
2315
  * Hook that fetches studio workspaces and organizes them by projectId:dataset
2267
2316
  * @internal
2317
+ *
2318
+ * @example
2319
+ * ```tsx
2320
+ * import {useStudioWorkspacesByProjectIdDataset} from '@sanity/sdk-react'
2321
+ * import {Card, Code, Button} from '@sanity/ui'
2322
+ * import {Suspense} from 'react'
2323
+ *
2324
+ * function WorkspacesCard() {
2325
+ * const {workspacesByProjectIdAndDataset, error} = useStudioWorkspacesByProjectIdDataset()
2326
+ * if (error) {
2327
+ * return <div>Error: {error}</div>
2328
+ * }
2329
+ * return (
2330
+ * <Card padding={4} radius={2} shadow={1}>
2331
+ * <Code language="json">
2332
+ * {JSON.stringify(workspacesByProjectIdAndDataset, null, 2)}
2333
+ * </Code>
2334
+ * </Card>
2335
+ * )
2336
+ * }
2337
+ *
2338
+ * // Wrap the component with Suspense since the hook may suspend
2339
+ * function DashboardWorkspaces() {
2340
+ * return (
2341
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
2342
+ * <WorkspacesCard />
2343
+ * </Suspense>
2344
+ * )
2345
+ * }
2346
+ * ```
2268
2347
  */
2269
2348
  export declare function useStudioWorkspacesByProjectIdDataset(): StudioWorkspacesResult
2270
2349
 
@@ -2343,7 +2422,6 @@ export declare function useWindowConnection<
2343
2422
  name,
2344
2423
  connectTo,
2345
2424
  onMessage,
2346
- onStatus,
2347
2425
  }: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage>
2348
2426
 
2349
2427
  /**
@@ -2353,7 +2431,6 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
2353
2431
  name: string
2354
2432
  connectTo: string
2355
2433
  onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
2356
- onStatus?: (status: ComlinkStatus) => void
2357
2434
  }
2358
2435
 
2359
2436
  /**