Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #55 from ckeditor/t/54
Browse files Browse the repository at this point in the history
Other: The `inputTransformation` event is now emitted additionally with `dataTransfer` object. Closes #54 .
  • Loading branch information
scofalik authored Sep 13, 2018
2 parents 0d239eb + 766ee7f commit f3589b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export default class Clipboard extends Plugin {

content = this._htmlDataProcessor.toView( content );

this.fire( 'inputTransformation', { content } );
this.fire( 'inputTransformation', { content, dataTransfer } );

view.scrollToTheSelection();
}, { priority: 'low' } );
Expand Down Expand Up @@ -253,8 +253,9 @@ export default class Clipboard extends Plugin {
}

/**
* Fired with a `content`, which comes from the clipboard (was pasted or dropped) and
* should be processed in order to be inserted into the editor.
* Fired with a `content` and `dataTransfer` objects. The `content` which comes from the clipboard (was pasted or dropped)
* should be processed in order to be inserted into the editor. The `dataTransfer` object is available
* in case the transformation functions needs access to a raw clipboard data.
* It's part of the {@link module:clipboard/clipboard~Clipboard "clipboard pipeline"}.
*
* @see module:clipboard/clipboardobserver~ClipboardObserver
Expand All @@ -263,6 +264,7 @@ export default class Clipboard extends Plugin {
* @param {Object} data Event data.
* @param {module:engine/view/documentfragment~DocumentFragment} data.content Event data. Content to be inserted into the editor.
* It can be modified by the event listeners. Read more about the clipboard pipelines in {@link module:clipboard/clipboard~Clipboard}
* @param {module:clipboard/datatransfer~DataTransfer} data.dataTransfer Data transfer instance.
*/

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe( 'Clipboard feature', () => {

clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
expect( data.content ).is.instanceOf( ViewDocumentFragment );
expect( data.dataTransfer ).to.equal( dataTransferMock );
expect( stringifyView( data.content ) ).to.equal( '<p>x</p>' );

done();
Expand Down Expand Up @@ -109,6 +110,7 @@ describe( 'Clipboard feature', () => {

clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
expect( data.content ).is.instanceOf( ViewDocumentFragment );
expect( data.dataTransfer ).to.equal( dataTransferMock );
expect( stringifyView( data.content ) ).to.equal( '<p>x</p><p>y z</p>' );

done();
Expand Down Expand Up @@ -136,6 +138,7 @@ describe( 'Clipboard feature', () => {

clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
expect( data.content ).is.instanceOf( ViewDocumentFragment );
expect( data.dataTransfer ).to.equal( dataTransferMock );
expect( stringifyView( data.content ) ).to.equal( '' );

expect( editorViewCalled.calledOnce ).to.be.true;
Expand Down

0 comments on commit f3589b4

Please sign in to comment.