@ckeditor/ckeditor5-core 41.1.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.
Files changed (107) hide show
  1. package/dist/content-index.css +4 -0
  2. package/dist/editor-index.css +4 -0
  3. package/dist/index.css +4 -0
  4. package/dist/index.js +2411 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/types/accessibility.d.ts +361 -0
  7. package/dist/types/augmentation.d.ts +10 -0
  8. package/dist/types/command.d.ts +189 -0
  9. package/dist/types/commandcollection.d.ts +83 -0
  10. package/dist/types/context.d.ts +237 -0
  11. package/dist/types/contextplugin.d.ts +61 -0
  12. package/dist/types/editingkeystrokehandler.d.ts +56 -0
  13. package/dist/types/editor/editor.d.ts +478 -0
  14. package/dist/types/editor/editorconfig.d.ts +666 -0
  15. package/dist/types/editor/utils/attachtoform.d.ts +15 -0
  16. package/dist/types/editor/utils/dataapimixin.d.ts +79 -0
  17. package/dist/types/editor/utils/elementapimixin.d.ts +35 -0
  18. package/dist/types/editor/utils/securesourceelement.d.ts +17 -0
  19. package/dist/types/index.d.ts +89 -0
  20. package/dist/types/multicommand.d.ts +66 -0
  21. package/dist/types/pendingactions.d.ts +117 -0
  22. package/dist/types/plugin.d.ts +274 -0
  23. package/dist/types/plugincollection.d.ts +117 -0
  24. package/dist/types/typings.d.ts +8 -0
  25. package/lang/contexts.json +13 -1
  26. package/lang/translations/af.po +48 -0
  27. package/lang/translations/ar.po +48 -0
  28. package/lang/translations/ast.po +48 -0
  29. package/lang/translations/az.po +48 -0
  30. package/lang/translations/bg.po +48 -0
  31. package/lang/translations/bn.po +48 -0
  32. package/lang/translations/bs.po +48 -0
  33. package/lang/translations/ca.po +48 -0
  34. package/lang/translations/cs.po +48 -0
  35. package/lang/translations/da.po +48 -0
  36. package/lang/translations/de-ch.po +48 -0
  37. package/lang/translations/de.po +48 -0
  38. package/lang/translations/el.po +48 -0
  39. package/lang/translations/en-au.po +48 -0
  40. package/lang/translations/en-gb.po +48 -0
  41. package/lang/translations/en.po +48 -0
  42. package/lang/translations/eo.po +48 -0
  43. package/lang/translations/es-co.po +48 -0
  44. package/lang/translations/es.po +48 -0
  45. package/lang/translations/et.po +48 -0
  46. package/lang/translations/eu.po +48 -0
  47. package/lang/translations/fa.po +48 -0
  48. package/lang/translations/fi.po +48 -0
  49. package/lang/translations/fr.po +48 -0
  50. package/lang/translations/gl.po +48 -0
  51. package/lang/translations/gu.po +48 -0
  52. package/lang/translations/he.po +49 -1
  53. package/lang/translations/hi.po +48 -0
  54. package/lang/translations/hr.po +48 -0
  55. package/lang/translations/hu.po +48 -0
  56. package/lang/translations/hy.po +48 -0
  57. package/lang/translations/id.po +48 -0
  58. package/lang/translations/it.po +48 -0
  59. package/lang/translations/ja.po +48 -0
  60. package/lang/translations/jv.po +48 -0
  61. package/lang/translations/km.po +48 -0
  62. package/lang/translations/kn.po +48 -0
  63. package/lang/translations/ko.po +48 -0
  64. package/lang/translations/ku.po +48 -0
  65. package/lang/translations/lt.po +48 -0
  66. package/lang/translations/lv.po +48 -0
  67. package/lang/translations/ms.po +48 -0
  68. package/lang/translations/nb.po +48 -0
  69. package/lang/translations/ne.po +48 -0
  70. package/lang/translations/nl.po +48 -0
  71. package/lang/translations/no.po +48 -0
  72. package/lang/translations/oc.po +48 -0
  73. package/lang/translations/pl.po +48 -0
  74. package/lang/translations/pt-br.po +48 -0
  75. package/lang/translations/pt.po +48 -0
  76. package/lang/translations/ro.po +48 -0
  77. package/lang/translations/ru.po +48 -0
  78. package/lang/translations/si.po +48 -0
  79. package/lang/translations/sk.po +48 -0
  80. package/lang/translations/sl.po +48 -0
  81. package/lang/translations/sq.po +48 -0
  82. package/lang/translations/sr-latn.po +48 -0
  83. package/lang/translations/sr.po +48 -0
  84. package/lang/translations/sv.po +48 -0
  85. package/lang/translations/th.po +48 -0
  86. package/lang/translations/tk.po +48 -0
  87. package/lang/translations/tr.po +48 -0
  88. package/lang/translations/tt.po +48 -0
  89. package/lang/translations/ug.po +48 -0
  90. package/lang/translations/uk.po +48 -0
  91. package/lang/translations/ur.po +48 -0
  92. package/lang/translations/uz.po +48 -0
  93. package/lang/translations/vi.po +48 -0
  94. package/lang/translations/zh-cn.po +48 -0
  95. package/lang/translations/zh.po +48 -0
  96. package/package.json +4 -3
  97. package/src/accessibility.d.ts +361 -0
  98. package/src/accessibility.js +315 -0
  99. package/src/context.js +6 -2
  100. package/src/editor/editor.d.ts +61 -0
  101. package/src/editor/editor.js +65 -3
  102. package/src/editor/editorconfig.d.ts +5 -0
  103. package/src/editor/utils/dataapimixin.d.ts +6 -2
  104. package/src/editor/utils/dataapimixin.js +3 -15
  105. package/src/index.d.ts +2 -0
  106. package/src/typings.d.ts +8 -0
  107. package/src/typings.js +5 -0
