@sanity/sdk-react 2.9.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 +92 -26
- package/dist/index.js +304 -193
- package/dist/index.js.map +1 -1
- package/package.json +9 -11
- package/src/_exports/sdk-react.ts +4 -0
- package/src/components/SDKProvider.tsx +36 -8
- package/src/components/SanityApp.tsx +2 -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.tsx +5 -4
- package/src/context/ResourcesContext.tsx +7 -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 +6 -6
- package/src/hooks/dashboard/useDispatchIntent.ts +6 -6
- 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 +10 -10
- package/src/hooks/document/useApplyDocumentActions.ts +17 -17
- package/src/hooks/document/useDocument.ts +5 -5
- package/src/hooks/document/useDocumentEvent.ts +4 -4
- package/src/hooks/document/useDocumentPermissions.test.tsx +10 -10
- package/src/hooks/document/useDocumentPermissions.ts +8 -8
- package/src/hooks/document/useDocumentSyncStatus.ts +2 -2
- package/src/hooks/document/useEditDocument.ts +2 -2
- package/src/hooks/documents/useDocuments.ts +9 -6
- package/src/hooks/helpers/useNormalizedResourceOptions.ts +131 -0
- package/src/hooks/helpers/useTrackHookUsage.ts +2 -2
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +9 -8
- package/src/hooks/presence/usePresence.test.tsx +56 -9
- package/src/hooks/presence/usePresence.ts +23 -4
- package/src/hooks/preview/useDocumentPreview.tsx +8 -7
- package/src/hooks/projection/useDocumentProjection.ts +6 -6
- package/src/hooks/query/useQuery.ts +10 -9
- package/src/hooks/releases/useActiveReleases.ts +10 -10
- package/src/hooks/releases/usePerspective.ts +9 -9
- package/src/context/SourcesContext.tsx +0 -7
- package/src/hooks/helpers/useNormalizedSourceOptions.ts +0 -107
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'
|
|
@@ -605,13 +605,74 @@ export declare interface SanityAppProps {
|
|
|
605
605
|
config?: SanityConfig | SanityConfig[]
|
|
606
606
|
/** @deprecated use the `config` prop instead. */
|
|
607
607
|
sanityConfigs?: SanityConfig[]
|
|
608
|
-
|
|
608
|
+
resources?: Record<string, DocumentResource>
|
|
609
609
|
children: React.ReactNode
|
|
610
610
|
fallback: React.ReactNode
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
export {SanityDocument}
|
|
614
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
|
+
|
|
615
676
|
export {SanityProjectMember}
|
|
616
677
|
|
|
617
678
|
/**
|
|
@@ -635,7 +696,7 @@ export declare interface SDKProviderProps extends AuthBoundaryProps {
|
|
|
635
696
|
children: ReactNode
|
|
636
697
|
config: SanityConfig | SanityConfig[]
|
|
637
698
|
fallback: ReactNode
|
|
638
|
-
|
|
699
|
+
resources?: Record<string, DocumentResource>
|
|
639
700
|
}
|
|
640
701
|
|
|
641
702
|
/**
|
|
@@ -744,7 +805,7 @@ declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
|
|
|
744
805
|
* ```
|
|
745
806
|
*/
|
|
746
807
|
declare type UseActiveReleases = {
|
|
747
|
-
(options?:
|
|
808
|
+
(options?: WithResourceNameSupport<SanityConfig> | undefined): ReleaseDocument[]
|
|
748
809
|
}
|
|
749
810
|
|
|
750
811
|
/**
|
|
@@ -1286,7 +1347,7 @@ declare interface UseApplyDocumentActions {
|
|
|
1286
1347
|
action:
|
|
1287
1348
|
| DocumentAction<TDocumentType, TDataset, TProjectId>
|
|
1288
1349
|
| DocumentAction<TDocumentType, TDataset, TProjectId>[],
|
|
1289
|
-
options?:
|
|
1350
|
+
options?: WithResourceNameSupport<ApplyDocumentActionsOptions>,
|
|
1290
1351
|
) => Promise<ActionsResult<SanityDocument_2<TDocumentType, `${TProjectId}.${TDataset}`>>>
|
|
1291
1352
|
}
|
|
1292
1353
|
|
|
@@ -1674,8 +1735,8 @@ export declare const useDatasets: UseDatasets
|
|
|
1674
1735
|
* - `action` - Action to perform (currently only 'edit' is supported). Will prompt a picker if multiple handlers are available.
|
|
1675
1736
|
* - `intentId` - Specific ID of the intent to dispatch. Either `action` or `intentId` is required.
|
|
1676
1737
|
* - `documentHandle` - The document handle containing document ID, type, and either:
|
|
1677
|
-
* - `projectId` and `dataset` for traditional dataset
|
|
1678
|
-
* - `
|
|
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')}`
|
|
1679
1740
|
* - `paremeters` - Optional parameters to include in the dispatch; will be passed to the resolved intent handler
|
|
1680
1741
|
* @returns An object containing:
|
|
1681
1742
|
* - `dispatchIntent` - Function to dispatch the intent message
|
|
@@ -1724,7 +1785,7 @@ export declare function useDispatchIntent(params: UseDispatchIntentParams): Disp
|
|
|
1724
1785
|
declare interface UseDispatchIntentParams {
|
|
1725
1786
|
action?: 'edit'
|
|
1726
1787
|
intentId?: string
|
|
1727
|
-
documentHandle:
|
|
1788
|
+
documentHandle: WithResourceNameSupport<DocumentHandle>
|
|
1728
1789
|
parameters?: Record<string, unknown>
|
|
1729
1790
|
}
|
|
1730
1791
|
|
|
@@ -2009,7 +2070,7 @@ declare type UseDocumentOptions<
|
|
|
2009
2070
|
TDocumentType extends string = string,
|
|
2010
2071
|
TDataset extends string = string,
|
|
2011
2072
|
TProjectId extends string = string,
|
|
2012
|
-
> =
|
|
2073
|
+
> = WithResourceNameSupport<DocumentOptions<TPath, TDocumentType, TDataset, TProjectId>>
|
|
2013
2074
|
|
|
2014
2075
|
/**
|
|
2015
2076
|
*
|
|
@@ -2157,7 +2218,7 @@ export declare function useDocumentPreview({
|
|
|
2157
2218
|
* @public
|
|
2158
2219
|
* @category Types
|
|
2159
2220
|
*/
|
|
2160
|
-
export declare interface useDocumentPreviewOptions extends
|
|
2221
|
+
export declare interface useDocumentPreviewOptions extends WithResourceNameSupport<DocumentHandle> {
|
|
2161
2222
|
/**
|
|
2162
2223
|
* Optional ref object to track visibility. When provided, preview resolution
|
|
2163
2224
|
* only occurs when the referenced element is visible in the viewport.
|
|
@@ -2318,7 +2379,7 @@ export declare interface useDocumentProjectionOptions<
|
|
|
2318
2379
|
TDocumentType extends string = string,
|
|
2319
2380
|
TDataset extends string = string,
|
|
2320
2381
|
TProjectId extends string = string,
|
|
2321
|
-
> extends
|
|
2382
|
+
> extends WithResourceNameSupport<DocumentHandle<TDocumentType, TDataset, TProjectId>> {
|
|
2322
2383
|
/** The GROQ projection string */
|
|
2323
2384
|
projection: TProjection
|
|
2324
2385
|
/** Optional parameters for the projection query */
|
|
@@ -2915,10 +2976,10 @@ declare type UsePerspective = {
|
|
|
2915
2976
|
export declare const usePerspective: UsePerspective
|
|
2916
2977
|
|
|
2917
2978
|
/**
|
|
2918
|
-
* 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.
|
|
2919
2980
|
* @public
|
|
2920
2981
|
*/
|
|
2921
|
-
export declare function usePresence(): {
|
|
2982
|
+
export declare function usePresence(options?: WithResourceNameSupport<DatasetHandle>): {
|
|
2922
2983
|
locations: UserPresence[]
|
|
2923
2984
|
}
|
|
2924
2985
|
|
|
@@ -3085,7 +3146,7 @@ export declare function useQuery<
|
|
|
3085
3146
|
* }
|
|
3086
3147
|
* ```
|
|
3087
3148
|
*/
|
|
3088
|
-
export declare function useQuery<TData>(options:
|
|
3149
|
+
export declare function useQuery<TData>(options: WithResourceNameSupport<QueryOptions>): {
|
|
3089
3150
|
/** The query result, cast to the provided type TData */
|
|
3090
3151
|
data: TData
|
|
3091
3152
|
/** True if another query is resolving in the background (suspense handles the initial loading state) */
|
|
@@ -3093,14 +3154,14 @@ export declare function useQuery<TData>(options: WithSourceNameSupport<QueryOpti
|
|
|
3093
3154
|
}
|
|
3094
3155
|
|
|
3095
3156
|
/**
|
|
3096
|
-
* Hook options for useQuery, supporting both direct
|
|
3157
|
+
* Hook options for useQuery, supporting both direct resource and resourceName.
|
|
3097
3158
|
* @beta
|
|
3098
3159
|
*/
|
|
3099
3160
|
declare type UseQueryOptions<
|
|
3100
3161
|
TQuery extends string = string,
|
|
3101
3162
|
TDataset extends string = string,
|
|
3102
3163
|
TProjectId extends string = string,
|
|
3103
|
-
> =
|
|
3164
|
+
> = WithResourceNameSupport<QueryOptions<TQuery, TDataset, TProjectId>>
|
|
3104
3165
|
|
|
3105
3166
|
/**
|
|
3106
3167
|
* @internal
|
|
@@ -3487,23 +3548,28 @@ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
|
|
|
3487
3548
|
) => TFrameMessage['response']
|
|
3488
3549
|
|
|
3489
3550
|
/**
|
|
3490
|
-
* Adds React hook support (
|
|
3491
|
-
* This wrapper allows hooks to accept `
|
|
3492
|
-
* which is then resolved to a `
|
|
3493
|
-
* For now, we are trying to avoid
|
|
3494
|
-
* 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.
|
|
3495
3556
|
*
|
|
3496
|
-
* @typeParam T - The core type to extend (must have optional `
|
|
3557
|
+
* @typeParam T - The core type to extend (must have optional `resource` field)
|
|
3497
3558
|
* @beta
|
|
3498
3559
|
*/
|
|
3499
|
-
declare type
|
|
3560
|
+
declare type WithResourceNameSupport<
|
|
3500
3561
|
T extends {
|
|
3501
|
-
|
|
3562
|
+
resource?: DocumentResource
|
|
3502
3563
|
},
|
|
3503
3564
|
> = T & {
|
|
3504
3565
|
/**
|
|
3505
|
-
* Optional name of a
|
|
3506
|
-
* 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.
|
|
3507
3573
|
* @beta
|
|
3508
3574
|
*/
|
|
3509
3575
|
sourceName?: string
|