Documentation ¶
Overview ¶
Package transform implements document transforms, which are used by the editor to treat changes as first-class values, which can be saved, shared, and reasoned about.
Index ¶
- Variables
- type AddMarkStep
- func (s *AddMarkStep) Apply(doc *model.Node) StepResult
- func (s *AddMarkStep) GetMap() *StepMap
- func (s *AddMarkStep) Invert(doc *model.Node) Step
- func (s *AddMarkStep) Map(mapping Mappable) Step
- func (s *AddMarkStep) Merge(other Step) (Step, bool)
- func (s *AddMarkStep) ToJSON() map[string]interface{}
- type MapResult
- type Mappable
- type RemoveMarkStep
- func (s *RemoveMarkStep) Apply(doc *model.Node) StepResult
- func (s *RemoveMarkStep) GetMap() *StepMap
- func (s *RemoveMarkStep) Invert(doc *model.Node) Step
- func (s *RemoveMarkStep) Map(mapping Mappable) Step
- func (s *RemoveMarkStep) Merge(other Step) (Step, bool)
- func (s *RemoveMarkStep) ToJSON() map[string]interface{}
- type ReplaceAroundStep
- func (s *ReplaceAroundStep) Apply(doc *model.Node) StepResult
- func (s *ReplaceAroundStep) GetMap() *StepMap
- func (s *ReplaceAroundStep) Invert(doc *model.Node) Step
- func (s *ReplaceAroundStep) Map(mapping Mappable) Step
- func (s *ReplaceAroundStep) Merge(other Step) (Step, bool)
- func (s *ReplaceAroundStep) ToJSON() map[string]interface{}
- type ReplaceStep
- func (s *ReplaceStep) Apply(doc *model.Node) StepResult
- func (s *ReplaceStep) GetMap() *StepMap
- func (s *ReplaceStep) Invert(doc *model.Node) Step
- func (s *ReplaceStep) Map(mapping Mappable) Step
- func (s *ReplaceStep) Merge(other Step) (Step, bool)
- func (s *ReplaceStep) ToJSON() map[string]interface{}
- type SetAttrsStep
- func (s *SetAttrsStep) Apply(doc *model.Node) StepResult
- func (s *SetAttrsStep) GetMap() *StepMap
- func (s *SetAttrsStep) Invert(doc *model.Node) Step
- func (s *SetAttrsStep) Map(mapping Mappable) Step
- func (s *SetAttrsStep) Merge(other Step) (Step, bool)
- func (s *SetAttrsStep) ToJSON() map[string]interface{}
- type Step
- func AddMarkStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func RemoveMarkStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func ReplaceAroundStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func ReplaceStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func SetAttrsStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func StepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- func TableSortStepFromJSON(schema *model.Schema, obj map[string]interface{}) (Step, error)
- type StepMap
- type StepResult
Constants ¶
This section is empty.
Variables ¶
var EmptyStepMap = NewStepMap(nil)
EmptyStepMap is an empty StepMap.
Functions ¶
This section is empty.
Types ¶
type AddMarkStep ¶
AddMarkStep adds a mark to all inline content between two positions.
func NewAddMarkStep ¶
func NewAddMarkStep(from, to int, mark *model.Mark) *AddMarkStep
NewAddMarkStep is the constructor for AddMarkStep.
func (*AddMarkStep) Apply ¶
func (s *AddMarkStep) Apply(doc *model.Node) StepResult
Apply is a method of the Step interface.
func (*AddMarkStep) GetMap ¶
func (s *AddMarkStep) GetMap() *StepMap
GetMap is a method of the Step interface.
func (*AddMarkStep) Invert ¶
func (s *AddMarkStep) Invert(doc *model.Node) Step
Invert is a method of the Step interface.
func (*AddMarkStep) Map ¶
func (s *AddMarkStep) Map(mapping Mappable) Step
Map is a method of the Step interface.
func (*AddMarkStep) Merge ¶
func (s *AddMarkStep) Merge(other Step) (Step, bool)
Merge is a method of the Step interface.
func (*AddMarkStep) ToJSON ¶ added in v0.2.0
func (s *AddMarkStep) ToJSON() map[string]interface{}
ToJSON is a method of the Step interface.
type MapResult ¶
type MapResult struct { // The mapped version of the position. Pos int // Tells you whether the position was deleted, that is, whether the step // removed its surroundings from the document. Deleted bool }
MapResult is an object representing a mapped position with extra information.
func NewMapResult ¶
NewMapResult is the constructor for MapResult
type Mappable ¶
type Mappable interface { // 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(pos int, assoc ...int) int // MapResult maps a position, and returns 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 when assoc points in the // direction of the deleted content. MapResult(pos int, assoc ...int) *MapResult }
Mappable is an interface. There are several things that positions can be mapped through. Such objects conform to this interface.
type RemoveMarkStep ¶
RemoveMarkStep adds a mark to all inline content between two positions.
func NewRemoveMarkStep ¶
func NewRemoveMarkStep(from, to int, mark *model.Mark) *RemoveMarkStep
NewRemoveMarkStep is the constructor for RemoveMarkStep.
func (*RemoveMarkStep) Apply ¶
func (s *RemoveMarkStep) Apply(doc *model.Node) StepResult
Apply is a method of the Step interface.
func (*RemoveMarkStep) GetMap ¶
func (s *RemoveMarkStep) GetMap() *StepMap
GetMap is a method of the Step interface.
func (*RemoveMarkStep) Invert ¶
func (s *RemoveMarkStep) Invert(doc *model.Node) Step
Invert is a method of the Step interface.
func (*RemoveMarkStep) Map ¶
func (s *RemoveMarkStep) Map(mapping Mappable) Step
Map is a method of the Step interface.
func (*RemoveMarkStep) Merge ¶
func (s *RemoveMarkStep) Merge(other Step) (Step, bool)
Merge is a method of the Step interface.
func (*RemoveMarkStep) ToJSON ¶ added in v0.2.0
func (s *RemoveMarkStep) ToJSON() map[string]interface{}
ToJSON is a method of the Step interface.
type ReplaceAroundStep ¶
type ReplaceAroundStep struct { From int To int GapFrom int GapTo int Slice *model.Slice Insert int Structure bool }
ReplaceAroundStep replaces a part of the document with a slice of content, but preserve a range of the replaced content by moving it into the slice.
func NewReplaceAroundStep ¶
func NewReplaceAroundStep(from, to, gapFrom, gapTo int, slice *model.Slice, insert int, structure bool) *ReplaceAroundStep
NewReplaceAroundStep creates 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 the ReplaceStep class.
func (*ReplaceAroundStep) Apply ¶
func (s *ReplaceAroundStep) Apply(doc *model.Node) StepResult
Apply is a method of the Step interface.
func (*ReplaceAroundStep) GetMap ¶
func (s *ReplaceAroundStep) GetMap() *StepMap
GetMap is a method of the Step interface.
func (*ReplaceAroundStep) Invert ¶
func (s *ReplaceAroundStep) Invert(doc *model.Node) Step
Invert is a method of the Step interface.
func (*ReplaceAroundStep) Map ¶
func (s *ReplaceAroundStep) Map(mapping Mappable) Step
Map is a method of the Step interface.
func (*ReplaceAroundStep) Merge ¶
func (s *ReplaceAroundStep) Merge(other Step) (Step, bool)
Merge is a method of the Step interface.
func (*ReplaceAroundStep) ToJSON ¶ added in v0.2.0
func (s *ReplaceAroundStep) ToJSON() map[string]interface{}
ToJSON is a method of the Step interface.
type ReplaceStep ¶
ReplaceStep replaces a part of the document with a slice of new content.
func NewReplaceStep ¶
func NewReplaceStep(from, to int, slice *model.Slice, structure ...bool) *ReplaceStep
NewReplaceStep is the constructor of ReplaceStep.
The given slice should fit the 'gap' between from and to—the depths must line up, and the surrounding nodes must be able to be joined with the open sides of the slice. When structure 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).
func (*ReplaceStep) Apply ¶
func (s *ReplaceStep) Apply(doc *model.Node) StepResult
Apply is a method of the Step interface.
func (*ReplaceStep) GetMap ¶
func (s *ReplaceStep) GetMap() *StepMap
GetMap is a method of the Step interface.
func (*ReplaceStep) Invert ¶
func (s *ReplaceStep) Invert(doc *model.Node) Step
Invert is a method of the Step interface.
func (*ReplaceStep) Map ¶
func (s *ReplaceStep) Map(mapping Mappable) Step
Map is a method of the Step interface.
func (*ReplaceStep) Merge ¶
func (s *ReplaceStep) Merge(other Step) (Step, bool)
Merge is a method of the Step interface.
func (*ReplaceStep) ToJSON ¶ added in v0.2.0
func (s *ReplaceStep) ToJSON() map[string]interface{}
ToJSON is a method of the Step interface.
type SetAttrsStep ¶ added in v0.4.10
SetAttrsStep can be used to change the attributes of a node.
For more context, see: - https://discuss.prosemirror.net/t/preventing-image-placeholder-replacement-from-being-undone/1394/1 - https://bitbucket.org/atlassian/atlassian-frontend-mirror/src/master/editor/adf-schema/src/steps/set-attrs.tsx
func NewSetAttrsStep ¶ added in v0.4.10
func NewSetAttrsStep(pos int, attrs map[string]interface{}) *SetAttrsStep
NewSetAttrsStep is a constructor for SetAttrsStep
func (*SetAttrsStep) Apply ¶ added in v0.4.10
func (s *SetAttrsStep) Apply(doc *model.Node) StepResult
Apply is a method of the Step interface.
func (*SetAttrsStep) GetMap ¶ added in v0.4.10
func (s *SetAttrsStep) GetMap() *StepMap
GetMap is a method of the Step interface.
func (*SetAttrsStep) Invert ¶ added in v0.4.10
func (s *SetAttrsStep) Invert(doc *model.Node) Step
Invert is a method of the Step interface.
func (*SetAttrsStep) Map ¶ added in v0.4.10
func (s *SetAttrsStep) Map(mapping Mappable) Step
Map is a method of the Step interface.
func (*SetAttrsStep) Merge ¶ added in v0.4.10
func (s *SetAttrsStep) Merge(other Step) (Step, bool)
Merge is a method of the Step interface.
func (*SetAttrsStep) ToJSON ¶ added in v0.4.10
func (s *SetAttrsStep) ToJSON() map[string]interface{}
ToJSON is a method of the Step interface.
type Step ¶
type Step interface { // 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. Apply(doc *model.Node) StepResult // GetMap gets 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. GetMap() *StepMap // Invert creates an inverted version of this step. Needs the document as // it was before the step as argument. Invert(doc *model.Node) Step // 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. Map(mapping Mappable) Step // Merge tries 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. Merge(other Step) (Step, bool) // ToJSON creates 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. ToJSON() map[string]interface{} }
Step objects represent 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.
func AddMarkStepFromJSON ¶ added in v0.2.0
AddMarkStepFromJSON builds an AddMarkStep from a JSON representation.
func RemoveMarkStepFromJSON ¶ added in v0.2.0
RemoveMarkStepFromJSON builds an RemoveMarkStep from a JSON representation.
func ReplaceAroundStepFromJSON ¶ added in v0.2.0
ReplaceAroundStepFromJSON builds an RemoveMarkStep from a JSON representation.
func ReplaceStepFromJSON ¶ added in v0.2.0
ReplaceStepFromJSON builds an RemoveMarkStep from a JSON representation.
func SetAttrsStepFromJSON ¶ added in v0.4.10
SetAttrsStepFromJSON builds an SetAttrsStep from a JSON representation.
func StepFromJSON ¶ added in v0.2.0
StepFromJSON deserializes a step from its JSON representation. Will call through to the step class' own implementation of this method.
func TableSortStepFromJSON ¶ added in v0.4.11
TableSortStepFromJSON builds a step that does nothing. It is used by atlaskit. Cf https://bitbucket.org/atlassian/atlaskit-mk-2/src/master/packages/editor/editor-core/src/plugins/table/utils/sort-step.ts
type StepMap ¶
StepMap is 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.
func NewStepMap ¶
NewStepMap creates 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].
func (*StepMap) Invert ¶
Invert creates an inverted version of this map. The result can be used to map positions in the post-step document to the pre-step document.
type StepResult ¶
type StepResult struct { // :: ?Node The transformed document. Doc *model.Node // :: ?string Text providing information about a failed step. Failed string }
StepResult is the result of applying a step. Contains either a new document or a failure value.
func FromReplace ¶
FromReplace calls Node.replace with the given arguments. Create a successful result if it succeeds, and a failed one if it throws a `ReplaceError`.