@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.
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-core",
|
|
3
|
-
"version": "35.
|
|
3
|
+
"version": "35.3.0",
|
|
4
4
|
"description": "The core architecture of CKEditor 5 – the best browser-based rich text editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wysiwyg",
|
|
@@ -23,25 +23,28 @@
|
|
|
23
23
|
],
|
|
24
24
|
"main": "src/index.js",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ckeditor/ckeditor5-engine": "^35.
|
|
27
|
-
"@ckeditor/ckeditor5-ui": "^35.
|
|
28
|
-
"@ckeditor/ckeditor5-utils": "^35.
|
|
26
|
+
"@ckeditor/ckeditor5-engine": "^35.3.0",
|
|
27
|
+
"@ckeditor/ckeditor5-ui": "^35.3.0",
|
|
28
|
+
"@ckeditor/ckeditor5-utils": "^35.3.0",
|
|
29
29
|
"lodash-es": "^4.17.15"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@ckeditor/ckeditor5-autoformat": "^35.
|
|
33
|
-
"@ckeditor/ckeditor5-basic-styles": "^35.
|
|
34
|
-
"@ckeditor/ckeditor5-block-quote": "^35.
|
|
35
|
-
"@ckeditor/ckeditor5-editor-classic": "^35.
|
|
36
|
-
"@ckeditor/ckeditor5-essentials": "^35.
|
|
37
|
-
"@ckeditor/ckeditor5-heading": "^35.
|
|
38
|
-
"@ckeditor/ckeditor5-image": "^35.
|
|
39
|
-
"@ckeditor/ckeditor5-indent": "^35.
|
|
40
|
-
"@ckeditor/ckeditor5-link": "^35.
|
|
41
|
-
"@ckeditor/ckeditor5-list": "^35.
|
|
42
|
-
"@ckeditor/ckeditor5-media-embed": "^35.
|
|
43
|
-
"@ckeditor/ckeditor5-paragraph": "^35.
|
|
44
|
-
"@ckeditor/ckeditor5-table": "^35.
|
|
32
|
+
"@ckeditor/ckeditor5-autoformat": "^35.3.0",
|
|
33
|
+
"@ckeditor/ckeditor5-basic-styles": "^35.3.0",
|
|
34
|
+
"@ckeditor/ckeditor5-block-quote": "^35.3.0",
|
|
35
|
+
"@ckeditor/ckeditor5-editor-classic": "^35.3.0",
|
|
36
|
+
"@ckeditor/ckeditor5-essentials": "^35.3.0",
|
|
37
|
+
"@ckeditor/ckeditor5-heading": "^35.3.0",
|
|
38
|
+
"@ckeditor/ckeditor5-image": "^35.3.0",
|
|
39
|
+
"@ckeditor/ckeditor5-indent": "^35.3.0",
|
|
40
|
+
"@ckeditor/ckeditor5-link": "^35.3.0",
|
|
41
|
+
"@ckeditor/ckeditor5-list": "^35.3.0",
|
|
42
|
+
"@ckeditor/ckeditor5-media-embed": "^35.3.0",
|
|
43
|
+
"@ckeditor/ckeditor5-paragraph": "^35.3.0",
|
|
44
|
+
"@ckeditor/ckeditor5-table": "^35.3.0",
|
|
45
|
+
"typescript": "^4.8.4",
|
|
46
|
+
"webpack": "^5.58.1",
|
|
47
|
+
"webpack-cli": "^4.9.0"
|
|
45
48
|
},
|
|
46
49
|
"engines": {
|
|
47
50
|
"node": ">=14.0.0",
|
|
@@ -58,9 +61,14 @@
|
|
|
58
61
|
},
|
|
59
62
|
"files": [
|
|
60
63
|
"lang",
|
|
61
|
-
"src",
|
|
64
|
+
"src/**/*.js",
|
|
65
|
+
"src/**/*.d.ts",
|
|
62
66
|
"theme",
|
|
63
67
|
"ckeditor5-metadata.json",
|
|
64
68
|
"CHANGELOG.md"
|
|
65
|
-
]
|
|
69
|
+
],
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsc -p ./tsconfig.release.json",
|
|
72
|
+
"postversion": "npm run build"
|
|
73
|
+
}
|
|
66
74
|
}
|
package/src/command.js
CHANGED
|
@@ -2,14 +2,7 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* @module core/command
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
11
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
12
|
-
|
|
5
|
+
import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
13
6
|
/**
|
|
14
7
|
* The base class for CKEditor commands.
|
|
15
8
|
*
|
|
@@ -25,236 +18,214 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
|
25
18
|
*
|
|
26
19
|
* @mixes module:utils/observablemixin~ObservableMixin
|
|
27
20
|
*/
|
|
28
|
-
export default class Command {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Destroys the command.
|
|
236
|
-
*/
|
|
237
|
-
destroy() {
|
|
238
|
-
this.stopListening();
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Event fired by the {@link #execute} method. The command action is a listener to this event so it's
|
|
243
|
-
* possible to change/cancel the behavior of the command by listening to this event.
|
|
244
|
-
*
|
|
245
|
-
* See {@link module:utils/observablemixin~ObservableMixin#decorate} for more information and samples.
|
|
246
|
-
*
|
|
247
|
-
* **Note:** This event is fired even if command is disabled. However, it is automatically blocked
|
|
248
|
-
* by a high priority listener in order to prevent command execution.
|
|
249
|
-
*
|
|
250
|
-
* @event execute
|
|
251
|
-
*/
|
|
21
|
+
export default class Command extends Observable {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new `Command` instance.
|
|
24
|
+
*
|
|
25
|
+
* @param {module:core/editor/editor~Editor} editor Editor on which this command will be used.
|
|
26
|
+
*/
|
|
27
|
+
constructor(editor) {
|
|
28
|
+
super();
|
|
29
|
+
/**
|
|
30
|
+
* The editor on which this command will be used.
|
|
31
|
+
*
|
|
32
|
+
* @readonly
|
|
33
|
+
* @member {module:core/editor/editor~Editor}
|
|
34
|
+
*/
|
|
35
|
+
this.editor = editor;
|
|
36
|
+
/**
|
|
37
|
+
* The value of the command. A concrete command class should define what it represents for it.
|
|
38
|
+
*
|
|
39
|
+
* For example, the `'bold'` command's value indicates whether the selection starts in a bolded text.
|
|
40
|
+
* And the value of the `'link'` command may be an object with links details.
|
|
41
|
+
*
|
|
42
|
+
* It is possible for a command to have no value (e.g. for stateless actions such as `'uploadImage'`).
|
|
43
|
+
*
|
|
44
|
+
* A concrete command class should control this value by overriding the {@link #refresh `refresh()`} method.
|
|
45
|
+
*
|
|
46
|
+
* @observable
|
|
47
|
+
* @readonly
|
|
48
|
+
* @member #value
|
|
49
|
+
*/
|
|
50
|
+
this.set('value', undefined);
|
|
51
|
+
/**
|
|
52
|
+
* Flag indicating whether a command is enabled or disabled.
|
|
53
|
+
* A disabled command will do nothing when executed.
|
|
54
|
+
*
|
|
55
|
+
* A concrete command class should control this value by overriding the {@link #refresh `refresh()`} method.
|
|
56
|
+
*
|
|
57
|
+
* It is possible to disable a command from "outside". For instance, in your integration you may want to disable
|
|
58
|
+
* a certain set of commands for the time being. To do that, you can use the fact that `isEnabled` is observable
|
|
59
|
+
* and it fires the `set:isEnabled` event every time anyone tries to modify its value:
|
|
60
|
+
*
|
|
61
|
+
* function disableCommand( cmd ) {
|
|
62
|
+
* cmd.on( 'set:isEnabled', forceDisable, { priority: 'highest' } );
|
|
63
|
+
*
|
|
64
|
+
* cmd.isEnabled = false;
|
|
65
|
+
*
|
|
66
|
+
* // Make it possible to enable the command again.
|
|
67
|
+
* return () => {
|
|
68
|
+
* cmd.off( 'set:isEnabled', forceDisable );
|
|
69
|
+
* cmd.refresh();
|
|
70
|
+
* };
|
|
71
|
+
*
|
|
72
|
+
* function forceDisable( evt ) {
|
|
73
|
+
* evt.return = false;
|
|
74
|
+
* evt.stop();
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
*
|
|
78
|
+
* // Usage:
|
|
79
|
+
*
|
|
80
|
+
* // Disabling the command.
|
|
81
|
+
* const enableBold = disableCommand( editor.commands.get( 'bold' ) );
|
|
82
|
+
*
|
|
83
|
+
* // Enabling the command again.
|
|
84
|
+
* enableBold();
|
|
85
|
+
*
|
|
86
|
+
* @observable
|
|
87
|
+
* @readonly
|
|
88
|
+
* @member {Boolean} #isEnabled
|
|
89
|
+
*/
|
|
90
|
+
this.set('isEnabled', false);
|
|
91
|
+
/**
|
|
92
|
+
* A flag indicating whether a command execution changes the editor data or not.
|
|
93
|
+
*
|
|
94
|
+
* Commands with `affectsData` set to `false` will not be automatically disabled in
|
|
95
|
+
* the {@link module:core/editor/editor~Editor#isReadOnly read-only mode} and
|
|
96
|
+
* {@glink features/read-only#related-features other editor modes} with restricted user write permissions.
|
|
97
|
+
*
|
|
98
|
+
* **Note:** You do not have to set it for your every command. It is `true` by default.
|
|
99
|
+
*
|
|
100
|
+
* @readonly
|
|
101
|
+
* @default true
|
|
102
|
+
* @member {Boolean} #affectsData
|
|
103
|
+
*/
|
|
104
|
+
this._affectsData = true;
|
|
105
|
+
/**
|
|
106
|
+
* Holds identifiers for {@link #forceDisabled} mechanism.
|
|
107
|
+
*
|
|
108
|
+
* @type {Set.<String>}
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
this._disableStack = new Set();
|
|
112
|
+
this.decorate('execute');
|
|
113
|
+
// By default every command is refreshed when changes are applied to the model.
|
|
114
|
+
this.listenTo(this.editor.model.document, 'change', () => {
|
|
115
|
+
this.refresh();
|
|
116
|
+
});
|
|
117
|
+
this.on('execute', evt => {
|
|
118
|
+
if (!this.isEnabled) {
|
|
119
|
+
evt.stop();
|
|
120
|
+
}
|
|
121
|
+
}, { priority: 'high' });
|
|
122
|
+
// By default commands are disabled when the editor is in read-only mode.
|
|
123
|
+
this.listenTo(editor, 'change:isReadOnly', (evt, name, value) => {
|
|
124
|
+
if (value && this.affectsData) {
|
|
125
|
+
this.forceDisabled('readOnlyMode');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this.clearForceDisabled('readOnlyMode');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
get affectsData() {
|
|
133
|
+
return this._affectsData;
|
|
134
|
+
}
|
|
135
|
+
set affectsData(affectsData) {
|
|
136
|
+
this._affectsData = affectsData;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
|
|
140
|
+
* in this method.
|
|
141
|
+
*
|
|
142
|
+
* This method is automatically called when
|
|
143
|
+
* {@link module:engine/model/document~Document#event:change any changes are applied to the document}.
|
|
144
|
+
*/
|
|
145
|
+
refresh() {
|
|
146
|
+
this.isEnabled = true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Disables the command.
|
|
150
|
+
*
|
|
151
|
+
* Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
|
|
152
|
+
* (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
|
|
153
|
+
* The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
|
|
154
|
+
*
|
|
155
|
+
* Disabling and enabling a command:
|
|
156
|
+
*
|
|
157
|
+
* command.isEnabled; // -> true
|
|
158
|
+
* command.forceDisabled( 'MyFeature' );
|
|
159
|
+
* command.isEnabled; // -> false
|
|
160
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
161
|
+
* command.isEnabled; // -> true
|
|
162
|
+
*
|
|
163
|
+
* Command disabled by multiple features:
|
|
164
|
+
*
|
|
165
|
+
* command.forceDisabled( 'MyFeature' );
|
|
166
|
+
* command.forceDisabled( 'OtherFeature' );
|
|
167
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
168
|
+
* command.isEnabled; // -> false
|
|
169
|
+
* command.clearForceDisabled( 'OtherFeature' );
|
|
170
|
+
* command.isEnabled; // -> true
|
|
171
|
+
*
|
|
172
|
+
* Multiple disabling with the same identifier is redundant:
|
|
173
|
+
*
|
|
174
|
+
* command.forceDisabled( 'MyFeature' );
|
|
175
|
+
* command.forceDisabled( 'MyFeature' );
|
|
176
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
177
|
+
* command.isEnabled; // -> true
|
|
178
|
+
*
|
|
179
|
+
* **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
|
|
180
|
+
* so the command might be still disabled after {@link #clearForceDisabled} was used.
|
|
181
|
+
*
|
|
182
|
+
* @param {String} id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
|
|
183
|
+
*/
|
|
184
|
+
forceDisabled(id) {
|
|
185
|
+
this._disableStack.add(id);
|
|
186
|
+
if (this._disableStack.size == 1) {
|
|
187
|
+
this.on('set:isEnabled', forceDisable, { priority: 'highest' });
|
|
188
|
+
this.isEnabled = false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
|
|
193
|
+
*
|
|
194
|
+
* @param {String} id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
|
|
195
|
+
*/
|
|
196
|
+
clearForceDisabled(id) {
|
|
197
|
+
this._disableStack.delete(id);
|
|
198
|
+
if (this._disableStack.size == 0) {
|
|
199
|
+
this.off('set:isEnabled', forceDisable);
|
|
200
|
+
this.refresh();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Executes the command.
|
|
205
|
+
*
|
|
206
|
+
* A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
|
|
207
|
+
* to the command.
|
|
208
|
+
*
|
|
209
|
+
* The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
|
|
210
|
+
* This behavior is implemented by a high priority listener to the {@link #event:execute} event.
|
|
211
|
+
*
|
|
212
|
+
* In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
|
|
213
|
+
*
|
|
214
|
+
* This method may return a value, which would be forwarded all the way down to the
|
|
215
|
+
* {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
|
|
216
|
+
*
|
|
217
|
+
* @fires execute
|
|
218
|
+
*/
|
|
219
|
+
execute(...args) { return undefined; }
|
|
220
|
+
/**
|
|
221
|
+
* Destroys the command.
|
|
222
|
+
*/
|
|
223
|
+
destroy() {
|
|
224
|
+
this.stopListening();
|
|
225
|
+
}
|
|
252
226
|
}
|
|
253
|
-
|
|
254
|
-
mix( Command, ObservableMixin );
|
|
255
|
-
|
|
256
227
|
// Helper function that forces command to be disabled.
|
|
257
|
-
function forceDisable(
|
|
258
|
-
|
|
259
|
-
|
|
228
|
+
function forceDisable(evt) {
|
|
229
|
+
evt.return = false;
|
|
230
|
+
evt.stop();
|
|
260
231
|
}
|