Class

AttributeOperation (engine/model/operation)

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

class

Operation to change nodes' attribute.

Using this class you can add, remove or change value of the attribute.

Filtering

Properties

  • baseVersion : Number

    inherited

    version on which operation can be applied. If you try to apply operation with different base version than the document version the model-document-applyOperation-wrong-version error is thrown.

  • batch : Batch | null

    inherited

    Batch to which the operation is added or null if the operation is not added to any batch yet.

  • isDocumentOperation : Boolean

    readonly inherited

    Defines whether operation is executed on attached or detached items.

  • key : String

    readonly

    Key of an attribute to change or remove.

  • newValue : *

    readonly

    New value of the attribute with given key or null, if operation should remove attribute.

  • oldValue : *

    readonly

    Old value of the attribute with given key or null, if attribute was not set before.

  • range : Range

    readonly

    Range on which operation should be applied.

  • type : String

    readonly inherited

    Operation type.

Static properties

  • className : String

    inherited static

    Name of the operation class used for serialization.

Methods

  • constructor( range, key, oldValue, newValue, baseVersion )

    Creates an operation that changes, removes or adds attributes.

    If only newValue is set, attribute will be added on a node. Note that all nodes in operation's range must not have an attribute with the same key as the added attribute.

    If only oldValue is set, then attribute with given key will be removed. Note that all nodes in operation's range must have an attribute with that key added.

    If both newValue and oldValue are set, then the operation will change the attribute value. Note that all nodes in operation's ranges must already have an attribute with given key and oldValue as value

    Parameters

    range : Range

    Range on which the operation should be applied. Must be a flat range.

    key : String

    Key of an attribute to change or remove.

    oldValue : *

    Old value of the attribute with given key or null, if attribute was not set before.

    newValue : *

    New value of the attribute with given key or null, if operation should remove attribute.

    baseVersion : Number | null

    Document version on which operation can be applied or null if the operation operates on detached (non-document) tree.

  • clone() → AttributeOperation

    Creates and returns an operation that has the same parameters as this operation.

    Returns

    AttributeOperation

    Clone of this operation.

  • getReversed() → AttributeOperation

  • toJSON() → Object

    inherited

    Custom toJSON method to solve child-parent circular dependencies.

    Returns

    Object

    Clone of this object with the operation property replaced with string.

  • _execute()

    protected inherited

    Executes the operation - modifications described by the operation properties will be applied to the model tree.

  • _validate()

    protected inherited

    Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws an error if operation is not valid.

Static methods

  • fromJSON( json, document ) → AttributeOperation

    static

    Creates AttributeOperation object from deserilized object, i.e. from parsed JSON string.

    Parameters

    json : Object

    Deserialized JSON object.

    document : Document

    Document on which this operation will be applied.

    Returns

    AttributeOperation