prosekit/core/test
TestEditor<E>
An editor for testing purposes.
Extends
Editor
<E
>
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
focused
get
focused():boolean
Whether the editor is focused.
Returns
boolean
Inherited from
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
mounted
get
mounted():boolean
Whether the editor is mounted.
Returns
boolean
Inherited from
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
schema
get
schema():Schema
<ExtractNodeNames
<E
>,ExtractMarkNames
<E
>>
The editor schema.
Returns
Schema
<ExtractNodeNames
<E
>, ExtractMarkNames
<E
>>
Inherited from
state
get
state():EditorState
The editor's current state.
Returns
Inherited from
view
get
view():EditorView
The editor view.
Returns
Inherited from
Methods
blur()
blur():
void
Blur the editor.
Returns
void
Inherited from
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
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
focus()
focus():
void
Focus the editor.
Returns
void
Inherited from
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
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
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
unmount()
unmount():
void
Unmount the editor. This is equivalent to mount(null)
.
Returns
void
Inherited from
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
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
createTestEditor()
createTestEditor<
E
>(options
):TestEditor
<E
>
Type Parameters
• E extends Extension
<ExtensionTyping
<any
, any
, any
>>
Parameters
• options: EditorOptions
<E
>
Returns
TestEditor
<E
>