Browse Source

Use of utlis object refactor

Oskar Wrobel 9 years ago
parent
commit
433db4ddfe
35 changed files with 106 additions and 104 deletions
  1. 2 2
      packages/ckeditor5-engine/src/treecontroller/modelconversiondispatcher.js
  2. 2 2
      packages/ckeditor5-engine/src/treecontroller/view-converter-builder.js
  3. 2 2
      packages/ckeditor5-engine/src/treecontroller/viewconversiondispatcher.js
  4. 2 2
      packages/ckeditor5-engine/src/treemodel/characterproxy.js
  5. 2 2
      packages/ckeditor5-engine/src/treemodel/composer/composer.js
  6. 2 2
      packages/ckeditor5-engine/src/treemodel/composer/deletecontents.js
  7. 10 10
      packages/ckeditor5-engine/src/treemodel/delta/basic-transformations.js
  8. 2 2
      packages/ckeditor5-engine/src/treemodel/document.js
  9. 2 2
      packages/ckeditor5-engine/src/treemodel/element.js
  10. 2 2
      packages/ckeditor5-engine/src/treemodel/liveposition.js
  11. 2 2
      packages/ckeditor5-engine/src/treemodel/liverange.js
  12. 2 2
      packages/ckeditor5-engine/src/treemodel/node.js
  13. 5 4
      packages/ckeditor5-engine/src/treemodel/nodelist.js
  14. 2 2
      packages/ckeditor5-engine/src/treemodel/operation/moveoperation.js
  15. 2 2
      packages/ckeditor5-engine/src/treemodel/operation/transform.js
  16. 6 6
      packages/ckeditor5-engine/src/treemodel/position.js
  17. 2 2
      packages/ckeditor5-engine/src/treemodel/range.js
  18. 4 3
      packages/ckeditor5-engine/src/treemodel/selection.js
  19. 3 3
      packages/ckeditor5-engine/src/treemodel/text.js
  20. 2 2
      packages/ckeditor5-engine/src/treemodel/textproxy.js
  21. 4 3
      packages/ckeditor5-engine/src/treeview/documentfragment.js
  22. 4 3
      packages/ckeditor5-engine/src/treeview/element.js
  23. 2 2
      packages/ckeditor5-engine/src/treeview/node.js
  24. 3 3
      packages/ckeditor5-engine/src/treeview/position.js
  25. 3 3
      packages/ckeditor5-engine/src/treeview/selection.js
  26. 2 2
      packages/ckeditor5-engine/src/treeview/treeview.js
  27. 3 3
      packages/ckeditor5-engine/src/treeview/writer.js
  28. 2 2
      packages/ckeditor5-engine/tests/treemodel/characterproxy.js
  29. 7 7
      packages/ckeditor5-engine/tests/treemodel/delta/attributedelta.js
  30. 3 3
      packages/ckeditor5-engine/tests/treemodel/delta/delta.js
  31. 3 3
      packages/ckeditor5-engine/tests/treemodel/document/document.js
  32. 2 2
      packages/ckeditor5-engine/tests/treemodel/selection.js
  33. 4 4
      packages/ckeditor5-engine/tests/treeview/domconverter.js
  34. 5 5
      packages/ckeditor5-engine/tests/treeview/element.js
  35. 1 3
      packages/ckeditor5-engine/tests/treeview/treeview.js

+ 2 - 2
packages/ckeditor5-engine/src/treecontroller/modelconversiondispatcher.js

@@ -9,7 +9,7 @@ import Consumable from './modelconsumable.js';
 import Range from '../treemodel/range.js';
 import TextProxy from '../treemodel/textproxy.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 import extend from '../../utils/lib/lodash/extend.js';
 
 /**
@@ -424,4 +424,4 @@ export default class ModelConversionDispatcher {
 	 */
 }
 
-utils.mix( ModelConversionDispatcher, EmitterMixin );
+mix( ModelConversionDispatcher, EmitterMixin );

+ 2 - 2
packages/ckeditor5-engine/src/treecontroller/view-converter-builder.js

@@ -7,7 +7,7 @@
 
 import Matcher from '../treeview/matcher.js';
 import ModelElement from '../treemodel/element.js';
-import utils from '../../utils/utils';
+import isIterable from '../../utils/isIterable';
 
 /**
  * Provides chainable, high-level API to easily build basic view-to-model converters that are appended to given
@@ -372,7 +372,7 @@ class ViewConverterBuilder {
 
 // Helper function that sets given attributes on given `engine.treeModel.Item` or `engine.treeModel.DocumentFragment`.
 function setAttributeOn( toChange, attribute, data, conversionApi ) {
-	if ( utils.isIterable( toChange ) ) {
+	if ( isIterable( toChange ) ) {
 		for ( let node of toChange ) {
 			setAttributeOn( node, attribute, data, conversionApi );
 		}

+ 2 - 2
packages/ckeditor5-engine/src/treecontroller/viewconversiondispatcher.js

@@ -9,7 +9,7 @@ import ViewConsumable from './viewconsumable.js';
 import ViewElement from '../treeview/element.js';
 import ViewText from '../treeview/text.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 import extend from '../../utils/lib/lodash/extend.js';
 
 /**
@@ -215,7 +215,7 @@ export default class ViewConversionDispatcher {
 	 */
 }
 
