UNPKG

next-sanity

Version:
89 lines 4.9 kB
import "@sanity/comlink"; import "@sanity/presentation-comlink"; import { useOptimistic } from "@sanity/visual-editing/react"; import { ClientPerspective, ClientPerspective as ClientPerspective$1, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client"; /** * The Sanity Client perspective used when fetching data in Draft Mode, in the `sanityFetch` calls * used by React Server Components on the page. Note that some of them might set the `perspective` to a different value. * This value is what's used by default. * @public */ type DraftPerspective = "checking" | "unknown" | ClientPerspective$1; /** * * @public */ type DraftEnvironment = "checking" | "presentation-iframe" | "presentation-window" | "live" | "static" | "unknown"; /** * Reports the current draft mode environment. * Use it to determine how to adapt the UI based on wether: * - Your app is previewed in a iframe, inside Presentation Tool in a Sanity Studio. * - Your app is previewed in a new window, spawned from Presentation Tool in a Sanity Studio. * - Your app is live previewing drafts in a standalone context. * - Your app is previewing drafts, but not live. * - Your app is not previewing anything (that could be detected). * @public */ declare function useDraftModeEnvironment(): DraftEnvironment; /** * Reports the Sanity Client perspective used to fetch data in `sanityFetch` used on the page. * If the hook is used outside Draft Mode it will resolve to `'unknown'`. * If the hook is used but the `<SanityLive />` component is not present then it'll stay in `'checking'` and console warn after a timeout that it seems like you're missing the component. * @public */ declare function useDraftModePerspective(): DraftPerspective; /** * Detects if the application is being previewed inside Sanity Presentation Tool. * Presentation Tool can open the application in an iframe, or in a new window. * When in this context there are some UI you usually don't want to show, * for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to * the editorial experience. * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool, * then `true` if it is, and `false` otherwise. * @public */ declare function useIsPresentationTool(): boolean | null; /** * Detects if the application is considered to be in a "Live Preview" mode. * Live Preview means that the application is either: * - being previewed inside Sanity Presentation Tool * - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as "Standalone Live Preview'" * When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention. * This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts, * to avoid interrupting the user that is consuming your content. * This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX, * while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time. * * The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not. * Then `true` if it is, and `false` otherwise. * @public */ declare function useIsLivePreview(): boolean | null; /** @alpha */ type UsePresentationQueryReturnsInactive = { data: null; sourceMap: null; perspective: null; }; /** @alpha */ type UsePresentationQueryReturnsActive<QueryString extends string> = { data: ClientReturn<QueryString>; sourceMap: ContentSourceMap | null; perspective: ClientPerspective$1; }; type UsePresentationQueryReturns<QueryString extends string> = UsePresentationQueryReturnsInactive | UsePresentationQueryReturnsActive<QueryString>; /** * Experimental hook that can run queries in Presentation Tool. * Query results are sent back over postMessage whenever the query results change. * It also works with optimistic updates in the studio itself, offering low latency updates. * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases. * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe. * @alpha */ declare function usePresentationQuery<const QueryString extends string>(props: { query: QueryString; params?: QueryParams | Promise<QueryParams>; stega?: boolean; }): UsePresentationQueryReturns<QueryString>; export { type ClientPerspective, type DraftEnvironment, type DraftPerspective, UsePresentationQueryReturns, UsePresentationQueryReturnsActive, UsePresentationQueryReturnsInactive, useDraftModeEnvironment, useDraftModePerspective, useIsLivePreview, useIsPresentationTool, useOptimistic, usePresentationQuery }; //# sourceMappingURL=index.d.ts.map