Kaynağa Gözat

Make better separation of used utils.

Mateusz Samsel 6 yıl önce
ebeveyn
işleme
67c85dfd2d

+ 6 - 10
packages/ckeditor5-font/src/fontcolor/fontcolorui.js

@@ -11,8 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 
 import fontColorIcon from '../../theme/icons/font-family.svg';
 import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
-import { FONT_COLOR, normalizeOptions } from '../utils';
-import ColorTableView from '../ui/colortableview';
+import { FONT_COLOR, normalizeOptions, colorUI } from '../utils';
 export default class FontColorUI extends Plugin {
 	/**
 	 * @inheritDoc
@@ -27,16 +26,13 @@ export default class FontColorUI extends Plugin {
 		// Register UI component.
 		editor.ui.componentFactory.add( FONT_COLOR, locale => {
 			const dropdownView = createDropdown( locale );
-
-			const colorTableView = new ColorTableView( locale, {
-				colors: options.map( item => ( { name: item.label, color: item.model } ) )
-			} );
-
-			colorTableView.set( 'removeButtonTooltip', t( 'Remove text color' ) );
-			dropdownView.panelView.children.add( colorTableView );
+			const colorTableView = colorUI.addColorsToDropdown(
+				dropdownView,
+				options.map( item => ( { name: item.label, color: item.model } ) )
+			);
 
 			colorTableView.bind( 'selectedColor' ).to( command, 'value' );
-			colorTableView.delegate( 'colorPicked' ).to( dropdownView, 'execute' );
+			colorTableView.set( 'removeButtonTooltip', t( 'Remove text color' ) );
 
 			dropdownView.buttonView.set( {
 				label: t( 'Font Color' ),

+ 14 - 0
packages/ckeditor5-font/src/utils.js

@@ -7,6 +7,8 @@
  * @module font/utils
  */
 
+import ColorTableView from './ui/colortableview';
+
 /**
  * Builds a proper {@link module:engine/conversion/conversion~ConverterDefinition converter definition} out of input data.
  *
@@ -76,3 +78,15 @@ function getOptionDefinition( option ) {
 		}
 	};
 }
+
+export const colorUI = {
+	addColorsToDropdown( dropdownView, colors ) {
+		const locale = dropdownView.locale;
+		const colorTableView = new ColorTableView( locale, { colors } );
+
+		dropdownView.panelView.children.add( colorTableView );
+
+		colorTableView.delegate( 'colorPicked' ).to( dropdownView, 'execute' );
+		return colorTableView;
+	}
+};