UNPKG

@sanity/visual-editing

Version:

[![npm stat](https://img.shields.io/npm/dm/@sanity/visual-editing.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@sanity/visual-editing) [![npm version](https://img.shields.io/npm/v/@sanity/visual-editing.svg?style=flat-square)](https://

84 lines (78 loc) 2.43 kB
import type {StudioPathLike} from '@sanity/client/csm' /** * @public */ export declare type CreateDataAttribute<T extends CreateDataAttributeProps> = (T extends WithRequired<CreateDataAttributeProps, 'id' | 'type' | 'path'> ? { /** * 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<CreateDataAttributeProps, 'id' | 'type'> ? (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< T & { path: StudioPathLike } > /** * Combines the current props with additional props * @param props - New props to merge with any existing props * @public */ combine: <U extends CreateDataAttributeProps>(props: U) => CreateDataAttribute<T & U> } /** * 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 */ export declare function createDataAttribute<T extends CreateDataAttributeProps>( props: T, ): CreateDataAttribute<T> /** * 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 */ export declare 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 } /** * Helper * @internal */ export declare type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] } export {}