prosekit/core/test
TestEditor
An editor for testing purposes.
constructor
new TestEditor<E extends Extension>(instance: EditorInstance): TestEditor<E>
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.
get focused(): boolean
Whether the editor is focused.
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.
get mounted(): boolean
Whether the editor is mounted.
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.
get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>
The editor schema.
get state(): EditorState
The editor's current state.
get view(): EditorView
The editor view.
blur
Blur the editor.
tsconst blur: () => void
canExec
Check if the given command can be executed. Return
true
if the command can be executed, otherwisefalse
.tsconst canExec: (command: Command) => boolean
dispatchEvent
- ts
const dispatchEvent: (event: Event) => void
exec
Execute the given command. Return
true
if the command was successfully executed, otherwisefalse
.tsconst exec: (command: Command) => boolean
focus
Focus the editor.
tsconst focus: () => void
mount
Mount the editor to the given HTML element. Pass
null
orundefined
to unmount the editor.tsconst mount: (place: undefined | null | HTMLElement) => void
set
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.Example
tsconst editor = createTestEditor({ extension }) const n = editor.nodes const doc = n.doc(n.paragraph('<a>Hello<b> world!')) editor.set(doc) // "Hello" is selected.
tsconst set: (doc: Node) => void
setContent
Update the editor's document and selection.
tsconst setContent: (content: string | Node | NodeJSON | HTMLElement, selection?: Selection | "start" | SelectionJSON | "end") => void
unmount
Unmount the editor. This is equivalent to
mount(null)
.tsconst unmount: () => void
updateState
Update the editor's state.
Remarks
This is an advanced method. Use it only if you have a specific reason to directly manipulate the editor's state.
tsconst updateState: (state: EditorState) => void
use
Register an extension to the editor. Return a function to unregister the extension.
tsconst use: (extension: Extension) => VoidFunction
createTestEditor
function createTestEditor<E extends Extension>(options: EditorOptions<E>): TestEditor<E>