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

Extracted nested editable styles and logic to widgets. #74

Merged
merged 8 commits into from
Mar 28, 2017
Merged

Conversation

szymonkups
Copy link
Contributor

@szymonkups szymonkups commented Mar 17, 2017

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 to toWidget.

@szymonkups szymonkups requested a review from Reinmar March 17, 2017 14:39
* @param {module:engine/view/document~Document} viewDocument
* @returns {module:engine/view/editableelement~EditableElement}
*/
export function createNestedEditable( elementName, viewDocument ) {
Copy link
Member

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().


editable.on( 'change:isFocused', ( evt, property, is ) => {
if ( is ) {
editable.addClass( 'focused' );
Copy link
Member

Choose a reason for hiding this comment

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

…ilar parameter as toWidget function. Small docs fixes.
Copy link
Member

@oleq oleq left a 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' );
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 ) => {
Copy link
Member

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 );

Copy link
Member

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.


.ck-widget.image {
figcaption {
figcaption.ck-editable {
Copy link
Member

@oleq oleq Mar 27, 2017

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?

@import '~@ckeditor/ckeditor5-theme-lark/theme/helpers/_states.scss';

.ck-widget {
margin: 10px 0;
Copy link
Member

Choose a reason for hiding this comment

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

padding: 0;

&.ck-widget_selected, &.ck-widget_selected:hover {
outline: 2px solid #ace;
Copy link
Member

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.

}

&:hover {
outline: 2px solid yellow;
Copy link
Member

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.

}

.ck-editable {
// The `:focus` styles is applied before `.focused` class inside editables.
Copy link
Member

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".

.ck-editable {
// The `:focus` styles is applied before `.focused` class inside editables.
// These styles show different border for a blink of an eye.
&:focus {
Copy link
Member

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?

Copy link
Contributor Author

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' );
	}
}


.ck-widget.image {
figcaption {
figcaption.ck-editable {
background-color: ck-color( 'foreground' );
padding: 10px;
Copy link
Member

Choose a reason for hiding this comment

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

ck-spacing()


.ck-widget.image {
figcaption {
figcaption.ck-editable {
background-color: ck-color( 'foreground' );
padding: 10px;
font-size: .8em;
Copy link
Member

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.

@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 {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@Reinmar Reinmar Mar 28, 2017

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?

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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


&:hover {
outline: $widget-outline-thickness solid ck-color( 'widget-hover' );
}
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😭

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested editables must have their classes
3 participants