@ckeditor/ckeditor5-core 40.0.0 → 40.2.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +28 -28
  2. package/LICENSE.md +3 -3
  3. package/README.md +1 -1
  4. package/lang/contexts.json +5 -1
  5. package/lang/translations/af.po +16 -0
  6. package/lang/translations/ar.po +16 -0
  7. package/lang/translations/ast.po +16 -0
  8. package/lang/translations/az.po +16 -0
  9. package/lang/translations/bg.po +16 -0
  10. package/lang/translations/bn.po +16 -0
  11. package/lang/translations/bs.po +16 -0
  12. package/lang/translations/ca.po +16 -0
  13. package/lang/translations/cs.po +16 -0
  14. package/lang/translations/da.po +16 -0
  15. package/lang/translations/de-ch.po +16 -0
  16. package/lang/translations/de.po +16 -0
  17. package/lang/translations/el.po +16 -0
  18. package/lang/translations/en-au.po +16 -0
  19. package/lang/translations/en-gb.po +16 -0
  20. package/lang/translations/en.po +16 -0
  21. package/lang/translations/eo.po +16 -0
  22. package/lang/translations/es-co.po +16 -0
  23. package/lang/translations/es.po +16 -0
  24. package/lang/translations/et.po +16 -0
  25. package/lang/translations/eu.po +16 -0
  26. package/lang/translations/fa.po +16 -0
  27. package/lang/translations/fi.po +16 -0
  28. package/lang/translations/fr.po +16 -0
  29. package/lang/translations/gl.po +16 -0
  30. package/lang/translations/gu.po +16 -0
  31. package/lang/translations/he.po +16 -0
  32. package/lang/translations/hi.po +16 -0
  33. package/lang/translations/hr.po +16 -0
  34. package/lang/translations/hu.po +16 -0
  35. package/lang/translations/hy.po +16 -0
  36. package/lang/translations/id.po +16 -0
  37. package/lang/translations/it.po +16 -0
  38. package/lang/translations/ja.po +16 -0
  39. package/lang/translations/jv.po +16 -0
  40. package/lang/translations/km.po +16 -0
  41. package/lang/translations/kn.po +16 -0
  42. package/lang/translations/ko.po +16 -0
  43. package/lang/translations/ku.po +16 -0
  44. package/lang/translations/lt.po +16 -0
  45. package/lang/translations/lv.po +16 -0
  46. package/lang/translations/ms.po +16 -0
  47. package/lang/translations/nb.po +16 -0
  48. package/lang/translations/ne.po +16 -0
  49. package/lang/translations/nl.po +16 -0
  50. package/lang/translations/no.po +16 -0
  51. package/lang/translations/oc.po +16 -0
  52. package/lang/translations/pl.po +16 -0
  53. package/lang/translations/pt-br.po +16 -0
  54. package/lang/translations/pt.po +16 -0
  55. package/lang/translations/ro.po +16 -0
  56. package/lang/translations/ru.po +16 -0
  57. package/lang/translations/si.po +16 -0
  58. package/lang/translations/sk.po +16 -0
  59. package/lang/translations/sl.po +16 -0
  60. package/lang/translations/sq.po +16 -0
  61. package/lang/translations/sr-latn.po +17 -1
  62. package/lang/translations/sr.po +16 -0
  63. package/lang/translations/sv.po +16 -0
  64. package/lang/translations/th.po +16 -0
  65. package/lang/translations/tk.po +16 -0
  66. package/lang/translations/tr.po +16 -0
  67. package/lang/translations/tt.po +16 -0
  68. package/lang/translations/ug.po +17 -1
  69. package/lang/translations/uk.po +16 -0
  70. package/lang/translations/ur.po +16 -0
  71. package/lang/translations/uz.po +16 -0
  72. package/lang/translations/vi.po +16 -0
  73. package/lang/translations/zh-cn.po +16 -0
  74. package/lang/translations/zh.po +16 -0
  75. package/package.json +3 -3
  76. package/src/augmentation.d.ts +10 -10
  77. package/src/augmentation.js +5 -5
  78. package/src/command.d.ts +189 -189
  79. package/src/command.js +185 -185
  80. package/src/commandcollection.d.ts +83 -83
  81. package/src/commandcollection.js +83 -83
  82. package/src/context.d.ts +237 -237
  83. package/src/context.js +225 -225
  84. package/src/contextplugin.d.ts +61 -61
  85. package/src/contextplugin.js +43 -43
  86. package/src/editingkeystrokehandler.d.ts +56 -56
  87. package/src/editingkeystrokehandler.js +57 -57
  88. package/src/editor/editor.d.ts +417 -417
  89. package/src/editor/editor.js +316 -316
  90. package/src/editor/editorconfig.d.ts +661 -660
  91. package/src/editor/editorconfig.js +5 -5
  92. package/src/editor/utils/attachtoform.d.ts +15 -15
  93. package/src/editor/utils/attachtoform.js +57 -57
  94. package/src/editor/utils/dataapimixin.d.ts +75 -75
  95. package/src/editor/utils/dataapimixin.js +24 -24
  96. package/src/editor/utils/elementapimixin.d.ts +35 -31
  97. package/src/editor/utils/elementapimixin.js +43 -42
  98. package/src/editor/utils/securesourceelement.d.ts +17 -17
  99. package/src/editor/utils/securesourceelement.js +35 -35
  100. package/src/index.d.ts +66 -62
  101. package/src/index.js +103 -95
  102. package/src/multicommand.d.ts +66 -66
  103. package/src/multicommand.js +82 -82
  104. package/src/pendingactions.d.ts +117 -117
  105. package/src/pendingactions.js +116 -116
  106. package/src/plugin.d.ts +274 -274
  107. package/src/plugin.js +106 -106
  108. package/src/plugincollection.d.ts +117 -117
  109. package/src/plugincollection.js +473 -473
  110. package/theme/icons/image-asset-manager.svg +1 -0
  111. package/theme/icons/image-upload.svg +1 -0
  112. package/theme/icons/image-url.svg +1 -0
  113. package/theme/icons/image.svg +1 -1
  114. package/theme/icons/low-vision.svg +1 -1
  115. package/theme/icons/text-alternative.svg +1 -0
