8
0
Просмотр исходного кода

Split `clipboardInput` event into `input` and `clipboardInput`.

Piotr Jasiun 8 лет назад
Родитель
Сommit
0319f7c309

+ 3 - 5
packages/ckeditor5-clipboard/src/clipboard.js

@@ -111,7 +111,7 @@ export default class Clipboard extends Plugin {
 
 		// The clipboard paste pipeline.
 
-		this.listenTo( editingView, 'paste', ( evt, data ) => {
+		this.listenTo( editingView, 'input', ( evt, data ) => {
 			const dataTransfer = data.dataTransfer;
 			let content = '';
 
@@ -123,12 +123,10 @@ export default class Clipboard extends Plugin {
 
 			content = this._htmlDataProcessor.toView( content );
 
-			data.preventDefault();
-
-			editingView.fire( 'clipboardInput', { dataTransfer, content } );
+			editingView.fire( 'clipboardInputTransformation', { content } );
 		}, { priority: 'low' } );
 
-		this.listenTo( editingView, 'clipboardInput', ( evt, data ) => {
+		this.listenTo( editingView, 'clipboardInputTransformation', ( evt, data ) => {
 			if ( !data.content.isEmpty ) {
 				const dataController = this.editor.data;
 

+ 10 - 0
packages/ckeditor5-clipboard/src/clipboardobserver.js

@@ -23,6 +23,16 @@ export default class ClipboardObserver extends DomEventObserver {
 		super( doc );
 
 		this.domEventType = [ 'paste', 'copy', 'cut', 'drop' ];
+
+		this.document.on( 'paste', _handleInput, { priority: 'low' } );
+		this.document.on( 'drop', _handleInput, { priority: 'low' } );
+
+		function _handleInput( evt, data ) {
+			// Prevent page refreshing.
+			data.preventDefault();
+
+			this.document.fire( 'input', { data: data.dataTransfer } );
+		}
 	}
 
 	onDomEvent( domEvent ) {

+ 4 - 2
packages/ckeditor5-clipboard/src/datatransfer.js

@@ -19,6 +19,8 @@ export default class DataTransfer {
 		 * @member {DataTransfer} #_native
 		 */
 		this._native = nativeDataTransfer;
+
+		this.files = Array.from( this.getFiles() );
 	}
 
 	/**
@@ -43,7 +45,7 @@ export default class DataTransfer {
 		this._native.setData( type, data );
 	}
 
-	*getFiles() {
+	*_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 ) : [];
@@ -61,7 +63,7 @@ export default class DataTransfer {
 		}
 	}
 
-	getTypes() {
+	get types() {
 		return this._native.types;
 	}
 }