-utils.mix( ViewConversionDispatcher, EmitterMixin );
+mix( ViewConversionDispatcher, EmitterMixin );
 
 /**
  * Conversion interface that is registered for given {@link engine.treeController.ViewConversionDispatcher} and is

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/characterproxy.js

@@ -6,7 +6,7 @@
 'use strict';
 
 import Node from './node.js';
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
 
 /**
  * A proxy object representing one character stored in the tree data model. It looks and behaves like
@@ -97,7 +97,7 @@ export default class CharacterProxy extends Node {
 	 * {@link engine.treeModel.CharacterProxy#getAttributes}.
 	 */
 	setAttributesTo( attrs ) {
-		let attrsMap = utils.toMap( attrs );
+		let attrsMap = toMap( attrs );
 
 		this.clearAttributes();
 

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/composer/composer.js

@@ -5,7 +5,7 @@
 
 'use strict';
 
-import utils from '../../../utils/utils.js';
+import mix from '../../../utils/mix.js';
 import EmitterMixin from '../../../utils/emittermixin.js';
 import deleteContents from './deletecontents.js';
 import modifySelection from './modifyselection.js';
@@ -63,7 +63,7 @@ export default class Composer {
 	}
 }
 
-utils.mix( Composer, EmitterMixin );
+mix( Composer, EmitterMixin );
 
 /**
  * Event fired when {@link engine.treeModel.composer.Composer#deleteContents} method is called.

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/composer/deletecontents.js

@@ -7,7 +7,7 @@
 
 import LivePosition from '../liveposition.js';
 import Position from '../position.js';
-import utils from '../../../utils/utils.js';
+import compareArrays from '../../../utils/comparearrays.js';
 
 /**
  * Delete contents of the selection and merge siblings. The resulting selection is always collapsed.
@@ -42,7 +42,7 @@ export default function deleteContents( batch, selection, options = {} ) {
 	if ( options.merge ) {
 		const endPath = endPos.path;
 		const mergeEnd = Math.min( startPos.path.length - 1, endPath.length - 1 );
-		let mergeDepth = utils.compareArrays( startPos.path, endPath );
+		let mergeDepth = compareArrays( startPos.path, endPath );
 
 		if ( typeof mergeDepth == 'number' ) {
 			for ( ; mergeDepth < mergeEnd; mergeDepth++ ) {

+ 10 - 10
packages/ckeditor5-engine/src/treemodel/delta/basic-transformations.js

@@ -22,7 +22,7 @@ import WeakInsertDelta from './weakinsertdelta.js';
 import WrapDelta from './wrapdelta.js';
 import UnwrapDelta from './unwrapdelta.js';
 
-import utils from '../../../utils/utils.js';
+import compareArrays from '../../../utils/comparearrays.js';
 
 // Provide transformations for default deltas.
 
@@ -60,7 +60,7 @@ addTransformationCase( MoveDelta, MergeDelta, ( a, b, isStrong ) => {
 	// didn't happen) and then apply the original move operation. This is "mirrored" in MergeDelta x MoveDelta
 	// transformation below, where we simply do not apply MergeDelta.
 
-	const operateInSameParent = utils.compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.sourcePosition.getParentPath(), b.position.getParentPath() ) === 'SAME';
 	const mergeInsideMoveRange = a.sourcePosition.offset <= b.position.offset && a.sourcePosition.offset + a.howMany > b.position.offset;
 
 	if ( operateInSameParent && mergeInsideMoveRange ) {
@@ -91,7 +91,7 @@ addTransformationCase( MergeDelta, MoveDelta, ( a, b, isStrong ) => {
 	// If merge is applied at the position between moved nodes we cancel the merge as it's results may be unexpected and
 	// very weird. Even if we do some "magic" we don't know what really are users' expectations.
 
-	const operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.position.getParentPath(), b.sourcePosition.getParentPath() ) === 'SAME';
 	const mergeInsideMoveRange = b.sourcePosition.offset <= a.position.offset && b.sourcePosition.offset + b.howMany > a.position.offset;
 
 	if ( operateInSameParent && mergeInsideMoveRange ) {
@@ -109,7 +109,7 @@ addTransformationCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 	const pathB = b.position.getParentPath();
 
 	// The special case is for splits inside the same parent.
-	if ( utils.compareArrays( pathA, pathB ) == 'SAME' ) {
+	if ( compareArrays( pathA, pathB ) == 'SAME' ) {
 		if ( a.position.offset == b.position.offset ) {
 			// We are applying split at the position where split already happened. Additional split is not needed.
 			return [ new Delta() ];
@@ -145,7 +145,7 @@ addTransformationCase( SplitDelta, SplitDelta, ( a, b, isStrong ) => {
 addTransformationCase( SplitDelta, UnwrapDelta, ( a, b, isStrong ) => {
 	// If incoming split delta tries to split a node that just got unwrapped, there is actually nothing to split,
 	// so we discard that delta.
-	if ( utils.compareArrays( b.position.path, a.position.getParentPath() ) === 'SAME' ) {
+	if ( compareArrays( b.position.path, a.position.getParentPath() ) === 'SAME' ) {
 		// This is "no-op" delta, it has no type and no operations, it basically does nothing.
 		// It is used when we don't want to apply changes but still we need to return a delta.
 		return [ new Delta() ];
@@ -159,14 +159,14 @@ addTransformationCase( SplitDelta, WrapDelta, ( a, b, isStrong ) => {
 	// If split is applied at the position between wrapped nodes, we cancel the split as it's results may be unexpected and
 	// very weird. Even if we do some "magic" we don't know what really are users' expectations.
 
-	const operateInSameParent = utils.compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.position.getParentPath(), b.range.start.getParentPath() ) === 'SAME';
 	const splitInsideWrapRange = b.range.start.offset < a.position.offset && b.range.end.offset >= a.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
 		// This is "no-op" delta, it has no type and no operations, it basically does nothing.
 		// It is used when we don't want to apply changes but still we need to return a delta.
 		return [ new Delta() ];
-	} else if ( utils.compareArrays( a.position.getParentPath(), b.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
+	} else if ( compareArrays( a.position.getParentPath(), b.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
 		// Split position is directly inside the last node from wrap range.
 		// If that's the case, we manually change split delta so it will "target" inside the wrapping element.
 		// By doing so we will be inserting split node right to the original node which feels natural and is a good UX.
@@ -211,7 +211,7 @@ addTransformationCase( SplitDelta, WrapDelta, ( a, b, isStrong ) => {
 addTransformationCase( UnwrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	// If incoming unwrap delta tries to unwrap node that got split we should unwrap the original node and the split copy.
 	// This can be achieved either by reverting split and applying unwrap to singular node, or creating additional unwrap delta.
-	if ( utils.compareArrays( a.position.path, b.position.getParentPath() ) === 'SAME' ) {
+	if ( compareArrays( a.position.path, b.position.getParentPath() ) === 'SAME' ) {
 		return [
 			b.getReversed(),
 			a.clone()
@@ -239,7 +239,7 @@ addTransformationCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 	// If incoming wrap delta tries to wrap range that contains split position, we have to cancel the split and apply
 	// the wrap. Since split was already applied, we have to revert it.
 
-	const operateInSameParent = utils.compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'SAME';
+	const operateInSameParent = compareArrays( a.range.start.getParentPath(), b.position.getParentPath() ) === 'SAME';
 	const splitInsideWrapRange = a.range.start.offset < b.position.offset && a.range.end.offset >= b.position.offset;
 
 	if ( operateInSameParent && splitInsideWrapRange ) {
@@ -247,7 +247,7 @@ addTransformationCase( WrapDelta, SplitDelta, ( a, b, isStrong ) => {
 			b.getReversed(),
 			a.clone()
 		];
-	} else if ( utils.compareArrays( b.position.getParentPath(), a.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
+	} else if ( compareArrays( b.position.getParentPath(), a.range.end.getShiftedBy( -1 ).path ) === 'SAME' ) {
 		const delta = a.clone();
 
 		// Move wrapping element insert position one node further so it is after the split node insertion.

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/document.js

@@ -15,7 +15,7 @@ import History from './history.js';
 import Selection from './selection.js';
 import EmitterMixin from '../../utils/emittermixin.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 import Schema from './schema.js';
 import Composer from './composer/composer.js';
 import clone from '../../utils/lib/lodash/clone.js';
@@ -334,4 +334,4 @@ export default class Document {
 	 */
 }
 
