prosekit/pm/state
Re-exports from prosemirror-state.
Classes
Section titled “Classes”AllSelection
Section titled “AllSelection”A selection type that represents selecting the whole document (which can not necessarily be expressed with a text selection, when there are for example leaf block nodes at the start or end of the document).
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new AllSelection(
doc
:ProseMirrorNode
):AllSelection
-
Create an all-selection over the given document.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly $anchor:
ResolvedPos
-
The resolved anchor of the selection (the side that stays in place when the selection is modified).
-
readonly $head:
ResolvedPos
-
The resolved head of the selection (the side that moves when the selection is modified).
-
ranges: readonly
SelectionRange
[] -
The ranges covered by the selection.
-
visible:
boolean
-
Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to
true
.
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get $from():
ResolvedPos
The resolved lower bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get $to():
ResolvedPos
The resolved upper bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”anchor
Section titled “anchor”Get Signature
Section titled “Get Signature”get anchor():
number
The selection’s anchor, as an unresolved position.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get empty():
boolean
Indicates whether the selection contains any content.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get from():
number
The lower bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get head():
number
The selection’s head.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get to():
number
The upper bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”content()
Section titled “content()”-
Get the content of this selection as a slice.
Inherited from
Section titled “Inherited from”
-
Test whether the selection is the same as another selection.
Overrides
Section titled “Overrides”
getBookmark()
Section titled “getBookmark()”-
getBookmark():
object
-
Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.
Overrides
Section titled “Overrides”
-
map(
doc
:ProseMirrorNode
):AllSelection
-
Map this selection through a mappable thing.
doc
should be the new document to which we are mapping.Overrides
Section titled “Overrides”
replace()
Section titled “replace()”-
replace(
tr
:Transaction
,content?
:Slice
):void
-
Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.
Overrides
Section titled “Overrides”
replaceWith()
Section titled “replaceWith()”-
replaceWith(
tr
:Transaction
,node
:ProseMirrorNode
):void
-
Replace the selection with the given node, appending the changes to the given transaction.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a
type
property whose value matches the ID under which you registered your class.Overrides
Section titled “Overrides”
atEnd()
Section titled “atEnd()”-
static atEnd(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the end of the given document.
Inherited from
Section titled “Inherited from”
atStart()
Section titled “atStart()”-
static atStart(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the start of the given document. Will return an
AllSelection
if no valid position exists.Inherited from
Section titled “Inherited from”
findFrom()
Section titled “findFrom()”-
static findFrom(
$pos
:ResolvedPos
,dir
:number
,textOnly?
:boolean
):null
|Selection
-
Find a valid cursor or leaf node selection starting at the given position and searching back if
dir
is negative, and forward if positive. WhentextOnly
is true, only consider cursor selections. Will return null when no valid selection position is found.Inherited from
Section titled “Inherited from”
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
doc
:ProseMirrorNode
,json
:any
):Selection
-
Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,selectionClass
:object
):object
-
To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.
Inherited from
Section titled “Inherited from”
near()
Section titled “near()”-
static near(
$pos
:ResolvedPos
,bias?
:number
):Selection
-
Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if
bias
is negative, it will search backwards first.Inherited from
Section titled “Inherited from”
EditorState
Section titled “EditorState”The state of a ProseMirror editor is represented by an object of this type. A state is a persistent data structure—it isn’t updated, but rather a new state value is computed from an old one using the apply
method.
A state holds a number of built-in fields, and plugins can define additional fields.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new EditorState():
EditorState
Properties
Section titled “Properties”-
The current document.
-
storedMarks:
null
| readonlyMark
[] -
A set of marks to apply to the next input. Will be null when no explicit marks have been set.
Accessors
Section titled “Accessors”plugins
Section titled “plugins”Get Signature
Section titled “Get Signature”get plugins(): readonly
ProseMirrorPlugin
<any
>[]
The plugins that are active in this state.
Returns
Section titled “Returns”readonly ProseMirrorPlugin
<any
>[]
schema
Section titled “schema”Get Signature
Section titled “Get Signature”The schema of the state’s document.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get tr():
Transaction
Start a transaction from this state.
Returns
Section titled “Returns”Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
tr
:Transaction
):EditorState
-
Apply the given transaction to produce a new state.
applyTransaction()
Section titled “applyTransaction()”-
applyTransaction(
rootTr
:Transaction
):object
-
Verbose variant of
apply
that returns the precise transactions that were applied (which might be influenced by the transaction hooks of plugins) along with the new state.
reconfigure()
Section titled “reconfigure()”-
reconfigure(
config
:object
):EditorState
-
Create a new state based on this one, but with an adjusted set of active plugins. State fields that exist in both sets of plugins are kept unchanged. Those that no longer exist are dropped, and those that are new are initialized using their
init
method, passing in the new configuration object..
toJSON()
Section titled “toJSON()”-
toJSON(
pluginFields?
:object
):any
-
Serialize this state to JSON. If you want to serialize the state of plugins, pass an object mapping property names to use in the resulting JSON object to plugin objects. The argument may also be a string or number, in which case it is ignored, to support the way
JSON.stringify
callstoString
methods.
create()
Section titled “create()”-
static create(
config
:EditorStateConfig
):EditorState
-
Create a new state.
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
config
:object
,json
:any
,pluginFields?
:object
):EditorState
-
Deserialize a JSON representation of a state.
config
should have at least aschema
field, and should contain array of plugins to initialize the state with.pluginFields
can be used to deserialize the state of plugins, by associating plugin instances with the property names they use in the JSON object.
NodeSelection
Section titled “NodeSelection”A node selection is a selection that points at a single node. All nodes marked selectable can be the target of a node selection. In such a selection, from
and to
point directly before and after the selected node, anchor
equals from
, and head
equals to
..
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new NodeSelection(
$pos
:ResolvedPos
):NodeSelection
-
Create a node selection. Does not verify the validity of its argument.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly $anchor:
ResolvedPos
-
The resolved anchor of the selection (the side that stays in place when the selection is modified).
-
readonly $head:
ResolvedPos
-
The resolved head of the selection (the side that moves when the selection is modified).
-
The selected node.
-
ranges: readonly
SelectionRange
[] -
The ranges covered by the selection.
-
visible:
boolean
-
Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to
true
.
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get $from():
ResolvedPos
The resolved lower bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get $to():
ResolvedPos
The resolved upper bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”anchor
Section titled “anchor”Get Signature
Section titled “Get Signature”get anchor():
number
The selection’s anchor, as an unresolved position.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get empty():
boolean
Indicates whether the selection contains any content.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get from():
number
The lower bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get head():
number
The selection’s head.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get to():
number
The upper bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”content()
Section titled “content()”-
Get the content of this selection as a slice.
Overrides
Section titled “Overrides”
-
Test whether the selection is the same as another selection.
Overrides
Section titled “Overrides”
getBookmark()
Section titled “getBookmark()”-
Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.
Overrides
Section titled “Overrides”
-
map(
doc
:ProseMirrorNode
,mapping
:Mappable
):Selection
-
Map this selection through a mappable thing.
doc
should be the new document to which we are mapping.Overrides
Section titled “Overrides”
replace()
Section titled “replace()”-
replace(
tr
:Transaction
,content?
:Slice
):void
-
Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.
Inherited from
Section titled “Inherited from”
replaceWith()
Section titled “replaceWith()”-
replaceWith(
tr
:Transaction
,node
:ProseMirrorNode
):void
-
Replace the selection with the given node, appending the changes to the given transaction.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a
type
property whose value matches the ID under which you registered your class.Overrides
Section titled “Overrides”
atEnd()
Section titled “atEnd()”-
static atEnd(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the end of the given document.
Inherited from
Section titled “Inherited from”
atStart()
Section titled “atStart()”-
static atStart(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the start of the given document. Will return an
AllSelection
if no valid position exists.Inherited from
Section titled “Inherited from”
create()
Section titled “create()”-
static create(
doc
:ProseMirrorNode
,from
:number
):NodeSelection
-
Create a node selection from non-resolved positions.
findFrom()
Section titled “findFrom()”-
static findFrom(
$pos
:ResolvedPos
,dir
:number
,textOnly?
:boolean
):null
|Selection
-
Find a valid cursor or leaf node selection starting at the given position and searching back if
dir
is negative, and forward if positive. WhentextOnly
is true, only consider cursor selections. Will return null when no valid selection position is found.Inherited from
Section titled “Inherited from”
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
doc
:ProseMirrorNode
,json
:any
):Selection
-
Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).
Inherited from
Section titled “Inherited from”
isSelectable()
Section titled “isSelectable()”-
static isSelectable(
node
:ProseMirrorNode
):boolean
-
Determines whether the given node may be selected as a node selection.
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,selectionClass
:object
):object
-
To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.
Inherited from
Section titled “Inherited from”
near()
Section titled “near()”-
static near(
$pos
:ResolvedPos
,bias?
:number
):Selection
-
Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if
bias
is negative, it will search backwards first.Inherited from
Section titled “Inherited from”
PluginKey<PluginState>
Section titled “PluginKey<PluginState>”A key is used to tag plugins in a way that makes it possible to find them, given an editor state. Assigning a key does mean only one plugin of that type can be active in a state.
Type Parameters
Section titled “Type Parameters”Type Parameter | Default type |
---|---|
|
|
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”Methods
Section titled “Methods”-
get(
state
:EditorState
):undefined
|ProseMirrorPlugin
<PluginState
> -
Get the active plugin with this key, if any, from an editor state.
getState()
Section titled “getState()”-
getState(
state
:EditorState
):undefined
|PluginState
-
Get the plugin’s state from an editor state.
ProseMirrorPlugin<PluginState>
Section titled “ProseMirrorPlugin<PluginState>”Plugins bundle functionality that can be added to an editor. They are part of the editor state and may influence that state and the view that contains it.
Type Parameters
Section titled “Type Parameters”Type Parameter | Default type |
---|---|
|
|
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new ProseMirrorPlugin<PluginState>(
spec
:PluginSpec
<PluginState
>):ProseMirrorPlugin
<PluginState
> -
Create a plugin.
Properties
Section titled “Properties”-
readonly props:
EditorProps
<ProseMirrorPlugin
<PluginState
>> -
The props exported by this plugin.
-
readonly spec:
PluginSpec
<PluginState
> -
The plugin’s spec object.
Methods
Section titled “Methods”getState()
Section titled “getState()”-
getState(
state
:EditorState
):undefined
|PluginState
-
Extract the plugin’s state field from an editor state.
abstract Selection
Section titled “abstract Selection”Superclass for editor selections. Every selection type should extend this. Should not be instantiated directly.
Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new Selection(
$anchor
:ResolvedPos
,$head
:ResolvedPos
,ranges?
: readonlySelectionRange
[]):Selection
-
Initialize a selection with the head and anchor and ranges. If no ranges are given, constructs a single range across
$anchor
and$head
.
Properties
Section titled “Properties”-
readonly $anchor:
ResolvedPos
-
The resolved anchor of the selection (the side that stays in place when the selection is modified).
-
readonly $head:
ResolvedPos
-
The resolved head of the selection (the side that moves when the selection is modified).
-
ranges: readonly
SelectionRange
[] -
The ranges covered by the selection.
-
visible:
boolean
-
Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to
true
.
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get $from():
ResolvedPos
The resolved lower bound of the selection’s main range.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get $to():
ResolvedPos
The resolved upper bound of the selection’s main range.
Returns
Section titled “Returns”anchor
Section titled “anchor”Get Signature
Section titled “Get Signature”get anchor():
number
The selection’s anchor, as an unresolved position.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get empty():
boolean
Indicates whether the selection contains any content.
Returns
Section titled “Returns”boolean
Get Signature
Section titled “Get Signature”get from():
number
The lower bound of the selection’s main range.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get head():
number
The selection’s head.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get to():
number
The upper bound of the selection’s main range.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”content()
Section titled “content()”-
Test whether the selection is the same as another selection.
getBookmark()
Section titled “getBookmark()”-
Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.
-
abstract map(
doc
:ProseMirrorNode
,mapping
:Mappable
):Selection
-
Map this selection through a mappable thing.
doc
should be the new document to which we are mapping.
replace()
Section titled “replace()”-
replace(
tr
:Transaction
,content?
:Slice
):void
-
Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.
replaceWith()
Section titled “replaceWith()”-
replaceWith(
tr
:Transaction
,node
:ProseMirrorNode
):void
-
Replace the selection with the given node, appending the changes to the given transaction.
toJSON()
Section titled “toJSON()”-
abstract toJSON():
any
-
Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a
type
property whose value matches the ID under which you registered your class.
atEnd()
Section titled “atEnd()”-
static atEnd(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the end of the given document.
atStart()
Section titled “atStart()”-
static atStart(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the start of the given document. Will return an
AllSelection
if no valid position exists.
findFrom()
Section titled “findFrom()”-
static findFrom(
$pos
:ResolvedPos
,dir
:number
,textOnly?
:boolean
):null
|Selection
-
Find a valid cursor or leaf node selection starting at the given position and searching back if
dir
is negative, and forward if positive. WhentextOnly
is true, only consider cursor selections. Will return null when no valid selection position is found.
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
doc
:ProseMirrorNode
,json
:any
):Selection
-
Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,selectionClass
:object
):object
-
To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.
near()
Section titled “near()”-
static near(
$pos
:ResolvedPos
,bias?
:number
):Selection
-
Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if
bias
is negative, it will search backwards first.
SelectionRange
Section titled “SelectionRange”Represents a selected range in a document.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new SelectionRange(
$from
:ResolvedPos
,$to
:ResolvedPos
):SelectionRange
-
Create a range.
Properties
Section titled “Properties”-
readonly $from:
ResolvedPos
-
The lower bound of the range.
-
readonly $to:
ResolvedPos
-
The upper bound of the range.
TextSelection
Section titled “TextSelection”A text selection represents a classical editor selection, with a head (the moving side) and anchor (immobile side), both of which point into textblock nodes. It can be empty (a regular cursor position).
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new TextSelection(
$anchor
:ResolvedPos
,$head?
:ResolvedPos
):TextSelection
-
Construct a text selection between the given points.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly $anchor:
ResolvedPos
-
The resolved anchor of the selection (the side that stays in place when the selection is modified).
-
readonly $head:
ResolvedPos
-
The resolved head of the selection (the side that moves when the selection is modified).
-
ranges: readonly
SelectionRange
[] -
The ranges covered by the selection.
-
visible:
boolean
-
Controls whether, when a selection of this type is active in the browser, the selected range should be visible to the user. Defaults to
true
.
Accessors
Section titled “Accessors”$cursor
Section titled “$cursor”Get Signature
Section titled “Get Signature”get $cursor():
null
| ResolvedPos
Returns a resolved position if this is a cursor selection (an empty text selection), and null otherwise.
Returns
Section titled “Returns”null
| ResolvedPos
Get Signature
Section titled “Get Signature”get $from():
ResolvedPos
The resolved lower bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get $to():
ResolvedPos
The resolved upper bound of the selection’s main range.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”anchor
Section titled “anchor”Get Signature
Section titled “Get Signature”get anchor():
number
The selection’s anchor, as an unresolved position.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get empty():
boolean
Indicates whether the selection contains any content.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get from():
number
The lower bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get head():
number
The selection’s head.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get to():
number
The upper bound of the selection’s main range.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”content()
Section titled “content()”-
Get the content of this selection as a slice.
Inherited from
Section titled “Inherited from”
-
Test whether the selection is the same as another selection.
Overrides
Section titled “Overrides”
getBookmark()
Section titled “getBookmark()”-
Get a bookmark for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that.
Overrides
Section titled “Overrides”
-
map(
doc
:ProseMirrorNode
,mapping
:Mappable
):Selection
-
Map this selection through a mappable thing.
doc
should be the new document to which we are mapping.Overrides
Section titled “Overrides”
replace()
Section titled “replace()”-
replace(
tr
:Transaction
,content?
:Slice
):void
-
Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction.
Overrides
Section titled “Overrides”
replaceWith()
Section titled “replaceWith()”-
replaceWith(
tr
:Transaction
,node
:ProseMirrorNode
):void
-
Replace the selection with the given node, appending the changes to the given transaction.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Convert the selection to a JSON representation. When implementing this for a custom selection class, make sure to give the object a
type
property whose value matches the ID under which you registered your class.Overrides
Section titled “Overrides”
atEnd()
Section titled “atEnd()”-
static atEnd(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the end of the given document.
Inherited from
Section titled “Inherited from”
atStart()
Section titled “atStart()”-
static atStart(
doc
:ProseMirrorNode
):Selection
-
Find the cursor or leaf node selection closest to the start of the given document. Will return an
AllSelection
if no valid position exists.Inherited from
Section titled “Inherited from”
between()
Section titled “between()”-
static between(
$anchor
:ResolvedPos
,$head
:ResolvedPos
,bias?
:number
):Selection
-
Return a text selection that spans the given positions or, if they aren’t text positions, find a text selection near them.
bias
determines whether the method searches forward (default) or backwards (negative number) first. Will fall back to callingSelection.near
when the document doesn’t contain a valid text position.
create()
Section titled “create()”-
static create(
doc
:ProseMirrorNode
,anchor
:number
,head?
:number
):TextSelection
-
Create a text selection from non-resolved positions.
findFrom()
Section titled “findFrom()”-
static findFrom(
$pos
:ResolvedPos
,dir
:number
,textOnly?
:boolean
):null
|Selection
-
Find a valid cursor or leaf node selection starting at the given position and searching back if
dir
is negative, and forward if positive. WhentextOnly
is true, only consider cursor selections. Will return null when no valid selection position is found.Inherited from
Section titled “Inherited from”
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
doc
:ProseMirrorNode
,json
:any
):Selection
-
Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method).
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,selectionClass
:object
):object
-
To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that’s unlikely to clash with classes from other modules.
Inherited from
Section titled “Inherited from”
near()
Section titled “near()”-
static near(
$pos
:ResolvedPos
,bias?
:number
):Selection
-
Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if
bias
is negative, it will search backwards first.Inherited from
Section titled “Inherited from”
Transaction
Section titled “Transaction”An editor state transaction, which can be applied to a state to create an updated state. Use EditorState.tr
to create an instance.
Transactions track changes to the document (they are a subclass of Transform
), but also other state changes, like selection updates and adjustments of the set of stored marks. In addition, you can store metadata properties in a transaction, which are extra pieces of information that client code or plugins can use to describe what a transaction represents, so that they can update their own state accordingly.
The editor view uses a few metadata properties: it will attach a property "pointer"
with the value true
to selection transactions directly caused by mouse or touch input, a "composition"
property holding an ID identifying the composition that caused it to transactions caused by composed DOM input, and a "uiEvent"
property of that may be "paste"
, "cut"
, or "drop"
.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new Transaction(
doc
:ProseMirrorNode
):Transaction
-
Create a transform that starts with the given document.
Inherited from
Section titled “Inherited from”
Properties
Section titled “Properties”-
The current document (the result of applying the steps in the transform).
-
readonly docs:
ProseMirrorNode
[] -
The documents before each of the steps.
-
storedMarks:
null
| readonlyMark
[] -
The stored marks set by this transaction, if any.
-
time:
number
-
The timestamp associated with this transaction, in the same format as
Date.now()
.
Accessors
Section titled “Accessors”before
Section titled “before”Get Signature
Section titled “Get Signature”get before():
ProseMirrorNode
The starting document.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”docChanged
Section titled “docChanged”Get Signature
Section titled “Get Signature”get docChanged():
boolean
True when the document has been changed (when there are any steps).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isGeneric
Section titled “isGeneric”Get Signature
Section titled “Get Signature”get isGeneric():
boolean
Returns true if this transaction doesn’t contain any metadata, and can thus safely be extended.
Returns
Section titled “Returns”boolean
scrolledIntoView
Section titled “scrolledIntoView”Get Signature
Section titled “Get Signature”get scrolledIntoView():
boolean
True when this transaction has had scrollIntoView
called on it.
Returns
Section titled “Returns”boolean
selection
Section titled “selection”Get Signature
Section titled “Get Signature”The transaction’s current selection. This defaults to the editor selection mapped through the steps in the transaction, but can be overwritten with setSelection
.
Returns
Section titled “Returns”selectionSet
Section titled “selectionSet”Get Signature
Section titled “Get Signature”get selectionSet():
boolean
Whether the selection was explicitly updated by this transaction.
Returns
Section titled “Returns”boolean
storedMarksSet
Section titled “storedMarksSet”Get Signature
Section titled “Get Signature”get storedMarksSet():
boolean
Whether the stored marks were explicitly set for this transaction.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”addMark()
Section titled “addMark()”-
Add the given mark to the inline content between
from
andto
.Inherited from
Section titled “Inherited from”
addNodeMark()
Section titled “addNodeMark()”-
addNodeMark(
pos
:number
,mark
:Mark
):this
-
Add a mark to the node at position
pos
.Inherited from
Section titled “Inherited from”
addStoredMark()
Section titled “addStoredMark()”-
addStoredMark(
mark
:Mark
):this
-
Add a mark to the set of stored marks.
clearIncompatible()
Section titled “clearIncompatible()”-
clearIncompatible(
pos
:number
,parentType
:NodeType
,match?
:ContentMatch
):this
-
Removes all marks and nodes from the content of the node at
pos
that don’t match the given new parent node type. Accepts an optional starting content match as third argument.Inherited from
Section titled “Inherited from”
delete()
Section titled “delete()”-
delete(
from
:number
,to
:number
):this
-
Delete the content between the given positions.
Inherited from
Section titled “Inherited from”
deleteRange()
Section titled “deleteRange()”-
deleteRange(
from
:number
,to
:number
):this
-
Delete the given range, expanding it to cover fully covered parent nodes until a valid replace is found.
Inherited from
Section titled “Inherited from”
deleteSelection()
Section titled “deleteSelection()”-
deleteSelection():
this
-
Delete the selection.
ensureMarks()
Section titled “ensureMarks()”-
ensureMarks(
marks
: readonlyMark
[]):this
-
Make sure the current stored marks or, if that is null, the marks at the selection, match the given set of marks. Does nothing if this is already the case.
getMeta()
Section titled “getMeta()”-
getMeta(
key
:string
|ProseMirrorPlugin
<any
> |PluginKey
<any
>):any
-
Retrieve a metadata property for a given name or plugin.
insert()
Section titled “insert()”-
insert(
pos
:number
,content
:ProseMirrorNode
|ProseMirrorFragment
| readonlyProseMirrorNode
[]):this
-
Insert the given content at the given position.
Inherited from
Section titled “Inherited from”
insertText()
Section titled “insertText()”-
insertText(
text
:string
,from?
:number
,to?
:number
):this
-
Replace the given range, or the selection if no range is given, with a text node containing the given string.
join()
Section titled “join()”-
join(
pos
:number
,depth?
:number
):this
-
Join the blocks around the given position. If depth is 2, their last and first siblings are also joined, and so on.
Inherited from
Section titled “Inherited from”
lift()
Section titled “lift()”-
Split the content in the given range off from its parent, if there is sibling content before or after it, and move it up the tree to the depth specified by
target
. You’ll probably want to useliftTarget
to computetarget
, to make sure the lift is valid.Inherited from
Section titled “Inherited from”
maybeStep()
Section titled “maybeStep()”-
maybeStep(
step
:Step
):StepResult
-
Try to apply a step in this transformation, ignoring it if it fails. Returns the step result.
Inherited from
Section titled “Inherited from”
removeMark()
Section titled “removeMark()”-
removeMark(
from
:number
,to
:number
,mark?
:null
|MarkType
|Mark
):this
-
Remove marks from inline nodes between
from
andto
. Whenmark
is a single mark, remove precisely that mark. When it is a mark type, remove all marks of that type. When it is null, remove all marks of any type.Inherited from
Section titled “Inherited from”
removeNodeMark()
Section titled “removeNodeMark()”-
removeNodeMark(
pos
:number
,mark
:MarkType
|Mark
):this
-
Remove a mark (or all marks of the given type) from the node at position
pos
.Inherited from
Section titled “Inherited from”
removeStoredMark()
Section titled “removeStoredMark()”-
removeStoredMark(
mark
:MarkType
|Mark
):this
-
Remove a mark or mark type from the set of stored marks.
replace()
Section titled “replace()”-
Replace the part of the document between
from
andto
with the givenslice
.Inherited from
Section titled “Inherited from”
replaceRange()
Section titled “replaceRange()”-
replaceRange(
from
:number
,to
:number
,slice
:Slice
):this
-
Replace a range of the document with a given slice, using
from
,to
, and the slice’sopenStart
property as hints, rather than fixed start and end points. This method may grow the replaced area or close open nodes in the slice in order to get a fit that is more in line with WYSIWYG expectations, by dropping fully covered parent nodes of the replaced region when they are marked non-defining as context, or including an open parent node from the slice that is marked as defining its content.This is the method, for example, to handle paste. The similar
replace
method is a more primitive tool which will not move the start and end of its given range, and is useful in situations where you need more precise control over what happens.Inherited from
Section titled “Inherited from”
replaceRangeWith()
Section titled “replaceRangeWith()”-
replaceRangeWith(
from
:number
,to
:number
,node
:ProseMirrorNode
):this
-
Replace the given range with a node, but use
from
andto
as hints, rather than precise positions. When from and to are the same and are at the start or end of a parent node in which the given node doesn’t fit, this method may move them out towards a parent that does allow the given node to be placed. When the given range completely covers a parent node, this method may completely replace that parent node.Inherited from
Section titled “Inherited from”
replaceSelection()
Section titled “replaceSelection()”-
replaceSelection(
slice
:Slice
):this
-
Replace the current selection with the given slice.
replaceSelectionWith()
Section titled “replaceSelectionWith()”-
replaceSelectionWith(
node
:ProseMirrorNode
,inheritMarks?
:boolean
):this
-
Replace the selection with the given node. When
inheritMarks
is true and the content is inline, it inherits the marks from the place where it is inserted.
replaceWith()
Section titled “replaceWith()”-
replaceWith(
from
:number
,to
:number
,content
:ProseMirrorNode
|ProseMirrorFragment
| readonlyProseMirrorNode
[]):this
-
Replace the given range with the given content, which may be a fragment, node, or array of nodes.
Inherited from
Section titled “Inherited from”
scrollIntoView()
Section titled “scrollIntoView()”-
scrollIntoView():
this
-
Indicate that the editor should scroll the selection into view when updated to the state produced by this transaction.
setBlockType()
Section titled “setBlockType()”-
setBlockType(
from
:number
,to
:undefined
|number
,type
:NodeType
,attrs?
:null
|Attrs
| (oldNode
:ProseMirrorNode
) =>Attrs
):this
-
Set the type of all textblocks (partly) between
from
andto
to the given node type with the given attributes.Inherited from
Section titled “Inherited from”
setDocAttribute()
Section titled “setDocAttribute()”-
setDocAttribute(
attr
:string
,value
:any
):this
-
Set a single attribute on the document to a new value.
Inherited from
Section titled “Inherited from”
setMeta()
Section titled “setMeta()”-
setMeta(
key
:string
|ProseMirrorPlugin
<any
> |PluginKey
<any
>,value
:any
):this
-
Store a metadata property in this transaction, keyed either by name or by plugin.
setNodeAttribute()
Section titled “setNodeAttribute()”-
setNodeAttribute(
pos
:number
,attr
:string
,value
:any
):this
-
Set a single attribute on a given node to a new value. The
pos
addresses the document content. UsesetDocAttribute
to set attributes on the document itself.Inherited from
Section titled “Inherited from”
setNodeMarkup()
Section titled “setNodeMarkup()”-
setNodeMarkup(
pos
:number
,type?
:null
|NodeType
,attrs?
:null
|Attrs
,marks?
: readonlyMark
[]):this
-
Change the type, attributes, and/or marks of the node at
pos
. Whentype
isn’t given, the existing node type is preserved,Inherited from
Section titled “Inherited from”
setSelection()
Section titled “setSelection()”-
setSelection(
selection
:Selection
):this
-
Update the transaction’s current selection. Will determine the selection that the editor gets when the transaction is applied.
setStoredMarks()
Section titled “setStoredMarks()”-
setStoredMarks(
marks
:null
| readonlyMark
[]):this
-
Set the current stored marks.
setTime()
Section titled “setTime()”-
setTime(
time
:number
):this
-
Update the timestamp for the transaction.
split()
Section titled “split()”-
split(
pos
:number
,depth?
:number
,typesAfter?
: (null
| {attrs?
:null
|Attrs
;type
:NodeType
; })[]):this
-
Split the node at the given position, and optionally, if
depth
is greater than one, any number of nodes above that. By default, the parts split off will inherit the node type of the original node. This can be changed by passing an array of types and attributes to use after the split (with the outermost nodes coming first).Inherited from
Section titled “Inherited from”
step()
Section titled “step()”-
Apply a new step in this transform, saving the result. Throws an error when the step fails.
Inherited from
Section titled “Inherited from”
wrap()
Section titled “wrap()”-
Wrap the given range in the given set of wrappers. The wrappers are assumed to be valid in this position, and should probably be computed with
findWrapping
.Inherited from
Section titled “Inherited from”
Interfaces
Section titled “Interfaces”EditorStateConfig
Section titled “EditorStateConfig”The type of object passed to EditorState.create
.
Properties
Section titled “Properties”-
The starting document. Either this or
schema
must be provided.
-
plugins?: readonly
ProseMirrorPlugin
<any
>[] -
The plugins that should be active in this state.
-
storedMarks?:
null
| readonlyMark
[] -
The initial set of stored marks.
PluginSpec<PluginState>
Section titled “PluginSpec<PluginState>”This is the type passed to the Plugin
constructor. It provides a definition for a plugin.
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Indexable
Section titled “Indexable”[key
: string
]: any
Additional properties are allowed on plugin specs, which can be read via Plugin.spec
.
Properties
Section titled “Properties”-
appendTransaction?: (
transactions
: readonlyTransaction
[],oldState
:EditorState
,newState
:EditorState
) =>undefined
|null
|Transaction
-
Allows the plugin to append another transaction to be applied after the given array of transactions. When another plugin appends a transaction after this was called, it is called again with the new state and new transactions—but only the new transactions, i.e. it won’t be passed transactions that it already saw.
-
filterTransaction?: (
tr
:Transaction
,state
:EditorState
) =>boolean
-
When present, this will be called before a transaction is applied by the state, allowing the plugin to cancel it (by returning false).
-
Can be used to make this a keyed plugin. You can have only one plugin with a given key in a given state, but it is possible to access the plugin’s configuration and state through the key, without having access to the plugin instance object.
-
props?:
EditorProps
<ProseMirrorPlugin
<PluginState
>> -
The view props added by this plugin. Props that are functions will be bound to have the plugin instance as their
this
binding.
-
state?:
StateField
<PluginState
> -
Allows a plugin to define a state field, an extra slot in the state object in which it can keep its own data.
-
view?: (
view
:EditorView
) =>PluginView
-
When the plugin needs to interact with the editor view, or set something up in the DOM, use this field. The function will be called when the plugin’s state is associated with an editor view.
SelectionBookmark
Section titled “SelectionBookmark”A lightweight, document-independent representation of a selection. You can define a custom bookmark type for a custom selection class to make the history handle it well.
Properties
Section titled “Properties”-
map: (
mapping
:Mappable
) =>SelectionBookmark
-
Map the bookmark through a set of changes.
-
resolve: (
doc
:ProseMirrorNode
) =>Selection
-
Resolve the bookmark to a real selection again. This may need to do some error checking and may fall back to a default (usually
TextSelection.between
) if mapping made the bookmark invalid.
StateField<T>
Section titled “StateField<T>”A plugin spec may provide a state field (under its state
property) of this type, which describes the state it wants to keep. Functions provided here are always called with the plugin instance as their this
binding.
Type Parameters
Section titled “Type Parameters”Type Parameter |
---|
|
Properties
Section titled “Properties”-
apply: (
tr
:Transaction
,value
:T
,oldState
:EditorState
,newState
:EditorState
) =>T
-
Apply the given transaction to this state field, producing a new field value. Note that the
newState
argument is again a partially constructed state does not yet contain the state from plugins coming after this one.
-
fromJSON?: (
config
:EditorStateConfig
,value
:any
,state
:EditorState
) =>T
-
Deserialize the JSON representation of this field. Note that the
state
argument is again a half-initialized state.
-
init: (
config
:EditorStateConfig
,instance
:EditorState
) =>T
-
Initialize the value of the field.
config
will be the object passed toEditorState.create
. Note thatinstance
is a half-initialized state instance, and will not have values for plugin fields initialized after this one.
-
toJSON?: (
value
:T
) =>any
-
Convert this field to JSON. Optional, can be left off to disable JSON serialization for the field.
Type Aliases
Section titled “Type Aliases”Command()
Section titled “Command()”-
type Command = (
state
:EditorState
,dispatch?
: (tr
:Transaction
) =>void
,view?
:EditorView
) =>boolean
-
Commands are functions that take a state and a an optional transaction dispatch function and…
- determine whether they apply to this state
- if not, return false
- if
dispatch
was passed, perform their effect, possibly by passing a transaction todispatch
- return true
In some cases, the editor view is passed as a third argument.
PluginView
Section titled “PluginView” type PluginView = {
destroy?
: () => void
; update?
: (view
: EditorView
, prevState
: EditorState
) => void
; }
A stateful object that can be installed in an editor by a plugin.
Properties
Section titled “Properties”-
destroy?: () =>
void
-
Called when the view is destroyed or receives a state with different plugins.
-
update?: (
view
:EditorView
,prevState
:EditorState
) =>void
-
Called whenever the view’s state is updated.
References
Section titled “References”Plugin
Section titled “Plugin”Renames and re-exports ProseMirrorPlugin