8
0
Maciej Bukowski 8 лет назад
Родитель
Сommit
b492d9cac2

+ 1 - 1
packages/ckeditor5-clipboard/src/clipboard.js

@@ -51,7 +51,7 @@ import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/html
  *		this.listenTo( editor.editing.view, 'clipboardInput', ( evt, data ) => {
  *			const content = customTransform( data.dataTransfer.get( 'text/html' ) );
  *			const transformedContent = transform( content );
- * 			data.dataTransfer.set( 'text/html', transformedContent );
+ *			data.dataTransfer.set( 'text/html', transformedContent );
  *		} );
  *
  * ### On {@link module:clipboard/clipboard~Clipboard#event:inputTransformation}

+ 27 - 26
packages/ckeditor5-clipboard/src/datatransfer.js

@@ -12,6 +12,14 @@
  */
 export default class DataTransfer {
 	constructor( nativeDataTransfer ) {
+		/**
+		 * The array of files created from the native `DataTransfer#files` or `DataTransfer#items`.
+		 *
+		 * @readonly
+		 * @member {Array.<File>} #files
+		 */
+		this.files = getFiles( nativeDataTransfer );
+
 		/**
 		 * The native DataTransfer object.
 		 *
@@ -19,14 +27,15 @@ export default class DataTransfer {
 		 * @member {DataTransfer} #_native
 		 */
 		this._native = nativeDataTransfer;
+	}
 
-		/**
-		 * The array of files created from the native `DataTransfer#files` and `DataTransfer#items` objects.
-		 *
-		 * @public
-		 * @member {Array.<File>} #files
-		 */
-		this.files = Array.from( this._getFiles() );
+	/**
+	 * Returns an array of available native content types.
+	 *
+	 * @returns {Array.<String>}
+	 */
+	get types() {
+		return this._native.types;
 	}
 
 	/**
@@ -50,26 +59,18 @@ export default class DataTransfer {
 	setData( type, data ) {
 		this._native.setData( type, data );
 	}
+}
 
-	*_getFiles() {
-		// DataTransfer.files and items are Array-like and might not have an iterable interface.
-		const files = this._native.files ? Array.from( this._native.files ) : [];
-		const items = this._native.items ? Array.from( this._native.items ) : [];
-
-		if ( files.length ) {
-			yield* files;
-		}
-		// // Chrome have empty DataTransfer.files, but let get files through the items interface.
-		else {
-			for ( const item of items ) {
-				if ( item.kind == 'file' ) {
-					yield item.getAsFile();
-				}
-			}
-		}
-	}
+function getFiles( nativeDataTransfer ) {
+	// DataTransfer.files and items are Array-like and might not have an iterable interface.
+	const files = nativeDataTransfer.files ? Array.from( nativeDataTransfer.files ) : [];
+	const items = nativeDataTransfer.items ? Array.from( nativeDataTransfer.items ) : [];
 
-	get types() {
-		return this._native.types;
+	if ( files.length ) {
+		return files;
 	}
+	// Chrome have empty DataTransfer.files, but let get files through the items interface.
+	return items
+		.filter( item => item.kind === 'file' )
+		.map( item => item.getAsFile() );
 }