1 | import { Conversion, DataController, EditingController, Model } from '@ckeditor/ckeditor5-engine';
|
2 | import Config from '@ckeditor/ckeditor5-utils/src/config';
|
3 | import Locale from '@ckeditor/ckeditor5-utils/src/locale';
|
4 | import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
5 | import CommandCollection from '../commandcollection';
|
6 | import ContextPlugin from '../contextplugin';
|
7 | import EditingKeystrokeHandler from '../editingkeystrokehandler';
|
8 | import Plugin, { LoadedPlugins } from '../plugin';
|
9 | import PluginCollection from '../plugincollection';
|
10 | import { EditorConfig } from './editorconfig';
|
11 |
|
12 | // tslint:disable-next-line:no-empty-interface
|
13 | export default interface Editor extends Observable {}
|
14 |
|
15 | export default abstract class Editor implements Observable {
|
16 | /**
|
17 | * Creates a new instance of the editor class.
|
18 | *
|
19 | * Usually, not to be used directly. See the static {@link module:core/editor/editor~Editor.create `create()`} method.
|
20 | */
|
21 | constructor(config?: EditorConfig);
|
22 |
|
23 | /**
|
24 | * Stores all configurations specific to this editor instance.
|
25 | *
|
26 | * editor.config.get( 'image.toolbar' );
|
27 | * // -> [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ]
|
28 | */
|
29 | readonly config: Config;
|
30 |
|
31 | /**
|
32 | * The plugins loaded and in use by this editor instance.
|
33 | *
|
34 | * editor.plugins.get( 'ClipboardPipeline' ); // -> An instance of the clipboard pipeline plugin.
|
35 | */
|
36 | readonly plugins: PluginCollection;
|
37 |
|
38 | /**
|
39 | * The locale instance.
|
40 | */
|
41 | readonly locale: Locale;
|
42 |
|
43 | /**
|
44 | * Shorthand for {module:utils/locale~Locale#t}.
|
45 | */
|
46 | t: Locale['t'];
|
47 |
|
48 | /**
|
49 | * Commands registered to the editor.
|
50 | *
|
51 | * Use the shorthand {`editor.execute()`} method to execute commands:
#execute |
52 | *
|
53 | * // Execute the bold command:
|
54 | * editor.execute( 'bold' );
|
55 | *
|
56 | * // Check the state of the bold command:
|
57 | * editor.commands.get( 'bold' ).value;
|
58 | */
|
59 | readonly commands: CommandCollection;
|
60 |
|
61 | /**
|
62 | * Indicates the editor life-cycle state.
|
63 | *
|
64 | * The editor is in one of the following states:
|
65 | *
|
66 | * * `initializing` – During the editor initialization (before
|
67 | * {@link module:core/editor/editor~Editor.create `Editor.create()`}) finished its job.
|
68 | * * `ready` – After the promise returned by the {@link module:core/editor/editor~Editor.create `Editor.create()`}
|
69 | * method is resolved.
|
70 | * * `destroyed` – Once the {@link #destroy `editor.destroy()`} method was called.
|
71 | */
|
72 | get state(): 'initializing' | 'ready' | 'destroyed';
|
73 | protected set state(value: 'initializing' | 'ready' | 'destroyed');
|
74 |
|
75 | /**
|
76 | * Defines whether this editor is in read-only mode.
|
77 | *
|
78 | * In read-only mode the editor {@link #commands commands} are disabled so it is not possible
|
79 | * to modify the document by using them. Also, the editable element(s) become non-editable.
|
80 | *
|
81 | * In order to make the editor read-only, you can set this value directly:
|
82 | *
|
83 | * editor.isReadOnly = true;
|
84 | */
|
85 | get isReadOnly(): boolean;
|
86 | protected set isReadOnly(value: boolean);
|
87 |
|
88 | /**
|
89 | * The editor's model.
|
90 | *
|
91 | * The central point of the editor's abstract data model.
|
92 | */
|
93 | readonly model: Model;
|
94 |
|
95 | /**
|
96 | * The {@link module:engine/controller/datacontroller~DataController data controller}.
|
97 | * Used e.g. for setting and retrieving the editor data.
|
98 | */
|
99 | readonly data: DataController;
|
100 |
|
101 | /**
|
102 | * The {@link module:engine/controller/editingcontroller~EditingController editing controller}.
|
103 | * Controls user input and rendering the content for editing.
|
104 | */
|
105 | readonly editing: EditingController;
|
106 |
|
107 | /**
|
108 | * Conversion manager through which you can register model-to-view and view-to-model converters.
|
109 | *
|
110 | * See the {@link module:engine/conversion/conversion~Conversion} documentation to learn how to add converters.
|
111 | */
|
112 | readonly conversion: Conversion;
|
113 |
|
114 | /**
|
115 | * An instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
|
116 | *
|
117 | * It allows setting simple keystrokes:
|
118 | *
|
119 | * // Execute the bold command on Ctrl+E:
|
120 | * editor.keystrokes.set( 'Ctrl+E', 'bold' );
|
121 | *
|
122 | * // Execute your own callback:
|
123 | * editor.keystrokes.set( 'Ctrl+E', ( data, cancel ) => {
|
124 | * console.log( data.keyCode );
|
125 | *
|
126 | * // Prevent the default (native) action and stop the underlying keydown event
|
127 | * // so no other editor feature will interfere.
|
128 | * cancel();
|
129 | * } );
|
130 | *
|
131 | * Note: Certain typing-oriented keystrokes (like <kbd>Backspace</kbd> or <kbd>Enter</kbd>) are handled
|
132 | * by a low-level mechanism and trying to listen to them via the keystroke handler will not work reliably.
|
133 | * To handle these specific keystrokes, see the events fired by the
|
134 | * {@link module:engine/view/document~Document editing view document} (`editor.editing.view.document`).
|
135 | */
|
136 | readonly keystrokes: EditingKeystrokeHandler;
|
137 |
|
138 | /**
|
139 | * Loads and initializes plugins specified in the configuration.
|
140 | */
|
141 | initPlugins(): Promise<LoadedPlugins>;
|
142 |
|
143 | /**
|
144 | * Destroys the editor instance, releasing all resources used by it.
|
145 | *
|
146 | * **Note** The editor cannot be destroyed during the initialization phase so if it is called
|
147 | * while the editor {@link #state is being initialized}, it will wait for the editor initialization before destroying it.
|
148 | */
|
149 | destroy(): Promise<void>;
|
150 |
|
151 | /**
|
152 | * Executes the specified command with given parameters.
|
153 | *
|
154 | * Shorthand for:
|
155 | *
|
156 | * editor.commands.get( commandName ).execute( ... );
|
157 | */
|
158 | execute(commandName: string, ...args: unknown[]): any;
|
159 |
|
160 | /**
|
161 | * Focuses the editor.
|
162 | *
|
163 | * **Note** To explicitly focus the editing area of the editor, use the
|
164 | * {@link module:engine/view/view~View#focus `editor.editing.view.focus()`} method of the editing view.
|
165 | *
|
166 | * Check out the {@glink framework/guides/deep-dive/ui/focus-tracking#focus-in-the-editor-ui Focus in the editor UI} section
|
167 | * of the {@glink framework/guides/deep-dive/ui/focus-tracking Deep dive into focus tracking} guide to learn more.
|
168 | */
|
169 | focus(): void;
|
170 |
|
171 | static create(sourceElementOrData: HTMLElement | string, config?: EditorConfig): Promise<Editor>;
|
172 | static builtinPlugins: Array<typeof Plugin | typeof ContextPlugin | string>;
|
173 | static defaultConfig?: EditorConfig | undefined;
|
174 | }
|