prosekit/pm/transform
Re-exports from prosemirror-transform.
Classes
Section titled “Classes”AddMarkStep
Section titled “AddMarkStep”Add a mark to all inline content between two positions.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new AddMarkStep(
from
:number
,to
:number
,mark
:Mark
):AddMarkStep
-
Create a mark step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly from:
number
-
The start of the marked range.
-
readonly to:
number
-
The end of the marked range.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Inherited from
Section titled “Inherited from”
invert()
Section titled “invert()”-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Overrides
Section titled “Overrides”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
AddNodeMarkStep
Section titled “AddNodeMarkStep”Add a mark to a specific node.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new AddNodeMarkStep(
pos
:number
,mark
:Mark
):AddNodeMarkStep
-
Create a node mark step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly pos:
number
-
The position of the target node.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Inherited from
Section titled “Inherited from”
invert()
Section titled “invert()”-
invert(
doc
:ProseMirrorNode
):Step
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
AttrStep
Section titled “AttrStep”Update an attribute in a specific node.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new AttrStep(
pos
:number
,attr
:string
,value
:any
):AttrStep
-
Construct an attribute step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly attr:
string
-
The attribute to set.
-
readonly pos:
number
-
The position of the target node.
-
readonly value:
any
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Overrides
Section titled “Overrides”
invert()
Section titled “invert()”-
invert(
doc
:ProseMirrorNode
):AttrStep
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Overrides
Section titled “Overrides”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
DocAttrStep
Section titled “DocAttrStep”Update an attribute in the doc node.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new DocAttrStep(
attr
:string
,value
:any
):DocAttrStep
-
Construct an attribute step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly attr:
string
-
The attribute to set.
-
readonly value:
any
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Overrides
Section titled “Overrides”
invert()
Section titled “invert()”-
invert(
doc
:ProseMirrorNode
):DocAttrStep
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
static fromJSON(
schema
:Schema
,json
:any
):DocAttrStep
-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Overrides
Section titled “Overrides”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
Mapping
Section titled “Mapping”A mapping represents a pipeline of zero or more step maps. It has special provisions for losslessly handling mapping positions through a series of steps in which some steps are inverted versions of earlier steps. (This comes up when ‘rebasing’ steps for collaboration or history management.)
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new Mapping(
maps?
: readonlyStepMap
[],from?
:number
,to?
:number
):Mapping
-
Create a new mapping with the given position maps.
Properties
Section titled “Properties”-
from:
number
-
The starting position in the
maps
array, used whenmap
ormapResult
is called.
-
to:
number
-
The end position in the
maps
array.
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get maps(): readonly
StepMap
[]
The step maps in this mapping.
Returns
Section titled “Returns”readonly StepMap
[]
Methods
Section titled “Methods”appendMap()
Section titled “appendMap()”-
Add a step map to the end of this mapping. If
mirrors
is given, it should be the index of the step map that is the mirror image of this one.
appendMapping()
Section titled “appendMapping()”-
appendMapping(
mapping
:Mapping
):void
-
Add all the step maps in a given mapping to this one (preserving mirroring information).
appendMappingInverted()
Section titled “appendMappingInverted()”-
appendMappingInverted(
mapping
:Mapping
):void
-
Append the inverse of the given mapping to this one.
getMirror()
Section titled “getMirror()”-
getMirror(
n
:number
):undefined
|number
-
Finds the offset of the step map that mirrors the map at the given offset, in this mapping (as per the second argument to
appendMap
).
invert()
Section titled “invert()”-
map(
pos
:number
,assoc?
:number
):number
-
Map a position through this mapping.
Implementation of
Section titled “Implementation of”
mapResult()
Section titled “mapResult()”-
Map a position through this mapping, returning a mapping result.
Implementation of
Section titled “Implementation of”
slice()
Section titled “slice()”-
Create a mapping that maps only through a part of this one.
MapResult
Section titled “MapResult”An object representing a mapped position with extra information.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”Properties
Section titled “Properties”-
readonly pos:
number
-
The mapped version of the position.
Accessors
Section titled “Accessors”deleted
Section titled “deleted”Get Signature
Section titled “Get Signature”get deleted():
boolean
Tells you whether the position was deleted, that is, whether the step removed the token on the side queried (via the assoc
) argument from the document.
Returns
Section titled “Returns”boolean
deletedAcross
Section titled “deletedAcross”Get Signature
Section titled “Get Signature”get deletedAcross():
boolean
Tells whether any of the steps mapped through deletes across the position (including both the token before and after the position).
Returns
Section titled “Returns”boolean
deletedAfter
Section titled “deletedAfter”Get Signature
Section titled “Get Signature”get deletedAfter():
boolean
True when the token after the mapped position was deleted.
Returns
Section titled “Returns”boolean
deletedBefore
Section titled “deletedBefore”Get Signature
Section titled “Get Signature”get deletedBefore():
boolean
Tells you whether the token before the mapped position was deleted.
Returns
Section titled “Returns”boolean
RemoveMarkStep
Section titled “RemoveMarkStep”Remove a mark from all inline content between two positions.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new RemoveMarkStep(
from
:number
,to
:number
,mark
:Mark
):RemoveMarkStep
-
Create a mark-removing step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly from:
number
-
The start of the unmarked range.
-
readonly to:
number
-
The end of the unmarked range.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Inherited from
Section titled “Inherited from”
invert()
Section titled “invert()”-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Overrides
Section titled “Overrides”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
RemoveNodeMarkStep
Section titled “RemoveNodeMarkStep”Remove a mark from a specific node.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new RemoveNodeMarkStep(
pos
:number
,mark
:Mark
):RemoveNodeMarkStep
-
Create a mark-removing step.
Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly pos:
number
-
The position of the target node.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Inherited from
Section titled “Inherited from”
invert()
Section titled “invert()”-
invert(
doc
:ProseMirrorNode
):Step
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
ReplaceAroundStep
Section titled “ReplaceAroundStep”Replace a part of the document with a slice of content, but preserve a range of the replaced content by moving it into the slice.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new ReplaceAroundStep(
from
:number
,to
:number
,gapFrom
:number
,gapTo
:number
,slice
:Slice
,insert
:number
):ReplaceAroundStep
-
Create a replace-around step with the given range and gap.
insert
should be the point in the slice into which the content of the gap should be moved.structure
has the same meaning as it has in theReplaceStep
class.Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly from:
number
-
The start position of the replaced range.
-
readonly gapFrom:
number
-
The start of preserved range.
-
readonly gapTo:
number
-
The end of preserved range.
-
readonly insert:
number
-
The position in the slice where the preserved range should be inserted.
-
readonly to:
number
-
The end position of the replaced range.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Overrides
Section titled “Overrides”
invert()
Section titled “invert()”-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
map(
mapping
:Mappable
):null
|ReplaceAroundStep
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Inherited from
Section titled “Inherited from”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
ReplaceStep
Section titled “ReplaceStep”Replace a part of the document with a slice of new content.
Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new ReplaceStep(
from
:number
,to
:number
,slice
:Slice
):ReplaceStep
-
The given
slice
should fit the ‘gap’ betweenfrom
andto
—the depths must line up, and the surrounding nodes must be able to be joined with the open sides of the slice. Whenstructure
is true, the step will fail if the content between from and to is not just a sequence of closing and then opening tokens (this is to guard against rebased replace steps overwriting something they weren’t supposed to).Overrides
Section titled “Overrides”
Properties
Section titled “Properties”-
readonly from:
number
-
The start position of the replaced range.
-
readonly to:
number
-
The end position of the replaced range.
Methods
Section titled “Methods”apply()
Section titled “apply()”-
apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
Overrides
Section titled “Overrides”
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
Overrides
Section titled “Overrides”
invert()
Section titled “invert()”-
invert(
doc
:ProseMirrorNode
):ReplaceStep
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
Overrides
Section titled “Overrides”
-
map(
mapping
:Mappable
):null
|ReplaceStep
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.Overrides
Section titled “Overrides”
merge()
Section titled “merge()”-
merge(
other
:Step
):null
|ReplaceStep
-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
Overrides
Section titled “Overrides”
toJSON()
Section titled “toJSON()”-
toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.Overrides
Section titled “Overrides”
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
Inherited from
Section titled “Inherited from”
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
Inherited from
Section titled “Inherited from”
abstract Step
Section titled “abstract Step”A step object represents an atomic change. It generally applies only to the document it was created for, since the positions stored in it will only make sense for that document.
New steps are defined by creating classes that extend Step
, overriding the apply
, invert
, map
, getMap
and fromJSON
methods, and registering your class with a unique JSON-serialization identifier using Step.jsonID
.
Extended by
Section titled “Extended by”AddMarkStep
AddNodeMarkStep
AttrStep
DocAttrStep
RemoveMarkStep
RemoveNodeMarkStep
ReplaceAroundStep
ReplaceStep
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”Methods
Section titled “Methods”apply()
Section titled “apply()”-
abstract apply(
doc
:ProseMirrorNode
):StepResult
-
Applies this step to the given document, returning a result object that either indicates failure, if the step can not be applied to this document, or indicates success by containing a transformed document.
getMap()
Section titled “getMap()”-
Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document.
invert()
Section titled “invert()”-
abstract invert(
doc
:ProseMirrorNode
):Step
-
Create an inverted version of this step. Needs the document as it was before the step as argument.
-
Map this step through a mappable thing, returning either a version of that step with its positions adjusted, or
null
if the step was entirely deleted by the mapping.
merge()
Section titled “merge()”-
Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can’t be merged.
toJSON()
Section titled “toJSON()”-
abstract toJSON():
any
-
Create a JSON-serializeable representation of this step. When defining this for a custom subclass, make sure the result object includes the step type’s JSON id under the
stepType
property.
fromJSON()
Section titled “fromJSON()”-
Deserialize a step from its JSON representation. Will call through to the step class’ own implementation of this method.
jsonID()
Section titled “jsonID()”-
static jsonID(
id
:string
,stepClass
:object
):object
-
To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that’s unlikely to clash with steps from other modules.
StepMap
Section titled “StepMap”A map describing the deletions and insertions made by a step, which can be used to find the correspondence between positions in the pre-step version of a document and the same position in the post-step version.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
Create a position map. The modifications to the document are represented as an array of numbers, in which each group of three represents a modified chunk as
[start, oldSize, newSize]
.
Properties
Section titled “Properties”Methods
Section titled “Methods”forEach()
Section titled “forEach()”-
forEach(
f
: (oldStart
:number
,oldEnd
:number
,newStart
:number
,newEnd
:number
) =>void
):void
-
Calls the given function on each of the changed ranges included in this map.
invert()
Section titled “invert()”-
Create an inverted version of this map. The result can be used to map positions in the post-step document to the pre-step document.
-
map(
pos
:number
,assoc?
:number
):number
-
Map a position through this object. When given,
assoc
(should be -1 or 1, defaults to 1) determines with which side the position is associated, which determines in which direction to move when a chunk of content is inserted at the mapped position.Implementation of
Section titled “Implementation of”
mapResult()
Section titled “mapResult()”-
Map a position, and return an object containing additional information about the mapping. The result’s
deleted
field tells you whether the position was deleted (completely enclosed in a replaced range) during the mapping. When content on only one side is deleted, the position itself is only considered deleted whenassoc
points in the direction of the deleted content.Implementation of
Section titled “Implementation of”
offset()
Section titled “offset()”-
Create a map that moves all positions by offset
n
(which may be negative). This can be useful when applying steps meant for a sub-document to a larger document, or vice-versa.
StepResult
Section titled “StepResult”The result of applying a step. Contains either a new document or a failure value.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new StepResult():
StepResult
Properties
Section titled “Properties”-
readonly doc:
null
|ProseMirrorNode
-
The transformed document, if successful.
-
readonly failed:
null
|string
-
The failure message, if unsuccessful.
Methods
Section titled “Methods”fail()
Section titled “fail()”-
static fail(
message
:string
):StepResult
-
Create a failed step result.
fromReplace()
Section titled “fromReplace()”-
static fromReplace(
doc
:ProseMirrorNode
,from
:number
,to
:number
,slice
:Slice
):StepResult
-
Call
Node.replace
with the given arguments. Create a successful result if it succeeds, and a failed one if it throws aReplaceError
.
-
static ok(
doc
:ProseMirrorNode
):StepResult
-
Create a successful step result.
Transform
Section titled “Transform”Abstraction to build up and track an array of steps representing a document transformation.
Most transforming methods return the Transform
object itself, so that they can be chained.
Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”-
new Transform(
doc
:ProseMirrorNode
):Transform
-
Create a transform that starts with the given document.
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.
Accessors
Section titled “Accessors”before
Section titled “before”Get Signature
Section titled “Get Signature”get before():
ProseMirrorNode
The starting document.
Returns
Section titled “Returns”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
Methods
Section titled “Methods”addMark()
Section titled “addMark()”-
Add the given mark to the inline content between
from
andto
.
addNodeMark()
Section titled “addNodeMark()”-
addNodeMark(
pos
:number
,mark
:Mark
):this
-
Add a mark to the node at position
pos
.
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.
delete()
Section titled “delete()”-
delete(
from
:number
,to
:number
):this
-
Delete the content between the given positions.
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.
insert()
Section titled “insert()”-
insert(
pos
:number
,content
:ProseMirrorNode
|ProseMirrorFragment
| readonlyProseMirrorNode
[]):this
-
Insert the given content at the given position.
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.
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.
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.
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.
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
.
replace()
Section titled “replace()”-
Replace the part of the document between
from
andto
with the givenslice
.
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.
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.
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.
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.
setDocAttribute()
Section titled “setDocAttribute()”-
setDocAttribute(
attr
:string
,value
:any
):this
-
Set a single attribute on the document to a new value.
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.
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,
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).
step()
Section titled “step()”-
Apply a new step in this transform, saving the result. Throws an error when the step fails.
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
.
Interfaces
Section titled “Interfaces”Mappable
Section titled “Mappable”There are several things that positions can be mapped through. Such objects conform to this interface.
Properties
Section titled “Properties”-
map: (
pos
:number
,assoc?
:number
) =>number
-
Map a position through this object. When given,
assoc
(should be -1 or 1, defaults to 1) determines with which side the position is associated, which determines in which direction to move when a chunk of content is inserted at the mapped position.
-
Map a position, and return an object containing additional information about the mapping. The result’s
deleted
field tells you whether the position was deleted (completely enclosed in a replaced range) during the mapping. When content on only one side is deleted, the position itself is only considered deleted whenassoc
points in the direction of the deleted content.
Functions
Section titled “Functions”canJoin()
Section titled “canJoin()”-
function canJoin(
doc
:ProseMirrorNode
,pos
:number
):boolean
-
Test whether the blocks before and after a given position can be joined.
canSplit()
Section titled “canSplit()”-
function canSplit(
doc
:ProseMirrorNode
,pos
:number
,depth?
:number
,typesAfter?
: (null
| {attrs?
:null
|Attrs
;type
:NodeType
; })[]):boolean
-
Check whether splitting at the given position is allowed.
dropPoint()
Section titled “dropPoint()”-
function dropPoint(
doc
:ProseMirrorNode
,pos
:number
,slice
:Slice
):null
|number
-
Finds a position at or around the given position where the given slice can be inserted. Will look at parent nodes’ nearest boundary and try there, even if the original position wasn’t directly at the start or end of that node. Returns null when no position was found.
findWrapping()
Section titled “findWrapping()”-
function findWrapping(
range
:NodeRange
,nodeType
:NodeType
,attrs?
:null
|Attrs
,innerRange?
:NodeRange
):null
|object
[] -
Try to find a valid way to wrap the content in the given range in a node of the given type. May introduce extra nodes around and inside the wrapper node, if necessary. Returns null if no valid wrapping could be found. When
innerRange
is given, that range’s content is used as the content to fit into the wrapping, instead of the content ofrange
.
insertPoint()
Section titled “insertPoint()”-
function insertPoint(
doc
:ProseMirrorNode
,pos
:number
,nodeType
:NodeType
):null
|number
-
Try to find a point where a node of the given type can be inserted near
pos
, by searching up the node hierarchy whenpos
itself isn’t a valid place but is at the start or end of a node. Return null if no position was found.
joinPoint()
Section titled “joinPoint()”-
function joinPoint(
doc
:ProseMirrorNode
,pos
:number
,dir?
:number
):undefined
|number
-
Find an ancestor of the given position that can be joined to the block before (or after if
dir
is positive). Returns the joinable point, if any.
liftTarget()
Section titled “liftTarget()”-
function liftTarget(
range
:NodeRange
):null
|number
-
Try to find a target depth to which the content in the given range can be lifted. Will not go across isolating parent nodes.
replaceStep()
Section titled “replaceStep()”-
function replaceStep(
doc
:ProseMirrorNode
,from
:number
,to?
:number
,slice?
:Slice
):null
|Step
-
‘Fit’ a slice into a given position in the document, producing a step that inserts it. Will return null if there’s no meaningful way to insert the slice here, or inserting it would be a no-op (an empty slice over an empty range).