@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
@@ -1,473 +1,473 @@
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/plugincollection
7
- */
8
- import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.
11
- */
12
- export default class PluginCollection extends EmitterMixin() {
13
- /**
14
- * Creates an instance of the plugin collection class.
15
- * Allows loading and initializing plugins and their dependencies.
16
- * Allows providing a list of already loaded plugins. These plugins will not be destroyed along with this collection.
17
- *
18
- * @param availablePlugins Plugins (constructors) which the collection will be able to use
19
- * when {@link module:core/plugincollection~PluginCollection#init} is used with the plugin names (strings, instead of constructors).
20
- * Usually, the editor will pass its built-in plugins to the collection so they can later be
21
- * used in `config.plugins` or `config.removePlugins` by names.
22
- * @param contextPlugins A list of already initialized plugins represented by a `[ PluginConstructor, pluginInstance ]` pair.
23
- */
24
- constructor(context, availablePlugins = [], contextPlugins = []) {
25
- super();
26
- this._plugins = new Map();
27
- this._context = context;
28
- this._availablePlugins = new Map();
29
- for (const PluginConstructor of availablePlugins) {
30
- if (PluginConstructor.pluginName) {
31
- this._availablePlugins.set(PluginConstructor.pluginName, PluginConstructor);
32
- }
33
- }
34
- this._contextPlugins = new Map();
35
- for (const [PluginConstructor, pluginInstance] of contextPlugins) {
36
- this._contextPlugins.set(PluginConstructor, pluginInstance);
37
- this._contextPlugins.set(pluginInstance, PluginConstructor);
38
- // To make it possible to require a plugin by its name.
39
- if (PluginConstructor.pluginName) {
40
- this._availablePlugins.set(PluginConstructor.pluginName, PluginConstructor);
41
- }
42
- }
43
- }
44
- /**
45
- * Iterable interface.
46
- *
47
- * Returns `[ PluginConstructor, pluginInstance ]` pairs.
48
- */
49
- *[Symbol.iterator]() {
50
- for (const entry of this._plugins) {
51
- if (typeof entry[0] == 'function') {
52
- yield entry;
53
- }
54
- }
55
- }
56
- /**
57
- * Gets the plugin instance by its constructor or name.
58
- *
59
- * ```ts
60
- * // Check if 'Clipboard' plugin was loaded.
61
- * if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
62
- * // Get clipboard plugin instance
63
- * const clipboard = editor.plugins.get( 'ClipboardPipeline' );
64
- *
65
- * this.listenTo( clipboard, 'inputTransformation', ( evt, data ) => {
66
- * // Do something on clipboard input.
67
- * } );
68
- * }
69
- * ```
70
- *
71
- * **Note**: This method will throw an error if a plugin is not loaded. Use `{@link #has editor.plugins.has()}`
72
- * to check if a plugin is available.
73
- *
74
- * @param key The plugin constructor or {@link module:core/plugin~PluginStaticMembers#pluginName name}.
75
- */
76
- get(key) {
77
- const plugin = this._plugins.get(key);
78
- if (!plugin) {
79
- let pluginName = key;
80
- if (typeof key == 'function') {
81
- pluginName = key.pluginName || key.name;
82
- }
83
- /**
84
- * The plugin is not loaded and could not be obtained.
85
- *
86
- * Plugin classes (constructors) need to be provided to the editor and must be loaded before they can be obtained from
87
- * the plugin collection.
88
- * This is usually done in CKEditor 5 builds by setting the {@link module:core/editor/editor~Editor.builtinPlugins}
89
- * property.
90
- *
91
- * **Note**: You can use `{@link module:core/plugincollection~PluginCollection#has editor.plugins.has()}`
92
- * to check if a plugin was loaded.
93
- *
94
- * @error plugincollection-plugin-not-loaded
95
- * @param plugin The name of the plugin which is not loaded.
96
- */
97
- throw new CKEditorError('plugincollection-plugin-not-loaded', this._context, { plugin: pluginName });
98
- }
99
- return plugin;
100
- }
101
- /**
102
- * Checks if a plugin is loaded.
103
- *
104
- * ```ts
105
- * // Check if the 'Clipboard' plugin was loaded.
106
- * if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
107
- * // Now use the clipboard plugin instance:
108
- * const clipboard = editor.plugins.get( 'ClipboardPipeline' );
109
- *
110
- * // ...
111
- * }
112
- * ```
113
- *
114
- * @param key The plugin constructor or {@link module:core/plugin~PluginStaticMembers#pluginName name}.
115
- */
116
- has(key) {
117
- return this._plugins.has(key);
118
- }
119
- /**
120
- * Initializes a set of plugins and adds them to the collection.
121
- *
122
- * @param plugins An array of {@link module:core/plugin~PluginInterface plugin constructors}
123
- * or {@link module:core/plugin~PluginStaticMembers#pluginName plugin names}.
124
- * @param pluginsToRemove Names of the plugins or plugin constructors
125
- * that should not be loaded (despite being specified in the `plugins` array).
126
- * @param pluginsSubstitutions An array of {@link module:core/plugin~PluginInterface plugin constructors}
127
- * that will be used to replace plugins of the same names that were passed in `plugins` or that are in their dependency tree.
128
- * A useful option for replacing built-in plugins while creating tests (for mocking their APIs). Plugins that will be replaced
129
- * must follow these rules:
130
- * * The new plugin must be a class.
131
- * * The new plugin must be named.
132
- * * Both plugins must not depend on other plugins.
133
- * @returns A promise which gets resolved once all plugins are loaded and available in the collection.
134
- */
135
- init(plugins, pluginsToRemove = [], pluginsSubstitutions = []) {
136
- // Plugin initialization procedure consists of 2 main steps:
137
- // 1) collecting all available plugin constructors,
138
- // 2) verification whether all required plugins can be instantiated.
139
- //
140
- // In the first step, all plugin constructors, available in the provided `plugins` array and inside
141
- // plugin's dependencies (from the `Plugin.requires` array), are recursively collected and added to the existing
142
- // `this._availablePlugins` map, but without any verification at the given moment. Performing the verification
143
- // at this point (during the plugin constructor searching) would cause false errors to occur, that some plugin
144
- // is missing but in fact it may be defined further in the array as the dependency of other plugin. After
145
- // traversing the entire dependency tree, it will be checked if all required "top level" plugins are available.
146
- //
147
- // In the second step, the list of plugins that have not been explicitly removed is traversed to get all the
148
- // plugin constructors to be instantiated in the correct order and to validate against some rules. Finally, if
149
- // no plugin is missing and no other error has been found, they all will be instantiated.
150
- // eslint-disable-next-line @typescript-eslint/no-this-alias
151
- const that = this;
152
- const context = this._context;
153
- findAvailablePluginConstructors(plugins);
154
- validatePlugins(plugins);
155
- const pluginsToLoad = plugins.filter(plugin => !isPluginRemoved(plugin, pluginsToRemove));
156
- const pluginConstructors = [...getPluginConstructors(pluginsToLoad)];
157
- substitutePlugins(pluginConstructors, pluginsSubstitutions);
158
- const pluginInstances = loadPlugins(pluginConstructors);
159
- return initPlugins(pluginInstances, 'init')
160
- .then(() => initPlugins(pluginInstances, 'afterInit'))
161
- .then(() => pluginInstances);
162
- function isPluginConstructor(plugin) {
163
- return typeof plugin === 'function';
164
- }
165
- function isContextPlugin(plugin) {
166
- return isPluginConstructor(plugin) && !!plugin.isContextPlugin;
167
- }
168
- function isPluginRemoved(plugin, pluginsToRemove) {
169
- return pluginsToRemove.some(removedPlugin => {
170
- if (removedPlugin === plugin) {
171
- return true;
172
- }
173
- if (getPluginName(plugin) === removedPlugin) {
174
- return true;
175
- }
176
- if (getPluginName(removedPlugin) === plugin) {
177
- return true;
178
- }
179
- return false;
180
- });
181
- }
182
- function getPluginName(plugin) {
183
- return isPluginConstructor(plugin) ?
184
- plugin.pluginName || plugin.name :
185
- plugin;
186
- }
187
- function findAvailablePluginConstructors(plugins, processed = new Set()) {
188
- plugins.forEach(plugin => {
189
- if (!isPluginConstructor(plugin)) {
190
- return;
191
- }
192
- if (processed.has(plugin)) {
193
- return;
194
- }
195
- processed.add(plugin);
196
- if (plugin.pluginName && !that._availablePlugins.has(plugin.pluginName)) {
197
- that._availablePlugins.set(plugin.pluginName, plugin);
198
- }
199
- if (plugin.requires) {
200
- findAvailablePluginConstructors(plugin.requires, processed);
201
- }
202
- });
203
- }
204
- function getPluginConstructors(plugins, processed = new Set()) {
205
- return plugins
206
- .map(plugin => {
207
- return isPluginConstructor(plugin) ?
208
- plugin :
209
- that._availablePlugins.get(plugin);
210
- })
211
- .reduce((result, plugin) => {
212
- if (processed.has(plugin)) {
213
- return result;
214
- }
215
- processed.add(plugin);
216
- if (plugin.requires) {
217
- validatePlugins(plugin.requires, plugin);
218
- getPluginConstructors(plugin.requires, processed).forEach(plugin => result.add(plugin));
219
- }
220
- return result.add(plugin);
221
- }, new Set());
222
- }
223
- function validatePlugins(plugins, parentPluginConstructor = null) {
224
- plugins
225
- .map(plugin => {
226
- return isPluginConstructor(plugin) ?
227
- plugin :
228
- that._availablePlugins.get(plugin) || plugin;
229
- })
230
- .forEach(plugin => {
231
- checkMissingPlugin(plugin, parentPluginConstructor);
232
- checkContextPlugin(plugin, parentPluginConstructor);
233
- checkRemovedPlugin(plugin, parentPluginConstructor);
234
- });
235
- }
236
- function checkMissingPlugin(plugin, parentPluginConstructor) {
237
- if (isPluginConstructor(plugin)) {
238
- return;
239
- }
240
- if (parentPluginConstructor) {
241
- /**
242
- * A required "soft" dependency was not found on the plugin list.
243
- *
244
- * When configuring the editor, either prior to building (via
245
- * {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}) or when
246
- * creating a new instance of the editor (e.g. via
247
- * {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`}), you need to provide
248
- * some of the dependencies for other plugins that you used.
249
- *
250
- * This error is thrown when one of these dependencies was not provided. The name of the missing plugin
251
- * can be found in `missingPlugin` and the plugin that required it in `requiredBy`.
252
- *
253
- * In order to resolve it, you need to import the missing plugin and add it to the
254
- * current list of plugins (`Editor.builtinPlugins` or `config.plugins`/`config.extraPlugins`).
255
- *
256
- * Soft requirements were introduced in version 26.0.0. If you happen to stumble upon this error
257
- * when upgrading to version 26.0.0, read also the
258
- * {@glink updating/guides/update-to-26 Migration to 26.0.0} guide.
259
- *
260
- * @error plugincollection-soft-required
261
- * @param missingPlugin The name of the required plugin.
262
- * @param requiredBy The name of the plugin that requires the other plugin.
263
- */
264
- throw new CKEditorError('plugincollection-soft-required', context, { missingPlugin: plugin, requiredBy: getPluginName(parentPluginConstructor) });
265
- }
266
- /**
267
- * A plugin is not available and could not be loaded.
268
- *
269
- * Plugin classes (constructors) need to be provided to the editor before they can be loaded by name.
270
- * This is usually done in CKEditor 5 builds by setting the {@link module:core/editor/editor~Editor.builtinPlugins}
271
- * property.
272
- *
273
- * **If you see this warning when using one of the {@glink installation/getting-started/predefined-builds
274
- * CKEditor 5 Builds}**,
275
- * it means that you try to enable a plugin which was not included in that build. This may be due to a typo
276
- * in the plugin name or simply because that plugin is not a part of this build. In the latter scenario,
277
- * read more about {@glink installation/getting-started/quick-start custom builds}.
278
- *
279
- * **If you see this warning when using one of the editor creators directly** (not a build), then it means
280
- * that you tried loading plugins by name. However, unlike CKEditor 4, CKEditor 5 does not implement a "plugin loader".
281
- * This means that CKEditor 5 does not know where to load the plugin modules from. Therefore, you need to
282
- * provide each plugin through a reference (as a constructor function). Check out the examples in
283
- * {@glink installation/advanced/alternative-setups/integrating-from-source-webpack "Building from source"}.
284
- *
285
- * @error plugincollection-plugin-not-found
286
- * @param plugin The name of the plugin which could not be loaded.
287
- */
288
- throw new CKEditorError('plugincollection-plugin-not-found', context, { plugin });
289
- }
290
- function checkContextPlugin(plugin, parentPluginConstructor) {
291
- if (!isContextPlugin(parentPluginConstructor)) {
292
- return;
293
- }
294
- if (isContextPlugin(plugin)) {
295
- return;
296
- }
297
- /**
298
- * If a plugin is a context plugin, all plugins it requires should also be context plugins
299
- * instead of plugins. In other words, if one plugin can be used in the context,
300
- * all its requirements should also be ready to be used in the context. Note that the context
301
- * provides only a part of the API provided by the editor. If one plugin needs a full
302
- * editor API, all plugins which require it are considered as plugins that need a full
303
- * editor API.
304
- *
305
- * @error plugincollection-context-required
306
- * @param plugin The name of the required plugin.
307
- * @param requiredBy The name of the parent plugin.
308
- */
309
- throw new CKEditorError('plugincollection-context-required', context, { plugin: getPluginName(plugin), requiredBy: getPluginName(parentPluginConstructor) });
310
- }
311
- function checkRemovedPlugin(plugin, parentPluginConstructor) {
312
- if (!parentPluginConstructor) {
313
- return;
314
- }
315
- if (!isPluginRemoved(plugin, pluginsToRemove)) {
316
- return;
317
- }
318
- /**
319
- * Cannot load a plugin because one of its dependencies is listed in the `removePlugins` option.
320
- *
321
- * @error plugincollection-required
322
- * @param plugin The name of the required plugin.
323
- * @param requiredBy The name of the parent plugin.
324
- */
325
- throw new CKEditorError('plugincollection-required', context, { plugin: getPluginName(plugin), requiredBy: getPluginName(parentPluginConstructor) });
326
- }
327
- function loadPlugins(pluginConstructors) {
328
- return pluginConstructors.map(PluginConstructor => {
329
- let pluginInstance = that._contextPlugins.get(PluginConstructor);
330
- pluginInstance = pluginInstance || new PluginConstructor(context);
331
- that._add(PluginConstructor, pluginInstance);
332
- return pluginInstance;
333
- });
334
- }
335
- function initPlugins(pluginInstances, method) {
336
- return pluginInstances.reduce((promise, plugin) => {
337
- if (!plugin[method]) {
338
- return promise;
339
- }
340
- if (that._contextPlugins.has(plugin)) {
341
- return promise;
342
- }
343
- return promise.then(plugin[method].bind(plugin));
344
- }, Promise.resolve());
345
- }
346
- /**
347
- * Replaces plugin constructors with the specified set of plugins.
348
- */
349
- function substitutePlugins(pluginConstructors, pluginsSubstitutions) {
350
- for (const pluginItem of pluginsSubstitutions) {
351
- if (typeof pluginItem != 'function') {
352
- /**
353
- * The plugin replacing an existing plugin must be a function.
354
- *
355
- * @error plugincollection-replace-plugin-invalid-type
356
- */
357
- throw new CKEditorError('plugincollection-replace-plugin-invalid-type', null, { pluginItem });
358
- }
359
- const pluginName = pluginItem.pluginName;
360
- if (!pluginName) {
361
- /**
362
- * The plugin replacing an existing plugin must have a name.
363
- *
364
- * @error plugincollection-replace-plugin-missing-name
365
- */
366
- throw new CKEditorError('plugincollection-replace-plugin-missing-name', null, { pluginItem });
367
- }
368
- if (pluginItem.requires && pluginItem.requires.length) {
369
- /**
370
- * The plugin replacing an existing plugin cannot depend on other plugins.
371
- *
372
- * @error plugincollection-plugin-for-replacing-cannot-have-dependencies
373
- */
374
- throw new CKEditorError('plugincollection-plugin-for-replacing-cannot-have-dependencies', null, { pluginName });
375
- }
376
- const pluginToReplace = that._availablePlugins.get(pluginName);
377
- if (!pluginToReplace) {
378
- /**
379
- * The replaced plugin does not exist in the
380
- * {@link module:core/plugincollection~PluginCollection available plugins} collection.
381
- *
382
- * @error plugincollection-plugin-for-replacing-not-exist
383
- */
384
- throw new CKEditorError('plugincollection-plugin-for-replacing-not-exist', null, { pluginName });
385
- }
386
- const indexInPluginConstructors = pluginConstructors.indexOf(pluginToReplace);
387
- if (indexInPluginConstructors === -1) {
388
- // The Context feature can substitute plugins as well.
389
- // It may happen that the editor will be created with the given context, where the plugin for substitute
390
- // was already replaced. In such a case, we don't want to do it again.
391
- if (that._contextPlugins.has(pluginToReplace)) {
392
- return;
393
- }
394
- /**
395
- * The replaced plugin will not be loaded so it cannot be replaced.
396
- *
397
- * @error plugincollection-plugin-for-replacing-not-loaded
398
- */
399
- throw new CKEditorError('plugincollection-plugin-for-replacing-not-loaded', null, { pluginName });
400
- }
401
- if (pluginToReplace.requires && pluginToReplace.requires.length) {
402
- /**
403
- * The replaced plugin cannot depend on other plugins.
404
- *
405
- * @error plugincollection-replaced-plugin-cannot-have-dependencies
406
- */
407
- throw new CKEditorError('plugincollection-replaced-plugin-cannot-have-dependencies', null, { pluginName });
408
- }
409
- pluginConstructors.splice(indexInPluginConstructors, 1, pluginItem);
410
- that._availablePlugins.set(pluginName, pluginItem);
411
- }
412
- }
413
- }
414
- /**
415
- * Destroys all loaded plugins.
416
- */
417
- destroy() {
418
- const promises = [];
419
- for (const [, pluginInstance] of this) {
420
- if (typeof pluginInstance.destroy == 'function' && !this._contextPlugins.has(pluginInstance)) {
421
- promises.push(pluginInstance.destroy());
422
- }
423
- }
424
- return Promise.all(promises);
425
- }
426
- /**
427
- * Adds the plugin to the collection. Exposed mainly for testing purposes.
428
- *
429
- * @param PluginConstructor The plugin constructor.
430
- * @param plugin The instance of the plugin.
431
- */
432
- _add(PluginConstructor, plugin) {
433
- this._plugins.set(PluginConstructor, plugin);
434
- const pluginName = PluginConstructor.pluginName;
435
- if (!pluginName) {
436
- return;
437
- }
438
- if (this._plugins.has(pluginName)) {
439
- /**
440
- * Two plugins with the same {@link module:core/plugin~PluginStaticMembers#pluginName} were loaded.
441
- * This will lead to runtime conflicts between these plugins.
442
- *
443
- * In practice, this warning usually means that new plugins were added to an existing CKEditor 5 build.
444
- * Plugins should always be added to a source version of the editor (`@ckeditor/ckeditor5-editor-*`),
445
- * not to an editor imported from one of the `@ckeditor/ckeditor5-build-*` packages.
446
- *
447
- * Check your import paths and the list of plugins passed to
448
- * {@link module:core/editor/editor~Editor.create `Editor.create()`}
449
- * or specified in {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}.
450
- *
451
- * The second option is that your `node_modules/` directory contains duplicated versions of the same
452
- * CKEditor 5 packages. Normally, on clean installations, npm deduplicates packages in `node_modules/`, so
453
- * it may be enough to call `rm -rf node_modules && npm i`. However, if you installed conflicting versions
454
- * of some packages, their dependencies may need to be installed in more than one version which may lead to this
455
- * warning.
456
- *
457
- * Technically speaking, this error occurs because after adding a plugin to an existing editor build
458
- * the dependencies of this plugin are being duplicated.
459
- * They are already built into that editor build and now get added for the second time as dependencies
460
- * of the plugin you are installing.
461
- *
462
- * Read more about {@glink installation/plugins/installing-plugins Installing plugins}.
463
- *
464
- * @error plugincollection-plugin-name-conflict
465
- * @param pluginName The duplicated plugin name.
466
- * @param plugin1 The first plugin constructor.
467
- * @param plugin2 The second plugin constructor.
468
- */
469
- throw new CKEditorError('plugincollection-plugin-name-conflict', null, { pluginName, plugin1: this._plugins.get(pluginName).constructor, plugin2: PluginConstructor });
470
- }
471
- this._plugins.set(pluginName, plugin);
472
- }
473
- }
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/plugincollection
7
+ */
8
+ import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
9
+ /**
10
+ * Manages a list of CKEditor plugins, including loading, resolving dependencies and initialization.
11
+ */
12
+ export default class PluginCollection extends EmitterMixin() {
13
+ /**
14
+ * Creates an instance of the plugin collection class.
15
+ * Allows loading and initializing plugins and their dependencies.
16
+ * Allows providing a list of already loaded plugins. These plugins will not be destroyed along with this collection.
17
+ *
18
+ * @param availablePlugins Plugins (constructors) which the collection will be able to use
19
+ * when {@link module:core/plugincollection~PluginCollection#init} is used with the plugin names (strings, instead of constructors).
20
+ * Usually, the editor will pass its built-in plugins to the collection so they can later be
21
+ * used in `config.plugins` or `config.removePlugins` by names.
22
+ * @param contextPlugins A list of already initialized plugins represented by a `[ PluginConstructor, pluginInstance ]` pair.
23
+ */
24
+ constructor(context, availablePlugins = [], contextPlugins = []) {
25
+ super();
26
+ this._plugins = new Map();
27
+ this._context = context;
28
+ this._availablePlugins = new Map();
29
+ for (const PluginConstructor of availablePlugins) {
30
+ if (PluginConstructor.pluginName) {
31
+ this._availablePlugins.set(PluginConstructor.pluginName, PluginConstructor);
32
+ }
33
+ }
34
+ this._contextPlugins = new Map();
35
+ for (const [PluginConstructor, pluginInstance] of contextPlugins) {
36
+ this._contextPlugins.set(PluginConstructor, pluginInstance);
37
+ this._contextPlugins.set(pluginInstance, PluginConstructor);
38
+ // To make it possible to require a plugin by its name.
39
+ if (PluginConstructor.pluginName) {
40
+ this._availablePlugins.set(PluginConstructor.pluginName, PluginConstructor);
41
+ }
42
+ }
43
+ }
44
+ /**
45
+ * Iterable interface.
46
+ *
47
+ * Returns `[ PluginConstructor, pluginInstance ]` pairs.
48
+ */
49
+ *[Symbol.iterator]() {
50
+ for (const entry of this._plugins) {
51
+ if (typeof entry[0] == 'function') {
52
+ yield entry;
53
+ }
54
+ }
55
+ }
56
+ /**
57
+ * Gets the plugin instance by its constructor or name.
58
+ *
59
+ * ```ts
60
+ * // Check if 'Clipboard' plugin was loaded.
61
+ * if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
62
+ * // Get clipboard plugin instance
63
+ * const clipboard = editor.plugins.get( 'ClipboardPipeline' );
64
+ *
65
+ * this.listenTo( clipboard, 'inputTransformation', ( evt, data ) => {
66
+ * // Do something on clipboard input.
67
+ * } );
68
+ * }
69
+ * ```
70
+ *
71
+ * **Note**: This method will throw an error if a plugin is not loaded. Use `{@link #has editor.plugins.has()}`
72
+ * to check if a plugin is available.
73
+ *
74
+ * @param key The plugin constructor or {@link module:core/plugin~PluginStaticMembers#pluginName name}.
75
+ */
76
+ get(key) {
77
+ const plugin = this._plugins.get(key);
78
+ if (!plugin) {
79
+ let pluginName = key;
80
+ if (typeof key == 'function') {
81
+ pluginName = key.pluginName || key.name;
82
+ }
83
+ /**
84
+ * The plugin is not loaded and could not be obtained.
85
+ *
86
+ * Plugin classes (constructors) need to be provided to the editor and must be loaded before they can be obtained from
87
+ * the plugin collection.
88
+ * This is usually done in CKEditor 5 builds by setting the {@link module:core/editor/editor~Editor.builtinPlugins}
89
+ * property.
90
+ *
91
+ * **Note**: You can use `{@link module:core/plugincollection~PluginCollection#has editor.plugins.has()}`
92
+ * to check if a plugin was loaded.
93
+ *
94
+ * @error plugincollection-plugin-not-loaded
95
+ * @param plugin The name of the plugin which is not loaded.
96
+ */
97
+ throw new CKEditorError('plugincollection-plugin-not-loaded', this._context, { plugin: pluginName });
98
+ }
99
+ return plugin;
100
+ }
101
+ /**
102
+ * Checks if a plugin is loaded.
103
+ *
104
+ * ```ts
105
+ * // Check if the 'Clipboard' plugin was loaded.
106
+ * if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
107
+ * // Now use the clipboard plugin instance:
108
+ * const clipboard = editor.plugins.get( 'ClipboardPipeline' );
109
+ *
110
+ * // ...
111
+ * }
112
+ * ```
113
+ *
114
+ * @param key The plugin constructor or {@link module:core/plugin~PluginStaticMembers#pluginName name}.
115
+ */
116
+ has(key) {
117
+ return this._plugins.has(key);
118
+ }
119
+ /**
120
+ * Initializes a set of plugins and adds them to the collection.
121
+ *
122
+ * @param plugins An array of {@link module:core/plugin~PluginInterface plugin constructors}
123
+ * or {@link module:core/plugin~PluginStaticMembers#pluginName plugin names}.
124
+ * @param pluginsToRemove Names of the plugins or plugin constructors
125
+ * that should not be loaded (despite being specified in the `plugins` array).
126
+ * @param pluginsSubstitutions An array of {@link module:core/plugin~PluginInterface plugin constructors}
127
+ * that will be used to replace plugins of the same names that were passed in `plugins` or that are in their dependency tree.
128
+ * A useful option for replacing built-in plugins while creating tests (for mocking their APIs). Plugins that will be replaced
129
+ * must follow these rules:
130
+ * * The new plugin must be a class.
131
+ * * The new plugin must be named.
132
+ * * Both plugins must not depend on other plugins.
133
+ * @returns A promise which gets resolved once all plugins are loaded and available in the collection.
134
+ */
135
+ init(plugins, pluginsToRemove = [], pluginsSubstitutions = []) {
136
+ // Plugin initialization procedure consists of 2 main steps:
137
+ // 1) collecting all available plugin constructors,
138
+ // 2) verification whether all required plugins can be instantiated.
139
+ //
140
+ // In the first step, all plugin constructors, available in the provided `plugins` array and inside
141
+ // plugin's dependencies (from the `Plugin.requires` array), are recursively collected and added to the existing
142
+ // `this._availablePlugins` map, but without any verification at the given moment. Performing the verification
143
+ // at this point (during the plugin constructor searching) would cause false errors to occur, that some plugin
144
+ // is missing but in fact it may be defined further in the array as the dependency of other plugin. After
145
+ // traversing the entire dependency tree, it will be checked if all required "top level" plugins are available.
146
+ //
147
+ // In the second step, the list of plugins that have not been explicitly removed is traversed to get all the
148
+ // plugin constructors to be instantiated in the correct order and to validate against some rules. Finally, if
149
+ // no plugin is missing and no other error has been found, they all will be instantiated.
150
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
151
+ const that = this;
152
+ const context = this._context;
153
+ findAvailablePluginConstructors(plugins);
154
+ validatePlugins(plugins);
155
+ const pluginsToLoad = plugins.filter(plugin => !isPluginRemoved(plugin, pluginsToRemove));
156
+ const pluginConstructors = [...getPluginConstructors(pluginsToLoad)];
157
+ substitutePlugins(pluginConstructors, pluginsSubstitutions);
158
+ const pluginInstances = loadPlugins(pluginConstructors);
159
+ return initPlugins(pluginInstances, 'init')
160
+ .then(() => initPlugins(pluginInstances, 'afterInit'))
161
+ .then(() => pluginInstances);
162
+ function isPluginConstructor(plugin) {
163
+ return typeof plugin === 'function';
164
+ }
165
+ function isContextPlugin(plugin) {
166
+ return isPluginConstructor(plugin) && !!plugin.isContextPlugin;
167
+ }
168
+ function isPluginRemoved(plugin, pluginsToRemove) {
169
+ return pluginsToRemove.some(removedPlugin => {
170
+ if (removedPlugin === plugin) {
171
+ return true;
172
+ }
173
+ if (getPluginName(plugin) === removedPlugin) {
174
+ return true;
175
+ }
176
+ if (getPluginName(removedPlugin) === plugin) {
177
+ return true;
178
+ }
179
+ return false;
180
+ });
181
+ }
182
+ function getPluginName(plugin) {
183
+ return isPluginConstructor(plugin) ?
184
+ plugin.pluginName || plugin.name :
185
+ plugin;
186
+ }
187
+ function findAvailablePluginConstructors(plugins, processed = new Set()) {
188
+ plugins.forEach(plugin => {
189
+ if (!isPluginConstructor(plugin)) {
190
+ return;
191
+ }
192
+ if (processed.has(plugin)) {
193
+ return;
194
+ }
195
+ processed.add(plugin);
196
+ if (plugin.pluginName && !that._availablePlugins.has(plugin.pluginName)) {
197
+ that._availablePlugins.set(plugin.pluginName, plugin);
198
+ }
199
+ if (plugin.requires) {
200
+ findAvailablePluginConstructors(plugin.requires, processed);
201
+ }
202
+ });
203
+ }
204
+ function getPluginConstructors(plugins, processed = new Set()) {
205
+ return plugins
206
+ .map(plugin => {
207
+ return isPluginConstructor(plugin) ?
208
+ plugin :
209
+ that._availablePlugins.get(plugin);
210
+ })
211
+ .reduce((result, plugin) => {
212
+ if (processed.has(plugin)) {
213
+ return result;
214
+ }
215
+ processed.add(plugin);
216
+ if (plugin.requires) {
217
+ validatePlugins(plugin.requires, plugin);
218
+ getPluginConstructors(plugin.requires, processed).forEach(plugin => result.add(plugin));
219
+ }
220
+ return result.add(plugin);
221
+ }, new Set());
222
+ }
223
+ function validatePlugins(plugins, parentPluginConstructor = null) {
224
+ plugins
225
+ .map(plugin => {
226
+ return isPluginConstructor(plugin) ?
227
+ plugin :
228
+ that._availablePlugins.get(plugin) || plugin;
229
+ })
230
+ .forEach(plugin => {
231
+ checkMissingPlugin(plugin, parentPluginConstructor);
232
+ checkContextPlugin(plugin, parentPluginConstructor);
233
+ checkRemovedPlugin(plugin, parentPluginConstructor);
234
+ });
235
+ }
236
+ function checkMissingPlugin(plugin, parentPluginConstructor) {
237
+ if (isPluginConstructor(plugin)) {
238
+ return;
239
+ }
240
+ if (parentPluginConstructor) {
241
+ /**
242
+ * A required "soft" dependency was not found on the plugin list.
243
+ *
244
+ * When configuring the editor, either prior to building (via
245
+ * {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}) or when
246
+ * creating a new instance of the editor (e.g. via
247
+ * {@link module:core/editor/editorconfig~EditorConfig#plugins `config.plugins`}), you need to provide
248
+ * some of the dependencies for other plugins that you used.
249
+ *
250
+ * This error is thrown when one of these dependencies was not provided. The name of the missing plugin
251
+ * can be found in `missingPlugin` and the plugin that required it in `requiredBy`.
252
+ *
253
+ * In order to resolve it, you need to import the missing plugin and add it to the
254
+ * current list of plugins (`Editor.builtinPlugins` or `config.plugins`/`config.extraPlugins`).
255
+ *
256
+ * Soft requirements were introduced in version 26.0.0. If you happen to stumble upon this error
257
+ * when upgrading to version 26.0.0, read also the
258
+ * {@glink updating/guides/update-to-26 Migration to 26.0.0} guide.
259
+ *
260
+ * @error plugincollection-soft-required
261
+ * @param missingPlugin The name of the required plugin.
262
+ * @param requiredBy The name of the plugin that requires the other plugin.
263
+ */
264
+ throw new CKEditorError('plugincollection-soft-required', context, { missingPlugin: plugin, requiredBy: getPluginName(parentPluginConstructor) });
265
+ }
266
+ /**
267
+ * A plugin is not available and could not be loaded.
268
+ *
269
+ * Plugin classes (constructors) need to be provided to the editor before they can be loaded by name.
270
+ * This is usually done in CKEditor 5 builds by setting the {@link module:core/editor/editor~Editor.builtinPlugins}
271
+ * property.
272
+ *
273
+ * **If you see this warning when using one of the {@glink installation/getting-started/predefined-builds
274
+ * CKEditor 5 Builds}**,
275
+ * it means that you try to enable a plugin which was not included in that build. This may be due to a typo
276
+ * in the plugin name or simply because that plugin is not a part of this build. In the latter scenario,
277
+ * read more about {@glink installation/getting-started/quick-start custom builds}.
278
+ *
279
+ * **If you see this warning when using one of the editor creators directly** (not a build), then it means
280
+ * that you tried loading plugins by name. However, unlike CKEditor 4, CKEditor 5 does not implement a "plugin loader".
281
+ * This means that CKEditor 5 does not know where to load the plugin modules from. Therefore, you need to
282
+ * provide each plugin through a reference (as a constructor function). Check out the examples in
283
+ * {@glink installation/advanced/alternative-setups/integrating-from-source-webpack "Building from source"}.
284
+ *
285
+ * @error plugincollection-plugin-not-found
286
+ * @param plugin The name of the plugin which could not be loaded.
287
+ */
288
+ throw new CKEditorError('plugincollection-plugin-not-found', context, { plugin });
289
+ }
290
+ function checkContextPlugin(plugin, parentPluginConstructor) {
291
+ if (!isContextPlugin(parentPluginConstructor)) {
292
+ return;
293
+ }
294
+ if (isContextPlugin(plugin)) {
295
+ return;
296
+ }
297
+ /**
298
+ * If a plugin is a context plugin, all plugins it requires should also be context plugins
299
+ * instead of plugins. In other words, if one plugin can be used in the context,
300
+ * all its requirements should also be ready to be used in the context. Note that the context
301
+ * provides only a part of the API provided by the editor. If one plugin needs a full
302
+ * editor API, all plugins which require it are considered as plugins that need a full
303
+ * editor API.
304
+ *
305
+ * @error plugincollection-context-required
306
+ * @param plugin The name of the required plugin.
307
+ * @param requiredBy The name of the parent plugin.
308
+ */
309
+ throw new CKEditorError('plugincollection-context-required', context, { plugin: getPluginName(plugin), requiredBy: getPluginName(parentPluginConstructor) });
310
+ }
311
+ function checkRemovedPlugin(plugin, parentPluginConstructor) {
312
+ if (!parentPluginConstructor) {
313
+ return;
314
+ }
315
+ if (!isPluginRemoved(plugin, pluginsToRemove)) {
316
+ return;
317
+ }
318
+ /**
319
+ * Cannot load a plugin because one of its dependencies is listed in the `removePlugins` option.
320
+ *
321
+ * @error plugincollection-required
322
+ * @param plugin The name of the required plugin.
323
+ * @param requiredBy The name of the parent plugin.
324
+ */
325
+ throw new CKEditorError('plugincollection-required', context, { plugin: getPluginName(plugin), requiredBy: getPluginName(parentPluginConstructor) });
326
+ }
327
+ function loadPlugins(pluginConstructors) {
328
+ return pluginConstructors.map(PluginConstructor => {
329
+ let pluginInstance = that._contextPlugins.get(PluginConstructor);
330
+ pluginInstance = pluginInstance || new PluginConstructor(context);
331
+ that._add(PluginConstructor, pluginInstance);
332
+ return pluginInstance;
333
+ });
334
+ }
335
+ function initPlugins(pluginInstances, method) {
336
+ return pluginInstances.reduce((promise, plugin) => {
337
+ if (!plugin[method]) {
338
+ return promise;
339
+ }
340
+ if (that._contextPlugins.has(plugin)) {
341
+ return promise;
342
+ }
343
+ return promise.then(plugin[method].bind(plugin));
344
+ }, Promise.resolve());
345
+ }
346
+ /**
347
+ * Replaces plugin constructors with the specified set of plugins.
348
+ */
349
+ function substitutePlugins(pluginConstructors, pluginsSubstitutions) {
350
+ for (const pluginItem of pluginsSubstitutions) {
351
+ if (typeof pluginItem != 'function') {
352
+ /**
353
+ * The plugin replacing an existing plugin must be a function.
354
+ *
355
+ * @error plugincollection-replace-plugin-invalid-type
356
+ */
357
+ throw new CKEditorError('plugincollection-replace-plugin-invalid-type', null, { pluginItem });
358
+ }
359
+ const pluginName = pluginItem.pluginName;
360
+ if (!pluginName) {
361
+ /**
362
+ * The plugin replacing an existing plugin must have a name.
363
+ *
364
+ * @error plugincollection-replace-plugin-missing-name
365
+ */
366
+ throw new CKEditorError('plugincollection-replace-plugin-missing-name', null, { pluginItem });
367
+ }
368
+ if (pluginItem.requires && pluginItem.requires.length) {
369
+ /**
370
+ * The plugin replacing an existing plugin cannot depend on other plugins.
371
+ *
372
+ * @error plugincollection-plugin-for-replacing-cannot-have-dependencies
373
+ */
374
+ throw new CKEditorError('plugincollection-plugin-for-replacing-cannot-have-dependencies', null, { pluginName });
375
+ }
376
+ const pluginToReplace = that._availablePlugins.get(pluginName);
377
+ if (!pluginToReplace) {
378
+ /**
379
+ * The replaced plugin does not exist in the
380
+ * {@link module:core/plugincollection~PluginCollection available plugins} collection.
381
+ *
382
+ * @error plugincollection-plugin-for-replacing-not-exist
383
+ */
384
+ throw new CKEditorError('plugincollection-plugin-for-replacing-not-exist', null, { pluginName });
385
+ }
386
+ const indexInPluginConstructors = pluginConstructors.indexOf(pluginToReplace);
387
+ if (indexInPluginConstructors === -1) {
388
+ // The Context feature can substitute plugins as well.
389
+ // It may happen that the editor will be created with the given context, where the plugin for substitute
390
+ // was already replaced. In such a case, we don't want to do it again.
391
+ if (that._contextPlugins.has(pluginToReplace)) {
392
+ return;
393
+ }
394
+ /**
395
+ * The replaced plugin will not be loaded so it cannot be replaced.
396
+ *
397
+ * @error plugincollection-plugin-for-replacing-not-loaded
398
+ */
399
+ throw new CKEditorError('plugincollection-plugin-for-replacing-not-loaded', null, { pluginName });
400
+ }
401
+ if (pluginToReplace.requires && pluginToReplace.requires.length) {
402
+ /**
403
+ * The replaced plugin cannot depend on other plugins.
404
+ *
405
+ * @error plugincollection-replaced-plugin-cannot-have-dependencies
406
+ */
407
+ throw new CKEditorError('plugincollection-replaced-plugin-cannot-have-dependencies', null, { pluginName });
408
+ }
409
+ pluginConstructors.splice(indexInPluginConstructors, 1, pluginItem);
410
+ that._availablePlugins.set(pluginName, pluginItem);
411
+ }
412
+ }
413
+ }
414
+ /**
415
+ * Destroys all loaded plugins.
416
+ */
417
+ destroy() {
418
+ const promises = [];
419
+ for (const [, pluginInstance] of this) {
420
+ if (typeof pluginInstance.destroy == 'function' && !this._contextPlugins.has(pluginInstance)) {
421
+ promises.push(pluginInstance.destroy());
422
+ }
423
+ }
424
+ return Promise.all(promises);
425
+ }
426
+ /**
427
+ * Adds the plugin to the collection. Exposed mainly for testing purposes.
428
+ *
429
+ * @param PluginConstructor The plugin constructor.
430
+ * @param plugin The instance of the plugin.
431
+ */
432
+ _add(PluginConstructor, plugin) {
433
+ this._plugins.set(PluginConstructor, plugin);
434
+ const pluginName = PluginConstructor.pluginName;
435
+ if (!pluginName) {
436
+ return;
437
+ }
438
+ if (this._plugins.has(pluginName)) {
439
+ /**
440
+ * Two plugins with the same {@link module:core/plugin~PluginStaticMembers#pluginName} were loaded.
441
+ * This will lead to runtime conflicts between these plugins.
442
+ *
443
+ * In practice, this warning usually means that new plugins were added to an existing CKEditor 5 build.
444
+ * Plugins should always be added to a source version of the editor (`@ckeditor/ckeditor5-editor-*`),
445
+ * not to an editor imported from one of the `@ckeditor/ckeditor5-build-*` packages.
446
+ *
447
+ * Check your import paths and the list of plugins passed to
448
+ * {@link module:core/editor/editor~Editor.create `Editor.create()`}
449
+ * or specified in {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}.
450
+ *
451
+ * The second option is that your `node_modules/` directory contains duplicated versions of the same
452
+ * CKEditor 5 packages. Normally, on clean installations, npm deduplicates packages in `node_modules/`, so
453
+ * it may be enough to call `rm -rf node_modules && npm i`. However, if you installed conflicting versions
454
+ * of some packages, their dependencies may need to be installed in more than one version which may lead to this
455
+ * warning.
456
+ *
457
+ * Technically speaking, this error occurs because after adding a plugin to an existing editor build
458
+ * the dependencies of this plugin are being duplicated.
459
+ * They are already built into that editor build and now get added for the second time as dependencies
460
+ * of the plugin you are installing.
461
+ *
462
+ * Read more about {@glink installation/plugins/installing-plugins Installing plugins}.
463
+ *
464
+ * @error plugincollection-plugin-name-conflict
465
+ * @param pluginName The duplicated plugin name.
466
+ * @param plugin1 The first plugin constructor.
467
+ * @param plugin2 The second plugin constructor.
468
+ */
469
+ throw new CKEditorError('plugincollection-plugin-name-conflict', null, { pluginName, plugin1: this._plugins.get(pluginName).constructor, plugin2: PluginConstructor });
470
+ }
471
+ this._plugins.set(pluginName, plugin);
472
+ }
473
+ }