@sanity/sdk-react 0.0.0-alpha.19 → 0.0.0-alpha.20
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/README.md +1 -1
- package/dist/index.d.ts +130 -29
- package/dist/index.js +193 -99
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/_exports/index.ts +9 -1
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
- package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
- package/src/hooks/comlink/useFrameConnection.test.tsx +20 -10
- package/src/hooks/comlink/useFrameConnection.ts +33 -56
- package/src/hooks/comlink/useManageFavorite.ts +4 -1
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +6 -2
- package/src/hooks/comlink/useWindowConnection.test.ts +20 -10
- package/src/hooks/comlink/useWindowConnection.ts +69 -41
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +97 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +274 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +91 -0
- package/src/hooks/document/usePermissions.ts +5 -5
- package/src/hooks/preview/usePreview.test.tsx +6 -6
- package/src/hooks/preview/usePreview.tsx +5 -5
- package/src/hooks/projection/useProjection.test.tsx +9 -9
- package/src/hooks/projection/useProjection.ts +25 -13
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Here's how to implement your Sanity application:
|
|
|
26
26
|
1. Create a new React TypeScript project using the Sanity template
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
pnpx sanity@latest init --template
|
|
29
|
+
pnpx sanity@latest init --template app-quickstart
|
|
30
30
|
cd my-content-os-app
|
|
31
31
|
```
|
|
32
32
|
|
package/dist/index.d.ts
CHANGED
|
@@ -432,6 +432,11 @@ declare type ClientReturn<
|
|
|
432
432
|
Fallback = Any,
|
|
433
433
|
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
434
434
|
|
|
435
|
+
/**
|
|
436
|
+
* @public
|
|
437
|
+
*/
|
|
438
|
+
export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
|
|
439
|
+
|
|
435
440
|
/** @public */
|
|
436
441
|
declare interface ContentSourceMap {
|
|
437
442
|
mappings: ContentSourceMapMappings
|
|
@@ -827,7 +832,6 @@ export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
|
|
|
827
832
|
>['data'],
|
|
828
833
|
]
|
|
829
834
|
) => void
|
|
830
|
-
status: Status
|
|
831
835
|
}
|
|
832
836
|
|
|
833
837
|
/** @public */
|
|
@@ -1139,6 +1143,11 @@ declare interface ManageFavorite {
|
|
|
1139
1143
|
isConnected: boolean
|
|
1140
1144
|
}
|
|
1141
1145
|
|
|
1146
|
+
/**
|
|
1147
|
+
* @public
|
|
1148
|
+
*/
|
|
1149
|
+
declare type MessageData = Record<string, unknown> | undefined
|
|
1150
|
+
|
|
1142
1151
|
/**
|
|
1143
1152
|
* @internal
|
|
1144
1153
|
*/
|
|
@@ -1293,6 +1302,11 @@ declare type MutationSelectionQueryParams = {
|
|
|
1293
1302
|
[key: string]: Any
|
|
1294
1303
|
}
|
|
1295
1304
|
|
|
1305
|
+
declare interface NavigateToStudioResult {
|
|
1306
|
+
navigateToStudioDocument: () => void
|
|
1307
|
+
isConnected: boolean
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1296
1310
|
/** @internal */
|
|
1297
1311
|
declare class ObservableAssetsClient {
|
|
1298
1312
|
#private
|
|
@@ -3257,11 +3271,6 @@ export {SortOrderingItem}
|
|
|
3257
3271
|
/** @public */
|
|
3258
3272
|
declare type StackablePerspective = ('published' | 'drafts' | string) & {}
|
|
3259
3273
|
|
|
3260
|
-
/**
|
|
3261
|
-
* @public
|
|
3262
|
-
*/
|
|
3263
|
-
declare type Status = 'idle' | 'handshaking' | 'connected' | 'disconnected'
|
|
3264
|
-
|
|
3265
3274
|
/** @public */
|
|
3266
3275
|
declare interface StegaConfig {
|
|
3267
3276
|
/**
|
|
@@ -3308,6 +3317,12 @@ declare type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https:/
|
|
|
3308
3317
|
/** @alpha */
|
|
3309
3318
|
declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
|
|
3310
3319
|
|
|
3320
|
+
declare interface StudioWorkspacesResult {
|
|
3321
|
+
workspacesByResourceId: WorkspacesByResourceId
|
|
3322
|
+
error: string | null
|
|
3323
|
+
isConnected: boolean
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3311
3326
|
/** @public */
|
|
3312
3327
|
declare type SyncTag = `s1:${string}`
|
|
3313
3328
|
|
|
@@ -3648,6 +3663,26 @@ declare type UseCurrentUser = {
|
|
|
3648
3663
|
*/
|
|
3649
3664
|
export declare const useCurrentUser: UseCurrentUser
|
|
3650
3665
|
|
|
3666
|
+
/**
|
|
3667
|
+
* @remarks
|
|
3668
|
+
* A React hook that retrieves the dashboard organization ID that is currently selected in the Sanity Dashboard.
|
|
3669
|
+
*
|
|
3670
|
+
* @example
|
|
3671
|
+
* ```tsx
|
|
3672
|
+
* function DashboardComponent() {
|
|
3673
|
+
* const orgId = useDashboardOrganizationId()
|
|
3674
|
+
*
|
|
3675
|
+
* if (!orgId) return null
|
|
3676
|
+
*
|
|
3677
|
+
* return <div>Organization ID: {String(orgId)}</div>
|
|
3678
|
+
* }
|
|
3679
|
+
* ```
|
|
3680
|
+
*
|
|
3681
|
+
* @returns The dashboard organization ID (string | undefined)
|
|
3682
|
+
* @public
|
|
3683
|
+
*/
|
|
3684
|
+
export declare function useDashboardOrganizationId(): string | undefined
|
|
3685
|
+
|
|
3651
3686
|
declare type UseDatasets = {
|
|
3652
3687
|
/**
|
|
3653
3688
|
*
|
|
@@ -3948,6 +3983,7 @@ export declare interface UseFrameConnectionOptions<TWindowMessage extends Window
|
|
|
3948
3983
|
) => void
|
|
3949
3984
|
}
|
|
3950
3985
|
heartbeat?: boolean
|
|
3986
|
+
onStatus?: (status: ComlinkStatus) => void
|
|
3951
3987
|
}
|
|
3952
3988
|
|
|
3953
3989
|
/**
|
|
@@ -4120,6 +4156,18 @@ export declare const useLogOut: () => () => Promise<void>
|
|
|
4120
4156
|
*/
|
|
4121
4157
|
export declare function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite
|
|
4122
4158
|
|
|
4159
|
+
/**
|
|
4160
|
+
* @public
|
|
4161
|
+
* Hook that provides a function to navigate to a studio document.
|
|
4162
|
+
* @param documentHandle - The document handle containing document ID, type, and resource ID
|
|
4163
|
+
* @returns An object containing:
|
|
4164
|
+
* - navigateToStudioDocument - Function that when called will navigate to the studio document
|
|
4165
|
+
* - isConnected - Boolean indicating if connection to Core UI is established
|
|
4166
|
+
*/
|
|
4167
|
+
export declare function useNavigateToStudioDocument(
|
|
4168
|
+
documentHandle: DocumentHandle,
|
|
4169
|
+
): NavigateToStudioResult
|
|
4170
|
+
|
|
4123
4171
|
/**
|
|
4124
4172
|
* Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
|
|
4125
4173
|
* with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
|
|
@@ -4189,21 +4237,21 @@ export declare function usePaginatedList({
|
|
|
4189
4237
|
* import {publishDocument} from '@sanity/sdk'
|
|
4190
4238
|
*
|
|
4191
4239
|
* export function PublishButton({doc}: {doc: DocumentHandle}) {
|
|
4192
|
-
* const
|
|
4240
|
+
* const publishPermissions = usePermissions(publishDocument(doc))
|
|
4193
4241
|
* const applyAction = useApplyActions()
|
|
4194
4242
|
*
|
|
4195
4243
|
* return (
|
|
4196
4244
|
* <>
|
|
4197
4245
|
* <button
|
|
4198
|
-
* disabled={!
|
|
4246
|
+
* disabled={!publishPermissions.allowed}
|
|
4199
4247
|
* onClick={() => applyAction(publishDocument(doc))}
|
|
4200
|
-
* popoverTarget={`${
|
|
4248
|
+
* popoverTarget={`${publishPermissions.allowed ? undefined : 'publishButtonPopover'}`}
|
|
4201
4249
|
* >
|
|
4202
4250
|
* Publish
|
|
4203
4251
|
* </button>
|
|
4204
|
-
* {!
|
|
4252
|
+
* {!publishPermissions.allowed && (
|
|
4205
4253
|
* <div popover id="publishButtonPopover">
|
|
4206
|
-
* {
|
|
4254
|
+
* {publishPermissions.message}
|
|
4207
4255
|
* </div>
|
|
4208
4256
|
* )}
|
|
4209
4257
|
* </>
|
|
@@ -4231,7 +4279,7 @@ export declare function usePermissions(
|
|
|
4231
4279
|
* ```
|
|
4232
4280
|
* // PreviewComponent.jsx
|
|
4233
4281
|
* export default function PreviewComponent({ document }) {
|
|
4234
|
-
* const {
|
|
4282
|
+
* const { data: { title, subtitle, media }, isPending } = usePreview({ document })
|
|
4235
4283
|
* return (
|
|
4236
4284
|
* <article style={{ opacity: isPending ? 0.5 : 1}}>
|
|
4237
4285
|
* {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
|
|
@@ -4242,12 +4290,12 @@ export declare function usePermissions(
|
|
|
4242
4290
|
* }
|
|
4243
4291
|
*
|
|
4244
4292
|
* // DocumentList.jsx
|
|
4245
|
-
* const {
|
|
4293
|
+
* const { data, isPending } = useDocuments({ filter: '_type == "movie"' })
|
|
4246
4294
|
* return (
|
|
4247
4295
|
* <div>
|
|
4248
4296
|
* <h1>Movies</h1>
|
|
4249
4297
|
* <ul>
|
|
4250
|
-
* {isPending ? 'Loading…' :
|
|
4298
|
+
* {isPending ? 'Loading…' : data.map(movie => (
|
|
4251
4299
|
* <li key={movie._id}>
|
|
4252
4300
|
* <Suspense fallback='Loading…'>
|
|
4253
4301
|
* <PreviewComponent document={movie} />
|
|
@@ -4279,7 +4327,7 @@ export declare interface UsePreviewOptions {
|
|
|
4279
4327
|
*/
|
|
4280
4328
|
export declare interface UsePreviewResults {
|
|
4281
4329
|
/** The results of resolving the document’s preview values */
|
|
4282
|
-
|
|
4330
|
+
data: PreviewValue
|
|
4283
4331
|
/** True when preview values are being refreshed */
|
|
4284
4332
|
isPending: boolean
|
|
4285
4333
|
}
|
|
@@ -4323,21 +4371,25 @@ export declare const useProject: UseProject
|
|
|
4323
4371
|
* @param options - The document handle for the document you want to project values from, the projection string, and an optional ref
|
|
4324
4372
|
* @returns The projection values for the given document and a boolean to indicate whether the resolution is pending
|
|
4325
4373
|
*
|
|
4326
|
-
* @example Using a projection to
|
|
4374
|
+
* @example Using a projection to render a preview of document
|
|
4327
4375
|
* ```
|
|
4328
4376
|
* // ProjectionComponent.jsx
|
|
4329
4377
|
* export default function ProjectionComponent({ document }) {
|
|
4330
4378
|
* const ref = useRef(null)
|
|
4331
|
-
* const { results: { title,
|
|
4379
|
+
* const { results: { title, coverImage, authors }, isPending } = useProjection({
|
|
4332
4380
|
* document,
|
|
4333
|
-
*
|
|
4334
|
-
*
|
|
4381
|
+
* ref,
|
|
4382
|
+
* projection: `{
|
|
4383
|
+
* title,
|
|
4384
|
+
* 'coverImage': cover.asset->url,
|
|
4385
|
+
* 'authors': array::join(authors[]->{'name': firstName + ' ' + lastName + ' '}.name, ', ')
|
|
4386
|
+
* }`,
|
|
4335
4387
|
* })
|
|
4336
4388
|
*
|
|
4337
4389
|
* return (
|
|
4338
4390
|
* <article ref={ref} style={{ opacity: isPending ? 0.5 : 1}}>
|
|
4339
4391
|
* <h2>{title}</h2>
|
|
4340
|
-
* <
|
|
4392
|
+
* <img src={coverImage} alt={title} />
|
|
4341
4393
|
* <p>{authors}</p>
|
|
4342
4394
|
* </article>
|
|
4343
4395
|
* )
|
|
@@ -4350,13 +4402,13 @@ export declare const useProject: UseProject
|
|
|
4350
4402
|
* const { data } = useInfiniteList({ filter: '_type == "article"' })
|
|
4351
4403
|
* return (
|
|
4352
4404
|
* <div>
|
|
4353
|
-
* <h1>
|
|
4405
|
+
* <h1>Books</h1>
|
|
4354
4406
|
* <ul>
|
|
4355
|
-
* {data.map(
|
|
4356
|
-
* <li key={
|
|
4407
|
+
* {data.map(book => (
|
|
4408
|
+
* <li key={book._id}>
|
|
4357
4409
|
* <Suspense fallback='Loading…'>
|
|
4358
4410
|
* <ProjectionComponent
|
|
4359
|
-
* document={
|
|
4411
|
+
* document={book}
|
|
4360
4412
|
* />
|
|
4361
4413
|
* </Suspense>
|
|
4362
4414
|
* </li>
|
|
@@ -4372,14 +4424,22 @@ export declare function useProjection<TResult extends object>({
|
|
|
4372
4424
|
ref,
|
|
4373
4425
|
}: UseProjectionOptions): UseProjectionResults<TResult>
|
|
4374
4426
|
|
|
4375
|
-
|
|
4427
|
+
/**
|
|
4428
|
+
* @public
|
|
4429
|
+
* @category Types
|
|
4430
|
+
*/
|
|
4431
|
+
export declare interface UseProjectionOptions {
|
|
4376
4432
|
document: DocumentHandle
|
|
4377
4433
|
projection: ValidProjection
|
|
4378
4434
|
ref?: React.RefObject<unknown>
|
|
4379
4435
|
}
|
|
4380
4436
|
|
|
4381
|
-
|
|
4382
|
-
|
|
4437
|
+
/**
|
|
4438
|
+
* @public
|
|
4439
|
+
* @category Types
|
|
4440
|
+
*/
|
|
4441
|
+
export declare interface UseProjectionResults<TResult extends object> {
|
|
4442
|
+
data: TResult
|
|
4383
4443
|
isPending: boolean
|
|
4384
4444
|
}
|
|
4385
4445
|
|
|
@@ -4465,6 +4525,7 @@ export declare function useQuery<T>(
|
|
|
4465
4525
|
* @public
|
|
4466
4526
|
* Hook for managing document interaction history in Sanity Studio.
|
|
4467
4527
|
* This hook provides functionality to record document interactions.
|
|
4528
|
+
* @category History
|
|
4468
4529
|
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
4469
4530
|
* @returns An object containing:
|
|
4470
4531
|
* - `recordEvent` - Function to record document interactions
|
|
@@ -4520,6 +4581,12 @@ declare class UsersClient {
|
|
|
4520
4581
|
*/
|
|
4521
4582
|
export declare const useSanityInstance: (resourceId?: string) => SanityInstance
|
|
4522
4583
|
|
|
4584
|
+
/**
|
|
4585
|
+
* Hook that fetches studio workspaces and organizes them by projectId:dataset
|
|
4586
|
+
* @internal
|
|
4587
|
+
*/
|
|
4588
|
+
export declare function useStudioWorkspacesByResourceId(): StudioWorkspacesResult
|
|
4589
|
+
|
|
4523
4590
|
/**
|
|
4524
4591
|
*
|
|
4525
4592
|
* @public
|
|
@@ -4594,11 +4661,22 @@ export declare interface UseUsersResult {
|
|
|
4594
4661
|
|
|
4595
4662
|
/**
|
|
4596
4663
|
* @internal
|
|
4664
|
+
* Hook to wrap a Comlink node in a React hook.
|
|
4665
|
+
* Our store functionality takes care of the lifecycle of the node,
|
|
4666
|
+
* as well as sharing a single node between invocations if they share the same name.
|
|
4667
|
+
*
|
|
4668
|
+
* Generally not to be used directly, but to be used as a dependency of
|
|
4669
|
+
* Comlink-powered hooks like `useManageFavorite`.
|
|
4597
4670
|
*/
|
|
4598
4671
|
export declare function useWindowConnection<
|
|
4599
4672
|
TWindowMessage extends WindowMessage,
|
|
4600
4673
|
TFrameMessage extends FrameMessage,
|
|
4601
|
-
>(
|
|
4674
|
+
>({
|
|
4675
|
+
name,
|
|
4676
|
+
connectTo,
|
|
4677
|
+
onMessage,
|
|
4678
|
+
onStatus,
|
|
4679
|
+
}: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage>
|
|
4602
4680
|
|
|
4603
4681
|
/**
|
|
4604
4682
|
* @internal
|
|
@@ -4607,6 +4685,7 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
|
|
|
4607
4685
|
name: string
|
|
4608
4686
|
connectTo: string
|
|
4609
4687
|
onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
|
|
4688
|
+
onStatus?: (status: ComlinkStatus) => void
|
|
4610
4689
|
}
|
|
4611
4690
|
|
|
4612
4691
|
/**
|
|
@@ -4633,7 +4712,15 @@ export declare interface WindowConnection<TMessage extends WindowMessage> {
|
|
|
4633
4712
|
}
|
|
4634
4713
|
>['data'],
|
|
4635
4714
|
) => void
|
|
4636
|
-
|
|
4715
|
+
fetch: <TResponse>(
|
|
4716
|
+
type: string,
|
|
4717
|
+
data?: MessageData,
|
|
4718
|
+
options?: {
|
|
4719
|
+
signal?: AbortSignal
|
|
4720
|
+
suppressWarnings?: boolean
|
|
4721
|
+
responseTimeout?: number
|
|
4722
|
+
},
|
|
4723
|
+
) => Promise<TResponse>
|
|
4637
4724
|
}
|
|
4638
4725
|
|
|
4639
4726
|
/**
|
|
@@ -4643,4 +4730,18 @@ export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
|
|
|
4643
4730
|
event: TFrameMessage['data'],
|
|
4644
4731
|
) => TFrameMessage['response']
|
|
4645
4732
|
|
|
4733
|
+
declare interface Workspace {
|
|
4734
|
+
name: string
|
|
4735
|
+
title: string
|
|
4736
|
+
basePath: string
|
|
4737
|
+
dataset: string
|
|
4738
|
+
userApplicationId: string
|
|
4739
|
+
url: string
|
|
4740
|
+
_ref: string
|
|
4741
|
+
}
|
|
4742
|
+
|
|
4743
|
+
declare interface WorkspacesByResourceId {
|
|
4744
|
+
[key: string]: Workspace[]
|
|
4745
|
+
}
|
|
4746
|
+
|
|
4646
4747
|
export {}
|