@sanity/sdk-react 0.0.0-rc.0 → 0.0.0-rc.2
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 +398 -228
- package/dist/index.js +275 -166
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/_exports/index.ts +20 -12
- package/src/components/Login/LoginLinks.test.tsx +2 -2
- package/src/components/Login/LoginLinks.tsx +2 -2
- package/src/components/auth/AuthBoundary.test.tsx +2 -2
- package/src/components/auth/LoginCallback.test.tsx +3 -3
- package/src/components/auth/LoginCallback.tsx +4 -4
- package/src/hooks/auth/useCurrentUser.tsx +1 -0
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
- package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
- package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
- package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +6 -6
- package/src/hooks/auth/useLogOut.test.tsx +2 -2
- package/src/hooks/client/useClient.ts +1 -0
- package/src/hooks/comlink/useFrameConnection.test.tsx +20 -10
- package/src/hooks/comlink/useFrameConnection.ts +33 -56
- package/src/hooks/comlink/useManageFavorite.test.ts +9 -4
- package/src/hooks/comlink/useManageFavorite.ts +46 -14
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +7 -3
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +45 -14
- package/src/hooks/comlink/useWindowConnection.test.ts +20 -10
- package/src/hooks/comlink/useWindowConnection.ts +69 -41
- package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +123 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +278 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +92 -0
- package/src/hooks/datasets/useDatasets.ts +6 -3
- package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
- package/src/hooks/document/{useApplyActions.ts → useApplyDocumentActions.ts} +13 -12
- package/src/hooks/document/{usePermissions.ts → useDocumentPermissions.ts} +12 -10
- package/src/hooks/document/useDocumentSyncStatus.ts +4 -1
- package/src/hooks/document/useEditDocument.test.ts +8 -8
- package/src/hooks/document/useEditDocument.ts +2 -2
- package/src/hooks/{infiniteList/useInfiniteList.test.tsx → documents/useDocuments.test.tsx} +9 -9
- package/src/hooks/{infiniteList/useInfiniteList.ts → documents/useDocuments.ts} +10 -10
- package/src/hooks/{paginatedList/usePaginatedList.test.tsx → paginatedDocuments/usePaginatedDocuments.test.tsx} +14 -14
- package/src/hooks/{paginatedList/usePaginatedList.ts → paginatedDocuments/usePaginatedDocuments.ts} +7 -7
- 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 +27 -15
- package/src/hooks/projects/useProject.ts +4 -1
- package/src/hooks/projects/useProjects.ts +7 -3
- package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
- package/src/hooks/document/useApplyActions.test.ts +0 -25
|
@@ -6,16 +6,17 @@ import {createStateSourceHook} from '../helpers/createStateSourceHook'
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
8
8
|
* @category Types
|
|
9
|
+
* @interface
|
|
9
10
|
*/
|
|
10
11
|
export type ProjectWithoutMembers = Omit<SanityProject, 'members'>
|
|
11
12
|
|
|
12
13
|
type UseProjects = {
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
15
|
-
* Returns metadata for each project
|
|
16
|
+
* Returns metadata for each project you have access to.
|
|
16
17
|
*
|
|
17
18
|
* @category Projects
|
|
18
|
-
* @returns An array of metadata (minus the projects’ members) for each project
|
|
19
|
+
* @returns An array of metadata (minus the projects’ members) for each project
|
|
19
20
|
* @example
|
|
20
21
|
* ```tsx
|
|
21
22
|
* const projects = useProjects()
|
|
@@ -32,7 +33,10 @@ type UseProjects = {
|
|
|
32
33
|
(): ProjectWithoutMembers[]
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* @public
|
|
38
|
+
* @function
|
|
39
|
+
*/
|
|
36
40
|
export const useProjects: UseProjects = createStateSourceHook({
|
|
37
41
|
// remove `undefined` since we're suspending when that is the case
|
|
38
42
|
getState: getProjectsState as (instance: SanityInstance) => StateSource<ProjectWithoutMembers[]>,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {handleCallback} from '@sanity/sdk'
|
|
2
|
-
import {identity} from 'rxjs'
|
|
3
|
-
import {describe, it} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import {createCallbackHook} from '../helpers/createCallbackHook'
|
|
6
|
-
|
|
7
|
-
vi.mock('../helpers/createCallbackHook', () => ({createCallbackHook: vi.fn(identity)}))
|
|
8
|
-
vi.mock('@sanity/sdk', () => ({handleCallback: vi.fn()}))
|
|
9
|
-
|
|
10
|
-
describe('useHandleCallback', () => {
|
|
11
|
-
it('calls `createCallbackHook` with `handleCallback`', async () => {
|
|
12
|
-
const {useHandleCallback} = await import('./useHandleCallback')
|
|
13
|
-
expect(createCallbackHook).toHaveBeenCalledWith(handleCallback)
|
|
14
|
-
expect(useHandleCallback).toBe(handleCallback)
|
|
15
|
-
})
|
|
16
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {applyActions, createDocument, type ResourceId} from '@sanity/sdk'
|
|
2
|
-
import {describe, it} from 'vitest'
|
|
3
|
-
|
|
4
|
-
import {createCallbackHook} from '../helpers/createCallbackHook'
|
|
5
|
-
|
|
6
|
-
vi.mock('../helpers/createCallbackHook', () => ({
|
|
7
|
-
createCallbackHook: vi.fn((cb) => () => cb),
|
|
8
|
-
}))
|
|
9
|
-
vi.mock('@sanity/sdk', async (importOriginal) => {
|
|
10
|
-
const original = await importOriginal<typeof import('@sanity/sdk')>()
|
|
11
|
-
return {...original, applyActions: vi.fn()}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe('useApplyActions', () => {
|
|
15
|
-
it('calls `createCallbackHook` with `applyActions`', async () => {
|
|
16
|
-
const {useApplyActions} = await import('./useApplyActions')
|
|
17
|
-
const resourceId: ResourceId = 'project1.dataset1'
|
|
18
|
-
expect(createCallbackHook).not.toHaveBeenCalled()
|
|
19
|
-
|
|
20
|
-
expect(applyActions).not.toHaveBeenCalled()
|
|
21
|
-
const apply = useApplyActions(resourceId)
|
|
22
|
-
apply(createDocument({_type: 'author'}))
|
|
23
|
-
expect(applyActions).toHaveBeenCalledWith(createDocument({_type: 'author'}))
|
|
24
|
-
})
|
|
25
|
-
})
|