-utils.mix( Document, EmitterMixin );
+mix( Document, EmitterMixin );

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/element.js

@@ -9,7 +9,7 @@ import Node from './node.js';
 import NodeList from './nodelist.js';
 import DocumentFragment from './documentfragment.js';
 import Range from './range.js';
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
 
 /**
  * Tree data model element.
@@ -151,7 +151,7 @@ export default class Element extends Node {
 	 * @param {Iterable|Object} attrs Iterable object containing attributes to be set. See {@link engine.treeModel.Node#getAttributes}.
 	 */
 	setAttributesTo( attrs ) {
-		this._attrs = utils.toMap( attrs );
+		this._attrs = toMap( attrs );
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/liveposition.js

@@ -9,7 +9,7 @@ import RootElement from './rootelement.js';
 import Position from './position.js';
 import Range from './range.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
 
 /**
@@ -180,7 +180,7 @@ function transform( type, range, position ) {
 	this.root = transformed.root;
 }
 
-utils.mix( LivePosition, EmitterMixin );
+mix( LivePosition, EmitterMixin );
 
 /**
  * Enum representing how position is "sticking" with their neighbour nodes.

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/liverange.js

@@ -8,7 +8,7 @@
 import Range from './range.js';
 import LivePosition from './liveposition.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 
 /**
  * LiveRange is a Range in the Tree Model that updates itself as the tree changes. It may be used as a bookmark.
@@ -137,4 +137,4 @@ function fixBoundaries( type, range, position ) {
 	}
 }
 
-utils.mix( LiveRange, EmitterMixin );
+mix( LiveRange, EmitterMixin );

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/node.js

@@ -6,7 +6,7 @@
 'use strict';
 
 import clone from '../../utils/lib/lodash/clone.js';
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
 
 /**
@@ -42,7 +42,7 @@ export default class Node {
 		 * @protected
 		 * @member {Map} engine.treeModel.Node#_attrs
 		 */
-		this._attrs = utils.toMap( attrs );
+		this._attrs = toMap( attrs );
 	}
 
 	/**

+ 5 - 4
packages/ckeditor5-engine/src/treemodel/nodelist.js

@@ -8,7 +8,8 @@
 import CharacterProxy from './characterproxy.js';
 import Text from './text.js';
 import DocumentFragment from './documentfragment.js';
-import utils from '../../utils/utils.js';
+import mapsEqual from '../../utils/mapsequal.js';
+import isIterable from '../../utils/isiterable.js';
 import clone from '../../utils/lib/lodash/clone.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
 
@@ -132,7 +133,7 @@ export default class NodeList {
 		this._indexMap = [];
 
 		if ( nodes ) {
-			if ( typeof nodes == 'string' || !utils.isIterable( nodes ) ) {
+			if ( typeof nodes == 'string' || !isIterable( nodes ) ) {
 				nodes = [ nodes ];
 			}
 
@@ -154,7 +155,7 @@ export default class NodeList {
 
 					let prev = this._nodes[ this._nodes.length - 1 ];
 
-					if ( prev instanceof NodeListText && utils.mapsEqual( prev._attrs, node._attrs ) ) {
+					if ( prev instanceof NodeListText && mapsEqual( prev._attrs, node._attrs ) ) {
 						// If previously added text has same attributes, merge this text with it.
 						prev.text += node.text;
 						mergedWithPrev = true;
@@ -417,7 +418,7 @@ export default class NodeList {
 		let nodeAfter = this._nodes[ realIndexAfter ];
 
 		// Check if both of those nodes are text objects with same attributes.
-		if ( nodeBefore instanceof NodeListText && nodeAfter instanceof NodeListText && utils.mapsEqual( nodeBefore._attrs, nodeAfter._attrs ) ) {
+		if ( nodeBefore instanceof NodeListText && nodeAfter instanceof NodeListText && mapsEqual( nodeBefore._attrs, nodeAfter._attrs ) ) {
 			// Append text of text node after index to the before one.
 			nodeBefore.text += nodeAfter.text;
 

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

@@ -9,7 +9,7 @@ import Operation from './operation.js';
 import Position from '../position.js';
 import Range from '../range.js';
 import CKEditorError from '../../../utils/ckeditorerror.js';
-import utils from '../../../utils/utils.js';
+import compareArrays from '../../../utils/comparearrays.js';
 
 /**
  * Operation to move list of subsequent nodes from one position in the document to another.
@@ -125,7 +125,7 @@ export default class MoveOperation extends Operation {
 				'operation-move-range-into-itself: Trying to move a range of nodes to the inside of that range.'
 			);
 		} else {
-			if ( utils.compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == 'PREFIX' ) {
+			if ( compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == 'PREFIX' ) {
 				let i = this.sourcePosition.path.length - 1;
 
 				if ( this.targetPosition.path[ i ] >= sourceOffset && this.targetPosition.path[ i ] < sourceOffset + this.howMany ) {

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/operation/transform.js

@@ -13,7 +13,7 @@ import RemoveOperation from './removeoperation.js';
 import NoOperation from './nooperation.js';
 import Range from '../range.js';
 import isEqual from '../../../utils/lib/lodash/isEqual.js';
-import utils from '../../../utils/utils.js';
+import compareArrays from '../../../utils/compareArrays.js';
 
 /**
  * Transforms given {@link engine.treeModel.operation.Operation operation} by another
@@ -283,7 +283,7 @@ const ot = {
 			// That means that we transform common part in two cases:
 			// * `rangeA` is "deeper" than `rangeB` so it does not collide
 			// * `rangeA` is at the same level but is stronger than `rangeB`.
-			let aCompB = utils.compareArrays( a.sourcePosition.getParentPath(), b.sourcePosition.getParentPath() );
+			let aCompB = compareArrays( a.sourcePosition.getParentPath(), b.sourcePosition.getParentPath() );
 
 			// If the `b` MoveOperation points inside the `a` MoveOperation range, the common part will be included in
 			// range(s) that (is) are results of processing `difference`. If that's the case, we cannot include it again.

+ 6 - 6
packages/ckeditor5-engine/src/treemodel/position.js

@@ -8,7 +8,7 @@
 import DocumentFragment from './documentfragment.js';
 import Element from './element.js';
 import last from '../../utils/lib/lodash/last.js';
-import utils from '../../utils/utils.js';
+import compareArrays from '../../utils/comparearrays';
 import CKEditorError from '../../utils/ckeditorerror.js';
 
 /**
@@ -145,7 +145,7 @@ export default class Position {
 			return 'DIFFERENT';
 		}
 
-		const result = utils.compareArrays( this.path, otherPosition.path );
+		const result = compareArrays( this.path, otherPosition.path );
 
 		switch ( result ) {
 			case 'SAME':
@@ -209,7 +209,7 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
+		if ( compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
 			// If nodes are removed from the node that is pointed by this position...
 			if ( deletePosition.offset < this.offset ) {
 				// And are removed from before an offset of that position...
@@ -221,7 +221,7 @@ export default class Position {
 					transformed.offset -= howMany;
 				}
 			}
-		} else if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
+		} else if ( compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
 			// If nodes are removed from a node that is on a path to this position...
 			const i = deletePosition.path.length - 1;
 
@@ -260,14 +260,14 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
+		if ( compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
 			// If nodes are inserted in the node that is pointed by this position...
 			if ( insertPosition.offset < this.offset || ( insertPosition.offset == this.offset && insertBefore ) ) {
 				// And are inserted before an offset of that position...
 				// "Push" this positions offset.
 				transformed.offset += howMany;
 			}
-		} else if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
+		} else if ( compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
 			// If nodes are inserted in a node that is on a path to this position...
 			const i = insertPosition.path.length - 1;
 

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/range.js

@@ -7,7 +7,7 @@
 
 import Position from './position.js';
 import TreeWalker from './treewalker.js';
-import utils from '../../utils/utils.js';
+import compareArrays from '../../utils/comparearrays.js';
 
 /**
  * Range class. Range is iterable.
@@ -217,7 +217,7 @@ export default class Range {
 		let ranges = [];
 
 		// We find on which tree-level start and end have the lowest common ancestor
-		let cmp = utils.compareArrays( this.start.path, this.end.path );
+		let cmp = compareArrays( this.start.path, this.end.path );
 		// If comparison returned string it means that arrays are same.
 		let diffAt = ( typeof cmp == 'string' ) ? Math.min( this.start.path.length, this.end.path.length ) : cmp;
 

+ 4 - 3
packages/ckeditor5-engine/src/treemodel/selection.js

@@ -11,7 +11,8 @@ import LiveRange from './liverange.js';
 import EmitterMixin from '../../utils/emittermixin.js';
 import CharacterProxy from './characterproxy.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
+import mix from '../../utils/mix.js';
 
 const storePrefix = 'selection:';
 
@@ -349,7 +350,7 @@ export default class Selection {
 	 * @param {Iterable|Object} attrs Iterable object containing attributes to be set.
 	 */
 	setAttributesTo( attrs ) {
-		this._attrs = utils.toMap( attrs );
+		this._attrs = toMap( attrs );
 		this._setStoredAttributesTo( this._attrs );
 
 		this.fire( 'change:attribute' );
@@ -574,7 +575,7 @@ export default class Selection {
 	}
 }
 
