瀏覽代碼

Remove referrence to manualDecorators in form view. Rename manualDecorators to manualDecoratorCollection. Fix test and references to property.

Mateusz Samsel 6 年之前
父節點
當前提交
6ad952f845

+ 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.manualDecorators = new Collection();
+		this.manualDecoratorCollection = new Collection();
 	}
 
 	/**
@@ -50,7 +50,7 @@ export default class LinkCommand extends Command {
 
 		this.value = doc.selection.getAttribute( 'linkHref' );
 
-		for ( const manualDecorator of this.manualDecorators ) {
+		for ( const manualDecorator of this.manualDecoratorCollection ) {
 			manualDecorator.value = doc.selection.getAttribute( manualDecorator.id ) || false;
 		}
 

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

@@ -143,7 +143,7 @@ export default class LinkEditing extends Plugin {
 
 		const editor = this.editor;
 		const command = editor.commands.get( 'link' );
-		const manualDecorators = command.manualDecorators;
+		const manualDecoratorCollection = command.manualDecoratorCollection;
 
 		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.
-			manualDecorators.add( new ManualDecorator( Object.assign( { id: decoratorName }, decorator ) ) );
+			manualDecoratorCollection.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',
-							manualDecorators.get( decoratorName ).attributes,
+							manualDecoratorCollection.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.manualDecorators );
+		const formView = new LinkFormView( editor.locale, linkCommand.manualDecoratorCollection );
 
 		formView.urlInputView.bind( 'value' ).to( linkCommand, 'value' );
 

+ 13 - 22
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} [manualDecorators] Reference to custom attributes in
+	 * @param {module:utils/collection~Collection} [manualDecoratorCollection] Reference to manual decorators in
 	 * {@link module:link/linkcommand~LinkCommand#manualDecorators}.
 	 */
-	constructor( locale, manualDecorators ) {
+	constructor( locale, manualDecoratorCollection = [] ) {
 		super( locale );
 
 		const t = locale.t;
@@ -85,19 +85,6 @@ export default class LinkFormView extends View {
 		this.cancelButtonView = this._createButton( t( 'Cancel' ), cancelIcon, 'ck-button-cancel', 'cancel' );
 
 		/**
-		 * A reference to {@link module:link/linkcommand~LinkCommand#manualDecorators manual decorators}
-		 * collection of the {@link module:link/linkcommand~LinkCommand}.
-		 *
-		 * Helps bootstrap the {@link #manualDecoratorsUIView UI} so it corresponds with the global
-		 * configuration of manual decorators and to synchronize its state later on when the user
-		 * is editing the content.
-		 *
-		 * @readonly
-		 * @type {model:utils/collection~Collection}
-		 */
-		this.manualDecorators = manualDecorators;
-
-		/**
 		 * A collection of {@link module:ui/button/switchbuttonview~SwitchButtonView},
 		 * which corresponds to {@link #manualDecorators manual decorators} configured in the editor.
 		 * Populated by {@link #_createManualDecoratorsUIView}.
@@ -106,7 +93,7 @@ export default class LinkFormView extends View {
 		 * @readonly
 		 * @type {module:ui/viewcollection~ViewCollection}
 		 */
-		this._manualDecoratorSwitches = this._createManualDecoratorSwitches();
+		this._manualDecoratorSwitches = this._createManualDecoratorSwitches( manualDecoratorCollection );
 
 		/**
 		 * Collection of child views in the form.
@@ -114,7 +101,7 @@ export default class LinkFormView extends View {
 		 * @readonly
 		 * @type {module:ui/viewcollection~ViewCollection}
 		 */
-		this.children = this._createFormChildren();
+		this.children = this._createFormChildren( manualDecoratorCollection );
 
 		/**
 		 * A collection of views which can be focused in the form.
@@ -147,7 +134,7 @@ export default class LinkFormView extends View {
 
 		const classList = [ 'ck', 'ck-link-form' ];
 
-		if ( this.manualDecorators.length ) {
+		if ( manualDecoratorCollection.length ) {
 			classList.push( 'ck-link-form_layout-vertical' );
 		}
 
@@ -267,12 +254,14 @@ export default class LinkFormView extends View {
 	 * made based on {@link #manualDecorators}
 	 *
 	 * @private
+	 * @param {module:link/linkcommand~LinkCommand#manualDecorators} manualDecoratorCollection reference to collection of manual decorators
+	 * stored in link's command.
 	 * @returns {module:ui/viewcollection~ViewCollection} of Switch Buttons.
 	 */
-	_createManualDecoratorSwitches() {
+	_createManualDecoratorSwitches( manualDecoratorCollection ) {
 		const switches = this.createCollection();
 
-		for ( const manualDecorator of this.manualDecorators ) {
+		for ( const manualDecorator of manualDecoratorCollection ) {
 			const switchButton = new SwitchButtonView( this.locale );
 
 			switchButton.set( {
@@ -301,14 +290,16 @@ export default class LinkFormView extends View {
 	 * to those decorators.
 	 *
 	 * @private
+	 * @param {module:link/linkcommand~LinkCommand#manualDecorators} manualDecoratorCollection reference to collection of manual decorators
+	 * stored in link's command.
 	 * @returns {module:ui/viewcollection~ViewCollection} children of LinkFormView.
 	 */
-	_createFormChildren() {
+	_createFormChildren( manualDecoratorCollection ) {
 		const children = this.createCollection();
 
 		children.add( this.urlInputView );
 
-		if ( this.manualDecorators.length ) {
+		if ( manualDecoratorCollection.length ) {
 			const additionalButtonsView = new View();
 
 			additionalButtonsView.setTemplate( {

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

@@ -47,7 +47,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.manualDecorators ) {
+					for ( const manualDecorator of linkCommand.manualDecoratorCollection ) {
 						writer.removeAttribute( manualDecorator.id, range );
 					}
 				}

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

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

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

@@ -22,7 +22,7 @@ describe( 'LinkFormView', () => {
 	testUtils.createSinonSandbox();
 
 	beforeEach( () => {
-		view = new LinkFormView( { t: val => val }, [] );
+		view = new LinkFormView( { t: val => val } );
 		view.render();
 	} );
 
@@ -106,7 +106,7 @@ describe( 'LinkFormView', () => {
 		it( 'should register child views\' #element in #focusTracker', () => {
 			const spy = testUtils.sinon.spy( FocusTracker.prototype, 'add' );
 
-			view = new LinkFormView( { t: () => {} }, [] );
+			view = new LinkFormView( { t: () => {} } );
 			view.render();
 
 			sinon.assert.calledWithExactly( spy.getCall( 0 ), view.urlInputView.element );
@@ -115,7 +115,7 @@ describe( 'LinkFormView', () => {
 		} );
 
 		it( 'starts listening for #keystrokes coming from #element', () => {
-			view = new LinkFormView( { t: () => {} }, [] );
+			view = new LinkFormView( { t: () => {} } );
 
 			const spy = sinon.spy( view.keystrokes, 'listenTo' );