@ckeditor/ckeditor5-editor-multi-root 0.0.0-nightly-20241215.0 → 0.0.0-nightly-20241217.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12,24 +12,18 @@ 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
- * 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){
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){
26
20
  super(editor);
27
21
  this.view = view;
28
22
  this._lastFocusedEditableElement = null;
29
23
  }
30
24
  /**
31
- * Initializes the UI.
32
- */ init() {
25
+ * Initializes the UI.
26
+ */ init() {
33
27
  const view = this.view;
34
28
  view.render();
35
29
  // Keep track of the last focused editable element. Knowing which one was focused
@@ -61,17 +55,17 @@ import { isElement as isElement$1 } from 'lodash-es';
61
55
  this.fire('ready');
62
56
  }
63
57
  /**
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) {
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) {
75
69
  // The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
76
70
  // But it can be available earlier if a DOM element has been passed to `MultiRootEditor.create()`.
77
71
  const editableElement = editable.element;
@@ -104,22 +98,22 @@ import { isElement as isElement$1 } from 'lodash-es';
104
98
  this._initPlaceholder(editable, placeholder);
105
99
  }
106
100
  /**
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) {
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) {
116
110
  this.editor.editing.view.detachDomRoot(editable.name);
117
111
  editable.unbind('isFocused');
118
112
  this.removeEditableElement(editable.name);
119
113
  }
120
114
  /**
121
- * @inheritDoc
122
- */ destroy() {
115
+ * @inheritDoc
116
+ */ destroy() {
123
117
  super.destroy();
124
118
  for (const editable of Object.values(this.view.editables)){
125
119
  this.removeEditable(editable);
@@ -127,8 +121,8 @@ import { isElement as isElement$1 } from 'lodash-es';
127
121
  this.view.destroy();
128
122
  }
129
123
  /**
130
- * Initializes the editor main toolbar and its panel.
131
- */ _initToolbar() {
124
+ * Initializes the editor main toolbar and its panel.
125
+ */ _initToolbar() {
132
126
  const editor = this.editor;
133
127
  const view = this.view;
134
128
  const toolbar = view.toolbar;
@@ -137,12 +131,12 @@ import { isElement as isElement$1 } from 'lodash-es';
137
131
  this.addToolbar(view.toolbar);
138
132
  }
139
133
  /**
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) {
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) {
146
140
  if (!placeholder) {
147
141
  const configPlaceholder = this.editor.config.get('placeholder');
148
142
  if (configPlaceholder) {
@@ -173,35 +167,22 @@ import { isElement as isElement$1 } from 'lodash-es';
173
167
  * to learn more about this view.
174
168
  */ class MultiRootEditorUIView extends EditorUIView {
175
169
  /**
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 = {}){
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 = {}){
205
186
  super(locale);
206
187
  this._editingView = editingView;
207
188
  this.toolbar = new ToolbarView(locale, {
@@ -243,16 +224,16 @@ import { isElement as isElement$1 } from 'lodash-es';
243
224
  });
244
225
  }
245
226
  /**
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) {
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) {
256
237
  const editable = new InlineEditableUIView(this.locale, this._editingView, editableElement, {
257
238
  label
258
239
  });
@@ -264,10 +245,10 @@ import { isElement as isElement$1 } from 'lodash-es';
264
245
  return editable;
265
246
  }
266
247
  /**
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) {
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) {
271
252
  const editable = this.editables[editableName];
272
253
  if (this.isRendered) {
273
254
  this.deregisterChild(editable);
@@ -276,8 +257,8 @@ import { isElement as isElement$1 } from 'lodash-es';
276
257
  editable.destroy();
277
258
  }
278
259
  /**
279
- * @inheritDoc
280
- */ render() {
260
+ * @inheritDoc
261
+ */ render() {
281
262
  super.render();
282
263
  this.registerChild(Object.values(this.editables));
283
264
  this.registerChild(this.toolbar);
@@ -300,34 +281,21 @@ import { isElement as isElement$1 } from 'lodash-es';
300
281
  * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
301
282
  */ class MultiRootEditor extends Editor {
302
283
  /**
303
- * @inheritDoc
304
- */ static get editorName() {
284
+ * @inheritDoc
285
+ */ static get editorName() {
305
286
  return 'MultiRootEditor';
306
287
  }
307
288
  /**
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 = {}){
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 = {}){
331
299
  const rootNames = Object.keys(sourceElementsOrData);
332
300
  const sourceIsData = rootNames.length === 0 || typeof sourceElementsOrData[rootNames[0]] === 'string';
333
301
  if (sourceIsData && config.initialData !== undefined && Object.keys(config.initialData).length > 0) {
@@ -336,6 +304,13 @@ import { isElement as isElement$1 } from 'lodash-es';
336
304
  throw new CKEditorError('editor-create-initial-data', null);
337
305
  }
338
306
  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();
339
314
  if (!sourceIsData) {
340
315
  this.sourceElements = sourceElementsOrData;
341
316
  } else {
@@ -388,13 +363,13 @@ import { isElement as isElement$1 } from 'lodash-es';
388
363
  for (const [rootName, attributes] of Object.entries(rootsAttributes)){
389
364
  if (!this.model.document.getRoot(rootName)) {
390
365
  /**
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);
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);
398
373
  }
399
374
  for (const key of Object.keys(attributes)){
400
375
  this.registerRootAttribute(key);
@@ -469,19 +444,19 @@ import { isElement as isElement$1 } from 'lodash-es';
469
444
  const root = this.model.document.getRoot(rootName);
470
445
  if (!root) {
471
446
  /**
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, {
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, {
476
451
  rootName
477
452
  });
478
453
  }
479
454
  if (root._isLoaded) {
480
455
  /**
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');
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');
485
460
  evt.stop();
486
461
  }
487
462
  }, {
@@ -489,29 +464,29 @@ import { isElement as isElement$1 } from 'lodash-es';
489
464
  });
490
465
  }
491
466
  /**
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() {
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() {
515
490
  const shouldUpdateSourceElement = this.config.get('updateSourceElementOnDestroy');
516
491
  // Cache the data and editable DOM elements, then destroy.
517
492
  // It's safe to assume that the model->view conversion will not work after `super.destroy()`,
@@ -530,78 +505,78 @@ import { isElement as isElement$1 } from 'lodash-es';
530
505
  });
531
506
  }
532
507
  /**
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 } = {}) {
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 } = {}) {
605
580
  const _addRoot = (writer)=>{
606
581
  const root = writer.addRoot(rootName, elementName);
607
582
  if (data) {
@@ -621,59 +596,59 @@ import { isElement as isElement$1 } from 'lodash-es';
621
596
  }
622
597
  }
623
598
  /**
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) {
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) {
677
652
  if (isUndoable) {
678
653
  this.model.change((writer)=>writer.detachRoot(rootName));
679
654
  } else {
@@ -683,27 +658,27 @@ import { isElement as isElement$1 } from 'lodash-es';
683
658
  }
684
659
  }
685
660
  /**
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) {
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) {
696
671
  const editable = this.ui.view.createEditable(root.rootName, undefined, label);
697
672
  this.ui.addEditable(editable, placeholder);
698
673
  this.editing.view.forceRender();
699
674
  return editable.element;
700
675
  }
701
676
  /**
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) {
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) {
707
682
  const rootName = root.rootName;
708
683
  const editable = this.ui.view.editables[rootName];
709
684
  this.ui.removeEditable(editable);
@@ -711,34 +686,34 @@ import { isElement as isElement$1 } from 'lodash-es';
711
686
  return editable.element;
712
687
  }
713
688
  /**
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 = {} } = {}) {
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 = {} } = {}) {
742
717
  // `root` will be defined as it is guaranteed by a check in a higher priority callback.
743
718
  const root = this.model.document.getRoot(rootName);
744
719
  this.model.enqueueChange({
@@ -756,15 +731,15 @@ import { isElement as isElement$1 } from 'lodash-es';
756
731
  });
757
732
  }
758
733
  /**
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) {
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) {
768
743
  const data = {};
769
744
  for (const rootName of this.model.document.getRootNames()){
770
745
  data[rootName] = this.data.get({
@@ -775,13 +750,13 @@ import { isElement as isElement$1 } from 'lodash-es';
775
750
  return data;
776
751
  }
777
752
  /**
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() {
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() {
785
760
  const rootsAttributes = {};
786
761
  for (const rootName of this.model.document.getRootNames()){
787
762
  rootsAttributes[rootName] = this.getRootAttributes(rootName);
@@ -789,11 +764,11 @@ import { isElement as isElement$1 } from 'lodash-es';
789
764
  return rootsAttributes;
790
765
  }
791
766
  /**
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) {
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) {
797
772
  const rootAttributes = {};
798
773
  const root = this.model.document.getRoot(rootName);
799
774
  for (const key of this._registeredRootsAttributesKeys){
@@ -802,15 +777,15 @@ import { isElement as isElement$1 } from 'lodash-es';
802
777
  return rootAttributes;
803
778
  }
804
779
  /**
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) {
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) {
814
789
  if (this._registeredRootsAttributesKeys.has(key)) {
815
790
  return;
816
791
  }
@@ -820,46 +795,46 @@ import { isElement as isElement$1 } from 'lodash-es';
820
795
  });
821
796
  }
822
797
  /**
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) {
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) {
857
832
  if (rootName == '$graveyard') {
858
833
  /**
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);
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);
863
838
  }
864
839
  const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
865
840
  if (locksForGivenRoot) {
@@ -875,13 +850,13 @@ import { isElement as isElement$1 } from 'lodash-es';
875
850
  }
876
851
  }
877
852
  /**
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) {
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) {
885
860
  const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
886
861
  if (!locksForGivenRoot || !locksForGivenRoot.has(lockId)) {
887
862
  return;
@@ -897,127 +872,127 @@ import { isElement as isElement$1 } from 'lodash-es';
897
872
  }
898
873
  }
899
874
  /**
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 = {}) {
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 = {}) {
1021
996
  return new Promise((resolve)=>{
1022
997
  for (const sourceItem of Object.values(sourceElementsOrData)){
1023
998
  if (isElement(sourceItem) && sourceItem.tagName === 'TEXTAREA') {
@@ -1036,26 +1011,26 @@ import { isElement as isElement$1 } from 'lodash-es';
1036
1011
  });
1037
1012
  }
1038
1013
  /**
1039
- * @internal
1040
- */ _verifyRootsWithInitialData() {
1014
+ * @internal
1015
+ */ _verifyRootsWithInitialData() {
1041
1016
  const initialData = this.config.get('initialData');
1042
1017
  // Roots that are not in the initial data.
1043
1018
  for (const rootName of this.model.document.getRootNames()){
1044
1019
  if (!(rootName in initialData)) {
1045
1020
  /**
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);
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);
1059
1034
  }
1060
1035
  }
1061
1036
  // Roots that are not in the editor.