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

t/134: Various improvements to config.image.styles #140

Merged
merged 18 commits into from
Sep 21, 2017
Merged

t/134: Various improvements to config.image.styles #140

merged 18 commits into from
Sep 21, 2017

Conversation

oleq
Copy link
Member

@oleq oleq commented Sep 13, 2017

Suggested merge commit message (convention)

Feature: Allowed customization of default image styles. Defined formatting–oriented styles. Simplified config.image.styles syntax. Closes ckeditor/ckeditor5#5113. Closes ckeditor/ckeditor5#5114.

BREAKING CHANGE: From now on, the imageStyleFull uses object-full-width.svg icon.


Additional information

Requires:

Showcase in http://localhost:8125/ckeditor5-image/tests/manual/imagestyle.html.


Default config:

image: {
	styles: [ 'imageStyleFull', 'imageStyleSide' ]
}

Customizing just the icon and class in defaults:

image: {
	styles: [ 
		{ name: 'imageStyleFull', icon: 'left' }, 
		{ name: 'imageStyleSide', className: 'foo' } 
	]
}

Completely custom styles also benefit from translations and default icons:

image: {
	styles: [
		// This style's title will be translated, e.g. to german. It uses default right icon.
		{ name: 'foo', title: 'Full size image', icon: 'right', value: null, className: 'foo-class' },
		// This style does everything in a custom way.
		{ name: 'bar', title: 'bar', icon: '<svg>...</svg>', value: 'bar', className: 'bar-class' },
	]
}

@wwalc
Copy link
Member

wwalc commented Sep 14, 2017

Any chance the default CSS rules for imageStyleAlignLeft could play better by default with the content inside CKEditor? I used the default browser styles and rendered Classic Editor inside. I used blockquote and bulleted list and both look bad:

Align right (ok)

screen shot 2017-09-14 at 09 18 32

Align left (could be better)

screen shot 2017-09-14 at 09 18 41

Not sure if it's an issue with ckeditor5-image or related plugins responsible for blockquote/lists.
However anyone using these styles will face that problem so it would be nice to come with some solution.

@oleq
Copy link
Member Author

oleq commented Sep 14, 2017

For one thing, I could increase the default margin around the images.

Then there's the problem with lists and blockquotes that we faced recently. It boils down to overflow: hidden for <ol> and <blockquote> to enable block formatting. CKE4 is suffering because of that too (and the quote most of all):

image

@Reinmar
Copy link
Member

Reinmar commented Sep 14, 2017

I'm not sure how far we can go. We can increase margins – that's fine. But can we use overflow:hidden? That has, as we learnt, a pretty unclear effect. Developers may be confused by this.

OTOH, I'd love if the initial styling was perfect...

@oleq
Copy link
Member Author

oleq commented Sep 14, 2017

OTOH, I'd love if the initial styling was perfect...

I'm afraid there's nothing we can do. It's overflow, or nothing :/

image

image

There's a long discussion on this topic https://stackoverflow.com/questions/710158/why-do-my-list-item-bullets-overlap-floating-elements.

@Reinmar
Copy link
Member

Reinmar commented Sep 14, 2017

Hm... OK, seeing this I'm fine with overflow :D

@fredck
Copy link

fredck commented Sep 14, 2017

You mean fine, as long as the text of long paragraphs wrap around the image, right?

@wwalc
Copy link
Member

wwalc commented Sep 15, 2017

TL;DR:

I'd like to propose the following:

  • Increase the right margin for .ck-editor__editable .image.image-style-align-left
  • Apply overflow: hidden for blockquotes.

Reasoning below.


I guess there is no perfect solution. Thinking out loud: in terms of frequency of using semantic block structures I guess the order will be like:

  • paragraphs
  • headings
  • lists
  • ... long break ...
  • quotes

Paragraphs, headings

There is no issue to solve.

Lists

Bigger margin

.ck-editor__editable .image.image-style-align-left {margin-right: 2em}

screen shot 2017-09-15 at 10 30 33

Pros: the bullets are visible.
Pros: plays well with long lists.
Pros: the heading has better margin, IMO.

Overflow: hidden

screen shot 2017-09-15 at 10 30 11

Pros: the bullets are visible.
Cons: I don't like the significant difference between heading and lists margin.
Cons: in case of very long lists looks weird. Personally I create long lists quite often.

IMO: bigger margin wins

Quotes

No changes

screen shot 2017-09-15 at 10 41 51

Bigger margin (to solve issue with lists)

screen shot 2017-09-15 at 10 38 39

Overflow: hidden + bigger margin (to solve issue with lists)

screen shot 2017-09-15 at 10 38 23

Pros: in this case at least shorter quotes look okay. If someone wants to use longer quotes he will have to use either centered/full size image or align it to right, there is no better solution.

IMO: Overflow: hidden + bigger margin wins.

@Reinmar
Copy link
Member

Reinmar commented Sep 15, 2017

Agree. I didn't think that overflow:hidden will make long list indented on the entire height of them. This is bad for lists, but makes sense for quotes.

@wwalc
Copy link
Member

wwalc commented Sep 15, 2017

It looks like defining a completely custom style does not work, the className is not respected.

ClassicEditor
  .create( document.querySelector( '#editor' ), {
    image: {
      toolbar: [ 'imageTextAlternative', '|', 'imageStyleCustom', 'imageStyleAlignCenter', 'imageStyleAlignRight' ],

      styles: [
         // THIS ONE DOES NOT WORK
         { name: 'imageStyleCustom', icon: 'left', className: 'foo-class', title: 'Custom title' },
         'imageStyleAlignCenter',
         { name: 'imageStyleAlignRight', className: 'bar-class' }
      ]
    }
  })
