Skip to content

prosekit/core/test

TestEditor<E>

An editor for testing purposes.

Extends

Type Parameters

E extends Extension = Extension

Constructors

new TestEditor()

new TestEditor<E>(instance): TestEditor<E>

Parameters

instance: EditorInstance

Returns

TestEditor<E>

Overrides

Editor<E>.constructor

Accessors

commands

get commands(): ToCommandAction<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Commands"] extends undefined ? never : ExtractTyping<E>["Commands"]>[KeyType] }>

All CommandActions defined by the editor.

Returns

ToCommandAction<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Commands"] extends undefined ? never : ExtractTyping<E>["Commands"]>[KeyType] }>

Inherited from

Editor.commands

focused

get focused(): boolean

Whether the editor is focused.

Returns

boolean

Inherited from

Editor.focused

marks

get marks(): ToMarkAction<SimplifyDeeper<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Marks"] extends undefined ? never : ExtractTyping<E>["Marks"]>[KeyType] }>>

All MarkActions defined by the editor.

Returns

ToMarkAction<SimplifyDeeper<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Marks"] extends undefined ? never : ExtractTyping<E>["Marks"]>[KeyType] }>>

Inherited from

Editor.marks

mounted

get mounted(): boolean

Whether the editor is mounted.

Returns

boolean

Inherited from

Editor.mounted

nodes

get nodes(): ToNodeAction<SimplifyDeeper<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Nodes"] extends undefined ? never : ExtractTyping<E>["Nodes"]>[KeyType] }>>

All NodeActions defined by the editor.

Returns

ToNodeAction<SimplifyDeeper<{ [KeyType in string | number | symbol]: UnionToIntersection<ExtractTyping<E>["Nodes"] extends undefined ? never : ExtractTyping<E>["Nodes"]>[KeyType] }>>

Inherited from

Editor.nodes

schema

get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

The editor schema.

Returns

Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

Inherited from

Editor.schema

state

get state(): EditorState

The editor's current state.

Returns

EditorState

Inherited from

Editor.state

view

get view(): EditorView

The editor view.

Returns

EditorView

Inherited from

Editor.view

Methods

blur()

blur(): void

Blur the editor.

Returns

void

Inherited from

Editor.blur

canExec()

canExec(command): boolean

Check if the given command can be executed. Return true if the command can be executed, otherwise false.

Parameters

command: Command

Returns

boolean

Inherited from

Editor.canExec

dispatchEvent()

dispatchEvent(event): void

Parameters

event: Event

Returns

void

exec()

exec(command): boolean

Execute the given command. Return true if the command was successfully executed, otherwise false.

Parameters

command: Command

Returns

boolean

Inherited from

Editor.exec

focus()

focus(): void

Focus the editor.

Returns

void

Inherited from

Editor.focus

mount()

mount(place): void

Mount the editor to the given HTML element. Pass null or undefined to unmount the editor.

Parameters

place: undefined | null | HTMLElement

Returns

void

Inherited from

Editor.mount

set()

set(doc): void

Set the editor state to the given document. You can use special tokens <a> and <b> to set the anchor and head positions of the selection.

Parameters

doc: Node

Returns

void

Example
ts
const editor = createTestEditor({ extension })
const n = editor.nodes
const doc = n.doc(n.paragraph('<a>Hello<b> world!'))
editor.set(doc) // "Hello" is selected.

setContent()

setContent(content, selection?): void

Update the editor's document and selection.

Parameters

content: string | Node | NodeJSON | HTMLElement

The new document to set. It can be one of the following:

  • A ProseMirror node instance
  • A ProseMirror node JSON object
  • An HTML string
  • An HTML element instance

selection?: Selection | "start" | SelectionJSON | "end"

Optional. Specifies the new selection. It can be one of the following:

  • A ProseMirror selection instance
  • A ProseMirror selection JSON object
  • The string "start" (to set selection at the beginning, default value)
  • The string "end" (to set selection at the end)
Returns

void

Inherited from

Editor.setContent

unmount()

unmount(): void

Unmount the editor. This is equivalent to mount(null).

Returns

void

Inherited from

Editor.unmount

updateState()

updateState(state): void

Update the editor's state.

Parameters

state: EditorState

Returns

void

Remarks

This is an advanced method. Use it only if you have a specific reason to directly manipulate the editor's state.

Inherited from

Editor.updateState

use()

use(extension): VoidFunction

Register an extension to the editor. Return a function to unregister the extension.

Parameters

extension: Extension<ExtensionTyping<any, any, any>>

Returns

VoidFunction

Inherited from

Editor.use


createTestEditor()

createTestEditor<E>(options): TestEditor<E>

Type Parameters

E extends Extension<ExtensionTyping<any, any, any>>

Parameters

options: EditorOptions<E>

Returns

TestEditor<E>