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

T/16 Introduce DataTransfer#files property, change the clipboardInput event and add the inputTranformation event #17

Merged
merged 18 commits into from
Apr 12, 2017

Conversation

ma2ciek
Copy link
Contributor

@ma2ciek ma2ciek commented Apr 7, 2017

Suggested merge commit message (convention)

Feature: Introduced DataTransfer#files property. Changed the clipboardInput event and added the inputTranformation event. Closes ckeditor/ckeditor5#2656.

src/clipboard.js Outdated
@@ -95,7 +95,7 @@ export default class Clipboard extends Plugin {
* @inheritDoc
*/
static get pluginName() {
return 'clipboard/clipboard';
Copy link
Contributor Author

@ma2ciek ma2ciek Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Reinmar Not sure whether this should be a clipboard or clipboard/clipboard

Copy link
Member

@Reinmar Reinmar Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the documentation of Plugin.pluginName. It should be clipboard/clipboard – one is the package name (meaningful part of it) and the other is the module inside it.

@pjasiun
Copy link

pjasiun commented Apr 11, 2017

Note that this PR also introduced "files" in the dataTransfer object. It should be mentioned in the commit message.

@pjasiun
Copy link

pjasiun commented Apr 11, 2017

Also the files property miss documentation.

src/clipboard.js Outdated
@@ -179,34 +191,28 @@ export default class Clipboard extends Plugin {
}

/**
* Fired with a content which comes from the clipboard (was pasted or dropped) and
* Fired with a `dataTransfer`, which comes from the clipboard (was pasted or dropped) and
* should be processed in order to be inserted into the editor.
* It's part of the {@link module:clipboard/clipboard~Clipboard "clipboard pipeline"}.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is observers event now. Docs should be moved to the clipboard observer.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Apr 11, 2017

Note that this PR also introduced "files" in the dataTransfer object. It should be mentioned in the commit message.

Fixed.

Added some docs improvements.

@ma2ciek ma2ciek changed the title T/16 Split the clipboardInput event into the input and inputTranformation events T/16 Introduce DataTransfer#files property and split the clipboardInput event into the input and inputTranformation events Apr 11, 2017
@Reinmar
Copy link
Member

Reinmar commented Apr 11, 2017

You know guys that the #files prop makes for a perfect separate PR? ;) But ok... I'll review both things.

// Prevent page refreshing.
data.preventDefault();

doc.fire( 'input', { dataTransfer: data.dataTransfer } );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event is really confusing. There's a nativeinput event. So this one would need to be called clipboardInput. Is it ok?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine for me.

doc.on( 'drop', _handleInput, { priority: 'low' } );

function _handleInput( evt, data ) {
// Prevent page refreshing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true. This line doesn't prevent page refreshing. It prevents the default action (which only in case of file dropping can be page reload). No reason to comment it.

doc.on( 'paste', _handleInput, { priority: 'low' } );
doc.on( 'drop', _handleInput, { priority: 'low' } );

function _handleInput( evt, data ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to prefix this function name with _.

this.domEventType = [ 'paste', 'copy', 'cut' ];
this.domEventType = [ 'paste', 'copy', 'cut', 'drop' ];

doc.on( 'paste', _handleInput, { priority: 'low' } );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsafe and incorrect. this.listenTo() should be used. Those listeners should be gone together with the observer.

@@ -42,4 +50,26 @@ export default class DataTransfer {
setData( type, data ) {
this._native.setData( type, data );
}

*_getFiles() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this function a generator if above we do Array.from() anyway? It doesn't make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, it needs at least minimal docs. Or even better – move it out of the prototype as it doesn't make sense here (unless for testing purposes, but then document this too).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because of the historical reasons. There were no files at the very beginning because there are some performance problems with reading files handlers, but then I realized that you need to get files handlers anyway to check if there are files, so the property was created. That's true that there is not a reason to keep it as a generator.

if ( files.length ) {
yield* files;
}
// // Chrome have empty DataTransfer.files, but let get files through the items interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubled //.

}
}

get types() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be before methods and public stuff must be before protected and private stuff. Plus, it misses docs.

/**
* The array of files created from the native `DataTransfer#files` and `DataTransfer#items` objects.
*
* @public
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also @readonly.

@@ -19,6 +19,14 @@ export default class DataTransfer {
* @member {DataTransfer} #_native
*/
this._native = nativeDataTransfer;

/**
* The array of files created from the native `DataTransfer#files` and `DataTransfer#items` objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing – it indicates that #files is a combination of these two native properties while it's either one or another.

src/clipboard.js Outdated
* this.listenTo( editor.editing.view, 'input', ( evt, data ) => {
* const content = customTransform( data.dataTransfer.get( 'text/html' ) );
* const transformedContent = transform( content );
* data.dataTransfer.set( 'text/html', transformedContent );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

@@ -50,7 +64,7 @@ import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/html
* At this stage the pasted content can be processed by the features. E.g. a feature which wants to transform
* a pasted text into a link can be implemented in this way:
*
* this.listenTo( editor.editing.view, 'clipboardInput', ( evt, data ) => {
* this.listenTo( editor.plugins.get( 'clipboard/clipboard' ), 'inputTransformation', ( evt, data ) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I'm not sure that it makes sense to showcase this method of retrieving a plugin. It may not be loaded and such code would break. OTOH, showing the right way would make this code unnecessarily long, so perhaps we can leave this.

@Reinmar
Copy link
Member

Reinmar commented Apr 11, 2017

R- for now. I haven't checked all but the rest should be cosmetics.

@ma2ciek ma2ciek changed the title T/16 Introduce DataTransfer#files property and split the clipboardInput event into the input and inputTranformation events T/16 Introduce DataTransfer#files property and split the clipboardInput event into the clipboardInput and inputTranformation events Apr 11, 2017
@ma2ciek ma2ciek changed the title T/16 Introduce DataTransfer#files property and split the clipboardInput event into the clipboardInput and inputTranformation events T/16 Introduce DataTransfer#files property, change the clipboardInput event and add the inputTranformation event Apr 11, 2017
@ma2ciek
Copy link
Contributor Author

ma2ciek commented Apr 11, 2017

It's ready for the review once again.

@pjasiun pjasiun merged commit 16e8e2a into master Apr 12, 2017
@pjasiun pjasiun deleted the t/16 branch April 12, 2017 12:38
pjasiun pushed a commit that referenced this pull request Apr 12, 2017
Feature: Introduced DataTransfer#files property. Change the clipboard input pipeline. Closes #16.

BREAKING CHANGE: The `clipboardInput` event now contains only `DataTransfer`, no `content` there anymore. The separate `inputTransformation` event was introduced for the content transformations.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants