@sanity/sdk-react 0.0.0-alpha.8 → 0.0.0-rc.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.
Files changed (88) hide show
  1. package/README.md +33 -126
  2. package/dist/index.d.ts +4641 -2
  3. package/dist/index.js +960 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +17 -40
  6. package/src/_exports/index.ts +58 -10
  7. package/src/components/Login/LoginLinks.test.tsx +90 -0
  8. package/src/components/Login/LoginLinks.tsx +58 -0
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +104 -2
  12. package/src/components/SanityApp.tsx +54 -17
  13. package/src/components/auth/AuthBoundary.test.tsx +2 -2
  14. package/src/components/auth/AuthBoundary.tsx +13 -3
  15. package/src/components/auth/Login.test.tsx +1 -1
  16. package/src/components/auth/Login.tsx +11 -26
  17. package/src/components/auth/LoginCallback.tsx +4 -7
  18. package/src/components/auth/LoginError.tsx +12 -8
  19. package/src/components/auth/LoginFooter.tsx +13 -20
  20. package/src/components/auth/LoginLayout.tsx +8 -9
  21. package/src/components/auth/authTestHelpers.tsx +1 -8
  22. package/src/components/utils.ts +22 -0
  23. package/src/context/SanityInstanceContext.ts +4 -0
  24. package/src/context/SanityProvider.test.tsx +1 -1
  25. package/src/context/SanityProvider.tsx +10 -8
  26. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  27. package/src/hooks/auth/useAuthState.tsx +0 -2
  28. package/src/hooks/auth/useCurrentUser.tsx +26 -20
  29. package/src/hooks/client/useClient.ts +8 -30
  30. package/src/hooks/comlink/useFrameConnection.test.tsx +45 -10
  31. package/src/hooks/comlink/useFrameConnection.ts +24 -5
  32. package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
  33. package/src/hooks/comlink/useManageFavorite.ts +98 -0
  34. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
  35. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +75 -0
  36. package/src/hooks/comlink/useWindowConnection.test.ts +43 -12
  37. package/src/hooks/comlink/useWindowConnection.ts +13 -1
  38. package/src/hooks/context/useSanityInstance.test.tsx +1 -1
  39. package/src/hooks/context/useSanityInstance.ts +21 -5
  40. package/src/hooks/datasets/useDatasets.ts +37 -0
  41. package/src/hooks/document/useApplyActions.test.ts +25 -0
  42. package/src/hooks/document/useApplyActions.ts +74 -0
  43. package/src/hooks/document/useDocument.test.ts +81 -0
  44. package/src/hooks/document/useDocument.ts +107 -0
  45. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  46. package/src/hooks/document/useDocumentEvent.ts +54 -0
  47. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  48. package/src/hooks/document/useDocumentSyncStatus.ts +30 -0
  49. package/src/hooks/document/useEditDocument.test.ts +179 -0
  50. package/src/hooks/document/useEditDocument.ts +195 -0
  51. package/src/hooks/document/usePermissions.ts +82 -0
  52. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  53. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  54. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  55. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  56. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  57. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  58. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  59. package/src/hooks/preview/usePreview.tsx +7 -4
  60. package/src/hooks/projection/useProjection.test.tsx +218 -0
  61. package/src/hooks/projection/useProjection.ts +135 -0
  62. package/src/hooks/projects/useProject.ts +45 -0
  63. package/src/hooks/projects/useProjects.ts +41 -0
  64. package/src/hooks/query/useQuery.test.tsx +188 -0
  65. package/src/hooks/query/useQuery.ts +103 -0
  66. package/src/hooks/users/useUsers.test.ts +163 -0
  67. package/src/hooks/users/useUsers.ts +107 -0
  68. package/src/utils/getEnv.ts +21 -0
  69. package/src/version.ts +8 -0
  70. package/dist/_chunks-es/context.js +0 -8
  71. package/dist/_chunks-es/context.js.map +0 -1
  72. package/dist/_chunks-es/useLogOut.js +0 -44
  73. package/dist/_chunks-es/useLogOut.js.map +0 -1
  74. package/dist/components.d.ts +0 -111
  75. package/dist/components.js +0 -153
  76. package/dist/components.js.map +0 -1
  77. package/dist/context.d.ts +0 -45
  78. package/dist/context.js +0 -5
  79. package/dist/context.js.map +0 -1
  80. package/dist/hooks.d.ts +0 -3485
  81. package/dist/hooks.js +0 -167
  82. package/dist/hooks.js.map +0 -1
  83. package/src/_exports/components.ts +0 -2
  84. package/src/_exports/context.ts +0 -2
  85. package/src/_exports/hooks.ts +0 -27
  86. package/src/hooks/client/useClient.test.tsx +0 -130
  87. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  88. package/src/hooks/documentCollection/useDocuments.ts +0 -135
package/README.md CHANGED
@@ -7,155 +7,62 @@
7
7
 
8
8
  React hooks for creating Sanity applications.
9
9
 
10
- ## Installation
10
+ ## 💻 Installation
11
11
 
12
12
  ```bash
13
13
  npm i @sanity/sdk-react @sanity/sdk
14
14
  ```
15
15
 
16
- ## SDK Documentation
16
+ > 💡 Looking to build a Sanity application? Check out the [Quick Start](#quick-start) section.
17
+
18
+ ## 📚 SDK Documentation
17
19
 
18
20
  See the [SDK Documentation](https://sdk-docs.sanity.dev) for more information.
19
21
 
20
- ## Quick Start
22
+ ## 🚀 Quick Start
21
23
 
22
24
  Here's how to implement your Sanity application:
23
25
 
26
+ 1. Create a new React TypeScript project using the Sanity template
27
+
24
28
  ```bash
25
- # Create a new Vite React TypeScript project
26
- npm create vite@latest my-content-os-app -- --template react-ts -y
29
+ pnpx sanity@latest init --template core-app
27
30
  cd my-content-os-app
28
- # Install Sanity dependencies
29
- npm i @sanity/sdk-react @sanity/sdk
30
- # Run the app
31
- npm run dev
32
- # In another terminal, run the Sanity CoreUI
33
- npx @sanity/os-cli run --url=http://localhost:5173/
34
31
  ```
35
32
 
36
- ```tsx
37
- // src/App.tsx
38
- import {SanityConfig} from '@sanity/sdk'
39
- import {SanityApp} from '@sanity/sdk-react/components'
40
- import {useCurrentUser, useLogOut} from '@sanity/sdk-react/hooks'
41
-
42
- import './App.css'
43
-
44
- const sanityConfig: SanityConfig = {
45
- projectId: '<your-project-id>',
46
- dataset: '<your-dataset>',
47
- // optional auth config set projectId and dataset to '' and authScope to 'global' for a global token
48
- // auth: {
49
- // authScope: 'global',
50
- // ...
51
- // },
52
- }
53
-
54
- export function App(): JSX.Element {
55
- return (
56
- <SanityApp sanityConfig={sanityConfig}>
57
- <MyApp />
58
- </SanityApp>
59
- )
60
- }
61
-
62
- function MyApp() {
63
- const currentUser = useCurrentUser()
64
- const logout = useLogOut()
65
-
66
- return (
67
- <div>
68
- <h1>Hello, {currentUser?.name}!</h1>
69
- <button onClick={logout}>Logout</button>
70
- </div>
71
- )
72
- }
73
-
74
- export default App
75
- ```
33
+ 2. Install dependencies
76
34
 
77
- ```css
78
- /* src/App.css */
79
- #root {
80
- margin: auto;
81
- }
82
-
83
- .sc-login-layout {
84
- min-height: 100vh;
85
- display: flex;
86
- background: #f3f3f3;
87
- }
88
-
89
- .sc-login-layout__container {
90
- margin: auto;
91
- padding: 2rem;
92
- }
93
-
94
- .sc-login-layout__card {
95
- background: white;
96
- padding: 2rem;
97
- }
98
-
99
- .sc-login__title,
100
- .sc-login-callback {
101
- text-align: center;
102
- margin-bottom: 2rem;
103
- color: #333;
104
- }
105
-
106
- .sc-login-providers {
107
- display: flex;
108
- flex-direction: column;
109
- gap: 1rem;
110
- }
111
-
112
- .sc-login-providers a {
113
- padding: 0.8rem;
114
- border: 1px solid #ddd;
115
- text-decoration: none;
116
- color: #333;
117
- text-align: center;
118
- }
119
-
120
- .sc-login-footer {
121
- margin-top: 2rem;
122
- text-align: center;
123
- }
124
-
125
- .sc-login-footer__links {
126
- list-style: none;
127
- padding: 0;
128
- display: flex;
129
- justify-content: center;
130
- gap: 1.5rem;
131
- }
132
-
133
- .sc-login-footer__link a {
134
- font-size: 0.9rem;
135
- }
35
+ ```bash
36
+ npm i
136
37
  ```
137
38
 
138
- ## Available Hooks
39
+ 3. Run the app
139
40
 
140
- - `useAuthState` - Get current authentication state
141
- - `useCurrentUser` - Access the currently authenticated user
142
- - `useAuthToken` - Access the authentication token
143
- - `useLoginUrls` - Get OAuth login URLs
144
- - `useLogOut` - Handle user logout
145
- - `useSanityInstance` - Access the Sanity client instance
146
- - and more...
41
+ ```bash
42
+ npm run dev
43
+ ```
147
44
 
148
- ## TypeScript Support
45
+ 4. Open the App in Sanity Dashboard with your organization ID
46
+
47
+ ```
48
+ https://core.sanity.io/<your-organization-id>?dev=http://localhost:3333
49
+ ```
149
50
 
150
- This package includes TypeScript definitions. You can import types like:
51
+ 5. Update the `src/App.tsx` file with your Sanity project and dataset
151
52
 
152
53
  ```tsx
153
- import type {
154
- SanityProviderProps,
155
- AuthBoundaryProps,
156
- LoginLayoutProps,
157
- LoginErrorProps,
158
- } from '@sanity/react'
54
+ // src/App.tsx
55
+ import {createSanityInstance} from '@sanity/sdk'
56
+ ...
57
+
58
+ const sanityConfig: SanityConfigs = [
59
+ {
60
+ projectId: 'abc123',
61
+ dataset: 'production',
62
+ },
63
+ ]
64
+
65
+ ...
159
66
  ```
160
67
 
161
68
  ## License