import type * as S from 'sanity' export type { Rule as RuleType, CustomValidator, SlugOptions, PreviewConfig, PortableTextBlock, SchemaValidationValue, } from 'sanity' // Utility types export type ToggleProp = T | false export type FieldExtensions = { name?: string required?: boolean } export type BaseOmittedKeys = 'type' | 'name' export type SchemaToolField = Omit & FieldExtensions & S.FieldDefinitionBase & { validation?: S.SchemaValidationValue } export type IntrinsicDefinitionsUnion = Partial< S.IntrinsicDefinitions[keyof S.IntrinsicDefinitions] > export type ValidationReturn = S.ValidationBuilder, any> // Base type export type FieldProps = IntrinsicDefinitionsUnion & FieldExtensions & S.FieldDefinitionBase & { validation?: S.SchemaValidationValue } export type FieldReturn = ReturnType // Group type export type GroupProps = Omit export type GroupReturn = S.FieldGroupDefinition // Fieldset type export type FieldsetProps = Omit & { collapsible?: boolean collapsed?: boolean } export type FieldsetReturn = S.FieldsetDefinition // Preview type export type PreviewPrepare = Pick export type PreviewReturn = S.PreviewConfig export type PreviewProps = PreviewPrepare & { title?: string media?: string [key: string]: string | undefined | PreviewPrepare['prepare'] } export type LinkPreviewProps = S.PreviewConfig & { prefix?: string } // Default field types export type ArrayField = SchemaToolField export type BlockField = SchemaToolField export type BooleanField = SchemaToolField export type DateField = SchemaToolField export type DatetimeField = SchemaToolField export type DocumentField = SchemaToolField export type EmailField = SchemaToolField export type FileField = SchemaToolField export type GeopointField = SchemaToolField export type ImageField = SchemaToolField export type NumberField = SchemaToolField export type ObjectField = SchemaToolField export type ReferenceField = SchemaToolField> export type SlugField = SchemaToolField export type StringField = SchemaToolField export type TextField = SchemaToolField export type UrlField = SchemaToolField // Custom field types export type BlockContentField = Partial export type MultiReferenceField = Partial & { options?: { types?: string[] } } export type CategoriesField = MultiReferenceField & { options?: { types?: string[] } } export type CategoryField = ReferenceField export type CheckboxField = BooleanField export type ExcerptField = TextField export type FormField = Partial export type MessageField = StringField & { options?: { message?: string } } export type PublishedDateField = DateField export type RadioField = StringField export type RadioList = S.StringOptions['list'] export type SeoField = Omit export type TitleField = StringField // Link field export type LinkArgs = { condition?: RadioField url?: ToggleProp page?: ToggleProp hasHash?: ToggleProp hash?: ToggleProp file?: ToggleProp video?: ToggleProp label?: ToggleProp linkStyle?: ToggleProp linkSize?: ToggleProp target?: ToggleProp } export type ConditionsType = { [key: string]: string | FieldProps[] } export type LinkField = Partial & { types?: string[] args?: LinkArgs groups?: S.FieldGroupDefinition[] conditions?: ConditionsType } // Media field export type MediaArgs = { image?: ToggleProp video?: ToggleProp caption?: ToggleProp ratio?: ToggleProp } export type MediaField = Partial & { args?: MediaArgs conditions?: ConditionsType } // Hero field export type HeroArgs = { label?: ToggleProp heading?: ToggleProp content?: ToggleProp link?: ToggleProp media?: ToggleProp align?: ToggleProp } export type HeroField = Partial & { args?: HeroArgs } // Content group field export type ContentGroupField = { label?: ToggleProp heading?: ToggleProp content?: ToggleProp link?: ToggleProp } export type FieldDefaults = { fieldset?: string title?: TitleField slug?: SlugField path?: StringField } // Config type export interface CofigurableFieldTypes { array: ArrayField block: BlockField blockContent: BlockContentField boolean: BooleanField categories: CategoriesField category: CategoryField checkbox: CheckboxField contentGroup: ContentGroupField date: DateField datetime: DatetimeField document: DocumentField email: EmailField excerpt: ExcerptField file: FileField formField: FormField geopoint: GeopointField hero: HeroField image: ImageField link: LinkField media: MediaField message: MessageField multiReference: MultiReferenceField number: NumberField object: ObjectField publishedDate: PublishedDateField radio: RadioField reference: ReferenceField seo: SeoField slug: SlugField string: StringField text: TextField title: TitleField url: UrlField } export type ConfigType = { [K in keyof CofigurableFieldTypes]?: Partial } export type CustomFieldType = (...args: any[]) => FieldReturn | FieldReturn[] export type CustomFieldsetType = (...args: any[]) => FieldsetReturn | FieldsetReturn[] export type CustomGroupType = (...args: any[]) => GroupReturn | GroupReturn[] export type CustomPreviewType = (...args: any[]) => PreviewReturn export interface CustomTypes { F?: { [key: string]: CustomFieldType } FS?: { [key: string]: CustomFieldsetType } G?: { [key: string]: CustomGroupType } P?: { [key: string]: CustomPreviewType } V?: { [key: string]: any // TODO: Improve typing. Validation types are confusing } }