Browse Source

Update docs.

Maciej Gołaszewski 6 years ago
parent
commit
f23ef2ea62
2 changed files with 50 additions and 9 deletions
  1. 4 2
      packages/ckeditor5-core/src/indent.js
  2. 46 7
      packages/ckeditor5-core/src/multicommand.js

+ 4 - 2
packages/ckeditor5-core/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 {
 	/**

+ 46 - 7
packages/ckeditor5-core/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.<module:core/command~Command>}
+		 * @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 );
 	}
 }