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