@ckeditor/ckeditor5-core 35.2.1 → 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,15 +2,11 @@
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
  import Command from './command';
7
-
8
6
  import insertToPriorityArray from '@ckeditor/ckeditor5-utils/src/inserttopriorityarray';
9
-
10
7
  /**
11
8
  * @module core/multicommand
12
9
  */
13
-
14
10
  /**
15
11
  * A CKEditor command that aggregates other commands.
16
12
  *
@@ -36,73 +32,63 @@ import insertToPriorityArray from '@ckeditor/ckeditor5-utils/src/inserttopriorit
36
32
  * @extends module:core/command~Command
37
33
  */
38
34
  export default class MultiCommand extends Command {
39
- /**
40
- * @inheritDoc
41
- */
42
- constructor( editor ) {
43
- super( editor );
44
-
45
- /**
46
- * Registered child commands definitions.
47
- *
48
- * @type {Array.<Object>}
49
- * @private
50
- */
51
- this._childCommandsDefinitions = [];
52
- }
53
-
54
- /**
55
- * @inheritDoc
56
- */
57
- refresh() {
58
- // Override base command refresh(): the command's state is changed when one of child commands changes states.
59
- }
60
-
61
- /**
62
- * Executes the first enabled command which has the highest priority of all registered child commands.
63
- *
64
- * @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
65
- */
66
- execute( ...args ) {
67
- const command = this._getFirstEnabledCommand();
68
-
69
- return !!command && command.execute( args );
70
- }
71
-
72
- /**
73
- * Registers a child command.
74
- *
75
- * @param {module:core/command~Command} command
76
- * @param {Object} options An object with configuration options.
77
- * @param {module:utils/priorities~PriorityString} [options.priority='normal'] Priority of a command to register.
78
- */
79
- registerChildCommand( command, options = { priority: 'normal' } ) {
80
- insertToPriorityArray( this._childCommandsDefinitions, { command, priority: options.priority } );
81
-
82
- // Change multi command enabled state when one of registered commands changes state.
83
- command.on( 'change:isEnabled', () => this._checkEnabled() );
84
-
85
- this._checkEnabled();
86
- }
87
-
88
- /**
89
- * Checks if any of child commands is enabled.
90
- *
91
- * @private
92
- */
93
- _checkEnabled() {
94
- this.isEnabled = !!this._getFirstEnabledCommand();
95
- }
96
-
97
- /**
98
- * Returns a first enabled command with the highest priority or `undefined` if none of them is enabled.
99
- *
100
- * @returns {module:core/command~Command|undefined}
101
- * @private
102
- */
103
- _getFirstEnabledCommand() {
104
- const commandDefinition = this._childCommandsDefinitions.find( ( { command } ) => command.isEnabled );
105
-
106
- return commandDefinition && commandDefinition.command;
107
- }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ constructor(editor) {
39
+ super(editor);
40
+ /**
41
+ * Registered child commands definitions.
42
+ *
43
+ * @type {Array.<Object>}
44
+ * @private
45
+ */
46
+ this._childCommandsDefinitions = [];
47
+ }
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ refresh() {
52
+ // Override base command refresh(): the command's state is changed when one of child commands changes states.
53
+ }
54
+ /**
55
+ * Executes the first enabled command which has the highest priority of all registered child commands.
56
+ *
57
+ * @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
58
+ */
59
+ execute(...args) {
60
+ const command = this._getFirstEnabledCommand();
61
+ return !!command && command.execute(args);
62
+ }
63
+ /**
64
+ * Registers a child command.
65
+ *
66
+ * @param {module:core/command~Command} command
67
+ * @param {Object} options An object with configuration options.
68
+ * @param {module:utils/priorities~PriorityString} [options.priority='normal'] Priority of a command to register.
69
+ */
70
+ registerChildCommand(command, options = {}) {
71
+ insertToPriorityArray(this._childCommandsDefinitions, { command, priority: options.priority || 'normal' });
72
+ // Change multi command enabled state when one of registered commands changes state.
73
+ command.on('change:isEnabled', () => this._checkEnabled());
74
+ this._checkEnabled();
75
+ }
76
+ /**
77
+ * Checks if any of child commands is enabled.
78
+ *
79
+ * @private
80
+ */
81
+ _checkEnabled() {
82
+ this.isEnabled = !!this._getFirstEnabledCommand();
83
+ }
84
+ /**
85
+ * Returns a first enabled command with the highest priority or `undefined` if none of them is enabled.
86
+ *
87
+ * @returns {module:core/command~Command|undefined}
88
+ * @private
89
+ */
90
+ _getFirstEnabledCommand() {
91
+ const commandDefinition = this._childCommandsDefinitions.find(({ command }) => command.isEnabled);
92
+ return commandDefinition && commandDefinition.command;
93
+ }
108
94
  }
@@ -2,16 +2,13 @@
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/pendingactions
8
7
  */
9
-
10
8
  import ContextPlugin from './contextplugin';
11
- import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
9
+ import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
12
10
  import Collection from '@ckeditor/ckeditor5-utils/src/collection';
