@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 +505 -530
- package/dist/index.js.map +1 -1
- package/package.json +24 -7
- package/dist/augmentation.d.ts +0 -94
- package/dist/index.d.ts +0 -14
- package/dist/multirooteditor.d.ts +0 -548
- package/dist/multirooteditorui.d.ts +0 -78
- package/dist/multirooteditoruiview.d.ts +0 -86
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
122
|
-
|
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
|
-
|
131
|
-
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
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
|
-
|
280
|
-
|
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
|
-
|
304
|
-
|
284
|
+
* @inheritDoc
|
285
|
+
*/ static get editorName() {
|
305
286
|
return 'MultiRootEditor';
|
306
287
|
}
|
307
288
|
/**
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
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
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
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
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
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
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
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
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
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
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
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
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
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
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
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
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
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
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
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> </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
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
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
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
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
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
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
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
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
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
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
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
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
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
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
|
-
|
1040
|
-
|
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
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
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.
|