/** * Modified @sanity/types schema v3 * It would be nice to evenetually extend the sanity types directly */ import type { ComponentType } from 'react'; export declare namespace Schema { /** * The type definitions that are built into the sanity schema */ export type IntrinsicTypeDefinition = ArrayDefinition | BlockDefinition | BooleanDefinition | DateDefinition | DatetimeDefinition | DocumentDefinition | FileDefinition | GeopointDefinition | ImageDefinition | NumberDefinition | ObjectDefinition | ReferenceDefinition | CrossDatasetReferenceDefinition | SlugDefinition | StringDefinition | SpanDefinition | TextDefinition | UrlDefinition | UiDefinition; /** * Represents a Sanity schema type definition. * * It's recommend to use the `defineType` helper instead of this type by * itself. */ export type TypeDefinition = Extract | TypeAliasDefinition; /** * A union of all intrinsic types allowed natively in the schema. */ export type Type = IntrinsicTypeDefinition['type']; /** * Represents a reference to another type registered top-level in your schema. */ export interface TypeReference { type: string; name?: string; options?: TypeOptions & { [key: string]: unknown; }; } /** * Represents a type definition that is an alias/extension of an existing type * in your schema. Creating a type alias will re-register that existing type * under a different name. You can also override the default type options with * a type alias definition. */ export interface TypeAliasDefinition extends BaseDefinitionOptions { type: Exclude; options?: TypeOptions & { [key: string]: unknown; }; } /** * The shape of a field definition. Note, it's recommended to use the * `defineField` function instead of using this type directly. * * A field definition can be a reference to another registered top-level type * or a inline inline type definition. */ export type FieldDefinition = (Extract | TypeReference) & { name?: string; title?: string; description?: string; fieldset?: string; group?: string | string[]; hidden?: ConditionalProperty; readOnly?: ConditionalProperty; validation?: SchemaValidationValue; initialValue?: any; required?: boolean; }; export type ImageMetadataType = 'blurhash' | 'lqip' | 'palette' | 'exif' | 'location'; export type FieldsetDefinition = { name: string; title?: string; description?: string; hidden?: ConditionalProperty; readOnly?: ConditionalProperty; options?: ObjectOptions; }; export type FieldGroupDefinition = { name: string; title?: string; icon?: React.ComponentType | React.ReactNode; default?: boolean; }; interface BaseDefinitionOptions { name: string; title?: string; description?: string; hidden?: ConditionalProperty; readOnly?: ConditionalProperty; validation?: SchemaValidationValue; icon?: React.ComponentType | React.ReactNode; components?: { diff?: React.ComponentType; field?: React.ComponentType; input?: React.ComponentType; item?: React.ComponentType; preview?: React.ComponentType; }; initialValue?: any; } export type TypeOptions = T extends 'array' ? ArrayOptions : T extends 'block' ? BlockOptions : T extends 'boolean' ? BooleanOptions : T extends 'date' ? DateOptions : T extends 'datetime' ? DatetimeOptions : T extends 'file' ? FileOptions : T extends 'image' ? ImageOptions : T extends 'number' ? NumberOptions : T extends 'object' ? ObjectOptions : T extends 'crossDatasetReference' ? CrossDatasetReferenceDefinition : T extends 'string' ? StringOptions : never; export interface ArrayOptions { sortable?: boolean; layout?: 'tags' | 'grid'; list?: Array<{ title: string; value: TValue; } | string>; modal?: { type?: 'dialog' | 'popover'; width?: number | 'auto'; }; } export interface ArrayDefinition extends BaseDefinitionOptions { type: 'array'; of: Array; options?: ArrayOptions; } export interface BlockOptions { spellCheck?: boolean; } export interface BlockDefinition extends BaseDefinitionOptions { type: 'block'; styles?: Array<{ title: string; value: string; }>; lists?: Array<{ title: string; value: string; }>; marks?: unknown; of?: Array; options?: BlockOptions; } export interface BooleanOptions { layout?: 'switch' | 'checkbox'; } export interface BooleanDefinition extends BaseDefinitionOptions { type: 'boolean'; options?: BooleanOptions; } export interface DateOptions { calendarTodayLabel?: string; dateFormat?: string; } export interface DateDefinition extends BaseDefinitionOptions { type: 'date'; options?: DateOptions; placeholder?: string; } export interface DatetimeOptions { calendarTodayLabel?: string; dateFormat?: string; timeFormat?: string; timeStep?: number; } export interface DatetimeDefinition extends BaseDefinitionOptions { type: 'datetime'; options?: DatetimeOptions; placeholder?: string; } export interface DocumentDefinition extends Omit { type: 'document'; liveEdit?: boolean; orderings?: SortOrdering[]; } export interface FileOptions extends ObjectOptions { storeOriginalFilename?: boolean; accept?: string; } export interface FileDefinition extends Omit { type: 'file'; fields?: ObjectDefinition['fields']; options?: FileOptions; } export interface GeopointDefinition extends BaseDefinitionOptions { type: 'geopoint'; } interface AssetFieldOptions { /** * @deprecated This is now the default behavior - use `fieldset` to hide fields by default */ isHighlighted?: boolean; } export type AssetFieldDefinition = FieldDefinition & { options?: AssetFieldOptions; }; export interface ImageOptions extends FileOptions { metadata?: ImageMetadataType[]; hotspot?: boolean; } export interface ImageDefinition extends Omit { type: 'image'; fields?: AssetFieldDefinition[]; metadata?: ImageMetadataType[]; hotspot?: boolean; options?: ImageOptions; } export interface NumberOptions { list?: Array; layout?: 'radio' | 'dropdown'; direction?: 'horizontal' | 'vertical'; } export interface NumberDefinition extends BaseDefinitionOptions { type: 'number'; options?: NumberOptions; } export interface ObjectOptions { collapsible?: boolean; collapsed?: boolean; columns?: number; modal?: { type?: 'dialog' | 'popover'; width?: number | number[] | 'auto'; }; } export interface ObjectDefinition extends BaseDefinitionOptions { type: 'object'; fields: FieldDefinition[]; groups?: FieldGroupDefinition[]; fieldsets?: FieldsetDefinition[]; options?: ObjectOptions; } export interface ReferenceDefinition extends BaseDefinitionOptions { type: 'reference'; to: TypeDefinition | TypeReference | Array; weak?: boolean; } export interface CrossDatasetReferenceDefinition extends BaseDefinitionOptions { type: 'crossDatasetReference'; weak?: boolean; to: { type: string; title?: string; icon?: ComponentType; __experimental_search?: { path: string | string[]; weight?: number; mapWith?: string; }[]; }[]; dataset: string; projectId: string; studioUrl?: (document: { id: string; type?: string; }) => string | null; tokenId: string; } export interface SlugDefinition extends BaseDefinitionOptions { type: 'slug'; } export interface StringOptions { list?: { /** The UI title */ title: string; /** The form value */ value: string; /** Used in lists that support a description */ description?: string; /** Used in lists that support a 3rd supporting text */ tag?: string; }[]; layout?: 'radio' | 'dropdown'; direction?: 'vertical' | 'horizontal'; } export interface StringDefinition extends BaseDefinitionOptions { type: 'string'; options?: StringOptions; } export interface SpanDefinition extends BaseDefinitionOptions { type: 'span'; } export interface TextDefinition extends BaseDefinitionOptions { type: 'text'; rows?: number; } export interface UrlDefinition extends BaseDefinitionOptions { type: 'url'; } export interface UiDefinition { type: 'ui'; name?: string; title?: string; description?: string; uiType?: 'text' | 'divider'; } export {}; } export declare function defineType(schemaDefinition: Extract): Extract; export declare function defineField(schemaField: Schema.FieldDefinition): Schema.FieldDefinition; /** * Note: you probably want `SchemaTypeDefinition` instead * @see SchemaTypeDefinition */ export type SchemaType = ArraySchemaType | BooleanSchemaType | NumberSchemaType | ObjectSchemaType | StringSchemaType; /** * Represents a Sanity schema type definition with an optional type parameter. * * It's recommend to use the `defineType` helper instead of this type by * itself. */ export type SchemaTypeDefinition = Schema.TypeDefinition; export interface SchemaValidationError { helpId?: string; message: string; severity: 'error'; } export interface SchemaValidationWarning { helpId?: string; message: string; severity: 'warning'; } export type SchemaValidationProblem = SchemaValidationError | SchemaValidationWarning; export type SchemaValidationProblemPath = Array<{ kind: 'type'; type: string; name: string; } | { kind: 'property'; name: string; }>; export interface SchemaValidationProblemGroup { path: SchemaValidationProblemPath; problems: SchemaValidationProblem[]; } export interface Schema { _original?: { name: string; types: SchemaTypeDefinition[]; }; _registry: { [typeName: string]: any; }; _validation?: SchemaValidationProblemGroup[]; name: string; get: (name: string) => SchemaType | undefined; has: (name: string) => boolean; getTypeNames: () => string[]; } export interface SortOrderingItem { field: string; direction: 'asc' | 'desc'; } export type SortOrdering = { title: string; name: string; by: SortOrderingItem[]; }; export interface ConditionalPropertyCallbackContext { document: { [key: string]: unknown; } | undefined; parent?: any; value?: any; } export type ConditionalPropertyCallback = (context: ConditionalPropertyCallbackContext) => boolean; export type ConditionalProperty = boolean | ConditionalPropertyCallback | undefined; export type InitialValueResolver = (params?: Params) => Promise | Value; export type InitialValueProperty = Value | InitialValueResolver | undefined; /** * Represents the possible values of a schema type's `validation` field. * * If the schema has not been run through `inferFromSchema` from * `@sanity/validation` then value could be a function. * * `inferFromSchema` mutates the schema converts this value to an array of * `Rule` instances. * * @privateRemarks * * Usage of the schema inside the studio will almost always be from the compiled * `createSchema` function. In this case, you can cast the value or throw to * narrow the type. E.g.: * * ```ts * if (typeof type.validation === 'function') { * throw new Error( * `Schema type "${type.name}"'s \`validation\` was not run though \`inferFromSchema\`` * ) * } * ``` */ export type SchemaValidationValue = false | undefined | SchemaValidationValue[]; export interface BaseSchemaType { name: string; title?: string; description?: string; type?: SchemaType; liveEdit?: boolean; readOnly?: ConditionalProperty; hidden?: ConditionalProperty; icon?: ComponentType; initialValue?: InitialValueProperty; validation?: SchemaValidationValue; components?: { diff?: React.ComponentType; field?: React.ComponentType; input?: React.ComponentType; item?: React.ComponentType; preview?: React.ComponentType; }; /** * @deprecated This will be removed. */ placeholder?: string; } export interface TitledListValue { _key?: string; title: string; value?: V; } export interface EnumListProps { list?: TitledListValue[] | V[]; layout?: 'radio' | 'dropdown'; direction?: 'horizontal' | 'vertical'; } export interface StringSchemaType extends BaseSchemaType { jsonType: 'string'; options?: EnumListProps & { dateFormat?: string; timeFormat?: string; }; initialValue?: ((arg?: any) => Promise | string) | string | undefined; } export interface TextSchemaType extends StringSchemaType { rows?: number; } export interface NumberSchemaType extends BaseSchemaType { jsonType: 'number'; options?: EnumListProps; initialValue?: InitialValueProperty; } export interface BooleanSchemaType extends BaseSchemaType { jsonType: 'boolean'; options?: { layout: 'checkbox' | 'switch'; }; initialValue?: InitialValueProperty; } export interface ArraySchemaType extends BaseSchemaType { jsonType: 'array'; of: Exclude[]; options?: { list?: TitledListValue[] | V[]; layout?: V extends string ? 'tags' : 'grid'; direction?: 'horizontal' | 'vertical'; sortable?: boolean; modal?: { type?: 'dialog' | 'popover'; width?: number | 'auto'; }; }; } export type ArraySchemaTypeOf = Omit & { of: TSchemaType[]; }; /** * A specific `ObjectField` for `marks` in `SpanSchemaType` * @see SpanSchemaType */ export type MarksObjectField = { name: 'marks'; } & ObjectField>; /** * A specific `ObjectField` for `text` in `SpanSchemaType` * @see SpanSchemaType */ export type TextObjectField = { name: 'text'; } & ObjectField; /** * A specific `ObjectField` for `style` in `BlockSchemaType` * @see BlockSchemaType */ export type StyleObjectField = { name: 'style'; } & ObjectField; /** * A specific `ObjectField` for `list` in `BlockSchemaType` * @see BlockSchemaType */ export type ListObjectField = { name: 'list'; } & ObjectField; /** * The specific `children` field of a `block` type (`BlockSchemaType`) * @see BlockSchemaType */ export type BlockChildrenObjectField = { name: 'children'; } & ObjectField; /** * Represents the compiled schema shape for `span`s for portable text. * * Note: this does _not_ represent the schema definition shape. */ export interface SpanSchemaType extends Omit { annotations: (ObjectSchemaType & { blockEditor?: { icon?: string | ComponentType; render?: ComponentType; }; })[]; decorators: TitledListValue[]; fields: [MarksObjectField, TextObjectField]; } /** * Represents the compiled schema shape for `block`s for portable text. * * Note: this does _not_ represent the schema definition shape. */ export interface BlockSchemaType extends ObjectSchemaType { fields: [ BlockChildrenObjectField, StyleObjectField, ListObjectField, ...ObjectField[] ]; } export type ObjectFieldType = T & { hidden?: ConditionalProperty; readOnly?: ConditionalProperty; }; export interface ObjectField { name: string; fieldset?: string; group?: string | string[]; type: ObjectFieldType; } export interface FieldGroup { name: string; icon?: React.ComponentType; title?: string; description?: string; hidden?: ConditionalProperty; default?: boolean; fields?: ObjectField[]; } export interface ObjectSchemaType extends BaseSchemaType { jsonType: 'object'; fields: ObjectField[]; groups?: FieldGroup[]; fieldsets?: Fieldset[]; initialValue?: InitialValueProperty>; weak?: boolean; __experimental_search?: { path: string[]; weight: number; mapWith?: string; }[]; /** * @beta */ orderings?: SortOrdering[]; options?: any; } export interface ObjectSchemaTypeWithOptions extends Omit { options?: CollapseOptions & { columns?: number; }; } export interface SingleFieldSet { single: true; field: ObjectField; hidden?: ConditionalProperty; readOnly?: ConditionalProperty; group?: string | string[]; } export interface MultiFieldSet { name: string; title?: string; description?: string; single?: false; group?: string | string[]; options?: CollapseOptions & { columns?: number; }; fields: ObjectField[]; hidden?: ConditionalProperty; readOnly?: ConditionalProperty; } export type Fieldset = SingleFieldSet | MultiFieldSet; export interface CollapseOptions { collapsed?: boolean; collapsible?: boolean; /** * @deprecated Use `collapsible` instead */ collapsable?: boolean; } export interface AssetSchemaTypeOptions { accept?: string; storeOriginalFilename?: boolean; }