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