Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pastefromwordimage plugin to pastefromword #1214

Merged
merged 15 commits into from
Nov 27, 2017
Merged

Merge pastefromwordimage plugin to pastefromword #1214

merged 15 commits into from
Nov 27, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Nov 23, 2017

What is the purpose of this pull request?

Other, please explain
Code refactoring - Merge pastefromwordimage plugin to pastefromword

Does your PR contain necessary tests?

There remain all old tests. No new feature or bug fixes was added.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • move paste from word image plugin into paste from word
  • move tests related to this feature
  • add configuration option to disable pasting images from word

This is a subtask of #662

// Paste From Word Image:
// RTF clipboard is required for embeding images.
if ( CKEDITOR.plugins.clipboard.isCustomDataTypesSupported && configInlineImages ) {
editor.filter.allow( 'img[src]' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually in this case we don't want to force adding img to the allowed content list.

Instead we can do a bit more clever thing, and detect whether images are allowed. If not there's also no point in doing this logic. For example:

editor.filter.check( 'img[src]' )

Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

Maybe it's late and I'm missing something obvious, but the solutino does not work for me.

Sample case:

  1. Open pastewordwithimage manual test.
  2. Open any docx that has images in Microsoft Word.
  3. Select all & copy.
  4. Go back to the manual test.
  5. Focus editor.
  6. Empty the contents.
  7. Paste.

Expected

Images being inlined.

Actual

Images with file:// protocol are pasted.

Additional notes

I can see two main reasons to that:

And I'm wondering if that's the case, why no unit test is failing?

@@ -38,7 +38,7 @@
* @private
* @member CKEDITOR.plugins
*/
CKEDITOR.plugins.pastefromword = {};
CKEDITOR.plugins.pastefromword = CKEDITOR.plugins.pastefromword || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason for this reinitializaiton.

This file is meant to be loaded once, thus it's ok to start with an empty object.

Edit: now I know, see my comment in plugin.js file. 🙂

@@ -128,6 +135,117 @@

return !isLoaded;
}

function pasteFromWordImageListener( evt ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You did a good encapsulation of this logic, however this logic should go to the filter/default.js file.

And now I guess I know why you wanted to reuse the namespace 🙂.

There are several points to make this logic file a separate one:

  • It reduces the editor size, as it's loaded only on demand, when PFW is truly used.
  • It allows to customize it, and provide a custom implementation, as long as the interface is the same.

With that in mind, image inlining is an implementation detail and should be placed in the filter file.

/**
* Flag decides wheather emebeding images pasted with Word content is enabled or not.
*
* **Note:** Please be aware that emebeding images requires apropriate clipboard access in users' browser.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea about this notice. However we could make it a bit more precise, saying that it requires Clipboard API available only in modern browsers.

We could link to CKEDITOR.plugins.clipboard.isCustomDataTypesSupported property, as this is the information that determines that.

@@ -161,6 +279,16 @@
* @member CKEDITOR.config
*/

/**
* Flag decides wheather emebeding images pasted with Word content is enabled or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you check other places in our API docs we usually put an example how the config could be changed to a behavior opposite to the default.

Please add a code listing showing how this var could be set to false.

Copy link
Contributor

Choose a reason for hiding this comment

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

This markup doesn't render well:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you have provided a link to isCustomDataTypesSupported property, that's great - but you did that without any context, just put some words what it's all about.

@@ -0,0 +1,39 @@
/* bender-tags: clipboard,pastefromword */
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, rename file to lowercased pfw_image, actually... pfw prefix doesn't have much use here. After all it's a directory for pfw so only its tests are here. 🙂 So how about just image?

@@ -0,0 +1,39 @@
/* bender-tags: clipboard,pastefromword */
/* bender-ckeditor-plugins: pastefromword,ajax,basicstyles,bidi,font,link,toolbar,colorbutton,image */
/* bender-ckeditor-plugins: list,liststyle,sourcearea,format,justify,table,tableresize,tabletools,indent,indentblock,div,dialog */
Copy link
Contributor

Choose a reason for hiding this comment

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

I think many of this plugins could be safely removed. Could we do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reduced it, but few of them still remain.

@msamsel
Copy link
Contributor Author

msamsel commented Nov 24, 2017

I wasn't able to easily embed entire logic inside filter. It cause too many test errors. I'll extract it along with other stuff to refactoring ticket.

Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

Generally the code works well. There are just a few improvements we should make to the structure, and we're good to go.

@@ -161,6 +279,16 @@
* @member CKEDITOR.config
*/

/**
* Flag decides wheather emebeding images pasted with Word content is enabled or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

This markup doesn't render well:

image

@@ -161,6 +279,16 @@
* @member CKEDITOR.config
*/

/**
* Flag decides wheather emebeding images pasted with Word content is enabled or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you have provided a link to isCustomDataTypesSupported property, that's great - but you did that without any context, just put some words what it's all about.

editor.on( 'afterPasteFromWord', pasteFromWordImageListener );
}

function pasteFromWordImageListener( evt ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we simplify it to imagePastingListener?

* @returns {String} return.hex Hexadecimal string of an image embedded in `rtfContent`.
* @returns {String} return.type String represent type of image, allowed values: 'image/png', 'image/jpeg'.
*/
extractImagesFromRtf: function( rtfContent ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to avoid putting this logic at the very beginning of PFW filter file.

This part is not as important to expose it here. Instead I would suggest enclosing it in a dedicated namespace, like CKEDITOR.plugins.pastefromword.images and it could contain:

  • extractImagesFromRtf actually renamed to extractFromRtf.
  • extractImgTagsFromHtml actually renamed to extractTagsFromHtml.

Then move it a bit to the bottom of a file.

@mlewand mlewand self-requested a review November 24, 2017 21:48
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

Sorry pressed a wrong review result.

@msamsel msamsel requested a review from mlewand November 27, 2017 08:45
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

LGTM

@mlewand mlewand merged commit 5ee8d24 into t/662 Nov 27, 2017
mlewand added a commit that referenced this pull request Nov 27, 2017
Merge pastefromwordimage plugin to pastefromword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants