|
@@ -11,30 +11,28 @@ import CKEditorError from '../../ckeditorerror.js';
|
|
|
import TextFragment from '../textfragment.js';
|
|
import TextFragment from '../textfragment.js';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Operation to change nodes' attribute. Using this class you can add, remove or change value of the attribute.
|
|
|
|
|
|
|
+ * Creates an operation that changes, removes or adds attributes.
|
|
|
|
|
+ *
|
|
|
|
|
+ * If only the new attribute is set, then it will be inserted. Note that in all nodes in ranges there must be
|
|
|
|
|
+ * no attributes with the same key as the new attribute.
|
|
|
|
|
+ *
|
|
|
|
|
+ * If only the old attribute is set, then it will be removed. Note that this attribute must be present in all nodes in
|
|
|
|
|
+ * ranges.
|
|
|
*
|
|
*
|
|
|
- * @class treeModel.operation.AttributeOperation
|
|
|
|
|
|
|
+ * If both new and old attributes are set, then the operation will change the attribute value. Note that both new and
|
|
|
|
|
+ * old attributes have to have the same key and the old attribute must be present in all nodes in ranges.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {core.treeModel.Range} range Range on which the operation should be applied.
|
|
|
|
|
+ * @param {String} key Key of an attribute to change or remove.
|
|
|
|
|
+ * @param {*} oldValue Old value of the attribute with given key or `null` if adding a new attribute.
|
|
|
|
|
+ * @param {*} newValue New value to set for the attribute. If `null`, then the operation just removes the attribute.
|
|
|
|
|
+ * @param {Number} baseVersion {@link core.treeModel.Document#version} on which the operation can be applied.
|
|
|
|
|
+ * @class core.treeModel.operation.AttributeOperation
|
|
|
|
|
+ * @classdesc
|
|
|
|
|
+ * Operation to change nodes' attribute. Using this class you can add, remove or change value of the attribute.
|
|
|
|
|
+ * @extends core.treeModel.operation.Operation
|
|
|
*/
|
|
*/
|
|
|
export default class AttributeOperation extends Operation {
|
|
export default class AttributeOperation extends Operation {
|
|
|
- /**
|
|
|
|
|
- * Creates an operation that changes, removes or adds attributes.
|
|
|
|
|
- *
|
|
|
|
|
- * If only the new attribute is set, then it will be inserted. Note that in all nodes in ranges there must be
|
|
|
|
|
- * no attributes with the same key as the new attribute.
|
|
|
|
|
- *
|
|
|
|
|
- * If only the old attribute is set, then it will be removed. Note that this attribute must be present in all nodes in
|
|
|
|
|
- * ranges.
|
|
|
|
|
- *
|
|
|
|
|
- * If both new and old attributes are set, then the operation will change the attribute value. Note that both new and
|
|
|
|
|
- * old attributes have to have the same key and the old attribute must be present in all nodes in ranges.
|
|
|
|
|
- *
|
|
|
|
|
- * @param {treeModel.Range} range Range on which the operation should be applied.
|
|
|
|
|
- * @param {String} key Key of an attribute to change or remove.
|
|
|
|
|
- * @param {*} oldValue Old value of the attribute with given key or `null` if adding a new attribute.
|
|
|
|
|
- * @param {*} newValue New value to set for the attribute. If `null`, then the operation just removes the attribute.
|
|
|
|
|
- * @param {Number} baseVersion {@link treeModel.Document#version} on which the operation can be applied.
|
|
|
|
|
- * @constructor
|
|
|
|
|
- */
|
|
|
|
|
constructor( range, key, oldValue, newValue, baseVersion ) {
|
|
constructor( range, key, oldValue, newValue, baseVersion ) {
|
|
|
super( baseVersion );
|
|
super( baseVersion );
|
|
|
|
|
|
|
@@ -42,7 +40,8 @@ export default class AttributeOperation extends Operation {
|
|
|
* Range on which operation should be applied.
|
|
* Range on which operation should be applied.
|
|
|
*
|
|
*
|
|
|
* @readonly
|
|
* @readonly
|
|
|
- * @type {treeModel.Range}
|
|
|
|
|
|
|
+ * @member core.treeModel.operation.AttributeOperation#range
|
|
|
|
|
+ * @type {core.treeModel.Range}
|
|
|
*/
|
|
*/
|
|
|
this.range = Range.createFromRange( range );
|
|
this.range = Range.createFromRange( range );
|
|
|
|
|
|
|
@@ -50,6 +49,7 @@ export default class AttributeOperation extends Operation {
|
|
|
* Key of an attribute to change or remove.
|
|
* Key of an attribute to change or remove.
|
|
|
*
|
|
*
|
|
|
* @readonly
|
|
* @readonly
|
|
|
|
|
+ * @member core.treeModel.operation.AttributeOperation#key
|
|
|
* @type {String}
|
|
* @type {String}
|
|
|
*/
|
|
*/
|
|
|
this.key = key;
|
|
this.key = key;
|
|
@@ -57,6 +57,7 @@ export default class AttributeOperation extends Operation {
|
|
|
/**
|
|
/**
|
|
|
* Old value of the attribute with given key or `null` if adding a new attribute.
|
|
* Old value of the attribute with given key or `null` if adding a new attribute.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @member core.treeModel.operation.AttributeOperation#oldValue
|
|
|
* @readonly
|
|
* @readonly
|
|
|
* @type {*}
|
|
* @type {*}
|
|
|
*/
|
|
*/
|
|
@@ -65,6 +66,7 @@ export default class AttributeOperation extends Operation {
|
|
|
/**
|
|
/**
|
|
|
* New value to set for the attribute. If `null`, then the operation just removes the attribute.
|
|
* New value to set for the attribute. If `null`, then the operation just removes the attribute.
|
|
|
*
|
|
*
|
|
|
|
|
+ * @member core.treeModel.operation.AttributeOperation#newValue
|
|
|
* @readonly
|
|
* @readonly
|
|
|
* @type {*}
|
|
* @type {*}
|
|
|
*/
|
|
*/
|
|
@@ -75,10 +77,18 @@ export default class AttributeOperation extends Operation {
|
|
|
return 'attr';
|
|
return 'attr';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @method core.treeModel.operation.AttributeOperation#clone
|
|
|
|
|
+ * @returns {core.treeModel.operation.AttributeOperation}
|
|
|
|
|
+ */
|
|
|
clone() {
|
|
clone() {
|
|
|
return new AttributeOperation( this.range, this.key, this.oldValue, this.newValue, this.baseVersion );
|
|
return new AttributeOperation( this.range, this.key, this.oldValue, this.newValue, this.baseVersion );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @method core.treeModel.operation.AttributeOperation#clone
|
|
|
|
|
+ * @returns {core.treeModel.operation.AttributeOperation}
|
|
|
|
|
+ */
|
|
|
getReversed() {
|
|
getReversed() {
|
|
|
return new AttributeOperation( this.range, this.key, this.newValue, this.oldValue, this.baseVersion + 1 );
|
|
return new AttributeOperation( this.range, this.key, this.newValue, this.oldValue, this.baseVersion + 1 );
|
|
|
}
|
|
}
|
|
@@ -90,7 +100,7 @@ export default class AttributeOperation extends Operation {
|
|
|
* The attribute which should be removed does not exists for the given node.
|
|
* The attribute which should be removed does not exists for the given node.
|
|
|
*
|
|
*
|
|
|
* @error operation-attribute-no-attr-to-remove
|
|
* @error operation-attribute-no-attr-to-remove
|
|
|
- * @param {treeModel.Node} node
|
|
|
|
|
|
|
+ * @param {core.treeModel.Node} node
|
|
|
* @param {String} key
|
|
* @param {String} key
|
|
|
* @param {*} value
|
|
* @param {*} value
|
|
|
*/
|
|
*/
|
|
@@ -105,7 +115,7 @@ export default class AttributeOperation extends Operation {
|
|
|
* The attribute with given key already exists for the given node.
|
|
* The attribute with given key already exists for the given node.
|
|
|
*
|
|
*
|
|
|
* @error operation-attribute-attr-exists
|
|
* @error operation-attribute-attr-exists
|
|
|
- * @param {treeModel.Node} node
|
|
|
|
|
|
|
+ * @param {core.treeModel.Node} node
|
|
|
* @param {String} key
|
|
* @param {String} key
|
|
|
*/
|
|
*/
|
|
|
throw new CKEditorError(
|
|
throw new CKEditorError(
|