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

T/4: Initial Font plugin implementation. #5

Merged
merged 101 commits into from
Feb 15, 2018
Merged

T/4: Initial Font plugin implementation. #5

merged 101 commits into from
Feb 15, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Jan 10, 2018

Suggested merge commit message (convention)

Feature: Initial Font feature implementation. Closes ckeditor/ckeditor5#2275. Closes ckeditor/ckeditor5#2276. Closes ckeditor/ckeditor5#2277.


Additional information

The changes in UI/Theme changes which element gets borders and white background by default. Now it's only to dropdown button with label only - other types of buttons are rendered as buttons.

I have only one major issue with this PR which requires talks/decisions. I've used Regex to create view converter definition for Font Family as font-family inline styles might be defined in various ways in HTML - by using quotes (single/double) or by not using them. So there's a regex that checks any variation of:

  • Long Font Name, Other Font Name
  • "Long Font Name", Other Font Name
  • Long Font Name, 'Other Font Name'
  • ... etc

// Remove quotes from font names. They will be normalized later.
const fontNames = fontDefinition.replace( /"|'/g, '' ).split( ',' );
// The first matched font name will be used as dropdown list item title and as model value
const firstFontName = fontNames[ 0 ];
// CSS-compatible font names.
const cssFontNames = fontNames.map( normalizeFontNameForCSS );
// TODO: Maybe we can come with something better here?
// TODO: Also document this behavior in engine as it uses matcher~Pattern not ViewElementDefinition.
// TODO: Maybe a better solution will be a callback here? (also needs documentation)
// This will match any quote type with whitespace.
const quotesMatch = '("|\'|&qout;|\\W){0,2}';
// Full regex will catch any style of quotation used in view.
// Example:
// from string: "Font Foo Foo, Font Bar"
// it will create a regex that will match any quotation mix:
// - "Font Foo Foo", Font Bar
// - 'Font Foo Foo', "Font Bar"
// - ... etc.
const regexString = `${ quotesMatch }${ fontNames.map( n => n.trim() ).join( `${ quotesMatch },${ quotesMatch }` ) }${ quotesMatch }`;
return {
title: firstFontName,
model: firstFontName,
view: {
name: 'span',
style: {
'font-family': cssFontNames.join( ', ' )
}
},
acceptsAlso: [
{
name: 'span',
style: {
'font-family': new RegExp( regexString )
}
}
]
};

What I can create instead is a use of a callback that would basically to what this regex but programatically. Only thing would be updating documentation in definition-based-coverters (and ViewElementDefinition, etc) to reflect this behavior.

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.

The code looks great. What we need is a better, more verbose documentation to help developers use the (sub–)features we developed.


{@snippet features/build-font-size-source}

The {@link module:font/fontsize~FontSize} feature enables support for setting font size.
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid this is not a very rich introduction. We should clearly state here that the feature is about inline elements, classes and the style attribute.


{@snippet features/build-font-family-source}

The {@link module:font/fontfamily~FontFamily} feature enables support for setting font family.
Copy link
Member

Choose a reason for hiding this comment

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

See my first comment in the font-size.md.

## Configuring font size options

It is possible to configure which font size options are supported by the editor. Use the {@link module:font/fontsize~FontSizeConfig#options `fontSize.options`} configuration option to do so.
Use the special keyword `'normal'` to use the default font size defined in the web page styles.
Copy link
Member

Choose a reason for hiding this comment

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

Why normal but not default? Font size defined default for the same purpose. Is this by design?

*
* @extends module:core/plugin~Plugin
*/
export default class Font extends Plugin {
Copy link
Member

Choose a reason for hiding this comment

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

This plugin has no manual test and is not even mentioned in docs. What's the purpose of it then?

src/font.js Outdated
import FontSize from './fontsize';

/**
* The Font plugin.
Copy link
Member

Choose a reason for hiding this comment

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

What does it do? Because it requires some classes it does not mean it enables them.

Copy link
Member

Choose a reason for hiding this comment

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

s/Font/font/

import fontFamilyIcon from '../../theme/icons/font-family.svg';

/**
* @extends module:core/plugin~Plugin
Copy link
Member

Choose a reason for hiding this comment

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

What does it do? What sort of UI does it create? How to use it in the configuration?

const FONT_SIZE = 'fontSize';

/**
* The Font Size Editing feature.
Copy link
Member

Choose a reason for hiding this comment

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

What does it do? Since we break features into pieces we must explain what each piece is responsible for if developers are expected to use them.

const FONT_FAMILY = 'fontFamily';

/**
* The Font Family Editing feature.
Copy link
Member

Choose a reason for hiding this comment

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

What does it do? Since we break features into pieces we must explain what each piece is responsible for if developers are expected to use them.

import '../../theme/fontsize.css';

/**
* @extends module:core/plugin~Plugin
Copy link
Member

Choose a reason for hiding this comment

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

Same as font family UI.

- `'big'`
- `'huge'`

Each size is represented in the view as a `<span>` element with the `text-*` class. For example, the `'tiny'` preset looks as follows in the editor data:
Copy link
Member

Choose a reason for hiding this comment

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

We must clearly state that we don't provide the styles. It's up to developers to style .ck-content span.tiny {} and we must show a short snippet how to do that.

@oleq
Copy link
Member

oleq commented Feb 12, 2018

I also think that this exponential approach to font previews in docs is a little bit too much
image
The last option is just enormous :P

@jodator
Copy link
Contributor Author

jodator commented Feb 12, 2018

The last option is just enormous :P

No it's huge ;P

@Reinmar
Copy link
Member

Reinmar commented Feb 12, 2018

Men... always talking about the size.

@oleq
Copy link
Member

oleq commented Feb 12, 2018

I was also wondering why these two landed so far from each other in Umberto
image

@Reinmar
Copy link
Member

Reinmar commented Feb 13, 2018

cc @m-turek

@m-turek
Copy link

m-turek commented Feb 13, 2018

I was also wondering why these two landed so far from each other in Umberto

That's my bad, Array.prototype.sort() doesn't preserve order of elements with same value of sorting criteria. I'll fix it soon (today)

Edit: Should work fine now if you reinstall Umberto

@dkonopka
Copy link

dkonopka commented Feb 13, 2018

Should we change left(right) padding of every element in .ck-list to px instead of em like in heading? https://github.com/ckeditor/ckeditor5-heading/issues/63
paddinglist
headingpadding

cc @oleq

@oleq
Copy link
Member

oleq commented Feb 13, 2018

You're right @dkonopka. We should see this fixed.

@jodator
Copy link
Contributor Author

jodator commented Feb 14, 2018

I've fixed another issue in Umberto (the list view in dropdown had margin and padding set): ckeditor/ckeditor5#494 (comment).

Besides that dropdown looks OK.

@jodator
Copy link
Contributor Author

jodator commented Feb 14, 2018

@oleq & @Reinmar I've updated the docs as best I could do :) The dropdown looks OK in docs now.

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.

Font Size & Font Family UI/UX Implement font family editing plugin Implement font size editing plugin
5 participants