@ckeditor/ckeditor5-core 41.2.0 → 41.3.0-alpha.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/editor/utils/dataapimixin
7
+ */
8
+ import type Editor from '../editor.js';
9
+ import type { Constructor } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * Implementation of the {@link module:core/editor/utils/dataapimixin~DataApi}.
12
+ *
13
+ * @deprecated This functionality is already implemented by the `Editor` class.
14
+ */
15
+ export default function DataApiMixin<Base extends Constructor<Editor>>(base: Base): Base;
16
+ /**
17
+ * Interface defining editor methods for setting and getting data to and from the editor's main root element
18
+ * using the {@link module:core/editor/editor~Editor#data data pipeline}.
19
+ *
20
+ * This interface is not a part of the {@link module:core/editor/editor~Editor} class because one may want to implement
21
+ * an editor with multiple root elements, in which case the methods for setting and getting data will need to be implemented
22
+ * differently.
23
+ *
24
+ * @deprecated This interface is implemented by all `Editor` instances by default.
25
+ */
26
+ export interface DataApi {
27
+ /**
28
+ * Sets the data in the editor.
29
+ *
30
+ * ```ts
31
+ * editor.setData( '<p>This is editor!</p>' );
32
+ * ```
33
+ *
34
+ * If your editor implementation uses multiple roots, you should pass an object with keys corresponding
35
+ * to the editor root names and values equal to the data that should be set in each root:
36
+ *
37
+ * ```ts
38
+ * editor.setData( {
39
+ * header: '<p>Content for header part.</p>',
40
+ * content: '<p>Content for main part.</p>',
41
+ * footer: '<p>Content for footer part.</p>'
42
+ * } );
43
+ * ```
44
+ *
45
+ * By default the editor accepts HTML. This can be controlled by injecting a different data processor.
46
+ * See the {@glink features/markdown Markdown output} guide for more details.
47
+ *
48
+ * @param data Input data.
49
+ */
50
+ setData(data: string | Record<string, string>): void;
51
+ /**
52
+ * Gets the data from the editor.
53
+ *
54
+ * ```ts
55
+ * editor.getData(); // -> '<p>This is editor!</p>'
56
+ * ```
57
+ *
58
+ * If your editor implementation uses multiple roots, you should pass root name as one of the options:
59
+ *
60
+ * ```ts
61
+ * editor.getData( { rootName: 'header' } ); // -> '<p>Content for header part.</p>'
62
+ * ```
63
+ *
64
+ * By default, the editor outputs HTML. This can be controlled by injecting a different data processor.
65
+ * See the {@glink features/markdown Markdown output} guide for more details.
66
+ *
67
+ * A warning is logged when you try to retrieve data for a detached root, as most probably this is a mistake. A detached root should
68
+ * be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.
69
+ *
70
+ * @param options Additional configuration for the retrieved data.
71
+ * Editor features may introduce more configuration options that can be set through this parameter.
72
+ * @param options.rootName Root name. Default to `'main'`.
73
+ * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
74
+ * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
75
+ * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
76
+ * @returns Output data.
77
+ */
78
+ getData(options?: Record<string, unknown>): string;
79
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/editor/utils/elementapimixin
7
+ */
8
+ import { type Constructor, type Mixed } from '@ckeditor/ckeditor5-utils';
9
+ import type Editor from '../editor.js';
10
+ /**
11
+ * Implementation of the {@link module:core/editor/utils/elementapimixin~ElementApi}.
12
+ */
13
+ export default function ElementApiMixin<Base extends Constructor<Editor>>(base: Base): Mixed<Base, ElementApi>;
14
+ /**
15
+ * Interface describing an editor that replaced a DOM element (was "initialized on an element").
16
+ *
17
+ * Such an editor should provide a method to
18
+ * {@link module:core/editor/utils/elementapimixin~ElementApi#updateSourceElement update the replaced element with the current data}.
19
+ */
20
+ export interface ElementApi {
21
+ /**
22
+ * The element on which the editor has been initialized.
23
+ *
24
+ * @readonly
25
+ */
26
+ sourceElement: HTMLElement | undefined;
27
+ /**
28
+ * Updates the {@link #sourceElement editor source element}'s content with the data if the
29
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
30
+ * configuration option is set to `true`.
31
+ *
32
+ * @param data Data that the {@link #sourceElement editor source element} should be updated with.
33
+ */
34
+ updateSourceElement(data?: string): void;
35
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type { default as Editor } from '../editor.js';
6
+ /**
7
+ * Marks the source element on which the editor was initialized. This prevents other editor instances from using this element.
8
+ *
9
+ * Running multiple editor instances on the same source element causes various issues and it is
10
+ * crucial this helper is called as soon as the source element is known to prevent collisions.
11
+ *
12
+ * @param editor Editor instance.
13
+ * @param sourceElement Element to bind with the editor instance.
14
+ */
15
+ export default function secureSourceElement(editor: Editor, sourceElement: HTMLElement & {
16
+ ckeditorInstance?: Editor;
17
+ }): void;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
7
+ */
8
+ export { default as Plugin, type PluginDependencies, type PluginConstructor } from './plugin.js';
9
+ export { default as Command, type CommandExecuteEvent } from './command.js';
10
+ export { default as MultiCommand } from './multicommand.js';
11
+ export type { CommandsMap } from './commandcollection.js';
12
+ export type { PluginsMap, default as PluginCollection } from './plugincollection.js';
13
+ export { default as Context, type ContextConfig } from './context.js';
14
+ export { default as ContextPlugin, type ContextPluginDependencies } from './contextplugin.js';
15
+ export { type EditingKeystrokeCallback } from './editingkeystrokehandler.js';
16
+ export type { PartialBy } from './typings.js';
17
+ export { default as Editor, type EditorReadyEvent, type EditorDestroyEvent } from './editor/editor.js';
18
+ export type { EditorConfig, LanguageConfig, ToolbarConfig, ToolbarConfigItem, UiConfig } from './editor/editorconfig.js';
19
+ export { default as attachToForm } from './editor/utils/attachtoform.js';
20
+ export { default as DataApiMixin, type DataApi } from './editor/utils/dataapimixin.js';
21
+ export { default as ElementApiMixin, type ElementApi } from './editor/utils/elementapimixin.js';
22
+ export { default as secureSourceElement } from './editor/utils/securesourceelement.js';
23
+ export { default as PendingActions, type PendingAction } from './pendingactions.js';
24
+ export type { KeystrokeInfos as KeystrokeInfoDefinitions, KeystrokeInfoGroup as KeystrokeInfoGroupDefinition, KeystrokeInfoCategory as KeystrokeInfoCategoryDefinition, KeystrokeInfoDefinition as KeystrokeInfoDefinition } from './accessibility.js';
25
+ export declare const icons: {
26
+ bold: string;
27
+ cancel: string;
28
+ caption: string;
29
+ check: string;
30
+ cog: string;
31
+ colorPalette: string;
32
+ eraser: string;
33
+ history: string;
34
+ image: string;
35
+ imageUpload: string;
36
+ imageAssetManager: string;
37
+ imageUrl: string;
38
+ lowVision: string;
39
+ textAlternative: string;
40
+ loupe: string;
41
+ previousArrow: string;
42
+ nextArrow: string;
43
+ importExport: string;
44
+ paragraph: string;
45
+ plus: string;
46
+ text: string;
47
+ alignBottom: string;
48
+ alignMiddle: string;
49
+ alignTop: string;
50
+ alignLeft: string;
51
+ alignCenter: string;
52
+ alignRight: string;
53
+ alignJustify: string;
54
+ objectLeft: string;
55
+ objectCenter: string;
56
+ objectRight: string;
57
+ objectFullWidth: string;
58
+ objectInline: string;
59
+ objectBlockLeft: string;
60
+ objectBlockRight: string;
61
+ objectSizeFull: string;
62
+ objectSizeLarge: string;
63
+ objectSizeSmall: string;
64
+ objectSizeMedium: string;
65
+ pencil: string;
66
+ pilcrow: string;
67
+ quote: string;
68
+ threeVerticalDots: string;
69
+ dragIndicator: string;
70
+ redo: string;
71
+ undo: string;
72
+ bulletedList: string;
73
+ numberedList: string;
74
+ todoList: string;
75
+ codeBlock: string;
76
+ browseFiles: string;
77
+ heading1: string;
78
+ heading2: string;
79
+ heading3: string;
80
+ heading4: string;
81
+ heading5: string;
82
+ heading6: string;
83
+ horizontalLine: string;
84
+ html: string;
85
+ indent: string;
86
+ outdent: string;
87
+ table: string;
88
+ };
89
+ import './augmentation.js';
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/multicommand
7
+ */
8
+ import Command from './command.js';
9
+ import { type PriorityString } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * A CKEditor command that aggregates other commands.
12
+ *
13
+ * This command is used to proxy multiple commands. The multi-command is enabled when
14
+ * at least one of its registered child commands is enabled.
15
+ * When executing a multi-command, the first enabled command with highest priority will be executed.
16
+ *
17
+ * ```ts
18
+ * const multiCommand = new MultiCommand( editor );
19
+ *
20
+ * const commandFoo = new Command( editor );
21
+ * const commandBar = new Command( editor );
22
+ *
23
+ * // Register a child command.
24
+ * multiCommand.registerChildCommand( commandFoo );
25
+ * // Register a child command with a low priority.
26
+ * multiCommand.registerChildCommand( commandBar, { priority: 'low' } );
27
+ *
28
+ * // Enable one of the commands.
29
+ * commandBar.isEnabled = true;
30
+ *
31
+ * multiCommand.execute(); // Will execute commandBar.
32
+ * ```
33
+ */
34
+ export default class MultiCommand extends Command {
35
+ /**
36
+ * Registered child commands definitions.
37
+ */
38
+ private _childCommandsDefinitions;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ refresh(): void;
43
+ /**
44
+ * Executes the first enabled command which has the highest priority of all registered child commands.
45
+ *
46
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
47
+ */
48
+ execute(...args: Array<unknown>): unknown;
49
+ /**
50
+ * Registers a child command.
51
+ *
52
+ * @param options An object with configuration options.
53
+ * @param options.priority Priority of a command to register.
54
+ */
55
+ registerChildCommand(command: Command, options?: {
56
+ priority?: PriorityString;
57
+ }): void;
58
+ /**
59
+ * Checks if any of child commands is enabled.
60
+ */
61
+ private _checkEnabled;
62
+ /**
63
+ * Returns a first enabled command with the highest priority or `undefined` if none of them is enabled.
64
+ */
65
+ private _getFirstEnabledCommand;
66
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/pendingactions
7
+ */
8
+ import ContextPlugin from './contextplugin.js';
9
+ import { type CollectionAddEvent, type CollectionRemoveEvent, type Observable } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * The list of pending editor actions.
12
+ *
13
+ * This plugin should be used to synchronise plugins that execute long-lasting actions
14
+ * (e.g. file upload) with the editor integration. It gives the developer who integrates the editor
15
+ * an easy way to check if there are any actions pending whenever such information is needed.
16
+ * All plugins that register a pending action also provide a message about the action that is ongoing
17
+ * which can be displayed to the user. This lets them decide if they want to interrupt the action or wait.
18
+ *
19
+ * Adding and updating a pending action:
20
+ *
21
+ * ```ts
22
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
23
+ * const action = pendingActions.add( 'Upload in progress: 0%.' );
24
+ *
25
+ * // You can update the message:
26
+ * action.message = 'Upload in progress: 10%.';
27
+ * ```
28
+ *
29
+ * Removing a pending action:
30
+ *
31
+ * ```ts
32
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
33
+ * const action = pendingActions.add( 'Unsaved changes.' );
34
+ *
35
+ * pendingActions.remove( action );
36
+ * ```
37
+ *
38
+ * Getting pending actions:
39
+ *
40
+ * ```ts
41
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
42
+ *
43
+ * const action1 = pendingActions.add( 'Action 1' );
44
+ * const action2 = pendingActions.add( 'Action 2' );
45
+ *
46
+ * pendingActions.first; // Returns action1
47
+ * Array.from( pendingActions ); // Returns [ action1, action2 ]
48
+ * ```
49
+ *
50
+ * This plugin is used by features like {@link module:upload/filerepository~FileRepository} to register their ongoing actions
51
+ * and by features like {@link module:autosave/autosave~Autosave} to detect whether there are any ongoing actions.
52
+ * Read more about saving the data in the {@glink installation/getting-started/getting-and-setting-data Saving and getting data} guide.
53
+ */
54
+ export default class PendingActions extends ContextPlugin implements Iterable<PendingAction> {
55
+ /**
56
+ * Defines whether there is any registered pending action.
57
+ *
58
+ * @readonly
59
+ * @observable
60
+ */
61
+ hasAny: boolean;
62
+ /**
63
+ * A list of pending actions.
64
+ */
65
+ private _actions;
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ static get pluginName(): "PendingActions";
70
+ /**
71
+ * @inheritDoc
72
+ */
73
+ init(): void;
74
+ /**
75
+ * Adds an action to the list of pending actions.
76
+ *
77
+ * This method returns an action object with an observable message property.
78
+ * The action object can be later used in the {@link #remove} method. It also allows you to change the message.
79
+ *
80
+ * @param message The action message.
81
+ * @returns An observable object that represents a pending action.
82
+ */
83
+ add(message: string): PendingAction;
84
+ /**
85
+ * Removes an action from the list of pending actions.
86
+ *
87
+ * @param action An action object.
88
+ */
89
+ remove(action: PendingAction): void;
90
+ /**
91
+ * Returns the first action from the list or null if the list is empty
92
+ *
93
+ * @returns The pending action object.
94
+ */
95
+ get first(): PendingAction | null;
96
+ /**
97
+ * Iterable interface.
98
+ */
99
+ [Symbol.iterator](): Iterator<PendingAction>;
100
+ }
101
+ export interface PendingAction extends Observable {
102
+ message: string;
103
+ }
104
+ /**
105
+ * Fired when an action is added to the list.
106
+ *
107
+ * @eventName ~PendingActions#add
108
+ * @param action The added action.
109
+ */
110
+ export type PendingActionsAddEvent = CollectionAddEvent<PendingAction>;
111
+ /**
112
+ * Fired when an action is removed from the list.
113
+ *
114
+ * @eventName ~PendingActions#remove
115
+ * @param action The removed action.
116
+ */
117
+ export type PendingActionsRemoveEvent = CollectionRemoveEvent<PendingAction>;
@@ -0,0 +1,274 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type Editor from './editor/editor.js';
6
+ declare const Plugin_base: {
7
+ new (): import("@ckeditor/ckeditor5-utils").Observable;
8
+ prototype: import("@ckeditor/ckeditor5-utils").Observable;
9
+ };
10
+ /**
11
+ * The base class for CKEditor plugin classes.
12
+ */
13
+ export default class Plugin extends Plugin_base implements PluginInterface {
14
+ /**
15
+ * The editor instance.
16
+ *
17
+ * Note that most editors implement the {@link module:core/editor/editor~Editor#ui} property.
18
+ * However, editors with an external UI (i.e. Bootstrap-based) or a headless editor may not have this property or
19
+ * throw an error when accessing it.
20
+ *
21
+ * Because of above, to make plugins more universal, it is recommended to split features into:
22
+ * - The "editing" part that uses the {@link module:core/editor/editor~Editor} class without `ui` property.
23
+ * - The "UI" part that uses the {@link module:core/editor/editor~Editor} class and accesses `ui` property.
24
+ */
25
+ readonly editor: Editor;
26
+ /**
27
+ * Flag indicating whether a plugin is enabled or disabled.
28
+ * A disabled plugin will not transform text.
29
+ *
30
+ * Plugin can be simply disabled like that:
31
+ *
32
+ * ```ts
33
+ * // Disable the plugin so that no toolbars are visible.
34
+ * editor.plugins.get( 'TextTransformation' ).isEnabled = false;
35
+ * ```
36
+ *
37
+ * You can also use {@link #forceDisabled} method.
38
+ *
39
+ * @observable
40
+ * @readonly
41
+ */
42
+ isEnabled: boolean;
43
+ /**
44
+ * Holds identifiers for {@link #forceDisabled} mechanism.
45
+ */
46
+ private _disableStack;
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ constructor(editor: Editor);
51
+ /**
52
+ * Disables the plugin.
53
+ *
54
+ * Plugin may be disabled by multiple features or algorithms (at once). When disabling a plugin, unique id should be passed
55
+ * (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the plugin.
56
+ * The plugin becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
57
+ *
58
+ * Disabling and enabling a plugin:
59
+ *
60
+ * ```ts
61
+ * plugin.isEnabled; // -> true
62
+ * plugin.forceDisabled( 'MyFeature' );
63
+ * plugin.isEnabled; // -> false
64
+ * plugin.clearForceDisabled( 'MyFeature' );
65
+ * plugin.isEnabled; // -> true
66
+ * ```
67
+ *
68
+ * Plugin disabled by multiple features:
69
+ *
70
+ * ```ts
71
+ * plugin.forceDisabled( 'MyFeature' );
72
+ * plugin.forceDisabled( 'OtherFeature' );
73
+ * plugin.clearForceDisabled( 'MyFeature' );
74
+ * plugin.isEnabled; // -> false
75
+ * plugin.clearForceDisabled( 'OtherFeature' );
76
+ * plugin.isEnabled; // -> true
77
+ * ```
78
+ *
79
+ * Multiple disabling with the same identifier is redundant:
80
+ *
81
+ * ```ts
82
+ * plugin.forceDisabled( 'MyFeature' );
83
+ * plugin.forceDisabled( 'MyFeature' );
84
+ * plugin.clearForceDisabled( 'MyFeature' );
85
+ * plugin.isEnabled; // -> true
86
+ * ```
87
+ *
88
+ * **Note:** some plugins or algorithms may have more complex logic when it comes to enabling or disabling certain plugins,
89
+ * so the plugin might be still disabled after {@link #clearForceDisabled} was used.
90
+ *
91
+ * @param id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the plugin.
92
+ */
93
+ forceDisabled(id: string): void;
94
+ /**
95
+ * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
96
+ *
97
+ * @param id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
98
+ */
99
+ clearForceDisabled(id: string): void;
100
+ /**
101
+ * @inheritDoc
102
+ */
103
+ destroy(): void;
104
+ /**
105
+ * @inheritDoc
106
+ */
107
+ static get isContextPlugin(): false;
108
+ }
109
+ /**
110
+ * The base interface for CKEditor plugins.
111
+ *
112
+ * In its minimal form a plugin can be a simple function that accepts {@link module:core/editor/editor~Editor the editor}
113
+ * as a parameter:
114
+ *
115
+ * ```ts
116
+ * // A simple plugin that enables a data processor.
117
+ * function MyPlugin( editor ) {
118
+ * editor.data.processor = new MyDataProcessor();
119
+ * }
120
+ * ```
121
+ *
122
+ * In most cases however, you will want to inherit from the {@link ~Plugin} class which implements the
123
+ * {@link module:utils/observablemixin~Observable} and is, therefore, more convenient:
124
+ *
125
+ * ```ts
126
+ * class MyPlugin extends Plugin {
127
+ * init() {
128
+ * // `listenTo()` and `editor` are available thanks to `Plugin`.
129
+ * // By using `listenTo()` you will ensure that the listener is removed when
130
+ * // the plugin is destroyed.
131
+ * this.listenTo( this.editor.data, 'ready', () => {
132
+ * // Do something when the data is ready.
133
+ * } );
134
+ * }
135
+ * }
136
+ * ```
137
+ *
138
+ * The plugin class can have `pluginName` and `requires` static members. See {@link ~PluginStaticMembers} for more details.
139
+ *
140
+ * The plugin can also implement methods (e.g. {@link ~PluginInterface#init `init()`} or
141
+ * {@link ~PluginInterface#destroy `destroy()`}) which, when present, will be used to properly
142
+ * initialize and destroy the plugin.
143
+ *
144
+ * **Note:** When defined as a plain function, the plugin acts as a constructor and will be
145
+ * called in parallel with other plugins' {@link ~PluginConstructor constructors}.
146
+ * This means the code of that plugin will be executed **before** {@link ~PluginInterface#init `init()`} and
147
+ * {@link ~PluginInterface#afterInit `afterInit()`} methods of other plugins and, for instance,
148
+ * you cannot use it to extend other plugins' {@glink framework/architecture/editing-engine#schema schema}
149
+ * rules as they are defined later on during the `init()` stage.
150
+ */
151
+ export interface PluginInterface {
152
+ /**
153
+ * The second stage (after plugin constructor) of the plugin initialization.
154
+ * Unlike the plugin constructor this method can be asynchronous.
155
+ *
156
+ * A plugin's `init()` method is called after its {@link ~PluginStaticMembers#requires dependencies} are initialized,
157
+ * so in the same order as the constructors of these plugins.
158
+ *
159
+ * **Note:** This method is optional. A plugin instance does not need to have it defined.
160
+ */
161
+ init?(): Promise<unknown> | null | undefined | void;
162
+ /**
163
+ * The third (and last) stage of the plugin initialization. See also {@link ~PluginConstructor} and {@link ~PluginInterface#init}.
164
+ *
165
+ * **Note:** This method is optional. A plugin instance does not need to have it defined.
166
+ */
167
+ afterInit?(): Promise<unknown> | null | undefined | void;
168
+ /**
169
+ * Destroys the plugin.
170
+ *
171
+ * **Note:** This method is optional. A plugin instance does not need to have it defined.
172
+ */
173
+ destroy?(): Promise<unknown> | null | undefined | void;
174
+ }
175
+ /**
176
+ * Creates a new plugin instance. This is the first step of the plugin initialization.
177
+ * See also {@link ~PluginInterface#init} and {@link ~PluginInterface#afterInit}.
178
+ *
179
+ * The plugin static properties should conform to {@link ~PluginStaticMembers `PluginStaticMembers` interface}.
180
+ *
181
+ * A plugin is always instantiated after its {@link ~PluginStaticMembers#requires dependencies} and the
182
+ * {@link ~PluginInterface#init} and {@link ~PluginInterface#afterInit} methods are called in the same order.
183
+ *
184
+ * Usually, you will want to put your plugin's initialization code in the {@link ~PluginInterface#init} method.
185
+ * The constructor can be understood as "before init" and used in special cases, just like
186
+ * {@link ~PluginInterface#afterInit} serves the special "after init" scenarios (e.g.the code which depends on other
187
+ * plugins, but which does not {@link ~PluginStaticMembers#requires explicitly require} them).
188
+ */
189
+ export type PluginConstructor<TContext = Editor> = (PluginClassConstructor<TContext> | PluginFunctionConstructor<TContext>) & PluginStaticMembers<TContext>;
190
+ /**
191
+ * In most cases, you will want to inherit from the {@link ~Plugin} class which implements the
192
+ * {@link module:utils/observablemixin~Observable} and is, therefore, more convenient:
193
+ *
194
+ * ```ts
195
+ * class MyPlugin extends Plugin {
196
+ * init() {
197
+ * // `listenTo()` and `editor` are available thanks to `Plugin`.
198
+ * // By using `listenTo()` you will ensure that the listener is removed when
199
+ * // the plugin is destroyed.
200
+ * this.listenTo( this.editor.data, 'ready', () => {
201
+ * // Do something when the data is ready.
202
+ * } );
203
+ * }
204
+ * }
205
+ * ```
206
+ */
207
+ export type PluginClassConstructor<TContext = Editor> = new (editor: TContext) => PluginInterface;
208
+ /**
209
+ * In its minimal form a plugin can be a simple function that accepts {@link module:core/editor/editor~Editor the editor}
210
+ * as a parameter:
211
+ *
212
+ * ```ts
213
+ * // A simple plugin that enables a data processor.
214
+ * function MyPlugin( editor ) {
215
+ * editor.data.processor = new MyDataProcessor();
216
+ * }
217
+ * ```
218
+ */
219
+ export type PluginFunctionConstructor<TContext = Editor> = (editor: TContext) => void;
220
+ /**
221
+ * Static properties of a plugin.
222
+ */
223
+ export interface PluginStaticMembers<TContext = Editor> {
224
+ /**
225
+ * An array of plugins required by this plugin.
226
+ *
227
+ * To keep the plugin class definition tight it is recommended to define this property as a static getter:
228
+ *
229
+ * ```ts
230
+ * import Image from './image.js';
231
+ *
232
+ * export default class ImageCaption {
233
+ * static get requires() {
234
+ * return [ Image ];
235
+ * }
236
+ * }
237
+ * ```
238
+ */
239
+ readonly requires?: PluginDependencies<TContext>;
240
+ /**
241
+ * An optional name of the plugin. If set, the plugin will be available in
242
+ * {@link module:core/plugincollection~PluginCollection#get} by its
243
+ * name and its constructor. If not, then only by its constructor.
244
+ *
245
+ * The name should reflect the constructor name.
246
+ *
247
+ * To keep the plugin class definition tight, it is recommended to define this property as a static getter:
248
+ *
249
+ * ```ts
250
+ * export default class ImageCaption {
251
+ * static get pluginName() {
252
+ * return 'ImageCaption';
253
+ * }
254
+ * }
255
+ * ```
256
+ *
257
+ * Note: The native `Function.name` property could not be used to keep the plugin name because
258
+ * it will be mangled during code minification.
259
+ *
260
+ * Naming a plugin is necessary to enable removing it through the
261
+ * {@link module:core/editor/editorconfig~EditorConfig#removePlugins `config.removePlugins`} option.
262
+ */
263
+ readonly pluginName?: string;
264
+ /**
265
+ * A flag which defines if a plugin is allowed or not allowed to be used directly by a {@link module:core/context~Context}.
266
+ */
267
+ readonly isContextPlugin?: boolean;
268
+ }
269
+ export type PluginDependencies<TContext = Editor> = ReadonlyArray<PluginConstructor<TContext> | string>;
270
+ /**
271
+ * An array of loaded plugins.
272
+ */
273
+ export type LoadedPlugins = Array<PluginInterface>;
274
+ export {};