Răsfoiți Sursa

Marked operation utils names as protected.

Oskar Wróbel 8 ani în urmă
părinte
comite
014e794117

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

@@ -10,7 +10,7 @@
 import Operation from './operation';
 import Operation from './operation';
 import Range from '../range';
 import Range from '../range';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
-import { setAttribute } from './utils';
+import { _setAttribute } from './utils';
 import isEqual from '@ckeditor/ckeditor5-utils/src/lib/lodash/isEqual';
 import isEqual from '@ckeditor/ckeditor5-utils/src/lib/lodash/isEqual';
 
 
 /**
 /**
@@ -151,7 +151,7 @@ export default class AttributeOperation extends Operation {
 		// If value to set is same as old value, don't do anything.
 		// If value to set is same as old value, don't do anything.
 		if ( !isEqual( this.oldValue, this.newValue ) ) {
 		if ( !isEqual( this.oldValue, this.newValue ) ) {
 			// Execution.
 			// Execution.
-			setAttribute( this.range, this.key, this.newValue );
+			_setAttribute( this.range, this.key, this.newValue );
 		}
 		}
 
 
 		return { range: this.range, key: this.key, oldValue: this.oldValue, newValue: this.newValue };
 		return { range: this.range, key: this.key, oldValue: this.oldValue, newValue: this.newValue };

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

@@ -10,7 +10,7 @@
 import Operation from './operation';
 import Operation from './operation';
 import Position from '../position';
 import Position from '../position';
 import Range from '../range';
 import Range from '../range';
-import { remove } from './utils';
+import { _remove } from './utils';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 
 /**
 /**
@@ -73,7 +73,7 @@ export default class DetachOperation extends Operation {
 			throw new CKEditorError( 'detach-operation-on-document-node: Cannot detach document node.' );
 			throw new CKEditorError( 'detach-operation-on-document-node: Cannot detach document node.' );
 		}
 		}
 
 
-		const nodes = remove( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ) );
+		const nodes = _remove( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ) );
 
 
 		return { nodes };
 		return { nodes };
 	}
 	}

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

@@ -11,7 +11,7 @@ import Operation from './operation';
 import Position from '../position';
 import Position from '../position';
 import NodeList from '../nodelist';
 import NodeList from '../nodelist';
 import RemoveOperation from './removeoperation';
 import RemoveOperation from './removeoperation';
-import { insert, normalizeNodes } from './utils';
+import { _insert, _normalizeNodes } from './utils';
 import Text from '../text';
 import Text from '../text';
 import Element from '../element';
 import Element from '../element';
 
 
@@ -45,7 +45,7 @@ export default class InsertOperation extends Operation {
 		 * @readonly
 		 * @readonly
 		 * @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
 		 * @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
 		 */
 		 */
-		this.nodes = new NodeList( normalizeNodes( nodes ) );
+		this.nodes = new NodeList( _normalizeNodes( nodes ) );
 
 
 		/**
 		/**
 		 * @inheritDoc
 		 * @inheritDoc
@@ -94,7 +94,7 @@ export default class InsertOperation extends Operation {
 		const originalNodes = this.nodes;
 		const originalNodes = this.nodes;
 		this.nodes = new NodeList( [ ...originalNodes ].map( node => node.clone( true ) ) );
 		this.nodes = new NodeList( [ ...originalNodes ].map( node => node.clone( true ) ) );
 
 
-		const range = insert( this.position, originalNodes );
+		const range = _insert( this.position, originalNodes );
 
 
 		return { range };
 		return { range };
 	}
 	}

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

@@ -12,7 +12,7 @@ import Position from '../position';
 import Range from '../range';
 import Range from '../range';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
 import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
-import { move } from './utils';
+import { _move } from './utils';
 
 
 /**
 /**
  * Operation to move a range of {@link module:engine/model/item~Item model items}
  * Operation to move a range of {@link module:engine/model/item~Item model items}
@@ -184,7 +184,7 @@ export default class MoveOperation extends Operation {
 			}
 			}
 		}
 		}
 
 
-		const range = move( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ), this.targetPosition );
+		const range = _move( Range.createFromPositionAndShift( this.sourcePosition, this.howMany ), this.targetPosition );
 
 
 		return {
 		return {
 			sourcePosition: this.sourcePosition,
 			sourcePosition: this.sourcePosition,

+ 8 - 17
packages/ckeditor5-engine/src/model/operation/utils.js

@@ -22,15 +22,6 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  * @protected
  * @protected
  * @namespace utils
  * @namespace utils
  */
  */
