Explorar el Código

Docs: Improved color utils docs. Minor code refactoring.

Aleksander Nowodzinski hace 6 años
padre
commit
3c87eb498c
Se han modificado 2 ficheros con 21 adiciones y 17 borrados
  1. 2 2
      packages/ckeditor5-font/src/ui/colorui.js
  2. 19 15
      packages/ckeditor5-font/src/utils.js

+ 2 - 2
packages/ckeditor5-font/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.

+ 19 - 15
packages/ckeditor5-font/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 {