Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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.

class Transform {
constructor(doc: Node);
get before(): Node;
doc: Node;
get docChanged(): boolean;
readonly docs: Node[];
readonly mapping: Mapping;
readonly steps: Step[];
 
addMark(
from: number,
to: number,
mark: Mark,
): this;
addNodeMark(pos: number, mark: Mark): this;
clearIncompatible(
pos: number,
parentType: NodeType,
match?: ContentMatch,
): this;
delete(from: number, to: number): this;
deleteRange(from: number, to: number): this;
insert(pos: number, content: Fragment | Node | readonly Node[]): this;
join(pos: number, depth?: number): this;
lift(range: NodeRange, target: number): this;
maybeStep(step: Step): StepResult;
removeMark(
from: number,
to: number,
mark?: Mark | MarkType | null,
): this;
removeNodeMark(pos: number, mark: Mark | MarkType): this;
replace(
from: number,
to?: number,
slice?: Slice,
): this;
replaceRange(
from: number,
to: number,
slice: Slice,
): this;
replaceRangeWith(
from: number,
to: number,
node: Node,
): this;
replaceWith(
from: number,
to: number,
content: Fragment | Node | readonly Node[],
): this;
setBlockType(
from: number,
to: number | undefined,
type: NodeType,
attrs?: Attrs | null,
): this;
setDocAttribute(attr: string, value: any): this;
setNodeAttribute(
pos: number,
attr: string,
value: any,
): this;
setNodeMarkup(
pos: number,
type?: NodeType | null,
attrs?: Attrs | null,
marks?: readonly Mark[],
): this;
split(
pos: number,
depth?: number,
typesAfter?: (null | {
type: NodeType;
attrs?: Attrs | null;
}
)
[]
,
): this;
step(step: Step): this;
wrap(range: NodeRange, wrappers: readonly {
type: NodeType;
attrs?: Attrs | null;
}
[]
): this;
}

§Constructors

§
new Transform(doc: Node)
[src]

Create a transform that starts with the given document.

§Properties

§
before: Node readonly
[src]

The starting document.

§

The current document (the result of applying the steps in the transform).

§
docChanged: boolean readonly
[src]

True when the document has been changed (when there are any steps).

§
docs: Node[]
[src]

The documents before each of the steps.

§
mapping: Mapping
[src]

A mapping with the maps for each of the steps in this transform.

§
steps: Step[]
[src]

The steps in this transform.

§Methods

§
addMark(from: number, to: number, mark: Mark): this
[src]

Add the given mark to the inline content between from and to.

§
addNodeMark(pos: number, mark: Mark): this
[src]

Add a mark to the node at position pos.

§
clearIncompatible(pos: number, parentType: NodeType, match?: ContentMatch): this
[src]

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(from: number, to: number): this
[src]

Delete the content between the given positions.

§
deleteRange(from: number, to: number): this
[src]

Delete the given range, expanding it to cover fully covered parent nodes until a valid replace is found.

§
insert(pos: number, content: Fragment | Node | readonly Node[]): this
[src]

Insert the given content at the given position.

§
join(pos: number, depth?: number): this
[src]

Join the blocks around the given position. If depth is 2, their last and first siblings are also joined, and so on.

§
lift(range: NodeRange, target: number): this
[src]

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.

§
maybeStep(step: Step): StepResult
[src]

Try to apply a step in this transformation, ignoring it if it fails. Returns the step result.

§
removeMark(from: number, to: number, mark?: Mark | MarkType | null): this
[src]

Remove marks from inline nodes between from and to. When mark 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(pos: number, mark: Mark | MarkType): this
[src]

Remove a mark (or a mark of the given type) from the node at position pos.

§
replace(from: number, to?: number, slice?: Slice): this
[src]

Replace the part of the document between from and to with the given slice.

§
replaceRange(from: number, to: number, slice: Slice): this
[src]

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.
§
replaceRangeWith(from: number, to: number, node: Node): this
[src]

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.

§
replaceWith(from: number, to: number, content: Fragment | Node | readonly Node[]): this
[src]

Replace the given range with the given content, which may be a fragment, node, or array of nodes.

§
setBlockType(from: number, to: number | undefined, type: NodeType, attrs?: Attrs | null): this
[src]

Set the type of all textblocks (partly) between from and to to the given node type with the given attributes.

§
setDocAttribute(attr: string, value: any): this
[src]

Set a single attribute on the document to a new value.

§
setNodeAttribute(pos: number, attr: string, value: any): this
[src]

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.

§
setNodeMarkup(pos: number, type?: NodeType | null, attrs?: Attrs | null, marks?: readonly Mark[]): this
[src]

Change the type, attributes, and/or marks of the node at pos. When type isn't given, the existing node type is preserved,

§
split(pos: number, depth?: number, typesAfter?: (null | {
type: NodeType;
attrs?: Attrs | null;
}
)
[]
): this
[src]

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.

§
step(step: Step): this
[src]

Apply a new step in this transform, saving the result. Throws an error when the step fails.

§
wrap(range: NodeRange, wrappers: readonly {
type: NodeType;
attrs?: Attrs | null;
}
[]
): this
[src]

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.