@sanity/sdk-react 0.0.0-alpha.15 → 0.0.0-alpha.17

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 (49) hide show
  1. package/dist/_chunks-es/context.js +9 -1
  2. package/dist/_chunks-es/context.js.map +1 -1
  3. package/dist/_chunks-es/useLogOut.js +28 -15
  4. package/dist/_chunks-es/useLogOut.js.map +1 -1
  5. package/dist/components.d.ts +37 -9
  6. package/dist/components.js +171 -96
  7. package/dist/components.js.map +1 -1
  8. package/dist/hooks.d.ts +417 -145
  9. package/dist/hooks.js +470 -226
  10. package/dist/hooks.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.js +10 -2
  13. package/dist/index.js.map +1 -1
  14. package/package.json +7 -4
  15. package/src/_exports/hooks.ts +15 -6
  16. package/src/_exports/index.ts +1 -10
  17. package/src/components/SDKProvider.test.tsx +3 -3
  18. package/src/components/SDKProvider.tsx +18 -7
  19. package/src/components/SanityApp.test.tsx +5 -5
  20. package/src/components/SanityApp.tsx +38 -24
  21. package/src/hooks/_synchronous-groq-js.mjs +4 -0
  22. package/src/hooks/client/useClient.ts +4 -1
  23. package/src/hooks/context/useSanityInstance.ts +1 -1
  24. package/src/hooks/datasets/useDatasets.ts +26 -1
  25. package/src/hooks/document/useApplyActions.test.ts +5 -4
  26. package/src/hooks/document/useApplyActions.ts +10 -4
  27. package/src/hooks/document/useDocument.ts +3 -3
  28. package/src/hooks/document/useDocumentEvent.ts +2 -0
  29. package/src/hooks/document/useDocumentSyncStatus.ts +2 -1
  30. package/src/hooks/document/useEditDocument.ts +31 -33
  31. package/src/hooks/helpers/createCallbackHook.tsx +3 -2
  32. package/src/hooks/helpers/createStateSourceHook.tsx +6 -10
  33. package/src/hooks/infiniteList/useInfiniteList.test.tsx +152 -0
  34. package/src/hooks/infiniteList/useInfiniteList.ts +174 -0
  35. package/src/hooks/paginatedList/usePaginatedList.test.tsx +259 -0
  36. package/src/hooks/paginatedList/usePaginatedList.ts +290 -0
  37. package/src/hooks/projection/useProjection.ts +3 -3
  38. package/src/hooks/projects/useProject.ts +25 -1
  39. package/src/hooks/projects/useProjects.ts +33 -11
  40. package/src/hooks/query/useQuery.test.tsx +188 -0
  41. package/src/hooks/query/useQuery.ts +103 -0
  42. package/src/hooks/users/useUsers.ts +2 -2
  43. package/src/utils/getEnv.ts +21 -0
  44. package/src/version.ts +8 -0
  45. package/src/hooks/documentCollection/types.ts +0 -19
  46. package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
  47. package/src/hooks/documentCollection/useDocuments.ts +0 -126
  48. package/src/hooks/documentCollection/useSearch.test.ts +0 -100
  49. package/src/hooks/documentCollection/useSearch.ts +0 -75
@@ -1,6 +1,14 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { c } from "react/compiler-runtime";
2
3
  import { createContext } from "react";
