@sanity/sdk-react 0.0.0-alpha.17 → 0.0.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-es/SanityInstanceContext.js +6 -0
- package/dist/_chunks-es/SanityInstanceContext.js.map +1 -0
- package/dist/_chunks-es/useLogOut.js +1 -1
- package/dist/_chunks-es/useLogOut.js.map +1 -1
- package/dist/components.js +1 -1
- package/dist/context.js +11 -1
- package/dist/context.js.map +1 -1
- package/dist/hooks.d.ts +80 -0
- package/dist/hooks.js +88 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/_exports/hooks.ts +2 -0
- package/src/context/SanityInstanceContext.ts +4 -0
- package/src/context/SanityProvider.tsx +3 -3
- package/src/hooks/comlink/useManageFavorite.test.ts +106 -0
- package/src/hooks/comlink/useManageFavorite.ts +98 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +77 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +75 -0
- package/src/hooks/context/useSanityInstance.ts +1 -1
- package/dist/_chunks-es/context.js +0 -16
- package/dist/_chunks-es/context.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SanityInstanceContext.js","sources":["../../src/context/SanityInstanceContext.ts"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {createContext} from 'react'\n\nexport const SanityInstanceContext = createContext<SanityInstance[] | null>(null)\n"],"names":["SanityInstanceContext","createContext"],"mappings":";AAGaA,MAAAA,wBAAwBC,cAAuC,IAAI;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getAuthState, handleCallback, getLoginUrlsState, fetchLoginUrls, logout } from "@sanity/sdk";
|
|
2
2
|
import { c } from "react/compiler-runtime";
|
|
3
3
|
import { useContext, useSyncExternalStore, useMemo } from "react";
|
|
4
|
-
import { SanityInstanceContext } from "./
|
|
4
|
+
import { SanityInstanceContext } from "./SanityInstanceContext.js";
|
|
5
5
|
const useSanityInstance = (resourceId) => {
|
|
6
6
|
const $ = c(5), sanityInstance = useContext(SanityInstanceContext);
|
|
7
7
|
if (!sanityInstance)
|
|
@@ -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 {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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,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
|
+
{"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/SanityInstanceContext'\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,CAC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,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;"}
|
package/dist/components.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ErrorBoundary } from "react-error-boundary";
|
|
|
5
5
|
import { useLoginUrls, useHandleCallback, useLogOut, useAuthState } from "./_chunks-es/useLogOut.js";
|
|
6
6
|
import { Fragment, Suspense, useEffect } from "react";
|
|
7
7
|
import { SanityLogo } from "@sanity/logos";
|
|
8
|
-
import { SanityProvider } from "./
|
|
8
|
+
import { SanityProvider } from "./context.js";
|
|
9
9
|
function isInIframe() {
|
|
10
10
|
return typeof window < "u" && window.self !== window.top;
|
|
11
11
|
}
|
package/dist/context.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { SanityInstanceContext } from "./_chunks-es/SanityInstanceContext.js";
|
|
4
|
+
const 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
|
+
};
|
|
2
12
|
export {
|
|
3
13
|
SanityProvider
|
|
4
14
|
};
|
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"context.js","sources":["../src/context/SanityProvider.tsx"],"sourcesContent":["import {type SanityInstance} from '@sanity/sdk'\nimport {type ReactElement} from 'react'\n\nimport {SanityInstanceContext} from './SanityInstanceContext'\n\n/**\n * @internal\n */\nexport interface SanityProviderProps {\n children: React.ReactNode\n sanityInstances: SanityInstance[]\n}\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":["SanityProvider","t0","$","_c","children","sanityInstances","t1"],"mappings":";;;AA2CO,MAAMA,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;"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -658,6 +658,11 @@ declare type DisconnectEvent = {
|
|
|
658
658
|
|
|
659
659
|
export {DocumentHandle}
|
|
660
660
|
|
|
661
|
+
declare interface DocumentInteractionHistory {
|
|
662
|
+
recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
|
|
663
|
+
isConnected: boolean
|
|
664
|
+
}
|
|
665
|
+
|
|
661
666
|
/**
|
|
662
667
|
* Modifies an existing draft document.
|
|
663
668
|
* It applies the given patch to the document referenced by draftId.
|
|
@@ -1058,6 +1063,13 @@ declare type Logger =
|
|
|
1058
1063
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1059
1064
|
>
|
|
1060
1065
|
|
|
1066
|
+
declare interface ManageFavorite {
|
|
1067
|
+
favorite: () => void
|
|
1068
|
+
unfavorite: () => void
|
|
1069
|
+
isFavorited: boolean
|
|
1070
|
+
isConnected: boolean
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1061
1073
|
/**
|
|
1062
1074
|
* @internal
|
|
1063
1075
|
*/
|
|
@@ -3872,6 +3884,41 @@ export declare function useLoginUrls(): AuthProvider[]
|
|
|
3872
3884
|
*/
|
|
3873
3885
|
export declare const useLogOut: () => () => Promise<void>
|
|
3874
3886
|
|
|
3887
|
+
/**
|
|
3888
|
+
* @beta
|
|
3889
|
+
*
|
|
3890
|
+
* ## useManageFavorite
|
|
3891
|
+
* This hook provides functionality to add and remove documents from favorites,
|
|
3892
|
+
* and tracks the current favorite status of the document.
|
|
3893
|
+
* @category Core UI Communication
|
|
3894
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
3895
|
+
* @returns An object containing:
|
|
3896
|
+
* - `favorite` - Function to add document to favorites
|
|
3897
|
+
* - `unfavorite` - Function to remove document from favorites
|
|
3898
|
+
* - `isFavorited` - Boolean indicating if document is currently favorited
|
|
3899
|
+
* - `isConnected` - Boolean indicating if connection to Core UI is established
|
|
3900
|
+
*
|
|
3901
|
+
* @example
|
|
3902
|
+
* ```tsx
|
|
3903
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
3904
|
+
* const {_id, _type} = props
|
|
3905
|
+
* const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({
|
|
3906
|
+
* _id,
|
|
3907
|
+
* _type
|
|
3908
|
+
* })
|
|
3909
|
+
*
|
|
3910
|
+
* return (
|
|
3911
|
+
* <Button
|
|
3912
|
+
* disabled={!isConnected}
|
|
3913
|
+
* onClick={() => isFavorited ? unfavorite() : favorite()}
|
|
3914
|
+
* text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
|
|
3915
|
+
* />
|
|
3916
|
+
* )
|
|
3917
|
+
* }
|
|
3918
|
+
* ```
|
|
3919
|
+
*/
|
|
3920
|
+
export declare function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite
|
|
3921
|
+
|
|
3875
3922
|
/**
|
|
3876
3923
|
* Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
|
|
3877
3924
|
* with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
|
|
@@ -4213,6 +4260,39 @@ export declare function useQuery<T>(
|
|
|
4213
4260
|
isPending: boolean
|
|
4214
4261
|
}
|
|
4215
4262
|
|
|
4263
|
+
/**
|
|
4264
|
+
* @public
|
|
4265
|
+
* Hook for managing document interaction history in Sanity Studio.
|
|
4266
|
+
* This hook provides functionality to record document interactions.
|
|
4267
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
4268
|
+
* @returns An object containing:
|
|
4269
|
+
* - `recordEvent` - Function to record document interactions
|
|
4270
|
+
* - `isConnected` - Boolean indicating if connection to Studio is established
|
|
4271
|
+
*
|
|
4272
|
+
* @example
|
|
4273
|
+
* ```tsx
|
|
4274
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
4275
|
+
* const {_id, _type} = props
|
|
4276
|
+
* const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
|
|
4277
|
+
* _id,
|
|
4278
|
+
* _type
|
|
4279
|
+
* })
|
|
4280
|
+
*
|
|
4281
|
+
* return (
|
|
4282
|
+
* <Button
|
|
4283
|
+
* disabled={!isConnected}
|
|
4284
|
+
* onClick={() => recordEvent('viewed')}
|
|
4285
|
+
* text={'Viewed'}
|
|
4286
|
+
* />
|
|
4287
|
+
* )
|
|
4288
|
+
* }
|
|
4289
|
+
* ```
|
|
4290
|
+
*/
|
|
4291
|
+
export declare function useRecordDocumentHistoryEvent({
|
|
4292
|
+
_id,
|
|
4293
|
+
_type,
|
|
4294
|
+
}: DocumentHandle): DocumentInteractionHistory
|
|
4295
|
+
|
|
4216
4296
|
/** @public */
|
|
4217
4297
|
declare class UsersClient {
|
|
4218
4298
|
#private
|
package/dist/hooks.js
CHANGED
|
@@ -3,6 +3,7 @@ import { useAuthState, useHandleCallback, useLogOut, useLoginUrls } from "./_chu
|
|
|
3
3
|
import { getTokenState, getCurrentUserState, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, resolveDatasets, getDatasetsState, applyActions, getResourceId, resolveDocument, getDocumentState, subscribeDocumentEvents, getDocumentSyncStatus, editDocument, getPermissionsState, getQueryKey, parseQueryKey, getQueryState, resolveQuery, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, createUsersStore } from "@sanity/sdk";
|
|
4
4
|
import { c } from "react/compiler-runtime";
|
|
5
5
|
import { useState, useEffect, useRef, useInsertionEffect, useSyncExternalStore, useTransition, useMemo } from "react";
|
|
6
|
+
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
6
7
|
import { firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
7
8
|
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState), useClient = createStateSourceHook({
|
|
8
9
|
getState: getClientState,
|
|
@@ -117,6 +118,91 @@ function useWindowConnection(options) {
|
|
|
117
118
|
function _temp$4(unsub) {
|
|
118
119
|
return unsub();
|
|
119
120
|
}
|
|
121
|
+
function useManageFavorite(t0) {
|
|
122
|
+
const $ = c(14), {
|
|
123
|
+
_id,
|
|
124
|
+
_type
|
|
125
|
+
} = t0, [isFavorited, setIsFavorited] = useState(!1);
|
|
126
|
+
let t1;
|
|
127
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
128
|
+
name: SDK_NODE_NAME,
|
|
129
|
+
connectTo: SDK_CHANNEL_NAME
|
|
130
|
+
}, $[0] = t1) : t1 = $[0];
|
|
131
|
+
const {
|
|
132
|
+
sendMessage,
|
|
133
|
+
status
|
|
134
|
+
} = useWindowConnection(t1);
|
|
135
|
+
let t2;
|
|
136
|
+
$[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (action, setFavoriteState) => {
|
|
137
|
+
if (!(!_id || !_type))
|
|
138
|
+
try {
|
|
139
|
+
const message = {
|
|
140
|
+
type: "core/v1/events/favorite",
|
|
141
|
+
data: {
|
|
142
|
+
eventType: action,
|
|
143
|
+
documentId: _id,
|
|
144
|
+
documentType: _type
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
sendMessage(message.type, message.data), setIsFavorited(setFavoriteState);
|
|
148
|
+
} catch (t32) {
|
|
149
|
+
const err = t32, error = err instanceof Error ? err : new Error("Failed to update favorite status");
|
|
150
|
+
throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, error), error;
|
|
151
|
+
}
|
|
152
|
+
}, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
|
|
153
|
+
const handleFavoriteAction = t2;
|
|
154
|
+
let t3;
|
|
155
|
+
$[5] !== handleFavoriteAction ? (t3 = () => handleFavoriteAction("added", !0), $[5] = handleFavoriteAction, $[6] = t3) : t3 = $[6];
|
|
156
|
+
const favorite = t3;
|
|
157
|
+
let t4;
|
|
158
|
+
$[7] !== handleFavoriteAction ? (t4 = () => handleFavoriteAction("removed", !1), $[7] = handleFavoriteAction, $[8] = t4) : t4 = $[8];
|
|
159
|
+
const unfavorite = t4, t5 = status === "connected";
|
|
160
|
+
let t6;
|
|
161
|
+
return $[9] !== favorite || $[10] !== isFavorited || $[11] !== t5 || $[12] !== unfavorite ? (t6 = {
|
|
162
|
+
favorite,
|
|
163
|
+
unfavorite,
|
|
164
|
+
isFavorited,
|
|
165
|
+
isConnected: t5
|
|
166
|
+
}, $[9] = favorite, $[10] = isFavorited, $[11] = t5, $[12] = unfavorite, $[13] = t6) : t6 = $[13], t6;
|
|
167
|
+
}
|
|
168
|
+
function useRecordDocumentHistoryEvent(t0) {
|
|
169
|
+
const $ = c(8), {
|
|
170
|
+
_id,
|
|
171
|
+
_type
|
|
172
|
+
} = t0;
|
|
173
|
+
let t1;
|
|
174
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
|
|
175
|
+
name: SDK_NODE_NAME,
|
|
176
|
+
connectTo: SDK_CHANNEL_NAME
|
|
177
|
+
}, $[0] = t1) : t1 = $[0];
|
|
178
|
+
const {
|
|
179
|
+
sendMessage,
|
|
180
|
+
status
|
|
181
|
+
} = useWindowConnection(t1);
|
|
182
|
+
let t2;
|
|
183
|
+
$[1] !== _id || $[2] !== _type || $[3] !== sendMessage ? (t2 = (eventType) => {
|
|
184
|
+
try {
|
|
185
|
+
const message = {
|
|
186
|
+
type: "core/v1/events/history",
|
|
187
|
+
data: {
|
|
188
|
+
eventType,
|
|
189
|
+
documentId: _id,
|
|
190
|
+
documentType: _type
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
sendMessage(message.type, message.data);
|
|
194
|
+
} catch (t32) {
|
|
195
|
+
const error = t32;
|
|
196
|
+
throw console.error("Failed to record history event:", error), error;
|
|
197
|
+
}
|
|
198
|
+
}, $[1] = _id, $[2] = _type, $[3] = sendMessage, $[4] = t2) : t2 = $[4];
|
|
199
|
+
const recordEvent = t2, t3 = status === "connected";
|
|
200
|
+
let t4;
|
|
201
|
+
return $[5] !== recordEvent || $[6] !== t3 ? (t4 = {
|
|
202
|
+
recordEvent,
|
|
203
|
+
isConnected: t3
|
|
204
|
+
}, $[5] = recordEvent, $[6] = t3, $[7] = t4) : t4 = $[7], t4;
|
|
205
|
+
}
|
|
120
206
|
const useDatasets = createStateSourceHook({
|
|
121
207
|
// remove `undefined` since we're suspending when that is the case
|
|
122
208
|
getState: getDatasetsState,
|
|
@@ -558,6 +644,7 @@ export {
|
|
|
558
644
|
useInfiniteList,
|
|
559
645
|
useLogOut,
|
|
560
646
|
useLoginUrls,
|
|
647
|
+
useManageFavorite,
|
|
561
648
|
usePaginatedList,
|
|
562
649
|
usePermissions,
|
|
563
650
|
usePreview,
|
|
@@ -565,6 +652,7 @@ export {
|
|
|
565
652
|
useProjection,
|
|
566
653
|
useProjects,
|
|
567
654
|
useQuery,
|
|
655
|
+
useRecordDocumentHistoryEvent,
|
|
568
656
|
useSanityInstance,
|
|
569
657
|
useUsers,
|
|
570
658
|
useWindowConnection
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../src/hooks/auth/useAuthToken.tsx","../src/hooks/auth/useCurrentUser.tsx","../src/hooks/client/useClient.ts","../src/hooks/comlink/useFrameConnection.ts","../src/hooks/comlink/useWindowConnection.ts","../src/hooks/datasets/useDatasets.ts","../src/hooks/document/useApplyActions.ts","../src/hooks/document/useDocument.ts","../src/hooks/document/useDocumentEvent.ts","../src/hooks/document/useDocumentSyncStatus.ts","../src/hooks/document/useEditDocument.ts","../src/hooks/document/usePermissions.ts","../src/hooks/query/useQuery.ts","../src/hooks/infiniteList/useInfiniteList.ts","../src/hooks/paginatedList/usePaginatedList.ts","../src/hooks/preview/usePreview.tsx","../src/hooks/projection/useProjection.ts","../src/hooks/projects/useProject.ts","../src/hooks/projects/useProjects.ts","../src/hooks/users/useUsers.ts"],"sourcesContent":["import {getTokenState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * Hook to get the currently logged in user\n * @internal\n * @returns The current user or null if not authenticated\n */\nexport const useAuthToken = createStateSourceHook(getTokenState)\n","import {type CurrentUser, getCurrentUserState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseCurrentUser = {\n /**\n * @public\n *\n * Provides the currently authenticated user’s profile information.\n *\n * @category Users\n * @returns The current user data\n *\n * @example Rendering a basic user profile\n * ```\n * const user = useCurrentUser()\n *\n * return (\n * <figure>\n * <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />\n * <h2>{user?.name}</h2>\n * </figure>\n * )\n * ```\n */\n (): CurrentUser | null\n}\n\n/**\n * @public\n * @TODO This should not return null — users of a custom app will always be authenticated via Core\n */\nexport const useCurrentUser: UseCurrentUser = createStateSourceHook(getCurrentUserState)\n","import {getClientState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * A React hook that provides a client that subscribes to changes in your application,\n * such as user authentication changes.\n *\n * @remarks\n * The hook uses `useSyncExternalStore` to safely subscribe to changes\n * and ensure consistency between server and client rendering.\n *\n * @category Platform\n * @returns A Sanity client\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const client = useClient({apiVersion: '2024-11-12'})\n * const [document, setDocument] = useState(null)\n * useEffect(async () => {\n * const doc = client.fetch('*[_id == \"myDocumentId\"]')\n * setDocument(doc)\n * }, [])\n * return <div>{JSON.stringify(document) ?? 'Loading...'}</div>\n * }\n * ```\n *\n * @public\n */\nexport const useClient = createStateSourceHook({\n getState: getClientState,\n getResourceId: (e) => e.resourceId,\n})\n","import {type Status} from '@sanity/comlink'\nimport {\n type FrameMessage,\n getOrCreateChannel,\n getOrCreateController,\n releaseChannel,\n type WindowMessage,\n} from '@sanity/sdk'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @internal\n */\nexport type FrameMessageHandler<TWindowMessage extends WindowMessage> = (\n event: TWindowMessage['data'],\n) => TWindowMessage['response'] | Promise<TWindowMessage['response']>\n\n/**\n * @internal\n */\nexport interface UseFrameConnectionOptions<TWindowMessage extends WindowMessage> {\n name: string\n connectTo: string\n targetOrigin: string\n onMessage?: {\n [K in TWindowMessage['type']]: (data: Extract<TWindowMessage, {type: K}>['data']) => void\n }\n heartbeat?: boolean\n}\n\n/**\n * @internal\n */\nexport interface FrameConnection<TFrameMessage extends FrameMessage> {\n connect: (frameWindow: Window) => () => void // Return cleanup function\n sendMessage: <T extends TFrameMessage['type']>(\n ...params: Extract<TFrameMessage, {type: T}>['data'] extends undefined\n ? [type: T]\n : [type: T, data: Extract<TFrameMessage, {type: T}>['data']]\n ) => void\n status: Status\n}\n\n/**\n * @internal\n */\nexport function useFrameConnection<\n TFrameMessage extends FrameMessage,\n TWindowMessage extends WindowMessage,\n>(options: UseFrameConnectionOptions<TWindowMessage>): FrameConnection<TFrameMessage> {\n const {onMessage, targetOrigin, name, connectTo, heartbeat} = options\n const instance = useSanityInstance()\n const [status, setStatus] = useState<Status>('idle')\n\n const controller = useMemo(\n () => getOrCreateController(instance, targetOrigin),\n [instance, targetOrigin],\n )\n\n const channel = useMemo(\n () =>\n getOrCreateChannel(instance, {\n name,\n connectTo,\n heartbeat,\n }),\n [instance, name, connectTo, heartbeat],\n )\n\n useEffect(() => {\n if (!channel) return\n\n const unsubscribe = channel.onStatus((event) => {\n setStatus(event.status)\n })\n\n return unsubscribe\n }, [channel])\n\n useEffect(() => {\n if (!channel || !onMessage) return\n\n const unsubscribers: Array<() => void> = []\n\n Object.entries(onMessage).forEach(([type, handler]) => {\n // type assertion, but we've already constrained onMessage to have the correct handler type\n const unsubscribe = channel.on(type, handler as FrameMessageHandler<TWindowMessage>)\n unsubscribers.push(unsubscribe)\n })\n\n return () => {\n unsubscribers.forEach((unsub) => unsub())\n }\n }, [channel, onMessage])\n\n const connect = useCallback(\n (frameWindow: Window) => {\n const removeTarget = controller?.addTarget(frameWindow)\n return () => {\n removeTarget?.()\n }\n },\n [controller],\n )\n\n const sendMessage = useCallback(\n <T extends TFrameMessage['type']>(\n type: T,\n data?: Extract<TFrameMessage, {type: T}>['data'],\n ) => {\n channel?.post(type, data)\n },\n [channel],\n )\n\n // cleanup channel on unmount\n useEffect(() => {\n return () => {\n releaseChannel(instance, name)\n }\n }, [name, instance])\n\n return {\n connect,\n sendMessage,\n status,\n }\n}\n","import {type Status} from '@sanity/comlink'\nimport {type FrameMessage, getOrCreateNode, releaseNode, type WindowMessage} from '@sanity/sdk'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @internal\n */\nexport type WindowMessageHandler<TFrameMessage extends FrameMessage> = (\n event: TFrameMessage['data'],\n) => TFrameMessage['response']\n\n/**\n * @internal\n */\nexport interface UseWindowConnectionOptions<TMessage extends FrameMessage> {\n name: string\n connectTo: string\n onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>\n}\n\n/**\n * @internal\n */\nexport interface WindowConnection<TMessage extends WindowMessage> {\n sendMessage: <TType extends TMessage['type']>(\n type: TType,\n data?: Extract<TMessage, {type: TType}>['data'],\n ) => void\n status: Status\n}\n\n/**\n * @internal\n */\nexport function useWindowConnection<\n TWindowMessage extends WindowMessage,\n TFrameMessage extends FrameMessage,\n>(options: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage> {\n const {name, onMessage, connectTo} = options\n const instance = useSanityInstance()\n const [status, setStatus] = useState<Status>('idle')\n\n const node = useMemo(\n () => getOrCreateNode(instance, {name, connectTo}),\n [instance, name, connectTo],\n )\n\n useEffect(() => {\n const unsubscribe = node.onStatus((newStatus) => {\n setStatus(newStatus)\n })\n\n return unsubscribe\n }, [node, instance, name])\n\n useEffect(() => {\n if (!onMessage) return\n\n const unsubscribers: Array<() => void> = []\n\n Object.entries(onMessage).forEach(([type, handler]) => {\n const unsubscribe = node.on(type, handler as WindowMessageHandler<TFrameMessage>)\n unsubscribers.push(unsubscribe)\n })\n\n return () => {\n unsubscribers.forEach((unsub) => unsub())\n }\n }, [node, onMessage])\n\n const sendMessage = useCallback(\n <TType extends WindowMessage['type']>(\n type: TType,\n data?: Extract<WindowMessage, {type: TType}>['data'],\n ) => {\n node?.post(type, data)\n },\n [node],\n )\n\n // cleanup node on unmount\n useEffect(() => {\n return () => {\n releaseNode(instance, name)\n }\n }, [instance, name])\n\n return {\n sendMessage,\n status,\n }\n}\n","import {type DatasetsResponse} from '@sanity/client'\nimport {getDatasetsState, resolveDatasets, type SanityInstance, type StateSource} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseDatasets = {\n /**\n *\n * Returns metadata for each dataset in your organization.\n *\n * @category Datasets\n * @returns The metadata for your organization's datasets\n *\n * @example\n * ```tsx\n * const datasets = useDatasets()\n *\n * return (\n * <select>\n * {datasets.map((dataset) => (\n * <option key={dataset.name}>{dataset.name}</option>\n * ))}\n * </select>\n * )\n * ```\n *\n */\n (): DatasetsResponse\n}\n\n/** @public */\nexport const useDatasets: UseDatasets = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getDatasetsState as (instance: SanityInstance) => StateSource<DatasetsResponse>,\n shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === undefined,\n suspender: resolveDatasets,\n})\n","import {\n type ActionsResult,\n applyActions,\n type ApplyActionsOptions,\n type DocumentAction,\n type ResourceId,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n *\n * @beta\n *\n * Provides a callback for applying one or more actions to a document.\n *\n * @category Documents\n * @param resourceId - The resource ID of the document to apply actions to. If not provided, the document will use the default resource.\n * @returns A function that takes one more more {@link DocumentAction}s and returns a promise that resolves to an {@link ActionsResult}.\n * @example Publish or unpublish a document\n * ```\n * import { publishDocument, unpublishDocument } from '@sanity/sdk'\n * import { useApplyActions } from '@sanity/sdk-react'\n *\n * const apply = useApplyActions()\n * const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }\n *\n * return (\n * <button onClick={() => apply(publishDocument(myDocument))}>Publish</button>\n * <button onClick={() => apply(unpublishDocument(myDocument))}>Unpublish</button>\n * )\n * ```\n *\n * @example Create and publish a new document\n * ```\n * import { createDocument, publishDocument } from '@sanity/sdk'\n * import { useApplyActions } from '@sanity/sdk-react'\n *\n * const apply = useApplyActions()\n *\n * const handleCreateAndPublish = () => {\n * const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }\n * apply([\n * createDocument(handle),\n * publishDocument(handle),\n * ])\n * }\n *\n * return (\n * <button onClick={handleCreateAndPublish}>\n * I’m feeling lucky\n * </button>\n * )\n * ```\n */\nexport function useApplyActions(\n resourceId?: ResourceId,\n): <TDocument extends SanityDocument>(\n action: DocumentAction<TDocument> | DocumentAction<TDocument>[],\n options?: ApplyActionsOptions,\n) => Promise<ActionsResult<TDocument>>\n\n/** @beta */\nexport function useApplyActions(\n resourceId?: ResourceId,\n): (\n action: DocumentAction | DocumentAction[],\n options?: ApplyActionsOptions,\n) => Promise<ActionsResult> {\n return _useApplyActions(resourceId)()\n}\n\nconst _useApplyActions = (resourceId?: ResourceId) => createCallbackHook(applyActions, resourceId)\n","import {\n type DocumentHandle,\n getDocumentState,\n getResourceId,\n type JsonMatch,\n type JsonMatchPath,\n resolveDocument,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @beta\n *\n * ## useDocument(doc, path)\n * Read and subscribe to nested values in a document\n * @category Documents\n * @param doc - The document to read state from. If you pass a `DocumentHandle` with a `resourceId` in the DocumentResourceId format (`document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @param path - The path to the nested value to read from\n * @returns The value at the specified path\n * @example\n * ```tsx\n * import {type DocumentHandle, useDocument} from '@sanity/sdk-react'\n *\n * function OrderLink({documentHandle}: {documentHandle: DocumentHandle}) {\n * const title = useDocument(documentHandle, 'title')\n * const id = useDocument(documentHandle, '_id')\n *\n * return (\n * <a href=`/order/${id}`>Order {title} today!</a>\n * )\n * }\n * ```\n *\n */\nexport function useDocument<\n TDocument extends SanityDocument,\n TPath extends JsonMatchPath<TDocument>,\n>(doc: DocumentHandle<TDocument>, path: TPath): JsonMatch<TDocument, TPath> | undefined\n\n/**\n * @beta\n * ## useDocument(doc)\n * Read and subscribe to an entire document\n * @param doc - The document to read state from\n * @returns The document state as an object\n * @example\n * ```tsx\n * import {type SanityDocument, type DocumentHandle, useDocument} from '@sanity/sdk-react'\n *\n * interface Book extends SanityDocument {\n * title: string\n * author: string\n * summary: string\n * }\n *\n * function DocumentView({documentHandle}: {documentHandle: DocumentHandle}) {\n * const book = useDocument<Book>(documentHandle)\n *\n * return (\n * <article>\n * <h1>{book?.title}</h1>\n * <address>By {book?.author}</address>\n *\n * <h2>Summary</h2>\n * {book?.summary}\n *\n * <h2>Order</h2>\n * <a href=`/order/${book._id}`>Order {book?.title} today!</a>\n * </article>\n * )\n * }\n * ```\n *\n */\nexport function useDocument<TDocument extends SanityDocument>(\n doc: DocumentHandle<TDocument>,\n): TDocument | null\n\n/**\n * @beta\n * Reads and subscribes to a document’s realtime state, incorporating both local and remote changes.\n * When called with a `path` argument, the hook will return the nested value’s state.\n * When called without a `path` argument, the entire document’s state will be returned.\n *\n * @remarks\n * `useDocument` is designed to be used within a realtime context in which local updates to documents\n * need to be displayed before they are persisted to the remote copy. This can be useful within a collaborative\n * or realtime editing interface where local changes need to be reflected immediately.\n *\n * However, this hook can be too resource intensive for applications where static document values simply\n * need to be displayed (or when changes to documents don’t need to be reflected immediately);\n * consider using `usePreview` or `useQuery` for these use cases instead. These hooks leverage the Sanity\n * Live Content API to provide a more efficient way to read and subscribe to document state.\n */\nexport function useDocument(doc: DocumentHandle, path?: string): unknown {\n return _useDocument(doc, path)\n}\n\nconst _useDocument = createStateSourceHook<[doc: DocumentHandle, path?: string], unknown>({\n getState: getDocumentState,\n shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === undefined,\n suspender: resolveDocument,\n getResourceId: (doc) => getResourceId(doc.resourceId),\n})\n","import {\n type DocumentEvent,\n type DocumentHandle,\n getResourceId,\n subscribeDocumentEvents,\n} from '@sanity/sdk'\nimport {useCallback, useEffect, useInsertionEffect, useRef} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n *\n * @beta\n *\n * Subscribes an event handler to events in your application’s document store, such as document\n * creation, deletion, and updates.\n *\n * @category Documents\n * @param handler - The event handler to register.\n * @param doc - The document to subscribe to events for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @example\n * ```\n * import {useDocumentEvent} from '@sanity/sdk-react'\n * import {type DocumentEvent} from '@sanity/sdk'\n *\n * useDocumentEvent((event) => {\n * if (event.type === DocumentEvent.DocumentDeletedEvent) {\n * alert(`Document with ID ${event.documentId} deleted!`)\n * } else {\n * console.log(event)\n * }\n * })\n * ```\n */\nexport function useDocumentEvent(\n handler: (documentEvent: DocumentEvent) => void,\n doc: DocumentHandle,\n): void {\n const ref = useRef(handler)\n\n useInsertionEffect(() => {\n ref.current = handler\n })\n\n const stableHandler = useCallback((documentEvent: DocumentEvent) => {\n return ref.current(documentEvent)\n }, [])\n\n const instance = useSanityInstance(getResourceId(doc.resourceId))\n useEffect(() => {\n return subscribeDocumentEvents(instance, stableHandler)\n }, [instance, stableHandler])\n}\n","import {type DocumentHandle, getDocumentSyncStatus} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseDocumentSyncStatus = {\n /**\n * Exposes the document’s sync status between local and remote document states.\n *\n * @category Documents\n * @param doc - The document handle to get sync status for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @returns `true` if local changes are synced with remote, `false` if the changes are not synced, and `undefined` if the document is not found\n * @example Disable a Save button when there are no changes to sync\n * ```\n * const myDocumentHandle = { _id: 'documentId', _type: 'documentType', resourceId: 'document:projectId:dataset:documentId' }\n * const documentSynced = useDocumentSyncStatus(myDocumentHandle)\n *\n * return (\n * <button disabled={documentSynced}>\n * Save Changes\n * </button>\n * )\n * ```\n */\n (doc: DocumentHandle): boolean | undefined\n}\n\n/** @beta */\nexport const useDocumentSyncStatus: UseDocumentSyncStatus =\n createStateSourceHook(getDocumentSyncStatus)\n","import {\n type ActionsResult,\n type DocumentHandle,\n editDocument,\n getDocumentState,\n getResourceId,\n type JsonMatch,\n type JsonMatchPath,\n resolveDocument,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\nimport {useCallback} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\nimport {useApplyActions} from './useApplyActions'\n\nconst ignoredKeys = ['_id', '_type', '_createdAt', '_updatedAt', '_rev']\n\ntype Updater<TValue> = TValue | ((nextValue: TValue) => TValue)\n\n/**\n *\n * @beta\n *\n * ## useEditDocument(doc, path)\n * Edit a nested value within a document\n *\n * @category Documents\n * @param doc - The document to be edited; either as a document handle or the document’s ID a string\n * @param path - The path to the nested value to be edited\n * @returns A function to update the nested value. Accepts either a new value, or an updater function that exposes the previous value and returns a new value.\n * @example Update a document’s name by providing the new value directly\n * ```\n * const handle = { _id: 'documentId', _type: 'documentType' }\n * const name = useDocument(handle, 'name')\n * const editName = useEditDocument(handle, 'name')\n *\n * function handleNameChange(event: React.ChangeEvent<HTMLInputElement>) {\n * editName(event.target.value)\n * }\n *\n * return (\n * <input type='text' value={name} onChange={handleNameChange} />\n * )\n * ```\n *\n * @example Update a count on a document by providing an updater function\n * ```\n * const handle = { _id: 'documentId', _type: 'documentType' }\n * const count = useDocument(handle, 'count')\n * const editCount = useEditDocument(handle, 'count')\n *\n * function incrementCount() {\n * editCount(previousCount => previousCount + 1)\n * }\n *\n * return (\n * <>\n * <button onClick={incrementCount}>\n * Increment\n * </button>\n * Current count: {count}\n * </>\n * )\n * ```\n */\nexport function useEditDocument<\n TDocument extends SanityDocument,\n TPath extends JsonMatchPath<TDocument>,\n>(\n doc: DocumentHandle<TDocument>,\n path: TPath,\n): (nextValue: Updater<JsonMatch<TDocument, TPath>>) => Promise<ActionsResult<TDocument>>\n\n/**\n *\n * @beta\n *\n * ## useEditDocument(doc)\n * Edit an entire document\n * @param doc - The document to be edited; either as a document handle or the document’s ID a string. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @returns A function to update the document state. Accepts either a new document state, or an updater function that exposes the previous document state and returns the new document state.\n * @example\n * ```\n * const myDocumentHandle = { _id: 'documentId', _type: 'documentType' }\n *\n * const myDocument = useDocument(myDocumentHandle)\n * const { title, price } = myDocument\n *\n * const editMyDocument = useEditDocument(myDocumentHandle)\n *\n * function handleFieldChange(e: React.ChangeEvent<HTMLInputElement>) {\n * const {name, value} = e.currentTarget\n * // Use an updater function to update the document state based on the previous state\n * editMyDocument(previousDocument => ({\n * ...previousDocument,\n * [name]: value\n * }))\n * }\n *\n * function handleSaleChange(e: React.ChangeEvent<HTMLInputElement>) {\n * const { checked } = e.currentTarget\n * if (checked) {\n * // Use an updater function to add a new salePrice field;\n * // set it at a 20% discount off the normal price\n * editMyDocument(previousDocument => ({\n * ...previousDocument,\n * salePrice: previousDocument.price * 0.8,\n * }))\n * } else {\n * // Get the document state without the salePrice field\n * const { salePrice, ...rest } = myDocument\n * // Update the document state to remove the salePrice field\n * editMyDocument(rest)\n * }\n * }\n *\n * return (\n * <>\n * <form onSubmit={e => e.preventDefault()}>\n * <input name='title' type='text' value={title} onChange={handleFieldChange} />\n * <input name='price' type='number' value={price} onChange={handleFieldChange} />\n * <input\n * name='salePrice'\n * type='checkbox'\n * checked={Object(myDocument).hasOwnProperty('salePrice')}\n * onChange={handleSaleChange}\n * />\n * </form>\n * <pre><code>\n * {JSON.stringify(myDocument, null, 2)}\n * </code></pre>\n * </>\n * )\n * ```\n */\nexport function useEditDocument<TDocument extends SanityDocument>(\n doc: DocumentHandle<TDocument>,\n): (nextValue: Updater<TDocument>) => Promise<ActionsResult<TDocument>>\n\n/**\n *\n * @beta\n *\n * Enables editing of a document’s state.\n * When called with a `path` argument, the hook will return a function for updating a nested value.\n * When called without a `path` argument, the hook will return a function for updating the entire document.\n */\nexport function useEditDocument(\n doc: DocumentHandle,\n path?: string,\n): (updater: Updater<unknown>) => Promise<ActionsResult> {\n const resourceId = getResourceId(doc.resourceId)!\n const documentId = doc._id\n const instance = useSanityInstance(resourceId)\n const apply = useApplyActions(resourceId)\n const isDocumentReady = useCallback(\n () => getDocumentState(instance, documentId).getCurrent() !== undefined,\n [instance, documentId],\n )\n if (!isDocumentReady()) throw resolveDocument(instance, documentId)\n\n return (updater: Updater<unknown>) => {\n if (path) {\n const nextValue =\n typeof updater === 'function'\n ? updater(getDocumentState(instance, documentId, path).getCurrent())\n : updater\n\n return apply(editDocument(doc, {set: {[path]: nextValue}}))\n }\n\n const current = getDocumentState(instance, documentId).getCurrent()\n const nextValue = typeof updater === 'function' ? updater(current) : updater\n\n if (typeof nextValue !== 'object' || !nextValue) {\n throw new Error(\n `No path was provided to \\`useEditDocument\\` and the value provided was not a document object.`,\n )\n }\n\n const allKeys = Object.keys({...current, ...nextValue})\n const editActions = allKeys\n .filter((key) => !ignoredKeys.includes(key))\n .filter((key) => current?.[key] !== nextValue[key])\n .map((key) =>\n key in nextValue\n ? editDocument(doc, {set: {[key]: nextValue[key]}})\n : editDocument(doc, {unset: [key]}),\n )\n\n return apply(editActions)\n }\n}\n","import {\n type DocumentAction,\n getPermissionsState,\n getResourceId,\n type PermissionsResult,\n} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {filter, firstValueFrom} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n *\n * @beta\n *\n * Check if the current user has the specified permissions for the given document actions.\n *\n * @category Permissions\n * @param actions - One more more calls to a particular document action function for a given document\n * @returns An object that specifies whether the action is allowed; if the action is not allowed, an explanatory message and list of reasons is also provided.\n *\n * @example Checking for permission to publish a document\n * ```ts\n * import {usePermissions, useApplyActions} from '@sanity/sdk-react'\n * import {publishDocument} from '@sanity/sdk'\n *\n * export function PublishButton({doc}: {doc: DocumentHandle}) {\n * const canPublish = usePermissions(publishDocument(doc))\n * const applyAction = useApplyActions()\n *\n * return (\n * <>\n * <button\n * disabled={!canPublish.allowed}\n * onClick={() => applyAction(publishDocument(doc))}\n * popoverTarget={`${canPublish.allowed ? undefined : 'publishButtonPopover'}`}\n * >\n * Publish\n * </button>\n * {!canPublish.allowed && (\n * <div popover id=\"publishButtonPopover\">\n * {canPublish.message}\n * </div>\n * )}\n * </>\n * )\n * }\n * ```\n */\nexport function usePermissions(actions: DocumentAction | DocumentAction[]): PermissionsResult {\n // if actions is an array, we need to check each action to see if the resourceId is the same\n if (Array.isArray(actions)) {\n const resourceIds = actions.map((action) => action.resourceId)\n const uniqueResourceIds = new Set(resourceIds)\n if (uniqueResourceIds.size !== 1) {\n throw new Error('All actions must have the same resourceId')\n }\n }\n const resourceId = Array.isArray(actions)\n ? getResourceId(actions[0].resourceId)\n : getResourceId(actions.resourceId)\n\n const instance = useSanityInstance(resourceId)\n const isDocumentReady = useCallback(\n () => getPermissionsState(instance, actions).getCurrent() !== undefined,\n [actions, instance],\n )\n if (!isDocumentReady()) {\n throw firstValueFrom(\n getPermissionsState(instance, actions).observable.pipe(\n filter((result) => result !== undefined),\n ),\n )\n }\n\n const {subscribe, getCurrent} = useMemo(\n () => getPermissionsState(instance, actions),\n [actions, instance],\n )\n\n return useSyncExternalStore(subscribe, getCurrent) as PermissionsResult\n}\n","import {\n getQueryKey,\n getQueryState,\n parseQueryKey,\n type QueryOptions,\n resolveQuery,\n} from '@sanity/sdk'\nimport {useEffect, useMemo, useState, useSyncExternalStore, useTransition} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * Executes GROQ queries against a Sanity dataset.\n *\n * This hook provides a convenient way to fetch and subscribe to real-time updates\n * for your Sanity content. Changes made to the dataset’s content will trigger\n * automatic updates.\n *\n * @remarks\n * The returned `isPending` flag indicates when a React transition is in progress,\n * which can be used to show loading states for query changes.\n *\n * @beta\n * @category GROQ\n * @param query - GROQ query string to execute\n * @param options - Optional configuration for the query\n * @returns Object containing the query result and a pending state flag\n *\n * @example Basic usage\n * ```tsx\n * const {data, isPending} = useQuery<Movie[]>('*[_type == \"movie\"]')\n * ```\n *\n * @example Using parameters\n * ```tsx\n * // With parameters\n * const {data} = useQuery<Movie>('*[_type == \"movie\" && _id == $id][0]', {\n * params: { id: 'movie-123' }\n * })\n * ```\n *\n * @example With a loading state for transitions\n * ```tsx\n * const {data, isPending} = useQuery<Movie[]>('*[_type == \"movie\"]')\n * return (\n * <div>\n * {isPending && <div>Updating...</div>}\n * <ul>\n * {data.map(movie => <li key={movie._id}>{movie.title}</li>)}\n * </ul>\n * </div>\n * )\n * ```\n *\n */\nexport function useQuery<T>(query: string, options?: QueryOptions): {data: T; isPending: boolean} {\n const instance = useSanityInstance(options?.resourceId)\n // Use React's useTransition to avoid UI jank when queries change\n const [isPending, startTransition] = useTransition()\n\n // Get the unique key for this query and its options\n const queryKey = getQueryKey(query, options)\n // Use a deferred state to avoid immediate re-renders when the query changes\n const [deferredQueryKey, setDeferredQueryKey] = useState(queryKey)\n // Parse the deferred query key back into a query and options\n const deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey])\n\n // Create an AbortController to cancel in-flight requests when needed\n const [ref, setRef] = useState<AbortController>(new AbortController())\n\n // When the query or options change, start a transition to update the query\n useEffect(() => {\n if (queryKey === deferredQueryKey) return\n\n startTransition(() => {\n // Abort any in-flight requests for the previous query\n if (ref && !ref.signal.aborted) {\n ref.abort()\n setRef(new AbortController())\n }\n\n setDeferredQueryKey(queryKey)\n })\n }, [deferredQueryKey, queryKey, ref])\n\n // Get the state source for this query from the query store\n const {getCurrent, subscribe} = useMemo(\n () => getQueryState(instance, deferred.query, deferred.options),\n [instance, deferred],\n )\n\n // If data isn't available yet, suspend rendering until it is\n // This is the React Suspense integration - throwing a promise\n // will cause React to show the nearest Suspense fallback\n if (getCurrent() === undefined) {\n throw resolveQuery(instance, deferred.query, {...deferred.options, signal: ref.signal})\n }\n\n // Subscribe to updates and get the current data\n // useSyncExternalStore ensures the component re-renders when the data changes\n const data = useSyncExternalStore(subscribe, getCurrent) as T\n return {data, isPending}\n}\n","import {type DocumentHandle, type QueryOptions} from '@sanity/sdk'\nimport {type SortOrderingItem} from '@sanity/types'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useQuery} from '../query/useQuery'\n\nconst DEFAULT_BATCH_SIZE = 25\nconst DEFAULT_PERSPECTIVE = 'drafts'\n\n/**\n * Result structure returned from the infinite list query\n * @internal\n */\ninterface InfiniteListQueryResult {\n count: number\n data: DocumentHandle[]\n}\n\n/**\n * Configuration options for the useInfiniteList hook\n *\n * @beta\n * @category Types\n */\nexport interface InfiniteListOptions extends QueryOptions {\n /**\n * GROQ filter expression to apply to the query\n */\n filter?: string\n /**\n * Number of items to load per batch (defaults to 25)\n */\n batchSize?: number\n /**\n * Sorting configuration for the results\n */\n orderings?: SortOrderingItem[]\n /**\n * Text search query to filter results\n */\n search?: string\n}\n\n/**\n * Return value from the useInfiniteList hook\n *\n * @beta\n * @category Types\n */\nexport interface InfiniteList {\n /**\n * Array of document handles for the current batch\n */\n data: DocumentHandle[]\n /**\n * Whether there are more items available to load\n */\n hasMore: boolean\n /**\n * Total count of items matching the query\n */\n count: number\n /**\n * Whether a query is currently in progress\n */\n isPending: boolean\n /**\n * Function to load the next batch of results\n */\n loadMore: () => void\n}\n\n/**\n * Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,\n * with infinite scrolling support. The number of document handles returned per batch is customizable,\n * and additional batches can be loaded using the supplied `loadMore` function.\n *\n * @beta\n * @category Documents\n * @param options - Configuration options for the infinite list\n * @returns An object containing the list of document handles, the loading state, the total count of retrived document handles, and a function to load more\n * @example\n * ```tsx\n * const {data, hasMore, isPending, loadMore} = useInfiniteList({\n * filter: '_type == \"post\"',\n * search: searchTerm,\n * batchSize: 10,\n * orderings: [{field: '_createdAt', direction: 'desc'}]\n * })\n *\n * return (\n * <div>\n * Total documents: {count}\n * <ol>\n * {data.map((doc) => (\n * <li key={doc._id}>\n * <MyDocumentComponent doc={doc} />\n * </li>\n * ))}\n * </ol>\n * {hasMore && <button onClick={loadMore}>Load More</button>}\n * </div>\n * )\n * ```\n *\n */\nexport function useInfiniteList({\n batchSize = DEFAULT_BATCH_SIZE,\n params,\n search,\n filter,\n orderings,\n ...options\n}: InfiniteListOptions): InfiniteList {\n const perspective = options.perspective ?? DEFAULT_PERSPECTIVE\n const [limit, setLimit] = useState(batchSize)\n\n // Reset the limit to the current batchSize whenever any query parameters\n // (filter, search, params, orderings) or batchSize changes\n const key = JSON.stringify({filter, search, params, orderings, batchSize})\n useEffect(() => {\n setLimit(batchSize)\n }, [key, batchSize])\n\n const filterClause = useMemo(() => {\n const conditions: string[] = []\n\n // Add search query if specified\n if (search?.trim()) {\n conditions.push(`[@] match text::query(\"${search.trim()}\")`)\n }\n\n // Add additional filter if specified\n if (filter) {\n conditions.push(`(${filter})`)\n }\n\n return conditions.length ? `[${conditions.join(' && ')}]` : ''\n }, [filter, search])\n\n const orderClause = orderings\n ? `| order(${orderings\n .map((ordering) =>\n [ordering.field, ordering.direction.toLowerCase()]\n .map((str) => str.trim())\n .filter(Boolean)\n .join(' '),\n )\n .join(',')})`\n : ''\n\n const dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`\n const countQuery = `count(*${filterClause})`\n\n const {\n data: {count, data},\n isPending,\n } = useQuery<InfiniteListQueryResult>(`{\"count\":${countQuery},\"data\":${dataQuery}}`, {\n ...options,\n params,\n perspective,\n })\n\n const hasMore = data.length < count\n\n const loadMore = useCallback(() => {\n setLimit((prev) => Math.min(prev + batchSize, count))\n }, [count, batchSize])\n\n return useMemo(\n () => ({data, hasMore, count, isPending, loadMore}),\n [data, hasMore, count, isPending, loadMore],\n )\n}\n","import {type DocumentHandle, type QueryOptions} from '@sanity/sdk'\nimport {type SortOrderingItem} from '@sanity/types'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useQuery} from '../query/useQuery'\n\nconst DEFAULT_PERSPECTIVE = 'drafts'\n\n/**\n * Configuration options for the usePaginatedList hook\n *\n * @beta\n * @category Types\n */\nexport interface PaginatedListOptions extends QueryOptions {\n /**\n * GROQ filter expression to apply to the query\n */\n filter?: string\n /**\n * Number of items to display per page (defaults to 25)\n */\n pageSize?: number\n /**\n * Sorting configuration for the results\n */\n orderings?: SortOrderingItem[]\n /**\n * Text search query to filter results\n */\n search?: string\n}\n\n/**\n * Return value from the usePaginatedList hook\n *\n * @beta\n * @category Types\n */\nexport interface PaginatedList {\n /**\n * Array of document handles for the current page\n */\n data: DocumentHandle[]\n /**\n * Whether a query is currently in progress\n */\n isPending: boolean\n\n /**\n * Number of items displayed per page\n */\n pageSize: number\n /**\n * Current page number (1-indexed)\n */\n currentPage: number\n /**\n * Total number of pages available\n */\n totalPages: number\n\n /**\n * Starting index of the current page (0-indexed)\n */\n startIndex: number\n /**\n * Ending index of the current page (exclusive, 0-indexed)\n */\n endIndex: number\n /**\n * Total count of items matching the query\n */\n count: number\n\n /**\n * Navigate to the first page\n */\n firstPage: () => void\n /**\n * Whether there is a first page available to navigate to\n */\n hasFirstPage: boolean\n\n /**\n * Navigate to the previous page\n */\n previousPage: () => void\n /**\n * Whether there is a previous page available to navigate to\n */\n hasPreviousPage: boolean\n\n /**\n * Navigate to the next page\n */\n nextPage: () => void\n /**\n * Whether there is a next page available to navigate to\n */\n hasNextPage: boolean\n\n /**\n * Navigate to the last page\n */\n lastPage: () => void\n /**\n * Whether there is a last page available to navigate to\n */\n hasLastPage: boolean\n\n /**\n * Navigate to a specific page number\n * @param pageNumber - The page number to navigate to (1-indexed)\n */\n goToPage: (pageNumber: number) => void\n}\n\n/**\n * Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,\n * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,\n * while page navigation is handled via the included navigation functions.\n *\n * @beta\n * @category Documents\n * @param options - Configuration options for the paginated list\n * @returns An object containing the current page of document handles, the loading and pagination state, and navigation functions\n * @example\n * ```tsx\n * const {\n * data,\n * isPending,\n * currentPage,\n * totalPages,\n * nextPage,\n * previousPage,\n * hasNextPage,\n * hasPreviousPage\n * } = usePaginatedList({\n * filter: '_type == \"post\"',\n * search: searchTerm,\n * pageSize: 10,\n * orderings: [{field: '_createdAt', direction: 'desc'}]\n * })\n *\n * return (\n * <>\n * <table>\n * {data.map(doc => (\n * <MyTableRowComponent key={doc._id} doc={doc} />\n * ))}\n * </table>\n * <>\n * {hasPreviousPage && <button onClick={previousPage}>Previous</button>}\n * {currentPage} / {totalPages}\n * {hasNextPage && <button onClick={nextPage}>Next</button>}\n * </>\n * </>\n * )\n * ```\n *\n */\nexport function usePaginatedList({\n filter = '',\n pageSize = 25,\n params = {},\n orderings,\n search,\n ...options\n}: PaginatedListOptions = {}): PaginatedList {\n const [pageIndex, setPageIndex] = useState(0)\n const key = JSON.stringify({filter, search, params, orderings, pageSize})\n // Reset the pageIndex to 0 whenever any query parameters (filter, search,\n // params, orderings) or pageSize changes\n useEffect(() => {\n setPageIndex(0)\n }, [key])\n\n const startIndex = pageIndex * pageSize\n const endIndex = (pageIndex + 1) * pageSize\n const perspective = options.perspective ?? DEFAULT_PERSPECTIVE\n\n const filterClause = useMemo(() => {\n const conditions: string[] = []\n\n // Add search query if specified\n if (search?.trim()) {\n conditions.push(`[@] match text::query(\"${search.trim()}\")`)\n }\n\n // Add additional filter if specified\n if (filter) {\n conditions.push(`(${filter})`)\n }\n\n return conditions.length ? `[${conditions.join(' && ')}]` : ''\n }, [filter, search])\n\n const orderClause = orderings\n ? `| order(${orderings\n .map((ordering) =>\n [ordering.field, ordering.direction.toLowerCase()]\n .map((str) => str.trim())\n .filter(Boolean)\n .join(' '),\n )\n .join(',')})`\n : ''\n\n const dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`\n const countQuery = `count(*${filterClause})`\n\n const {\n data: {data, count},\n isPending,\n } = useQuery<{data: DocumentHandle[]; count: number}>(\n `{\"data\":${dataQuery},\"count\":${countQuery}}`,\n {\n ...options,\n perspective,\n params,\n },\n )\n\n const totalPages = Math.ceil(count / pageSize)\n const currentPage = pageIndex + 1\n\n // Navigation methods\n const firstPage = useCallback(() => setPageIndex(0), [])\n const previousPage = useCallback(() => setPageIndex((prev) => Math.max(prev - 1, 0)), [])\n const nextPage = useCallback(\n () => setPageIndex((prev) => Math.min(prev + 1, totalPages - 1)),\n [totalPages],\n )\n const lastPage = useCallback(() => setPageIndex(totalPages - 1), [totalPages])\n const goToPage = useCallback(\n (pageNumber: number) => {\n if (pageNumber < 1 || pageNumber > totalPages) return\n setPageIndex(pageNumber - 1)\n },\n [totalPages],\n )\n\n // Boolean flags for page availability\n const hasFirstPage = pageIndex > 0\n const hasPreviousPage = pageIndex > 0\n const hasNextPage = pageIndex < totalPages - 1\n const hasLastPage = pageIndex < totalPages - 1\n\n return useMemo(\n () => ({\n data,\n isPending,\n pageSize,\n currentPage,\n totalPages,\n startIndex,\n endIndex,\n count,\n firstPage,\n hasFirstPage,\n previousPage,\n hasPreviousPage,\n nextPage,\n hasNextPage,\n lastPage,\n hasLastPage,\n goToPage,\n }),\n [\n data,\n isPending,\n pageSize,\n currentPage,\n totalPages,\n startIndex,\n endIndex,\n count,\n firstPage,\n hasFirstPage,\n previousPage,\n hasPreviousPage,\n nextPage,\n hasNextPage,\n lastPage,\n hasLastPage,\n goToPage,\n ],\n )\n}\n","import {type DocumentHandle, getPreviewState, type PreviewValue, resolvePreview} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {distinctUntilChanged, EMPTY, Observable, startWith, switchMap} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @beta\n * @category Types\n */\nexport interface UsePreviewOptions {\n document: DocumentHandle\n ref?: React.RefObject<unknown>\n}\n\n/**\n * @beta\n * @category Types\n */\nexport interface UsePreviewResults {\n /** The results of resolving the document’s preview values */\n results: PreviewValue\n /** True when preview values are being refreshed */\n isPending: boolean\n}\n\n/**\n * @beta\n *\n * Returns the preview values of a document (specified via a `DocumentHandle`),\n * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.\n * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview\n * resolution will only occur if the `ref` is intersecting the current viewport.\n *\n * @category Documents\n * @param options - The document handle for the document you want to resolve preview values for, and an optional ref\n * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending\n *\n * @example Combining with useDocuments to render a collection of document previews\n * ```\n * // PreviewComponent.jsx\n * export default function PreviewComponent({ document }) {\n * const { results: { title, subtitle, media }, isPending } = usePreview({ document })\n * return (\n * <article style={{ opacity: isPending ? 0.5 : 1}}>\n * {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}\n * <h2>{title}</h2>\n * <p>{subtitle}</p>\n * </article>\n * )\n * }\n *\n * // DocumentList.jsx\n * const { results, isPending } = useDocuments({ filter: '_type == \"movie\"' })\n * return (\n * <div>\n * <h1>Movies</h1>\n * <ul>\n * {isPending ? 'Loading…' : results.map(movie => (\n * <li key={movie._id}>\n * <Suspense fallback='Loading…'>\n * <PreviewComponent document={movie} />\n * </Suspense>\n * </li>\n * ))}\n * </ul>\n * </div>\n * )\n * ```\n */\nexport function usePreview({document: {_id, _type}, ref}: UsePreviewOptions): UsePreviewResults {\n const instance = useSanityInstance()\n\n const stateSource = useMemo(\n () => getPreviewState(instance, {document: {_id, _type}}),\n [instance, _id, _type],\n )\n\n // Create subscribe function for useSyncExternalStore\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n const subscription = new Observable<boolean>((observer) => {\n // for environments that don't have an intersection observer\n if (typeof IntersectionObserver === 'undefined' || typeof HTMLElement === 'undefined') {\n return\n }\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => observer.next(entry.isIntersecting),\n {rootMargin: '0px', threshold: 0},\n )\n if (ref?.current && ref.current instanceof HTMLElement) {\n intersectionObserver.observe(ref.current)\n }\n return () => intersectionObserver.disconnect()\n })\n .pipe(\n startWith(false),\n distinctUntilChanged(),\n switchMap((isVisible) =>\n isVisible\n ? new Observable<void>((obs) => {\n return stateSource.subscribe(() => obs.next())\n })\n : EMPTY,\n ),\n )\n .subscribe({next: onStoreChanged})\n\n return () => subscription.unsubscribe()\n },\n [stateSource, ref],\n )\n\n // Create getSnapshot function to return current state\n const getSnapshot = useCallback(() => {\n const currentState = stateSource.getCurrent()\n if (currentState.results === null) throw resolvePreview(instance, {document: {_id, _type}})\n return currentState as UsePreviewResults\n }, [_id, _type, instance, stateSource])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n","import {\n type DocumentHandle,\n getProjectionState,\n resolveProjection,\n type ValidProjection,\n} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {distinctUntilChanged, EMPTY, Observable, startWith, switchMap} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\ninterface UseProjectionOptions {\n document: DocumentHandle\n projection: ValidProjection\n ref?: React.RefObject<unknown>\n}\n\ninterface UseProjectionResults<TResult extends object> {\n results: TResult\n isPending: boolean\n}\n\n/**\n * @beta\n *\n * Returns the projection values of a document (specified via a `DocumentHandle`),\n * based on the provided projection string. These values are live and will update in realtime.\n * To reduce unnecessary network requests for resolving the projection values, an optional `ref` can be passed to the hook so that projection\n * resolution will only occur if the `ref` is intersecting the current viewport.\n *\n * @category Documents\n * @param options - The document handle for the document you want to project values from, the projection string, and an optional ref\n * @returns The projection values for the given document and a boolean to indicate whether the resolution is pending\n *\n * @example Using a projection to display specific document fields\n * ```\n * // ProjectionComponent.jsx\n * export default function ProjectionComponent({ document }) {\n * const ref = useRef(null)\n * const { results: { title, description, authors }, isPending } = useProjection({\n * document,\n * projection: '{title, \"description\": pt::text(\"description\"), \"authors\": array::join(authors[]->name, \", \")}',\n * ref\n * })\n *\n * return (\n * <article ref={ref} style={{ opacity: isPending ? 0.5 : 1}}>\n * <h2>{title}</h2>\n * <p>{description}</p>\n * <p>{authors}</p>\n * </article>\n * )\n * }\n * ```\n *\n * @example Combining with useInfiniteList to render a collection with specific fields\n * ```\n * // DocumentList.jsx\n * const { data } = useInfiniteList({ filter: '_type == \"article\"' })\n * return (\n * <div>\n * <h1>Articles</h1>\n * <ul>\n * {data.map(article => (\n * <li key={article._id}>\n * <Suspense fallback='Loading…'>\n * <ProjectionComponent\n * document={article}\n * />\n * </Suspense>\n * </li>\n * ))}\n * </ul>\n * </div>\n * )\n * ```\n */\nexport function useProjection<TResult extends object>({\n document: {_id, _type},\n projection,\n ref,\n}: UseProjectionOptions): UseProjectionResults<TResult> {\n const instance = useSanityInstance()\n\n const stateSource = useMemo(\n () => getProjectionState<TResult>(instance, {document: {_id, _type}, projection}),\n [instance, _id, _type, projection],\n )\n\n // Create subscribe function for useSyncExternalStore\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n const subscription = new Observable<boolean>((observer) => {\n // for environments that don't have an intersection observer\n if (typeof IntersectionObserver === 'undefined' || typeof HTMLElement === 'undefined') {\n return\n }\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => observer.next(entry.isIntersecting),\n {rootMargin: '0px', threshold: 0},\n )\n if (ref?.current && ref.current instanceof HTMLElement) {\n intersectionObserver.observe(ref.current)\n }\n return () => intersectionObserver.disconnect()\n })\n .pipe(\n startWith(false),\n distinctUntilChanged(),\n switchMap((isVisible) =>\n isVisible\n ? new Observable<void>((obs) => {\n return stateSource.subscribe(() => obs.next())\n })\n : EMPTY,\n ),\n )\n .subscribe({next: onStoreChanged})\n\n return () => subscription.unsubscribe()\n },\n [stateSource, ref],\n )\n\n // Create getSnapshot function to return current state\n const getSnapshot = useCallback(() => {\n const currentState = stateSource.getCurrent()\n if (currentState.results === null)\n throw resolveProjection(instance, {document: {_id, _type}, projection})\n return currentState as UseProjectionResults<TResult>\n }, [_id, _type, projection, instance, stateSource])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n","import {\n getProjectState,\n resolveProject,\n type SanityInstance,\n type SanityProject,\n type StateSource,\n} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseProject = {\n /**\n *\n * Returns metadata for a given project\n *\n * @category Projects\n * @param projectId - The ID of the project to retrieve metadata for\n * @returns The metadata for the project\n * @example\n * ```tsx\n * function ProjectMetadata({ projectId }: { projectId: string }) {\n * const project = useProject(projectId)\n *\n * return (\n * <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>\n * <h1>{project.displayName}</h1>\n * </figure>\n * )\n * }\n * ```\n */\n (projectId: string): SanityProject\n}\n\n/** @public */\nexport const useProject: UseProject = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getProjectState as (\n instance: SanityInstance,\n projectId: string,\n ) => StateSource<SanityProject>,\n shouldSuspend: (instance, projectId) =>\n getProjectState(instance, projectId).getCurrent() === undefined,\n suspender: resolveProject,\n})\n","import {type SanityProject} from '@sanity/client'\nimport {getProjectsState, resolveProjects, type SanityInstance, type StateSource} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @public\n * @category Types\n */\nexport type ProjectWithoutMembers = Omit<SanityProject, 'members'>\n\ntype UseProjects = {\n /**\n *\n * Returns metadata for each project in your organization.\n *\n * @category Projects\n * @returns An array of metadata (minus the projects’ members) for each project in your organization\n * @example\n * ```tsx\n * const projects = useProjects()\n *\n * return (\n * <select>\n * {projects.map((project) => (\n * <option key={project.id}>{project.displayName}</option>\n * ))}\n * </select>\n * )\n * ```\n */\n (): ProjectWithoutMembers[]\n}\n\n/** @public */\nexport const useProjects: UseProjects = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getProjectsState as (instance: SanityInstance) => StateSource<ProjectWithoutMembers[]>,\n shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === undefined,\n suspender: resolveProjects,\n})\n","import {createUsersStore, type ResourceType, type SanityUser} from '@sanity/sdk'\nimport {useCallback, useEffect, useState, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @public\n * @category Types\n */\nexport interface UseUsersParams {\n /**\n * The type of resource to fetch users for.\n */\n resourceType: ResourceType\n /**\n * The ID of the resource to fetch users for.\n */\n resourceId: string\n /**\n * The limit of users to fetch.\n */\n limit?: number\n}\n\n/**\n * @public\n * @category Types\n */\nexport interface UseUsersResult {\n /**\n * The users fetched.\n */\n users: SanityUser[]\n /**\n * Whether there are more users to fetch.\n */\n hasMore: boolean\n /**\n * Load more users.\n */\n loadMore: () => void\n}\n\n/**\n *\n * @public\n *\n * Retrieves the users for a given resource (either a project or an organization).\n *\n * @category Users\n * @param params - The resource type and its ID, and the limit of users to fetch\n * @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users\n *\n * @example\n * ```\n * const { users, hasMore, loadMore } = useUsers({\n * resourceType: 'organization',\n * resourceId: 'my-org-id',\n * limit: 10,\n * })\n *\n * return (\n * <div>\n * {users.map(user => (\n * <figure key={user.sanityUserId}>\n * <img src={user.profile.imageUrl} alt='' />\n * <figcaption>{user.profile.displayName}</figcaption>\n * <address>{user.profile.email}</address>\n * </figure>\n * ))}\n * {hasMore && <button onClick={loadMore}>Load More</button>}\n * </div>\n * )\n * ```\n */\nexport function useUsers(params: UseUsersParams): UseUsersResult {\n const instance = useSanityInstance(params.resourceId)\n const [store] = useState(() => createUsersStore(instance))\n\n useEffect(() => {\n store.setOptions({\n resourceType: params.resourceType,\n resourceId: params.resourceId,\n })\n }, [params.resourceType, params.resourceId, store])\n\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n if (store.getState().getCurrent().initialFetchCompleted === false) {\n store.resolveUsers()\n }\n const unsubscribe = store.getState().subscribe(onStoreChanged)\n\n return () => {\n unsubscribe()\n store.dispose()\n }\n },\n [store],\n )\n\n const getSnapshot = useCallback(() => store.getState().getCurrent(), [store])\n\n const {users, hasMore} = useSyncExternalStore(subscribe, getSnapshot) || {}\n\n return {users, hasMore, loadMore: store.loadMore}\n}\n"],"names":["useAuthToken","createStateSourceHook","getTokenState","useCurrentUser","getCurrentUserState","useClient","getState","getClientState","getResourceId","e","resourceId","useFrameConnection","options","$","_c","onMessage","targetOrigin","name","connectTo","heartbeat","instance","useSanityInstance","status","setStatus","useState","t0","t1","getOrCreateController","controller","t2","t3","getOrCreateChannel","channel","t4","t5","onStatus","event","useEffect","t6","t7","unsubscribers","Object","entries","forEach","t8","type","handler","unsubscribe_0","on","push","unsubscribe","_temp","frameWindow","removeTarget","addTarget","connect","t9","type_0","data","post","sendMessage","t10","t11","releaseChannel","t12","unsub","useWindowConnection","getOrCreateNode","node","newStatus","releaseNode","useDatasets","getDatasetsState","shouldSuspend","getCurrent","undefined","suspender","resolveDatasets","useApplyActions","_useApplyActions","createCallbackHook","applyActions","useDocument","doc","path","_useDocument","getDocumentState","_id","resolveDocument","useDocumentEvent","ref","useRef","current","useInsertionEffect","Symbol","for","documentEvent","stableHandler","subscribeDocumentEvents","useDocumentSyncStatus","getDocumentSyncStatus","ignoredKeys","useEditDocument","documentId","apply","updater","nextValue","editDocument","set","nextValue_0","Error","editActions","keys","filter","key_0","key","map","key_1","unset","includes","usePermissions","actions","Array","isArray","resourceIds","Set","size","getPermissionsState","firstValueFrom","observable","pipe","_temp2","subscribe","useSyncExternalStore","result","action","useQuery","query","isPending","startTransition","useTransition","queryKey","getQueryKey","deferredQueryKey","setDeferredQueryKey","deferred","useMemo","parseQueryKey","setRef","AbortController","signal","aborted","abort","getQueryState","resolveQuery","DEFAULT_BATCH_SIZE","DEFAULT_PERSPECTIVE","useInfiniteList","orderings","params","search","batchSize","perspective","limit","setLimit","JSON","stringify","conditions","trim","length","join","filterClause","orderClause","dataQuery","countQuery","count","hasMore","prev","Math","min","loadMore","ordering","field","direction","toLowerCase","Boolean","str","usePaginatedList","pageSize","pageIndex","setPageIndex","startIndex","endIndex","totalPages","ceil","currentPage","firstPage","t13","_temp3","previousPage","t14","prev_0","nextPage","t15","lastPage","t16","pageNumber","goToPage","hasFirstPage","hasPreviousPage","hasNextPage","hasLastPage","t17","t18","max","usePreview","document","_type","getPreviewState","stateSource","onStoreChanged","subscription","Observable","observer","IntersectionObserver","HTMLElement","intersectionObserver","entry","next","isIntersecting","rootMargin","threshold","observe","disconnect","startWith","distinctUntilChanged","switchMap","isVisible","obs","EMPTY","currentState","results","resolvePreview","useProjection","projection","getProjectionState","resolveProjection","useProject","getProjectState","projectId","resolveProject","useProjects","getProjectsState","resolveProjects","useUsers","createUsersStore","store","resourceType","setOptions","initialFetchCompleted","resolveUsers","dispose","getSnapshot","users"],"mappings":";;;;;;AASaA,MAAAA,eAAeC,sBAAsBC,aAAa,GCuBlDC,iBAAiCF,sBAAsBG,mBAAmB,GCF1EC,YAAYJ,sBAAsB;AAAA,EAC7CK,UAAUC;AAAAA,EACVC,eAAgBC,OAAMA,EAAEC;AAC1B,CAAC;ACeM,SAAAC,mBAAAC,SAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA,GAIL;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAA8DP,SAC9DQ,WAAiBC,kBAAkB,GACnC,CAAAC,QAAAC,SAAA,IAA4BC,SAAiB,MAAM;AAAC,MAAAC,IAAAC;AAAAb,IAAAO,CAAAA,MAAAA,YAAAP,SAAAG,gBAG5CU,KAAAC,sBAAsBP,UAAUJ,YAAY,GAACH,OAAAO,UAAAP,OAAAG,cAAAH,OAAAa,MAAAA,KAAAb,EAAA,CAAA,GAAAY,KAA7CC;AADR,QAAAE,aAAmBH;AAGlB,MAAAI,IAAAC;AAAAjB,IAAA,CAAA,MAAAK,aAAAL,EAAAM,CAAAA,MAAAA,aAAAN,EAAAO,CAAAA,MAAAA,YAAAP,SAAAI,QAIGa,KAAAC,mBAAmBX,UAAQ;AAAA,IAAAH;AAAAA,IAAA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pErO,KAAA;AAAA,IAAAqO;AAAAA,IAAAvF;AAAAA,IAAAI,UAA2B4E,MAAK5E;AAAAA,EAAAA,GAAUvK,QAAAmK,SAAAnK,EAAA,EAAA,IAAAmP,MAAA5E,UAAAvK,QAAA0P,OAAA1P,QAAAqB,MAAAA,KAAArB,EAAA,EAAA,GAA1CqB;AAA0C;"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../src/hooks/auth/useAuthToken.tsx","../src/hooks/auth/useCurrentUser.tsx","../src/hooks/client/useClient.ts","../src/hooks/comlink/useFrameConnection.ts","../src/hooks/comlink/useWindowConnection.ts","../src/hooks/comlink/useManageFavorite.ts","../src/hooks/comlink/useRecordDocumentHistoryEvent.ts","../src/hooks/datasets/useDatasets.ts","../src/hooks/document/useApplyActions.ts","../src/hooks/document/useDocument.ts","../src/hooks/document/useDocumentEvent.ts","../src/hooks/document/useDocumentSyncStatus.ts","../src/hooks/document/useEditDocument.ts","../src/hooks/document/usePermissions.ts","../src/hooks/query/useQuery.ts","../src/hooks/infiniteList/useInfiniteList.ts","../src/hooks/paginatedList/usePaginatedList.ts","../src/hooks/preview/usePreview.tsx","../src/hooks/projection/useProjection.ts","../src/hooks/projects/useProject.ts","../src/hooks/projects/useProjects.ts","../src/hooks/users/useUsers.ts"],"sourcesContent":["import {getTokenState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * Hook to get the currently logged in user\n * @internal\n * @returns The current user or null if not authenticated\n */\nexport const useAuthToken = createStateSourceHook(getTokenState)\n","import {type CurrentUser, getCurrentUserState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseCurrentUser = {\n /**\n * @public\n *\n * Provides the currently authenticated user’s profile information.\n *\n * @category Users\n * @returns The current user data\n *\n * @example Rendering a basic user profile\n * ```\n * const user = useCurrentUser()\n *\n * return (\n * <figure>\n * <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />\n * <h2>{user?.name}</h2>\n * </figure>\n * )\n * ```\n */\n (): CurrentUser | null\n}\n\n/**\n * @public\n * @TODO This should not return null — users of a custom app will always be authenticated via Core\n */\nexport const useCurrentUser: UseCurrentUser = createStateSourceHook(getCurrentUserState)\n","import {getClientState} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * A React hook that provides a client that subscribes to changes in your application,\n * such as user authentication changes.\n *\n * @remarks\n * The hook uses `useSyncExternalStore` to safely subscribe to changes\n * and ensure consistency between server and client rendering.\n *\n * @category Platform\n * @returns A Sanity client\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const client = useClient({apiVersion: '2024-11-12'})\n * const [document, setDocument] = useState(null)\n * useEffect(async () => {\n * const doc = client.fetch('*[_id == \"myDocumentId\"]')\n * setDocument(doc)\n * }, [])\n * return <div>{JSON.stringify(document) ?? 'Loading...'}</div>\n * }\n * ```\n *\n * @public\n */\nexport const useClient = createStateSourceHook({\n getState: getClientState,\n getResourceId: (e) => e.resourceId,\n})\n","import {type Status} from '@sanity/comlink'\nimport {\n type FrameMessage,\n getOrCreateChannel,\n getOrCreateController,\n releaseChannel,\n type WindowMessage,\n} from '@sanity/sdk'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @internal\n */\nexport type FrameMessageHandler<TWindowMessage extends WindowMessage> = (\n event: TWindowMessage['data'],\n) => TWindowMessage['response'] | Promise<TWindowMessage['response']>\n\n/**\n * @internal\n */\nexport interface UseFrameConnectionOptions<TWindowMessage extends WindowMessage> {\n name: string\n connectTo: string\n targetOrigin: string\n onMessage?: {\n [K in TWindowMessage['type']]: (data: Extract<TWindowMessage, {type: K}>['data']) => void\n }\n heartbeat?: boolean\n}\n\n/**\n * @internal\n */\nexport interface FrameConnection<TFrameMessage extends FrameMessage> {\n connect: (frameWindow: Window) => () => void // Return cleanup function\n sendMessage: <T extends TFrameMessage['type']>(\n ...params: Extract<TFrameMessage, {type: T}>['data'] extends undefined\n ? [type: T]\n : [type: T, data: Extract<TFrameMessage, {type: T}>['data']]\n ) => void\n status: Status\n}\n\n/**\n * @internal\n */\nexport function useFrameConnection<\n TFrameMessage extends FrameMessage,\n TWindowMessage extends WindowMessage,\n>(options: UseFrameConnectionOptions<TWindowMessage>): FrameConnection<TFrameMessage> {\n const {onMessage, targetOrigin, name, connectTo, heartbeat} = options\n const instance = useSanityInstance()\n const [status, setStatus] = useState<Status>('idle')\n\n const controller = useMemo(\n () => getOrCreateController(instance, targetOrigin),\n [instance, targetOrigin],\n )\n\n const channel = useMemo(\n () =>\n getOrCreateChannel(instance, {\n name,\n connectTo,\n heartbeat,\n }),\n [instance, name, connectTo, heartbeat],\n )\n\n useEffect(() => {\n if (!channel) return\n\n const unsubscribe = channel.onStatus((event) => {\n setStatus(event.status)\n })\n\n return unsubscribe\n }, [channel])\n\n useEffect(() => {\n if (!channel || !onMessage) return\n\n const unsubscribers: Array<() => void> = []\n\n Object.entries(onMessage).forEach(([type, handler]) => {\n // type assertion, but we've already constrained onMessage to have the correct handler type\n const unsubscribe = channel.on(type, handler as FrameMessageHandler<TWindowMessage>)\n unsubscribers.push(unsubscribe)\n })\n\n return () => {\n unsubscribers.forEach((unsub) => unsub())\n }\n }, [channel, onMessage])\n\n const connect = useCallback(\n (frameWindow: Window) => {\n const removeTarget = controller?.addTarget(frameWindow)\n return () => {\n removeTarget?.()\n }\n },\n [controller],\n )\n\n const sendMessage = useCallback(\n <T extends TFrameMessage['type']>(\n type: T,\n data?: Extract<TFrameMessage, {type: T}>['data'],\n ) => {\n channel?.post(type, data)\n },\n [channel],\n )\n\n // cleanup channel on unmount\n useEffect(() => {\n return () => {\n releaseChannel(instance, name)\n }\n }, [name, instance])\n\n return {\n connect,\n sendMessage,\n status,\n }\n}\n","import {type Status} from '@sanity/comlink'\nimport {type FrameMessage, getOrCreateNode, releaseNode, type WindowMessage} from '@sanity/sdk'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @internal\n */\nexport type WindowMessageHandler<TFrameMessage extends FrameMessage> = (\n event: TFrameMessage['data'],\n) => TFrameMessage['response']\n\n/**\n * @internal\n */\nexport interface UseWindowConnectionOptions<TMessage extends FrameMessage> {\n name: string\n connectTo: string\n onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>\n}\n\n/**\n * @internal\n */\nexport interface WindowConnection<TMessage extends WindowMessage> {\n sendMessage: <TType extends TMessage['type']>(\n type: TType,\n data?: Extract<TMessage, {type: TType}>['data'],\n ) => void\n status: Status\n}\n\n/**\n * @internal\n */\nexport function useWindowConnection<\n TWindowMessage extends WindowMessage,\n TFrameMessage extends FrameMessage,\n>(options: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage> {\n const {name, onMessage, connectTo} = options\n const instance = useSanityInstance()\n const [status, setStatus] = useState<Status>('idle')\n\n const node = useMemo(\n () => getOrCreateNode(instance, {name, connectTo}),\n [instance, name, connectTo],\n )\n\n useEffect(() => {\n const unsubscribe = node.onStatus((newStatus) => {\n setStatus(newStatus)\n })\n\n return unsubscribe\n }, [node, instance, name])\n\n useEffect(() => {\n if (!onMessage) return\n\n const unsubscribers: Array<() => void> = []\n\n Object.entries(onMessage).forEach(([type, handler]) => {\n const unsubscribe = node.on(type, handler as WindowMessageHandler<TFrameMessage>)\n unsubscribers.push(unsubscribe)\n })\n\n return () => {\n unsubscribers.forEach((unsub) => unsub())\n }\n }, [node, onMessage])\n\n const sendMessage = useCallback(\n <TType extends WindowMessage['type']>(\n type: TType,\n data?: Extract<WindowMessage, {type: TType}>['data'],\n ) => {\n node?.post(type, data)\n },\n [node],\n )\n\n // cleanup node on unmount\n useEffect(() => {\n return () => {\n releaseNode(instance, name)\n }\n }, [instance, name])\n\n return {\n sendMessage,\n status,\n }\n}\n","import {type Events, SDK_CHANNEL_NAME, SDK_NODE_NAME} from '@sanity/message-protocol'\nimport {type DocumentHandle, type FrameMessage} from '@sanity/sdk'\nimport {useCallback, useState} from 'react'\n\nimport {useWindowConnection} from './useWindowConnection'\n\n// should we import this whole type from the message protocol?\n\ninterface ManageFavorite {\n favorite: () => void\n unfavorite: () => void\n isFavorited: boolean\n isConnected: boolean\n}\n\n/**\n * @beta\n *\n * ## useManageFavorite\n * This hook provides functionality to add and remove documents from favorites,\n * and tracks the current favorite status of the document.\n * @category Core UI Communication\n * @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`\n * @returns An object containing:\n * - `favorite` - Function to add document to favorites\n * - `unfavorite` - Function to remove document from favorites\n * - `isFavorited` - Boolean indicating if document is currently favorited\n * - `isConnected` - Boolean indicating if connection to Core UI is established\n *\n * @example\n * ```tsx\n * function MyDocumentAction(props: DocumentActionProps) {\n * const {_id, _type} = props\n * const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({\n * _id,\n * _type\n * })\n *\n * return (\n * <Button\n * disabled={!isConnected}\n * onClick={() => isFavorited ? unfavorite() : favorite()}\n * text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}\n * />\n * )\n * }\n * ```\n */\nexport function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite {\n const [isFavorited, setIsFavorited] = useState(false) // should load this from a comlink fetch\n const {sendMessage, status} = useWindowConnection<Events.FavoriteMessage, FrameMessage>({\n name: SDK_NODE_NAME,\n connectTo: SDK_CHANNEL_NAME,\n })\n\n const handleFavoriteAction = useCallback(\n (action: 'added' | 'removed', setFavoriteState: boolean) => {\n if (!_id || !_type) return\n\n try {\n const message: Events.FavoriteMessage = {\n type: 'core/v1/events/favorite',\n data: {\n eventType: action,\n documentId: _id,\n documentType: _type,\n },\n }\n\n sendMessage(message.type, message.data)\n setIsFavorited(setFavoriteState)\n } catch (err) {\n const error = err instanceof Error ? err : new Error('Failed to update favorite status')\n // eslint-disable-next-line no-console\n console.error(\n `Failed to ${action === 'added' ? 'favorite' : 'unfavorite'} document:`,\n error,\n )\n throw error\n }\n },\n [_id, _type, sendMessage],\n )\n\n const favorite = useCallback(() => handleFavoriteAction('added', true), [handleFavoriteAction])\n\n const unfavorite = useCallback(\n () => handleFavoriteAction('removed', false),\n [handleFavoriteAction],\n )\n\n return {\n favorite,\n unfavorite,\n isFavorited,\n isConnected: status === 'connected',\n }\n}\n","import {type Events, SDK_CHANNEL_NAME, SDK_NODE_NAME} from '@sanity/message-protocol'\nimport {type DocumentHandle, type FrameMessage} from '@sanity/sdk'\nimport {useCallback} from 'react'\n\nimport {useWindowConnection} from './useWindowConnection'\n\ninterface DocumentInteractionHistory {\n recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void\n isConnected: boolean\n}\n\n/**\n * @public\n * Hook for managing document interaction history in Sanity Studio.\n * This hook provides functionality to record document interactions.\n * @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`\n * @returns An object containing:\n * - `recordEvent` - Function to record document interactions\n * - `isConnected` - Boolean indicating if connection to Studio is established\n *\n * @example\n * ```tsx\n * function MyDocumentAction(props: DocumentActionProps) {\n * const {_id, _type} = props\n * const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({\n * _id,\n * _type\n * })\n *\n * return (\n * <Button\n * disabled={!isConnected}\n * onClick={() => recordEvent('viewed')}\n * text={'Viewed'}\n * />\n * )\n * }\n * ```\n */\nexport function useRecordDocumentHistoryEvent({\n _id,\n _type,\n}: DocumentHandle): DocumentInteractionHistory {\n const {sendMessage, status} = useWindowConnection<Events.HistoryMessage, FrameMessage>({\n name: SDK_NODE_NAME,\n connectTo: SDK_CHANNEL_NAME,\n })\n\n const recordEvent = useCallback(\n (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => {\n try {\n const message: Events.HistoryMessage = {\n type: 'core/v1/events/history',\n data: {\n eventType,\n documentId: _id,\n documentType: _type,\n },\n }\n\n sendMessage(message.type, message.data)\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to record history event:', error)\n throw error\n }\n },\n [_id, _type, sendMessage],\n )\n\n return {\n recordEvent,\n isConnected: status === 'connected',\n }\n}\n","import {type DatasetsResponse} from '@sanity/client'\nimport {getDatasetsState, resolveDatasets, type SanityInstance, type StateSource} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseDatasets = {\n /**\n *\n * Returns metadata for each dataset in your organization.\n *\n * @category Datasets\n * @returns The metadata for your organization's datasets\n *\n * @example\n * ```tsx\n * const datasets = useDatasets()\n *\n * return (\n * <select>\n * {datasets.map((dataset) => (\n * <option key={dataset.name}>{dataset.name}</option>\n * ))}\n * </select>\n * )\n * ```\n *\n */\n (): DatasetsResponse\n}\n\n/** @public */\nexport const useDatasets: UseDatasets = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getDatasetsState as (instance: SanityInstance) => StateSource<DatasetsResponse>,\n shouldSuspend: (instance) => getDatasetsState(instance).getCurrent() === undefined,\n suspender: resolveDatasets,\n})\n","import {\n type ActionsResult,\n applyActions,\n type ApplyActionsOptions,\n type DocumentAction,\n type ResourceId,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\n\nimport {createCallbackHook} from '../helpers/createCallbackHook'\n\n/**\n *\n * @beta\n *\n * Provides a callback for applying one or more actions to a document.\n *\n * @category Documents\n * @param resourceId - The resource ID of the document to apply actions to. If not provided, the document will use the default resource.\n * @returns A function that takes one more more {@link DocumentAction}s and returns a promise that resolves to an {@link ActionsResult}.\n * @example Publish or unpublish a document\n * ```\n * import { publishDocument, unpublishDocument } from '@sanity/sdk'\n * import { useApplyActions } from '@sanity/sdk-react'\n *\n * const apply = useApplyActions()\n * const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }\n *\n * return (\n * <button onClick={() => apply(publishDocument(myDocument))}>Publish</button>\n * <button onClick={() => apply(unpublishDocument(myDocument))}>Unpublish</button>\n * )\n * ```\n *\n * @example Create and publish a new document\n * ```\n * import { createDocument, publishDocument } from '@sanity/sdk'\n * import { useApplyActions } from '@sanity/sdk-react'\n *\n * const apply = useApplyActions()\n *\n * const handleCreateAndPublish = () => {\n * const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }\n * apply([\n * createDocument(handle),\n * publishDocument(handle),\n * ])\n * }\n *\n * return (\n * <button onClick={handleCreateAndPublish}>\n * I’m feeling lucky\n * </button>\n * )\n * ```\n */\nexport function useApplyActions(\n resourceId?: ResourceId,\n): <TDocument extends SanityDocument>(\n action: DocumentAction<TDocument> | DocumentAction<TDocument>[],\n options?: ApplyActionsOptions,\n) => Promise<ActionsResult<TDocument>>\n\n/** @beta */\nexport function useApplyActions(\n resourceId?: ResourceId,\n): (\n action: DocumentAction | DocumentAction[],\n options?: ApplyActionsOptions,\n) => Promise<ActionsResult> {\n return _useApplyActions(resourceId)()\n}\n\nconst _useApplyActions = (resourceId?: ResourceId) => createCallbackHook(applyActions, resourceId)\n","import {\n type DocumentHandle,\n getDocumentState,\n getResourceId,\n type JsonMatch,\n type JsonMatchPath,\n resolveDocument,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @beta\n *\n * ## useDocument(doc, path)\n * Read and subscribe to nested values in a document\n * @category Documents\n * @param doc - The document to read state from. If you pass a `DocumentHandle` with a `resourceId` in the DocumentResourceId format (`document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @param path - The path to the nested value to read from\n * @returns The value at the specified path\n * @example\n * ```tsx\n * import {type DocumentHandle, useDocument} from '@sanity/sdk-react'\n *\n * function OrderLink({documentHandle}: {documentHandle: DocumentHandle}) {\n * const title = useDocument(documentHandle, 'title')\n * const id = useDocument(documentHandle, '_id')\n *\n * return (\n * <a href=`/order/${id}`>Order {title} today!</a>\n * )\n * }\n * ```\n *\n */\nexport function useDocument<\n TDocument extends SanityDocument,\n TPath extends JsonMatchPath<TDocument>,\n>(doc: DocumentHandle<TDocument>, path: TPath): JsonMatch<TDocument, TPath> | undefined\n\n/**\n * @beta\n * ## useDocument(doc)\n * Read and subscribe to an entire document\n * @param doc - The document to read state from\n * @returns The document state as an object\n * @example\n * ```tsx\n * import {type SanityDocument, type DocumentHandle, useDocument} from '@sanity/sdk-react'\n *\n * interface Book extends SanityDocument {\n * title: string\n * author: string\n * summary: string\n * }\n *\n * function DocumentView({documentHandle}: {documentHandle: DocumentHandle}) {\n * const book = useDocument<Book>(documentHandle)\n *\n * return (\n * <article>\n * <h1>{book?.title}</h1>\n * <address>By {book?.author}</address>\n *\n * <h2>Summary</h2>\n * {book?.summary}\n *\n * <h2>Order</h2>\n * <a href=`/order/${book._id}`>Order {book?.title} today!</a>\n * </article>\n * )\n * }\n * ```\n *\n */\nexport function useDocument<TDocument extends SanityDocument>(\n doc: DocumentHandle<TDocument>,\n): TDocument | null\n\n/**\n * @beta\n * Reads and subscribes to a document’s realtime state, incorporating both local and remote changes.\n * When called with a `path` argument, the hook will return the nested value’s state.\n * When called without a `path` argument, the entire document’s state will be returned.\n *\n * @remarks\n * `useDocument` is designed to be used within a realtime context in which local updates to documents\n * need to be displayed before they are persisted to the remote copy. This can be useful within a collaborative\n * or realtime editing interface where local changes need to be reflected immediately.\n *\n * However, this hook can be too resource intensive for applications where static document values simply\n * need to be displayed (or when changes to documents don’t need to be reflected immediately);\n * consider using `usePreview` or `useQuery` for these use cases instead. These hooks leverage the Sanity\n * Live Content API to provide a more efficient way to read and subscribe to document state.\n */\nexport function useDocument(doc: DocumentHandle, path?: string): unknown {\n return _useDocument(doc, path)\n}\n\nconst _useDocument = createStateSourceHook<[doc: DocumentHandle, path?: string], unknown>({\n getState: getDocumentState,\n shouldSuspend: (instance, doc) => getDocumentState(instance, doc._id).getCurrent() === undefined,\n suspender: resolveDocument,\n getResourceId: (doc) => getResourceId(doc.resourceId),\n})\n","import {\n type DocumentEvent,\n type DocumentHandle,\n getResourceId,\n subscribeDocumentEvents,\n} from '@sanity/sdk'\nimport {useCallback, useEffect, useInsertionEffect, useRef} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n *\n * @beta\n *\n * Subscribes an event handler to events in your application’s document store, such as document\n * creation, deletion, and updates.\n *\n * @category Documents\n * @param handler - The event handler to register.\n * @param doc - The document to subscribe to events for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @example\n * ```\n * import {useDocumentEvent} from '@sanity/sdk-react'\n * import {type DocumentEvent} from '@sanity/sdk'\n *\n * useDocumentEvent((event) => {\n * if (event.type === DocumentEvent.DocumentDeletedEvent) {\n * alert(`Document with ID ${event.documentId} deleted!`)\n * } else {\n * console.log(event)\n * }\n * })\n * ```\n */\nexport function useDocumentEvent(\n handler: (documentEvent: DocumentEvent) => void,\n doc: DocumentHandle,\n): void {\n const ref = useRef(handler)\n\n useInsertionEffect(() => {\n ref.current = handler\n })\n\n const stableHandler = useCallback((documentEvent: DocumentEvent) => {\n return ref.current(documentEvent)\n }, [])\n\n const instance = useSanityInstance(getResourceId(doc.resourceId))\n useEffect(() => {\n return subscribeDocumentEvents(instance, stableHandler)\n }, [instance, stableHandler])\n}\n","import {type DocumentHandle, getDocumentSyncStatus} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseDocumentSyncStatus = {\n /**\n * Exposes the document’s sync status between local and remote document states.\n *\n * @category Documents\n * @param doc - The document handle to get sync status for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @returns `true` if local changes are synced with remote, `false` if the changes are not synced, and `undefined` if the document is not found\n * @example Disable a Save button when there are no changes to sync\n * ```\n * const myDocumentHandle = { _id: 'documentId', _type: 'documentType', resourceId: 'document:projectId:dataset:documentId' }\n * const documentSynced = useDocumentSyncStatus(myDocumentHandle)\n *\n * return (\n * <button disabled={documentSynced}>\n * Save Changes\n * </button>\n * )\n * ```\n */\n (doc: DocumentHandle): boolean | undefined\n}\n\n/** @beta */\nexport const useDocumentSyncStatus: UseDocumentSyncStatus =\n createStateSourceHook(getDocumentSyncStatus)\n","import {\n type ActionsResult,\n type DocumentHandle,\n editDocument,\n getDocumentState,\n getResourceId,\n type JsonMatch,\n type JsonMatchPath,\n resolveDocument,\n} from '@sanity/sdk'\nimport {type SanityDocument} from '@sanity/types'\nimport {useCallback} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\nimport {useApplyActions} from './useApplyActions'\n\nconst ignoredKeys = ['_id', '_type', '_createdAt', '_updatedAt', '_rev']\n\ntype Updater<TValue> = TValue | ((nextValue: TValue) => TValue)\n\n/**\n *\n * @beta\n *\n * ## useEditDocument(doc, path)\n * Edit a nested value within a document\n *\n * @category Documents\n * @param doc - The document to be edited; either as a document handle or the document’s ID a string\n * @param path - The path to the nested value to be edited\n * @returns A function to update the nested value. Accepts either a new value, or an updater function that exposes the previous value and returns a new value.\n * @example Update a document’s name by providing the new value directly\n * ```\n * const handle = { _id: 'documentId', _type: 'documentType' }\n * const name = useDocument(handle, 'name')\n * const editName = useEditDocument(handle, 'name')\n *\n * function handleNameChange(event: React.ChangeEvent<HTMLInputElement>) {\n * editName(event.target.value)\n * }\n *\n * return (\n * <input type='text' value={name} onChange={handleNameChange} />\n * )\n * ```\n *\n * @example Update a count on a document by providing an updater function\n * ```\n * const handle = { _id: 'documentId', _type: 'documentType' }\n * const count = useDocument(handle, 'count')\n * const editCount = useEditDocument(handle, 'count')\n *\n * function incrementCount() {\n * editCount(previousCount => previousCount + 1)\n * }\n *\n * return (\n * <>\n * <button onClick={incrementCount}>\n * Increment\n * </button>\n * Current count: {count}\n * </>\n * )\n * ```\n */\nexport function useEditDocument<\n TDocument extends SanityDocument,\n TPath extends JsonMatchPath<TDocument>,\n>(\n doc: DocumentHandle<TDocument>,\n path: TPath,\n): (nextValue: Updater<JsonMatch<TDocument, TPath>>) => Promise<ActionsResult<TDocument>>\n\n/**\n *\n * @beta\n *\n * ## useEditDocument(doc)\n * Edit an entire document\n * @param doc - The document to be edited; either as a document handle or the document’s ID a string. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)\n * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.\n * @returns A function to update the document state. Accepts either a new document state, or an updater function that exposes the previous document state and returns the new document state.\n * @example\n * ```\n * const myDocumentHandle = { _id: 'documentId', _type: 'documentType' }\n *\n * const myDocument = useDocument(myDocumentHandle)\n * const { title, price } = myDocument\n *\n * const editMyDocument = useEditDocument(myDocumentHandle)\n *\n * function handleFieldChange(e: React.ChangeEvent<HTMLInputElement>) {\n * const {name, value} = e.currentTarget\n * // Use an updater function to update the document state based on the previous state\n * editMyDocument(previousDocument => ({\n * ...previousDocument,\n * [name]: value\n * }))\n * }\n *\n * function handleSaleChange(e: React.ChangeEvent<HTMLInputElement>) {\n * const { checked } = e.currentTarget\n * if (checked) {\n * // Use an updater function to add a new salePrice field;\n * // set it at a 20% discount off the normal price\n * editMyDocument(previousDocument => ({\n * ...previousDocument,\n * salePrice: previousDocument.price * 0.8,\n * }))\n * } else {\n * // Get the document state without the salePrice field\n * const { salePrice, ...rest } = myDocument\n * // Update the document state to remove the salePrice field\n * editMyDocument(rest)\n * }\n * }\n *\n * return (\n * <>\n * <form onSubmit={e => e.preventDefault()}>\n * <input name='title' type='text' value={title} onChange={handleFieldChange} />\n * <input name='price' type='number' value={price} onChange={handleFieldChange} />\n * <input\n * name='salePrice'\n * type='checkbox'\n * checked={Object(myDocument).hasOwnProperty('salePrice')}\n * onChange={handleSaleChange}\n * />\n * </form>\n * <pre><code>\n * {JSON.stringify(myDocument, null, 2)}\n * </code></pre>\n * </>\n * )\n * ```\n */\nexport function useEditDocument<TDocument extends SanityDocument>(\n doc: DocumentHandle<TDocument>,\n): (nextValue: Updater<TDocument>) => Promise<ActionsResult<TDocument>>\n\n/**\n *\n * @beta\n *\n * Enables editing of a document’s state.\n * When called with a `path` argument, the hook will return a function for updating a nested value.\n * When called without a `path` argument, the hook will return a function for updating the entire document.\n */\nexport function useEditDocument(\n doc: DocumentHandle,\n path?: string,\n): (updater: Updater<unknown>) => Promise<ActionsResult> {\n const resourceId = getResourceId(doc.resourceId)!\n const documentId = doc._id\n const instance = useSanityInstance(resourceId)\n const apply = useApplyActions(resourceId)\n const isDocumentReady = useCallback(\n () => getDocumentState(instance, documentId).getCurrent() !== undefined,\n [instance, documentId],\n )\n if (!isDocumentReady()) throw resolveDocument(instance, documentId)\n\n return (updater: Updater<unknown>) => {\n if (path) {\n const nextValue =\n typeof updater === 'function'\n ? updater(getDocumentState(instance, documentId, path).getCurrent())\n : updater\n\n return apply(editDocument(doc, {set: {[path]: nextValue}}))\n }\n\n const current = getDocumentState(instance, documentId).getCurrent()\n const nextValue = typeof updater === 'function' ? updater(current) : updater\n\n if (typeof nextValue !== 'object' || !nextValue) {\n throw new Error(\n `No path was provided to \\`useEditDocument\\` and the value provided was not a document object.`,\n )\n }\n\n const allKeys = Object.keys({...current, ...nextValue})\n const editActions = allKeys\n .filter((key) => !ignoredKeys.includes(key))\n .filter((key) => current?.[key] !== nextValue[key])\n .map((key) =>\n key in nextValue\n ? editDocument(doc, {set: {[key]: nextValue[key]}})\n : editDocument(doc, {unset: [key]}),\n )\n\n return apply(editActions)\n }\n}\n","import {\n type DocumentAction,\n getPermissionsState,\n getResourceId,\n type PermissionsResult,\n} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {filter, firstValueFrom} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n *\n * @beta\n *\n * Check if the current user has the specified permissions for the given document actions.\n *\n * @category Permissions\n * @param actions - One more more calls to a particular document action function for a given document\n * @returns An object that specifies whether the action is allowed; if the action is not allowed, an explanatory message and list of reasons is also provided.\n *\n * @example Checking for permission to publish a document\n * ```ts\n * import {usePermissions, useApplyActions} from '@sanity/sdk-react'\n * import {publishDocument} from '@sanity/sdk'\n *\n * export function PublishButton({doc}: {doc: DocumentHandle}) {\n * const canPublish = usePermissions(publishDocument(doc))\n * const applyAction = useApplyActions()\n *\n * return (\n * <>\n * <button\n * disabled={!canPublish.allowed}\n * onClick={() => applyAction(publishDocument(doc))}\n * popoverTarget={`${canPublish.allowed ? undefined : 'publishButtonPopover'}`}\n * >\n * Publish\n * </button>\n * {!canPublish.allowed && (\n * <div popover id=\"publishButtonPopover\">\n * {canPublish.message}\n * </div>\n * )}\n * </>\n * )\n * }\n * ```\n */\nexport function usePermissions(actions: DocumentAction | DocumentAction[]): PermissionsResult {\n // if actions is an array, we need to check each action to see if the resourceId is the same\n if (Array.isArray(actions)) {\n const resourceIds = actions.map((action) => action.resourceId)\n const uniqueResourceIds = new Set(resourceIds)\n if (uniqueResourceIds.size !== 1) {\n throw new Error('All actions must have the same resourceId')\n }\n }\n const resourceId = Array.isArray(actions)\n ? getResourceId(actions[0].resourceId)\n : getResourceId(actions.resourceId)\n\n const instance = useSanityInstance(resourceId)\n const isDocumentReady = useCallback(\n () => getPermissionsState(instance, actions).getCurrent() !== undefined,\n [actions, instance],\n )\n if (!isDocumentReady()) {\n throw firstValueFrom(\n getPermissionsState(instance, actions).observable.pipe(\n filter((result) => result !== undefined),\n ),\n )\n }\n\n const {subscribe, getCurrent} = useMemo(\n () => getPermissionsState(instance, actions),\n [actions, instance],\n )\n\n return useSyncExternalStore(subscribe, getCurrent) as PermissionsResult\n}\n","import {\n getQueryKey,\n getQueryState,\n parseQueryKey,\n type QueryOptions,\n resolveQuery,\n} from '@sanity/sdk'\nimport {useEffect, useMemo, useState, useSyncExternalStore, useTransition} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * Executes GROQ queries against a Sanity dataset.\n *\n * This hook provides a convenient way to fetch and subscribe to real-time updates\n * for your Sanity content. Changes made to the dataset’s content will trigger\n * automatic updates.\n *\n * @remarks\n * The returned `isPending` flag indicates when a React transition is in progress,\n * which can be used to show loading states for query changes.\n *\n * @beta\n * @category GROQ\n * @param query - GROQ query string to execute\n * @param options - Optional configuration for the query\n * @returns Object containing the query result and a pending state flag\n *\n * @example Basic usage\n * ```tsx\n * const {data, isPending} = useQuery<Movie[]>('*[_type == \"movie\"]')\n * ```\n *\n * @example Using parameters\n * ```tsx\n * // With parameters\n * const {data} = useQuery<Movie>('*[_type == \"movie\" && _id == $id][0]', {\n * params: { id: 'movie-123' }\n * })\n * ```\n *\n * @example With a loading state for transitions\n * ```tsx\n * const {data, isPending} = useQuery<Movie[]>('*[_type == \"movie\"]')\n * return (\n * <div>\n * {isPending && <div>Updating...</div>}\n * <ul>\n * {data.map(movie => <li key={movie._id}>{movie.title}</li>)}\n * </ul>\n * </div>\n * )\n * ```\n *\n */\nexport function useQuery<T>(query: string, options?: QueryOptions): {data: T; isPending: boolean} {\n const instance = useSanityInstance(options?.resourceId)\n // Use React's useTransition to avoid UI jank when queries change\n const [isPending, startTransition] = useTransition()\n\n // Get the unique key for this query and its options\n const queryKey = getQueryKey(query, options)\n // Use a deferred state to avoid immediate re-renders when the query changes\n const [deferredQueryKey, setDeferredQueryKey] = useState(queryKey)\n // Parse the deferred query key back into a query and options\n const deferred = useMemo(() => parseQueryKey(deferredQueryKey), [deferredQueryKey])\n\n // Create an AbortController to cancel in-flight requests when needed\n const [ref, setRef] = useState<AbortController>(new AbortController())\n\n // When the query or options change, start a transition to update the query\n useEffect(() => {\n if (queryKey === deferredQueryKey) return\n\n startTransition(() => {\n // Abort any in-flight requests for the previous query\n if (ref && !ref.signal.aborted) {\n ref.abort()\n setRef(new AbortController())\n }\n\n setDeferredQueryKey(queryKey)\n })\n }, [deferredQueryKey, queryKey, ref])\n\n // Get the state source for this query from the query store\n const {getCurrent, subscribe} = useMemo(\n () => getQueryState(instance, deferred.query, deferred.options),\n [instance, deferred],\n )\n\n // If data isn't available yet, suspend rendering until it is\n // This is the React Suspense integration - throwing a promise\n // will cause React to show the nearest Suspense fallback\n if (getCurrent() === undefined) {\n throw resolveQuery(instance, deferred.query, {...deferred.options, signal: ref.signal})\n }\n\n // Subscribe to updates and get the current data\n // useSyncExternalStore ensures the component re-renders when the data changes\n const data = useSyncExternalStore(subscribe, getCurrent) as T\n return {data, isPending}\n}\n","import {type DocumentHandle, type QueryOptions} from '@sanity/sdk'\nimport {type SortOrderingItem} from '@sanity/types'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useQuery} from '../query/useQuery'\n\nconst DEFAULT_BATCH_SIZE = 25\nconst DEFAULT_PERSPECTIVE = 'drafts'\n\n/**\n * Result structure returned from the infinite list query\n * @internal\n */\ninterface InfiniteListQueryResult {\n count: number\n data: DocumentHandle[]\n}\n\n/**\n * Configuration options for the useInfiniteList hook\n *\n * @beta\n * @category Types\n */\nexport interface InfiniteListOptions extends QueryOptions {\n /**\n * GROQ filter expression to apply to the query\n */\n filter?: string\n /**\n * Number of items to load per batch (defaults to 25)\n */\n batchSize?: number\n /**\n * Sorting configuration for the results\n */\n orderings?: SortOrderingItem[]\n /**\n * Text search query to filter results\n */\n search?: string\n}\n\n/**\n * Return value from the useInfiniteList hook\n *\n * @beta\n * @category Types\n */\nexport interface InfiniteList {\n /**\n * Array of document handles for the current batch\n */\n data: DocumentHandle[]\n /**\n * Whether there are more items available to load\n */\n hasMore: boolean\n /**\n * Total count of items matching the query\n */\n count: number\n /**\n * Whether a query is currently in progress\n */\n isPending: boolean\n /**\n * Function to load the next batch of results\n */\n loadMore: () => void\n}\n\n/**\n * Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,\n * with infinite scrolling support. The number of document handles returned per batch is customizable,\n * and additional batches can be loaded using the supplied `loadMore` function.\n *\n * @beta\n * @category Documents\n * @param options - Configuration options for the infinite list\n * @returns An object containing the list of document handles, the loading state, the total count of retrived document handles, and a function to load more\n * @example\n * ```tsx\n * const {data, hasMore, isPending, loadMore} = useInfiniteList({\n * filter: '_type == \"post\"',\n * search: searchTerm,\n * batchSize: 10,\n * orderings: [{field: '_createdAt', direction: 'desc'}]\n * })\n *\n * return (\n * <div>\n * Total documents: {count}\n * <ol>\n * {data.map((doc) => (\n * <li key={doc._id}>\n * <MyDocumentComponent doc={doc} />\n * </li>\n * ))}\n * </ol>\n * {hasMore && <button onClick={loadMore}>Load More</button>}\n * </div>\n * )\n * ```\n *\n */\nexport function useInfiniteList({\n batchSize = DEFAULT_BATCH_SIZE,\n params,\n search,\n filter,\n orderings,\n ...options\n}: InfiniteListOptions): InfiniteList {\n const perspective = options.perspective ?? DEFAULT_PERSPECTIVE\n const [limit, setLimit] = useState(batchSize)\n\n // Reset the limit to the current batchSize whenever any query parameters\n // (filter, search, params, orderings) or batchSize changes\n const key = JSON.stringify({filter, search, params, orderings, batchSize})\n useEffect(() => {\n setLimit(batchSize)\n }, [key, batchSize])\n\n const filterClause = useMemo(() => {\n const conditions: string[] = []\n\n // Add search query if specified\n if (search?.trim()) {\n conditions.push(`[@] match text::query(\"${search.trim()}\")`)\n }\n\n // Add additional filter if specified\n if (filter) {\n conditions.push(`(${filter})`)\n }\n\n return conditions.length ? `[${conditions.join(' && ')}]` : ''\n }, [filter, search])\n\n const orderClause = orderings\n ? `| order(${orderings\n .map((ordering) =>\n [ordering.field, ordering.direction.toLowerCase()]\n .map((str) => str.trim())\n .filter(Boolean)\n .join(' '),\n )\n .join(',')})`\n : ''\n\n const dataQuery = `*${filterClause}${orderClause}[0...${limit}]{_id,_type}`\n const countQuery = `count(*${filterClause})`\n\n const {\n data: {count, data},\n isPending,\n } = useQuery<InfiniteListQueryResult>(`{\"count\":${countQuery},\"data\":${dataQuery}}`, {\n ...options,\n params,\n perspective,\n })\n\n const hasMore = data.length < count\n\n const loadMore = useCallback(() => {\n setLimit((prev) => Math.min(prev + batchSize, count))\n }, [count, batchSize])\n\n return useMemo(\n () => ({data, hasMore, count, isPending, loadMore}),\n [data, hasMore, count, isPending, loadMore],\n )\n}\n","import {type DocumentHandle, type QueryOptions} from '@sanity/sdk'\nimport {type SortOrderingItem} from '@sanity/types'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\n\nimport {useQuery} from '../query/useQuery'\n\nconst DEFAULT_PERSPECTIVE = 'drafts'\n\n/**\n * Configuration options for the usePaginatedList hook\n *\n * @beta\n * @category Types\n */\nexport interface PaginatedListOptions extends QueryOptions {\n /**\n * GROQ filter expression to apply to the query\n */\n filter?: string\n /**\n * Number of items to display per page (defaults to 25)\n */\n pageSize?: number\n /**\n * Sorting configuration for the results\n */\n orderings?: SortOrderingItem[]\n /**\n * Text search query to filter results\n */\n search?: string\n}\n\n/**\n * Return value from the usePaginatedList hook\n *\n * @beta\n * @category Types\n */\nexport interface PaginatedList {\n /**\n * Array of document handles for the current page\n */\n data: DocumentHandle[]\n /**\n * Whether a query is currently in progress\n */\n isPending: boolean\n\n /**\n * Number of items displayed per page\n */\n pageSize: number\n /**\n * Current page number (1-indexed)\n */\n currentPage: number\n /**\n * Total number of pages available\n */\n totalPages: number\n\n /**\n * Starting index of the current page (0-indexed)\n */\n startIndex: number\n /**\n * Ending index of the current page (exclusive, 0-indexed)\n */\n endIndex: number\n /**\n * Total count of items matching the query\n */\n count: number\n\n /**\n * Navigate to the first page\n */\n firstPage: () => void\n /**\n * Whether there is a first page available to navigate to\n */\n hasFirstPage: boolean\n\n /**\n * Navigate to the previous page\n */\n previousPage: () => void\n /**\n * Whether there is a previous page available to navigate to\n */\n hasPreviousPage: boolean\n\n /**\n * Navigate to the next page\n */\n nextPage: () => void\n /**\n * Whether there is a next page available to navigate to\n */\n hasNextPage: boolean\n\n /**\n * Navigate to the last page\n */\n lastPage: () => void\n /**\n * Whether there is a last page available to navigate to\n */\n hasLastPage: boolean\n\n /**\n * Navigate to a specific page number\n * @param pageNumber - The page number to navigate to (1-indexed)\n */\n goToPage: (pageNumber: number) => void\n}\n\n/**\n * Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,\n * with support for traditional paginated interfaces. The number of document handles returned per page is customizable,\n * while page navigation is handled via the included navigation functions.\n *\n * @beta\n * @category Documents\n * @param options - Configuration options for the paginated list\n * @returns An object containing the current page of document handles, the loading and pagination state, and navigation functions\n * @example\n * ```tsx\n * const {\n * data,\n * isPending,\n * currentPage,\n * totalPages,\n * nextPage,\n * previousPage,\n * hasNextPage,\n * hasPreviousPage\n * } = usePaginatedList({\n * filter: '_type == \"post\"',\n * search: searchTerm,\n * pageSize: 10,\n * orderings: [{field: '_createdAt', direction: 'desc'}]\n * })\n *\n * return (\n * <>\n * <table>\n * {data.map(doc => (\n * <MyTableRowComponent key={doc._id} doc={doc} />\n * ))}\n * </table>\n * <>\n * {hasPreviousPage && <button onClick={previousPage}>Previous</button>}\n * {currentPage} / {totalPages}\n * {hasNextPage && <button onClick={nextPage}>Next</button>}\n * </>\n * </>\n * )\n * ```\n *\n */\nexport function usePaginatedList({\n filter = '',\n pageSize = 25,\n params = {},\n orderings,\n search,\n ...options\n}: PaginatedListOptions = {}): PaginatedList {\n const [pageIndex, setPageIndex] = useState(0)\n const key = JSON.stringify({filter, search, params, orderings, pageSize})\n // Reset the pageIndex to 0 whenever any query parameters (filter, search,\n // params, orderings) or pageSize changes\n useEffect(() => {\n setPageIndex(0)\n }, [key])\n\n const startIndex = pageIndex * pageSize\n const endIndex = (pageIndex + 1) * pageSize\n const perspective = options.perspective ?? DEFAULT_PERSPECTIVE\n\n const filterClause = useMemo(() => {\n const conditions: string[] = []\n\n // Add search query if specified\n if (search?.trim()) {\n conditions.push(`[@] match text::query(\"${search.trim()}\")`)\n }\n\n // Add additional filter if specified\n if (filter) {\n conditions.push(`(${filter})`)\n }\n\n return conditions.length ? `[${conditions.join(' && ')}]` : ''\n }, [filter, search])\n\n const orderClause = orderings\n ? `| order(${orderings\n .map((ordering) =>\n [ordering.field, ordering.direction.toLowerCase()]\n .map((str) => str.trim())\n .filter(Boolean)\n .join(' '),\n )\n .join(',')})`\n : ''\n\n const dataQuery = `*${filterClause}${orderClause}[${startIndex}...${endIndex}]{_id,_type}`\n const countQuery = `count(*${filterClause})`\n\n const {\n data: {data, count},\n isPending,\n } = useQuery<{data: DocumentHandle[]; count: number}>(\n `{\"data\":${dataQuery},\"count\":${countQuery}}`,\n {\n ...options,\n perspective,\n params,\n },\n )\n\n const totalPages = Math.ceil(count / pageSize)\n const currentPage = pageIndex + 1\n\n // Navigation methods\n const firstPage = useCallback(() => setPageIndex(0), [])\n const previousPage = useCallback(() => setPageIndex((prev) => Math.max(prev - 1, 0)), [])\n const nextPage = useCallback(\n () => setPageIndex((prev) => Math.min(prev + 1, totalPages - 1)),\n [totalPages],\n )\n const lastPage = useCallback(() => setPageIndex(totalPages - 1), [totalPages])\n const goToPage = useCallback(\n (pageNumber: number) => {\n if (pageNumber < 1 || pageNumber > totalPages) return\n setPageIndex(pageNumber - 1)\n },\n [totalPages],\n )\n\n // Boolean flags for page availability\n const hasFirstPage = pageIndex > 0\n const hasPreviousPage = pageIndex > 0\n const hasNextPage = pageIndex < totalPages - 1\n const hasLastPage = pageIndex < totalPages - 1\n\n return useMemo(\n () => ({\n data,\n isPending,\n pageSize,\n currentPage,\n totalPages,\n startIndex,\n endIndex,\n count,\n firstPage,\n hasFirstPage,\n previousPage,\n hasPreviousPage,\n nextPage,\n hasNextPage,\n lastPage,\n hasLastPage,\n goToPage,\n }),\n [\n data,\n isPending,\n pageSize,\n currentPage,\n totalPages,\n startIndex,\n endIndex,\n count,\n firstPage,\n hasFirstPage,\n previousPage,\n hasPreviousPage,\n nextPage,\n hasNextPage,\n lastPage,\n hasLastPage,\n goToPage,\n ],\n )\n}\n","import {type DocumentHandle, getPreviewState, type PreviewValue, resolvePreview} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {distinctUntilChanged, EMPTY, Observable, startWith, switchMap} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @beta\n * @category Types\n */\nexport interface UsePreviewOptions {\n document: DocumentHandle\n ref?: React.RefObject<unknown>\n}\n\n/**\n * @beta\n * @category Types\n */\nexport interface UsePreviewResults {\n /** The results of resolving the document’s preview values */\n results: PreviewValue\n /** True when preview values are being refreshed */\n isPending: boolean\n}\n\n/**\n * @beta\n *\n * Returns the preview values of a document (specified via a `DocumentHandle`),\n * including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.\n * To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview\n * resolution will only occur if the `ref` is intersecting the current viewport.\n *\n * @category Documents\n * @param options - The document handle for the document you want to resolve preview values for, and an optional ref\n * @returns The preview values for the given document and a boolean to indicate whether the resolution is pending\n *\n * @example Combining with useDocuments to render a collection of document previews\n * ```\n * // PreviewComponent.jsx\n * export default function PreviewComponent({ document }) {\n * const { results: { title, subtitle, media }, isPending } = usePreview({ document })\n * return (\n * <article style={{ opacity: isPending ? 0.5 : 1}}>\n * {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}\n * <h2>{title}</h2>\n * <p>{subtitle}</p>\n * </article>\n * )\n * }\n *\n * // DocumentList.jsx\n * const { results, isPending } = useDocuments({ filter: '_type == \"movie\"' })\n * return (\n * <div>\n * <h1>Movies</h1>\n * <ul>\n * {isPending ? 'Loading…' : results.map(movie => (\n * <li key={movie._id}>\n * <Suspense fallback='Loading…'>\n * <PreviewComponent document={movie} />\n * </Suspense>\n * </li>\n * ))}\n * </ul>\n * </div>\n * )\n * ```\n */\nexport function usePreview({document: {_id, _type}, ref}: UsePreviewOptions): UsePreviewResults {\n const instance = useSanityInstance()\n\n const stateSource = useMemo(\n () => getPreviewState(instance, {document: {_id, _type}}),\n [instance, _id, _type],\n )\n\n // Create subscribe function for useSyncExternalStore\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n const subscription = new Observable<boolean>((observer) => {\n // for environments that don't have an intersection observer\n if (typeof IntersectionObserver === 'undefined' || typeof HTMLElement === 'undefined') {\n return\n }\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => observer.next(entry.isIntersecting),\n {rootMargin: '0px', threshold: 0},\n )\n if (ref?.current && ref.current instanceof HTMLElement) {\n intersectionObserver.observe(ref.current)\n }\n return () => intersectionObserver.disconnect()\n })\n .pipe(\n startWith(false),\n distinctUntilChanged(),\n switchMap((isVisible) =>\n isVisible\n ? new Observable<void>((obs) => {\n return stateSource.subscribe(() => obs.next())\n })\n : EMPTY,\n ),\n )\n .subscribe({next: onStoreChanged})\n\n return () => subscription.unsubscribe()\n },\n [stateSource, ref],\n )\n\n // Create getSnapshot function to return current state\n const getSnapshot = useCallback(() => {\n const currentState = stateSource.getCurrent()\n if (currentState.results === null) throw resolvePreview(instance, {document: {_id, _type}})\n return currentState as UsePreviewResults\n }, [_id, _type, instance, stateSource])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n","import {\n type DocumentHandle,\n getProjectionState,\n resolveProjection,\n type ValidProjection,\n} from '@sanity/sdk'\nimport {useCallback, useMemo, useSyncExternalStore} from 'react'\nimport {distinctUntilChanged, EMPTY, Observable, startWith, switchMap} from 'rxjs'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\ninterface UseProjectionOptions {\n document: DocumentHandle\n projection: ValidProjection\n ref?: React.RefObject<unknown>\n}\n\ninterface UseProjectionResults<TResult extends object> {\n results: TResult\n isPending: boolean\n}\n\n/**\n * @beta\n *\n * Returns the projection values of a document (specified via a `DocumentHandle`),\n * based on the provided projection string. These values are live and will update in realtime.\n * To reduce unnecessary network requests for resolving the projection values, an optional `ref` can be passed to the hook so that projection\n * resolution will only occur if the `ref` is intersecting the current viewport.\n *\n * @category Documents\n * @param options - The document handle for the document you want to project values from, the projection string, and an optional ref\n * @returns The projection values for the given document and a boolean to indicate whether the resolution is pending\n *\n * @example Using a projection to display specific document fields\n * ```\n * // ProjectionComponent.jsx\n * export default function ProjectionComponent({ document }) {\n * const ref = useRef(null)\n * const { results: { title, description, authors }, isPending } = useProjection({\n * document,\n * projection: '{title, \"description\": pt::text(\"description\"), \"authors\": array::join(authors[]->name, \", \")}',\n * ref\n * })\n *\n * return (\n * <article ref={ref} style={{ opacity: isPending ? 0.5 : 1}}>\n * <h2>{title}</h2>\n * <p>{description}</p>\n * <p>{authors}</p>\n * </article>\n * )\n * }\n * ```\n *\n * @example Combining with useInfiniteList to render a collection with specific fields\n * ```\n * // DocumentList.jsx\n * const { data } = useInfiniteList({ filter: '_type == \"article\"' })\n * return (\n * <div>\n * <h1>Articles</h1>\n * <ul>\n * {data.map(article => (\n * <li key={article._id}>\n * <Suspense fallback='Loading…'>\n * <ProjectionComponent\n * document={article}\n * />\n * </Suspense>\n * </li>\n * ))}\n * </ul>\n * </div>\n * )\n * ```\n */\nexport function useProjection<TResult extends object>({\n document: {_id, _type},\n projection,\n ref,\n}: UseProjectionOptions): UseProjectionResults<TResult> {\n const instance = useSanityInstance()\n\n const stateSource = useMemo(\n () => getProjectionState<TResult>(instance, {document: {_id, _type}, projection}),\n [instance, _id, _type, projection],\n )\n\n // Create subscribe function for useSyncExternalStore\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n const subscription = new Observable<boolean>((observer) => {\n // for environments that don't have an intersection observer\n if (typeof IntersectionObserver === 'undefined' || typeof HTMLElement === 'undefined') {\n return\n }\n\n const intersectionObserver = new IntersectionObserver(\n ([entry]) => observer.next(entry.isIntersecting),\n {rootMargin: '0px', threshold: 0},\n )\n if (ref?.current && ref.current instanceof HTMLElement) {\n intersectionObserver.observe(ref.current)\n }\n return () => intersectionObserver.disconnect()\n })\n .pipe(\n startWith(false),\n distinctUntilChanged(),\n switchMap((isVisible) =>\n isVisible\n ? new Observable<void>((obs) => {\n return stateSource.subscribe(() => obs.next())\n })\n : EMPTY,\n ),\n )\n .subscribe({next: onStoreChanged})\n\n return () => subscription.unsubscribe()\n },\n [stateSource, ref],\n )\n\n // Create getSnapshot function to return current state\n const getSnapshot = useCallback(() => {\n const currentState = stateSource.getCurrent()\n if (currentState.results === null)\n throw resolveProjection(instance, {document: {_id, _type}, projection})\n return currentState as UseProjectionResults<TResult>\n }, [_id, _type, projection, instance, stateSource])\n\n return useSyncExternalStore(subscribe, getSnapshot)\n}\n","import {\n getProjectState,\n resolveProject,\n type SanityInstance,\n type SanityProject,\n type StateSource,\n} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\ntype UseProject = {\n /**\n *\n * Returns metadata for a given project\n *\n * @category Projects\n * @param projectId - The ID of the project to retrieve metadata for\n * @returns The metadata for the project\n * @example\n * ```tsx\n * function ProjectMetadata({ projectId }: { projectId: string }) {\n * const project = useProject(projectId)\n *\n * return (\n * <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>\n * <h1>{project.displayName}</h1>\n * </figure>\n * )\n * }\n * ```\n */\n (projectId: string): SanityProject\n}\n\n/** @public */\nexport const useProject: UseProject = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getProjectState as (\n instance: SanityInstance,\n projectId: string,\n ) => StateSource<SanityProject>,\n shouldSuspend: (instance, projectId) =>\n getProjectState(instance, projectId).getCurrent() === undefined,\n suspender: resolveProject,\n})\n","import {type SanityProject} from '@sanity/client'\nimport {getProjectsState, resolveProjects, type SanityInstance, type StateSource} from '@sanity/sdk'\n\nimport {createStateSourceHook} from '../helpers/createStateSourceHook'\n\n/**\n * @public\n * @category Types\n */\nexport type ProjectWithoutMembers = Omit<SanityProject, 'members'>\n\ntype UseProjects = {\n /**\n *\n * Returns metadata for each project in your organization.\n *\n * @category Projects\n * @returns An array of metadata (minus the projects’ members) for each project in your organization\n * @example\n * ```tsx\n * const projects = useProjects()\n *\n * return (\n * <select>\n * {projects.map((project) => (\n * <option key={project.id}>{project.displayName}</option>\n * ))}\n * </select>\n * )\n * ```\n */\n (): ProjectWithoutMembers[]\n}\n\n/** @public */\nexport const useProjects: UseProjects = createStateSourceHook({\n // remove `undefined` since we're suspending when that is the case\n getState: getProjectsState as (instance: SanityInstance) => StateSource<ProjectWithoutMembers[]>,\n shouldSuspend: (instance) => getProjectsState(instance).getCurrent() === undefined,\n suspender: resolveProjects,\n})\n","import {createUsersStore, type ResourceType, type SanityUser} from '@sanity/sdk'\nimport {useCallback, useEffect, useState, useSyncExternalStore} from 'react'\n\nimport {useSanityInstance} from '../context/useSanityInstance'\n\n/**\n * @public\n * @category Types\n */\nexport interface UseUsersParams {\n /**\n * The type of resource to fetch users for.\n */\n resourceType: ResourceType\n /**\n * The ID of the resource to fetch users for.\n */\n resourceId: string\n /**\n * The limit of users to fetch.\n */\n limit?: number\n}\n\n/**\n * @public\n * @category Types\n */\nexport interface UseUsersResult {\n /**\n * The users fetched.\n */\n users: SanityUser[]\n /**\n * Whether there are more users to fetch.\n */\n hasMore: boolean\n /**\n * Load more users.\n */\n loadMore: () => void\n}\n\n/**\n *\n * @public\n *\n * Retrieves the users for a given resource (either a project or an organization).\n *\n * @category Users\n * @param params - The resource type and its ID, and the limit of users to fetch\n * @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users\n *\n * @example\n * ```\n * const { users, hasMore, loadMore } = useUsers({\n * resourceType: 'organization',\n * resourceId: 'my-org-id',\n * limit: 10,\n * })\n *\n * return (\n * <div>\n * {users.map(user => (\n * <figure key={user.sanityUserId}>\n * <img src={user.profile.imageUrl} alt='' />\n * <figcaption>{user.profile.displayName}</figcaption>\n * <address>{user.profile.email}</address>\n * </figure>\n * ))}\n * {hasMore && <button onClick={loadMore}>Load More</button>}\n * </div>\n * )\n * ```\n */\nexport function useUsers(params: UseUsersParams): UseUsersResult {\n const instance = useSanityInstance(params.resourceId)\n const [store] = useState(() => createUsersStore(instance))\n\n useEffect(() => {\n store.setOptions({\n resourceType: params.resourceType,\n resourceId: params.resourceId,\n })\n }, [params.resourceType, params.resourceId, store])\n\n const subscribe = useCallback(\n (onStoreChanged: () => void) => {\n if (store.getState().getCurrent().initialFetchCompleted === false) {\n store.resolveUsers()\n }\n const unsubscribe = store.getState().subscribe(onStoreChanged)\n\n return () => {\n unsubscribe()\n store.dispose()\n }\n },\n [store],\n )\n\n const getSnapshot = useCallback(() => store.getState().getCurrent(), [store])\n\n const {users, hasMore} = useSyncExternalStore(subscribe, getSnapshot) || {}\n\n return {users, hasMore, loadMore: store.loadMore}\n}\n"],"names":["useAuthToken","createStateSourceHook","getTokenState","useCurrentUser","getCurrentUserState","useClient","getState","getClientState","getResourceId","e","resourceId","useFrameConnection","options","$","_c","onMessage","targetOrigin","name","connectTo","heartbeat","instance","useSanityInstance","status","setStatus","useState","t0","t1","getOrCreateController","controller","t2","t3","getOrCreateChannel","channel","t4","t5","onStatus","event","useEffect","t6","t7","unsubscribers","Object","entries","forEach","t8","type","handler","unsubscribe_0","on","push","unsubscribe","_temp","frameWindow","removeTarget","addTarget","connect","t9","type_0","data","post","sendMessage","t10","t11","releaseChannel","t12","unsub","useWindowConnection","getOrCreateNode","node","newStatus","releaseNode","useManageFavorite","_id","_type","isFavorited","setIsFavorited","Symbol","for","SDK_NODE_NAME","SDK_CHANNEL_NAME","action","setFavoriteState","message","eventType","documentId","documentType","err","error","Error","handleFavoriteAction","favorite","unfavorite","isConnected","useRecordDocumentHistoryEvent","recordEvent","useDatasets","getDatasetsState","shouldSuspend","getCurrent","undefined","suspender","resolveDatasets","useApplyActions","_useApplyActions","createCallbackHook","applyActions","useDocument","doc","path","_useDocument","getDocumentState","resolveDocument","useDocumentEvent","ref","useRef","current","useInsertionEffect","documentEvent","stableHandler","subscribeDocumentEvents","useDocumentSyncStatus","getDocumentSyncStatus","ignoredKeys","useEditDocument","apply","updater","nextValue","editDocument","set","nextValue_0","editActions","keys","filter","key_0","key","map","key_1","unset","includes","usePermissions","actions","Array","isArray","resourceIds","Set","size","getPermissionsState","firstValueFrom","observable","pipe","_temp2","subscribe","useSyncExternalStore","result","useQuery","query","isPending","startTransition","useTransition","queryKey","getQueryKey","deferredQueryKey","setDeferredQueryKey","deferred","useMemo","parseQueryKey","setRef","AbortController","signal","aborted","abort","getQueryState","resolveQuery","DEFAULT_BATCH_SIZE","DEFAULT_PERSPECTIVE","useInfiniteList","orderings","params","search","batchSize","perspective","limit","setLimit","JSON","stringify","conditions","trim","length","join","filterClause","orderClause","dataQuery","countQuery","count","hasMore","prev","Math","min","loadMore","ordering","field","direction","toLowerCase","Boolean","str","usePaginatedList","pageSize","pageIndex","setPageIndex","startIndex","endIndex","totalPages","ceil","currentPage","firstPage","t13","_temp3","previousPage","t14","prev_0","nextPage","t15","lastPage","t16","pageNumber","goToPage","hasFirstPage","hasPreviousPage","hasNextPage","hasLastPage","t17","t18","max","usePreview","document","getPreviewState","stateSource","onStoreChanged","subscription","Observable","observer","IntersectionObserver","HTMLElement","intersectionObserver","entry","next","isIntersecting","rootMargin","threshold","observe","disconnect","startWith","distinctUntilChanged","switchMap","isVisible","obs","EMPTY","currentState","results","resolvePreview","useProjection","projection","getProjectionState","resolveProjection","useProject","getProjectState","projectId","resolveProject","useProjects","getProjectsState","resolveProjects","useUsers","createUsersStore","store","resourceType","setOptions","initialFetchCompleted","resolveUsers","dispose","getSnapshot","users"],"mappings":";;;;;;;AASaA,MAAAA,eAAeC,sBAAsBC,aAAa,GCuBlDC,iBAAiCF,sBAAsBG,mBAAmB,GCF1EC,YAAYJ,sBAAsB;AAAA,EAC7CK,UAAUC;AAAAA,EACVC,eAAgBC,OAAMA,EAAEC;AAC1B,CAAC;ACeM,SAAAC,mBAAAC,SAAA;AAAAC,QAAAA,IAAAC,EAAA,EAAA,GAIL;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAA8DP,SAC9DQ,WAAiBC,kBAAkB,GACnC,CAAAC,QAAAC,SAAA,IAA4BC,SAAiB,MAAM;AAAC,MAAAC,IAAAC;AAAAb,IAAAO,CAAAA,MAAAA,YAAAP,SAAAG,gBAG5CU,KAA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
|
5
5
|
"description": "Sanity SDK React toolkit for Content OS",
|
|
6
6
|
"keywords": [
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
"prettier": "@sanity/prettier-config",
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@sanity/logos": "^2.1.13",
|
|
71
|
+
"@sanity/message-protocol": "^0.1.0",
|
|
71
72
|
"@sanity/types": "^3.78.1",
|
|
72
|
-
"react-compiler-runtime": "19.0.0-beta-bafa41b-20250307",
|
|
73
73
|
"react-error-boundary": "^4.1.2",
|
|
74
74
|
"rxjs": "^7.8.1",
|
|
75
|
-
"@sanity/sdk": "0.0.0-alpha.
|
|
75
|
+
"@sanity/sdk": "0.0.0-alpha.17"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@sanity/browserslist-config": "^1.0.5",
|
package/src/_exports/hooks.ts
CHANGED
|
@@ -11,6 +11,8 @@ export {
|
|
|
11
11
|
useFrameConnection,
|
|
12
12
|
type UseFrameConnectionOptions,
|
|
13
13
|
} from '../hooks/comlink/useFrameConnection'
|
|
14
|
+
export {useManageFavorite} from '../hooks/comlink/useManageFavorite'
|
|
15
|
+
export {useRecordDocumentHistoryEvent} from '../hooks/comlink/useRecordDocumentHistoryEvent'
|
|
14
16
|
export {
|
|
15
17
|
useWindowConnection,
|
|
16
18
|
type UseWindowConnectionOptions,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {type SanityInstance} from '@sanity/sdk'
|
|
2
|
-
import {
|
|
2
|
+
import {type ReactElement} from 'react'
|
|
3
|
+
|
|
4
|
+
import {SanityInstanceContext} from './SanityInstanceContext'
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @internal
|
|
@@ -9,8 +11,6 @@ export interface SanityProviderProps {
|
|
|
9
11
|
sanityInstances: SanityInstance[]
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export const SanityInstanceContext = createContext<SanityInstance[] | null>(null)
|
|
13
|
-
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
16
16
|
*
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {type Message, type Node, type Status} from '@sanity/comlink'
|
|
2
|
+
import {getOrCreateNode} from '@sanity/sdk'
|
|
3
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {act, renderHook} from '../../../test/test-utils'
|
|
6
|
+
import {useManageFavorite} from './useManageFavorite'
|
|
7
|
+
|
|
8
|
+
vi.mock(import('@sanity/sdk'), async (importOriginal) => {
|
|
9
|
+
const actual = await importOriginal()
|
|
10
|
+
return {
|
|
11
|
+
...actual,
|
|
12
|
+
getOrCreateNode: vi.fn(),
|
|
13
|
+
releaseNode: vi.fn(),
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('useManageFavorite', () => {
|
|
18
|
+
let node: Node<Message, Message>
|
|
19
|
+
let statusCallback: ((status: Status) => void) | null = null
|
|
20
|
+
|
|
21
|
+
const mockDocumentHandle = {
|
|
22
|
+
_id: 'mock-id',
|
|
23
|
+
_type: 'mock-type',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function createMockNode() {
|
|
27
|
+
return {
|
|
28
|
+
on: vi.fn(() => () => {}),
|
|
29
|
+
post: vi.fn(),
|
|
30
|
+
stop: vi.fn(),
|
|
31
|
+
onStatus: vi.fn((callback) => {
|
|
32
|
+
statusCallback = callback
|
|
33
|
+
return () => {}
|
|
34
|
+
}),
|
|
35
|
+
} as unknown as Node<Message, Message>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
statusCallback = null
|
|
40
|
+
node = createMockNode()
|
|
41
|
+
vi.mocked(getOrCreateNode).mockReturnValue(node)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should initialize with default states', () => {
|
|
45
|
+
const {result} = renderHook(() => useManageFavorite(mockDocumentHandle))
|
|
46
|
+
|
|
47
|
+
expect(result.current.isFavorited).toBe(false)
|
|
48
|
+
expect(result.current.isConnected).toBe(false)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should handle favorite action', () => {
|
|
52
|
+
const {result} = renderHook(() => useManageFavorite(mockDocumentHandle))
|
|
53
|
+
|
|
54
|
+
act(() => {
|
|
55
|
+
result.current.favorite()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
expect(node.post).toHaveBeenCalledWith('core/v1/events/favorite', {
|
|
59
|
+
documentId: 'mock-id',
|
|
60
|
+
documentType: 'mock-type',
|
|
61
|
+
eventType: 'added',
|
|
62
|
+
})
|
|
63
|
+
expect(result.current.isFavorited).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should handle unfavorite action', () => {
|
|
67
|
+
const {result} = renderHook(() => useManageFavorite(mockDocumentHandle))
|
|
68
|
+
|
|
69
|
+
act(() => {
|
|
70
|
+
result.current.unfavorite()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
expect(node.post).toHaveBeenCalledWith('core/v1/events/favorite', {
|
|
74
|
+
documentId: 'mock-id',
|
|
75
|
+
documentType: 'mock-type',
|
|
76
|
+
eventType: 'removed',
|
|
77
|
+
})
|
|
78
|
+
expect(result.current.isFavorited).toBe(false)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should throw error during favorite/unfavorite actions', () => {
|
|
82
|
+
const errorMessage = 'Failed to update favorite status'
|
|
83
|
+
|
|
84
|
+
vi.mocked(node.post).mockImplementationOnce(() => {
|
|
85
|
+
throw new Error(errorMessage)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const {result} = renderHook(() => useManageFavorite(mockDocumentHandle))
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
expect(() => result.current.favorite()).toThrow(errorMessage)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('should update connection status', () => {
|
|
96
|
+
const {result} = renderHook(() => useManageFavorite(mockDocumentHandle))
|
|
97
|
+
|
|
98
|
+
expect(result.current.isConnected).toBe(false)
|
|
99
|
+
|
|
100
|
+
act(() => {
|
|
101
|
+
statusCallback?.('connected')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
expect(result.current.isConnected).toBe(true)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {type Events, SDK_CHANNEL_NAME, SDK_NODE_NAME} from '@sanity/message-protocol'
|
|
2
|
+
import {type DocumentHandle, type FrameMessage} from '@sanity/sdk'
|
|
3
|
+
import {useCallback, useState} from 'react'
|
|
4
|
+
|
|
5
|
+
import {useWindowConnection} from './useWindowConnection'
|
|
6
|
+
|
|
7
|
+
// should we import this whole type from the message protocol?
|
|
8
|
+
|
|
9
|
+
interface ManageFavorite {
|
|
10
|
+
favorite: () => void
|
|
11
|
+
unfavorite: () => void
|
|
12
|
+
isFavorited: boolean
|
|
13
|
+
isConnected: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @beta
|
|
18
|
+
*
|
|
19
|
+
* ## useManageFavorite
|
|
20
|
+
* This hook provides functionality to add and remove documents from favorites,
|
|
21
|
+
* and tracks the current favorite status of the document.
|
|
22
|
+
* @category Core UI Communication
|
|
23
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
24
|
+
* @returns An object containing:
|
|
25
|
+
* - `favorite` - Function to add document to favorites
|
|
26
|
+
* - `unfavorite` - Function to remove document from favorites
|
|
27
|
+
* - `isFavorited` - Boolean indicating if document is currently favorited
|
|
28
|
+
* - `isConnected` - Boolean indicating if connection to Core UI is established
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
33
|
+
* const {_id, _type} = props
|
|
34
|
+
* const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({
|
|
35
|
+
* _id,
|
|
36
|
+
* _type
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* return (
|
|
40
|
+
* <Button
|
|
41
|
+
* disabled={!isConnected}
|
|
42
|
+
* onClick={() => isFavorited ? unfavorite() : favorite()}
|
|
43
|
+
* text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
|
|
44
|
+
* />
|
|
45
|
+
* )
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function useManageFavorite({_id, _type}: DocumentHandle): ManageFavorite {
|
|
50
|
+
const [isFavorited, setIsFavorited] = useState(false) // should load this from a comlink fetch
|
|
51
|
+
const {sendMessage, status} = useWindowConnection<Events.FavoriteMessage, FrameMessage>({
|
|
52
|
+
name: SDK_NODE_NAME,
|
|
53
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const handleFavoriteAction = useCallback(
|
|
57
|
+
(action: 'added' | 'removed', setFavoriteState: boolean) => {
|
|
58
|
+
if (!_id || !_type) return
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const message: Events.FavoriteMessage = {
|
|
62
|
+
type: 'core/v1/events/favorite',
|
|
63
|
+
data: {
|
|
64
|
+
eventType: action,
|
|
65
|
+
documentId: _id,
|
|
66
|
+
documentType: _type,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sendMessage(message.type, message.data)
|
|
71
|
+
setIsFavorited(setFavoriteState)
|
|
72
|
+
} catch (err) {
|
|
73
|
+
const error = err instanceof Error ? err : new Error('Failed to update favorite status')
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.error(
|
|
76
|
+
`Failed to ${action === 'added' ? 'favorite' : 'unfavorite'} document:`,
|
|
77
|
+
error,
|
|
78
|
+
)
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[_id, _type, sendMessage],
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const favorite = useCallback(() => handleFavoriteAction('added', true), [handleFavoriteAction])
|
|
86
|
+
|
|
87
|
+
const unfavorite = useCallback(
|
|
88
|
+
() => handleFavoriteAction('removed', false),
|
|
89
|
+
[handleFavoriteAction],
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
favorite,
|
|
94
|
+
unfavorite,
|
|
95
|
+
isFavorited,
|
|
96
|
+
isConnected: status === 'connected',
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {type Message, type Node, type Status} from '@sanity/comlink'
|
|
2
|
+
import {getOrCreateNode} from '@sanity/sdk'
|
|
3
|
+
import {beforeEach, describe, expect, it, vi} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {act, renderHook} from '../../../test/test-utils'
|
|
6
|
+
import {useRecordDocumentHistoryEvent} from './useRecordDocumentHistoryEvent'
|
|
7
|
+
|
|
8
|
+
vi.mock(import('@sanity/sdk'), async (importOriginal) => {
|
|
9
|
+
const actual = await importOriginal()
|
|
10
|
+
return {
|
|
11
|
+
...actual,
|
|
12
|
+
getOrCreateNode: vi.fn(),
|
|
13
|
+
releaseNode: vi.fn(),
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('useRecordDocumentHistoryEvent', () => {
|
|
18
|
+
let node: Node<Message, Message>
|
|
19
|
+
let statusCallback: ((status: Status) => void) | null = null
|
|
20
|
+
|
|
21
|
+
const mockDocumentHandle = {
|
|
22
|
+
_id: 'mock-id',
|
|
23
|
+
_type: 'mock-type',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function createMockNode() {
|
|
27
|
+
return {
|
|
28
|
+
on: vi.fn(() => () => {}),
|
|
29
|
+
post: vi.fn(),
|
|
30
|
+
stop: vi.fn(),
|
|
31
|
+
onStatus: vi.fn((callback) => {
|
|
32
|
+
statusCallback = callback
|
|
33
|
+
return () => {}
|
|
34
|
+
}),
|
|
35
|
+
} as unknown as Node<Message, Message>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
statusCallback = null
|
|
40
|
+
node = createMockNode()
|
|
41
|
+
vi.mocked(getOrCreateNode).mockReturnValue(node)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('should initialize with correct connection status', () => {
|
|
45
|
+
const {result} = renderHook(() => useRecordDocumentHistoryEvent(mockDocumentHandle))
|
|
46
|
+
|
|
47
|
+
expect(result.current.isConnected).toBe(false)
|
|
48
|
+
|
|
49
|
+
act(() => {
|
|
50
|
+
statusCallback?.('connected')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
expect(result.current.isConnected).toBe(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should send correct message when recording events', () => {
|
|
57
|
+
const {result} = renderHook(() => useRecordDocumentHistoryEvent(mockDocumentHandle))
|
|
58
|
+
|
|
59
|
+
result.current.recordEvent('viewed')
|
|
60
|
+
|
|
61
|
+
expect(node.post).toHaveBeenCalledWith('core/v1/events/history', {
|
|
62
|
+
eventType: 'viewed',
|
|
63
|
+
documentId: 'mock-id',
|
|
64
|
+
documentType: 'mock-type',
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('should handle errors when sending messages', () => {
|
|
69
|
+
vi.mocked(node.post).mockImplementation(() => {
|
|
70
|
+
throw new Error('Failed to send message')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const {result} = renderHook(() => useRecordDocumentHistoryEvent(mockDocumentHandle))
|
|
74
|
+
|
|
75
|
+
expect(() => result.current.recordEvent('viewed')).toThrow('Failed to send message')
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {type Events, SDK_CHANNEL_NAME, SDK_NODE_NAME} from '@sanity/message-protocol'
|
|
2
|
+
import {type DocumentHandle, type FrameMessage} from '@sanity/sdk'
|
|
3
|
+
import {useCallback} from 'react'
|
|
4
|
+
|
|
5
|
+
import {useWindowConnection} from './useWindowConnection'
|
|
6
|
+
|
|
7
|
+
interface DocumentInteractionHistory {
|
|
8
|
+
recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
|
|
9
|
+
isConnected: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
* Hook for managing document interaction history in Sanity Studio.
|
|
15
|
+
* This hook provides functionality to record document interactions.
|
|
16
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
17
|
+
* @returns An object containing:
|
|
18
|
+
* - `recordEvent` - Function to record document interactions
|
|
19
|
+
* - `isConnected` - Boolean indicating if connection to Studio is established
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
24
|
+
* const {_id, _type} = props
|
|
25
|
+
* const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
|
|
26
|
+
* _id,
|
|
27
|
+
* _type
|
|
28
|
+
* })
|
|
29
|
+
*
|
|
30
|
+
* return (
|
|
31
|
+
* <Button
|
|
32
|
+
* disabled={!isConnected}
|
|
33
|
+
* onClick={() => recordEvent('viewed')}
|
|
34
|
+
* text={'Viewed'}
|
|
35
|
+
* />
|
|
36
|
+
* )
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function useRecordDocumentHistoryEvent({
|
|
41
|
+
_id,
|
|
42
|
+
_type,
|
|
43
|
+
}: DocumentHandle): DocumentInteractionHistory {
|
|
44
|
+
const {sendMessage, status} = useWindowConnection<Events.HistoryMessage, FrameMessage>({
|
|
45
|
+
name: SDK_NODE_NAME,
|
|
46
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const recordEvent = useCallback(
|
|
50
|
+
(eventType: 'viewed' | 'edited' | 'created' | 'deleted') => {
|
|
51
|
+
try {
|
|
52
|
+
const message: Events.HistoryMessage = {
|
|
53
|
+
type: 'core/v1/events/history',
|
|
54
|
+
data: {
|
|
55
|
+
eventType,
|
|
56
|
+
documentId: _id,
|
|
57
|
+
documentType: _type,
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
sendMessage(message.type, message.data)
|
|
62
|
+
} catch (error) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.error('Failed to record history event:', error)
|
|
65
|
+
throw error
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
[_id, _type, sendMessage],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
recordEvent,
|
|
73
|
+
isConnected: status === 'connected',
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {type SanityInstance} from '@sanity/sdk'
|
|
2
2
|
import {useContext} from 'react'
|
|
3
3
|
|
|
4
|
-
import {SanityInstanceContext} from '../../context/
|
|
4
|
+
import {SanityInstanceContext} from '../../context/SanityInstanceContext'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* `useSanityInstance` returns the current Sanity instance from the application context.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { c } from "react/compiler-runtime";
|
|
3
|
-
import { createContext } from "react";
|
|
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
|
-
};
|
|
12
|
-
export {
|
|
13
|
-
SanityInstanceContext,
|
|
14
|
-
SanityProvider
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;"}
|