Browse Source

Code refactoring.

Aleksander Nowodzinski 6 years ago
parent
commit
92dd991ee6

+ 2 - 2
packages/ckeditor5-link/src/linkcommand.js

@@ -38,7 +38,7 @@ export default class LinkCommand extends Command {
 		 * @readonly
 		 * @type {module:utils/collection~Collection.<module:link/utils~ManualDecorator>}
 		 */
-		this.manualDecoratorCollection = new Collection();
+		this.manualDecorators = new Collection();
 	}
 
 	/**
@@ -50,7 +50,7 @@ export default class LinkCommand extends Command {
 
 		this.value = doc.selection.getAttribute( 'linkHref' );
 
-		for ( const manualDecorator of this.manualDecoratorCollection ) {
+		for ( const manualDecorator of this.manualDecorators ) {
 			manualDecorator.value = doc.selection.getAttribute( manualDecorator.id ) || false;
 		}
 

+ 4 - 4
packages/ckeditor5-link/src/linkediting.js

@@ -127,7 +127,7 @@ export default class LinkEditing extends Plugin {
 	/**
 	 * Processes an array of configured {@link module:link/link~LinkDecoratorManualDefinition manual decorators}
 	 * and transforms them into {@link module:link/utils~ManualDecorator} instances and stores them in the
-	 * {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection} collection (a model for manual decorators state).
+	 * {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
 	 *
 	 * Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attributeToElement}
 	 * converter for each manual decorator and extends the {@link module:engine/model/schema~Schema model's schema}
@@ -143,7 +143,7 @@ export default class LinkEditing extends Plugin {
 
 		const editor = this.editor;
 		const command = editor.commands.get( 'link' );
-		const manualDecoratorCollection = command.manualDecoratorCollection;
+		const manualDecorators = command.manualDecorators;
 
 		manualDecoratorDefinitions.forEach( ( decorator, index ) => {
 			const decoratorName = `linkManualDecorator${ index }`;
@@ -151,7 +151,7 @@ export default class LinkEditing extends Plugin {
 			editor.model.schema.extend( '$text', { allowAttributes: decoratorName } );
 
 			// Keeps reference to manual decorator to decode its name to attributes during downcast.
-			manualDecoratorCollection.add( new ManualDecorator( Object.assign( { id: decoratorName }, decorator ) ) );
+			manualDecorators.add( new ManualDecorator( Object.assign( { id: decoratorName }, decorator ) ) );
 
 			editor.conversion.for( 'downcast' ).attributeToElement( {
 				model: decoratorName,
@@ -159,7 +159,7 @@ export default class LinkEditing extends Plugin {
 					if ( manualDecoratorName ) {
 						const element = writer.createAttributeElement(
 							'a',
-							manualDecoratorCollection.get( decoratorName ).attributes,
+							manualDecorators.get( decoratorName ).attributes,
 							{
 								priority: 5
 							}

+ 1 - 1
packages/ckeditor5-link/src/linkui.js

@@ -144,7 +144,7 @@ export default class LinkUI extends Plugin {
 		const editor = this.editor;
 		const linkCommand = editor.commands.get( 'link' );
 
-		const formView = new LinkFormView( editor.locale, linkCommand.manualDecoratorCollection );
+		const formView = new LinkFormView( editor.locale, linkCommand.manualDecorators );
 
 		formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' );
 

+ 20 - 19
packages/ckeditor5-link/src/ui/linkformview.js

@@ -38,10 +38,10 @@ export default class LinkFormView extends View {
 	 * Also see {@link #render}.
 	 *
 	 * @param {module:utils/locale~Locale} [locale] The localization services instance.
-	 * @param {module:utils/collection~Collection} [manualDecoratorCollection] Reference to manual decorators in
-	 * {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection}.
+	 * @param {module:utils/collection~Collection} [manualDecorators] Reference to manual decorators in
+	 * {@link module:link/linkcommand~LinkCommand#manualDecorators}.
 	 */
