Skip to content
GitHubDiscord

prosekit/core/test

Type Parameter Default type

E extends Extension

Extension

get commands(): ExtractCommandActions<E>

All CommandActions defined by the editor.

ExtractCommandActions<E>

Editor.commands

get focused(): boolean

Whether the editor is focused.

boolean

Editor.focused

get marks(): ExtractMarkActions<E>

All MarkActions defined by the editor.

ExtractMarkActions<E>

Editor.marks

get mounted(): boolean

Whether the editor is mounted.

boolean

Editor.mounted

get nodes(): ExtractNodeActions<E>

All NodeActions defined by the editor.

ExtractNodeActions<E>

Editor.nodes

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

The editor schema.

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

Editor.schema

get state(): EditorState

The editor’s current state.

EditorState

Editor.state

get view(): EditorView

The editor view.

EditorView

Editor.view

blur(): void

Blur the editor.

Editor.blur

canExec(command: Command): boolean

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

Editor.canExec

dispatchEvent(event: Event): void

exec(command: Command): boolean

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

Editor.exec

focus(): void

Focus the editor.

Editor.focus

getDocHTML(options?: getDocHTMLOptions): string

Return a HTML string representing the editor’s current document.

Editor.getDocHTML

getDocJSON(): NodeJSON

Return a JSON object representing the editor’s current document.

Editor.getDocJSON

mount(place: undefined | null | HTMLElement): void

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

Editor.mount

set(doc: ProseMirrorNode): 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.

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(content: string | ProseMirrorNode | NodeJSON | HTMLElement, selection?: Selection | "start" | SelectionJSON | "end"): void

Update the editor’s document and selection.

Editor.setContent

unmount(): void

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

Editor.unmount

updateState(state: EditorState): void

Update the editor’s state.

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

Editor.updateState

use(extension: Extension): VoidFunction

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

Editor.use

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