@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.
- package/package.json +27 -19
- package/src/command.js +209 -238
- package/src/commandcollection.js +84 -96
- package/src/context.js +219 -314
- package/src/contextplugin.js +29 -36
- package/src/editingkeystrokehandler.js +42 -49
- package/src/editor/editor.js +360 -440
- package/src/editor/editorconfig.js +5 -0
- package/src/editor/editorui.js +436 -544
- package/src/editor/utils/attachtoform.js +39 -49
- package/src/editor/utils/dataapimixin.js +17 -68
- package/src/editor/utils/elementapimixin.js +32 -67
- package/src/editor/utils/securesourceelement.js +22 -32
- package/src/index.js +34 -51
- package/src/multicommand.js +59 -73
- package/src/pendingactions.js +77 -103
- package/src/plugin.js +119 -276
- package/src/plugincollection.js +470 -584
- package/src/editor/editorconfig.jsdoc +0 -426
- package/src/editor/editorwithui.jsdoc +0 -29
package/src/multicommand.js
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
}
|
package/src/pendingactions.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
}
|