Explorar el Código

Updated basic styles classes after the removal of Controller class.

Aleksander Nowodziński hace 9 años
padre
commit
1cf76d06c6

+ 16 - 16
packages/ckeditor5-basic-styles/src/bold.js

@@ -5,9 +5,7 @@
 
 import Feature from '../core/feature.js';
 import BoldEngine from './boldengine.js';
-import ButtonController from '../ui/button/button.js';
 import ButtonView from '../ui/button/buttonview.js';
-import Model from '../ui/model.js';
 
 /**
  * The bold feature. It introduces the Bold button and the <kbd>Ctrl+B</kbd> keystroke.
@@ -34,23 +32,25 @@ export default class Bold extends Feature {
 		const command = editor.commands.get( 'bold' );
 		const keystroke = 'CTRL+B';
 
-		// Create button model.
-		const buttonModel = new Model( {
-			isEnabled: true,
-			isOn: false,
-			label: t( 'Bold' ),
-			icon: 'bold',
-			keystroke
-		} );
+		// Add bold button to feature components.
+		editor.ui.featureComponents.add( 'bold', ( locale ) => {
+			const view = new ButtonView( locale );
 
-		// Bind button model to command.
-		buttonModel.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
+			view.set( {
+				isEnabled: true,
+				isOn: false,
+				label: t( 'Bold' ),
+				icon: 'bold',
+				keystroke
+			} );
 
-		// Execute command.
-		this.listenTo( buttonModel, 'execute', () => editor.execute( 'bold' ) );
+			view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
 
-		// Add bold button to feature components.
-		editor.ui.featureComponents.add( 'bold', ButtonController, ButtonView, buttonModel );
+			// Execute command.
+			this.listenTo( view, 'execute', () => editor.execute( 'bold' ) );
+
+			return view;
+		} );
 
 		// Set the Ctrl+B keystroke.
 		editor.keystrokes.set( keystroke, 'bold' );

+ 16 - 16
packages/ckeditor5-basic-styles/src/italic.js

@@ -5,9 +5,7 @@
 
 import Feature from '../core/feature.js';
 import ItalicEngine from './italicengine.js';
-import ButtonController from '../ui/button/button.js';
 import ButtonView from '../ui/button/buttonview.js';
-import Model from '../ui/model.js';
 
 /**
  * The italic feature. It introduces the Italic button and the <kbd>Ctrl+I</kbd> keystroke.
@@ -34,23 +32,25 @@ export default class Italic extends Feature {
 		const command = editor.commands.get( 'italic' );
 		const keystroke = 'CTRL+I';
 
-		// Create button model.
-		const buttonModel = new Model( {
-			isEnabled: true,
-			isOn: false,
-			label: t( 'Italic' ),
-			icon: 'italic',
-			keystroke
-		} );
+		// Add bold button to feature components.
+		editor.ui.featureComponents.add( 'italic', ( locale ) => {
+			const view = new ButtonView( locale );
 
-		// Bind button model to command.
-		buttonModel.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
+			view.set( {
+				isEnabled: true,
+				isOn: false,
+				label: t( 'Italic' ),
+				icon: 'italic',
+				keystroke
+			} );
 
-		// Execute command.
-		this.listenTo( buttonModel, 'execute', () => editor.execute( 'italic' ) );
+			view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
 
-		// Add bold button to feature components.
-		editor.ui.featureComponents.add( 'italic', ButtonController, ButtonView, buttonModel );
+			// Execute command.
+			this.listenTo( view, 'execute', () => editor.execute( 'italic' ) );
+
+			return view;
+		} );
 
 		// Set the Ctrl+I keystroke.
 		editor.keystrokes.set( keystroke, 'italic' );

+ 10 - 12
packages/ckeditor5-basic-styles/tests/bold.js

@@ -8,14 +8,14 @@
 import ClassicTestEditor from 'tests/core/_utils/classictesteditor.js';
 import Bold from 'ckeditor5/basic-styles/bold.js';
 import BoldEngine from 'ckeditor5/basic-styles/boldengine.js';
-import ButtonController from 'ckeditor5/ui/button/button.js';
+import ButtonView from 'ckeditor5/ui/button/buttonview.js';
 import testUtils from 'tests/core/_utils/utils.js';
 import { keyCodes } from 'ckeditor5/utils/keyboard.js';
 
 testUtils.createSinonSandbox();
 
 describe( 'Bold', () => {
-	let editor, boldController;
+	let editor, boldView;
 
 	beforeEach( () => {
 		const editorElement = document.createElement( 'div' );
@@ -27,7 +27,7 @@ describe( 'Bold', () => {
 			.then( newEditor => {
 				editor = newEditor;
 
-				boldController = editor.ui.featureComponents.create( 'bold' );
+				boldView = editor.ui.featureComponents.create( 'bold' );
 			} );
 	} );
 
@@ -44,36 +44,34 @@ describe( 'Bold', () => {
 	} );
 
 	it( 'should register bold feature component', () => {
-		expect( boldController ).to.be.instanceOf( ButtonController );
+		expect( boldView ).to.be.instanceOf( ButtonView );
 	} );
 
 	it( 'should execute bold command on model execute event', () => {
 		const executeSpy = testUtils.sinon.spy( editor, 'execute' );
-		const model = boldController.model;
 
-		model.fire( 'execute' );
+		boldView.fire( 'execute' );
 
 		sinon.assert.calledOnce( executeSpy );
 		sinon.assert.calledWithExactly( executeSpy, 'bold' );
 	} );
 
 	it( 'should bind model to bold command', () => {
-		const model = boldController.model;
 		const command = editor.commands.get( 'bold' );
 
-		expect( model.isOn ).to.be.false;
+		expect( boldView.isOn ).to.be.false;
 
-		expect( model.isEnabled ).to.be.true;
+		expect( boldView.isEnabled ).to.be.true;
 
 		command.value = true;
-		expect( model.isOn ).to.be.true;
+		expect( boldView.isOn ).to.be.true;
 
 		command.isEnabled = false;
-		expect( model.isEnabled ).to.be.false;
+		expect( boldView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {
-		expect( boldController.model.keystroke ).to.equal( 'CTRL+B' );
+		expect( boldView.keystroke ).to.equal( 'CTRL+B' );
 	} );
 
 	it( 'should set editor keystroke', () => {

+ 10 - 12
packages/ckeditor5-basic-styles/tests/italic.js

@@ -8,14 +8,14 @@
 import ClassicTestEditor from 'tests/core/_utils/classictesteditor.js';
 import Italic from 'ckeditor5/basic-styles/italic.js';
 import ItalicEngine from 'ckeditor5/basic-styles/italicengine.js';
-import ButtonController from 'ckeditor5/ui/button/button.js';
+import ButtonView from 'ckeditor5/ui/button/buttonview.js';
 import testUtils from 'tests/core/_utils/utils.js';
 import { keyCodes } from 'ckeditor5/utils/keyboard.js';
 
 testUtils.createSinonSandbox();
 
 describe( 'Italic', () => {
-	let editor, italicController;
+	let editor, italicView;
 
 	beforeEach( () => {
 		const editorElement = document.createElement( 'div' );
@@ -27,7 +27,7 @@ describe( 'Italic', () => {
 			.then( newEditor => {
 				editor = newEditor;
 
-				italicController = editor.ui.featureComponents.create( 'italic' );
+				italicView = editor.ui.featureComponents.create( 'italic' );
 			} );
 	} );
 
@@ -44,36 +44,34 @@ describe( 'Italic', () => {
 	} );
 
 	it( 'should register italic feature component', () => {
-		expect( italicController ).to.be.instanceOf( ButtonController );
+		expect( italicView ).to.be.instanceOf( ButtonView );
 	} );
 
 	it( 'should execute italic command on model execute event', () => {
 		const executeSpy = testUtils.sinon.spy( editor, 'execute' );
-		const model = italicController.model;
 
-		model.fire( 'execute' );
+		italicView.fire( 'execute' );
 
 		sinon.assert.calledOnce( executeSpy );
 		sinon.assert.calledWithExactly( executeSpy, 'italic' );
 	} );
 
 	it( 'should bind model to italic command', () => {
-		const model = italicController.model;
 		const command = editor.commands.get( 'italic' );
 
-		expect( model.isOn ).to.be.false;
+		expect( italicView.isOn ).to.be.false;
 
-		expect( model.isEnabled ).to.be.true;
+		expect( italicView.isEnabled ).to.be.true;
 
 		command.value = true;
-		expect( model.isOn ).to.be.true;
+		expect( italicView.isOn ).to.be.true;
 
 		command.isEnabled = false;
-		expect( model.isEnabled ).to.be.false;
+		expect( italicView.isEnabled ).to.be.false;
 	} );
 
 	it( 'should set keystroke in the model', () => {
-		expect( italicController.model.keystroke ).to.equal( 'CTRL+I' );
+		expect( italicView.keystroke ).to.equal( 'CTRL+I' );
 	} );
 
 	it( 'should set editor keystroke', () => {