@sanity/sdk-react 0.0.0-alpha.2 → 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 +38 -67
- package/dist/index.d.ts +4742 -2
- package/dist/index.js +1054 -2
- package/dist/index.js.map +1 -1
- package/package.json +27 -58
- package/src/_exports/index.ts +66 -10
- package/src/components/Login/LoginLinks.test.tsx +2 -12
- package/src/components/Login/LoginLinks.tsx +14 -29
- package/src/components/SDKProvider.test.tsx +79 -0
- package/src/components/SDKProvider.tsx +42 -0
- package/src/components/SanityApp.test.tsx +156 -0
- package/src/components/SanityApp.tsx +90 -0
- package/src/components/auth/AuthBoundary.test.tsx +4 -17
- package/src/components/auth/AuthBoundary.tsx +20 -4
- package/src/components/auth/Login.test.tsx +2 -16
- package/src/components/auth/Login.tsx +11 -30
- package/src/components/auth/LoginCallback.test.tsx +2 -17
- package/src/components/auth/LoginCallback.tsx +5 -10
- package/src/components/auth/LoginError.test.tsx +2 -17
- package/src/components/auth/LoginError.tsx +11 -16
- package/src/components/auth/LoginFooter.test.tsx +2 -16
- package/src/components/auth/LoginFooter.tsx +8 -24
- package/src/components/auth/LoginLayout.test.tsx +2 -16
- package/src/components/auth/LoginLayout.tsx +8 -38
- package/src/components/auth/authTestHelpers.tsx +11 -0
- package/src/components/utils.ts +22 -0
- package/src/context/SanityInstanceContext.ts +4 -0
- package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
- package/src/context/SanityProvider.tsx +50 -0
- package/src/hooks/_synchronous-groq-js.mjs +4 -0
- package/src/hooks/auth/useAuthState.tsx +4 -5
- package/src/hooks/auth/useAuthToken.tsx +1 -1
- package/src/hooks/auth/useCurrentUser.tsx +27 -4
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
- package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
- package/src/hooks/auth/useHandleCallback.tsx +1 -0
- package/src/hooks/auth/useLogOut.tsx +1 -1
- package/src/hooks/auth/useLoginUrls.tsx +1 -0
- package/src/hooks/client/useClient.ts +8 -30
- package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
- package/src/hooks/comlink/useFrameConnection.ts +107 -0
- package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
- package/src/hooks/comlink/useManageFavorite.ts +101 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +79 -0
- package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
- package/src/hooks/comlink/useWindowConnection.ts +122 -0
- package/src/hooks/context/useSanityInstance.test.tsx +2 -2
- package/src/hooks/context/useSanityInstance.ts +24 -8
- 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/datasets/useDatasets.ts +37 -0
- package/src/hooks/document/useApplyActions.test.ts +25 -0
- package/src/hooks/document/useApplyActions.ts +74 -0
- package/src/hooks/document/useDocument.test.ts +81 -0
- package/src/hooks/document/useDocument.ts +107 -0
- package/src/hooks/document/useDocumentEvent.test.ts +63 -0
- package/src/hooks/document/useDocumentEvent.ts +54 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
- package/src/hooks/document/useDocumentSyncStatus.ts +30 -0
- package/src/hooks/document/useEditDocument.test.ts +179 -0
- package/src/hooks/document/useEditDocument.ts +195 -0
- package/src/hooks/document/usePermissions.ts +82 -0
- package/src/hooks/helpers/createCallbackHook.tsx +3 -2
- package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
- package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
- package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
- package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
- package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
- package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
- package/src/hooks/preview/usePreview.test.tsx +19 -10
- package/src/hooks/preview/usePreview.tsx +67 -13
- package/src/hooks/projection/useProjection.test.tsx +218 -0
- package/src/hooks/projection/useProjection.ts +147 -0
- package/src/hooks/projects/useProject.ts +45 -0
- package/src/hooks/projects/useProjects.ts +41 -0
- package/src/hooks/query/useQuery.test.tsx +188 -0
- package/src/hooks/query/useQuery.ts +103 -0
- package/src/hooks/users/useUsers.test.ts +163 -0
- package/src/hooks/users/useUsers.ts +107 -0
- package/src/utils/getEnv.ts +21 -0
- package/src/version.ts +8 -0
- package/src/vite-env.d.ts +10 -0
- package/dist/_chunks-es/useLogOut.js +0 -44
- package/dist/_chunks-es/useLogOut.js.map +0 -1
- package/dist/assets/bundle-CcAyERuZ.css +0 -11
- package/dist/components.d.ts +0 -257
- package/dist/components.js +0 -316
- package/dist/components.js.map +0 -1
- package/dist/hooks.d.ts +0 -187
- package/dist/hooks.js +0 -81
- package/dist/hooks.js.map +0 -1
- package/src/_exports/components.ts +0 -13
- package/src/_exports/hooks.ts +0 -9
- package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
- package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
- package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
- package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
- package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
- package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
- package/src/components/context/SanityProvider.tsx +0 -42
- package/src/css/css.config.js +0 -220
- package/src/css/paramour.css +0 -2347
- package/src/css/styles.css +0 -11
- package/src/hooks/client/useClient.test.tsx +0 -130
- package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
- package/src/hooks/documentCollection/useDocuments.ts +0 -87
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export {AuthBoundary, type AuthBoundaryProps} from '../components/auth/AuthBoundary'
|
|
2
|
-
export {AuthError} from '../components/auth/AuthError'
|
|
3
|
-
export {Login} from '../components/auth/Login'
|
|
4
|
-
export {LoginCallback} from '../components/auth/LoginCallback'
|
|
5
|
-
export {LoginError, type LoginErrorProps} from '../components/auth/LoginError'
|
|
6
|
-
export {LoginLayout, type LoginLayoutProps} from '../components/auth/LoginLayout'
|
|
7
|
-
export type {SanityProviderProps} from '../components/context/SanityProvider'
|
|
8
|
-
export {SanityProvider} from '../components/context/SanityProvider'
|
|
9
|
-
export {DocumentGridLayout} from '../components/DocumentGridLayout/DocumentGridLayout'
|
|
10
|
-
export {DocumentListLayout} from '../components/DocumentListLayout/DocumentListLayout'
|
|
11
|
-
export {DocumentPreviewLayout} from '../components/DocumentPreviewLayout/DocumentPreviewLayout'
|
|
12
|
-
export {type DocumentPreviewLayoutProps} from '../components/DocumentPreviewLayout/DocumentPreviewLayout'
|
|
13
|
-
export {LoginLinks} from '../components/Login/LoginLinks'
|
package/src/_exports/hooks.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export {useAuthState} from '../hooks/auth/useAuthState'
|
|
2
|
-
export {useAuthToken} from '../hooks/auth/useAuthToken'
|
|
3
|
-
export {useCurrentUser} from '../hooks/auth/useCurrentUser'
|
|
4
|
-
export {useHandleCallback} from '../hooks/auth/useHandleCallback'
|
|
5
|
-
export {useLoginUrls} from '../hooks/auth/useLoginUrls'
|
|
6
|
-
export {useLogOut} from '../hooks/auth/useLogOut'
|
|
7
|
-
export {useSanityInstance} from '../hooks/context/useSanityInstance'
|
|
8
|
-
export {type UseDocuments, useDocuments} from '../hooks/documentCollection/useDocuments'
|
|
9
|
-
export {usePreview, type UsePreviewOptions} from '../hooks/preview/usePreview'
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {type Meta, type StoryObj} from '@storybook/react'
|
|
2
|
-
|
|
3
|
-
import {DocumentPreviewLayout} from '../DocumentPreviewLayout/DocumentPreviewLayout.tsx'
|
|
4
|
-
import {DocumentGridLayout} from './DocumentGridLayout.tsx'
|
|
5
|
-
|
|
6
|
-
const meta: Meta<typeof DocumentGridLayout> = {
|
|
7
|
-
title: 'DocumentGridLayout',
|
|
8
|
-
component: DocumentGridLayout,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default meta
|
|
12
|
-
type Story = StoryObj<typeof meta>
|
|
13
|
-
|
|
14
|
-
const mockDocs = [
|
|
15
|
-
{id: '1', title: 'Just a title', url: '#', docType: 'article', status: 'published'},
|
|
16
|
-
{
|
|
17
|
-
id: '2',
|
|
18
|
-
title: 'A title, but also',
|
|
19
|
-
subtitle: 'A subtitle',
|
|
20
|
-
docType: 'article',
|
|
21
|
-
status: 'draft',
|
|
22
|
-
media: {
|
|
23
|
-
type: 'image-asset',
|
|
24
|
-
url: 'https://picsum.photos/75/75',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: '3',
|
|
29
|
-
title: 'Hello World',
|
|
30
|
-
subtitle: 'What a nice list I get to live in',
|
|
31
|
-
docType: 'image',
|
|
32
|
-
status: 'published',
|
|
33
|
-
media: {
|
|
34
|
-
type: 'image-asset',
|
|
35
|
-
url: 'https://picsum.photos/80/80',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: '4',
|
|
40
|
-
title: 'I’ve been selected',
|
|
41
|
-
subtitle: 'I feel special',
|
|
42
|
-
selected: true,
|
|
43
|
-
docType: 'video',
|
|
44
|
-
status: 'draft',
|
|
45
|
-
media: {
|
|
46
|
-
type: 'image-asset',
|
|
47
|
-
url: 'https://picsum.photos/100/100',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: '5',
|
|
52
|
-
title: 'A very long title that at some point might get truncated if it goes for long enough',
|
|
53
|
-
subtitle:
|
|
54
|
-
'Along with a subtitle that is quite long as well, in order to demonstrate the truncation of its text',
|
|
55
|
-
docType: 'audio',
|
|
56
|
-
status: 'published',
|
|
57
|
-
media: {
|
|
58
|
-
type: 'image-asset',
|
|
59
|
-
url: 'https://picsum.photos/75/75',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
id: '6',
|
|
64
|
-
title: 'Hello World',
|
|
65
|
-
subtitle: 'What a nice list I get to live in',
|
|
66
|
-
docType: 'pdf',
|
|
67
|
-
status: 'published',
|
|
68
|
-
media: {
|
|
69
|
-
type: 'image-asset',
|
|
70
|
-
url: 'https://picsum.photos/75/75',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
{id: '7', title: 'Just a title', url: '#', docType: 'note', status: 'published,'},
|
|
74
|
-
{
|
|
75
|
-
id: '8',
|
|
76
|
-
title: 'A title, but also',
|
|
77
|
-
subtitle: 'A subtitle',
|
|
78
|
-
docType: 'document',
|
|
79
|
-
status: 'draft',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
id: '9',
|
|
83
|
-
title: 'Hello World',
|
|
84
|
-
subtitle: 'What a nice list I get to live in',
|
|
85
|
-
docType: 'biography',
|
|
86
|
-
status: 'published',
|
|
87
|
-
media: {
|
|
88
|
-
type: 'image-asset',
|
|
89
|
-
url: 'https://picsum.photos/200/200',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
]
|
|
93
|
-
|
|
94
|
-
export const Default: Story = {
|
|
95
|
-
render: () => {
|
|
96
|
-
return (
|
|
97
|
-
<DocumentGridLayout>
|
|
98
|
-
{mockDocs.map((doc) => (
|
|
99
|
-
<li key={doc.id}>
|
|
100
|
-
<DocumentPreviewLayout
|
|
101
|
-
title={doc.title}
|
|
102
|
-
subtitle={doc.subtitle}
|
|
103
|
-
media={doc.media}
|
|
104
|
-
selected={doc.selected}
|
|
105
|
-
docType={doc.docType}
|
|
106
|
-
status={doc.status}
|
|
107
|
-
/>
|
|
108
|
-
</li>
|
|
109
|
-
))}
|
|
110
|
-
</DocumentGridLayout>
|
|
111
|
-
)
|
|
112
|
-
},
|
|
113
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {render, screen} from '../../../test/test-utils.tsx'
|
|
4
|
-
import {DocumentGridLayout} from './DocumentGridLayout.tsx'
|
|
5
|
-
|
|
6
|
-
describe('DocumentGridLayout', () => {
|
|
7
|
-
const mockDocuments = [
|
|
8
|
-
{
|
|
9
|
-
id: '1',
|
|
10
|
-
title: 'Test Document 1',
|
|
11
|
-
subtitle: 'Subtitle 1',
|
|
12
|
-
docType: 'post',
|
|
13
|
-
status: 'published',
|
|
14
|
-
url: '/doc/1',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: '2',
|
|
18
|
-
title: 'Test Document 2',
|
|
19
|
-
subtitle: 'Subtitle 2',
|
|
20
|
-
docType: 'page',
|
|
21
|
-
status: 'draft',
|
|
22
|
-
url: '/doc/2',
|
|
23
|
-
},
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
it('renders the expected content', () => {
|
|
27
|
-
render(
|
|
28
|
-
<DocumentGridLayout>
|
|
29
|
-
{mockDocuments.map((doc) => (
|
|
30
|
-
<li key={doc.id}>{doc.title}</li>
|
|
31
|
-
))}
|
|
32
|
-
</DocumentGridLayout>,
|
|
33
|
-
)
|
|
34
|
-
const list = screen.getByRole('list')
|
|
35
|
-
expect(list.tagName).toBe('OL')
|
|
36
|
-
expect(list.classList).toContain('DocumentGridLayout')
|
|
37
|
-
|
|
38
|
-
const items = screen.getAllByRole('listitem')
|
|
39
|
-
expect(items[0]).toContainHTML('Test Document 1')
|
|
40
|
-
expect(items[1]).toContainHTML('Test Document 2')
|
|
41
|
-
})
|
|
42
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import '../../css/styles.css'
|
|
2
|
-
|
|
3
|
-
import type {PropsWithChildren, ReactElement} from 'react'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export const DocumentGridLayout = (props: PropsWithChildren): ReactElement => {
|
|
9
|
-
return (
|
|
10
|
-
<>
|
|
11
|
-
<style>{`
|
|
12
|
-
.DocumentGridLayout {
|
|
13
|
-
grid-template-columns: repeat(auto-fit, minmax(38ch, 1fr));
|
|
14
|
-
}
|
|
15
|
-
`}</style>
|
|
16
|
-
<ol className="DocumentGridLayout list-none grid">{props.children}</ol>
|
|
17
|
-
</>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
DocumentGridLayout.displayName = 'DocumentGridLayout'
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {type Meta, type StoryObj} from '@storybook/react'
|
|
2
|
-
|
|
3
|
-
import {DocumentPreviewLayout} from '../DocumentPreviewLayout/DocumentPreviewLayout.tsx'
|
|
4
|
-
import {DocumentListLayout} from './DocumentListLayout.tsx'
|
|
5
|
-
|
|
6
|
-
const meta: Meta<typeof DocumentListLayout> = {
|
|
7
|
-
title: 'DocumentListLayout',
|
|
8
|
-
component: DocumentListLayout,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default meta
|
|
12
|
-
type Story = StoryObj<typeof meta>
|
|
13
|
-
|
|
14
|
-
const mockDocs = [
|
|
15
|
-
{id: '1', title: 'Just a title', url: '#', docType: 'article', status: 'published'},
|
|
16
|
-
{
|
|
17
|
-
id: '2',
|
|
18
|
-
title: 'A title, but also',
|
|
19
|
-
subtitle: 'A subtitle',
|
|
20
|
-
docType: 'article',
|
|
21
|
-
status: 'draft',
|
|
22
|
-
media: {
|
|
23
|
-
type: 'image-asset',
|
|
24
|
-
url: 'https://picsum.photos/75/75',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: '3',
|
|
29
|
-
title: 'Hello World',
|
|
30
|
-
subtitle: 'What a nice list I get to live in',
|
|
31
|
-
docType: 'image',
|
|
32
|
-
status: 'published',
|
|
33
|
-
media: {
|
|
34
|
-
type: 'image-asset',
|
|
35
|
-
url: 'https://picsum.photos/100/100',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
id: '4',
|
|
40
|
-
title: 'I’ve been selected',
|
|
41
|
-
subtitle: 'I feel special',
|
|
42
|
-
selected: true,
|
|
43
|
-
docType: 'video',
|
|
44
|
-
status: 'draft',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: '5',
|
|
48
|
-
title: 'A very long title that at some point might get truncated if it goes for long enough',
|
|
49
|
-
subtitle:
|
|
50
|
-
'Along with a subtitle that is quite long as well, in order to demonstrate the truncation of its text',
|
|
51
|
-
docType: 'audio',
|
|
52
|
-
status: 'published',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
id: '6',
|
|
56
|
-
title: 'Hello World',
|
|
57
|
-
subtitle: 'What a nice list I get to live in',
|
|
58
|
-
docType: 'pdf',
|
|
59
|
-
status: 'published',
|
|
60
|
-
media: {
|
|
61
|
-
type: 'image-asset',
|
|
62
|
-
url: 'https://picsum.photos/80/80',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
{id: '7', title: 'Just a title', url: '#', docType: 'note', status: 'published,'},
|
|
66
|
-
{
|
|
67
|
-
id: '8',
|
|
68
|
-
title: 'A title, but also',
|
|
69
|
-
subtitle: 'A subtitle',
|
|
70
|
-
docType: 'document',
|
|
71
|
-
status: 'draft',
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
id: '9',
|
|
75
|
-
title: 'Hello World',
|
|
76
|
-
subtitle: 'What a nice list I get to live in',
|
|
77
|
-
docType: 'biography',
|
|
78
|
-
status: 'published',
|
|
79
|
-
media: {
|
|
80
|
-
type: 'image-asset',
|
|
81
|
-
url: 'https://picsum.photos/200/200',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
]
|
|
85
|
-
|
|
86
|
-
export const Default: Story = {
|
|
87
|
-
render: () => {
|
|
88
|
-
return (
|
|
89
|
-
<DocumentListLayout>
|
|
90
|
-
{mockDocs.map((doc) => (
|
|
91
|
-
<li key={doc.id}>
|
|
92
|
-
<DocumentPreviewLayout
|
|
93
|
-
title={doc.title}
|
|
94
|
-
subtitle={doc.subtitle}
|
|
95
|
-
media={doc.media}
|
|
96
|
-
selected={doc.selected}
|
|
97
|
-
docType={doc.docType}
|
|
98
|
-
status={doc.status}
|
|
99
|
-
/>
|
|
100
|
-
</li>
|
|
101
|
-
))}
|
|
102
|
-
</DocumentListLayout>
|
|
103
|
-
)
|
|
104
|
-
},
|
|
105
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {describe, expect, it} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {render, screen} from '../../../test/test-utils.tsx'
|
|
4
|
-
import {DocumentListLayout} from './DocumentListLayout.tsx'
|
|
5
|
-
|
|
6
|
-
describe('DocumentListLayout', () => {
|
|
7
|
-
const mockDocuments = [
|
|
8
|
-
{
|
|
9
|
-
id: '1',
|
|
10
|
-
title: 'Test Document 1',
|
|
11
|
-
subtitle: 'Subtitle 1',
|
|
12
|
-
docType: 'post',
|
|
13
|
-
status: 'published',
|
|
14
|
-
url: '/doc/1',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
id: '2',
|
|
18
|
-
title: 'Test Document 2',
|
|
19
|
-
subtitle: 'Subtitle 2',
|
|
20
|
-
docType: 'page',
|
|
21
|
-
status: 'draft',
|
|
22
|
-
url: '/doc/2',
|
|
23
|
-
},
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
it('renders the expected content', () => {
|
|
27
|
-
render(
|
|
28
|
-
<DocumentListLayout>
|
|
29
|
-
{mockDocuments.map((doc) => (
|
|
30
|
-
<li key={doc.id}>{doc.title}</li>
|
|
31
|
-
))}
|
|
32
|
-
</DocumentListLayout>,
|
|
33
|
-
)
|
|
34
|
-
const list = screen.getByRole('list')
|
|
35
|
-
expect(list.tagName).toBe('OL')
|
|
36
|
-
expect(list.classList).toContain('DocumentListLayout')
|
|
37
|
-
|
|
38
|
-
const items = screen.getAllByRole('listitem')
|
|
39
|
-
expect(items[0]).toContainHTML('Test Document 1')
|
|
40
|
-
expect(items[1]).toContainHTML('Test Document 2')
|
|
41
|
-
})
|
|
42
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import '../../css/styles.css'
|
|
2
|
-
|
|
3
|
-
import type {PropsWithChildren, ReactElement} from 'react'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export const DocumentListLayout = (props: PropsWithChildren): ReactElement => {
|
|
9
|
-
return <ol className="DocumentListLayout list-none">{props.children}</ol>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
DocumentListLayout.displayName = 'DocumentListLayout'
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# DocumentPreviewLayout
|
|
2
|
-
|
|
3
|
-
The DocumentPreviewLayout component is used to render a compact representation of a [document](#). These previews are often rendered for each document within a [DocumentListUI component](#), but can also be rendered as standalone components.
|
|
4
|
-
|
|
5
|
-
Document previews surface the following information about each document:
|
|
6
|
-
|
|
7
|
-
- The document's title
|
|
8
|
-
- A subtitle (optional)
|
|
9
|
-
- A piece of media, such as an icon or image (optional)
|
|
10
|
-
- The document type (optional)
|
|
11
|
-
- The document’s state, such as draft or published (optional)
|
|
12
|
-
|
|
13
|
-
Additionally, each document preview can take a `url` prop to enable navigation changes when selecting the document, and a `selected` prop to indicate that a given document has been selected.
|
|
14
|
-
|
|
15
|
-
![An image of the stock preview component]()
|
|
16
|
-
|
|
17
|
-
```jsx
|
|
18
|
-
<DocumentPreviewLayout
|
|
19
|
-
title={doc.title}
|
|
20
|
-
subtitle={doc.subtitle}
|
|
21
|
-
media={doc.media}
|
|
22
|
-
docType={doc.type}
|
|
23
|
-
docState={doc.published ? 'published' : 'draft'}
|
|
24
|
-
url={doc.url}
|
|
25
|
-
selected={true}
|
|
26
|
-
/>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
```shell
|
|
32
|
-
npm install @sanity/sdk
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
import DocumentPreviewLayout from `@sanity/sdk/react/DocumentPreviewLayout`
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Props
|
|
40
|
-
|
|
41
|
-
| Name | Type | Description |
|
|
42
|
-
| ---------- | -------------------- | ----------------------------------------------------------- |
|
|
43
|
-
| `title` | `string` | The title to display for the document |
|
|
44
|
-
| `subtitle` | `string` (optional) | The subtitle to display for the document |
|
|
45
|
-
| `media` | `node` (optional) | The image, icon, or other node to display with the document |
|
|
46
|
-
| `docType` | `string` (optional) | The document type |
|
|
47
|
-
| `docState` | `string` (optional) | The state of the document, such as 'published' or 'draft' |
|
|
48
|
-
| `url` | `string` (optional) | The URL to navigate to when selecting the document |
|
|
49
|
-
| `selected` | `boolean` (optional) | The `selected` state of the document; defaults to `false` |
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {type Meta, type StoryObj} from '@storybook/react'
|
|
2
|
-
|
|
3
|
-
import {DocumentPreviewLayout} from './DocumentPreviewLayout'
|
|
4
|
-
|
|
5
|
-
const meta: Meta<typeof DocumentPreviewLayout> = {
|
|
6
|
-
title: 'DocumentPreviewLayout',
|
|
7
|
-
component: DocumentPreviewLayout,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default meta
|
|
11
|
-
type Story = StoryObj<typeof meta>
|
|
12
|
-
|
|
13
|
-
export const Basic: Story = {
|
|
14
|
-
args: {
|
|
15
|
-
title: 'Hello World',
|
|
16
|
-
},
|
|
17
|
-
render: (props) => {
|
|
18
|
-
return <DocumentPreviewLayout {...props} />
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const AllProps: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
title: 'Hello World',
|
|
25
|
-
subtitle: 'It’s nice to meet you',
|
|
26
|
-
onClick: () => {
|
|
27
|
-
alert('Hello World!')
|
|
28
|
-
},
|
|
29
|
-
media: {
|
|
30
|
-
type: 'image-asset',
|
|
31
|
-
url: 'https://picsum.photos/80/80',
|
|
32
|
-
},
|
|
33
|
-
docType: 'article',
|
|
34
|
-
status: 'published',
|
|
35
|
-
},
|
|
36
|
-
render: (props) => {
|
|
37
|
-
return <DocumentPreviewLayout {...props} />
|
|
38
|
-
},
|
|
39
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {render, screen} from '../../../test/test-utils.tsx'
|
|
2
|
-
import {DocumentPreviewLayout} from './DocumentPreviewLayout'
|
|
3
|
-
|
|
4
|
-
describe('DocumentPreviewLayout', () => {
|
|
5
|
-
it('renders the data it receives via props', () => {
|
|
6
|
-
render(<DocumentPreviewLayout title="Test Preview" subtitle="It works" />)
|
|
7
|
-
expect(screen.getByText('Test Preview')).toBeVisible()
|
|
8
|
-
expect(screen.getByText('It works')).toBeVisible()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('renders empty when no title is provided (todo)', () => {
|
|
12
|
-
const {container} = render(<DocumentPreviewLayout title="" />)
|
|
13
|
-
expect(container).toBeEmptyDOMElement()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('renders the doctype when one is provided', () => {
|
|
17
|
-
render(<DocumentPreviewLayout title="Test Preview" docType="article" />)
|
|
18
|
-
expect(screen.getByText('article')).toBeVisible()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('renders the published status when provided', () => {
|
|
22
|
-
render(<DocumentPreviewLayout title="Test Preview" status="published" />)
|
|
23
|
-
expect(screen.getByText('published')).toBeVisible()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('renders the draft status when provided', () => {
|
|
27
|
-
render(<DocumentPreviewLayout title="Test Preview" status="draft" />)
|
|
28
|
-
expect(screen.getByText('draft')).toBeVisible()
|
|
29
|
-
})
|
|
30
|
-
})
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import 'inter-ui/inter.css'
|
|
2
|
-
import '../../css/styles.css'
|
|
3
|
-
|
|
4
|
-
import {DocumentIcon} from '@sanity/icons'
|
|
5
|
-
import {forwardRef} from 'react'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export interface DocumentPreviewLayoutProps {
|
|
11
|
-
docType?: string
|
|
12
|
-
media?: {type: string; url: string} | null | undefined
|
|
13
|
-
onClick?: () => void
|
|
14
|
-
selected?: boolean
|
|
15
|
-
status?: string
|
|
16
|
-
subtitle?: string
|
|
17
|
-
title: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* This is a component that renders a document preview.
|
|
22
|
-
*
|
|
23
|
-
* @public
|
|
24
|
-
*
|
|
25
|
-
* @param props - The props for the DocumentPreviewLayout component.
|
|
26
|
-
* @returns - The DocumentPreviewLayout component.
|
|
27
|
-
*/
|
|
28
|
-
export const DocumentPreviewLayout = forwardRef(
|
|
29
|
-
(
|
|
30
|
-
{
|
|
31
|
-
docType,
|
|
32
|
-
media,
|
|
33
|
-
onClick,
|
|
34
|
-
selected = false,
|
|
35
|
-
status = '',
|
|
36
|
-
subtitle = '',
|
|
37
|
-
title,
|
|
38
|
-
}: DocumentPreviewLayoutProps,
|
|
39
|
-
ref: React.Ref<HTMLElement>,
|
|
40
|
-
): JSX.Element => {
|
|
41
|
-
// @TODO: empty state
|
|
42
|
-
if (!title) {
|
|
43
|
-
return <></>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let PreviewMedia
|
|
47
|
-
|
|
48
|
-
if (media?.url) {
|
|
49
|
-
const baseUrl = new URL(media.url)
|
|
50
|
-
baseUrl.searchParams.set('h', '66')
|
|
51
|
-
baseUrl.searchParams.set('w', '66')
|
|
52
|
-
baseUrl.searchParams.set('fit', 'crop')
|
|
53
|
-
const mediaUrl = baseUrl.toString()
|
|
54
|
-
// media url string params for sanity img
|
|
55
|
-
PreviewMedia = <img src={mediaUrl} alt="" />
|
|
56
|
-
} else {
|
|
57
|
-
PreviewMedia = <DocumentIcon />
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<>
|
|
62
|
-
<style>{`
|
|
63
|
-
.DocumentPreviewLayout {
|
|
64
|
-
--_hoverFocusBg: light-dark(var(--shade-11), var(--tint-1));
|
|
65
|
-
--_selectedBg: light-dark(var(--blue-10), var(--blue-2));
|
|
66
|
-
--_selectedFg: light-dark(var(--gray-1), var(--gray-10));
|
|
67
|
-
--_titleFg: light-dark(var(--gray-1), var(--gray-10));
|
|
68
|
-
--_subtitleFg: light-dark(var(--gray-4), var(--gray-7));
|
|
69
|
-
--_docTypeFg: light-dark(var(--gray-1), var(--gray-10));
|
|
70
|
-
--_docTypeBg: light-dark(var(--shade-10), var(--tint-1));
|
|
71
|
-
--_publishedFg: light-dark(var(--gray-1), var(--gray-10));
|
|
72
|
-
--_publishedBg: light-dark(var(--green-10), var(--green-2));
|
|
73
|
-
--_draftFg: light-dark(var(--gray-1), var(--gray-10));
|
|
74
|
-
--_draftBg: light-dark(var(--yellow-6), var(--yellow-2));
|
|
75
|
-
|
|
76
|
-
appearance: none;
|
|
77
|
-
|
|
78
|
-
&:has(:hover, focus) {
|
|
79
|
-
background-color: var(--hoverFocusBg, var(--_hoverFocusBg));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
&.selected {
|
|
83
|
-
background-color: var(--selectedBg, var(--_selectedBg));
|
|
84
|
-
color: var(--selectedFg, var(--_selectedFg));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
.Title {
|
|
88
|
-
color: var(--titleFg, var(--_titleFg));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
&:not(.selected) .Subtitle {
|
|
92
|
-
color: var(--subtitleFg, var(--_subtitleFg));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.Media {
|
|
96
|
-
aspect-ratio: 1;
|
|
97
|
-
inline-size: 33px;
|
|
98
|
-
border-color: var(--gray-8);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
.DocType {
|
|
102
|
-
color: var(--docTypeFg, var(--_docTypeFg));
|
|
103
|
-
background-color: var(--docTypeBg, var(--_docTypeBg));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.Published {
|
|
107
|
-
color: var(--publishedFg, var(--_publishedFg));
|
|
108
|
-
background-color: var(--publishedBg, var(--_publishedBg));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.Draft {
|
|
112
|
-
color: var(--draftFg, var(--_draftFg));
|
|
113
|
-
background-color: var(--draftBg, var(--_draftBg));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
:is(.Published, .Draft) figcaption {
|
|
117
|
-
@container (width < 52ch) {
|
|
118
|
-
clip: rect(0 0 0 0);
|
|
119
|
-
clip-path: inset(50%);
|
|
120
|
-
height: 1px;
|
|
121
|
-
overflow: hidden;
|
|
122
|
-
position: absolute;
|
|
123
|
-
white-space: nowrap;
|
|
124
|
-
width: 1px;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
`}</style>
|
|
130
|
-
<button
|
|
131
|
-
onClick={onClick}
|
|
132
|
-
ref={ref as React.Ref<HTMLButtonElement>}
|
|
133
|
-
className={`DocumentPreviewLayout block si-100 text-start p-1 radius1 ${selected ? 'selected' : ''}`}
|
|
134
|
-
>
|
|
135
|
-
<div className="container-inline flex align-items-center gap-2 font-sans">
|
|
136
|
-
<figure className="Media border0 border-solid flex-none flex align-items-center justify-content-center object-cover">
|
|
137
|
-
{PreviewMedia}
|
|
138
|
-
</figure>
|
|
139
|
-
|
|
140
|
-
<div className="leading2 flex-grow overflow-hidden">
|
|
141
|
-
<p className="Title text-1 font-medium truncate">{title}</p>
|
|
142
|
-
{subtitle && <p className="Subtitle text-1 truncate">{subtitle}</p>}
|
|
143
|
-
</div>
|
|
144
|
-
|
|
145
|
-
{docType && (
|
|
146
|
-
<figure className="DocType inline-block pb-5 pi-3 radius-pill text-2">
|
|
147
|
-
<figcaption className="inline">{docType}</figcaption>
|
|
148
|
-
</figure>
|
|
149
|
-
)}
|
|
150
|
-
|
|
151
|
-
{/* @TODO: finalize UI for this */}
|
|
152
|
-
{status === 'published' && (
|
|
153
|
-
<figure className="Published inline-block pb-5 pi-3 radius-pill text-2">
|
|
154
|
-
✔︎ <figcaption className="inline">published</figcaption>
|
|
155
|
-
</figure>
|
|
156
|
-
)}
|
|
157
|
-
|
|
158
|
-
{/* @TODO: finalize UI for this */}
|
|
159
|
-
{status === 'draft' && (
|
|
160
|
-
<figure className="Draft inline-block pb-5 pi-3 radius-pill text-2">
|
|
161
|
-
⛑︎ <figcaption className="inline">draft</figcaption>
|
|
162
|
-
</figure>
|
|
163
|
-
)}
|
|
164
|
-
</div>
|
|
165
|
-
</button>
|
|
166
|
-
</>
|
|
167
|
-
)
|
|
168
|
-
},
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
DocumentPreviewLayout.displayName = 'DocumentPreviewLayout'
|