1 | import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
2 | import ContextPlugin from './contextplugin';
|
3 | import Editor from './editor/editor';
|
4 | import { EditorWithUI } from './editor/editorwithui';
|
5 |
|
6 | // tslint:disable-next-line:no-empty-interface
|
7 | export default interface Plugin extends Observable {}
|
8 |
|
9 | /**
|
10 | * The base class for CKEditor plugin classes.
|
11 | */
|
12 | export default class Plugin implements Observable {
|
13 | constructor(editor: Editor);
|
14 | /**
|
15 | * The editor instance.
|
16 | *
|
17 | * Note that most editors implement the {module:core/editor/editorwithui~EditorWithUI} interface in addition
|
18 | * to the base {module:core/editor/editor~Editor} interface. However, editors with an external UI
|
19 | * (i.e. Bootstrap-based) or a headless editor may not implement the {module:core/editor/editorwithui~EditorWithUI}
|
20 | * interface.
|
21 | *
|
22 | * Because of above, to make plugins more universal, it is recommended to split features into:
|
23 | * - The "editing" part that only uses the {module:core/editor/editor~Editor} interface.
|
24 | * - The "UI" part that uses both the {module:core/editor/editor~Editor} interface and
|
25 | * the {module:core/editor/editorwithui~EditorWithUI} interface.
|
26 | */
|
27 | readonly editor: Editor | EditorWithUI;
|
28 | /**
|
29 | * Flag indicating whether a plugin is enabled or disabled.
|
30 | * A disabled plugin will not transform text.
|
31 | *
|
32 | * Plugin can be simply disabled like that:
|
33 | *
|
34 | * // Disable the plugin so that no toolbars are visible.
|
35 | * editor.plugins.get( 'TextTransformation' ).isEnabled = false;
|
36 | *
|
37 | * You can also use { #forceDisabled} method.
|
38 | */
|
39 | isEnabled: boolean;
|
40 | /**
|
41 | * Disables the plugin.
|
42 | *
|
43 | * Plugin may be disabled by multiple features or algorithms (at once). When disabling a plugin, unique id should be passed
|
44 | * (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the plugin.
|
45 | * The plugin becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
|
46 | *
|
47 | * Disabling and enabling a plugin:
|
48 | *
|
49 | * plugin.isEnabled; // -> true
|
50 | * plugin.forceDisabled( 'MyFeature' );
|
51 | * plugin.isEnabled; // -> false
|
52 | * plugin.clearForceDisabled( 'MyFeature' );
|
53 | * plugin.isEnabled; // -> true
|
54 | *
|
55 | * Plugin disabled by multiple features:
|
56 | *
|
57 | * plugin.forceDisabled( 'MyFeature' );
|
58 | * plugin.forceDisabled( 'OtherFeature' );
|
59 | * plugin.clearForceDisabled( 'MyFeature' );
|
60 | * plugin.isEnabled; // -> false
|
61 | * plugin.clearForceDisabled( 'OtherFeature' );
|
62 | * plugin.isEnabled; // -> true
|
63 | *
|
64 | * Multiple disabling with the same identifier is redundant:
|
65 | *
|
66 | * plugin.forceDisabled( 'MyFeature' );
|
67 | * plugin.forceDisabled( 'MyFeature' );
|
68 | * plugin.clearForceDisabled( 'MyFeature' );
|
69 | * plugin.isEnabled; // -> true
|
70 | *
|
71 | * **Note:** some plugins or algorithms may have more complex logic when it comes to enabling or disabling certain plugins,
|
72 | * so the plugin might be still disabled after {@link #clearForceDisabled} was used.
|
73 | */
|
74 | forceDisabled(id: string): void;
|
75 | /**
|
76 | * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
|
77 | */
|
78 | clearForceDisabled(id: string): void;
|
79 | /**
|
80 | * Destroys the plugin.
|
81 | *
|
82 | * **Note:** This method is optional. A plugin instance does not need to have it defined.
|
83 | */
|
84 | destroy(): void;
|
85 | /**
|
86 | * A flag which defines if a plugin is allowed or not allowed to be used directly by a {@link module:core/context~Context}.
|
87 | */
|
88 | static readonly isContextPlugin: false;
|
89 | /**
|
90 | * An array of plugins required by this plugin.
|
91 | *
|
92 | * To keep the plugin class definition tight it is recommended to define this property as a static getter:
|
93 | *
|
94 | * import Image from './image.js';
|
95 | *
|
96 | * export default class ImageCaption {
|
97 | * static get requires() {
|
98 | * return [ Image ];
|
99 | * }
|
100 | * }
|
101 | */
|
102 | static readonly requires?: Array<typeof Plugin | typeof ContextPlugin | string> | undefined;
|
103 | /**
|
104 | * An optional name of the plugin. If set, the plugin will be available in
|
105 | * {@link module:core/plugincollection~PluginCollection#get} by its
|
106 | * name and its constructor. If not, then only by its constructor.
|
107 | *
|
108 | * The name should reflect the constructor name.
|
109 | *
|
110 | * To keep the plugin class definition tight, it is recommended to define this property as a static getter:
|
111 | *
|
112 | * export default class ImageCaption {
|
113 | * static get pluginName() {
|
114 | * return 'ImageCaption';
|
115 | * }
|
116 | * }
|
117 | *
|
118 | * Note: The native `Function.name` property could not be used to keep the plugin name because
|
119 | * it will be mangled during code minification.
|
120 | *
|
121 | * Naming a plugin is necessary to enable removing it through the
|
122 | * {@link module:core/editor/editorconfig~EditorConfig#removePlugins `config.removePlugins`} option.
|
123 | */
|
124 | static readonly pluginName?: string | undefined;
|
125 | /**
|
126 | * The second stage (after plugin {@link #constructor}) of the plugin initialization.
|
127 | * Unlike the plugin constructor this method can be asynchronous.
|
128 | *
|
129 | * A plugin's `init()` method is called after its {@link module:core/plugin~PluginInterface.requires dependencies} are initialized,
|
130 | * so in the same order as the constructors of these plugins.
|
131 | *
|
132 | * **Note:** This method is optional. A plugin instance does not need to have it defined.
|
133 | */
|
134 | init?(): void | Promise<void>;
|
135 | /**
|
136 | * The third (and last) stage of the plugin initialization. See also {@link #constructor} and {@link #init}.
|
137 | *
|
138 | * **Note:** This method is optional. A plugin instance does not need to have it defined.
|
139 | */
|
140 | afterInit?(): Promise<void> | void;
|
141 | }
|
142 |
|
143 | // Beware that this defines a class constructor, not the class instance.
|
144 | export interface PluginInterface<T = Plugin> {
|
145 | new (editor: Editor): T;
|
146 | init?(): Promise<void> | void;
|
147 | afterInit?(): Promise<void> | void;
|
148 | destroy?(): Promise<void> | void;
|
149 | }
|
150 |
|
151 | export type LoadedPlugins = Array<typeof Plugin | typeof ContextPlugin>;
|