@ckeditor/ckeditor5-core 40.0.0 → 40.2.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +28 -28
  2. package/LICENSE.md +3 -3
  3. package/README.md +1 -1
  4. package/lang/contexts.json +5 -1
  5. package/lang/translations/af.po +16 -0
  6. package/lang/translations/ar.po +16 -0
  7. package/lang/translations/ast.po +16 -0
  8. package/lang/translations/az.po +16 -0
  9. package/lang/translations/bg.po +16 -0
  10. package/lang/translations/bn.po +16 -0
  11. package/lang/translations/bs.po +16 -0
  12. package/lang/translations/ca.po +16 -0
  13. package/lang/translations/cs.po +16 -0
  14. package/lang/translations/da.po +16 -0
  15. package/lang/translations/de-ch.po +16 -0
  16. package/lang/translations/de.po +16 -0
  17. package/lang/translations/el.po +16 -0
  18. package/lang/translations/en-au.po +16 -0
  19. package/lang/translations/en-gb.po +16 -0
  20. package/lang/translations/en.po +16 -0
  21. package/lang/translations/eo.po +16 -0
  22. package/lang/translations/es-co.po +16 -0
  23. package/lang/translations/es.po +16 -0
  24. package/lang/translations/et.po +16 -0
  25. package/lang/translations/eu.po +16 -0
  26. package/lang/translations/fa.po +16 -0
  27. package/lang/translations/fi.po +16 -0
  28. package/lang/translations/fr.po +16 -0
  29. package/lang/translations/gl.po +16 -0
  30. package/lang/translations/gu.po +16 -0
  31. package/lang/translations/he.po +16 -0
  32. package/lang/translations/hi.po +16 -0
  33. package/lang/translations/hr.po +16 -0
  34. package/lang/translations/hu.po +16 -0
  35. package/lang/translations/hy.po +16 -0
  36. package/lang/translations/id.po +16 -0
  37. package/lang/translations/it.po +16 -0
  38. package/lang/translations/ja.po +16 -0
  39. package/lang/translations/jv.po +16 -0
  40. package/lang/translations/km.po +16 -0
  41. package/lang/translations/kn.po +16 -0
  42. package/lang/translations/ko.po +16 -0
  43. package/lang/translations/ku.po +16 -0
  44. package/lang/translations/lt.po +16 -0
  45. package/lang/translations/lv.po +16 -0
  46. package/lang/translations/ms.po +16 -0
  47. package/lang/translations/nb.po +16 -0
  48. package/lang/translations/ne.po +16 -0
  49. package/lang/translations/nl.po +16 -0
  50. package/lang/translations/no.po +16 -0
  51. package/lang/translations/oc.po +16 -0
  52. package/lang/translations/pl.po +16 -0
  53. package/lang/translations/pt-br.po +16 -0
  54. package/lang/translations/pt.po +16 -0
  55. package/lang/translations/ro.po +16 -0
  56. package/lang/translations/ru.po +16 -0
  57. package/lang/translations/si.po +16 -0
  58. package/lang/translations/sk.po +16 -0
  59. package/lang/translations/sl.po +16 -0
  60. package/lang/translations/sq.po +16 -0
  61. package/lang/translations/sr-latn.po +17 -1
  62. package/lang/translations/sr.po +16 -0
  63. package/lang/translations/sv.po +16 -0
  64. package/lang/translations/th.po +16 -0
  65. package/lang/translations/tk.po +16 -0
  66. package/lang/translations/tr.po +16 -0
  67. package/lang/translations/tt.po +16 -0
  68. package/lang/translations/ug.po +17 -1
  69. package/lang/translations/uk.po +16 -0
  70. package/lang/translations/ur.po +16 -0
  71. package/lang/translations/uz.po +16 -0
  72. package/lang/translations/vi.po +16 -0
  73. package/lang/translations/zh-cn.po +16 -0
  74. package/lang/translations/zh.po +16 -0
  75. package/package.json +3 -3
  76. package/src/augmentation.d.ts +10 -10
  77. package/src/augmentation.js +5 -5
  78. package/src/command.d.ts +189 -189
  79. package/src/command.js +185 -185
  80. package/src/commandcollection.d.ts +83 -83
  81. package/src/commandcollection.js +83 -83
  82. package/src/context.d.ts +237 -237
  83. package/src/context.js +225 -225
  84. package/src/contextplugin.d.ts +61 -61
  85. package/src/contextplugin.js +43 -43
  86. package/src/editingkeystrokehandler.d.ts +56 -56
  87. package/src/editingkeystrokehandler.js +57 -57
  88. package/src/editor/editor.d.ts +417 -417
  89. package/src/editor/editor.js +316 -316
  90. package/src/editor/editorconfig.d.ts +661 -660
  91. package/src/editor/editorconfig.js +5 -5
  92. package/src/editor/utils/attachtoform.d.ts +15 -15
  93. package/src/editor/utils/attachtoform.js +57 -57
  94. package/src/editor/utils/dataapimixin.d.ts +75 -75
  95. package/src/editor/utils/dataapimixin.js +24 -24
  96. package/src/editor/utils/elementapimixin.d.ts +35 -31
  97. package/src/editor/utils/elementapimixin.js +43 -42
  98. package/src/editor/utils/securesourceelement.d.ts +17 -17
  99. package/src/editor/utils/securesourceelement.js +35 -35
  100. package/src/index.d.ts +66 -62
  101. package/src/index.js +103 -95
  102. package/src/multicommand.d.ts +66 -66
  103. package/src/multicommand.js +82 -82
  104. package/src/pendingactions.d.ts +117 -117
  105. package/src/pendingactions.js +116 -116
  106. package/src/plugin.d.ts +274 -274
  107. package/src/plugin.js +106 -106
  108. package/src/plugincollection.d.ts +117 -117
  109. package/src/plugincollection.js +473 -473
  110. package/theme/icons/image-asset-manager.svg +1 -0
  111. package/theme/icons/image-upload.svg +1 -0
  112. package/theme/icons/image-url.svg +1 -0
  113. package/theme/icons/image.svg +1 -1
  114. package/theme/icons/low-vision.svg +1 -1
  115. package/theme/icons/text-alternative.svg +1 -0
