Bläddra i källkod

Merge pull request #70 from cksource/t/33-tree

Tree Data Model. Fixes: #33.
Piotr Jasiun 10 år sedan
förälder
incheckning
55aac3f246

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1057 - 678
packages/ckeditor5-ui/src/lib/lodash/lodash-ckeditor.js


+ 25 - 1
packages/ckeditor5-ui/src/utils-lodash.js

@@ -47,7 +47,31 @@
 		 * @member utils
 		 * @method isObject
 		 */
-		'isObject'
+		'isObject',
+
+		/**
+		 * See Lo-Dash: https://lodash.com/docs#isArray
+		 *
+		 * @member utils
+		 * @method isArray
+		 */
+		'isArray',
+
+		/**
+		 * See Lo-Dash: https://lodash.com/docs#last
+		 *
+		 * @member utils
+		 * @method last
+		 */
+		'last',
+
+		/**
+		 * See Lo-Dash: https://lodash.com/docs#isEqual
+		 *
+		 * @member utils
+		 * @method isEqual
+		 */
+		'isEqual'
 	];
 
 	// Make this compatible with CommonJS as well so it can be used in Node (e.g. "grunt lodash").

+ 74 - 1
packages/ckeditor5-ui/src/utils.js

@@ -43,9 +43,82 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 			return function() {
 				return next++;
 			};
-		} )()
+		} )(),
+
+		/**
+		 * Checks if value implements iterator interface.
+		 *
+		 * @param {Mixed} value The value to check.
+		 * @returns {Boolean} True if value implements iterator interface.
+		 */
+		isIterable( value ) {
+			return !!( value && value[ Symbol.iterator ] );
+		},
+
+		/**
+		 * Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
+		 * or completely different.
+		 *
+		 *   compareArrays( [ 0, 2 ], [ 0, 2 ] ); // SAME
+		 *   compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // PREFIX
+		 *   compareArrays( [ 0, 2 ], [ 0 ] ); // EXTENSION
+		 *   compareArrays( [ 0, 2 ], [ 1, 2 ] ); // DIFFERENT
+		 *
+		 * @param {Array} a Array that is compared.
+		 * @param {Array} b Array to compare with.
+		 * @returns {Number} How array `a` is related to array `b`. Represented by one of flags:
+		 * `a` is {@link utils.compareArrays#SAME same}, `a` is a {@link utils.compareArrays#PREFIX prefix),
+		 * `a` is a {@link utils.compareArrays#EXTENSION extension}, or `a` is {@link utils.compareArrays#DIFFERENT different}.
+		 */
+		compareArrays( a, b ) {
+			var minLen = Math.min( a.length, b.length );
+
+			for ( var i = 0; i < minLen; i++ ) {
+				if ( a[ i ] != b[ i ] ) {
+					// The arrays are different.
+					return utils.compareArrays.DIFFERENT;
+				}
+			}
+
+			// Both arrays were same at all points.
+			if ( a.length == b.length ) {
+				// If their length is also same, they are the same.
+				return utils.compareArrays.SAME;
+			} else if ( a.length < b.length ) {
+				// Compared array is shorter so it is a prefix of the other array.
+				return utils.compareArrays.PREFIX;
+			} else {
+				// Compared array is longer so it is a suffix of the other array.
+				return utils.compareArrays.EXTENSION;
+			}
+		}
 	};
 
+	/**
+	 * Flag for "is same as" relation between arrays.
+	 *
+	 * @type {Number}
+	 */
+	utils.compareArrays.SAME = 0;
+	/**
+	 * Flag for "is a prefix of" relation between arrays.
+	 *
+	 * @type {Number}
+	 */
+	utils.compareArrays.PREFIX = 1;
+	/**
+	 * Flag for "is a suffix of" relation between arrays.
+	 *
+	 * @type {number}
+	 */
+	utils.compareArrays.EXTENSION = 2;
+	/**
+	 * Flag for "is different than" relation between arrays.
+	 *
+	 * @type {Number}
+	 */
+	utils.compareArrays.DIFFERENT = 3;
+
 	// Extend "utils" with Lo-Dash methods.
 	for ( var i = 0; i < lodashIncludes.length; i++ ) {
 		utils[ lodashIncludes[ i ] ] = lodash[ lodashIncludes[ i ] ];

Vissa filer visades inte eftersom för många filer har ändrats