8
0
Szymon Kupś 9 лет назад
Родитель
Сommit
f5a21969d1

+ 13 - 1
packages/ckeditor5-image/src/imagestyle/converters.js

@@ -7,7 +7,7 @@
  * @module image/imagestyle/converters
  */
 
-import { isImage, getStyleByValue } from './utils';
+import { isImage } from '../utils';
 
 /**
  * Returns converter for `imageStyle` attribute. It can be used for adding, changing and removing the attribute.
@@ -84,3 +84,15 @@ export function viewToModelImageStyle( style ) {
 		modelImageElement.setAttribute( 'imageStyle', style.value );
 	};
 }
+
+// Returns style with given `value` from array of styles.
+// @param {String} value
+// @param {Array.<module:image/imagestyle/imagestyleengine~ImageStyleFormat> } styles
+// @return {module:image/imagestyle/imagestyleengine~ImageStyleFormat|undefined}
+function getStyleByValue( value, styles ) {
+	for ( let style of styles ) {
+		if ( style.value === value ) {
+			return style;
+		}
+	}
+}

+ 1 - 1
packages/ckeditor5-image/src/imagestyle/imagestylecommand.js

@@ -8,7 +8,7 @@
  */
 
 import Command from 'ckeditor5-core/src/command/command';
-import { isImage } from './utils';
+import { isImage } from '../utils';
 
 /**
  * The image style command. It is used to apply different image styles.

+ 0 - 36
packages/ckeditor5-image/src/imagestyle/utils.js

@@ -1,36 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module image/imagestyle/utils
- */
-
-import ModelElement from 'ckeditor5-engine/src/model/element';
-
-/**
- * Checks if provided modelElement is an instance of {@link module:engine/model/element~Element Element} and its name
- * equals to `image`.
- *
- * @param {module:engine/model/element~Element} modelElement
- * @returns {Boolean}
- */
-export function isImage( modelElement ) {
-	return modelElement instanceof ModelElement && modelElement.name == 'image';
-}
-
-/**
- * Returns style with given `value` from array of styles.
- *
- * @param {String} value
- * @param {Array.<module:image/imagestyle/imagestyleengine~ImageStyleFormat> } styles
- * @return {module:image/imagestyle/imagestyleengine~ImageStyleFormat|undefined}
- */
-export function getStyleByValue( value, styles ) {
-	for ( let style of styles ) {
-		if ( style.value === value ) {
-			return style;
-		}
-	}
-}

+ 12 - 0
packages/ckeditor5-image/src/utils.js

@@ -8,6 +8,7 @@
  */
 
 import { widgetize, isWidget } from './widget/utils';
+import ModelElement from 'ckeditor5-engine/src/model/element';
 
 const imageSymbol = Symbol( 'isImage' );
 
@@ -34,3 +35,14 @@ export function toImageWidget( viewElement ) {
 export function isImageWidget( viewElement ) {
 	return !!viewElement.getCustomProperty( imageSymbol ) && isWidget( viewElement );
 }
+
+/**
+ * Checks if provided modelElement is an instance of {@link module:engine/model/element~Element Element} and its name
+ * is `image`.
+ *
+ * @param {module:engine/model/element~Element} modelElement
+ * @returns {Boolean}
+ */
+export function isImage( modelElement ) {
+	return modelElement instanceof ModelElement && modelElement.name == 'image';
+}

+ 0 - 48
packages/ckeditor5-image/tests/imagestyle/utils.js

@@ -1,48 +0,0 @@
-/**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import { isImage, getStyleByValue } from 'ckeditor5-image/src/imagestyle/utils';
-import ModelElement from 'ckeditor5-engine/src/model/element';
-
-describe( 'ImageStyle utils', () => {
-	describe( 'isImage', () => {
-		it( 'should return true for image element', () => {
-			const image = new ModelElement( 'image' );
-
-			expect( isImage( image ) ).to.be.true;
-		} );
-
-		it( 'should return true false for different elements', () => {
-			const image = new ModelElement( 'foo' );
-
-			expect( isImage( image ) ).to.be.false;
-		} );
-
-		it( 'should return true false for null and undefined', () => {
-			expect( isImage( null ) ).to.be.false;
-			expect( isImage( undefined ) ).to.be.false;
-		} );
-	} );
-
-	describe( 'getStyleByValue', () => {
-		const styles = [
-			{ name: 'style 1', title: 'title 1', icon: 'style1-icon', value: 'style1', className: 'style1-class' },
-			{ name: 'style 2', title: 'title 2', icon: 'style2-icon', value: 'style2', className: 'style2-class' }
-		];
-
-		it( 'should return proper styles for values', () => {
-			expect( getStyleByValue( 'style1', styles ) ).to.equal( styles[ 0 ] );
-			expect( getStyleByValue( 'style2', styles ) ).to.equal( styles[ 1 ] );
-		} );
-
-		it( 'should return undefined when style is not found', () => {
-			expect( getStyleByValue( 'foo', styles ) ).to.be.undefined;
-		} );
-
-		it( 'should return undefined when empty styles array is provided', () => {
-			expect( getStyleByValue( 'style1', [] ) ).to.be.undefined;
-		} );
-	} );
-} );

+ 21 - 1
packages/ckeditor5-image/tests/utils.js

@@ -4,7 +4,8 @@
  */
 
 import ViewElement from 'ckeditor5-engine/src/view/element';
-import { toImageWidget, isImageWidget } from 'ckeditor5-image/src/utils';
+import ModelElement from 'ckeditor5-engine/src/model/element';
+import { toImageWidget, isImageWidget, isImage } from 'ckeditor5-image/src/utils';
 import { isWidget } from 'ckeditor5-image/src/widget/utils';
 
 describe( 'image widget utils', () => {
@@ -30,4 +31,23 @@ describe( 'image widget utils', () => {
 			expect( isImageWidget( new ViewElement( 'p' ) ) ).to.be.false;
 		} );
 	} );
+
+	describe( 'isImage', () => {
+		it( 'should return true for image element', () => {
+			const image = new ModelElement( 'image' );
+
+			expect( isImage( image ) ).to.be.true;
+		} );
+
+		it( 'should return true false for different elements', () => {
+			const image = new ModelElement( 'foo' );
+
+			expect( isImage( image ) ).to.be.false;
+		} );
+
+		it( 'should return true false for null and undefined', () => {
+			expect( isImage( null ) ).to.be.false;
+			expect( isImage( undefined ) ).to.be.false;
+		} );
+	} );
 } );