-
Notifications
You must be signed in to change notification settings - Fork 37
Extracted nested editable styles and logic to widgets. #74
Conversation
src/widget/utils.js
Outdated
* @param {module:engine/view/document~Document} viewDocument | ||
* @returns {module:engine/view/editableelement~EditableElement} | ||
*/ | ||
export function createNestedEditable( elementName, viewDocument ) { |
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 would be more consistent with widgetize()
if it accepted an element.
BTW, it'd be hard to follow "widgetize"'s namig style in this case, so perhaps we could use these names: toWidget()
and toWidgetEditable()
.
src/widget/utils.js
Outdated
|
||
editable.on( 'change:isFocused', ( evt, property, is ) => { | ||
if ( is ) { | ||
editable.addClass( 'focused' ); |
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.
Should be: ck-editable_focused
.
See https://github.com/ckeditor/ckeditor5-design/wiki/Code-Style-Naming-Guidelines#css-classes
…ilar parameter as toWidget function. Small docs fixes.
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.
Look fine but requires some improvements in styles.
* @returns {module:engine/view/editableelement~EditableElement} Returns same element that was provided in `editable` param. | ||
*/ | ||
export function toWidgetEditable( editable ) { | ||
editable.setAttribute( 'contenteditable', 'true' ); |
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 and the following line should be done via Template.apply()
. One of the reasons we decided to have a Template
class was that DOM attrs should be touched via unified API.
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.
That's not true. This isn't UI. This is the engine and the element here isn't a native DOM element. We've been talking about unifying the APIs, but that never happened and I guess won't happen anytime soon.
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.
Nice catch! I didn't notice that this isn't DOM. You're right, ofc ;-)
editable.setAttribute( 'contenteditable', 'true' ); | ||
editable.addClass( 'ck-editable' ); | ||
|
||
editable.on( 'change:isFocused', ( evt, property, is ) => { |
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.
new Template( {
attributes: {
contenteditable: true,
class: [
'ck-editable',
bind.if( editable, 'isFocused', 'ck-editable_focused' )
]
}
} ).apply( editable );
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.
As above – nope. This is not a native element.
theme/imagecaption/theme.scss
Outdated
|
||
.ck-widget.image { | ||
figcaption { | ||
figcaption.ck-editable { |
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.
Does figcaption
selector is really needed? Wouldn't .ck-editable
be specific enough?
theme/widget/theme.scss
Outdated
@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_states.scss'; | ||
|
||
.ck-widget { | ||
margin: 10px 0; |
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 that https://github.com/ckeditor/ckeditor5-theme-lark/blob/master/theme/helpers/_spacing.scss#L32-L34 would make more sense.
theme/widget/theme.scss
Outdated
padding: 0; | ||
|
||
&.ck-widget_selected, &.ck-widget_selected:hover { | ||
outline: 2px solid #ace; |
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.
These colors #ace
, #ddd
and yellow
should be variables. Or better, they should come from https://github.com/ckeditor/ckeditor5-theme-lark/blob/master/theme/helpers/_colors.scss#L21-L27. Or even better, the widgets could extend the standard palette. We've never used it before, but it could still work:
@include ck-color-add( (
'widget-selected': #ace, //
'widget-blurred': #ddd
) );
then
outline: 2px solid ck-color( 'widget-selected' );
BTW: We have focus
color, which I think makes more sense than #ace
.
theme/widget/theme.scss
Outdated
} | ||
|
||
&:hover { | ||
outline: 2px solid yellow; |
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.
2px
is a magic number. This should be a variable on the top of the file. Also: see above.
theme/widget/theme.scss
Outdated
} | ||
|
||
.ck-editable { | ||
// The `:focus` styles is applied before `.focused` class inside editables. |
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.
Outdated docs (.focused
?).
Also "styles is" vs. "styles are".
theme/widget/theme.scss
Outdated
.ck-editable { | ||
// The `:focus` styles is applied before `.focused` class inside editables. | ||
// These styles show different border for a blink of an eye. | ||
&:focus { |
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.
Despite the comment, I don't quite get why we need this structure :focus ..._focused
. A few more words would explain it better. Or do we need it at all?
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 can be simplified to:
.ck-editable {
&.ck-editable_focused, &:focus {
@include ck-focus-ring( 'outline' );
@include ck-box-shadow( $ck-inner-shadow );
background-color: ck-color( 'background' );
}
}
theme/imagecaption/theme.scss
Outdated
|
||
.ck-widget.image { | ||
figcaption { | ||
figcaption.ck-editable { | ||
background-color: ck-color( 'foreground' ); | ||
padding: 10px; |
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.
ck-spacing()
theme/imagecaption/theme.scss
Outdated
|
||
.ck-widget.image { | ||
figcaption { | ||
figcaption.ck-editable { | ||
background-color: ck-color( 'foreground' ); | ||
padding: 10px; | ||
font-size: .8em; |
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.
ck-font-size( -1 )
I guess.
theme/imagecaption/theme.scss
Outdated
@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_shadow.scss'; | ||
@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_states.scss'; | ||
@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_spacing.scss'; | ||
@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_fonts.scss'; | ||
|
||
.ck-widget.image { |
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'd be better if these styles had nothing to do with the widget classes. The widgets theme use widget classes (and hence applies to the editor only) and the image theme uses image classes.
Actually, this is a bigger topic. For the widgets we're defining styles which will apply in a context of the editor cause we use editor classes like .ck-widget
. For the content (like figure.image
) we want to provide generic content styles like in the CKEditor 4's contents.css
. So, they need to be overrideable but still so specific to apply to editor contents only, not the whole page.
The only idea I've got now is to prefix all of them with .ck-editor__editable
. WDYT, @oleq?
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.
Isn't .ck-editor .image
enough? Because I think it is and it's a better DX because devs don't need to think what is "editable" and why. All they want is a styled image in the CKEditor.
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 .ck-editor
applied in the inline editor? It'd be best if the class was as short as possible, but I think it can't be .ck-editor
.
If we would like to use something shorter than .ck-editor__editable
, then perhaps we can start using an additional class .ck-content
for the editables?
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 .ck-editor applied in the inline editor?
No. A good point. Let's proceed with .ck-editor__editable
then.
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 it for the future: https://github.com/ckeditor/ckeditor5-ui/issues/176.
|
||
&:hover { | ||
outline: $widget-outline-thickness solid ck-color( 'widget-hover' ); | ||
} |
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.
Something's wrong here... Indentation! :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.
😭
Suggested merge commit message (convention)
Fix: Nested editables have own CSS classes and their creation utility is extracted to widgets. Closes ckeditor/ckeditor5#5067.
BREAKING CHANGE: Widget utility function
widgetize
is renamed totoWidget
.