@ckeditor/ckeditor5-editor-multi-root 0.0.0-nightly-20240509.0 → 0.0.0-nightly-20240510.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 +741 -706
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -2,17 +2,35 @@
|
|
2
2
|
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
4
|
*/
|
5
|
-
import {
|
6
|
-
import {
|
5
|
+
import { Editor, secureSourceElement, Context } from '@ckeditor/ckeditor5-core/dist/index.js';
|
6
|
+
import { CKEditorError, logWarning, setDataInElement, getDataFromElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
7
7
|
import { EditorWatchdog, ContextWatchdog } from '@ckeditor/ckeditor5-watchdog/dist/index.js';
|
8
|
-
import { EditorUI, _initMenuBar, EditorUIView,
|
8
|
+
import { EditorUI, _initMenuBar, EditorUIView, ToolbarView, MenuBarView, InlineEditableUIView } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
9
9
|
import { enablePlaceholder } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
10
10
|
import { isElement as isElement$1 } from 'lodash-es';
|
11
11
|
|
12
|
-
|
12
|
+
/**
|
13
|
+
* The multi-root editor UI class.
|
14
|
+
*/ class MultiRootEditorUI extends EditorUI {
|
15
|
+
/**
|
16
|
+
* The main (top–most) view of the editor UI.
|
17
|
+
*/ view;
|
18
|
+
/**
|
19
|
+
* The editable element that was focused the last time when any of the editables had focus.
|
20
|
+
*/ _lastFocusedEditableElement;
|
21
|
+
/**
|
22
|
+
* Creates an instance of the multi-root editor UI class.
|
23
|
+
*
|
24
|
+
* @param editor The editor instance.
|
25
|
+
* @param view The view of the UI.
|
26
|
+
*/ constructor(editor, view){
|
27
|
+
super(editor);
|
28
|
+
this.view = view;
|
29
|
+
this._lastFocusedEditableElement = null;
|
30
|
+
}
|
13
31
|
/**
|
14
|
-
|
15
|
-
|
32
|
+
* Initializes the UI.
|
33
|
+
*/ init() {
|
16
34
|
const view = this.view;
|
17
35
|
view.render();
|
18
36
|
// Keep track of the last focused editable element. Knowing which one was focused
|
@@ -44,17 +62,17 @@ class MultiRootEditorUI extends EditorUI {
|
|
44
62
|
this.fire('ready');
|
45
63
|
}
|
46
64
|
/**
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
65
|
+
* Adds the editable to the editor UI.
|
66
|
+
*
|
67
|
+
* After the editable is added to the editor UI it can be considered "active".
|
68
|
+
*
|
69
|
+
* The editable is attached to the editor editing pipeline, which means that it will be updated as the editor model updates and
|
70
|
+
* changing its content will be reflected in the editor model. Keystrokes, focus handling and placeholder are initialized.
|
71
|
+
*
|
72
|
+
* @param editable The editable instance to add.
|
73
|
+
* @param placeholder Placeholder for the editable element. If not set, placeholder value from the
|
74
|
+
* {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
|
75
|
+
*/ addEditable(editable, placeholder) {
|
58
76
|
// The editable UI element in DOM is available for sure only after the editor UI view has been rendered.
|
59
77
|
// But it can be available earlier if a DOM element has been passed to `MultiRootEditor.create()`.
|
60
78
|
const editableElement = editable.element;
|
@@ -87,22 +105,22 @@ class MultiRootEditorUI extends EditorUI {
|
|
87
105
|
this._initPlaceholder(editable, placeholder);
|
88
106
|
}
|
89
107
|
/**
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
108
|
+
* Removes the editable instance from the editor UI.
|
109
|
+
*
|
110
|
+
* Removed editable can be considered "deactivated".
|
111
|
+
*
|
112
|
+
* The editable is detached from the editing pipeline, so model changes are no longer reflected in it. All handling added in
|
113
|
+
* {@link #addEditable} is removed.
|
114
|
+
*
|
115
|
+
* @param editable Editable to remove from the editor UI.
|
116
|
+
*/ removeEditable(editable) {
|
99
117
|
this.editor.editing.view.detachDomRoot(editable.name);
|
100
118
|
editable.unbind('isFocused');
|
101
119
|
this.removeEditableElement(editable.name);
|
102
120
|
}
|
103
121
|
/**
|
104
|
-
|
105
|
-
|
122
|
+
* @inheritDoc
|
123
|
+
*/ destroy() {
|
106
124
|
super.destroy();
|
107
125
|
for (const editable of Object.values(this.view.editables)){
|
108
126
|
this.removeEditable(editable);
|
@@ -110,8 +128,8 @@ class MultiRootEditorUI extends EditorUI {
|
|
110
128
|
this.view.destroy();
|
111
129
|
}
|
112
130
|
/**
|
113
|
-
|
114
|
-
|
131
|
+
* Initializes the editor main toolbar and its panel.
|
132
|
+
*/ _initToolbar() {
|
115
133
|
const editor = this.editor;
|
116
134
|
const view = this.view;
|
117
135
|
const toolbar = view.toolbar;
|
@@ -120,12 +138,12 @@ class MultiRootEditorUI extends EditorUI {
|
|
120
138
|
this.addToolbar(view.toolbar);
|
121
139
|
}
|
122
140
|
/**
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
141
|
+
* Enables the placeholder text on a given editable.
|
142
|
+
*
|
143
|
+
* @param editable Editable on which the placeholder should be set.
|
144
|
+
* @param placeholder Placeholder for the editable element. If not set, placeholder value from the
|
145
|
+
* {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
|
146
|
+
*/ _initPlaceholder(editable, placeholder) {
|
129
147
|
if (!placeholder) {
|
130
148
|
const configPlaceholder = this.editor.config.get('placeholder');
|
131
149
|
if (configPlaceholder) {
|
@@ -144,77 +162,45 @@ class MultiRootEditorUI extends EditorUI {
|
|
144
162
|
keepOnFocus: true
|
145
163
|
});
|
146
164
|
}
|
147
|
-
/**
|
148
|
-
* Creates an instance of the multi-root editor UI class.
|
149
|
-
*
|
150
|
-
* @param editor The editor instance.
|
151
|
-
* @param view The view of the UI.
|
152
|
-
*/ constructor(editor, view){
|
153
|
-
super(editor);
|
154
|
-
this.view = view;
|
155
|
-
this._lastFocusedEditableElement = null;
|
156
|
-
}
|
157
165
|
}
|
158
166
|
|
159
|
-
|
167
|
+
/**
|
168
|
+
* The multi-root editor UI view. It is a virtual view providing an inline
|
169
|
+
* {@link module:editor-multi-root/multirooteditoruiview~MultiRootEditorUIView#editable} and a
|
170
|
+
* {@link module:editor-multi-root/multirooteditoruiview~MultiRootEditorUIView#toolbar}, but without any
|
171
|
+
* specific arrangement of the components in the DOM.
|
172
|
+
*
|
173
|
+
* See {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}
|
174
|
+
* to learn more about this view.
|
175
|
+
*/ class MultiRootEditorUIView extends EditorUIView {
|
160
176
|
/**
|
161
|
-
|
162
|
-
|
163
|
-
* If `editableElement` is provided, the editable instance will be created on top of it. Otherwise, the editor will create a new
|
164
|
-
* DOM element and use it instead.
|
165
|
-
*
|
166
|
-
* @param editableName The name for the editable.
|
167
|
-
* @param editableElement DOM element for which the editable should be created.
|
168
|
-
* @returns The created editable instance.
|
169
|
-
*/ createEditable(editableName, editableElement) {
|
170
|
-
const t = this.locale.t;
|
171
|
-
const editable = new InlineEditableUIView(this.locale, this._editingView, editableElement, {
|
172
|
-
label: (editable)=>{
|
173
|
-
return t('Rich Text Editor. Editing area: %0', editable.name);
|
174
|
-
}
|
175
|
-
});
|
176
|
-
this.editables[editableName] = editable;
|
177
|
-
editable.name = editableName;
|
178
|
-
if (this.isRendered) {
|
179
|
-
this.registerChild(editable);
|
180
|
-
}
|
181
|
-
return editable;
|
182
|
-
}
|
177
|
+
* The main toolbar of the multi-root editor UI.
|
178
|
+
*/ toolbar;
|
183
179
|
/**
|
184
|
-
|
185
|
-
|
186
|
-
* @param editableName The name of the editable that should be removed.
|
187
|
-
*/ removeEditable(editableName) {
|
188
|
-
const editable = this.editables[editableName];
|
189
|
-
if (this.isRendered) {
|
190
|
-
this.deregisterChild(editable);
|
191
|
-
}
|
192
|
-
delete this.editables[editableName];
|
193
|
-
editable.destroy();
|
194
|
-
}
|
180
|
+
* Menu bar view instance.
|
181
|
+
*/ menuBarView;
|
195
182
|
/**
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
}
|
183
|
+
* Editable elements used by the multi-root editor UI.
|
184
|
+
*/ editables;
|
185
|
+
editable;
|
186
|
+
/**
|
187
|
+
* The editing view instance this view is related to.
|
188
|
+
*/ _editingView;
|
203
189
|
/**
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
190
|
+
* Creates an instance of the multi-root editor UI view.
|
191
|
+
*
|
192
|
+
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
193
|
+
* @param editingView The editing view instance this view is related to.
|
194
|
+
* @param editableNames Names for all editable views. For each name, one
|
195
|
+
* {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`} instance will be initialized.
|
196
|
+
* @param options Configuration options for the view instance.
|
197
|
+
* @param options.editableElements The editable elements to be used, assigned to their names. If not specified, they will be
|
198
|
+
* automatically created by {@link module:ui/editableui/inline/inlineeditableuiview~InlineEditableUIView `InlineEditableUIView`}
|
199
|
+
* instances.
|
200
|
+
* @param options.shouldToolbarGroupWhenFull When set to `true` enables automatic items grouping
|
201
|
+
* in the main {@link module:editor-multi-root/multirooteditoruiview~MultiRootEditorUIView#toolbar toolbar}.
|
202
|
+
* See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
|
203
|
+
*/ constructor(locale, editingView, editableNames, options = {}){
|
218
204
|
super(locale);
|
219
205
|
this._editingView = editingView;
|
220
206
|
this.toolbar = new ToolbarView(locale, {
|
@@ -251,6 +237,49 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
251
237
|
}
|
252
238
|
});
|
253
239
|
}
|
240
|
+
/**
|
241
|
+
* Creates an editable instance with given name and registers it in the editor UI view.
|
242
|
+
*
|
243
|
+
* If `editableElement` is provided, the editable instance will be created on top of it. Otherwise, the editor will create a new
|
244
|
+
* DOM element and use it instead.
|
245
|
+
*
|
246
|
+
* @param editableName The name for the editable.
|
247
|
+
* @param editableElement DOM element for which the editable should be created.
|
248
|
+
* @returns The created editable instance.
|
249
|
+
*/ createEditable(editableName, editableElement) {
|
250
|
+
const t = this.locale.t;
|
251
|
+
const editable = new InlineEditableUIView(this.locale, this._editingView, editableElement, {
|
252
|
+
label: (editable)=>{
|
253
|
+
return t('Rich Text Editor. Editing area: %0', editable.name);
|
254
|
+
}
|
255
|
+
});
|
256
|
+
this.editables[editableName] = editable;
|
257
|
+
editable.name = editableName;
|
258
|
+
if (this.isRendered) {
|
259
|
+
this.registerChild(editable);
|
260
|
+
}
|
261
|
+
return editable;
|
262
|
+
}
|
263
|
+
/**
|
264
|
+
* Destroys and removes the editable from the editor UI view.
|
265
|
+
*
|
266
|
+
* @param editableName The name of the editable that should be removed.
|
267
|
+
*/ removeEditable(editableName) {
|
268
|
+
const editable = this.editables[editableName];
|
269
|
+
if (this.isRendered) {
|
270
|
+
this.deregisterChild(editable);
|
271
|
+
}
|
272
|
+
delete this.editables[editableName];
|
273
|
+
editable.destroy();
|
274
|
+
}
|
275
|
+
/**
|
276
|
+
* @inheritDoc
|
277
|
+
*/ render() {
|
278
|
+
super.render();
|
279
|
+
this.registerChild(Object.values(this.editables));
|
280
|
+
this.registerChild(this.toolbar);
|
281
|
+
this.registerChild(this.menuBarView);
|
282
|
+
}
|
254
283
|
}
|
255
284
|
|
256
285
|
/**
|
@@ -284,29 +313,212 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
284
313
|
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
|
285
314
|
*/ class MultiRootEditor extends Editor {
|
286
315
|
/**
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
316
|
+
* @inheritDoc
|
317
|
+
*/ ui;
|
318
|
+
/**
|
319
|
+
* The elements on which the editor has been initialized.
|
320
|
+
*/ sourceElements;
|
321
|
+
/**
|
322
|
+
* Holds attributes keys that were passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `rootsAttributes`}
|
323
|
+
* config property and should be returned by {@link #getRootsAttributes}.
|
324
|
+
*/ _registeredRootsAttributesKeys = new Set();
|
325
|
+
/**
|
326
|
+
* A set of lock IDs for enabling or disabling particular root.
|
327
|
+
*/ _readOnlyRootLocks = new Map();
|
328
|
+
/**
|
329
|
+
* Creates an instance of the multi-root editor.
|
330
|
+
*
|
331
|
+
* **Note:** Do not use the constructor to create editor instances. Use the static
|
332
|
+
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
|
333
|
+
*
|
334
|
+
* @param sourceElementsOrData The DOM elements that will be the source for the created editor
|
335
|
+
* or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
|
336
|
+
* For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
|
337
|
+
* @param config The editor configuration.
|
338
|
+
*/ constructor(sourceElementsOrData, config = {}){
|
339
|
+
const rootNames = Object.keys(sourceElementsOrData);
|
340
|
+
const sourceIsData = rootNames.length === 0 || typeof sourceElementsOrData[rootNames[0]] === 'string';
|
341
|
+
if (sourceIsData && config.initialData !== undefined && Object.keys(config.initialData).length > 0) {
|
342
|
+
// Documented in core/editor/editorconfig.jsdoc.
|
343
|
+
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
344
|
+
throw new CKEditorError('editor-create-initial-data', null);
|
345
|
+
}
|
346
|
+
super(config);
|
347
|
+
if (!sourceIsData) {
|
348
|
+
this.sourceElements = sourceElementsOrData;
|
349
|
+
} else {
|
350
|
+
this.sourceElements = {};
|
351
|
+
}
|
352
|
+
if (this.config.get('initialData') === undefined) {
|
353
|
+
// Create initial data object containing data from all roots.
|
354
|
+
const initialData = {};
|
355
|
+
for (const rootName of rootNames){
|
356
|
+
initialData[rootName] = getInitialData(sourceElementsOrData[rootName]);
|
357
|
+
}
|
358
|
+
this.config.set('initialData', initialData);
|
359
|
+
}
|
360
|
+
if (!sourceIsData) {
|
361
|
+
for (const rootName of rootNames){
|
362
|
+
secureSourceElement(this, sourceElementsOrData[rootName]);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
this.editing.view.document.roots.on('add', (evt, viewRoot)=>{
|
366
|
+
// Here we change the standard binding of readOnly flag by adding
|
367
|
+
// additional constraint that multi-root has (enabling / disabling particular root).
|
368
|
+
viewRoot.unbind('isReadOnly');
|
369
|
+
viewRoot.bind('isReadOnly').to(this.editing.view.document, 'isReadOnly', (isReadOnly)=>{
|
370
|
+
return isReadOnly || this._readOnlyRootLocks.has(viewRoot.rootName);
|
371
|
+
});
|
372
|
+
// Hacky solution to nested editables.
|
373
|
+
// Nested editables should be managed each separately and do not base on view document or view root.
|
374
|
+
viewRoot.on('change:isReadOnly', (evt, prop, value)=>{
|
375
|
+
const viewRange = this.editing.view.createRangeIn(viewRoot);
|
376
|
+
for (const viewItem of viewRange.getItems()){
|
377
|
+
if (viewItem.is('editableElement')) {
|
378
|
+
viewItem.unbind('isReadOnly');
|
379
|
+
viewItem.isReadOnly = value;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
});
|
383
|
+
});
|
384
|
+
for (const rootName of rootNames){
|
385
|
+
// Create root and `UIView` element for each editable container.
|
386
|
+
this.model.document.createRoot('$root', rootName);
|
387
|
+
}
|
388
|
+
if (this.config.get('lazyRoots')) {
|
389
|
+
for (const rootName of this.config.get('lazyRoots')){
|
390
|
+
const root = this.model.document.createRoot('$root', rootName);
|
391
|
+
root._isLoaded = false;
|
392
|
+
}
|
393
|
+
}
|
394
|
+
if (this.config.get('rootsAttributes')) {
|
395
|
+
const rootsAttributes = this.config.get('rootsAttributes');
|
396
|
+
for (const [rootName, attributes] of Object.entries(rootsAttributes)){
|
397
|
+
if (!this.model.document.getRoot(rootName)) {
|
398
|
+
/**
|
399
|
+
* Trying to set attributes on a non-existing root.
|
400
|
+
*
|
401
|
+
* Roots specified in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes} do not match initial
|
402
|
+
* editor roots.
|
403
|
+
*
|
404
|
+
* @error multi-root-editor-root-attributes-no-root
|
405
|
+
*/ throw new CKEditorError('multi-root-editor-root-attributes-no-root', null);
|
406
|
+
}
|
407
|
+
for (const key of Object.keys(attributes)){
|
408
|
+
this.registerRootAttribute(key);
|
409
|
+
}
|
410
|
+
}
|
411
|
+
this.data.on('init', ()=>{
|
412
|
+
this.model.enqueueChange({
|
413
|
+
isUndoable: false
|
414
|
+
}, (writer)=>{
|
415
|
+
for (const [name, attributes] of Object.entries(rootsAttributes)){
|
416
|
+
const root = this.model.document.getRoot(name);
|
417
|
+
for (const [key, value] of Object.entries(attributes)){
|
418
|
+
if (value !== null) {
|
419
|
+
writer.setAttribute(key, value, root);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
});
|
424
|
+
});
|
425
|
+
}
|
426
|
+
const options = {
|
427
|
+
shouldToolbarGroupWhenFull: !this.config.get('toolbar.shouldNotGroupWhenFull'),
|
428
|
+
editableElements: sourceIsData ? undefined : sourceElementsOrData
|
429
|
+
};
|
430
|
+
const view = new MultiRootEditorUIView(this.locale, this.editing.view, rootNames, options);
|
431
|
+
this.ui = new MultiRootEditorUI(this, view);
|
432
|
+
this.model.document.on('change:data', ()=>{
|
433
|
+
const changedRoots = this.model.document.differ.getChangedRoots();
|
434
|
+
// Fire detaches first. If there are multiple roots removed and added in one batch, it should be easier to handle if
|
435
|
+
// changes aren't mixed. Detaching will usually lead to just removing DOM elements. Detaching first will lead to a clean DOM
|
436
|
+
// when new editables are added in `addRoot` event.
|
437
|
+
for (const changes of changedRoots){
|
438
|
+
const root = this.model.document.getRoot(changes.name);
|
439
|
+
if (changes.state == 'detached') {
|
440
|
+
this.fire('detachRoot', root);
|
441
|
+
}
|
442
|
+
}
|
443
|
+
for (const changes of changedRoots){
|
444
|
+
const root = this.model.document.getRoot(changes.name);
|
445
|
+
if (changes.state == 'attached') {
|
446
|
+
this.fire('addRoot', root);
|
447
|
+
}
|
448
|
+
}
|
449
|
+
});
|
450
|
+
// Overwrite `Model#canEditAt()` decorated method.
|
451
|
+
// Check if the provided selection is inside a read-only root. If so, return `false`.
|
452
|
+
this.listenTo(this.model, 'canEditAt', (evt, [selection])=>{
|
453
|
+
// Skip empty selections.
|
454
|
+
if (!selection) {
|
455
|
+
return;
|
456
|
+
}
|
457
|
+
let selectionInReadOnlyRoot = false;
|
458
|
+
for (const range of selection.getRanges()){
|
459
|
+
const root = range.root;
|
460
|
+
if (this._readOnlyRootLocks.has(root.rootName)) {
|
461
|
+
selectionInReadOnlyRoot = true;
|
462
|
+
break;
|
463
|
+
}
|
464
|
+
}
|
465
|
+
// If selection is in read-only root, return `false` and prevent further processing.
|
466
|
+
// Otherwise, allow for other callbacks (or default callback) to evaluate.
|
467
|
+
if (selectionInReadOnlyRoot) {
|
468
|
+
evt.return = false;
|
469
|
+
evt.stop();
|
470
|
+
}
|
471
|
+
}, {
|
472
|
+
priority: 'high'
|
473
|
+
});
|
474
|
+
this.decorate('loadRoot');
|
475
|
+
this.on('loadRoot', (evt, [rootName])=>{
|
476
|
+
const root = this.model.document.getRoot(rootName);
|
477
|
+
if (!root) {
|
478
|
+
/**
|
479
|
+
* The root to load does not exist.
|
480
|
+
*
|
481
|
+
* @error multi-root-editor-load-root-no-root
|
482
|
+
*/ throw new CKEditorError('multi-root-editor-load-root-no-root', this, {
|
483
|
+
rootName
|
484
|
+
});
|
485
|
+
}
|
486
|
+
if (root._isLoaded) {
|
487
|
+
/**
|
488
|
+
* The root to load was already loaded before. The `loadRoot()` call has no effect.
|
489
|
+
*
|
490
|
+
* @error multi-root-editor-load-root-already-loaded
|
491
|
+
*/ logWarning('multi-root-editor-load-root-already-loaded');
|
492
|
+
evt.stop();
|
493
|
+
}
|
494
|
+
}, {
|
495
|
+
priority: 'highest'
|
496
|
+
});
|
497
|
+
}
|
498
|
+
/**
|
499
|
+
* Destroys the editor instance, releasing all resources used by it.
|
500
|
+
*
|
501
|
+
* Updates the original editor element with the data if the
|
502
|
+
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
|
503
|
+
* configuration option is set to `true`.
|
504
|
+
*
|
505
|
+
* **Note**: The multi-root editor does not remove the toolbar and editable when destroyed. You can
|
506
|
+
* do that yourself in the destruction chain, if you need to:
|
507
|
+
*
|
508
|
+
* ```ts
|
509
|
+
* editor.destroy().then( () => {
|
510
|
+
* // Remove the toolbar from DOM.
|
511
|
+
* editor.ui.view.toolbar.element.remove();
|
512
|
+
*
|
513
|
+
* // Remove editable elements from DOM.
|
514
|
+
* for ( const editable of Object.values( editor.ui.view.editables ) ) {
|
515
|
+
* editable.element.remove();
|
516
|
+
* }
|
517
|
+
*
|
518
|
+
* console.log( 'Editor was destroyed' );
|
519
|
+
* } );
|
520
|
+
* ```
|
521
|
+
*/ destroy() {
|
310
522
|
const shouldUpdateSourceElement = this.config.get('updateSourceElementOnDestroy');
|
311
523
|
// Cache the data and editable DOM elements, then destroy.
|
312
524
|
// It's safe to assume that the model->view conversion will not work after `super.destroy()`,
|
@@ -325,78 +537,78 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
325
537
|
});
|
326
538
|
}
|
327
539
|
/**
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
540
|
+
* Adds a new root to the editor.
|
541
|
+
*
|
542
|
+
* ```ts
|
543
|
+
* editor.addRoot( 'myRoot', { data: '<p>Initial root data.</p>' } );
|
544
|
+
* ```
|
545
|
+
*
|
546
|
+
* After a root is added, you will be able to modify and retrieve its data.
|
547
|
+
*
|
548
|
+
* All root names must be unique. An error will be thrown if you will try to create a root with the name same as
|
549
|
+
* an already existing, attached root. However, you can call this method for a detached root. See also {@link #detachRoot}.
|
550
|
+
*
|
551
|
+
* Whenever a root is added, the editor instance will fire {@link #event:addRoot `addRoot` event}. The event is also called when
|
552
|
+
* the root is added indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
|
553
|
+
*
|
554
|
+
* Note, that this method only adds a root to the editor model. It **does not** create a DOM editable element for the new root.
|
555
|
+
* Until such element is created (and attached to the root), the root is "virtual": it is not displayed anywhere and its data can
|
556
|
+
* be changed only using the editor API.
|
557
|
+
*
|
558
|
+
* To create a DOM editable element for the root, listen to {@link #event:addRoot `addRoot` event} and call {@link #createEditable}.
|
559
|
+
* Then, insert the DOM element in a desired place, that will depend on the integration with your application and your requirements.
|
560
|
+
*
|
561
|
+
* ```ts
|
562
|
+
* editor.on( 'addRoot', ( evt, root ) => {
|
563
|
+
* const editableElement = editor.createEditable( root );
|
564
|
+
*
|
565
|
+
* // You may want to create a more complex DOM structure here.
|
566
|
+
* //
|
567
|
+
* // Alternatively, you may want to create a DOM structure before
|
568
|
+
* // calling `editor.addRoot()` and only append `editableElement` at
|
569
|
+
* // a proper place.
|
570
|
+
*
|
571
|
+
* document.querySelector( '#editors' ).appendChild( editableElement );
|
572
|
+
* } );
|
573
|
+
*
|
574
|
+
* // ...
|
575
|
+
*
|
576
|
+
* editor.addRoot( 'myRoot' ); // Will create a root, a DOM editable element and append it to `#editors` container element.
|
577
|
+
* ```
|
578
|
+
*
|
579
|
+
* You can set root attributes on the new root while you add it:
|
580
|
+
*
|
581
|
+
* ```ts
|
582
|
+
* // Add a collapsed root at fourth position from top.
|
583
|
+
* // Keep in mind that these are just examples of attributes. You need to provide your own features that will handle the attributes.
|
584
|
+
* editor.addRoot( 'myRoot', { attributes: { isCollapsed: true, index: 4 } } );
|
585
|
+
* ```
|
586
|
+
*
|
587
|
+
* Note that attributes added together with a root are automatically registered.
|
588
|
+
*
|
589
|
+
* See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
|
590
|
+
* {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
|
591
|
+
*
|
592
|
+
* By setting `isUndoable` flag to `true`, you can allow for detaching the root using the undo feature.
|
593
|
+
*
|
594
|
+
* Additionally, you can group adding multiple roots in one undo step. This can be useful if you add multiple roots that are
|
595
|
+
* combined into one, bigger UI element, and want them all to be undone together.
|
596
|
+
*
|
597
|
+
* ```ts
|
598
|
+
* let rowId = 0;
|
599
|
+
*
|
600
|
+
* editor.model.change( () => {
|
601
|
+
* editor.addRoot( 'left-row-' + rowId, { isUndoable: true } );
|
602
|
+
* editor.addRoot( 'center-row-' + rowId, { isUndoable: true } );
|
603
|
+
* editor.addRoot( 'right-row-' + rowId, { isUndoable: true } );
|
604
|
+
*
|
605
|
+
* rowId++;
|
606
|
+
* } );
|
607
|
+
* ```
|
608
|
+
*
|
609
|
+
* @param rootName Name of the root to add.
|
610
|
+
* @param options Additional options for the added root.
|
611
|
+
*/ addRoot(rootName, { data = '', attributes = {}, elementName = '$root', isUndoable = false } = {}) {
|
400
612
|
const _addRoot = (writer)=>{
|
401
613
|
const root = writer.addRoot(rootName, elementName);
|
402
614
|
if (data) {
|
@@ -416,59 +628,59 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
416
628
|
}
|
417
629
|
}
|
418
630
|
/**
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
631
|
+
* Detaches a root from the editor.
|
632
|
+
*
|
633
|
+
* ```ts
|
634
|
+
* editor.detachRoot( 'myRoot' );
|
635
|
+
* ```
|
636
|
+
*
|
637
|
+
* A detached root is not entirely removed from the editor model, however it can be considered removed.
|
638
|
+
*
|
639
|
+
* After a root is detached all its children are removed, all markers inside it are removed, and whenever something is inserted to it,
|
640
|
+
* it is automatically removed as well. Finally, a detached root is not returned by
|
641
|
+
* {@link module:engine/model/document~Document#getRootNames} by default.
|
642
|
+
*
|
643
|
+
* It is possible to re-add a previously detached root calling {@link #addRoot}.
|
644
|
+
*
|
645
|
+
* Whenever a root is detached, the editor instance will fire {@link #event:detachRoot `detachRoot` event}. The event is also
|
646
|
+
* called when the root is detached indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
|
647
|
+
*
|
648
|
+
* Note, that this method only detached a root in the editor model. It **does not** destroy the DOM editable element linked with
|
649
|
+
* the root and it **does not** remove the DOM element from the DOM structure of your application.
|
650
|
+
*
|
651
|
+
* To properly remove a DOM editable element after a root was detached, listen to {@link #event:detachRoot `detachRoot` event}
|
652
|
+
* and call {@link #detachEditable}. Then, remove the DOM element from your application.
|
653
|
+
*
|
654
|
+
* ```ts
|
655
|
+
* editor.on( 'detachRoot', ( evt, root ) => {
|
656
|
+
* const editableElement = editor.detachEditable( root );
|
657
|
+
*
|
658
|
+
* // You may want to do an additional DOM clean-up here.
|
659
|
+
*
|
660
|
+
* editableElement.remove();
|
661
|
+
* } );
|
662
|
+
*
|
663
|
+
* // ...
|
664
|
+
*
|
665
|
+
* editor.detachRoot( 'myRoot' ); // Will detach the root, and remove the DOM editable element.
|
666
|
+
* ```
|
667
|
+
*
|
668
|
+
* By setting `isUndoable` flag to `true`, you can allow for re-adding the root using the undo feature.
|
669
|
+
*
|
670
|
+
* Additionally, you can group detaching multiple roots in one undo step. This can be useful if the roots are combined into one,
|
671
|
+
* bigger UI element, and you want them all to be re-added together.
|
672
|
+
*
|
673
|
+
* ```ts
|
674
|
+
* editor.model.change( () => {
|
675
|
+
* editor.detachRoot( 'left-row-3', true );
|
676
|
+
* editor.detachRoot( 'center-row-3', true );
|
677
|
+
* editor.detachRoot( 'right-row-3', true );
|
678
|
+
* } );
|
679
|
+
* ```
|
680
|
+
*
|
681
|
+
* @param rootName Name of the root to detach.
|
682
|
+
* @param isUndoable Whether detaching the root can be undone (using the undo feature) or not.
|
683
|
+
*/ detachRoot(rootName, isUndoable = false) {
|
472
684
|
if (isUndoable) {
|
473
685
|
this.model.change((writer)=>writer.detachRoot(rootName));
|
474
686
|
} else {
|
@@ -478,26 +690,26 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
478
690
|
}
|
479
691
|
}
|
480
692
|
/**
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
693
|
+
* Creates and returns a new DOM editable element for the given root element.
|
694
|
+
*
|
695
|
+
* The new DOM editable is attached to the model root and can be used to modify the root content.
|
696
|
+
*
|
697
|
+
* @param root Root for which the editable element should be created.
|
698
|
+
* @param placeholder Placeholder for the editable element. If not set, placeholder value from the
|
699
|
+
* {@link module:core/editor/editorconfig~EditorConfig#placeholder editor configuration} will be used (if it was provided).
|
700
|
+
* @returns The created DOM element. Append it in a desired place in your application.
|
701
|
+
*/ createEditable(root, placeholder) {
|
490
702
|
const editable = this.ui.view.createEditable(root.rootName);
|
491
703
|
this.ui.addEditable(editable, placeholder);
|
492
704
|
this.editing.view.forceRender();
|
493
705
|
return editable.element;
|
494
706
|
}
|
495
707
|
/**
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
708
|
+
* Detaches the DOM editable element that was attached to the given root.
|
709
|
+
*
|
710
|
+
* @param root Root for which the editable element should be detached.
|
711
|
+
* @returns The DOM element that was detached. You may want to remove it from your application DOM structure.
|
712
|
+
*/ detachEditable(root) {
|
501
713
|
const rootName = root.rootName;
|
502
714
|
const editable = this.ui.view.editables[rootName];
|
503
715
|
this.ui.removeEditable(editable);
|
@@ -505,34 +717,34 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
505
717
|
return editable.element;
|
506
718
|
}
|
507
719
|
/**
|
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
|
-
|
720
|
+
* Loads a root that has previously been declared in {@link module:core/editor/editorconfig~EditorConfig#lazyRoots `lazyRoots`}
|
721
|
+
* configuration option.
|
722
|
+
*
|
723
|
+
* Only roots specified in the editor config can be loaded. A root cannot be loaded multiple times. A root cannot be unloaded and
|
724
|
+
* loading a root cannot be reverted using the undo feature.
|
725
|
+
*
|
726
|
+
* When a root becomes loaded, it will be treated by the editor as though it was just added. This, among others, means that all
|
727
|
+
* related events and mechanisms will be fired, including {@link ~MultiRootEditor#event:addRoot `addRoot` event},
|
728
|
+
* {@link module:engine/model/document~Document#event:change `model.Document` `change` event}, model post-fixers and conversion.
|
729
|
+
*
|
730
|
+
* Until the root becomes loaded, all above mechanisms are suppressed.
|
731
|
+
*
|
732
|
+
* This method is {@link module:utils/observablemixin~Observable#decorate decorated}.
|
733
|
+
*
|
734
|
+
* Note that attributes loaded together with a root are automatically registered.
|
735
|
+
*
|
736
|
+
* See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
|
737
|
+
* {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes` configuration option}.
|
738
|
+
*
|
739
|
+
* When this method is used in real-time collaboration environment, its effects become asynchronous as the editor will first synchronize
|
740
|
+
* with the remote editing session, before the root is added to the editor.
|
741
|
+
*
|
742
|
+
* If the root has been already loaded by any other client, the additional data passed in `loadRoot()` parameters will be ignored.
|
743
|
+
*
|
744
|
+
* @param rootName Name of the root to load.
|
745
|
+
* @param options Additional options for the loaded root.
|
746
|
+
* @fires loadRoot
|
747
|
+
*/ loadRoot(rootName, { data = '', attributes = {} } = {}) {
|
536
748
|
// `root` will be defined as it is guaranteed by a check in a higher priority callback.
|
537
749
|
const root = this.model.document.getRoot(rootName);
|
538
750
|
this.model.enqueueChange({
|
@@ -550,15 +762,15 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
550
762
|
});
|
551
763
|
}
|
552
764
|
/**
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
765
|
+
* Returns the document data for all attached roots.
|
766
|
+
*
|
767
|
+
* @param options Additional configuration for the retrieved data.
|
768
|
+
* Editor features may introduce more configuration options that can be set through this parameter.
|
769
|
+
* @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
|
770
|
+
* which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
|
771
|
+
* use `'none'`. In such cases exact content will be returned (for example `'<p> </p>'` for an empty editor).
|
772
|
+
* @returns The full document data.
|
773
|
+
*/ getFullData(options) {
|
562
774
|
const data = {};
|
563
775
|
for (const rootName of this.model.document.getRootNames()){
|
564
776
|
data[rootName] = this.data.get({
|
@@ -569,13 +781,13 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
569
781
|
return data;
|
570
782
|
}
|
571
783
|
/**
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
784
|
+
* Returns attributes for all attached roots.
|
785
|
+
*
|
786
|
+
* Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
|
787
|
+
* If a registered root attribute is not set for a given root, `null` will be returned.
|
788
|
+
*
|
789
|
+
* @returns Object with roots attributes. Keys are roots names, while values are attributes set on given root.
|
790
|
+
*/ getRootsAttributes() {
|
579
791
|
const rootsAttributes = {};
|
580
792
|
for (const rootName of this.model.document.getRootNames()){
|
581
793
|
rootsAttributes[rootName] = this.getRootAttributes(rootName);
|
@@ -583,11 +795,11 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
583
795
|
return rootsAttributes;
|
584
796
|
}
|
585
797
|
/**
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
798
|
+
* Returns attributes for the specified root.
|
799
|
+
*
|
800
|
+
* Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
|
801
|
+
* If a registered root attribute is not set for a given root, `null` will be returned.
|
802
|
+
*/ getRootAttributes(rootName) {
|
591
803
|
const rootAttributes = {};
|
592
804
|
const root = this.model.document.getRoot(rootName);
|
593
805
|
for (const key of this._registeredRootsAttributesKeys){
|
@@ -596,15 +808,15 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
596
808
|
return rootAttributes;
|
597
809
|
}
|
598
810
|
/**
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
811
|
+
* Registers given string as a root attribute key. Registered root attributes are added to
|
812
|
+
* {@link module:engine/model/schema~Schema schema}, and also returned by
|
813
|
+
* {@link ~MultiRootEditor#getRootAttributes `getRootAttributes()`} and
|
814
|
+
* {@link ~MultiRootEditor#getRootsAttributes `getRootsAttributes()`}.
|
815
|
+
*
|
816
|
+
* Note: attributes passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `config.rootsAttributes`} are
|
817
|
+
* automatically registered as the editor is initialized. However, registering the same attribute twice does not have any negative
|
818
|
+
* impact, so it is recommended to use this method in any feature that uses roots attributes.
|
819
|
+
*/ registerRootAttribute(key) {
|
608
820
|
if (this._registeredRootsAttributesKeys.has(key)) {
|
609
821
|
return;
|
610
822
|
}
|
@@ -614,46 +826,46 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
614
826
|
});
|
615
827
|
}
|
616
828
|
/**
|
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
|
-
|
829
|
+
* Switches given editor root to the read-only mode.
|
830
|
+
*
|
831
|
+
* In contrary to {@link module:core/editor/editor~Editor#enableReadOnlyMode `enableReadOnlyMode()`}, which switches the whole editor
|
832
|
+
* 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
|
833
|
+
* editing only a part of the editor content.
|
834
|
+
*
|
835
|
+
* When you switch a root to the read-only mode, you need provide a unique identifier (`lockId`) that will identify this request. You
|
836
|
+
* will need to provide the same `lockId` when you will want to
|
837
|
+
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot re-enable} the root.
|
838
|
+
*
|
839
|
+
* ```ts
|
840
|
+
* const model = editor.model;
|
841
|
+
* const myRoot = model.document.getRoot( 'myRoot' );
|
842
|
+
*
|
843
|
+
* editor.disableRoot( 'myRoot', 'my-lock' );
|
844
|
+
* model.canEditAt( myRoot ); // `false`
|
845
|
+
*
|
846
|
+
* editor.disableRoot( 'myRoot', 'other-lock' );
|
847
|
+
* editor.disableRoot( 'myRoot', 'other-lock' ); // Multiple locks with the same ID have no effect.
|
848
|
+
* model.canEditAt( myRoot ); // `false`
|
849
|
+
*
|
850
|
+
* editor.enableRoot( 'myRoot', 'my-lock' );
|
851
|
+
* model.canEditAt( myRoot ); // `false`
|
852
|
+
*
|
853
|
+
* editor.enableRoot( 'myRoot', 'other-lock' );
|
854
|
+
* model.canEditAt( myRoot ); // `true`
|
855
|
+
* ```
|
856
|
+
*
|
857
|
+
* See also {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode()`} and
|
858
|
+
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot `MultiRootEditor#enableRoot()`}.
|
859
|
+
*
|
860
|
+
* @param rootName Name of the root to switch to read-only mode.
|
861
|
+
* @param lockId A unique ID for setting the editor to the read-only state.
|
862
|
+
*/ disableRoot(rootName, lockId) {
|
651
863
|
if (rootName == '$graveyard') {
|
652
864
|
/**
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
865
|
+
* You cannot disable the `$graveyard` root.
|
866
|
+
*
|
867
|
+
* @error multi-root-editor-cannot-disable-graveyard-root
|
868
|
+
*/ throw new CKEditorError('multi-root-editor-cannot-disable-graveyard-root', this);
|
657
869
|
}
|
658
870
|
const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
|
659
871
|
if (locksForGivenRoot) {
|
@@ -669,13 +881,13 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
669
881
|
}
|
670
882
|
}
|
671
883
|
/**
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
884
|
+
* Removes given read-only lock from the given root.
|
885
|
+
*
|
886
|
+
* See {@link module:editor-multi-root/multirooteditor~MultiRootEditor#disableRoot `disableRoot()`}.
|
887
|
+
*
|
888
|
+
* @param rootName Name of the root to switch back from the read-only mode.
|
889
|
+
* @param lockId A unique ID for setting the editor to the read-only state.
|
890
|
+
*/ enableRoot(rootName, lockId) {
|
679
891
|
const locksForGivenRoot = this._readOnlyRootLocks.get(rootName);
|
680
892
|
if (!locksForGivenRoot || !locksForGivenRoot.has(lockId)) {
|
681
893
|
return;
|
@@ -691,139 +903,139 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
691
903
|
}
|
692
904
|
}
|
693
905
|
/**
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
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
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
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
|
-
|
906
|
+
* Creates a new multi-root editor instance.
|
907
|
+
*
|
908
|
+
* **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
|
909
|
+
* after the editor has been initialized.
|
910
|
+
*
|
911
|
+
* There are a few different ways to initialize the multi-root editor.
|
912
|
+
*
|
913
|
+
* # Using existing DOM elements:
|
914
|
+
*
|
915
|
+
* ```ts
|
916
|
+
* MultiRootEditor.create( {
|
917
|
+
* intro: document.querySelector( '#editor-intro' ),
|
918
|
+
* content: document.querySelector( '#editor-content' ),
|
919
|
+
* sidePanelLeft: document.querySelector( '#editor-side-left' ),
|
920
|
+
* sidePanelRight: document.querySelector( '#editor-side-right' ),
|
921
|
+
* outro: document.querySelector( '#editor-outro' )
|
922
|
+
* } )
|
923
|
+
* .then( editor => {
|
924
|
+
* console.log( 'Editor was initialized', editor );
|
925
|
+
*
|
926
|
+
* // Append the toolbar inside a provided DOM element.
|
927
|
+
* document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
|
928
|
+
* } )
|
929
|
+
* .catch( err => {
|
930
|
+
* console.error( err.stack );
|
931
|
+
* } );
|
932
|
+
* ```
|
933
|
+
*
|
934
|
+
* The elements' content will be used as the editor data and elements will become editable elements.
|
935
|
+
*
|
936
|
+
* # Creating a detached editor
|
937
|
+
*
|
938
|
+
* Alternatively, you can initialize the editor by passing the initial data directly as strings.
|
939
|
+
* In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
|
940
|
+
*
|
941
|
+
* ```ts
|
942
|
+
* MultiRootEditor.create( {
|
943
|
+
* intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
|
944
|
+
* content: '<p>Lorem ipsum dolor sit amet.</p>',
|
945
|
+
* sidePanelLeft: '<blockquote>Strong quotation from article.</blockquote>',
|
946
|
+
* sidePanelRight: '<p>List of similar articles...</p>',
|
947
|
+
* outro: '<p>Closing text.</p>'
|
948
|
+
* } )
|
949
|
+
* .then( editor => {
|
950
|
+
* console.log( 'Editor was initialized', editor );
|
951
|
+
*
|
952
|
+
* // Append the toolbar inside a provided DOM element.
|
953
|
+
* document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
|
954
|
+
*
|
955
|
+
* // Append DOM editable elements created by the editor.
|
956
|
+
* const editables = editor.ui.view.editables;
|
957
|
+
* const container = document.querySelector( '#editable-container' );
|
958
|
+
*
|
959
|
+
* container.appendChild( editables.intro.element );
|
960
|
+
* container.appendChild( editables.content.element );
|
961
|
+
* container.appendChild( editables.outro.element );
|
962
|
+
* } )
|
963
|
+
* .catch( err => {
|
964
|
+
* console.error( err.stack );
|
965
|
+
* } );
|
966
|
+
* ```
|
967
|
+
*
|
968
|
+
* This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
|
969
|
+
* web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
|
970
|
+
*
|
971
|
+
* # Using an existing DOM element (and data provided in `config.initialData`)
|
972
|
+
*
|
973
|
+
* You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
|
974
|
+
*
|
975
|
+
* ```ts
|
976
|
+
* MultiRootEditor.create( {
|
977
|
+
* intro: document.querySelector( '#editor-intro' ),
|
978
|
+
* content: document.querySelector( '#editor-content' ),
|
979
|
+
* sidePanelLeft: document.querySelector( '#editor-side-left' ),
|
980
|
+
* sidePanelRight: document.querySelector( '#editor-side-right' ),
|
981
|
+
* outro: document.querySelector( '#editor-outro' )
|
982
|
+
* }, {
|
983
|
+
* initialData: {
|
984
|
+
* intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
|
985
|
+
* content: '<p>Lorem ipsum dolor sit amet.</p>',
|
986
|
+
* sidePanelLeft '<blockquote>Strong quotation from article.</blockquote>':
|
987
|
+
* sidePanelRight '<p>List of similar articles...</p>':
|
988
|
+
* outro: '<p>Closing text.</p>'
|
989
|
+
* }
|
990
|
+
* } )
|
991
|
+
* .then( editor => {
|
992
|
+
* console.log( 'Editor was initialized', editor );
|
993
|
+
*
|
994
|
+
* // Append the toolbar inside a provided DOM element.
|
995
|
+
* document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
|
996
|
+
* } )
|
997
|
+
* .catch( err => {
|
998
|
+
* console.error( err.stack );
|
999
|
+
* } );
|
1000
|
+
* ```
|
1001
|
+
*
|
1002
|
+
* This method can be used to initialize the editor on an existing element with the specified content in case if your integration
|
1003
|
+
* makes it difficult to set the content of the source element.
|
1004
|
+
*
|
1005
|
+
* Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
|
1006
|
+
*
|
1007
|
+
* # Configuring the editor
|
1008
|
+
*
|
1009
|
+
* See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
|
1010
|
+
* customizing plugins, toolbar and more.
|
1011
|
+
*
|
1012
|
+
* # Using the editor from source
|
1013
|
+
*
|
1014
|
+
* The code samples listed in the previous sections of this documentation assume that you are using an
|
1015
|
+
* {@glink installation/getting-started/predefined-builds editor build}
|
1016
|
+
* (for example – `@ckeditor/ckeditor5-build-multi-root`).
|
1017
|
+
*
|
1018
|
+
* If you want to use the multi-root editor from source (`@ckeditor/ckeditor5-editor-multi-root-editor/src/multirooteditor`),
|
1019
|
+
* you need to define the list of
|
1020
|
+
* {@link module:core/editor/editorconfig~EditorConfig#plugins plugins to be initialized} and
|
1021
|
+
* {@link module:core/editor/editorconfig~EditorConfig#toolbar toolbar items}. Read more about using the editor from
|
1022
|
+
* source in the {@glink installation/advanced/alternative-setups/integrating-from-source-webpack dedicated guide}.
|
1023
|
+
*
|
1024
|
+
* @param sourceElementsOrData The DOM elements that will be the source for the created editor
|
1025
|
+
* or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
|
1026
|
+
*
|
1027
|
+
* If DOM elements are passed, their content will be automatically loaded to the editor upon initialization and the elements will be
|
1028
|
+
* 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
|
1029
|
+
* {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy} option
|
1030
|
+
* is set to `true`.
|
1031
|
+
*
|
1032
|
+
* If the initial data is passed, a detached editor will be created. For each entry in the passed object, one editor root and one
|
1033
|
+
* editable DOM element will be created. You will need to attach the editable elements into the DOM manually. The elements are available
|
1034
|
+
* through the {@link module:editor-multi-root/multirooteditorui~MultiRootEditorUI#getEditableElement `editor.ui.getEditableElement()`}
|
1035
|
+
* method.
|
1036
|
+
* @param config The editor configuration.
|
1037
|
+
* @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
|
1038
|
+
*/ static create(sourceElementsOrData, config = {}) {
|
827
1039
|
return new Promise((resolve)=>{
|
828
1040
|
for (const sourceItem of Object.values(sourceElementsOrData)){
|
829
1041
|
if (isElement(sourceItem) && sourceItem.tagName === 'TEXTAREA') {
|
@@ -842,26 +1054,41 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
842
1054
|
});
|
843
1055
|
}
|
844
1056
|
/**
|
845
|
-
|
846
|
-
|
1057
|
+
* The {@link module:core/context~Context} class.
|
1058
|
+
*
|
1059
|
+
* Exposed as static editor field for easier access in editor builds.
|
1060
|
+
*/ static Context = Context;
|
1061
|
+
/**
|
1062
|
+
* The {@link module:watchdog/editorwatchdog~EditorWatchdog} class.
|
1063
|
+
*
|
1064
|
+
* Exposed as static editor field for easier access in editor builds.
|
1065
|
+
*/ static EditorWatchdog = EditorWatchdog;
|
1066
|
+
/**
|
1067
|
+
* The {@link module:watchdog/contextwatchdog~ContextWatchdog} class.
|
1068
|
+
*
|
1069
|
+
* Exposed as static editor field for easier access in editor builds.
|
1070
|
+
*/ static ContextWatchdog = ContextWatchdog;
|
1071
|
+
/**
|
1072
|
+
* @internal
|
1073
|
+
*/ _verifyRootsWithInitialData() {
|
847
1074
|
const initialData = this.config.get('initialData');
|
848
1075
|
// Roots that are not in the initial data.
|
849
1076
|
for (const rootName of this.model.document.getRootNames()){
|
850
1077
|
if (!(rootName in initialData)) {
|
851
1078
|
/**
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
1079
|
+
* Editor roots do not match the
|
1080
|
+
* {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
|
1081
|
+
*
|
1082
|
+
* This may happen for one of the two reasons:
|
1083
|
+
*
|
1084
|
+
* * Configuration error. The `sourceElementsOrData` parameter in
|
1085
|
+
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} contains different
|
1086
|
+
* roots than {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData` configuration}.
|
1087
|
+
* * As the editor was initialized, the {@link module:core/editor/editorconfig~EditorConfig#initialData `initialData`}
|
1088
|
+
* configuration value or the state of the editor roots has been changed.
|
1089
|
+
*
|
1090
|
+
* @error multi-root-editor-root-initial-data-mismatch
|
1091
|
+
*/ throw new CKEditorError('multi-root-editor-root-initial-data-mismatch', null);
|
865
1092
|
}
|
866
1093
|
}
|
867
1094
|
// Roots that are not in the editor.
|
@@ -873,199 +1100,7 @@ class MultiRootEditorUIView extends EditorUIView {
|
|
873
1100
|
}
|
874
1101
|
}
|
875
1102
|
}
|
876
|
-
/**
|
877
|
-
* Creates an instance of the multi-root editor.
|
878
|
-
*
|
879
|
-
* **Note:** Do not use the constructor to create editor instances. Use the static
|
880
|
-
* {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
|
881
|
-
*
|
882
|
-
* @param sourceElementsOrData The DOM elements that will be the source for the created editor
|
883
|
-
* or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
|
884
|
-
* For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
|
885
|
-
* @param config The editor configuration.
|
886
|
-
*/ constructor(sourceElementsOrData, config = {}){
|
887
|
-
const rootNames = Object.keys(sourceElementsOrData);
|
888
|
-
const sourceIsData = rootNames.length === 0 || typeof sourceElementsOrData[rootNames[0]] === 'string';
|
889
|
-
if (sourceIsData && config.initialData !== undefined && Object.keys(config.initialData).length > 0) {
|
890
|
-
// Documented in core/editor/editorconfig.jsdoc.
|
891
|
-
// eslint-disable-next-line ckeditor5-rules/ckeditor-error-message
|
892
|
-
throw new CKEditorError('editor-create-initial-data', null);
|
893
|
-
}
|
894
|
-
super(config);
|
895
|
-
/**
|
896
|
-
* Holds attributes keys that were passed in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes `rootsAttributes`}
|
897
|
-
* config property and should be returned by {@link #getRootsAttributes}.
|
898
|
-
*/ this._registeredRootsAttributesKeys = new Set();
|
899
|
-
/**
|
900
|
-
* A set of lock IDs for enabling or disabling particular root.
|
901
|
-
*/ this._readOnlyRootLocks = new Map();
|
902
|
-
if (!sourceIsData) {
|
903
|
-
this.sourceElements = sourceElementsOrData;
|
904
|
-
} else {
|
905
|
-
this.sourceElements = {};
|
906
|
-
}
|
907
|
-
if (this.config.get('initialData') === undefined) {
|
908
|
-
// Create initial data object containing data from all roots.
|
909
|
-
const initialData = {};
|
910
|
-
for (const rootName of rootNames){
|
911
|
-
initialData[rootName] = getInitialData(sourceElementsOrData[rootName]);
|
912
|
-
}
|
913
|
-
this.config.set('initialData', initialData);
|
914
|
-
}
|
915
|
-
if (!sourceIsData) {
|
916
|
-
for (const rootName of rootNames){
|
917
|
-
secureSourceElement(this, sourceElementsOrData[rootName]);
|
918
|
-
}
|
919
|
-
}
|
920
|
-
this.editing.view.document.roots.on('add', (evt, viewRoot)=>{
|
921
|
-
// Here we change the standard binding of readOnly flag by adding
|
922
|
-
// additional constraint that multi-root has (enabling / disabling particular root).
|
923
|
-
viewRoot.unbind('isReadOnly');
|
924
|
-
viewRoot.bind('isReadOnly').to(this.editing.view.document, 'isReadOnly', (isReadOnly)=>{
|
925
|
-
return isReadOnly || this._readOnlyRootLocks.has(viewRoot.rootName);
|
926
|
-
});
|
927
|
-
// Hacky solution to nested editables.
|
928
|
-
// Nested editables should be managed each separately and do not base on view document or view root.
|
929
|
-
viewRoot.on('change:isReadOnly', (evt, prop, value)=>{
|
930
|
-
const viewRange = this.editing.view.createRangeIn(viewRoot);
|
931
|
-
for (const viewItem of viewRange.getItems()){
|
932
|
-
if (viewItem.is('editableElement')) {
|
933
|
-
viewItem.unbind('isReadOnly');
|
934
|
-
viewItem.isReadOnly = value;
|
935
|
-
}
|
936
|
-
}
|
937
|
-
});
|
938
|
-
});
|
939
|
-
for (const rootName of rootNames){
|
940
|
-
// Create root and `UIView` element for each editable container.
|
941
|
-
this.model.document.createRoot('$root', rootName);
|
942
|
-
}
|
943
|
-
if (this.config.get('lazyRoots')) {
|
944
|
-
for (const rootName of this.config.get('lazyRoots')){
|
945
|
-
const root = this.model.document.createRoot('$root', rootName);
|
946
|
-
root._isLoaded = false;
|
947
|
-
}
|
948
|
-
}
|
949
|
-
if (this.config.get('rootsAttributes')) {
|
950
|
-
const rootsAttributes = this.config.get('rootsAttributes');
|
951
|
-
for (const [rootName, attributes] of Object.entries(rootsAttributes)){
|
952
|
-
if (!this.model.document.getRoot(rootName)) {
|
953
|
-
/**
|
954
|
-
* Trying to set attributes on a non-existing root.
|
955
|
-
*
|
956
|
-
* Roots specified in {@link module:core/editor/editorconfig~EditorConfig#rootsAttributes} do not match initial
|
957
|
-
* editor roots.
|
958
|
-
*
|
959
|
-
* @error multi-root-editor-root-attributes-no-root
|
960
|
-
*/ throw new CKEditorError('multi-root-editor-root-attributes-no-root', null);
|
961
|
-
}
|
962
|
-
for (const key of Object.keys(attributes)){
|
963
|
-
this.registerRootAttribute(key);
|
964
|
-
}
|
965
|
-
}
|
966
|
-
this.data.on('init', ()=>{
|
967
|
-
this.model.enqueueChange({
|
968
|
-
isUndoable: false
|
969
|
-
}, (writer)=>{
|
970
|
-
for (const [name, attributes] of Object.entries(rootsAttributes)){
|
971
|
-
const root = this.model.document.getRoot(name);
|
972
|
-
for (const [key, value] of Object.entries(attributes)){
|
973
|
-
if (value !== null) {
|
974
|
-
writer.setAttribute(key, value, root);
|
975
|
-
}
|
976
|
-
}
|
977
|
-
}
|
978
|
-
});
|
979
|
-
});
|
980
|
-
}
|
981
|
-
const options = {
|
982
|
-
shouldToolbarGroupWhenFull: !this.config.get('toolbar.shouldNotGroupWhenFull'),
|
983
|
-
editableElements: sourceIsData ? undefined : sourceElementsOrData
|
984
|
-
};
|
985
|
-
const view = new MultiRootEditorUIView(this.locale, this.editing.view, rootNames, options);
|
986
|
-
this.ui = new MultiRootEditorUI(this, view);
|
987
|
-
this.model.document.on('change:data', ()=>{
|
988
|
-
const changedRoots = this.model.document.differ.getChangedRoots();
|
989
|
-
// Fire detaches first. If there are multiple roots removed and added in one batch, it should be easier to handle if
|
990
|
-
// changes aren't mixed. Detaching will usually lead to just removing DOM elements. Detaching first will lead to a clean DOM
|
991
|
-
// when new editables are added in `addRoot` event.
|
992
|
-
for (const changes of changedRoots){
|
993
|
-
const root = this.model.document.getRoot(changes.name);
|
994
|
-
if (changes.state == 'detached') {
|
995
|
-
this.fire('detachRoot', root);
|
996
|
-
}
|
997
|
-
}
|
998
|
-
for (const changes of changedRoots){
|
999
|
-
const root = this.model.document.getRoot(changes.name);
|
1000
|
-
if (changes.state == 'attached') {
|
1001
|
-
this.fire('addRoot', root);
|
1002
|
-
}
|
1003
|
-
}
|
1004
|
-
});
|
1005
|
-
// Overwrite `Model#canEditAt()` decorated method.
|
1006
|
-
// Check if the provided selection is inside a read-only root. If so, return `false`.
|
1007
|
-
this.listenTo(this.model, 'canEditAt', (evt, [selection])=>{
|
1008
|
-
// Skip empty selections.
|
1009
|
-
if (!selection) {
|
1010
|
-
return;
|
1011
|
-
}
|
1012
|
-
let selectionInReadOnlyRoot = false;
|
1013
|
-
for (const range of selection.getRanges()){
|
1014
|
-
const root = range.root;
|
1015
|
-
if (this._readOnlyRootLocks.has(root.rootName)) {
|
1016
|
-
selectionInReadOnlyRoot = true;
|
1017
|
-
break;
|
1018
|
-
}
|
1019
|
-
}
|
1020
|
-
// If selection is in read-only root, return `false` and prevent further processing.
|
1021
|
-
// Otherwise, allow for other callbacks (or default callback) to evaluate.
|
1022
|
-
if (selectionInReadOnlyRoot) {
|
1023
|
-
evt.return = false;
|
1024
|
-
evt.stop();
|
1025
|
-
}
|
1026
|
-
}, {
|
1027
|
-
priority: 'high'
|
1028
|
-
});
|
1029
|
-
this.decorate('loadRoot');
|
1030
|
-
this.on('loadRoot', (evt, [rootName])=>{
|
1031
|
-
const root = this.model.document.getRoot(rootName);
|
1032
|
-
if (!root) {
|
1033
|
-
/**
|
1034
|
-
* The root to load does not exist.
|
1035
|
-
*
|
1036
|
-
* @error multi-root-editor-load-root-no-root
|
1037
|
-
*/ throw new CKEditorError('multi-root-editor-load-root-no-root', this, {
|
1038
|
-
rootName
|
1039
|
-
});
|
1040
|
-
}
|
1041
|
-
if (root._isLoaded) {
|
1042
|
-
/**
|
1043
|
-
* The root to load was already loaded before. The `loadRoot()` call has no effect.
|
1044
|
-
*
|
1045
|
-
* @error multi-root-editor-load-root-already-loaded
|
1046
|
-
*/ logWarning('multi-root-editor-load-root-already-loaded');
|
1047
|
-
evt.stop();
|
1048
|
-
}
|
1049
|
-
}, {
|
1050
|
-
priority: 'highest'
|
1051
|
-
});
|
1052
|
-
}
|
1053
1103
|
}
|
1054
|
-
/**
|
1055
|
-
* The {@link module:core/context~Context} class.
|
1056
|
-
*
|
1057
|
-
* Exposed as static editor field for easier access in editor builds.
|
1058
|
-
*/ MultiRootEditor.Context = Context;
|
1059
|
-
/**
|
1060
|
-
* The {@link module:watchdog/editorwatchdog~EditorWatchdog} class.
|
1061
|
-
*
|
1062
|
-
* Exposed as static editor field for easier access in editor builds.
|
1063
|
-
*/ MultiRootEditor.EditorWatchdog = EditorWatchdog;
|
1064
|
-
/**
|
1065
|
-
* The {@link module:watchdog/contextwatchdog~ContextWatchdog} class.
|
1066
|
-
*
|
1067
|
-
* Exposed as static editor field for easier access in editor builds.
|
1068
|
-
*/ MultiRootEditor.ContextWatchdog = ContextWatchdog;
|
1069
1104
|
function getInitialData(sourceElementOrData) {
|
1070
1105
|
return isElement(sourceElementOrData) ? getDataFromElement(sourceElementOrData) : sourceElementOrData;
|
1071
1106
|
}
|