@@ -1,316 +1,316 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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/editor
7
- */
8
- import { Config, CKEditorError, ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
- import { Conversion, DataController, EditingController, Model, StylesProcessor } from '@ckeditor/ckeditor5-engine';
10
- import Context from '../context';
11
- import PluginCollection from '../plugincollection';
12
- import CommandCollection from '../commandcollection';
13
- import EditingKeystrokeHandler from '../editingkeystrokehandler';
14
- /**
15
- * The class representing a basic, generic editor.
16
- *
17
- * Check out the list of its subclasses to learn about specific editor implementations.
18
- *
19
- * All editor implementations (like {@link module:editor-classic/classiceditor~ClassicEditor} or
20
- * {@link module:editor-inline/inlineeditor~InlineEditor}) should extend this class. They can add their
21
- * own methods and properties.
22
- *
23
- * When you are implementing a plugin, this editor represents the API
24
- * which your plugin can expect to get when using its {@link module:core/plugin~Plugin#editor} property.
25
- *
26
- * This API should be sufficient in order to implement the "editing" part of your feature
27
- * (schema definition, conversion, commands, keystrokes, etc.).
28
- * It does not define the editor UI, which is available only if
29
- * the specific editor implements also the {@link ~Editor#ui} property
30
- * (as most editor implementations do).
31
- */
32
- export default class Editor extends ObservableMixin() {
33
- /**
34
- * Creates a new instance of the editor class.
35
- *
36
- * Usually, not to be used directly. See the static {@link module:core/editor/editor~Editor.create `create()`} method.
37
- *
38
- * @param config The editor configuration.
39
- */
40
- constructor(config = {}) {
41
- super();
42
- const constructor = this.constructor;
43
- // Prefer the language passed as the argument to the constructor instead of the constructor's `defaultConfig`, if both are set.
44
- const language = config.language || (constructor.defaultConfig && constructor.defaultConfig.language);
45
- this._context = config.context || new Context({ language });
46
- this._context._addEditor(this, !config.context);
47
- // Clone the plugins to make sure that the plugin array will not be shared
48
- // between editors and make the watchdog feature work correctly.
49
- const availablePlugins = Array.from(constructor.builtinPlugins || []);
50
- this.config = new Config(config, constructor.defaultConfig);
51
- this.config.define('plugins', availablePlugins);
52
- this.config.define(this._context._getEditorConfig());
53
- this.plugins = new PluginCollection(this, availablePlugins, this._context.plugins);
54
- this.locale = this._context.locale;
55
- this.t = this.locale.t;
56
- this._readOnlyLocks = new Set();
57
- this.commands = new CommandCollection();
58
- this.set('state', 'initializing');
59
- this.once('ready', () => (this.state = 'ready'), { priority: 'high' });
60
- this.once('destroy', () => (this.state = 'destroyed'), { priority: 'high' });
61
- this.model = new Model();
62
- this.on('change:isReadOnly', () => {
63
- this.model.document.isReadOnly = this.isReadOnly;
64
- });
65
- const stylesProcessor = new StylesProcessor();
66
- this.data = new DataController(this.model, stylesProcessor);
67
- this.editing = new EditingController(this.model, stylesProcessor);
68
- this.editing.view.document.bind('isReadOnly').to(this);
69
- this.conversion = new Conversion([this.editing.downcastDispatcher, this.data.downcastDispatcher], this.data.upcastDispatcher);
70
- this.conversion.addAlias('dataDowncast', this.data.downcastDispatcher);
71
- this.conversion.addAlias('editingDowncast', this.editing.downcastDispatcher);
72
- this.keystrokes = new EditingKeystrokeHandler(this);
73
- this.keystrokes.listenTo(this.editing.view.document);
74
- }
75
- /**
76
- * Defines whether the editor is in the 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 need to call the {@link #enableReadOnlyMode} method:
82
- *
83
- * ```ts
84
- * editor.enableReadOnlyMode( 'feature-id' );
85
- * ```
86
- *
87
- * Later, to turn off the read-only mode, call {@link #disableReadOnlyMode}:
88
- *
89
- * ```ts
90
- * editor.disableReadOnlyMode( 'feature-id' );
91
- * ```
92
- *
93
- * @readonly
94
- * @observable
95
- */
96
- get isReadOnly() {
97
- return this._readOnlyLocks.size > 0;
98
- }
99
- set isReadOnly(value) {
100
- /**
101
- * The {@link module:core/editor/editor~Editor#isReadOnly Editor#isReadOnly} property is read-only since version `34.0.0`
102
- * and can be set only using {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode( lockId )`} and
103
- * {@link module:core/editor/editor~Editor#disableReadOnlyMode `Editor#disableReadOnlyMode( lockId )`}.
104
- *
105
- * Usage before version `34.0.0`:
106
- *
107
- * ```ts
108
- * editor.isReadOnly = true;
109
- * editor.isReadOnly = false;
110
- * ```
111
- *
112
- * Usage since version `34.0.0`:
113
- *
114
- * ```ts
115
- * editor.enableReadOnlyMode( 'my-feature-id' );
116
- * editor.disableReadOnlyMode( 'my-feature-id' );
117
- * ```
118
- *
119
- * @error editor-isreadonly-has-no-setter
120
- */
121
- throw new CKEditorError('editor-isreadonly-has-no-setter');
122
- }
123
- /**
124
- * Turns on the read-only mode in the editor.
125
- *
126
- * Editor can be switched to or out of the read-only mode by many features, under various circumstances. The editor supports locking
127
- * 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
128
- * the same time, without conflicting with each other. It guarantees that you will not make the editor editable accidentally (which
129
- * could lead to errors).
130
- *
131
- * Each read-only mode request is identified by a unique id (also called "lock"). If multiple plugins requested to turn on the
132
- * read-only mode, then, the editor will become editable only after all these plugins turn the read-only mode off (using the same ids).
133
- *
134
- * Note, that you cannot force the editor to disable the read-only mode if other plugins set it.
135
- *
136
- * After the first `enableReadOnlyMode()` call, the {@link #isReadOnly `isReadOnly` property} will be set to `true`:
137
- *
138
- * ```ts
139
- * editor.isReadOnly; // `false`.
140
- * editor.enableReadOnlyMode( 'my-feature-id' );
141
- * editor.isReadOnly; // `true`.
142
- * ```
143
- *
144
- * You can turn off the read-only mode ("clear the lock") using the {@link #disableReadOnlyMode `disableReadOnlyMode()`} method:
145
- *
146
- * ```ts
147
- * editor.enableReadOnlyMode( 'my-feature-id' );
148
- * // ...
149
- * editor.disableReadOnlyMode( 'my-feature-id' );
150
- * editor.isReadOnly; // `false`.
151
- * ```
152
- *
153
- * All "locks" need to be removed to enable editing:
154
- *
155
- * ```ts
156
- * editor.enableReadOnlyMode( 'my-feature-id' );
157
- * editor.enableReadOnlyMode( 'my-other-feature-id' );
158
- * // ...
159
- * editor.disableReadOnlyMode( 'my-feature-id' );
160
- * editor.isReadOnly; // `true`.
161
- * editor.disableReadOnlyMode( 'my-other-feature-id' );
162
- * editor.isReadOnly; // `false`.
163
- * ```
164
- *
165
- * @param lockId A unique ID for setting the editor to the read-only state.
166
- */
167
- enableReadOnlyMode(lockId) {
168
- if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
169
- /**
170
- * The lock ID is missing or it is not a string or symbol.
171
- *
172
- * @error editor-read-only-lock-id-invalid
173
- */
174
- throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
175
- }
176
- if (this._readOnlyLocks.has(lockId)) {
177
- return;
178
- }
179
- this._readOnlyLocks.add(lockId);
180
- if (this._readOnlyLocks.size === 1) {
181
- // Manually fire the `change:isReadOnly` event as only getter is provided.
182
- this.fire('change:isReadOnly', 'isReadOnly', true, false);
183
- }
184
- }
185
- /**
186
- * Removes the read-only lock from the editor with given lock ID.
187
- *
188
- * When no lock is present on the editor anymore, then the {@link #isReadOnly `isReadOnly` property} will be set to `false`.
189
- *
190
- * @param lockId The lock ID for setting the editor to the read-only state.
191
- */
192
- disableReadOnlyMode(lockId) {
193
- if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
194
- throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
195
- }
196
- if (!this._readOnlyLocks.has(lockId)) {
197
- return;
198
- }
199
- this._readOnlyLocks.delete(lockId);
200
- if (this._readOnlyLocks.size === 0) {
201
- // Manually fire the `change:isReadOnly` event as only getter is provided.
202
- this.fire('change:isReadOnly', 'isReadOnly', false, true);
203
- }
204
- }
205
- /**
206
- * Loads and initializes plugins specified in the configuration.
207
- *
208
- * @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
209
- */
210
- initPlugins() {
211
- const config = this.config;
212
- const plugins = config.get('plugins');
213
- const removePlugins = config.get('removePlugins') || [];
214
- const extraPlugins = config.get('extraPlugins') || [];
215
- const substitutePlugins = config.get('substitutePlugins') || [];
216
- return this.plugins.init(plugins.concat(extraPlugins), removePlugins, substitutePlugins);
217
- }
218
- /**
219
- * Destroys the editor instance, releasing all resources used by it.
220
- *
221
- * **Note** The editor cannot be destroyed during the initialization phase so if it is called
222
- * while the editor {@link #state is being initialized}, it will wait for the editor initialization before destroying it.
223
- *
224
- * @fires destroy
225
- * @returns A promise that resolves once the editor instance is fully destroyed.
226
- */
227
- destroy() {
228
- let readyPromise = Promise.resolve();
229
- if (this.state == 'initializing') {
230
- readyPromise = new Promise(resolve => this.once('ready', resolve));
231
- }
232
- return readyPromise
233
- .then(() => {
234
- this.fire('destroy');
235
- this.stopListening();
236
- this.commands.destroy();
237
- })
238
- .then(() => this.plugins.destroy())
239
- .then(() => {
240
- this.model.destroy();
241
- this.data.destroy();
242
- this.editing.destroy();
243
- this.keystrokes.destroy();
244
- })
245
- // Remove the editor from the context.
246
- // When the context was created by this editor, the context will be destroyed.
247
- .then(() => this._context._removeEditor(this));
248
- }
249
- /**
250
- * Executes the specified command with given parameters.
251
- *
252
- * Shorthand for:
253
- *
254
- * ```ts
255
- * editor.commands.get( commandName ).execute( ... );
256
- * ```
257
- *
258
- * @param commandName The name of the command to execute.
259
- * @param commandParams Command parameters.
260
- * @returns The value returned by the {@link module:core/commandcollection~CommandCollection#execute `commands.execute()`}.
261
- */
262
- execute(commandName, ...commandParams) {
263
- try {
264
- return this.commands.execute(commandName, ...commandParams);
265
- }
266
- catch (err) {
267
- // @if CK_DEBUG // throw err;
268
- /* istanbul ignore next -- @preserve */
269
- CKEditorError.rethrowUnexpectedError(err, this);
270
- }
271
- }
272
- /**
273
- * Focuses the editor.
274
- *
275
- * **Note** To explicitly focus the editing area of the editor, use the
276
- * {@link module:engine/view/view~View#focus `editor.editing.view.focus()`} method of the editing view.
277
- *
278
- * Check out the {@glink framework/deep-dive/ui/focus-tracking#focus-in-the-editor-ui Focus in the editor UI} section
279
- * of the {@glink framework/deep-dive/ui/focus-tracking Deep dive into focus tracking} guide to learn more.
280
- */
281
- focus() {
282
- this.editing.view.focus();
283
- }
284
- /* istanbul ignore next -- @preserve */
285
- /**
286
- * Creates and initializes a new editor instance.
287
- *
288
- * This is an abstract method. Every editor type needs to implement its own initialization logic.
289
- *
290
- * See the `create()` methods of the existing editor types to learn how to use them:
291
- *
292
- * * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}
293
- * * {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}
294
- * * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
295
- * * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}
296
- */
297
- static create(...args) {
298
- throw new Error('This is an abstract method.');
299
- }
300
- }
301
- /**
302
- * This error is thrown when trying to pass a `<textarea>` element to a `create()` function of an editor class.
303
- *
304
- * The only editor type which can be initialized on `<textarea>` elements is
305
- * the {@glink installation/getting-started/predefined-builds#classic-editor classic editor}.
306
- * This editor hides the passed element and inserts its own UI next to it. Other types of editors reuse the passed element as their root
307
- * editable element and therefore `<textarea>` is not appropriate for them. Use a `<div>` or another text container instead:
308
- *
309
- * ```html
310
- * <div id="editor">
311
- * <p>Initial content.</p>
312
- * </div>
313
- * ```
314
- *
315
- * @error editor-wrong-element
316
- */
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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/editor
7
+ */
8
+ import { Config, CKEditorError, ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
+ import { Conversion, DataController, EditingController, Model, StylesProcessor } from '@ckeditor/ckeditor5-engine';
10
+ import Context from '../context';
11
+ import PluginCollection from '../plugincollection';
12
+ import CommandCollection from '../commandcollection';
13
+ import EditingKeystrokeHandler from '../editingkeystrokehandler';
14
+ /**
15
+ * The class representing a basic, generic editor.
16
+ *
17
+ * Check out the list of its subclasses to learn about specific editor implementations.
18
+ *
19
+ * All editor implementations (like {@link module:editor-classic/classiceditor~ClassicEditor} or
20
+ * {@link module:editor-inline/inlineeditor~InlineEditor}) should extend this class. They can add their
21
+ * own methods and properties.
22
+ *
23
+ * When you are implementing a plugin, this editor represents the API
24
+ * which your plugin can expect to get when using its {@link module:core/plugin~Plugin#editor} property.
25
+ *
26
+ * This API should be sufficient in order to implement the "editing" part of your feature
27
+ * (schema definition, conversion, commands, keystrokes, etc.).
28
+ * It does not define the editor UI, which is available only if
29
+ * the specific editor implements also the {@link ~Editor#ui} property
30
+ * (as most editor implementations do).
31
+ */
32
+ export default class Editor extends ObservableMixin() {
33
+ /**
34
+ * Creates a new instance of the editor class.
35
+ *
36
+ * Usually, not to be used directly. See the static {@link module:core/editor/editor~Editor.create `create()`} method.
37
+ *
38
+ * @param config The editor configuration.
39
+ */
40
+ constructor(config = {}) {
41
+ super();
42
+ const constructor = this.constructor;
43
+ // Prefer the language passed as the argument to the constructor instead of the constructor's `defaultConfig`, if both are set.
44
+ const language = config.language || (constructor.defaultConfig && constructor.defaultConfig.language);
45
+ this._context = config.context || new Context({ language });
46
+ this._context._addEditor(this, !config.context);
47
+ // Clone the plugins to make sure that the plugin array will not be shared
48
+ // between editors and make the watchdog feature work correctly.
49
+ const availablePlugins = Array.from(constructor.builtinPlugins || []);
50
+ this.config = new Config(config, constructor.defaultConfig);
51
+ this.config.define('plugins', availablePlugins);
52
+ this.config.define(this._context._getEditorConfig());
53
+ this.plugins = new PluginCollection(this, availablePlugins, this._context.plugins);
54
+ this.locale = this._context.locale;
55
+ this.t = this.locale.t;
56
+ this._readOnlyLocks = new Set();
57
+ this.commands = new CommandCollection();
58
+ this.set('state', 'initializing');
59
+ this.once('ready', () => (this.state = 'ready'), { priority: 'high' });
60
+ this.once('destroy', () => (this.state = 'destroyed'), { priority: 'high' });
61
+ this.model = new Model();
62
+ this.on('change:isReadOnly', () => {
63
+ this.model.document.isReadOnly = this.isReadOnly;
64
+ });
65
+ const stylesProcessor = new StylesProcessor();
66
+ this.data = new DataController(this.model, stylesProcessor);
67
+ this.editing = new EditingController(this.model, stylesProcessor);
68
+ this.editing.view.document.bind('isReadOnly').to(this);
69
+ this.conversion = new Conversion([this.editing.downcastDispatcher, this.data.downcastDispatcher], this.data.upcastDispatcher);
70
+ this.conversion.addAlias('dataDowncast', this.data.downcastDispatcher);
71
+ this.conversion.addAlias('editingDowncast', this.editing.downcastDispatcher);
72
+ this.keystrokes = new EditingKeystrokeHandler(this);
73
+ this.keystrokes.listenTo(this.editing.view.document);
74
+ }
75
+ /**
76
+ * Defines whether the editor is in the 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 need to call the {@link #enableReadOnlyMode} method:
82
+ *
83
+ * ```ts
84
+ * editor.enableReadOnlyMode( 'feature-id' );
85
+ * ```
86
+ *
87
+ * Later, to turn off the read-only mode, call {@link #disableReadOnlyMode}:
88
+ *
89
+ * ```ts
90
+ * editor.disableReadOnlyMode( 'feature-id' );
91
+ * ```
92
+ *
93
+ * @readonly
94
+ * @observable
95
+ */
96
+ get isReadOnly() {
97
+ return this._readOnlyLocks.size > 0;
98
+ }
99
+ set isReadOnly(value) {
100
+ /**
101
+ * The {@link module:core/editor/editor~Editor#isReadOnly Editor#isReadOnly} property is read-only since version `34.0.0`
102
+ * and can be set only using {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode( lockId )`} and
103
+ * {@link module:core/editor/editor~Editor#disableReadOnlyMode `Editor#disableReadOnlyMode( lockId )`}.
104
+ *
105
+ * Usage before version `34.0.0`:
106
+ *
107
+ * ```ts
108
+ * editor.isReadOnly = true;
109
+ * editor.isReadOnly = false;
110
+ * ```
111
+ *
112
+ * Usage since version `34.0.0`:
113
+ *
114
+ * ```ts
115
+ * editor.enableReadOnlyMode( 'my-feature-id' );
116
+ * editor.disableReadOnlyMode( 'my-feature-id' );
117
+ * ```
118
+ *
119
+ * @error editor-isreadonly-has-no-setter
120
+ */
121
+ throw new CKEditorError('editor-isreadonly-has-no-setter');
122
+ }
123
+ /**
124
+ * Turns on the read-only mode in the editor.
125
+ *
126
+ * Editor can be switched to or out of the read-only mode by many features, under various circumstances. The editor supports locking
127
+ * 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
128
+ * the same time, without conflicting with each other. It guarantees that you will not make the editor editable accidentally (which
129
+ * could lead to errors).
130
+ *
131
+ * Each read-only mode request is identified by a unique id (also called "lock"). If multiple plugins requested to turn on the
132
+ * read-only mode, then, the editor will become editable only after all these plugins turn the read-only mode off (using the same ids).
133
+ *
134
+ * Note, that you cannot force the editor to disable the read-only mode if other plugins set it.
135
+ *
136
+ * After the first `enableReadOnlyMode()` call, the {@link #isReadOnly `isReadOnly` property} will be set to `true`:
137
+ *
138
+ * ```ts
139
+ * editor.isReadOnly; // `false`.
140
+ * editor.enableReadOnlyMode( 'my-feature-id' );
141
+ * editor.isReadOnly; // `true`.
142
+ * ```
143
+ *
144
+ * You can turn off the read-only mode ("clear the lock") using the {@link #disableReadOnlyMode `disableReadOnlyMode()`} method:
145
+ *
146
+ * ```ts
147
+ * editor.enableReadOnlyMode( 'my-feature-id' );
148
+ * // ...
149
+ * editor.disableReadOnlyMode( 'my-feature-id' );
150
+ * editor.isReadOnly; // `false`.
151
+ * ```
152
+ *
153
+ * All "locks" need to be removed to enable editing:
154
+ *
155
+ * ```ts
156
+ * editor.enableReadOnlyMode( 'my-feature-id' );
157
+ * editor.enableReadOnlyMode( 'my-other-feature-id' );
158
+ * // ...
159
+ * editor.disableReadOnlyMode( 'my-feature-id' );
160
+ * editor.isReadOnly; // `true`.
161
+ * editor.disableReadOnlyMode( 'my-other-feature-id' );
162
+ * editor.isReadOnly; // `false`.
163
+ * ```
164
+ *
165
+ * @param lockId A unique ID for setting the editor to the read-only state.
166
+ */
167
+ enableReadOnlyMode(lockId) {
168
+ if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
169
+ /**
170
+ * The lock ID is missing or it is not a string or symbol.
171
+ *
172
+ * @error editor-read-only-lock-id-invalid
173
+ */
174
+ throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
175
+ }
176
+ if (this._readOnlyLocks.has(lockId)) {
177
+ return;
178
+ }
179
+ this._readOnlyLocks.add(lockId);
180
+ if (this._readOnlyLocks.size === 1) {
181
+ // Manually fire the `change:isReadOnly` event as only getter is provided.
182
+ this.fire('change:isReadOnly', 'isReadOnly', true, false);
183
+ }
184
+ }
185
+ /**
186
+ * Removes the read-only lock from the editor with given lock ID.
187
+ *
188
+ * When no lock is present on the editor anymore, then the {@link #isReadOnly `isReadOnly` property} will be set to `false`.
189
+ *
190
+ * @param lockId The lock ID for setting the editor to the read-only state.
191
+ */
192
+ disableReadOnlyMode(lockId) {
193
+ if (typeof lockId !== 'string' && typeof lockId !== 'symbol') {
194
+ throw new CKEditorError('editor-read-only-lock-id-invalid', null, { lockId });
195
+ }
196
+ if (!this._readOnlyLocks.has(lockId)) {
197
+ return;
198
+ }
199
+ this._readOnlyLocks.delete(lockId);
200
+ if (this._readOnlyLocks.size === 0) {
201
+ // Manually fire the `change:isReadOnly` event as only getter is provided.
202
+ this.fire('change:isReadOnly', 'isReadOnly', false, true);
203
+ }
204
+ }
205
+ /**
206
+ * Loads and initializes plugins specified in the configuration.
207
+ *
208
+ * @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
209
+ */
210
+ initPlugins() {
211
+ const config = this.config;
212
+ const plugins = config.get('plugins');
213
+ const removePlugins = config.get('removePlugins') || [];
214
+ const extraPlugins = config.get('extraPlugins') || [];
215
+ const substitutePlugins = config.get('substitutePlugins') || [];
216
+ return this.plugins.init(plugins.concat(extraPlugins), removePlugins, substitutePlugins);
217
+ }
218
+ /**
219
+ * Destroys the editor instance, releasing all resources used by it.
220
+ *
221
+ * **Note** The editor cannot be destroyed during the initialization phase so if it is called
222
+ * while the editor {@link #state is being initialized}, it will wait for the editor initialization before destroying it.
223
+ *
224
+ * @fires destroy
225
+ * @returns A promise that resolves once the editor instance is fully destroyed.
226
+ */
227
+ destroy() {
228
+ let readyPromise = Promise.resolve();
229
+ if (this.state == 'initializing') {
230
+ readyPromise = new Promise(resolve => this.once('ready', resolve));
231
+ }
232
+ return readyPromise
233
+ .then(() => {
234
+ this.fire('destroy');
235
+ this.stopListening();
236
+ this.commands.destroy();
237
+ })
238
+ .then(() => this.plugins.destroy())
239
+ .then(() => {
240
+ this.model.destroy();
241
+ this.data.destroy();
242
+ this.editing.destroy();
243
+ this.keystrokes.destroy();
244
+ })
245
+ // Remove the editor from the context.
246
+ // When the context was created by this editor, the context will be destroyed.
247
+ .then(() => this._context._removeEditor(this));
248
+ }
249
+ /**
250
+ * Executes the specified command with given parameters.
251
+ *
252
+ * Shorthand for:
253
+ *
254
+ * ```ts
255
+ * editor.commands.get( commandName ).execute( ... );
256
+ * ```
257
+ *
258
+ * @param commandName The name of the command to execute.
259
+ * @param commandParams Command parameters.
260
+ * @returns The value returned by the {@link module:core/commandcollection~CommandCollection#execute `commands.execute()`}.
261
+ */
262
+ execute(commandName, ...commandParams) {
263
+ try {
264
+ return this.commands.execute(commandName, ...commandParams);
265
+ }
266
+ catch (err) {
267
+ // @if CK_DEBUG // throw err;
268
+ /* istanbul ignore next -- @preserve */
269
+ CKEditorError.rethrowUnexpectedError(err, this);
270
+ }
271
+ }
272
+ /**
273
+ * Focuses the editor.
274
+ *
275
+ * **Note** To explicitly focus the editing area of the editor, use the
276
+ * {@link module:engine/view/view~View#focus `editor.editing.view.focus()`} method of the editing view.
277
+ *
278
+ * Check out the {@glink framework/deep-dive/ui/focus-tracking#focus-in-the-editor-ui Focus in the editor UI} section
279
+ * of the {@glink framework/deep-dive/ui/focus-tracking Deep dive into focus tracking} guide to learn more.
280
+ */
281
+ focus() {
282
+ this.editing.view.focus();
283
+ }
284
+ /* istanbul ignore next -- @preserve */
285
+ /**
286
+ * Creates and initializes a new editor instance.
287
+ *
288
+ * This is an abstract method. Every editor type needs to implement its own initialization logic.
289
+ *
290
+ * See the `create()` methods of the existing editor types to learn how to use them:
291
+ *
292
+ * * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}
293
+ * * {@link module:editor-balloon/ballooneditor~BalloonEditor.create `BalloonEditor.create()`}
294
+ * * {@link module:editor-decoupled/decouplededitor~DecoupledEditor.create `DecoupledEditor.create()`}
295
+ * * {@link module:editor-inline/inlineeditor~InlineEditor.create `InlineEditor.create()`}
296
+ */
297
+ static create(...args) {
298
+ throw new Error('This is an abstract method.');
299
+ }
300
+ }
301
+ /**
302
+ * This error is thrown when trying to pass a `<textarea>` element to a `create()` function of an editor class.
303
+ *
304
+ * The only editor type which can be initialized on `<textarea>` elements is
305
+ * the {@glink installation/getting-started/predefined-builds#classic-editor classic editor}.
306
+ * This editor hides the passed element and inserts its own UI next to it. Other types of editors reuse the passed element as their root
307
+ * editable element and therefore `<textarea>` is not appropriate for them. Use a `<div>` or another text container instead:
308
+ *
309
+ * ```html
310
+ * <div id="editor">
311
+ * <p>Initial content.</p>
312
+ * </div>
313
+ * ```
314
+ *
315
+ * @error editor-wrong-element
316
+ */