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/editor/editorconfig
|
7 | */
|
8 | import type { ArrayOrItem, Translations } from '@ckeditor/ckeditor5-utils';
|
9 | import type Context from '../context.js';
|
10 | import type { PluginConstructor } from '../plugin.js';
|
11 | import type Editor from './editor.js';
|
12 | import type { MenuBarConfig } from '@ckeditor/ckeditor5-ui';
|
13 | /**
|
14 | * CKEditor configuration options.
|
15 | *
|
16 | * An object defining the editor configuration can be passed when initializing the editor:
|
17 | *
|
18 | * ```ts
|
19 | * EditorClass
|
20 | * .create( {
|
21 | * toolbar: [ 'bold', 'italic' ],
|
22 | * image: {
|
23 | * styles: [
|
24 | * ...
|
25 | * ]
|
26 | * }
|
27 | * } )
|
28 | * .then( ... )
|
29 | * .catch( ... );
|
30 | * ```
|
31 | */
|
32 | export interface EditorConfig {
|
33 | context?: Context;
|
34 | /**
|
35 | * The list of additional plugins to load along those already available in the
|
36 | * editor. It extends the {@link #plugins `plugins`} configuration.
|
37 | *
|
38 | * ```ts
|
39 | * function MyPlugin( editor ) {
|
40 | * // ...
|
41 | * }
|
42 | *
|
43 | * const config = {
|
44 | * extraPlugins: [ MyPlugin ]
|
45 | * };
|
46 | * ```
|
47 | *
|
48 | * **Note:** This configuration works only for simple plugins which utilize the
|
49 | * {@link module:core/plugin~PluginInterface plugin interface} and have no dependencies. To extend a
|
50 | * build with complex features, try [CKEditr 5 Builder](https://ckeditor.com/ckeditor-5/builder?redirect=docs).
|
51 | *
|
52 | * **Note:** Make sure you include the new features in you toolbar configuration. Learn more
|
53 | * about the {@glink getting-started/setup/toolbar toolbar setup}.
|
54 | */
|
55 | extraPlugins?: Array<PluginConstructor<Editor>>;
|
56 | /**
|
57 | * The initial editor data to be used instead of the provided element's HTML content.
|
58 | *
|
59 | * ```ts
|
60 | * ClassicEditor
|
61 | * .create( document.querySelector( '#editor' ), {
|
62 | * initialData: '<h2>Initial data</h2><p>Foo bar.</p>'
|
63 | * } )
|
64 | * .then( ... )
|
65 | * .catch( ... );
|
66 | * ```
|
67 | *
|
68 | * By default, the editor is initialized with the content of the element on which this editor is initialized.
|
69 | * This configuration option lets you override this behavior and pass different initial data.
|
70 | * It is especially useful if it is difficult for your integration to put the data inside the HTML element.
|
71 | *
|
72 | * If your editor implementation uses multiple roots, you should pass an object with keys corresponding to the editor
|
73 | * roots names and values equal to the data that should be set in each root:
|
74 | *
|
75 | * ```ts
|
76 | * MultiRootEditor.create(
|
77 | * // Roots for the editor:
|
78 | * {
|
79 | * header: document.querySelector( '#header' ),
|
80 | * content: document.querySelector( '#content' ),
|
81 | * leftSide: document.querySelector( '#left-side' ),
|
82 | * rightSide: document.querySelector( '#right-side' )
|
83 | * },
|
84 | * // Config:
|
85 | * {
|
86 | * initialData: {
|
87 | * header: '<p>Content for header part.</p>',
|
88 | * content: '<p>Content for main part.</p>',
|
89 | * leftSide: '<p>Content for left-side box.</p>',
|
90 | * rightSide: '<p>Content for right-side box.</p>'
|
91 | * }
|
92 | * }
|
93 | * )
|
94 | * .then( ... )
|
95 | * .catch( ... );
|
96 | * ```
|
97 | *
|
98 | * See also {@link module:core/editor/editor~Editor.create Editor.create()} documentation for the editor implementation which you use.
|
99 | *
|
100 | * **Note:** If initial data is passed to `Editor.create()` in the first parameter (instead of a DOM element), and,
|
101 | * at the same time, `config.initialData` is set, an error will be thrown as those two options exclude themselves.
|
102 | *
|
103 | * If `config.initialData` is not set when the editor is initialized, the data received in `Editor.create()` call
|
104 | * will be used to set `config.initialData`. As a result, `initialData` is always set in the editor's config and
|
105 | * plugins can read and/or modify it during initialization.
|
106 | */
|
107 | initialData?: string | Record<string, string>;
|
108 | /**
|
109 | * The language of the editor UI and its content.
|
110 | *
|
111 | * Simple usage (change the language of the UI and the content):
|
112 | *
|
113 | * ```ts
|
114 | * ClassicEditor
|
115 | * .create( document.querySelector( '#editor' ), {
|
116 | * // The UI of the editor as well as its content will be in German.
|
117 | * language: 'de'
|
118 | * } )
|
119 | * .then( editor => {
|
120 | * console.log( editor );
|
121 | * } )
|
122 | * .catch( error => {
|
123 | * console.error( error );
|
124 | * } );
|
125 | * ```
|
126 | *
|
127 | * Use different languages for the UI and the content using the {@link module:core/editor/editorconfig~LanguageConfig configuration}
|
128 | * syntax:
|
129 | *
|
130 | * ```ts
|
131 | * ClassicEditor
|
132 | * .create( document.querySelector( '#editor' ), {
|
133 | * language: {
|
134 | * // The UI will be in English.
|
135 | * ui: 'en',
|
136 | *
|
137 | * // But the content will be edited in Arabic.
|
138 | * content: 'ar'
|
139 | * }
|
140 | * } )
|
141 | * .then( editor => {
|
142 | * console.log( editor );
|
143 | * } )
|
144 | * .catch( error => {
|
145 | * console.error( error );
|
146 | * } );
|
147 | * ```
|
148 | *
|
149 | * The language of the content has an impact on the editing experience, for instance it affects screen readers
|
150 | * and spell checkers. It is also particularly useful for typing in certain languages (e.g. right–to–left ones)
|
151 | * because it changes the default alignment of the text.
|
152 | *
|
153 | * The language codes are defined in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) standard.
|
154 | *
|
155 | * You need to add the corresponding translation file for the new UI language to work.
|
156 | * Translation files are available on CDN:
|
157 | *
|
158 | * ```html
|
159 | * <script type="importmap">
|
160 | * {
|
161 | * "imports": {
|
162 | * "ckeditor5": "https://cdn.ckeditor.com/ckeditor5/<VERSION>/ckeditor5.js",
|
163 | * "ckeditor5/": "https://cdn.ckeditor.com/ckeditor5/<VERSION>/"
|
164 | * }
|
165 | * }
|
166 | * </script>
|
167 | * <script type="module">
|
168 | * import { ClassicEditor, Essentials, Paragraph } from 'ckeditor5';
|
169 | * import translations from 'ckeditor5/dist/translations/pl.js';
|
170 | *
|
171 | * await ClassicEditor.create( document.querySelector( '#editor' ), {
|
172 | * plugins: [
|
173 | * Essentials,
|
174 | * Paragraph,
|
175 | * ],
|
176 | * toolbar: {
|
177 | * items: [ 'undo', 'redo' ]
|
178 | * },
|
179 | * translations
|
180 | * } );
|
181 | * </script>
|
182 | * ```
|
183 | *
|
184 | * You can add translation using NPM as well.
|
185 | *
|
186 | * ```html
|
187 | * import { ClassicEditor, Essentials, Paragraph } from 'ckeditor5';
|
188 | * import translations from 'ckeditor5/dist/translations/pl.js';
|
189 | *
|
190 | * import 'ckeditor5/dist/styles.css';
|
191 | *
|
192 | * await ClassicEditor.create( document.querySelector( '#editor' ), {
|
193 | * plugins: [
|
194 | * Essentials,
|
195 | * Paragraph,
|
196 | * ],
|
197 | * toolbar: {
|
198 | * items: [ 'undo', 'redo' ]
|
199 | * },
|
200 | * translations
|
201 | * } );
|
202 | * ```
|
203 | *
|
204 | * Check the {@glink getting-started/setup/ui-language UI language} guide for more information about
|
205 | * the localization options and translation process.
|
206 | */
|
207 | language?: string | LanguageConfig;
|
208 | /**
|
209 | * The editor menu bar configuration.
|
210 | *
|
211 | * **Note**: The menu bar is not available in all editor types. Currently, only the
|
212 | * {@link module:editor-classic/classiceditor~ClassicEditor Classic editor} and
|
213 | * {@link module:editor-decoupled/decouplededitor~DecoupledEditor Decoupled editor}
|
214 | * support this feature. Setting the `config.menuBar` configuration for other editor types will have no effect.
|
215 | *
|
216 | * In Classic editor, the menu bar is hidden by default. Set the `isVisible` configuration flag to `true` in order to show it:
|
217 | *
|
218 | * ```ts
|
219 | * ClassicEditor
|
220 | * .create( document.querySelector( '#editor' ), {
|
221 | * menuBar: {
|
222 | * isVisible: true
|
223 | * }
|
224 | * } )
|
225 | * .then( ... );
|
226 | * ```
|
227 | *
|
228 | * When using the Decoupled editor, you will need to insert the menu bar in a desired place yourself. For example:
|
229 | *
|
230 | * ```ts
|
231 | * DecoupledEditor
|
232 | * .create( document.querySelector( '#editor' ), {
|
233 | * toolbar: [ 'undo', 'redo', 'bold', 'italic', 'numberedList', 'bulletedList' ],
|
234 | * } )
|
235 | * .then( editor => {
|
236 | * document.getElementById( '#menuBarContainer' ).appendChild( editor.ui.view.menuBarView.element );
|
237 | * } );
|
238 | * ```
|
239 | *
|
240 | * **Note**: You do not have to set the `items` property in this configuration in order to use the menu bar.
|
241 | * By default, a {@link module:ui/menubar/utils#DefaultMenuBarItems default set of items} is used that already includes
|
242 | * **all core editor features**. For your convenience, there are `config.menuBar.addItems` and
|
243 | * `config.menuBar.removeItems` options available that will help you adjust the default configuration without setting the
|
244 | * entire menu bar structure from scratch (see below).
|
245 | *
|
246 | * **Removing items from the menu bar**
|
247 | *
|
248 | * You can use the `config.menuBar.removeItems` option to remove items from the default menu bar configuration. You can
|
249 | * remove individual buttons (e.g. "Bold" or "Block quote"), item groups (e.g. the basic styles section that
|
250 | * includes multiple buttons such as "Bold", "Italic", "Underline", etc.), or whole menus (e.g. the "Insert" menu). Please
|
251 | * refer to the {@link module:ui/menubar/utils#DefaultMenuBarItems default configuration} to see default buttons/groups/menus
|
252 | * and their structure.
|
253 | *
|
254 | * To remove individual buttons from the menu bar:
|
255 | *
|
256 | * ```ts
|
257 | * ClassicEditor
|
258 | * .create( document.querySelector( '#editor' ), {
|
259 | * menuBar: {
|
260 | * // Removes "Bold" and "Block quote" buttons from their respective menus.
|
261 | * removeItems: [ 'menuBar:bold', 'menuBar:blockQuote' ]
|
262 | * }
|
263 | * } )
|
264 | * .then( ... );
|
265 | * ```
|
266 | *
|
267 | * To remove a group of buttons from the menu bar:
|
268 | *
|
269 | * ```ts
|
270 | * ClassicEditor
|
271 | * .create( document.querySelector( '#editor' ), {
|
272 | * menuBar: {
|
273 | * // Removes the entire basic styles group ("Bold", "Italic", "Underline", etc.) from the "Format" menu.
|
274 | * removeItems: [ 'basicStyles' ]
|
275 | * }
|
276 | * } )
|
277 | * .then( ... );
|
278 | * ```
|
279 | *
|
280 | * To remove a menu from the menu bar:
|
281 | *
|
282 | * ```ts
|
283 | * ClassicEditor
|
284 | * .create( document.querySelector( '#editor' ), {
|
285 | * menuBar: {
|
286 | * // Removes the whole top-level "Insert" menu from the menu bar.
|
287 | * removeItems: [ 'insert' ]
|
288 | * }
|
289 | * } )
|
290 | * .then( ... );
|
291 | * ```
|
292 | *
|
293 | * **Adding items to the menu bar**
|
294 | *
|
295 | * Using the `config.menuBar.addItems` option you can add individual buttons, button groups or entire menus to the structure
|
296 | * of the menu bar. You can add existing components that you removed from their original position, or add your own components.
|
297 | *
|
298 | * **Note**: When adding items please make sure that features (editor plugins) that bring specific menu bar items are loaded.
|
299 | * For instance, the "Bold" button will not show up in the menu bar unless the {@glink features/basic-styles basic styles} feature is
|
300 | * loaded. {@link module:core/editor/editorconfig~EditorConfig#plugins Learn more} about loading plugins.
|
301 | *
|
302 | * Each entry in the `config.menuBar.addItems` is an object with one of the following properties:
|
303 | *
|
304 | * * `item` – A name of the button to be added to a specific button group (e.g. `'menuBar:bold'` or `'myButton'`),
|
305 | * * `menu` – A {@link module:ui/menubar/menubarview#MenuBarMenuDefinition definition of a menu} that should be added to
|
306 | * the menu bar,
|
307 | * * `group` – A {@link module:ui/menubar/menubarview#MenuBarMenuGroupDefinition definition of a button group} that should be
|
308 | * added to a specific menu.
|
309 | *
|
310 | * Additionally, each entry must define the `position` property that accepts the following values:
|
311 | * * `'start'` – Adds a top-level menu (e.g. "Format", "Insert", etc.) at the beginning of the menu bar,
|
312 | * * `'start:GROUP_OR_MENU'` – Adds a button/group at the beginning of the specific group/menu,
|
313 | * * `'end'` – Adds a top-level menu (e.g. "Format", "Insert", etc.) at the end of the menu bar,
|
314 | * * `'end:GROUP_OR_MENU'` – Adds a button/group at the end of the specific group/menu,
|
315 | * * `'after:BUTTON_OR_GROUP_OR_MENU'` – Adds a button/group/menu right after the specific button/group/menu,
|
316 | * * `'before:BUTTON_OR_GROUP_OR_MENU'` – Adds a button/group/menu right after the specific button/group/menu.
|
317 | *
|
318 | * Please refer to the {@link module:ui/menubar/utils#DefaultMenuBarItems default configuration} to learn about the
|
319 | * names of buttons and positions they can be added at.
|
320 | *
|
321 | * To add a new top-level menu with specific buttons at the end of the menu bar:
|
322 | *
|
323 | * ```ts
|
324 | * ClassicEditor
|
325 | * .create( document.querySelector( '#editor' ), {
|
326 | * menuBar: {
|
327 | * addItems: [
|
328 | * {
|
329 | * menu: {
|
330 | * menuId: 'my-menu',
|
331 | * label: 'My menu',
|
332 | * groups: [
|
333 | * {
|
334 | * groupId: 'my-buttons',
|
335 | * items: [
|
336 | * 'menuBar:bold',
|
337 | * 'menuBar:italic',
|
338 | * 'menuBar:underline'
|
339 | * ]
|
340 | * }
|
341 | * ]
|
342 | * },
|
343 | * position: 'end'
|
344 | * }
|
345 | * ]
|
346 | * }
|
347 | * } )
|
348 | * .then( ... );
|
349 | * ```
|
350 | *
|
351 | * To add a new group of buttons to the "Format" menu after basic styles buttons ("Bold", "Italic", "Underline", etc.):
|
352 | *
|
353 | * ```ts
|
354 | * ClassicEditor
|
355 | * .create( document.querySelector( '#editor' ), {
|
356 | * menuBar: {
|
357 | * addItems: [
|
358 | * {
|
359 | * group: {
|
360 | * groupId: 'my-buttons',
|
361 | * items: [
|
362 | * 'myButton1',
|
363 | * 'myButton2',
|
364 | * ]
|
365 | * },
|
366 | * position: 'after:basicStyles'
|
367 | * }
|
368 | * ]
|
369 | * }
|
370 | * } )
|
371 | * .then( ... );
|
372 | * ```
|
373 | *
|
374 | * To add a new button to the basic styles group ("Bold", "Italic", "Underline", etc.) in the "Format" menu:
|
375 | *
|
376 | * ```ts
|
377 | * ClassicEditor
|
378 | * .create( document.querySelector( '#editor' ), {
|
379 | * menuBar: {
|
380 | * addItems: [
|
381 | * {
|
382 | * item: 'myButton',
|
383 | * position: 'end:basicStyles'
|
384 | * }
|
385 | * ]
|
386 | * }
|
387 | * } )
|
388 | * .then( ... );
|
389 | * ```
|
390 | *
|
391 | * To add a new sub-menu in the "Format" menu:
|
392 | *
|
393 | * ```ts
|
394 | * ClassicEditor
|
395 | * .create( document.querySelector( '#editor' ), {
|
396 | * menuBar: {
|
397 | * addItems: [
|
398 | * {
|
399 | * menu: {
|
400 | * menuId: 'my-sub-menu',
|
401 | * label: 'My sub-menu',
|
402 | * groups: [
|
403 | * {
|
404 | * groupId: 'my-buttons',
|
405 | * items: [
|
406 | * 'myButton1',
|
407 | * 'myButton2',
|
408 | * ]
|
409 | * }
|
410 | * ]
|
411 | * },
|
412 | * position: 'after:basicStyles'
|
413 | * }
|
414 | * ]
|
415 | * }
|
416 | * } )
|
417 | * .then( ... );
|
418 | * ```
|
419 | *
|
420 | * **Defining menu bar from scratch**
|
421 | *
|
422 | * If the `config.menuBar.addItems` and `config.menuBar.removeItems` options are not enough to adjust the
|
423 | * {@link module:ui/menubar/utils#DefaultMenuBarItems default configuration}, you can set the menu bar structure from scratch.
|
424 | *
|
425 | * For instance, to create a minimalistic menu bar configuration with just two main categories (menus), use the following code snippet:
|
426 | *
|
427 | * ```ts
|
428 | * ClassicEditor
|
429 | * .create( document.querySelector( '#editor' ), {
|
430 | * menuBar: {
|
431 | * items: [
|
432 | * {
|
433 | * menuId: 'formatting',
|
434 | * label: 'Formatting',
|
435 | * groups: [
|
436 | * {
|
437 | * groupId: 'basicStyles',
|
438 | * items: [
|
439 | * 'menuBar:bold',
|
440 | * 'menuBar:italic',
|
441 | * ]
|
442 | * },
|
443 | * {
|
444 | * groupId: 'misc',
|
445 | * items: [
|
446 | * 'menuBar:heading',
|
447 | * 'menuBar:bulletedList',
|
448 | * 'menuBar:numberedList'
|
449 | * ]
|
450 | * }
|
451 | * ]
|
452 | * },
|
453 | * {
|
454 | * menuId: 'myButtons',
|
455 | * label: 'My actions',
|
456 | * groups: [
|
457 | * {
|
458 | * groupId: 'undo',
|
459 | * items: [
|
460 | * 'myButton1',
|
461 | * 'myButton2'
|
462 | * ]
|
463 | * }
|
464 | * ]
|
465 | * }
|
466 | * ]
|
467 | * }
|
468 | * } )
|
469 | * .then( ... );
|
470 | * ```
|
471 | */
|
472 | menuBar?: MenuBarConfig;
|
473 | /**
|
474 | * Specifies the text displayed in the editor when there is no content (editor is empty). It is intended to
|
475 | * help users locate the editor in the application (form) and prompt them to input the content. Work similarly
|
476 | * as to the native DOM
|
477 | * [`placeholder` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#The_placeholder_attribute)
|
478 | * used by inputs.
|
479 | *
|
480 | * ```ts
|
481 | * ClassicEditor
|
482 | * .create( document.querySelector( '#editor' ), {
|
483 | * placeholder: 'Type some text...'
|
484 | * } )
|
485 | * .then( ... )
|
486 | * .catch( ... );
|
487 | * ```
|
488 | *
|
489 | * If your editor implementation uses multiple roots, you should pass an object with keys corresponding to the editor
|
490 | * roots names and values equal to the placeholder that should be set in each root:
|
491 | *
|
492 | * ```ts
|
493 | * MultiRootEditor.create(
|
494 | * // Roots for the editor:
|
495 | * {
|
496 | * header: document.querySelector( '#header' ),
|
497 | * content: document.querySelector( '#content' ),
|
498 | * leftSide: document.querySelector( '#left-side' ),
|
499 | * rightSide: document.querySelector( '#right-side' )
|
500 | * },
|
501 | * // Config:
|
502 | * {
|
503 | * placeholder: {
|
504 | * header: 'Type header...',
|
505 | * content: 'Type content...',
|
506 | * leftSide: 'Type left-side...',
|
507 | * rightSide: 'Type right-side...'
|
508 | * }
|
509 | * }
|
510 | * )
|
511 | * .then( ... )
|
512 | * .catch( ... );
|
513 | * ```
|
514 | *
|
515 | * The placeholder text is displayed as a pseudo–element of an empty paragraph in the editor content.
|
516 | * The paragraph has the `.ck-placeholder` CSS class and the `data-placeholder` attribute.
|
517 | *
|
518 | * ```html
|
519 | * <p data-placeholder="Type some text..." class="ck-placeholder">
|
520 | * ::before
|
521 | * </p>
|
522 | * ```
|
523 | *
|
524 | * **Note**: Placeholder text can also be set using the `placeholder` attribute if a `<textarea>` is passed to
|
525 | * the `create()` method, e.g. {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`}.
|
526 | *
|
527 | * **Note**: This configuration has precedence over the value of the `placeholder` attribute of a `<textarea>`
|
528 | * element passed to the `create()` method.
|
529 | *
|
530 | * See the {@glink features/editor-placeholder "Editor placeholder"} guide for more information and live examples.
|
531 | */
|
532 | placeholder?: string | Record<string, string>;
|
533 | /**
|
534 | * The list of plugins to load.
|
535 | *
|
536 | * ```ts
|
537 | * import {
|
538 | * // A preset of plugins is a plugin as well.
|
539 | * Essentials,
|
540 | * // The bold plugin.
|
541 | * Bold
|
542 | * } from 'ckeditor5';
|
543 | *
|
544 | * const config = {
|
545 | * plugins: [ Essentials, Bold ]
|
546 | * };
|
547 | * ```
|
548 | *
|
549 | * **Note:** To load additional plugins, you should use the {@link #extraPlugins `extraPlugins`} configuration.
|
550 | * To narrow the list of loaded plugins, use the {@link #removePlugins `removePlugins`} configuration.
|
551 | */
|
552 | plugins?: Array<PluginConstructor<Editor> | string>;
|
553 | /**
|
554 | * The list of plugins which should not be loaded despite being available in
|
555 | * the editor.
|
556 | *
|
557 | * ```ts
|
558 | * const config = {
|
559 | * removePlugins: [ 'Bold', 'Italic' ]
|
560 | * };
|
561 | * ```
|
562 | *
|
563 | * **Note:** Be careful when removing plugins using `config.removePlugins`.
|
564 | * If removed plugins were providing toolbar buttons, the default toolbar configuration included in a build
|
565 | * will become invalid. In such case you need to provide the updated
|
566 | * {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar configuration}.
|
567 | */
|
568 | removePlugins?: Array<PluginConstructor<Editor> | string>;
|
569 | substitutePlugins?: Array<PluginConstructor<Editor>>;
|
570 | /**
|
571 | * The editor toolbar configuration.
|
572 | *
|
573 | * Simple format (specifies only toolbar items):
|
574 | *
|
575 | * ```ts
|
576 | * const config = {
|
577 | * toolbar: [ 'bold', 'italic', '|', 'undo', 'redo' ]
|
578 | * };
|
579 | * ```
|
580 | *
|
581 | * Extended format:
|
582 | *
|
583 | * ```ts
|
584 | * const config = {
|
585 | * toolbar: {
|
586 | * items: [ 'bold', 'italic', '|', 'undo', 'redo', '-', 'numberedList', 'bulletedList' ],
|
587 | *
|
588 | * shouldNotGroupWhenFull: true
|
589 | * }
|
590 | * };
|
591 | * ```
|
592 | *
|
593 | * Options which can be set using the extended format:
|
594 | *
|
595 | * * **`toolbar.items`** – An array of toolbar item names. The components (buttons, dropdowns, etc.) which can be used
|
596 | * as toolbar items are defined in `editor.ui.componentFactory` and can be listed using the following snippet:
|
597 | *
|
598 | * ```ts
|
599 | * Array.from( editor.ui.componentFactory.names() );
|
600 | * ```
|
601 | *
|
602 | * You can also use `'|'` to create a separator between groups of items:
|
603 | *
|
604 | * ```
|
605 | * toolbar: [ 'bold', 'italic', '|', 'undo', 'redo' ]
|
606 | * ```
|
607 | *
|
608 | * or `'-'` to make a line break and render items in multiple lines:
|
609 | *
|
610 | * ```
|
611 | * toolbar: [ 'bold', 'italic', '-', 'undo', 'redo' ]
|
612 | * ```
|
613 | *
|
614 | * Line break will work only in the extended format when `shouldNotGroupWhenFull` option is set to `true`.
|
615 | *
|
616 | * **Note**: To save space in your toolbar, you can group several items into a dropdown:
|
617 | *
|
618 | * ```
|
619 | * toolbar: [
|
620 | * {
|
621 | * label: 'Basic styles',
|
622 | * icon: 'text',
|
623 | * items: [ 'bold', 'italic', ... ]
|
624 | * },
|
625 | * '|',
|
626 | * 'undo', 'redo'
|
627 | * ]
|
628 | * ```
|
629 | *
|
630 | * The code above will create a "Basic styles" dropdown with a "text" icon containing the "bold" and "italic" buttons.
|
631 | * You can customize the look of the dropdown by setting the `withText`, `icon`, and `tooltip` properties:
|
632 | *
|
633 | * * **Displaying a label**
|
634 | *
|
635 | * For instance, to hide the icon and to display the label only, you can use the following configuration:
|
636 | *
|
637 | * ```ts
|
638 | * {
|
639 | * label: 'Basic styles',
|
640 | * // Show the textual label of the drop-down. Note that the "icon" property is not configured.
|
641 | * withText: true,
|
642 | * items: [ 'bold', 'italic', ... ]
|
643 | * }
|
644 | * ```
|
645 | *
|
646 | * * **Selecting an icon**
|
647 | *
|
648 | * You can use one of the common icons provided by the editor (`'bold'`, `'plus'`, `'text'`, `'importExport'`, `'alignLeft'`,
|
649 | * `'paragraph'`, `'threeVerticalDots'`, `'dragIndicator'`, `'pilcrow'`):
|
650 | *
|
651 | * ```ts
|
652 | * {
|
653 | * label: '...',
|
654 | * // A "plus" sign icon works best for content insertion tools.
|
655 | * icon: 'plus',
|
656 | * items: [ ... ]
|
657 | * }
|
658 | * ```
|
659 | *
|
660 | * If no icon is specified, `'threeVerticalDots'` will be used as a default:
|
661 | *
|
662 | * ```ts
|
663 | * // No icon specified, using a default one.
|
664 | * {
|
665 | * label: 'Default icon',
|
666 | * items: [ ... ]
|
667 | * }
|
668 | * ```
|
669 | *
|
670 | * If `icon: false` is configured, no icon will be displayed at all and the text label will show up instead:
|
671 | *
|
672 | * ```ts
|
673 | * // This drop-down has no icon. The text label will be displayed instead.
|
674 | * {
|
675 | * label: 'No icon',
|
676 | * icon: false,
|
677 | * items: [ ... ]
|
678 | * }
|
679 | * ```
|
680 | *
|
681 | * You can also set a custom icon for the drop-down by passing an SVG string:
|
682 | *
|
683 | * ```ts
|
684 | * {
|
685 | * label: '...',
|
686 | * // If you want your icon to change the color dynamically (e.g. when the dropdown opens), avoid fill="..."
|
687 | * // and stroke="..." styling attributes. Use solid shapes and avoid paths with strokes.
|
688 | * icon: '<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">...</svg>',
|
689 | * items: [ ... ]
|
690 | * }
|
691 | * ```
|
692 | *
|
693 | * * **Customizing the tooltip**
|
694 | *
|
695 | * By default, the tooltip of the button shares its text with the label. You can customize it to better describe your dropdown
|
696 | * using the `tooltip` property ({@link module:ui/button/buttonview~ButtonView#tooltip learn more}):
|
697 | *
|
698 | * ```ts
|
699 | * {
|
700 | * label: 'Drop-down label',
|
701 | * tooltip: 'Custom tooltip of the drop-down',
|
702 | * icon: '...',
|
703 | * items: [ ... ]
|
704 | * }
|
705 | * ```
|
706 | *
|
707 | * * **`toolbar.viewportTopOffset` (deprecated)** – The offset (in pixels) from the top of the viewport used when positioning a
|
708 | * sticky toolbar.
|
709 | * Useful when a page with which the editor is being integrated has some other sticky or fixed elements
|
710 | * (e.g. the top menu). Thanks to setting the toolbar offset the toolbar will not be positioned underneath or above the page's UI.
|
711 | *
|
712 | * **This property has been deprecated and will be removed in the future versions of CKEditor. Please use
|
713 | * `{@link module:core/editor/editorconfig~EditorConfig#ui EditorConfig#ui.viewportOffset}` instead.**
|
714 | *
|
715 | * * **`toolbar.shouldNotGroupWhenFull`** – When set to `true`, the toolbar will stop grouping items
|
716 | * and let them wrap to the next line if there is not enough space to display them in a single row.
|
717 | */
|
718 | toolbar?: ToolbarConfig;
|
719 | /**
|
720 | * The editor UI configuration.
|
721 | *
|
722 | * ```ts
|
723 | * ClassicEditor
|
724 | * .create( document.querySelector( '#editor' ), {
|
725 | * ui: { ... }
|
726 | * } )
|
727 | * .then( ... )
|
728 | * .catch( ... );
|
729 | * ```
|
730 | *
|
731 | * Options which can be set using the UI configuration:
|
732 | *
|
733 | * * **`ui.viewportOffset`** – The offset (in pixels) of the viewport from every direction. It is
|
734 | * used when positioning a sticky toolbar or other absolutely positioned UI elements.
|
735 | * Useful when a page with which the editor is being integrated has some other sticky or fixed elements
|
736 | * (e.g. the top menu). Thanks to setting the UI viewport offset, the toolbar and other contextual balloons will not be positioned
|
737 | * underneath or above the page's UI.
|
738 | *
|
739 | * ```ts
|
740 | * ui: {
|
741 | * viewportOffset: { top: 10, right: 10, bottom: 10, left: 10 }
|
742 | * }
|
743 | * ```
|
744 | *
|
745 | * **Note:** If you want to modify the viewport offset in runtime (after the editor was created), you can do that by overriding
|
746 | * {@link module:ui/editorui/editorui~EditorUI#viewportOffset `editor.ui.viewportOffset`}.
|
747 | *
|
748 | * * **`ui.poweredBy`** – The configuration of the project logo displayed over the editor's editing area in
|
749 | * open-source integrations. It allows customizing the position of the logo to minimize the risk of collision with the
|
750 | * editor content and UI.
|
751 | *
|
752 | * The following configuration properties are supported:
|
753 | *
|
754 | * * **`position`** – The position of the project's logo (default: `'border'`).
|
755 | * * When `'inside'`, the logo will be displayed within the boundaries of the editing area.
|
756 | * * When `'border'`, the logo will be displayed over the bottom border of the editing area.
|
757 | *
|
758 | * * **`side`** (`'left'` or `'right'`, default: `'right'`) – The side of the editing area where the
|
759 | * logo will be displayed.
|
760 | *
|
761 | * **Note**: If {@link module:core/editor/editorconfig~EditorConfig#language `config.language`} is set to an RTL (right-to-left)
|
762 | * language, the side switches to `'left'` by default.
|
763 | *
|
764 | * * **`label`** (default: `'Powered by'`) – The label displayed next to the project's logo.
|
765 | *
|
766 | * **Note**: Set the value to `null` to display the logo without any text.
|
767 | *
|
768 | * * **`verticalOffset`** (default: `5`) – The vertical distance the logo can be moved away from its default position.
|
769 | *
|
770 | * **Note**: If `position` is `'border'`, the offset is measured from the (vertical) center of the logo.
|
771 | *
|
772 | * * **`horizontalOffset`** (default: `5`) – The horizontal distance between the side of the editing root and the
|
773 | * nearest side of the logo.
|
774 | *
|
775 | * ```ts
|
776 | * ui: {
|
777 | * poweredBy: {
|
778 | * position: 'border',
|
779 | * side: 'left',
|
780 | * verticalOffset: 2,
|
781 | * horizontalOffset: 30
|
782 | * }
|
783 | * }
|
784 | */
|
785 | ui?: UiConfig;
|
786 | /**
|
787 | * Enables updating the source element after the editor is destroyed.
|
788 | *
|
789 | * Enabling this option might have some security implications, as the editor doesn't have control over all data
|
790 | * in the output.
|
791 | *
|
792 | * Be careful, especially while using the
|
793 | * {@glink features/markdown Markdown}, {@glink features/html/general-html-support General HTML Support}, or
|
794 | * {@glink features/html/html-embed HTML embed} features.
|
795 | */
|
796 | updateSourceElementOnDestroy?: boolean;
|
797 | /**
|
798 | * The license key for the CKEditor 5 commercial license and the premium features.
|
799 | *
|
800 | * If you do not have a key yet, please [contact us](https://ckeditor.com/contact/) or
|
801 | * [order a trial](https://orders.ckeditor.com/trial/premium-features).
|
802 | */
|
803 | licenseKey?: string;
|
804 | /**
|
805 | * Translations to be used in the editor.
|
806 | */
|
807 | translations?: ArrayOrItem<Translations>;
|
808 | /**
|
809 | * Label text for the `aria-label` attribute set on editor editing area. Used by assistive technologies
|
810 | * to tell apart multiple editor instances (editing areas) on the page. If not set, a default
|
811 | * "Rich Text Editor. Editing area [name of the area]" is used instead.
|
812 | *
|
813 | * ```ts
|
814 | * ClassicEditor
|
815 | * .create( document.querySelector( '#editor' ), {
|
816 | * label: 'My editor'
|
817 | * } )
|
818 | * .then( ... )
|
819 | * .catch( ... );
|
820 | * ```
|
821 | *
|
822 | * If your editor implementation uses multiple roots, you should pass an object with keys corresponding to the editor
|
823 | * roots names and values equal to the label that should be used for each root:
|
824 | *
|
825 | * ```ts
|
826 | * MultiRootEditor.create(
|
827 | * // Roots for the editor:
|
828 | * {
|
829 | * header: document.querySelector( '#header' ),
|
830 | * content: document.querySelector( '#content' ),
|
831 | * leftSide: document.querySelector( '#left-side' ),
|
832 | * rightSide: document.querySelector( '#right-side' )
|
833 | * },
|
834 | * // Config:
|
835 | * {
|
836 | * label: {
|
837 | * header: 'Header label',
|
838 | * content: 'Content label',
|
839 | * leftSide: 'Left side label',
|
840 | * rightSide: 'Right side label'
|
841 | * }
|
842 | * }
|
843 | * )
|
844 | * .then( ... )
|
845 | * .catch( ... );
|
846 | * ```
|
847 | */
|
848 | label?: string | Record<string, string>;
|
849 | }
|
850 | /**
|
851 | * The `config.initialData` option cannot be used together with the initial data passed as the first parameter of
|
852 | * {@link module:core/editor/editor~Editor.create `Editor.create()`}.
|
853 | *
|
854 | * @error editor-create-initial-data
|
855 | */
|
856 | /**
|
857 | * The configuration of the editor language.
|
858 | *
|
859 | * ```ts
|
860 | * ClassicEditor
|
861 | * .create( document.querySelector( '#editor' ), {
|
862 | * language: ... // The editor language configuration.
|
863 | * } )
|
864 | * .then( editor => {
|
865 | * console.log( editor );
|
866 | * } )
|
867 | * .catch( error => {
|
868 | * console.error( error );
|
869 | * } );
|
870 | * ```
|
871 | *
|
872 | * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
873 | */
|
874 | export interface LanguageConfig {
|
875 | /**
|
876 | * Allows to use a different language for the editor UI.
|
877 | *
|
878 | * The language codes are defined in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) standard.
|
879 | */
|
880 | ui?: string;
|
881 | /**
|
882 | * Allows to use a different language of the editor content.
|
883 | *
|
884 | * The language codes are defined in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) standard.
|
885 | */
|
886 | content?: string;
|
887 | }
|
888 | export type ToolbarConfig = Array<ToolbarConfigItem> | {
|
889 | items?: Array<ToolbarConfigItem>;
|
890 | removeItems?: Array<string>;
|
891 | shouldNotGroupWhenFull?: boolean;
|
892 | icon?: string;
|
893 | };
|
894 | export type ToolbarConfigItem = string | {
|
895 | items: Array<ToolbarConfigItem>;
|
896 | label: string;
|
897 | icon?: string | false;
|
898 | withText?: boolean;
|
899 | tooltip?: boolean | string | ((label: string, keystroke: string | undefined) => string);
|
900 | };
|
901 | /**
|
902 | * The “Powered by CKEditor” logo configuration options.
|
903 | **/
|
904 | export interface PoweredByConfig {
|
905 | /**
|
906 | * The position of the project's logo.
|
907 | *
|
908 | * * When `'inside'`, the logo will be displayed within the boundaries of the editing area.
|
909 | * * When `'border'`, the logo will be displayed over the bottom border of the editing area.
|
910 | *
|
911 | * @default 'border'
|
912 | */
|
913 | position: 'inside' | 'border';
|
914 | /**
|
915 | * Allows choosing the side of the editing area where the logo will be displayed.
|
916 | *
|
917 | * **Note:** If {@link module:core/editor/editorconfig~EditorConfig#language `config.language`} is set to an RTL (right-to-left)
|
918 | * language, the side switches to `'left'` by default.
|
919 | *
|
920 | * @default 'right'
|
921 | */
|
922 | side: 'left' | 'right';
|
923 | /**
|
924 | * Allows changing the label displayed next to the CKEditor logo.
|
925 | *
|
926 | * **Note:** Set the value to `null` to hide the label.
|
927 | *
|
928 | * @default 'Powered by'
|
929 | */
|
930 | label: string | null;
|
931 | /**
|
932 | * The vertical distance the logo can be moved away from its default position.
|
933 | *
|
934 | * **Note:** If `position` is `'border'`, the offset is measured from the (vertical) center of the logo.
|
935 | *
|
936 | * @default 5
|
937 | */
|
938 | verticalOffset: number;
|
939 | /**
|
940 | * The horizontal distance between the side of the editing root and the nearest side of the logo.
|
941 | *
|
942 | * @default 5
|
943 | */
|
944 | horizontalOffset: number;
|
945 | /**
|
946 | * Allows to show the logo even if the valid commercial license is configured using
|
947 | * the {@link module:core/editor/editorconfig~EditorConfig#licenseKey `config.licenseKey`} setting.
|
948 | *
|
949 | * @default false
|
950 | */
|
951 | forceVisible?: boolean;
|
952 | }
|
953 | /**
|
954 | * The offset (in pixels) of the viewport from every direction used when positioning a sticky toolbar or other
|
955 | * absolutely positioned UI elements.
|
956 | */
|
957 | export interface ViewportOffsetConfig {
|
958 | /**
|
959 | * The bottom offset in pixels.
|
960 | */
|
961 | bottom?: number;
|
962 | /**
|
963 | * The left offset in pixels.
|
964 | */
|
965 | left?: number;
|
966 | /**
|
967 | * The right offset in pixels.
|
968 | */
|
969 | right?: number;
|
970 | /**
|
971 | * The top offset in pixels.
|
972 | */
|
973 | top?: number;
|
974 | }
|
975 | export interface UiConfig {
|
976 | /**
|
977 | * The viewport offset used for positioning various absolutely positioned UI elements.
|
978 | *
|
979 | * Read more in {@link module:core/editor/editorconfig~ViewportOffsetConfig}.
|
980 | **/
|
981 | viewportOffset?: ViewportOffsetConfig;
|
982 | /**
|
983 | * The configuration of the “Powered by CKEditor” logo.
|
984 | *
|
985 | * Read more in {@link module:core/editor/editorconfig~PoweredByConfig}.
|
986 | **/
|
987 | poweredBy?: PoweredByConfig;
|
988 | }
|
989 |
|
\ | No newline at end of file |