Explorar o código

Changed order of the methods in code.

Kamil Piechaczek %!s(int64=7) %!d(string=hai) anos
pai
achega
7f04655bee

+ 14 - 14
packages/ckeditor5-engine/src/model/element.js

@@ -156,20 +156,6 @@ export default class Element extends Node {
 		return this._children.getNodeStartOffset( node );
 	}
 
-	/**
-	 * Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
-	 * If clone is deep, the original element's children are also cloned. If not, then empty element is removed.
-	 *
-	 * @protected
-	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
-	 * element will be cloned without any child.
-	 */
-	_clone( deep = false ) {
-		const children = deep ? Array.from( this._children ).map( node => node._clone( true ) ) : null;
-
-		return new Element( this.name, this.getAttributes(), children );
-	}
-
 	/**
 	 * Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
 	 * too high, returns {@link module:engine/model/element~Element#getChildIndex index after last child}.
@@ -233,6 +219,20 @@ export default class Element extends Node {
 		return json;
 	}
 
+	/**
+	 * Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
+	 * If clone is deep, the original element's children are also cloned. If not, then empty element is removed.
+	 *
+	 * @protected
+	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
+	 * element will be cloned without any child.
+	 */
+	_clone( deep = false ) {
+		const children = deep ? Array.from( this._children ).map( node => node._clone( true ) ) : null;
+
+		return new Element( this.name, this.getAttributes(), children );
+	}
+
 	/**
 	 * {@link module:engine/model/element~Element#_insertChildren Inserts} one or more nodes at the end of this element.
 	 *

+ 25 - 25
packages/ckeditor5-engine/src/model/node.js

@@ -201,16 +201,6 @@ export default class Node {
 		return this.root.document || null;
 	}
 
-	/**
-	 * Creates a copy of this node, that is a node with exactly same attributes, and returns it.
-	 *
-	 * @protected
-	 * @returns {module:engine/model/node~Node} Node with same attributes as this node.
-	 */
-	_clone() {
-		return new Node( this._attrs );
-	}
-
 	/**
 	 * Gets path to the node. The path is an array containing starting offsets of consecutive ancestors of this node,
 	 * beginning from {@link module:engine/model/node~Node#root root}, down to this node's starting offset. The path can be used to
@@ -324,6 +314,31 @@ export default class Node {
 		return this._attrs.keys();
 	}
 
+	/**
+	 * Converts `Node` to plain object and returns it.
+	 *
+	 * @returns {Object} `Node` converted to plain object.
+	 */
+	toJSON() {
+		const json = {};
+
+		if ( this._attrs.size ) {
+			json.attributes = [ ...this._attrs ];
+		}
+
+		return json;
+	}
+
+	/**
+	 * Creates a copy of this node, that is a node with exactly same attributes, and returns it.
+	 *
+	 * @protected
+	 * @returns {module:engine/model/node~Node} Node with same attributes as this node.
+	 */
+	_clone() {
+		return new Node( this._attrs );
+	}
+
 	/**
 	 * Removes this node from it's parent.
 	 *
@@ -374,21 +389,6 @@ export default class Node {
 		this._attrs.clear();
 	}
 
-	/**
-	 * Converts `Node` to plain object and returns it.
-	 *
-	 * @returns {Object} `Node` converted to plain object.
-	 */
-	toJSON() {
-		const json = {};
-
-		if ( this._attrs.size ) {
-			json.attributes = [ ...this._attrs ];
-		}
-
-		return json;
-	}
-
 	/**
 	 * Checks whether given model tree object is of given type.
 	 *

+ 10 - 10
packages/ckeditor5-engine/src/model/text.js

@@ -68,16 +68,6 @@ export default class Text extends Node {
 		return type == 'text';
 	}
 
-	/**
-	 * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
-	 *
-	 * @protected
-	 * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
-	 */
-	_clone() {
-		return new Text( this.data, this.getAttributes() );
-	}
-
 	/**
 	 * Converts `Text` instance to plain object and returns it.
 	 *
@@ -91,6 +81,16 @@ export default class Text extends Node {
 		return json;
 	}
 
+	/**
+	 * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
+	 *
+	 * @protected
+	 * @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
+	 */
+	_clone() {
+		return new Text( this.data, this.getAttributes() );
+	}
+
 	/**
 	 * Creates a `Text` instance from given plain object (i.e. parsed JSON string).
 	 *

+ 12 - 12
packages/ckeditor5-engine/src/view/attributeelement.js

@@ -72,6 +72,18 @@ export default class AttributeElement extends Element {
 		}
 	}
 
+	/**
+	 * Checks if this element is similar to other element.
+	 * Both elements should have the same name, attributes and priority to be considered as similar.
+	 * Two similar elements can contain different set of children nodes.
+	 *
+	 * @param {module:engine/view/element~Element} otherElement
+	 * @returns {Boolean}
+	 */
+	isSimilar( otherElement ) {
+		return super.isSimilar( otherElement ) && this.priority == otherElement.priority;
+	}
+
 	/**
 	 * Clones provided element with priority.
 	 *
@@ -88,18 +100,6 @@ export default class AttributeElement extends Element {
 
 		return cloned;
 	}
-
-	/**
-	 * Checks if this element is similar to other element.
-	 * Both elements should have the same name, attributes and priority to be considered as similar.
-	 * Two similar elements can contain different set of children nodes.
-	 *
-	 * @param {module:engine/view/element~Element} otherElement
-	 * @returns {Boolean}
-	 */
-	isSimilar( otherElement ) {
-		return super.isSimilar( otherElement ) && this.priority == otherElement.priority;
-	}
 }
 
 /**

+ 36 - 36
packages/ckeditor5-engine/src/view/element.js

@@ -158,42 +158,6 @@ export default class Element extends Node {
 		}
 	}
 
-	/**
-	 * Clones provided element.
-	 *
-	 * @protected
-	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
-	 * element will be cloned without any children.
-	 * @returns {module:engine/view/element~Element} Clone of this element.
-	 */
-	_clone( deep = false ) {
-		const childrenClone = [];
-
-		if ( deep ) {
-			for ( const child of this.getChildren() ) {
-				childrenClone.push( child._clone( deep ) );
-			}
-		}
-
-		// ContainerElement and AttributeElement should be also cloned properly.
-		const cloned = new this.constructor( this.name, this._attrs, childrenClone );
-
-		// Classes and styles are cloned separately - this solution is faster than adding them back to attributes and
-		// parse once again in constructor.
-		cloned._classes = new Set( this._classes );
-		cloned._styles = new Map( this._styles );
-
-		// Clone custom properties.
-		cloned._customProperties = new Map( this._customProperties );
-
-		// Clone filler offset method.
-		// We can't define this method in a prototype because it's behavior which
-		// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
-		cloned.getFillerOffset = this.getFillerOffset;
-
-		return cloned;
-	}
-
 	/**
 	 * Gets child at the given index.
 	 *
@@ -512,6 +476,42 @@ export default class Element extends Node {
 			( attributes == '' ? '' : ` ${ attributes }` );
 	}
 
+	/**
+	 * Clones provided element.
+	 *
+	 * @protected
+	 * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
+	 * element will be cloned without any children.
+	 * @returns {module:engine/view/element~Element} Clone of this element.
+	 */
+	_clone( deep = false ) {
+		const childrenClone = [];
+
+		if ( deep ) {
+			for ( const child of this.getChildren() ) {
+				childrenClone.push( child._clone( deep ) );
+			}
+		}
+
+		// ContainerElement and AttributeElement should be also cloned properly.
+		const cloned = new this.constructor( this.name, this._attrs, childrenClone );
+
+		// Classes and styles are cloned separately - this solution is faster than adding them back to attributes and
+		// parse once again in constructor.
+		cloned._classes = new Set( this._classes );
+		cloned._styles = new Map( this._styles );
+
+		// Clone custom properties.
+		cloned._customProperties = new Map( this._customProperties );
+
+		// Clone filler offset method.
+		// We can't define this method in a prototype because it's behavior which
+		// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
+		cloned.getFillerOffset = this.getFillerOffset;
+
+		return cloned;
+	}
+
 	/**
 	 * {@link module:engine/view/element~Element#_insertChildren Insert} a child node or a list of child nodes at the end of this node
 	 * and sets the parent of these nodes to this element.