@portabletext/editor
Version:
Portable Text Editor made in React
1,967 lines (1,913 loc) • 229 kB
TypeScript
import {Patch} from '@portabletext/patches'
import type {
ArrayDefinition,
ArraySchemaType,
BlockDecoratorDefinition,
BlockListDefinition,
BlockStyleDefinition,
ObjectSchemaType,
Path,
PortableTextListBlock,
TypedObject,
} from '@sanity/types'
import {
PortableTextBlock,
PortableTextChild,
PortableTextObject,
PortableTextSpan,
PortableTextTextBlock,
} from '@sanity/types'
import type {
BaseSyntheticEvent,
ClipboardEvent as ClipboardEvent_2,
KeyboardEvent as KeyboardEvent_2,
default as React_2,
ReactElement,
RefObject,
} from 'react'
import {
Component,
FocusEvent as FocusEvent_2,
ForwardRefExoticComponent,
JSX,
MutableRefObject,
PropsWithChildren,
RefAttributes,
TextareaHTMLAttributes,
} from 'react'
import type {Observable, Subject} from 'rxjs'
import {BaseRange, Descendant} from 'slate'
import type {Operation} from 'slate'
import type {DOMNode} from 'slate-dom'
import type {ReactEditor} from 'slate-react'
import {
ActionArgs,
ActionFunction,
ActorRef,
ActorRefFrom,
ActorRefFromLogic,
AnyActorLogic,
AnyActorRef,
AnyEventObject,
ConditionalRequired,
InputFrom,
IsNotNever,
MachineSnapshot,
MetaObject,
NonReducibleUnknown,
RequiredLogicInput,
StateMachine,
StateValue,
Values,
} from 'xstate'
import type {EventObject, Snapshot} from 'xstate'
import {GuardArgs} from 'xstate/guards'
import {
AnnotationPath as AnnotationPath_2,
BlockOffset as BlockOffset_2,
BlockPath as BlockPath_2,
ChildPath as ChildPath_2,
Editor as Editor_2,
InvalidValueResolution as InvalidValueResolution_2,
} from '..'
import {
Behavior as Behavior_2,
CustomBehaviorEvent as CustomBehaviorEvent_2,
InsertPlacement as InsertPlacement_2,
NativeBehaviorEvent as NativeBehaviorEvent_2,
} from '../behaviors'
import {
InputBehaviorEvent as InputBehaviorEvent_2,
MouseBehaviorEvent as MouseBehaviorEvent_2,
} from '../behaviors/behavior.types.event'
import {MIMEType as MIMEType_2} from '../internal-utils/mime-type'
import {EditorPriority as EditorPriority_2} from '../priority/priority.types'
import {
PickFromUnion as PickFromUnion_2,
StrictExtract as StrictExtract_2,
} from '../type-utils'
import {BlockWithOptionalKey as BlockWithOptionalKey_2} from '../types/block-with-optional-key'
declare type AbstractBehaviorEvent =
| {
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.set'>
at: AnnotationPath
props: Record<string, unknown>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'annotation.toggle'>
annotation: {
name: string
value: {
[prop: string]: unknown
}
}
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'decorator.toggle'>
decorator: string
at?: {
anchor: BlockOffset
focus: BlockOffset
}
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
unit: 'character' | 'word' | 'line' | 'block'
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
at: BlockPath
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'delete.child'>
at: ChildPath
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
unit: 'character' | 'word' | 'line' | 'block'
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
at: {
anchor: BlockOffset
focus: BlockOffset
}
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'deserialize'>
originEvent:
| PickFromUnion<
NativeBehaviorEvent,
'type',
'drag.drop' | 'clipboard.paste'
>
| InputBehaviorEvent
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'serialize'>
originEvent: PickFromUnion<
NativeBehaviorEvent,
'type',
'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.success'>
mimeType: MIMEType
data: Array<PortableTextBlock>
originEvent:
| PickFromUnion<
NativeBehaviorEvent,
'type',
'drag.drop' | 'clipboard.paste'
>
| InputBehaviorEvent
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'deserialization.failure'>
mimeType: MIMEType
reason: string
originEvent:
| PickFromUnion<
NativeBehaviorEvent,
'type',
'drag.drop' | 'clipboard.paste'
>
| InputBehaviorEvent
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'serialization.success'>
mimeType: MIMEType
data: string
originEvent: PickFromUnion<
NativeBehaviorEvent,
'type',
'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'serialization.failure'>
mimeType: MIMEType
reason: string
originEvent: PickFromUnion<
NativeBehaviorEvent,
'type',
'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
blocks: Array<BlockWithOptionalKey>
placement: InsertPlacement
select?: 'start' | 'end' | 'none'
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'insert.break'>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'insert.soft break'>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'list item.add'>
listItem: string
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'list item.remove'>
listItem: string
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'list item.toggle'>
listItem: string
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'move.block down'>
at: BlockPath
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'move.block up'>
at: BlockPath
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'select.previous block'>
select?: 'start' | 'end'
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'select.next block'>
select?: 'start' | 'end'
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'split'>
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'style.add'>
style: string
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'style.remove'>
style: string
}
| {
type: StrictExtract<SyntheticBehaviorEventType, 'style.toggle'>
style: string
}
/**************************************
* Abstract events
**************************************/
declare const abstractBehaviorEventTypes: readonly [
'annotation.set',
'annotation.toggle',
'decorator.toggle',
'delete.backward',
'delete.block',
'delete.child',
'delete.forward',
'delete.text',
'deserialize',
'deserialization.success',
'deserialization.failure',
'insert.blocks',
'insert.break',
'insert.soft break',
'list item.add',
'list item.remove',
'list item.toggle',
'move.block down',
'move.block up',
'select.previous block',
'select.next block',
'serialize',
'serialization.success',
'serialization.failure',
'split',
'style.add',
'style.remove',
'style.toggle',
]
/**
* @public
*/
export declare type AddedAnnotationPaths = {
/**
* @deprecated An annotation may be applied to multiple blocks, resulting
* in multiple `markDef`'s being created. Use `markDefPaths` instead.
*/
markDefPath: Path
markDefPaths: Array<Path>
/**
* @deprecated Does not return anything meaningful since an annotation
* can span multiple blocks and spans. If references the span closest
* to the focus point of the selection.
*/
spanPath: Path
}
/**
* @public
*/
export declare type AnnotationDefinition<
TBaseDefinition extends BaseDefinition = BaseDefinition,
> = TBaseDefinition & {
fields?: ReadonlyArray<FieldDefinition>
}
/**
* @public
*/
export declare type AnnotationPath = [
{
_key: string
},
'markDefs',
{
_key: string
},
]
/**
* @public
*/
export declare type AnnotationSchemaType = BaseDefinition & {
fields: ReadonlyArray<FieldDefinition>
}
/**
* @public
*/
export declare type BaseDefinition = {
name: string
title?: string
}
/**
* @beta
*/
declare type Behavior<
TBehaviorEventType extends
| '*'
| `${BehaviorEventTypeNamespace}.*`
| BehaviorEvent['type'] =
| '*'
| `${BehaviorEventTypeNamespace}.*`
| BehaviorEvent['type'],
TGuardResponse = true,
TBehaviorEvent extends
ResolveBehaviorEvent<TBehaviorEventType> = ResolveBehaviorEvent<TBehaviorEventType>,
> = {
/**
* Editor Event that triggers this Behavior.
*/
on: TBehaviorEventType
/**
* Predicate function that determines if the Behavior should be executed.
* Returning a non-nullable value from the guard will pass the value to the
* actions and execute them.
*/
guard?: BehaviorGuard<TBehaviorEvent, TGuardResponse>
/**
* Array of Behavior Action sets.
* Each set represents a step in the history stack.
*/
actions: Array<BehaviorActionSet<TBehaviorEvent, TGuardResponse>>
}
/**
* @beta
*/
declare type BehaviorAction =
| {
type: 'execute'
event: SyntheticBehaviorEvent
}
| {
type: 'forward'
event: NativeBehaviorEvent | SyntheticBehaviorEvent | CustomBehaviorEvent
}
| {
type: 'raise'
event: SyntheticBehaviorEvent | CustomBehaviorEvent
}
| {
type: 'effect'
effect: () => void
}
/**
* @beta
*/
declare type BehaviorActionSet<TBehaviorEvent, TGuardResponse> = (
payload: {
snapshot: EditorSnapshot
event: TBehaviorEvent
dom: EditorDom
},
guardResponse: TGuardResponse,
) => Array<BehaviorAction>
declare type BehaviorConfig = {
behavior: Behavior
priority: EditorPriority
}
/**
* @beta
*/
declare type BehaviorEvent =
| SyntheticBehaviorEvent
| NativeBehaviorEvent
| CustomBehaviorEvent
declare type BehaviorEventTypeNamespace =
| SyntheticBehaviorEventNamespace
| NativeBehaviorEventNamespace
| CustomBehaviorEventNamespace
/**
* @beta
*/
declare type BehaviorGuard<TBehaviorEvent, TGuardResponse> = (payload: {
snapshot: EditorSnapshot
event: TBehaviorEvent
dom: EditorDom
}) => TGuardResponse | false
/** @beta */
export declare interface BlockAnnotationRenderProps {
block: PortableTextBlock
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
path: Path
schemaType: ObjectSchemaType
selected: boolean
/** @deprecated Use `schemaType` instead */
type: ObjectSchemaType
value: PortableTextObject
}
/** @beta */
export declare interface BlockChildRenderProps {
annotations: PortableTextObject[]
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
path: Path
selected: boolean
schemaType: ObjectSchemaType
/** @deprecated Use `schemaType` instead */
type: ObjectSchemaType
value: PortableTextChild
}
/** @beta */
export declare interface BlockDecoratorRenderProps {
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
path: Path
schemaType: BlockDecoratorDefinition
selected: boolean
/** @deprecated Use `schemaType` instead */
type: BlockDecoratorDefinition
value: string
}
/** @beta */
export declare interface BlockListItemRenderProps {
block: PortableTextTextBlock
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
level: number
path: Path
schemaType: BlockListDefinition
selected: boolean
value: string
}
/**
* @public
*/
export declare type BlockObjectDefinition<
TBaseDefinition extends BaseDefinition = BaseDefinition,
> = TBaseDefinition & {
fields?: ReadonlyArray<FieldDefinition>
}
/**
* @public
*/
export declare type BlockObjectSchemaType = BaseDefinition & {
fields: ReadonlyArray<FieldDefinition>
}
/**
* @beta
*/
export declare type BlockOffset = {
path: BlockPath
offset: number
}
/**
* @public
*/
export declare type BlockPath = [
{
_key: string
},
]
/** @beta */
export declare interface BlockRenderProps {
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
level?: number
listItem?: string
path: BlockPath
selected: boolean
style?: string
schemaType: ObjectSchemaType
/** @deprecated Use `schemaType` instead */
type: ObjectSchemaType
value: PortableTextBlock
}
/** @beta */
export declare interface BlockStyleRenderProps {
block: PortableTextTextBlock
children: ReactElement<any>
editorElementRef: RefObject<HTMLElement | null>
focused: boolean
path: Path
selected: boolean
schemaType: BlockStyleDefinition
value: string
}
declare type BlockWithOptionalKey =
| TextBlockWithOptionalKey
| ObjectBlockWithOptionalKey
/**
* The editor blurred
* @beta */
export declare type BlurChange = {
type: 'blur'
event: FocusEvent_2<HTMLDivElement, Element>
}
/**
* @public
*/
export declare type ChildPath = [
{
_key: string
},
'children',
{
_key: string
},
]
declare type ClipboardBehaviorEvent =
| {
type: StrictExtract<NativeBehaviorEventType, 'clipboard.copy'>
originEvent: {
dataTransfer: DataTransfer
}
position: Pick<EventPosition, 'selection'>
}
| {
type: StrictExtract<NativeBehaviorEventType, 'clipboard.cut'>
originEvent: {
dataTransfer: DataTransfer
}
position: Pick<EventPosition, 'selection'>
}
| {
type: StrictExtract<NativeBehaviorEventType, 'clipboard.paste'>
originEvent: {
dataTransfer: DataTransfer
}
position: Pick<EventPosition, 'selection'>
}
/**
* The editor was either connected or disconnected to the network
* To show out of sync warnings etc when in collaborative mode.
* @beta
* @deprecated The change is no longer emitted
* */
export declare type ConnectionChange = {
type: 'connection'
value: 'online' | 'offline'
}
declare type Converter<TMIMEType extends MIMEType = MIMEType> = {
mimeType: TMIMEType
serialize: Serializer<TMIMEType>
deserialize: Deserializer<TMIMEType>
}
declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
| {
type: 'serialize'
originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
}
| {
type: 'serialization.failure'
mimeType: TMIMEType
originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
reason: string
}
| {
type: 'serialization.success'
data: string
mimeType: TMIMEType
originEvent: 'clipboard.copy' | 'clipboard.cut' | 'drag.dragstart'
}
| {
type: 'deserialize'
data: string
}
| {
type: 'deserialization.failure'
mimeType: TMIMEType
reason: string
}
| {
type: 'deserialization.success'
data: Array<PortableTextBlock>
mimeType: TMIMEType
}
/**
* @beta
*/
declare type CustomBehaviorEvent<
TPayload extends Record<string, unknown> = Record<string, unknown>,
TType extends string = string,
TInternalType extends CustomBehaviorEventType<
'custom',
TType
> = CustomBehaviorEventType<'custom', TType>,
> = {
type: TInternalType
} & TPayload
/**************************************
* Custom events
**************************************/
declare type CustomBehaviorEventNamespace = 'custom'
declare type CustomBehaviorEventType<
TNamespace extends CustomBehaviorEventNamespace,
TType extends string = '',
> = TType extends '' ? `${TNamespace}` : `${TNamespace}.${TType}`
declare type DecoratedRange = BaseRange & {
rangeDecoration: RangeDecoration
}
/**
* @public
*/
export declare type DecoratorDefinition<
TBaseDefinition extends BaseDefinition = BaseDefinition,
> = TBaseDefinition
/**
* @public
*/
export declare type DecoratorSchemaType = BaseDefinition & {
/**
* @deprecated
* Use `name` instead
*/
value: string
}
/**
* @public
* A helper wrapper that adds editor support, such as autocomplete and type checking, for a schema definition.
* @example
* ```ts
* import { defineSchema } from '@portabletext/editor'
*
* const schemaDefinition = defineSchema({
* decorators: [{name: 'strong'}, {name: 'em'}, {name: 'underline'}],
* annotations: [{name: 'link'}],
* styles: [
* {name: 'normal'},
* {name: 'h1'},
* {name: 'h2'},
* {name: 'h3'},
* {name: 'blockquote'},
* ],
* lists: [],
* inlineObjects: [],
* blockObjects: [],
* }
* ```
*/
export declare function defineSchema<
const TSchemaDefinition extends SchemaDefinition,
>(definition: TSchemaDefinition): TSchemaDefinition
declare type Deserializer<TMIMEType extends MIMEType> = ({
snapshot,
event,
}: {
snapshot: EditorSnapshot
event: PickFromUnion<ConverterEvent<TMIMEType>, 'type', 'deserialize'>
}) => PickFromUnion<
ConverterEvent<TMIMEType>,
'type',
'deserialization.success' | 'deserialization.failure'
>
declare type DragBehaviorEvent =
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.dragstart'>
originEvent: {
clientX: number
clientY: number
dataTransfer: DataTransfer
}
position: Pick<EventPosition, 'selection'>
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.drag'>
originEvent: {
dataTransfer: DataTransfer
}
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.dragend'>
originEvent: {
dataTransfer: DataTransfer
}
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.dragenter'>
originEvent: {
dataTransfer: DataTransfer
}
position: EventPosition
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.dragover'>
originEvent: {
dataTransfer: DataTransfer
}
dragOrigin?: Pick<EventPosition, 'selection'>
position: EventPosition
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.drop'>
originEvent: {
dataTransfer: DataTransfer
}
dragOrigin?: Pick<EventPosition, 'selection'>
position: EventPosition
}
| {
type: StrictExtract<NativeBehaviorEventType, 'drag.dragleave'>
originEvent: {
dataTransfer: DataTransfer
}
}
/** @beta */
export declare interface EditableAPI {
activeAnnotations: () => PortableTextObject[]
isAnnotationActive: (annotationType: PortableTextObject['_type']) => boolean
addAnnotation: <
TSchemaType extends {
name: string
},
>(
type: TSchemaType,
value?: {
[prop: string]: unknown
},
) =>
| {
markDefPath: Path
markDefPaths: Array<Path>
spanPath: Path
}
| undefined
blur: () => void
delete: (
selection: EditorSelection,
options?: EditableAPIDeleteOptions,
) => void
findByPath: (
path: Path,
) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
findDOMNode: (
element: PortableTextBlock | PortableTextChild,
) => DOMNode | undefined
focus: () => void
focusBlock: () => PortableTextBlock | undefined
focusChild: () => PortableTextChild | undefined
getSelection: () => EditorSelection
getFragment: () => PortableTextBlock[] | undefined
getValue: () => PortableTextBlock[] | undefined
hasBlockStyle: (style: string) => boolean
hasListStyle: (listStyle: string) => boolean
insertBlock: <
TSchemaType extends {
name: string
},
>(
type: TSchemaType,
value?: {
[prop: string]: unknown
},
) => Path
insertChild: <
TSchemaType extends {
name: string
},
>(
type: TSchemaType,
value?: {
[prop: string]: unknown
},
) => Path
insertBreak: () => void
isCollapsedSelection: () => boolean
isExpandedSelection: () => boolean
isMarkActive: (mark: string) => boolean
isSelectionsOverlapping: (
selectionA: EditorSelection,
selectionB: EditorSelection,
) => boolean
isVoid: (element: PortableTextBlock | PortableTextChild) => boolean
marks: () => string[]
redo: () => void
removeAnnotation: <
TSchemaType extends {
name: string
},
>(
type: TSchemaType,
) => void
select: (selection: EditorSelection) => void
toggleBlockStyle: (blockStyle: string) => void
toggleList: (listStyle: string) => void
toggleMark: (mark: string) => void
undo: () => void
}
/** @beta */
export declare interface EditableAPIDeleteOptions {
mode?: 'blocks' | 'children' | 'selected'
}
/**
* @public
*/
export declare type Editor = {
dom: EditorDom
getSnapshot: () => EditorSnapshot
/**
* @beta
*/
registerBehavior: (config: {behavior: Behavior}) => () => void
send: (event: EditorEvent) => void
on: ActorRef<Snapshot<unknown>, EventObject, EditorEmittedEvent>['on']
}
/**
* @internal
*/
declare type EditorActor = ActorRefFrom<typeof editorMachine>
/**
* When the editor changes, it will emit a change item describing the change
* @beta */
export declare type EditorChange =
| BlurChange
| ConnectionChange
| ErrorChange
| FocusChange
| InvalidValue
| LoadingChange
| MutationChange
| PatchChange
| ReadyChange
| RedoChange
| SelectionChange
| UndoChange
| UnsetChange
| ValueChange
/**
* @beta
*/
export declare type EditorChanges = Subject<EditorChange>
/**
* @public
*/
export declare type EditorConfig = {
/**
* @beta
*/
keyGenerator?: () => string
/**
* @deprecated Will be removed in the next major version
*/
maxBlocks?: number
readOnly?: boolean
initialValue?: Array<PortableTextBlock>
} & (
| {
schemaDefinition: SchemaDefinition
schema?: undefined
}
| {
schemaDefinition?: undefined
schema: ArraySchemaType<PortableTextBlock> | ArrayDefinition
}
)
/**
* @public
*/
export declare type EditorContext = {
converters: Array<Converter>
keyGenerator: () => string
readOnly: boolean
schema: EditorSchema
selection: EditorSelection
value: Array<PortableTextBlock>
}
declare type EditorDom = {
getBlockNodes: (snapshot: EditorSnapshot) => Array<Node>
getChildNodes: (snapshot: EditorSnapshot) => Array<Node>
/**
* Let the Editor set the drag ghost. This is to be sure that it will get
* properly removed again when the drag ends.
*/
setDragGhost: ({
event,
ghost,
}: {
event: PickFromUnion<BehaviorEvent, 'type', 'drag.dragstart'>
ghost: {
element: HTMLElement
x: number
y: number
}
}) => void
}
/**
* @public
*/
export declare type EditorEmittedEvent =
| {
type: 'blurred'
event: FocusEvent_2<HTMLDivElement, Element>
}
| {
/**
* @deprecated Will be removed in the next major version
*/
type: 'done loading'
}
| {
type: 'editable'
}
| ErrorEvent_2
| {
type: 'focused'
event: FocusEvent_2<HTMLDivElement, Element>
}
| {
type: 'invalid value'
resolution: InvalidValueResolution | null
value: Array<PortableTextBlock> | undefined
}
| {
/**
* @deprecated Will be removed in the next major version
*/
type: 'loading'
}
| MutationEvent
| PatchEvent
| {
type: 'read only'
}
| {
type: 'ready'
}
| {
type: 'selection'
selection: EditorSelection
}
| {
type: 'value changed'
value: Array<PortableTextBlock> | undefined
}
/**
* @public
*/
export declare type EditorEvent =
| ExternalEditorEvent
| ExternalBehaviorEvent
| {
type: 'update value'
value: Array<PortableTextBlock> | undefined
}
/**
* @public
* @deprecated
* This component has been renamed. Use `EventListenerPlugin` instead.
*
* ```
* import {EventListenerPlugin} from '@portabletext/editor/plugins'
* ```
*/
export declare function EditorEventListener(props: {
on: (event: EditorEmittedEvent) => void
}): null
/**
* @internal
*/
declare const editorMachine: StateMachine<
{
behaviors: Set<BehaviorConfig>
behaviorsSorted: boolean
converters: Set<Converter>
getLegacySchema: () => PortableTextMemberSchemaTypes
keyGenerator: () => string
pendingEvents: Array<InternalPatchEvent | MutationEvent>
pendingIncomingPatchesEvents: Array<PatchesEvent>
schema: EditorSchema
initialReadOnly: boolean
maxBlocks: number | undefined
selection: EditorSelection
initialValue: Array<PortableTextBlock> | undefined
internalDrag?: {
origin: Pick<EventPosition, 'selection'>
}
dragGhost?: HTMLElement
slateEditor?: PortableTextSlateEditor
},
| InternalPatchEvent
| MutationEvent
| PatchesEvent
| {
type: 'update readOnly'
readOnly: boolean
}
| {
type: 'update maxBlocks'
maxBlocks: number | undefined
}
| {
type: 'add behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'remove behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'blur'
editor: PortableTextSlateEditor
}
| {
type: 'focus'
editor: PortableTextSlateEditor
}
| {
type: 'normalizing'
}
| {
type: 'update selection'
selection: EditorSelection
}
| {
type: 'done normalizing'
}
| {
type: 'done syncing value'
}
| {
type: 'syncing value'
}
| {
type: 'behavior event'
behaviorEvent: BehaviorEvent
editor: PortableTextSlateEditor
nativeEvent?: {
preventDefault: () => void
}
}
| {
type: 'set drag ghost'
ghost: HTMLElement
}
| {
type: 'dragstart'
ghost?: HTMLElement
origin: Pick<EventPosition, 'selection'>
}
| {
type: 'dragend'
}
| {
type: 'drop'
},
{},
never,
Values<{
'add behavior to context': {
type: 'add behavior to context'
params: NonReducibleUnknown
}
'remove behavior from context': {
type: 'remove behavior from context'
params: NonReducibleUnknown
}
'emit patch event': {
type: 'emit patch event'
params: NonReducibleUnknown
}
'emit mutation event': {
type: 'emit mutation event'
params: NonReducibleUnknown
}
'emit read only': {
type: 'emit read only'
params: NonReducibleUnknown
}
'emit editable': {
type: 'emit editable'
params: NonReducibleUnknown
}
'defer event': {
type: 'defer event'
params: NonReducibleUnknown
}
'emit pending events': {
type: 'emit pending events'
params: NonReducibleUnknown
}
'emit ready': {
type: 'emit ready'
params: NonReducibleUnknown
}
'clear pending events': {
type: 'clear pending events'
params: NonReducibleUnknown
}
'defer incoming patches': {
type: 'defer incoming patches'
params: NonReducibleUnknown
}
'emit pending incoming patches': {
type: 'emit pending incoming patches'
params: NonReducibleUnknown
}
'clear pending incoming patches': {
type: 'clear pending incoming patches'
params: NonReducibleUnknown
}
'handle blur': {
type: 'handle blur'
params: unknown
}
'handle focus': {
type: 'handle focus'
params: unknown
}
'handle behavior event': {
type: 'handle behavior event'
params: unknown
}
'sort behaviors': {
type: 'sort behaviors'
params: NonReducibleUnknown
}
}>,
{
type: 'slate is busy'
params: unknown
},
never,
{
'edit mode':
| {
editable:
| 'idle'
| 'dragging internally'
| {
focusing: 'busy' | 'checking if busy'
}
}
| {
'read only': 'read only' | 'determine initial edit mode'
}
'setup':
| 'setting up'
| {
'set up': {
'value sync': 'idle' | 'syncing value'
'writing':
| 'dirty'
| {
pristine: 'idle' | 'normalizing'
}
}
}
},
'dragging internally',
{
converters?: Array<Converter>
getLegacySchema: () => PortableTextMemberSchemaTypes
keyGenerator: () => string
maxBlocks?: number
readOnly?: boolean
schema: EditorSchema
initialValue?: Array<PortableTextBlock>
},
NonReducibleUnknown,
| InternalPatchEvent
| MutationEvent
| PatchesEvent
| {
type: 'blurred'
event: FocusEvent_2<HTMLDivElement, Element>
}
| {
type: 'done loading'
}
| {
type: 'editable'
}
| {
type: 'error'
name: string
description: string
data: unknown
}
| {
type: 'focused'
event: FocusEvent_2<HTMLDivElement, Element>
}
| {
type: 'invalid value'
resolution: InvalidValueResolution_2 | null
value: Array<PortableTextBlock> | undefined
}
| {
type: 'loading'
}
| {
type: 'read only'
}
| {
type: 'ready'
}
| {
type: 'selection'
selection: EditorSelection
}
| {
type: 'value changed'
value: Array<PortableTextBlock> | undefined
},
MetaObject,
{
readonly id: 'editor'
readonly context: ({
input,
}: {
spawn: {
<TSrc extends never>(
logic: TSrc,
...[options]: never
): ActorRefFromLogic<never>
<TLogic extends AnyActorLogic>(
src: TLogic,
...[options]: ConditionalRequired<
[
options?:
| ({
id?: never
systemId?: string
input?: InputFrom<TLogic> | undefined
syncSnapshot?: boolean
} & {[K in RequiredLogicInput<TLogic>]: unknown})
| undefined,
],
IsNotNever<RequiredLogicInput<TLogic>>
>
): ActorRefFromLogic<TLogic>
}
input: {
converters?: Array<Converter>
getLegacySchema: () => PortableTextMemberSchemaTypes
keyGenerator: () => string
maxBlocks?: number
readOnly?: boolean
schema: EditorSchema
initialValue?: Array<PortableTextBlock>
}
self: ActorRef<
MachineSnapshot<
{
behaviors: Set<BehaviorConfig>
behaviorsSorted: boolean
converters: Set<Converter>
getLegacySchema: () => PortableTextMemberSchemaTypes
keyGenerator: () => string
pendingEvents: Array<InternalPatchEvent | MutationEvent>
pendingIncomingPatchesEvents: Array<PatchesEvent>
schema: EditorSchema
initialReadOnly: boolean
maxBlocks: number | undefined
selection: EditorSelection
initialValue: Array<PortableTextBlock> | undefined
internalDrag?: {
origin: Pick<EventPosition, 'selection'>
}
dragGhost?: HTMLElement
slateEditor?: PortableTextSlateEditor
},
| InternalPatchEvent
| MutationEvent
| PatchesEvent
| {
type: 'update readOnly'
readOnly: boolean
}
| {
type: 'update maxBlocks'
maxBlocks: number | undefined
}
| {
type: 'add behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'remove behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'blur'
editor: PortableTextSlateEditor
}
| {
type: 'focus'
editor: PortableTextSlateEditor
}
| {
type: 'normalizing'
}
| {
type: 'update selection'
selection: EditorSelection
}
| {
type: 'done normalizing'
}
| {
type: 'done syncing value'
}
| {
type: 'syncing value'
}
| {
type: 'behavior event'
behaviorEvent: BehaviorEvent
editor: PortableTextSlateEditor
nativeEvent?: {
preventDefault: () => void
}
}
| {
type: 'set drag ghost'
ghost: HTMLElement
}
| {
type: 'dragstart'
ghost?: HTMLElement
origin: Pick<EventPosition, 'selection'>
}
| {
type: 'dragend'
}
| {
type: 'drop'
},
Record<string, AnyActorRef | undefined>,
StateValue,
string,
unknown,
any,
any
>,
| InternalPatchEvent
| MutationEvent
| PatchesEvent
| {
type: 'update readOnly'
readOnly: boolean
}
| {
type: 'update maxBlocks'
maxBlocks: number | undefined
}
| {
type: 'add behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'remove behavior'
behaviorConfig: BehaviorConfig
}
| {
type: 'blur'
editor: PortableTextSlateEditor
}
| {
type: 'focus'
editor: PortableTextSlateEditor
}
| {
type: 'normalizing'
}
| {
type: 'update selection'
selection: EditorSelection
}
| {
type: 'done normalizing'
}
| {
type: 'done syncing value'
}
| {
type: 'syncing value'
}
| {
type: 'behavior event'
behaviorEvent: BehaviorEvent
editor: PortableTextSlateEditor
nativeEvent?: {
preventDefault: () => void
}
}
| {
type: 'set drag ghost'
ghost: HTMLElement
}
| {
type: 'dragstart'
ghost?: HTMLElement
origin: Pick<EventPosition, 'selection'>
}
| {
type: 'dragend'
}
| {
type: 'drop'
},
AnyEventObject
>
}) => {
behaviors: Set<{
behavior: Behavior_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select'
| 'clipboard.copy'
| 'clipboard.cut'
| 'clipboard.paste'
| 'drag.dragstart'
| 'drag.drag'
| 'drag.dragend'
| 'drag.dragenter'
| 'drag.dragover'
| 'drag.dragleave'
| 'drag.drop'
| 'input.*'
| 'keyboard.keydown'
| 'keyboard.keyup'
| 'mouse.click'
| '*'
| `custom.${string}`
| 'deserialize.*'
| 'serialize.*'
| 'split.*'
| 'delete.*'
| 'select.*'
| 'style.*'
| 'block.*'
| 'history.*'
| 'insert.*'
| 'annotation.*'
| 'decorator.*'
| 'child.*'
| 'deserialization.*'
| 'list item.*'
| 'move.*'
| 'serialization.*'
| 'clipboard.*'
| 'drag.*'
| 'keyboard.*'
| 'mouse.*',
true,
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'annotation.add'
>
annotation: {
name: string
value: {
[prop: string]: unknown
}
}
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'annotation.remove'
>
annotation: {
name: string
}
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'block.set'
>
at: BlockPath_2
props: Record<string, unknown>
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'block.unset'
>
at: BlockPath_2
props: Array<string>
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'child.set'
>
at: ChildPath_2
props: {
[prop: string]: unknown
}
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'child.unset'
>
at: ChildPath_2
props: Array<string>
}
| {
type: StrictExtract_2<
| 'annotation.set'
| 'annotation.toggle'
| 'decorator.toggle'
| 'delete.backward'
| 'delete.block'
| 'delete.child'
| 'delete.forward'
| 'delete.text'
| 'deserialize'
| 'deserialization.success'
| 'deserialization.failure'
| 'insert.blocks'
| 'insert.break'
| 'insert.soft break'
| 'list item.add'
| 'list item.remove'
| 'list item.toggle'
| 'move.block down'
| 'move.block up'
| 'select.previous block'
| 'select.next block'
| 'serialize'
| 'serialization.success'
| 'serialization.failure'
| 'split'
| 'style.add'
| 'style.remove'
| 'style.toggle'
| 'annotation.add'
| 'annotation.remove'
| 'block.set'
| 'block.unset'
| 'child.set'
| 'child.unset'
| 'decorator.add'
| 'decorator.remove'
| 'delete'
| 'history.redo'
| 'history.undo'
| 'insert.inline object'
| 'insert.block'
| 'insert.span'
| 'insert.text'
| 'move.backward'
| 'move.block'
| 'move.forward'
| 'select',
'decorator.add'
>
decorator: string
at?: {
anchor: BlockOffset_2