@@ -0,0 +1,315 @@
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/accessibility
7
+ */
8
+ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
+ const DEFAULT_CATEGORY_ID = 'contentEditing';
10
+ export const DEFAULT_GROUP_ID = 'common';
11
+ /**
12
+ * A common namespace for various accessibility features of the editor.
13
+ *
14
+ * **Information about editor keystrokes**
15
+ *
16
+ * * The information about keystrokes available in the editor is stored in the {@link #keystrokeInfos} property.
17
+ * * New info entries can be added using the {@link #addKeystrokeInfoCategory}, {@link #addKeystrokeInfoGroup},
18
+ * and {@link #addKeystrokeInfos} methods.
19
+ */
20
+ export default class Accessibility {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ constructor(editor) {
25
+ /**
26
+ * Stores information about keystrokes brought by editor features for the users to interact with the editor, mainly
27
+ * keystroke combinations and their accessible labels.
28
+ *
29
+ * This information is particularly useful for screen reader and other assistive technology users. It gets displayed
30
+ * by the {@link module:ui/editorui/accessibilityhelp/accessibilityhelp~AccessibilityHelp Accessibility help} dialog.
31
+ *
32
+ * Keystrokes are organized in categories and groups. They can be added using ({@link #addKeystrokeInfoCategory},
33
+ * {@link #addKeystrokeInfoGroup}, and {@link #addKeystrokeInfos}) methods.
34
+ *
35
+ * Please note that:
36
+ * * two categories are always available:
37
+ * * `'contentEditing'` for keystrokes related to content creation,
38
+ * * `'navigation'` for keystrokes related to navigation in the UI and the content.
39
+ * * unless specified otherwise, new keystrokes are added into the `'contentEditing'` category and the `'common'`
40
+ * keystroke group within that category while using the {@link #addKeystrokeInfos} method.
41
+ */
42
+ this.keystrokeInfos = new Map();
43
+ this._editor = editor;
44
+ const t = editor.locale.t;
45
+ this.addKeystrokeInfoCategory({
46
+ id: DEFAULT_CATEGORY_ID,
47
+ label: t('Content editing keystrokes'),
48
+ description: t('These keyboard shortcuts allow for quick access to content editing features.')
49
+ });
50
+ this.addKeystrokeInfoCategory({
51
+ id: 'navigation',
52
+ label: t('User interface and content navigation keystrokes'),
53
+ description: t('Use the following keystrokes for more efficient navigation in the CKEditor 5 user interface.'),
54
+ groups: [
55
+ {
56
+ id: 'common',
57
+ keystrokes: [
58
+ {
59
+ label: t('Close contextual balloons, dropdowns, and dialogs'),
60
+ keystroke: 'Esc'
61
+ },
62
+ {
63
+ label: t('Open the accessibility help dialog'),
64
+ keystroke: 'Alt+0'
65
+ },
66
+ {
67
+ label: t('Move focus between form fields (inputs, buttons, etc.)'),
68
+ keystroke: [['Tab'], ['Shift+Tab']]
69
+ },
70
+ {
71
+ label: t('Move focus to the toolbar, navigate between toolbars'),
72
+ keystroke: 'Alt+F10',
73
+ mayRequireFn: true
74
+ },
75
+ {
76
+ label: t('Navigate through the toolbar'),
77
+ keystroke: [['arrowup'], ['arrowright'], ['arrowdown'], ['arrowleft']]
78
+ },
79
+ {
80
+ label: t('Execute the currently focused button'),
81
+ keystroke: [['Enter'], ['Space']]
82
+ }
83
+ ]
84
+ }
85
+ ]
86
+ });
87
+ }
88
+ /**
89
+ * Adds a top-level category in the {@link #keystrokeInfos keystroke information database} with a label and optional description.
90
+ *
91
+ * Categories organize keystrokes and help users to find the right keystroke. Each category can have multiple groups
92
+ * of keystrokes that narrow down the context in which the keystrokes are available. Every keystroke category comes
93
+ * with a `'common'` group by default.
94
+ *
95
+ * By default, two categories are available:
96
+ * * `'contentEditing'` for keystrokes related to content creation,
97
+ * * `'navigation'` for keystrokes related to navigation in the UI and the content.
98
+ *
99
+ * To create a new keystroke category with new groups, use the following code:
100
+ *
101
+ * ```js
102
+ * class MyPlugin extends Plugin {
103
+ * // ...
104
+ * init() {
105
+ * const editor = this.editor;
106
+ * const t = editor.t;
107
+ *
108
+ * // ...
109
+ *
110
+ * editor.accessibility.addKeystrokeInfoCategory( {
111
+ * id: 'myCategory',
112
+ * label: t( 'My category' ),
113
+ * description: t( 'My category description.' ),
114
+ * groups: [
115
+ * {
116
+ * id: 'myGroup',
117
+ * label: t( 'My keystroke group' ),
118
+ * keystrokes: [
119
+ * {
120
+ * label: t( 'Keystroke label 1' ),
121
+ * keystroke: 'Ctrl+Shift+N'
122
+ * },
123
+ * {
124
+ * label: t( 'Keystroke label 2' ),
125
+ * keystroke: 'Ctrl+Shift+M'
126
+ * }
127
+ * ]
128
+ * }
129
+ * ]
130
+ * };
131
+ * }
132
+ * }
133
+ * ```
134
+ *
135
+ * See {@link #keystrokeInfos}, {@link #addKeystrokeInfoGroup}, and {@link #addKeystrokeInfos}.
136
+ */
137
+ addKeystrokeInfoCategory({ id, label, description, groups }) {
138
+ this.keystrokeInfos.set(id, {
139
+ id,
140
+ label,
141
+ description,
142
+ groups: new Map()
143
+ });
144
+ this.addKeystrokeInfoGroup({
145
+ categoryId: id,
146
+ id: DEFAULT_GROUP_ID
147
+ });
148
+ if (groups) {
149
+ groups.forEach(group => {
150
+ this.addKeystrokeInfoGroup({
151
+ categoryId: id,
152
+ ...group
153
+ });
154
+ });
155
+ }
156
+ }
157
+ /**
158
+ * Adds a group of keystrokes in a specific category to the {@link #keystrokeInfos keystroke information database}.
159
+ *
160
+ * Groups narrow down the context in which the keystrokes are available. When `categoryId` is not specified,
161
+ * the group goes to the `'contentEditing'` category (default).
162
+ *
163
+ * To create a new group within an existing category, use the following code:
164
+ *
165
+ * ```js
166
+ * class MyPlugin extends Plugin {
167
+ * // ...
168
+ * init() {
169
+ * const editor = this.editor;
170
+ * const t = editor.t;
171
+ *
172
+ * // ...
173
+ *
174
+ * editor.accessibility.addKeystrokeInfoGroup( {
175
+ * id: 'myGroup',
176
+ * categoryId: 'navigation',
177
+ * label: t( 'My keystroke group' ),
178
+ * keystrokes: [
179
+ * {
180
+ * label: t( 'Keystroke label 1' ),
181
+ * keystroke: 'Ctrl+Shift+N'
182
+ * },
183
+ * {
184
+ * label: t( 'Keystroke label 2' ),
185
+ * keystroke: 'Ctrl+Shift+M'
186
+ * }
187
+ * ]
188
+ * } );
189
+ * }
190
+ * }
191
+ * ```
192
+ *
193
+ * See {@link #keystrokeInfos}, {@link #addKeystrokeInfoCategory}, and {@link #addKeystrokeInfos}.
194
+ */
195
+ addKeystrokeInfoGroup({ categoryId = DEFAULT_CATEGORY_ID, id, label, keystrokes }) {
196
+ const category = this.keystrokeInfos.get(categoryId);
197
+ if (!category) {
198
+ throw new CKEditorError('accessibility-unknown-keystroke-info-category', this._editor, { groupId: id, categoryId });
199
+ }
200
+ category.groups.set(id, {
201
+ id,
202
+ label,
203
+ keystrokes: keystrokes || []
204
+ });
205
+ }
206
+ /**
207
+ * Adds information about keystrokes to the {@link #keystrokeInfos keystroke information database}.
208
+ *
209
+ * Keystrokes without specified `groupId` or `categoryId` go to the `'common'` group in the `'contentEditing'` category (default).
210
+ *
211
+ * To add a keystroke brought by your plugin (using default group and category), use the following code:
212
+ *
213
+ * ```js
214
+ * class MyPlugin extends Plugin {
215
+ * // ...
216
+ * init() {
217
+ * const editor = this.editor;
218
+ * const t = editor.t;
219
+ *
220
+ * // ...
221
+ *
222
+ * editor.accessibility.addKeystrokeInfos( {
223
+ * keystrokes: [
224
+ * {
225
+ * label: t( 'Keystroke label' ),
226
+ * keystroke: 'CTRL+B'
227
+ * }
228
+ * ]
229
+ * } );
230
+ * }
231
+ * }
232
+ * ```
233
+ * To add a keystroke in a specific existing `'widget'` group in the default `'contentEditing'` category:
234
+ *
235
+ * ```js
236
+ * class MyPlugin extends Plugin {
237
+ * // ...
238
+ * init() {
239
+ * const editor = this.editor;
240
+ * const t = editor.t;
241
+ *
242
+ * // ...
243
+ *
244
+ * editor.accessibility.addKeystrokeInfos( {
245
+ * // Add a keystroke to the existing "widget" group.
246
+ * groupId: 'widget',
247
+ * keystrokes: [
248
+ * {
249
+ * label: t( 'A an action on a selected widget' ),
250
+ * keystroke: 'Ctrl+D',
251
+ * }
252
+ * ]
253
+ * } );
254
+ * }
255
+ * }
256
+ * ```
257
+ *
258
+ * To add a keystroke to another existing category (using default group):
259
+ *
260
+ * ```js
261
+ * class MyPlugin extends Plugin {
262
+ * // ...
263
+ * init() {
264
+ * const editor = this.editor;
265
+ * const t = editor.t;
266
+ *
267
+ * // ...
268
+ *
269
+ * editor.accessibility.addKeystrokeInfos( {
270
+ * // Add keystrokes to the "navigation" category (one of defaults).
271
+ * categoryId: 'navigation',
272
+ * keystrokes: [
273
+ * {
274
+ * label: t( 'Keystroke label' ),
275
+ * keystroke: 'CTRL+B'
276
+ * }
277
+ * ]
278
+ * } );
279
+ * }
280
+ * }
281
+ * ```
282
+ *
283
+ * See {@link #keystrokeInfos}, {@link #addKeystrokeInfoGroup}, and {@link #addKeystrokeInfoCategory}.
284
+ */
285
+ addKeystrokeInfos({ categoryId = DEFAULT_CATEGORY_ID, groupId = DEFAULT_GROUP_ID, keystrokes }) {
286
+ if (!this.keystrokeInfos.has(categoryId)) {
287
+ /**
288
+ * Cannot add keystrokes in an unknown category. Use
289
+ * {@link module:core/accessibility~Accessibility#addKeystrokeInfoCategory}
290
+ * to add a new category or make sure the specified category exists.
291
+ *
292
+ * @error accessibility-unknown-keystroke-info-category
293
+ * @param categoryId The id of the unknown keystroke category.
294
+ * @param keystrokes Keystroke definitions about to be added.
295
+ */
296
+ throw new CKEditorError('accessibility-unknown-keystroke-info-category', this._editor, { categoryId, keystrokes });
297
+ }
298
+ const category = this.keystrokeInfos.get(categoryId);
299
+ if (!category.groups.has(groupId)) {
300
+ /**
301
+ * Cannot add keystrokes to an unknown group.
302
+ *
303
+ * Use {@link module:core/accessibility~Accessibility#addKeystrokeInfoGroup}
304
+ * to add a new group or make sure the specified group exists.
305
+ *
306
+ * @error accessibility-unknown-keystroke-info-group
307
+ * @param groupId The id of the unknown keystroke group.
308
+ * @param categoryId The id of category the unknown group should belong to.
309
+ * @param keystrokes Keystroke definitions about to be added.
310
+ */
311
+ throw new CKEditorError('accessibility-unknown-keystroke-info-group', this._editor, { groupId, categoryId, keystrokes });
312
+ }
313
+ category.groups.get(groupId).keystrokes.push(...keystrokes);
314
+ }
315
+ }
package/src/context.js CHANGED
@@ -50,14 +50,18 @@ export default class Context {
50
50
  * It is used to destroy the context when removing the editor that has created the context.
51
51
  */
52
52
  this._contextOwner = null;
53
- this.config = new Config(config, this.constructor.defaultConfig);
53
+ // We don't pass translations to the config, because its behavior of splitting keys
54
+ // with dots (e.g. `resize.width` => `resize: { width }`) breaks the translations.
55
+ const { translations, ...rest } = config || {};
56
+ this.config = new Config(rest, this.constructor.defaultConfig);
54
57
  const availablePlugins = this.constructor.builtinPlugins;
55
58
  this.config.define('plugins', availablePlugins);
56
59
  this.plugins = new PluginCollection(this, availablePlugins);
57
60
  const languageConfig = this.config.get('language') || {};
58
61
  this.locale = new Locale({
59
62
  uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
60
- contentLanguage: this.config.get('language.content')
63
+ contentLanguage: this.config.get('language.content'),
64
+ translations
61
65
  });
62
66
  this.t = this.locale.t;
63
67
  this.editors = new Collection();
@@ -12,6 +12,7 @@ import Context from '../context.js';
12
12
  import PluginCollection from '../plugincollection.js';
13
13
  import CommandCollection, { type CommandsMap } from '../commandcollection.js';
14
14
  import EditingKeystrokeHandler from '../editingkeystrokehandler.js';
15
+ import Accessibility from '../accessibility.js';
15
16
  import type { LoadedPlugins, PluginConstructor } from '../plugin.js';
16
17
  import type { EditorConfig } from './editorconfig.js';
17
18
  declare const Editor_base: {
@@ -37,6 +38,10 @@ declare const Editor_base: {
37
38
  * (as most editor implementations do).
38
39
  */
39
40
  export default abstract class Editor extends Editor_base {
41
+ /**
42
+ * A namespace for the accessibility features of the editor.
43
+ */
44
+ readonly accessibility: Accessibility;
40
45
  /**
41
46
  * Commands registered to the editor.
42
47
  *
@@ -314,6 +319,62 @@ export default abstract class Editor extends Editor_base {
314
319
  * @param lockId The lock ID for setting the editor to the read-only state.
315
320
  */
316
321
  disableReadOnlyMode(lockId: string | symbol): void;
322
+ /**
323
+ * Sets the data in the editor.
324
+ *
325
+ * ```ts
326
+ * editor.setData( '<p>This is editor!</p>' );
327
+ * ```
328
+ *
329
+ * If your editor implementation uses multiple roots, you should pass an object with keys corresponding
330
+ * to the editor root names and values equal to the data that should be set in each root:
331
+ *
332
+ * ```ts
333
+ * editor.setData( {
334
+ * header: '<p>Content for header part.</p>',
335
+ * content: '<p>Content for main part.</p>',
336
+ * footer: '<p>Content for footer part.</p>'
337
+ * } );
338
+ * ```
339
+ *
340
+ * By default the editor accepts HTML. This can be controlled by injecting a different data processor.
341
+ * See the {@glink features/markdown Markdown output} guide for more details.
342
+ *
343
+ * @param data Input data.
344
+ */
345
+ setData(data: string | Record<string, string>): void;
346
+ /**
347
+ * Gets the data from the editor.
348
+ *
349
+ * ```ts
350
+ * editor.getData(); // -> '<p>This is editor!</p>'
351
+ * ```
352
+ *
353
+ * If your editor implementation uses multiple roots, you should pass root name as one of the options:
354
+ *
355
+ * ```ts
356
+ * editor.getData( { rootName: 'header' } ); // -> '<p>Content for header part.</p>'
357
+ * ```
358
+ *
359
+ * By default, the editor outputs HTML. This can be controlled by injecting a different data processor.
360
+ * See the {@glink features/markdown Markdown output} guide for more details.
361
+ *
362
+ * 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
363
+ * be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.
364
+ *
365
+ * @param options Additional configuration for the retrieved data.
366
+ * Editor features may introduce more configuration options that can be set through this parameter.
367
+ * @param options.rootName Root name. Defaults to `'main'`.
368
+ * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
369
+ * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
370
+ * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
371
+ * @returns Output data.
372
+ */
373
+ getData(options?: {
374
+ rootName?: string;
375
+ trim?: 'empty' | 'none';
376
+ [key: string]: unknown;
377
+ }): string;
317
378
  /**
318
379
  * Loads and initializes plugins specified in the configuration.
319
380
  *
@@ -11,6 +11,7 @@ import Context from '../context.js';
11
11
  import PluginCollection from '../plugincollection.js';
12
12
  import CommandCollection from '../commandcollection.js';
13
13
  import EditingKeystrokeHandler from '../editingkeystrokehandler.js';
14
+ import Accessibility from '../accessibility.js';
14
15
  /**
15
16
  * The class representing a basic, generic editor.
16
17
  *
@@ -40,14 +41,18 @@ export default class Editor extends ObservableMixin() {
40
41
  constructor(config = {}) {
41
42
  super();
42
43
  const constructor = this.constructor;
44
+ // We don't pass translations to the config, because its behavior of splitting keys
45
+ // with dots (e.g. `resize.width` => `resize: { width }`) breaks the translations.
46
+ const { translations: defaultTranslations, ...defaultConfig } = constructor.defaultConfig || {};
47
+ const { translations = defaultTranslations, ...rest } = config;
43
48
  // 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 });
49
+ const language = config.language || defaultConfig.language;
50
+ this._context = config.context || new Context({ language, translations });
46
51
  this._context._addEditor(this, !config.context);
47
52
  // Clone the plugins to make sure that the plugin array will not be shared
48
53
  // between editors and make the watchdog feature work correctly.
49
54
  const availablePlugins = Array.from(constructor.builtinPlugins || []);
50
- this.config = new Config(config, constructor.defaultConfig);
55
+ this.config = new Config(rest, defaultConfig);
51
56
  this.config.define('plugins', availablePlugins);
52
57
  this.config.define(this._context._getEditorConfig());
53
58
  this.plugins = new PluginCollection(this, availablePlugins, this._context.plugins);
@@ -71,6 +76,7 @@ export default class Editor extends ObservableMixin() {
71
76
  this.conversion.addAlias('editingDowncast', this.editing.downcastDispatcher);
72
77
  this.keystrokes = new EditingKeystrokeHandler(this);
73
78
  this.keystrokes.listenTo(this.editing.view.document);
79
+ this.accessibility = new Accessibility(this);
74
80
  }
75
81
  /**
76
82
  * Defines whether the editor is in the read-only mode.
@@ -202,6 +208,62 @@ export default class Editor extends ObservableMixin() {
202
208
  this.fire('change:isReadOnly', 'isReadOnly', false, true);
203
209
  }
204
210
  }
211
+ /**
212
+ * Sets the data in the editor.
213
+ *
214
+ * ```ts
215
+ * editor.setData( '<p>This is editor!</p>' );
216
+ * ```
217
+ *
218
+ * If your editor implementation uses multiple roots, you should pass an object with keys corresponding
219
+ * to the editor root names and values equal to the data that should be set in each root:
220
+ *
221
+ * ```ts
222
+ * editor.setData( {
223
+ * header: '<p>Content for header part.</p>',
224
+ * content: '<p>Content for main part.</p>',
225
+ * footer: '<p>Content for footer part.</p>'
226
+ * } );
227
+ * ```
228
+ *
229
+ * By default the editor accepts HTML. This can be controlled by injecting a different data processor.
230
+ * See the {@glink features/markdown Markdown output} guide for more details.
231
+ *
232
+ * @param data Input data.
233
+ */
234
+ setData(data) {
235
+ this.data.set(data);
236
+ }
237
+ /**
238
+ * Gets the data from the editor.
239
+ *
240
+ * ```ts
241
+ * editor.getData(); // -> '<p>This is editor!</p>'
242
+ * ```
243
+ *
244
+ * If your editor implementation uses multiple roots, you should pass root name as one of the options:
245
+ *
246
+ * ```ts
247
+ * editor.getData( { rootName: 'header' } ); // -> '<p>Content for header part.</p>'
248
+ * ```
249
+ *
250
+ * By default, the editor outputs HTML. This can be controlled by injecting a different data processor.
251
+ * See the {@glink features/markdown Markdown output} guide for more details.
252
+ *
253
+ * 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
254
+ * be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.
255
+ *
256
+ * @param options Additional configuration for the retrieved data.
257
+ * Editor features may introduce more configuration options that can be set through this parameter.
258
+ * @param options.rootName Root name. Defaults to `'main'`.
259
+ * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
260
+ * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
261
+ * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
262
+ * @returns Output data.
263
+ */
264
+ getData(options) {
265
+ return this.data.get(options);
266
+ }
205
267
  /**
206
268
  * Loads and initializes plugins specified in the configuration.
207
269
  *
@@ -5,6 +5,7 @@
5
5
  /**
6
6
  * @module core/editor/editorconfig
7
7
  */
8
+ import type { ArrayOrItem, Translations } from '@ckeditor/ckeditor5-utils';
8
9
  import type Context from '../context.js';
9
10
  import type { PluginConstructor } from '../plugin.js';
10
11
  import type Editor from './editor.js';
@@ -519,6 +520,10 @@ export interface EditorConfig {
519
520
  * [order a trial](https://orders.ckeditor.com/trial/premium-features).
520
521
  */
521
522
  licenseKey?: string;
523
+ /**
524
+ * Translations to be used in the editor.
525
+ */
526
+ translations?: ArrayOrItem<Translations>;
522
527
  }
523
528
  /**
524
529
  * The `config.initialData` option cannot be used together with the initial data passed as the first parameter of
@@ -6,11 +6,13 @@
6
6
  * @module core/editor/utils/dataapimixin
7
7
  */
8
8
  import type Editor from '../editor.js';
9
- import type { Constructor, Mixed } from '@ckeditor/ckeditor5-utils';
9
+ import type { Constructor } from '@ckeditor/ckeditor5-utils';
10
10
  /**
11
11
  * Implementation of the {@link module:core/editor/utils/dataapimixin~DataApi}.
12
+ *
13
+ * @deprecated This functionality is already implemented by the `Editor` class.
12
14
  */
13
- export default function DataApiMixin<Base extends Constructor<Editor>>(base: Base): Mixed<Base, DataApi>;
15
+ export default function DataApiMixin<Base extends Constructor<Editor>>(base: Base): Base;
14
16
  /**
15
17
  * Interface defining editor methods for setting and getting data to and from the editor's main root element
16
18
  * using the {@link module:core/editor/editor~Editor#data data pipeline}.
@@ -18,6 +20,8 @@ export default function DataApiMixin<Base extends Constructor<Editor>>(base: Bas
18
20
  * This interface is not a part of the {@link module:core/editor/editor~Editor} class because one may want to implement
19
21
  * an editor with multiple root elements, in which case the methods for setting and getting data will need to be implemented
20
22
  * differently.
23
+ *
24
+ * @deprecated This interface is implemented by all `Editor` instances by default.
21
25
  */
22
26
  export interface DataApi {
23
27
  /**
@@ -4,21 +4,9 @@
4
4
  */
5
5
  /**
6
6
  * Implementation of the {@link module:core/editor/utils/dataapimixin~DataApi}.
7
+ *
8
+ * @deprecated This functionality is already implemented by the `Editor` class.
7
9
  */
8
10
  export default function DataApiMixin(base) {
9
- class Mixin extends base {
10
- setData(data) {
11
- this.data.set(data);
12
- }
13
- getData(options) {
14
- return this.data.get(options);
15
- }
16
- }
17
- return Mixin;
18
- }
19
- // Backward compatibility with `mix`.
20
- {
21
- const mixin = DataApiMixin(Object);
22
- DataApiMixin.setData = mixin.prototype.setData;
23
- DataApiMixin.getData = mixin.prototype.getData;
11
+ return base;
24
12
  }
package/src/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export type { PluginsMap, default as PluginCollection } from './plugincollection
13
13
  export { default as Context, type ContextConfig } from './context.js';
14
14
  export { default as ContextPlugin, type ContextPluginDependencies } from './contextplugin.js';
15
15
  export { type EditingKeystrokeCallback } from './editingkeystrokehandler.js';
16
+ export type { PartialBy } from './typings.js';
16
17
  export { default as Editor, type EditorReadyEvent, type EditorDestroyEvent } from './editor/editor.js';
17
18
  export type { EditorConfig, LanguageConfig, ToolbarConfig, ToolbarConfigItem, UiConfig } from './editor/editorconfig.js';
18
19
  export { default as attachToForm } from './editor/utils/attachtoform.js';
@@ -20,6 +21,7 @@ export { default as DataApiMixin, type DataApi } from './editor/utils/dataapimix
20
21
  export { default as ElementApiMixin, type ElementApi } from './editor/utils/elementapimixin.js';
21
22
  export { default as secureSourceElement } from './editor/utils/securesourceelement.js';
22
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';
23
25
  export declare const icons: {
24
26
  bold: string;
25
27
  cancel: string;
@@ -0,0 +1,8 @@
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/typings
7
+ */
8
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
package/src/typings.js ADDED
@@ -0,0 +1,5 @@
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
+ export {};