ProsemirrorEx.Transform.Step behaviour (prosemirror_ex v0.3.0)

Copy Markdown View Source

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.

This module defines the behaviour that all step types must implement, and provides a registry for JSON serialization/deserialization.

Ports Step from prosemirror-transform/src/step.ts.

Summary

Callbacks

Applies this step to the given document, returning a StepResult.

Deserialize a step from its JSON representation.

Create an inverted version of this step. Needs the document as it was before the step.

Map this step through a mappable thing, returning a mapped step or nil.

Try to merge this step with another one. Returns the merged step or nil.

Get the step map that represents the changes made by this step.

Create a JSON-serializable representation of this step.

Functions

Deserialize a step from its JSON representation. Dispatches to the registered module based on the stepType field.

Register a step module under a string ID for JSON serialization. Raises if the ID is already registered.

Callbacks

apply(step, doc)

@callback apply(step :: term(), doc :: term()) :: ProsemirrorEx.Transform.StepResult.t()

Applies this step to the given document, returning a StepResult.

from_json(schema, json)

@callback from_json(schema :: term(), json :: map()) :: term()

Deserialize a step from its JSON representation.

invert(step, doc)

@callback invert(step :: term(), doc :: term()) :: term()

Create an inverted version of this step. Needs the document as it was before the step.

map(step, mappable)

@callback map(step :: term(), mappable :: term()) :: term() | nil

Map this step through a mappable thing, returning a mapped step or nil.

merge(step, other)

@callback merge(step :: term(), other :: term()) :: term() | nil

Try to merge this step with another one. Returns the merged step or nil.

step_map(step)

@callback step_map(step :: term()) :: ProsemirrorEx.Transform.StepMap.t()

Get the step map that represents the changes made by this step.

to_json(step)

@callback to_json(step :: term()) :: map()

Create a JSON-serializable representation of this step.

Functions

from_json(schema, json)

Deserialize a step from its JSON representation. Dispatches to the registered module based on the stepType field.

json_id(id, module)

Register a step module under a string ID for JSON serialization. Raises if the ID is already registered.