-utils.mix( Selection, EmitterMixin );
+mix( Selection, EmitterMixin );
 
 /**
  * Fired whenever selection ranges are changed through {@link engine.treeModel.Selection Selection API}. Not fired when

+ 3 - 3
packages/ckeditor5-engine/src/treemodel/text.js

@@ -5,7 +5,7 @@
 
 'use strict';
 
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
 
 /**
  * Data structure for text with attributes. Note that `Text` is not a {@link engine.treeModel.Node}. This class is used
@@ -37,7 +37,7 @@ export default class Text {
 		 * @protected
 		 * @member {Map} engine.treeModel.Text#_attrs
 		 */
-		this._attrs = utils.toMap( attrs );
+		this._attrs = toMap( attrs );
 	}
 
 	/**
@@ -85,7 +85,7 @@ export default class Text {
 	 * @param {Iterable|Object} attrs Iterable object containing attributes to be set. See {@link engine.treeModel.Text#getAttributes}.
 	 */
 	setAttributesTo( attrs ) {
-		this._attrs = utils.toMap( attrs );
+		this._attrs = toMap( attrs );
 	}
 
 	/**

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/textproxy.js

@@ -6,7 +6,7 @@
 'use strict';
 
 import CharacterProxy from './characterproxy.js';
-import utils from '../../utils/utils.js';
+import toMap from '../../utils/tomap.js';
 
 /**
  * TextProxy is an aggregator for multiple CharacterProxy instances that are placed next to each other in
@@ -140,7 +140,7 @@ export default class TextProxy {
 	 * See {@link engine.treeModel.TextProxy#getAttributes}.
 	 */
 	setAttributesTo( attrs ) {
-		let attrsMap = utils.toMap( attrs );
+		let attrsMap = toMap( attrs );
 
 		this.clearAttributes();
 

+ 4 - 3
packages/ckeditor5-engine/src/treeview/documentfragment.js

@@ -5,7 +5,8 @@
 
 'use strict';
 
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
+import isIterable from '../../utils/isiterable.js';
 import EmitterMixin from '../../utils/emittermixin.js';
 
 /**
@@ -102,7 +103,7 @@ export default class DocumentFragment {
 		this._fireChange( 'CHILDREN', this );
 		let count = 0;
 
-		if ( !utils.isIterable( nodes ) ) {
+		if ( !isIterable( nodes ) ) {
 			nodes = [ nodes ];
 		}
 
@@ -147,4 +148,4 @@ export default class DocumentFragment {
 	}
 }
 
-utils.mix( DocumentFragment, EmitterMixin );
+mix( DocumentFragment, EmitterMixin );

+ 4 - 3
packages/ckeditor5-engine/src/treeview/element.js

@@ -6,7 +6,8 @@
 'use strict';
 
 import Node from './node.js';
-import utils from '../../utils/utils.js';
+import objectToMap from '../../utils/objecttomap.js';
+import isIterable from '../../utils/isiterable.js';
 import isPlainObject from '../../utils/lib/lodash/isPlainObject.js';
 
 /**
@@ -55,7 +56,7 @@ export default class Element extends Node {
 		 * @member {Map} engine.treeView.Element#_attrs
 		 */
 		if ( isPlainObject( attrs ) ) {
-			this._attrs = utils.objectToMap( attrs );
+			this._attrs = objectToMap( attrs );
 		} else {
 			this._attrs = new Map( attrs );
 		}
@@ -280,7 +281,7 @@ export default class Element extends Node {
 		this._fireChange( 'CHILDREN', this );
 		let count = 0;
 
-		if ( !utils.isIterable( nodes ) ) {
+		if ( !isIterable( nodes ) ) {
 			nodes = [ nodes ];
 		}
 

+ 2 - 2
packages/ckeditor5-engine/src/treeview/node.js

@@ -7,7 +7,7 @@
 
 import CKEditorError from '../../utils/ckeditorerror.js';
 import EmitterMixin from '../../utils/emittermixin.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 
 /**
  * Abstract tree view node class.
@@ -184,4 +184,4 @@ export default class Node {
 	 */
 }
 
-utils.mix( Node, EmitterMixin );
+mix( Node, EmitterMixin );

+ 3 - 3
packages/ckeditor5-engine/src/treeview/position.js

@@ -5,7 +5,7 @@
 
 'use strict';
 
-import utils from '../../utils/utils.js';
+import compareArrays from '../../utils/comparearrays.js';
 import Text from './text.js';
 
 /**
@@ -141,7 +141,7 @@ export default class Position {
 		const otherPath = otherPosition.parent.getAncestors( { includeNode: true } );
 
 		// Compare both path arrays to find common ancestor.
-		const result = utils.compareArrays( path, otherPath );
+		const result = compareArrays( path, otherPath );
 
 		let commonAncestorIndex;
 
@@ -200,4 +200,4 @@ export default class Position {
  * If positions are in different roots `'DIFFERENT'` flag is returned.
  *
  * @typedef {String} engine.treeView.PositionRelation
- */
+ */

+ 3 - 3
packages/ckeditor5-engine/src/treeview/selection.js

@@ -8,7 +8,7 @@
 import CKEditorError from '../../utils/ckeditorerror.js';
 import Range from './range.js';
 import Position from './position.js';
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 import EmitterMixin from '../../utils/emittermixin.js';
 
 /**
@@ -302,10 +302,10 @@ export default class Selection {
 	}
 }
 
-utils.mix( Selection, EmitterMixin );
+mix( Selection, EmitterMixin );
 
 /**
  * Fired whenever selection ranges are changed through {@link engine.treeView.Selection Selection API}.
  *
  * @event engine.treeView.Selection#change
- */
+ */

+ 2 - 2
packages/ckeditor5-engine/src/treeview/treeview.js

@@ -10,7 +10,7 @@ import Renderer from './renderer.js';
 import DomConverter from './domconverter.js';
 import Writer from './writer.js';
 
-import utils from '../../utils/utils.js';
+import mix from '../../utils/mix.js';
 
 /**
  * TreeView class creates an abstract layer over the content editable area.
@@ -167,7 +167,7 @@ export default class TreeView {
 	}
 }
 
-utils.mix( TreeView, EmitterMixin );
+mix( TreeView, EmitterMixin );
 
 /**
  * Enum representing type of the change.

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

@@ -12,7 +12,7 @@ import Text from './text.js';
 import Range from './range.js';
 import CKEditorError from '../../utils/ckeditorerror.js';
 import DocumentFragment from './documentfragment.js';
-import utils from '../../utils/utils.js';
+import isIterable from '../../utils/isiterable.js';
 
 /**
  * Tree View Writer class.
@@ -232,7 +232,7 @@ import utils from '../../utils/utils.js';
 	 * @returns {engine.treeView.Range} Range around inserted nodes.
 	 */
 	insert( position, nodes ) {
-		nodes = utils.isIterable( nodes ) ? [ ...nodes ] : [ nodes ];
+		nodes = isIterable( nodes ) ? [ ...nodes ] : [ nodes ];
 
 		// Check if nodes to insert are instances of AttributeElements, ContainerElements or Text.
 		validateNodesToInsert( nodes );
@@ -887,4 +887,4 @@ function validateNodesToInsert( nodes ) {
 			validateNodesToInsert( node.getChildren() );
 		}
 	}
-}
+}

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/characterproxy.js