13
11
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
14
-
15
12
  /**
16
13
  * The list of pending editor actions.
17
14
  *
@@ -53,103 +50,80 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
53
50
  * @extends module:core/contextplugin~ContextPlugin
54
51
  */
55
52
  export default class PendingActions extends ContextPlugin {
56
- /**
57
- * @inheritDoc
58
- */
59
- static get pluginName() {
60
- return 'PendingActions';
61
- }
62
-
63
- /**
64
- * @inheritDoc
65
- */
66
- init() {
67
- /**
68
- * Defines whether there is any registered pending action.
69
- *
70
- * @readonly
71
- * @observable
72
- * @member {Boolean} #hasAny
73
- */
74
- this.set( 'hasAny', false );
75
-
76
- /**
77
- * A list of pending actions.
78
- *
79
- * @private
80
- * @type {module:utils/collection~Collection}
81
- */
82
- this._actions = new Collection( { idProperty: '_id' } );
83
- this._actions.delegate( 'add', 'remove' ).to( this );
84
- }
85
-
86
- /**
87
- * Adds an action to the list of pending actions.
88
- *
89
- * This method returns an action object with an observable message property.
90
- * The action object can be later used in the {@link #remove} method. It also allows you to change the message.
91
- *
92
- * @param {String} message The action message.
93
- * @returns {Object} An observable object that represents a pending action.
94
- */
95
- add( message ) {
96
- if ( typeof message !== 'string' ) {
97
- /**
98
- * The message must be a string.
99
- *
100
- * @error pendingactions-add-invalid-message
101
- */
102
- throw new CKEditorError( 'pendingactions-add-invalid-message', this );
103
- }
104
-
105
- const action = Object.create( ObservableMixin );
106
-
107
- action.set( 'message', message );
108
- this._actions.add( action );
109
- this.hasAny = true;
110
-
111
- return action;
112
- }
113
-
114
- /**
115
- * Removes an action from the list of pending actions.
116
- *
117
- * @param {Object} action An action object.
118
- */
119
- remove( action ) {
120
- this._actions.remove( action );
121
- this.hasAny = !!this._actions.length;
122
- }
123
-
124
- /**
125
- * Returns the first action from the list or null when list is empty
126
- *
127
- * returns {Object|null} The pending action object.
128
- */
129
- get first() {
130
- return this._actions.get( 0 );
131
- }
132
-
133
- /**
134
- * Iterable interface.
135
- *
136
- * @returns {Iterable.<*>}
137
- */
138
- [ Symbol.iterator ]() {
139
- return this._actions[ Symbol.iterator ]();
140
- }
141
-
142
- /**
143
- * Fired when an action is added to the list.
144
- *
145
- * @event add
146
- * @param {Object} action The added action.
147
- */
148
-
149
- /**
150
- * Fired when an action is removed from the list.
151
- *
152
- * @event remove
153
- * @param {Object} action The removed action.
154
- */
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ static get pluginName() {
57
+ return 'PendingActions';
58
+ }
59
+ /**
60
+ * @inheritDoc
61
+ */
62
+ init() {
63
+ /**
64
+ * Defines whether there is any registered pending action.
65
+ *
66
+ * @readonly
67
+ * @observable
68
+ * @member {Boolean} #hasAny
69
+ */
70
+ this.set('hasAny', false);
71
+ /**
72
+ * A list of pending actions.
73
+ *
74
+ * @private
75
+ * @type {module:utils/collection~Collection}
76
+ */
77
+ this._actions = new Collection({ idProperty: '_id' });
78
+ this._actions.delegate('add', 'remove').to(this);
79
+ }
80
+ /**
81
+ * Adds an action to the list of pending actions.
82
+ *
83
+ * This method returns an action object with an observable message property.
84
+ * The action object can be later used in the {@link #remove} method. It also allows you to change the message.
85
+ *
86
+ * @param {String} message The action message.
87
+ * @returns {Object} An observable object that represents a pending action.
88
+ */
89
+ add(message) {
90
+ if (typeof message !== 'string') {
91
+ /**
92
+ * The message must be a string.
93
+ *
94
+ * @error pendingactions-add-invalid-message
95
+ */
96
+ throw new CKEditorError('pendingactions-add-invalid-message', this);
97
+ }
98
+ const action = new Observable();
99
+ action.set('message', message);
100
+ this._actions.add(action);
101
+ this.hasAny = true;
102
+ return action;
103
+ }
104
+ /**
105
+ * Removes an action from the list of pending actions.
106
+ *
107
+ * @param {Object} action An action object.
108
+ */
109
+ remove(action) {
110
+ this._actions.remove(action);
111
+ this.hasAny = !!this._actions.length;
112
+ }
113
+ /**
114
+ * Returns the first action from the list or null when list is empty
115
+ *
116
+ * returns {Object|null} The pending action object.
117
+ */
118
+ get first() {
119
+ return this._actions.get(0);
120
+ }
121
+ /**
122
+ * Iterable interface.
123
+ *
124
+ * @returns {Iterable.<*>}
125
+ */
126
+ [Symbol.iterator]() {
127
+ return this._actions[Symbol.iterator]();
128
+ }
155
129
  }