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