@sanity/sdk-react 0.0.0-alpha.16 → 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.
@@ -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
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 | 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 = 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,aAAa,UAAU,gBAAgB,UAAU,GAAG,MAAM;AACtE,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,iB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aQ,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;"}
@@ -1,8 +1,9 @@
1
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,99 +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
192
  const DEFAULT_FALLBACK = /* @__PURE__ */ jsx(Fragment$1, { children: "Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling." });
133
- function SDKProvider({ children, sanityConfigs, fallback }) {
134
- const sanityInstances = useMemo(() => sanityConfigs.map((sanityConfig) => createSanityInstance(sanityConfig)), [sanityConfigs]);
135
- return /* @__PURE__ */ jsx(SanityProvider, { sanityInstances, children: /* @__PURE__ */ jsx(Suspense, { fallback: fallback ?? DEFAULT_FALLBACK, children: /* @__PURE__ */ jsx(AuthBoundary, { children }) }) });
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);
136
211
  }
137
212
  const CORE_URL = "https://core.sanity.io";
138
- function SanityApp({ sanityConfigs, children, fallback }) {
139
- const [_sanityConfigs, setSanityConfigs] = useState(sanityConfigs);
140
- return useEffect(() => {
141
- let timeout;
142
- return isInIframe() ? setSanityConfigs(
143
- sanityConfigs.map((sanityConfig) => ({
144
- ...sanityConfig,
145
- auth: {
146
- ...sanityConfig.auth,
147
- storageArea: void 0
148
- }
149
- }))
150
- ) : isLocalUrl(window) || (timeout = setTimeout(() => {
151
- console.warn("Redirecting to core", CORE_URL), window.location.replace(CORE_URL);
152
- }, 1e3)), () => clearTimeout(timeout);
153
- }, [sanityConfigs]), /* @__PURE__ */ jsx(SDKProvider, { sanityConfigs: _sanityConfigs, fallback, 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);
154
230
  }
155
231
  export {
156
232
  AuthBoundary,
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sources":["../src/components/utils.ts","../src/components/auth/AuthError.ts","../src/components/auth/LoginFooter.tsx","../src/components/auth/LoginLayout.tsx","../src/components/auth/Login.tsx","../src/components/auth/LoginCallback.tsx","../src/components/auth/LoginError.tsx","../src/components/auth/AuthBoundary.tsx","../src/components/SDKProvider.tsx","../src/components/SanityApp.tsx"],"sourcesContent":["export function isInIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n}\n\n/**\n * @internal\n *\n * Checks if the current URL is a local URL.\n *\n * @param window - The window object\n * @returns True if the current URL is a local URL, false otherwise\n */\nexport function isLocalUrl(window: Window): boolean {\n const url = typeof window !== 'undefined' ? window.location.href : ''\n\n return (\n url.startsWith('http://localhost') ||\n url.startsWith('https://localhost') ||\n url.startsWith('http://127.0.0.1') ||\n url.startsWith('https://127.0.0.1')\n )\n}\n","/**\n * Error class for authentication-related errors. Wraps errors thrown during the\n * authentication flow.\n *\n * @remarks\n * This class provides a consistent error type for authentication failures while\n * preserving the original error as the cause. If the original error has a\n * message property, it will be used as the error message.\n *\n * @alpha\n */\nexport class AuthError extends Error {\n constructor(error: unknown) {\n if (\n typeof error === 'object' &&\n !!error &&\n 'message' in error &&\n typeof error.message === 'string'\n ) {\n super(error.message)\n } else {\n super()\n }\n\n this.cause = error\n }\n}\n","import {SanityLogo} from '@sanity/logos'\nimport {Fragment} from 'react'\n\nconst LINKS = [\n {\n url: 'https://slack.sanity.io/',\n i18nKey: 'workspaces.community-title',\n title: 'Community',\n },\n {\n url: 'https://www.sanity.io/docs',\n i18nKey: 'workspaces.docs-title',\n title: 'Docs',\n },\n {\n url: 'https://www.sanity.io/legal/privacy',\n i18nKey: 'workspaces.privacy-title',\n title: 'Privacy',\n },\n {\n url: 'https://www.sanity.io',\n i18nKey: 'workspaces.sanity-io-title',\n title: 'sanity.io',\n },\n]\n\n/**\n * Default footer component for login screens showing Sanity branding and legal\n * links.\n *\n * @alpha\n */\nexport function LoginFooter(): React.ReactNode {\n return (\n <div className=\"sc-login-footer\">\n <SanityLogo className=\"sc-login-footer__logo\" />\n\n <ul className=\"sc-login-footer__links\">\n {LINKS.map((link) => (\n <Fragment key={link.title}>\n <li className=\"sc-login-footer__link\">\n <a href={link.url} target=\"_blank\" rel=\"noopener noreferrer\">\n {link.title}\n </a>\n </li>\n </Fragment>\n ))}\n </ul>\n </div>\n )\n}\n","import {LoginFooter} from './LoginFooter'\n\n/**\n * @alpha\n */\nexport interface LoginLayoutProps {\n /** Optional header content rendered at top of card */\n header?: React.ReactNode\n\n /** Optional footer content rendered below card. Defaults to an internal login footer */\n footer?: React.ReactNode\n\n /** Main content rendered in card body */\n children?: React.ReactNode\n}\n\n/**\n * Layout component for login-related screens providing consistent styling and structure.\n * Renders content in a centered card with optional header and footer sections.\n *\n * Can be used to build custom login screens for the AuthBoundary component, including:\n * - Login provider selection (LoginComponent)\n * - OAuth callback handling (CallbackComponent)\n * - Error states (LoginErrorComponent)\n *\n * @example\n * ```tsx\n * // Custom login screen using the layout\n * function CustomLogin({header, footer}: LoginLayoutProps) {\n * return (\n * <LoginLayout\n * header={header}\n * footer={footer}\n * >\n * <CustomLoginContent />\n * </LoginLayout>\n * )\n * }\n *\n * // Use with AuthBoundary\n * <AuthBoundary\n * LoginComponent={CustomLogin}\n * header={<Logo />}\n * >\n * <ProtectedContent />\n * </AuthBoundary>\n * ```\n *\n * @alpha\n */\nexport function LoginLayout({\n children,\n footer = <LoginFooter />,\n header,\n}: LoginLayoutProps): React.ReactNode {\n return (\n <div className=\"sc-login-layout\">\n <div className=\"sc-login-layout__container\">\n <div className=\"sc-login-layout__card\">\n {header && <div className=\"sc-login-layout__card-header\">{header}</div>}\n\n {children && <div className=\"sc-login-layout__card-body\">{children}</div>}\n </div>\n\n {footer}\n </div>\n </div>\n )\n}\n","import {type JSX, Suspense} from 'react'\n\nimport {useLoginUrls} from '../../hooks/auth/useLoginUrls'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * Login component that displays available authentication providers.\n * Renders a list of login options with a loading fallback while providers load.\n *\n * @alpha\n * @internal\n */\nexport function Login({header, footer}: LoginLayoutProps): JSX.Element {\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login\">\n <h1 className=\"sc-login__title\">Choose login provider</h1>\n\n <Suspense fallback={<div className=\"sc-login__loading\">Loading…</div>}>\n <Providers />\n </Suspense>\n </div>\n </LoginLayout>\n )\n}\n\nfunction Providers() {\n const loginUrls = useLoginUrls()\n\n return (\n <div className=\"sc-login-providers\">\n {loginUrls.map(({title, url}) => (\n <a key={url} href={url}>\n {title}\n </a>\n ))}\n </div>\n )\n}\n","import {useEffect} from 'react'\n\nimport {useHandleCallback} from '../../hooks/auth/useHandleCallback'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n/**\n * Component shown during auth callback processing that handles login completion.\n * Automatically processes the auth callback when mounted and updates the URL\n * to remove callback parameters without triggering a page reload.\n *\n * @alpha\n */\nexport function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {\n const handleCallback = useHandleCallback()\n\n useEffect(() => {\n const url = new URL(location.href)\n handleCallback(url.toString()).then((replacementLocation) => {\n if (replacementLocation) {\n // history API with `replaceState` is used to prevent a reload but still\n // remove the short-lived token from the URL\n history.replaceState(null, '', replacementLocation)\n }\n })\n }, [handleCallback])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-callback\">\n <h1 className=\"sc-login-callback__title\">Logging you in…</h1>\n <div className=\"sc-login-callback__loading\">Loading…</div>\n </div>\n </LoginLayout>\n )\n}\n","import {useCallback} from 'react'\nimport {type FallbackProps} from 'react-error-boundary'\n\nimport {useLogOut} from '../../hooks/auth/useLogOut'\nimport {AuthError} from './AuthError'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * @alpha\n */\nexport type LoginErrorProps = FallbackProps & LoginLayoutProps\n\n/**\n * Displays authentication error details and provides retry functionality.\n * Only handles {@link AuthError} instances - rethrows other error types.\n *\n * @alpha\n */\nexport function LoginError({\n error,\n resetErrorBoundary,\n header,\n footer,\n}: LoginErrorProps): React.ReactNode {\n if (!(error instanceof AuthError)) throw error\n const logout = useLogOut()\n\n const handleRetry = useCallback(async () => {\n await logout()\n resetErrorBoundary()\n }, [logout, resetErrorBoundary])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-error\">\n <div className=\"sc-login-error__content\">\n <h2 className=\"sc-login-error__title\">Authentication Error</h2>\n <p className=\"sc-login-error__description\">\n Please try again or contact support if the problem persists.\n </p>\n </div>\n\n <button className=\"sc-login-error__button\" onClick={handleRetry}>\n Retry\n </button>\n </div>\n </LoginLayout>\n )\n}\n","import {AuthStateType} from '@sanity/sdk'\nimport {useMemo} from 'react'\nimport {ErrorBoundary, type FallbackProps} from 'react-error-boundary'\n\nimport {useAuthState} from '../../hooks/auth/useAuthState'\nimport {isInIframe} from '../utils'\nimport {AuthError} from './AuthError'\nimport {Login} from './Login'\nimport {LoginCallback} from './LoginCallback'\nimport {LoginError, type LoginErrorProps} from './LoginError'\nimport {type LoginLayoutProps} from './LoginLayout'\n\n// Only import bridge if we're in an iframe. This assumes that the app is\n// running within SanityOS if it is in an iframe.\nif (isInIframe()) {\n const parsedUrl = new URL(window.location.href)\n const mode = new URLSearchParams(parsedUrl.hash.slice(1)).get('mode')\n const script = document.createElement('script')\n script.src =\n mode === 'core-ui--staging'\n ? 'https://core.sanity-cdn.work/bridge.js'\n : 'https://core.sanity-cdn.com/bridge.js'\n script.type = 'module'\n script.async = true\n document.head.appendChild(script)\n}\n\n/**\n * @internal\n */\ninterface AuthBoundaryProps extends LoginLayoutProps {\n /**\n * Custom component to render the login screen.\n * Receives all login layout props. Defaults to {@link Login}.\n */\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render during OAuth callback processing.\n * Receives all login layout props. Defaults to {@link LoginCallback}.\n */\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render when authentication errors occur.\n * Receives login layout props and error boundary props. Defaults to\n * {@link LoginError}\n */\n LoginErrorComponent?: React.ComponentType<LoginErrorProps>\n}\n\n/**\n * A component that handles authentication flow and error boundaries for a\n * protected section of the application.\n *\n * @remarks\n * This component manages different authentication states and renders the\n * appropriate components based on that state.\n *\n * @example\n * ```tsx\n * function App() {\n * return (\n * <AuthBoundary header={<MyLogo />}>\n * <ProtectedContent />\n * </AuthBoundary>\n * )\n * }\n * ```\n *\n * @internal\n */\nexport function AuthBoundary({\n LoginErrorComponent = LoginError,\n ...props\n}: AuthBoundaryProps): React.ReactNode {\n const {header, footer} = props\n const FallbackComponent = useMemo(() => {\n return function LoginComponentWithLayoutProps(fallbackProps: FallbackProps) {\n return <LoginErrorComponent {...fallbackProps} header={header} footer={footer} />\n }\n }, [header, footer, LoginErrorComponent])\n\n return (\n <ErrorBoundary FallbackComponent={FallbackComponent}>\n <AuthSwitch {...props} />\n </ErrorBoundary>\n )\n}\n\ninterface AuthSwitchProps extends LoginLayoutProps {\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n}\n\nfunction AuthSwitch({\n LoginComponent = Login,\n CallbackComponent = LoginCallback,\n children,\n ...props\n}: AuthSwitchProps) {\n const authState = useAuthState()\n\n switch (authState.type) {\n case AuthStateType.ERROR: {\n throw new AuthError(authState.error)\n }\n case AuthStateType.LOGGING_IN: {\n return <CallbackComponent {...props} />\n }\n case AuthStateType.LOGGED_IN: {\n return children\n }\n default: {\n return <LoginComponent {...props} />\n }\n }\n}\n","import {createSanityInstance, type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement, type ReactNode, Suspense, useMemo} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\n\nconst DEFAULT_FALLBACK = (\n <>\n Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling.\n </>\n)\n\n/**\n * @internal\n */\nexport interface SDKProviderProps {\n children: ReactNode\n sanityConfigs: SanityConfig[]\n fallback: ReactNode\n}\n\n/**\n * @internal\n *\n * Top-level context provider that provides access to the Sanity SDK.\n */\nexport function SDKProvider({children, sanityConfigs, fallback}: SDKProviderProps): ReactElement {\n const sanityInstances = useMemo(() => {\n return sanityConfigs.map((sanityConfig: SanityConfig) => createSanityInstance(sanityConfig))\n }, [sanityConfigs])\n\n return (\n <SanityProvider sanityInstances={sanityInstances}>\n {/* This Suspense boundary is necessary because some hooks may suspend.\n It ensures that the Sanity instance state created above remains stable\n before rendering the AuthBoundary and its children. */}\n <Suspense fallback={fallback ?? DEFAULT_FALLBACK}>\n <AuthBoundary>{children}</AuthBoundary>\n </Suspense>\n </SanityProvider>\n )\n}\n","import {type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement, useEffect, useState} from 'react'\n\nimport {SDKProvider} from './SDKProvider'\nimport {isInIframe, isLocalUrl} from './utils'\n\n/**\n * @public\n */\nexport interface SanityAppProps {\n sanityConfigs: SanityConfig[]\n children: React.ReactNode\n fallback: React.ReactNode\n}\n\nconst CORE_URL = 'https://core.sanity.io'\n\n/**\n * @public\n *\n * The SanityApp component provides your Sanity application with access to your Sanity configuration,\n * as well as application context and state which is used by the Sanity React hooks. Your application\n * must be wrapped with the SanityApp component to function properly.\n *\n * @param props - Your Sanity configuration and the React children to render\n * @returns Your Sanity application, integrated with your Sanity configuration and application context\n *\n * @example\n * ```tsx\n * import { SanityApp } from '@sanity/sdk-react'\n *\n * import MyAppRoot from './Root'\n *\n * // Single project configuration\n * const mySanityConfigs = [\n * {\n * projectId: 'my-project-id',\n * dataset: 'production',\n * },\n * ]\n *\n * // Or multiple project configurations\n * const multipleConfigs = [\n * // Configuration for your main project. This will be used as the default project for all hooks if no resource ID override is provided.\n * {\n * projectId: 'marketing-website-project',\n * dataset: 'production',\n * },\n * // Configuration for a separate blog project\n * {\n * projectId: 'blog-project',\n * dataset: 'production',\n * },\n * // Configuration for a separate ecommerce project\n * {\n * projectId: 'ecommerce-project',\n * dataset: 'production',\n * }\n * ]\n *\n * export default function MyApp() {\n * return (\n * <SanityApp sanityConfigs={mySanityConfigs}>\n * <MyAppRoot />\n * </SanityApp>\n * )\n * }\n * ```\n */\nexport function SanityApp({sanityConfigs, children, fallback}: SanityAppProps): ReactElement {\n const [_sanityConfigs, setSanityConfigs] = useState<SanityConfig[]>(sanityConfigs)\n\n useEffect(() => {\n let timeout: NodeJS.Timeout | undefined\n\n if (isInIframe()) {\n // When running in an iframe Content OS, we don't want to store tokens\n setSanityConfigs(\n sanityConfigs.map((sanityConfig) => ({\n ...sanityConfig,\n auth: {\n ...sanityConfig.auth,\n storageArea: undefined,\n },\n })),\n )\n } else if (!isLocalUrl(window)) {\n // If the app is not running in an iframe and is not a local url, redirect to core.\n timeout = setTimeout(() => {\n // eslint-disable-next-line no-console\n console.warn('Redirecting to core', CORE_URL)\n window.location.replace(CORE_URL)\n }, 1000)\n }\n return () => clearTimeout(timeout)\n }, [sanityConfigs])\n\n return (\n <SDKProvider sanityConfigs={_sanityConfigs} fallback={fallback}>\n {children}\n </SDKProvider>\n )\n}\n"],"names":["window"],"mappings":";;;;;;;AAAO,SAAS,aAAsB;AACpC,SAAO,OAAO,SAAW,OAAe,OAAO,SAAS,OAAO;AACjE;AAUO,SAAS,WAAWA,SAAyB;AAClD,QAAM,MAAM,OAAOA,UAAW,MAAcA,QAAO,SAAS,OAAO;AAEnE,SACE,IAAI,WAAW,kBAAkB,KACjC,IAAI,WAAW,mBAAmB,KAClC,IAAI,WAAW,kBAAkB,KACjC,IAAI,WAAW,mBAAmB;AAEtC;ACVO,MAAM,kBAAkB,MAAM;AAAA,EACnC,YAAY,OAAgB;AAExB,WAAO,SAAU,YACf,SACF,aAAa,SACb,OAAO,MAAM,WAAY,WAEzB,MAAM,MAAM,OAAO,IAEnB,MAAM,GAGR,KAAK,QAAQ;AAAA,EAAA;AAEjB;ACvBA,MAAM,QAAQ;AAAA,EACZ;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAEX;AAQO,SAAS,cAA+B;A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AAqB,YAAY,CAAC,GAC1F,CAAC,aAAa,CAAC;AAElB,SACG,oBAAA,gBAAA,EAAe,iBAId,UAAA,oBAAC,UAAS,EAAA,UAAU,YAAY,kBAC9B,UAAC,oBAAA,cAAA,EAAc,SAAS,CAAA,EAC1B,CAAA,GACF;AAEJ;AC1BA,MAAM,WAAW;AAsDV,SAAS,UAAU,EAAC,eAAe,UAAU,YAAyC;AAC3F,QAAM,CAAC,gBAAgB,gBAAgB,IAAI,SAAyB,aAAa;AAEjF,SAAA,UAAU,MAAM;AACV,QAAA;AAEJ,WAAI,WAEF,IAAA;AAAA,MACE,cAAc,IAAI,CAAC,kBAAkB;AAAA,QACnC,GAAG;AAAA,QACH,MAAM;AAAA,UACJ,GAAG,aAAa;AAAA,UAChB,aAAa;AAAA,QAAA;AAAA,MACf,EACA;AAAA,QAEM,WAAW,MAAM,MAE3B,UAAU,WAAW,MAAM;AAEzB,cAAQ,KAAK,uBAAuB,QAAQ,GAC5C,OAAO,SAAS,QAAQ,QAAQ;AAAA,IAC/B,GAAA,GAAI,IAEF,MAAM,aAAa,OAAO;AAAA,EAAA,GAChC,CAAC,aAAa,CAAC,uBAGf,aAAY,EAAA,eAAe,gBAAgB,UACzC,UACH;AAEJ;"}
1
+ {"version":3,"file":"components.js","sources":["../src/components/utils.ts","../src/components/auth/AuthError.ts","../src/components/auth/LoginFooter.tsx","../src/components/auth/LoginLayout.tsx","../src/components/auth/Login.tsx","../src/components/auth/LoginCallback.tsx","../src/components/auth/LoginError.tsx","../src/components/auth/AuthBoundary.tsx","../src/components/SDKProvider.tsx","../src/components/SanityApp.tsx"],"sourcesContent":["export function isInIframe(): boolean {\n return typeof window !== 'undefined' && window.self !== window.top\n}\n\n/**\n * @internal\n *\n * Checks if the current URL is a local URL.\n *\n * @param window - The window object\n * @returns True if the current URL is a local URL, false otherwise\n */\nexport function isLocalUrl(window: Window): boolean {\n const url = typeof window !== 'undefined' ? window.location.href : ''\n\n return (\n url.startsWith('http://localhost') ||\n url.startsWith('https://localhost') ||\n url.startsWith('http://127.0.0.1') ||\n url.startsWith('https://127.0.0.1')\n )\n}\n","/**\n * Error class for authentication-related errors. Wraps errors thrown during the\n * authentication flow.\n *\n * @remarks\n * This class provides a consistent error type for authentication failures while\n * preserving the original error as the cause. If the original error has a\n * message property, it will be used as the error message.\n *\n * @alpha\n */\nexport class AuthError extends Error {\n constructor(error: unknown) {\n if (\n typeof error === 'object' &&\n !!error &&\n 'message' in error &&\n typeof error.message === 'string'\n ) {\n super(error.message)\n } else {\n super()\n }\n\n this.cause = error\n }\n}\n","import {SanityLogo} from '@sanity/logos'\nimport {Fragment} from 'react'\n\nconst LINKS = [\n {\n url: 'https://slack.sanity.io/',\n i18nKey: 'workspaces.community-title',\n title: 'Community',\n },\n {\n url: 'https://www.sanity.io/docs',\n i18nKey: 'workspaces.docs-title',\n title: 'Docs',\n },\n {\n url: 'https://www.sanity.io/legal/privacy',\n i18nKey: 'workspaces.privacy-title',\n title: 'Privacy',\n },\n {\n url: 'https://www.sanity.io',\n i18nKey: 'workspaces.sanity-io-title',\n title: 'sanity.io',\n },\n]\n\n/**\n * Default footer component for login screens showing Sanity branding and legal\n * links.\n *\n * @alpha\n */\nexport function LoginFooter(): React.ReactNode {\n return (\n <div className=\"sc-login-footer\">\n <SanityLogo className=\"sc-login-footer__logo\" />\n\n <ul className=\"sc-login-footer__links\">\n {LINKS.map((link) => (\n <Fragment key={link.title}>\n <li className=\"sc-login-footer__link\">\n <a href={link.url} target=\"_blank\" rel=\"noopener noreferrer\">\n {link.title}\n </a>\n </li>\n </Fragment>\n ))}\n </ul>\n </div>\n )\n}\n","import {LoginFooter} from './LoginFooter'\n\n/**\n * @alpha\n */\nexport interface LoginLayoutProps {\n /** Optional header content rendered at top of card */\n header?: React.ReactNode\n\n /** Optional footer content rendered below card. Defaults to an internal login footer */\n footer?: React.ReactNode\n\n /** Main content rendered in card body */\n children?: React.ReactNode\n}\n\n/**\n * Layout component for login-related screens providing consistent styling and structure.\n * Renders content in a centered card with optional header and footer sections.\n *\n * Can be used to build custom login screens for the AuthBoundary component, including:\n * - Login provider selection (LoginComponent)\n * - OAuth callback handling (CallbackComponent)\n * - Error states (LoginErrorComponent)\n *\n * @example\n * ```tsx\n * // Custom login screen using the layout\n * function CustomLogin({header, footer}: LoginLayoutProps) {\n * return (\n * <LoginLayout\n * header={header}\n * footer={footer}\n * >\n * <CustomLoginContent />\n * </LoginLayout>\n * )\n * }\n *\n * // Use with AuthBoundary\n * <AuthBoundary\n * LoginComponent={CustomLogin}\n * header={<Logo />}\n * >\n * <ProtectedContent />\n * </AuthBoundary>\n * ```\n *\n * @alpha\n */\nexport function LoginLayout({\n children,\n footer = <LoginFooter />,\n header,\n}: LoginLayoutProps): React.ReactNode {\n return (\n <div className=\"sc-login-layout\">\n <div className=\"sc-login-layout__container\">\n <div className=\"sc-login-layout__card\">\n {header && <div className=\"sc-login-layout__card-header\">{header}</div>}\n\n {children && <div className=\"sc-login-layout__card-body\">{children}</div>}\n </div>\n\n {footer}\n </div>\n </div>\n )\n}\n","import {type JSX, Suspense} from 'react'\n\nimport {useLoginUrls} from '../../hooks/auth/useLoginUrls'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * Login component that displays available authentication providers.\n * Renders a list of login options with a loading fallback while providers load.\n *\n * @alpha\n * @internal\n */\nexport function Login({header, footer}: LoginLayoutProps): JSX.Element {\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login\">\n <h1 className=\"sc-login__title\">Choose login provider</h1>\n\n <Suspense fallback={<div className=\"sc-login__loading\">Loading…</div>}>\n <Providers />\n </Suspense>\n </div>\n </LoginLayout>\n )\n}\n\nfunction Providers() {\n const loginUrls = useLoginUrls()\n\n return (\n <div className=\"sc-login-providers\">\n {loginUrls.map(({title, url}) => (\n <a key={url} href={url}>\n {title}\n </a>\n ))}\n </div>\n )\n}\n","import {useEffect} from 'react'\n\nimport {useHandleCallback} from '../../hooks/auth/useHandleCallback'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n/**\n * Component shown during auth callback processing that handles login completion.\n * Automatically processes the auth callback when mounted and updates the URL\n * to remove callback parameters without triggering a page reload.\n *\n * @alpha\n */\nexport function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {\n const handleCallback = useHandleCallback()\n\n useEffect(() => {\n const url = new URL(location.href)\n handleCallback(url.toString()).then((replacementLocation) => {\n if (replacementLocation) {\n // history API with `replaceState` is used to prevent a reload but still\n // remove the short-lived token from the URL\n history.replaceState(null, '', replacementLocation)\n }\n })\n }, [handleCallback])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-callback\">\n <h1 className=\"sc-login-callback__title\">Logging you in…</h1>\n <div className=\"sc-login-callback__loading\">Loading…</div>\n </div>\n </LoginLayout>\n )\n}\n","import {useCallback} from 'react'\nimport {type FallbackProps} from 'react-error-boundary'\n\nimport {useLogOut} from '../../hooks/auth/useLogOut'\nimport {AuthError} from './AuthError'\nimport {LoginLayout, type LoginLayoutProps} from './LoginLayout'\n\n/**\n * @alpha\n */\nexport type LoginErrorProps = FallbackProps & LoginLayoutProps\n\n/**\n * Displays authentication error details and provides retry functionality.\n * Only handles {@link AuthError} instances - rethrows other error types.\n *\n * @alpha\n */\nexport function LoginError({\n error,\n resetErrorBoundary,\n header,\n footer,\n}: LoginErrorProps): React.ReactNode {\n if (!(error instanceof AuthError)) throw error\n const logout = useLogOut()\n\n const handleRetry = useCallback(async () => {\n await logout()\n resetErrorBoundary()\n }, [logout, resetErrorBoundary])\n\n return (\n <LoginLayout header={header} footer={footer}>\n <div className=\"sc-login-error\">\n <div className=\"sc-login-error__content\">\n <h2 className=\"sc-login-error__title\">Authentication Error</h2>\n <p className=\"sc-login-error__description\">\n Please try again or contact support if the problem persists.\n </p>\n </div>\n\n <button className=\"sc-login-error__button\" onClick={handleRetry}>\n Retry\n </button>\n </div>\n </LoginLayout>\n )\n}\n","import {AuthStateType} from '@sanity/sdk'\nimport {useMemo} from 'react'\nimport {ErrorBoundary, type FallbackProps} from 'react-error-boundary'\n\nimport {useAuthState} from '../../hooks/auth/useAuthState'\nimport {isInIframe} from '../utils'\nimport {AuthError} from './AuthError'\nimport {Login} from './Login'\nimport {LoginCallback} from './LoginCallback'\nimport {LoginError, type LoginErrorProps} from './LoginError'\nimport {type LoginLayoutProps} from './LoginLayout'\n\n// Only import bridge if we're in an iframe. This assumes that the app is\n// running within SanityOS if it is in an iframe.\nif (isInIframe()) {\n const parsedUrl = new URL(window.location.href)\n const mode = new URLSearchParams(parsedUrl.hash.slice(1)).get('mode')\n const script = document.createElement('script')\n script.src =\n mode === 'core-ui--staging'\n ? 'https://core.sanity-cdn.work/bridge.js'\n : 'https://core.sanity-cdn.com/bridge.js'\n script.type = 'module'\n script.async = true\n document.head.appendChild(script)\n}\n\n/**\n * @internal\n */\ninterface AuthBoundaryProps extends LoginLayoutProps {\n /**\n * Custom component to render the login screen.\n * Receives all login layout props. Defaults to {@link Login}.\n */\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render during OAuth callback processing.\n * Receives all login layout props. Defaults to {@link LoginCallback}.\n */\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n\n /**\n * Custom component to render when authentication errors occur.\n * Receives login layout props and error boundary props. Defaults to\n * {@link LoginError}\n */\n LoginErrorComponent?: React.ComponentType<LoginErrorProps>\n}\n\n/**\n * A component that handles authentication flow and error boundaries for a\n * protected section of the application.\n *\n * @remarks\n * This component manages different authentication states and renders the\n * appropriate components based on that state.\n *\n * @example\n * ```tsx\n * function App() {\n * return (\n * <AuthBoundary header={<MyLogo />}>\n * <ProtectedContent />\n * </AuthBoundary>\n * )\n * }\n * ```\n *\n * @internal\n */\nexport function AuthBoundary({\n LoginErrorComponent = LoginError,\n ...props\n}: AuthBoundaryProps): React.ReactNode {\n const {header, footer} = props\n const FallbackComponent = useMemo(() => {\n return function LoginComponentWithLayoutProps(fallbackProps: FallbackProps) {\n return <LoginErrorComponent {...fallbackProps} header={header} footer={footer} />\n }\n }, [header, footer, LoginErrorComponent])\n\n return (\n <ErrorBoundary FallbackComponent={FallbackComponent}>\n <AuthSwitch {...props} />\n </ErrorBoundary>\n )\n}\n\ninterface AuthSwitchProps extends LoginLayoutProps {\n LoginComponent?: React.ComponentType<LoginLayoutProps>\n CallbackComponent?: React.ComponentType<LoginLayoutProps>\n}\n\nfunction AuthSwitch({\n LoginComponent = Login,\n CallbackComponent = LoginCallback,\n children,\n ...props\n}: AuthSwitchProps) {\n const authState = useAuthState()\n\n switch (authState.type) {\n case AuthStateType.ERROR: {\n throw new AuthError(authState.error)\n }\n case AuthStateType.LOGGING_IN: {\n return <CallbackComponent {...props} />\n }\n case AuthStateType.LOGGED_IN: {\n return children\n }\n default: {\n return <LoginComponent {...props} />\n }\n }\n}\n","import {createSanityInstance, type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement, type ReactNode, Suspense, useMemo} from 'react'\n\nimport {SanityProvider} from '../context/SanityProvider'\nimport {AuthBoundary} from './auth/AuthBoundary'\n\nconst DEFAULT_FALLBACK = (\n <>\n Warning: No fallback provided. Please supply a fallback prop to ensure proper Suspense handling.\n </>\n)\n\n/**\n * @internal\n */\nexport interface SDKProviderProps {\n children: ReactNode\n sanityConfigs: SanityConfig[]\n fallback: ReactNode\n}\n\n/**\n * @internal\n *\n * Top-level context provider that provides access to the Sanity SDK.\n */\nexport function SDKProvider({children, sanityConfigs, fallback}: SDKProviderProps): ReactElement {\n const sanityInstances = useMemo(() => {\n return sanityConfigs.map((sanityConfig: SanityConfig) => createSanityInstance(sanityConfig))\n }, [sanityConfigs])\n\n return (\n <SanityProvider sanityInstances={sanityInstances}>\n {/* This Suspense boundary is necessary because some hooks may suspend.\n It ensures that the Sanity instance state created above remains stable\n before rendering the AuthBoundary and its children. */}\n <Suspense fallback={fallback ?? DEFAULT_FALLBACK}>\n <AuthBoundary>{children}</AuthBoundary>\n </Suspense>\n </SanityProvider>\n )\n}\n","import {type SanityConfig} from '@sanity/sdk'\nimport {type ReactElement, useEffect} from 'react'\n\nimport {SDKProvider} from './SDKProvider'\nimport {isInIframe, isLocalUrl} from './utils'\n\n/**\n * @public\n */\nexport interface SanityAppProps {\n sanityConfigs: SanityConfig[]\n children: React.ReactNode\n fallback: React.ReactNode\n}\n\nconst CORE_URL = 'https://core.sanity.io'\n\n/**\n * @public\n *\n * The SanityApp component provides your Sanity application with access to your Sanity configuration,\n * as well as application context and state which is used by the Sanity React hooks. Your application\n * must be wrapped with the SanityApp component to function properly.\n *\n * @param props - Your Sanity configuration and the React children to render\n * @returns Your Sanity application, integrated with your Sanity configuration and application context\n *\n * @example\n * ```tsx\n * import { SanityApp } from '@sanity/sdk-react'\n *\n * import MyAppRoot from './Root'\n *\n * // Single project configuration\n * const mySanityConfigs = [\n * {\n * projectId: 'my-project-id',\n * dataset: 'production',\n * },\n * ]\n *\n * // Or multiple project configurations\n * const multipleConfigs = [\n * // Configuration for your main project. This will be used as the default project for all hooks if no resource ID override is provided.\n * {\n * projectId: 'marketing-website-project',\n * dataset: 'production',\n * },\n * // Configuration for a separate blog project\n * {\n * projectId: 'blog-project',\n * dataset: 'production',\n * },\n * // Configuration for a separate ecommerce project\n * {\n * projectId: 'ecommerce-project',\n * dataset: 'production',\n * }\n * ]\n *\n * export default function MyApp() {\n * return (\n * <SanityApp sanityConfigs={mySanityConfigs}>\n * <MyAppRoot />\n * </SanityApp>\n * )\n * }\n * ```\n */\nexport function SanityApp({sanityConfigs, children, fallback}: SanityAppProps): ReactElement {\n useEffect(() => {\n let timeout: NodeJS.Timeout | undefined\n\n if (!isInIframe() && !isLocalUrl(window)) {\n // If the app is not running in an iframe and is not a local url, redirect to core.\n timeout = setTimeout(() => {\n // eslint-disable-next-line no-console\n console.warn('Redirecting to core', CORE_URL)\n window.location.replace(CORE_URL)\n }, 1000)\n }\n return () => clearTimeout(timeout)\n }, [sanityConfigs])\n\n return (\n <SDKProvider sanityConfigs={sanityConfigs} fallback={fallback}>\n {children}\n </SDKProvider>\n )\n}\n"],"names":["isInIframe","window","self","top","isLocalUrl","url","location","href","startsWith","AuthError","Error","constructor","error","message","cause","LINKS","i18nKey","title","LoginFooter","$","_c","t0","Symbol","for","t1","map","_temp","link","LoginLayout","children","footer","header","Login","t2","t3","Providers","loginUrls","useLoginUrls","LoginCallback","handleCallback","useHandleCallback","URL","toString","then","useEffect","t4","replacementLocation","history","replaceState","LoginError","resetErrorBoundary","logout","useLogOut","handleRetry","parsedUrl","mode","URLSearchParams","hash","slice","get","script","document","createElement","src","type","async","head","appendChild","AuthBoundary","props","LoginErrorComponent","undefined","fallbackProps","FallbackComponent","t5","AuthSwitch","LoginComponent","CallbackComponent","authState","useAuthState","AuthStateType","ERROR","LOGGING_IN","LOGGED_IN","DEFAULT_FALLBACK","SDKProvider","sanityConfigs","fallback","sanityInstances","t6","sanityConfig","createSanityInstance","CORE_URL","SanityApp","_temp2","timeout","clearTimeout","console","warn","replace"],"mappings":";;;;;;;;AAAO,SAASA,aAAsB;AACpC,SAAO,OAAOC,SAAW,OAAeA,OAAOC,SAASD,OAAOE;AACjE;AAUO,SAASC,WAAWH,SAAyB;AAClD,QAAMI,MAAM,OAAOJ,UAAW,MAAcA,QAAOK,SAASC,OAAO;AAEnE,SACEF,IAAIG,WAAW,kBAAkB,KACjCH,IAAIG,WAAW,mBAAmB,KAClCH,IAAIG,WAAW,kBAAkB,KACjCH,IAAIG,WAAW,mBAAmB;AAEtC;ACVO,MAAMC,kBAAkBC,MAAM;AAAA,EACnCC,YAAYC,OAAgB;AAExB,WAAOA,SAAU,YACfA,SACF,aAAaA,SACb,OAAOA,MAAMC,WAAY,WAEzB,MAAMD,MAAMC,OAAO,IAEnB,MAAM,GAGR,KAAKC,QAAQF;AAAAA,EAAAA;AAEjB;ACvBA,MAAMG,QAAQ,CACZ;AAAA,EACEV,KAAK;AAAA,EACLW,SAAS;AAAA,EACTC,OAAO;AACT,GACA;AAAA,EACEZ,KAAK;AAAA,EACLW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