-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
plugins/pastefromword/plugin.js
Outdated
// Paste From Word Image: | ||
// RTF clipboard is required for embeding images. | ||
if ( CKEDITOR.plugins.clipboard.isCustomDataTypesSupported && configInlineImages ) { | ||
editor.filter.allow( 'img[src]' ); |
There was a problem hiding this comment.
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]' )
There was a problem hiding this 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:
- Open pastewordwithimage manual test.
- Open any docx that has images in Microsoft Word.
- Select all & copy.
- Go back to the manual test.
- Focus editor.
- Empty the contents.
- Paste.
Expected
Images being inlined.
Actual
Images with file://
protocol are pasted.
Additional notes
I can see two main reasons to that:
- https://github.com/ckeditor/ckeditor-dev/blob/5b876ee/plugins/pastefromword/plugin.js#L67 - doesn't seem to work when called
getNative=true
. If you call it just asdata.dataTransfer.getData( 'text/rtf' ) : null,
it seems to work fine. - https://github.com/ckeditor/ckeditor-dev/blob/5b876ee/plugins/pastefromword/plugin.js#L117 -
editor.filter.check( 'img[src]' )
is executed too early. Not all plugins are registered at that time, meaning not every ACF rule is already signed in. We should check it later, or simply each time at a runtime.
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 || {}; |
There was a problem hiding this comment.
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. 🙂
plugins/pastefromword/plugin.js
Outdated
@@ -128,6 +135,117 @@ | |||
|
|||
return !isLoaded; | |||
} | |||
|
|||
function pasteFromWordImageListener( evt ) { |
There was a problem hiding this comment.
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.
plugins/pastefromword/plugin.js
Outdated
/** | ||
* 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. |
There was a problem hiding this comment.
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.
plugins/pastefromword/plugin.js
Outdated
@@ -161,6 +279,16 @@ | |||
* @member CKEDITOR.config | |||
*/ | |||
|
|||
/** | |||
* Flag decides wheather emebeding images pasted with Word content is enabled or not. |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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.
plugins/pastefromword/plugin.js
Outdated
@@ -161,6 +279,16 @@ | |||
* @member CKEDITOR.config | |||
*/ | |||
|
|||
/** | |||
* Flag decides wheather emebeding images pasted with Word content is enabled or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugins/pastefromword/plugin.js
Outdated
@@ -161,6 +279,16 @@ | |||
* @member CKEDITOR.config | |||
*/ | |||
|
|||
/** | |||
* Flag decides wheather emebeding images pasted with Word content is enabled or not. |
There was a problem hiding this comment.
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.
plugins/pastefromword/plugin.js
Outdated
editor.on( 'afterPasteFromWord', pasteFromWordImageListener ); | ||
} | ||
|
||
function pasteFromWordImageListener( evt ) { |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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 toextractFromRtf
.extractImgTagsFromHtml
actually renamed toextractTagsFromHtml
.
Then move it a bit to the bottom of a file.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merge pastefromwordimage plugin to pastefromword
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
What changes did you make?
paste from word image
plugin into paste from wordThis is a subtask of #662