@sanity/sdk-react 0.0.0-alpha.9 → 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.
- package/README.md +33 -126
- package/dist/index.d.ts +4641 -2
- package/dist/index.js +960 -2
- package/dist/index.js.map +1 -1
- package/package.json +17 -41
- package/src/_exports/index.ts +58 -10
- package/src/components/Login/LoginLinks.test.tsx +90 -0
- package/src/components/Login/LoginLinks.tsx +58 -0
- package/src/components/SDKProvider.test.tsx +79 -0
- package/src/components/SDKProvider.tsx +42 -0
- package/src/components/SanityApp.test.tsx +104 -2
- package/src/components/SanityApp.tsx +54 -17
- package/src/components/auth/AuthBoundary.test.tsx +2 -2
- package/src/components/auth/AuthBoundary.tsx +13 -3
- package/src/components/auth/Login.test.tsx +1 -1
- package/src/components/auth/Login.tsx +11 -26
- package/src/components/auth/LoginCallback.tsx +4 -7
- package/src/components/auth/LoginError.tsx +12 -8
- package/src/components/auth/LoginFooter.tsx +13 -20
- package/src/components/auth/LoginLayout.tsx +8 -9
- package/src/components/auth/authTestHelpers.tsx +1 -8
- package/src/components/utils.ts +22 -0
- package/src/context/SanityInstanceContext.ts +4 -0
- package/src/context/SanityProvider.test.tsx +1 -1
- package/src/context/SanityProvider.tsx +10 -8
- package/src/hooks/_synchronous-groq-js.mjs +4 -0
- package/src/hooks/auth/useAuthState.tsx +0 -2
- package/src/hooks/auth/useCurrentUser.tsx +26 -20
- package/src/hooks/client/useClient.ts +8 -30
- package/src/hooks/comlink/useFrameConnection.test.tsx +45 -10
- package/src/hooks/comlink/useFrameConnection.ts +24 -5
- package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
- package/src/hooks/comlink/useManageFavorite.ts +98 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +75 -0
- package/src/hooks/comlink/useWindowConnection.test.ts +43 -12
- package/src/hooks/comlink/useWindowConnection.ts +13 -1
- package/src/hooks/context/useSanityInstance.test.tsx +1 -1
- package/src/hooks/context/useSanityInstance.ts +21 -5
- package/src/hooks/datasets/useDatasets.ts +37 -0
- package/src/hooks/document/useApplyActions.test.ts +5 -4
- package/src/hooks/document/useApplyActions.ts +55 -5
- package/src/hooks/document/useDocument.test.ts +2 -2
- package/src/hooks/document/useDocument.ts +90 -21
- package/src/hooks/document/useDocumentEvent.test.ts +13 -3
- package/src/hooks/document/useDocumentEvent.ts +36 -4
- package/src/hooks/document/useDocumentSyncStatus.test.ts +1 -1
- package/src/hooks/document/useDocumentSyncStatus.ts +26 -2
- package/src/hooks/document/useEditDocument.test.ts +55 -10
- package/src/hooks/document/useEditDocument.ts +159 -31
- 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.tsx +7 -4
- package/src/hooks/projection/useProjection.test.tsx +218 -0
- package/src/hooks/projection/useProjection.ts +135 -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/dist/_chunks-es/context.js +0 -8
- package/dist/_chunks-es/context.js.map +0 -1
- package/dist/_chunks-es/useLogOut.js +0 -45
- package/dist/_chunks-es/useLogOut.js.map +0 -1
- package/dist/components.d.ts +0 -111
- package/dist/components.js +0 -153
- package/dist/components.js.map +0 -1
- package/dist/context.d.ts +0 -45
- package/dist/context.js +0 -5
- package/dist/context.js.map +0 -1
- package/dist/hooks.d.ts +0 -3532
- package/dist/hooks.js +0 -218
- package/dist/hooks.js.map +0 -1
- package/src/_exports/components.ts +0 -2
- package/src/_exports/context.ts +0 -2
- package/src/_exports/hooks.ts +0 -32
- 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 -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
78
|
-
|
|
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
|
-
|
|
39
|
+
3. Run the app
|
|
139
40
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
+
5. Update the `src/App.tsx` file with your Sanity project and dataset
|
|
151
52
|
|
|
152
53
|
```tsx
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|