@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.
Files changed (112) hide show
  1. package/README.md +38 -67
  2. package/dist/index.d.ts +4742 -2
  3. package/dist/index.js +1054 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +27 -58
  6. package/src/_exports/index.ts +66 -10
  7. package/src/components/Login/LoginLinks.test.tsx +2 -12
  8. package/src/components/Login/LoginLinks.tsx +14 -29
  9. package/src/components/SDKProvider.test.tsx +79 -0
  10. package/src/components/SDKProvider.tsx +42 -0
  11. package/src/components/SanityApp.test.tsx +156 -0
  12. package/src/components/SanityApp.tsx +90 -0
  13. package/src/components/auth/AuthBoundary.test.tsx +4 -17
  14. package/src/components/auth/AuthBoundary.tsx +20 -4
  15. package/src/components/auth/Login.test.tsx +2 -16
  16. package/src/components/auth/Login.tsx +11 -30
  17. package/src/components/auth/LoginCallback.test.tsx +2 -17
  18. package/src/components/auth/LoginCallback.tsx +5 -10
  19. package/src/components/auth/LoginError.test.tsx +2 -17
  20. package/src/components/auth/LoginError.tsx +11 -16
  21. package/src/components/auth/LoginFooter.test.tsx +2 -16
  22. package/src/components/auth/LoginFooter.tsx +8 -24
  23. package/src/components/auth/LoginLayout.test.tsx +2 -16
  24. package/src/components/auth/LoginLayout.tsx +8 -38
  25. package/src/components/auth/authTestHelpers.tsx +11 -0
  26. package/src/components/utils.ts +22 -0
  27. package/src/context/SanityInstanceContext.ts +4 -0
  28. package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
  29. package/src/context/SanityProvider.tsx +50 -0
  30. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  31. package/src/hooks/auth/useAuthState.tsx +4 -5
  32. package/src/hooks/auth/useAuthToken.tsx +1 -1
  33. package/src/hooks/auth/useCurrentUser.tsx +27 -4
  34. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
  35. package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
  36. package/src/hooks/auth/useHandleCallback.tsx +1 -0
  37. package/src/hooks/auth/useLogOut.tsx +1 -1
  38. package/src/hooks/auth/useLoginUrls.tsx +1 -0
  39. package/src/hooks/client/useClient.ts +8 -30
  40. package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
  41. package/src/hooks/comlink/useFrameConnection.ts +107 -0
  42. package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
  43. package/src/hooks/comlink/useManageFavorite.ts +101 -0
  44. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
  45. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +79 -0
  46. package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
  47. package/src/hooks/comlink/useWindowConnection.ts +122 -0
  48. package/src/hooks/context/useSanityInstance.test.tsx +2 -2
  49. package/src/hooks/context/useSanityInstance.ts +24 -8
  50. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +97 -0
  51. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +274 -0
  52. package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +91 -0
  53. package/src/hooks/datasets/useDatasets.ts +37 -0
  54. package/src/hooks/document/useApplyActions.test.ts +25 -0
  55. package/src/hooks/document/useApplyActions.ts +74 -0
  56. package/src/hooks/document/useDocument.test.ts +81 -0
  57. package/src/hooks/document/useDocument.ts +107 -0
  58. package/src/hooks/document/useDocumentEvent.test.ts +63 -0
  59. package/src/hooks/document/useDocumentEvent.ts +54 -0
  60. package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
  61. package/src/hooks/document/useDocumentSyncStatus.ts +30 -0
  62. package/src/hooks/document/useEditDocument.test.ts +179 -0
  63. package/src/hooks/document/useEditDocument.ts +195 -0
  64. package/src/hooks/document/usePermissions.ts +82 -0
  65. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  66. package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
  67. package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
  68. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  69. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  70. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  71. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  72. package/src/hooks/preview/usePreview.test.tsx +19 -10
  73. package/src/hooks/preview/usePreview.tsx +67 -13
  74. package/src/hooks/projection/useProjection.test.tsx +218 -0
  75. package/src/hooks/projection/useProjection.ts +147 -0
  76. package/src/hooks/projects/useProject.ts +45 -0
  77. package/src/hooks/projects/useProjects.ts +41 -0
  78. package/src/hooks/query/useQuery.test.tsx +188 -0
  79. package/src/hooks/query/useQuery.ts +103 -0
  80. package/src/hooks/users/useUsers.test.ts +163 -0
  81. package/src/hooks/users/useUsers.ts +107 -0
  82. package/src/utils/getEnv.ts +21 -0
  83. package/src/version.ts +8 -0
  84. package/src/vite-env.d.ts +10 -0
  85. package/dist/_chunks-es/useLogOut.js +0 -44
  86. package/dist/_chunks-es/useLogOut.js.map +0 -1
  87. package/dist/assets/bundle-CcAyERuZ.css +0 -11
  88. package/dist/components.d.ts +0 -257
  89. package/dist/components.js +0 -316
  90. package/dist/components.js.map +0 -1
  91. package/dist/hooks.d.ts +0 -187
  92. package/dist/hooks.js +0 -81
  93. package/dist/hooks.js.map +0 -1
  94. package/src/_exports/components.ts +0 -13
  95. package/src/_exports/hooks.ts +0 -9
  96. package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
  97. package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
  98. package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
  99. package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
  100. package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
  101. package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
  102. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
  103. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
  104. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
  105. package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
  106. package/src/components/context/SanityProvider.tsx +0 -42
  107. package/src/css/css.config.js +0 -220
  108. package/src/css/paramour.css +0 -2347
  109. package/src/css/styles.css +0 -11
  110. package/src/hooks/client/useClient.test.tsx +0 -130
  111. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  112. package/src/hooks/documentCollection/useDocuments.ts +0 -87
