@ckeditor/ckeditor5-core 35.2.1 → 35.3.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.
- package/package.json +27 -19
- package/src/command.js +209 -238
- package/src/commandcollection.js +84 -96
- package/src/context.js +219 -314
- package/src/contextplugin.js +29 -36
- package/src/editingkeystrokehandler.js +42 -49
- package/src/editor/editor.js +360 -440
- package/src/editor/editorconfig.js +5 -0
- package/src/editor/editorui.js +436 -544
- package/src/editor/utils/attachtoform.js +39 -49
- package/src/editor/utils/dataapimixin.js +17 -68
- package/src/editor/utils/elementapimixin.js +32 -67
- package/src/editor/utils/securesourceelement.js +22 -32
- package/src/index.js +34 -51
- package/src/multicommand.js +59 -73
- package/src/pendingactions.js +77 -103
- package/src/plugin.js +119 -276
- package/src/plugincollection.js +470 -584
- package/src/editor/editorconfig.jsdoc +0 -426
- package/src/editor/editorwithui.jsdoc +0 -29
package/src/editor/editor.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module core/editor/editor
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Context from '../context';
|
|
11
9
|
import Config from '@ckeditor/ckeditor5-utils/src/config';
|
|
12
10
|
import EditingController from '@ckeditor/ckeditor5-engine/src/controller/editingcontroller';
|
|
@@ -16,12 +14,9 @@ import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontro
|
|
|
16
14
|
import Conversion from '@ckeditor/ckeditor5-engine/src/conversion/conversion';
|
|
17
15
|
import Model from '@ckeditor/ckeditor5-engine/src/model/model';
|
|
18
16
|
import EditingKeystrokeHandler from '../editingkeystrokehandler';
|
|
19
|
-
|
|
20
|
-
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
21
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
17
|
+
import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
|
|
22
18
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
23
19
|
import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';
|
|
24
|
-
|
|
25
20
|
/**
|
|
26
21
|
* The class representing a basic, generic editor.
|
|
27
22
|
*
|
|
@@ -43,440 +38,367 @@ import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';
|
|
|
43
38
|
* @abstract
|
|
44
39
|
* @mixes module:utils/observablemixin~ObservableMixin
|
|
45
40
|
*/
|
|
46
|
-
export default class Editor {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.keystrokes = new EditingKeystrokeHandler( this );
|
|
222
|
-
this.keystrokes.listenTo( this.editing.view.document );
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Defines whether the editor is in the read-only mode.
|
|
227
|
-
*
|
|
228
|
-
* In read-only mode the editor {@link #commands commands} are disabled so it is not possible
|
|
229
|
-
* to modify the document by using them. Also, the editable element(s) become non-editable.
|
|
230
|
-
*
|
|
231
|
-
* In order to make the editor read-only, you need to call the {@link #enableReadOnlyMode} method:
|
|
232
|
-
*
|
|
233
|
-
* editor.enableReadOnlyMode( 'feature-id' );
|
|
234
|
-
*
|
|
41
|
+
export default class Editor extends Observable {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new instance of the editor class.
|
|
44
|
+
*
|
|
45
|
+
* Usually, not to be used directly. See the static {@link module:core/editor/editor~Editor.create `create()`} method.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} [config={}] The editor configuration.
|
|
48
|
+
*/
|
|
49
|
+
constructor(config = {}) {
|
|
50
|
+
super();
|
|
51
|
+
const constructor = this.constructor;
|
|
52
|
+
// Prefer the language passed as the argument to the constructor instead of the constructor's `defaultConfig`, if both are set.
|
|
53
|
+
const language = config.language || (constructor.defaultConfig && constructor.defaultConfig.language);
|
|
54
|
+
/**
|
|
55
|
+
* The editor context.
|
|
56
|
+
* When it is not provided through the configuration, the editor creates it.
|
|
57
|
+
*
|
|
58
|
+
* @protected
|
|
59
|
+
* @type {module:core/context~Context}
|
|
60
|
+
*/
|
|
61
|
+
this._context = config.context || new Context({ language });
|
|
62
|
+
this._context._addEditor(this, !config.context);
|
|
63
|
+
// Clone the plugins to make sure that the plugin array will not be shared
|
|
64
|
+
// between editors and make the watchdog feature work correctly.
|
|
65
|
+
const availablePlugins = Array.from(constructor.builtinPlugins || []);
|
|
66
|
+
/**
|
|
67
|
+
* Stores all configurations specific to this editor instance.
|
|
68
|
+
*
|
|
69
|
+
* editor.config.get( 'image.toolbar' );
|
|
70
|
+
* // -> [ 'imageStyle:block', 'imageStyle:side', '|', 'toggleImageCaption', 'imageTextAlternative' ]
|
|
71
|
+
*
|
|
72
|
+
* @readonly
|
|
73
|
+
* @member {module:utils/config~Config}
|
|
74
|
+
*/
|
|
75
|
+
this.config = new Config(config, constructor.defaultConfig);
|
|
76
|
+
this.config.define('plugins', availablePlugins);
|
|
77
|
+
this.config.define(this._context._getEditorConfig());
|
|
78
|
+
/**
|
|
79
|
+
* The plugins loaded and in use by this editor instance.
|
|
80
|
+
*
|
|
81
|
+
* editor.plugins.get( 'ClipboardPipeline' ); // -> An instance of the clipboard pipeline plugin.
|
|
82
|
+
*
|
|
83
|
+
* @readonly
|
|
84
|
+
* @member {module:core/plugincollection~PluginCollection}
|
|
85
|
+
*/
|
|
86
|
+
this.plugins = new PluginCollection(this, availablePlugins, this._context.plugins);
|
|
87
|
+
/**
|
|
88
|
+
* The locale instance.
|
|
89
|
+
*
|
|
90
|
+
* @readonly
|
|
91
|
+
* @type {module:utils/locale~Locale}
|
|
92
|
+
*/
|
|
93
|
+
this.locale = this._context.locale;
|
|
94
|
+
/**
|
|
95
|
+
* Shorthand for {@link module:utils/locale~Locale#t}.
|
|
96
|
+
*
|
|
97
|
+
* @see module:utils/locale~Locale#t
|
|
98
|
+
* @method #t
|
|
99
|
+
*/
|
|
100
|
+
this.t = this.locale.t;
|
|
101
|
+
/**
|
|
102
|
+
* A set of lock IDs for the {@link #isReadOnly} getter.
|
|
103
|
+
*
|
|
104
|
+
* @private
|
|
105
|
+
* @type {Set.<String|Symbol>}
|
|
106
|
+
*/
|
|
107
|
+
this._readOnlyLocks = new Set();
|
|
108
|
+
/**
|
|
109
|
+
* Commands registered to the editor.
|
|
110
|
+
*
|
|
111
|
+
* Use the shorthand {@link #execute `editor.execute()`} method to execute commands:
|
|
112
|
+
*
|
|
113
|
+
* // Execute the bold command:
|
|
114
|
+
* editor.execute( 'bold' );
|
|
115
|
+
*
|
|
116
|
+
* // Check the state of the bold command:
|
|
117
|
+
* editor.commands.get( 'bold' ).value;
|
|
118
|
+
*
|
|
119
|
+
* @readonly
|
|
120
|
+
* @member {module:core/commandcollection~CommandCollection}
|
|
121
|
+
*/
|
|
122
|
+
this.commands = new CommandCollection();
|
|
123
|
+
/**
|
|
124
|
+
* Indicates the editor life-cycle state.
|
|
125
|
+
*
|
|
126
|
+
* The editor is in one of the following states:
|
|
127
|
+
*
|
|
128
|
+
* * `initializing` – During the editor initialization (before
|
|
129
|
+
* {@link module:core/editor/editor~Editor.create `Editor.create()`}) finished its job.
|
|
130
|
+
* * `ready` – After the promise returned by the {@link module:core/editor/editor~Editor.create `Editor.create()`}
|
|
131
|
+
* method is resolved.
|
|
132
|
+
* * `destroyed` – Once the {@link #destroy `editor.destroy()`} method was called.
|
|
133
|
+
*
|
|
134
|
+
* @observable
|
|
135
|
+
* @member {'initializing'|'ready'|'destroyed'} #state
|
|
136
|
+
*/
|
|
137
|
+
this.set('state', 'initializing');
|
|
138
|
+
this.once('ready', () => (this.state = 'ready'), { priority: 'high' });
|
|
139
|
+
this.once('destroy', () => (this.state = 'destroyed'), { priority: 'high' });
|
|
140
|
+
/**
|
|
141
|
+
* The editor's model.
|
|
142
|
+
*
|
|
143
|
+
* The central point of the editor's abstract data model.
|
|
144
|
+
*
|
|
145
|
+
* @readonly
|
|
146
|
+
* @member {module:engine/model/model~Model}
|
|
147
|
+
*/
|
|
148
|
+
this.model = new Model();
|
|
149
|
+
const stylesProcessor = new StylesProcessor();
|
|
150
|
+
/**
|
|
151
|
+
* The {@link module:engine/controller/datacontroller~DataController data controller}.
|
|
152
|
+
* Used e.g. for setting and retrieving the editor data.
|
|
153
|
+
*
|
|
154
|
+
* @readonly
|
|
155
|
+
* @member {module:engine/controller/datacontroller~DataController}
|
|
156
|
+
*/
|
|
157
|
+
this.data = new DataController(this.model, stylesProcessor);
|
|
158
|
+
/**
|
|
159
|
+
* The {@link module:engine/controller/editingcontroller~EditingController editing controller}.
|
|
160
|
+
* Controls user input and rendering the content for editing.
|
|
161
|
+
*
|
|
162
|
+
* @readonly
|
|
163
|
+
* @member {module:engine/controller/editingcontroller~EditingController}
|
|
164
|
+
*/
|
|
165
|
+
this.editing = new EditingController(this.model, stylesProcessor);
|
|
166
|
+
this.editing.view.document.bind('isReadOnly').to(this);
|
|
167
|
+
/**
|
|
168
|
+
* Conversion manager through which you can register model-to-view and view-to-model converters.
|
|
169
|
+
*
|
|
170
|
+
* See the {@link module:engine/conversion/conversion~Conversion} documentation to learn how to add converters.
|
|
171
|
+
*
|
|
172
|
+
* @readonly
|
|
173
|
+
* @member {module:engine/conversion/conversion~Conversion}
|
|
174
|
+
*/
|
|
175
|
+
this.conversion = new Conversion([this.editing.downcastDispatcher, this.data.downcastDispatcher], this.data.upcastDispatcher);
|
|
176
|
+
this.conversion.addAlias('dataDowncast', this.data.downcastDispatcher);
|
|
177
|
+
this.conversion.addAlias('editingDowncast', this.editing.downcastDispatcher);
|
|
178
|
+
/**
|
|
179
|
+
* An instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}.
|
|
180
|
+
*
|
|
181
|
+
* It allows setting simple keystrokes:
|
|
182
|
+
*
|
|
183
|
+
* // Execute the bold command on Ctrl+E:
|
|
184
|
+
* editor.keystrokes.set( 'Ctrl+E', 'bold' );
|
|
185
|
+
*
|
|
186
|
+
* // Execute your own callback:
|
|
187
|
+
* editor.keystrokes.set( 'Ctrl+E', ( data, cancel ) => {
|
|
188
|
+
* console.log( data.keyCode );
|
|
189
|
+
*
|
|
190
|
+
* // Prevent the default (native) action and stop the underlying keydown event
|
|
191
|
+
* // so no other editor feature will interfere.
|
|
192
|
+
* cancel();
|
|
193
|
+
* } );
|
|
194
|
+
*
|
|
195
|
+
* Note: Certain typing-oriented keystrokes (like <kbd>Backspace</kbd> or <kbd>Enter</kbd>) are handled
|
|
196
|
+
* by a low-level mechanism and trying to listen to them via the keystroke handler will not work reliably.
|
|
197
|
+
* To handle these specific keystrokes, see the events fired by the
|
|
198
|
+
* {@link module:engine/view/document~Document editing view document} (`editor.editing.view.document`).
|
|
199
|
+
*
|
|
200
|
+
* @readonly
|
|
201
|
+
* @member {module:core/editingkeystrokehandler~EditingKeystrokeHandler}
|
|
202
|
+
*/
|
|
203
|
+
this.keystrokes = new EditingKeystrokeHandler(this);
|
|
204
|
+
this.keystrokes.listenTo(this.editing.view.document);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Defines whether the editor is in the read-only mode.
|
|
208
|
+
*
|
|
209
|
+
* In read-only mode the editor {@link #commands commands} are disabled so it is not possible
|
|
210
|
+
* to modify the document by using them. Also, the editable element(s) become non-editable.
|
|
211
|
+
*
|
|
212
|
+
* In order to make the editor read-only, you need to call the {@link #enableReadOnlyMode} method:
|
|
213
|
+
*
|
|
214
|
+
* editor.enableReadOnlyMode( 'feature-id' );
|
|
215
|
+
*
|
|
235
216
|
* Later, to turn off the read-only mode, call {@link #disableReadOnlyMode}:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Focuses the editor.
|
|
425
|
-
*
|
|
426
|
-
* **Note** To explicitly focus the editing area of the editor, use the
|
|
427
|
-
* {@link module:engine/view/view~View#focus `editor.editing.view.focus()`} method of the editing view.
|
|
428
|
-
*
|
|
429
|
-
* Check out the {@glink framework/guides/deep-dive/ui/focus-tracking#focus-in-the-editor-ui Focus in the editor UI} section
|
|
430
|
-
* of the {@glink framework/guides/deep-dive/ui/focus-tracking Deep dive into focus tracking} guide to learn more.
|
|
431
|
-
*/
|
|
432
|
-
focus() {
|
|
433
|
-
this.editing.view.focus();
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* Creates and initializes a new editor instance.
|
|
438
|
-
*
|
|
439
|
-
* This is an abstract method. Every editor type needs to implement its own initialization logic.
|
|
440
|
-
*
|
|
441
|
-
* See the `create()` methods of the existing editor types to learn how to use them:
|
|
442
|
-
*
|
|
443
|
-
* * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}
|
|
444
|
-
* * {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}
|
|
445
|
-
* * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
|
|
446
|
-
* * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}
|
|
447
|
-
*
|
|
448
|
-
* @abstract
|
|
449
|
-
* @method module:core/editor/editor~Editor.create
|
|
450
|
-
*/
|
|
217
|
+
*
|
|
218
|
+
* editor.disableReadOnlyMode( 'feature-id' );
|
|
219
|
+
*
|
|
220
|
+
* @readonly
|
|
221
|
+
* @observable
|
|
222
|
+
* @member {Boolean} #isReadOnly
|
|
223
|
+
*/
|
|
224
|
+
get isReadOnly() {
|
|
225
|
+
return this._readOnlyLocks.size > 0;
|
|
226
|
+
}
|
|
227
|
+
set isReadOnly(value) {
|
|
228
|
+
/**
|
|
229
|
+
* The {@link #isReadOnly Editor#isReadOnly} property is read-only since version `34.0.0` and can be set only using
|
|
230
|
+
* {@link #enableReadOnlyMode `Editor#enableReadOnlyMode( lockId )`} and
|
|
231
|
+
* {@link #disableReadOnlyMode `Editor#disableReadOnlyMode( lockId )`}.
|
|
232
|
+
*
|
|
233
|
+
* Usage before version `34.0.0`:
|
|
234
|
+
*
|
|
235
|
+
* editor.isReadOnly = true;
|
|
236
|
+
* editor.isReadOnly = false;
|
|
237
|
+
*
|
|
238
|
+
* Usage since version `34.0.0`:
|
|
239
|
+
*
|
|
240
|
+
* editor.enableReadOnlyMode( 'my-feature-id' );
|
|
241
|
+
* editor.disableReadOnlyMode( 'my-feature-id' );
|
|
242
|
+
*
|
|
243
|
+
* @error editor-isreadonly-has-no-setter
|
|
244
|
+
*/
|
|
245
|
+
throw new CKEditorError('editor-isreadonly-has-no-setter');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Turns on the read-only mode in the editor.
|
|
249
|
+
*
|
|
250
|
+
* Editor can be switched to or out of the read-only mode by many features, under various circumstances. The editor supports locking
|
|
251
|
+
* mechanism for the read-only mode. It enables easy control over the read-only mode when many features wants to turn it on or off at
|
|
252
|
+
* the same time, without conflicting with each other. It guarantees that you will not make the editor editable accidentally (which
|
|
253
|
+
* could lead to errors).
|
|
254
|
+
*
|
|
255
|
+
* Each read-only mode request is identified by a unique id (also called "lock"). If multiple plugins requested to turn on the
|
|
256
|
+
* read-only mode, then, the editor will become editable only after all these plugins turn the read-only mode off (using the same ids).
|
|
257
|
+
*
|
|
258
|
+
* Note, that you cannot force the editor to disable the read-only mode if other plugins set it.
|
|
259
|
+
*
|
|
260
|
+
* After the first `enableReadOnlyMode()` call, the {@link #isReadOnly `isReadOnly` property} will be set to `true`:
|
|
261
|
+
*
|
|
262
|
+
* editor.isReadOnly; // `false`.
|
|
263
|
+
* editor.enableReadOnlyMode( 'my-feature-id' );
|
|
264
|
+
* editor.isReadOnly; // `true`.
|
|
265
|
+
*
|
|
266
|
+
* You can turn off the read-only mode ("clear the lock") using the {@link #disableReadOnlyMode `disableReadOnlyMode()`} method:
|
|
267
|
+
*
|
|
268
|
+
* editor.enableReadOnlyMode( 'my-feature-id' );
|
|
269
|
+
* // ...
|
|
270
|
+
* editor.disableReadOnlyMode( 'my-feature-id' );
|
|
271
|
+
* editor.isReadOnly; // `false`.
|
|
272
|
+
*
|
|
273
|
+
* All "locks" need to be removed to enable editing:
|
|
274
|
+
*
|
|
275
|
+
* editor.enableReadOnlyMode( 'my-feature-id' );
|
|
276
|
+
* editor.enableReadOnlyMode( 'my-other-feature-id' );
|
|
277
|
+
* // ...
|
|
278
|
+
* editor.disableReadOnlyMode( 'my-feature-id' );
|
|
279
|
+
* editor.isReadOnly; // `true`.
|
|
280
|
+
* editor.disableReadOnlyMode( 'my-other-feature-id' );
|
|
281
|
+
* editor.isReadOnly; // `false`.
|
|
282
|
+
*
|
|
283
|
+
* @param {String|Symbol} lockId A unique ID for setting the editor to the read-only state.
|
|
284
|
+
*/
|
|
285
|
+
enableReadOnlyMode(lockId) {
|
|
286
|
+
if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
|
|
287
|
+
/**
|
|
288
|
+
* The lock ID is missing or it is not a string or symbol.
|
|
289
|
+
*
|
|
290
|
+
* @error editor-read-only-lock-id-invalid
|
|
291
|
+
*/
|
|
292
|
+
throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
|
|
293
|
+
}
|
|
294
|
+
if (this._readOnlyLocks.has(lockId)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
this._readOnlyLocks.add(lockId);
|
|
298
|
+
if (this._readOnlyLocks.size === 1) {
|
|
299
|
+
// Manually fire the `change:isReadOnly` event as only getter is provided.
|
|
300
|
+
this.fire('change:isReadOnly', 'isReadOnly', true, false);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Removes the read-only lock from the editor with given lock ID.
|
|
305
|
+
*
|
|
306
|
+
* When no lock is present on the editor anymore, then the {@link #isReadOnly `isReadOnly` property} will be set to `false`.
|
|
307
|
+
*
|
|
308
|
+
* @param {String|Symbol} lockId The lock ID for setting the editor to the read-only state.
|
|
309
|
+
*/
|
|
310
|
+
disableReadOnlyMode(lockId) {
|
|
311
|
+
if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
|
|
312
|
+
throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
|
|
313
|
+
}
|
|
314
|
+
if (!this._readOnlyLocks.has(lockId)) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this._readOnlyLocks.delete(lockId);
|
|
318
|
+
if (this._readOnlyLocks.size === 0) {
|
|
319
|
+
// Manually fire the `change:isReadOnly` event as only getter is provided.
|
|
320
|
+
this.fire('change:isReadOnly', 'isReadOnly', false, true);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Loads and initializes plugins specified in the configuration.
|
|
325
|
+
*
|
|
326
|
+
* @returns {Promise.<module:core/plugin~LoadedPlugins>} A promise which resolves
|
|
327
|
+
* once the initialization is completed, providing an array of loaded plugins.
|
|
328
|
+
*/
|
|
329
|
+
initPlugins() {
|
|
330
|
+
const config = this.config;
|
|
331
|
+
const plugins = config.get('plugins');
|
|
332
|
+
const removePlugins = config.get('removePlugins') || [];
|
|
333
|
+
const extraPlugins = config.get('extraPlugins') || [];
|
|
334
|
+
const substitutePlugins = config.get('substitutePlugins') || [];
|
|
335
|
+
return this.plugins.init(plugins.concat(extraPlugins), removePlugins, substitutePlugins);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Destroys the editor instance, releasing all resources used by it.
|
|
339
|
+
*
|
|
340
|
+
* **Note** The editor cannot be destroyed during the initialization phase so if it is called
|
|
341
|
+
* while the editor {@link #state is being initialized}, it will wait for the editor initialization before destroying it.
|
|
342
|
+
*
|
|
343
|
+
* @fires destroy
|
|
344
|
+
* @returns {Promise} A promise that resolves once the editor instance is fully destroyed.
|
|
345
|
+
*/
|
|
346
|
+
destroy() {
|
|
347
|
+
let readyPromise = Promise.resolve();
|
|
348
|
+
if (this.state == 'initializing') {
|
|
349
|
+
readyPromise = new Promise(resolve => this.once('ready', resolve));
|
|
350
|
+
}
|
|
351
|
+
return readyPromise
|
|
352
|
+
.then(() => {
|
|
353
|
+
this.fire('destroy');
|
|
354
|
+
this.stopListening();
|
|
355
|
+
this.commands.destroy();
|
|
356
|
+
})
|
|
357
|
+
.then(() => this.plugins.destroy())
|
|
358
|
+
.then(() => {
|
|
359
|
+
this.model.destroy();
|
|
360
|
+
this.data.destroy();
|
|
361
|
+
this.editing.destroy();
|
|
362
|
+
this.keystrokes.destroy();
|
|
363
|
+
})
|
|
364
|
+
// Remove the editor from the context.
|
|
365
|
+
// When the context was created by this editor, the context will be destroyed.
|
|
366
|
+
.then(() => this._context._removeEditor(this));
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Executes the specified command with given parameters.
|
|
370
|
+
*
|
|
371
|
+
* Shorthand for:
|
|
372
|
+
*
|
|
373
|
+
* editor.commands.get( commandName ).execute( ... );
|
|
374
|
+
*
|
|
375
|
+
* @param {String} commandName The name of the command to execute.
|
|
376
|
+
* @param {*} [...commandParams] Command parameters.
|
|
377
|
+
* @returns {*} The value returned by the {@link module:core/commandcollection~CommandCollection#execute `commands.execute()`}.
|
|
378
|
+
*/
|
|
379
|
+
execute(commandName, ...args) {
|
|
380
|
+
try {
|
|
381
|
+
return this.commands.execute(commandName, ...args);
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
// @if CK_DEBUG // throw err;
|
|
385
|
+
/* istanbul ignore next */
|
|
386
|
+
CKEditorError.rethrowUnexpectedError(err, this);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Focuses the editor.
|
|
391
|
+
*
|
|
392
|
+
* **Note** To explicitly focus the editing area of the editor, use the
|
|
393
|
+
* {@link module:engine/view/view~View#focus `editor.editing.view.focus()`} method of the editing view.
|
|
394
|
+
*
|
|
395
|
+
* Check out the {@glink framework/guides/deep-dive/ui/focus-tracking#focus-in-the-editor-ui Focus in the editor UI} section
|
|
396
|
+
* of the {@glink framework/guides/deep-dive/ui/focus-tracking Deep dive into focus tracking} guide to learn more.
|
|
397
|
+
*/
|
|
398
|
+
focus() {
|
|
399
|
+
this.editing.view.focus();
|
|
400
|
+
}
|
|
451
401
|
}
|
|
452
|
-
|
|
453
|
-
mix( Editor, ObservableMixin );
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Fired when the {@link module:engine/controller/datacontroller~DataController#event:ready data} and all additional
|
|
457
|
-
* editor components are ready.
|
|
458
|
-
*
|
|
459
|
-
* Note: This event is most useful for plugin developers. When integrating the editor with your website or
|
|
460
|
-
* application, you do not have to listen to `editor#ready` because when the promise returned by the static
|
|
461
|
-
* {@link module:core/editor/editor~Editor.create `Editor.create()`} event is resolved, the editor is already ready.
|
|
462
|
-
* In fact, since the first moment when the editor instance is available to you is inside `then()`'s callback,
|
|
463
|
-
* you cannot even add a listener to the `editor#ready` event.
|
|
464
|
-
*
|
|
465
|
-
* See also the {@link #state `editor.state`} property.
|
|
466
|
-
*
|
|
467
|
-
* @event ready
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Fired when this editor instance is destroyed. The editor at this point is not usable and this event should be used to
|
|
472
|
-
* perform the clean-up in any plugin.
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* See also the {@link #state `editor.state`} property.
|
|
476
|
-
*
|
|
477
|
-
* @event destroy
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
402
|
/**
|
|
481
403
|
* This error is thrown when trying to pass a `<textarea>` element to a `create()` function of an editor class.
|
|
482
404
|
*
|
|
@@ -491,7 +413,6 @@ mix( Editor, ObservableMixin );
|
|
|
491
413
|
*
|
|
492
414
|
* @error editor-wrong-element
|
|
493
415
|
*/
|
|
494
|
-
|
|
495
416
|
/**
|
|
496
417
|
* An array of plugins built into this editor class.
|
|
497
418
|
*
|
|
@@ -539,7 +460,6 @@ mix( Editor, ObservableMixin );
|
|
|
539
460
|
* @static
|
|
540
461
|
* @member {Array.<Function>} module:core/editor/editor~Editor.builtinPlugins
|
|
541
462
|
*/
|
|
542
|
-
|
|
543
463
|
/**
|
|
544
464
|
* The default configuration which is built into the editor class.
|
|
545
465
|
*
|