@sanity/sdk-react 0.0.0-alpha.1 → 0.0.0-alpha.11
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 +163 -0
- package/dist/_chunks-es/context.js +8 -0
- package/dist/_chunks-es/context.js.map +1 -0
- package/dist/_chunks-es/useLogOut.js +29 -20
- package/dist/_chunks-es/useLogOut.js.map +1 -1
- package/dist/components.d.ts +24 -149
- package/dist/components.js +33 -153
- package/dist/components.js.map +1 -1
- package/dist/context.d.ts +45 -0
- package/dist/context.js +5 -0
- package/dist/context.js.map +1 -0
- package/dist/hooks.d.ts +3401 -12
- package/dist/hooks.js +210 -15
- package/dist/hooks.js.map +1 -1
- package/package.json +42 -32
- package/src/_exports/components.ts +2 -12
- package/src/_exports/context.ts +2 -0
- package/src/_exports/hooks.ts +25 -0
- package/src/components/Login/LoginLinks.test.tsx +7 -16
- package/src/components/Login/LoginLinks.tsx +14 -29
- package/src/components/SanityApp.test.tsx +54 -0
- package/src/components/SanityApp.tsx +53 -0
- package/src/components/auth/AuthBoundary.test.tsx +17 -21
- package/src/components/auth/AuthBoundary.tsx +14 -7
- 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/context → context}/SanityProvider.test.tsx +1 -1
- package/src/{components/context → context}/SanityProvider.tsx +12 -6
- package/src/hooks/auth/useAuthState.test.tsx +10 -100
- package/src/hooks/auth/useAuthState.tsx +5 -10
- package/src/hooks/auth/useAuthToken.test.tsx +10 -88
- package/src/hooks/auth/useAuthToken.tsx +4 -10
- package/src/hooks/auth/useCurrentUser.test.tsx +10 -44
- package/src/hooks/auth/useCurrentUser.tsx +22 -22
- package/src/hooks/auth/useHandleCallback.test.tsx +10 -19
- package/src/hooks/auth/useHandleCallback.tsx +4 -9
- package/src/hooks/auth/useLogOut.test.tsx +11 -62
- package/src/hooks/auth/useLogOut.tsx +4 -9
- package/src/hooks/auth/useLoginUrls.test.tsx +47 -40
- package/src/hooks/auth/useLoginUrls.tsx +7 -6
- package/src/hooks/client/useClient.test.tsx +1 -1
- package/src/hooks/client/useClient.ts +3 -3
- package/src/hooks/comlink/useFrameConnection.test.tsx +122 -0
- package/src/hooks/comlink/useFrameConnection.ts +111 -0
- package/src/hooks/comlink/useWindowConnection.test.ts +94 -0
- package/src/hooks/comlink/useWindowConnection.ts +82 -0
- package/src/hooks/context/useSanityInstance.test.tsx +1 -1
- package/src/hooks/context/useSanityInstance.ts +4 -4
- package/src/hooks/document/useApplyActions.test.ts +24 -0
- package/src/hooks/document/useApplyActions.ts +24 -0
- package/src/hooks/document/useDocument.test.ts +81 -0
- package/src/hooks/document/useDocument.ts +38 -0
- package/src/hooks/document/useDocumentEvent.test.ts +53 -0
- package/src/hooks/document/useDocumentEvent.ts +22 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
- package/src/hooks/document/useDocumentSyncStatus.ts +6 -0
- package/src/hooks/document/useEditDocument.test.ts +172 -0
- package/src/hooks/document/useEditDocument.ts +80 -0
- package/src/hooks/documentCollection/useDocuments.test.ts +130 -0
- package/src/hooks/documentCollection/useDocuments.ts +135 -0
- package/src/hooks/helpers/createCallbackHook.test.tsx +106 -0
- package/src/hooks/helpers/createCallbackHook.tsx +15 -0
- package/src/hooks/helpers/createStateSourceHook.test.tsx +130 -0
- package/src/hooks/helpers/createStateSourceHook.tsx +21 -0
- package/src/hooks/preview/usePreview.test.tsx +175 -0
- package/src/hooks/preview/usePreview.tsx +120 -0
- package/src/vite-env.d.ts +10 -0
- package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -95
- package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
- package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -23
- package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -95
- package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
- package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -15
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -34
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -115
- package/src/hooks/Documents/.keep +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://sanity.io">
|
|
3
|
+
<img src="https://cdn.sanity.io/images/3do82whm/next/1dfce9dde7a62ccaa8e8377254a1e919f6c07ad3-128x128.svg" />
|
|
4
|
+
</a>
|
|
5
|
+
<h1 align="center">Sanity SDK - React</h1>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
React hooks for creating Sanity applications.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i @sanity/sdk-react @sanity/sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## SDK Documentation
|
|
17
|
+
|
|
18
|
+
See the [SDK Documentation](https://sdk-docs.sanity.dev) for more information.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
Here's how to implement your Sanity application:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Create a new Vite React TypeScript project
|
|
26
|
+
npm create vite@latest my-content-os-app -- --template react-ts -y
|
|
27
|
+
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
|
+
```
|
|
35
|
+
|
|
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
|
+
```
|
|
76
|
+
|
|
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
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Available Hooks
|
|
139
|
+
|
|
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...
|
|
147
|
+
|
|
148
|
+
## TypeScript Support
|
|
149
|
+
|
|
150
|
+
This package includes TypeScript definitions. You can import types like:
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import type {
|
|
154
|
+
SanityProviderProps,
|
|
155
|
+
AuthBoundaryProps,
|
|
156
|
+
LoginLayoutProps,
|
|
157
|
+
LoginErrorProps,
|
|
158
|
+
} from '@sanity/react'
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT © Sanity.io
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
const SanityInstanceContext = createContext(null), SanityProvider = ({ children, sanityInstance }) => /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstance, children });
|
|
4
|
+
export {
|
|
5
|
+
SanityInstanceContext,
|
|
6
|
+
SanityProvider
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../../src/context/SanityProvider.tsx"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {createContext, type ReactElement} from 'react'\n\n/**\n * @public\n */\nexport interface SanityProviderProps {\n children: React.ReactNode\n sanityInstance: SanityInstance\n}\n\nexport const SanityInstanceContext = createContext<SanityInstance | null>(null)\n\n/**\n * Top-level context provider that provides access to the Sanity configuration instance.\n * This must wrap any components making use of the Sanity SDK React hooks.\n * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.\n * @internal\n * @param props - Sanity project and dataset configuration\n * @returns Rendered component\n * @example\n * ```tsx\n * import {createSanityInstance} from '@sanity/sdk'\n * import {SanityProvider} from '@sanity/sdk-react'\n *\n * import MyAppRoot from './Root'\n *\n * const sanityInstance = createSanityInstance({\n * projectId: 'your-project-id',\n * dataset: 'production',\n * })\n *\n * export default function MyApp() {\n * return (\n * <SanityProvider sanityInstance={sanityInstance}>\n * <MyAppRoot />\n * </SanityProvider>\n * )\n * }\n * ```\n */\nexport const SanityProvider = ({children, sanityInstance}: SanityProviderProps): ReactElement => {\n return (\n <SanityInstanceContext.Provider value={sanityInstance}>\n {children}\n </SanityInstanceContext.Provider>\n )\n}\n"],"names":[],"mappings":";;AAWO,MAAM,wBAAwB,cAAqC,IAAI,GA8BjE,iBAAiB,CAAC,EAAC,UAAU,eAAc,0BAEnD,sBAAsB,UAAtB,EAA+B,OAAO,gBACpC,SACH,CAAA;"}
|
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const SanityInstanceContext = createContext(null), SanityProvider = ({ children, sanityInstance }) => /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstance, children }), useSanityInstance = () => {
|
|
1
|
+
import { getAuthState, handleCallback, getLoginUrlsState, fetchLoginUrls, logout } from "@sanity/sdk";
|
|
2
|
+
import { useContext, useMemo, useSyncExternalStore, useCallback } from "react";
|
|
3
|
+
import { SanityInstanceContext } from "./context.js";
|
|
4
|
+
const useSanityInstance = () => {
|
|
6
5
|
const sanityInstance = useContext(SanityInstanceContext);
|
|
7
6
|
if (!sanityInstance)
|
|
8
7
|
throw new Error("useSanityInstance must be called from within the SanityProvider");
|
|
9
8
|
return sanityInstance;
|
|
10
9
|
};
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
function createStateSourceHook(stateSourceFactory) {
|
|
11
|
+
function useHook(...params) {
|
|
12
|
+
const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(
|
|
13
|
+
() => stateSourceFactory(instance, ...params),
|
|
14
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
15
|
+
[instance, ...params]
|
|
16
|
+
);
|
|
17
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
18
|
+
}
|
|
19
|
+
return useHook;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
const useAuthState = createStateSourceHook(getAuthState);
|
|
22
|
+
function createCallbackHook(callback) {
|
|
23
|
+
function useHook() {
|
|
24
|
+
const instance = useSanityInstance();
|
|
25
|
+
return useCallback((...params) => callback(instance, ...params), [instance]);
|
|
26
|
+
}
|
|
27
|
+
return useHook;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
const useHandleCallback = createCallbackHook(handleCallback);
|
|
30
|
+
function useLoginUrls() {
|
|
31
|
+
const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(() => getLoginUrlsState(instance), [instance]);
|
|
32
|
+
if (!getCurrent()) throw fetchLoginUrls(instance);
|
|
33
|
+
return useSyncExternalStore(subscribe, getCurrent);
|
|
23
34
|
}
|
|
24
|
-
const useLogOut = ()
|
|
25
|
-
const instance = useSanityInstance(), { logout } = getAuthStore(instance);
|
|
26
|
-
return logout;
|
|
27
|
-
};
|
|
35
|
+
const useLogOut = createCallbackHook(logout);
|
|
28
36
|
export {
|
|
29
|
-
|
|
37
|
+
createCallbackHook,
|
|
38
|
+
createStateSourceHook,
|
|
30
39
|
useAuthState,
|
|
31
40
|
useHandleCallback,
|
|
32
41
|
useLogOut,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLogOut.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"useLogOut.js","sources":["../../src/hooks/context/useSanityInstance.ts","../../src/hooks/helpers/createStateSourceHook.tsx","../../src/hooks/auth/useAuthState.tsx","../../src/hooks/helpers/createCallbackHook.tsx","../../src/hooks/auth/useHandleCallback.tsx","../../src/hooks/auth/useLoginUrls.tsx","../../src/hooks/auth/useLogOut.tsx"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {useContext} from 'react'\n\nimport {SanityInstanceContext} from '../../context/SanityProvider'\n\n/**\n * `useSanityInstance` returns the current Sanity instance from the application context.\n * This must be called from within a `SanityProvider` component.\n * @public\n * @returns The current Sanity instance\n * @example\n * ```tsx\n * const instance = useSanityInstance()\n * ```\n */\nexport const useSanityInstance = (): SanityInstance => {\n const sanityInstance = useContext(SanityInstanceContext)\n if (!sanityInstance) {\n throw new Error('useSanityInstance must be called from within the SanityProvider')\n }\n\n return sanityInstance\n}\n","import {type SanityInstance, type StateSource} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\nexport function createStateSourceHook<TParams extends unknown[], TState>(\n stateSourceFactory: (instance: SanityInstance, ...params: TParams) => StateSource<TState>,\n): (...params: TParams) => TState {\n function useHook(...params: TParams) {\n const instance = useSanityInstance()\n const {subscribe, getCurrent} = useMemo(\n () => stateSourceFactory(instance, ...params),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [instance, ...params],\n )\n\n return useSyncExternalStore(subscribe, getCurrent)\n }\n\n return useHook\n}\n","import {type AuthState, getAuthState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @internal\n * A React hook that subscribes to authentication state changes.\n *\n * This hook provides access to the current authentication state type from the Sanity auth store.\n * It automatically re-renders when the authentication state changes.\n *\n * @remarks\n * The hook uses `useSyncExternalStore` to safely subscribe to auth state changes\n * and ensure consistency between server and client rendering.\n *\n * @returns The current authentication state type\n *\n * @example\n * ```tsx\n * function AuthStatus() {\n * const authState = useAuthState()\n * return <div>Current auth state: {authState}</div>\n * }\n * ```\n *\n * @public\n */\nexport const useAuthState: () => AuthState = createStateSourceHook(getAuthState)\n","import {type SanityInstance} from '@sanity/sdk'\nimport {useCallback} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\nexport function createCallbackHook<TParams extends unknown[], TReturn>(\n callback: (instance: SanityInstance, ...params: TParams) => TReturn,\n): () => (...params: TParams) => TReturn {\n function useHook() {\n const instance = useSanityInstance()\n return useCallback((...params: TParams) => callback(instance, ...params), [instance])\n }\n\n return useHook\n}\n","import {handleCallback} from '@sanity/sdk'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n * @internal\n * A React hook that returns a function for handling authentication callbacks.\n *\n * @remarks\n * This hook provides access to the authentication store's callback handler,\n * which processes auth redirects by extracting the session ID and fetching the\n * authentication token. If fetching the long-lived token is successful,\n * `handleCallback` will return a Promise that resolves a new location that\n * removes the short-lived token from the URL. Use this in combination with\n * `history.replaceState` or your own router's `replace` function to update the\n * current location without triggering a reload.\n *\n * @example\n * ```tsx\n * function AuthCallback() {\n * const handleCallback = useHandleCallback()\n * const router = useRouter() // Example router\n *\n * useEffect(() => {\n * async function processCallback() {\n * // Handle the callback and get the cleaned URL\n * const newUrl = await handleCallback(window.location.href)\n *\n * if (newUrl) {\n * // Replace URL without triggering navigation\n * router.replace(newUrl, {shallow: true})\n * }\n * }\n *\n * processCallback().catch(console.error)\n * }, [handleCallback, router])\n *\n * return <div>Completing login...</div>\n * }\n * ```\n *\n * @returns A callback handler function that processes OAuth redirects\n * @public\n */\nexport const useHandleCallback = createCallbackHook(handleCallback)\n","import {type AuthProvider, fetchLoginUrls, getLoginUrlsState} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @internal\n * A React hook that retrieves the available authentication provider URLs for login.\n *\n * @remarks\n * This hook fetches the login URLs from the Sanity auth store when the component mounts.\n * Each provider object contains information about an authentication method, including its URL.\n * The hook will suspend if the login URLs have not yet loaded.\n *\n * @example\n * ```tsx\n * // LoginProviders component that uses the hook\n * function LoginProviders() {\n * const providers = useLoginUrls()\n *\n * return (\n * <div>\n * {providers.map((provider) => (\n * <a key={provider.name} href={provider.url}>\n * Login with {provider.title}\n * </a>\n * ))}\n * </div>\n * )\n * }\n *\n * // Parent component with Suspense boundary\n * function LoginPage() {\n * return (\n * <Suspense fallback={<div>Loading authentication providers...</div>}>\n * <LoginProviders />\n * </Suspense>\n * )\n * }\n * ```\n *\n * @returns An array of {@link AuthProvider} objects containing login URLs and provider information\n * @public\n */\nexport function useLoginUrls(): AuthProvider[] {\n const instance = useSanityInstance()\n const {subscribe, getCurrent} = useMemo(() => getLoginUrlsState(instance), [instance])\n\n if (!getCurrent()) throw fetchLoginUrls(instance)\n\n return useSyncExternalStore(subscribe, getCurrent as () => AuthProvider[])\n}\n","import {logout} from '@sanity/sdk'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n * Hook to log out of the current session\n * @internal\n * @returns A function to log out of the current session\n */\nexport const useLogOut = createCallbackHook(logout)\n"],"names":[],"mappings":";;;AAeO,MAAM,oBAAoB,MAAsB;AAC/C,QAAA,iBAAiB,WAAW,qBAAqB;AACvD,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,iEAAiE;AAG5E,SAAA;AACT;ACjBO,SAAS,sBACd,oBACgC;AAChC,WAAS,WAAW,QAAiB;AACnC,UAAM,WAAW,kBAAkB,GAC7B,EAAC,WAAW,WAAc,IAAA;AAAA,MAC9B,MAAM,mBAAmB,UAAU,GAAG,MAAM;AAAA;AAAA,MAE5C,CAAC,UAAU,GAAG,MAAM;AAAA,IACtB;AAEO,WAAA,qBAAqB,WAAW,UAAU;AAAA,EAAA;AAG5C,SAAA;AACT;ACOa,MAAA,eAAgC,sBAAsB,YAAY;ACtBxE,SAAS,mBACd,UACuC;AACvC,WAAS,UAAU;AACjB,UAAM,WAAW,kBAAkB;AAC5B,WAAA,YAAY,IAAI,WAAoB,SAAS,UAAU,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC;AAAA,EAAA;AAG/E,SAAA;AACT;AC8Ba,MAAA,oBAAoB,mBAAmB,cAAc;ACA3D,SAAS,eAA+B;AAC7C,QAAM,WAAW,qBACX,EAAC,WAAW,WAAU,IAAI,QAAQ,MAAM,kBAAkB,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAErF,MAAI,CAAC,WAAA,EAAc,OAAM,eAAe,QAAQ;AAEzC,SAAA,qBAAqB,WAAW,UAAkC;AAC3E;AC1Ca,MAAA,YAAY,mBAAmB,MAAM;"}
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {FallbackProps} from 'react-error-boundary'
|
|
2
|
-
import type {PropsWithChildren} from 'react'
|
|
3
2
|
import {ReactElement} from 'react'
|
|
4
|
-
import {
|
|
3
|
+
import {SanityConfig} from '@sanity/sdk'
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* A component that handles authentication flow and error boundaries for a
|
|
@@ -22,7 +21,7 @@ import {SanityInstance} from '@sanity/sdk'
|
|
|
22
21
|
* }
|
|
23
22
|
* ```
|
|
24
23
|
*
|
|
25
|
-
* @
|
|
24
|
+
* @internal
|
|
26
25
|
*/
|
|
27
26
|
export declare function AuthBoundary({
|
|
28
27
|
LoginErrorComponent,
|
|
@@ -30,9 +29,9 @@ export declare function AuthBoundary({
|
|
|
30
29
|
}: AuthBoundaryProps): React.ReactNode
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
|
-
* @
|
|
32
|
+
* @internal
|
|
34
33
|
*/
|
|
35
|
-
|
|
34
|
+
declare interface AuthBoundaryProps extends LoginLayoutProps {
|
|
36
35
|
/**
|
|
37
36
|
* Custom component to render the login screen.
|
|
38
37
|
* Receives all login layout props. Defaults to {@link Login}.
|
|
@@ -52,122 +51,14 @@ export declare interface AuthBoundaryProps extends LoginLayoutProps {
|
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
|
-
* @public
|
|
56
|
-
*/
|
|
57
|
-
export declare const DocumentGridLayout: {
|
|
58
|
-
(props: PropsWithChildren): ReactElement
|
|
59
|
-
displayName: string
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
export declare const DocumentListLayout: {
|
|
66
|
-
(props: PropsWithChildren): ReactElement
|
|
67
|
-
displayName: string
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* This is a component that renders a document preview.
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
*
|
|
75
|
-
* @param props - The props for the DocumentPreviewLayout component.
|
|
76
|
-
* @returns - The DocumentPreviewLayout component.
|
|
77
|
-
*/
|
|
78
|
-
export declare const DocumentPreviewLayout: {
|
|
79
|
-
({docType, selected, status, subtitle, title, url}: DocumentPreviewLayoutProps): JSX.Element
|
|
80
|
-
displayName: string
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
export declare interface DocumentPreviewLayoutProps {
|
|
87
|
-
docType?: string
|
|
88
|
-
media?: React.ReactNode
|
|
89
|
-
selected?: boolean
|
|
90
|
-
status?: string
|
|
91
|
-
subtitle?: string
|
|
92
|
-
title: string
|
|
93
|
-
url?: string
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Login component that displays available authentication providers.
|
|
98
|
-
* Renders a list of login options with a loading fallback while providers load.
|
|
99
|
-
*
|
|
100
|
-
* @alpha
|
|
101
|
-
*/
|
|
102
|
-
export declare function Login({header, footer}: LoginLayoutProps): JSX.Element
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Component shown during auth callback processing that handles login completion.
|
|
106
|
-
* Automatically processes the auth callback when mounted and updates the URL
|
|
107
|
-
* to remove callback parameters without triggering a page reload.
|
|
108
|
-
*
|
|
109
|
-
* @alpha
|
|
110
|
-
*/
|
|
111
|
-
export declare function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Displays authentication error details and provides retry functionality.
|
|
115
|
-
* Only handles {@link AuthError} instances - rethrows other error types.
|
|
116
|
-
*
|
|
117
|
-
* @alpha
|
|
118
|
-
*/
|
|
119
|
-
export declare function LoginError({
|
|
120
|
-
error,
|
|
121
|
-
resetErrorBoundary,
|
|
122
|
-
header,
|
|
123
|
-
footer,
|
|
124
|
-
}: LoginErrorProps): React.ReactNode
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @alpha
|
|
128
|
-
*/
|
|
129
|
-
export declare type LoginErrorProps = FallbackProps & LoginLayoutProps
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Layout component for login-related screens providing consistent styling and structure.
|
|
133
|
-
* Renders content in a centered card with optional header and footer sections.
|
|
134
|
-
*
|
|
135
|
-
* Can be used to build custom login screens for the AuthBoundary component, including:
|
|
136
|
-
* - Login provider selection (LoginComponent)
|
|
137
|
-
* - OAuth callback handling (CallbackComponent)
|
|
138
|
-
* - Error states (LoginErrorComponent)
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```tsx
|
|
142
|
-
* // Custom login screen using the layout
|
|
143
|
-
* function CustomLogin({header, footer}: LoginLayoutProps) {
|
|
144
|
-
* return (
|
|
145
|
-
* <LoginLayout
|
|
146
|
-
* header={header}
|
|
147
|
-
* footer={footer}
|
|
148
|
-
* >
|
|
149
|
-
* <CustomLoginContent />
|
|
150
|
-
* </LoginLayout>
|
|
151
|
-
* )
|
|
152
|
-
* }
|
|
153
|
-
*
|
|
154
|
-
* // Use with AuthBoundary
|
|
155
|
-
* <AuthBoundary
|
|
156
|
-
* LoginComponent={CustomLogin}
|
|
157
|
-
* header={<Logo />}
|
|
158
|
-
* >
|
|
159
|
-
* <ProtectedContent />
|
|
160
|
-
* </AuthBoundary>
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
54
|
* @alpha
|
|
164
55
|
*/
|
|
165
|
-
|
|
56
|
+
declare type LoginErrorProps = FallbackProps & LoginLayoutProps
|
|
166
57
|
|
|
167
58
|
/**
|
|
168
59
|
* @alpha
|
|
169
60
|
*/
|
|
170
|
-
|
|
61
|
+
declare interface LoginLayoutProps {
|
|
171
62
|
/** Optional header content rendered at top of card */
|
|
172
63
|
header?: React.ReactNode
|
|
173
64
|
/** Optional footer content rendered below card. Defaults to an internal login footer */
|
|
@@ -177,59 +68,43 @@ export declare interface LoginLayoutProps {
|
|
|
177
68
|
}
|
|
178
69
|
|
|
179
70
|
/**
|
|
180
|
-
* Component that handles Sanity authentication flow and renders login provider options
|
|
181
|
-
*
|
|
182
71
|
* @public
|
|
183
72
|
*
|
|
184
|
-
*
|
|
73
|
+
* The SanityApp component provides your Sanity application with access to your Sanity configuration,
|
|
74
|
+
* as well as application context and state which is used by the Sanity React hooks. Your application
|
|
75
|
+
* must be wrapped with the SanityApp component to function properly.
|
|
185
76
|
*
|
|
186
|
-
* @
|
|
187
|
-
*
|
|
188
|
-
* 1. Loading state during token exchange
|
|
189
|
-
* 2. Success state after successful authentication
|
|
190
|
-
* 3. Provider selection UI when not authenticated
|
|
77
|
+
* @param props - Your Sanity configuration and the React children to render
|
|
78
|
+
* @returns Your Sanity application, integrated with your Sanity configuration and application context
|
|
191
79
|
*
|
|
192
80
|
* @example
|
|
193
|
-
* ```tsx
|
|
194
|
-
* const config = { projectId: 'your-project-id', dataset: 'production' }
|
|
195
|
-
* return <LoginLinks sanityInstance={config} />
|
|
196
81
|
* ```
|
|
197
|
-
|
|
198
|
-
export declare const LoginLinks: () => ReactElement
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Top-level context provider that provides a Sanity configuration instance.
|
|
202
|
-
* This must wrap any Sanity SDK React component.
|
|
203
|
-
* @public
|
|
204
|
-
* @param props - Sanity project and dataset configuration
|
|
205
|
-
* @returns Rendered component
|
|
206
|
-
* @example
|
|
207
|
-
* ```tsx
|
|
208
|
-
* import {createSanityInstance} from '@sanity/sdk'
|
|
209
|
-
* import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'
|
|
82
|
+
* import { SanityApp } from '@sanity/sdk-react
|
|
210
83
|
*
|
|
211
|
-
*
|
|
84
|
+
* import MyAppRoot from './Root'
|
|
85
|
+
*
|
|
86
|
+
* const mySanityConfig = {
|
|
87
|
+
* procectId: 'my-project-id',
|
|
88
|
+
* dataset: 'production',
|
|
89
|
+
* }
|
|
212
90
|
*
|
|
213
91
|
* export default function MyApp() {
|
|
214
92
|
* return (
|
|
215
|
-
* <
|
|
216
|
-
*
|
|
217
|
-
* </
|
|
93
|
+
* <SanityApp sanityConfig={mySanityConfig}>
|
|
94
|
+
* <MyAppRoot />
|
|
95
|
+
* </SanityApp>
|
|
218
96
|
* )
|
|
219
97
|
* }
|
|
220
98
|
* ```
|
|
221
99
|
*/
|
|
222
|
-
export declare
|
|
223
|
-
children,
|
|
224
|
-
sanityInstance,
|
|
225
|
-
}: SanityProviderProps) => ReactElement
|
|
100
|
+
export declare function SanityApp({sanityConfig, children}: SanityAppProps): ReactElement
|
|
226
101
|
|
|
227
102
|
/**
|
|
228
103
|
* @public
|
|
229
104
|
*/
|
|
230
|
-
export declare interface
|
|
105
|
+
export declare interface SanityAppProps {
|
|
106
|
+
sanityConfig: SanityConfig
|
|
231
107
|
children: React.ReactNode
|
|
232
|
-
sanityInstance: SanityInstance
|
|
233
108
|
}
|
|
234
109
|
|
|
235
110
|
export {}
|