'
+ );
+ } );
+ } );
} );
diff --git a/tests/fontcolor/fontcolorui.js b/tests/fontcolor/fontcolorui.js
index 6b0e6a7..7e216dd 100644
--- a/tests/fontcolor/fontcolorui.js
+++ b/tests/fontcolor/fontcolorui.js
@@ -8,7 +8,7 @@
import FontColorEditing from '../../src/fontcolor/fontcolorediting';
import FontColorUI from '../../src/fontcolor/fontcolorui';
-import fontColorIcon from '../../theme/icons/font-family.svg';
+import fontColorIcon from '../../theme/icons/font-color.svg';
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
@@ -22,12 +22,12 @@ describe( 'FontColorUI', () => {
before( () => {
addTranslations( 'en', {
'Font Color': 'Font Color',
- 'Remove text color': 'Remove text color'
+ 'Remove color': 'Remove text color'
} );
addTranslations( 'pl', {
'Font Color': 'Kolor czcionki',
- 'Remove text color': 'Usuń kolor tekstu'
+ 'Remove color': 'Usuń kolor'
} );
} );
@@ -83,17 +83,7 @@ describe( 'FontColorUI', () => {
const dropdown = editor.ui.componentFactory.create( 'fontColor' );
dropdown.commandName = 'fontColor';
- dropdown.fire( 'execute' );
-
- sinon.assert.calledOnce( focusSpy );
- } );
-
- it( 'should focus view after command execution from splitbutton', () => {
- const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
- const dropdown = editor.ui.componentFactory.create( 'fontColor' );
-
- dropdown.commandName = 'fontColor';
- dropdown.buttonView.fire( 'execute' );
+ dropdown.fire( 'execute', { value: null } );
sinon.assert.calledOnce( focusSpy );
} );
@@ -122,7 +112,8 @@ describe( 'FontColorUI', () => {
it( 'works for the colorTableView#items in the panel', () => {
const colorTableView = dropdown.colorTableView;
- expect( colorTableView.removeButtonTooltip ).to.equal( 'Usuń kolor tekstu' );
+ expect( colorTableView.removeButtonTooltip ).to.equal( 'Usuń kolor' );
+ expect( colorTableView.items.first.label ).to.equal( 'Usuń kolor' );
} );
function localizedEditor() {
From c67befb31a28bf774405bc89bc0191a4a1172a8a Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 09:40:11 +0100
Subject: [PATCH 39/92] Add support for objects without label.
---
src/utils.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/utils.js b/src/utils.js
index 9199605..04c3636 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -80,7 +80,7 @@ function getColorsDefinition( color ) {
} else {
return {
model: color.color,
- label: color.label,
+ label: color.label || color.color,
hasBorder: color.hasBorder,
view: {
name: 'span',
From 23de22efe403b2e29f818cacd78113f78d05999e Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 09:58:44 +0100
Subject: [PATCH 40/92] Add pointer cursor for remove button.
---
theme/fontcolor.css | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/theme/fontcolor.css b/theme/fontcolor.css
index 2dcb1b6..3eec924 100644
--- a/theme/fontcolor.css
+++ b/theme/fontcolor.css
@@ -55,3 +55,7 @@
width: var(--ck-table-color-tile-size);
margin-right: var(--ck-spacing-large);
}
+
+.ck .ck-color-table__remove-color {
+ cursor: pointer;
+}
From 9e1d3df1d4055c4b2824b5edf04f361fc1b079b2 Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 10:26:45 +0100
Subject: [PATCH 41/92] Add color names.
---
.../fontbackgroundcolorediting.js | 59 ++++++++++++++-----
src/fontcolor/fontcolorediting.js | 59 ++++++++++++++-----
2 files changed, 88 insertions(+), 30 deletions(-)
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorediting.js b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
index aa60e51..5047eaf 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorediting.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
@@ -22,24 +22,53 @@ export default class FontBackgroundColorEditing extends Plugin {
editor.config.define( FONT_BACKGROUND_COLOR, {
colors: [
- 'hsl(0, 0%, 0%)',
- 'hsl(0, 0%, 30%)',
- 'hsl(0, 0%, 60%)',
- 'hsl(0, 0%, 90%)',
{
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Black'
+ }, {
+ color: 'hsl(0, 0%, 30%)',
+ label: 'Dim grey'
+ }, {
+ color: 'hsl(0, 0%, 60%)',
+ label: 'Grey'
+ }, {
+ color: 'hsl(0, 0%, 90%)',
+ label: 'Light grey'
+ }, {
color: 'hsl(0, 0%, 100%)',
+ label: 'White',
hasBorder: true
- },
- 'hsl(360, 75%, 60%)',
- 'hsl(30, 75%, 60%)',
- 'hsl(60, 75%, 60%)',
- 'hsl(90, 75%, 60%)',
- 'hsl(120, 75%, 60%)',
- 'hsl(150, 75%, 60%)',
- 'hsl(180, 75%, 60%)',
- 'hsl(210, 75%, 60%)',
- 'hsl(240, 75%, 60%)',
- 'hsl(270, 75%, 60%)'
+ }, {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Red'
+ }, {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Orange'
+ }, {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Yellow'
+ }, {
+ color: 'hsl(90, 75%, 60%)',
+ label: 'Light green'
+ }, {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Green'
+ }, {
+ color: 'hsl(150, 75%, 60%)',
+ label: 'Aquamarine'
+ }, {
+ color: 'hsl(180, 75%, 60%)',
+ label: 'Turquoise'
+ }, {
+ color: 'hsl(210, 75%, 60%)',
+ label: 'Light blue'
+ }, {
+ color: 'hsl(240, 75%, 60%)',
+ label: 'Blue'
+ }, {
+ color: 'hsl(270, 75%, 60%)',
+ label: 'Purple'
+ }
]
} );
diff --git a/src/fontcolor/fontcolorediting.js b/src/fontcolor/fontcolorediting.js
index a5238e1..c1cb3cd 100644
--- a/src/fontcolor/fontcolorediting.js
+++ b/src/fontcolor/fontcolorediting.js
@@ -22,24 +22,53 @@ export default class FontColorEditing extends Plugin {
editor.config.define( FONT_COLOR, {
colors: [
- 'hsl(0, 0%, 0%)',
- 'hsl(0, 0%, 30%)',
- 'hsl(0, 0%, 60%)',
- 'hsl(0, 0%, 90%)',
{
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Black'
+ }, {
+ color: 'hsl(0, 0%, 30%)',
+ label: 'Dim grey'
+ }, {
+ color: 'hsl(0, 0%, 60%)',
+ label: 'Grey'
+ }, {
+ color: 'hsl(0, 0%, 90%)',
+ label: 'Light grey'
+ }, {
color: 'hsl(0, 0%, 100%)',
+ label: 'White',
hasBorder: true
- },
- 'hsl(360, 75%, 60%)',
- 'hsl(30, 75%, 60%)',
- 'hsl(60, 75%, 60%)',
- 'hsl(90, 75%, 60%)',
- 'hsl(120, 75%, 60%)',
- 'hsl(150, 75%, 60%)',
- 'hsl(180, 75%, 60%)',
- 'hsl(210, 75%, 60%)',
- 'hsl(240, 75%, 60%)',
- 'hsl(270, 75%, 60%)'
+ }, {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Red'
+ }, {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Orange'
+ }, {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Yellow'
+ }, {
+ color: 'hsl(90, 75%, 60%)',
+ label: 'Light green'
+ }, {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Green'
+ }, {
+ color: 'hsl(150, 75%, 60%)',
+ label: 'Aquamarine'
+ }, {
+ color: 'hsl(180, 75%, 60%)',
+ label: 'Turquoise'
+ }, {
+ color: 'hsl(210, 75%, 60%)',
+ label: 'Light blue'
+ }, {
+ color: 'hsl(240, 75%, 60%)',
+ label: 'Blue'
+ }, {
+ color: 'hsl(270, 75%, 60%)',
+ label: 'Purple'
+ }
]
} );
From b04aad202080b2a8fc11c2ef2b950e93671eba32 Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 10:53:07 +0100
Subject: [PATCH 42/92] Add possibility to translate labels.
---
src/fontcolor/fontcolorui.js | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/src/fontcolor/fontcolorui.js b/src/fontcolor/fontcolorui.js
index 105f904..b0e5cf9 100644
--- a/src/fontcolor/fontcolorui.js
+++ b/src/fontcolor/fontcolorui.js
@@ -29,7 +29,7 @@ export default class FontColorUI extends Plugin {
const colorTableView = colorUI.addColorsToDropdown(
dropdownView,
options.map( element => ( {
- label: element.label,
+ label: t( element.label ),
color: element.model,
options: {
hasBorder: element.hasBorder
@@ -66,17 +66,6 @@ export default class FontColorUI extends Plugin {
} );
}
- /**
- * Returns options as defined in `config.fontFamily.options` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontfamily~FontFamilyOption}
- * in the correct language.
- *
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
- * when the user configuration is defined because the editor does not exist yet.
- *
- * @private
- * @returns {Array.}.
- */
_getLocalizedOptions() {
const editor = this.editor;
const colors = normalizeOptions( editor.config.get( `${ FONT_COLOR }.colors` ) );
From 90f2559e528e0d3fc037e61c5b4239fa449256cb Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 11:41:36 +0100
Subject: [PATCH 43/92] Add unit test for color translations.
---
tests/fontcolor/fontcolorediting.js | 59 +++++++++++++++++++++--------
tests/fontcolor/fontcolorui.js | 51 ++++++++++++++++++++++++-
2 files changed, 93 insertions(+), 17 deletions(-)
diff --git a/tests/fontcolor/fontcolorediting.js b/tests/fontcolor/fontcolorediting.js
index b435616..b4c7d64 100644
--- a/tests/fontcolor/fontcolorediting.js
+++ b/tests/fontcolor/fontcolorediting.js
@@ -39,24 +39,53 @@ describe( 'FontColorEditing', () => {
describe( 'default value', () => {
it( 'should be set', () => {
expect( editor.config.get( 'fontColor.colors' ) ).to.deep.equal( [
- 'hsl(0, 0%, 0%)',
- 'hsl(0, 0%, 30%)',
- 'hsl(0, 0%, 60%)',
- 'hsl(0, 0%, 90%)',
{
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Black'
+ }, {
+ color: 'hsl(0, 0%, 30%)',
+ label: 'Dim grey'
+ }, {
+ color: 'hsl(0, 0%, 60%)',
+ label: 'Grey'
+ }, {
+ color: 'hsl(0, 0%, 90%)',
+ label: 'Light grey'
+ }, {
color: 'hsl(0, 0%, 100%)',
+ label: 'White',
hasBorder: true
- },
- 'hsl(360, 75%, 60%)',
- 'hsl(30, 75%, 60%)',
- 'hsl(60, 75%, 60%)',
- 'hsl(90, 75%, 60%)',
- 'hsl(120, 75%, 60%)',
- 'hsl(150, 75%, 60%)',
- 'hsl(180, 75%, 60%)',
- 'hsl(210, 75%, 60%)',
- 'hsl(240, 75%, 60%)',
- 'hsl(270, 75%, 60%)'
+ }, {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Red'
+ }, {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Orange'
+ }, {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Yellow'
+ }, {
+ color: 'hsl(90, 75%, 60%)',
+ label: 'Light green'
+ }, {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Green'
+ }, {
+ color: 'hsl(150, 75%, 60%)',
+ label: 'Aquamarine'
+ }, {
+ color: 'hsl(180, 75%, 60%)',
+ label: 'Turquoise'
+ }, {
+ color: 'hsl(210, 75%, 60%)',
+ label: 'Light blue'
+ }, {
+ color: 'hsl(240, 75%, 60%)',
+ label: 'Blue'
+ }, {
+ color: 'hsl(270, 75%, 60%)',
+ label: 'Purple'
+ }
] );
} );
} );
diff --git a/tests/fontcolor/fontcolorui.js b/tests/fontcolor/fontcolorui.js
index 7e216dd..02a4f1a 100644
--- a/tests/fontcolor/fontcolorui.js
+++ b/tests/fontcolor/fontcolorui.js
@@ -22,12 +22,25 @@ describe( 'FontColorUI', () => {
before( () => {
addTranslations( 'en', {
'Font Color': 'Font Color',
- 'Remove color': 'Remove text color'
+ 'Remove color': 'Remove text color',
+ 'Black': 'Black',
+ 'White': 'White',
+ 'Red': 'Red',
+ 'Orange': 'Orange',
+ 'Blue': 'Blue',
+ 'Green': 'Green'
} );
addTranslations( 'pl', {
'Font Color': 'Kolor czcionki',
- 'Remove color': 'Usuń kolor'
+ 'Remove color': 'Usuń kolor',
+ 'Black': 'Czarny',
+ 'White': 'Biały',
+ 'Red': 'Czerwony',
+ 'Orange': 'Pomarańczowy',
+ 'Blue': 'Niebieski',
+ 'Green': 'Zielony',
+ 'Yellow': 'Żółty'
} );
} );
@@ -116,6 +129,40 @@ describe( 'FontColorUI', () => {
expect( colorTableView.items.first.label ).to.equal( 'Usuń kolor' );
} );
+ describe( 'works for', () => {
+ const colors = [
+ {
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Czarny'
+ }, {
+ color: 'hsl(0, 0%, 100%)',
+ label: 'Biały'
+ }, {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Czerwony'
+ }, {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Pomarańczowy'
+ }, {
+ color: 'hsl(240, 75%, 60%)',
+ label: 'Niebieski'
+ }, {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Zielony'
+ }, {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Żółty'
+ }
+ ];
+
+ colors.forEach( test => {
+ it( `tested color ${ test.color } with name ${ test.label }.`, () => {
+ const colorGrid = dropdown.colorTableView.items.get( 1 );
+ const tile = colorGrid.items.find( colorTile => test.color === colorTile.color );
+ expect( tile.label ).to.equal( test.label );
+ } );
+ } );
+ } );
function localizedEditor() {
const editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );
From 2f4807456b61930def14832f69e95a9b459518a1 Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 14:59:59 +0100
Subject: [PATCH 44/92] Add part of fixes after review.
---
.../fontbackgroundcolorcommand.js | 12 ++++++
.../fontbackgroundcolorediting.js | 21 +++++-----
.../fontbackgroundcolorui.js | 39 ++++++++++++-------
src/fontcolor/fontcolorcommand.js | 11 ++++++
src/fontcolor/fontcolorediting.js | 21 +++++-----
src/fontcolor/fontcolorui.js | 34 ++++++++++++----
src/ui/colorgrid.js | 6 ++-
src/ui/colortableview.js | 7 +---
src/ui/colortile.js | 1 +
src/utils.js | 18 ++++-----
10 files changed, 114 insertions(+), 56 deletions(-)
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorcommand.js b/src/fontbackgroundcolor/fontbackgroundcolorcommand.js
index 848319a..da85c65 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorcommand.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorcommand.js
@@ -9,6 +9,18 @@
import FontCommand from '../fontcommand';
import { FONT_BACKGROUND_COLOR } from '../utils';
+
+/**
+ * The font background color command. It's used by
+ * {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing}
+ * to apply the font background color.
+ *
+ * editor.execute( 'fontBackgroundColor', { value: 'rgb(250, 20, 20)' } );
+ *
+ * **Note**: Executing the command with value equal null removes the attribute from the model.
+ *
+ * @extends module:font/fontcommand~FontCommand
+ */
export default class FontBackgroundColorCommand extends FontCommand {
/**
* @inheritDoc
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorediting.js b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
index 5047eaf..4652d7b 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorediting.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
@@ -4,15 +4,23 @@
*/
/**
- * @module font/fontfamily/fontfamilyediting
+ * @module font/fontbackgroundcolor/fontbackgroundcolorediting
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-
import FontBackgroundColorCommand from './fontbackgroundcolorcommand';
-
import { FONT_BACKGROUND_COLOR, renderDowncastElement, renderUpcastAttribute } from '../utils';
+/**
+ * The font background color editing feature.
+ *
+ * It introduces the {@link module:font/fontbackgroundcolor/fontbackgroundcolorcommand~FontBackgroundColorCommand command} and
+ * the `fontBackgroundColor` attribute in the {@link module:engine/model/model~Model model} which renders
+ * in the {@link module:engine/view/view view} as an inline `` element (``),
+ * depending on the {@link module:font/fontbackgroundcolor~FontBackgroundColortConfig configuration}.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontBackgroundColorEditing extends Plugin {
/**
* @inheritDoc
@@ -91,13 +99,6 @@ export default class FontBackgroundColorEditing extends Plugin {
} );
editor.commands.add( FONT_BACKGROUND_COLOR, new FontBackgroundColorCommand( editor ) );
- }
-
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
// Allow fontBackgroundColor attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: FONT_BACKGROUND_COLOR } );
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorui.js b/src/fontbackgroundcolor/fontbackgroundcolorui.js
index 11b2fb8..b898fd9 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -8,10 +8,15 @@
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-
-import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { FONT_BACKGROUND_COLOR, normalizeOptions, colorUI } from '../utils';
+import { FONT_BACKGROUND_COLOR, normalizeOptions, addColorsToDropdown } from '../utils';
+import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
+
+/**
+ * The font background color UI plugin. It introduces the `'fontBackgroundColor'` dropdown.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontBackgroundColorUI extends Plugin {
/**
* @inheritDoc
@@ -26,7 +31,7 @@ export default class FontBackgroundColorUI extends Plugin {
// Register UI component.
editor.ui.componentFactory.add( FONT_BACKGROUND_COLOR, locale => {
const dropdownView = createDropdown( locale );
- const colorTableView = colorUI.addColorsToDropdown(
+ const colorTableView = addColorsToDropdown(
dropdownView,
options.map( element => ( {
label: element.label,
@@ -54,11 +59,15 @@ export default class FontBackgroundColorUI extends Plugin {
dropdownView.bind( 'isEnabled' ).to( command );
- dropdownView.on( 'execute', ( evt, val ) => {
- if ( val.value !== null ) {
- colorTableView.recentlyUsedColors.add( { color: val.value, hasBorder: val.hasBorder, label: val.label }, 0 );
+ dropdownView.on( 'execute', ( evt, data ) => {
+ if ( data.value !== null ) {
+ colorTableView.recentlyUsedColors.add( {
+ color: data.value,
+ hasBorder: data.hasBorder,
+ label: data.label
+ }, 0 );
}
- editor.execute( FONT_BACKGROUND_COLOR, val );
+ editor.execute( FONT_BACKGROUND_COLOR, data );
editor.editing.view.focus();
} );
@@ -67,19 +76,23 @@ export default class FontBackgroundColorUI extends Plugin {
}
/**
- * Returns options as defined in `config.fontFamily.options` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontfamily~FontFamilyOption}
+ * Returns options as defined in `config.fontBackgroundColor.colors` but processed to account for
+ * editor localization, i.e. to display {@link module:font/fontBackgroundColor~FontBackgroundColorOption}
* in the correct language.
*
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
* when the user configuration is defined because the editor does not exist yet.
*
* @private
- * @returns {Array.}.
+ * @returns {Array.}.
*/
_getLocalizedOptions() {
const editor = this.editor;
- const colors = normalizeOptions( editor.config.get( `${ FONT_BACKGROUND_COLOR }.colors` ) );
- return colors;
+ const t = editor.t;
+ const options = normalizeOptions( editor.config.get( `${ FONT_BACKGROUND_COLOR }.colors` ) );
+ options.forEach( option => {
+ option.label = t( option.label );
+ } );
+ return options;
}
}
diff --git a/src/fontcolor/fontcolorcommand.js b/src/fontcolor/fontcolorcommand.js
index b669c84..9b50c6d 100644
--- a/src/fontcolor/fontcolorcommand.js
+++ b/src/fontcolor/fontcolorcommand.js
@@ -9,6 +9,17 @@
import FontCommand from '../fontcommand';
import { FONT_COLOR } from '../utils';
+
+/**
+ * The font color command. It's used by {@link module:font/fontcolor/fontcolorediting~FontColorEditing}
+ * to apply the font color.
+ *
+ * editor.execute( 'fontColor', { value: 'rgb(250, 20, 20)' } );
+ *
+ * **Note**: Executing the command with value equal null removes the attribute from the model.
+ *
+ * @extends module:font/fontcommand~FontCommand
+ */
export default class FontColorCommand extends FontCommand {
/**
* @inheritDoc
diff --git a/src/fontcolor/fontcolorediting.js b/src/fontcolor/fontcolorediting.js
index c1cb3cd..ebb39ec 100644
--- a/src/fontcolor/fontcolorediting.js
+++ b/src/fontcolor/fontcolorediting.js
@@ -4,15 +4,23 @@
*/
/**
- * @module font/fontfamily/fontfamilyediting
+ * @module font/fontcolor/fontcolorediting
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-
import FontColorCommand from './fontcolorcommand';
-
import { FONT_COLOR, renderDowncastElement, renderUpcastAttribute } from '../utils';
+/**
+ * The font color editing feature.
+ *
+ * It introduces the {@link module:font/fontcolor/fontcolorcommand~FontColorCommand command} and
+ * the `fontColor` attribute in the {@link module:engine/model/model~Model model} which renders
+ * in the {@link module:engine/view/view view} as an inline `` element (``),
+ * depending on the {@link module:font/fontcolor~FontColortConfig configuration}.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontColorEditing extends Plugin {
/**
* @inheritDoc
@@ -91,13 +99,6 @@ export default class FontColorEditing extends Plugin {
} );
editor.commands.add( FONT_COLOR, new FontColorCommand( editor ) );
- }
-
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
// Allow fontColor attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: FONT_COLOR } );
diff --git a/src/fontcolor/fontcolorui.js b/src/fontcolor/fontcolorui.js
index b0e5cf9..c3314bf 100644
--- a/src/fontcolor/fontcolorui.js
+++ b/src/fontcolor/fontcolorui.js
@@ -8,10 +8,15 @@
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-
-import fontColorIcon from '../../theme/icons/font-color.svg';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { FONT_COLOR, normalizeOptions, colorUI } from '../utils';
+import { FONT_COLOR, normalizeOptions, addColorsToDropdown } from '../utils';
+import fontColorIcon from '../../theme/icons/font-color.svg';
+
+/**
+ * The font background color UI plugin. It introduces the `'fontBackgroundColor'` dropdown.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontColorUI extends Plugin {
/**
* @inheritDoc
@@ -26,10 +31,10 @@ export default class FontColorUI extends Plugin {
// Register UI component.
editor.ui.componentFactory.add( FONT_COLOR, locale => {
const dropdownView = createDropdown( locale );
- const colorTableView = colorUI.addColorsToDropdown(
+ const colorTableView = addColorsToDropdown(
dropdownView,
options.map( element => ( {
- label: t( element.label ),
+ label: element.label,
color: element.model,
options: {
hasBorder: element.hasBorder
@@ -66,9 +71,24 @@ export default class FontColorUI extends Plugin {
} );
}
+ /**
+ * Returns options as defined in `config.fontColor.colors` but processed to account for
+ * editor localization, i.e. to display {@link module:font/fontColor~FontColorOption}
+ * in the correct language.
+ *
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
+ * when the user configuration is defined because the editor does not exist yet.
+ *
+ * @private
+ * @returns {Array.}.
+ */
_getLocalizedOptions() {
const editor = this.editor;
- const colors = normalizeOptions( editor.config.get( `${ FONT_COLOR }.colors` ) );
- return colors;
+ const t = editor.t;
+ const options = normalizeOptions( editor.config.get( `${ FONT_COLOR }.colors` ) );
+ options.forEach( option => {
+ option.label = t( option.label );
+ } );
+ return options;
}
}
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
index 28df1e0..3fbd9d7 100644
--- a/src/ui/colorgrid.js
+++ b/src/ui/colorgrid.js
@@ -26,7 +26,11 @@ export default class ColorGrid extends View {
hasBorder: item.options.hasBorder
} );
colorTile.on( 'execute', () => {
- this.fire( 'execute', { value: item.color, hasBorder: item.options.hasBorder, label: item.label } );
+ this.fire( 'execute', {
+ value: item.color,
+ hasBorder: item.options.hasBorder,
+ label: item.label
+ } );
} );
this.items.add( colorTile );
} );
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index b589809..7e9e760 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -7,14 +7,12 @@ import View from '@ckeditor/ckeditor5-ui/src/view';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import ColorTile from './colortile';
import ColorGrid from './colorgrid';
-
-import removeButtonIcon from '@ckeditor/ckeditor5-core/theme/icons/eraser.svg';
-
-import '../../theme/fontcolor.css';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
+import removeButtonIcon from '@ckeditor/ckeditor5-core/theme/icons/eraser.svg';
+import '../../theme/fontcolor.css';
export default class ColorTableView extends View {
constructor( locale, { colors } ) {
@@ -27,7 +25,6 @@ export default class ColorTableView extends View {
this.keystrokes = new KeystrokeHandler();
this.set( 'selectedColor' );
- this.set( 'hoveredColor' );
this.set( 'removeButtonTooltip' );
this.set( 'colorColumns', 5 );
this.set( 'recentlyUsedColors', new Collection() );
diff --git a/src/ui/colortile.js b/src/ui/colortile.js
index b3ab5ff..5db0c7a 100644
--- a/src/ui/colortile.js
+++ b/src/ui/colortile.js
@@ -4,6 +4,7 @@
*/
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+
export default class ColorTile extends ButtonView {
constructor( locale ) {
super( locale );
diff --git a/src/utils.js b/src/utils.js
index 04c3636..0954edb 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -93,14 +93,12 @@ function getColorsDefinition( color ) {
}
}
-export const colorUI = {
- addColorsToDropdown( dropdownView, colors ) {
- const locale = dropdownView.locale;
- const colorTableView = new ColorTableView( locale, { colors } );
- dropdownView.colorTableView = colorTableView;
- dropdownView.panelView.children.add( colorTableView );
+export function addColorsToDropdown( dropdownView, colors ) {
+ const locale = dropdownView.locale;
+ const colorTableView = new ColorTableView( locale, { colors } );
+ dropdownView.colorTableView = colorTableView;
+ dropdownView.panelView.children.add( colorTableView );
- colorTableView.delegate( 'execute' ).to( dropdownView, 'execute' );
- return colorTableView;
- }
-};
+ colorTableView.delegate( 'execute' ).to( dropdownView, 'execute' );
+ return colorTableView;
+}
From 8c783f5c9f126537c2ecffdfc1ae4386312edd36 Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 15:48:13 +0100
Subject: [PATCH 45/92] Extract color UI to same class.
---
.../fontbackgroundcolorui.js | 90 ++--------------
src/fontcolor/fontcolorui.js | 84 ++-------------
src/ui/colorui.js | 102 ++++++++++++++++++
3 files changed, 121 insertions(+), 155 deletions(-)
create mode 100644 src/ui/colorui.js
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorui.js b/src/fontbackgroundcolor/fontbackgroundcolorui.js
index b898fd9..29a14d1 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -4,12 +4,11 @@
*/
/**
- * @module font/fontbackgroundcolor/fontbackgroundolorui
+ * @module font/fontcolor/fontcolorui
*/
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { FONT_BACKGROUND_COLOR, normalizeOptions, addColorsToDropdown } from '../utils';
+import ColorUI from '../ui/colorui';
+import { FONT_BACKGROUND_COLOR } from '../utils';
import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
/**
@@ -17,82 +16,13 @@ import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
*
* @extends module:core/plugin~Plugin
*/
-export default class FontBackgroundColorUI extends Plugin {
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
- const t = editor.t;
- const command = editor.commands.get( FONT_BACKGROUND_COLOR );
-
- const options = this._getLocalizedOptions();
-
- // Register UI component.
- editor.ui.componentFactory.add( FONT_BACKGROUND_COLOR, locale => {
- const dropdownView = createDropdown( locale );
- const colorTableView = addColorsToDropdown(
- dropdownView,
- options.map( element => ( {
- label: element.label,
- color: element.model,
- options: {
- hasBorder: element.hasBorder
- }
- } ) )
- );
- colorTableView.set( 'removeButtonTooltip', t( 'Remove color' ) );
-
- colorTableView.bind( 'selectedColor' ).to( command, 'value' );
-
- dropdownView.buttonView.set( {
- label: t( 'Font Background Color' ),
- icon: fontBackgroundColorIcon,
- tooltip: true
- } );
-
- dropdownView.extendTemplate( {
- attributes: {
- class: 'ck-font-background-color-dropdown'
- }
- } );
-
- dropdownView.bind( 'isEnabled' ).to( command );
-
- dropdownView.on( 'execute', ( evt, data ) => {
- if ( data.value !== null ) {
- colorTableView.recentlyUsedColors.add( {
- color: data.value,
- hasBorder: data.hasBorder,
- label: data.label
- }, 0 );
- }
- editor.execute( FONT_BACKGROUND_COLOR, data );
- editor.editing.view.focus();
- } );
-
- return dropdownView;
- } );
- }
-
- /**
- * Returns options as defined in `config.fontBackgroundColor.colors` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontBackgroundColor~FontBackgroundColorOption}
- * in the correct language.
- *
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
- * when the user configuration is defined because the editor does not exist yet.
- *
- * @private
- * @returns {Array.}.
- */
- _getLocalizedOptions() {
- const editor = this.editor;
- const t = editor.t;
- const options = normalizeOptions( editor.config.get( `${ FONT_BACKGROUND_COLOR }.colors` ) );
- options.forEach( option => {
- option.label = t( option.label );
+export default class FontColorUI extends ColorUI {
+ constructor( editor ) {
+ super( editor, {
+ commandName: FONT_BACKGROUND_COLOR,
+ componentName: FONT_BACKGROUND_COLOR,
+ icon: fontBackgroundColorIcon,
+ dropdownLabel: 'Font Background Color'
} );
- return options;
}
}
diff --git a/src/fontcolor/fontcolorui.js b/src/fontcolor/fontcolorui.js
index c3314bf..4d3611d 100644
--- a/src/fontcolor/fontcolorui.js
+++ b/src/fontcolor/fontcolorui.js
@@ -7,9 +7,8 @@
* @module font/fontcolor/fontcolorui
*/
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
-import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { FONT_COLOR, normalizeOptions, addColorsToDropdown } from '../utils';
+import ColorUI from '../ui/colorui';
+import { FONT_COLOR } from '../utils';
import fontColorIcon from '../../theme/icons/font-color.svg';
/**
@@ -17,78 +16,13 @@ import fontColorIcon from '../../theme/icons/font-color.svg';
*
* @extends module:core/plugin~Plugin
*/
-export default class FontColorUI extends Plugin {
- /**
- * @inheritDoc
- */
- init() {
- const editor = this.editor;
- const t = editor.t;
- const command = editor.commands.get( FONT_COLOR );
-
- const options = this._getLocalizedOptions();
-
- // Register UI component.
- editor.ui.componentFactory.add( FONT_COLOR, locale => {
- const dropdownView = createDropdown( locale );
- const colorTableView = addColorsToDropdown(
- dropdownView,
- options.map( element => ( {
- label: element.label,
- color: element.model,
- options: {
- hasBorder: element.hasBorder
- }
- } ) )
- );
- colorTableView.set( 'removeButtonTooltip', t( 'Remove color' ) );
-
- colorTableView.bind( 'selectedColor' ).to( command, 'value' );
-
- dropdownView.buttonView.set( {
- label: t( 'Font Color' ),
- icon: fontColorIcon,
- tooltip: true
- } );
-
- dropdownView.extendTemplate( {
- attributes: {
- class: 'ck-font-color-dropdown'
- }
- } );
-
- dropdownView.bind( 'isEnabled' ).to( command );
-
- dropdownView.on( 'execute', ( evt, val ) => {
- if ( val.value !== null ) {
- colorTableView.recentlyUsedColors.add( { color: val.value, hasBorder: val.hasBorder, label: val.label }, 0 );
- }
- editor.execute( FONT_COLOR, val );
- editor.editing.view.focus();
- } );
-
- return dropdownView;
- } );
- }
-
- /**
- * Returns options as defined in `config.fontColor.colors` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontColor~FontColorOption}
- * in the correct language.
- *
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
- * when the user configuration is defined because the editor does not exist yet.
- *
- * @private
- * @returns {Array.}.
- */
- _getLocalizedOptions() {
- const editor = this.editor;
- const t = editor.t;
- const options = normalizeOptions( editor.config.get( `${ FONT_COLOR }.colors` ) );
- options.forEach( option => {
- option.label = t( option.label );
+export default class FontColorUI extends ColorUI {
+ constructor( editor ) {
+ super( editor, {
+ commandName: FONT_COLOR,
+ componentName: FONT_COLOR,
+ icon: fontColorIcon,
+ dropdownLabel: 'Font Color'
} );
- return options;
}
}
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
new file mode 100644
index 0000000..a680beb
--- /dev/null
+++ b/src/ui/colorui.js
@@ -0,0 +1,102 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/**
+ * @module font/fontcolor/fontcolorui
+ */
+
+import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
+import { normalizeOptions, addColorsToDropdown } from '../utils';
+
+/**
+ * The font background color UI plugin. It introduces the `'fontBackgroundColor'` dropdown.
+ *
+ * @extends module:core/plugin~Plugin
+ */
+export default class ColorUI extends Plugin {
+ constructor( editor, { commandName, icon, componentName, dropdownLabel } ) {
+ super( editor );
+
+ this.commandName = commandName;
+ this.icon = icon;
+ this.componentName = componentName;
+ this.dropdownLabel = dropdownLabel;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ init() {
+ const editor = this.editor;
+ const t = editor.t;
+ const command = editor.commands.get( this.commandName );
+
+ const options = this._getLocalizedOptions();
+
+ // Register UI component.
+ editor.ui.componentFactory.add( this.componentName, locale => {
+ const dropdownView = createDropdown( locale );
+ const colorTableView = addColorsToDropdown(
+ dropdownView,
+ options.map( element => ( {
+ label: element.label,
+ color: element.model,
+ options: {
+ hasBorder: element.hasBorder
+ }
+ } ) )
+ );
+ colorTableView.set( 'removeButtonTooltip', t( 'Remove color' ) );
+
+ colorTableView.bind( 'selectedColor' ).to( command, 'value' );
+
+ dropdownView.buttonView.set( {
+ label: t( this.dropdownLabel ),
+ icon: this.icon,
+ tooltip: true
+ } );
+
+ dropdownView.extendTemplate( {
+ attributes: {
+ class: 'ck-color-ui-dropdown'
+ }
+ } );
+
+ dropdownView.bind( 'isEnabled' ).to( command );
+
+ dropdownView.on( 'execute', ( evt, val ) => {
+ if ( val.value !== null ) {
+ colorTableView.recentlyUsedColors.add( { color: val.value, hasBorder: val.hasBorder, label: val.label }, 0 );
+ }
+ editor.execute( this.commandName, val );
+ editor.editing.view.focus();
+ } );
+
+ return dropdownView;
+ } );
+ }
+
+ /**
+ * Returns options as defined in `config.fontColor.colors` but processed to account for
+ * editor localization, i.e. to display {@link module:font/fontColor~FontColorOption}
+ * in the correct language.
+ *
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
+ * when the user configuration is defined because the editor does not exist yet.
+ *
+ * @private
+ * @returns {Array.}.
+ */
+ _getLocalizedOptions() {
+ const editor = this.editor;
+ const t = editor.t;
+ const options = normalizeOptions( editor.config.get( `${ this.componentName }.colors` ) );
+ options.forEach( option => {
+ option.label = t( option.label );
+ } );
+ return options;
+ }
+}
From d2448e03b1433e534def893b345e8c3aedf2ef2d Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Thu, 21 Mar 2019 17:25:36 +0100
Subject: [PATCH 46/92] Add more docs to feature.
---
src/ui/colorgrid.js | 102 ++++++++++++++++++++++++++++++++++++++------
src/ui/colortile.js | 21 ++++++++-
src/ui/colorui.js | 40 ++++++++++++++---
3 files changed, 144 insertions(+), 19 deletions(-)
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
index 3fbd9d7..b38ba60 100644
--- a/src/ui/colorgrid.js
+++ b/src/ui/colorgrid.js
@@ -3,20 +3,75 @@
* For licensing, see LICENSE.md.
*/
+/**
+ * @module font/ui/colorgrid
+ */
+
import View from '@ckeditor/ckeditor5-ui/src/view';
import ColorTile from './colortile';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
+/**
+ * It keeps nicely collection of {@link module:font/ui/colortile~ColorTile}.
+ */
export default class ColorGrid extends View {
+ /**
+ * Construct instance of color grid used to display {@link module:font/ui/colortile~ColorTile} in drop down.
+ *
+ * @param {module:utils/locale~Locale} [locale] The localization services instance.
+ * @param {Object} config Configuration
+ * @param {Array. {
const colorTile = new ColorTile();
colorTile.set( {
@@ -42,27 +97,20 @@ export default class ColorGrid extends View {
class: 'ck-color-table__grid-container'
}
} );
-
- this._focusCycler = new FocusCycler( {
- focusables: this.items,
- focusTracker: this.focusTracker,
- keystrokeHandler: this.keystrokes,
- actions: {
- // Navigate list items backwards using the arrowup key.
- focusPrevious: 'arrowleft',
-
- // Navigate toolbar items forwards using the arrowdown key.
- focusNext: 'arrowright',
- }
- } );
}
+ /**
+ * Focuses the first focusable in {@link #items}.
+ */
focus() {
if ( this.items.length ) {
this.items.first.focus();
}
}
+ /**
+ * Focuses the last focusable in {@link #items}.
+ */
focusLast() {
if ( this.items.length ) {
const lastChild = this.children.last;
@@ -75,6 +123,9 @@ export default class ColorGrid extends View {
}
}
+ /**
+ * @inheritDoc
+ */
render() {
super.render();
@@ -95,3 +146,28 @@ export default class ColorGrid extends View {
this.keystrokes.listenTo( this.element );
}
}
+
+/**
+ * Color definition used to build {@link module:font/ui/colortile~ColorTile}.
+ *
+ * {
+ * color: hsl(0, 0%, 75%),
+ * label: 'Light Grey',
+ * options: {
+ * hasBorder: true
+ * }
+ * }
+ *
+ * @typedef module:font/ui/colorgrid~colorsDefinition
+ * @type Object
+ *
+ * @property {String} color String representing inserted color.
+ * It's used as value of background-color style in {@link module:font/ui/colortile~ColorTile}.
+ *
+ * @property {String} label String used as label for {@link module:font/ui/colortile~ColorTile}.
+ *
+ * @property {Object} options Additional options passed to build {@link module:font/ui/colortile~ColorTile}.
+ *
+ * @property {Boolean} options.hasBorder Flag indicates if special CSS class should be added
+ * to {@link module:font/ui/colortile~ColorTile}, which draw border around it.
+ */
diff --git a/src/ui/colortile.js b/src/ui/colortile.js
index 5db0c7a..8dbf787 100644
--- a/src/ui/colortile.js
+++ b/src/ui/colortile.js
@@ -3,15 +3,34 @@
* For licensing, see LICENSE.md.
*/
+/**
+ * @module font/ui/colortile
+ */
+
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+/**
+ * Class represents single color tile possible to click in dropdown. Element was designed
+ * for being used in {@link module:font/ui/colorgrid~ColorGrid}.
+ *
+ * @extends module:ui/button/buttonview~ButtonView
+ */
export default class ColorTile extends ButtonView {
constructor( locale ) {
super( locale );
-
const bind = this.bindTemplate;
+ /**
+ * String representing color which will be shown as tile's background.
+ * @type {String}
+ */
this.set( 'color' );
+
+ /**
+ * Parameter which trigger adding special CSS class to button.
+ * This class is responsible for displaying border around button.
+ * @type {Boolean}
+ */
this.set( 'hasBorder' );
this.extendTemplate( {
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index a680beb..90486cb 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -4,7 +4,7 @@
*/
/**
- * @module font/fontcolor/fontcolorui
+ * @module font/ui/colorui
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
@@ -12,17 +12,47 @@ import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import { normalizeOptions, addColorsToDropdown } from '../utils';
/**
- * The font background color UI plugin. It introduces the `'fontBackgroundColor'` dropdown.
+ * The color UI plugin. It's template for creating the `'fontBackgroundColor'` and the `'fotnColor'` dropdown.
+ * Plugin separates common logic responsible for displaying dropdown with color grids.
*
* @extends module:core/plugin~Plugin
*/
export default class ColorUI extends Plugin {
+ /**
+ * Creates plugin which adds UI with {@link module:font/ui/colortableview~ColorTableView} with proper configuration.
+ *
+ * @param {module:core/editor/editor~Editor} editor
+ * @param {Object} config Configuration object
+ * @param {String} config.commandName Name of command which will be execute after click into selected color tile.config.
+ * @param {String} config.componentName Name of this component in {@link module:ui/componentfactory~ComponentFactory}
+ * @param {String} config.icon SVG icon used in toolbar for displaying this UI element.
+ * @param {String} config.dropdownLabel Label used for icon in toolbar for this element.
+ */
constructor( editor, { commandName, icon, componentName, dropdownLabel } ) {
super( editor );
+ /**
+ * Name of command which will be execute after click into selected color tile.config.
+ * @type {String}
+ */
this.commandName = commandName;
- this.icon = icon;
+
+ /**
+ * Name of this component in {@link module:ui/componentfactory~ComponentFactory}.
+ * @type {String}
+ */
this.componentName = componentName;
+
+ /**
+ * SVG icon used in toolbar for displaying this UI element.
+ * @type {String}
+ */
+ this.icon = icon;
+
+ /**
+ * Label used for icon in toolbar for this element.
+ * @type {String}
+ */
this.dropdownLabel = dropdownLabel;
}
@@ -80,9 +110,9 @@ export default class ColorUI extends Plugin {
}
/**
- * Returns options as defined in `config.fontColor.colors` but processed to account for
+ * Returns options as defined in `config` but processed to account for
* editor localization, i.e. to display {@link module:font/fontColor~FontColorOption}
- * in the correct language.
+ * or {@link module:font/fontBackgroundColor~FontBackgroundColorOption} in the correct language.
*
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
* when the user configuration is defined because the editor does not exist yet.
From d7682b388c210774e956e6cf6f6a6ed6c96d8d2f Mon Sep 17 00:00:00 2001
From: Mateusz Samsel
Date: Fri, 22 Mar 2019 12:13:06 +0100
Subject: [PATCH 47/92] Other review part. Lots of docs improvements. Expose
config with amount of columns drawed in color table dropdown.
---
src/fontbackgroundcolor.js | 96 +++++++++++++
.../fontbackgroundcolorediting.js | 5 +-
.../fontbackgroundcolorui.js | 4 +-
src/fontcolor.js | 95 ++++++++++++
src/fontcolor/fontcolorediting.js | 5 +-
src/ui/colorgrid.js | 6 +-
src/ui/colortableview.js | 136 +++++++++++++++---
src/ui/colorui.js | 23 +--
src/utils.js | 38 ++++-
9 files changed, 368 insertions(+), 40 deletions(-)
diff --git a/src/fontbackgroundcolor.js b/src/fontbackgroundcolor.js
index f10d611..a52d392 100644
--- a/src/fontbackgroundcolor.js
+++ b/src/fontbackgroundcolor.js
@@ -11,6 +11,15 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontBackgroundColorEditing from './fontbackgroundcolor/fontbackgroundcolorediting';
import FontBackgroundColorUI from './fontbackgroundcolor/fontbackgroundcolorui';
+/**
+ * The font background color plugin.
+ *
+ * This is a "glue" plugin which loads
+ * the {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} and
+ * {@link module:font/fontbackgroundcolor/fontbackgroundcolorui~FontBackgroundColorUI} features in the editor.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontBackgroundColor extends Plugin {
/**
* @inheritDoc
@@ -26,3 +35,90 @@ export default class FontBackgroundColor extends Plugin {
return 'FontBackgroundColor';
}
}
+
+/**
+ * The configuration of the font background color feature.
+ * This option is used by the {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} feature.
+ *
+ * ClassicEditor
+ * .create( {
+ * fontBackgroundColor: ... // Font family feature configuration.
+ * } )
+ * .then( ... )
+ * .catch( ... );
+ *
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
+ *
+ * @interface module:font/fontbackgroundcolor~FontBackgroundColorConfig
+ */
+
+/**
+ * Available 'font background color' colors defined as an array of strings or objects. The default value is:
+ *
+ * const fontBackgroundColorConfig = {
+ * colors: [
+ * {
+ * color: 'hsl(0, 0%, 0%)',
+ * label: 'Black'
+ * }, {
+ * color: 'hsl(0, 0%, 30%)',
+ * label: 'Dim grey'
+ * }, {
+ * color: 'hsl(0, 0%, 60%)',
+ * label: 'Grey'
+ * }, {
+ * color: 'hsl(0, 0%, 90%)',
+ * label: 'Light grey'
+ * }, {
+ * color: 'hsl(0, 0%, 100%)',
+ * label: 'White',
+ * hasBorder: true
+ * }, {
+ * color: 'hsl(0, 75%, 60%)',
+ * label: 'Red'
+ * }, {
+ * color: 'hsl(30, 75%, 60%)',
+ * label: 'Orange'
+ * }, {
+ * color: 'hsl(60, 75%, 60%)',
+ * label: 'Yellow'
+ * }, {
+ * color: 'hsl(90, 75%, 60%)',
+ * label: 'Light green'
+ * }, {
+ * color: 'hsl(120, 75%, 60%)',
+ * label: 'Green'
+ * }, {
+ * color: 'hsl(150, 75%, 60%)',
+ * label: 'Aquamarine'
+ * }, {
+ * color: 'hsl(180, 75%, 60%)',
+ * label: 'Turquoise'
+ * }, {
+ * color: 'hsl(210, 75%, 60%)',
+ * label: 'Light blue'
+ * }, {
+ * color: 'hsl(240, 75%, 60%)',
+ * label: 'Blue'
+ * }, {
+ * color: 'hsl(270, 75%, 60%)',
+ * label: 'Purple'
+ * }
+ * ]
+ * };
+ *
+ * which configures 15 default colors. Each color is used in dropdown as available color to choose from dropdown.
+ *
+ * @member {Array.} module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors
+ */
+
+/**
+ * Value represent amount of drawn columns in color panel. It also represent amount of visible recently used colors.
+ * The default value is:
+ *
+ * const fontBackgroundColorConfig = {
+ * columns: 5
+ * }
+ *
+ * @member {Numebr} module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns
+ */
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorediting.js b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
index 4652d7b..d030c8e 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorediting.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
@@ -17,7 +17,7 @@ import { FONT_BACKGROUND_COLOR, renderDowncastElement, renderUpcastAttribute } f
* It introduces the {@link module:font/fontbackgroundcolor/fontbackgroundcolorcommand~FontBackgroundColorCommand command} and
* the `fontBackgroundColor` attribute in the {@link module:engine/model/model~Model model} which renders
* in the {@link module:engine/view/view view} as an inline `` element (``),
- * depending on the {@link module:font/fontbackgroundcolor~FontBackgroundColortConfig configuration}.
+ * depending on the {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig configuration}.
*
* @extends module:core/plugin~Plugin
*/
@@ -77,7 +77,8 @@ export default class FontBackgroundColorEditing extends Plugin {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
- ]
+ ],
+ columns: 5
} );
editor.conversion.for( 'upcast' ).elementToAttribute( {
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorui.js b/src/fontbackgroundcolor/fontbackgroundcolorui.js
index 29a14d1..fbfadf9 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -4,7 +4,7 @@
*/
/**
- * @module font/fontcolor/fontcolorui
+ * @module font/fontbackgroundcolor/fontbackgroundcolorui
*/
import ColorUI from '../ui/colorui';
@@ -16,7 +16,7 @@ import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
*
* @extends module:core/plugin~Plugin
*/
-export default class FontColorUI extends ColorUI {
+export default class FontBackgroundColorUI extends ColorUI {
constructor( editor ) {
super( editor, {
commandName: FONT_BACKGROUND_COLOR,
diff --git a/src/fontcolor.js b/src/fontcolor.js
index 18d3b1e..a56e728 100644
--- a/src/fontcolor.js
+++ b/src/fontcolor.js
@@ -11,6 +11,14 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontColorEditing from './fontcolor/fontcolorediting';
import FontColorUI from './fontcolor/fontcolorui';
+/**
+ * The font color plugin.
+ *
+ * This is a "glue" plugin which loads the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
+ * {@link module:font/fontcolor/fontcolorui~FontColorUI} features in the editor.
+ *
+ * @extends module:core/plugin~Plugin
+ */
export default class FontColor extends Plugin {
/**
* @inheritDoc
@@ -26,3 +34,90 @@ export default class FontColor extends Plugin {
return 'FontColor';
}
}
+
+/**
+ * The configuration of the font color feature.
+ * This option is used by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} feature.
+ *
+ * ClassicEditor
+ * .create( {
+ * fontColor: ... // Font family feature configuration.
+ * } )
+ * .then( ... )
+ * .catch( ... );
+ *
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
+ *
+ * @interface module:font/fontcolor~FontColorConfig
+ */
+
+/**
+ * Available 'font color' colors defined as an array of strings or objects. The default value is:
+ *
+ * const fontColorConfig = {
+ * colors: [
+ * {
+ * color: 'hsl(0, 0%, 0%)',
+ * label: 'Black'
+ * }, {
+ * color: 'hsl(0, 0%, 30%)',
+ * label: 'Dim grey'
+ * }, {
+ * color: 'hsl(0, 0%, 60%)',
+ * label: 'Grey'
+ * }, {
+ * color: 'hsl(0, 0%, 90%)',
+ * label: 'Light grey'
+ * }, {
+ * color: 'hsl(0, 0%, 100%)',
+ * label: 'White',
+ * hasBorder: true
+ * }, {
+ * color: 'hsl(0, 75%, 60%)',
+ * label: 'Red'
+ * }, {
+ * color: 'hsl(30, 75%, 60%)',
+ * label: 'Orange'
+ * }, {
+ * color: 'hsl(60, 75%, 60%)',
+ * label: 'Yellow'
+ * }, {
+ * color: 'hsl(90, 75%, 60%)',
+ * label: 'Light green'
+ * }, {
+ * color: 'hsl(120, 75%, 60%)',
+ * label: 'Green'
+ * }, {
+ * color: 'hsl(150, 75%, 60%)',
+ * label: 'Aquamarine'
+ * }, {
+ * color: 'hsl(180, 75%, 60%)',
+ * label: 'Turquoise'
+ * }, {
+ * color: 'hsl(210, 75%, 60%)',
+ * label: 'Light blue'
+ * }, {
+ * color: 'hsl(240, 75%, 60%)',
+ * label: 'Blue'
+ * }, {
+ * color: 'hsl(270, 75%, 60%)',
+ * label: 'Purple'
+ * }
+ * ]
+ * };
+ *
+ * which configures 15 default colors. Each color is used in dropdown as available color to choose from dropdown.
+ *
+ * @member {Array.} module:font/fontcolor~FontColorConfig#colors
+ */
+
+/**
+ * Value represent amount of drawn columns in color panel. It also represents amount of visible recently used colors.
+ * The default value is:
+ *
+ * const fontColorConfig = {
+ * columns: 5
+ * }
+ *
+ * @member {Numebr} module:font/fontcolor~FontColorConfig#columns
+ */
diff --git a/src/fontcolor/fontcolorediting.js b/src/fontcolor/fontcolorediting.js
index ebb39ec..d62a98f 100644
--- a/src/fontcolor/fontcolorediting.js
+++ b/src/fontcolor/fontcolorediting.js
@@ -17,7 +17,7 @@ import { FONT_COLOR, renderDowncastElement, renderUpcastAttribute } from '../uti
* It introduces the {@link module:font/fontcolor/fontcolorcommand~FontColorCommand command} and
* the `fontColor` attribute in the {@link module:engine/model/model~Model model} which renders
* in the {@link module:engine/view/view view} as an inline `` element (``),
- * depending on the {@link module:font/fontcolor~FontColortConfig configuration}.
+ * depending on the {@link module:font/fontcolor~FontColorConfig configuration}.
*
* @extends module:core/plugin~Plugin
*/
@@ -77,7 +77,8 @@ export default class FontColorEditing extends Plugin {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
- ]
+ ],
+ columns: 5
} );
editor.conversion.for( 'upcast' ).elementToAttribute( {
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
index b38ba60..0598c41 100644
--- a/src/ui/colorgrid.js
+++ b/src/ui/colorgrid.js
@@ -15,6 +15,8 @@ import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
/**
* It keeps nicely collection of {@link module:font/ui/colortile~ColorTile}.
+ *
+ * @extends module:ui/view~View
*/
export default class ColorGrid extends View {
/**
@@ -22,7 +24,7 @@ export default class ColorGrid extends View {
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
* @param {Object} config Configuration
- * @param {Array.} colorsDefinition Array with definitions
* required to build {@link module:font/ui/colortile~ColorTile}.
*/
constructor( locale, { colorsDefinition = [] } = {} ) {
@@ -158,7 +160,7 @@ export default class ColorGrid extends View {
* }
* }
*
- * @typedef module:font/ui/colorgrid~colorsDefinition
+ * @typedef {Object} module:font/ui/colorgrid~ColorDefinition
* @type Object
*
* @property {String} color String representing inserted color.
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index 7e9e760..e4fb332 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -3,6 +3,10 @@
* For licensing, see LICENSE.md.
*/
+/**
+ * @module font/ui/colortableview
+ */
+
import View from '@ckeditor/ckeditor5-ui/src/view';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import ColorTile from './colortile';
@@ -14,35 +18,87 @@ import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
import removeButtonIcon from '@ckeditor/ckeditor5-core/theme/icons/eraser.svg';
import '../../theme/fontcolor.css';
+/**
+ * Class which represents view with {@link module:font/ui/colorgrid~ColorGrid}
+ * and remove buttons inside {@link module:ui/dropdown/dropdownview~DropdownView}.
+ *
+ * @extends module:ui/view~View
+ */
export default class ColorTableView extends View {
- constructor( locale, { colors } ) {
+ /**
+ * Construct view which will be inserted as child of {@link module:ui/dropdown/dropdownview~DropdownView}
+ * @param {module:utils/locale~Locale} [locale] The localization services instance.
+ * @param {Object} config Configuration object
+ * @param {Array.
+
+ This text has light green color and blue background.
+
+
+
+ This text has white color and black background.
+
+
diff --git a/docs/_snippets/features/font.js b/docs/_snippets/features/font.js
index df67b6d..7940bf1 100644
--- a/docs/_snippets/features/font.js
+++ b/docs/_snippets/features/font.js
@@ -12,7 +12,17 @@ ClassicEditor
cloudServices: CS_CONFIG,
toolbar: {
items: [
- 'heading', '|', 'fontSize', 'fontFamily', '|', 'bulletedList', 'numberedList', 'undo', 'redo'
+ 'heading',
+ '|',
+ 'fontSize',
+ 'fontFamily',
+ 'fontColor',
+ 'fontBackgroundColor',
+ '|',
+ 'bulletedList',
+ 'numberedList',
+ 'undo',
+ 'redo'
],
viewportTopOffset: window.getViewportTopOffsetConfig()
}
diff --git a/docs/features/font.md b/docs/features/font.md
index 7a7a15c..87c6395 100644
--- a/docs/features/font.md
+++ b/docs/features/font.md
@@ -8,6 +8,8 @@ category: features
The {@link module:font/font~Font} plugin enables the following features in the editor:
* {@link module:font/fontfamily~FontFamily} – Allows to change the font family by applying inline `` elements with a `font-family` in the `style` attribute.
* {@link module:font/fontsize~FontSize} – Allows to control the font size by applying inline `` elements that either have a CSS class or a `font-size` in the `style` attribute.
+* {@link module:font/fontcolor~FontColor} – Allows to control the font color by applying inline `` elements with a `color` in the `style` attribute.
+* {@link module:font/fontbackgroundcolor~FontBackgroundColor} – Allows to control the font background color by applying inline `` elements with a `background-color` in the `style` attribute.
## Demo
@@ -145,6 +147,77 @@ ClassicEditor
{@snippet features/custom-font-size-numeric-options}
+## Configuring font color and font background color
+
+Plugin enables `font color` and `font background color`. Which allows on using style `color` and `background-color` over text.
+
+ Please notice that you can turn on only one of those plugins. As well as configure them separately.
+
+
+### Dropdown
+
+It is possible to configure which colors are available in dropdown in the editor. Use the `fontColor.colors` or `fontBackgroundColor.colors` configuration option to do so.
+
+It is possible to configure how many columns is shown in color dropdown. Use the `fontColor.columns` or `fontBackgroundColor.columns` configuration option to do so. This option also reflects to number of recently used colors section, which always have 1 row with amount of columns equal to `columns` configuration option.
+Default colors configuration is presented below:
+
+```js
+fontColor = {
+ colors: [
+ {
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Black'
+ }, {
+ color: 'hsl(0, 0%, 30%)',
+ label: 'Dim grey'
+ }, {
+ color: 'hsl(0, 0%, 60%)',
+ label: 'Grey'
+ }, {
+ color: 'hsl(0, 0%, 90%)',
+ label: 'Light grey'
+ }, {
+ color: 'hsl(0, 0%, 100%)',
+ label: 'White',
+ hasBorder: true
+ }, {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Red'
+ }, {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Orange'
+ }, {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Yellow'
+ }, {
+ color: 'hsl(90, 75%, 60%)',
+ label: 'Light green'
+ }, {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Green'
+ }, {
+ color: 'hsl(150, 75%, 60%)',
+ label: 'Aquamarine'
+ }, {
+ color: 'hsl(180, 75%, 60%)',
+ label: 'Turquoise'
+ }, {
+ color: 'hsl(210, 75%, 60%)',
+ label: 'Light blue'
+ }, {
+ color: 'hsl(240, 75%, 60%)',
+ label: 'Blue'
+ }, {
+ color: 'hsl(270, 75%, 60%)',
+ label: 'Purple'
+ }
+ ],
+ columns: 5
+}
+```
+
+{@snippet features/custom-font-color-and-background-color-options}
+
## Installation
To add this feature to your editor, install the [`@ckeditor/ckeditor5-font`](https://www.npmjs.com/package/@ckeditor/ckeditor5-font) package:
@@ -161,7 +234,7 @@ import Font from '@ckeditor/ckeditor5-font/src/font';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Font, ... ],
- toolbar: [ 'fontSize', 'fontFamily', ... ]
+ toolbar: [ 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', ... ]
} )
.then( ... )
.catch( ... );
@@ -256,6 +329,39 @@ The {@link module:font/fontsize~FontSize} plugin registers the following compone
editor.execute( 'fontSize' );
```
+The {@link module:font/fontcolor~FontColor} plugin registers the following components:
+
+* The `'fontColor'` dropdown,
+* The {@link module:font/fontcolor/fontcolorcommand~FontColorCommand `'fontColor'`} command.
+
+ The number of options and their names correspond to the {@link module:font/fontcolor~FontColorConfig#colors `fontColor.colors`}
+ and {@link module:font/fontcolor~FontColorConfig#columns `fontColor.columns`} configuration options.
+
+ You can change the font color of the current selection by executing the command with a desired value:
+
+ ```js
+ editor.execute( 'fontColor', { value: rgb(30, 188, 97) } );
+ ```
+
+ The `'fontColor'` command will accept any strings as values.
+
+The {@link module:font/fontbackgroundcolor~FontBackgroundColor} plugin registers the following components:
+
+* The `'fontColor'` dropdown,
+* The {@link module:font/fontbackgroundcolor/fontbackgroundcolorcommand~FontBackgroundColorCommand `'fontBackgroundColor'`} command.
+
+ The number of options and their names correspond to the {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors `fontBackgroundColor.colors`}
+ and {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns `fontBackgroundColor.columns`} configuration options.
+
+ You can change the font background color of the current selection by executing the command with a desired value:
+
+ ```js
+ editor.execute( 'fontBackgroundColor', { value: rgb(30, 188, 97) } );
+ ```
+
+ The `'fontBackgroundColor'` command will accept any strings as values.
+
+
## Contribute
The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5-font.
From ca81b72ba841cc3f87c0d9ad4a0620cd274a8cf7 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 13:07:21 +0100
Subject: [PATCH 61/92] Code refactoring in font utils.
---
src/utils.js | 61 ++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/src/utils.js b/src/utils.js
index 86245ff..441b288 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -9,6 +9,16 @@
import ColorTableView from './ui/colortableview';
+/**
+ * Name of font color plugin.
+ */
+export const FONT_COLOR = 'fontColor';
+
+/**
+ * Name of font background color plugin.
+ */
+export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
+
/**
* Builds a proper {@link module:engine/conversion/conversion~ConverterDefinition converter definition} out of input data.
*
@@ -38,16 +48,6 @@ export function buildDefinition( modelAttributeKey, options ) {
return definition;
}
-/**
- * Name of font color plugin
- */
-export const FONT_COLOR = 'fontColor';
-
-/**
- * Name of font background color plugin.
- */
-export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
-
/**
* Function for font color and font background color plugins
* which is responsible for upcasting data to model.
@@ -56,10 +56,7 @@ export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
* @param {String} styleAttr
*/
export function renderUpcastAttribute( styleAttr ) {
- return viewElement => {
- const fontColor = viewElement.getStyle( styleAttr );
- return normalizeColorCode( fontColor );
- };
+ return viewElement => normalizeColorCode( viewElement.getStyle( styleAttr ) );
}
/**
@@ -91,6 +88,25 @@ export function normalizeOptions( colorRow ) {
.filter( option => !!option );
}
+/**
+ * Helper which add {@link module:font/ui/colortableview~ColorTableView} to dropdown with proper initial values.
+ * @param {Object} config Configuration object
+ * @param {module:ui/dropdown/dropdownview~DropdownView} config.dropdownView Dropdown view to which
+ * will be added {@link module:font/ui/colortableview~ColorTableView}.
+ * @param {Array.} Array with objects representing color to be drawn in color grid.
+ */
+export function addColorsToDropdown( { dropdownView, colors, colorColumns, removeButtonLabel } ) {
+ const locale = dropdownView.locale;
+ const colorTableView = new ColorTableView( locale, { colors, colorColumns, removeButtonLabel } );
+
+ dropdownView.colorTableView = colorTableView;
+ dropdownView.panelView.children.add( colorTableView );
+
+ colorTableView.delegate( 'execute' ).to( dropdownView, 'execute' );
+
+ return colorTableView;
+}
+
function normalizeSingleColorDefinition( color ) {
if ( typeof color === 'string' ) {
return {
@@ -120,20 +136,3 @@ function normalizeSingleColorDefinition( color ) {
};
}
}
-
-/**
- * Helper which add {@link module:font/ui/colortableview~ColorTableView} to dropdown with proper initial values.
- * @param {Object} config Configuration object
- * @param {module:ui/dropdown/dropdownview~DropdownView} config.dropdownView Dropdown view to which
- * will be added {@link module:font/ui/colortableview~ColorTableView}.
- * @param {Array.} Array with objects representing color to be drawn in color grid.
- */
-export function addColorsToDropdown( { dropdownView, colors, colorColumns, removeButtonTooltip } ) {
- const locale = dropdownView.locale;
- const colorTableView = new ColorTableView( locale, { colors, colorColumns, removeButtonTooltip } );
- dropdownView.colorTableView = colorTableView;
- dropdownView.panelView.children.add( colorTableView );
-
- colorTableView.delegate( 'execute' ).to( dropdownView, 'execute' );
- return colorTableView;
-}
From 76368eb78e9781e8df78fa73afb30c329171509b Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 13:52:45 +0100
Subject: [PATCH 62/92] Tests: Code refactoring.
---
tests/fontbackgroundcolor/fontbackgroundcolorcommand.js | 1 -
tests/fontbackgroundcolor/fontbackgroundcoloreditng.js | 8 +++++---
tests/fontbackgroundcolor/fontbackgroundcolorui.js | 2 --
tests/fontcolor/fontcolorcommand.js | 1 -
tests/fontcolor/fontcolorediting.js | 9 ++++-----
tests/fontcolor/fontcolorui.js | 2 --
6 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/tests/fontbackgroundcolor/fontbackgroundcolorcommand.js b/tests/fontbackgroundcolor/fontbackgroundcolorcommand.js
index 24d8b19..67a39e5 100644
--- a/tests/fontbackgroundcolor/fontbackgroundcolorcommand.js
+++ b/tests/fontbackgroundcolor/fontbackgroundcolorcommand.js
@@ -5,7 +5,6 @@
import FontBackgroundColorCommand from '../../src/fontbackgroundcolor/fontbackgroundcolorcommand';
import FontCommand from '../../src/fontcommand';
-
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
describe( 'FontBackgroundColorCommand', () => {
diff --git a/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js b/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
index 150f5f3..8bcbf94 100644
--- a/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
+++ b/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
@@ -4,11 +4,12 @@
*/
import FontBackgroundColorEditing from './../../src/fontbackgroundcolor/fontbackgroundcolorediting';
-
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
-import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import {
+ getData as getModelData,
+ setData as setModelData
+} from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
describe( 'FontBackgroundColorEditing', () => {
let editor, doc;
@@ -133,6 +134,7 @@ describe( 'FontBackgroundColorEditing', () => {
'rgb( 20%, 30%, 40% )',
'#345678'
];
+
tests.forEach( test => {
it( `should convert fontBackgroundColor attribute: "${ test }" to proper style value.`, () => {
setModelData( doc, `fo<$text fontBackgroundColor="${ test }">o b$text>ar` );
diff --git a/tests/fontbackgroundcolor/fontbackgroundcolorui.js b/tests/fontbackgroundcolor/fontbackgroundcolorui.js
index 162236f..68f34d4 100644
--- a/tests/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/tests/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -8,9 +8,7 @@
import FontBackgroundColorEditing from './../../src/fontbackgroundcolor/fontbackgroundcolorediting';
import FontBackgroundColorUI from './../../src/fontbackgroundcolor/fontbackgroundcolorui';
import ColorUI from './../../src/ui/colorui';
-
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-
import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
describe( 'FontBckgroundColorUI', () => {
diff --git a/tests/fontcolor/fontcolorcommand.js b/tests/fontcolor/fontcolorcommand.js
index ae9cf29..f538198 100644
--- a/tests/fontcolor/fontcolorcommand.js
+++ b/tests/fontcolor/fontcolorcommand.js
@@ -5,7 +5,6 @@
import FontColorCommand from '../../src/fontcolor/fontcolorcommand';
import FontCommand from '../../src/fontcommand';
-
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
describe( 'FontColorCommand', () => {
diff --git a/tests/fontcolor/fontcolorediting.js b/tests/fontcolor/fontcolorediting.js
index a32263c..c3f900c 100644
--- a/tests/fontcolor/fontcolorediting.js
+++ b/tests/fontcolor/fontcolorediting.js
@@ -4,11 +4,12 @@
*/
import FontColorEditing from './../../src/fontcolor/fontcolorediting';
-
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
-
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
-import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import {
+ getData as getModelData,
+ setData as setModelData
+} from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
describe( 'FontColorEditing', () => {
let editor, doc;
@@ -31,7 +32,6 @@ describe( 'FontColorEditing', () => {
it( 'should set proper schema rules', () => {
expect( editor.model.schema.checkAttribute( [ '$block', '$text' ], 'fontColor' ) ).to.be.true;
expect( editor.model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'fontColor' ) ).to.be.true;
-
expect( editor.model.schema.checkAttribute( [ '$block' ], 'fontColor' ) ).to.be.false;
} );
@@ -181,7 +181,6 @@ describe( 'FontColorEditing', () => {
editor.setData( data );
expect( getModelData( doc ) ).to.equal( '[]f<$text fontColor="rgb(10,20,30)">o$text>o' );
-
expect( editor.getData() ).to.equal( '
foo
' );
} );
diff --git a/tests/fontcolor/fontcolorui.js b/tests/fontcolor/fontcolorui.js
index 88bf0b5..0bbdaf8 100644
--- a/tests/fontcolor/fontcolorui.js
+++ b/tests/fontcolor/fontcolorui.js
@@ -8,9 +8,7 @@
import FontColorEditing from './../../src/fontcolor/fontcolorediting';
import FontColorUI from './../../src/fontcolor/fontcolorui';
import ColorUI from './../../src/ui/colorui';
-
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
-
import fontColorIcon from '../../theme/icons/font-color.svg';
describe( 'FontColorUI', () => {
From 372ece40bb4ca08924b246dc8fc674f469acc634 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 13:56:41 +0100
Subject: [PATCH 63/92] Tests: Code refactoring.
---
tests/ui/colorgrid.js | 5 +++--
tests/ui/colortableview.js | 5 +++++
tests/ui/colortile.js | 6 +++---
tests/ui/colorui.js | 31 +++++++++++++++++++------------
4 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/tests/ui/colorgrid.js b/tests/ui/colorgrid.js
index c0ddfac..93a569d 100644
--- a/tests/ui/colorgrid.js
+++ b/tests/ui/colorgrid.js
@@ -11,10 +11,11 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import ColorTile from '../../src/ui/colortile';
-
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'ColorGrid', () => {
+ let locale, colorGrid;
+
const colorsDefinition = [
{
color: '#000',
@@ -36,7 +37,6 @@ describe( 'ColorGrid', () => {
}
}
];
- let locale, colorGrid;
beforeEach( () => {
locale = { t() {} };
@@ -145,6 +145,7 @@ describe( 'ColorGrid', () => {
expect( colorGrid.items.length ).to.equal( 4 );
sinon.assert.calledOnce( spy );
} );
+
it( 'removes element', () => {
const spy = sinon.spy( colorGrid.focusTracker, 'remove' );
diff --git a/tests/ui/colortableview.js b/tests/ui/colortableview.js
index 645867a..2f0ebed 100644
--- a/tests/ui/colortableview.js
+++ b/tests/ui/colortableview.js
@@ -17,6 +17,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'ColorTableView', () => {
let locale, colorTableView;
+
const colorsDefinition = [
{
color: '#000',
@@ -142,6 +143,7 @@ describe( 'ColorTableView', () => {
describe( 'static colors grid', () => {
let staticColorTable;
+
beforeEach( () => {
staticColorTable = colorTableView.items.get( 1 );
} );
@@ -187,6 +189,7 @@ describe( 'ColorTableView', () => {
isEnabled: false,
hasBorder: true
};
+
let recentColorsGridView, recentColorModel;
beforeEach( () => {
@@ -198,10 +201,12 @@ describe( 'ColorTableView', () => {
it( 'has proper length of populated items', () => {
expect( recentColorModel.length ).to.equal( 5 );
} );
+
for ( let i = 0; i < 5; i++ ) {
it( `initialized item with index: "${ i }" has proper attributes`, () => {
const modelItem = recentColorModel.get( i );
const viewItem = recentColorsGridView.items.get( i );
+
expect( modelItem.color ).to.equal( 'hsla(0, 0%, 0%, 0)' );
expect( modelItem.isEnabled ).to.be.false;
expect( modelItem.hasBorder ).to.be.true;
diff --git a/tests/ui/colortile.js b/tests/ui/colortile.js
index 3bb5d70..9dbe5b9 100644
--- a/tests/ui/colortile.js
+++ b/tests/ui/colortile.js
@@ -7,14 +7,14 @@ import ColorTile from './../../src/ui/colortile';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
describe( 'ColorTile', () => {
- it( 'inhertence from ButtonView', () => {
- const colorTile = new ColorTile();
- expect( colorTile ).to.be.instanceOf( ButtonView );
+ it( 'inherits from ButtonView', () => {
+ expect( new ColorTile() ).to.be.instanceOf( ButtonView );
} );
it( 'has proper attributes and classes', () => {
const colorTile = new ColorTile();
colorTile.render();
+
expect( colorTile.color ).to.be.undefined;
expect( colorTile.hasBorder ).to.be.undefined;
diff --git a/tests/ui/colorui.js b/tests/ui/colorui.js
index b89961f..09bd03a 100644
--- a/tests/ui/colorui.js
+++ b/tests/ui/colorui.js
@@ -21,12 +21,10 @@ describe( 'ColorUI', () => {
icon: '',
dropdownLabel: 'Test Color'
} );
+
editor.commands.add( 'testColorCommand', new FontColorCommand( editor ) );
}
- /**
- * @inheritDoc
- */
static get pluginName() {
return 'TestColorPlugin';
}
@@ -37,14 +35,17 @@ describe( 'ColorUI', () => {
'yellow',
{
color: '#000',
- }, {
+ },
+ {
color: 'rgb(255, 255, 255)',
label: 'White',
hasBorder: true
- }, {
+ },
+ {
color: 'red',
label: 'RED'
- }, {
+ },
+ {
color: '#00FF00',
label: 'Green',
hasBorder: false
@@ -194,7 +195,7 @@ describe( 'ColorUI', () => {
describe( 'localization', () => {
beforeEach( () => {
- return localizedEditor();
+ return createLocalizedEditor();
} );
it( 'works for the #buttonView', () => {
@@ -214,16 +215,20 @@ describe( 'ColorUI', () => {
{
color: 'yellow',
label: 'żółty'
- }, {
+ },
+ {
color: '#000',
label: '#000'
- }, {
+ },
+ {
color: 'rgb(255,255,255)',
label: 'Biały'
- }, {
+ },
+ {
color: 'red',
label: 'CZERWONY'
- }, {
+ },
+ {
color: '#00FF00',
label: 'Zielony'
}
@@ -233,11 +238,13 @@ describe( 'ColorUI', () => {
it( `tested color ${ test.color } with name ${ test.label }.`, () => {
const colorGrid = dropdown.colorTableView.items.get( 1 );
const tile = colorGrid.items.find( colorTile => test.color === colorTile.color );
+
expect( tile.label ).to.equal( test.label );
} );
} );
} );
- function localizedEditor() {
+
+ function createLocalizedEditor() {
const editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );
From 3b7af4476182c4f6493f0cea456283415f23ce67 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 14:05:32 +0100
Subject: [PATCH 64/92] Code refactoring: Used spacings from _spacing.css in
the color grid.
---
theme/fontcolor.css | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/theme/fontcolor.css b/theme/fontcolor.css
index 2bd33ed..cc96a63 100644
--- a/theme/fontcolor.css
+++ b/theme/fontcolor.css
@@ -6,16 +6,14 @@
:root {
--ck-table-color-tile-size: 20px;
--ck-table-color-max-columns: 5;
- --ck-table-color-padding: 10px;
-
--ck-color-table-color-tile-border: hsl(0, 0%, 90%);
--ck-color-table-color-tile-border-active: hsl(184, 80%, 50%);
}
.ck .ck-color-table__grid-container {
display: grid;
- grid-gap: calc( var(--ck-table-color-padding) / 2 );
- padding: var(--ck-table-color-padding);
+ grid-gap: calc( var(--ck-spacing-standard) / 2 );
+ padding: var(--ck-spacing-standard);
}
.ck .ck-color-table__color-tile {
@@ -46,10 +44,9 @@
align-items: center;
width: 100%;
border-bottom: 1px solid var(--ck-color-base-border);
- padding: calc(var(--ck-table-color-padding) / 2 ) var(--ck-table-color-padding);
+ padding: calc(var(--ck-spacing-standard) / 2 ) var(--ck-spacing-standard);
}
.ck .ck-button.ck-button_with-text.ck-color-table__remove-color svg {
- width: var(--ck-table-color-tile-size);
- margin-right: var(--ck-spacing-large);
+ margin-right: var(--ck-spacing-standard);
}
From a2d169e6cac33f828581ec740aaa000223a58ca7 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 15:06:34 +0100
Subject: [PATCH 65/92] Fixed broken color localization. Code refactoring.
---
src/fontbackgroundcolor.js | 42 +++++++++-----
.../fontbackgroundcolorediting.js | 42 +++++++++-----
src/fontcolor.js | 42 +++++++++-----
src/fontcolor/fontcolorediting.js | 42 +++++++++-----
src/ui/colorgrid.js | 45 ++++++++-------
src/ui/colorui.js | 37 +++---------
src/utils.js | 43 ++++++++++++++
.../fontbackgroundcoloreditng.js | 54 ++++++++++++------
tests/fontcolor/fontcolorediting.js | 54 ++++++++++++------
tests/ui/colorgrid.js | 6 +-
tests/ui/colortableview.js | 12 ++--
tests/ui/colorui.js | 57 +++++++++----------
tests/utils.js | 18 ++++--
13 files changed, 306 insertions(+), 188 deletions(-)
diff --git a/src/fontbackgroundcolor.js b/src/fontbackgroundcolor.js
index 3810869..8bf1b37 100644
--- a/src/fontbackgroundcolor.js
+++ b/src/fontbackgroundcolor.js
@@ -62,47 +62,61 @@ export default class FontBackgroundColor extends Plugin {
* {
* color: 'hsl(0, 0%, 0%)',
* label: 'Black'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 30%)',
* label: 'Dim grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 60%)',
* label: 'Grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 100%)',
* label: 'White',
* hasBorder: true
- * }, {
+ * },
+ * {
* color: 'hsl(0, 75%, 60%)',
* label: 'Red'
- * }, {
+ * },
+ * {
* color: 'hsl(30, 75%, 60%)',
* label: 'Orange'
- * }, {
+ * },
+ * {
* color: 'hsl(60, 75%, 60%)',
* label: 'Yellow'
- * }, {
+ * },
+ * {
* color: 'hsl(90, 75%, 60%)',
* label: 'Light green'
- * }, {
+ * },
+ * {
* color: 'hsl(120, 75%, 60%)',
* label: 'Green'
- * }, {
+ * },
+ * {
* color: 'hsl(150, 75%, 60%)',
* label: 'Aquamarine'
- * }, {
+ * },
+ * {
* color: 'hsl(180, 75%, 60%)',
* label: 'Turquoise'
- * }, {
+ * },
+ * {
* color: 'hsl(210, 75%, 60%)',
* label: 'Light blue'
- * }, {
+ * },
+ * {
* color: 'hsl(240, 75%, 60%)',
* label: 'Blue'
- * }, {
+ * },
+ * {
* color: 'hsl(270, 75%, 60%)',
* label: 'Purple'
* }
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorediting.js b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
index 7319117..ba338f9 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorediting.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorediting.js
@@ -33,47 +33,61 @@ export default class FontBackgroundColorEditing extends Plugin {
{
color: 'hsl(0, 0%, 0%)',
label: 'Black'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 30%)',
label: 'Dim grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 60%)',
label: 'Grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 90%)',
label: 'Light grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 100%)',
label: 'White',
hasBorder: true
- }, {
+ },
+ {
color: 'hsl(0, 75%, 60%)',
label: 'Red'
- }, {
+ },
+ {
color: 'hsl(30, 75%, 60%)',
label: 'Orange'
- }, {
+ },
+ {
color: 'hsl(60, 75%, 60%)',
label: 'Yellow'
- }, {
+ },
+ {
color: 'hsl(90, 75%, 60%)',
label: 'Light green'
- }, {
+ },
+ {
color: 'hsl(120, 75%, 60%)',
label: 'Green'
- }, {
+ },
+ {
color: 'hsl(150, 75%, 60%)',
label: 'Aquamarine'
- }, {
+ },
+ {
color: 'hsl(180, 75%, 60%)',
label: 'Turquoise'
- }, {
+ },
+ {
color: 'hsl(210, 75%, 60%)',
label: 'Light blue'
- }, {
+ },
+ {
color: 'hsl(240, 75%, 60%)',
label: 'Blue'
- }, {
+ },
+ {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
diff --git a/src/fontcolor.js b/src/fontcolor.js
index 2d0067d..86c59e6 100644
--- a/src/fontcolor.js
+++ b/src/fontcolor.js
@@ -61,47 +61,61 @@ export default class FontColor extends Plugin {
* {
* color: 'hsl(0, 0%, 0%)',
* label: 'Black'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 30%)',
* label: 'Dim grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 60%)',
* label: 'Grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 90%)',
* label: 'Light grey'
- * }, {
+ * },
+ * {
* color: 'hsl(0, 0%, 100%)',
* label: 'White',
* hasBorder: true
- * }, {
+ * },
+ * {
* color: 'hsl(0, 75%, 60%)',
* label: 'Red'
- * }, {
+ * },
+ * {
* color: 'hsl(30, 75%, 60%)',
* label: 'Orange'
- * }, {
+ * },
+ * {
* color: 'hsl(60, 75%, 60%)',
* label: 'Yellow'
- * }, {
+ * },
+ * {
* color: 'hsl(90, 75%, 60%)',
* label: 'Light green'
- * }, {
+ * },
+ * {
* color: 'hsl(120, 75%, 60%)',
* label: 'Green'
- * }, {
+ * },
+ * {
* color: 'hsl(150, 75%, 60%)',
* label: 'Aquamarine'
- * }, {
+ * },
+ * {
* color: 'hsl(180, 75%, 60%)',
* label: 'Turquoise'
- * }, {
+ * },
+ * {
* color: 'hsl(210, 75%, 60%)',
* label: 'Light blue'
- * }, {
+ * },
+ * {
* color: 'hsl(240, 75%, 60%)',
* label: 'Blue'
- * }, {
+ * },
+ * {
* color: 'hsl(270, 75%, 60%)',
* label: 'Purple'
* }
diff --git a/src/fontcolor/fontcolorediting.js b/src/fontcolor/fontcolorediting.js
index d08d550..ea5eb18 100644
--- a/src/fontcolor/fontcolorediting.js
+++ b/src/fontcolor/fontcolorediting.js
@@ -33,47 +33,61 @@ export default class FontColorEditing extends Plugin {
{
color: 'hsl(0, 0%, 0%)',
label: 'Black'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 30%)',
label: 'Dim grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 60%)',
label: 'Grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 90%)',
label: 'Light grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 100%)',
label: 'White',
hasBorder: true
- }, {
+ },
+ {
color: 'hsl(0, 75%, 60%)',
label: 'Red'
- }, {
+ },
+ {
color: 'hsl(30, 75%, 60%)',
label: 'Orange'
- }, {
+ },
+ {
color: 'hsl(60, 75%, 60%)',
label: 'Yellow'
- }, {
+ },
+ {
color: 'hsl(90, 75%, 60%)',
label: 'Light green'
- }, {
+ },
+ {
color: 'hsl(120, 75%, 60%)',
label: 'Green'
- }, {
+ },
+ {
color: 'hsl(150, 75%, 60%)',
label: 'Aquamarine'
- }, {
+ },
+ {
color: 'hsl(180, 75%, 60%)',
label: 'Turquoise'
- }, {
+ },
+ {
color: 'hsl(210, 75%, 60%)',
label: 'Light blue'
- }, {
+ },
+ {
color: 'hsl(240, 75%, 60%)',
label: 'Blue'
- }, {
+ },
+ {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
index 1103361..8c1e353 100644
--- a/src/ui/colorgrid.js
+++ b/src/ui/colorgrid.js
@@ -23,11 +23,12 @@ export default class ColorGrid extends View {
* Creates an instance of a color grid containing {@link module:font/ui/colortile~ColorTile}.
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
- * @param {Object} config Configuration
- * @param {Array.} colorsDefinition Array with definitions
- * required to build {@link module:font/ui/colortile~ColorTile}.
+ * @param {Object} options Component configuration
+ * @param {Array.} [options.colorsDefinition] Array with definitions
+ * required to create the {@link module:font/ui/colortile~ColorTile tiles}.
+ * @param {Number} options.colorColumns A number of columns to display the tiles.
*/
- constructor( locale, { colorsDefinition = [], colorColumns } = {} ) {
+ constructor( locale, options ) {
super( locale );
/**
@@ -74,26 +75,28 @@ export default class ColorGrid extends View {
}
} );
- colorsDefinition.forEach( item => {
- const colorTile = new ColorTile();
+ if ( options.colorsDefinition ) {
+ options.colorsDefinition.forEach( item => {
+ const colorTile = new ColorTile();
- colorTile.set( {
- color: item.color,
- label: item.label,
- tooltip: true,
- hasBorder: item.options.hasBorder
- } );
+ colorTile.set( {
+ color: item.color,
+ label: item.label,
+ tooltip: true,
+ hasBorder: item.options.hasBorder
+ } );
- colorTile.on( 'execute', () => {
- this.fire( 'execute', {
- value: item.color,
- hasBorder: item.options.hasBorder,
- label: item.label
+ colorTile.on( 'execute', () => {
+ this.fire( 'execute', {
+ value: item.color,
+ hasBorder: item.options.hasBorder,
+ label: item.label
+ } );
} );
- } );
- this.items.add( colorTile );
- } );
+ this.items.add( colorTile );
+ } );
+ }
this.setTemplate( {
tag: 'div',
@@ -101,7 +104,7 @@ export default class ColorGrid extends View {
attributes: {
class: 'ck-color-table__grid-container',
style: {
- gridTemplateColumns: `repeat( ${ colorColumns }, 1fr)`
+ gridTemplateColumns: `repeat( ${ options.colorColumns }, 1fr)`
}
}
} );
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index 8af0462..2f96ef5 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -10,8 +10,8 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import {
- normalizeOptions,
- addColorsToDropdown
+ addColorsToDropdown,
+ getLocalizedColorOptions
} from '../utils';
/**
@@ -74,18 +74,18 @@ export default class ColorUI extends Plugin {
const editor = this.editor;
const t = editor.t;
const command = editor.commands.get( this.commandName );
- const options = this._getLocalizedOptions();
+ const options = getLocalizedColorOptions( editor, this.componentName );
// Register UI component.
editor.ui.componentFactory.add( this.componentName, locale => {
const dropdownView = createDropdown( locale );
const colorTableView = addColorsToDropdown( {
dropdownView,
- colors: options.map( element => ( {
- label: element.label,
- color: element.model,
+ colors: options.map( option => ( {
+ label: option.label,
+ color: option.model,
options: {
- hasBorder: element.hasBorder
+ hasBorder: option.hasBorder
}
} ) ),
colorColumns: this.colorColumns,
@@ -124,27 +124,4 @@ export default class ColorUI extends Plugin {
return dropdownView;
} );
}
-
- /**
- * Returns options as defined in the `editor.config` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
- * or {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig} in the correct language.
- *
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
- * when the user configuration is defined because the editor does not exist yet.
- *
- * @private
- * @returns {Array.|Array.}.
- */
- _getLocalizedOptions() {
- const editor = this.editor;
- const t = editor.t;
- const options = normalizeOptions( editor.config.get( `${ this.componentName }.colors` ) );
-
- options.forEach( option => {
- option.label = t( option.label );
- } );
-
- return options;
- }
}
diff --git a/src/utils.js b/src/utils.js
index 441b288..7bb4c6e 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -107,6 +107,49 @@ export function addColorsToDropdown( { dropdownView, colors, colorColumns, remov
return colorTableView;
}
+/**
+ * Returns configuration options as defined in the `editor.config[ featureName ]` but processed to account for
+ * editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
+ * or {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig} in the correct language.
+ *
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
+ * when the user configuration is defined because the editor does not exist yet.
+ *
+ * @param {module:core/editor/editor~Editor} editor An editor instance.
+ * @param {String} featureName Determines which config (`editor.config[ featureName ]`) colors to localize.
+ * @returns {Array.|Array.}.
+ */
+export function getLocalizedColorOptions( editor, featureName ) {
+ const t = editor.t;
+ const localizedColorNames = {
+ Black: t( 'Black' ),
+ 'Dim grey': t( 'Dim grey' ),
+ Grey: t( 'Grey' ),
+ 'Light grey': t( 'Light grey' ),
+ White: t( 'White' ),
+ Red: t( 'Red' ),
+ Orange: t( 'Orange' ),
+ Yellow: t( 'Yellow' ),
+ 'Light green': t( 'Light green' ),
+ Green: t( 'Green' ),
+ Aquamarine: t( 'Aquamarine' ),
+ Turquoise: t( 'Turquoise' ),
+ 'Light blue': t( 'Light blue' ),
+ Blue: t( 'Blue' ),
+ Purple: t( 'Purple' )
+ };
+
+ return normalizeOptions( editor.config.get( featureName ).colors ).map( colorOption => {
+ const label = localizedColorNames[ colorOption.label ];
+
+ if ( label && label != colorOption.label ) {
+ colorOption.label = label;
+ }
+
+ return colorOption;
+ } );
+}
+
function normalizeSingleColorDefinition( color ) {
if ( typeof color === 'string' ) {
return {
diff --git a/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js b/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
index 8bcbf94..783ef84 100644
--- a/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
+++ b/tests/fontbackgroundcolor/fontbackgroundcoloreditng.js
@@ -43,47 +43,61 @@ describe( 'FontBackgroundColorEditing', () => {
{
color: 'hsl(0, 0%, 0%)',
label: 'Black'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 30%)',
label: 'Dim grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 60%)',
label: 'Grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 90%)',
label: 'Light grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 100%)',
label: 'White',
hasBorder: true
- }, {
+ },
+ {
color: 'hsl(0, 75%, 60%)',
label: 'Red'
- }, {
+ },
+ {
color: 'hsl(30, 75%, 60%)',
label: 'Orange'
- }, {
+ },
+ {
color: 'hsl(60, 75%, 60%)',
label: 'Yellow'
- }, {
+ },
+ {
color: 'hsl(90, 75%, 60%)',
label: 'Light green'
- }, {
+ },
+ {
color: 'hsl(120, 75%, 60%)',
label: 'Green'
- }, {
+ },
+ {
color: 'hsl(150, 75%, 60%)',
label: 'Aquamarine'
- }, {
+ },
+ {
color: 'hsl(180, 75%, 60%)',
label: 'Turquoise'
- }, {
+ },
+ {
color: 'hsl(210, 75%, 60%)',
label: 'Light blue'
- }, {
+ },
+ {
color: 'hsl(240, 75%, 60%)',
label: 'Blue'
- }, {
+ },
+ {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
@@ -102,10 +116,12 @@ describe( 'FontBackgroundColorEditing', () => {
{
label: 'Color1',
color: '#000'
- }, {
+ },
+ {
label: 'Color2',
color: '#123456'
- }, {
+ },
+ {
label: 'Color3',
color: 'rgb( 0, 10, 20 )'
},
@@ -155,10 +171,12 @@ describe( 'FontBackgroundColorEditing', () => {
{
label: 'Color1',
color: '#000'
- }, {
+ },
+ {
label: 'Color2',
color: '#123456'
- }, {
+ },
+ {
label: 'Color3',
color: 'rgb( 0, 10, 20 )'
},
diff --git a/tests/fontcolor/fontcolorediting.js b/tests/fontcolor/fontcolorediting.js
index c3f900c..ec54518 100644
--- a/tests/fontcolor/fontcolorediting.js
+++ b/tests/fontcolor/fontcolorediting.js
@@ -42,47 +42,61 @@ describe( 'FontColorEditing', () => {
{
color: 'hsl(0, 0%, 0%)',
label: 'Black'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 30%)',
label: 'Dim grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 60%)',
label: 'Grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 90%)',
label: 'Light grey'
- }, {
+ },
+ {
color: 'hsl(0, 0%, 100%)',
label: 'White',
hasBorder: true
- }, {
+ },
+ {
color: 'hsl(0, 75%, 60%)',
label: 'Red'
- }, {
+ },
+ {
color: 'hsl(30, 75%, 60%)',
label: 'Orange'
- }, {
+ },
+ {
color: 'hsl(60, 75%, 60%)',
label: 'Yellow'
- }, {
+ },
+ {
color: 'hsl(90, 75%, 60%)',
label: 'Light green'
- }, {
+ },
+ {
color: 'hsl(120, 75%, 60%)',
label: 'Green'
- }, {
+ },
+ {
color: 'hsl(150, 75%, 60%)',
label: 'Aquamarine'
- }, {
+ },
+ {
color: 'hsl(180, 75%, 60%)',
label: 'Turquoise'
- }, {
+ },
+ {
color: 'hsl(210, 75%, 60%)',
label: 'Light blue'
- }, {
+ },
+ {
color: 'hsl(240, 75%, 60%)',
label: 'Blue'
- }, {
+ },
+ {
color: 'hsl(270, 75%, 60%)',
label: 'Purple'
}
@@ -101,10 +115,12 @@ describe( 'FontColorEditing', () => {
{
label: 'Color1',
color: '#000'
- }, {
+ },
+ {
label: 'Color2',
color: '#123456'
- }, {
+ },
+ {
label: 'Color3',
color: 'rgb( 0, 10, 20 )'
},
@@ -153,10 +169,12 @@ describe( 'FontColorEditing', () => {
{
label: 'Color1',
color: '#000'
- }, {
+ },
+ {
label: 'Color2',
color: '#123456'
- }, {
+ },
+ {
label: 'Color3',
color: 'rgb( 0, 10, 20 )'
},
diff --git a/tests/ui/colorgrid.js b/tests/ui/colorgrid.js
index 93a569d..c5660b4 100644
--- a/tests/ui/colorgrid.js
+++ b/tests/ui/colorgrid.js
@@ -23,13 +23,15 @@ describe( 'ColorGrid', () => {
options: {
hasBorder: false
}
- }, {
+ },
+ {
color: 'rgb(255, 255, 255)',
label: 'White',
options: {
hasBorder: true
}
- }, {
+ },
+ {
color: 'red',
label: 'Red',
options: {
diff --git a/tests/ui/colortableview.js b/tests/ui/colortableview.js
index 2f0ebed..36ccae0 100644
--- a/tests/ui/colortableview.js
+++ b/tests/ui/colortableview.js
@@ -12,7 +12,6 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import removeButtonIcon from '@ckeditor/ckeditor5-core/theme/icons/eraser.svg';
-
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'ColorTableView', () => {
@@ -25,7 +24,8 @@ describe( 'ColorTableView', () => {
options: {
hasBorder: false
}
- }, {
+ },
+ {
color: 'rgb(255, 255, 255)',
label: 'White',
options: {
@@ -45,7 +45,7 @@ describe( 'ColorTableView', () => {
colorTableView = new ColorTableView( locale, {
colors: colorsDefinition,
colorColumns: 5,
- removeButtonTooltip: 'Remove color'
+ removeButtonLabel: 'Remove color'
} );
colorTableView.render();
} );
@@ -73,11 +73,11 @@ describe( 'ColorTableView', () => {
expect( colorTableView.selectedColor ).to.equal( 'white' );
} );
- it( 'keep tooltip for remove color button', () => {
- expect( colorTableView.removeButtonTooltip ).to.equal( 'Remove color' );
+ it( 'sets tooltip for the remove color button', () => {
+ expect( colorTableView.removeButtonLabel ).to.equal( 'Remove color' );
} );
- it( 'keep number of drawed columns', () => {
+ it( 'sets number of drawed columns', () => {
expect( colorTableView.colorColumns ).to.equal( 5 );
} );
diff --git a/tests/ui/colorui.js b/tests/ui/colorui.js
index 09bd03a..1de6ad4 100644
--- a/tests/ui/colorui.js
+++ b/tests/ui/colorui.js
@@ -19,7 +19,7 @@ describe( 'ColorUI', () => {
commandName: 'testColorCommand',
componentName: 'testColor',
icon: '',
- dropdownLabel: 'Test Color'
+ dropdownLabel: editor.locale.t( 'Test Color' )
} );
editor.commands.add( 'testColorCommand', new FontColorCommand( editor ) );
@@ -43,7 +43,7 @@ describe( 'ColorUI', () => {
},
{
color: 'red',
- label: 'RED'
+ label: 'Red'
},
{
color: '#00FF00',
@@ -57,21 +57,12 @@ describe( 'ColorUI', () => {
testUtils.createSinonSandbox();
before( () => {
- addTranslations( 'en', {
- 'Test Color': 'Test Color',
- 'Remove color': 'Remove color',
- 'yellow': 'yellow',
- 'White': 'White',
- 'RED': 'RED',
- 'Green': 'Green'
- } );
-
addTranslations( 'pl', {
- 'Test Color': 'Testowy plugin do kolorów',
+ 'Test Color': 'Testowy plugin',
'Remove color': 'Usuń kolor',
- 'yellow': 'żółty',
+ 'Yellow': 'Żółty',
'White': 'Biały',
- 'RED': 'CZERWONY',
+ 'Red': 'Czerwony',
'Green': 'Zielony'
} );
} );
@@ -117,7 +108,7 @@ describe( 'ColorUI', () => {
} );
it( 'has assigned proper dropdownLabel', () => {
- expect( testColorPlugin.dropdownLabel ).to.equal( 'Test Color' );
+ expect( testColorPlugin.dropdownLabel ).to.equal( 'Testowy plugin' );
} );
it( 'has assigned proper amount of columns', () => {
@@ -137,7 +128,7 @@ describe( 'ColorUI', () => {
it( 'button has the base properties', () => {
const button = dropdown.buttonView;
- expect( button ).to.have.property( 'label', 'Test Color' );
+ expect( button ).to.have.property( 'label', 'Testowy plugin' );
expect( button ).to.have.property( 'tooltip', true );
expect( button ).to.have.property( 'icon', '' );
} );
@@ -194,19 +185,28 @@ describe( 'ColorUI', () => {
} );
describe( 'localization', () => {
+ let editor, editorElement;
+
beforeEach( () => {
- return createLocalizedEditor();
+ editorElement = document.createElement( 'div' );
+ document.body.appendChild( editorElement );
+
+ return createLocalizedEditor( editorElement )
+ .then( localizedEditor => {
+ editor = localizedEditor;
+ } );
} );
- it( 'works for the #buttonView', () => {
- const buttonView = dropdown.buttonView;
+ afterEach( () => {
+ editorElement.remove();
- expect( buttonView.label ).to.equal( 'Testowy plugin do kolorów' );
+ return editor.destroy();
} );
it( 'works for the colorTableView#items in the panel', () => {
const colorTableView = dropdown.colorTableView;
- expect( colorTableView.removeButtonTooltip ).to.equal( 'Usuń kolor' );
+
+ expect( colorTableView.removeButtonLabel ).to.equal( 'Usuń kolor' );
expect( colorTableView.items.first.label ).to.equal( 'Usuń kolor' );
} );
@@ -214,7 +214,7 @@ describe( 'ColorUI', () => {
const colors = [
{
color: 'yellow',
- label: 'żółty'
+ label: 'yellow'
},
{
color: '#000',
@@ -226,7 +226,7 @@ describe( 'ColorUI', () => {
},
{
color: 'red',
- label: 'CZERWONY'
+ label: 'Czerwony'
},
{
color: '#00FF00',
@@ -235,7 +235,7 @@ describe( 'ColorUI', () => {
];
colors.forEach( test => {
- it( `tested color ${ test.color } with name ${ test.label }.`, () => {
+ it( `tested color "${ test.color }" translated to "${ test.label }".`, () => {
const colorGrid = dropdown.colorTableView.items.get( 1 );
const tile = colorGrid.items.find( colorTile => test.color === colorTile.color );
@@ -244,10 +244,7 @@ describe( 'ColorUI', () => {
} );
} );
- function createLocalizedEditor() {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
-
+ function createLocalizedEditor( editorElement ) {
return ClassicTestEditor
.create( editorElement, {
plugins: [ TestColorPlugin ],
@@ -260,9 +257,7 @@ describe( 'ColorUI', () => {
dropdown = editor.ui.componentFactory.create( 'testColor' );
command = editor.commands.get( 'testColorCommand' );
- editorElement.remove();
-
- return editor.destroy();
+ return editor;
} );
}
} );
diff --git a/tests/utils.js b/tests/utils.js
index bb865d2..2f4c186 100644
--- a/tests/utils.js
+++ b/tests/utils.js
@@ -19,14 +19,17 @@ describe( 'utils', () => {
'black',
{
color: 'black'
- }, {
+ },
+ {
color: 'black',
label: 'Black'
- }, {
+ },
+ {
color: 'black',
label: 'Black',
hasBorder: true
- }, {
+ },
+ {
color: 'black',
hasBorder: true
}
@@ -44,7 +47,8 @@ describe( 'utils', () => {
},
priority: 5
}
- }, {
+ },
+ {
model: 'black',
label: 'black',
hasBorder: false,
@@ -55,7 +59,8 @@ describe( 'utils', () => {
},
priority: 5
}
- }, {
+ },
+ {
model: 'black',
label: 'Black',
hasBorder: false,
@@ -107,7 +112,8 @@ describe( 'utils', () => {
options: {
hasBorder: false
}
- }, {
+ },
+ {
label: 'White',
color: '#FFFFFF',
options: {
From 5de2862f625578a3658f45c772ed76088fa1d7e8 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 15:15:40 +0100
Subject: [PATCH 66/92] Code refactoring and documentation.
---
src/ui/colorgrid.js | 12 ++++----
src/ui/colortableview.js | 30 +++++++++++--------
src/ui/colorui.js | 8 ++---
src/utils.js | 9 ++++--
.../fontbackgroundcolorui.js | 2 +-
tests/fontcolor/fontcolorui.js | 2 +-
tests/ui/colorgrid.js | 6 ++--
tests/ui/colortableview.js | 10 +++----
tests/ui/colorui.js | 2 +-
tests/utils.js | 6 ++--
10 files changed, 47 insertions(+), 40 deletions(-)
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
index 8c1e353..6a0df53 100644
--- a/src/ui/colorgrid.js
+++ b/src/ui/colorgrid.js
@@ -14,7 +14,7 @@ import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
/**
- * A grid of {@link module:font/ui/colortile~ColorTile}.
+ * A grid of {@link module:font/ui/colortile~ColorTile color tiles}.
*
* @extends module:ui/view~View
*/
@@ -24,9 +24,9 @@ export default class ColorGrid extends View {
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
* @param {Object} options Component configuration
- * @param {Array.} [options.colorsDefinition] Array with definitions
+ * @param {Array.} [options.colorDefinitions] Array with definitions
* required to create the {@link module:font/ui/colortile~ColorTile tiles}.
- * @param {Number} options.colorColumns A number of columns to display the tiles.
+ * @param {Number} options.columns A number of columns to display the tiles.
*/
constructor( locale, options ) {
super( locale );
@@ -75,8 +75,8 @@ export default class ColorGrid extends View {
}
} );
- if ( options.colorsDefinition ) {
- options.colorsDefinition.forEach( item => {
+ if ( options.colorDefinitions ) {
+ options.colorDefinitions.forEach( item => {
const colorTile = new ColorTile();
colorTile.set( {
@@ -104,7 +104,7 @@ export default class ColorGrid extends View {
attributes: {
class: 'ck-color-table__grid-container',
style: {
- gridTemplateColumns: `repeat( ${ options.colorColumns }, 1fr)`
+ gridTemplateColumns: `repeat( ${ options.columns }, 1fr)`
}
}
} );
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index 00cff05..b9cbab5 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -19,8 +19,11 @@ import removeButtonIcon from '@ckeditor/ckeditor5-core/theme/icons/eraser.svg';
import '../../theme/fontcolor.css';
/**
- * Class which represents a view with {@link module:font/ui/colorgrid~ColorGrid}
- * and remove color buttons.
+ * Class which represents a view with the following sub–components:
+ *
+ * * a remove color button,
+ * * a {@link module:font/ui/colorgrid~ColorGrid},
+ * * a grid of recently used colors.
*
* @extends module:ui/view~View
*/
@@ -30,12 +33,13 @@ export default class ColorTableView extends View {
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
* @param {Object} config Configuration object
- * @param {Array.} config.colors Array with definitions of colors to be displayed in the table.
- * @param {Number} config.colorColumns Number of columns in the color grid.
+ * @param {Array.} config.colors Array with definitions of colors to
+ * be displayed in the table.
+ * @param {Number} config.columns Number of columns in the color grid.
* Also determines how many recent color will be displayed.
* @param {String} config.removeButtonLabel A label of a button responsible for removing the color.
*/
- constructor( locale, { colors, colorColumns, removeButtonLabel } ) {
+ constructor( locale, { colors, columns, removeButtonLabel } ) {
super( locale );
/**
@@ -49,9 +53,9 @@ export default class ColorTableView extends View {
/**
* An array with objects representing colors to be displayed in the grid.
*
- * @type {Arrray.}
+ * @type {Arrray.}
*/
- this.colorsDefinition = colors;
+ this.colorDefinitions = colors;
/**
* Tracks information about DOM focus in the list.
@@ -88,7 +92,7 @@ export default class ColorTableView extends View {
*
* @type {Number}
*/
- this.colorColumns = colorColumns;
+ this.columns = columns;
/**
* A collection storing definitions of recently used colors.
@@ -162,8 +166,8 @@ export default class ColorTableView extends View {
*/
createStaticColorTable() {
const colorGrid = new ColorGrid( this.locale, {
- colorsDefinition: this.colorsDefinition,
- colorColumns: this.colorColumns
+ colorDefinitions: this.colorDefinitions,
+ columns: this.columns
} );
colorGrid.delegate( 'execute' ).to( this );
@@ -177,7 +181,7 @@ export default class ColorTableView extends View {
* @private
*/
recentlyUsed() {
- const recentViews = new ColorGrid( this.locale, { colorColumns: this.colorColumns } );
+ const recentViews = new ColorGrid( this.locale, { columns: this.columns } );
recentViews.items.bindTo( this.recentlyUsedColors ).using(
colorObj => {
@@ -218,7 +222,7 @@ export default class ColorTableView extends View {
this.recentlyUsedColors.remove( duplicates[ 1 ] );
}
- if ( this.recentlyUsedColors.length > this.colorColumns ) {
+ if ( this.recentlyUsedColors.length > this.columns ) {
this.recentlyUsedColors.remove( this.recentlyUsedColors.length - 1 );
}
} );
@@ -235,7 +239,7 @@ export default class ColorTableView extends View {
* @private
*/
initRecentCollection() {
- for ( let i = 0; i < this.colorColumns; i++ ) {
+ for ( let i = 0; i < this.columns; i++ ) {
this.recentlyUsedColors.add( {
color: 'hsla(0, 0%, 0%, 0)',
isEnabled: false,
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index 2f96ef5..886b00d 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -10,7 +10,7 @@
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import {
- addColorsToDropdown,
+ addColorTableToDropdown,
getLocalizedColorOptions
} from '../utils';
@@ -64,7 +64,7 @@ export default class ColorUI extends Plugin {
* Number of columns in color grid. Determines the number of recent colors to be displayed.
* @type {Number}
*/
- this.colorColumns = editor.config.get( `${ this.componentName }.columns` );
+ this.columns = editor.config.get( `${ this.componentName }.columns` );
}
/**
@@ -79,7 +79,7 @@ export default class ColorUI extends Plugin {
// Register UI component.
editor.ui.componentFactory.add( this.componentName, locale => {
const dropdownView = createDropdown( locale );
- const colorTableView = addColorsToDropdown( {
+ const colorTableView = addColorTableToDropdown( {
dropdownView,
colors: options.map( option => ( {
label: option.label,
@@ -88,7 +88,7 @@ export default class ColorUI extends Plugin {
hasBorder: option.hasBorder
}
} ) ),
- colorColumns: this.colorColumns,
+ columns: this.columns,
removeButtonLabel: t( 'Remove color' )
} );
diff --git a/src/utils.js b/src/utils.js
index 7bb4c6e..03342cd 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -90,14 +90,17 @@ export function normalizeOptions( colorRow ) {
/**
* Helper which add {@link module:font/ui/colortableview~ColorTableView} to dropdown with proper initial values.
+ *
* @param {Object} config Configuration object
* @param {module:ui/dropdown/dropdownview~DropdownView} config.dropdownView Dropdown view to which
* will be added {@link module:font/ui/colortableview~ColorTableView}.
- * @param {Array.} Array with objects representing color to be drawn in color grid.
+ * @param {Array.} Array with definitions representing colors to be displayed
+ * in the color table.
+ * @returns {module:font/ui/colortableview~ColorTableView} The new color table view.
*/
-export function addColorsToDropdown( { dropdownView, colors, colorColumns, removeButtonLabel } ) {
+export function addColorTableToDropdown( { dropdownView, colors, columns, removeButtonLabel } ) {
const locale = dropdownView.locale;
- const colorTableView = new ColorTableView( locale, { colors, colorColumns, removeButtonLabel } );
+ const colorTableView = new ColorTableView( locale, { colors, columns, removeButtonLabel } );
dropdownView.colorTableView = colorTableView;
dropdownView.panelView.children.add( colorTableView );
diff --git a/tests/fontbackgroundcolor/fontbackgroundcolorui.js b/tests/fontbackgroundcolor/fontbackgroundcolorui.js
index 68f34d4..012ff80 100644
--- a/tests/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/tests/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -44,6 +44,6 @@ describe( 'FontBckgroundColorUI', () => {
expect( fontBackgroundColorUIPlugin.componentName ).to.equal( 'fontBackgroundColor' );
expect( fontBackgroundColorUIPlugin.icon ).to.equal( fontBackgroundColorIcon );
expect( fontBackgroundColorUIPlugin.dropdownLabel ).to.equal( 'Font Background Color' );
- expect( fontBackgroundColorUIPlugin.colorColumns ).to.equal( 5 );
+ expect( fontBackgroundColorUIPlugin.columns ).to.equal( 5 );
} );
} );
diff --git a/tests/fontcolor/fontcolorui.js b/tests/fontcolor/fontcolorui.js
index 0bbdaf8..c3f1bdd 100644
--- a/tests/fontcolor/fontcolorui.js
+++ b/tests/fontcolor/fontcolorui.js
@@ -44,6 +44,6 @@ describe( 'FontColorUI', () => {
expect( fontColorUIPlugin.componentName ).to.equal( 'fontColor' );
expect( fontColorUIPlugin.icon ).to.equal( fontColorIcon );
expect( fontColorUIPlugin.dropdownLabel ).to.equal( 'Font Color' );
- expect( fontColorUIPlugin.colorColumns ).to.equal( 5 );
+ expect( fontColorUIPlugin.columns ).to.equal( 5 );
} );
} );
diff --git a/tests/ui/colorgrid.js b/tests/ui/colorgrid.js
index c5660b4..bd410d9 100644
--- a/tests/ui/colorgrid.js
+++ b/tests/ui/colorgrid.js
@@ -16,7 +16,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'ColorGrid', () => {
let locale, colorGrid;
- const colorsDefinition = [
+ const colorDefinitions = [
{
color: '#000',
label: 'Black',
@@ -42,7 +42,7 @@ describe( 'ColorGrid', () => {
beforeEach( () => {
locale = { t() {} };
- colorGrid = new ColorGrid( locale, { colorsDefinition } );
+ colorGrid = new ColorGrid( locale, { colorDefinitions } );
colorGrid.render();
} );
@@ -69,7 +69,7 @@ describe( 'ColorGrid', () => {
it( 'has proper number of elements', () => {
expect( colorGrid.items.length ).to.equal( 3 );
} );
- colorsDefinition.forEach( ( color, index ) => {
+ colorDefinitions.forEach( ( color, index ) => {
describe( 'child items has proper attributes', () => {
it( `for (index: ${ index }, color: ${ color.color }) child`, () => {
const colorTile = colorGrid.items.get( index );
diff --git a/tests/ui/colortableview.js b/tests/ui/colortableview.js
index 36ccae0..a84972c 100644
--- a/tests/ui/colortableview.js
+++ b/tests/ui/colortableview.js
@@ -17,7 +17,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
describe( 'ColorTableView', () => {
let locale, colorTableView;
- const colorsDefinition = [
+ const colorDefinitions = [
{
color: '#000',
label: 'Black',
@@ -43,8 +43,8 @@ describe( 'ColorTableView', () => {
beforeEach( () => {
locale = { t() {} };
colorTableView = new ColorTableView( locale, {
- colors: colorsDefinition,
- colorColumns: 5,
+ colors: colorDefinitions,
+ columns: 5,
removeButtonLabel: 'Remove color'
} );
colorTableView.render();
@@ -78,7 +78,7 @@ describe( 'ColorTableView', () => {
} );
it( 'sets number of drawed columns', () => {
- expect( colorTableView.colorColumns ).to.equal( 5 );
+ expect( colorTableView.columns ).to.equal( 5 );
} );
it( 'creaets collection of recently used colors', () => {
@@ -152,7 +152,7 @@ describe( 'ColorTableView', () => {
expect( staticColorTable.items.length ).to.equal( 3 );
} );
- colorsDefinition.forEach( ( item, index ) => {
+ colorDefinitions.forEach( ( item, index ) => {
it( `dispatch event to parent element for color: ${ item.color }`, () => {
const spy = sinon.spy();
colorTableView.on( 'execute', spy );
diff --git a/tests/ui/colorui.js b/tests/ui/colorui.js
index 1de6ad4..bb845ea 100644
--- a/tests/ui/colorui.js
+++ b/tests/ui/colorui.js
@@ -113,7 +113,7 @@ describe( 'ColorUI', () => {
it( 'has assigned proper amount of columns', () => {
// Value taken from editor's config above.
- expect( testColorPlugin.colorColumns ).to.equal( 3 );
+ expect( testColorPlugin.columns ).to.equal( 3 );
} );
} );
diff --git a/tests/utils.js b/tests/utils.js
index 2f4c186..a47a195 100644
--- a/tests/utils.js
+++ b/tests/utils.js
@@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/
-import { FONT_COLOR, FONT_BACKGROUND_COLOR, normalizeOptions, addColorsToDropdown } from './../src/utils';
+import { FONT_COLOR, FONT_BACKGROUND_COLOR, normalizeOptions, addColorTableToDropdown } from './../src/utils';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import ColorTableView from './../src/ui/colortableview';
@@ -103,7 +103,7 @@ describe( 'utils', () => {
const dropdown = createDropdown();
dropdown.render();
- addColorsToDropdown( {
+ addColorTableToDropdown( {
dropdownView: dropdown,
colors: [
{
@@ -121,7 +121,7 @@ describe( 'utils', () => {
}
}
],
- colorColumns: 2,
+ columns: 2,
removeButtonTooltip: 'Remove Color'
} );
From c8191d08928be8aa5c6b93f94f11247d5e952053 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Tue, 26 Mar 2019 16:03:25 +0100
Subject: [PATCH 67/92] Moved ColorGrid and ColorTile to ckeditor5-ui.
Refactroing of styles; some moved to ckeditor5-theme-lark.
---
src/ui/colorgrid.js | 175 ---------------------------------------
src/ui/colortableview.js | 10 +--
src/ui/colortile.js | 48 -----------
src/utils.js | 2 +-
tests/ui/colorgrid.js | 161 -----------------------------------
tests/ui/colortile.js | 30 -------
theme/fontcolor.css | 42 ----------
7 files changed, 6 insertions(+), 462 deletions(-)
delete mode 100644 src/ui/colorgrid.js
delete mode 100644 src/ui/colortile.js
delete mode 100644 tests/ui/colorgrid.js
delete mode 100644 tests/ui/colortile.js
diff --git a/src/ui/colorgrid.js b/src/ui/colorgrid.js
deleted file mode 100644
index 6a0df53..0000000
--- a/src/ui/colorgrid.js
+++ /dev/null
@@ -1,175 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module font/ui/colorgrid
- */
-
-import View from '@ckeditor/ckeditor5-ui/src/view';
-import ColorTile from './colortile';
-import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
-import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
-import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
-
-/**
- * A grid of {@link module:font/ui/colortile~ColorTile color tiles}.
- *
- * @extends module:ui/view~View
- */
-export default class ColorGrid extends View {
- /**
- * Creates an instance of a color grid containing {@link module:font/ui/colortile~ColorTile}.
- *
- * @param {module:utils/locale~Locale} [locale] The localization services instance.
- * @param {Object} options Component configuration
- * @param {Array.} [options.colorDefinitions] Array with definitions
- * required to create the {@link module:font/ui/colortile~ColorTile tiles}.
- * @param {Number} options.columns A number of columns to display the tiles.
- */
- constructor( locale, options ) {
- super( locale );
-
- /**
- * Collection of the child tile views.
- *
- * @readonly
- * @member {module:ui/viewcollection~ViewCollection}
- */
- this.items = this.createCollection();
-
- /**
- * Tracks information about DOM focus in the grid.
- *
- * @readonly
- * @member {module:utils/focustracker~FocusTracker}
- */
- this.focusTracker = new FocusTracker();
-
- /**
- * Instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
- *
- * @readonly
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
- */
- this.keystrokes = new KeystrokeHandler();
-
- /**
- * Helps cycling over focusable {@link #items} in the grid.
- *
- * @readonly
- * @protected
- * @member {module:ui/focuscycler~FocusCycler}
- */
- this._focusCycler = new FocusCycler( {
- focusables: this.items,
- focusTracker: this.focusTracker,
- keystrokeHandler: this.keystrokes,
- actions: {
- // Navigate grid items backwards using the arrowup key.
- focusPrevious: 'arrowleft',
-
- // Navigate grid items forwards using the arrowdown key.
- focusNext: 'arrowright',
- }
- } );
-
- if ( options.colorDefinitions ) {
- options.colorDefinitions.forEach( item => {
- const colorTile = new ColorTile();
-
- colorTile.set( {
- color: item.color,
- label: item.label,
- tooltip: true,
- hasBorder: item.options.hasBorder
- } );
-
- colorTile.on( 'execute', () => {
- this.fire( 'execute', {
- value: item.color,
- hasBorder: item.options.hasBorder,
- label: item.label
- } );
- } );
-
- this.items.add( colorTile );
- } );
- }
-
- this.setTemplate( {
- tag: 'div',
- children: this.items,
- attributes: {
- class: 'ck-color-table__grid-container',
- style: {
- gridTemplateColumns: `repeat( ${ options.columns }, 1fr)`
- }
- }
- } );
- }
-
- /**
- * Focuses the first focusable in {@link #items}.
- */
- focus() {
- if ( this.items.length ) {
- this.items.first.focus();
- }
- }
-
- /**
- * Focuses the last focusable in {@link #items}.
- */
- focusLast() {
- if ( this.items.length ) {
- this.items.last.focus();
- }
- }
-
- /**
- * @inheritDoc
- */
- render() {
- super.render();
-
- // Items added before rendering should be known to the #focusTracker.
- for ( const item of this.items ) {
- this.focusTracker.add( item.element );
- }
-
- this.items.on( 'add', ( evt, item ) => {
- this.focusTracker.add( item.element );
- } );
-
- this.items.on( 'remove', ( evt, item ) => {
- this.focusTracker.remove( item.element );
- } );
-
- // Start listening for the keystrokes coming from #element.
- this.keystrokes.listenTo( this.element );
- }
-}
-
-/**
- * A color definition used to create a {@link module:font/ui/colortile~ColorTile}.
- *
- * {
- * color: hsl(0, 0%, 75%),
- * label: 'Light Grey',
- * options: {
- * hasBorder: true
- * }
- * }
- *
- * @typedef {Object} module:font/ui/colorgrid~ColorDefinition
- * @type Object
- *
- * @property {String} color String representing a color.
- * It is used as value of background-color style in {@link module:font/ui/colortile~ColorTile}.
- * @property {String} label String used as label for {@link module:font/ui/colortile~ColorTile}.
- * @property {Object} options Additional options passed to create a {@link module:font/ui/colortile~ColorTile}.
- * @property {Boolean} options.hasBorder A flag that indicates if special a CSS class should be added
- * to {@link module:font/ui/colortile~ColorTile}, which renders a border around it.
- */
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index b9cbab5..4a64f8c 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -9,8 +9,8 @@
import View from '@ckeditor/ckeditor5-ui/src/view';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-import ColorTile from './colortile';
-import ColorGrid from './colorgrid';
+import ColorTile from '@ckeditor/ckeditor5-ui/src/colorgrid/colortile';
+import ColorGrid from '@ckeditor/ckeditor5-ui/src/colorgrid/colorgrid';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
@@ -22,7 +22,7 @@ import '../../theme/fontcolor.css';
* Class which represents a view with the following sub–components:
*
* * a remove color button,
- * * a {@link module:font/ui/colorgrid~ColorGrid},
+ * * a {@link module:ui/colorgrid/colorgrid~ColorGrid},
* * a grid of recently used colors.
*
* @extends module:ui/view~View
@@ -33,7 +33,7 @@ export default class ColorTableView extends View {
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
* @param {Object} config Configuration object
- * @param {Array.} config.colors Array with definitions of colors to
+ * @param {Array.} config.colors Array with definitions of colors to
* be displayed in the table.
* @param {Number} config.columns Number of columns in the color grid.
* Also determines how many recent color will be displayed.
@@ -53,7 +53,7 @@ export default class ColorTableView extends View {
/**
* An array with objects representing colors to be displayed in the grid.
*
- * @type {Arrray.}
+ * @type {Arrray.}
*/
this.colorDefinitions = colors;
diff --git a/src/ui/colortile.js b/src/ui/colortile.js
deleted file mode 100644
index cf61026..0000000
--- a/src/ui/colortile.js
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module font/ui/colortile
- */
-
-import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-
-/**
- * This class represents a single color tile in the {@link module:font/ui/colorgrid~ColorGrid}.
- *
- * @extends module:ui/button/buttonview~ButtonView
- */
-export default class ColorTile extends ButtonView {
- constructor( locale ) {
- super( locale );
-
- const bind = this.bindTemplate;
-
- /**
- * String representing a color shown as tile's background.
- * @type {String}
- */
- this.set( 'color' );
-
- /**
- * A flag that toggles a special CSS class responsible for displaying
- * a border around the button.
- * @type {Boolean}
- */
- this.set( 'hasBorder' );
-
- this.extendTemplate( {
- attributes: {
- style: {
- backgroundColor: bind.to( 'color' )
- },
- class: [
- 'ck-color-table__color-tile',
- bind.if( 'hasBorder', 'ck-color-table__color-tile_bordered' )
- ]
- }
- } );
- }
-}
diff --git a/src/utils.js b/src/utils.js
index 03342cd..240794c 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -94,7 +94,7 @@ export function normalizeOptions( colorRow ) {
* @param {Object} config Configuration object
* @param {module:ui/dropdown/dropdownview~DropdownView} config.dropdownView Dropdown view to which
* will be added {@link module:font/ui/colortableview~ColorTableView}.
- * @param {Array.} Array with definitions representing colors to be displayed
+ * @param {Array.} Array with definitions representing colors to be displayed
* in the color table.
* @returns {module:font/ui/colortableview~ColorTableView} The new color table view.
*/
diff --git a/tests/ui/colorgrid.js b/tests/ui/colorgrid.js
deleted file mode 100644
index bd410d9..0000000
--- a/tests/ui/colorgrid.js
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* globals Event */
-
-import ColorGrid from './../../src/ui/colorgrid';
-import ViewCollection from '@ckeditor/ckeditor5-ui/src/viewcollection';
-import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
-import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
-import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
-import ColorTile from '../../src/ui/colortile';
-import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
-
-describe( 'ColorGrid', () => {
- let locale, colorGrid;
-
- const colorDefinitions = [
- {
- color: '#000',
- label: 'Black',
- options: {
- hasBorder: false
- }
- },
- {
- color: 'rgb(255, 255, 255)',
- label: 'White',
- options: {
- hasBorder: true
- }
- },
- {
- color: 'red',
- label: 'Red',
- options: {
- hasBorder: false
- }
- }
- ];
-
- beforeEach( () => {
- locale = { t() {} };
- colorGrid = new ColorGrid( locale, { colorDefinitions } );
- colorGrid.render();
- } );
-
- testUtils.createSinonSandbox();
-
- describe( 'constructor()', () => {
- it( 'creates view collection with children', () => {
- expect( colorGrid.items ).to.be.instanceOf( ViewCollection );
- } );
-
- it( 'creates focus tracker', () => {
- expect( colorGrid.focusTracker ).to.be.instanceOf( FocusTracker );
- } );
-
- it( 'creates keystroke handler', () => {
- expect( colorGrid.keystrokes ).to.be.instanceOf( KeystrokeHandler );
- } );
-
- it( 'creates focus cycler', () => {
- expect( colorGrid._focusCycler ).to.be.instanceOf( FocusCycler );
- } );
-
- describe( 'add colors from definition as child items', () => {
- it( 'has proper number of elements', () => {
- expect( colorGrid.items.length ).to.equal( 3 );
- } );
- colorDefinitions.forEach( ( color, index ) => {
- describe( 'child items has proper attributes', () => {
- it( `for (index: ${ index }, color: ${ color.color }) child`, () => {
- const colorTile = colorGrid.items.get( index );
- expect( colorTile ).to.be.instanceOf( ColorTile );
- expect( colorTile.color ).to.equal( color.color );
- } );
- } );
- } );
- } );
- } );
-
- describe( 'execute()', () => {
- it( 'fires event for rendered tiles', () => {
- const spy = sinon.spy();
- const firstTile = colorGrid.items.first;
-
- colorGrid.on( 'execute', spy );
-
- firstTile.isEnabled = true;
-
- firstTile.element.dispatchEvent( new Event( 'click' ) );
- sinon.assert.callCount( spy, 1 );
-
- firstTile.isEnabled = false;
-
- firstTile.element.dispatchEvent( new Event( 'click' ) );
- sinon.assert.callCount( spy, 1 );
- } );
- } );
-
- describe( 'focus', () => {
- it( 'focuses the tile in DOM', () => {
- const spy = sinon.spy( colorGrid.items.first, 'focus' );
-
- colorGrid.focus();
-
- sinon.assert.calledOnce( spy );
-
- colorGrid.items.clear();
- colorGrid.focus();
-
- expect( colorGrid.items.length ).to.equal( 0 );
- sinon.assert.calledOnce( spy );
- } );
-
- it( 'focuses last the tile in DOM', () => {
- const spy = sinon.spy( colorGrid.items.last, 'focus' );
-
- colorGrid.focusLast();
-
- sinon.assert.calledOnce( spy );
-
- colorGrid.items.clear();
- colorGrid.focusLast();
-
- expect( colorGrid.items.length ).to.equal( 0 );
- sinon.assert.calledOnce( spy );
- } );
-
- describe( 'update elements in focus tracker', () => {
- it( 'adding new element', () => {
- const spy = sinon.spy( colorGrid.focusTracker, 'add' );
-
- const colorTile = new ColorTile();
- colorTile.set( {
- color: 'yellow',
- label: 'Yellow',
- tooltip: true,
- options: {
- hasBorder: false
- }
- } );
- colorGrid.items.add( colorTile );
-
- expect( colorGrid.items.length ).to.equal( 4 );
- sinon.assert.calledOnce( spy );
- } );
-
- it( 'removes element', () => {
- const spy = sinon.spy( colorGrid.focusTracker, 'remove' );
-
- colorGrid.items.remove( colorGrid.items.length - 1 );
-
- expect( colorGrid.items.length ).to.equal( 2 );
- sinon.assert.calledOnce( spy );
- } );
- } );
- } );
-} );
diff --git a/tests/ui/colortile.js b/tests/ui/colortile.js
deleted file mode 100644
index 9dbe5b9..0000000
--- a/tests/ui/colortile.js
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-import ColorTile from './../../src/ui/colortile';
-import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-
-describe( 'ColorTile', () => {
- it( 'inherits from ButtonView', () => {
- expect( new ColorTile() ).to.be.instanceOf( ButtonView );
- } );
-
- it( 'has proper attributes and classes', () => {
- const colorTile = new ColorTile();
- colorTile.render();
-
- expect( colorTile.color ).to.be.undefined;
- expect( colorTile.hasBorder ).to.be.undefined;
-
- colorTile.set( 'color', 'green' );
- expect( colorTile.color ).to.equal( 'green' );
- expect( colorTile.element.style.backgroundColor ).to.equal( 'green' );
- expect( colorTile.element.classList.contains( 'ck-color-table__color-tile' ) ).to.be.true;
- expect( colorTile.element.classList.contains( 'ck-color-table__color-tile_bordered' ) ).to.be.false;
-
- colorTile.set( 'hasBorder', true );
- expect( colorTile.element.classList.contains( 'ck-color-table__color-tile_bordered' ) ).to.be.true;
- } );
-} );
diff --git a/theme/fontcolor.css b/theme/fontcolor.css
index cc96a63..991dee3 100644
--- a/theme/fontcolor.css
+++ b/theme/fontcolor.css
@@ -3,50 +3,8 @@
* For licensing, see LICENSE.md.
*/
-:root {
- --ck-table-color-tile-size: 20px;
- --ck-table-color-max-columns: 5;
- --ck-color-table-color-tile-border: hsl(0, 0%, 90%);
- --ck-color-table-color-tile-border-active: hsl(184, 80%, 50%);
-}
-
-.ck .ck-color-table__grid-container {
- display: grid;
- grid-gap: calc( var(--ck-spacing-standard) / 2 );
- padding: var(--ck-spacing-standard);
-}
-
-.ck .ck-color-table__color-tile {
- width: var(--ck-table-color-tile-size);
- height: var(--ck-table-color-tile-size);
- min-width: var(--ck-table-color-tile-size);
- min-height: var(--ck-table-color-tile-size);
- border-radius: var(--ck-border-radius);
- transition: 200ms ease box-shadow;
-}
-
-.ck .ck-disabled.ck-color-table__color-tile {
- cursor: unset;
- transition: unset;
-}
-
-.ck .ck-color-table__color-tile_bordered {
- box-shadow: 0 0 0 1px var(--ck-color-table-color-tile-border);
-}
-
-.ck .ck-color-table__color-tile:hover:not( .ck-disabled ) {
- box-shadow: 0 0 0 2px var(--ck-color-table-color-tile-border-active);
-}
-
-/* If we change it to list element this CSS will be obsolete. */
.ck .ck-button.ck-color-table__remove-color {
display: flex;
align-items: center;
width: 100%;
- border-bottom: 1px solid var(--ck-color-base-border);
- padding: calc(var(--ck-spacing-standard) / 2 ) var(--ck-spacing-standard);
-}
-
-.ck .ck-button.ck-button_with-text.ck-color-table__remove-color svg {
- margin-right: var(--ck-spacing-standard);
}
From e7e1c0b099abb95196dd011f3bfb63a73453f321 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 10:33:30 +0100
Subject: [PATCH 68/92] Added .ck class to .ck-color-table.
---
src/ui/colortableview.js | 5 ++++-
tests/ui/colortableview.js | 4 +++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index 4a64f8c..f71ac28 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -126,7 +126,10 @@ export default class ColorTableView extends View {
this.setTemplate( {
tag: 'div',
attributes: {
- class: [ 'ck-color-table' ]
+ class: [
+ 'ck',
+ 'ck-color-table'
+ ]
},
children: this.items
} );
diff --git a/tests/ui/colortableview.js b/tests/ui/colortableview.js
index a84972c..e7ace91 100644
--- a/tests/ui/colortableview.js
+++ b/tests/ui/colortableview.js
@@ -31,7 +31,8 @@ describe( 'ColorTableView', () => {
options: {
hasBorder: true
}
- }, {
+ },
+ {
color: 'red',
label: 'Red',
options: {
@@ -90,6 +91,7 @@ describe( 'ColorTableView', () => {
} );
it( 'has proper class', () => {
+ expect( colorTableView.element.classList.contains( 'ck' ) ).to.be.true;
expect( colorTableView.element.classList.contains( 'ck-color-table' ) ).to.be.true;
} );
} );
From 46dfa2909337084f9513d3472dde848edd258b3d Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 10:36:04 +0100
Subject: [PATCH 69/92] Renamed ColorGrid, ColorTile -> ColorGridView,
ColorTileView.
---
src/ui/colortableview.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index f71ac28..6a44e21 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -9,8 +9,8 @@
import View from '@ckeditor/ckeditor5-ui/src/view';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
-import ColorTile from '@ckeditor/ckeditor5-ui/src/colorgrid/colortile';
-import ColorGrid from '@ckeditor/ckeditor5-ui/src/colorgrid/colorgrid';
+import ColorTileView from '@ckeditor/ckeditor5-ui/src/colorgrid/colortileview';
+import ColorGridView from '@ckeditor/ckeditor5-ui/src/colorgrid/colorgridview';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
import FocusCycler from '@ckeditor/ckeditor5-ui/src/focuscycler';
@@ -22,7 +22,7 @@ import '../../theme/fontcolor.css';
* Class which represents a view with the following sub–components:
*
* * a remove color button,
- * * a {@link module:ui/colorgrid/colorgrid~ColorGrid},
+ * * a {@link module:ui/colorgrid/colorgrid~ColorGridView},
* * a grid of recently used colors.
*
* @extends module:ui/view~View
@@ -168,7 +168,7 @@ export default class ColorTableView extends View {
* @private
*/
createStaticColorTable() {
- const colorGrid = new ColorGrid( this.locale, {
+ const colorGrid = new ColorGridView( this.locale, {
colorDefinitions: this.colorDefinitions,
columns: this.columns
} );
@@ -184,11 +184,11 @@ export default class ColorTableView extends View {
* @private
*/
recentlyUsed() {
- const recentViews = new ColorGrid( this.locale, { columns: this.columns } );
+ const recentViews = new ColorGridView( this.locale, { columns: this.columns } );
recentViews.items.bindTo( this.recentlyUsedColors ).using(
colorObj => {
- const colorTile = new ColorTile();
+ const colorTile = new ColorTileView();
colorTile.set( {
color: colorObj.color,
From b0ea7d2becc72f32c74882433a76975271c0394a Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 10:46:11 +0100
Subject: [PATCH 70/92] Updated contexts.json file.
---
lang/contexts.json | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lang/contexts.json b/lang/contexts.json
index 52edcfc..d2b22c0 100644
--- a/lang/contexts.json
+++ b/lang/contexts.json
@@ -5,5 +5,21 @@
"Big": "Dropdown option label for the 'big' font size preset.",
"Huge": "Dropdown option label for the 'huge' font size preset.",
"Font Family": "Tooltip for the font family dropdown.",
- "Default": "Dropdown option label for the default font family."
+ "Default": "Dropdown option label for the default font family.",
+ "Remove color": "Label or a button that removes the color from the text (font color and background).",
+ "Black": "Label of a button that applies a black text color (font color and background)",
+ "Dim grey": "Label of a button that applies a dim grey text color (font color and background)",
+ "Grey": "Label of a button that applies a grey text color (font color and background)",
+ "Light grey": "Label of a button that applies a light grey text color (font color and background)",
+ "White": "Label of a button that applies a white text color (font color and background)",
+ "Red": "Label of a button that applies a red text color (font color and background)",
+ "Orange": "Label of a button that applies a orange text color (font color and background)",
+ "Yellow": "Label of a button that applies a yellow text color (font color and background)",
+ "Light green": "Label of a button that applies a light green text color (font color and background)",
+ "Green": "Label of a button that applies a green text color (font color and background)",
+ "Aquamarine": "Label of a button that applies a aquamarine text color (font color and background)",
+ "Turquoise": "Label of a button that applies a turquoise text color (font color and background)",
+ "Light blue": "Label of a button that applies a light blue text color (font color and background)",
+ "Blue": "Label of a button that applies a blue text color (font color and background)",
+ "Purple": "Label of a button that applies a purple text color (font color and background)"
}
From 1ac04fc39017ea8383a743125bf8deb301688336 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 10:53:15 +0100
Subject: [PATCH 71/92] Code refactoring: color config localization.
---
src/ui/colorui.js | 6 ++++--
src/utils.js | 11 +++++------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index 886b00d..dfcf102 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -11,6 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import {
addColorTableToDropdown,
+ normalizeOptions,
getLocalizedColorOptions
} from '../utils';
@@ -74,14 +75,15 @@ export default class ColorUI extends Plugin {
const editor = this.editor;
const t = editor.t;
const command = editor.commands.get( this.commandName );
- const options = getLocalizedColorOptions( editor, this.componentName );
+ const colorsConfig = normalizeOptions( editor.config.get( this.componentName ).colors );
+ const localizedColors = getLocalizedColorOptions( editor, colorsConfig );
// Register UI component.
editor.ui.componentFactory.add( this.componentName, locale => {
const dropdownView = createDropdown( locale );
const colorTableView = addColorTableToDropdown( {
dropdownView,
- colors: options.map( option => ( {
+ colors: localizedColors.map( option => ( {
label: option.label,
color: option.model,
options: {
diff --git a/src/utils.js b/src/utils.js
index 240794c..5055ee4 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -111,18 +111,17 @@ export function addColorTableToDropdown( { dropdownView, colors, columns, remove
}
/**
- * Returns configuration options as defined in the `editor.config[ featureName ]` but processed to account for
- * editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
+ * Returns color configuration options as defined in the `editor.config.(fontColor|fontBackgroundColor).colors`
+ * but processed to account for editor localization, i.e. to display {@link module:font/fontcolor~FontColorConfig}
* or {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig} in the correct language.
*
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
* when the user configuration is defined because the editor does not exist yet.
*
* @param {module:core/editor/editor~Editor} editor An editor instance.
- * @param {String} featureName Determines which config (`editor.config[ featureName ]`) colors to localize.
- * @returns {Array.|Array.}.
+ * @returns {Array.}.
*/
-export function getLocalizedColorOptions( editor, featureName ) {
+export function getLocalizedColorOptions( editor, options ) {
const t = editor.t;
const localizedColorNames = {
Black: t( 'Black' ),
@@ -142,7 +141,7 @@ export function getLocalizedColorOptions( editor, featureName ) {
Purple: t( 'Purple' )
};
- return normalizeOptions( editor.config.get( featureName ).colors ).map( colorOption => {
+ return options.map( colorOption => {
const label = localizedColorNames[ colorOption.label ];
if ( label && label != colorOption.label ) {
From 8f37314757bb97408611901a6f1ad90b6f492dbd Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 11:13:12 +0100
Subject: [PATCH 72/92] Docs: Improvement in docs. Extended contexts.json.
---
lang/contexts.json | 2 ++
src/fontcolor/fontcolorui.js | 2 +-
src/ui/colorui.js | 4 +++-
src/utils.js | 9 +++++----
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/lang/contexts.json b/lang/contexts.json
index d2b22c0..37b312a 100644
--- a/lang/contexts.json
+++ b/lang/contexts.json
@@ -6,6 +6,8 @@
"Huge": "Dropdown option label for the 'huge' font size preset.",
"Font Family": "Tooltip for the font family dropdown.",
"Default": "Dropdown option label for the default font family.",
+ "Font color": "Label of a button that allows selecting a font color.",
+ "Font Background Color": "Label of a button that allows selecting a font background color.",
"Remove color": "Label or a button that removes the color from the text (font color and background).",
"Black": "Label of a button that applies a black text color (font color and background)",
"Dim grey": "Label of a button that applies a dim grey text color (font color and background)",
diff --git a/src/fontcolor/fontcolorui.js b/src/fontcolor/fontcolorui.js
index 597a7a3..b1a5113 100644
--- a/src/fontcolor/fontcolorui.js
+++ b/src/fontcolor/fontcolorui.js
@@ -12,7 +12,7 @@ import { FONT_COLOR } from '../utils';
import fontColorIcon from '../../theme/icons/font-color.svg';
/**
- * The font background color UI plugin. It introduces the `'fontColor'` dropdown.
+ * The font color UI plugin. It introduces the `'fontColor'` dropdown.
*
* @extends module:core/plugin~Plugin
*/
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index dfcf102..5605701 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -17,7 +17,9 @@ import {
/**
* The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
- * It is used to create the `'fontBackgroundColor'` and the `'fontColor'` dropdowns.
+ *
+ * It is used to create the `'fontBackgroundColor'` and the `'fontColor'` dropdowns, each hosting
+ * a {@link module:font/ui/colortableview~ColorTableView}.
*
* @extends module:core/plugin~Plugin
*/
diff --git a/src/utils.js b/src/utils.js
index 5055ee4..ab42bc2 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -89,13 +89,14 @@ export function normalizeOptions( colorRow ) {
}
/**
- * Helper which add {@link module:font/ui/colortableview~ColorTableView} to dropdown with proper initial values.
+ * Helper which add {@link module:font/ui/colortableview~ColorTableView} to a dropdown with proper initial values.
*
* @param {Object} config Configuration object
* @param {module:ui/dropdown/dropdownview~DropdownView} config.dropdownView Dropdown view to which
- * will be added {@link module:font/ui/colortableview~ColorTableView}.
- * @param {Array.} Array with definitions representing colors to be displayed
- * in the color table.
+ * a {@link module:font/ui/colortableview~ColorTableView} will be added.
+ * @param {Array.} config.colors An array with definitions
+ * representing colors to be displayed in the color table.
+ * @param {String} config.removeButtonLabel A label of a button responsible for removing the color.
* @returns {module:font/ui/colortableview~ColorTableView} The new color table view.
*/
export function addColorTableToDropdown( { dropdownView, colors, columns, removeButtonLabel } ) {
From fa83b3daf1517f431728d6688db43451f4622e50 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 11:28:25 +0100
Subject: [PATCH 73/92] Docs: Improved color utils docs. Minor code
refactoring.
---
src/ui/colorui.js | 4 ++--
src/utils.js | 34 +++++++++++++++++++---------------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/ui/colorui.js b/src/ui/colorui.js
index 5605701..acd2be7 100644
--- a/src/ui/colorui.js
+++ b/src/ui/colorui.js
@@ -11,7 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import {
addColorTableToDropdown,
- normalizeOptions,
+ normalizeColorOptions,
getLocalizedColorOptions
} from '../utils';
@@ -77,7 +77,7 @@ export default class ColorUI extends Plugin {
const editor = this.editor;
const t = editor.t;
const command = editor.commands.get( this.commandName );
- const colorsConfig = normalizeOptions( editor.config.get( this.componentName ).colors );
+ const colorsConfig = normalizeColorOptions( editor.config.get( this.componentName ).colors );
const localizedColors = getLocalizedColorOptions( editor, colorsConfig );
// Register UI component.
diff --git a/src/utils.js b/src/utils.js
index ab42bc2..46906c9 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -49,9 +49,11 @@ export function buildDefinition( modelAttributeKey, options ) {
}
/**
- * Function for font color and font background color plugins
- * which is responsible for upcasting data to model.
- * styleAttr should eqaul to `'color'` or `'background-color'`.
+ * A {@link module:font/fontcolor~FontColor font color} and
+ * {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
+ * responsible for upcasting data to model.
+ *
+ * **Note**: `styleAttr` should be either `'color'` or `'background-color'`.
*
* @param {String} styleAttr
*/
@@ -60,9 +62,11 @@ export function renderUpcastAttribute( styleAttr ) {
}
/**
- * Function for font color and font background color plugins
- * which is responsible for downcasting color attribute to span element.
- * styleAttr should eqaul to `'color'` or `'background-color'`.
+ * A {@link module:font/fontcolor~FontColor font color} and
+ * {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
+ * responsible for downcasting a color attribute to a span element.
+ *
+ * **Note**: `styleAttr` should be either `'color'` or `'background-color'`.
*
* @param {String} styleAttr
*/
@@ -72,18 +76,14 @@ export function renderDowncastElement( styleAttr ) {
} );
}
-function normalizeColorCode( value ) {
- return value.replace( /\s/g, '' );
-}
-
/**
- * Creates model of color from configuration option. It keeps them coherent,
- * regardles how user define them in config.
+ * Creates a unified color definition object from color configuration options.
+ * The object contains both the information necessary to render the UI and initialize a conversion.
*
- * @param {String|Object} colorRow
+ * @param {module:font/fontcolor~FontColorConfig#colors|module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors} options
*/
-export function normalizeOptions( colorRow ) {
- return colorRow
+export function normalizeColorOptions( options ) {
+ return options
.map( normalizeSingleColorDefinition )
.filter( option => !!option );
}
@@ -153,6 +153,10 @@ export function getLocalizedColorOptions( editor, options ) {
} );
}
+function normalizeColorCode( value ) {
+ return value.replace( /\s/g, '' );
+}
+
function normalizeSingleColorDefinition( color ) {
if ( typeof color === 'string' ) {
return {
From d82c21558de5b54f666e08df25974e36251808d1 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 12:07:32 +0100
Subject: [PATCH 74/92] Tests: Fixed broken test after renamed
normalizeOptions() to normalizeColorOptions().
---
tests/utils.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tests/utils.js b/tests/utils.js
index a47a195..73b701a 100644
--- a/tests/utils.js
+++ b/tests/utils.js
@@ -3,7 +3,12 @@
* For licensing, see LICENSE.md.
*/
-import { FONT_COLOR, FONT_BACKGROUND_COLOR, normalizeOptions, addColorTableToDropdown } from './../src/utils';
+import {
+ FONT_COLOR,
+ FONT_BACKGROUND_COLOR,
+ normalizeColorOptions,
+ addColorTableToDropdown
+} from './../src/utils';
import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import ColorTableView from './../src/ui/colortableview';
@@ -14,8 +19,8 @@ describe( 'utils', () => {
expect( FONT_BACKGROUND_COLOR ).to.equal( 'fontBackgroundColor' );
} );
- it( 'normalizeOptions can produce the same output object', () => {
- const normalizedArray = normalizeOptions( [
+ it( 'normalizeColorOptions can produce the same output object', () => {
+ const normalizedArray = normalizeColorOptions( [
'black',
{
color: 'black'
From dd003326e869d48528fdf6eefae3c6eee5338db2 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 14:26:47 +0100
Subject: [PATCH 75/92] Code refac: What the hell, used importable plugin name
constants for the font size and family too.
---
src/fontfamily/fontfamilycommand.js | 3 ++-
src/fontfamily/fontfamilyediting.js | 4 +---
src/fontfamily/fontfamilyui.js | 9 +++++----
src/fontsize/fontsizecommand.js | 3 ++-
src/fontsize/fontsizeediting.js | 4 +---
src/fontsize/fontsizeui.js | 11 ++++++-----
src/utils.js | 14 ++++++++++++--
7 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/src/fontfamily/fontfamilycommand.js b/src/fontfamily/fontfamilycommand.js
index d2d2ba1..c178da4 100644
--- a/src/fontfamily/fontfamilycommand.js
+++ b/src/fontfamily/fontfamilycommand.js
@@ -8,6 +8,7 @@
*/
import FontCommand from '../fontcommand';
+import { FONT_FAMILY } from '../utils';
/**
* The font family command. It is used by {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing}
@@ -24,6 +25,6 @@ export default class FontFamilyCommand extends FontCommand {
* @inheritDoc
*/
constructor( editor ) {
- super( editor, 'fontFamily' );
+ super( editor, FONT_FAMILY );
}
}
diff --git a/src/fontfamily/fontfamilyediting.js b/src/fontfamily/fontfamilyediting.js
index d2dcd93..e002e20 100644
--- a/src/fontfamily/fontfamilyediting.js
+++ b/src/fontfamily/fontfamilyediting.js
@@ -11,9 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontFamilyCommand from './fontfamilycommand';
import { normalizeOptions } from './utils';
-import { buildDefinition } from '../utils';
-
-const FONT_FAMILY = 'fontFamily';
+import { buildDefinition, FONT_FAMILY } from '../utils';
/**
* The font family editing feature.
diff --git a/src/fontfamily/fontfamilyui.js b/src/fontfamily/fontfamilyui.js
index 8856ce7..430dc14 100644
--- a/src/fontfamily/fontfamilyui.js
+++ b/src/fontfamily/fontfamilyui.js
@@ -13,6 +13,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import { createDropdown, addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
import { normalizeOptions } from './utils';
+import { FONT_FAMILY } from '../utils';
import fontFamilyIcon from '../../theme/icons/font-family.svg';
/**
@@ -30,10 +31,10 @@ export default class FontFamilyUI extends Plugin {
const options = this._getLocalizedOptions();
- const command = editor.commands.get( 'fontFamily' );
+ const command = editor.commands.get( FONT_FAMILY );
// Register UI component.
- editor.ui.componentFactory.add( 'fontFamily', locale => {
+ editor.ui.componentFactory.add( FONT_FAMILY, locale => {
const dropdownView = createDropdown( locale );
addListToDropdown( dropdownView, _prepareListOptions( options, command ) );
@@ -76,7 +77,7 @@ export default class FontFamilyUI extends Plugin {
const editor = this.editor;
const t = editor.t;
- const options = normalizeOptions( editor.config.get( 'fontFamily.options' ) );
+ const options = normalizeOptions( editor.config.get( FONT_FAMILY ).options );
return options.map( option => {
// The only title to localize is "Default" others are font names.
@@ -101,7 +102,7 @@ function _prepareListOptions( options, command ) {
const def = {
type: 'button',
model: new Model( {
- commandName: 'fontFamily',
+ commandName: FONT_FAMILY,
commandParam: option.model,
label: option.title,
withText: true
diff --git a/src/fontsize/fontsizecommand.js b/src/fontsize/fontsizecommand.js
index 5ad2158..78dcc3d 100644
--- a/src/fontsize/fontsizecommand.js
+++ b/src/fontsize/fontsizecommand.js
@@ -8,6 +8,7 @@
*/
import FontCommand from '../fontcommand';
+import { FONT_SIZE } from '../utils';
/**
* The font size command. It is used by {@link module:font/fontsize/fontsizeediting~FontSizeEditing}
@@ -24,6 +25,6 @@ export default class FontSizeCommand extends FontCommand {
* @inheritDoc
*/
constructor( editor ) {
- super( editor, 'fontSize' );
+ super( editor, FONT_SIZE );
}
}
diff --git a/src/fontsize/fontsizeediting.js b/src/fontsize/fontsizeediting.js
index db45b44..ef9502f 100644
--- a/src/fontsize/fontsizeediting.js
+++ b/src/fontsize/fontsizeediting.js
@@ -11,9 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontSizeCommand from './fontsizecommand';
import { normalizeOptions } from './utils';
-import { buildDefinition } from '../utils';
-
-const FONT_SIZE = 'fontSize';
+import { buildDefinition, FONT_SIZE } from '../utils';
/**
* The font size editing feature.
diff --git a/src/fontsize/fontsizeui.js b/src/fontsize/fontsizeui.js
index 4633b45..62c957b 100644
--- a/src/fontsize/fontsizeui.js
+++ b/src/fontsize/fontsizeui.js
@@ -12,7 +12,8 @@ import Model from '@ckeditor/ckeditor5-ui/src/model';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import { createDropdown, addListToDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { normalizeOptions } from '../fontsize/utils';
+import { normalizeOptions } from './utils';
+import { FONT_SIZE } from '../utils';
import fontSizeIcon from '../../theme/icons/font-size.svg';
import '../../theme/fontsize.css';
@@ -32,10 +33,10 @@ export default class FontSizeUI extends Plugin {
const options = this._getLocalizedOptions();
- const command = editor.commands.get( 'fontSize' );
+ const command = editor.commands.get( FONT_SIZE );
// Register UI component.
- editor.ui.componentFactory.add( 'fontSize', locale => {
+ editor.ui.componentFactory.add( FONT_SIZE, locale => {
const dropdownView = createDropdown( locale );
addListToDropdown( dropdownView, _prepareListOptions( options, command ) );
@@ -89,7 +90,7 @@ export default class FontSizeUI extends Plugin {
Huge: t( 'Huge' )
};
- const options = normalizeOptions( editor.config.get( 'fontSize.options' ) );
+ const options = normalizeOptions( editor.config.get( FONT_SIZE ).options );
return options.map( option => {
const title = localizedTitles[ option.title ];
@@ -115,7 +116,7 @@ function _prepareListOptions( options, command ) {
const def = {
type: 'button',
model: new Model( {
- commandName: 'fontSize',
+ commandName: FONT_SIZE,
commandParam: option.model,
label: option.title,
class: 'ck-fontsize-option',
diff --git a/src/utils.js b/src/utils.js
index 46906c9..fb9b00d 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -10,12 +10,22 @@
import ColorTableView from './ui/colortableview';
/**
- * Name of font color plugin.
+ * Name of the font size plugin.
+ */
+export const FONT_SIZE = 'fontSize';
+
+/**
+ * Name of the font family plugin.
+ */
+export const FONT_FAMILY = 'fontFamily';
+
+/**
+ * Name of the font color plugin.
*/
export const FONT_COLOR = 'fontColor';
/**
- * Name of font background color plugin.
+ * Name of font font background color plugin.
*/
export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
From 7771773f0507c026f7d2a4f4e22c81cabeb147dc Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 14:29:11 +0100
Subject: [PATCH 76/92] Docs: Added info about font color features to
README.md.
---
README.md | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9afec53..de6ae6e 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,12 @@ CKEditor 5 font feature
[![Dependency Status](https://david-dm.org/ckeditor/ckeditor5-font/status.svg)](https://david-dm.org/ckeditor/ckeditor5-font)
[![devDependency Status](https://david-dm.org/ckeditor/ckeditor5-font/dev-status.svg)](https://david-dm.org/ckeditor/ckeditor5-font?type=dev)
-This package implements font size and font family support for CKEditor 5.
+This package implements support for the following CKEditor 5 features:
+
+* font size,
+* font family,
+* font color,
+* font background color.
## Demo
From d8d2fd8bb9aa395058b4b44c89a98328b660c9f1 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 15:13:26 +0100
Subject: [PATCH 77/92] Docs: Improved the font feature guide. Changed wording
and code snippets.
---
...nt-color-and-background-color-options.html | 2 +-
docs/features/font.md | 185 +++++++++++-------
2 files changed, 115 insertions(+), 72 deletions(-)
diff --git a/docs/_snippets/features/custom-font-color-and-background-color-options.html b/docs/_snippets/features/custom-font-color-and-background-color-options.html
index 38f0fe6..8d85890 100644
--- a/docs/_snippets/features/custom-font-color-and-background-color-options.html
+++ b/docs/_snippets/features/custom-font-color-and-background-color-options.html
@@ -1,3 +1,3 @@
-
This is sampletext which has appliedmultiple different font colors and font backgroundcolors.
+
Text in this samplehasmultiplefont colors and font backgroundcolors.
diff --git a/docs/features/font.md b/docs/features/font.md
index 87c6395..dc56855 100644
--- a/docs/features/font.md
+++ b/docs/features/font.md
@@ -147,76 +147,114 @@ ClassicEditor
{@snippet features/custom-font-size-numeric-options}
-## Configuring font color and font background color
+## Configuring font color and font background color features
+
+Both font color and font background color features are configurable and share the same configuration format.
-Plugin enables `font color` and `font background color`. Which allows on using style `color` and `background-color` over text.
- Please notice that you can turn on only one of those plugins. As well as configure them separately.
+ Please note that {@link module:font/fontcolor~FontColor font color} and {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} are separate plugins. They must be enabled and configured individually.
-### Dropdown
+Check out the editor below with both features customized using the editor configuration:
+
+{@snippet features/custom-font-color-and-background-color-options}
-It is possible to configure which colors are available in dropdown in the editor. Use the `fontColor.colors` or `fontBackgroundColor.colors` configuration option to do so.
+### Specifying the available colors
-It is possible to configure how many columns is shown in color dropdown. Use the `fontColor.columns` or `fontBackgroundColor.columns` configuration option to do so. This option also reflects to number of recently used colors section, which always have 1 row with amount of columns equal to `columns` configuration option.
-Default colors configuration is presented below:
+It is possible to configure which colors are available in the color dropdown. Use the {@link module:font/fontColor~FontColor#colors `fontColor.colors`} and {@link module:font/fontBackgroundColor~FontBackgroundColor#colors `fontBackgroundColor.colors`} configuration options to do so.
```js
-fontColor = {
- colors: [
- {
- color: 'hsl(0, 0%, 0%)',
- label: 'Black'
- }, {
- color: 'hsl(0, 0%, 30%)',
- label: 'Dim grey'
- }, {
- color: 'hsl(0, 0%, 60%)',
- label: 'Grey'
- }, {
- color: 'hsl(0, 0%, 90%)',
- label: 'Light grey'
- }, {
- color: 'hsl(0, 0%, 100%)',
- label: 'White',
- hasBorder: true
- }, {
- color: 'hsl(0, 75%, 60%)',
- label: 'Red'
- }, {
- color: 'hsl(30, 75%, 60%)',
- label: 'Orange'
- }, {
- color: 'hsl(60, 75%, 60%)',
- label: 'Yellow'
- }, {
- color: 'hsl(90, 75%, 60%)',
- label: 'Light green'
- }, {
- color: 'hsl(120, 75%, 60%)',
- label: 'Green'
- }, {
- color: 'hsl(150, 75%, 60%)',
- label: 'Aquamarine'
- }, {
- color: 'hsl(180, 75%, 60%)',
- label: 'Turquoise'
- }, {
- color: 'hsl(210, 75%, 60%)',
- label: 'Light blue'
- }, {
- color: 'hsl(240, 75%, 60%)',
- label: 'Blue'
- }, {
- color: 'hsl(270, 75%, 60%)',
- label: 'Purple'
- }
- ],
- columns: 5
-}
+ClassicEditor
+ .create( document.querySelector( '#editor' ), {
+ fontColor: {
+ colors: [
+ {
+ color: 'hsl(0, 0%, 0%)',
+ label: 'Black'
+ },
+ {
+ color: 'hsl(0, 0%, 30%)',
+ label: 'Dim grey'
+ },
+ {
+ color: 'hsl(0, 0%, 60%)',
+ label: 'Grey'
+ },
+ {
+ color: 'hsl(0, 0%, 90%)',
+ label: 'Light grey'
+ },
+ {
+ color: 'hsl(0, 0%, 100%)',
+ label: 'White',
+ hasBorder: true
+ },
+
+ // ...
+ ]
+ },
+ fontBackgroundColor: {
+ colors: [
+ {
+ color: 'hsl(0, 75%, 60%)',
+ label: 'Red'
+ },
+ {
+ color: 'hsl(30, 75%, 60%)',
+ label: 'Orange'
+ },
+ {
+ color: 'hsl(60, 75%, 60%)',
+ label: 'Yellow'
+ },
+ {
+ color: 'hsl(90, 75%, 60%)',
+ label: 'Light green'
+ },
+ {
+ color: 'hsl(120, 75%, 60%)',
+ label: 'Green'
+ },
+
+ // ...
+ ]
+ },
+ toolbar: [
+ 'heading', 'bulletedList', 'numberedList', 'fontColor', 'fontBackgroundColor', 'undo', 'redo'
+ ]
+ } )
+ .then( ... )
+ .catch( ... );
```
-{@snippet features/custom-font-color-and-background-color-options}
+### Changing the geometry of the color grid
+
+It is also possible to configure in how many columns the colors in the grid are displayed. Use {@link module:font/fontColor~FontColor#columns `fontColor.columns`} and {@link module:font/fontBackgroundColor~FontBackgroundColor#columns `fontBackgroundColor.columns`} to do so.
+
+
+ The configuration of the columns also affects the number of recently used colors displayed under the color grid. The less columns, the fewer recently used colors will be displayed.
+
+
+```js
+ClassicEditor
+ .create( document.querySelector( '#editor' ), {
+ fontColor: {
+ columns: 3,
+
+ // ...
+ },
+ fontBackgroundColor: {
+ columns: 6,
+
+ // ...
+ },
+ toolbar: [
+ 'heading', 'bulletedList', 'numberedList', 'fontColor', 'fontBackgroundColor', 'undo', 'redo'
+ ]
+ } )
+ .then( ... )
+ .catch( ... );
+```
## Installation
@@ -334,33 +372,38 @@ The {@link module:font/fontcolor~FontColor} plugin registers the following compo
* The `'fontColor'` dropdown,
* The {@link module:font/fontcolor/fontcolorcommand~FontColorCommand `'fontColor'`} command.
- The number of options and their names correspond to the {@link module:font/fontcolor~FontColorConfig#colors `fontColor.colors`}
- and {@link module:font/fontcolor~FontColorConfig#columns `fontColor.columns`} configuration options.
-
You can change the font color of the current selection by executing the command with a desired value:
```js
- editor.execute( 'fontColor', { value: rgb(30, 188, 97) } );
+ editor.execute( 'fontColor', { value: 'rgb(30, 188, 97)' } );
```
- The `'fontColor'` command will accept any strings as values.
+ Passing an empty value will remove the font color from the selection:
+
+ ```js
+ editor.execute( 'fontColor' );
+ ```
The {@link module:font/fontbackgroundcolor~FontBackgroundColor} plugin registers the following components:
-* The `'fontColor'` dropdown,
+* The `'fontBackgroundColor'` dropdown,
* The {@link module:font/fontbackgroundcolor/fontbackgroundcolorcommand~FontBackgroundColorCommand `'fontBackgroundColor'`} command.
- The number of options and their names correspond to the {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors `fontBackgroundColor.colors`}
- and {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns `fontBackgroundColor.columns`} configuration options.
-
You can change the font background color of the current selection by executing the command with a desired value:
```js
- editor.execute( 'fontBackgroundColor', { value: rgb(30, 188, 97) } );
+ editor.execute( 'fontBackgroundColor', { value: 'rgb(30, 188, 97)' } );
```
- The `'fontBackgroundColor'` command will accept any strings as values.
+ Passing an empty value will remove the font background color from the selection:
+ ```js
+ editor.execute( 'fontBackgroundColor' );
+ ```
+
+
+ We recommend using the official {@link framework/guides/development-tools#ckeditor-5-inspector CKEditor 5 inspector} for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
+
## Contribute
From 73f2a9f7d2f1b6502b023f473babe47a37a849d7 Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 15:23:49 +0100
Subject: [PATCH 78/92] Tests: Fixed wording and grammar in the manual font
color test.
---
tests/manual/font-color.md | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/tests/manual/font-color.md b/tests/manual/font-color.md
index d854abf..8205283 100644
--- a/tests/manual/font-color.md
+++ b/tests/manual/font-color.md
@@ -1,8 +1,13 @@
### Loading
-The data should be loaded with different text and background colors with followed order. Colors 1-5 use predefined palette. Colors 6-8 use any css color not defined in configuration.
-Color 9-10 mixes colors from predefined palette and custom one.
-( First is font color, last is background color )
+The data should be loaded with different text and background colors in the following order:
+
+* Colors 1-5 use the predefined palette,
+* Colors 6-8 use custom CSS colors, not defined in the configuration,
+* Color 9-10 use a mix from the predefined palette and custom ones.
+
+The format is the editor content is `N. [font color]; [background color]`.
+
1. no-color; no-color
2. White; Black
3. Red; no-color
@@ -16,8 +21,7 @@ Color 9-10 mixes colors from predefined palette and custom one.
### Testing
-Try to:
-- Change color and background color by selecting many paragraphs.
-- Change color and background color by selecting some text.
-- Check if chosen colors from dropdown are added to recent color list.
-- Try to re-apply color from Recent Color list - check if it moves to it beginning.
+- Change the font color and font background color on selected text.
+- Change the font color and font background color across many paragraphs.
+- Check whether the colors are added to recent colors list.
+- Try to re-apply a color from recent colors list: the color should move to the beginning of the list.
From 4c9fd6b44895376061509b593d5c4191e737d89c Mon Sep 17 00:00:00 2001
From: Aleksander Nowodzinski
Date: Wed, 27 Mar 2019 17:08:52 +0100
Subject: [PATCH 79/92] Bound ColorGridView#selectedColor to
ColorTableView#selectedColor.
---
src/ui/colortableview.js | 1 +
tests/ui/colortableview.js | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/src/ui/colortableview.js b/src/ui/colortableview.js
index 6a44e21..ec9d8ae 100644
--- a/src/ui/colortableview.js
+++ b/src/ui/colortableview.js
@@ -174,6 +174,7 @@ export default class ColorTableView extends View {
} );
colorGrid.delegate( 'execute' ).to( this );
+ colorGrid.bind( 'selectedColor' ).to( this );
return colorGrid;
}
diff --git a/tests/ui/colortableview.js b/tests/ui/colortableview.js
index e7ace91..6bdc8a1 100644
--- a/tests/ui/colortableview.js
+++ b/tests/ui/colortableview.js
@@ -154,6 +154,14 @@ describe( 'ColorTableView', () => {
expect( staticColorTable.items.length ).to.equal( 3 );
} );
+ it( 'binds #selectedColor to the table', () => {
+ colorTableView.selectedColor = 'foo';
+ expect( staticColorTable.selectedColor ).to.equal( 'foo' );
+
+ colorTableView.selectedColor = 'bar';
+ expect( staticColorTable.selectedColor ).to.equal( 'bar' );
+ } );
+
colorDefinitions.forEach( ( item, index ) => {
it( `dispatch event to parent element for color: ${ item.color }`, () => {
const spy = sinon.spy();
From bb21e4c2ded974a9da478bf7d4c1eb3802b3b9a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:16:03 +0100
Subject: [PATCH 80/92] Add links to font color plugins into the docs of the
Font feature.
---
src/font.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/font.js b/src/font.js
index 706afa2..da331c3 100644
--- a/src/font.js
+++ b/src/font.js
@@ -19,6 +19,8 @@ import FontBackgroundColor from './fontbackgroundcolor';
*
* * {@link module:font/fontsize~FontSize},
* * {@link module:font/fontfamily~FontFamily}.
+ * * {@link module:font/fontcolor~FontColor},
+ * * {@link module:font/fontbackgroundcolor~FontBackgroundColor}.
*
* For a detailed overview, check the {@glink features/font Font feature} documentation
* and the {@glink api/font package page}.
From e7078f9e54272aff1c89d2fd3dae9d5bf85242b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:18:03 +0100
Subject: [PATCH 81/92] Add links to feature guide in new font plugins docs.
---
src/fontbackgroundcolor.js | 3 +++
src/fontcolor.js | 3 +++
2 files changed, 6 insertions(+)
diff --git a/src/fontbackgroundcolor.js b/src/fontbackgroundcolor.js
index 8bf1b37..50761b0 100644
--- a/src/fontbackgroundcolor.js
+++ b/src/fontbackgroundcolor.js
@@ -14,6 +14,9 @@ import FontBackgroundColorUI from './fontbackgroundcolor/fontbackgroundcolorui';
/**
* The font background color plugin.
*
+ * For a detailed overview, check the {@glink features/font font feature} documentation
+ * and the {@glink api/font package page}.
+ *
* This is a "glue" plugin which loads
* the {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} and
* {@link module:font/fontbackgroundcolor/fontbackgroundcolorui~FontBackgroundColorUI} features in the editor.
diff --git a/src/fontcolor.js b/src/fontcolor.js
index 86c59e6..eebb523 100644
--- a/src/fontcolor.js
+++ b/src/fontcolor.js
@@ -14,6 +14,9 @@ import FontColorUI from './fontcolor/fontcolorui';
/**
* The font color plugin.
*
+ * For a detailed overview, check the {@glink features/font font feature} documentation
+ * and the {@glink api/font package page}.
+ *
* This is a "glue" plugin which loads the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
* {@link module:font/fontcolor/fontcolorui~FontColorUI} features in the editor.
*
From 5467682af5aeebf92a16c07272f41d4e2a5b0601 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:19:14 +0100
Subject: [PATCH 82/92] Typo fix.
---
src/fontbackgroundcolor.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/fontbackgroundcolor.js b/src/fontbackgroundcolor.js
index 50761b0..6d72602 100644
--- a/src/fontbackgroundcolor.js
+++ b/src/fontbackgroundcolor.js
@@ -139,5 +139,5 @@ export default class FontBackgroundColor extends Plugin {
* columns: 5
* }
*
- * @member {Numebr} module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns
+ * @member {Number} module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns
*/
From 755a6034890a272bab404e0794382ff8e12b0d9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:20:58 +0100
Subject: [PATCH 83/92] Fix links to #columns in feature guide.
---
docs/features/font.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/features/font.md b/docs/features/font.md
index dc56855..5255a4f 100644
--- a/docs/features/font.md
+++ b/docs/features/font.md
@@ -161,7 +161,7 @@ Check out the editor below with both features customized using the editor config
### Specifying the available colors
-It is possible to configure which colors are available in the color dropdown. Use the {@link module:font/fontColor~FontColor#colors `fontColor.colors`} and {@link module:font/fontBackgroundColor~FontBackgroundColor#colors `fontBackgroundColor.colors`} configuration options to do so.
+It is possible to configure which colors are available in the color dropdown. Use the {@link module:font/fontColor~FontColorConfig#colors `fontColor.colors`} and {@link module:font/fontBackgroundColor~FontBackgroundColorConfig#colors `fontBackgroundColor.colors`} configuration options to do so.
```js
ClassicEditor
@@ -229,7 +229,7 @@ ClassicEditor
### Changing the geometry of the color grid
-It is also possible to configure in how many columns the colors in the grid are displayed. Use {@link module:font/fontColor~FontColor#columns `fontColor.columns`} and {@link module:font/fontBackgroundColor~FontBackgroundColor#columns `fontBackgroundColor.columns`} to do so.
+It is also possible to configure in how many columns the colors in the grid are displayed. Use {@link module:font/fontColor~FontColorConfig#columns `fontColor.columns`} and {@link module:font/fontBackgroundColor~FontBackgroundColorConfig#columns `fontBackgroundColor.columns`} to do so.
The configuration of the columns also affects the number of recently used colors displayed under the color grid. The less columns, the fewer recently used colors will be displayed.
From 8cba7545579f371777257ac3b16d73ea08b5fe55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:24:27 +0100
Subject: [PATCH 84/92] Add missing jsdoc annotations.
---
src/utils.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/utils.js b/src/utils.js
index fb9b00d..b646dfc 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -91,6 +91,7 @@ export function renderDowncastElement( styleAttr ) {
* The object contains both the information necessary to render the UI and initialize a conversion.
*
* @param {module:font/fontcolor~FontColorConfig#colors|module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors} options
+ * @returns {Array.}
*/
export function normalizeColorOptions( options ) {
return options
@@ -130,6 +131,7 @@ export function addColorTableToDropdown( { dropdownView, colors, columns, remove
* when the user configuration is defined because the editor does not exist yet.
*
* @param {module:core/editor/editor~Editor} editor An editor instance.
+ * @param {module:font/fontcolor~FontColorConfig#colors|module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors} options
* @returns {Array.}.
*/
export function getLocalizedColorOptions( editor, options ) {
From c5305735c5c5bb3daee6c5f3aba0a10e3a419913 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:24:45 +0100
Subject: [PATCH 85/92] Typo fix.
---
src/fontcolor.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/fontcolor.js b/src/fontcolor.js
index eebb523..94fd0dc 100644
--- a/src/fontcolor.js
+++ b/src/fontcolor.js
@@ -138,5 +138,5 @@ export default class FontColor extends Plugin {
* columns: 5
* }
*
- * @member {Numebr} module:font/fontcolor~FontColorConfig#columns
+ * @member {Number} module:font/fontcolor~FontColorConfig#columns
*/
From d772c7ef5944cdd4fb082655eea5cb32a2d3bae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:29:00 +0100
Subject: [PATCH 86/92] Fix incorrect links to API in feature guide.
---
docs/features/font.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/features/font.md b/docs/features/font.md
index 5255a4f..2276d75 100644
--- a/docs/features/font.md
+++ b/docs/features/font.md
@@ -161,7 +161,7 @@ Check out the editor below with both features customized using the editor config
### Specifying the available colors
-It is possible to configure which colors are available in the color dropdown. Use the {@link module:font/fontColor~FontColorConfig#colors `fontColor.colors`} and {@link module:font/fontBackgroundColor~FontBackgroundColorConfig#colors `fontBackgroundColor.colors`} configuration options to do so.
+It is possible to configure which colors are available in the color dropdown. Use the {@link module:font/fontcolor~FontColorConfig#colors `fontColor.colors`} and {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors `fontBackgroundColor.colors`} configuration options to do so.
```js
ClassicEditor
@@ -229,7 +229,7 @@ ClassicEditor
### Changing the geometry of the color grid
-It is also possible to configure in how many columns the colors in the grid are displayed. Use {@link module:font/fontColor~FontColorConfig#columns `fontColor.columns`} and {@link module:font/fontBackgroundColor~FontBackgroundColorConfig#columns `fontBackgroundColor.columns`} to do so.
+It is also possible to configure in how many columns the colors in the grid are displayed. Use {@link module:font/fontcolor~FontColorConfig#columns `fontColor.columns`} and {@link module:font/fontbackgroundcolor~FontBackgroundColorConfig#columns `fontBackgroundColor.columns`} to do so.
The configuration of the columns also affects the number of recently used colors displayed under the color grid. The less columns, the fewer recently used colors will be displayed.
From 920e286731fad1f30b0c1bf84c151a5b9e6433b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:34:24 +0100
Subject: [PATCH 87/92] Add missing jsdoc doclets to constructors.
---
src/fontbackgroundcolor/fontbackgroundcolorui.js | 3 +++
src/fontcolor/fontcolorui.js | 3 +++
2 files changed, 6 insertions(+)
diff --git a/src/fontbackgroundcolor/fontbackgroundcolorui.js b/src/fontbackgroundcolor/fontbackgroundcolorui.js
index 524f14a..32b08a4 100644
--- a/src/fontbackgroundcolor/fontbackgroundcolorui.js
+++ b/src/fontbackgroundcolor/fontbackgroundcolorui.js
@@ -17,6 +17,9 @@ import fontBackgroundColorIcon from '../../theme/icons/font-background.svg';
* @extends module:core/plugin~Plugin
*/
export default class FontBackgroundColorUI extends ColorUI {
+ /**
+ * @inheritDoc
+ */
constructor( editor ) {
const t = editor.locale.t;
diff --git a/src/fontcolor/fontcolorui.js b/src/fontcolor/fontcolorui.js
index b1a5113..f69c6e3 100644
--- a/src/fontcolor/fontcolorui.js
+++ b/src/fontcolor/fontcolorui.js
@@ -17,6 +17,9 @@ import fontColorIcon from '../../theme/icons/font-color.svg';
* @extends module:core/plugin~Plugin
*/
export default class FontColorUI extends ColorUI {
+ /**
+ * @inheritDoc
+ */
constructor( editor ) {
const t = editor.locale.t;
From 414fb19715160a087fedd90ec6cea10a178a5280 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 10:47:44 +0100
Subject: [PATCH 88/92] Add links to sub-features in api page.
---
docs/api/font.md | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/docs/api/font.md b/docs/api/font.md
index 5b34d16..cc54163 100644
--- a/docs/api/font.md
+++ b/docs/api/font.md
@@ -14,8 +14,11 @@ Check out the {@link features/font#demo demo in the Font feature} guide.
## Documentation
-See the {@link features/font Font feature} guide
-and {@link module:font/fontfamily~FontFamily} and {@link module:font/fontsize~FontSize} plugins documentation.
+See the {@link features/font Font feature} guide and plugins documentation:
+- {@link module:font/fontfamily~FontFamily}.
+- {@link module:font/fontsize~FontSize}.
+- {@link module:font/fontcolor~FontColor}.
+- {@link module:font/fontbackgroundcolor~FontBackgroundColor}.
## Installation
From ebcbe8c565b81473a138fd09ca78f37faa19cef7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 11:02:34 +0100
Subject: [PATCH 89/92] Add private methods docs.
---
src/utils.js | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/utils.js b/src/utils.js
index b646dfc..2bcb57a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -66,6 +66,7 @@ export function buildDefinition( modelAttributeKey, options ) {
* **Note**: `styleAttr` should be either `'color'` or `'background-color'`.
*
* @param {String} styleAttr
+ * @return {String}
*/
export function renderUpcastAttribute( styleAttr ) {
return viewElement => normalizeColorCode( viewElement.getStyle( styleAttr ) );
@@ -165,10 +166,18 @@ export function getLocalizedColorOptions( editor, options ) {
} );
}
+// Fixes color value string
+//
+// @param {String} value
+// @returns {String}
function normalizeColorCode( value ) {
return value.replace( /\s/g, '' );
}
+// Creates normalized color definition from user defined configuration.
+//
+// @param {String|Object}
+// @returns {module:ui/colorgrid/colorgrid~ColorDefinition}
function normalizeSingleColorDefinition( color ) {
if ( typeof color === 'string' ) {
return {
From 32cfbf1ec0c1937b0b07ea51c9927c6f39554996 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?=
Date: Fri, 29 Mar 2019 11:32:29 +0100
Subject: [PATCH 90/92] Update color definition related docs.
---
src/utils.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/utils.js b/src/utils.js
index 2bcb57a..ef4de54 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -91,8 +91,8 @@ export function renderDowncastElement( styleAttr ) {
* Creates a unified color definition object from color configuration options.
* The object contains both the information necessary to render the UI and initialize a conversion.
*
- * @param {module:font/fontcolor~FontColorConfig#colors|module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors} options
- * @returns {Array.}
+ * @param {module:ui/colorgrid/colorgrid~ColorDefinition} options
+ * @returns {Array.}
*/
export function normalizeColorOptions( options ) {
return options
@@ -132,7 +132,7 @@ export function addColorTableToDropdown( { dropdownView, colors, columns, remove
* when the user configuration is defined because the editor does not exist yet.
*
* @param {module:core/editor/editor~Editor} editor An editor instance.
- * @param {module:font/fontcolor~FontColorConfig#colors|module:font/fontbackgroundcolor~FontBackgroundColorConfig#colors} options
+ * @param {Array.} options
* @returns {Array.}.
*/
export function getLocalizedColorOptions( editor, options ) {
@@ -176,7 +176,7 @@ function normalizeColorCode( value ) {
// Creates normalized color definition from user defined configuration.
//
-// @param {String|Object}
+// @param {String|module:ui/colorgrid/colorgrid~ColorDefinition}
// @returns {module:ui/colorgrid/colorgrid~ColorDefinition}
function normalizeSingleColorDefinition( color ) {
if ( typeof color === 'string' ) {
From 50328e19dede89b5f4e67e52332decbafdfd5409 Mon Sep 17 00:00:00 2001
From: Marek Lewandowski
Date: Fri, 29 Mar 2019 13:40:11 +0100
Subject: [PATCH 91/92] Tests: Simplified manual test description.
---
tests/manual/font-color.md | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/tests/manual/font-color.md b/tests/manual/font-color.md
index 8205283..cbe94ec 100644
--- a/tests/manual/font-color.md
+++ b/tests/manual/font-color.md
@@ -6,18 +6,7 @@ The data should be loaded with different text and background colors in the follo
* Colors 6-8 use custom CSS colors, not defined in the configuration,
* Color 9-10 use a mix from the predefined palette and custom ones.
-The format is the editor content is `N. [font color]; [background color]`.
-
-1. no-color; no-color
-2. White; Black
-3. Red; no-color
-4. no-color; Light green
-5. Orange: Dim grey
-6. #00FFFF; rgb(255, 0, 0)
-7. hsla( 0, 0%, 0%, .7); gold
-8. rgba( 0, 120, 250, 0.8); hsla(270, 100%, 50%, 0.3)
-9. #ddd; Aquamarine
-10. Purple; #d82
+The format in the editor content is: `N. [font color]; [background color]`.
### Testing
From 2ab56e78bc4510434fc8fff411400fcf493532fc Mon Sep 17 00:00:00 2001
From: Marek Lewandowski
Date: Fri, 29 Mar 2019 14:35:31 +0100
Subject: [PATCH 92/92] Docs: Minor rewording to improve docs maintainability.
---
src/fontbackgroundcolor.js | 2 +-
src/fontcolor.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/fontbackgroundcolor.js b/src/fontbackgroundcolor.js
index 6d72602..daffdb1 100644
--- a/src/fontbackgroundcolor.js
+++ b/src/fontbackgroundcolor.js
@@ -58,7 +58,7 @@ export default class FontBackgroundColor extends Plugin {
/**
* Available font background colors defined as an array of strings or objects.
*
- * The default value registers 15 colors:
+ * The default value registers the following colors:
*
* const fontBackgroundColorConfig = {
* colors: [
diff --git a/src/fontcolor.js b/src/fontcolor.js
index 94fd0dc..e7845a3 100644
--- a/src/fontcolor.js
+++ b/src/fontcolor.js
@@ -57,7 +57,7 @@ export default class FontColor extends Plugin {
/**
* Available font colors defined as an array of strings or objects.
*
- * The default value registers 15 colors:
+ * The default value registers the following colors:
*
* const fontColorConfig = {
* colors: [