-
Notifications
You must be signed in to change notification settings - Fork 146
/
EditorPlugin.ts
45 lines (40 loc) · 1.68 KB
/
EditorPlugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
import type IEditor from './IEditor';
import type { PluginEvent } from '../event/PluginEvent';
/**
* Interface of an editor plugin
*/
export default interface EditorPlugin {
/**
* Get a friendly name of this plugin
*/
getName: () => string;
/**
* The first method that editor will call to a plugin when editor is initializing.
* It will pass in the editor instance, plugin should take this chance to save the
* editor reference so that it can call to any editor method or format API later.
* @param editor The editor object
*/
initialize: (editor: IEditor) => void;
/**
* The last method that editor will call to a plugin before it is disposed.
* Plugin can take this chance to clear the reference to editor. After this method is
* called, plugin should not call to any editor method since it will result in error.
*/
dispose: () => void;
/**
* Check if the plugin should handle the given event exclusively.
* Handle an event exclusively means other plugin will not receive this event in
* onPluginEvent method.
* If two plugins will return true in willHandleEventExclusively() for the same event,
* the final result depends on the order of the plugins are added into editor
* @param event The event to check:
*/
willHandleEventExclusively?: (event: PluginEvent) => boolean;
/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
* exclusively by another plugin.
* @param event The event to handle:
*/
onPluginEvent?: (event: PluginEvent) => void;
}