@ckeditor/ckeditor5-core 35.2.0 → 35.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,108 +2,96 @@
2
2
  * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module core/commandcollection
8
7
  */
9
-
10
8
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
11
-
12
9
  /**
13
10
  * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
14
11
  */
15
12
  export default class CommandCollection {
16
- /**
17
- * Creates collection instance.
18
- */
19
- constructor() {
20
- /**
21
- * Command map.
22
- *
23
- * @private
24
- * @member {Map}
25
- */
26
- this._commands = new Map();
27
- }
28
-
29
- /**
30
- * Registers a new command.
31
- *
32
- * @param {String} commandName The name of the command.
33
- * @param {module:core/command~Command} command
34
- */
35
- add( commandName, command ) {
36
- this._commands.set( commandName, command );
37
- }
38
-
39
- /**
40
- * Retrieves a command from the collection.
41
- *
42
- * @param {String} commandName The name of the command.
43
- * @returns {module:core/command~Command}
44
- */
45
- get( commandName ) {
46
- return this._commands.get( commandName );
47
- }
48
-
49
- /**
50
- * Executes a command.
51
- *
52
- * @param {String} commandName The name of the command.
53
- * @param {*} [...commandParams] Command parameters.
54
- * @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
55
- */
56
- execute( commandName, ...args ) {
57
- const command = this.get( commandName );
58
-
59
- if ( !command ) {
60
- /**
61
- * Command does not exist.
62
- *
63
- * @error commandcollection-command-not-found
64
- * @param {String} commandName Name of the command.
65
- */
66
- throw new CKEditorError( 'commandcollection-command-not-found', this, { commandName } );
67
- }
68
-
69
- return command.execute( ...args );
70
- }
71
-
72
- /**
73
- * Returns iterator of command names.
74
- *
75
- * @returns {Iterable.<String>}
76
- */
77
- * names() {
78
- yield* this._commands.keys();
79
- }
80
-
81
- /**
82
- * Returns iterator of command instances.
83
- *
84
- * @returns {Iterable.<module:core/command~Command>}
85
- */
86
- * commands() {
87
- yield* this._commands.values();
88
- }
89
-
90
- /**
91
- * Iterable interface.
92
- *
93
- * Returns `[ commandName, commandInstance ]` pairs.
94
- *
95
- * @returns {Iterable.<Array>}
96
- */
97
- [ Symbol.iterator ]() {
98
- return this._commands[ Symbol.iterator ]();
99
- }
100
-
101
- /**
102
- * Destroys all collection commands.
103
- */
104
- destroy() {
105
- for ( const command of this.commands() ) {
106
- command.destroy();
107
- }
108
- }
13
+ /**
14
+ * Creates collection instance.
15
+ */
16
+ constructor() {
17
+ /**
18
+ * Command map.
19
+ *
20
+ * @private
21
+ * @member {Map}
22
+ */
23
+ this._commands = new Map();
24
+ }
25
+ /**
26
+ * Registers a new command.
27
+ *
28
+ * @param {String} commandName The name of the command.
29
+ * @param {module:core/command~Command} command
30
+ */
31
+ add(commandName, command) {
32
+ this._commands.set(commandName, command);
33
+ }
34
+ /**
35
+ * Retrieves a command from the collection.
36
+ *
37
+ * @param {String} commandName The name of the command.
38
+ * @returns {module:core/command~Command}
39
+ */
40
+ get(commandName) {
41
+ return this._commands.get(commandName);
42
+ }
43
+ /**
44
+ * Executes a command.
45
+ *
46
+ * @param {String} commandName The name of the command.
47
+ * @param {*} [...commandParams] Command parameters.
48
+ * @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
49
+ */
50
+ execute(commandName, ...args) {
51
+ const command = this.get(commandName);
52
+ if (!command) {
53
+ /**
54
+ * Command does not exist.
55
+ *
56
+ * @error commandcollection-command-not-found
57
+ * @param {String} commandName Name of the command.
58
+ */
59
+ throw new CKEditorError('commandcollection-command-not-found', this, { commandName });
60
+ }
61
+ return command.execute(...args);
62
+ }
63
+ /**
64
+ * Returns iterator of command names.
65
+ *
66
+ * @returns {Iterable.<String>}
67
+ */
68
+ *names() {
69
+ yield* this._commands.keys();
70
+ }
71
+ /**
72
+ * Returns iterator of command instances.
73
+ *
74
+ * @returns {Iterable.<module:core/command~Command>}
75
+ */
76
+ *commands() {
77
+ yield* this._commands.values();
78
+ }
79
+ /**
80
+ * Iterable interface.
81
+ *
82
+ * Returns `[ commandName, commandInstance ]` pairs.
83
+ *
84
+ * @returns {Iterator.<Array>}
85
+ */
86
+ [Symbol.iterator]() {
87
+ return this._commands[Symbol.iterator]();
88
+ }
89
+ /**
90
+ * Destroys all collection commands.
91
+ */
92
+ destroy() {
93
+ for (const command of this.commands()) {
94
+ command.destroy();
95
+ }
96
+ }
109
97
  }