-const utils = {
-	insert,
-	remove,
-	move,
-	setAttribute,
-	normalizeNodes
-};
-
-export default utils;
 
 
 /**
 /**
  * Inserts given nodes at given position.
  * Inserts given nodes at given position.
@@ -41,8 +32,8 @@ export default utils;
  * @param {module:engine/model/node~NodeSet} nodes Nodes to insert.
  * @param {module:engine/model/node~NodeSet} nodes Nodes to insert.
  * @returns {module:engine/model/range~Range} Range spanning over inserted elements.
  * @returns {module:engine/model/range~Range} Range spanning over inserted elements.
  */
  */
-export function insert( position, nodes ) {
-	nodes = normalizeNodes( nodes );
+export function _insert( position, nodes ) {
+	nodes = _normalizeNodes( nodes );
 
 
 	// We have to count offset before inserting nodes because they can get merged and we would get wrong offsets.
 	// We have to count offset before inserting nodes because they can get merged and we would get wrong offsets.
 	const offset = nodes.reduce( ( sum, node ) => sum + node.offsetSize, 0 );
 	const offset = nodes.reduce( ( sum, node ) => sum + node.offsetSize, 0 );
@@ -71,7 +62,7 @@ export function insert( position, nodes ) {
  * @param {module:engine/model/range~Range} range Range containing nodes to remove.
  * @param {module:engine/model/range~Range} range Range containing nodes to remove.
  * @returns {Array.<module:engine/model/node~Node>}
  * @returns {Array.<module:engine/model/node~Node>}
  */
  */
-export function remove( range ) {
+export function _remove( range ) {
 	if ( !range.isFlat ) {
 	if ( !range.isFlat ) {
 		/**
 		/**
 		 * Trying to remove a range which starts and ends in different element.
 		 * Trying to remove a range which starts and ends in different element.
@@ -107,7 +98,7 @@ export function remove( range ) {
  * @param {module:engine/model/position~Position} targetPosition Position to which nodes should be moved.
  * @param {module:engine/model/position~Position} targetPosition Position to which nodes should be moved.
  * @returns {module:engine/model/range~Range} Range containing moved nodes.
  * @returns {module:engine/model/range~Range} Range containing moved nodes.
  */
  */
-export function move( sourceRange, targetPosition ) {
+export function _move( sourceRange, targetPosition ) {
 	if ( !sourceRange.isFlat ) {
 	if ( !sourceRange.isFlat ) {
 		/**
 		/**
 		 * Trying to move a range which starts and ends in different element.
 		 * Trying to move a range which starts and ends in different element.
@@ -118,13 +109,13 @@ export function move( sourceRange, targetPosition ) {
 			'Trying to move a range which starts and ends in different element.' );
 			'Trying to move a range which starts and ends in different element.' );
 	}
 	}
 
 
-	const nodes = remove( sourceRange );
+	const nodes = _remove( sourceRange );
 
 
 	// We have to fix `targetPosition` because model changed after nodes from `sourceRange` got removed and
 	// We have to fix `targetPosition` because model changed after nodes from `sourceRange` got removed and
 	// that change might have an impact on `targetPosition`.
 	// that change might have an impact on `targetPosition`.
 	targetPosition = targetPosition._getTransformedByDeletion( sourceRange.start, sourceRange.end.offset - sourceRange.start.offset );
 	targetPosition = targetPosition._getTransformedByDeletion( sourceRange.start, sourceRange.end.offset - sourceRange.start.offset );
 
 
-	return insert( targetPosition, nodes );
+	return _insert( targetPosition, nodes );
 }
 }
 
 
 /**
 /**
@@ -136,7 +127,7 @@ export function move( sourceRange, targetPosition ) {
  * @param {String} key Key of attribute to set.
  * @param {String} key Key of attribute to set.
  * @param {*} value Attribute value.
  * @param {*} value Attribute value.
  */
  */
-export function setAttribute( range, key, value ) {
+export function _setAttribute( range, key, value ) {
 	// Range might start or end in text nodes, so we have to split them.
 	// Range might start or end in text nodes, so we have to split them.
 	_splitNodeAtPosition( range.start );
 	_splitNodeAtPosition( range.start );
 	_splitNodeAtPosition( range.end );
 	_splitNodeAtPosition( range.end );
@@ -171,7 +162,7 @@ export function setAttribute( range, key, value ) {
  * @param {module:engine/model/node~NodeSet} nodes Objects to normalize.
  * @param {module:engine/model/node~NodeSet} nodes Objects to normalize.
  * @returns {Array.<module:engine/model/node~Node>} Normalized nodes.
  * @returns {Array.<module:engine/model/node~Node>} Normalized nodes.
  */
  */
-export function normalizeNodes( nodes ) {
+export function _normalizeNodes( nodes ) {
 	const normalized = [];
 	const normalized = [];
 
 
 	if ( !( nodes instanceof Array ) ) {
 	if ( !( nodes instanceof Array ) ) {

+ 22 - 22
packages/ckeditor5-engine/tests/model/operation/utils.js

@@ -10,7 +10,7 @@ import Text from '../../../src/model/text';
 import TextProxy from '../../../src/model/textproxy';
 import TextProxy from '../../../src/model/textproxy';
 import Position from '../../../src/model/position';
 import Position from '../../../src/model/position';
 import Range from '../../../src/model/range';
 import Range from '../../../src/model/range';
-import utils from '../../../src/model/operation/utils';
+import * as utils from '../../../src/model/operation/utils';
 import { getData } from '../../../src/dev-utils/model';
 import { getData } from '../../../src/dev-utils/model';
 
 
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
@@ -38,19 +38,19 @@ describe( 'writer utils', () => {
 
 
 	describe( 'insert', () => {
 	describe( 'insert', () => {
 		it( 'should insert nodes between nodes', () => {
 		it( 'should insert nodes between nodes', () => {
-			utils.insert( Position.createAt( root, 3 ), [ 'xxx', new Element( 'p' ) ] );
+			utils._insert( Position.createAt( root, 3 ), [ 'xxx', new Element( 'p' ) ] );
 
 
 			expectData( 'fooxxx<p></p><$text bold="true">bar</$text><image src="img.jpg"></image>xyz' );
 			expectData( 'fooxxx<p></p><$text bold="true">bar</$text><image src="img.jpg"></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should split text node if nodes at inserted at offset inside text node', () => {
 		it( 'should split text node if nodes at inserted at offset inside text node', () => {
-			utils.insert( Position.createAt( root, 5 ), new Element( 'p' ) );
+			utils._insert( Position.createAt( root, 5 ), new Element( 'p' ) );
 
 
 			expectData( 'foo<$text bold="true">ba</$text><p></p><$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
 			expectData( 'foo<$text bold="true">ba</$text><p></p><$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should merge text nodes if possible', () => {
 		it( 'should merge text nodes if possible', () => {
-			utils.insert( Position.createAt( root, 3 ), new Text( 'xxx', { bold: true } ) );
+			utils._insert( Position.createAt( root, 3 ), new Text( 'xxx', { bold: true } ) );
 
 
 			expectData( 'foo<$text bold="true">xxxbar</$text><image src="img.jpg"></image>xyz' );
 			expectData( 'foo<$text bold="true">xxxbar</$text><image src="img.jpg"></image>xyz' );
 		} );
 		} );
@@ -59,21 +59,21 @@ describe( 'writer utils', () => {
 	describe( 'remove', () => {
 	describe( 'remove', () => {
 		it( 'should remove nodes in given range', () => {
 		it( 'should remove nodes in given range', () => {
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
-			utils.remove( range );
+			utils._remove( range );
 
 
 			expectData( 'foo<image src="img.jpg"></image>xyz' );
 			expectData( 'foo<image src="img.jpg"></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should split text node if range starts or ends inside text node', () => {
 		it( 'should split text node if range starts or ends inside text node', () => {
 			const range = Range.createFromParentsAndOffsets( root, 1, root, 5 );
 			const range = Range.createFromParentsAndOffsets( root, 1, root, 5 );
-			utils.remove( range );
+			utils._remove( range );
 
 
 			expectData( 'f<$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
 			expectData( 'f<$text bold="true">r</$text><image src="img.jpg"></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should merge text nodes if possible', () => {
 		it( 'should merge text nodes if possible', () => {
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 7 );
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 7 );
-			utils.remove( range );
+			utils._remove( range );
 
 
 			expectData( 'fooxyz' );
 			expectData( 'fooxyz' );
 			expect( root.childCount ).to.equal( 1 );
 			expect( root.childCount ).to.equal( 1 );
@@ -81,7 +81,7 @@ describe( 'writer utils', () => {
 
 
 		it( 'should throw if given range is not flat', () => {
 		it( 'should throw if given range is not flat', () => {
 			expect( () => {
 			expect( () => {
-				utils.remove( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ) );
+				utils._remove( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ) );
 			} ).to.throw( CKEditorError, /operation-utils-remove-range-not-flat/ );
 			} ).to.throw( CKEditorError, /operation-utils-remove-range-not-flat/ );
 		} );
 		} );
 	} );
 	} );
@@ -89,21 +89,21 @@ describe( 'writer utils', () => {
 	describe( 'move', () => {
 	describe( 'move', () => {
 		it( 'should move a range of nodes', () => {
 		it( 'should move a range of nodes', () => {
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
-			utils.move( range, Position.createAt( root, 0 ) );
+			utils._move( range, Position.createAt( root, 0 ) );
 
 
 			expectData( '<$text bold="true">bar</$text>foo<image src="img.jpg"></image>xyz' );
 			expectData( '<$text bold="true">bar</$text>foo<image src="img.jpg"></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should correctly move if target position is in same element as moved range, but after range', () => {
 		it( 'should correctly move if target position is in same element as moved range, but after range', () => {
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
 			const range = Range.createFromParentsAndOffsets( root, 3, root, 6 );
-			utils.move( range, Position.createAt( root, 10 ) );
+			utils._move( range, Position.createAt( root, 10 ) );
 
 
 			expectData( 'foo<image src="img.jpg"></image>xyz<$text bold="true">bar</$text>' );
 			expectData( 'foo<image src="img.jpg"></image>xyz<$text bold="true">bar</$text>' );
 		} );
 		} );
 
 
 		it( 'should throw if given range is not flat', () => {
 		it( 'should throw if given range is not flat', () => {
 			expect( () => {
 			expect( () => {
-				utils.move( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ), null );
+				utils._move( new Range( new Position( root, [ 0 ] ), new Position( root, [ 1, 2 ] ) ), null );
 			} ).to.throw( CKEditorError, /operation-utils-move-range-not-flat/ );
 			} ).to.throw( CKEditorError, /operation-utils-move-range-not-flat/ );
 		} );
 		} );
 	} );
 	} );
@@ -111,21 +111,21 @@ describe( 'writer utils', () => {
 	describe( 'setAttribute', () => {
 	describe( 'setAttribute', () => {
 		it( 'should set attribute on given range of nodes', () => {
 		it( 'should set attribute on given range of nodes', () => {
 			const range = Range.createFromParentsAndOffsets( root, 6, root, 8 );
 			const range = Range.createFromParentsAndOffsets( root, 6, root, 8 );
-			utils.setAttribute( range, 'newAttr', true );
+			utils._setAttribute( range, 'newAttr', true );
 
 
 			expectData( 'foo<$text bold="true">bar</$text><image newAttr="true" src="img.jpg"></image><$text newAttr="true">x</$text>yz' );
 			expectData( 'foo<$text bold="true">bar</$text><image newAttr="true" src="img.jpg"></image><$text newAttr="true">x</$text>yz' );
 		} );
 		} );
 
 
 		it( 'should remove attribute if null was passed as a value', () => {
 		it( 'should remove attribute if null was passed as a value', () => {
 			const range = Range.createFromParentsAndOffsets( root, 6, root, 7 );
 			const range = Range.createFromParentsAndOffsets( root, 6, root, 7 );
-			utils.setAttribute( range, 'src', null );
+			utils._setAttribute( range, 'src', null );
 
 
 			expectData( 'foo<$text bold="true">bar</$text><image></image>xyz' );
 			expectData( 'foo<$text bold="true">bar</$text><image></image>xyz' );
 		} );
 		} );
 
 
 		it( 'should merge nodes if possible', () => {
 		it( 'should merge nodes if possible', () => {
 			const range = Range.createFromParentsAndOffsets( root, 0, root, 3 );
 			const range = Range.createFromParentsAndOffsets( root, 0, root, 3 );
-			utils.setAttribute( range, 'bold', true );
+			utils._setAttribute( range, 'bold', true );
 
 
 			expectData( '<$text bold="true">foobar</$text><image src="img.jpg"></image>xyz' );
 			expectData( '<$text bold="true">foobar</$text><image src="img.jpg"></image>xyz' );
 		} );
 		} );
@@ -136,11 +136,11 @@ describe( 'normalizeNodes', () => {
 	it( 'should change single object into an array', () => {
 	it( 'should change single object into an array', () => {
 		const p = new Element( 'p' );
 		const p = new Element( 'p' );
 
 
-		expect( utils.normalizeNodes( p ) ).to.deep.equal( [ p ] );
+		expect( utils._normalizeNodes( p ) ).to.deep.equal( [ p ] );
 	} );
 	} );
 
 
 	it( 'should change strings to text nodes', () => {
 	it( 'should change strings to text nodes', () => {
-		const text = utils.normalizeNodes( 'abc' )[ 0 ];
+		const text = utils._normalizeNodes( 'abc' )[ 0 ];
 
 
 		expect( text ).to.be.instanceof( Text );
 		expect( text ).to.be.instanceof( Text );
 		expect( text.data ).to.equal( 'abc' );
 		expect( text.data ).to.equal( 'abc' );
@@ -150,7 +150,7 @@ describe( 'normalizeNodes', () => {
 		const textNode = new Text( 'abc' );
 		const textNode = new Text( 'abc' );
 		const textProxy = new TextProxy( textNode, 1, 1 );
 		const textProxy = new TextProxy( textNode, 1, 1 );
 
 
-		const text = utils.normalizeNodes( textProxy )[ 0 ];
+		const text = utils._normalizeNodes( textProxy )[ 0 ];
 
 
 		expect( text ).to.be.instanceof( Text );
 		expect( text ).to.be.instanceof( Text );
 		expect( text.data ).to.equal( 'b' );
 		expect( text.data ).to.equal( 'b' );
@@ -159,11 +159,11 @@ describe( 'normalizeNodes', () => {
 	it( 'should not change elements', () => {
 	it( 'should not change elements', () => {
 		const p = new Element( 'p' );
 		const p = new Element( 'p' );
 
 
-		expect( utils.normalizeNodes( p )[ 0 ] ).to.equal( p );
+		expect( utils._normalizeNodes( p )[ 0 ] ).to.equal( p );
 	} );
 	} );
 
 
 	it( 'should omit unrecognized objects', () => {
 	it( 'should omit unrecognized objects', () => {
-		expect( utils.normalizeNodes( 1 ) ).to.deep.equal( [] );
+		expect( utils._normalizeNodes( 1 ) ).to.deep.equal( [] );
 	} );
 	} );
 
 
 	it( 'should accept arrays', () => {
 	it( 'should accept arrays', () => {
@@ -171,7 +171,7 @@ describe( 'normalizeNodes', () => {
 		const image = new Element( 'image' );
 		const image = new Element( 'image' );
 		const nodes = [ 'abc', text, image, 1, 'xyz' ];
 		const nodes = [ 'abc', text, image, 1, 'xyz' ];
 
 
-		const normalized = utils.normalizeNodes( nodes );
+		const normalized = utils._normalizeNodes( nodes );
 
 
 		expect( normalized[ 0 ] ).to.be.instanceof( Text );
 		expect( normalized[ 0 ] ).to.be.instanceof( Text );
 		expect( normalized[ 1 ] ).to.equal( text );
 		expect( normalized[ 1 ] ).to.equal( text );
@@ -180,7 +180,7 @@ describe( 'normalizeNodes', () => {
 	} );
 	} );
 
 
 	it( 'should merge text nodes if mergeTextNodes flag is set to true', () => {
 	it( 'should merge text nodes if mergeTextNodes flag is set to true', () => {
-		const normalized = utils.normalizeNodes( [ 'foo', 'bar' ], true );
+		const normalized = utils._normalizeNodes( [ 'foo', 'bar' ], true );
 
 
 		expect( normalized.length ).to.equal( 1 );
 		expect( normalized.length ).to.equal( 1 );
 		expect( normalized[ 0 ].data ).to.equal( 'foobar' );
 		expect( normalized[ 0 ].data ).to.equal( 'foobar' );
@@ -193,7 +193,7 @@ describe( 'normalizeNodes', () => {
 			'xyz'
 			'xyz'
 		];
 		];
 
 
-		const normalized = utils.normalizeNodes( nodes, true );
+		const normalized = utils._normalizeNodes( nodes, true );
 
 
 		expect( normalized[ 0 ] ).to.be.instanceof( Text );
 		expect( normalized[ 0 ] ).to.be.instanceof( Text );
 		expect( normalized[ 0 ].getAttribute( 'bold' ) ).to.be.true;
 		expect( normalized[ 0 ].getAttribute( 'bold' ) ).to.be.true;