-	constructor( locale, manualDecoratorCollection = [] ) {
+	constructor( locale, manualDecorators = [] ) {
 		super( locale );
 
 		const t = locale.t;
@@ -86,14 +86,14 @@ export default class LinkFormView extends View {
 
 		/**
 		 * A collection of {@link module:ui/button/switchbuttonview~SwitchButtonView},
-		 * which corresponds to {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection manual decorators}
+		 * which corresponds to {@link module:link/linkcommand~LinkCommand#manualDecorators manual decorators}
 		 * configured in the editor.
 		 *
 		 * @private
 		 * @readonly
 		 * @type {module:ui/viewcollection~ViewCollection}
 		 */
-		this._manualDecoratorSwitches = this._createManualDecoratorSwitches( manualDecoratorCollection );
+		this._manualDecoratorSwitches = this._createManualDecoratorSwitches( manualDecorators );
 
 		/**
 		 * Collection of child views in the form.
@@ -101,7 +101,7 @@ export default class LinkFormView extends View {
 		 * @readonly
 		 * @type {module:ui/viewcollection~ViewCollection}
 		 */
-		this.children = this._createFormChildren( manualDecoratorCollection );
+		this.children = this._createFormChildren( manualDecorators );
 
 		/**
 		 * A collection of views which can be focused in the form.
@@ -134,7 +134,7 @@ export default class LinkFormView extends View {
 
 		const classList = [ 'ck', 'ck-link-form' ];
 
-		if ( manualDecoratorCollection.length ) {
+		if ( manualDecorators.length ) {
 			classList.push( 'ck-link-form_layout-vertical' );
 		}
 
@@ -153,11 +153,12 @@ export default class LinkFormView extends View {
 	}
 
 	/**
-	 * Obtain state of the {@link module:ui/button/switchbuttonview~SwitchButtonView switch buttons} representing
-	 * {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection manual decorators}
-	 * in a currently opened {@link module:link/ui/linkformview~LinkFormView}.
+	 * Obtains the state of the {@link module:ui/button/switchbuttonview~SwitchButtonView switch buttons} representing
+	 * {@link module:link/linkcommand~LinkCommand#manualDecorators manual link decorators}
+	 * in the {@link module:link/ui/linkformview~LinkFormView}.
 	 *
-	 * @returns {Object} key-value pairs, where the key is the name of the decorator and the value is its state.
+	 * @returns {Object.<String,Boolean>} key-value pairs, where the key is the name of the decorator and the value is
+	 * its state.
 	 */
 	getDecoratorSwitchesState() {
 		return Array.from( this._manualDecoratorSwitches ).reduce( ( accumulator, switchButton ) => {
@@ -253,17 +254,17 @@ export default class LinkFormView extends View {
 
 	/**
 	 * Populates {@link module:ui/viewcollection~ViewCollection} of {@link module:ui/button/switchbuttonview~SwitchButtonView}
-	 * made based on {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection}
+	 * made based on {@link module:link/linkcommand~LinkCommand#manualDecorators}
 	 *
 	 * @private
-	 * @param {module:link/linkcommand~LinkCommand#manualDecoratorCollection} manualDecoratorCollection reference to
+	 * @param {module:link/linkcommand~LinkCommand#manualDecorators} manualDecorators reference to
 	 * collection of manual decorators stored in link's command.
 	 * @returns {module:ui/viewcollection~ViewCollection} of Switch Buttons.
 	 */
-	_createManualDecoratorSwitches( manualDecoratorCollection ) {
+	_createManualDecoratorSwitches( manualDecorators ) {
 		const switches = this.createCollection();
 
-		for ( const manualDecorator of manualDecoratorCollection ) {
+		for ( const manualDecorator of manualDecorators ) {
 			const switchButton = new SwitchButtonView( this.locale );
 
 			switchButton.set( {
@@ -287,21 +288,21 @@ export default class LinkFormView extends View {
 	/**
 	 * Populates the {@link #children} collection of the form.
 	 *
-	 * If {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection manual decorators} are configured in the editor, creates an
+	 * If {@link module:link/linkcommand~LinkCommand#manualDecorators manual decorators} are configured in the editor, creates an
 	 * additional `View` wrapping all {@link #_manualDecoratorSwitches} switch buttons corresponding
 	 * to those decorators.
 	 *
 	 * @private
-	 * @param {module:link/linkcommand~LinkCommand#manualDecoratorCollection} manualDecoratorCollection reference to
+	 * @param {module:link/linkcommand~LinkCommand#manualDecorators} manualDecorators reference to
 	 * collection of manual decorators stored in link's command.
 	 * @returns {module:ui/viewcollection~ViewCollection} children of LinkFormView.
 	 */
-	_createFormChildren( manualDecoratorCollection ) {
+	_createFormChildren( manualDecorators ) {
 		const children = this.createCollection();
 
 		children.add( this.urlInputView );
 
-		if ( manualDecoratorCollection.length ) {
+		if ( manualDecorators.length ) {
 			const additionalButtonsView = new View();
 
 			additionalButtonsView.setTemplate( {

+ 3 - 8
packages/ckeditor5-link/src/unlinkcommand.js

@@ -30,14 +30,9 @@ export default class UnlinkCommand extends Command {
 	 * When the selection is non-collapsed, removes the `linkHref` attribute from each node in selected ranges.
 	 *
 	 * # Decorators
-	 * If there are defined {@link module:link/link~LinkConfig#decorators decorators} in the editor's configuration,
-	 * then all decorators are removed together with `linkHref` attribute.
 	 *
-	 *		const unlinkCommand = editor.commands.get( 'unlink' )'
-	 *
-	 *		// model: [<$text href="example.com" linkDecorator0="true">Foo bar</$text>]
-	 *		unlinkCommand.execute();
-	 *		// model: [Foo bar]
+	 * If {@link module:link/link~LinkConfig#decorators `config.link.decorators`} is specified,
+	 * all configured decorators are removed together with the `linkHref` attribute.
 	 *
 	 * @fires execute
 	 */
@@ -57,7 +52,7 @@ export default class UnlinkCommand extends Command {
 				writer.removeAttribute( 'linkHref', range );
 				// If there are registered custom attributes, then remove them during unlink.
 				if ( linkCommand ) {
-					for ( const manualDecorator of linkCommand.manualDecoratorCollection ) {
+					for ( const manualDecorator of linkCommand.manualDecorators ) {
 						writer.removeAttribute( manualDecorator.id, range );
 					}
 				}

+ 4 - 4
packages/ckeditor5-link/src/utils.js

@@ -61,12 +61,12 @@ function isSafeUrl( url ) {
 }
 
 /**
- * Returns configuration options as defined in {@link module:link/link~LinkConfig#decorators `editor.config.decorators`} but processed
- * to respect localization of the editor, i.e. to display {@link module:link/link~LinkDecoratorManualDefinition label}
+ * Returns {@link module:link/link~LinkConfig#decorators `config.link.decorators`} configuration processed
+ * to respect the locale of the editor, i.e. to display {@link module:link/link~LinkDecoratorManualDefinition label}
  * in the correct language.
  *
- * **Note:** Only few most commonly used labels has provided translations. In all other cases decorators configuration should be
- * directly translated in configuration.
+ * **Note**: Only the few most commonly used labels are translated automatically. Other labels should be manually
+ * translated in the {@link module:link/link~LinkConfig#decorators `config.link.decorators`} configuration.
  *
  * @param {module:core/editor/editor~Editor} editor An editor instance
  * @returns {Array.<module:link/link~LinkDecoratorAutomaticDefinition|module:link/link~LinkDecoratorManualDefinition>}

+ 1 - 1
packages/ckeditor5-link/src/utils/manualdecorator.js

@@ -13,7 +13,7 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
 /**
  * Helper class which stores manual decorators with observable {@link module:link/utils~ManualDecorator#value}
  * to support integration with the UI state. An instance of this class is a model with state of single manual decorators.
- * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecoratorCollection}.
+ * These decorators are kept as collections in {@link module:link/linkcommand~LinkCommand#manualDecorators}.
  *
  * @mixes module:utils/observablemixin~ObservableMixin
  */

+ 2 - 2
packages/ckeditor5-link/tests/linkcommand.js

@@ -270,14 +270,14 @@ describe( 'LinkCommand', () => {
 					model = editor.model;
 					command = new LinkCommand( editor );
 
-					command.manualDecoratorCollection.add( new ManualDecorator( {
+					command.manualDecorators.add( new ManualDecorator( {
 						id: 'linkManualDecorator0',
 						label: 'Foo',
 						attributes: {
 							class: 'Foo'
 						}
 					} ) );
-					command.manualDecoratorCollection.add( new ManualDecorator( {
+					command.manualDecorators.add( new ManualDecorator( {
 						id: 'linkManualDecorator1',
 						label: 'Bar',
 						attributes: {

+ 1 - 1
packages/ckeditor5-link/tests/ui/linkformview.js

@@ -321,7 +321,7 @@ describe( 'LinkFormView', () => {
 				} )
 				.then( newEditor => {
 					editor = newEditor;
-					linkFormView = new LinkFormView( editor.locale, editor.commands.get( 'link' ).manualDecoratorCollection );
+					linkFormView = new LinkFormView( editor.locale, editor.commands.get( 'link' ).manualDecorators );
 				} );
 		} );