From fdb0c869fd5bbf6082b7a6e7d46108c0604f3852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Jun 2019 17:05:02 +0200 Subject: [PATCH 01/30] Multi command proof of concept. --- src/multicommand.js | 46 +++++++++++++++++++++++++++++++++++++++++ tests/manual/article.js | 18 +++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/multicommand.js diff --git a/src/multicommand.js b/src/multicommand.js new file mode 100644 index 00000000..793ae41d --- /dev/null +++ b/src/multicommand.js @@ -0,0 +1,46 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +import Command from './command'; +import Collection from '@ckeditor/ckeditor5-utils/src/collection'; + +/** + * @module core/multicommand + */ + +export default class MultiCommand extends Command { + constructor( editor ) { + super( editor ); + + this._childCommands = new Collection(); + } + + refresh() { + // The command listens to child commands rather then acts on refresh. + // TODO: check with track changes. + } + + execute() { + const { command } = this._getEnabled(); + + command.execute(); + } + + registerChildCommand( command ) { + this._childCommands.add( { command } ); + + command.on( 'change:isEnabled', () => this._checkEnabled() ); + + this._checkEnabled(); + } + + _checkEnabled() { + this.isEnabled = !!this._getEnabled(); + } + + _getEnabled() { + return this._childCommands.find( ( { command } ) => command.isEnabled ); + } +} diff --git a/tests/manual/article.js b/tests/manual/article.js index fc23773d..e19d818e 100644 --- a/tests/manual/article.js +++ b/tests/manual/article.js @@ -8,10 +8,26 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import ArticlePluginSet from '../_utils/articlepluginset'; +import MultiCommand from '../../src/multicommand'; +import Plugin from '../../src/plugin'; + +class IndentOutdent extends Plugin { + afterInit() { + const editor = this.editor; + + const indentCommand = new MultiCommand( editor ); + indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) ); + editor.commands.add( 'indent', indentCommand ); + + const outdentCommand = new MultiCommand( editor ); + outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) ); + editor.commands.add( 'outdent', outdentCommand ); + } +} ClassicEditor .create( document.querySelector( '#editor' ), { - plugins: [ ArticlePluginSet ], + plugins: [ ArticlePluginSet, IndentOutdent ], toolbar: [ 'heading', '|', From 5f6039ef03e17525bd862f30f00b4aa3f38e779b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Jun 2019 17:17:23 +0200 Subject: [PATCH 02/30] Add indent/outdent buttons stubs. --- tests/manual/article.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/manual/article.js b/tests/manual/article.js index e19d818e..5bc44f9e 100644 --- a/tests/manual/article.js +++ b/tests/manual/article.js @@ -10,8 +10,39 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor' import ArticlePluginSet from '../_utils/articlepluginset'; import MultiCommand from '../../src/multicommand'; import Plugin from '../../src/plugin'; +import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; class IndentOutdent extends Plugin { + init() { + const editor = this.editor; + const t = editor.t; + + this._createButton( 'indent', t( 'Indent' ) ); + this._createButton( 'outdent', t( 'Outdent' ) ); + } + + _createButton( commandName, label ) { + const editor = this.editor; + + editor.ui.componentFactory.add( commandName, locale => { + const command = editor.commands.get( commandName ); + const view = new ButtonView( locale ); + + view.set( { + label, + withText: true, + tooltip: true + } ); + + view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); + + // Execute command. + this.listenTo( view, 'execute', () => editor.execute( commandName ) ); + + return view; + } ); + } + afterInit() { const editor = this.editor; @@ -34,8 +65,13 @@ ClassicEditor 'bold', 'italic', 'link', + '|', + 'indent', + 'outdent', + '|', 'bulletedList', 'numberedList', + '|', 'blockQuote', 'insertTable', 'mediaEmbed', From c7a9f7b5adf4cd4cb37c9c10d09da352dc783596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 6 Jun 2019 17:32:38 +0200 Subject: [PATCH 03/30] Stub indent conversion. --- tests/manual/article.html | 2 +- tests/manual/article.js | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/manual/article.html b/tests/manual/article.html index 4faffd0a..1b8e2bfa 100644 --- a/tests/manual/article.html +++ b/tests/manual/article.html @@ -8,7 +8,7 @@

Heading 1

-

Paragraph

+

Paragraph

Bold Italic Link

  • UL List item 1
  • diff --git a/tests/manual/article.js b/tests/manual/article.js index 5bc44f9e..8b15c682 100644 --- a/tests/manual/article.js +++ b/tests/manual/article.js @@ -56,9 +56,45 @@ class IndentOutdent extends Plugin { } } +class IndentBlock extends Plugin { + init() { + const schema = this.editor.model.schema; + const conversion = this.editor.conversion; + + schema.extend( 'paragraph', { allowAttributes: 'indent' } ); + schema.extend( 'heading1', { allowAttributes: 'indent' } ); + + conversion.for( 'upcast' ).attributeToAttribute( { + view: { + styles: { + 'margin-left': /[\s\S]+/ + } + }, + model: { + key: 'indent', + value: viewElement => { + return viewElement.getStyle( 'margin-left' ); + } + } + } ); + + conversion.for( 'downcast' ).attributeToAttribute( { + model: 'indent', + view: modelAttributeValue => { + return { + key: 'style', + value: { + 'margin-left': modelAttributeValue + } + }; + } + } ); + } +} + ClassicEditor .create( document.querySelector( '#editor' ), { - plugins: [ ArticlePluginSet, IndentOutdent ], + plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ], toolbar: [ 'heading', '|', From db2d11f9c577dbf94ee7697609a8072f8c09ee8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Jun 2019 11:56:38 +0200 Subject: [PATCH 04/30] Prepare buttons POC. --- tests/manual/article.js | 83 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/tests/manual/article.js b/tests/manual/article.js index 8b15c682..10a30050 100644 --- a/tests/manual/article.js +++ b/tests/manual/article.js @@ -11,6 +11,53 @@ import ArticlePluginSet from '../_utils/articlepluginset'; import MultiCommand from '../../src/multicommand'; import Plugin from '../../src/plugin'; import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; +import Command from '../../src/command'; +import first from '@ckeditor/ckeditor5-utils/src/first'; + +class IndentBlockCommand extends Command { + /** + * @inheritDoc + */ + refresh() { + this.isEnabled = this._checkEnabled(); + } + + /** + * Indents or outdents (depends on the {@link #constructor}'s `indentDirection` parameter) selected list items. + * + * @fires execute + */ + execute() { + const model = this.editor.model; + const doc = model.document; + + const itemsToChange = Array.from( doc.selection.getSelectedBlocks() ); + + model.change( () => { + for ( const item of itemsToChange ) { + console.log( 'indent block', item ); + } + } ); + } + + /** + * Checks whether the command can be enabled in the current context. + * + * @private + * @returns {Boolean} Whether the command should be enabled. + */ + _checkEnabled() { + // Check whether any of position's ancestor is a list item. + const block = first( this.editor.model.document.selection.getSelectedBlocks() ); + + // If selection is not in a list item, the command is disabled. + if ( !block || !this.editor.model.schema.checkAttribute( block, 'indent' ) ) { + return false; + } + + return true; + } +} class IndentOutdent extends Plugin { init() { @@ -18,7 +65,11 @@ class IndentOutdent extends Plugin { const t = editor.t; this._createButton( 'indent', t( 'Indent' ) ); - this._createButton( 'outdent', t( 'Outdent' ) ); + // this._createButton( 'outdent', t( 'Outdent' ) ); + this._createButton( 'indentList', t( 'Indent List' ) ); + // this._createButton( 'outdentList', t( 'Outdent List' ) ); + this._createButton( 'indentBlock', t( 'Indent Block' ) ); + // this._createButton( 'outdentBlock', t( 'Outdent Block' ) ); } _createButton( commandName, label ) { @@ -46,10 +97,20 @@ class IndentOutdent extends Plugin { afterInit() { const editor = this.editor; + editor.commands.add( 'indentBlock', new IndentBlockCommand( editor ) ); + const indentCommand = new MultiCommand( editor ); + indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) ); + indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) ); + editor.commands.add( 'indent', indentCommand ); + // TODO nicer API? + // editor.commands.add( 'indentList', new Command(), 'indent' ); + // editor.commands.addMulti( 'indentList', new Command(), 'indent' ); + // editor.commands.addMulti( 'indentList', 'indent' ); + const outdentCommand = new MultiCommand( editor ); outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) ); editor.commands.add( 'outdent', outdentCommand ); @@ -97,20 +158,26 @@ ClassicEditor plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ], toolbar: [ 'heading', - '|', - 'bold', - 'italic', - 'link', + // '|', + // 'bold', + // 'italic', + // 'link', '|', 'indent', 'outdent', '|', + 'indentList', + 'outdentList', + '|', + 'indentBlock', + 'outdentBlock', + '|', 'bulletedList', 'numberedList', '|', - 'blockQuote', - 'insertTable', - 'mediaEmbed', + // 'blockQuote', + // 'insertTable', + // 'mediaEmbed', 'undo', 'redo' ], From e83aaacb7ae57533f86f04b590b6b9c502ec8c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 7 Jun 2019 12:58:11 +0200 Subject: [PATCH 05/30] Remove block indentation POC. --- tests/manual/article.js | 169 ++-------------------------------------- 1 file changed, 7 insertions(+), 162 deletions(-) diff --git a/tests/manual/article.js b/tests/manual/article.js index 10a30050..fc23773d 100644 --- a/tests/manual/article.js +++ b/tests/manual/article.js @@ -8,176 +8,21 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor'; import ArticlePluginSet from '../_utils/articlepluginset'; -import MultiCommand from '../../src/multicommand'; -import Plugin from '../../src/plugin'; -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; -import Command from '../../src/command'; -import first from '@ckeditor/ckeditor5-utils/src/first'; - -class IndentBlockCommand extends Command { - /** - * @inheritDoc - */ - refresh() { - this.isEnabled = this._checkEnabled(); - } - - /** - * Indents or outdents (depends on the {@link #constructor}'s `indentDirection` parameter) selected list items. - * - * @fires execute - */ - execute() { - const model = this.editor.model; - const doc = model.document; - - const itemsToChange = Array.from( doc.selection.getSelectedBlocks() ); - - model.change( () => { - for ( const item of itemsToChange ) { - console.log( 'indent block', item ); - } - } ); - } - - /** - * Checks whether the command can be enabled in the current context. - * - * @private - * @returns {Boolean} Whether the command should be enabled. - */ - _checkEnabled() { - // Check whether any of position's ancestor is a list item. - const block = first( this.editor.model.document.selection.getSelectedBlocks() ); - - // If selection is not in a list item, the command is disabled. - if ( !block || !this.editor.model.schema.checkAttribute( block, 'indent' ) ) { - return false; - } - - return true; - } -} - -class IndentOutdent extends Plugin { - init() { - const editor = this.editor; - const t = editor.t; - - this._createButton( 'indent', t( 'Indent' ) ); - // this._createButton( 'outdent', t( 'Outdent' ) ); - this._createButton( 'indentList', t( 'Indent List' ) ); - // this._createButton( 'outdentList', t( 'Outdent List' ) ); - this._createButton( 'indentBlock', t( 'Indent Block' ) ); - // this._createButton( 'outdentBlock', t( 'Outdent Block' ) ); - } - - _createButton( commandName, label ) { - const editor = this.editor; - - editor.ui.componentFactory.add( commandName, locale => { - const command = editor.commands.get( commandName ); - const view = new ButtonView( locale ); - - view.set( { - label, - withText: true, - tooltip: true - } ); - - view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); - - // Execute command. - this.listenTo( view, 'execute', () => editor.execute( commandName ) ); - - return view; - } ); - } - - afterInit() { - const editor = this.editor; - - editor.commands.add( 'indentBlock', new IndentBlockCommand( editor ) ); - - const indentCommand = new MultiCommand( editor ); - - indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) ); - indentCommand.registerChildCommand( editor.commands.get( 'indentBlock' ) ); - - editor.commands.add( 'indent', indentCommand ); - - // TODO nicer API? - // editor.commands.add( 'indentList', new Command(), 'indent' ); - // editor.commands.addMulti( 'indentList', new Command(), 'indent' ); - // editor.commands.addMulti( 'indentList', 'indent' ); - - const outdentCommand = new MultiCommand( editor ); - outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) ); - editor.commands.add( 'outdent', outdentCommand ); - } -} - -class IndentBlock extends Plugin { - init() { - const schema = this.editor.model.schema; - const conversion = this.editor.conversion; - - schema.extend( 'paragraph', { allowAttributes: 'indent' } ); - schema.extend( 'heading1', { allowAttributes: 'indent' } ); - - conversion.for( 'upcast' ).attributeToAttribute( { - view: { - styles: { - 'margin-left': /[\s\S]+/ - } - }, - model: { - key: 'indent', - value: viewElement => { - return viewElement.getStyle( 'margin-left' ); - } - } - } ); - - conversion.for( 'downcast' ).attributeToAttribute( { - model: 'indent', - view: modelAttributeValue => { - return { - key: 'style', - value: { - 'margin-left': modelAttributeValue - } - }; - } - } ); - } -} ClassicEditor .create( document.querySelector( '#editor' ), { - plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ], + plugins: [ ArticlePluginSet ], toolbar: [ 'heading', - // '|', - // 'bold', - // 'italic', - // 'link', - '|', - 'indent', - 'outdent', - '|', - 'indentList', - 'outdentList', - '|', - 'indentBlock', - 'outdentBlock', '|', + 'bold', + 'italic', + 'link', 'bulletedList', 'numberedList', - '|', - // 'blockQuote', - // 'insertTable', - // 'mediaEmbed', + 'blockQuote', + 'insertTable', + 'mediaEmbed', 'undo', 'redo' ], From 7833999ac4c00a63903d46798157280044811c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Tue, 11 Jun 2019 13:29:38 +0200 Subject: [PATCH 06/30] Extract Indent plugin stub. --- src/indent.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/indent.js diff --git a/src/indent.js b/src/indent.js new file mode 100644 index 00000000..d1f6eaac --- /dev/null +++ b/src/indent.js @@ -0,0 +1,55 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/** + * @module core/indent + */ +import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; + +import Plugin from './plugin'; +import MultiCommand from './multicommand'; + +export default class Indent extends Plugin { + init() { + const editor = this.editor; + const t = editor.t; + + editor.commands.add( 'indent', new MultiCommand( editor ) ); + editor.commands.add( 'outdent', new MultiCommand( editor ) ); + + this._createButton( 'indent', t( '>' ) ); + this._createButton( 'outdent', t( '<' ) ); + + // TODO: temporary - tests only + this._createButton( 'indentList', t( '> List' ) ); + this._createButton( 'outdentList', t( '< List' ) ); + + // TODO: temporary - tests only + this._createButton( 'indentBlock', t( '> Block' ) ); + this._createButton( 'outdentBlock', t( '< Block' ) ); + } + + _createButton( commandName, label ) { + const editor = this.editor; + + editor.ui.componentFactory.add( commandName, locale => { + const command = editor.commands.get( commandName ); + const view = new ButtonView( locale ); + + view.set( { + label, + withText: true, + tooltip: true + } ); + + view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); + + // Execute command. + this.listenTo( view, 'execute', () => editor.execute( commandName ) ); + + return view; + } ); + } +} From a53d8c503ca1b4defda9b301524d8949b966e7f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 12 Jun 2019 16:53:57 +0200 Subject: [PATCH 07/30] Add docs for indent plugin. --- src/indent.js | 46 +++++++++++++++++++++++--------- tests/indent.js | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 tests/indent.js diff --git a/src/indent.js b/src/indent.js index d1f6eaac..79f8221b 100644 --- a/src/indent.js +++ b/src/indent.js @@ -11,7 +11,31 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import Plugin from './plugin'; import MultiCommand from './multicommand'; +/** + * The indent feature. + * + * This plugin acts as a single entry point plugin for other features that implements indenting of elements like list or paragraphs. + * + * It registers the `'indent'` and `'outdent'` commands and it introduces the `'indent'` and `'outdent'` buttons that allow to + * increase or decrease text indentation of supported elements. + * + * The compatible features are: + * - the {@link module:list/list~List list} or {@link module:list/listediting~ListEditing list editing} feature for list indentation + * - the {@link module:indent-block/indentblock~IndentBlock block indentation} feature for indenting text blocks like paragraphs or headings + * + * **Note**: In order the commands and buttons to work at least one of compatible features is required. + */ export default class Indent extends Plugin { + /** + * @inheritDoc + */ + static get pluginName() { + return 'Indent'; + } + + /** + * @inheritDoc + */ init() { const editor = this.editor; const t = editor.t; @@ -19,19 +43,18 @@ export default class Indent extends Plugin { editor.commands.add( 'indent', new MultiCommand( editor ) ); editor.commands.add( 'outdent', new MultiCommand( editor ) ); - this._createButton( 'indent', t( '>' ) ); - this._createButton( 'outdent', t( '<' ) ); - - // TODO: temporary - tests only - this._createButton( 'indentList', t( '> List' ) ); - this._createButton( 'outdentList', t( '< List' ) ); - - // TODO: temporary - tests only - this._createButton( 'indentBlock', t( '> Block' ) ); - this._createButton( 'outdentBlock', t( '< Block' ) ); + this._defineButton( 'indent', t( 'Increase indent' ) ); + this._defineButton( 'outdent', t( 'Decrease indent' ) ); } - _createButton( commandName, label ) { + /** + * Defines an UI button. + * + * @param {String} commandName + * @param {String} label + * @private + */ + _defineButton( commandName, label ) { const editor = this.editor; editor.ui.componentFactory.add( commandName, locale => { @@ -46,7 +69,6 @@ export default class Indent extends Plugin { view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); - // Execute command. this.listenTo( view, 'execute', () => editor.execute( commandName ) ); return view; diff --git a/tests/indent.js b/tests/indent.js new file mode 100644 index 00000000..faa890ae --- /dev/null +++ b/tests/indent.js @@ -0,0 +1,70 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/* global document */ + +import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; +import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; + +import Indent from '../src/indent'; +import MultiCommand from '../src/multicommand'; + +describe.only( 'indent', () => { + let editor, element; + + testUtils.createSinonSandbox(); + + beforeEach( () => { + element = document.createElement( 'div' ); + document.body.appendChild( element ); + + return ClassicTestEditor + .create( element, { plugins: [ Indent ] } ) + .then( newEditor => { + editor = newEditor; + } ); + } ); + + afterEach( () => { + element.remove(); + + if ( editor ) { + return editor.destroy(); + } + } ); + + it( 'should be named', () => { + expect( Indent.pluginName ).to.equal( 'Indent' ); + } ); + + it( 'should be loaded', () => { + expect( editor.plugins.get( Indent ) ).to.be.instanceOf( Indent ); + } ); + + it( 'should register indent command', () => { + const command = editor.commands.get( 'indent' ); + + expect( command ).to.be.instanceof( MultiCommand ); + } ); + + it( 'should register outdent command', () => { + const command = editor.commands.get( 'outdent' ); + + expect( command ).to.be.instanceof( MultiCommand ); + } ); + + it( 'should set up button for indent', () => { + const indentButton = editor.ui.componentFactory.create( 'indent' ); + + expect( indentButton ).to.be.instanceOf( ButtonView ); + } ); + + it( 'should set up button for indent', () => { + const outdentButton = editor.ui.componentFactory.create( 'outdent' ); + + expect( outdentButton ).to.be.instanceOf( ButtonView ); + } ); +} ); From efc9fa006fa788f83afff10cfdae4c5f87ad47d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 12 Jun 2019 16:58:38 +0200 Subject: [PATCH 08/30] Remove .only from tests. --- tests/indent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/indent.js b/tests/indent.js index faa890ae..583f186c 100644 --- a/tests/indent.js +++ b/tests/indent.js @@ -12,7 +12,7 @@ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import Indent from '../src/indent'; import MultiCommand from '../src/multicommand'; -describe.only( 'indent', () => { +describe( 'indent', () => { let editor, element; testUtils.createSinonSandbox(); From 2c351985db091922e4a501239fcd8c5ca44e1680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 12 Jun 2019 17:38:43 +0200 Subject: [PATCH 09/30] Update docs. --- src/indent.js | 6 +++-- src/multicommand.js | 53 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/indent.js b/src/indent.js index 79f8221b..c5670001 100644 --- a/src/indent.js +++ b/src/indent.js @@ -20,10 +20,12 @@ import MultiCommand from './multicommand'; * increase or decrease text indentation of supported elements. * * The compatible features are: - * - the {@link module:list/list~List list} or {@link module:list/listediting~ListEditing list editing} feature for list indentation - * - the {@link module:indent-block/indentblock~IndentBlock block indentation} feature for indenting text blocks like paragraphs or headings + * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation + * - the {@link module:indent-block/indentblock~IndentBlock} feature for indenting text blocks like paragraphs or headings * * **Note**: In order the commands and buttons to work at least one of compatible features is required. + * + * @extends module:core/plugin~Plugin */ export default class Indent extends Plugin { /** diff --git a/src/multicommand.js b/src/multicommand.js index 793ae41d..d486093a 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -10,37 +10,76 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; * @module core/multicommand */ +/** + * A CKEditor command that aggregates other commands. + * + * This command is used to proxy multiple commands. The multi command is enabled when one of its registered child commands is enabled. + * Whe executing multi command the first command that is enabled will be executed. + * + * @extends module:core/command~Command + */ export default class MultiCommand extends Command { + /** + * @inheritDoc + */ constructor( editor ) { super( editor ); + /** + * Registered child commands. + * + * @type {module:utils/collection~Collection.} + * @private + */ this._childCommands = new Collection(); } + /** + * @inheritDoc + */ refresh() { - // The command listens to child commands rather then acts on refresh. - // TODO: check with track changes. + // Override base command refresh(): the command's state is changed when one of child commands changes states. } - execute() { - const { command } = this._getEnabled(); + /** + * Executes the first of it registered child commands. + */ + execute( ...args ) { + const { command } = this._getFirstEnabledCommand(); - command.execute(); + command.execute( args ); } + /** + * Registers a command as child command. + * + * @param {module:core/command~Command} command + */ registerChildCommand( command ) { this._childCommands.add( { command } ); + // Change multi command enabled state when one of registered commands changes state. command.on( 'change:isEnabled', () => this._checkEnabled() ); this._checkEnabled(); } + /** + * Checks if any of child commands is enabled. + * + * @private + */ _checkEnabled() { - this.isEnabled = !!this._getEnabled(); + this.isEnabled = !!this._getFirstEnabledCommand(); } - _getEnabled() { + /** + * Returns a first enabled command or undefined if none of them is enabled. + * + * @returns {module:core/command~Command|undefined} + * @private + */ + _getFirstEnabledCommand() { return this._childCommands.find( ( { command } ) => command.isEnabled ); } } From 618b31aeee50e3a9f218b69adb7d1ce73e2e928a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 13 Jun 2019 17:56:58 +0200 Subject: [PATCH 10/30] Add missing test for MultiCommand. --- tests/multicommand.js | 124 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 tests/multicommand.js diff --git a/tests/multicommand.js b/tests/multicommand.js new file mode 100644 index 00000000..e67742ce --- /dev/null +++ b/tests/multicommand.js @@ -0,0 +1,124 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +import MultiCommand from '../src/multicommand'; +import ModelTestEditor from './_utils/modeltesteditor'; +import Command from '../src/command'; + +describe( 'MultiCommand', () => { + let editor, multiCommand; + + beforeEach( () => { + return ModelTestEditor + .create() + .then( newEditor => { + editor = newEditor; + multiCommand = new MultiCommand( editor ); + } ); + } ); + + afterEach( () => { + multiCommand.destroy(); + + return editor.destroy(); + } ); + + describe( 'isEnabled', () => { + it( 'is always falsy when no child commands are registered', () => { + expect( multiCommand.isEnabled ).to.false; + + multiCommand.refresh(); + + expect( multiCommand.isEnabled ).to.false; + } ); + + it( 'is set to true if one of registered commands is true', () => { + expect( multiCommand.isEnabled ).to.false; + + const commandA = new Command( editor ); + const commandB = new Command( editor ); + + multiCommand.registerChildCommand( commandA ); + multiCommand.registerChildCommand( commandB ); + + expect( multiCommand.isEnabled ).to.false; + + commandA.isEnabled = true; + + expect( multiCommand.isEnabled ).to.be.true; + + commandA.isEnabled = false; + + expect( multiCommand.isEnabled ).to.be.false; + + commandB.isEnabled = true; + + expect( multiCommand.isEnabled ).to.be.true; + } ); + } ); + + describe( 'execute()', () => { + it( 'does not call any command if all are disabled', () => { + const commandA = new Command( editor ); + const commandB = new Command( editor ); + + multiCommand.registerChildCommand( commandA ); + multiCommand.registerChildCommand( commandB ); + + const spyA = sinon.spy( commandA, 'execute' ); + const spyB = sinon.spy( commandB, 'execute' ); + + multiCommand.execute(); + + sinon.assert.notCalled( spyA ); + sinon.assert.notCalled( spyB ); + } ); + + it( 'executes enabled command', () => { + const commandA = new Command( editor ); + const commandB = new Command( editor ); + const commandC = new Command( editor ); + + multiCommand.registerChildCommand( commandA ); + multiCommand.registerChildCommand( commandB ); + multiCommand.registerChildCommand( commandC ); + + const spyA = sinon.spy( commandA, 'execute' ); + const spyB = sinon.spy( commandB, 'execute' ); + const spyC = sinon.spy( commandC, 'execute' ); + + commandC.isEnabled = true; + + multiCommand.execute(); + + sinon.assert.notCalled( spyA ); + sinon.assert.notCalled( spyB ); + sinon.assert.calledOnce( spyC ); + } ); + + it( 'executes first registered command if many are enabled', () => { + const commandA = new Command( editor ); + const commandB = new Command( editor ); + const commandC = new Command( editor ); + + multiCommand.registerChildCommand( commandA ); + multiCommand.registerChildCommand( commandB ); + multiCommand.registerChildCommand( commandC ); + + const spyA = sinon.spy( commandA, 'execute' ); + const spyB = sinon.spy( commandB, 'execute' ); + const spyC = sinon.spy( commandC, 'execute' ); + + commandC.isEnabled = true; + commandB.isEnabled = true; + + multiCommand.execute(); + + sinon.assert.notCalled( spyA ); + sinon.assert.calledOnce( spyB ); + sinon.assert.notCalled( spyC ); + } ); + } ); +} ); From 900aeaf3ec6cbdfb853c860aeccaf0b740912aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 13 Jun 2019 17:57:18 +0200 Subject: [PATCH 11/30] Add missing test for indent. --- tests/indent.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/indent.js b/tests/indent.js index 583f186c..3d6ef789 100644 --- a/tests/indent.js +++ b/tests/indent.js @@ -67,4 +67,24 @@ describe( 'indent', () => { expect( outdentButton ).to.be.instanceOf( ButtonView ); } ); + + it( 'should execute indent command on button execute', () => { + const button = editor.ui.componentFactory.create( 'indent' ); + const spy = sinon.spy( editor, 'execute' ); + + button.fire( 'execute' ); + + sinon.assert.calledOnce( spy ); + sinon.assert.calledWithExactly( spy, 'indent' ); + } ); + + it( 'should execute outdent command on button execute', () => { + const button = editor.ui.componentFactory.create( 'outdent' ); + const spy = sinon.spy( editor, 'execute' ); + + button.fire( 'execute' ); + + sinon.assert.calledOnce( spy ); + sinon.assert.calledWithExactly( spy, 'outdent' ); + } ); } ); From 79a6aa4392b50fbcd479af3262e02f3294125fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 14 Jun 2019 10:37:53 +0200 Subject: [PATCH 12/30] Split the Indent plugin to Indent, IndentEditing and IndentUI. --- src/indent.js | 55 +++++++---------------------- src/indentediting.js | 40 ++++++++++++++++++++++ src/indentui.js | 69 +++++++++++++++++++++++++++++++++++++ tests/indent.js | 54 ++++------------------------- tests/indentediting.js | 57 ++++++++++++++++++++++++++++++ tests/indentui.js | 78 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 264 insertions(+), 89 deletions(-) create mode 100644 src/indentediting.js create mode 100644 src/indentui.js create mode 100644 tests/indentediting.js create mode 100644 tests/indentui.js diff --git a/src/indent.js b/src/indent.js index c5670001..27901897 100644 --- a/src/indent.js +++ b/src/indent.js @@ -6,23 +6,29 @@ /** * @module core/indent */ -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import Plugin from './plugin'; -import MultiCommand from './multicommand'; + +import IndentEditing from './indentediting'; +import IndentUI from './indentui'; /** * The indent feature. * * This plugin acts as a single entry point plugin for other features that implements indenting of elements like list or paragraphs. * - * It registers the `'indent'` and `'outdent'` commands and it introduces the `'indent'` and `'outdent'` buttons that allow to - * increase or decrease text indentation of supported elements. - * * The compatible features are: * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation * - the {@link module:indent-block/indentblock~IndentBlock} feature for indenting text blocks like paragraphs or headings * + * This is a "glue" plugin which loads the following plugins: + * + * * The {@link module:core/indentediting~IndentEditing indent editing feature} and + * * The {@link module:core/indentui~IndentUI indent UI feature}. + * + * The dependent plugins registers the `'indent'` and `'outdent'` commands and it introduces the `'indent'` and `'outdent'` buttons + * that allow to increase or decrease text indentation of supported elements. + * * **Note**: In order the commands and buttons to work at least one of compatible features is required. * * @extends module:core/plugin~Plugin @@ -38,42 +44,7 @@ export default class Indent extends Plugin { /** * @inheritDoc */ - init() { - const editor = this.editor; - const t = editor.t; - - editor.commands.add( 'indent', new MultiCommand( editor ) ); - editor.commands.add( 'outdent', new MultiCommand( editor ) ); - - this._defineButton( 'indent', t( 'Increase indent' ) ); - this._defineButton( 'outdent', t( 'Decrease indent' ) ); - } - - /** - * Defines an UI button. - * - * @param {String} commandName - * @param {String} label - * @private - */ - _defineButton( commandName, label ) { - const editor = this.editor; - - editor.ui.componentFactory.add( commandName, locale => { - const command = editor.commands.get( commandName ); - const view = new ButtonView( locale ); - - view.set( { - label, - withText: true, - tooltip: true - } ); - - view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); - - this.listenTo( view, 'execute', () => editor.execute( commandName ) ); - - return view; - } ); + static get requires() { + return [ IndentEditing, IndentUI ]; } } diff --git a/src/indentediting.js b/src/indentediting.js new file mode 100644 index 00000000..f7c63f3e --- /dev/null +++ b/src/indentediting.js @@ -0,0 +1,40 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/** + * @module core/indentediting + */ + +import Plugin from './plugin'; +import MultiCommand from './multicommand'; + +/** + * The indent editing feature. + * + * This plugin registers the `'indent'` and `'outdent'` commands. + * + * **Note**: In order the commands to work at least one of compatible features is required. Read more in + * {@link module:core/indent~Indent indent feature} api docs. + * + * @extends module:core/plugin~Plugin + */ +export default class IndentEditing extends Plugin { + /** + * @inheritDoc + */ + static get pluginName() { + return 'IndentEditing'; + } + + /** + * @inheritDoc + */ + init() { + const editor = this.editor; + + editor.commands.add( 'indent', new MultiCommand( editor ) ); + editor.commands.add( 'outdent', new MultiCommand( editor ) ); + } +} diff --git a/src/indentui.js b/src/indentui.js new file mode 100644 index 00000000..ef6ee955 --- /dev/null +++ b/src/indentui.js @@ -0,0 +1,69 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/** + * @module core/indentui + */ +import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; + +import Plugin from './plugin'; + +/** + * The indent feature. + * + * This plugin registers the `'indent'` and `'outdent'` buttons. + * + * **Note**: In order the commands to work at least one of compatible features is required. Read more in + * {@link module:core/indent~Indent indent feature} api docs. + * + * @extends module:core/plugin~Plugin + */ +export default class IndentUI extends Plugin { + /** + * @inheritDoc + */ + static get pluginName() { + return 'IndentUI'; + } + + /** + * @inheritDoc + */ + init() { + const editor = this.editor; + const t = editor.t; + + this._defineButton( 'indent', t( 'Increase indent' ) ); + this._defineButton( 'outdent', t( 'Decrease indent' ) ); + } + + /** + * Defines an UI button. + * + * @param {String} commandName + * @param {String} label + * @private + */ + _defineButton( commandName, label ) { + const editor = this.editor; + + editor.ui.componentFactory.add( commandName, locale => { + const command = editor.commands.get( commandName ); + const view = new ButtonView( locale ); + + view.set( { + label, + withText: true, + tooltip: true + } ); + + view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); + + this.listenTo( view, 'execute', () => editor.execute( commandName ) ); + + return view; + } ); + } +} diff --git a/tests/indent.js b/tests/indent.js index 3d6ef789..96d5a6f1 100644 --- a/tests/indent.js +++ b/tests/indent.js @@ -7,12 +7,12 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import Indent from '../src/indent'; -import MultiCommand from '../src/multicommand'; +import IndentEditing from '../src/indentediting'; +import IndentUI from '../src/indentui'; -describe( 'indent', () => { +describe( 'Indent', () => { let editor, element; testUtils.createSinonSandbox(); @@ -40,51 +40,11 @@ describe( 'indent', () => { expect( Indent.pluginName ).to.equal( 'Indent' ); } ); - it( 'should be loaded', () => { - expect( editor.plugins.get( Indent ) ).to.be.instanceOf( Indent ); + it( 'should load the IndentUI plugin', () => { + expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI ); } ); - it( 'should register indent command', () => { - const command = editor.commands.get( 'indent' ); - - expect( command ).to.be.instanceof( MultiCommand ); - } ); - - it( 'should register outdent command', () => { - const command = editor.commands.get( 'outdent' ); - - expect( command ).to.be.instanceof( MultiCommand ); - } ); - - it( 'should set up button for indent', () => { - const indentButton = editor.ui.componentFactory.create( 'indent' ); - - expect( indentButton ).to.be.instanceOf( ButtonView ); - } ); - - it( 'should set up button for indent', () => { - const outdentButton = editor.ui.componentFactory.create( 'outdent' ); - - expect( outdentButton ).to.be.instanceOf( ButtonView ); - } ); - - it( 'should execute indent command on button execute', () => { - const button = editor.ui.componentFactory.create( 'indent' ); - const spy = sinon.spy( editor, 'execute' ); - - button.fire( 'execute' ); - - sinon.assert.calledOnce( spy ); - sinon.assert.calledWithExactly( spy, 'indent' ); - } ); - - it( 'should execute outdent command on button execute', () => { - const button = editor.ui.componentFactory.create( 'outdent' ); - const spy = sinon.spy( editor, 'execute' ); - - button.fire( 'execute' ); - - sinon.assert.calledOnce( spy ); - sinon.assert.calledWithExactly( spy, 'outdent' ); + it( 'should load the IndentEditing plugin', () => { + expect( editor.plugins.get( IndentEditing ) ).to.be.instanceOf( IndentEditing ); } ); } ); diff --git a/tests/indentediting.js b/tests/indentediting.js new file mode 100644 index 00000000..2d5ea72f --- /dev/null +++ b/tests/indentediting.js @@ -0,0 +1,57 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/* global document */ + +import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; +import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; + +import MultiCommand from '../src/multicommand'; +import IndentEditing from '../src/indentediting'; + +describe( 'IndentEditing', () => { + let editor, element; + + testUtils.createSinonSandbox(); + + beforeEach( () => { + element = document.createElement( 'div' ); + document.body.appendChild( element ); + + return ClassicTestEditor + .create( element, { plugins: [ IndentEditing ] } ) + .then( newEditor => { + editor = newEditor; + } ); + } ); + + afterEach( () => { + element.remove(); + + if ( editor ) { + return editor.destroy(); + } + } ); + + it( 'should be named', () => { + expect( IndentEditing.pluginName ).to.equal( 'IndentEditing' ); + } ); + + it( 'should be loaded', () => { + expect( editor.plugins.get( IndentEditing ) ).to.be.instanceOf( IndentEditing ); + } ); + + it( 'should register indent command', () => { + const command = editor.commands.get( 'indent' ); + + expect( command ).to.be.instanceof( MultiCommand ); + } ); + + it( 'should register outdent command', () => { + const command = editor.commands.get( 'outdent' ); + + expect( command ).to.be.instanceof( MultiCommand ); + } ); +} ); diff --git a/tests/indentui.js b/tests/indentui.js new file mode 100644 index 00000000..512dbe0d --- /dev/null +++ b/tests/indentui.js @@ -0,0 +1,78 @@ +/** + * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. + * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license + */ + +/* global document */ + +import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; +import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; + +import IndentEditing from '../src/indentediting'; +import IndentUI from '../src/indentui'; + +describe( 'IndentUI', () => { + let editor, element; + + testUtils.createSinonSandbox(); + + beforeEach( () => { + element = document.createElement( 'div' ); + document.body.appendChild( element ); + + return ClassicTestEditor + .create( element, { plugins: [ IndentUI, IndentEditing ] } ) + .then( newEditor => { + editor = newEditor; + } ); + } ); + + afterEach( () => { + element.remove(); + + if ( editor ) { + return editor.destroy(); + } + } ); + + it( 'should be named', () => { + expect( IndentUI.pluginName ).to.equal( 'IndentUI' ); + } ); + + it( 'should be loaded', () => { + expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI ); + } ); + + it( 'should set up button for indent', () => { + const indentButton = editor.ui.componentFactory.create( 'indent' ); + + expect( indentButton ).to.be.instanceOf( ButtonView ); + } ); + + it( 'should set up button for indent', () => { + const outdentButton = editor.ui.componentFactory.create( 'outdent' ); + + expect( outdentButton ).to.be.instanceOf( ButtonView ); + } ); + + it( 'should execute indent command on button execute', () => { + const button = editor.ui.componentFactory.create( 'indent' ); + const spy = sinon.spy( editor, 'execute' ); + + button.fire( 'execute' ); + + sinon.assert.calledOnce( spy ); + sinon.assert.calledWithExactly( spy, 'indent' ); + } ); + + it( 'should execute outdent command on button execute', () => { + const button = editor.ui.componentFactory.create( 'outdent' ); + const spy = sinon.spy( editor, 'execute' ); + + button.fire( 'execute' ); + + sinon.assert.calledOnce( spy ); + sinon.assert.calledWithExactly( spy, 'outdent' ); + } ); +} ); From 569eba3e4d603ea595404fbc730d62d44c5f8a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 14 Jun 2019 10:49:41 +0200 Subject: [PATCH 13/30] Use VirtualTestEditor in IndentEditing tests. --- tests/indentediting.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/indentediting.js b/tests/indentediting.js index 2d5ea72f..b4a1f01c 100644 --- a/tests/indentediting.js +++ b/tests/indentediting.js @@ -3,33 +3,26 @@ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ -/* global document */ - -import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; +import VirtualTestEditor from './_utils/virtualtesteditor'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; import MultiCommand from '../src/multicommand'; import IndentEditing from '../src/indentediting'; describe( 'IndentEditing', () => { - let editor, element; + let editor; testUtils.createSinonSandbox(); beforeEach( () => { - element = document.createElement( 'div' ); - document.body.appendChild( element ); - - return ClassicTestEditor - .create( element, { plugins: [ IndentEditing ] } ) + return VirtualTestEditor + .create( { plugins: [ IndentEditing ] } ) .then( newEditor => { editor = newEditor; } ); } ); afterEach( () => { - element.remove(); - if ( editor ) { return editor.destroy(); } From b1e2f8de2b769465e83e06c16c59fd51f407a23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 14 Jun 2019 10:55:04 +0200 Subject: [PATCH 14/30] Move Indent* plugins to indent/Indent. --- src/{ => indent}/indent.js | 8 ++++---- src/{ => indent}/indentediting.js | 8 ++++---- src/{ => indent}/indentui.js | 6 +++--- tests/{ => indent}/indent.js | 6 +++--- tests/{ => indent}/indentediting.js | 8 ++++---- tests/{ => indent}/indentui.js | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/{ => indent}/indent.js (85%) rename src/{ => indent}/indentediting.js (81%) rename src/{ => indent}/indentui.js (91%) rename tests/{ => indent}/indent.js (88%) rename tests/{ => indent}/indentediting.js (82%) rename tests/{ => indent}/indentui.js (94%) diff --git a/src/indent.js b/src/indent/indent.js similarity index 85% rename from src/indent.js rename to src/indent/indent.js index 27901897..afdbbdd1 100644 --- a/src/indent.js +++ b/src/indent/indent.js @@ -4,10 +4,10 @@ */ /** - * @module core/indent + * @module core/indent/indent */ -import Plugin from './plugin'; +import Plugin from '../plugin'; import IndentEditing from './indentediting'; import IndentUI from './indentui'; @@ -23,8 +23,8 @@ import IndentUI from './indentui'; * * This is a "glue" plugin which loads the following plugins: * - * * The {@link module:core/indentediting~IndentEditing indent editing feature} and - * * The {@link module:core/indentui~IndentUI indent UI feature}. + * * The {@link module:core/indent/indentediting~IndentEditing indent editing feature} and + * * The {@link module:core/indent/indentui~IndentUI indent UI feature}. * * The dependent plugins registers the `'indent'` and `'outdent'` commands and it introduces the `'indent'` and `'outdent'` buttons * that allow to increase or decrease text indentation of supported elements. diff --git a/src/indentediting.js b/src/indent/indentediting.js similarity index 81% rename from src/indentediting.js rename to src/indent/indentediting.js index f7c63f3e..c465697b 100644 --- a/src/indentediting.js +++ b/src/indent/indentediting.js @@ -4,11 +4,11 @@ */ /** - * @module core/indentediting + * @module core/indent/indentediting */ -import Plugin from './plugin'; -import MultiCommand from './multicommand'; +import Plugin from '../plugin'; +import MultiCommand from '../multicommand'; /** * The indent editing feature. @@ -16,7 +16,7 @@ import MultiCommand from './multicommand'; * This plugin registers the `'indent'` and `'outdent'` commands. * * **Note**: In order the commands to work at least one of compatible features is required. Read more in - * {@link module:core/indent~Indent indent feature} api docs. + * {@link module:core/indent/indent~Indent indent feature} api docs. * * @extends module:core/plugin~Plugin */ diff --git a/src/indentui.js b/src/indent/indentui.js similarity index 91% rename from src/indentui.js rename to src/indent/indentui.js index ef6ee955..95000314 100644 --- a/src/indentui.js +++ b/src/indent/indentui.js @@ -4,11 +4,11 @@ */ /** - * @module core/indentui + * @module core/indent/indentui */ import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; -import Plugin from './plugin'; +import Plugin from '../plugin'; /** * The indent feature. @@ -16,7 +16,7 @@ import Plugin from './plugin'; * This plugin registers the `'indent'` and `'outdent'` buttons. * * **Note**: In order the commands to work at least one of compatible features is required. Read more in - * {@link module:core/indent~Indent indent feature} api docs. + * {@link module:core/indent/indent~Indent indent feature} api docs. * * @extends module:core/plugin~Plugin */ diff --git a/tests/indent.js b/tests/indent/indent.js similarity index 88% rename from tests/indent.js rename to tests/indent/indent.js index 96d5a6f1..de1fd7c3 100644 --- a/tests/indent.js +++ b/tests/indent/indent.js @@ -8,9 +8,9 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; -import Indent from '../src/indent'; -import IndentEditing from '../src/indentediting'; -import IndentUI from '../src/indentui'; +import Indent from '../../src/indent/indent'; +import IndentEditing from '../../src/indent/indentediting'; +import IndentUI from '../../src/indent/indentui'; describe( 'Indent', () => { let editor, element; diff --git a/tests/indentediting.js b/tests/indent/indentediting.js similarity index 82% rename from tests/indentediting.js rename to tests/indent/indentediting.js index b4a1f01c..3dc64bbc 100644 --- a/tests/indentediting.js +++ b/tests/indent/indentediting.js @@ -3,11 +3,11 @@ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ -import VirtualTestEditor from './_utils/virtualtesteditor'; -import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import VirtualTestEditor from '../_utils/virtualtesteditor'; +import testUtils from '../_utils/utils'; -import MultiCommand from '../src/multicommand'; -import IndentEditing from '../src/indentediting'; +import MultiCommand from '../../src/multicommand'; +import IndentEditing from '../../src/indent/indentediting'; describe( 'IndentEditing', () => { let editor; diff --git a/tests/indentui.js b/tests/indent/indentui.js similarity index 94% rename from tests/indentui.js rename to tests/indent/indentui.js index 512dbe0d..0db7fe9e 100644 --- a/tests/indentui.js +++ b/tests/indent/indentui.js @@ -9,8 +9,8 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; -import IndentEditing from '../src/indentediting'; -import IndentUI from '../src/indentui'; +import IndentEditing from '../../src/indent/indentediting'; +import IndentUI from '../../src/indent/indentui'; describe( 'IndentUI', () => { let editor, element; From 7e7b4c77fbcadf91e63914633fc5768dda47860e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 14 Jun 2019 13:09:29 +0200 Subject: [PATCH 15/30] Add example to MultiCommand. --- src/multicommand.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/multicommand.js b/src/multicommand.js index d486093a..3687add2 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -16,6 +16,20 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; * This command is used to proxy multiple commands. The multi command is enabled when one of its registered child commands is enabled. * Whe executing multi command the first command that is enabled will be executed. * + * const multiCommand = new MultiCommand( editor ); + * + * const commandFoo = new Command( editor ); + * const commandBar = new Command( editor ); + * + * // Register child commands. + * multiCommand.registerChildCommand( commandFoo ); + * multiCommand.registerChildCommand( commandBar ); + * + * // Enable one of commands + * commandBar.isEnabled = true; + * + * multiCommand.execute(); // Will execute commandBar. + * * @extends module:core/command~Command */ export default class MultiCommand extends Command { From dd39d16088cae997a5a4ddec1194e9180f4bc7d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Fri, 14 Jun 2019 13:45:36 +0200 Subject: [PATCH 16/30] Remove invalid itself inports. --- tests/indent/indent.js | 4 ++-- tests/indent/indentui.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/indent/indent.js b/tests/indent/indent.js index de1fd7c3..8f07f3ea 100644 --- a/tests/indent/indent.js +++ b/tests/indent/indent.js @@ -5,8 +5,8 @@ /* global document */ -import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; -import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import ClassicTestEditor from '../_utils/classictesteditor'; +import testUtils from '../_utils/utils'; import Indent from '../../src/indent/indent'; import IndentEditing from '../../src/indent/indentediting'; diff --git a/tests/indent/indentui.js b/tests/indent/indentui.js index 0db7fe9e..8986ad6c 100644 --- a/tests/indent/indentui.js +++ b/tests/indent/indentui.js @@ -5,8 +5,8 @@ /* global document */ -import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; -import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; +import ClassicTestEditor from '../_utils/classictesteditor'; +import testUtils from '../_utils/utils'; import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import IndentEditing from '../../src/indent/indentediting'; From ccb9c2c8213c4cfc1b426967ae444fb5511c9c46 Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:27:47 +0200 Subject: [PATCH 17/30] Update src/multicommand.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/multicommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multicommand.js b/src/multicommand.js index 3687add2..ff12190b 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -25,7 +25,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; * multiCommand.registerChildCommand( commandFoo ); * multiCommand.registerChildCommand( commandBar ); * - * // Enable one of commands + * // Enable one of the commands. * commandBar.isEnabled = true; * * multiCommand.execute(); // Will execute commandBar. From e970541315f016e218cd29c4527d64c67dfd256b Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:28:18 +0200 Subject: [PATCH 18/30] Update src/multicommand.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/multicommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multicommand.js b/src/multicommand.js index ff12190b..01ec6bd8 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -13,7 +13,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; /** * A CKEditor command that aggregates other commands. * - * This command is used to proxy multiple commands. The multi command is enabled when one of its registered child commands is enabled. + * This command is used to proxy multiple commands. The multi-command is enabled when at least one of its registered child commands is enabled. * Whe executing multi command the first command that is enabled will be executed. * * const multiCommand = new MultiCommand( editor ); From d531bb957eced124dbb3d23d142b8055bcb303cf Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:28:32 +0200 Subject: [PATCH 19/30] Update src/multicommand.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/multicommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multicommand.js b/src/multicommand.js index 01ec6bd8..02c65dfc 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -14,7 +14,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; * A CKEditor command that aggregates other commands. * * This command is used to proxy multiple commands. The multi-command is enabled when at least one of its registered child commands is enabled. - * Whe executing multi command the first command that is enabled will be executed. + * When executing a multi-command the first command that is enabled will be executed. * * const multiCommand = new MultiCommand( editor ); * From 2ef389a782ba1eabcfab0088278450f60e7bef7b Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:28:46 +0200 Subject: [PATCH 20/30] Update src/multicommand.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/multicommand.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multicommand.js b/src/multicommand.js index 02c65dfc..8c7a426f 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -65,7 +65,7 @@ export default class MultiCommand extends Command { } /** - * Registers a command as child command. + * Registers a child command. * * @param {module:core/command~Command} command */ From 7340ad2bbca73377c7f1a1ffb20ca1414fb7ee0d Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:29:03 +0200 Subject: [PATCH 21/30] Update src/indent/indent.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/indent/indent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indent/indent.js b/src/indent/indent.js index afdbbdd1..53d6d0ae 100644 --- a/src/indent/indent.js +++ b/src/indent/indent.js @@ -15,7 +15,7 @@ import IndentUI from './indentui'; /** * The indent feature. * - * This plugin acts as a single entry point plugin for other features that implements indenting of elements like list or paragraphs. + * This plugin acts as a single entry point plugin for other features that implement indenting of elements like lists or paragraphs. * * The compatible features are: * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation From dafe54dcbf2982c04cbdf98d399a1626f7f7c37a Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:29:22 +0200 Subject: [PATCH 22/30] Update src/indent/indent.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/indent/indent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indent/indent.js b/src/indent/indent.js index 53d6d0ae..be39b1bb 100644 --- a/src/indent/indent.js +++ b/src/indent/indent.js @@ -26,7 +26,7 @@ import IndentUI from './indentui'; * * The {@link module:core/indent/indentediting~IndentEditing indent editing feature} and * * The {@link module:core/indent/indentui~IndentUI indent UI feature}. * - * The dependent plugins registers the `'indent'` and `'outdent'` commands and it introduces the `'indent'` and `'outdent'` buttons + * The dependent plugins register the `'indent'` and `'outdent'` commands and it introduce the `'indent'` and `'outdent'` buttons * that allow to increase or decrease text indentation of supported elements. * * **Note**: In order the commands and buttons to work at least one of compatible features is required. From e1661d0c0e753ef49306949b811cdcb863fd265e Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:29:37 +0200 Subject: [PATCH 23/30] Update src/indent/indent.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/indent/indent.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/indent/indent.js b/src/indent/indent.js index be39b1bb..274efe24 100644 --- a/src/indent/indent.js +++ b/src/indent/indent.js @@ -18,6 +18,7 @@ import IndentUI from './indentui'; * This plugin acts as a single entry point plugin for other features that implement indenting of elements like lists or paragraphs. * * The compatible features are: + * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation * - the {@link module:indent-block/indentblock~IndentBlock} feature for indenting text blocks like paragraphs or headings * From f2296c8557334ec9ed9476d290ac3dacba73c0e9 Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:29:49 +0200 Subject: [PATCH 24/30] Update src/indent/indent.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/indent/indent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indent/indent.js b/src/indent/indent.js index 274efe24..7fa97d3d 100644 --- a/src/indent/indent.js +++ b/src/indent/indent.js @@ -20,7 +20,7 @@ import IndentUI from './indentui'; * The compatible features are: * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation - * - the {@link module:indent-block/indentblock~IndentBlock} feature for indenting text blocks like paragraphs or headings + * * the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation * * This is a "glue" plugin which loads the following plugins: * From 401ac7afb2360abb1d17b573769ec13d8c56b856 Mon Sep 17 00:00:00 2001 From: Maciej Date: Wed, 26 Jun 2019 15:30:02 +0200 Subject: [PATCH 25/30] Update src/indent/indent.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Piotrek Koszuliński --- src/indent/indent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indent/indent.js b/src/indent/indent.js index 7fa97d3d..ff05de15 100644 --- a/src/indent/indent.js +++ b/src/indent/indent.js @@ -28,7 +28,7 @@ import IndentUI from './indentui'; * * The {@link module:core/indent/indentui~IndentUI indent UI feature}. * * The dependent plugins register the `'indent'` and `'outdent'` commands and it introduce the `'indent'` and `'outdent'` buttons - * that allow to increase or decrease text indentation of supported elements. + * which allow to increase or decrease text indentation of supported elements. * * **Note**: In order the commands and buttons to work at least one of compatible features is required. * From 75b3176a34a0852afae5e095a59e369c59e499fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 26 Jun 2019 15:53:14 +0200 Subject: [PATCH 26/30] Move Indent* classes from core to intend plugin. --- src/indent/indent.js | 51 --------------------------- src/indent/indentediting.js | 40 --------------------- src/indent/indentui.js | 69 ------------------------------------- 3 files changed, 160 deletions(-) delete mode 100644 src/indent/indent.js delete mode 100644 src/indent/indentediting.js delete mode 100644 src/indent/indentui.js diff --git a/src/indent/indent.js b/src/indent/indent.js deleted file mode 100644 index ff05de15..00000000 --- a/src/indent/indent.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/** - * @module core/indent/indent - */ - -import Plugin from '../plugin'; - -import IndentEditing from './indentediting'; -import IndentUI from './indentui'; - -/** - * The indent feature. - * - * This plugin acts as a single entry point plugin for other features that implement indenting of elements like lists or paragraphs. - * - * The compatible features are: - - * - the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation - * * the {@link module:list/list~List} or {@link module:list/listediting~ListEditing} feature for list indentation - * - * This is a "glue" plugin which loads the following plugins: - * - * * The {@link module:core/indent/indentediting~IndentEditing indent editing feature} and - * * The {@link module:core/indent/indentui~IndentUI indent UI feature}. - * - * The dependent plugins register the `'indent'` and `'outdent'` commands and it introduce the `'indent'` and `'outdent'` buttons - * which allow to increase or decrease text indentation of supported elements. - * - * **Note**: In order the commands and buttons to work at least one of compatible features is required. - * - * @extends module:core/plugin~Plugin - */ -export default class Indent extends Plugin { - /** - * @inheritDoc - */ - static get pluginName() { - return 'Indent'; - } - - /** - * @inheritDoc - */ - static get requires() { - return [ IndentEditing, IndentUI ]; - } -} diff --git a/src/indent/indentediting.js b/src/indent/indentediting.js deleted file mode 100644 index c465697b..00000000 --- a/src/indent/indentediting.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/** - * @module core/indent/indentediting - */ - -import Plugin from '../plugin'; -import MultiCommand from '../multicommand'; - -/** - * The indent editing feature. - * - * This plugin registers the `'indent'` and `'outdent'` commands. - * - * **Note**: In order the commands to work at least one of compatible features is required. Read more in - * {@link module:core/indent/indent~Indent indent feature} api docs. - * - * @extends module:core/plugin~Plugin - */ -export default class IndentEditing extends Plugin { - /** - * @inheritDoc - */ - static get pluginName() { - return 'IndentEditing'; - } - - /** - * @inheritDoc - */ - init() { - const editor = this.editor; - - editor.commands.add( 'indent', new MultiCommand( editor ) ); - editor.commands.add( 'outdent', new MultiCommand( editor ) ); - } -} diff --git a/src/indent/indentui.js b/src/indent/indentui.js deleted file mode 100644 index 95000314..00000000 --- a/src/indent/indentui.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/** - * @module core/indent/indentui - */ -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; - -import Plugin from '../plugin'; - -/** - * The indent feature. - * - * This plugin registers the `'indent'` and `'outdent'` buttons. - * - * **Note**: In order the commands to work at least one of compatible features is required. Read more in - * {@link module:core/indent/indent~Indent indent feature} api docs. - * - * @extends module:core/plugin~Plugin - */ -export default class IndentUI extends Plugin { - /** - * @inheritDoc - */ - static get pluginName() { - return 'IndentUI'; - } - - /** - * @inheritDoc - */ - init() { - const editor = this.editor; - const t = editor.t; - - this._defineButton( 'indent', t( 'Increase indent' ) ); - this._defineButton( 'outdent', t( 'Decrease indent' ) ); - } - - /** - * Defines an UI button. - * - * @param {String} commandName - * @param {String} label - * @private - */ - _defineButton( commandName, label ) { - const editor = this.editor; - - editor.ui.componentFactory.add( commandName, locale => { - const command = editor.commands.get( commandName ); - const view = new ButtonView( locale ); - - view.set( { - label, - withText: true, - tooltip: true - } ); - - view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' ); - - this.listenTo( view, 'execute', () => editor.execute( commandName ) ); - - return view; - } ); - } -} From 3849a8c5f9dad7eff83c3abb8899dddec4d6bf0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 27 Jun 2019 10:19:51 +0200 Subject: [PATCH 27/30] Use an Array for internal commands store in MultiCommand. --- src/multicommand.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/multicommand.js b/src/multicommand.js index 8c7a426f..6afad569 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -13,7 +13,8 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection'; /** * A CKEditor command that aggregates other commands. * - * This command is used to proxy multiple commands. The multi-command is enabled when at least one of its registered child commands is enabled. + * This command is used to proxy multiple commands. The multi-command is enabled when + * at least one of its registered child commands is enabled. * When executing a multi-command the first command that is enabled will be executed. * * const multiCommand = new MultiCommand( editor ); @@ -42,10 +43,10 @@ export default class MultiCommand extends Command { /** * Registered child commands. * - * @type {module:utils/collection~Collection.} + * @type {Array.} * @private */ - this._childCommands = new Collection(); + this._childCommands = []; } /** @@ -59,7 +60,7 @@ export default class MultiCommand extends Command { * Executes the first of it registered child commands. */ execute( ...args ) { - const { command } = this._getFirstEnabledCommand(); + const command = this._getFirstEnabledCommand(); command.execute( args ); } @@ -70,7 +71,7 @@ export default class MultiCommand extends Command { * @param {module:core/command~Command} command */ registerChildCommand( command ) { - this._childCommands.add( { command } ); + this._childCommands.push( command ); // Change multi command enabled state when one of registered commands changes state. command.on( 'change:isEnabled', () => this._checkEnabled() ); @@ -94,6 +95,6 @@ export default class MultiCommand extends Command { * @private */ _getFirstEnabledCommand() { - return this._childCommands.find( ( { command } ) => command.isEnabled ); + return this._childCommands.find( command => command.isEnabled ); } } From f23cd7000826b70a4aa4284e46f2335b6ace6e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 27 Jun 2019 10:21:16 +0200 Subject: [PATCH 28/30] Move Indent* tests to indent also. --- tests/indent/indent.js | 50 ---------------------- tests/indent/indentediting.js | 50 ---------------------- tests/indent/indentui.js | 78 ----------------------------------- 3 files changed, 178 deletions(-) delete mode 100644 tests/indent/indent.js delete mode 100644 tests/indent/indentediting.js delete mode 100644 tests/indent/indentui.js diff --git a/tests/indent/indent.js b/tests/indent/indent.js deleted file mode 100644 index 8f07f3ea..00000000 --- a/tests/indent/indent.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/* global document */ - -import ClassicTestEditor from '../_utils/classictesteditor'; -import testUtils from '../_utils/utils'; - -import Indent from '../../src/indent/indent'; -import IndentEditing from '../../src/indent/indentediting'; -import IndentUI from '../../src/indent/indentui'; - -describe( 'Indent', () => { - let editor, element; - - testUtils.createSinonSandbox(); - - beforeEach( () => { - element = document.createElement( 'div' ); - document.body.appendChild( element ); - - return ClassicTestEditor - .create( element, { plugins: [ Indent ] } ) - .then( newEditor => { - editor = newEditor; - } ); - } ); - - afterEach( () => { - element.remove(); - - if ( editor ) { - return editor.destroy(); - } - } ); - - it( 'should be named', () => { - expect( Indent.pluginName ).to.equal( 'Indent' ); - } ); - - it( 'should load the IndentUI plugin', () => { - expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI ); - } ); - - it( 'should load the IndentEditing plugin', () => { - expect( editor.plugins.get( IndentEditing ) ).to.be.instanceOf( IndentEditing ); - } ); -} ); diff --git a/tests/indent/indentediting.js b/tests/indent/indentediting.js deleted file mode 100644 index 3dc64bbc..00000000 --- a/tests/indent/indentediting.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -import VirtualTestEditor from '../_utils/virtualtesteditor'; -import testUtils from '../_utils/utils'; - -import MultiCommand from '../../src/multicommand'; -import IndentEditing from '../../src/indent/indentediting'; - -describe( 'IndentEditing', () => { - let editor; - - testUtils.createSinonSandbox(); - - beforeEach( () => { - return VirtualTestEditor - .create( { plugins: [ IndentEditing ] } ) - .then( newEditor => { - editor = newEditor; - } ); - } ); - - afterEach( () => { - if ( editor ) { - return editor.destroy(); - } - } ); - - it( 'should be named', () => { - expect( IndentEditing.pluginName ).to.equal( 'IndentEditing' ); - } ); - - it( 'should be loaded', () => { - expect( editor.plugins.get( IndentEditing ) ).to.be.instanceOf( IndentEditing ); - } ); - - it( 'should register indent command', () => { - const command = editor.commands.get( 'indent' ); - - expect( command ).to.be.instanceof( MultiCommand ); - } ); - - it( 'should register outdent command', () => { - const command = editor.commands.get( 'outdent' ); - - expect( command ).to.be.instanceof( MultiCommand ); - } ); -} ); diff --git a/tests/indent/indentui.js b/tests/indent/indentui.js deleted file mode 100644 index 8986ad6c..00000000 --- a/tests/indent/indentui.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. - * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license - */ - -/* global document */ - -import ClassicTestEditor from '../_utils/classictesteditor'; -import testUtils from '../_utils/utils'; -import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; - -import IndentEditing from '../../src/indent/indentediting'; -import IndentUI from '../../src/indent/indentui'; - -describe( 'IndentUI', () => { - let editor, element; - - testUtils.createSinonSandbox(); - - beforeEach( () => { - element = document.createElement( 'div' ); - document.body.appendChild( element ); - - return ClassicTestEditor - .create( element, { plugins: [ IndentUI, IndentEditing ] } ) - .then( newEditor => { - editor = newEditor; - } ); - } ); - - afterEach( () => { - element.remove(); - - if ( editor ) { - return editor.destroy(); - } - } ); - - it( 'should be named', () => { - expect( IndentUI.pluginName ).to.equal( 'IndentUI' ); - } ); - - it( 'should be loaded', () => { - expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI ); - } ); - - it( 'should set up button for indent', () => { - const indentButton = editor.ui.componentFactory.create( 'indent' ); - - expect( indentButton ).to.be.instanceOf( ButtonView ); - } ); - - it( 'should set up button for indent', () => { - const outdentButton = editor.ui.componentFactory.create( 'outdent' ); - - expect( outdentButton ).to.be.instanceOf( ButtonView ); - } ); - - it( 'should execute indent command on button execute', () => { - const button = editor.ui.componentFactory.create( 'indent' ); - const spy = sinon.spy( editor, 'execute' ); - - button.fire( 'execute' ); - - sinon.assert.calledOnce( spy ); - sinon.assert.calledWithExactly( spy, 'indent' ); - } ); - - it( 'should execute outdent command on button execute', () => { - const button = editor.ui.componentFactory.create( 'outdent' ); - const spy = sinon.spy( editor, 'execute' ); - - button.fire( 'execute' ); - - sinon.assert.calledOnce( spy ); - sinon.assert.calledWithExactly( spy, 'outdent' ); - } ); -} ); From d8517ce0683a563d8faff0773b1921c1380f562e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 27 Jun 2019 10:54:18 +0200 Subject: [PATCH 29/30] Revert article manual tests html file. --- tests/manual/article.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/manual/article.html b/tests/manual/article.html index 1b8e2bfa..4faffd0a 100644 --- a/tests/manual/article.html +++ b/tests/manual/article.html @@ -8,7 +8,7 @@

    Heading 1

    -

    Paragraph

    +

    Paragraph

    Bold Italic Link

    • UL List item 1
    • From 0b23e78f57bb319e5f39bbce7a7294596d677570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Thu, 27 Jun 2019 14:14:36 +0200 Subject: [PATCH 30/30] Remove useless import from MultiCommand. --- src/multicommand.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/multicommand.js b/src/multicommand.js index 6afad569..a7ba6524 100644 --- a/src/multicommand.js +++ b/src/multicommand.js @@ -4,7 +4,6 @@ */ import Command from './command'; -import Collection from '@ckeditor/ckeditor5-utils/src/collection'; /** * @module core/multicommand