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.
§Properties
True when the document has been changed (when there are any steps).
§Methods
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 the given range, expanding it to cover fully covered parent nodes until a valid replace is found.
Join the blocks around the given position. If depth is 2, their last and first siblings are also joined, and so on.
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 use
liftTarget
to compute target
, to make
sure the lift is valid.
Try to apply a step in this transformation, ignoring it if it fails. Returns the step result.
Replace a range of the document with a given slice, using
from
, to
, and the slice's
openStart
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`](https://prosemirror.net/docs/ref/#transform.Transform.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.
Replace the given range with a node, but use from
and to
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.
Set a single attribute on the document to a new value.
Set a single attribute on a given node to a new value.
The pos
addresses the document content. Use setDocAttribute
to set attributes on the document itself.
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.