@sanity/sdk-react 2.4.0 → 2.6.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/README.md +652 -4
- package/dist/index.d.ts +85 -14
- package/dist/index.js +184 -57
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/_exports/sdk-react.ts +5 -0
- package/src/components/SDKProvider.tsx +8 -3
- package/src/components/SanityApp.tsx +2 -1
- package/src/context/SourcesContext.tsx +7 -0
- package/src/context/renderSanityApp.test.tsx +355 -0
- package/src/context/renderSanityApp.tsx +48 -0
- package/src/hooks/agent/useAgentResourceContext.test.tsx +245 -0
- package/src/hooks/agent/useAgentResourceContext.ts +106 -0
- package/src/hooks/context/useSource.tsx +34 -0
- package/src/hooks/dashboard/useDispatchIntent.test.ts +25 -22
- package/src/hooks/dashboard/useDispatchIntent.ts +9 -10
- package/src/hooks/dashboard/utils/{getResourceIdFromDocumentHandle.test.ts → useResourceIdFromDocumentHandle.test.ts} +33 -59
- package/src/hooks/dashboard/utils/useResourceIdFromDocumentHandle.ts +46 -0
- package/src/hooks/document/useApplyDocumentActions.test.ts +124 -9
- package/src/hooks/document/useApplyDocumentActions.ts +44 -4
- package/src/hooks/document/useDocumentPermissions.test.tsx +3 -3
- package/src/hooks/document/useDocumentPermissions.ts +9 -6
- package/src/hooks/document/useEditDocument.ts +3 -0
- package/src/hooks/documents/useDocuments.ts +3 -2
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +1 -0
- package/src/hooks/query/useQuery.ts +21 -8
- package/src/hooks/releases/usePerspective.test.tsx +1 -0
- package/src/hooks/releases/usePerspective.ts +1 -1
- package/src/hooks/dashboard/types.ts +0 -12
- package/src/hooks/dashboard/utils/getResourceIdFromDocumentHandle.ts +0 -53
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {type DocumentHandle, type DocumentSource} from '@sanity/sdk'
|
|
2
|
-
|
|
3
|
-
import {type DocumentHandleWithSource} from '../types'
|
|
4
|
-
|
|
5
|
-
// Internal constant for accessing source ID
|
|
6
|
-
const SOURCE_ID = '__sanity_internal_sourceId' as const
|
|
7
|
-
|
|
8
|
-
interface DashboardMessageResource {
|
|
9
|
-
id: string
|
|
10
|
-
type?: 'media-library' | 'canvas'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const isDocumentHandleWithSource = (
|
|
14
|
-
documentHandle: DocumentHandle | DocumentHandleWithSource,
|
|
15
|
-
): documentHandle is DocumentHandleWithSource => {
|
|
16
|
-
return 'source' in documentHandle
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Currently only used for dispatching intents to the dashboard,
|
|
20
|
-
* but could easily be extended to other dashboard hooks
|
|
21
|
-
* @beta
|
|
22
|
-
*/
|
|
23
|
-
export function getResourceIdFromDocumentHandle(
|
|
24
|
-
documentHandle: DocumentHandle | DocumentHandleWithSource,
|
|
25
|
-
): DashboardMessageResource {
|
|
26
|
-
let source: DocumentSource | undefined
|
|
27
|
-
|
|
28
|
-
const {projectId, dataset} = documentHandle
|
|
29
|
-
if (isDocumentHandleWithSource(documentHandle)) {
|
|
30
|
-
source = documentHandle.source
|
|
31
|
-
}
|
|
32
|
-
let resourceId: string = projectId + '.' + dataset
|
|
33
|
-
let resourceType: 'media-library' | 'canvas' | undefined
|
|
34
|
-
|
|
35
|
-
if (source) {
|
|
36
|
-
const sourceId = (source as Record<string, unknown>)[SOURCE_ID]
|
|
37
|
-
if (Array.isArray(sourceId)) {
|
|
38
|
-
if (sourceId[0] === 'media-library' || sourceId[0] === 'canvas') {
|
|
39
|
-
resourceType = sourceId[0] as 'media-library' | 'canvas'
|
|
40
|
-
resourceId = sourceId[1] as string
|
|
41
|
-
}
|
|
42
|
-
} else if (sourceId && typeof sourceId === 'object' && 'projectId' in sourceId) {
|
|
43
|
-
const datasetSource = sourceId as {projectId: string; dataset: string}
|
|
44
|
-
// don't create type since it's ambiguous for project / dataset docs
|
|
45
|
-
resourceId = `${datasetSource.projectId}.${datasetSource.dataset}`
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
id: resourceId,
|
|
51
|
-
type: resourceType,
|
|
52
|
-
}
|
|
53
|
-
}
|