@sanity/sdk-react 0.0.0-alpha.3 → 0.0.0-alpha.30

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.
Files changed (131) hide show
  1. package/README.md +6 -100
  2. package/dist/index.d.ts +2390 -2
  3. package/dist/index.js +1119 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +35 -49
  6. package/src/_exports/index.ts +2 -10
  7. package/src/_exports/sdk-react.ts +73 -0
  8. package/src/components/SDKProvider.test.tsx +103 -0
  9. package/src/components/SDKProvider.tsx +52 -0
  10. package/src/components/SanityApp.test.tsx +244 -0
  11. package/src/components/SanityApp.tsx +106 -0
  12. package/src/components/auth/AuthBoundary.test.tsx +204 -29
  13. package/src/components/auth/AuthBoundary.tsx +96 -19
  14. package/src/components/auth/ConfigurationError.ts +22 -0
  15. package/src/components/auth/LoginCallback.test.tsx +22 -24
  16. package/src/components/auth/LoginCallback.tsx +6 -16
  17. package/src/components/auth/LoginError.test.tsx +11 -18
  18. package/src/components/auth/LoginError.tsx +43 -25
  19. package/src/components/utils.ts +22 -0
  20. package/src/context/ResourceProvider.test.tsx +157 -0
  21. package/src/context/ResourceProvider.tsx +111 -0
  22. package/src/context/SanityInstanceContext.ts +4 -0
  23. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  24. package/src/hooks/auth/useAuthState.tsx +4 -5
  25. package/src/hooks/auth/useAuthToken.tsx +1 -1
  26. package/src/hooks/auth/useCurrentUser.tsx +28 -4
  27. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  28. package/src/hooks/auth/useDashboardOrganizationId.tsx +30 -0
  29. package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
  30. package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
  31. package/src/hooks/auth/useLogOut.test.tsx +2 -2
  32. package/src/hooks/auth/useLogOut.tsx +1 -1
  33. package/src/hooks/auth/useLoginUrl.tsx +14 -0
  34. package/src/hooks/auth/useVerifyOrgProjects.test.tsx +136 -0
  35. package/src/hooks/auth/useVerifyOrgProjects.tsx +48 -0
  36. package/src/hooks/client/useClient.ts +13 -33
  37. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  38. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  39. package/src/hooks/comlink/useManageFavorite.test.ts +368 -0
  40. package/src/hooks/comlink/useManageFavorite.ts +210 -0
  41. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +85 -0
  42. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +115 -0
  43. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  44. package/src/hooks/comlink/useWindowConnection.ts +123 -0
  45. package/src/hooks/context/useSanityInstance.test.tsx +157 -15
  46. package/src/hooks/context/useSanityInstance.ts +68 -11
  47. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +276 -0
  48. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +139 -0
  49. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +291 -0
  50. package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +101 -0
  51. package/src/hooks/datasets/useDatasets.test.ts +80 -0
  52. package/src/hooks/datasets/useDatasets.ts +52 -0
  53. package/src/hooks/document/useApplyDocumentActions.test.ts +20 -0
  54. package/src/hooks/document/useApplyDocumentActions.ts +124 -0
  55. package/src/hooks/document/useDocument.test.ts +118 -0
  56. package/src/hooks/document/useDocument.ts +212 -0
  57. package/src/hooks/document/useDocumentEvent.test.ts +62 -0
  58. package/src/hooks/document/useDocumentEvent.ts +94 -0
  59. package/src/hooks/document/useDocumentPermissions.test.ts +204 -0
  60. package/src/hooks/document/useDocumentPermissions.ts +131 -0
  61. package/src/hooks/document/useDocumentSyncStatus.test.ts +23 -0
  62. package/src/hooks/document/useDocumentSyncStatus.ts +61 -0
  63. package/src/hooks/document/useEditDocument.test.ts +196 -0
  64. package/src/hooks/document/useEditDocument.ts +314 -0
  65. package/src/hooks/documents/useDocuments.test.tsx +179 -0
  66. package/src/hooks/documents/useDocuments.ts +300 -0
  67. package/src/hooks/helpers/createCallbackHook.test.tsx +2 -2
  68. package/src/hooks/helpers/createCallbackHook.tsx +1 -1
  69. package/src/hooks/helpers/createStateSourceHook.test.tsx +67 -1
  70. package/src/hooks/helpers/createStateSourceHook.tsx +27 -11
  71. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +284 -0
  72. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +353 -0
  73. package/src/hooks/preview/usePreview.test.tsx +85 -17
  74. package/src/hooks/preview/usePreview.tsx +81 -22
  75. package/src/hooks/projection/useProjection.test.tsx +283 -0
  76. package/src/hooks/projection/useProjection.ts +232 -0
  77. package/src/hooks/projects/useProject.test.ts +80 -0
  78. package/src/hooks/projects/useProject.ts +51 -0
  79. package/src/hooks/projects/useProjects.test.ts +77 -0
  80. package/src/hooks/projects/useProjects.ts +45 -0
  81. package/src/hooks/query/useQuery.test.tsx +188 -0
  82. package/src/hooks/query/useQuery.ts +193 -0
  83. package/src/hooks/releases/useActiveReleases.test.tsx +84 -0
  84. package/src/hooks/releases/useActiveReleases.ts +39 -0
  85. package/src/hooks/releases/usePerspective.test.tsx +120 -0
  86. package/src/hooks/releases/usePerspective.ts +49 -0
  87. package/src/hooks/users/useUsers.test.tsx +330 -0
  88. package/src/hooks/users/useUsers.ts +120 -0
  89. package/src/utils/getEnv.ts +21 -0
  90. package/src/version.ts +8 -0
  91. package/src/vite-env.d.ts +10 -0
  92. package/dist/_chunks-es/useLogOut.js +0 -44
  93. package/dist/_chunks-es/useLogOut.js.map +0 -1
  94. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  95. package/dist/components.d.ts +0 -259
  96. package/dist/components.js +0 -301
  97. package/dist/components.js.map +0 -1
  98. package/dist/hooks.d.ts +0 -186
  99. package/dist/hooks.js +0 -81
  100. package/dist/hooks.js.map +0 -1
  101. package/src/_exports/components.ts +0 -13
  102. package/src/_exports/hooks.ts +0 -9
  103. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  104. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  105. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  106. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  107. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  108. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  109. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  110. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  111. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  112. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  113. package/src/components/Login/LoginLinks.test.tsx +0 -100
  114. package/src/components/Login/LoginLinks.tsx +0 -73
  115. package/src/components/auth/Login.test.tsx +0 -41
  116. package/src/components/auth/Login.tsx +0 -45
  117. package/src/components/auth/LoginFooter.test.tsx +0 -29
  118. package/src/components/auth/LoginFooter.tsx +0 -65
  119. package/src/components/auth/LoginLayout.test.tsx +0 -33
  120. package/src/components/auth/LoginLayout.tsx +0 -81
  121. package/src/components/context/SanityProvider.test.tsx +0 -25
  122. package/src/components/context/SanityProvider.tsx +0 -42
  123. package/src/css/css.config.js +0 -220
  124. package/src/css/paramour.css +0 -2347
  125. package/src/css/styles.css +0 -11
  126. package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
  127. package/src/hooks/auth/useLoginUrls.test.tsx +0 -68
  128. package/src/hooks/auth/useLoginUrls.tsx +0 -51
  129. package/src/hooks/client/useClient.test.tsx +0 -130
  130. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  131. package/src/hooks/documentCollection/useDocuments.ts +0 -87
