diff --git a/packages/@sanity/types/src/reference/types.ts b/packages/@sanity/types/src/reference/types.ts index 8e85f8a2ad68..89d3a9ce4726 100644 --- a/packages/@sanity/types/src/reference/types.ts +++ b/packages/@sanity/types/src/reference/types.ts @@ -2,7 +2,7 @@ import {type SanityClient} from '@sanity/client' import {type SanityDocument} from '../documents' import {type Path} from '../paths' -import {type BaseOptions} from '../schema' +import {type BaseSchemaTypeOptions} from '../schema' /** @public */ export interface Reference { @@ -57,7 +57,7 @@ export interface ReferenceFilterQueryOptions { } /** @public */ -export interface ReferenceBaseOptions extends BaseOptions { +export interface ReferenceBaseOptions extends BaseSchemaTypeOptions { disableNew?: boolean } diff --git a/packages/@sanity/types/src/schema/definition/type/array.ts b/packages/@sanity/types/src/schema/definition/type/array.ts index 8e271b491fb9..2a9668597285 100644 --- a/packages/@sanity/types/src/schema/definition/type/array.ts +++ b/packages/@sanity/types/src/schema/definition/type/array.ts @@ -9,8 +9,8 @@ import { type TypeAliasDefinition, } from '../schemaDefinition' import { - type BaseOptions, type BaseSchemaDefinition, + type BaseSchemaTypeOptions, type SearchConfiguration, type TitledListValue, } from './common' @@ -18,7 +18,7 @@ import { export type {InsertMenuOptions} /** @public */ -export interface ArrayOptions extends SearchConfiguration, BaseOptions { +export interface ArrayOptions extends SearchConfiguration, BaseSchemaTypeOptions { list?: TitledListValue[] | V[] // inferring the array.of value for ArrayDefinition cause too much code-noise and was removed. // Since we don't have the type-info needed here, we allow values diff --git a/packages/@sanity/types/src/schema/definition/type/block.ts b/packages/@sanity/types/src/schema/definition/type/block.ts index ee3a8ef47bd6..7c045b7e58c2 100644 --- a/packages/@sanity/types/src/schema/definition/type/block.ts +++ b/packages/@sanity/types/src/schema/definition/type/block.ts @@ -3,13 +3,13 @@ import {type ComponentType, type ReactNode} from 'react' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' import {type ArrayOfType} from './array' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' import {type ObjectDefinition} from './object' /** * Schema options for a Block schema definition * @public */ -export interface BlockOptions extends BaseOptions { +export interface BlockOptions extends BaseSchemaTypeOptions { /** * Turn on or off the builtin browser spellchecking. Default is on. */ diff --git a/packages/@sanity/types/src/schema/definition/type/boolean.ts b/packages/@sanity/types/src/schema/definition/type/boolean.ts index a9f68a70e3c4..30c0ef83ffdd 100644 --- a/packages/@sanity/types/src/schema/definition/type/boolean.ts +++ b/packages/@sanity/types/src/schema/definition/type/boolean.ts @@ -1,9 +1,9 @@ import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ -export interface BooleanOptions extends BaseOptions { +export interface BooleanOptions extends BaseSchemaTypeOptions { layout?: 'switch' | 'checkbox' } diff --git a/packages/@sanity/types/src/schema/definition/type/common.ts b/packages/@sanity/types/src/schema/definition/type/common.ts index 7ebc2e9d1c84..5c3c3abc2b08 100644 --- a/packages/@sanity/types/src/schema/definition/type/common.ts +++ b/packages/@sanity/types/src/schema/definition/type/common.ts @@ -27,7 +27,7 @@ export type FieldGroupDefinition = { /** * Options for configuring how Sanity Create interfaces with the type or field. */ -export interface SanityCreateTypeOptions { +export interface SanityCreateOptions { /** Set to true to exclude a type or field from appearing in Sanity Create */ exclude?: boolean } @@ -39,8 +39,8 @@ export interface SanityCreateTypeOptions { * * @public * */ -export interface BaseOptions { - sanityCreate?: SanityCreateTypeOptions +export interface BaseSchemaTypeOptions { + sanityCreate?: SanityCreateOptions } /** @public */ diff --git a/packages/@sanity/types/src/schema/definition/type/date.ts b/packages/@sanity/types/src/schema/definition/type/date.ts index 5c71cf5e3d34..b76e17009dd5 100644 --- a/packages/@sanity/types/src/schema/definition/type/date.ts +++ b/packages/@sanity/types/src/schema/definition/type/date.ts @@ -1,10 +1,10 @@ import {type FieldReference} from '../../../validation' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ -export interface DateOptions extends BaseOptions { +export interface DateOptions extends BaseSchemaTypeOptions { dateFormat?: string } diff --git a/packages/@sanity/types/src/schema/definition/type/datetime.ts b/packages/@sanity/types/src/schema/definition/type/datetime.ts index 3f1895c2eaf4..7cc85c042f08 100644 --- a/packages/@sanity/types/src/schema/definition/type/datetime.ts +++ b/packages/@sanity/types/src/schema/definition/type/datetime.ts @@ -1,10 +1,10 @@ import {type FieldReference} from '../../../validation' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ -export interface DatetimeOptions extends BaseOptions { +export interface DatetimeOptions extends BaseSchemaTypeOptions { dateFormat?: string timeFormat?: string timeStep?: number diff --git a/packages/@sanity/types/src/schema/definition/type/document.ts b/packages/@sanity/types/src/schema/definition/type/document.ts index ab5f62b89348..e567dd18b42e 100644 --- a/packages/@sanity/types/src/schema/definition/type/document.ts +++ b/packages/@sanity/types/src/schema/definition/type/document.ts @@ -1,7 +1,7 @@ import {type SanityDocument} from '../../../documents/types' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty, type SortOrdering} from '../../types' -import {type BaseOptions} from './common' +import {type BaseSchemaTypeOptions} from './common' import {type ObjectDefinition} from './object' /** @@ -10,7 +10,7 @@ import {type ObjectDefinition} from './object' * @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface DocumentOptions extends BaseOptions {} +export interface DocumentOptions extends BaseSchemaTypeOptions {} /** @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface diff --git a/packages/@sanity/types/src/schema/definition/type/email.ts b/packages/@sanity/types/src/schema/definition/type/email.ts index 108604009d78..001c2a7672a0 100644 --- a/packages/@sanity/types/src/schema/definition/type/email.ts +++ b/packages/@sanity/types/src/schema/definition/type/email.ts @@ -1,6 +1,6 @@ import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface @@ -9,7 +9,7 @@ export interface EmailRule extends RuleDef {} /** @public */ // only exists to support declaration extensions // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface EmailOptions extends BaseOptions {} +export interface EmailOptions extends BaseSchemaTypeOptions {} /** @public */ export interface EmailDefinition extends BaseSchemaDefinition { diff --git a/packages/@sanity/types/src/schema/definition/type/geopoint.ts b/packages/@sanity/types/src/schema/definition/type/geopoint.ts index ca020bc91df5..2e3d00bfac3f 100644 --- a/packages/@sanity/types/src/schema/definition/type/geopoint.ts +++ b/packages/@sanity/types/src/schema/definition/type/geopoint.ts @@ -1,6 +1,6 @@ import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** * Geographical point representing a pair of latitude and longitude coordinates, @@ -37,7 +37,7 @@ export interface GeopointRule extends RuleDef {} /** @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface GeopointOptions extends BaseOptions {} +export interface GeopointOptions extends BaseSchemaTypeOptions {} /** @public */ export interface GeopointDefinition extends BaseSchemaDefinition { diff --git a/packages/@sanity/types/src/schema/definition/type/number.ts b/packages/@sanity/types/src/schema/definition/type/number.ts index 5d8557430ace..939383f240c0 100644 --- a/packages/@sanity/types/src/schema/definition/type/number.ts +++ b/packages/@sanity/types/src/schema/definition/type/number.ts @@ -1,11 +1,11 @@ import {type FieldReference} from '../../../validation' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition, type EnumListProps} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions, type EnumListProps} from './common' /** @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface NumberOptions extends EnumListProps, BaseOptions {} +export interface NumberOptions extends EnumListProps, BaseSchemaTypeOptions {} /** @public */ export interface NumberRule extends RuleDef { diff --git a/packages/@sanity/types/src/schema/definition/type/object.ts b/packages/@sanity/types/src/schema/definition/type/object.ts index 0abff4c46da5..443bdf5d830a 100644 --- a/packages/@sanity/types/src/schema/definition/type/object.ts +++ b/packages/@sanity/types/src/schema/definition/type/object.ts @@ -3,14 +3,14 @@ import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' import {type FieldDefinition} from '../schemaDefinition' import { - type BaseOptions, type BaseSchemaDefinition, + type BaseSchemaTypeOptions, type FieldGroupDefinition, type FieldsetDefinition, } from './common' /** @public */ -export interface ObjectOptions extends BaseOptions { +export interface ObjectOptions extends BaseSchemaTypeOptions { collapsible?: boolean collapsed?: boolean columns?: number diff --git a/packages/@sanity/types/src/schema/definition/type/slug.ts b/packages/@sanity/types/src/schema/definition/type/slug.ts index cc788eada6c9..cf1accd73d90 100644 --- a/packages/@sanity/types/src/schema/definition/type/slug.ts +++ b/packages/@sanity/types/src/schema/definition/type/slug.ts @@ -3,7 +3,7 @@ import {type SlugifierFn, type SlugSourceFn} from '../../../slug' import {type SlugIsUniqueValidator} from '../../../validation' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ export interface SlugValue { @@ -16,7 +16,7 @@ export interface SlugValue { export interface SlugRule extends RuleDef {} /** @public */ -export interface SlugOptions extends BaseOptions { +export interface SlugOptions extends BaseSchemaTypeOptions { source?: string | Path | SlugSourceFn maxLength?: number slugify?: SlugifierFn diff --git a/packages/@sanity/types/src/schema/definition/type/string.ts b/packages/@sanity/types/src/schema/definition/type/string.ts index 753ee9fa4686..dd7ed8034eb9 100644 --- a/packages/@sanity/types/src/schema/definition/type/string.ts +++ b/packages/@sanity/types/src/schema/definition/type/string.ts @@ -2,15 +2,18 @@ import {type FieldReference} from '../../../validation' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' import { - type BaseOptions, type BaseSchemaDefinition, + type BaseSchemaTypeOptions, type EnumListProps, type SearchConfiguration, } from './common' /** @public */ // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface StringOptions extends EnumListProps, SearchConfiguration, BaseOptions {} +export interface StringOptions + extends EnumListProps, + SearchConfiguration, + BaseSchemaTypeOptions {} /** @public */ export interface StringRule extends RuleDef { diff --git a/packages/@sanity/types/src/schema/definition/type/url.ts b/packages/@sanity/types/src/schema/definition/type/url.ts index b7847ae1d388..906314b21fd7 100644 --- a/packages/@sanity/types/src/schema/definition/type/url.ts +++ b/packages/@sanity/types/src/schema/definition/type/url.ts @@ -1,7 +1,7 @@ import {type UriValidationOptions} from '../../../validation/types' import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder' import {type InitialValueProperty} from '../../types' -import {type BaseOptions, type BaseSchemaDefinition} from './common' +import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common' /** @public */ export interface UrlRule extends RuleDef { @@ -11,7 +11,7 @@ export interface UrlRule extends RuleDef { /** @public */ // only exists to support declaration extensions // eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface UrlOptions extends BaseOptions {} +export interface UrlOptions extends BaseSchemaTypeOptions {} /** @public */ export interface UrlDefinition extends BaseSchemaDefinition { diff --git a/packages/sanity/src/core/create/start-in-create/StartInCreateAction.tsx b/packages/sanity/src/core/create/start-in-create/StartInCreateAction.tsx index bada2bf003c2..2d7b24939af7 100644 --- a/packages/sanity/src/core/create/start-in-create/StartInCreateAction.tsx +++ b/packages/sanity/src/core/create/start-in-create/StartInCreateAction.tsx @@ -1,3 +1,4 @@ +import {type BaseSchemaTypeOptions} from '@sanity/types' import {useCallback, useState} from 'react' import { @@ -5,6 +6,7 @@ import { type DocumentActionDescription, type DocumentActionProps, } from '../../config' +import {useSchema} from '../../hooks' import {useTranslation} from '../../i18n' import {isStartInCreateAutoConfirmed, setStartInCreateAutoConfirm} from '../createStorage' import {createLocaleNamespace} from '../i18n' @@ -38,6 +40,10 @@ export function StartInCreateAction( const {appId} = useStudioAppIdStore(appIdCache) const {t} = useTranslation(createLocaleNamespace) + const schema = useSchema() + const schemaType = schema.get(type) + const isExcludedByOption = (schemaType?.type?.options as BaseSchemaTypeOptions | undefined) + ?.sanityCreate?.exclude const [isDialogOpen, setDialogOpen] = useState(false) const [isLinking, setLinking] = useState(false) @@ -53,7 +59,7 @@ export function StartInCreateAction( const createLinkId = (draft?._id ?? published?._id ?? liveEdit) ? id : `drafts.${id}` //appId will always be undefined when start in create is disabled via config - if (!appId || doc?._createdAt) { + if (isExcludedByOption || !appId || doc?._createdAt) { return null }