sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
1,938 lines (1,832 loc) • 131 kB
TypeScript
import {ActorRefFrom} from 'xstate'
import {ActorRefFromLogic} from 'xstate'
import {ArraySchemaType} from '@sanity/types'
import {AssetMetadataType} from '@sanity/types'
import {AssetSource} from '@sanity/types'
import {AssetSourceSpec} from '@sanity/types'
import {BooleanSchemaType} from '@sanity/types'
import {ButtonTone} from '@sanity/ui'
import {ClientConfig} from '@sanity/client'
import {ClientPerspective} from '@sanity/client'
import {ComponentType} from 'react'
import {CrossDatasetReferenceValue} from '@sanity/types'
import {CSSProperties} from 'react'
import {CurrentUser} from '@sanity/types'
import {DialogProps} from '@sanity/ui'
import {Diff} from '@sanity/diff'
import {EditorChange} from '@portabletext/editor'
import {EditorSelection} from '@portabletext/editor'
import {ErrorInfo} from 'react'
import {EventObject} from 'xstate'
import {FileValue} from '@sanity/types'
import {FocusEvent as FocusEvent_2} from 'react'
import {FocusEventHandler} from 'react'
import {FormEventHandler} from 'react'
import {FormNodeValidation} from '@sanity/types'
import {GeopointValue} from '@sanity/types'
import {HotkeyOptions} from '@portabletext/editor'
import {I18nTextRecord} from '@sanity/types'
import {ImageUrlFitMode} from '@sanity/types'
import {ImageValue} from '@sanity/types'
import {InitialValueProperty} from '@sanity/types'
import {InitialValueResolverContext} from '@sanity/types'
import {KeyedObject} from '@sanity/types'
import {KeyedSegment} from '@sanity/types'
import {MarkdownShortcutsPluginProps} from '@portabletext/plugin-markdown-shortcuts'
import {MetaObject} from 'xstate'
import {MutableRefObject} from 'react'
import {NonReducibleUnknown} from 'xstate'
import {NumberSchemaType} from '@sanity/types'
import {ObjectSchemaType} from '@sanity/types'
import {Observable} from 'rxjs'
import {ObservableActorLogic} from 'xstate'
import {OnCopyFn} from '@portabletext/editor'
import {OnPasteFn} from '@portabletext/editor'
import {Path} from '@sanity/types'
import {PathSegment} from '@sanity/types'
import {PortableTextBlock} from '@sanity/types'
import {PortableTextEditor} from '@portabletext/editor'
import {PortableTextObject} from '@sanity/types'
import {PreviewUrlResolver} from '@sanity/preview-url-secret/define-preview-url'
import {PromiseActorLogic} from 'xstate'
import {RangeDecoration} from '@portabletext/editor'
import {ReactNode} from 'react'
import {ReferenceValue} from '@sanity/types'
import {RefObject} from 'react'
import {ReleaseDocument} from '@sanity/client'
import {RootTheme} from '@sanity/ui/theme'
import {Router} from 'sanity/router'
import {RouterState} from 'sanity/router'
import {SanityClient} from '@sanity/client'
import {SanityDocument} from '@sanity/types'
import {SanityDocumentLike} from '@sanity/types'
import {Schema} from '@sanity/types'
import {SchemaType} from '@sanity/types'
import {SchemaTypeDefinition} from '@sanity/types'
import {SearchStrategy} from '@sanity/types'
import {Serializable} from '@sanity/presentation-comlink'
import {SerializableArray} from '@sanity/presentation-comlink'
import {SerializableObject} from '@sanity/presentation-comlink'
import {SerializablePrimitive} from '@sanity/presentation-comlink'
import {SlugValue} from '@sanity/types'
import {StackablePerspective} from '@sanity/client'
import {StateMachine} from 'xstate'
import {StringSchemaType} from '@sanity/types'
import {TFunction} from 'i18next'
import {TypographyPluginProps} from '@portabletext/plugin-typography'
import {User} from '@sanity/types'
import {ValidationMarker} from '@sanity/types'
declare interface Action extends NavbarActionBase {
onAction: () => void
selected: boolean
title: string
render?: undefined
}
/**
* @hidden
* @beta
*/
declare interface ActionComponent<ActionProps, ActionDescription> {
(props: ActionProps): ActionDescription | null
}
declare interface ActionWithCustomRender extends NavbarActionBase {
render: () => React.ReactElement
}
/**
* @hidden
* @beta */
declare interface ActiveToolLayoutProps {
renderDefault: (props: ActiveToolLayoutProps) => React.JSX.Element
activeTool: Tool
}
/**
* @public
* Config for the apps that are available in the studio.
*/
declare type AppsOptions = {
canvas?: {
enabled: boolean
/**
* To allow the "Link to canvas" action on localhost, or in studios not listed under Studios in https://www.sanity.io/manage
* provide a fallback origin as a string.
*
* The string must be the exactly equal `name` as shown for the Studio in manage, and the studio must have create-manifest.json available.
*
* If the provided fallback Studio does not expose create-manifest.json "Link to canvas" will fail when using the fallback.
*
* Example: `wonderful.sanity.studio`
*
* Keep in mind that when fallback origin is used, Canvas will use the schema types and dataset in the *deployed* Studio,
* not from localhost.
*
* To see data synced from Canvas in your localhost Studio, you must ensure that the deployed fallback studio uses the same
* workspace and schemas as your local configuration.
*
*/
fallbackStudioOrigin?: string
}
}
/**
* @hidden
* @public */
declare interface ArrayFieldProps extends BaseFieldProps {
schemaType: ArraySchemaType
value: unknown[] | undefined
collapsed?: boolean
collapsible?: boolean
onCollapse: () => void
onExpand: () => void
inputProps: ArrayOfObjectsInputProps
}
/**
* @hidden
* @beta */
declare interface ArrayInputCopyEvent<Item> {
items: Item[]
}
/**
* These are the props an implementation of the ArrayFunctions component will receive
*
*
* @hidden
* @beta
*/
declare interface ArrayInputFunctionsProps<Item, SchemaType extends ArraySchemaType> {
children?: ReactNode
onItemAppend: (itemValue: Item) => void
onChange: (event: PatchEvent) => void
onValueCreate: (type: SchemaType) => Item
onItemPrepend: (itemValue: Item) => void
path: Path
readOnly?: boolean
schemaType: SchemaType
value?: Item[]
}
/**
* @hidden
* @beta */
declare interface ArrayInputInsertEvent<Item> {
items: Item[]
position: 'before' | 'after'
referenceItem: KeyedSegment | number
skipInitialValue?: boolean
open?: boolean
}
/**
* @hidden
* @beta */
declare interface ArrayInputMoveItemEvent {
fromIndex: number
toIndex: number
}
/**
* @hidden
* @beta */
declare interface ArrayItemError {
kind: 'error'
key: string
index: number
error: InvalidItemTypeError
}
/** @public */
declare interface ArrayOfObjectsFormNode<
T extends any[] = KeyedObject[],
S extends ArraySchemaType = ArraySchemaType,
> extends BaseFormNode<T, S> {
/** The focus path of the form node. */
focusPath: Path
/**
* @hidden
* @beta */
members: ArrayOfObjectsMember[]
}
/**
* @hidden
* @public */
declare interface ArrayOfObjectsInputProps<
T extends {
_key: string
} = {
_key: string
},
S extends ArraySchemaType = ArraySchemaType,
>
extends BaseInputProps, Omit<ArrayOfObjectsFormNode<T[], S>, 'displayInlineChanges'> {
/**
* @hidden
* @beta */
arrayFunctions?: ComponentType<ArrayInputFunctionsProps<T, S>>
/**
* @hidden
* @beta */
onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void
/**
* @hidden
* @beta */
onItemAppend: (item: T) => void
/**
* @hidden
* @beta */
onItemPrepend: (item: T) => void
/**
* @hidden
* @beta */
onItemRemove: (itemKey: string) => void
/**
* @hidden
* @beta */
onItemMove: (event: ArrayInputMoveItemEvent) => void
/**
* @hidden
* @beta */
onInsert: (event: ArrayInputInsertEvent<T>) => void
/**
* @hidden
* @beta */
resolveInitialValue: (type: SchemaType, params: Record<string, unknown>) => Promise<T>
/**
* @hidden
* @beta */
resolveUploader: UploaderResolver<ObjectSchemaType>
/**
* @hidden
* @beta */
onUpload?: (event: UploadEvent) => void
/**
* @hidden
* @beta */
onSelectFile?: (props: InputOnSelectFileFunctionProps) => void
/**
* @hidden
* @beta */
onPathFocus: (path: Path, payload?: OnPathFocusPayload) => void
/**
* for array inputs using expand/collapse semantics for items
*
* @hidden
* @beta
*/
onItemCollapse: (itemKey: string) => void
/**
* @hidden
* @beta */
onItemExpand: (itemKey: string) => void
/**
* for array inputs using modal open/close semantics for items
*
* @hidden
* @beta
*/
onItemOpen: (path: Path) => void
/**
* @hidden
* @beta */
onItemClose: () => void
/**
* @hidden
* @beta */
renderAnnotation?: RenderAnnotationCallback
/**
* @hidden
* @beta */
renderBlock?: RenderBlockCallback
/**
* @hidden
* @beta */
renderInlineBlock?: RenderBlockCallback
/**
* @hidden
* @beta */
renderField: RenderFieldCallback
/**
* @hidden
* @beta */
renderInput: RenderInputCallback
/**
* @hidden
* @beta */
renderItem: RenderArrayOfObjectsItemCallback
/**
* @hidden
* @beta */
renderPreview: RenderPreviewCallback
/**
* @hidden
* @beta */
elementProps: ComplexElementProps
}
/**
* @hidden
* @beta */
declare interface ArrayOfObjectsItemMember<Node extends ObjectArrayFormNode = ObjectArrayFormNode> {
kind: 'item'
key: string
index: number
collapsed: boolean | undefined
collapsible: boolean | undefined
open: boolean
parentSchemaType: ArraySchemaType
/**
* @hidden
* @beta */
item: Node
}
/**
* @hidden
* @beta */
declare type ArrayOfObjectsMember = ArrayOfObjectsItemMember | ArrayItemError
/**
* @hidden
* @beta */
declare type ArrayOfPrimitivesElementType<T extends any[]> = T extends (infer K)[] ? K : unknown
/** @public */
declare interface ArrayOfPrimitivesFormNode<
T extends (string | number | boolean)[] = (string | number | boolean)[],
S extends ArraySchemaType = ArraySchemaType,
> extends BaseFormNode<T, S> {
/** The focus path of the form node. */
focusPath: Path
/**
* @hidden
* @beta */
members: ArrayOfPrimitivesMember[]
}
/**
* @hidden
* @public */
declare interface ArrayOfPrimitivesInputProps<
T extends string | boolean | number = string | boolean | number,
S extends ArraySchemaType = ArraySchemaType,
>
extends BaseInputProps, Omit<ArrayOfPrimitivesFormNode<T[], S>, 'displayInlineChanges'> {
/**
* @hidden
* @beta */
arrayFunctions?: ComponentType<ArrayInputFunctionsProps<T, S>>
onSetCollapsed: (collapsed: boolean) => void
/**
* @hidden
* @beta */
onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void
/**
* @hidden
* @beta */
onItemAppend: (item: ArrayOfPrimitivesElementType<T[]>) => void
/**
* @hidden
* @beta */
onItemPrepend: (item: ArrayOfPrimitivesElementType<T[]>) => void
/**
* @hidden
* @beta */
onItemRemove: (index: number) => void
/**
* @hidden
* @beta */
onMoveItem: (event: ArrayInputMoveItemEvent) => void
/**
* @hidden
* @beta */
onInsert: (event: {items: T[]; position: 'before' | 'after'; referenceIndex: number}) => void
/**
* @hidden
* @beta */
resolveUploader: UploaderResolver<NumberSchemaType | BooleanSchemaType | StringSchemaType>
/**
* @hidden
* @beta */
onUpload: (event: UploadEvent) => void
/**
* @hidden
* @beta */
onIndexFocus: (index: number) => void
/**
* @hidden
* @beta */
renderAnnotation?: RenderAnnotationCallback
/**
* @hidden
* @beta */
renderBlock?: RenderBlockCallback
/**
* @hidden
* @beta */
renderInlineBlock?: RenderBlockCallback
/**
* @hidden
* @beta */
renderInput: RenderInputCallback
/**
* @hidden
* @beta */
renderItem: RenderArrayOfPrimitivesItemCallback
/**
* @hidden
* @beta */
renderPreview: RenderPreviewCallback
/**
* @hidden
* @beta */
elementProps: ComplexElementProps
}
/**
* @hidden
* @beta */
declare interface ArrayOfPrimitivesItemMember<Node extends PrimitiveFormNode = PrimitiveFormNode> {
kind: 'item'
key: string
index: number
open: boolean
parentSchemaType: ArraySchemaType
/**
* @hidden
* @beta */
item: Node
}
/**
* @hidden
* @beta */
declare type ArrayOfPrimitivesMember = ArrayOfPrimitivesItemMember | ArrayItemError
/**
* @hidden
* @beta
*/
declare type AssetSourceResolver = ComposableOption<AssetSource[], ConfigContext>
/**
* @hidden
* @beta
*/
declare type AsyncComposableOption<TValue, TContext> = (
prev: TValue,
context: TContext,
) => Promise<TValue>
/**
* Authentication options
*
* @public
*/
declare interface AuthConfig {
/**
* Login method to use for the studio. Can be one of:
* - `dual` (default) - attempt to use cookies where possible, falling back to
* storing authentication token in `localStorage` otherwise
* - `cookie` - explicitly disable `localStorage` method, relying only on cookies. May fail due
* to cookies being treated as third-party cookies in some browsers, thus the default is `dual`.
* - `token` - explicitly disable cookies, relying only on `localStorage` method
*/
loginMethod?: LoginMethod
/**
* Whether to append the providers specified in `providers` with the default providers from the
* API, or replace the default providers with the ones specified.
*
* @deprecated Use the function form of `providers` instead for more control
*/
mode?: 'append' | 'replace'
/**
* If true, the "Choose login provider" (eg "Google, "GitHub", "E-mail/password") screen
* will be skipped if only a single provider is configured in the `providers` array -
* instead it will redirect unauthenticated users straight to the authentication URL.
*/
redirectOnSingle?: boolean
/**
* Array of authentication providers to use, or a function that takes an array of default
* authentication providers (fetched from the Sanity API) and should return a new list of
* providers. This can be used to selectively replace, add or remove providers from the
* list of choices.
*
* @remarks If a static array of providers is provided, the `mode` property is taken into account
* when determining what to do with it - `append` will append the providers to the default set
* of providers, while `replace` will replace the default providers with the ones specified.
*
* If not set, the default providers will be used.
*/
providers?: AuthProvider[] | ((prev: AuthProvider[]) => AuthProvider[] | Promise<AuthProvider[]>)
/**
* The API hostname for requests. Should usually be left undefined,
* but can be set if using custom cname for API domain.
*/
apiHost?: string
}
/**
* A provider of authentication.
*
* By default, a list of providers for a project will be fetched from the
* {@link https://api.sanity.io/v1/auth/providers | Sanity API}, but you may choose to limit this
* list by explicitly defining the providers you want to allow, or add additional custom providers
* that conforms to the authentication provider specification outlined in
* {@link https://www.sanity.io/docs/third-party-login | the documentation}.
*
* @public
*/
declare interface AuthProvider {
/**
* URL-friendly identifier/name for the provider, eg `github`
*/
name: string
/**
* Human friendly title for the provider, eg `GitHub`
*/
title: string
/**
* URL for the authentication endpoint that will trigger the authentication flow
*/
url: string
/**
* URL for a logo to display next to the provider in the login screen
*/
logo?: string
}
/**
* The unit an `AuthStore` emits to determine the user's authentication state.
*
* @beta
* @hidden
*/
declare interface AuthState {
/**
* Similar to a logged-in flag. This state is used in places like the
* `AuthBoundary` to determine whether or not it should render the
* `NotAuthenticatedComponent`. Implementers may choose to set this to `true`
* while also also emitting a `currentUser` of `null` if a `null` user is
* accepted (e.g. a project that doesn't require a login)
*/
authenticated: boolean
/**
* The value of the user logged in or `null` if none is provided
*/
currentUser: CurrentUser | null
/**
* A client that is expected to be pre-configured to allow for any downstream
* requests in the Studio
*/
client: SanityClient
}
/**
* The interface used by the Studio that produces a `SanityClient` and
* `CurrentUser` that gets passed to the resulting `Workspace`s and `Source`s.
*
* NOTE: This interface is primarily for internal use. Refer to
* `createAuthStore` instead.
*
* @beta
* @hidden
*/
declare interface AuthStore {
/**
* Emits `AuthState`s. This should update when the user's auth state changes.
* E.g. After a login, a new `AuthState` could be emitted with a non-null
* `currentUser` and `authenticated: true`
*
* NOTE: all auth store implementations should emit on subscribe using
* something like shareReplay(1) to ensure all new subscribers get an
* `AuthState` value on subscribe
*/
state: Observable<AuthState>
/**
* Emits auth tokens, or `null` if not configured to use them or they do not exist
*/
token?: Observable<string | null>
/**
* Custom auth stores are expected to implement a UI that initiates the user's
* authentication. For the typical case in `createAuthStore`, this means
* loading the providers and showing them as options to the user.
*/
LoginComponent?: ComponentType<LoginComponentProps>
/**
* Custom auth stores can implement a function that runs when the user logs
* out. The implementation is expected to remove all credentials both locally
* and on the server.
*/
logout?: () => void
/**
* Custom auth stores can implement a function that is designated to run when
* the Studio loads (e.g. to trade a session ID for a token in cookie-less
* mode). Within the Studio, this is called within the `AuthBoundary`.
*/
handleCallbackUrl?: () => Promise<void>
}
/**
* @hidden
* @beta
*/
declare interface BaseActionDescription {
disabled?: boolean
icon?: ReactNode | ComponentType
label: string
onHandle?: () => void
title?: ReactNode
tone?: ButtonTone
shortcut?: string | null
dialog?: unknown
}
/**
* @hidden
* @public */
declare interface BaseFieldProps {
/** @beta */
actions?: DocumentFieldAction[]
/** @internal @deprecated DO NOT USE */
__internal_comments?: FieldCommentsProps
/** @internal @deprecated ONLY USED BY AI ASSIST PLUGIN */
__internal_slot?: ReactNode
schemaType: SchemaType
title: string | undefined
description: string | undefined
/**
* @hidden
* @beta */
presence: FormNodePresence[]
validation: FormNodeValidation[]
level: number
inputId: string
value: unknown | undefined
path: Path
name: string
index: number
changed: boolean
children: ReactNode
version?: string
renderDefault: (props: FieldProps) => React.JSX.Element
}
/**
* @hidden
* @public
*/
declare interface BaseFormNode<
T = unknown,
S extends SchemaType = SchemaType,
> extends NodeDiffProps<ProvenanceDiffAnnotation, T> {
/** The unique identifier of the node. */
id: string
/** The schema type of the node. */
schemaType: S
/** The level of the node in the form hierarchy. */
level: number
/** The path of the node in the form hierarchy. */
path: Path
/**
* @hidden
* @beta */
presence: FormNodePresence[]
/** The validation markers of the node. */
validation: FormNodeValidation[]
/** The value of the node. */
value: T | undefined
/** Whether the node is read-only. */
readOnly?: boolean
/** Whether the node is focused. */
focused?: boolean
displayInlineChanges?: boolean
}
/**
* @hidden
* @public */
declare interface BaseInputProps {
renderDefault: (props: InputProps) => React.JSX.Element
/**
* Whether the input should display inline changes. Inline changes express how a field's value
* differs from its upstream version. Unlike custom diff components, inline changes is a mode
* that allows the input component itself to display the change in situ.
*/
displayInlineChanges: boolean
}
/**
* Props for the base item component.
*
* @public
*/
declare interface BaseItemProps<T> extends NodeDiffProps<ProvenanceDiffAnnotation> {
/** The schema type of the item. */
schemaType: SchemaType
/** The index of the item. */
index: number
/** The level of the item. */
level: number
/** The value of the item. */
value: unknown
/** The path of the item. */
path: Path
/** The title of the item. */
title: string | undefined
/** The description of the item. */
description: string | undefined
/** The ID of the input element. */
inputId: string
/** The function to call when the item receives focus. */
onFocus: (event: FocusEvent_2) => void
/** The function to call when the item loses focus. */
onBlur: (event: FocusEvent_2) => void
/** Whether the item is read-only. */
readOnly?: boolean
/** Whether the item is focused. */
focused?: boolean
/** The function to call when the item is removed. */
onRemove: () => void
/**
* @hidden
* @beta */
onInsert: (event: Omit<ArrayInputInsertEvent<T>, 'referenceItem'>) => void
/**
* @hidden
* @beta */
onCopy: (event: Omit<ArrayInputCopyEvent<T>, 'referenceItem'>) => void
/** The children of the item. */
children: ReactNode
/** The validation markers for the item. */
validation: FormNodeValidation[]
/**
* @hidden
* @beta */
presence: FormNodePresence[]
/** The function to call to render the default item. See {@link ItemProps} */
renderDefault: (props: ItemProps) => React.JSX.Element
}
/**
* @internal
* Configuration for studio beta features.
* */
declare interface BetaFeatures {
/** beta features with the form namespace */
form?: {
/**
* Enhanced Object Dialog is a new dialog for editing objects in the studio.
* @beta
*/
enhancedObjectDialog?: {
enabled: boolean
}
}
/**
* @deprecated - The Start in Create flow has been removed and will be updated in an upcoming studio release.
*/
create?: {
/**
* When true, a "Start in Sanity Create" action will be shown for all new documents, in place of regular document actions,
* when the following are true:
* - the origin of the current url is listed under Studios in sanity.to/manage (OR fallbackStudioOrigin is provided)
* - [origin]/static/create-manifest.json is available over HTTP GET
*
* The manifest file is automatically created and deployed when deploying studios with `sanity deploy`
*
* @see #fallbackStudioOrigin
*/
startInCreateEnabled?: boolean
/**
* To show the "Start in Create" button on localhost, or in studios not listed under Studios in https://www.sanity.io/manage
* provide a fallback origin as a string.
*
* The string must be the exactly equal `name` as shown for the Studio in manage, and the studio must have create-manifest.json available.
*
* If the provided fallback Studio does not expose create-manifest.json "Start in Sanity Create" will fail when using the fallback.
*
* Example: `wonderful.sanity.studio`
*
* Keep in mind that when fallback origin is used, Sanity Create will used the schema types and dataset in the *deployed* Studio,
* not from localhost.
*
* To see data synced from Sanity Create in your localhost Studio, you must ensure that the deployed fallback studio uses the same
* workspace and schemas as your local configuration.
*
* @see #startInCreateEnabled
*/
fallbackStudioOrigin?: string
}
/**
* Config for the history events API .
*
* If enabled, it will use the new events API to fetch document history.
*
* If it is not enabled, it will continue using the legacy Timeline.
*/
eventsAPI?: {
documents?: boolean
releases?: boolean
}
}
/**
* Props for rendering a Portable Text annotation
*
* @public
* @remarks If you want to render a mix of the annotated text and non-text content, you have to attribute
* the non-text containers with `contentEditable={false}`. See the second example.
* @example Simple example of customizing the annotation text to render yellow.
* ```ts
* (props: BlockAnnotationProps) =>
* props.renderDefault({
* ...props,
* textElement: <span style={{color: 'yellow'}}>{props.textElement}</span>,
* })
* ```
* @example Simple example of rendering the annotation with a custom modal for editing.
* Note that the form content container is attributed as `contentEditable={false}`.
* This is to signal to the text editor that this content isn't part of the editable text.
* ```ts
* (props: BlockAnnotationProps) => {
* return (
* <>
* // Render the annotated text
* <span onClick={props.onOpen}>
* {props.textElement}
* </span>
* // Render the editing form if the object is opened
* {props.open && (
* <Dialog
* contentEditable={false} // Attribute this as non-editable to the text editor
* header={`Edit ${props.schemaType.title}`}
* id={`dialog-${props.value._key}`}
* onClickOutside={props.onClose}
* onClose={props.onClose}
* >
* <Box margin={2} padding={2}>
* {props.children}
* </Box>
* </Dialog>
* )}
* </>
* )
* }
* ```
* */
declare interface BlockAnnotationProps {
/**
* Boundary element of the floating toolbar element.
*/
__unstable_floatingBoundary: HTMLElement | null
/**
* Boundary element where the text for this annotation appears.
*/
__unstable_referenceBoundary: HTMLElement | null
/**
* DOM element for the annotated text.
*/
__unstable_referenceElement: HTMLElement | null
/**
* Wether the annotated text node has editor focus.
* @remarks differs from `focused` which is wether the annotation object has form focus.
*/
__unstable_textElementFocus?: boolean
/**
* The input form for the annotation object.
* @remarks If you wrap this in something, you must make sure to put `contentEditable={false}` on the root container.
* Otherwise the editor will think content is part of the editable text and will error.
*/
children: ReactNode
/**
* If the editor form for this annotation object currently have form focus.
*/
focused: boolean
/**
* Markers (meta data) connected to this annotation.
* @deprecated - use `renderBlock` and `renderInlineBlock` interfaces instead
*/
markers: PortableTextMarker[]
/**
* Closes the editing form connected to this annotation.
*/
onClose: () => void
/**
* Opens the editing form connected to this annotation.
*/
onOpen: () => void
/**
* Focus a form node in the object for this annotation.
* @param path - the relative path to the form node to put focus on.
*/
onPathFocus: (path: Path) => void
/**
* Removes the annotation object from the text.
*/
onRemove: () => void
/**
* If the annotation is currently opened for editing.
*/
open: boolean
/**
* The parent schema type. For annotations this this the block type.
*/
parentSchemaType: SchemaType
/**
* The full form path to this annotation from document root.
*/
path: Path
/**
* Form presence for this annotation.
*/
presence: FormNodePresence[]
/**
* Is the annotation object read only?
*/
readOnly: boolean
/**
* Plugin chain render callback.
*/
renderAnnotation?: RenderAnnotationCallback
/**
* Plugin chain render callback.
*/
renderBlock?: RenderBlockCallback
/**
* Plugin chain render callback.
*/
renderDefault: (props: BlockAnnotationProps) => React.JSX.Element
/**
* Plugin chain render callback.
*/
renderField: RenderFieldCallback
/**
* Plugin chain render callback.
*/
renderInlineBlock?: RenderBlockCallback
/**
* Plugin chain render callback.
*/
renderInput: RenderInputCallback
/**
* Plugin chain render callback.
*/
renderItem: RenderArrayOfObjectsItemCallback
/**
* Plugin chain render callback.
*/
renderPreview: RenderPreviewCallback
/**
* The schema type for the annotation object.
*/
schemaType: ObjectSchemaType & {
i18nTitleKey?: string
}
/**
* If the annotated text currently is selected by the user.
*/
selected: boolean
/**
* React element of the text that is being annotated.
*/
textElement: React.JSX.Element
/**
* Form validation for the annotation object.
*/
validation: FormNodeValidation[]
/**
* Value of the annotation object.
*/
value: PortableTextObject
}
/**
* Props for rendering a Portable Text block
*
* @public
*/
declare interface BlockProps {
/**
* Boundary element of the floating toolbar element.
*/
__unstable_floatingBoundary: HTMLElement | null
/**
* Boundary element for the block.
*/
__unstable_referenceBoundary: HTMLElement | null
/**
* DOM element for the block.
*/
__unstable_referenceElement: HTMLElement | null
/**
* The default rendering of the block (the text).
*/
children: ReactNode
/**
* If the block currently is focused by the user.
*/
focused: boolean
/**
* Markers (meta data) connected to this annotation.
* @deprecated - use `renderBlock` and `renderInlineBlock` interfaces instead
*/
markers: PortableTextMarker[]
/**
* Closes the editing form connected to this block.
* For regular text blocks this is not relevant.
*/
onClose: () => void
/**
* Opens the editing form connected to this block.
* For regular text blocks this is not relevant.
*/
onOpen: () => void
/**
* Focus a form node in this block.
* @param path - the relative path to the form node to put focus on.
*/
onPathFocus: (path: Path) => void
/**
* Removes the block.
*/
onRemove: () => void
/**
* If the block is currently opened for editing.
*/
open: boolean
/**
* The parent schema type (array type).
*/
parentSchemaType: ArraySchemaType | ObjectSchemaType
/**
* The full form path to this block from document root.
*/
path: Path
/**
* Form presence for this block.
*/
presence: FormNodePresence[]
/**
* Is the block object read only?
*/
readOnly: boolean
/**
* Plugin chain render callback.
*/
renderAnnotation?: RenderAnnotationCallback
/**
* Plugin chain render callback.
*/
renderBlock?: RenderBlockCallback
/**
* Plugin chain render callback (default rendering function of the block).
*/
renderDefault: (props: BlockProps) => React.JSX.Element
/**
* Plugin chain render callback.
*/
renderField: RenderFieldCallback
/**
* Plugin chain render callback.
*/
renderInlineBlock?: RenderBlockCallback
/**
* Plugin chain render callback.
*/
renderInput: RenderInputCallback
/**
* Plugin chain render callback.
*/
renderItem: RenderArrayOfObjectsItemCallback
/**
* Plugin chain render callback.
*/
renderPreview: RenderPreviewCallback
/**
* The schema type for the block.
*/
schemaType: ObjectSchemaType
/**
* If the block is in the user's selection.
*/
selected: boolean
/**
* Form validation for the block object.
*/
validation: FormNodeValidation[]
/**
* Value of the block.
*/
value: PortableTextBlock
}
/**
* @hidden
* @public */
declare interface BooleanFieldProps extends BaseFieldProps {
schemaType: BooleanSchemaType
value: boolean | undefined
inputProps: BooleanInputProps
}
/** @public */
declare type BooleanFormNode<S extends BooleanSchemaType = BooleanSchemaType> = BaseFormNode<
boolean,
S
>
/**
* @hidden
* @public */
declare interface BooleanInputProps<S extends BooleanSchemaType = BooleanSchemaType>
extends BaseInputProps, Omit<BooleanFormNode<S>, 'displayInlineChanges'> {
/**
* @hidden
* @beta */
onChange: (patch: FormPatch | FormPatch[] | PatchEvent) => void
/**
* A shorthand aggregation of any validation errors the input currently have
* Will be falsey if no error.
* In the case of multiple errors it will be a newline delimited string of each error message
* For advanced use cases use the ´validation´ prop which contains more levels and details
*/
validationError?: string
/**
* @hidden
* @beta */
elementProps: PrimitiveInputElementProps
}
/**
* @hidden
* @beta */
declare type BufferedDocumentEvent =
| SnapshotEvent
| DocumentRebaseEvent
| DocumentMutationEvent
| CommittedEvent
declare interface CheckPermissionInput {
checkPermissionName: DocumentValuePermission
document: Partial<SanityDocument> | null
}
/**
* All possible URL search parameters used by the Presentation tool
* @public
*/
export declare interface CombinedSearchParams
extends StructureDocumentPaneParams, PresentationSearchParams {}
/**
* @hidden
* @beta */
declare interface CommittedEvent {
type: 'committed'
}
/**
* @hidden
* @beta */
declare interface ComplexElementProps {
'id': string
'onFocus': FocusEventHandler
'onBlur': FocusEventHandler
'ref': MutableRefObject<any>
'aria-describedby': string | undefined
}
/** @public */
declare type ComposableOption<TValue, TContext> = (prev: TValue, context: TContext) => TValue
/**
* @public
*/
declare type ComputeDiff<Annotation> = (value: unknown) => Diff<Annotation>
/** @public */
declare interface ConfigContext {
/**
* The ID of the project.
*/
projectId: string
/**
* The name of the dataset.
*/
dataset: string
/**
* The schema for this source.
*/
schema: Schema
/**
* The current user or `null` if not authenticated.
*/
currentUser: CurrentUser | null
/**
* A function that returns a Sanity client with the {@link SourceClientOptions | specified options}.
*/
getClient: (options: SourceClientOptions) => SanityClient
/**
* Localization resources
*/
i18n: LocaleSource
/** @beta */
[DECISION_PARAMETERS_SCHEMA]?: DecisionParametersConfig
}
/**
* Represents the connection status between the Sanity Studio and Presentation's preview iframe.
* @public
*/
export declare type ConnectionStatus = 'connected' | 'connecting' | 'reconnecting' | 'idle'
declare interface Context {
url: URL | null
error: Error | null
visualEditingOverlaysEnabled: boolean
}
declare interface Context_2 {
initialUrl: URL | null
previewUrl: URL | null
allowOrigins: URLPattern[] | null
error: Error | null
previewSearchParam: string | null
previewUrlSecret: {
secret: string
expiresAt: Date
} | null
previewAccessSharingCreatePermission: PermissionCheckResult | null
previewAccessSharingReadPermission: PermissionCheckResult | null
previewAccessSharingUpdatePermission: PermissionCheckResult | null
previewUrlSecretPermission: PermissionCheckResult | null
previewMode: PreviewUrlPreviewMode | null
}
/**
* Generic function type used in `DocumentResolver` definitions that receives a `DocumentResolverContext` and returns a computed value.
* @param context - `DocumentResolverContext` containing route information (origin, params, path)
* @returns Computed value based on the context (typically a string for filters or an object for parameters)
* @public
*/
export declare type ContextFn<T> = (context: DocumentResolverContext) => T
/**
* Symbol for configuring decision parameters schema
* @beta
*/
declare const DECISION_PARAMETERS_SCHEMA: unique symbol
/**
* Configuration for decision parameters
* @beta
*/
declare interface DecisionParametersConfig {
[key: string]: string[]
}
/** @beta */
declare type DefaultPluginsWorkspaceOptions = {
tasks: {
enabled: boolean
}
scheduledDrafts: {
enabled: boolean
}
scheduledPublishing: ScheduledPublishingPluginOptions
releases: {
enabled?: boolean
/**
* Limit the number of releases that can be created by this workspace.
*/
limit?: number
/**
* Actions for releases.
*/
actions?: ReleaseActionComponent[] | ReleaseActionsResolver
}
mediaLibrary?: MediaLibraryConfig
}
/**
* Define documents for a given location.
* This function doesn't do anything itself, it is used to provide type information.
* @param resolvers - resolvers that return documents.
* @public
*/
export declare function defineDocuments(resolvers: DocumentResolver[]): typeof resolvers
/**
* Define locations for a given document type.
* This function doesn't do anything itself, it is used to provide type information.
* @param resolver - resolver that return locations for a document.
* @public
*/
export declare function defineLocations<K extends string>(
resolver: DocumentLocationResolverObject<K> | DocumentLocationsState,
): typeof resolver
/**
* @deprecated the `previewUrl.initial`, `previewUrl.allowOrigins` and `previewUrl.previewMode.enable` supports async functions that offer advanced control over how preview URLs are resolved
* @public
*/
declare type DeprecatedPreviewUrlResolver = PreviewUrlResolver<SanityClient>
/**
* @hidden
* @beta */
declare interface DocumentActionComponent extends ActionComponent<
DocumentActionProps,
DocumentActionDescription
> {
/**
* An optional meta property that can used to replace this document action
* with another. E.g.:
*
* ```js
* import {defineConfig} from 'sanity'
* import {MyPublishAction} from '...'
*
* export default defineConfig({
* document: {
* actions: (prev) =>
* prev.map((previousAction) =>
* previousAction.action === 'publish' ? MyPublishAction : previousAction
* ),
* },
* })
* ```
*/
action?: SanityDefinedAction
/**
* For debugging purposes
*/
displayName?: string
}
/**
* @hidden
* @beta */
declare interface DocumentActionConfirmDialogProps {
type: 'confirm'
tone?: ButtonTone
message: ReactNode
onConfirm: () => void
onCancel: () => void
cancelButtonIcon?: ComponentType | ReactNode
cancelButtonText?: string
confirmButtonIcon?: ComponentType | ReactNode
confirmButtonText?: string
}
/**
* @hidden
* @beta */
declare interface DocumentActionCustomDialogComponentProps {
type: 'custom'
component: ReactNode
}
/**
* @hidden
* @beta
*/
declare interface DocumentActionDescription extends GroupableActionDescription<DocumentActionGroup> {
dialog?: DocumentActionDialogProps | false | null
}
/**
* @hidden
* @beta */
declare type DocumentActionDialogProps =
| DocumentActionConfirmDialogProps
| DocumentActionPopoverDialogProps
| DocumentActionModalDialogProps
| DocumentActionCustomDialogComponentProps
/**
* @hidden
* @beta */
declare type DocumentActionGroup = 'default' | 'paneActions'
/**
* @hidden
* @beta */
declare interface DocumentActionModalDialogProps {
type?: 'dialog'
content: ReactNode
/**
*
* @hidden
* @beta
*/
footer?: DialogProps['footer']
/**
*
* @hidden
* @beta
*/
header?: ReactNode
onClose: () => void
showCloseButton?: boolean
/**
*
* @hidden
* @beta
*/
width?: 'small' | 'medium' | 'large' | 'full'
}
/**
* @hidden
* @beta */
declare interface DocumentActionPopoverDialogProps {
type: 'popover'
content: ReactNode
onClose: () => void
}
/**
* @hidden
* @beta */
declare interface DocumentActionProps extends EditStateFor {
revision?: string
/**
* @deprecated - do not use, will be removed in a future major version, use local state instead, for example call `setDialogOpen(false)` in dialog's `onCancel` callback.
*/
onComplete: () => void
/**
* Whether the initial value has been resolved.
*/
initialValueResolved: boolean
}
/**
* @hidden
* @beta
*/
declare interface DocumentActionsContext extends ConfigContext {
documentId?: string
schemaType: string
/** releaseId of the open document, it's undefined if it's published or the draft */
releaseId: string | undefined
/** the type of the currently active document. */
versionType: DocumentActionsVersionType
}
/**
* @hidden
* @beta
*/
declare type DocumentActionsResolver = ComposableOption<
DocumentActionComponent[],
DocumentActionsContext
>
/**
* @hidden
* @beta
*/
declare type DocumentActionsVersionType =
| 'published'
| 'draft'
| 'revision'
| 'version'
| 'scheduled-draft'
/**
* @hidden
* @beta */
declare interface DocumentBadgeComponent extends HookCollectionActionHook<
DocumentBadgeProps,
DocumentBadgeDescription
> {
(props: DocumentBadgeProps): DocumentBadgeDescription | null
}
/**
* @hidden
* @beta */
declare interface DocumentBadgeDescription {
title?: string
label?: string | undefined
color?: 'primary' | 'success' | 'warning' | 'danger'
icon?: ReactNode | ComponentType
}
/**
* @hidden
* @beta */
declare interface DocumentBadgeProps extends EditStateFor {}
/**
* @hidden
* @beta
*/
declare interface DocumentBadgesContext extends ConfigContext {
documentId?: string
schemaType: string
}
/**
* @hidden
* @beta
*/
declare type DocumentBadgesResolver = ComposableOption<
DocumentBadgeComponent[],
DocumentBadgesContext
>
/** @hidden @beta */
declare interface DocumentCommentsEnabledContext {
documentId?: string
documentType: string
}
declare interface DocumentComponents {
/** @internal */
unstable_layout?: ComponentType<DocumentLayoutProps>
}
/**
* @hidden
* @beta */
declare interface DocumentFieldAction {
name: string
useAction: DocumentFieldActionHook
}
/**
* @hidden
* @beta */
declare interface DocumentFieldActionDivider {
type: 'divider'
}
/**
* @hidden
* @beta */
declare interface DocumentFieldActionGroup {
type: 'group'
children: DocumentFieldActionNode[]
disabled?:
| boolean
| {
reason: ReactNode
}
expanded?: boolean
hidden?: boolean
icon?: ComponentType
renderAsButton?: boolean
status?: DocumentFieldActionStatus
title: string
i18n?: I18nTextRecord<'title'>
tone?: DocumentFieldActionTone
}
/**
* @hidden
* @beta */
declare interface DocumentFieldActionHook {
(props: DocumentFieldActionProps): DocumentFieldActionItem | DocumentFieldActionGroup
}
/**
* @hidden
* @beta */
declare interface DocumentFieldActionItem {
type: 'action'
disabled?:
| boolean
| {
reason: ReactNode
}
hidden?: boolean
icon?: ComponentType
iconRight?: ComponentType
onAction: () => void
renderAsButton?: boolean
selected?: boolean
status?: DocumentFieldActionStatus
title: string
i18n?: I18nTextRecord<'title'>
tone?: DocumentFieldActionTone
}
/**
* @hidden
* @beta */
declare type DocumentFieldActionNode =
| DocumentFieldActionItem
| DocumentFieldActionGroup
| DocumentFieldActionDivider
/**
* @hidden
* @beta */
declare interface DocumentFieldActionProps {
documentId: string
documentType: string
path: Path
schemaType: SchemaType
}
/**
* @hidden
* @beta */
declare type DocumentFieldActionsResolver = ComposableOption<
DocumentFieldAction[],
DocumentFieldActionsResolverContext
>
/**
* @hidden
* @beta */
declare interface DocumentFieldActionsResolverContext extends ConfigContext {
documentId: string
documentType: string
schemaType: SchemaType
}
/**
* @hidden
* @beta */
declare type DocumentFieldActionStatus = 'info' | 'success' | 'warning' | 'error'
/**
* @hidden
* @beta */
declare type DocumentFieldActionTone = 'primary' | 'positive' | 'caution' | 'critical'
declare interface DocumentInRelease {
memoKey: string
isPending?: boolean
document: SanityDocument & {
publishedDocumentExists: boolean
}
validation: DocumentValidationStatus
}
/** @hidden @beta */
declare interface DocumentInspector {
name: string
component: DocumentInspectorComponent
/**
* Hook for defining a menu item for the inspector.
*/
useMenuItem?: (props: DocumentInspectorUseMenuItemProps) => DocumentInspectorMenuItem
/**
* Callback for when the inspector is closed, which can be used to clean up custom document pane
* parameters.
*/
onClose?: (ctx: {params: Record<string, string | undefined>}) => {
params: Record<string, string | undefined>
}
/**
* Callback for when the inspector is opened, which can be used to set custom document pane
* parameters.
*/
onOpen?: (ctx: {params: Record<string, string | undefined>}) => {
params: Record<string, string | undefined>
}
}
/** @hidden @beta */
declare type DocumentInspectorComponent = ComponentType<DocumentInspectorProps>
/** @hidden @beta */
declare interface DocumentInspectorContext extends ConfigContext {
documentId?: string
documentType: string
}
/** @hidden @beta */
declare interface DocumentInspectorMenuItem {
hidden?: boolean
hotkeys?: string[]
icon?: ComponentType
showAsAction?: boolean
status?: ButtonTone
title: string
tone?: ButtonTone
}
/** @hidden @beta */
declare interface DocumentInspectorProps {
documentId: string
documentType: string
onClose: () => void
}
/** @hidden @beta */
declare type DocumentInspectorsResolver = ComposableOption<
DocumentInspector[],
DocumentInspectorContext
>
/** @hidden @beta */
declare interface DocumentInspectorUseMenuItemProps {
documentId: string
documentType: string
}
/**
*
* @hidden
* @beta
*/
declare type DocumentLanguageFilterComponent = ComponentType<{
schemaType: ObjectSchemaType
}>
/**
*
* @hidden
* @beta
*/
declare interface DocumentLanguageFilterContext extends ConfigContext {
documentId?: string
schemaType: string
}
/**
*
* @hidden
* @beta
*/
declare type DocumentLanguageFilterResolver = ComposableOption<
DocumentLanguageFilterComponent[],
DocumentLanguageFilterContext
>
/** @internal*/
declare interface DocumentLayoutProps {
/**
* The ID of the document. This is a read-only property and changing it will have no effect.
*/
documentId: string
/**
* The type of the document. This is a read-only property and changing it will have no effect.
*/
documentType: string
renderDefault: (props: DocumentLayoutProps) => React.JSX.Element
}
/**
* Represents a document location
* @public
*/
export declare interface DocumentLocation {
/**
* Title of the document
*/
title: string
/**
* URL of the document location
*/
href: string
}
/**
* Function used for advanced document location resolution
* @param params - Object with document `id` and document `type` properties
* @param context - Object with `documentStore` property for creating listenQuery subscriptions
* @returns Document location state, optionally as an Observable, or null/undefined if no locations are available
* @public
*/
export declare type DocumentLocationResolver = (
params: {
id: string
type: string
version: string | undefined
perspectiveStack: StackablePerspective[]
},
context: {
documentStore: DocumentStore
},
) =>
| DocumentLocationsState
| null
| undefined
| Observable<DocumentLocationsState | null | undefined>
/**
* Document location resolver object
* @public
*/
export declare type DocumentLocationResolverObject<K extends string = string> = {
/**
* Object for selecting document fields
*/
select: Record<K, string>
/**
* Function that accepts a document with the selected fields and returns an optional document location state
*/
resolve: (value: Record<K, any> | null) => DocumentLocationsState | null | undefined | void
}
/**
* Object of document location resolver definitions per document type
* @public
*/
export declare type DocumentLocationResolvers = Record<
string,
DocumentLocationResolverObject | DocumentLocationsState
>
/**
* State for describing document locations or providing a message if locations are unavailable
* @public
*/
export declare interface DocumentLocationsState {
/**
* Array of document locations
*/
locations?: DocumentLocation[]
/**
* Message to display if locations are unavailable
*/
message?: string
/**
* Tone of the message
*/
tone?: 'positive' | 'caution' | 'critical'
}
/**
* @hidden
* @beta */
declare interface DocumentMutationEvent {
type: 'mutation'
document: SanityDocument
mutations: MutationPayload[]
origin: 'local' | 'remote'
}
/**
* @hidden
* @beta
*/
declare interface DocumentPluginOptions {
badges?: DocumentBadgeComponent[] | DocumentBadgesResolver
actions?: DocumentActionComponent[] | DocumentActionsResolver
/**
* Components for the document.
* @internal
*/
components?: DocumentComponents
/** @internal */
unstable_fieldActions?: DocumentFieldAction[] | DocumentFieldActionsResolver
/** @hidden @beta */
inspectors?: DocumentInspector[] | DocumentInspectorsResolver
/**
* @hidden
* @beta
*/
productionUrl?: AsyncComposableOption<string | undefined, ResolveProductionUrlContext>
/**
* @hidden
* @beta
*/
unstable_languageFilter?: DocumentLanguageFilterResolver
/**
* @hidden
* @beta
*/
newDocumentOptions?: NewDocumentOptionsResolver
/** @deprecated Use `comments` instead */
unstable_comments?: {
enabled: boolean | ((context: DocumentCommentsEnabledContext) => boolean)
}
/** @internal */
comments?: {
enabled: boolean | ((context: DocumentCommentsEnabledContext) => boolean)
}
drafts?: {
/**
* Whether the workspace provides the draft model for interacting with documents.
*
* When switched off, documents may only be edited:
*
* - Inside a release.
* - Outside a release if they support live-edit.
*/
enabled?: boolean
}
}
/**
* @hidden
* @beta */
declare interface DocumentRebaseEvent {
type: 'rebase'
document: SanityDocument
remoteMutations: MutationPayload[]
localMutations: MutationPayload[]
}
/**
* @hidden
* @beta */
declare interface DocumentRemoteMutationEvent {
type: 'r