@@ -1,81 +0,0 @@
1
- import {Card, Flex} from '@sanity/ui'
2
-
3
- import {LoginFooter} from './LoginFooter'
4
-
5
- /**
6
- * @alpha
7
- */
8
- export interface LoginLayoutProps {
9
- /** Optional header content rendered at top of card */
10
- header?: React.ReactNode
11
-
12
- /** Optional footer content rendered below card. Defaults to an internal login footer */
13
- footer?: React.ReactNode
14
-
15
- /** Main content rendered in card body */
16
- children?: React.ReactNode
17
- }
18
-
19
- /**
20
- * Layout component for login-related screens providing consistent styling and structure.
21
- * Renders content in a centered card with optional header and footer sections.
22
- *
23
- * Can be used to build custom login screens for the AuthBoundary component, including:
24
- * - Login provider selection (LoginComponent)
25
- * - OAuth callback handling (CallbackComponent)
26
- * - Error states (LoginErrorComponent)
27
- *
28
- * @example
29
- * ```tsx
30
- * // Custom login screen using the layout
31
- * function CustomLogin({header, footer}: LoginLayoutProps) {
32
- * return (
33
- * <LoginLayout
34
- * header={header}
35
- * footer={footer}
36
- * >
37
- * <CustomLoginContent />
38
- * </LoginLayout>
39
- * )
40
- * }
41
- *
42
- * // Use with AuthBoundary
43
- * <AuthBoundary
44
- * LoginComponent={CustomLogin}
45
- * header={<Logo />}
46
- * >
47
- * <ProtectedContent />
48
- * </AuthBoundary>
49
- * ```
50
- *
51
- * @alpha
52
- */
53
- export function LoginLayout({
54
- children,
55
- footer = <LoginFooter />,
56
- header,
57
- }: LoginLayoutProps): React.ReactNode {
58
- return (
59
- <div style={{width: '100%', display: 'flex'}}>
60
- <Flex direction="column" gap={4} style={{width: '320px', margin: 'auto', display: 'flex'}}>
61
- <Card border radius={2} paddingY={4}>
62
- <Flex direction="column" gap={4}>
63
- {header && (
64
- <Card borderBottom paddingX={4} paddingBottom={3}>
65
- {header}
66
- </Card>
67
- )}
68
-
69
- {children && (
70
- <Flex paddingX={4} direction="column" style={{minHeight: '154px'}}>
71
- {children}
72
- </Flex>
73
- )}
74
- </Flex>
75
- </Card>
76
-
77
- {footer}
78
- </Flex>
79
- </div>
80
- )
81
- }
@@ -1,25 +0,0 @@
1
- import {createSanityInstance} from '@sanity/sdk'
2
- import {render} from '@testing-library/react'
3
- import {describe, expect, it} from 'vitest'
4
-
5
- import {useSanityInstance} from '../../hooks/context/useSanityInstance'
6
- import {SanityProvider} from './SanityProvider'
7
-
8
- describe('SanityProvider', () => {
9
- const sanityInstance = createSanityInstance({projectId: 'test-project', dataset: 'production'})
10
-
11
- it('provides instance to nested components', () => {
12
- const TestComponent = () => {
13
- const instance = useSanityInstance()
14
- return <div data-testid="test">{instance.identity.projectId}</div>
15
- }
16
-
17
- const {getByTestId} = render(
18
- <SanityProvider sanityInstance={sanityInstance}>
19
- <TestComponent />
20
- </SanityProvider>,
21
- )
22
-
23
- expect(getByTestId('test')).toHaveTextContent('test-project')
24
- })
25
- })
@@ -1,42 +0,0 @@
1
- import {type SanityInstance} from '@sanity/sdk'
2
- import {createContext, type ReactElement} from 'react'
3
-
4
- /**
5
- * @public
6
- */
7
- export interface SanityProviderProps {
8
- children: React.ReactNode
9
- sanityInstance: SanityInstance
10
- }
11
-
12
- export const SanityInstanceContext = createContext<SanityInstance | null>(null)
13
-
14
- /**
15
- * Top-level context provider that provides a Sanity configuration instance.
16
- * This must wrap any Sanity SDK React component.
17
- * @public
18
- * @param props - Sanity project and dataset configuration
19
- * @returns Rendered component
20
- * @example
21
- * ```tsx
22
- * import {createSanityInstance} from '@sanity/sdk'
23
- * import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'
24
- *
25
- * const sanityInstance = createSanityInstance({projectId: 'your-project-id', dataset: 'production'})
26
- *
27
- * export default function MyApp() {
28
- * return (
29
- * <SanityProvider sanityInstance={sanityInstance}>
30
- * <ExampleComponent />
31
- * </SanityProvider>
32
- * )
33
- * }
34
- * ```
35
- */
36
- export const SanityProvider = ({children, sanityInstance}: SanityProviderProps): ReactElement => {
37
- return (
38
- <SanityInstanceContext.Provider value={sanityInstance}>
39
- {children}
40
- </SanityInstanceContext.Provider>
41
- )
42
- }
@@ -1,220 +0,0 @@
1
- export default {
2
- color: {
3
- spots: {
4
- 'tint-0': 'hsla(0, 0%, 100%, 0.035)',
5
- 'tint-1': 'hsla(0, 0%, 100%, 0.1)',
6
- 'tint-2': 'hsla(0, 0%, 100%, 0.19)',
7
- 'tint-3': 'hsla(0, 0%, 100%, 0.28)',
8
- 'tint-4': 'hsla(0, 0%, 100%, 0.36)',
9
- 'tint-5': 'hsla(0, 0%, 100%, 0.45)',
10
- 'tint-6': 'hsla(0, 0%, 100%, 0.55)',
11
- 'tint-7': 'hsla(0, 0%, 100%, 0.64)',
12
- 'tint-8': 'hsla(0, 0%, 100%, 0.73)',
13
- 'tint-9': 'hsla(0, 0%, 100%, 0.815)',
14
- 'tint-10': 'hsla(0, 0%, 100%, 0.895)',
15
- 'tint-11': 'hsla(0, 0%, 100%, 0.94)',
16
-
17
- 'shade-0': 'hsla(0, 0%, 0%, 0.94)',
18
- 'shade-1': 'hsla(0, 0%, 0%, 0.899)',
19
- 'shade-2': 'hsla(0, 0%, 0%, 0.8)',
20
- 'shade-3': 'hsla(0, 0%, 0%, 0.69)',
21
- 'shade-4': 'hsla(0, 0%, 0%, 0.6)',
22
- 'shade-5': 'hsla(0, 0%, 0%, 0.5)',
23
- 'shade-6': 'hsla(0, 0%, 0%, 0.41)',
24
- 'shade-7': 'hsla(0, 0%, 0%, 0.32)',
25
- 'shade-8': 'hsla(0, 0%, 0%, 0.24)',
26
- 'shade-9': 'hsla(0, 0%, 0%, 0.16)',
27
- 'shade-10': 'hsla(0, 0%, 0%, 0.07)',
28
- 'shade-11': 'hsla(0, 0%, 0%, 0.035)',
29
-
30
- 'gray-0': '#000000',
31
- 'gray-1': '#1a1a1a',
32
- 'gray-2': '#353535',
33
- 'gray-3': '#4e4e4e',
34
- 'gray-4': '#686868',
35
- 'gray-5': '#808080',
36
- 'gray-6': '#979797',
37
- 'gray-7': '#adadad',
38
- 'gray-8': '#c2c2c2',
39
- 'gray-9': '#d7d7d7',
40
- 'gray-10': '#ebebeb',
41
- 'gray-11': '#ffffff',
42
-
43
- 'slate-gray-0': '#0c0c0e',
44
- 'slate-gray-1': '#26262c',
45
- 'slate-gray-2': '#403f49',
46
- 'slate-gray-3': '#595865',
47
- 'slate-gray-4': '#71707f',
48
- 'slate-gray-5': '#878697',
49
- 'slate-gray-6': '#9d9cad',
50
- 'slate-gray-7': '#b1b0c0',
51
- 'slate-gray-8': '#c4c4d0',
52
- 'slate-gray-9': '#d7d6e0',
53
- 'slate-gray-10': '#e8e8ee',
54
- 'slate-gray-11': '#fafafb',
55
-
56
- 'blue-0': '#060c16',
57
- 'blue-1': '#122443',
58
- 'blue-2': '#1f3c6f',
59
- 'blue-3': '#2e5397',
60
- 'blue-4': '#3e6aba',
61
- 'blue-5': '#5180d7',
62
- 'blue-6': '#6696ec',
63
- 'blue-7': '#7faaf9',
64
- 'blue-8': '#99beff',
65
- 'blue-9': '#b6d2ff',
66
- 'blue-10': '#d4e4ff',
67
- 'blue-11': '#f2f7ff',
68
-
69
- 'indigo-0': '#0d0a18',
70
- 'indigo-1': '#271f4b',
71
- 'indigo-2': '#41337b',
72
- 'indigo-3': '#5b48a6',
73
- 'indigo-4': '#735dcc',
74
- 'indigo-5': '#8a72ea',
75
- 'indigo-6': '#a088ff',
76
- 'indigo-7': '#b39eff',
77
- 'indigo-8': '#c6b3ff',
78
- 'indigo-9': '#d7c9ff',
79
- 'indigo-10': '#e8e0ff',
80
- 'indigo-11': '#f8f6ff',
81
-
82
- 'violet-0': '#160a1b',
83
- 'violet-1': '#3b1a47',
84
- 'violet-2': '#5e2a72',
85
- 'violet-3': '#7f3c98',
86
- 'violet-4': '#9d4eba',
87
- 'violet-5': '#b662d6',
88
- 'violet-6': '#cb77eb',
89
- 'violet-7': '#db8ef8',
90
- 'violet-8': '#e7a6ff',
91
- 'violet-9': '#f0c0ff',
92
- 'violet-10': '#f7daff',
93
- 'violet-11': '#fdf4ff',
94
-
95
- 'magenta-0': '#130811',
96
- 'magenta-1': '#381831',
97
- 'magenta-2': '#5c2850',
98
- 'magenta-3': '#803870',
99
- 'magenta-4': '#a4488f',
100
- 'magenta-5': '#c858af',
101
- 'magenta-6': '#db6ec3',
102
- 'magenta-7': '#e289ce',
103
- 'magenta-8': '#e8a4d9',
104
- 'magenta-9': '#efbfe4',
105
- 'magenta-10': '#f6daf0',
106
- 'magenta-11': '#fdf5fb',
107
-
108
- 'red-0': '#130707',
109
- 'red-1': '#3b1516',
110
- 'red-2': '#632325',
111
- 'red-3': '#8b3233',
112
- 'red-4': '#b34042',
113
- 'red-5': '#db4e51',
114
- 'red-6': '#f06467',
115
- 'red-7': '#f28183',
116
- 'red-8': '#f59d9f',
117
- 'red-9': '#f8babb',
118
- 'red-10': '#fbd7d7',
119
- 'red-11': '#fef3f3',
120
-
121
- 'red-orange-0': '#120705',
122
- 'red-orange-1': '#371410',
123
- 'red-orange-2': '#5c221a',
124
- 'red-orange-3': '#813025',
125
- 'red-orange-4': '#a63e2f',
126
- 'red-orange-5': '#cc4c3a',
127
- 'red-orange-6': '#e06150',
128
- 'red-orange-7': '#e67f70',
129
- 'red-orange-8': '#eb9c91',
130
- 'red-orange-9': '#f1b9b1',
131
- 'red-orange-10': '#f7d6d1',
132
- 'red-orange-11': '#fdf3f2',
133
-
134
- 'orange-0': '#201307',
135
- 'orange-1': '#43240f',
136
- 'orange-2': '#693612',
137
- 'orange-3': '#8f4812',
138
- 'orange-4': '#b05710',
139
- 'orange-5': '#d1660c',
140
- 'orange-6': '#f47603',
141
- 'orange-7': '#ff8f32',
142
- 'orange-8': '#ffa960',
143
- 'orange-9': '#ffc28c',
144
- 'orange-10': '#ffdab8',
145
- 'orange-11': '#fff2e7',
146
-
147
- 'yellow-0': '#000000',
148
- 'yellow-1': '#413b15',
149
- 'yellow-2': '#655c19',
150
- 'yellow-3': '#857a1a',
151
- 'yellow-4': '#a1941a',
152
- 'yellow-5': '#c0b017',
153
- 'yellow-6': '#eedb0b',
154
- 'yellow-7': '#feee45',
155
- 'yellow-8': '#fdf377',
156
- 'yellow-9': '#fdf8a2',
157
- 'yellow-10': '#fdfcca',
158
- 'yellow-11': '#fffff1',
159
-
160
- 'green-0': '#011409',
161
- 'green-1': '#0a311e',
162
- 'green-2': '#134d33',
163
- 'green-3': '#1b6846',
164
- 'green-4': '#238158',
165
- 'green-5': '#2b9968',
166
- 'green-6': '#34b379',
167
- 'green-7': '#45dc8f',
168
- 'green-8': '#58f19c',
169
- 'green-9': '#9ef4c4',
170
- 'green-10': '#c5f9dd',
171
- 'green-11': '#effff9',
172
-
173
- 'teal-0': '#080e0c',
174
- 'teal-1': '#152621',
175
- 'teal-2': '#1d3f35',
176
- 'teal-3': '#25594a',
177
- 'teal-4': '#2b7560',
178
- 'teal-5': '#309178',
179
- 'teal-6': '#48a98e',
180
- 'teal-7': '#6eb9a1',
181
- 'teal-8': '#90c9b6',
182
- 'teal-9': '#b0d8ca',
183
- 'teal-10': '#d0e8df',
184
- 'teal-11': '#f0f8f5',
185
-
186
- 'cyan-0': '#000000',
187
- 'cyan-1': '#132223',
188
- 'cyan-2': '#1b3f41',
189
- 'cyan-3': '#205e62',
190
- 'cyan-4': '#237f84',
191
- 'cyan-5': '#21a2a8',
192
- 'cyan-6': '#45bbc1',
193
- 'cyan-7': '#74c9cd',
194
- 'cyan-8': '#9ad6d9',
195
- 'cyan-9': '#bde4e6',
196
- 'cyan-10': '#def2f2',
197
- 'cyan-11': '#ffffff',
198
- },
199
- },
200
- fonts: {
201
- sans: 'Inter, system-ui, Avenir, Helvetica, Arial, sans-serif',
202
- },
203
- grid: {
204
- steps: 12,
205
- },
206
- spaceScale: {
207
- steps: 6,
208
- baseMin: 16,
209
- baseMax: 16,
210
- scaleMin: 'minor-third',
211
- scaleMax: 'minor-third',
212
- },
213
- typeScale: {
214
- steps: 6,
215
- baseMin: 16,
216
- baseMax: 16,
217
- scaleMin: 'minor-third',
218
- scaleMax: 'minor-third',
219
- },
220
- }