Module

engine/model/operation/transform

@ckeditor/ckeditor5-engine/src/model/operation/transform

module

Filtering

Type Definitions

Functions

  • _getComplementaryAttributeOperations( insertOperation, key, newValue ) → AttributeOperation | null

    private

    Helper function for AttributeOperation x InsertOperation (and reverse) transformation.

    For given insertOperation it checks the inserted node if it has an attribute key set to a value different than newValue. If so, it generates an AttributeOperation which changes the value of key attribute to newValue.

    Parameters

    insertOperation : InsertOperation
    key : String
    newValue : *

    Returns

    AttributeOperation | null
  • getTransformation( OperationA, OperationB ) → function

    private

    Returns a previously set transformation function for transforming an instance of OperationA by an instance of OperationB.

    If no transformation was set for given pair of operations, noUpdateTransformation is returned. This means that if no transformation was set, the OperationA instance will not change when transformed by the OperationB instance.

    Parameters

    OperationA : function
    OperationB : function

    Returns

    function

    Function set to transform an instance of OperationA by an instance of OperationB.

  • noUpdateTransformation( a ) → Array.<Operation>

    private

    A transformation function that only clones operation to transform, without changing it.

    Parameters

    a : Operation

    Operation to transform.

    Returns

    Array.<Operation>
  • padWithNoOps( operations, howMany )

    private

    Adds howMany instances of NoOperation to operations set.

    Parameters

    operations : Array.<Operation>
    howMany : Number
  • setTransformation( OperationA, OperationB, transformationFunction )

    protected

    Sets a transformation function to be be used to transform instances of class OperationA by instances of class OperationB.

    The transformationFunction is passed three parameters:

    • a - operation to be transformed, an instance of OperationA,
    • b - operation to be transformed by, an instance of OperationB,
    • context - object with additional information about transformation context.

    The transformationFunction should return transformation result, which is an array with one or multiple operation instances.

    Parameters

    OperationA : function
    OperationB : function
    transformationFunction : function

    Function to use for transforming.

  • transform( a, b, context ) → Array.<Operation>

    Transforms operation a by operation b.

    Parameters

    a : Operation

    Operation to be transformed.

    b : Operation

    Operation to transform by.

    context : TransformationContext

    Transformation context for this transformation.

    Returns

    Array.<Operation>

    Transformation result.

  • transformSets( operationsA, operationsB, options = { options.document, [options.useRelations], [options.padWithNoOps] } ) → Object

    Performs a transformation of two sets of operations - operationsA and operationsB. The transformation is two-way - both transformed operationsA and transformed operationsB are returned.

    Note, that the first operation in each set should base on the same document state ( document version).

    It is assumed that operationsA are "more important" during conflict resolution between two operations.

    New copies of both passed arrays and operations inside them are returned. Passed arguments are not altered.

    Base versions of the transformed operations sets are updated accordingly. For example, assume that base versions are 4 and there are 3 operations in operationsA and 5 operations in operationsB. Then:

    • transformed operationsA will start from base version 9 (4 base version + 5 operations B),
    • transformed operationsB will start from base version 7 (4 base version + 3 operations A).

    If no operation was broken into two during transformation, then both sets will end up with an operation that bases on version 11:

    • transformed operationsA start from 9 and there are 3 of them, so the last will have baseVersion equal to 11,
    • transformed operationsB start from 7 and there are 5 of them, so the last will have baseVersion equal to 11.

    Parameters

    operationsA : Array.<Operation>
    operationsB : Array.<Operation>
    options : Object

    Additional transformation options.

    Properties
    options.document : Document | null

    Document which the operations change.

    [ options.useRelations ] : Boolean

    Whether during transformation relations should be used (used during undo for better conflict resolution).

    Defaults to false

    [ options.padWithNoOps ] : Boolean

    Whether additional NoOperations should be added to the transformation results to force the same last base version for both transformed sets (in case if some operations got broken into multiple operations during transformation).

    Defaults to false

    Returns

    Object

    Transformation result.

    Array.<Operation>

    return.operationsA Transformed operationsA.

    Array.<Operation>

    return.operationsB Transformed operationsB.

    Map

    return.originalOperations A map that links transformed operations to original operations. The keys are the transformed operations and the values are the original operations from the input (operationsA and operationsB).

  • updateBaseVersions( operations, baseVersion )

    private

    An utility function that updates base versions of passed operations.

    The function simply sets baseVersion as a base version of the first passed operation and then increments it for each following operation in operations.

    Parameters

    operations : Array.<Operation>

    Operations to update.

    baseVersion : Number

    Base version to set for the first operation in operations.