@@ -0,0 +1,107 @@
1
+ import {createUsersStore, type ResourceType, type SanityUser} from '@sanity/sdk'
2
+ import {useCallback, useEffect, useState, useSyncExternalStore} from 'react'
3
+
4
+ import {useSanityInstance} from '../context/useSanityInstance'
5
+
6
+ /**
7
+ * @public
8
+ * @category Types
9
+ */
10
+ export interface UseUsersParams {
11
+ /**
12
+ * The type of resource to fetch users for.
13
+ */
14
+ resourceType: ResourceType
15
+ /**
16
+ * The ID of the resource to fetch users for.
17
+ */
18
+ resourceId: string
19
+ /**
20
+ * The limit of users to fetch.
21
+ */
22
+ limit?: number
23
+ }
24
+
25
+ /**
26
+ * @public
27
+ * @category Types
28
+ */
29
+ export interface UseUsersResult {
30
+ /**
31
+ * The users fetched.
32
+ */
33
+ users: SanityUser[]
34
+ /**
35
+ * Whether there are more users to fetch.
36
+ */
37
+ hasMore: boolean
38
+ /**
39
+ * Load more users.
40
+ */
41
+ loadMore: () => void
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @public
47
+ *
48
+ * Retrieves the users for a given resource (either a project or an organization).
49
+ *
50
+ * @category Users
51
+ * @param params - The resource type and its ID, and the limit of users to fetch
52
+ * @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users
53
+ *
54
+ * @example
55
+ * ```
56
+ * const { users, hasMore, loadMore } = useUsers({
57
+ * resourceType: 'organization',
58
+ * resourceId: 'my-org-id',
59
+ * limit: 10,
60
+ * })
61
+ *
62
+ * return (
63
+ * <div>
64
+ * {users.map(user => (
65
+ * <figure key={user.sanityUserId}>
66
+ * <img src={user.profile.imageUrl} alt='' />
67
+ * <figcaption>{user.profile.displayName}</figcaption>
68
+ * <address>{user.profile.email}</address>
69
+ * </figure>
70
+ * ))}
71
+ * {hasMore && <button onClick={loadMore}>Load More</button>}
72
+ * </div>
73
+ * )
74
+ * ```
75
+ */
76
+ export function useUsers(params: UseUsersParams): UseUsersResult {
77
+ const instance = useSanityInstance(params.resourceId)
78
+ const [store] = useState(() => createUsersStore(instance))
79
+
80
+ useEffect(() => {
81
+ store.setOptions({
82
+ resourceType: params.resourceType,
83
+ resourceId: params.resourceId,
84
+ })
85
+ }, [params.resourceType, params.resourceId, store])
86
+
87
+ const subscribe = useCallback(
88
+ (onStoreChanged: () => void) => {
89
+ if (store.getState().getCurrent().initialFetchCompleted === false) {
90
+ store.resolveUsers()
91
+ }
92
+ const unsubscribe = store.getState().subscribe(onStoreChanged)
93
+
94
+ return () => {
95
+ unsubscribe()
96
+ store.dispose()
97
+ }
98
+ },
99
+ [store],
100
+ )
101
+
102
+ const getSnapshot = useCallback(() => store.getState().getCurrent(), [store])
103
+
104
+ const {users, hasMore} = useSyncExternalStore(subscribe, getSnapshot) || {}
105
+
106
+ return {users, hasMore, loadMore: store.loadMore}
107
+ }
@@ -0,0 +1,21 @@
1
+ // Local type declaration for Remix
2
+ type WindowWithEnv = Window &
3
+ typeof globalThis & {
4
+ ENV?: Record<string, unknown>
5
+ }
6
+
7
+ type KnownEnvVar = 'DEV' | 'PKG_VERSION'
8
+
9
+ export function getEnv(key: KnownEnvVar): unknown {
10
+ if (typeof import.meta !== 'undefined' && import.meta.env) {
11
+ // Vite environment variables
12
+ return (import.meta.env as unknown as Record<string, unknown>)[key]
13
+ } else if (typeof process !== 'undefined' && process.env) {
14
+ // Node.js or server-side environment variables
15
+ return process.env[key]
16
+ } else if (typeof window !== 'undefined' && (window as WindowWithEnv).ENV) {
17
+ // Remix-style client-side environment variables
18
+ return (window as WindowWithEnv).ENV?.[key]
19
+ }
20
+ return undefined
21
+ }
package/src/version.ts ADDED
@@ -0,0 +1,8 @@
1
+ import {version} from '../package.json'
2
+ import {getEnv} from './utils/getEnv'
3
+
4
+ /**
5
+ * This version is provided by pkg-utils at build time
6
+ * @internal
7
+ */
8
+ export const REACT_SDK_VERSION = getEnv('PKG_VERSION') || `${version}-development`
@@ -0,0 +1,10 @@
1
+ /// <reference types="vite/client" />
2
+ /// <reference types="vite/types/importMeta.d.ts" />
3
+
4
+ interface ImportMetaEnv {
5
+ DEV: boolean
6
+ }
7
+
8
+ interface ImportMeta {
9
+ readonly env: ImportMetaEnv
10
+ }
@@ -1,44 +0,0 @@
1
- import { getAuthState, getLoginUrlsState, fetchLoginUrls, handleCallback, logout } from "@sanity/sdk";
2
- import { createContext, useContext, useMemo, useSyncExternalStore, useCallback } from "react";
3
- import { jsx } from "react/jsx-runtime";
4
- const SanityInstanceContext = createContext(null), SanityProvider = ({ children, sanityInstance }) => /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstance, children }), useSanityInstance = () => {
5
- const sanityInstance = useContext(SanityInstanceContext);
6
- if (!sanityInstance)
7
- throw new Error("useSanityInstance must be called from within the SanityProvider");
8
- return sanityInstance;
9
- };
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;
20
- }
21
- const useAuthState = createStateSourceHook(getAuthState);
22
- function useLoginUrls() {
23
- const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(() => getLoginUrlsState(instance), [instance]);
24
- if (!getCurrent()) throw fetchLoginUrls(instance);
25
- return useSyncExternalStore(subscribe, getCurrent);
26
- }
27
- function createCallbackHook(callback) {
28
- function useHook() {
29
- const instance = useSanityInstance();
30
- return useCallback((...params) => callback(instance, ...params), [instance]);
31
- }
32
- return useHook;
33
- }
34
- const useHandleCallback = createCallbackHook(handleCallback), useLogOut = createCallbackHook(logout);
35
- export {
36
- SanityProvider,
37
- createStateSourceHook,
38
- useAuthState,
39
- useHandleCallback,
40
- useLogOut,
41
- useLoginUrls,
42
- useSanityInstance
43
- };
44
- //# sourceMappingURL=useLogOut.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLogOut.js","sources":["../../src/components/context/SanityProvider.tsx","../../src/hooks/context/useSanityInstance.ts","../../src/hooks/helpers/createStateSourceHook.tsx","../../src/hooks/auth/useAuthState.tsx","../../src/hooks/auth/useLoginUrls.tsx","../../src/hooks/helpers/createCallbackHook.tsx","../../src/hooks/auth/useHandleCallback.tsx","../../src/hooks/auth/useLogOut.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 a Sanity configuration instance.\n * This must wrap any Sanity SDK React component.\n * @public\n * @param props - Sanity project and dataset configuration\n * @returns Rendered component\n * @example\n * ```tsx\n * import {createSanityInstance} from '@sanity/sdk'\n * import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'\n *\n * const sanityInstance = createSanityInstance({projectId: 'your-project-id', dataset: 'production'})\n *\n * export default function MyApp() {\n * return (\n * <SanityProvider sanityInstance={sanityInstance}>\n * <ExampleComponent />\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","import type {SanityInstance} from '@sanity/sdk'\nimport {useContext} from 'react'\n\nimport {SanityInstanceContext} from '../../components/context/SanityProvider'\n\n/**\n * Hook that provides the current Sanity instance from the 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, 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 {getAuthState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\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 the component 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 = createStateSourceHook(getAuthState)\n","import {type AuthProvider, fetchLoginUrls, getLoginUrlsState} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\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 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 * 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 {logout} from '@sanity/sdk'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n * Hook to log out of the current session\n * @public\n * @returns A function to log out of the current session\n */\nexport const useLogOut = createCallbackHook(logout)\n"],"names":[],"mappings":";;;AAWO,MAAM,wBAAwB,cAAqC,IAAI,GAwBjE,iBAAiB,CAAC,EAAC,UAAU,eAAc,0BAEnD,sBAAsB,UAAtB,EAA+B,OAAO,gBACpC,SACH,CAAA,GCxBS,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;ACMa,MAAA,eAAe,sBAAsB,YAAY;ACiBvD,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;AC7CO,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;AC6Ba,MAAA,oBAAoB,mBAAmB,cAAc,GClCrD,YAAY,mBAAmB,MAAM;"}
@@ -1,11 +0,0 @@
1
- @import './paramour.css';
2
-
3
- body {
4
- color-scheme: light dark;
5
- color: light-dark(var(--gray-1), var(--gray-10));
6
- background-color: light-dark(var(--gray-11), var(--gray-1));
7
- }
8
-
9
- .container-inline {
10
- container-type: inline-size;
11
- }
@@ -1,257 +0,0 @@
1
- import {FallbackProps} from 'react-error-boundary'
2
- import {ForwardRefExoticComponent} from 'react'
3
- import type {PropsWithChildren} from 'react'
4
- import {ReactElement} from 'react'
5
- import {RefAttributes} from 'react'
6
- import {SanityInstance} from '@sanity/sdk'
7
-
8
- /**
9
- * A component that handles authentication flow and error boundaries for a
10
- * protected section of the application.
11
- *
12
- * @remarks
13
- * This component manages different authentication states and renders the
14
- * appropriate components based on that state.
15
- *
16
- * @example
17
- * ```tsx
18
- * function App() {
19
- * return (
20
- * <AuthBoundary header={<MyLogo />}>
21
- * <ProtectedContent />
22
- * </AuthBoundary>
23
- * )
24
- * }
25
- * ```
26
- *
27
- * @alpha
28
- */
29
- export declare function AuthBoundary({
30
- LoginErrorComponent,
31
- ...props
32
- }: AuthBoundaryProps): React.ReactNode
33
-
34
- /**
35
- * @alpha
36
- */
37
- export declare interface AuthBoundaryProps extends LoginLayoutProps {
38
- /**
39
- * Custom component to render the login screen.
40
- * Receives all login layout props. Defaults to {@link Login}.
41
- */
42
- LoginComponent?: React.ComponentType<LoginLayoutProps>
43
- /**
44
- * Custom component to render during OAuth callback processing.
45
- * Receives all login layout props. Defaults to {@link LoginCallback}.
46
- */
47
- CallbackComponent?: React.ComponentType<LoginLayoutProps>
48
- /**
49
- * Custom component to render when authentication errors occur.
50
- * Receives login layout props and error boundary props. Defaults to
51
- * {@link LoginError}
52
- */
53
- LoginErrorComponent?: React.ComponentType<LoginErrorProps>
54
- }
55
-
56
- /**
57
- * Error class for authentication-related errors. Wraps errors thrown during the
58
- * authentication flow.
59
- *
60
- * @remarks
61
- * This class provides a consistent error type for authentication failures while
62
- * preserving the original error as the cause. If the original error has a
63
- * message property, it will be used as the error message.
64
- *
65
- * @alpha
66
- */
67
- export declare class AuthError extends Error {
68
- constructor(error: unknown)
69
- }
70
-
71
- /**
72
- * @public
73
- */
74
- export declare const DocumentGridLayout: {
75
- (props: PropsWithChildren): ReactElement
76
- displayName: string
77
- }
78
-
79
- /**
80
- * @public
81
- */
82
- export declare const DocumentListLayout: {
83
- (props: PropsWithChildren): ReactElement
84
- displayName: string
85
- }
86
-
87
- /**
88
- * This is a component that renders a document preview.
89
- *
90
- * @public
91
- *
92
- * @param props - The props for the DocumentPreviewLayout component.
93
- * @returns - The DocumentPreviewLayout component.
94
- */
95
- export declare const DocumentPreviewLayout: ForwardRefExoticComponent<
96
- DocumentPreviewLayoutProps & RefAttributes<HTMLElement>
97
- >
98
-
99
- /**
100
- * @public
101
- */
102
- export declare interface DocumentPreviewLayoutProps {
103
- docType?: string
104
- media?:
105
- | {
106
- type: string
107
- url: string
108
- }
109
- | null
110
- | undefined
111
- onClick?: () => void
112
- selected?: boolean
113
- status?: string
114
- subtitle?: string
115
- title: string
116
- }
117
-
118
- /**
119
- * Login component that displays available authentication providers.
120
- * Renders a list of login options with a loading fallback while providers load.
121
- *
122
- * @alpha
123
- */
124
- export declare function Login({header, footer}: LoginLayoutProps): JSX.Element
125
-
126
- /**
127
- * Component shown during auth callback processing that handles login completion.
128
- * Automatically processes the auth callback when mounted and updates the URL
129
- * to remove callback parameters without triggering a page reload.
130
- *
131
- * @alpha
132
- */
133
- export declare function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode
134
-
135
- /**
136
- * Displays authentication error details and provides retry functionality.
137
- * Only handles {@link AuthError} instances - rethrows other error types.
138
- *
139
- * @alpha
140
- */
141
- export declare function LoginError({
142
- error,
143
- resetErrorBoundary,
144
- header,
145
- footer,
146
- }: LoginErrorProps): React.ReactNode
147
-
148
- /**
149
- * @alpha
150
- */
151
- export declare type LoginErrorProps = FallbackProps & LoginLayoutProps
152
-
153
- /**
154
- * Layout component for login-related screens providing consistent styling and structure.
155
- * Renders content in a centered card with optional header and footer sections.
156
- *
157
- * Can be used to build custom login screens for the AuthBoundary component, including:
158
- * - Login provider selection (LoginComponent)
159
- * - OAuth callback handling (CallbackComponent)
160
- * - Error states (LoginErrorComponent)
161
- *
162
- * @example
163
- * ```tsx
164
- * // Custom login screen using the layout
165
- * function CustomLogin({header, footer}: LoginLayoutProps) {
166
- * return (
167
- * <LoginLayout
168
- * header={header}
169
- * footer={footer}
170
- * >
171
- * <CustomLoginContent />
172
- * </LoginLayout>
173
- * )
174
- * }
175
- *
176
- * // Use with AuthBoundary
177
- * <AuthBoundary
178
- * LoginComponent={CustomLogin}
179
- * header={<Logo />}
180
- * >
181
- * <ProtectedContent />
182
- * </AuthBoundary>
183
- * ```
184
- *
185
- * @alpha
186
- */
187
- export declare function LoginLayout({children, footer, header}: LoginLayoutProps): React.ReactNode
188
-
189
- /**
190
- * @alpha
191
- */
192
- export declare interface LoginLayoutProps {
193
- /** Optional header content rendered at top of card */
194
- header?: React.ReactNode
195
- /** Optional footer content rendered below card. Defaults to an internal login footer */
196
- footer?: React.ReactNode
197
- /** Main content rendered in card body */
198
- children?: React.ReactNode
199
- }
200
-
201
- /**
202
- * Component that handles Sanity authentication flow and renders login provider options
203
- *
204
- * @public
205
- *
206
- * @returns Rendered component
207
- *
208
- * @remarks
209
- * The component handles three states:
210
- * 1. Loading state during token exchange
211
- * 2. Success state after successful authentication
212
- * 3. Provider selection UI when not authenticated
213
- *
214
- * @example
215
- * ```tsx
216
- * const config = { projectId: 'your-project-id', dataset: 'production' }
217
- * return <LoginLinks sanityInstance={config} />
218
- * ```
219
- */
220
- export declare const LoginLinks: () => ReactElement
221
-
222
- /**
223
- * Top-level context provider that provides a Sanity configuration instance.
224
- * This must wrap any Sanity SDK React component.
225
- * @public
226
- * @param props - Sanity project and dataset configuration
227
- * @returns Rendered component
228
- * @example
229
- * ```tsx
230
- * import {createSanityInstance} from '@sanity/sdk'
231
- * import {ExampleComponent, SanityProvider} from '@sanity/sdk-react'
232
- *
233
- * const sanityInstance = createSanityInstance({projectId: 'your-project-id', dataset: 'production'})
234
- *
235
- * export default function MyApp() {
236
- * return (
237
- * <SanityProvider sanityInstance={sanityInstance}>
238
- * <ExampleComponent />
239
- * </SanityProvider>
240
- * )
241
- * }
242
- * ```
243
- */
244
- export declare const SanityProvider: ({
245
- children,
246
- sanityInstance,
247
- }: SanityProviderProps) => ReactElement
248
-
249
- /**
250
- * @public
251
- */
252
- export declare interface SanityProviderProps {
253
- children: React.ReactNode
254
- sanityInstance: SanityInstance
255
- }
256
-
257
- export {}