Browse Source

"_clone()" method is now protected.

Kamil Piechaczek 7 years ago
parent
commit
a559f429d9

+ 3 - 2
packages/ckeditor5-engine/src/model/element.js

@@ -159,11 +159,12 @@ export default class Element extends 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;
+	_clone( deep = false ) {
+		const children = deep ? Array.from( this._children ).map( node => node._clone( true ) ) : null;
 
 		return new Element( this.name, this.getAttributes(), children );
 	}

+ 2 - 1
packages/ckeditor5-engine/src/model/node.js

@@ -204,9 +204,10 @@ export default class Node {
 	/**
 	 * 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() {
+	_clone() {
 		return new Node( this._attrs );
 	}
 

+ 2 - 2
packages/ckeditor5-engine/src/model/operation/insertoperation.js

@@ -63,7 +63,7 @@ export default class InsertOperation extends Operation {
 	 * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.
 	 */
 	clone() {
-		const nodes = new NodeList( [ ...this.nodes ].map( node => node.clone( true ) ) );
+		const nodes = new NodeList( [ ...this.nodes ].map( node => node._clone( true ) ) );
 
 		return new InsertOperation( this.position, nodes, this.baseVersion );
 	}
@@ -107,7 +107,7 @@ export default class InsertOperation extends Operation {
 		// to the operation, not modified. For example, text nodes can get merged or cropped while Elements can
 		// get children. It is important that InsertOperation has the copy of original nodes in intact state.
 		const originalNodes = this.nodes;
-		this.nodes = new NodeList( [ ...originalNodes ].map( node => node.clone( true ) ) );
+		this.nodes = new NodeList( [ ...originalNodes ].map( node => node._clone( true ) ) );
 
 		_insert( this.position, originalNodes );
 	}

+ 4 - 1
packages/ckeditor5-engine/src/model/text.js

@@ -70,8 +70,11 @@ export default class Text extends Node {
 
 	/**
 	 * 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() {
+	_clone() {
 		return new Text( this.data, this.getAttributes() );
 	}
 

+ 1 - 1
packages/ckeditor5-engine/src/model/utils/getselectedcontent.js

@@ -71,7 +71,7 @@ export default function getSelectedContent( model, selection ) {
 			if ( item.is( 'textProxy' ) ) {
 				writer.appendText( item.data, item.getAttributes(), frag );
 			} else {
-				writer.append( item.clone( true ), frag );
+				writer.append( item._clone( true ), frag );
 			}
 		}
 

+ 3 - 2
packages/ckeditor5-engine/src/view/attributeelement.js

@@ -75,12 +75,13 @@ export default class AttributeElement extends Element {
 	/**
 	 * Clones provided element with priority.
 	 *
+	 * @protected
 	 * @param {Boolean} deep 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/attributeelement~AttributeElement} Clone of this element.
 	 */
-	clone( deep ) {
-		const cloned = super.clone( deep );
+	_clone( deep ) {
+		const cloned = super._clone( deep );
 
 		// Clone priority too.
 		cloned._priority = this._priority;

+ 3 - 2
packages/ckeditor5-engine/src/view/element.js

@@ -161,16 +161,17 @@ 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 ) {
+	_clone( deep = false ) {
 		const childrenClone = [];
 
 		if ( deep ) {
 			for ( const child of this.getChildren() ) {
-				childrenClone.push( child.clone( deep ) );
+				childrenClone.push( child._clone( deep ) );
 			}
 		}
 

+ 2 - 1
packages/ckeditor5-engine/src/view/text.js

@@ -41,9 +41,10 @@ export default class Text extends Node {
 	/**
 	 * Clones this node.
 	 *
+	 * @protected
 	 * @returns {module:engine/view/text~Text} Text node that is a clone of this node.
 	 */
-	clone() {
+	_clone() {
 		return new Text( this.data );
 	}
 

+ 3 - 3
packages/ckeditor5-engine/src/view/writer.js

@@ -409,7 +409,7 @@ export default class Writer {
 		if ( position.isAtStart ) {
 			return Position.createBefore( element );
 		} else if ( !position.isAtEnd ) {
-			const newElement = element.clone( false );
+			const newElement = element._clone( false );
 
 			this.insert( Position.createAfter( element ), newElement );
 
@@ -885,7 +885,7 @@ export default class Writer {
 			// Wrap text, empty elements, ui elements or attributes with higher or equal priority.
 			if ( isText || isEmpty || isUI || ( isAttribute && shouldABeOutsideB( attribute, child ) ) ) {
 				// Clone attribute.
-				const newAttribute = attribute.clone();
+				const newAttribute = attribute._clone();
 
 				// Wrap current node with new attribute;
 				child._remove();
@@ -1378,7 +1378,7 @@ function _breakAttributes( position, forceSplitText = false ) {
 		const offsetAfter = positionParent.index + 1;
 
 		// Break element.
-		const clonedNode = positionParent.clone();
+		const clonedNode = positionParent._clone();
 
 		// Insert cloned node to position's parent node.
 		positionParent.parent._insertChildren( offsetAfter, clonedNode );

+ 3 - 3
packages/ckeditor5-engine/tests/model/element.js

@@ -62,13 +62,13 @@ describe( 'Element', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should return an element with same name, attributes and same instances of children if clone was not deep', () => {
 			const p = new Element( 'p' );
 			const foo = new Text( 'foo' );
 
 			const element = new Element( 'elem', { bold: true, italic: true }, [ p, foo ] );
-			const copy = element.clone();
+			const copy = element._clone();
 
 			expect( copy.name ).to.equal( 'elem' );
 			expect( Array.from( copy.getAttributes() ) ).to.deep.equal( [ [ 'bold', true ], [ 'italic', true ] ] );
@@ -81,7 +81,7 @@ describe( 'Element', () => {
 			const p = new Element( 'p', null, bar );
 
 			const element = new Element( 'elem', { bold: true, italic: true }, [ p, foo ] );
-			const copy = element.clone( true );
+			const copy = element._clone( true );
 
 			expect( copy.name ).to.equal( 'elem' );
 			expect( Array.from( copy.getAttributes() ) ).to.deep.equal( [ [ 'bold', true ], [ 'italic', true ] ] );

+ 2 - 2
packages/ckeditor5-engine/tests/model/node.js

@@ -136,10 +136,10 @@ describe( 'Node', () => {
 		} );
 	} );
 
-	describe( 'clone()', () => {
+	describe( '_clone()', () => {
 		it( 'should return a copy of cloned node', () => {
 			const node = new Node( { foo: 'bar' } );
-			const copy = node.clone();
+			const copy = node._clone();
 
 			expect( copy ).not.to.equal( node );
 			expect( Array.from( copy.getAttributes() ) ).to.deep.equal( Array.from( node.getAttributes() ) );

+ 2 - 2
packages/ckeditor5-engine/tests/model/text.js

@@ -52,10 +52,10 @@ describe( 'Text', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should return a new Text instance, with data and attributes equal to cloned text node', () => {
 			const text = new Text( 'foo', { bold: true } );
-			const copy = text.clone();
+			const copy = text._clone();
 
 			expect( copy.data ).to.equal( 'foo' );
 			expect( Array.from( copy.getAttributes() ) ).to.deep.equal( [ [ 'bold', true ] ] );

+ 2 - 2
packages/ckeditor5-engine/tests/view/attributeelement.js

@@ -48,12 +48,12 @@ describe( 'AttributeElement', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should clone element with priority', () => {
 			const el = new AttributeElement( 'b' );
 			el._priority = 7;
 
-			const clone = el.clone();
+			const clone = el._clone();
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );

+ 1 - 1
packages/ckeditor5-engine/tests/view/editableelement.js

@@ -38,7 +38,7 @@ describe( 'EditableElement', () => {
 
 		it( 'should be cloned properly', () => {
 			element._document = docMock;
-			const newElement = element.clone();
+			const newElement = element._clone();
 
 			expect( newElement.document ).to.equal( docMock );
 		} );

+ 12 - 12
packages/ckeditor5-engine/tests/view/element.js

@@ -123,10 +123,10 @@ describe( 'Element', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should clone element', () => {
 			const el = new Element( 'p', { attr1: 'foo', attr2: 'bar' } );
-			const clone = el.clone();
+			const clone = el._clone();
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );
@@ -140,7 +140,7 @@ describe( 'Element', () => {
 				new Element( 'span', { attr: 'qux' } )
 			] );
 			const count = el.childCount;
-			const clone = el.clone( true );
+			const clone = el._clone( true );
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );
@@ -163,7 +163,7 @@ describe( 'Element', () => {
 				new Element( 'b', { attr: 'baz' } ),
 				new Element( 'span', { attr: 'qux' } )
 			] );
-			const clone = el.clone( false );
+			const clone = el._clone( false );
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );
@@ -175,7 +175,7 @@ describe( 'Element', () => {
 		it( 'should clone class attribute', () => {
 			const el = new Element( 'p', { foo: 'bar' } );
 			el._addClass( [ 'baz', 'qux' ] );
-			const clone = el.clone( false );
+			const clone = el._clone( false );
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );
@@ -185,7 +185,7 @@ describe( 'Element', () => {
 
 		it( 'should clone style attribute', () => {
 			const el = new Element( 'p', { style: 'color: red; font-size: 12px;' } );
-			const clone = el.clone( false );
+			const clone = el._clone( false );
 
 			expect( clone ).to.not.equal( el );
 			expect( clone.name ).to.equal( el.name );
@@ -201,7 +201,7 @@ describe( 'Element', () => {
 			el._setCustomProperty( 'foo', 'bar' );
 			el._setCustomProperty( symbol, 'baz' );
 
-			const cloned = el.clone();
+			const cloned = el._clone();
 
 			expect( cloned.getCustomProperty( 'foo' ) ).to.equal( 'bar' );
 			expect( cloned.getCustomProperty( symbol ) ).to.equal( 'baz' );
@@ -214,7 +214,7 @@ describe( 'Element', () => {
 			expect( el.getFillerOffset ).to.be.undefined;
 			el.getFillerOffset = fm;
 
-			const cloned = el.clone();
+			const cloned = el._clone();
 
 			expect( cloned.getFillerOffset ).to.equal( fm );
 		} );
@@ -237,16 +237,16 @@ describe( 'Element', () => {
 		} );
 
 		it( 'sould return false when name is not the same', () => {
-			const other = el.clone();
+			const other = el._clone();
 			other.name = 'div';
 
 			expect( el.isSimilar( other ) ).to.be.false;
 		} );
 
 		it( 'should return false when attributes are not the same', () => {
-			const other1 = el.clone();
-			const other2 = el.clone();
-			const other3 = el.clone();
+			const other1 = el._clone();
+			const other2 = el._clone();
+			const other3 = el._clone();
 			other1._setAttribute( 'baz', 'qux' );
 			other2._setAttribute( 'foo', 'not-bar' );
 			other3._removeAttribute( 'foo' );

+ 2 - 2
packages/ckeditor5-engine/tests/view/emptyelement.js

@@ -70,9 +70,9 @@ describe( 'EmptyElement', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should be cloned properly', () => {
-			const newEmptyElement = emptyElement.clone();
+			const newEmptyElement = emptyElement._clone();
 
 			expect( newEmptyElement.name ).to.equal( 'img' );
 			expect( newEmptyElement.getAttribute( 'alt' ) ).to.equal( 'alternative text' );

+ 1 - 1
packages/ckeditor5-engine/tests/view/rooteditableelement.js

@@ -86,7 +86,7 @@ describe( 'RootEditableElement', () => {
 		root._document = createDocumentMock();
 		root.rootName = 'header';
 
-		const newRoot = root.clone();
+		const newRoot = root._clone();
 
 		expect( newRoot._document ).to.equal( root._document );
 		expect( newRoot.rootName ).to.equal( root.rootName );

+ 3 - 3
packages/ckeditor5-engine/tests/view/text.js

@@ -40,10 +40,10 @@ describe( 'Text', () => {
 		} );
 	} );
 
-	describe( 'clone', () => {
+	describe( '_clone()', () => {
 		it( 'should return new text with same data', () => {
 			const text = new Text( 'foo bar' );
-			const clone = text.clone();
+			const clone = text._clone();
 
 			expect( clone ).to.not.equal( text );
 			expect( clone.data ).to.equal( text.data );
@@ -69,7 +69,7 @@ describe( 'Text', () => {
 		} );
 
 		it( 'should return false when data is not the same', () => {
-			const other = text.clone();
+			const other = text._clone();
 			other.data = 'not-foo';
 
 			expect( text.isSimilar( other ) ).to.be.false;

+ 2 - 2
packages/ckeditor5-engine/tests/view/uielement.js

@@ -82,9 +82,9 @@ describe( 'UIElement', () => {
 		} );
 	} );
 
-	describe( 'clone()', () => {
+	describe( '_clone()', () => {
 		it( 'should be properly cloned', () => {
-			const newUIElement = uiElement.clone();
+			const newUIElement = uiElement._clone();
 
 			expect( newUIElement.name ).to.equal( 'span' );
 			expect( newUIElement.getAttribute( 'foo' ) ).to.equal( 'bar' );