1 |
|
2 |
|
3 |
|
4 |
|
5 | import type { LoadedPlugins, PluginClassConstructor, PluginConstructor, PluginInterface } from './plugin.js';
|
6 | declare const PluginCollection_base: {
|
7 | new (): import("@ckeditor/ckeditor5-utils").Emitter;
|
8 | prototype: import("@ckeditor/ckeditor5-utils").Emitter;
|
9 | };
|
10 |
|
11 |
|
12 |
|
13 | export default class PluginCollection<TContext extends object> extends PluginCollection_base implements Iterable<PluginEntry<TContext>> {
|
14 | private _context;
|
15 | private _plugins;
|
16 | |
17 |
|
18 |
|
19 | private _availablePlugins;
|
20 | |
21 |
|
22 |
|
23 | private _contextPlugins;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | constructor(context: TContext, availablePlugins?: Iterable<PluginConstructor<TContext>>, contextPlugins?: Iterable<PluginEntry<TContext>>);
|
36 | /**
|
37 | * Iterable interface.
|
38 | *
|
39 | * Returns `[ PluginConstructor, pluginInstance ]` pairs.
|
40 | */
|
41 | [Symbol.iterator](): IterableIterator<PluginEntry<TContext>>;
|
42 | get<TConstructor extends PluginClassConstructor<TContext>>(key: TConstructor): InstanceType<TConstructor>;
|
43 | get<TName extends string>(key: TName): PluginsMap[TName];
|
44 | /**
|
45 | * Checks if a plugin is loaded.
|
46 | *
|
47 | * ```ts
|
48 | * // Check if the 'Clipboard' plugin was loaded.
|
49 | * if ( editor.plugins.has( 'ClipboardPipeline' ) ) {
|
50 | *
|
51 | * const clipboard = editor.plugins.get( 'ClipboardPipeline' );
|
52 | *
|
53 | *
|
54 | * }
|
55 | * ```
|
56 | *
|
57 | * @param key The plugin constructor or {@link module:core/plugin~PluginStaticMembers#pluginName name}.
|
58 | */
|
59 | has(key: PluginConstructor<TContext> | string): boolean;
|
60 | /**
|
61 | * Initializes a set of plugins and adds them to the collection.
|
62 | *
|
63 | * @param plugins An array of {@link module:core/plugin~PluginInterface plugin constructors}
|
64 | * or {@link module:core/plugin~PluginStaticMembers#pluginName plugin names}.
|
65 | * @param pluginsToRemove Names of the plugins or plugin constructors
|
66 | * that should not be loaded (despite being specified in the `plugins` array).
|
67 | * @param pluginsSubstitutions An array of {@link module:core/plugin~PluginInterface plugin constructors}
|
68 | * that will be used to replace plugins of the same names that were passed in `plugins` or that are in their dependency tree.
|
69 | * A useful option for replacing built-in plugins while creating tests (for mocking their APIs). Plugins that will be replaced
|
70 | * must follow these rules:
|
71 | * * The new plugin must be a class.
|
72 | * * The new plugin must be named.
|
73 | * * Both plugins must not depend on other plugins.
|
74 | * @returns A promise which gets resolved once all plugins are loaded and available in the collection.
|
75 | */
|
76 | init(plugins: ReadonlyArray<PluginConstructor<TContext> | string>, pluginsToRemove?: ReadonlyArray<PluginConstructor<TContext> | string>, pluginsSubstitutions?: ReadonlyArray<PluginConstructor<TContext>>): Promise<LoadedPlugins>;
|
77 | /**
|
78 | * Destroys all loaded plugins.
|
79 | */
|
80 | destroy(): Promise<unknown>;
|
81 | /**
|
82 | * Adds the plugin to the collection. Exposed mainly for testing purposes.
|
83 | *
|
84 | * @param PluginConstructor The plugin constructor.
|
85 | * @param plugin The instance of the plugin.
|
86 | */
|
87 | private _add;
|
88 | }
|
89 | /**
|
90 | * A `[ PluginConstructor, pluginInstance ]` pair.
|
91 | */
|
92 | export type PluginEntry<TContext> = [PluginConstructor<TContext>, PluginInterface];
|
93 | /**
|
94 | * Helper type that maps plugin names to their types.
|
95 | * It is meant to be extended with module augmentation.
|
96 | *
|
97 | * ```ts
|
98 | * class MyPlugin extends Plugin {
|
99 | * public static pluginName() {
|
100 | * return 'MyPlugin' as const;
|
101 | * }
|
102 | * }
|
103 | *
|
104 | * declare module '@ckeditor/ckeditor5-core' {
|
105 | * interface PluginsMap {
|
106 | * [ MyPlugin.pluginName ]: MyPlugin;
|
107 | * }
|
108 | * }
|
109 | *
|
110 | *
|
111 | * const myPlugin = editor.plugins.get( 'MyPlugin' );
|
112 | * ```
|
113 | */
|
114 | export interface PluginsMap {
|
115 | [name: string]: PluginInterface;
|
116 | }
|
117 | export {};
|
118 |
|
\ | No newline at end of file |