-
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
Styles system for Easy Image #1518
Conversation
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 just checked docs, and test briefly, there are a few things that needs to be addressed before I proceed with review further.
File names for icons got long and tricky, there's easyimagealigncenter.png
, easyimagealignleft.png
and easyimagealignright.png
. Since we already have easyimageside.png
, how about making it a easyimagecenter.png
(skip "align" part)? Simpler and more consistent.
@bender-ckeditor-plugins: sourcearea, wysiwygarea, floatingspace, toolbar, easyimage | ||
|
||
1. Click on image widget. | ||
2. Click on one of button in balloon toolbar. **Note:** first style is a totally custom one, therefore it does not have any icon. |
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.
(…) one of buttons in the toolbar. (…)
<p>Armstrong spent about <s>three and a half</s> two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5 kg) of lunar material for return to Earth. A third member of the mission, <a href="http://en.wikipedia.org/wiki/Michael_Collins_(astronaut)">Michael Collins</a>, piloted the <a href="http://en.wikipedia.org/wiki/Apollo_Command/Service_Module">command</a> spacecraft alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.</p> | ||
</div> | ||
|
||
<h2>Inline editor</h2> |
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's no source button in the inline editor, so let's skip it and leave just divarea
.
@@ -0,0 +1,53 @@ | |||
<h2>Classic editor</h2> | |||
<div id="classic"> | |||
<p><strong>Apollo 11</strong> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p> |
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.
Do we actually need all the wrapping text? It's a lot of it. Try to reduce it.
@@ -0,0 +1,43 @@ | |||
<h2>Classic editor</h2> | |||
<div id="classic"> | |||
<p><strong>Apollo 11</strong> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p> |
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.
Do we actually need all the wrapping text? It's a lot of it. Try to reduce it.
@@ -0,0 +1,13 @@ | |||
@bender-tags: 4.9.0, feature, 932 | |||
@bender-ui: collapsed | |||
@bender-ckeditor-plugins: sourcearea, wysiwygarea, floatingspace, toolbar, easyimage |
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.
No need for sourcearea plugin here.
@@ -43,6 +46,15 @@ The outline is not a part of the element's dimensions, we have to use a border a | |||
max-width: 25%; |
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.
Actually I find this entire block now very, very little readable. I think it would be better idea to split it into 3 groups (left, right, center). Even if it would cost us repeating max-width
/ float
I feel that would be more readable.
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've limit center styles to 90% (just to differentiate them from full
styles).
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.
Sounds like a good idea 👍
plugins/easyimage/plugin.js
Outdated
* style would produce `EasyimageLeft` button and `easyimageLeft` command. | ||
* | ||
* @since 4.9.0 | ||
* @cfg {Object<string,Object>} easyimage_styles |
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.
We use uppercased String
in docs.
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.
The proper format would be Object.<foo, bar>
(note the dot and space.
plugins/easyimage/plugin.js
Outdated
* * `icon` - path to the icon used in the balloon toolbar, | ||
* * `iconHiDpi` - path to the high DPI version of the icon. | ||
* | ||
* config.easyimage_styles = { |
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.
Reported as ckeditor/jsduck#8. I've mitigated it by moving note "Every style added […]" directly under the list.
attributes: { | ||
'class': 'test' | ||
}, | ||
icon: 'test' |
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/easyimage/plugin.js
Outdated
* items to the context menu for Easy Image widget. | ||
* | ||
* @since 4.9.0 | ||
* @cfg {Array/String} [easyimage_toolbar=[ 'EasyimageFull', 'EasyimageSide', 'EasyimageAlt' ]] |
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.
It's expected to contain an array of strings, so accurate type hint is String[]/String
.
Also I have rebased this branch onto latest Easy Image feature branch in |
Aren't icons names tied with button names? In that case it won't work unless integration with custom button icons is merged. |
I've also rebased branch to newest |
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 solution looks to be good, but requires some polishing/simplifications before going live.
Please add a rogue case, where one adds a style like:
{
element: 'div',
attributes: {
'class': 'test'
},
label: 'Hacky style'
}
There should be assertion that element tag name has not changed. That will keep us safe form future regression assuming that widget<->style integration would have implemented handling for such styles.
plugins/easyimage/plugin.js
Outdated
* @cfg {String} [easyimage_alignLeftClass='easyimage-alignLeft'] | ||
* @member CKEDITOR.config | ||
*/ | ||
CKEDITOR.config.easyimage_alignLeftClass = 'easyimage-alignLeft'; |
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's not much benefit from exposing easyimage_*Class
members. Let's avoid redundancy, the proper way to configure that should be config.easyimage_styles
option. We should reflect it in example listing of config.easyimage_styles
.
Say you want to customize the class name for left align, then you should use:
config.easyimage_styles = {
alignLeft: {
attributes: {
'class': 'my-custom-left-align'
}
},
};
Note how I skipped label, button etc. It should be merged, thus the default should apply.
My brief testing shows that it already works that way, so that's cool.
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.
This is exactly what you have covered in "test override default styles" test, and that's the way how it should be done.
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've also dropped easyimage_full
and easyimage_side
classes, the only one left is the main class for the widget.
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.
Great! That's exactly what I've been looking for.
@@ -43,6 +46,15 @@ The outline is not a part of the element's dimensions, we have to use a border a | |||
max-width: 25%; |
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.
Sounds like a good idea 👍
plugins/easyimage/plugin.js
Outdated
|
||
editor._.easyImageToolbarContext = editor.balloonToolbars.create( { | ||
buttons: 'EasyimageFull,EasyimageSide,EasyimageAlt', | ||
buttons: buttons.join ? buttons.join( ',' ) : buttons, | ||
widgets: [ WIDGET_NAME ] | ||
} ); | ||
} | ||
|
||
function addMenuItems( editor ) { |
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 could we rename this function to something that mentions context menu? Because this is solely context menu integration thing.
plugins/easyimage/plugin.js
Outdated
@@ -10,12 +10,45 @@ | |||
WIDGET_NAME = 'easyimage'; | |||
|
|||
function addCommands( editor ) { |
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.
This function now has too much logic. Instead it would be a good idea for us to split it into two functions with a clear task/responsibility - addCommands
and addButtons
.
I guess that would require you to make defaultStyles
and editor.config.easyimage_styles
union in parent closure, and pass the merged object as a parameter to both of them.
plugins/easyimage/plugin.js
Outdated
iconHiDpi: style.iconHiDpi | ||
}; | ||
|
||
delete style.label; |
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.
Is this really needed? Will CKEDITOR.style
break if it gets definition with stray properties?
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 not this whole function is redundant.
plugins/easyimage/plugin.js
Outdated
@@ -30,105 +63,170 @@ | |||
}; | |||
} | |||
|
|||
function createCommand( exec, refreshCheck, forceSelectionCheck ) { | |||
function createButton( button ) { | |||
editor.ui.addButton( button.name, { |
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.
editor.ui.addButton
could be unavailable if something changes in the dependency tree. Just to be safe I'd prefer adding that to requires
list for this plugin.
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.
button
is already an explicit requirement for easyimage
.
max-width: 90%; | ||
} | ||
|
||
.cke_widget_wrapper_easyimage-alignRight, :not(.cke_widget_wrapper_easyimage):not(.cke_widget_wrapper_easyimage-alignRight) > .easyimage-alignRight { |
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 this particular selector could be joined to the .cke_widget_wrapper_easyimage-side, :not(.cke_widget_wrapper_easyimage):not(.cke_widget_wrapper_easyimage-side) > .easyimage-side
selector above.
plugins/easyimage/plugin.js
Outdated
* }, | ||
* label: 'Align left', | ||
* icon: '/foo/bar/icons/baz.png', | ||
* iconHidpi: '/foo/bar/icons/hidpi/baz.png' |
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.
It's iconHiDpi
(note letter casing).
plugins/easyimage/plugin.js
Outdated
/** | ||
* List of buttons to be displayed in a balloon toolbar for Easy Image widget. | ||
* If Context Menu plugin is enabled, this config variable will be used also to add | ||
* items to the context menu for Easy Image widget. |
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 add a code listing where it uses left / center / right align buttons.
plugins/easyimage/plugin.js
Outdated
} ); | ||
styleDefinition.type = 'widget'; | ||
styleDefinition.widget = 'easyimage'; | ||
styleDefinition.group = 'easyimage'; |
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.
What if we actually allowed to specify group? That would allow people to do these crazy border kind of things, without affecting the alignment.
So my thinking here is to make the group
default to 'easyimage'
if not defined, but preserve styleDefinition.group
if present.
That would be nice option for extensibility.
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.
With our current way of handling styles (buttons that allow only applying styles) such change will result in non-reversible styles. I'd leave it the way it is for now.
Make sense, let's leave it as it is now. |
I've also rebased branch onto the latest |
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 work with the tests.
I was missing a possibility to customize group for added styles. Played a bit and it works fine, which is a nice addition.
Also I was thinking if we could avoid data duplication (I'm thinking about _styles
member and style name being kept in widget.data). I gave it a try and it was possible to reuse CKEDITOR.styleCommand
which results with a single source of truth - reducing a risk of future mistakes by desyncing the two.
These were the biggest issues, other than that there were few minor things:
- Tests not being ignored on unsupported environments.
- No information in config docs about styles available by defalt.
Other than that code organization seemed to be fine.
I proposed changes in #1583.
That will help us smell some integration problems on other browsers if something goes wrong.
The only source of information about applied style is the widget element itself. Also widget is no longer defaulted to a full style. Thus few TCs are failing in tests/plugins/easyimage/uploadintegrations suite.
It is now configurable with the confg.easyimage_defaultStyle option.
…o that only one listener is added per editor for a better performance.
…if widget already has one.
…. Minor simplification for refresh commands.
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.
With recent changes all looks good.
Styles system for Easy Image
What is the purpose of this pull request?
New feature
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
Rewrite of whole commands system for EI, enabling to add custom styles. Additionaly existing commands (
easyimageFull
andeasyimageSide
) were moved into the new style system.