@@ -10,7 +10,7 @@
 import Node from '/ckeditor5/engine/treemodel/node.js';
 import Element from '/ckeditor5/engine/treemodel/element.js';
 import Text from '/ckeditor5/engine/treemodel/text.js';
-import utils from '/ckeditor5/utils/utils.js';
+import mapsEqual from '/ckeditor5/utils/mapsequal.js';
 
 describe( 'CharacterProxy', () => {
 	let text, element, char;
@@ -34,7 +34,7 @@ describe( 'CharacterProxy', () => {
 	} );
 
 	it( 'should have attributes list equal to passed to Text instance', () => {
-		expect( utils.mapsEqual( char._attrs, text._attrs ) ).to.be.true;
+		expect( mapsEqual( char._attrs, text._attrs ) ).to.be.true;
 	} );
 
 	it( 'should return correct index in parent node', () => {

+ 7 - 7
packages/ckeditor5-engine/tests/treemodel/delta/attributedelta.js

@@ -7,7 +7,7 @@
 
 'use strict';
 
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 import Document from '/ckeditor5/engine/treemodel/document.js';
 import Text from '/ckeditor5/engine/treemodel/text.js';
 import Range from '/ckeditor5/engine/treemodel/range.js';
@@ -36,13 +36,13 @@ describe( 'Batch', () => {
 	} );
 
 	function getOperationsCount() {
-		let count = 0;
+		let totalNumber = 0;
 
 		for ( let delta of batch.deltas ) {
-			count += utils.count( delta.operations );
+			totalNumber += count( delta.operations );
 		}
 
-		return count;
+		return totalNumber;
 	}
 
 	describe( 'change attribute on node', () => {
@@ -155,15 +155,15 @@ describe( 'Batch', () => {
 		}
 
 		function getChangesAttrsCount() {
-			let count = 0;
+			let totalNumber = 0;
 
 			for ( let delta of batch.deltas ) {
 				for ( let operation of delta.operations ) {
-					count += utils.count( operation.range.getItems( { singleCharacters: true } ) );
+					totalNumber += count( operation.range.getItems( { singleCharacters: true } ) );
 				}
 			}
 
-			return count;
+			return totalNumber;
 		}
 
 		function getCompressedAttrs() {

+ 3 - 3
packages/ckeditor5-engine/tests/treemodel/delta/delta.js

@@ -7,7 +7,7 @@
 
 'use strict';
 
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 import Delta from '/ckeditor5/engine/treemodel/delta/delta.js';
 import Operation from '/ckeditor5/engine/treemodel/operation/operation.js';
 
@@ -70,9 +70,9 @@ describe( 'Delta', () => {
 			delta.addOperation( {} );
 			delta.addOperation( {} );
 
-			const count = utils.count( delta.operations );
+			const totalNumber = count( delta.operations );
 
-			expect( count ).to.equal( 3 );
+			expect( totalNumber ).to.equal( 3 );
 		} );
 	} );
 

+ 3 - 3
packages/ckeditor5-engine/tests/treemodel/document/document.js

@@ -13,7 +13,7 @@ import Composer from '/ckeditor5/engine/treemodel/composer/composer.js';
 import RootElement from '/ckeditor5/engine/treemodel/rootelement.js';
 import Batch from '/ckeditor5/engine/treemodel/batch.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 
 describe( 'Document', () => {
 	let doc;
@@ -28,7 +28,7 @@ describe( 'Document', () => {
 			expect( doc._roots.size ).to.equal( 1 );
 			expect( doc.graveyard ).to.be.instanceof( RootElement );
 			expect( doc.graveyard.getChildCount() ).to.equal( 0 );
-			expect( utils.count( doc.selection.getRanges() ) ).to.equal( 1 );
+			expect( count( doc.selection.getRanges() ) ).to.equal( 1 );
 
 			expect( doc.composer ).to.be.instanceof( Composer );
 			expect( doc.schema ).to.be.instanceof( Schema );
@@ -37,7 +37,7 @@ describe( 'Document', () => {
 
 	describe( 'rootNames', () => {
 		it( 'should return empty iterator if no roots exist', () => {
-			expect( utils.count( doc.rootNames ) ).to.equal( 0 );
+			expect( count( doc.rootNames ) ).to.equal( 0 );
 		} );
 
 		it( 'should return an iterator of all roots without the graveyard', () => {

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/selection.js

@@ -18,7 +18,7 @@ import InsertOperation from '/ckeditor5/engine/treemodel/operation/insertoperati
 import MoveOperation from '/ckeditor5/engine/treemodel/operation/moveoperation.js';
 import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 import testUtils from '/tests/ckeditor5/_utils/utils.js';
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 
 testUtils.createSinonSandbox();
 
@@ -293,7 +293,7 @@ describe( 'Selection', () => {
 
 			selection.setFocus( selection.focus );
 
-			expect( utils.count( selection.getRanges() ) ).to.equal( 2 );
+			expect( count( selection.getRanges() ) ).to.equal( 2 );
 			expect( spy.callCount ).to.equal( 0 );
 		} );
 

+ 4 - 4
packages/ckeditor5-engine/tests/treeview/domconverter.js

@@ -7,7 +7,7 @@
 
 'use strict';
 
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 import ViewElement from '/ckeditor5/engine/treeview/element.js';
 import ViewText from '/ckeditor5/engine/treeview/text.js';
 import DomConverter from '/ckeditor5/engine/treeview/domconverter.js';
@@ -90,7 +90,7 @@ describe( 'DomConverter', () => {
 			expect( viewP.name ).to.equal( 'p' );
 
 			expect( viewP.getAttribute( 'class' ) ).to.equal( 'foo' );
-			expect( utils.count( viewP.getAttributeKeys() ) ).to.equal( 1 );
+			expect( count( viewP.getAttributeKeys() ) ).to.equal( 1 );
 
 			expect( viewP.getChildCount() ).to.equal( 2 );
 			expect( viewP.getChild( 0 ).name ).to.equal( 'img' );
@@ -116,7 +116,7 @@ describe( 'DomConverter', () => {
 			expect( viewP.name ).to.equal( 'p' );
 
 			expect( viewP.getAttribute( 'class' ) ).to.equal( 'foo' );
-			expect( utils.count( viewP.getAttributeKeys() ) ).to.equal( 1 );
+			expect( count( viewP.getAttributeKeys() ) ).to.equal( 1 );
 
 			expect( viewP.getChildCount() ).to.equal( 2 );
 			expect( viewP.getChild( 0 ).name ).to.equal( 'img' );
@@ -146,7 +146,7 @@ describe( 'DomConverter', () => {
 			expect( viewP.name ).to.equal( 'p' );
 
 			expect( viewP.getAttribute( 'class' ) ).to.equal( 'foo' );
-			expect( utils.count( viewP.getAttributeKeys() ) ).to.equal( 1 );
+			expect( count( viewP.getAttributeKeys() ) ).to.equal( 1 );
 
 			expect( viewP.getChildCount() ).to.equal( 0 );
 			expect( converter.getCorrespondingDom( viewP ) ).to.not.equal( domP );

+ 5 - 5
packages/ckeditor5-engine/tests/treeview/element.js

@@ -7,7 +7,7 @@
 
 'use strict';
 
-import utils from '/ckeditor5/utils/utils.js';
+import count from '/ckeditor5/utils/count.js';
 import Node from '/ckeditor5/engine/treeview/node.js';
 import ViewElement from '/ckeditor5/engine/treeview/element.js';
 
@@ -19,14 +19,14 @@ describe( 'Element', () => {
 			expect( el ).to.be.an.instanceof( Node );
 			expect( el ).to.have.property( 'name' ).that.equals( 'p' );
 			expect( el ).to.have.property( 'parent' ).that.is.null;
-			expect( utils.count( el.getAttributeKeys() ) ).to.equal( 0 );
+			expect( count( el.getAttributeKeys() ) ).to.equal( 0 );
 		} );
 
 		it( 'should create element with attributes as plain object', () => {
 			const el = new ViewElement( 'p', { foo: 'bar' } );
 
 			expect( el ).to.have.property( 'name' ).that.equals( 'p' );
-			expect( utils.count( el.getAttributeKeys() ) ).to.equal( 1 );
+			expect( count( el.getAttributeKeys() ) ).to.equal( 1 );
 			expect( el.getAttribute( 'foo' ) ).to.equal( 'bar' );
 		} );
 
@@ -37,7 +37,7 @@ describe( 'Element', () => {
 			const el = new ViewElement( 'p', attrs );
 
 			expect( el ).to.have.property( 'name' ).that.equals( 'p' );
-			expect( utils.count( el.getAttributeKeys() ) ).to.equal( 1 );
+			expect( count( el.getAttributeKeys() ) ).to.equal( 1 );
 			expect( el.getAttribute( 'foo' ) ).to.equal( 'bar' );
 		} );
 
@@ -483,7 +483,7 @@ describe( 'Element', () => {
 
 				expect( el.hasAttribute( 'foo' ) ).to.be.false;
 
-				expect( utils.count( el.getAttributeKeys() ) ).to.equal( 0 );
+				expect( count( el.getAttributeKeys() ) ).to.equal( 0 );
 			} );
 
 			it( 'should fire change event with ATTRIBUTES type', ( done ) => {

+ 1 - 3
packages/ckeditor5-engine/tests/treeview/treeview.js

@@ -13,9 +13,7 @@ import Renderer from '/ckeditor5/engine/treeview/renderer.js';
 import Writer from '/ckeditor5/engine/treeview/writer.js';
 import DomConverter from '/ckeditor5/engine/treeview/domconverter.js';
 
-import utils from '/ckeditor5/utils/utils.js';
-
-const count = utils.count;
+import count from '/ckeditor5/utils/count.js';
 
 describe( 'TreeView', () => {
 	describe( 'constructor', () => {