.catch( error => {
  console.error( error );
} );

imageStyleCustom correctly shows up in the image toolbar, but the class is not applied. Note that overriding className for imageStyleAlignRight works.

@oleq
Copy link
Member Author

oleq commented Sep 15, 2017

@wwalc Does it show up in editor.plugins.get( ImageStyleEngine ).imageStyles (the class)?

@wwalc
Copy link
Member

wwalc commented Sep 15, 2017

@oleq I modified the manual test in http://localhost:8125/ckeditor5-image/tests/manual/imagestyle.html

ClassicEditor
	.create( document.querySelector( '#editor-semantic' ), {
		plugins: [
			ImageToolbar,
			EnterPlugin,
			TypingPlugin,
			ParagraphPlugin,
			HeadingPlugin,
			ImagePlugin,
			UndoPlugin,
			ClipboardPlugin,
			ImageStyle
		],
		toolbar: [ 'headings', 'undo', 'redo' ],
		image: {
			// You need to configure the image toolbar too, so it uses the new style buttons.
			toolbar: [ 'imageTextAlternative', '|', 'imageStyleCustom', 'imageStyleAlignCenter', 'imageStyleAlignRight' ],

			styles: [
				{ name: 'imageStyleCustom', icon: 'left', className: 'foo-class', title: 'Custom title' },
				'imageStyleAlignCenter',
				{ name: 'imageStyleAlignRight', className: 'bar-class' }
			]
		}
	} )
	.then( editor => {
		window.editorSemantic = editor;
	} )
	.catch( err => {
		console.error( err.stack );
	} );

With such test, in Firefox in the console I have the following results:

screen shot 2017-09-15 at 18 06 33

Note: I initially reproduced the same issue in a manually created classic build. So I can confirm it using both a build and a modified manual test.

@oleq
Copy link
Member Author

oleq commented Sep 19, 2017

@wwalc

{ name: 'imageStyleCustom', icon: 'left', className: 'foo-class', title: 'Custom title' },

does not work because it has no value defined. I'm wondering if we should log.warn in such case 🤔 Or at least make it clear in the documentation.

…better interaction with default list styles.
@oleq
Copy link
Member Author

oleq commented Sep 19, 2017

I increased the default image margins for better interaction with lists. An overflow for blockquote should be added in a followup in the ckeditor5-block-quote repository.

BTW, I found a funny bug in Chrome. Can you also reproduce it? I hope it's not CKEditor–specific.

kapture 2017-09-19 at 13 43 02

@wwalc
Copy link
Member

wwalc commented Sep 19, 2017

does not work because it has no value defined. I'm wondering if we should log.warn in such case 🤔 Or at least make it clear in the documentation.

Doh. It's fine. I have no idea why I missed the value property. I must have copied something that did not contain value defined at all.

BTW. Wouldn't it be more intuitive is the default value was set to whatever the className is set? Or to something like class-className? After all when defining styles I wouldn't care most of the time about some internal model attribute. Also isn't there a chance that when asking users to define manually such thing they may break something else (e.g. using title, alt or whatever as a value)?

@oleq
Copy link
Member Author

oleq commented Sep 19, 2017

TBH, I also find it a little bit confusing that the value must always be provided as a null|String.

Do you remember why we decided to go this way, @szymonkups? Can we do anything about this?

@szymonkups
Copy link
Contributor

szymonkups commented Sep 19, 2017

Do you remember why we decided to go this way, @szymonkups? Can we do anything about this?

This is implemented this way just to provide a way to configure model value for the style. Looking at this now I think @wwalc opinion has more sense to treat it as some internals that should be hidden from the configurator. Value is stored inside known attribute so I think that it is safe to create value based on style name and/or class name. This will require to mark default style in some different way - currently by setting null as the value.

@Reinmar
Copy link
Member

Reinmar commented Sep 19, 2017

This will require to mark default style in some different way - currently by setting null as the value.

Yup. Good point.

Agree with the rest too.

… #name instead. Defined ImageStyleFormat#isDefault.
@@ -48,7 +48,7 @@ export function modelToViewStyleAttribute( styles ) {
*/
export function viewToModelStyleAttribute( styles ) {
// Convert only styles without `null` value.
Copy link
Member

Choose a reason for hiding this comment

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

Is the comment still valid here?

@oleq
Copy link
Member Author

oleq commented Sep 20, 2017

I got rid of ImageStyleFormat#value in ad1a540. Please let me know if it works for you and does not break anything.

It also means some fixes in documentation are needed in the ckeditor5 repo https://github.com/ckeditor/ckeditor5/tree/t/ckeditor5-image/134.

I also enabled CI in https://github.com/ckeditor/ckeditor5/tree/t/ckeditor5-image/134.

Copy link
Member

@wwalc wwalc left a comment

Choose a reason for hiding this comment

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

I did not check the whole PR deeply, but the things that I requested to be corrected seem to work okay now. I'll review and update all the image docs once this PR merged.

@oleq
Copy link
Member Author

oleq commented Sep 20, 2017

@szymonkups Could you review this issue?

@Reinmar
Copy link
Member

Reinmar commented Sep 20, 2017

I'd start from the fact that CI for this branch fails :P

@Reinmar
Copy link
Member

Reinmar commented Sep 20, 2017

Oopsie – I haven't noticed that this feature requires changes in other pkgs.

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