@ckeditor/ckeditor5-editor-multi-root 0.0.0-nightly-20241218.0 → 0.0.0-nightly-20241219.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12,18 +12,24 @@ import { isElement as isElement$1 } from 'lodash-es';
12
12
  * The multi-root editor UI class.
13
13
  */ class MultiRootEditorUI extends EditorUI {
14
14
  /**
15
- * Creates an instance of the multi-root editor UI class.
16
- *
17
- * @param editor The editor instance.
18
- * @param view The view of the UI.
19
- */ constructor(editor, view){
15
+ * The main (top–most) view of the editor UI.
16
+ */ view;
17
+ /**
18
+ * The editable element that was focused the last time when any of the editables had focus.
19
+ */ _lastFocusedEditableElement;
20
+ /**
21
+ * Creates an instance of the multi-root editor UI class.
22
+ *
23
+ * @param editor The editor instance.
24
+ * @param view The view of the UI.
25
+ */ constructor(editor, view){
20
26
  super(editor);
21
27
  this.view = view;
22
28
  this._lastFocusedEditableElement = null;
23
29
  }
24
30
  /**
25
- * Initializes the UI.
26
- */ init() {
31
+ * Initializes the UI.
32
+ */ init() {
27
33
  const view = this.view;
28
34
  view.render();
29
35
  // Keep track of the last focused editable element. Knowing which one was focused
@@ -55,17 +61,17 @@ import { isElement as isElement$1 } from 'lodash-es';
55
61
  this.fire('ready');
56
62
  }
57
63
  /**
58
- * Adds the editable to the editor UI.
59
- *
60
- * After the editable is added to the editor UI it can be considered "active".
61
- *
62
- * The editable is attached to the editor editing pipeline, which means that it will be updated as the editor model updates and
63
- * changing its content will be reflected in the editor model. Keystrokes, focus handling and placeholder are initialized.
64
- *
65
- * @param editable The editable instance to add.
66
- * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
67
- * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
68
- */ addEditable(editable, placeholder) {
64
+ * Adds the editable to the editor UI.
65
+ *
66
+ * After the editable is added to the editor UI it can be considered "active".
67
+ *
68
+ * The editable is attached to the editor editing pipeline, which means that it will be updated as the editor model updates and
69
+ * changing its content will be reflected in the editor model. Keystrokes, focus handling and placeholder are initialized.
70
+ *
71
+ * @param editable The editable instance to add.
72
+ * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
73
+ * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
74
+ */ addEditable(editable, placeholder) {
69
75
  // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
70
76
  // But it can be available earlier if a DOM element has been passed to `MultiRootEditor.create()`.
71
77
  const editableElement = editable.element;
@@ -98,22 +104,22 @@ import { isElement as isElement$1 } from 'lodash-es';
98
104
  this._initPlaceholder(editable, placeholder);
99
105
  }
100
106
  /**
101
- * Removes the editable instance from the editor UI.
102
- *
103
- * Removed editable can be considered "deactivated".
104
- *
105
- * The editable is detached from the editing pipeline, so model changes are no longer reflected in it. All handling added in
106
- * {@link #addEditable} is removed.
107
- *
108
- * @param editable Editable to remove from the editor UI.
109
- */ removeEditable(editable) {
107
+ * Removes the editable instance from the editor UI.
108
+ *
109
+ * Removed editable can be considered "deactivated".
110
+ *
111
+ * The editable is detached from the editing pipeline, so model changes are no longer reflected in it. All handling added in
112
+ * {@link #addEditable} is removed.
113
+ *
114
+ * @param editable Editable to remove from the editor UI.
115
+ */ removeEditable(editable) {
110
116
  this.editor.editing.view.detachDomRoot(editable.name);
111
117
  editable.unbind('isFocused');
112
118
  this.removeEditableElement(editable.name);
113
119
  }
114
120
  /**
115
- * @inheritDoc
116
- */ destroy() {
121
+ * @inheritDoc
122
+ */ destroy() {
117
123
  super.destroy();
118
124
  for (const editable of Object.values(this.view.editables)){
119
125
  this.removeEditable(editable);
@@ -121,8 +127,8 @@ import { isElement as isElement$1 } from 'lodash-es';
121
127
  this.view.destroy();
122
128
  }
123
129
  /**
124
- * Initializes the editor main toolbar and its panel.
125
- */ _initToolbar() {
130
+ * Initializes the editor main toolbar and its panel.
131
+ */ _initToolbar() {
126
132
  const editor = this.editor;
127
133
  const view = this.view;
128
134
  const toolbar = view.toolbar;
@@ -131,12 +137,12 @@ import { isElement as isElement$1 } from 'lodash-es';
131
137
  this.addToolbar(view.toolbar);
132
138
  }
133
139
  /**
134
- * Enables the placeholder text on a given editable.
135
- *
136
- * @param editable Editable on which the placeholder should be set.
137
- * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
138
- * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
139
- */ _initPlaceholder(editable, placeholder) {
140
+ * Enables the placeholder text on a given editable.
141
+ *
142
+ * @param editable Editable on which the placeholder should be set.
143
+ * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
144
+ * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
145
+ */ _initPlaceholder(editable, placeholder) {
140
146
  if (!placeholder) {
141
147
  const configPlaceholder = this.editor.config.get('placeholder');
142
148
  if (configPlaceholder) {
@@ -167,22 +173,35 @@ import { isElement as isElement$1 } from 'lodash-es';
167
173
  * to learn more about this view.
168
174
  */ class MultiRootEditorUIView extends EditorUIView {
169
175
  /**
170
- * Creates an instance of the multi-root editor UI view.
171
- *
172
- * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
173
- * @param editingView The editing view instance this view is related to.
174
- * @param editableNames Names for all editable views. For each name, one
175
- * {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`} instance will be initialized.
176
- * @param options Configuration options for the view instance.
177
- * @param options.editableElements The editable elements to be used, assigned to their names. If not specified, they will be
178
- * automatically created by {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`}
179
- * instances.
180
- * @param options.shouldToolbarGroupWhenFull When set to `true` enables automatic items grouping
181
- * in the main {@link module:editor-multi-root/multirooteditoruiview~MultiRootEditorUIView#toolbar toolbar}.
182
- * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
183
- * @param options.label When set, this value will be used as an accessible `aria-label` of the
184
- * {@link module:ui/editableui/editableuiview~EditableUIView editable view} elements.
185
- */ constructor(locale, editingView, editableNames, options = {}){
176
+ * The main toolbar of the multi-root editor UI.
177
+ */ toolbar;
178
+ /**
179
+ * Editable elements used by the multi-root editor UI.
180
+ */ editables;
181
+ editable;
182
+ /**
183
+ * Menu bar view instance.
184
+ */ menuBarView;
185
+ /**
186
+ * The editing view instance this view is related to.
187
+ */ _editingView;
188
+ /**
189
+ * Creates an instance of the multi-root editor UI view.
190
+ *
191
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
192
+ * @param editingView The editing view instance this view is related to.
193
+ * @param editableNames Names for all editable views. For each name, one
194
+ * {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`} instance will be initialized.
195
+ * @param options Configuration options for the view instance.
196
+ * @param options.editableElements The editable elements to be used, assigned to their names. If not specified, they will be
197
+ * automatically created by {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`}
198
+ * instances.
199
+ * @param options.shouldToolbarGroupWhenFull When set to `true` enables automatic items grouping
200
+ * in the main {@link module:editor-multi-root/multirooteditoruiview~MultiRootEditorUIView#toolbar toolbar}.
201
+ * See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
202
+ * @param options.label When set, this value will be used as an accessible `aria-label` of the
203
+ * {@link module:ui/editableui/editableuiview~EditableUIView editable view} elements.
204
+ */ constructor(locale, editingView, editableNames, options = {}){
186
205
  super(locale);
187
206
  this._editingView = editingView;
188
207
  this.toolbar = new ToolbarView(locale, {
@@ -224,16 +243,16 @@ import { isElement as isElement$1 } from 'lodash-es';
224
243
  });
225
244
  }
226
245
  /**
227
- * Creates an editable instance with given name and registers it in the editor UI view.
228
- *
229
- * If `editableElement` is provided, the editable instance will be created on top of it. Otherwise, the editor will create a new
230
- * DOM element and use it instead.
231
- *
232
- * @param editableName The name for the editable.
233
- * @param editableElement DOM element for which the editable should be created.
234
- * @param label The accessible editable label used by assistive technologies.
235
- * @returns The created editable instance.
236
- */ createEditable(editableName, editableElement, label) {
246
+ * Creates an editable instance with given name and registers it in the editor UI view.
247
+ *
248
+ * If `editableElement` is provided, the editable instance will be created on top of it. Otherwise, the editor will create a new
249
+ * DOM element and use it instead.
250
+ *
251
+ * @param editableName The name for the editable.
252
+ * @param editableElement DOM element for which the editable should be created.
253
+ * @param label The accessible editable label used by assistive technologies.
254
+ * @returns The created editable instance.
255
+ */ createEditable(editableName, editableElement, label) {
237
256
  const editable = new InlineEditableUIView(this.locale, this._editingView, editableElement, {
238
257
  label
239
258
  });
@@ -245,10 +264,10 @@ import { isElement as isElement$1 } from 'lodash-es';
245
264
  return editable;
246
265
  }
247
266
  /**
248
- * Destroys and removes the editable from the editor UI view.
249
- *
250
- * @param editableName The name of the editable that should be removed.
251
- */ removeEditable(editableName) {
267
+ * Destroys and removes the editable from the editor UI view.
268
+ *
269
+ * @param editableName The name of the editable that should be removed.
270
+ */ removeEditable(editableName) {
252
271
  const editable = this.editables[editableName];
253
272
  if (this.isRendered) {
254
273
  this.deregisterChild(editable);
@@ -257,8 +276,8 @@ import { isElement as isElement$1 } from 'lodash-es';
257
276
  editable.destroy();
258
277
  }
259
278
  /**
260
- * @inheritDoc
261
- */ render() {
279
+ * @inheritDoc
280
+ */ render() {
262
281
  super.render();
263
282
  this.registerChild(Object.values(this.editables));
264
283
  this.registerChild(this.toolbar);
@@ -281,21 +300,34 @@ import { isElement as isElement$1 } from 'lodash-es';
281
300
  * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
282
301
  */ class MultiRootEditor extends Editor {
283
302
  /**
284
- * @inheritDoc
285
- */ static get editorName() {
303
+ * @inheritDoc
304
+ */ static get editorName() {
286
305
  return 'MultiRootEditor';
287
306
  }
288
307
  /**
289
- * Creates an instance of the multi-root editor.
290
- *
291
- * **Note:** Do not use the constructor to create editor instances. Use the static
292
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
293
- *
294
- * @param sourceElementsOrData The DOM elements that will be the source for the created editor
295
- * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
296
- * For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
297
- * @param config The editor configuration.
298
- */ constructor(sourceElementsOrData, config = {}){
308
+ * @inheritDoc
309
+ */ ui;
310
+ /**
311
+ * The elements on which the editor has been initialized.
312
+ */ sourceElements;
313
+ /**
314
+ * Holds attributes keys that were passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `rootsAttributes`}
315
+ * config property and should be returned by {@link #getRootsAttributes}.
316
+ */ _registeredRootsAttributesKeys = new Set();
317
+ /**
318
+ * A set of lock IDs for enabling or disabling particular root.
319
+ */ _readOnlyRootLocks = new Map();
320
+ /**
321
+ * Creates an instance of the multi-root editor.
322
+ *
323
+ * **Note:** Do not use the constructor to create editor instances. Use the static
324
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
325
+ *
326
+ * @param sourceElementsOrData The DOM elements that will be the source for the created editor
327
+ * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
328
+ * For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
329
+ * @param config The editor configuration.
330
+ */ constructor(sourceElementsOrData, config = {}){
299
331
  const rootNames = Object.keys(sourceElementsOrData);
300
332
  const sourceIsData = rootNames.length === 0 || typeof sourceElementsOrData[rootNames[0]] === 'string';
301
333
  if (sourceIsData && config.initialData !== undefined && Object.keys(config.initialData).length > 0) {
@@ -304,13 +336,6 @@ import { isElement as isElement$1 } from 'lodash-es';
304
336
  throw new CKEditorError('editor-create-initial-data', null);
305
337
  }
306
338
  super(config);
307
- /**
308
- * Holds attributes keys that were passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `rootsAttributes`}
309
- * config property and should be returned by {@link #getRootsAttributes}.
310
- */ this._registeredRootsAttributesKeys = new Set();
311
- /**
312
- * A set of lock IDs for enabling or disabling particular root.
313
- */ this._readOnlyRootLocks = new Map();
314
339
  if (!sourceIsData) {
315
340
  this.sourceElements = sourceElementsOrData;
316
341
  } else {
@@ -363,13 +388,13 @@ import { isElement as isElement$1 } from 'lodash-es';
363
388
  for (const [rootName, attributes] of Object.entries(rootsAttributes)){
364
389
  if (!this.model.document.getRoot(rootName)) {
365
390
  /**
366
- * Trying to set attributes on a non-existing root.
367
- *
368
- * Roots specified in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes} do not match initial
369
- * editor roots.
370
- *
371
- * @error multi-root-editor-root-attributes-no-root
372
- */ throw new CKEditorError('multi-root-editor-root-attributes-no-root', null);
391
+ * Trying to set attributes on a non-existing root.
392
+ *
393
+ * Roots specified in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes} do not match initial
394
+ * editor roots.
395
+ *
396
+ * @error multi-root-editor-root-attributes-no-root
397
+ */ throw new CKEditorError('multi-root-editor-root-attributes-no-root', null);
373
398
  }
374
399
  for (const key of Object.keys(attributes)){
375
400
  this.registerRootAttribute(key);
@@ -444,19 +469,19 @@ import { isElement as isElement$1 } from 'lodash-es';
444
469
  const root = this.model.document.getRoot(rootName);
445
470
  if (!root) {
446
471
  /**
447
- * The root to load does not exist.
448
- *
449
- * @error multi-root-editor-load-root-no-root
450
- */ throw new CKEditorError('multi-root-editor-load-root-no-root', this, {
472
+ * The root to load does not exist.
473
+ *
474
+ * @error multi-root-editor-load-root-no-root
475
+ */ throw new CKEditorError('multi-root-editor-load-root-no-root', this, {
451
476
  rootName
452
477
  });
453
478
  }
454
479
  if (root._isLoaded) {
455
480
  /**
456
- * The root to load was already loaded before. The `loadRoot()` call has no effect.
457
- *
458
- * @error multi-root-editor-load-root-already-loaded
459
- */ logWarning('multi-root-editor-load-root-already-loaded');
481
+ * The root to load was already loaded before. The `loadRoot()` call has no effect.
482
+ *
483
+ * @error multi-root-editor-load-root-already-loaded
484
+ */ logWarning('multi-root-editor-load-root-already-loaded');
460
485
  evt.stop();
461
486
  }
462
487
  }, {
@@ -464,29 +489,29 @@ import { isElement as isElement$1 } from 'lodash-es';
464
489
  });
465
490
  }
466
491
  /**
467
- * Destroys the editor instance, releasing all resources used by it.
468
- *
469
- * Updates the original editor element with the data if the
470
- * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
471
- * configuration option is set to `true`.
472
- *
473
- * **Note**: The multi-root editor does not remove the toolbar and editable when destroyed. You can
474
- * do that yourself in the destruction chain, if you need to:
475
- *
476
- * ```ts
477
- * editor.destroy().then( () => {
478
- * // Remove the toolbar from DOM.
479
- * editor.ui.view.toolbar.element.remove();
480
- *
481
- * // Remove editable elements from DOM.
482
- * for ( const editable of Object.values( editor.ui.view.editables ) ) {
483
- * editable.element.remove();
484
- * }
485
- *
486
- * console.log( 'Editor was destroyed' );
487
- * } );
488
- * ```
489
- */ destroy() {
492
+ * Destroys the editor instance, releasing all resources used by it.
493
+ *
494
+ * Updates the original editor element with the data if the
495
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
496
+ * configuration option is set to `true`.
497
+ *
498
+ * **Note**: The multi-root editor does not remove the toolbar and editable when destroyed. You can
499
+ * do that yourself in the destruction chain, if you need to:
500
+ *
501
+ * ```ts
502
+ * editor.destroy().then( () => {
503
+ * // Remove the toolbar from DOM.
504
+ * editor.ui.view.toolbar.element.remove();
505
+ *
506
+ * // Remove editable elements from DOM.
507
+ * for ( const editable of Object.values( editor.ui.view.editables ) ) {
508
+ * editable.element.remove();
509
+ * }
510
+ *
511
+ * console.log( 'Editor was destroyed' );
512
+ * } );
513
+ * ```
514
+ */ destroy() {
490
515
  const shouldUpdateSourceElement = this.config.get('updateSourceElementOnDestroy');
491
516
  // Cache the data and editable DOM elements, then destroy.
492
517
  // It's safe to assume that the model->view conversion will not work after `super.destroy()`,
@@ -505,78 +530,78 @@ import { isElement as isElement$1 } from 'lodash-es';
505
530
  });
506
531
  }
507
532
  /**
508
- * Adds a new root to the editor.
509
- *
510
- * ```ts
511
- * editor.addRoot( 'myRoot', { data: '<p>Initial root data.</p>' } );
512
- * ```
513
- *
514
- * After a root is added, you will be able to modify and retrieve its data.
515
- *
516
- * All root names must be unique. An error will be thrown if you will try to create a root with the name same as
517
- * an already existing, attached root. However, you can call this method for a detached root. See also {@link #detachRoot}.
518
- *
519
- * Whenever a root is added, the editor instance will fire {@link #event:addRoot `addRoot` event}. The event is also called when
520
- * the root is added indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
521
- *
522
- * Note, that this method only adds a root to the editor model. It **does not** create a DOM editable element for the new root.
523
- * Until such element is created (and attached to the root), the root is "virtual": it is not displayed anywhere and its data can
524
- * be changed only using the editor API.
525
- *
526
- * To create a DOM editable element for the root, listen to {@link #event:addRoot `addRoot` event} and call {@link #createEditable}.
527
- * Then, insert the DOM element in a desired place, that will depend on the integration with your application and your requirements.
528
- *
529
- * ```ts
530
- * editor.on( 'addRoot', ( evt, root ) => {
531
- * const editableElement = editor.createEditable( root );
532
- *
533
- * // You may want to create a more complex DOM structure here.
534
- * //
535
- * // Alternatively, you may want to create a DOM structure before
536
- * // calling `editor.addRoot()` and only append `editableElement` at
537
- * // a proper place.
538
- *
539
- * document.querySelector( '#editors' ).appendChild( editableElement );
540
- * } );
541
- *
542
- * // ...
543
- *
544
- * editor.addRoot( 'myRoot' ); // Will create a root, a DOM editable element and append it to `#editors` container element.
545
- * ```
546
- *
547
- * You can set root attributes on the new root while you add it:
548
- *
549
- * ```ts
550
- * // Add a collapsed root at fourth position from top.
551
- * // Keep in mind that these are just examples of attributes. You need to provide your own features that will handle the attributes.
552
- * editor.addRoot( 'myRoot', { attributes: { isCollapsed: true, index: 4 } } );
553
- * ```
554
- *
555
- * Note that attributes added together with a root are automatically registered.
556
- *
557
- * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
558
- * {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
559
- *
560
- * By setting `isUndoable` flag to `true`, you can allow for detaching the root using the undo feature.
561
- *
562
- * Additionally, you can group adding multiple roots in one undo step. This can be useful if you add multiple roots that are
563
- * combined into one, bigger UI element, and want them all to be undone together.
564
- *
565
- * ```ts
566
- * let rowId = 0;
567
- *
568
- * editor.model.change( () => {
569
- * editor.addRoot( 'left-row-' + rowId, { isUndoable: true } );
570
- * editor.addRoot( 'center-row-' + rowId, { isUndoable: true } );
571
- * editor.addRoot( 'right-row-' + rowId, { isUndoable: true } );
572
- *
573
- * rowId++;
574
- * } );
575
- * ```
576
- *
577
- * @param rootName Name of the root to add.
578
- * @param options Additional options for the added root.
579
- */ addRoot(rootName, { data = '', attributes = {}, elementName = '$root', isUndoable = false } = {}) {
533
+ * Adds a new root to the editor.
534
+ *
535
+ * ```ts
536
+ * editor.addRoot( 'myRoot', { data: '<p>Initial root data.</p>' } );
537
+ * ```
538
+ *
539
+ * After a root is added, you will be able to modify and retrieve its data.
540
+ *
541
+ * All root names must be unique. An error will be thrown if you will try to create a root with the name same as
542
+ * an already existing, attached root. However, you can call this method for a detached root. See also {@link #detachRoot}.
543
+ *
544
+ * Whenever a root is added, the editor instance will fire {@link #event:addRoot `addRoot` event}. The event is also called when
545
+ * the root is added indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
546
+ *
547
+ * Note, that this method only adds a root to the editor model. It **does not** create a DOM editable element for the new root.
548
+ * Until such element is created (and attached to the root), the root is "virtual": it is not displayed anywhere and its data can
549
+ * be changed only using the editor API.
550
+ *
551
+ * To create a DOM editable element for the root, listen to {@link #event:addRoot `addRoot` event} and call {@link #createEditable}.
552
+ * Then, insert the DOM element in a desired place, that will depend on the integration with your application and your requirements.
553
+ *
554
+ * ```ts
555
+ * editor.on( 'addRoot', ( evt, root ) => {
556
+ * const editableElement = editor.createEditable( root );
557
+ *
558
+ * // You may want to create a more complex DOM structure here.
559
+ * //
560
+ * // Alternatively, you may want to create a DOM structure before
561
+ * // calling `editor.addRoot()` and only append `editableElement` at
562
+ * // a proper place.
563
+ *
564
+ * document.querySelector( '#editors' ).appendChild( editableElement );
565
+ * } );
566
+ *
567
+ * // ...
568
+ *
569
+ * editor.addRoot( 'myRoot' ); // Will create a root, a DOM editable element and append it to `#editors` container element.
570
+ * ```
571
+ *
572
+ * You can set root attributes on the new root while you add it:
573
+ *
574
+ * ```ts
575
+ * // Add a collapsed root at fourth position from top.
576
+ * // Keep in mind that these are just examples of attributes. You need to provide your own features that will handle the attributes.
577
+ * editor.addRoot( 'myRoot', { attributes: { isCollapsed: true, index: 4 } } );
578
+ * ```
579
+ *
580
+ * Note that attributes added together with a root are automatically registered.
581
+ *
582
+ * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
583
+ * {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
584
+ *
585
+ * By setting `isUndoable` flag to `true`, you can allow for detaching the root using the undo feature.
586
+ *
587
+ * Additionally, you can group adding multiple roots in one undo step. This can be useful if you add multiple roots that are
588
+ * combined into one, bigger UI element, and want them all to be undone together.
589
+ *
590
+ * ```ts
591
+ * let rowId = 0;
592
+ *
593
+ * editor.model.change( () => {
594
+ * editor.addRoot( 'left-row-' + rowId, { isUndoable: true } );
595
+ * editor.addRoot( 'center-row-' + rowId, { isUndoable: true } );
596
+ * editor.addRoot( 'right-row-' + rowId, { isUndoable: true } );
597
+ *
598
+ * rowId++;
599
+ * } );
600
+ * ```
601
+ *
602
+ * @param rootName Name of the root to add.
603
+ * @param options Additional options for the added root.
604
+ */ addRoot(rootName, { data = '', attributes = {}, elementName = '$root', isUndoable = false } = {}) {
580
605
  const _addRoot = (writer)=>{
581
606
  const root = writer.addRoot(rootName, elementName);
582
607
  if (data) {
@@ -596,59 +621,59 @@ import { isElement as isElement$1 } from 'lodash-es';
596
621
  }
597
622
  }
598
623
  /**
599
- * Detaches a root from the editor.
600
- *
601
- * ```ts
602
- * editor.detachRoot( 'myRoot' );
603
- * ```
604
- *
605
- * A detached root is not entirely removed from the editor model, however it can be considered removed.
606
- *
607
- * After a root is detached all its children are removed, all markers inside it are removed, and whenever something is inserted to it,
608
- * it is automatically removed as well. Finally, a detached root is not returned by
609
- * {@link module:engine/model/document~Document#getRootNames} by default.
610
- *
611
- * It is possible to re-add a previously detached root calling {@link #addRoot}.
612
- *
613
- * Whenever a root is detached, the editor instance will fire {@link #event:detachRoot `detachRoot` event}. The event is also
614
- * called when the root is detached indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
615
- *
616
- * Note, that this method only detached a root in the editor model. It **does not** destroy the DOM editable element linked with
617
- * the root and it **does not** remove the DOM element from the DOM structure of your application.
618
- *
619
- * To properly remove a DOM editable element after a root was detached, listen to {@link #event:detachRoot `detachRoot` event}
620
- * and call {@link #detachEditable}. Then, remove the DOM element from your application.
621
- *
622
- * ```ts
623
- * editor.on( 'detachRoot', ( evt, root ) => {
624
- * const editableElement = editor.detachEditable( root );
625
- *
626
- * // You may want to do an additional DOM clean-up here.
627
- *
628
- * editableElement.remove();
629
- * } );
630
- *
631
- * // ...
632
- *
633
- * editor.detachRoot( 'myRoot' ); // Will detach the root, and remove the DOM editable element.
634
- * ```
635
- *
636
- * By setting `isUndoable` flag to `true`, you can allow for re-adding the root using the undo feature.
637
- *
638
- * Additionally, you can group detaching multiple roots in one undo step. This can be useful if the roots are combined into one,
639
- * bigger UI element, and you want them all to be re-added together.
640
- *
641
- * ```ts
642
- * editor.model.change( () => {
643
- * editor.detachRoot( 'left-row-3', true );
644
- * editor.detachRoot( 'center-row-3', true );
645
- * editor.detachRoot( 'right-row-3', true );
646
- * } );
647
- * ```
648
- *
649
- * @param rootName Name of the root to detach.
650
- * @param isUndoable Whether detaching the root can be undone (using the undo feature) or not.
651
- */ detachRoot(rootName, isUndoable = false) {
624
+ * Detaches a root from the editor.
625
+ *
626
+ * ```ts
627
+ * editor.detachRoot( 'myRoot' );
628
+ * ```
629
+ *
630
+ * A detached root is not entirely removed from the editor model, however it can be considered removed.
631
+ *
632
+ * After a root is detached all its children are removed, all markers inside it are removed, and whenever something is inserted to it,
633
+ * it is automatically removed as well. Finally, a detached root is not returned by
634
+ * {@link module:engine/model/document~Document#getRootNames} by default.
635
+ *
636
+ * It is possible to re-add a previously detached root calling {@link #addRoot}.
637
+ *
638
+ * Whenever a root is detached, the editor instance will fire {@link #event:detachRoot `detachRoot` event}. The event is also
639
+ * called when the root is detached indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
640
+ *
641
+ * Note, that this method only detached a root in the editor model. It **does not** destroy the DOM editable element linked with
642
+ * the root and it **does not** remove the DOM element from the DOM structure of your application.
643
+ *
644
+ * To properly remove a DOM editable element after a root was detached, listen to {@link #event:detachRoot `detachRoot` event}
645
+ * and call {@link #detachEditable}. Then, remove the DOM element from your application.
646
+ *
647
+ * ```ts
648
+ * editor.on( 'detachRoot', ( evt, root ) => {
649
+ * const editableElement = editor.detachEditable( root );
650
+ *
651
+ * // You may want to do an additional DOM clean-up here.
652
+ *
653
+ * editableElement.remove();
654
+ * } );
655
+ *
656
+ * // ...
657
+ *
658
+ * editor.detachRoot( 'myRoot' ); // Will detach the root, and remove the DOM editable element.
659
+ * ```
660
+ *
661
+ * By setting `isUndoable` flag to `true`, you can allow for re-adding the root using the undo feature.
662
+ *
663
+ * Additionally, you can group detaching multiple roots in one undo step. This can be useful if the roots are combined into one,
664
+ * bigger UI element, and you want them all to be re-added together.
665
+ *
666
+ * ```ts
667
+ * editor.model.change( () => {
668
+ * editor.detachRoot( 'left-row-3', true );
669
+ * editor.detachRoot( 'center-row-3', true );
670
+ * editor.detachRoot( 'right-row-3', true );
671
+ * } );
672
+ * ```
673
+ *
674
+ * @param rootName Name of the root to detach.
675
+ * @param isUndoable Whether detaching the root can be undone (using the undo feature) or not.
676
+ */ detachRoot(rootName, isUndoable = false) {
652
677
  if (isUndoable) {
653
678
  this.model.change((writer)=>writer.detachRoot(rootName));
654
679
  } else {
@@ -658,27 +683,27 @@ import { isElement as isElement$1 } from 'lodash-es';
658
683
  }
659
684
  }
660
685
  /**
661
- * Creates and returns a new DOM editable element for the given root element.
662
- *
663
- * The new DOM editable is attached to the model root and can be used to modify the root content.
664
- *
665
- * @param root Root for which the editable element should be created.
666
- * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
667
- * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
668
- * @param label The accessible label text describing the editable to the assistive technologies.
669
- * @returns The created DOM element. Append it in a desired place in your application.
670
- */ createEditable(root, placeholder, label) {
686
+ * Creates and returns a new DOM editable element for the given root element.
687
+ *
688
+ * The new DOM editable is attached to the model root and can be used to modify the root content.
689
+ *
690
+ * @param root Root for which the editable element should be created.
691
+ * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
692
+ * {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
693
+ * @param label The accessible label text describing the editable to the assistive technologies.
694
+ * @returns The created DOM element. Append it in a desired place in your application.
695
+ */ createEditable(root, placeholder, label) {
671
696
  const editable = this.ui.view.createEditable(root.rootName, undefined, label);
672
697
  this.ui.addEditable(editable, placeholder);
673
698
  this.editing.view.forceRender();
674
699
  return editable.element;
675
700
  }
676
701
  /**
677
- * Detaches the DOM editable element that was attached to the given root.
678
- *
679
- * @param root Root for which the editable element should be detached.
680
- * @returns The DOM element that was detached. You may want to remove it from your application DOM structure.
681
- */ detachEditable(root) {
702
+ * Detaches the DOM editable element that was attached to the given root.
703
+ *
704
+ * @param root Root for which the editable element should be detached.
705
+ * @returns The DOM element that was detached. You may want to remove it from your application DOM structure.
706
+ */ detachEditable(root) {
682
707
  const rootName = root.rootName;
683
708
  const editable = this.ui.view.editables[rootName];
684
709
  this.ui.removeEditable(editable);
@@ -686,34 +711,34 @@ import { isElement as isElement$1 } from 'lodash-es';
686
711
  return editable.element;
687
712
  }
688
713
  /**
689
- * Loads a root that has previously been declared in {@link module:core/editor/editorconfig~EditorConfig#lazyRoots `lazyRoots`}
690
- * configuration option.
691
- *
692
- * Only roots specified in the editor config can be loaded. A root cannot be loaded multiple times. A root cannot be unloaded and
693
- * loading a root cannot be reverted using the undo feature.
694
- *
695
- * When a root becomes loaded, it will be treated by the editor as though it was just added. This, among others, means that all
696
- * related events and mechanisms will be fired, including {@link ~MultiRootEditor#event:addRoot `addRoot` event},
697
- * {@link module:engine/model/document~Document#event:change `model.Document` `change` event}, model post-fixers and conversion.
698
- *
699
- * Until the root becomes loaded, all above mechanisms are suppressed.
700
- *
701
- * This method is {@link module:utils/observablemixin~Observable#decorate decorated}.
702
- *
703
- * Note that attributes loaded together with a root are automatically registered.
704
- *
705
- * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
706
- * {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
707
- *
708
- * When this method is used in real-time collaboration environment, its effects become asynchronous as the editor will first synchronize
709
- * with the remote editing session, before the root is added to the editor.
710
- *
711
- * If the root has been already loaded by any other client, the additional data passed in `loadRoot()` parameters will be ignored.
712
- *
713
- * @param rootName Name of the root to load.
714
- * @param options Additional options for the loaded root.
715
- * @fires loadRoot
716
- */ loadRoot(rootName, { data = '', attributes = {} } = {}) {
714
+ * Loads a root that has previously been declared in {@link module:core/editor/editorconfig~EditorConfig#lazyRoots `lazyRoots`}
715
+ * configuration option.
716
+ *
717
+ * Only roots specified in the editor config can be loaded. A root cannot be loaded multiple times. A root cannot be unloaded and
718
+ * loading a root cannot be reverted using the undo feature.
719
+ *
720
+ * When a root becomes loaded, it will be treated by the editor as though it was just added. This, among others, means that all
721
+ * related events and mechanisms will be fired, including {@link ~MultiRootEditor#event:addRoot `addRoot` event},
722
+ * {@link module:engine/model/document~Document#event:change `model.Document` `change` event}, model post-fixers and conversion.
723
+ *
724
+ * Until the root becomes loaded, all above mechanisms are suppressed.
725
+ *
726
+ * This method is {@link module:utils/observablemixin~Observable#decorate decorated}.
727
+ *
728
+ * Note that attributes loaded together with a root are automatically registered.
729
+ *
730
+ * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
731
+ * {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
732
+ *
733
+ * When this method is used in real-time collaboration environment, its effects become asynchronous as the editor will first synchronize
734
+ * with the remote editing session, before the root is added to the editor.
735
+ *
736
+ * If the root has been already loaded by any other client, the additional data passed in `loadRoot()` parameters will be ignored.
737
+ *
738
+ * @param rootName Name of the root to load.
739
+ * @param options Additional options for the loaded root.
740
+ * @fires loadRoot
741
+ */ loadRoot(rootName, { data = '', attributes = {} } = {}) {
717
742
  // `root` will be defined as it is guaranteed by a check in a higher priority callback.
718
743
  const root = this.model.document.getRoot(rootName);
719
744
  this.model.enqueueChange({
@@ -731,15 +756,15 @@ import { isElement as isElement$1 } from 'lodash-es';
731
756
  });
732
757
  }
733
758
  /**
734
- * Returns the document data for all attached roots.
735
- *
736
- * @param options Additional configuration for the retrieved data.
737
- * Editor features may introduce more configuration options that can be set through this parameter.
738
- * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
739
- * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
740
- * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
741
- * @returns The full document data.
742
- */ getFullData(options) {
759
+ * Returns the document data for all attached roots.
760
+ *
761
+ * @param options Additional configuration for the retrieved data.
762
+ * Editor features may introduce more configuration options that can be set through this parameter.
763
+ * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
764
+ * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
765
+ * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
766
+ * @returns The full document data.
767
+ */ getFullData(options) {
743
768
  const data = {};
744
769
  for (const rootName of this.model.document.getRootNames()){
745
770
  data[rootName] = this.data.get({
@@ -750,13 +775,13 @@ import { isElement as isElement$1 } from 'lodash-es';
750
775
  return data;
751
776
  }
752
777
  /**
753
- * Returns attributes for all attached roots.
754
- *
755
- * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
756
- * If a registered root attribute is not set for a given root, `null` will be returned.
757
- *
758
- * @returns Object with roots attributes. Keys are roots names, while values are attributes set on given root.
759
- */ getRootsAttributes() {
778
+ * Returns attributes for all attached roots.
779
+ *
780
+ * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
781
+ * If a registered root attribute is not set for a given root, `null` will be returned.
782
+ *
783
+ * @returns Object with roots attributes. Keys are roots names, while values are attributes set on given root.
784
+ */ getRootsAttributes() {
760
785
  const rootsAttributes = {};
761
786
  for (const rootName of this.model.document.getRootNames()){
762
787
  rootsAttributes[rootName] = this.getRootAttributes(rootName);
@@ -764,11 +789,11 @@ import { isElement as isElement$1 } from 'lodash-es';
764
789
  return rootsAttributes;
765
790
  }
766
791
  /**
767
- * Returns attributes for the specified root.
768
- *
769
- * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
770
- * If a registered root attribute is not set for a given root, `null` will be returned.
771
- */ getRootAttributes(rootName) {
792
+ * Returns attributes for the specified root.
793
+ *
794
+ * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
795
+ * If a registered root attribute is not set for a given root, `null` will be returned.
796
+ */ getRootAttributes(rootName) {
772
797
  const rootAttributes = {};
773
798
  const root = this.model.document.getRoot(rootName);
774
799
  for (const key of this._registeredRootsAttributesKeys){
@@ -777,15 +802,15 @@ import { isElement as isElement$1 } from 'lodash-es';
777
802
  return rootAttributes;
778
803
  }
779
804
  /**
780
- * Registers given string as a root attribute key. Registered root attributes are added to
781
- * {@link module:engine/model/schema~Schema schema}, and also returned by
782
- * {@link ~MultiRootEditor#getRootAttributes `getRootAttributes()`} and
783
- * {@link ~MultiRootEditor#getRootsAttributes `getRootsAttributes()`}.
784
- *
785
- * Note: attributes passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes`} are
786
- * automatically registered as the editor is initialized. However, registering the same attribute twice does not have any negative
787
- * impact, so it is recommended to use this method in any feature that uses roots attributes.
788
- */ registerRootAttribute(key) {
805
+ * Registers given string as a root attribute key. Registered root attributes are added to
806
+ * {@link module:engine/model/schema~Schema schema}, and also returned by
807
+ * {@link ~MultiRootEditor#getRootAttributes `getRootAttributes()`} and
808
+ * {@link ~MultiRootEditor#getRootsAttributes `getRootsAttributes()`}.
809
+ *
810
+ * Note: attributes passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes`} are
811
+ * automatically registered as the editor is initialized. However, registering the same attribute twice does not have any negative
812
+ * impact, so it is recommended to use this method in any feature that uses roots attributes.
813
+ */ registerRootAttribute(key) {
789
814
  if (this._registeredRootsAttributesKeys.has(key)) {
790
815
  return;
791
816
  }
@@ -795,46 +820,46 @@ import { isElement as isElement$1 } from 'lodash-es';
795
820
  });
796
821
  }
797
822
  /**
798
- * Switches given editor root to the read-only mode.
799
- *
800
- * In contrary to {@link module:core/editor/editor~Editor#enableReadOnlyMode `enableReadOnlyMode()`}, which switches the whole editor
801
- * to the read-only mode, this method turns only a particular root to the read-only mode. This can be useful when you want to prevent
802
- * editing only a part of the editor content.
803
- *
804
- * When you switch a root to the read-only mode, you need provide a unique identifier (`lockId`) that will identify this request. You
805
- * will need to provide the same `lockId` when you will want to
806
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot re-enable} the root.
807
- *
808
- * ```ts
809
- * const model = editor.model;
810
- * const myRoot = model.document.getRoot( 'myRoot' );
811
- *
812
- * editor.disableRoot( 'myRoot', 'my-lock' );
813
- * model.canEditAt( myRoot ); // `false`
814
- *
815
- * editor.disableRoot( 'myRoot', 'other-lock' );
816
- * editor.disableRoot( 'myRoot', 'other-lock' ); // Multiple locks with the same ID have no effect.
817
- * model.canEditAt( myRoot ); // `false`
818
- *
819
- * editor.enableRoot( 'myRoot', 'my-lock' );
820
- * model.canEditAt( myRoot ); // `false`
821
- *
822
- * editor.enableRoot( 'myRoot', 'other-lock' );
823
- * model.canEditAt( myRoot ); // `true`
824
- * ```
825
- *
826
- * See also {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode()`} and
827
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot `MultiRootEditor#enableRoot()`}.
828
- *
829
- * @param rootName Name of the root to switch to read-only mode.
830
- * @param lockId A unique ID for setting the editor to the read-only state.
831
- */ disableRoot(rootName, lockId) {
823
+ * Switches given editor root to the read-only mode.
824
+ *
825
+ * In contrary to {@link module:core/editor/editor~Editor#enableReadOnlyMode `enableReadOnlyMode()`}, which switches the whole editor
826
+ * to the read-only mode, this method turns only a particular root to the read-only mode. This can be useful when you want to prevent
827
+ * editing only a part of the editor content.
828
+ *
829
+ * When you switch a root to the read-only mode, you need provide a unique identifier (`lockId`) that will identify this request. You
830
+ * will need to provide the same `lockId` when you will want to
831
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot re-enable} the root.
832
+ *
833
+ * ```ts
834
+ * const model = editor.model;
835
+ * const myRoot = model.document.getRoot( 'myRoot' );
836
+ *
837
+ * editor.disableRoot( 'myRoot', 'my-lock' );
838
+ * model.canEditAt( myRoot ); // `false`
839
+ *
840
+ * editor.disableRoot( 'myRoot', 'other-lock' );
841
+ * editor.disableRoot( 'myRoot', 'other-lock' ); // Multiple locks with the same ID have no effect.
842
+ * model.canEditAt( myRoot ); // `false`
843
+ *
844
+ * editor.enableRoot( 'myRoot', 'my-lock' );
845
+ * model.canEditAt( myRoot ); // `false`
846
+ *
847
+ * editor.enableRoot( 'myRoot', 'other-lock' );
848
+ * model.canEditAt( myRoot ); // `true`
849
+ * ```
850
+ *
851
+ * See also {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode()`} and
852
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot `MultiRootEditor#enableRoot()`}.
853
+ *
854
+ * @param rootName Name of the root to switch to read-only mode.
855
+ * @param lockId A unique ID for setting the editor to the read-only state.
856
+ */ disableRoot(rootName, lockId) {
832
857
  if (rootName == '$graveyard') {
833
858
  /**
834
- * You cannot disable the `$graveyard` root.
835
- *
836
- * @error multi-root-editor-cannot-disable-graveyard-root
837
- */ throw new CKEditorError('multi-root-editor-cannot-disable-graveyard-root', this);
859
+ * You cannot disable the `$graveyard` root.
860
+ *
861
+ * @error multi-root-editor-cannot-disable-graveyard-root
862
+ */ throw new CKEditorError('multi-root-editor-cannot-disable-graveyard-root', this);
838
863
  }
839
864
  const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
840
865
  if (locksForGivenRoot) {
@@ -850,13 +875,13 @@ import { isElement as isElement$1 } from 'lodash-es';
850
875
  }
851
876
  }
852
877
  /**
853
- * Removes given read-only lock from the given root.
854
- *
855
- * See {@link module:editor-multi-root/multirooteditor~MultiRootEditor#disableRoot `disableRoot()`}.
856
- *
857
- * @param rootName Name of the root to switch back from the read-only mode.
858
- * @param lockId A unique ID for setting the editor to the read-only state.
859
- */ enableRoot(rootName, lockId) {
878
+ * Removes given read-only lock from the given root.
879
+ *
880
+ * See {@link module:editor-multi-root/multirooteditor~MultiRootEditor#disableRoot `disableRoot()`}.
881
+ *
882
+ * @param rootName Name of the root to switch back from the read-only mode.
883
+ * @param lockId A unique ID for setting the editor to the read-only state.
884
+ */ enableRoot(rootName, lockId) {
860
885
  const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
861
886
  if (!locksForGivenRoot || !locksForGivenRoot.has(lockId)) {
862
887
  return;
@@ -872,127 +897,127 @@ import { isElement as isElement$1 } from 'lodash-es';
872
897
  }
873
898
  }
874
899
  /**
875
- * Creates a new multi-root editor instance.
876
- *
877
- * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
878
- * after the editor has been initialized.
879
- *
880
- * There are a few different ways to initialize the multi-root editor.
881
- *
882
- * # Using existing DOM elements:
883
- *
884
- * ```ts
885
- * MultiRootEditor.create( {
886
- * intro: document.querySelector( '#editor-intro' ),
887
- * content: document.querySelector( '#editor-content' ),
888
- * sidePanelLeft: document.querySelector( '#editor-side-left' ),
889
- * sidePanelRight: document.querySelector( '#editor-side-right' ),
890
- * outro: document.querySelector( '#editor-outro' )
891
- * } )
892
- * .then( editor => {
893
- * console.log( 'Editor was initialized', editor );
894
- *
895
- * // Append the toolbar inside a provided DOM element.
896
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
897
- * } )
898
- * .catch( err => {
899
- * console.error( err.stack );
900
- * } );
901
- * ```
902
- *
903
- * The elements' content will be used as the editor data and elements will become editable elements.
904
- *
905
- * # Creating a detached editor
906
- *
907
- * Alternatively, you can initialize the editor by passing the initial data directly as strings.
908
- * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
909
- *
910
- * ```ts
911
- * MultiRootEditor.create( {
912
- * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
913
- * content: '<p>Lorem ipsum dolor sit amet.</p>',
914
- * sidePanelLeft: '<blockquote>Strong quotation from article.</blockquote>',
915
- * sidePanelRight: '<p>List of similar articles...</p>',
916
- * outro: '<p>Closing text.</p>'
917
- * } )
918
- * .then( editor => {
919
- * console.log( 'Editor was initialized', editor );
920
- *
921
- * // Append the toolbar inside a provided DOM element.
922
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
923
- *
924
- * // Append DOM editable elements created by the editor.
925
- * const editables = editor.ui.view.editables;
926
- * const container = document.querySelector( '#editable-container' );
927
- *
928
- * container.appendChild( editables.intro.element );
929
- * container.appendChild( editables.content.element );
930
- * container.appendChild( editables.outro.element );
931
- * } )
932
- * .catch( err => {
933
- * console.error( err.stack );
934
- * } );
935
- * ```
936
- *
937
- * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
938
- * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
939
- *
940
- * # Using an existing DOM element (and data provided in `config.initialData`)
941
- *
942
- * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
943
- *
944
- * ```ts
945
- * MultiRootEditor.create( {
946
- * intro: document.querySelector( '#editor-intro' ),
947
- * content: document.querySelector( '#editor-content' ),
948
- * sidePanelLeft: document.querySelector( '#editor-side-left' ),
949
- * sidePanelRight: document.querySelector( '#editor-side-right' ),
950
- * outro: document.querySelector( '#editor-outro' )
951
- * }, {
952
- * initialData: {
953
- * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
954
- * content: '<p>Lorem ipsum dolor sit amet.</p>',
955
- * sidePanelLeft '<blockquote>Strong quotation from article.</blockquote>':
956
- * sidePanelRight '<p>List of similar articles...</p>':
957
- * outro: '<p>Closing text.</p>'
958
- * }
959
- * } )
960
- * .then( editor => {
961
- * console.log( 'Editor was initialized', editor );
962
- *
963
- * // Append the toolbar inside a provided DOM element.
964
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
965
- * } )
966
- * .catch( err => {
967
- * console.error( err.stack );
968
- * } );
969
- * ```
970
- *
971
- * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
972
- * makes it difficult to set the content of the source element.
973
- *
974
- * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
975
- *
976
- * # Configuring the editor
977
- *
978
- * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
979
- * customizing plugins, toolbar and more.
980
- *
981
- * @param sourceElementsOrData The DOM elements that will be the source for the created editor
982
- * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
983
- *
984
- * If DOM elements are passed, their content will be automatically loaded to the editor upon initialization and the elements will be
985
- * used as the editor's editable areas. The editor data will be set back to the original element once the editor is destroyed if the
986
- * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy} option
987
- * is set to `true`.
988
- *
989
- * If the initial data is passed, a detached editor will be created. For each entry in the passed object, one editor root and one
990
- * editable DOM element will be created. You will need to attach the editable elements into the DOM manually. The elements are available
991
- * through the {@link module:editor-multi-root/multirooteditorui~MultiRootEditorUI#getEditableElement `editor.ui.getEditableElement()`}
992
- * method.
993
- * @param config The editor configuration.
994
- * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
995
- */ static create(sourceElementsOrData, config = {}) {
900
+ * Creates a new multi-root editor instance.
901
+ *
902
+ * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
903
+ * after the editor has been initialized.
904
+ *
905
+ * There are a few different ways to initialize the multi-root editor.
906
+ *
907
+ * # Using existing DOM elements:
908
+ *
909
+ * ```ts
910
+ * MultiRootEditor.create( {
911
+ * intro: document.querySelector( '#editor-intro' ),
912
+ * content: document.querySelector( '#editor-content' ),
913
+ * sidePanelLeft: document.querySelector( '#editor-side-left' ),
914
+ * sidePanelRight: document.querySelector( '#editor-side-right' ),
915
+ * outro: document.querySelector( '#editor-outro' )
916
+ * } )
917
+ * .then( editor => {
918
+ * console.log( 'Editor was initialized', editor );
919
+ *
920
+ * // Append the toolbar inside a provided DOM element.
921
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
922
+ * } )
923
+ * .catch( err => {
924
+ * console.error( err.stack );
925
+ * } );
926
+ * ```
927
+ *
928
+ * The elements' content will be used as the editor data and elements will become editable elements.
929
+ *
930
+ * # Creating a detached editor
931
+ *
932
+ * Alternatively, you can initialize the editor by passing the initial data directly as strings.
933
+ * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
934
+ *
935
+ * ```ts
936
+ * MultiRootEditor.create( {
937
+ * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
938
+ * content: '<p>Lorem ipsum dolor sit amet.</p>',
939
+ * sidePanelLeft: '<blockquote>Strong quotation from article.</blockquote>',
940
+ * sidePanelRight: '<p>List of similar articles...</p>',
941
+ * outro: '<p>Closing text.</p>'
942
+ * } )
943
+ * .then( editor => {
944
+ * console.log( 'Editor was initialized', editor );
945
+ *
946
+ * // Append the toolbar inside a provided DOM element.
947
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
948
+ *
949
+ * // Append DOM editable elements created by the editor.
950
+ * const editables = editor.ui.view.editables;
951
+ * const container = document.querySelector( '#editable-container' );
952
+ *
953
+ * container.appendChild( editables.intro.element );
954
+ * container.appendChild( editables.content.element );
955
+ * container.appendChild( editables.outro.element );
956
+ * } )
957
+ * .catch( err => {
958
+ * console.error( err.stack );
959
+ * } );
960
+ * ```
961
+ *
962
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
963
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
964
+ *
965
+ * # Using an existing DOM element (and data provided in `config.initialData`)
966
+ *
967
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
968
+ *
969
+ * ```ts
970
+ * MultiRootEditor.create( {
971
+ * intro: document.querySelector( '#editor-intro' ),
972
+ * content: document.querySelector( '#editor-content' ),
973
+ * sidePanelLeft: document.querySelector( '#editor-side-left' ),
974
+ * sidePanelRight: document.querySelector( '#editor-side-right' ),
975
+ * outro: document.querySelector( '#editor-outro' )
976
+ * }, {
977
+ * initialData: {
978
+ * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
979
+ * content: '<p>Lorem ipsum dolor sit amet.</p>',
980
+ * sidePanelLeft '<blockquote>Strong quotation from article.</blockquote>':
981
+ * sidePanelRight '<p>List of similar articles...</p>':
982
+ * outro: '<p>Closing text.</p>'
983
+ * }
984
+ * } )
985
+ * .then( editor => {
986
+ * console.log( 'Editor was initialized', editor );
987
+ *
988
+ * // Append the toolbar inside a provided DOM element.
989
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
990
+ * } )
991
+ * .catch( err => {
992
+ * console.error( err.stack );
993
+ * } );
994
+ * ```
995
+ *
996
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
997
+ * makes it difficult to set the content of the source element.
998
+ *
999
+ * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
1000
+ *
1001
+ * # Configuring the editor
1002
+ *
1003
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
1004
+ * customizing plugins, toolbar and more.
1005
+ *
1006
+ * @param sourceElementsOrData The DOM elements that will be the source for the created editor
1007
+ * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
1008
+ *
1009
+ * If DOM elements are passed, their content will be automatically loaded to the editor upon initialization and the elements will be
1010
+ * used as the editor's editable areas. The editor data will be set back to the original element once the editor is destroyed if the
1011
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy} option
1012
+ * is set to `true`.
1013
+ *
1014
+ * If the initial data is passed, a detached editor will be created. For each entry in the passed object, one editor root and one
1015
+ * editable DOM element will be created. You will need to attach the editable elements into the DOM manually. The elements are available
1016
+ * through the {@link module:editor-multi-root/multirooteditorui~MultiRootEditorUI#getEditableElement `editor.ui.getEditableElement()`}
1017
+ * method.
1018
+ * @param config The editor configuration.
1019
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
1020
+ */ static create(sourceElementsOrData, config = {}) {
996
1021
  return new Promise((resolve)=>{
997
1022
  for (const sourceItem of Object.values(sourceElementsOrData)){
998
1023
  if (isElement(sourceItem) && sourceItem.tagName === 'TEXTAREA') {
@@ -1011,26 +1036,26 @@ import { isElement as isElement$1 } from 'lodash-es';
1011
1036
  });
1012
1037
  }
1013
1038
  /**
1014
- * @internal
1015
- */ _verifyRootsWithInitialData() {
1039
+ * @internal
1040
+ */ _verifyRootsWithInitialData() {
1016
1041
  const initialData = this.config.get('initialData');
1017
1042
  // Roots that are not in the initial data.
1018
1043
  for (const rootName of this.model.document.getRootNames()){
1019
1044
  if (!(rootName in initialData)) {
1020
1045
  /**
1021
- * Editor roots do not match the
1022
- * {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
1023
- *
1024
- * This may happen for one of the two reasons:
1025
- *
1026
- * * Configuration error. The `sourceElementsOrData` parameter in
1027
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} contains different
1028
- * roots than {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
1029
- * * As the editor was initialized, the {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData`}
1030
- * configuration value or the state of the editor roots has been changed.
1031
- *
1032
- * @error multi-root-editor-root-initial-data-mismatch
1033
- */ throw new CKEditorError('multi-root-editor-root-initial-data-mismatch', null);
1046
+ * Editor roots do not match the
1047
+ * {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
1048
+ *
1049
+ * This may happen for one of the two reasons:
1050
+ *
1051
+ * * Configuration error. The `sourceElementsOrData` parameter in
1052
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} contains different
1053
+ * roots than {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
1054
+ * * As the editor was initialized, the {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData`}
1055
+ * configuration value or the state of the editor roots has been changed.
1056
+ *
1057
+ * @error multi-root-editor-root-initial-data-mismatch
1058
+ */ throw new CKEditorError('multi-root-editor-root-initial-data-mismatch', null);
1034
1059
  }
1035
1060
  }
1036
1061
  // Roots that are not in the editor.