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