3
- const SanityInstanceContext = createContext(null), SanityProvider = ({ children, sanityInstances }) => /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstances, children });
4
+ const SanityInstanceContext = createContext(null), SanityProvider = (t0) => {
5
+ const $ = c(3), {
6
+ children,
7
+ sanityInstances
8
+ } = t0;
9
+ let t1;
10
+ return $[0] !== children || $[1] !== sanityInstances ? (t1 = /* @__PURE__ */ jsx(SanityInstanceContext.Provider, { value: sanityInstances, children }), $[0] = children, $[1] = sanityInstances, $[2] = t1) : t1 = $[2], t1;
11
+ };
4
12
  export {
5
13
  SanityInstanceContext,
6
14
  SanityProvider
@@ -1 +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 * @internal\n */\nexport interface SanityProviderProps {\n children: React.ReactNode\n sanityInstances: SanityInstance[]\n}\n\nexport const SanityInstanceContext = createContext<SanityInstance[] | null>(null)\n\n/**\n * @internal\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 *\n * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.\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, sanityInstances}: SanityProviderProps): ReactElement => {\n return (\n <SanityInstanceContext.Provider value={sanityInstances}>\n {children}\n </SanityInstanceContext.Provider>\n )\n}\n"],"names":[],"mappings":";;AAWO,MAAM,wBAAwB,cAAuC,IAAI,GAgCnE,iBAAiB,CAAC,EAAC,UAAU,gBAAe,0BAEpD,sBAAsB,UAAtB,EAA+B,OAAO,iBACpC,SACH,CAAA;"}
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 * @internal\n */\nexport interface SanityProviderProps {\n children: React.ReactNode\n sanityInstances: SanityInstance[]\n}\n\nexport const SanityInstanceContext = createContext<SanityInstance[] | null>(null)\n\n/**\n * @internal\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 *\n * @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.\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, sanityInstances}: SanityProviderProps): ReactElement => {\n return (\n <SanityInstanceContext.Provider value={sanityInstances}>\n {children}\n </SanityInstanceContext.Provider>\n )\n}\n"],"names":["SanityInstanceContext","createContext","SanityProvider","t0","$","_c","children","sanityInstances","t1"],"mappings":";;;AAWO,MAAMA,wBAAwBC,cAAuC,IAAI,GAgCnEC,iBAAiBC,CAAA,OAAA;AAAAC,QAAAA,IAAAC,EAAA,CAAA,GAAC;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAAAJ;AAAgDK,MAAAA;AAAA,SAAAJ,EAAAE,CAAAA,MAAAA,YAAAF,SAAAG,mBAE3EC,KAAA,oBAAA,sBAAA,UAAA,EAAuCD,OAAAA,iBACpCD,SAAAA,CACH,GAAiCF,OAAAE,UAAAF,OAAAG,iBAAAH,OAAAI,MAAAA,KAAAJ,EAAA,CAAA,GAFjCI;AAEiC;"}
@@ -1,8 +1,9 @@
1
1
  import { getAuthState, handleCallback, getLoginUrlsState, fetchLoginUrls, logout } from "@sanity/sdk";
2
- import { useContext, useMemo, useSyncExternalStore, useCallback } from "react";
2
+ import { c } from "react/compiler-runtime";
3
+ import { useContext, useSyncExternalStore, useMemo } from "react";
3
4
  import { SanityInstanceContext } from "./context.js";
4
5
  const useSanityInstance = (resourceId) => {
5
- const sanityInstance = useContext(SanityInstanceContext);
6
+ const $ = c(5), sanityInstance = useContext(SanityInstanceContext);
6
7
  if (!sanityInstance)
7
8
  throw new Error("useSanityInstance must be called from within the SanityProvider");
8
9
  if (sanityInstance.length === 0)
@@ -11,39 +12,51 @@ const useSanityInstance = (resourceId) => {
11
12
  return sanityInstance[0];
12
13
  if (!resourceId)
13
14
  throw new Error("resourceId is required when there are multiple Sanity instances");
14
- const instance = sanityInstance.find((inst) => inst.identity.resourceId === resourceId);
15
+ let t0;
16
+ if ($[0] !== resourceId || $[1] !== sanityInstance) {
17
+ let t1;
18
+ $[3] !== resourceId ? (t1 = (inst) => inst.identity.resourceId === resourceId, $[3] = resourceId, $[4] = t1) : t1 = $[4], t0 = sanityInstance.find(t1), $[0] = resourceId, $[1] = sanityInstance, $[2] = t0;
19
+ } else
20
+ t0 = $[2];
21
+ const instance = t0;
15
22
  if (!instance)
16
23
  throw new Error(`Sanity instance with resourceId ${resourceId} not found`);
17
24
  return instance;
18
25
  };
19
26
  function createStateSourceHook(options) {
20
27
  const getState = typeof options == "function" ? options : options.getState, getResourceId = "getResourceId" in options ? options.getResourceId : void 0, suspense = "shouldSuspend" in options && "suspender" in options ? options : void 0;
21
- function useHook(...params) {
28
+ function useHook(...t0) {
29
+ const $ = c(5), params = t0;
22
30
  let resourceId;
23
- getResourceId && (resourceId = getResourceId(...params));
31
+ if (getResourceId) {
32
+ let t12;
33
+ $[0] !== params ? (t12 = getResourceId(...params), $[0] = params, $[1] = t12) : t12 = $[1], resourceId = t12;
34
+ }
24
35
  const instance = useSanityInstance(resourceId);
25
- if (suspense?.shouldSuspend(instance, ...params))
36
+ if (suspense?.suspender && suspense?.shouldSuspend?.(instance, ...params))
26
37
  throw suspense.suspender(instance, ...params);
27
- const state = useMemo(
28
- () => getState(instance, ...params),
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- [instance, ...params]
31
- );
38
+ let t1;
39
+ $[2] !== instance || $[3] !== params ? (t1 = getState(instance, ...params), $[2] = instance, $[3] = params, $[4] = t1) : t1 = $[4];
40
+ const state = t1;
32
41
  return useSyncExternalStore(state.subscribe, state.getCurrent);
33
42
  }
34
43
  return useHook;
35
44
  }
36
45
  const useAuthState = createStateSourceHook(getAuthState);
37
- function createCallbackHook(callback) {
46
+ function createCallbackHook(callback, resourceId) {
38
47
  function useHook() {
39
- const instance = useSanityInstance();
40
- return useCallback((...params) => callback(instance, ...params), [instance]);
48
+ const $ = c(2), instance = useSanityInstance(resourceId);
49
+ let t0;
50
+ return $[0] !== instance ? (t0 = (...t1) => callback(instance, ...t1), $[0] = instance, $[1] = t0) : t0 = $[1], t0;
41
51
  }
42
52
  return useHook;
43
53
  }
44
54
  const useHandleCallback = createCallbackHook(handleCallback);
45
55
  function useLoginUrls() {
46
- const instance = useSanityInstance(), { subscribe, getCurrent } = useMemo(() => getLoginUrlsState(instance), [instance]);
56
+ const instance = useSanityInstance(), {
57
+ subscribe,
58
+ getCurrent
59
+ } = useMemo(() => getLoginUrlsState(instance), [instance]);
47
60
  if (!getCurrent()) throw fetchLoginUrls(instance);
48
61
  return useSyncExternalStore(subscribe, getCurrent);
49
62
  }
@@ -1 +1 @@
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 * @internal\n *\n * @param resourceId - The resourceId of the Sanity instance to return (optional)\n * @returns The current Sanity instance\n * @example\n * ```tsx\n * const instance = useSanityInstance('abc123:production')\n * ```\n */\nexport const useSanityInstance = (resourceId?: string): SanityInstance => {\n const sanityInstance = useContext(SanityInstanceContext)\n if (!sanityInstance) {\n throw new Error('useSanityInstance must be called from within the SanityProvider')\n }\n if (sanityInstance.length === 0) {\n throw new Error('No Sanity instances found')\n }\n if (sanityInstance.length === 1 || !resourceId) {\n return sanityInstance[0]\n }\n\n if (!resourceId) {\n throw new Error('resourceId is required when there are multiple Sanity instances')\n }\n\n const instance = sanityInstance.find((inst) => inst.identity.resourceId === resourceId)\n if (!instance) {\n throw new Error(`Sanity instance with resourceId ${resourceId} not found`)\n }\n return instance\n}\n","import {type ResourceId, type SanityInstance, type StateSource} from '@sanity/sdk'\nimport {useMemo, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\ntype StateSourceFactory<TParams extends unknown[], TState> = (\n instance: SanityInstance,\n ...params: TParams\n) => StateSource<TState>\n\ninterface CreateStateSourceHookOptions<TParams extends unknown[], TState> {\n getState: StateSourceFactory<TParams, TState>\n shouldSuspend: (instance: SanityInstance, ...params: TParams) => boolean\n suspender: (instance: SanityInstance, ...params: TParams) => Promise<unknown>\n getResourceId?: (...params: TParams) => ResourceId\n}\n\nexport function createStateSourceHook<TParams extends unknown[], TState>(\n options: StateSourceFactory<TParams, TState> | CreateStateSourceHookOptions<TParams, TState>,\n): (...params: TParams) => TState {\n const getState = typeof options === 'function' ? options : options.getState\n const getResourceId = 'getResourceId' in options ? options.getResourceId : undefined\n const suspense = 'shouldSuspend' in options && 'suspender' in options ? options : undefined\n\n function useHook(...params: TParams) {\n let resourceId: ResourceId | undefined\n if (getResourceId) {\n resourceId = getResourceId(...params)\n }\n const instance = useSanityInstance(resourceId)\n if (suspense?.shouldSuspend(instance, ...params)) {\n throw suspense.suspender(instance, ...params)\n }\n\n const state = useMemo(\n () => getState(instance, ...params),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [instance, ...params],\n )\n return useSyncExternalStore(state.subscribe, state.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 */\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":";;;AAiBa,MAAA,oBAAoB,CAAC,eAAwC;AAClE,QAAA,iBAAiB,WAAW,qBAAqB;AACvD,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,iEAAiE;AAEnF,MAAI,eAAe,WAAW;AACtB,UAAA,IAAI,MAAM,2BAA2B;AAEzC,MAAA,eAAe,WAAW,KAAK,CAAC;AAClC,WAAO,eAAe,CAAC;AAGzB,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,iEAAiE;AAG7E,QAAA,WAAW,eAAe,KAAK,CAAC,SAAS,KAAK,SAAS,eAAe,UAAU;AACtF,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,mCAAmC,UAAU,YAAY;AAEpE,SAAA;AACT;ACrBO,SAAS,sBACd,SACgC;AAChC,QAAM,WAAW,OAAO,WAAY,aAAa,UAAU,QAAQ,UAC7D,gBAAgB,mBAAmB,UAAU,QAAQ,gBAAgB,QACrE,WAAW,mBAAmB,WAAW,eAAe,UAAU,UAAU;AAElF,WAAS,WAAW,QAAiB;AAC/B,QAAA;AACA,sBACF,aAAa,cAAc,GAAG,MAAM;AAEhC,UAAA,WAAW,kBAAkB,UAAU;AAC7C,QAAI,UAAU,cAAc,UAAU,GAAG,MAAM;AAC7C,YAAM,SAAS,UAAU,UAAU,GAAG,MAAM;AAG9C,UAAM,QAAQ;AAAA,MACZ,MAAM,SAAS,UAAU,GAAG,MAAM;AAAA;AAAA,MAElC,CAAC,UAAU,GAAG,MAAM;AAAA,IACtB;AACA,WAAO,qBAAqB,MAAM,WAAW,MAAM,UAAU;AAAA,EAAA;AAGxD,SAAA;AACT;AClBa,MAAA,eAAgC,sBAAsB,YAAY;ACpBxE,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;"}
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 * @internal\n *\n * @param resourceId - The resourceId of the Sanity instance to return (optional)\n * @returns The current Sanity instance\n * @example\n * ```tsx\n * const instance = useSanityInstance('abc123.production')\n * ```\n */\nexport const useSanityInstance = (resourceId?: string): SanityInstance => {\n const sanityInstance = useContext(SanityInstanceContext)\n if (!sanityInstance) {\n throw new Error('useSanityInstance must be called from within the SanityProvider')\n }\n if (sanityInstance.length === 0) {\n throw new Error('No Sanity instances found')\n }\n if (sanityInstance.length === 1 || !resourceId) {\n return sanityInstance[0]\n }\n\n if (!resourceId) {\n throw new Error('resourceId is required when there are multiple Sanity instances')\n }\n\n const instance = sanityInstance.find((inst) => inst.identity.resourceId === resourceId)\n if (!instance) {\n throw new Error(`Sanity instance with resourceId ${resourceId} not found`)\n }\n return instance\n}\n","import {type ResourceId, type SanityInstance, type StateSource} from '@sanity/sdk'\nimport {useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\ntype StateSourceFactory<TParams extends unknown[], TState> = (\n instance: SanityInstance,\n ...params: TParams\n) => StateSource<TState>\n\ninterface CreateStateSourceHookOptions<TParams extends unknown[], TState> {\n getState: StateSourceFactory<TParams, TState>\n shouldSuspend?: (instance: SanityInstance, ...params: TParams) => boolean\n suspender?: (instance: SanityInstance, ...params: TParams) => Promise<unknown>\n getResourceId?: (...params: TParams) => ResourceId | undefined\n}\n\nexport function createStateSourceHook<TParams extends unknown[], TState>(\n options: StateSourceFactory<TParams, TState> | CreateStateSourceHookOptions<TParams, TState>,\n): (...params: TParams) => TState {\n const getState = typeof options === 'function' ? options : options.getState\n const getResourceId = 'getResourceId' in options ? options.getResourceId : undefined\n const suspense = 'shouldSuspend' in options && 'suspender' in options ? options : undefined\n\n function useHook(...params: TParams) {\n let resourceId: ResourceId | undefined\n if (getResourceId) {\n resourceId = getResourceId(...params)\n }\n const instance = useSanityInstance(resourceId)\n if (suspense?.suspender && suspense?.shouldSuspend?.(instance, ...params)) {\n throw suspense.suspender(instance, ...params)\n }\n\n const state = getState(instance, ...params)\n return useSyncExternalStore(state.subscribe, state.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 */\nexport const useAuthState: () => AuthState = createStateSourceHook(getAuthState)\n","import {type ResourceId, 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 resourceId?: ResourceId,\n): () => (...params: TParams) => TReturn {\n function useHook() {\n const instance = useSanityInstance(resourceId)\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":["useSanityInstance","resourceId","$","_c","sanityInstance","useContext","SanityInstanceContext","Error","length","t0","t1","inst","identity","find","instance","createStateSourceHook","options","getState","getResourceId","undefined","suspense","useHook","params","suspender","shouldSuspend","state","useSyncExternalStore","subscribe","getCurrent","useAuthState","getAuthState","createCallbackHook","callback","useHandleCallback","handleCallback","useLoginUrls","useMemo","getLoginUrlsState","fetchLoginUrls","useLogOut","logout"],"mappings":";;;;AAiBO,MAAMA,oBAAoBC,CAAA,eAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAC/BC,iBAAuBC,WAAAC,qBAAgC;AAAC,MAAA,CACnDF;AAAcG,UAAAA,IAAAA,MACD,iEAAiE;AAAA,MAE/EH,eAAcI,WAAa;AAAAD,UAAAA,IAAAA,MACb,2BAA2B;AAEzCH,MAAAA,eAAcI,WAAA,MAAkBP;AAAU,WACrCG,eAAc,CAAA;AAAA,MAAA,CAGlBH;AAAUM,UAAAA,IAAAA,MACG,iEAAiE;AAAAE,MAAAA;AAAA,MAAAP,EAAAD,CAAAA,MAAAA,cAAAC,SAAAE,gBAAA;AAAAM,QAAAA;AAAAR,aAAAD,cAG9CS,KAAAC,UAAUA,KAAIC,SAAAX,eAAyBA,YAAUC,OAAAD,YAAAC,OAAAQ,MAAAA,KAAAR,EAAA,CAAA,GAArEO,KAAAL,eAAcS,KAAMH,EAAiD,GAACR,OAAAD,YAAAC,OAAAE,gBAAAF,OAAAO;AAAAA,EAAA;AAAAA,SAAAP,EAAA,CAAA;AAAvF,QAAAY,WAAiBL;AAAsE,MAAA,CAClFK;AAAQ,UAAA,IAAAP,MACK,mCAAmCN,UAAU,YAAY;AAEpEa,SAAAA;AAAQ;ACpBV,SAASC,sBACdC,SACgC;AAChC,QAAMC,WAAW,OAAOD,WAAY,aAAaA,UAAUA,QAAQC,UAC7DC,gBAAgB,mBAAmBF,UAAUA,QAAQE,gBAAgBC,QACrEC,WAAW,mBAAmBJ,WAAW,eAAeA,UAAUA,UAAUG;AAElF,WAAAE,WAAAZ,IAAA;AAAA,UAAAP,IAAAC,EAAA,CAAA,GAAiBmB,SAAAb;AACXR,QAAAA;AAAkC,QAAAiB,eAAA;AAAAR,UAAAA;AAAAR,eAAAoB,UAEvBZ,MAAAQ,cAAiBI,GAAAA,MAAM,GAACpB,OAAAoB,QAAApB,OAAAQ,OAAAA,MAAAR,EAAA,CAAA,GAArCD,aAAaA;AAAAA,IAAAA;AAEfa,UAAAA,WAAiBd,kBAAkBC,UAAU;AAAC,QAC1CmB,UAAAG,aAAAH,UAAAI,gBAAiDV,UAAaQ,GAAAA,MAAM;AAAC,YACjEF,SAAAG,UAAmBT,UAAQ,GAAKQ,MAAM;AAACZ,QAAAA;AAAAR,MAAAY,CAAAA,MAAAA,YAAAZ,SAAAoB,UAGjCZ,KAAAO,SAASH,UAAQ,GAAKQ,MAAM,GAACpB,OAAAY,UAAAZ,OAAAoB,QAAApB,OAAAQ,MAAAA,KAAAR,EAAA,CAAA;AAA3C,UAAAuB,QAAcf;AAA6B,WACpCgB,qBAAqBD,MAAKE,WAAYF,MAAKG,UAAW;AAAA,EAAA;AAGxDP,SAAAA;AACT;ACdaQ,MAAAA,eAAgCd,sBAAsBe,YAAY;ACpB/DC,SAAAA,mBACdC,UACA/B,YACuC;AACvC,WAAAoB,UAAA;AAAA,UAAAnB,IAAAC,EAAA,CAAA,GACEW,WAAiBd,kBAAAC,UAA4B;AAACQ,QAAAA;AAAAP,WAAAA,SAAAY,YAC3BL,KAAAA,IAAAC,OAAwBsB,SAASlB,UAAQ,GAAxCJ,EAAmD,GAACR,OAAAY,UAAAZ,OAAAO,MAAAA,KAAAP,EAAA,CAAA,GAAjEO;AAAAA,EAAAA;AAGFY,SAAAA;AACT;AC6BaY,MAAAA,oBAAoBF,mBAAmBG,cAAc;ACA3D,SAASC,eAA+B;AACvCrB,QAAAA,WAAWd,qBACX;AAAA,IAAC2B;AAAAA,IAAWC;AAAAA,EAAAA,IAAcQ,QAAQ,MAAMC,kBAAkBvB,QAAQ,GAAG,CAACA,QAAQ,CAAC;AAErF,MAAI,CAACc,WAAAA,EAAc,OAAMU,eAAexB,QAAQ;AAEzCY,SAAAA,qBAAqBC,WAAWC,UAAkC;AAC3E;AC1CaW,MAAAA,YAAYR,mBAAmBS,MAAM;"}
@@ -79,26 +79,48 @@ declare interface LoginLayoutProps {
79
79
  * @returns Your Sanity application, integrated with your Sanity configuration and application context
80
80
  *
81
81
  * @example
82
- * ```
83
- * import { SanityApp } from '@sanity/sdk-react
82
+ * ```tsx
83
+ * import { SanityApp } from '@sanity/sdk-react'
84
84
  *
85
85
  * import MyAppRoot from './Root'
86
86
  *
87
- * const mySanityConfig = {
88
- * procectId: 'my-project-id',
89
- * dataset: 'production',
90
- * }
87
+ * // Single project configuration
88
+ * const mySanityConfigs = [
89
+ * {
90
+ * projectId: 'my-project-id',
91
+ * dataset: 'production',
92
+ * },
93
+ * ]
94
+ *
95
+ * // Or multiple project configurations
96
+ * const multipleConfigs = [
97
+ * // Configuration for your main project. This will be used as the default project for all hooks if no resource ID override is provided.
98
+ * {
99
+ * projectId: 'marketing-website-project',
100
+ * dataset: 'production',
101
+ * },
102
+ * // Configuration for a separate blog project
103
+ * {
104
+ * projectId: 'blog-project',
105
+ * dataset: 'production',
106
+ * },
107
+ * // Configuration for a separate ecommerce project
108
+ * {
109
+ * projectId: 'ecommerce-project',
110
+ * dataset: 'production',
111
+ * }
112
+ * ]
91
113
  *
92
114
  * export default function MyApp() {
93
115
  * return (
94
- * <SanityApp sanityConfig={mySanityConfig}>
116
+ * <SanityApp sanityConfigs={mySanityConfigs}>
95
117
  * <MyAppRoot />
96
118
  * </SanityApp>
97
119
  * )
98
120
  * }
99
121
  * ```
100
122
  */
101
- export declare function SanityApp({sanityConfigs, children}: SanityAppProps): ReactElement
123
+ export declare function SanityApp({sanityConfigs, children, fallback}: SanityAppProps): ReactElement
102
124
 
103
125
  /**
104
126
  * @public
@@ -106,6 +128,7 @@ export declare function SanityApp({sanityConfigs, children}: SanityAppProps): Re
106
128
  export declare interface SanityAppProps {
107
129
  sanityConfigs: SanityConfig[]
108
130
  children: React.ReactNode
131
+ fallback: React.ReactNode
109
132
  }
110
133
 
111
134
  /**
@@ -113,7 +136,11 @@ export declare interface SanityAppProps {
113
136
  *
114
137
  * Top-level context provider that provides access to the Sanity SDK.
115
138
  */
116
- export declare function SDKProvider({children, sanityConfigs}: SDKProviderProps): ReactElement
139
+ export declare function SDKProvider({
140
+ children,
141
+ sanityConfigs,
142
+ fallback,
143
+ }: SDKProviderProps): ReactElement
117
144
 
118
145
  /**
119
146
  * @internal
@@ -121,6 +148,7 @@ export declare function SDKProvider({children, sanityConfigs}: SDKProviderProps)
121
148
  export declare interface SDKProviderProps {
122
149
  children: ReactNode
123
150
  sanityConfigs: SanityConfig[]
151
+ fallback: ReactNode
124
152
  }
125
153
 
126
154
  export {}
@@ -1,8 +1,9 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
1
+ import { jsxs, jsx, Fragment as Fragment$1 } from "react/jsx-runtime";
2
+ import { c } from "react/compiler-runtime";
2
3
  import { AuthStateType, createSanityInstance } from "@sanity/sdk";
3
- import { Fragment, Suspense, useEffect, useCallback, useMemo, useState } from "react";
4
4
  import { ErrorBoundary } from "react-error-boundary";
5
5
  import { useLoginUrls, useHandleCallback, useLogOut, useAuthState } from "./_chunks-es/useLogOut.js";
6
+ import { Fragment, Suspense, useEffect } from "react";
6
7
  import { SanityLogo } from "@sanity/logos";
7
8
  import { SanityProvider } from "./_chunks-es/context.js";
8
9
  function isInIframe() {
@@ -17,33 +18,35 @@ class AuthError extends Error {
17
18
  typeof error == "object" && error && "message" in error && typeof error.message == "string" ? super(error.message) : super(), this.cause = error;
18
19
  }
19
20
  }
20
- const LINKS = [
21
- {
22
- url: "https://slack.sanity.io/",
23
- i18nKey: "workspaces.community-title",
24
- title: "Community"
25
- },
26
- {
27
- url: "https://www.sanity.io/docs",
28
- i18nKey: "workspaces.docs-title",
29
- title: "Docs"
30
- },
31
- {
32
- url: "https://www.sanity.io/legal/privacy",
33
- i18nKey: "workspaces.privacy-title",
34
- title: "Privacy"
35
- },
36
- {
37
- url: "https://www.sanity.io",
38
- i18nKey: "workspaces.sanity-io-title",
39
- title: "sanity.io"
40
- }
41
- ];
21
+ const LINKS = [{
22
+ url: "https://slack.sanity.io/",
23
+ i18nKey: "workspaces.community-title",
24
+ title: "Community"
25
+ }, {
26
+ url: "https://www.sanity.io/docs",
27
+ i18nKey: "workspaces.docs-title",
28
+ title: "Docs"
29
+ }, {
30
+ url: "https://www.sanity.io/legal/privacy",
31
+ i18nKey: "workspaces.privacy-title",
32
+ title: "Privacy"
33
+ }, {
34
+ url: "https://www.sanity.io",
35
+ i18nKey: "workspaces.sanity-io-title",
36
+ title: "sanity.io"
37
+ }];
42
38
  function LoginFooter() {
43
- return /* @__PURE__ */ jsxs("div", { className: "sc-login-footer", children: [
44
- /* @__PURE__ */ jsx(SanityLogo, { className: "sc-login-footer__logo" }),
45
- /* @__PURE__ */ jsx("ul", { className: "sc-login-footer__links", children: LINKS.map((link) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("li", { className: "sc-login-footer__link", children: /* @__PURE__ */ jsx("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title }) }) }, link.title)) })
46
- ] });
39
+ const $ = c(2);
40
+ let t0;
41
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx(SanityLogo, { className: "sc-login-footer__logo" }), $[0] = t0) : t0 = $[0];
42
+ let t1;
43
+ return $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsxs("div", { className: "sc-login-footer", children: [
44
+ t0,
45
+ /* @__PURE__ */ jsx("ul", { className: "sc-login-footer__links", children: LINKS.map(_temp$4) })
46
+ ] }), $[1] = t1) : t1 = $[1], t1;
47
+ }
48
+ function _temp$4(link) {
49
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("li", { className: "sc-login-footer__link", children: /* @__PURE__ */ jsx("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title }) }) }, link.title);
47
50
  }
48
51
  function LoginLayout({
49
52
  children,
@@ -58,100 +61,172 @@ function LoginLayout({
58
61
  footer
59
62
  ] }) });
60
63
  }
61
- function Login({ header, footer }) {
62
- return /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login", children: [
63
- /* @__PURE__ */ jsx("h1", { className: "sc-login__title", children: "Choose login provider" }),
64
+ function Login(t0) {
65
+ const $ = c(5), {
66
+ header,
67
+ footer
68
+ } = t0;
69
+ let t1;
70
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx("h1", { className: "sc-login__title", children: "Choose login provider" }), $[0] = t1) : t1 = $[0];
71
+ let t2;
72
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsxs("div", { className: "sc-login", children: [
73
+ t1,
64
74
  /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { className: "sc-login__loading", children: "Loading\u2026" }), children: /* @__PURE__ */ jsx(Providers, {}) })
65
- ] }) });
75
+ ] }), $[1] = t2) : t2 = $[1];
76
+ let t3;
77
+ return $[2] !== footer || $[3] !== header ? (t3 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t2 }), $[2] = footer, $[3] = header, $[4] = t3) : t3 = $[4], t3;
66
78
  }
67
79
  function Providers() {
68
- const loginUrls = useLoginUrls();
69
- return /* @__PURE__ */ jsx("div", { className: "sc-login-providers", children: loginUrls.map(({ title, url }) => /* @__PURE__ */ jsx("a", { href: url, children: title }, url)) });
80
+ const $ = c(4), loginUrls = useLoginUrls();
81
+ let t0;
82
+ $[0] !== loginUrls ? (t0 = loginUrls.map(_temp$3), $[0] = loginUrls, $[1] = t0) : t0 = $[1];
83
+ let t1;
84
+ return $[2] !== t0 ? (t1 = /* @__PURE__ */ jsx("div", { className: "sc-login-providers", children: t0 }), $[2] = t0, $[3] = t1) : t1 = $[3], t1;
85
+ }
86
+ function _temp$3(t0) {
87
+ const {
88
+ title,
89
+ url
90
+ } = t0;
91
+ return /* @__PURE__ */ jsx("a", { href: url, children: title }, url);
70
92
  }
71
- function LoginCallback({ header, footer }) {
72
- const handleCallback = useHandleCallback();
73
- return useEffect(() => {
93
+ function LoginCallback(t0) {
94
+ const $ = c(7), {
95
+ header,
96
+ footer
97
+ } = t0, handleCallback = useHandleCallback();
98
+ let t1, t2;
99
+ $[0] !== handleCallback ? (t1 = () => {
74
100
  const url = new URL(location.href);
75
- handleCallback(url.toString()).then((replacementLocation) => {
76
- replacementLocation && history.replaceState(null, "", replacementLocation);
77
- });
78
- }, [handleCallback]), /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login-callback", children: [
101
+ handleCallback(url.toString()).then(_temp$2);
102
+ }, t2 = [handleCallback], $[0] = handleCallback, $[1] = t1, $[2] = t2) : (t1 = $[1], t2 = $[2]), useEffect(t1, t2);
103
+ let t3;
104
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-callback", children: [
79
105
  /* @__PURE__ */ jsx("h1", { className: "sc-login-callback__title", children: "Logging you in\u2026" }),
80
106
  /* @__PURE__ */ jsx("div", { className: "sc-login-callback__loading", children: "Loading\u2026" })
81
- ] }) });
107
+ ] }), $[3] = t3) : t3 = $[3];
108
+ let t4;
109
+ return $[4] !== footer || $[5] !== header ? (t4 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t3 }), $[4] = footer, $[5] = header, $[6] = t4) : t4 = $[6], t4;
82
110
  }
83
- function LoginError({
84
- error,
85
- resetErrorBoundary,
86
- header,
87
- footer
88
- }) {
89
- if (!(error instanceof AuthError)) throw error;
90
- const logout = useLogOut(), handleRetry = useCallback(async () => {
111
+ function _temp$2(replacementLocation) {
112
+ replacementLocation && history.replaceState(null, "", replacementLocation);
113
+ }
114
+ function LoginError(t0) {
115
+ const $ = c(10), {
116
+ error,
117
+ resetErrorBoundary,
118
+ header,
119
+ footer
120
+ } = t0;
121
+ if (!(error instanceof AuthError))
122
+ throw error;
123
+ const logout = useLogOut();
124
+ let t1;
125
+ $[0] !== logout || $[1] !== resetErrorBoundary ? (t1 = async () => {
91
126
  await logout(), resetErrorBoundary();
92
- }, [logout, resetErrorBoundary]);
93
- return /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
94
- /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
95
- /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: "Authentication Error" }),
96
- /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: "Please try again or contact support if the problem persists." })
97
- ] }),
127
+ }, $[0] = logout, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
128
+ const handleRetry = t1;
129
+ let t2;
130
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
131
+ /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: "Authentication Error" }),
132
+ /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: "Please try again or contact support if the problem persists." })
133
+ ] }), $[3] = t2) : t2 = $[3];
134
+ let t3;
135
+ $[4] !== handleRetry ? (t3 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
136
+ t2,
98
137
  /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" })
99
- ] }) });
138
+ ] }), $[4] = handleRetry, $[5] = t3) : t3 = $[5];
139
+ let t4;
140
+ return $[6] !== footer || $[7] !== header || $[8] !== t3 ? (t4 = /* @__PURE__ */ jsx(LoginLayout, { header, footer, children: t3 }), $[6] = footer, $[7] = header, $[8] = t3, $[9] = t4) : t4 = $[9], t4;
100
141
  }
101
142
  if (isInIframe()) {
102
143
  const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
103
144
  script.src = mode === "core-ui--staging" ? "https://core.sanity-cdn.work/bridge.js" : "https://core.sanity-cdn.com/bridge.js", script.type = "module", script.async = !0, document.head.appendChild(script);
104
145
  }
105
- function AuthBoundary({
106
- LoginErrorComponent = LoginError,
107
- ...props
108
- }) {
109
- const { header, footer } = props, FallbackComponent = useMemo(() => function(fallbackProps) {
146
+ function AuthBoundary(t0) {
147
+ const $ = c(12);
148
+ let props, t1;
149
+ $[0] !== t0 ? ({
150
+ LoginErrorComponent: t1,
151
+ ...props
152
+ } = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]);
153
+ const LoginErrorComponent = t1 === void 0 ? LoginError : t1, {
154
+ header,
155
+ footer
156
+ } = props;
157
+ let t2, t3;
158
+ $[3] !== LoginErrorComponent || $[4] !== footer || $[5] !== header ? (t3 = function(fallbackProps) {
110
159
  return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps, header, footer });
111
- }, [header, footer, LoginErrorComponent]);
112
- return /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: /* @__PURE__ */ jsx(AuthSwitch, { ...props }) });
160
+ }, $[3] = LoginErrorComponent, $[4] = footer, $[5] = header, $[6] = t3) : t3 = $[6], t2 = t3;
161
+ const FallbackComponent = t2;
162
+ let t4;
163
+ $[7] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[7] = props, $[8] = t4) : t4 = $[8];
164
+ let t5;
165
+ return $[9] !== FallbackComponent || $[10] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[9] = FallbackComponent, $[10] = t4, $[11] = t5) : t5 = $[11], t5;
113
166
  }
114
- function AuthSwitch({
115
- LoginComponent = Login,
116
- CallbackComponent = LoginCallback,
117
- children,
118
- ...props
119
- }) {
120
- const authState = useAuthState();
167
+ function AuthSwitch(t0) {
168
+ const $ = c(11);
169
+ let children, props, t1, t2;
170
+ $[0] !== t0 ? ({
171
+ LoginComponent: t1,
172
+ CallbackComponent: t2,
173
+ children,
174
+ ...props
175
+ } = t0, $[0] = t0, $[1] = children, $[2] = props, $[3] = t1, $[4] = t2) : (children = $[1], props = $[2], t1 = $[3], t2 = $[4]);
176
+ const LoginComponent = t1 === void 0 ? Login : t1, CallbackComponent = t2 === void 0 ? LoginCallback : t2, authState = useAuthState();
121
177
  switch (authState.type) {
122
178
  case AuthStateType.ERROR:
123
179
  throw new AuthError(authState.error);
124
- case AuthStateType.LOGGING_IN:
125
- return /* @__PURE__ */ jsx(CallbackComponent, { ...props });
180
+ case AuthStateType.LOGGING_IN: {
181
+ let t3;
182
+ return $[5] !== CallbackComponent || $[6] !== props ? (t3 = /* @__PURE__ */ jsx(CallbackComponent, { ...props }), $[5] = CallbackComponent, $[6] = props, $[7] = t3) : t3 = $[7], t3;
183
+ }
126
184
  case AuthStateType.LOGGED_IN:
127
185
  return children;
128
- default:
129
- return /* @__PURE__ */ jsx(LoginComponent, { ...props });
186
+ default: {
187
+ let t3;
188
+ return $[8] !== LoginComponent || $[9] !== props ? (t3 = /* @__PURE__ */ jsx(LoginComponent, { ...props }), $[8] = LoginComponent, $[9] = props, $[10] = t3) : t3 = $[10], t3;
189
+ }
130
190
  }
131
191
  }
132
- function SDKProvider({ children, sanityConfigs }) {
133
- const sanityInstances = sanityConfigs.map(
134
- (sanityConfig) => createSanityInstance(sanityConfig)
135
- );
136
- return /* @__PURE__ */ jsx(SanityProvider, { sanityInstances, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) });
192
+ const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment$1, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
193
+ function SDKProvider(t0) {
194
+ const $ = c(10), {
195
+ children,
196
+ sanityConfigs,
197
+ fallback
198
+ } = t0;
199
+ let t1, t2;
200
+ $[0] !== sanityConfigs ? (t2 = sanityConfigs.map(_temp$1), $[0] = sanityConfigs, $[1] = t2) : t2 = $[1], t1 = t2;
201
+ const sanityInstances = t1, t3 = fallback ?? DEFAULT_FALLBACK;
202
+ let t4;
203
+ $[2] !== children ? (t4 = /* @__PURE__ */ jsx(AuthBoundary, { children }), $[2] = children, $[3] = t4) : t4 = $[3];
204
+ let t5;
205
+ $[4] !== t3 || $[5] !== t4 ? (t5 = /* @__PURE__ */ jsx(Suspense, { fallback: t3, children: t4 }), $[4] = t3, $[5] = t4, $[6] = t5) : t5 = $[6];
206
+ let t6;
207
+ return $[7] !== sanityInstances || $[8] !== t5 ? (t6 = /* @__PURE__ */ jsx(SanityProvider, { sanityInstances, children: t5 }), $[7] = sanityInstances, $[8] = t5, $[9] = t6) : t6 = $[9], t6;
208
+ }
209
+ function _temp$1(sanityConfig) {
210
+ return createSanityInstance(sanityConfig);
137
211
  }
138
212
  const CORE_URL = "https://core.sanity.io";
139
- function SanityApp({ sanityConfigs, children }) {
140
- const [_sanityConfigs, setSanityConfigs] = useState(sanityConfigs);
141
- return useEffect(() => {
142
- let timeout;
143
- return isInIframe() ? setSanityConfigs(
144
- sanityConfigs.map((sanityConfig) => ({
145
- ...sanityConfig,
146
- auth: {
147
- ...sanityConfig.auth,
148
- storageArea: void 0
149
- }
150
- }))
151
- ) : isLocalUrl(window) || (timeout = setTimeout(() => {
152
- console.warn("Redirecting to core", CORE_URL), window.location.replace(CORE_URL);
153
- }, 1e3)), () => clearTimeout(timeout);
154
- }, [sanityConfigs]), /* @__PURE__ */ jsx(SDKProvider, { sanityConfigs: _sanityConfigs, children });
213
+ function SanityApp(t0) {
214
+ const $ = c(6), {
215
+ sanityConfigs,
216
+ children,
217
+ fallback
218
+ } = t0;
219
+ let t1;
220
+ $[0] !== sanityConfigs ? (t1 = [sanityConfigs], $[0] = sanityConfigs, $[1] = t1) : t1 = $[1], useEffect(_temp2, t1);
221
+ let t2;
222
+ return $[2] !== children || $[3] !== fallback || $[4] !== sanityConfigs ? (t2 = /* @__PURE__ */ jsx(SDKProvider, { sanityConfigs, fallback, children }), $[2] = children, $[3] = fallback, $[4] = sanityConfigs, $[5] = t2) : t2 = $[5], t2;
223
+ }
224
+ function _temp2() {
225
+ let timeout;
226
+ return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp, 1e3)), () => clearTimeout(timeout);
227
+ }
228
+ function _temp() {
229
+ console.warn("Redirecting to core", CORE_URL), window.location.replace(CORE_URL);
155
230
  }
156
231
  export {
157
232
  AuthBoundary,