Ver código fonte

Code refactoring in font utils.

Aleksander Nowodzinski 6 anos atrás
pai
commit
ad72a91ab6
1 arquivos alterados com 30 adições e 31 exclusões
  1. 30 31
      packages/ckeditor5-font/src/utils.js

+ 30 - 31
packages/ckeditor5-font/src/utils.js

@@ -9,6 +9,16 @@
 
 
 import ColorTableView from './ui/colortableview';
 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.
  * 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;
 	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
  * Function for font color and font background color plugins
  * which is responsible for upcasting data to model.
  * which is responsible for upcasting data to model.
@@ -56,10 +56,7 @@ export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
  * @param {String} styleAttr
  * @param {String} styleAttr
  */
  */
 export function renderUpcastAttribute( 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 );
 		.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.<Object>}  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 ) {
 function normalizeSingleColorDefinition( color ) {
 	if ( typeof color === 'string' ) {
 	if ( typeof color === 'string' ) {
 		return {
 		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.<Object>}  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;
-}