@sanity/sdk-react 2.8.0 → 2.10.0
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/index.d.ts +232 -47
- package/dist/index.js +468 -263
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
- package/src/_exports/sdk-react.ts +5 -0
- package/src/components/SDKProvider.tsx +36 -8
- package/src/components/SanityApp.tsx +3 -2
- package/src/components/auth/AuthBoundary.tsx +8 -1
- package/src/components/auth/DashboardAccessRequest.tsx +37 -0
- package/src/components/auth/LoginError.test.tsx +191 -5
- package/src/components/auth/LoginError.tsx +100 -56
- package/src/components/errors/ChunkLoadError.test.tsx +59 -0
- package/src/components/errors/ChunkLoadError.tsx +56 -0
- package/src/components/errors/chunkReloadStorage.ts +57 -0
- package/src/context/ResourceProvider.test.tsx +7 -1
- package/src/context/ResourceProvider.tsx +11 -4
- package/src/context/ResourcesContext.tsx +7 -0
- package/src/context/SDKStudioContext.ts +6 -0
- package/src/context/SanityInstanceProvider.test.tsx +100 -0
- package/src/context/SanityInstanceProvider.tsx +71 -0
- package/src/hooks/auth/useVerifyOrgProjects.tsx +13 -6
- package/src/hooks/dashboard/useDispatchIntent.test.ts +8 -6
- package/src/hooks/dashboard/useDispatchIntent.ts +6 -6
- package/src/hooks/dashboard/useWindowTitle.test.ts +213 -0
- package/src/hooks/dashboard/useWindowTitle.ts +112 -0
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.test.ts +15 -15
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +13 -13
- package/src/hooks/document/useApplyDocumentActions.test.ts +113 -10
- package/src/hooks/document/useApplyDocumentActions.ts +99 -3
- package/src/hooks/document/useDocument.ts +22 -6
- package/src/hooks/document/useDocumentEvent.test.tsx +3 -3
- package/src/hooks/document/useDocumentEvent.ts +10 -3
- package/src/hooks/document/useDocumentPermissions.test.tsx +86 -2
- package/src/hooks/document/useDocumentPermissions.ts +22 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +13 -2
- package/src/hooks/document/useDocumentSyncStatus.ts +14 -5
- package/src/hooks/document/useEditDocument.ts +34 -8
- package/src/hooks/documents/useDocuments.ts +11 -6
- package/src/hooks/helpers/useNormalizedResourceOptions.ts +131 -0
- package/src/hooks/helpers/useTrackHookUsage.ts +37 -0
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +11 -8
- package/src/hooks/presence/usePresence.test.tsx +56 -9
- package/src/hooks/presence/usePresence.ts +25 -4
- package/src/hooks/preview/useDocumentPreview.test.tsx +84 -193
- package/src/hooks/preview/useDocumentPreview.tsx +40 -55
- package/src/hooks/projection/useDocumentProjection.ts +8 -6
- package/src/hooks/query/useQuery.ts +12 -9
- package/src/hooks/releases/useActiveReleases.ts +32 -13
- package/src/hooks/releases/usePerspective.ts +26 -14
- package/src/hooks/users/useUser.ts +2 -0
- package/src/hooks/users/useUsers.ts +2 -0
- package/src/context/SourcesContext.tsx +0 -7
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -85
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {DocumentEvent} from '@sanity/sdk'
|
|
|
19
19
|
import {DocumentHandle} from '@sanity/sdk'
|
|
20
20
|
import {DocumentOptions} from '@sanity/sdk'
|
|
21
21
|
import {DocumentPermissionsResult} from '@sanity/sdk'
|
|
22
|
-
import {
|
|
22
|
+
import {DocumentResource} from '@sanity/sdk'
|
|
23
23
|
import {FallbackProps} from 'react-error-boundary'
|
|
24
24
|
import {FavoriteStatusResponse} from '@sanity/sdk'
|
|
25
25
|
import {FrameMessage} from '@sanity/sdk'
|
|
@@ -28,7 +28,6 @@ import {GetUsersOptions} from '@sanity/sdk'
|
|
|
28
28
|
import {JsonMatch} from '@sanity/sdk'
|
|
29
29
|
import {MediaResource} from '@sanity/message-protocol'
|
|
30
30
|
import {PathChangeMessage} from '@sanity/message-protocol'
|
|
31
|
-
import {PerspectiveHandle} from '@sanity/sdk'
|
|
32
31
|
import {PreviewValue} from '@sanity/sdk'
|
|
33
32
|
import {ProjectHandle} from '@sanity/sdk'
|
|
34
33
|
import {PropsWithChildren} from 'react'
|
|
@@ -606,13 +605,74 @@ export declare interface SanityAppProps {
|
|
|
606
605
|
config?: SanityConfig | SanityConfig[]
|
|
607
606
|
/** @deprecated use the `config` prop instead. */
|
|
608
607
|
sanityConfigs?: SanityConfig[]
|
|
609
|
-
|
|
608
|
+
resources?: Record<string, DocumentResource>
|
|
610
609
|
children: React.ReactNode
|
|
611
610
|
fallback: React.ReactNode
|
|
612
611
|
}
|
|
613
612
|
|
|
614
613
|
export {SanityDocument}
|
|
615
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Provides an externally-created Sanity instance to child components through React Context.
|
|
617
|
+
*
|
|
618
|
+
* @internal
|
|
619
|
+
*
|
|
620
|
+
* @remarks
|
|
621
|
+
* Unlike {@link ResourceProvider}, this component does not create or dispose a SanityInstance.
|
|
622
|
+
* The caller is responsible for creating the instance via `createSanityInstance` and disposing
|
|
623
|
+
* it when appropriate. This is useful when a non-React system layer (e.g. a state machine)
|
|
624
|
+
* owns the instance and the React tree should consume it without managing its lifecycle.
|
|
625
|
+
*
|
|
626
|
+
* All SDK hooks (`useSanityInstance`, `useDocuments`, etc.) will read from the provided instance.
|
|
627
|
+
*
|
|
628
|
+
* @example Providing a pre-created instance
|
|
629
|
+
* ```tsx
|
|
630
|
+
* import { createSanityInstance, type SanityConfig } from '@sanity/sdk'
|
|
631
|
+
* import { SanityInstanceProvider } from '@sanity/sdk-react'
|
|
632
|
+
*
|
|
633
|
+
* const config: SanityConfig = {
|
|
634
|
+
* projectId: 'my-project-id',
|
|
635
|
+
* dataset: 'production',
|
|
636
|
+
* }
|
|
637
|
+
*
|
|
638
|
+
* const instance = createSanityInstance(config)
|
|
639
|
+
*
|
|
640
|
+
* function App() {
|
|
641
|
+
* return (
|
|
642
|
+
* <SanityInstanceProvider instance={instance} fallback={<div>Loading...</div>}>
|
|
643
|
+
* <MyApp />
|
|
644
|
+
* </SanityInstanceProvider>
|
|
645
|
+
* )
|
|
646
|
+
* }
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* @category Components
|
|
650
|
+
*/
|
|
651
|
+
export declare function SanityInstanceProvider({
|
|
652
|
+
instance,
|
|
653
|
+
fallback,
|
|
654
|
+
children,
|
|
655
|
+
}: SanityInstanceProviderProps): React.ReactNode
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Props for the SanityInstanceProvider component
|
|
659
|
+
* @public
|
|
660
|
+
*/
|
|
661
|
+
export declare interface SanityInstanceProviderProps {
|
|
662
|
+
/**
|
|
663
|
+
* A pre-created SanityInstance to provide to child components.
|
|
664
|
+
* The caller owns the instance lifecycle — SanityInstanceProvider
|
|
665
|
+
* will not dispose it on unmount.
|
|
666
|
+
*/
|
|
667
|
+
instance: SanityInstance
|
|
668
|
+
/**
|
|
669
|
+
* React node to show while content is loading.
|
|
670
|
+
* Used as the fallback for the internal Suspense boundary.
|
|
671
|
+
*/
|
|
672
|
+
fallback: React.ReactNode
|
|
673
|
+
children: React.ReactNode
|
|
674
|
+
}
|
|
675
|
+
|
|
616
676
|
export {SanityProjectMember}
|
|
617
677
|
|
|
618
678
|
/**
|
|
@@ -636,7 +696,7 @@ export declare interface SDKProviderProps extends AuthBoundaryProps {
|
|
|
636
696
|
children: ReactNode
|
|
637
697
|
config: SanityConfig | SanityConfig[]
|
|
638
698
|
fallback: ReactNode
|
|
639
|
-
|
|
699
|
+
resources?: Record<string, DocumentResource>
|
|
640
700
|
}
|
|
641
701
|
|
|
642
702
|
/**
|
|
@@ -689,6 +749,12 @@ export declare interface StudioWorkspaceHandle {
|
|
|
689
749
|
projectId: string
|
|
690
750
|
/** The dataset name for this workspace. */
|
|
691
751
|
dataset: string
|
|
752
|
+
/**
|
|
753
|
+
* Whether the Studio has determined the user is authenticated.
|
|
754
|
+
* When `true` and the token source emits `null`, the SDK infers
|
|
755
|
+
* cookie-based auth is in use and skips the logged-out state.
|
|
756
|
+
*/
|
|
757
|
+
authenticated?: boolean
|
|
692
758
|
/** Authentication state for this workspace. */
|
|
693
759
|
auth: {
|
|
694
760
|
/**
|
|
@@ -723,13 +789,6 @@ declare interface Subscription {
|
|
|
723
789
|
|
|
724
790
|
declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
|
|
725
791
|
|
|
726
|
-
/**
|
|
727
|
-
* @public
|
|
728
|
-
*/
|
|
729
|
-
declare type UseActiveReleases = {
|
|
730
|
-
(): ReleaseDocument[]
|
|
731
|
-
}
|
|
732
|
-
|
|
733
792
|
/**
|
|
734
793
|
* @public
|
|
735
794
|
|
|
@@ -745,6 +804,14 @@ declare type UseActiveReleases = {
|
|
|
745
804
|
* const activeReleases = useActiveReleases()
|
|
746
805
|
* ```
|
|
747
806
|
*/
|
|
807
|
+
declare type UseActiveReleases = {
|
|
808
|
+
(options?: WithResourceNameSupport<SanityConfig> | undefined): ReleaseDocument[]
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* @public
|
|
813
|
+
* @function
|
|
814
|
+
*/
|
|
748
815
|
export declare const useActiveReleases: UseActiveReleases
|
|
749
816
|
|
|
750
817
|
/**
|
|
@@ -1280,7 +1347,7 @@ declare interface UseApplyDocumentActions {
|
|
|
1280
1347
|
action:
|
|
1281
1348
|
| DocumentAction<TDocumentType, TDataset, TProjectId>
|
|
1282
1349
|
| DocumentAction<TDocumentType, TDataset, TProjectId>[],
|
|
1283
|
-
options?: ApplyDocumentActionsOptions
|
|
1350
|
+
options?: WithResourceNameSupport<ApplyDocumentActionsOptions>,
|
|
1284
1351
|
) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
|
|
1285
1352
|
}
|
|
1286
1353
|
|
|
@@ -1406,6 +1473,66 @@ declare interface UseApplyDocumentActions {
|
|
|
1406
1473
|
* return <button onClick={handleCreateArticle}>Create Article</button>
|
|
1407
1474
|
* }
|
|
1408
1475
|
* ```
|
|
1476
|
+
*
|
|
1477
|
+
* @example Create a new document in a release
|
|
1478
|
+
* ```tsx
|
|
1479
|
+
* import {
|
|
1480
|
+
* createDocument,
|
|
1481
|
+
* createDocumentHandle,
|
|
1482
|
+
* useApplyDocumentActions
|
|
1483
|
+
* } from '@sanity/sdk-react'
|
|
1484
|
+
*
|
|
1485
|
+
* function CreateArticleButton() {
|
|
1486
|
+
* const apply = useApplyDocumentActions()
|
|
1487
|
+
*
|
|
1488
|
+
* const handleCreateArticle = () => {
|
|
1489
|
+
* // Use any valid document ID — not the internal `versions.<releaseName>.<id>` format or "drafts.<id>" format.
|
|
1490
|
+
* // New documents must be explicitly created with `createDocument` to become part of a release.
|
|
1491
|
+
* const newDocHandle = createDocumentHandle({
|
|
1492
|
+
* documentId: crypto.randomUUID(), // or the existing document ID you want to make a release version of
|
|
1493
|
+
* documentType: 'article',
|
|
1494
|
+
* perspective: {releaseName: 'summer-drop'},
|
|
1495
|
+
* })
|
|
1496
|
+
*
|
|
1497
|
+
* apply(
|
|
1498
|
+
* createDocument(newDocHandle, {
|
|
1499
|
+
* title: 'New Article',
|
|
1500
|
+
* author: 'John Doe',
|
|
1501
|
+
* publishedAt: new Date().toISOString(),
|
|
1502
|
+
* })
|
|
1503
|
+
* )
|
|
1504
|
+
* }
|
|
1505
|
+
*
|
|
1506
|
+
* return <button onClick={handleCreateArticle}>Create Article</button>
|
|
1507
|
+
* }
|
|
1508
|
+
* ```
|
|
1509
|
+
*
|
|
1510
|
+
* @example Edit an existing document in a release
|
|
1511
|
+
* ```tsx
|
|
1512
|
+
* import {
|
|
1513
|
+
* editDocument,
|
|
1514
|
+
* createDocumentHandle,
|
|
1515
|
+
* useApplyDocumentActions
|
|
1516
|
+
* } from '@sanity/sdk-react'
|
|
1517
|
+
*
|
|
1518
|
+
* function EditArticleInReleaseButton({documentId}: {documentId: string}) {
|
|
1519
|
+
* const apply = useApplyDocumentActions()
|
|
1520
|
+
*
|
|
1521
|
+
* const handleEdit = () => {
|
|
1522
|
+
* // Pass the document's regular ID — not `versions.<releaseName>.<id>`.
|
|
1523
|
+
* // Documents that already have a version in the release can be edited directly with `editDocument`.
|
|
1524
|
+
* const docHandle = createDocumentHandle({
|
|
1525
|
+
* documentId,
|
|
1526
|
+
* documentType: 'article',
|
|
1527
|
+
* perspective: {releaseName: 'summer-drop'},
|
|
1528
|
+
* })
|
|
1529
|
+
*
|
|
1530
|
+
* apply(editDocument(docHandle, {title: 'Updated for release'}))
|
|
1531
|
+
* }
|
|
1532
|
+
*
|
|
1533
|
+
* return <button onClick={handleEdit}>Edit in Release</button>
|
|
1534
|
+
* }
|
|
1535
|
+
* ```
|
|
1409
1536
|
*/
|
|
1410
1537
|
export declare const useApplyDocumentActions: UseApplyDocumentActions
|
|
1411
1538
|
|
|
@@ -1608,8 +1735,8 @@ export declare const useDatasets: UseDatasets
|
|
|
1608
1735
|
* - `action` - Action to perform (currently only 'edit' is supported). Will prompt a picker if multiple handlers are available.
|
|
1609
1736
|
* - `intentId` - Specific ID of the intent to dispatch. Either `action` or `intentId` is required.
|
|
1610
1737
|
* - `documentHandle` - The document handle containing document ID, type, and either:
|
|
1611
|
-
* - `projectId` and `dataset` for traditional dataset
|
|
1612
|
-
* - `
|
|
1738
|
+
* - `projectId` and `dataset` for traditional dataset resources, like `{documentId: '123', documentType: 'book', projectId: 'abc123', dataset: 'production'}`
|
|
1739
|
+
* - `resource` for media library, canvas, or dataset resources, like `{documentId: '123', documentType: 'sanity.asset', resource: mediaLibrarySource('ml123')}` or `{documentId: '123', documentType: 'sanity.canvas.document', resource: canvasSource('canvas123')}`
|
|
1613
1740
|
* - `paremeters` - Optional parameters to include in the dispatch; will be passed to the resolved intent handler
|
|
1614
1741
|
* @returns An object containing:
|
|
1615
1742
|
* - `dispatchIntent` - Function to dispatch the intent message
|
|
@@ -1658,14 +1785,14 @@ export declare function useDispatchIntent(params: UseDispatchIntentParams): Disp
|
|
|
1658
1785
|
declare interface UseDispatchIntentParams {
|
|
1659
1786
|
action?: 'edit'
|
|
1660
1787
|
intentId?: string
|
|
1661
|
-
documentHandle:
|
|
1788
|
+
documentHandle: WithResourceNameSupport<DocumentHandle>
|
|
1662
1789
|
parameters?: Record<string, unknown>
|
|
1663
1790
|
}
|
|
1664
1791
|
|
|
1665
1792
|
declare interface UseDocument {
|
|
1666
1793
|
/** @internal */
|
|
1667
1794
|
<TDocumentType extends string, TDataset extends string, TProjectId extends string = string>(
|
|
1668
|
-
options:
|
|
1795
|
+
options: UseDocumentOptions<undefined, TDocumentType, TDataset, TProjectId>,
|
|
1669
1796
|
): {
|
|
1670
1797
|
data: SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`> | null
|
|
1671
1798
|
}
|
|
@@ -1676,7 +1803,7 @@ declare interface UseDocument {
|
|
|
1676
1803
|
TDataset extends string = string,
|
|
1677
1804
|
TProjectId extends string = string,
|
|
1678
1805
|
>(
|
|
1679
|
-
options:
|
|
1806
|
+
options: UseDocumentOptions<TPath, TDocumentType>,
|
|
1680
1807
|
): {
|
|
1681
1808
|
data: JsonMatch<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>, TPath> | undefined
|
|
1682
1809
|
}
|
|
@@ -1756,7 +1883,7 @@ declare interface UseDocument {
|
|
|
1756
1883
|
TDataset extends string = string,
|
|
1757
1884
|
TProjectId extends string = string,
|
|
1758
1885
|
>(
|
|
1759
|
-
options:
|
|
1886
|
+
options: UseDocumentOptions<TPath, TDocumentType>,
|
|
1760
1887
|
): TPath extends string
|
|
1761
1888
|
? {
|
|
1762
1889
|
data:
|
|
@@ -1827,7 +1954,7 @@ declare interface UseDocument {
|
|
|
1827
1954
|
* @inlineType DocumentOptions
|
|
1828
1955
|
*/
|
|
1829
1956
|
<TData, TPath extends string>(
|
|
1830
|
-
options:
|
|
1957
|
+
options: UseDocumentOptions<TPath>,
|
|
1831
1958
|
): TPath extends string
|
|
1832
1959
|
? {
|
|
1833
1960
|
data: TData | undefined
|
|
@@ -1838,7 +1965,7 @@ declare interface UseDocument {
|
|
|
1838
1965
|
/**
|
|
1839
1966
|
* @internal
|
|
1840
1967
|
*/
|
|
1841
|
-
(options:
|
|
1968
|
+
(options: UseDocumentOptions): {
|
|
1842
1969
|
data: unknown
|
|
1843
1970
|
}
|
|
1844
1971
|
}
|
|
@@ -1938,6 +2065,13 @@ declare interface UseDocumentEventOptions<
|
|
|
1938
2065
|
onEvent: (documentEvent: DocumentEvent) => void
|
|
1939
2066
|
}
|
|
1940
2067
|
|
|
2068
|
+
declare type UseDocumentOptions<
|
|
2069
|
+
TPath extends string | undefined = undefined,
|
|
2070
|
+
TDocumentType extends string = string,
|
|
2071
|
+
TDataset extends string = string,
|
|
2072
|
+
TProjectId extends string = string,
|
|
2073
|
+
> = WithResourceNameSupport<DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>>
|
|
2074
|
+
|
|
1941
2075
|
/**
|
|
1942
2076
|
*
|
|
1943
2077
|
* @public
|
|
@@ -2023,7 +2157,7 @@ export declare function useDocumentPermissions(
|
|
|
2023
2157
|
* @public
|
|
2024
2158
|
*
|
|
2025
2159
|
* Attempts to infer preview values of a document (specified via a `DocumentHandle`),
|
|
2026
|
-
* including the document
|
|
2160
|
+
* including the document's `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
|
|
2027
2161
|
* To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
|
|
2028
2162
|
* resolution will only occur if the `ref` is intersecting the current viewport.
|
|
2029
2163
|
*
|
|
@@ -2032,9 +2166,13 @@ export declare function useDocumentPermissions(
|
|
|
2032
2166
|
* @remarks
|
|
2033
2167
|
* Values returned by this hook may not be as expected. It is currently unable to read preview values as defined in your schema;
|
|
2034
2168
|
* instead, it attempts to infer these preview values by checking against a basic set of potential fields on your document.
|
|
2035
|
-
* We are anticipating being able to significantly improve this hook
|
|
2169
|
+
* We are anticipating being able to significantly improve this hook's functionality and output in a future release.
|
|
2036
2170
|
* For now, we recommend using {@link useDocumentProjection} for rendering individual document fields (or projections of those fields).
|
|
2037
2171
|
*
|
|
2172
|
+
* Internally, this hook is implemented as a specialized projection with post-processing logic.
|
|
2173
|
+
* It uses a fixed GROQ projection to fetch common preview fields (title, subtitle, media) and
|
|
2174
|
+
* transforms the results into the PreviewValue format.
|
|
2175
|
+
*
|
|
2038
2176
|
* @category Documents
|
|
2039
2177
|
* @param options - The document handle for the document you want to infer preview values for, and an optional ref
|
|
2040
2178
|
* @returns The inferred values for the given document and a boolean to indicate whether the resolution is pending
|
|
@@ -2080,7 +2218,7 @@ export declare function useDocumentPreview({
|
|
|
2080
2218
|
* @public
|
|
2081
2219
|
* @category Types
|
|
2082
2220
|
*/
|
|
2083
|
-
export declare interface useDocumentPreviewOptions extends DocumentHandle {
|
|
2221
|
+
export declare interface useDocumentPreviewOptions extends WithResourceNameSupport<DocumentHandle> {
|
|
2084
2222
|
/**
|
|
2085
2223
|
* Optional ref object to track visibility. When provided, preview resolution
|
|
2086
2224
|
* only occurs when the referenced element is visible in the viewport.
|
|
@@ -2093,7 +2231,7 @@ export declare interface useDocumentPreviewOptions extends DocumentHandle {
|
|
|
2093
2231
|
* @category Types
|
|
2094
2232
|
*/
|
|
2095
2233
|
export declare interface useDocumentPreviewResults {
|
|
2096
|
-
/** The results of inferring the document
|
|
2234
|
+
/** The results of inferring the document's preview values */
|
|
2097
2235
|
data: PreviewValue
|
|
2098
2236
|
/** True when inferred preview values are being refreshed */
|
|
2099
2237
|
isPending: boolean
|
|
@@ -2241,7 +2379,7 @@ export declare interface useDocumentProjectionOptions<
|
|
|
2241
2379
|
TDocumentType extends string = string,
|
|
2242
2380
|
TDataset extends string = string,
|
|
2243
2381
|
TProjectId extends string = string,
|
|
2244
|
-
> extends
|
|
2382
|
+
> extends WithResourceNameSupport<DocumentHandle<TDocumentType, TDataset, TProjectId>> {
|
|
2245
2383
|
/** The GROQ projection string */
|
|
2246
2384
|
projection: TProjection
|
|
2247
2385
|
/** Optional parameters for the projection query */
|
|
@@ -2805,13 +2943,6 @@ export declare function usePaginatedDocuments<
|
|
|
2805
2943
|
TProjectId
|
|
2806
2944
|
>
|
|
2807
2945
|
|
|
2808
|
-
/**
|
|
2809
|
-
* @public
|
|
2810
|
-
*/
|
|
2811
|
-
declare type UsePerspective = {
|
|
2812
|
-
(perspectiveHandle: PerspectiveHandle): string | string[]
|
|
2813
|
-
}
|
|
2814
|
-
|
|
2815
2946
|
/**
|
|
2816
2947
|
* @public
|
|
2817
2948
|
* @function
|
|
@@ -2834,13 +2965,21 @@ declare type UsePerspective = {
|
|
|
2834
2965
|
*
|
|
2835
2966
|
* @returns The perspective for the given perspective handle.
|
|
2836
2967
|
*/
|
|
2968
|
+
declare type UsePerspective = {
|
|
2969
|
+
(perspectiveHandle: DatasetHandle): string | string[]
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
/**
|
|
2973
|
+
* @public
|
|
2974
|
+
* @function
|
|
2975
|
+
*/
|
|
2837
2976
|
export declare const usePerspective: UsePerspective
|
|
2838
2977
|
|
|
2839
2978
|
/**
|
|
2840
|
-
* A hook for subscribing to presence information for the current project.
|
|
2979
|
+
* A hook for subscribing to presence information for the current project or Canvas.
|
|
2841
2980
|
* @public
|
|
2842
2981
|
*/
|
|
2843
|
-
export declare function usePresence(): {
|
|
2982
|
+
export declare function usePresence(options?: WithResourceNameSupport<DatasetHandle>): {
|
|
2844
2983
|
locations: UserPresence[]
|
|
2845
2984
|
}
|
|
2846
2985
|
|
|
@@ -3007,7 +3146,7 @@ export declare function useQuery<
|
|
|
3007
3146
|
* }
|
|
3008
3147
|
* ```
|
|
3009
3148
|
*/
|
|
3010
|
-
export declare function useQuery<TData>(options:
|
|
3149
|
+
export declare function useQuery<TData>(options: WithResourceNameSupport<QueryOptions>): {
|
|
3011
3150
|
/** The query result, cast to the provided type TData */
|
|
3012
3151
|
data: TData
|
|
3013
3152
|
/** True if another query is resolving in the background (suspense handles the initial loading state) */
|
|
@@ -3015,14 +3154,14 @@ export declare function useQuery<TData>(options: WithSourceNameSupport<QueryOpti
|
|
|
3015
3154
|
}
|
|
3016
3155
|
|
|
3017
3156
|
/**
|
|
3018
|
-
* Hook options for useQuery, supporting both direct
|
|
3157
|
+
* Hook options for useQuery, supporting both direct resource and resourceName.
|
|
3019
3158
|
* @beta
|
|
3020
3159
|
*/
|
|
3021
3160
|
declare type UseQueryOptions<
|
|
3022
3161
|
TQuery extends string = string,
|
|
3023
3162
|
TDataset extends string = string,
|
|
3024
3163
|
TProjectId extends string = string,
|
|
3025
|
-
> =
|
|
3164
|
+
> = WithResourceNameSupport<QueryOptions<TQuery, TDataset, TProjectId>>
|
|
3026
3165
|
|
|
3027
3166
|
/**
|
|
3028
3167
|
* @internal
|
|
@@ -3336,6 +3475,47 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
|
|
|
3336
3475
|
onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
|
|
3337
3476
|
}
|
|
3338
3477
|
|
|
3478
|
+
/**
|
|
3479
|
+
* Sets the browser's document title, automatically including the app's name
|
|
3480
|
+
* from the manifest.
|
|
3481
|
+
*
|
|
3482
|
+
* This follows the same convention as Sanity Studio workspaces, where the
|
|
3483
|
+
* workspace name is always present in the title:
|
|
3484
|
+
*
|
|
3485
|
+
* - With a view title: `<viewTitle> | <appTitle>`
|
|
3486
|
+
* - Without a view title: `<appTitle>`
|
|
3487
|
+
*
|
|
3488
|
+
* The Sanity dashboard appends `| Sanity` to produce the final browser tab title.
|
|
3489
|
+
*
|
|
3490
|
+
* @param viewTitle - An optional view-specific title to prepend to the app title.
|
|
3491
|
+
*
|
|
3492
|
+
* @example
|
|
3493
|
+
* ```tsx
|
|
3494
|
+
* import {useWindowTitle} from '@sanity/sdk-react'
|
|
3495
|
+
*
|
|
3496
|
+
* function MoviesList() {
|
|
3497
|
+
* useWindowTitle('Movies')
|
|
3498
|
+
* return <div>...</div>
|
|
3499
|
+
* }
|
|
3500
|
+
*
|
|
3501
|
+
* // Browser tab: "Movies | My App | Sanity"
|
|
3502
|
+
* ```
|
|
3503
|
+
*
|
|
3504
|
+
* @example
|
|
3505
|
+
* ```tsx
|
|
3506
|
+
* // Call without arguments to show just the app title
|
|
3507
|
+
* function AppRoot() {
|
|
3508
|
+
* useWindowTitle()
|
|
3509
|
+
* return <Outlet />
|
|
3510
|
+
* }
|
|
3511
|
+
*
|
|
3512
|
+
* // Browser tab: "My App | Sanity"
|
|
3513
|
+
* ```
|
|
3514
|
+
*
|
|
3515
|
+
* @public
|
|
3516
|
+
*/
|
|
3517
|
+
export declare function useWindowTitle(viewTitle?: string): void
|
|
3518
|
+
|
|
3339
3519
|
/**
|
|
3340
3520
|
* @internal
|
|
3341
3521
|
*/
|
|
@@ -3368,23 +3548,28 @@ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
|
|
|
3368
3548
|
) => TFrameMessage['response']
|
|
3369
3549
|
|
|
3370
3550
|
/**
|
|
3371
|
-
* Adds React hook support (
|
|
3372
|
-
* This wrapper allows hooks to accept `
|
|
3373
|
-
* which is then resolved to a `
|
|
3374
|
-
* For now, we are trying to avoid
|
|
3375
|
-
* functions having
|
|
3551
|
+
* Adds React hook support (resourceName resolution) to core types.
|
|
3552
|
+
* This wrapper allows hooks to accept `resourceName` as a convenience,
|
|
3553
|
+
* which is then resolved to a `DocumentResource` at the React layer.
|
|
3554
|
+
* For now, we are trying to avoid resource name resolution in core --
|
|
3555
|
+
* functions having resources explicitly passed will reduce complexity.
|
|
3376
3556
|
*
|
|
3377
|
-
* @typeParam T - The core type to extend (must have optional `
|
|
3557
|
+
* @typeParam T - The core type to extend (must have optional `resource` field)
|
|
3378
3558
|
* @beta
|
|
3379
3559
|
*/
|
|
3380
|
-
declare type
|
|
3560
|
+
declare type WithResourceNameSupport<
|
|
3381
3561
|
T extends {
|
|
3382
|
-
|
|
3562
|
+
resource?: DocumentResource
|
|
3383
3563
|
},
|
|
3384
3564
|
> = T & {
|
|
3385
3565
|
/**
|
|
3386
|
-
* Optional name of a
|
|
3387
|
-
* If provided, will be resolved to a `
|
|
3566
|
+
* Optional name of a resource to resolve from context.
|
|
3567
|
+
* If provided, will be resolved to a `DocumentResource` via `ResourcesContext`.
|
|
3568
|
+
* @beta
|
|
3569
|
+
*/
|
|
3570
|
+
resourceName?: string
|
|
3571
|
+
/**
|
|
3572
|
+
* @deprecated Use `resourceName` instead.
|
|
3388
3573
|
* @beta
|
|
3389
3574
|
*/
|
|
3390
3575
|
sourceName?: string
|