/** @public */ declare type ClientPerspective = DeprecatedPreviewDrafts | 'published' | 'drafts' | 'raw' | StackablePerspective[]; /** * @deprecated use 'drafts' instead */ declare type DeprecatedPreviewDrafts = 'previewDrafts'; /** @alpha */ declare type IndexTuple = [number | '', number | '']; /** @alpha */ declare type KeyedSegment = { _key: string; }; /** @alpha */ declare type Path = PathSegment[]; /** @alpha */ declare type PathSegment = string | number | KeyedSegment | IndexTuple; /** @public */ declare type StackablePerspective = ('published' | 'drafts' | string) & {}; /** * Path syntax as used by the `sanity` package, you can give it a string: * `products[0].images[_key=="abc123"].asset._ref` * or an array: * `['products', 0, 'images', {_key: 'abc123'}, 'asset', '_ref']` * @alpha */ declare type StudioPathLike = Path | string; /** * Data resolved from a Sanity node * @public */ type SanityNode = { baseUrl: string; id: string; path: string; perspective?: string; dataset?: string; projectId?: string; tool?: string; type?: string; workspace?: string; }; /** * Data resolved from a Sanity Stega node * @public */ type SanityStegaNode = { origin: string; href: string; data?: unknown; }; /** * Helper * @internal */ type WithRequired = T & { [P in K]-?: T[P]; }; /** * The metadata that can be embedded in a data attribute. * All values are marked optional in the base type as they can be provided incrementally using the `createDataAttribute` function. * @public */ interface CreateDataAttributeProps { /** The studio base URL, optional */ baseUrl?: string; /** The dataset, optional */ dataset?: string; /** The document ID, required */ id?: string; /** The field path, required */ path?: StudioPathLike; /** The project ID, optional */ projectId?: string; /** The studio tool name, optional */ tool?: string; /** The document type, required */ type?: string; /** The studio workspace, optional */ workspace?: string; /** The studio perspective, optional, used for "Open in Studio" links */ perspective?: string; } /** * @public */ type CreateDataAttribute = (T extends WithRequired ? { /** * Returns a string representation of the data attribute * @param path - An optional path to concatenate with any existing path * @public */ (path?: StudioPathLike): string; /** * Returns a string representation of the data attribute * @public */ toString(): string; } : T extends WithRequired ? (path: StudioPathLike) => string : object) & { /** * Concatenate the current path with a new path * @param path - A path to concatenate with any existing path * @public */ scope(path: StudioPathLike): CreateDataAttribute; /** * Combines the current props with additional props * @param props - New props to merge with any existing props * @public */ combine: (props: U) => CreateDataAttribute; }; /** * A helper function for creating `data-sanity` attributes by explicitly providing metadata. * @returns An object with methods for incrementally adding and scoping metadata, and for generating a data attribute string. * @public */ declare function createDataAttribute(props: T): CreateDataAttribute; /** * Preview frame history update * @public */ type HistoryUpdate = { type: 'push' | 'pop' | 'replace'; title?: string; url: string; }; /** * @deprecated - the new major of Sanity Studio will no longer send this event, as better APIs like `loader/query-listen`, are available */ type DeprecatedHistoryRefreshMutation = { /** * source 'mutation' means a document were mutated and the preview might need to refresh */ source: 'mutation'; /** * If true then there's either preview-kit or a loader connected on the page * @deprecated – it's up to the application to know wether loaders are enabled or not, and how best to implement a refresh handler that works optimally, * the next major of Sanity Studio will not set this field */ livePreviewEnabled: boolean; /** * Select metadata about the document that were mutated * If it's prefixed with `drafts.` then it's a draft document, otherwise it's a published document. */ document: { /** * If it's prefixed with `drafts.` then it's a draft document, otherwise it's a published document. */ _id: string; /** * The document type is frequently used in `revalidateTag` scenarios with Next.js App Router */ _type: string; /** * The document revision, can be used to dedupe requests, as we always send two due to debouncing and handling Content Lake eventual consistency */ _rev: string; /** * If the document has a top level slug field named `slug` with the type `slug`, then it'll be included here */ slug?: { current?: string | null; }; }; }; /** * Preview frame history refresh event, emitted by Presentation Tool * @public */ type HistoryRefresh = { /** * source 'manual' means the refresh button were clicked by the user */ source: 'manual'; /** * If true then there's either preview-kit or a loader connected on the page * @deprecated – it's up to the application to know wether loaders are enabled or not, and how best to implement a refresh handler that works optimally, * the next major of Sanity Studio will not set this field */ livePreviewEnabled: boolean; } | DeprecatedHistoryRefreshMutation; /** * * @public */ type HistoryAdapterNavigate = (update: HistoryUpdate) => void; /** * * @public */ interface HistoryAdapter { subscribe: (navigate: HistoryAdapterNavigate) => () => void; update: (update: HistoryUpdate) => void; } /** * Cleanup function used when e.g. unmounting * @public */ type DisableVisualEditing = () => void; /** * A report of a stega payload found somewhere it will always cause a bug or unnecessary bloat. * Reports are produced when the `onSuspiciousStega` callback is provided to Visual Editing. * @public */ interface SuspiciousStegaReport { /** * Where the stega payload was found: * - `attribute` — in an element attribute where stega always causes problems, such as `class` * (selectors no longer match), `id` (broken anchors and `getElementById`), `href`/`src` and * other URL attributes (the invisible characters end up percent-encoded in requests), * `style`, `name`, `value` or `data-*` attributes (broken equality checks). * - `head` — anywhere inside ``, e.g. `` or `meta[content]`. Content in `<head>` * is never rendered, so the payload is pure bloat and corrupts SEO/social metadata. * - `script` — inside a `<script>` element, e.g. JSON-LD or embedded state. * - `style` — inside a `<style>` element, breaking selectors or values. * - `form-value` — in a form field value (e.g. `<textarea>` content), where it would be * submitted along with user input. * - `url` — in the page URL itself, meaning the page was reached through a link that had * stega encoded into it. */ kind: 'attribute' | 'head' | 'script' | 'style' | 'form-value' | 'url'; /** * The element the stega payload was found on or in. Undefined for `url` reports. */ element?: Element; /** * The name of the attribute containing the stega payload, if it was found in an attribute. */ attribute?: string; /** * The raw value containing the stega payload. */ value: string; /** * The value with the stega payload stripped — what the value should have been. Apply * `stegaClean` from `@sanity/client/stega` to the source value to fix the issue. */ cleaned: string; /** * The decoded edit info, if the payload could be decoded. Points to the document and field * that produced the value. */ sanity?: SanityNode | SanityStegaNode; } /** * Framework-neutral options for enabling Visual Editing. * * This is `VisualEditingOptions` from `@sanity/visual-editing` minus the alpha * `components` and `plugins` options — they take React components, which this * package intentionally does not expose (re-using the upstream type would also * pull `@types/react` into the emitted declarations). React-based custom * overlay components and plugins remain available from `@sanity/visual-editing`. * @public */ interface VisualEditingOptions { /** * The history adapter is used for Sanity Presentation to navigate URLs in the preview frame. */ history?: HistoryAdapter; /** * While Visual Editing is enabled, stega-encoded metadata (invisible characters) is * automatically stripped from clipboard data when content is copied from the page. * Set this option to `true` to opt out and keep stega in copied content. */ keepStegaOnCopy?: boolean; /** * This event can be used to make sure server side data fetching uses the same client * perspective as the Sanity Studio that is driving the visual editing. */ onPerspectiveChange?: (perspective: ClientPerspective) => void; /** * Fires when the editing variant changes in the Studio, with the bare variant id, * or undefined when the variant is cleared. Allows persisting the change to a * session cookie so server-side fetches can apply it. */ onVariantChange?: (variant: string | undefined) => void; /** * Reports stega payloads found in places where they always cause bugs or bloat. */ onSuspiciousStega?: (reports: SuspiciousStegaReport[]) => void; /** * The refresh API allows smarter refresh logic than the default `location.reload()` behavior. */ refresh?: (payload: HistoryRefresh) => false | Promise<void>; /** * The CSS z-index on the root node that renders overlays. */ zIndex?: string | number; } /** * Enables Visual Editing overlays on a page with Content Source Map encoding. * * The overlay renderer (and its inlined React runtime) stays in a separate * lazy chunk that only loads when this function is called. * @public */ declare function enableVisualEditing(options?: VisualEditingOptions): DisableVisualEditing; export { type CreateDataAttribute, type CreateDataAttributeProps, type DisableVisualEditing, type HistoryAdapter, type HistoryAdapterNavigate, type HistoryRefresh, type HistoryUpdate, type SuspiciousStegaReport, type VisualEditingOptions, type WithRequired, createDataAttribute, enableVisualEditing }; //# sourceMappingURL=index.d.ts.map