package/src/command.js CHANGED
@@ -1,185 +1,185 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module core/command
7
- */
8
- import { ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * Base class for the CKEditor commands.
11
- *
12
- * Commands are the main way to manipulate the editor contents and state. They are mostly used by UI elements (or by other
13
- * commands) to make changes in the model. Commands are available in every part of the code that has access to
14
- * the {@link module:core/editor/editor~Editor editor} instance.
15
- *
16
- * Instances of registered commands can be retrieved from {@link module:core/editor/editor~Editor#commands `editor.commands`}.
17
- * The easiest way to execute a command is through {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
18
- *
19
- * By default, commands are disabled when the editor is in the {@link module:core/editor/editor~Editor#isReadOnly read-only} mode
20
- * but commands with the {@link module:core/command~Command#affectsData `affectsData`} flag set to `false` will not be disabled.
21
- */
22
- export default class Command extends ObservableMixin() {
23
- /**
24
- * Creates a new `Command` instance.
25
- *
26
- * @param editor The editor on which this command will be used.
27
- */
28
- constructor(editor) {
29
- super();
30
- this.editor = editor;
31
- this.set('value', undefined);
32
- this.set('isEnabled', false);
33
- this._affectsData = true;
34
- this._isEnabledBasedOnSelection = true;
35
- this._disableStack = new Set();
36
- this.decorate('execute');
37
- // By default, every command is refreshed when changes are applied to the model.
38
- this.listenTo(this.editor.model.document, 'change', () => {
39
- this.refresh();
40
- });
41
- this.listenTo(editor, 'change:isReadOnly', () => {
42
- this.refresh();
43
- });
44
- // By default, commands are disabled if the selection is in non-editable place or editor is in read-only mode.
45
- this.on('set:isEnabled', evt => {
46
- if (!this.affectsData) {
47
- return;
48
- }
49
- const selection = editor.model.document.selection;
50
- const selectionInGraveyard = selection.getFirstPosition().root.rootName == '$graveyard';
51
- const canEditAtSelection = !selectionInGraveyard && editor.model.canEditAt(selection);
52
- // Disable if editor is read only, or when selection is in a place which cannot be edited.
53
- //
54
- // Checking `editor.isReadOnly` is needed for all commands that have `_isEnabledBasedOnSelection == false`.
55
- // E.g. undo does not base on selection, but affects data and should be disabled when the editor is in read-only mode.
56
- if (editor.isReadOnly || this._isEnabledBasedOnSelection && !canEditAtSelection) {
57
- evt.return = false;
58
- evt.stop();
59
- }
60
- }, { priority: 'highest' });
61
- this.on('execute', evt => {
62
- if (!this.isEnabled) {
63
- evt.stop();
64
- }
65
- }, { priority: 'high' });
66
- }
67
- /**
68
- * A flag indicating whether a command execution changes the editor data or not.
69
- *
70
- * Commands with `affectsData` set to `false` will not be automatically disabled in
71
- * the {@link module:core/editor/editor~Editor#isReadOnly read-only mode} and
72
- * {@glink features/read-only#related-features other editor modes} with restricted user write permissions.
73
- *
74
- * **Note:** You do not have to set it for your every command. It is `true` by default.
75
- *
76
- * @default true
77
- */
78
- get affectsData() {
79
- return this._affectsData;
80
- }
81
- set affectsData(affectsData) {
82
- this._affectsData = affectsData;
83
- }
84
- /**
85
- * Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
86
- * in this method.
87
- *
88
- * This method is automatically called when
89
- * {@link module:engine/model/document~Document#event:change any changes are applied to the document}.
90
- */
91
- refresh() {
92
- this.isEnabled = true;
93
- }
94
- /**
95
- * Disables the command.
96
- *
97
- * Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
98
- * (e.g. the feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
99
- * The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
100
- *
101
- * Disabling and enabling a command:
102
- *
103
- * ```ts
104
- * command.isEnabled; // -> true
105
- * command.forceDisabled( 'MyFeature' );
106
- * command.isEnabled; // -> false
107
- * command.clearForceDisabled( 'MyFeature' );
108
- * command.isEnabled; // -> true
109
- * ```
110
- *
111
- * Command disabled by multiple features:
112
- *
113
- * ```ts
114
- * command.forceDisabled( 'MyFeature' );
115
- * command.forceDisabled( 'OtherFeature' );
116
- * command.clearForceDisabled( 'MyFeature' );
117
- * command.isEnabled; // -> false
118
- * command.clearForceDisabled( 'OtherFeature' );
119
- * command.isEnabled; // -> true
120
- * ```
121
- *
122
- * Multiple disabling with the same identifier is redundant:
123
- *
124
- * ```ts
125
- * command.forceDisabled( 'MyFeature' );
126
- * command.forceDisabled( 'MyFeature' );
127
- * command.clearForceDisabled( 'MyFeature' );
128
- * command.isEnabled; // -> true
129
- * ```
130
- *
131
- * **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
132
- * so the command might be still disabled after {@link #clearForceDisabled} was used.
133
- *
134
- * @param id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
135
- */
136
- forceDisabled(id) {
137
- this._disableStack.add(id);
138
- if (this._disableStack.size == 1) {
139
- this.on('set:isEnabled', forceDisable, { priority: 'highest' });
140
- this.isEnabled = false;
141
- }
142
- }
143
- /**
144
- * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
145
- *
146
- * @param id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
147
- */
148
- clearForceDisabled(id) {
149
- this._disableStack.delete(id);
150
- if (this._disableStack.size == 0) {
151
- this.off('set:isEnabled', forceDisable);
152
- this.refresh();
153
- }
154
- }
155
- /**
156
- * Executes the command.
157
- *
158
- * A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
159
- * to the command.
160
- *
161
- * The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
162
- * This behavior is implemented by a high priority listener to the {@link #event:execute} event.
163
- *
164
- * In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
165
- *
166
- * This method may return a value, which would be forwarded all the way down to the
167
- * {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
168
- *
169
- * @fires execute
170
- */
171
- execute(...args) { return undefined; }
172
- /**
173
- * Destroys the command.
174
- */
175
- destroy() {
176
- this.stopListening();
177
- }
178
- }
179
- /**
180
- * Helper function that forces command to be disabled.
181
- */
182
- function forceDisable(evt) {
183
- evt.return = false;
184
- evt.stop();
185
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module core/command
7
+ */
8
+ import { ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
+ /**
10
+ * Base class for the CKEditor commands.
11
+ *
12
+ * Commands are the main way to manipulate the editor contents and state. They are mostly used by UI elements (or by other
13
+ * commands) to make changes in the model. Commands are available in every part of the code that has access to
14
+ * the {@link module:core/editor/editor~Editor editor} instance.
15
+ *
16
+ * Instances of registered commands can be retrieved from {@link module:core/editor/editor~Editor#commands `editor.commands`}.
17
+ * The easiest way to execute a command is through {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
18
+ *
19
+ * By default, commands are disabled when the editor is in the {@link module:core/editor/editor~Editor#isReadOnly read-only} mode
20
+ * but commands with the {@link module:core/command~Command#affectsData `affectsData`} flag set to `false` will not be disabled.
21
+ */
22
+ export default class Command extends ObservableMixin() {
23
+ /**
24
+ * Creates a new `Command` instance.
25
+ *
26
+ * @param editor The editor on which this command will be used.
27
+ */
28
+ constructor(editor) {
29
+ super();
30
+ this.editor = editor;
31
+ this.set('value', undefined);
32
+ this.set('isEnabled', false);
33
+ this._affectsData = true;
34
+ this._isEnabledBasedOnSelection = true;
35
+ this._disableStack = new Set();
36
+ this.decorate('execute');
37
+ // By default, every command is refreshed when changes are applied to the model.
38
+ this.listenTo(this.editor.model.document, 'change', () => {
39
+ this.refresh();
40
+ });
41
+ this.listenTo(editor, 'change:isReadOnly', () => {
42
+ this.refresh();
43
+ });
44
+ // By default, commands are disabled if the selection is in non-editable place or editor is in read-only mode.
45
+ this.on('set:isEnabled', evt => {
46
+ if (!this.affectsData) {
47
+ return;
48
+ }
49
+ const selection = editor.model.document.selection;
50
+ const selectionInGraveyard = selection.getFirstPosition().root.rootName == '$graveyard';
51
+ const canEditAtSelection = !selectionInGraveyard && editor.model.canEditAt(selection);
52
+ // Disable if editor is read only, or when selection is in a place which cannot be edited.
53
+ //
54
+ // Checking `editor.isReadOnly` is needed for all commands that have `_isEnabledBasedOnSelection == false`.
55
+ // E.g. undo does not base on selection, but affects data and should be disabled when the editor is in read-only mode.
56
+ if (editor.isReadOnly || this._isEnabledBasedOnSelection && !canEditAtSelection) {
57
+ evt.return = false;
58
+ evt.stop();
59
+ }
60
+ }, { priority: 'highest' });
61
+ this.on('execute', evt => {
62
+ if (!this.isEnabled) {
63
+ evt.stop();
64
+ }
65
+ }, { priority: 'high' });
66
+ }
67
+ /**
68
+ * A flag indicating whether a command execution changes the editor data or not.
69
+ *
70
+ * Commands with `affectsData` set to `false` will not be automatically disabled in
71
+ * the {@link module:core/editor/editor~Editor#isReadOnly read-only mode} and
72
+ * {@glink features/read-only#related-features other editor modes} with restricted user write permissions.
73
+ *
74
+ * **Note:** You do not have to set it for your every command. It is `true` by default.
75
+ *
76
+ * @default true
77
+ */
78
+ get affectsData() {
79
+ return this._affectsData;
80
+ }
81
+ set affectsData(affectsData) {
82
+ this._affectsData = affectsData;
83
+ }
84
+ /**
85
+ * Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
86
+ * in this method.
87
+ *
88
+ * This method is automatically called when
89
+ * {@link module:engine/model/document~Document#event:change any changes are applied to the document}.
90
+ */
91
+ refresh() {
92
+ this.isEnabled = true;
93
+ }
94
+ /**
95
+ * Disables the command.
96
+ *
97
+ * Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
98
+ * (e.g. the feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
99
+ * The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
100
+ *
101
+ * Disabling and enabling a command:
102
+ *
103
+ * ```ts
104
+ * command.isEnabled; // -> true
105
+ * command.forceDisabled( 'MyFeature' );
106
+ * command.isEnabled; // -> false
107
+ * command.clearForceDisabled( 'MyFeature' );
108
+ * command.isEnabled; // -> true
109
+ * ```
110
+ *
111
+ * Command disabled by multiple features:
112
+ *
113
+ * ```ts
114
+ * command.forceDisabled( 'MyFeature' );
115
+ * command.forceDisabled( 'OtherFeature' );
116
+ * command.clearForceDisabled( 'MyFeature' );
117
+ * command.isEnabled; // -> false
118
+ * command.clearForceDisabled( 'OtherFeature' );
119
+ * command.isEnabled; // -> true
120
+ * ```
121
+ *
122
+ * Multiple disabling with the same identifier is redundant:
123
+ *
124
+ * ```ts
125
+ * command.forceDisabled( 'MyFeature' );
126
+ * command.forceDisabled( 'MyFeature' );
127
+ * command.clearForceDisabled( 'MyFeature' );
128
+ * command.isEnabled; // -> true
129
+ * ```
130
+ *
131
+ * **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
132
+ * so the command might be still disabled after {@link #clearForceDisabled} was used.
133
+ *
134
+ * @param id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
135
+ */
136
+ forceDisabled(id) {
137
+ this._disableStack.add(id);
138
+ if (this._disableStack.size == 1) {
139
+ this.on('set:isEnabled', forceDisable, { priority: 'highest' });
140
+ this.isEnabled = false;
141
+ }
142
+ }
143
+ /**
144
+ * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
145
+ *
146
+ * @param id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
147
+ */
148
+ clearForceDisabled(id) {
149
+ this._disableStack.delete(id);
150
+ if (this._disableStack.size == 0) {
151
+ this.off('set:isEnabled', forceDisable);
152
+ this.refresh();
153
+ }
154
+ }
155
+ /**
156
+ * Executes the command.
157
+ *
158
+ * A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
159
+ * to the command.
160
+ *
161
+ * The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
162
+ * This behavior is implemented by a high priority listener to the {@link #event:execute} event.
163
+ *
164
+ * In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
165
+ *
166
+ * This method may return a value, which would be forwarded all the way down to the
167
+ * {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
168
+ *
169
+ * @fires execute
170
+ */
171
+ execute(...args) { return undefined; } // eslint-disable-line @typescript-eslint/no-unused-vars
172
+ /**
173
+ * Destroys the command.
174
+ */
175
+ destroy() {
176
+ this.stopListening();
177
+ }
178
+ }
179
+ /**
180
+ * Helper function that forces command to be disabled.
181
+ */
182
+ function forceDisable(evt) {
183
+ evt.return = false;
184
+ evt.stop();
185
+ }
@@ -1,83 +1,83 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import type Command from './command';
6
- /**
7
- * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
8
- */
9
- export default class CommandCollection implements Iterable<[string, Command]> {
10
- /**
11
- * Command map.
12
- */
13
- private _commands;
14
- /**
15
- * Creates collection instance.
16
- */
17
- constructor();
18
- /**
19
- * Registers a new command.
20
- *
21
- * @param commandName The name of the command.
22
- */
23
- add<TName extends string>(commandName: TName, command: CommandsMap[TName]): void;
24
- /**
25
- * Retrieves a command from the collection.
26
- *
27
- * @param commandName The name of the command.
28
- */
29
- get<TName extends string>(commandName: TName): CommandsMap[TName] | undefined;
30
- /**
31
- * Executes a command.
32
- *
33
- * @param commandName The name of the command.
34
- * @param commandParams Command parameters.
35
- * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
36
- */
37
- execute<TName extends string>(commandName: TName, ...commandParams: Parameters<CommandsMap[TName]['execute']>): ReturnType<CommandsMap[TName]['execute']>;
38
- /**
39
- * Returns iterator of command names.
40
- */
41
- names(): IterableIterator<string>;
42
- /**
43
- * Returns iterator of command instances.
44
- */
45
- commands(): IterableIterator<Command>;
46
- /**
47
- * Iterable interface.
48
- *
49
- * Returns `[ commandName, commandInstance ]` pairs.
50
- */
51
- [Symbol.iterator](): Iterator<[string, Command]>;
52
- /**
53
- * Destroys all collection commands.
54
- */
55
- destroy(): void;
56
- }
57
- /**
58
- * Helper type that maps command names to their types.
59
- * It is meant to be extended with module augmentation.
60
- *
61
- * ```ts
62
- * class MyCommand extends Command {
63
- * public execute( parameter: A ): B {
64
- * // ...
65
- * }
66
- * }
67
- *
68
- * declare module '@ckeditor/ckeditor5-core' {
69
- * interface CommandsMap {
70
- * myCommand: MyCommand;
71
- * }
72
- * }
73
- *
74
- * // Returns `MyCommand | undefined`.
75
- * const myCommand = editor.commands.get( 'myCommand' );
76
- *
77
- * // Expects `A` type as parameter and returns `B`.
78
- * const value = editor.commands.execute( 'myCommand', new A() );
79
- * ```
80
- */
81
- export interface CommandsMap {
82
- [name: string]: Command;
83
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type Command from './command';
6
+ /**
7
+ * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
8
+ */
9
+ export default class CommandCollection implements Iterable<[string, Command]> {
10
+ /**
11
+ * Command map.
12
+ */
13
+ private _commands;
14
+ /**
15
+ * Creates collection instance.
16
+ */
17
+ constructor();
18
+ /**
19
+ * Registers a new command.
20
+ *
21
+ * @param commandName The name of the command.
22
+ */
23
+ add<TName extends string>(commandName: TName, command: CommandsMap[TName]): void;
24
+ /**
25
+ * Retrieves a command from the collection.
26
+ *
27
+ * @param commandName The name of the command.
28
+ */
29
+ get<TName extends string>(commandName: TName): CommandsMap[TName] | undefined;
30
+ /**
31
+ * Executes a command.
32
+ *
33
+ * @param commandName The name of the command.
34
+ * @param commandParams Command parameters.
35
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
36
+ */
37
+ execute<TName extends string>(commandName: TName, ...commandParams: Parameters<CommandsMap[TName]['execute']>): ReturnType<CommandsMap[TName]['execute']>;
38
+ /**
39
+ * Returns iterator of command names.
40
+ */
41
+ names(): IterableIterator<string>;
42
+ /**
43
+ * Returns iterator of command instances.
44
+ */
45
+ commands(): IterableIterator<Command>;
46
+ /**
47
+ * Iterable interface.
48
+ *
49
+ * Returns `[ commandName, commandInstance ]` pairs.
50
+ */
51
+ [Symbol.iterator](): Iterator<[string, Command]>;
52
+ /**
53
+ * Destroys all collection commands.
54
+ */
55
+ destroy(): void;
56
+ }
57
+ /**
58
+ * Helper type that maps command names to their types.
59
+ * It is meant to be extended with module augmentation.
60
+ *
61
+ * ```ts
62
+ * class MyCommand extends Command {
63
+ * public execute( parameter: A ): B {
64
+ * // ...
65
+ * }
66
+ * }
67
+ *
68
+ * declare module '@ckeditor/ckeditor5-core' {
69
+ * interface CommandsMap {
70
+ * myCommand: MyCommand;
71
+ * }
72
+ * }
73
+ *
74
+ * // Returns `MyCommand | undefined`.
75
+ * const myCommand = editor.commands.get( 'myCommand' );
76
+ *
77
+ * // Expects `A` type as parameter and returns `B`.
78
+ * const value = editor.commands.execute( 'myCommand', new A() );
79
+ * ```
80
+ */
81
+ export interface CommandsMap {
82
+ [name: string]: Command;
83
+ }