@ckeditor/ckeditor5-editor-multi-root 48.2.0 → 48.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,790 +1,790 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module editor-multi-root/multirooteditor
7
- */
8
- import { Editor, type EditorConfig, type RootConfig, type EditorRootAttributes, type ViewRootElementDefinition } from '@ckeditor/ckeditor5-core';
9
- import { type DecoratedMethodEvent } from '@ckeditor/ckeditor5-utils';
10
- import { MultiRootEditorUI } from './multirooteditorui.js';
11
- import { type ModelRootElement } from '@ckeditor/ckeditor5-engine';
6
+ * @module editor-multi-root/multirooteditor
7
+ */
8
+ import { Editor, type EditorConfig, type RootConfig, type EditorRootAttributes, type ViewRootElementDefinition } from "@ckeditor/ckeditor5-core";
9
+ import { type DecoratedMethodEvent } from "@ckeditor/ckeditor5-utils";
10
+ import { MultiRootEditorUI } from "./multirooteditorui.js";
11
+ import { type ModelRootElement } from "@ckeditor/ckeditor5-engine";
12
12
  /**
13
- * The multi-root editor implementation.
14
- *
15
- * The multi-root editor provides multiple inline editable elements and a toolbar. All editable areas are controlled by one editor
16
- * instance, which means that they share common configuration, document ID, or undo stack.
17
- *
18
- * This type of editor is dedicated to integrations which require a customized UI with an open structure, featuring multiple editable areas,
19
- * allowing developers to have a control over the exact location of these editable areas.
20
- *
21
- * In order to create a multi-root editor instance, use the static
22
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method.
23
- *
24
- * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
25
- */
13
+ * The multi-root editor implementation.
14
+ *
15
+ * The multi-root editor provides multiple inline editable elements and a toolbar. All editable areas are controlled by one editor
16
+ * instance, which means that they share common configuration, document ID, or undo stack.
17
+ *
18
+ * This type of editor is dedicated to integrations which require a customized UI with an open structure, featuring multiple editable areas,
19
+ * allowing developers to have a control over the exact location of these editable areas.
20
+ *
21
+ * In order to create a multi-root editor instance, use the static
22
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method.
23
+ *
24
+ * Note that you will need to attach the editor toolbar to your web page manually, in a desired place, after the editor is initialized.
25
+ */
26
26
  export declare class MultiRootEditor extends Editor {
27
- /**
28
- * @inheritDoc
29
- */
30
- static get editorName(): 'MultiRootEditor';
31
- /**
32
- * @inheritDoc
33
- */
34
- readonly ui: MultiRootEditorUI;
35
- /**
36
- * The elements on which the editor has been initialized.
37
- */
38
- readonly sourceElements: Record<string, HTMLElement>;
39
- /**
40
- * A set of lock IDs for enabling or disabling particular root.
41
- */
42
- private readonly _readOnlyRootLocks;
43
- /**
44
- * Creates an instance of the multi-root editor.
45
- *
46
- * **Note:** Do not use the constructor to create editor instances. Use the static
47
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
48
- *
49
- * @param config The editor configuration.
50
- */
51
- protected constructor(config: EditorConfig);
52
- /**
53
- * Creates an instance of the multi-root editor.
54
- *
55
- * **Note:** Do not use the constructor to create editor instances. Use the static
56
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
57
- *
58
- * **Note**: This constructor signature is deprecated and will be removed in the future release.
59
- *
60
- * @deprecated
61
- * @param sourceElementsOrData The DOM elements that will be the source for the created editor
62
- * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
63
- * For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
64
- * @param config The editor configuration.
65
- */
66
- protected constructor(sourceElementsOrData: Record<string, HTMLElement> | Record<string, string>, config: EditorConfig);
67
- /**
68
- * Destroys the editor instance, releasing all resources used by it.
69
- *
70
- * Updates the original editor element with the data if the
71
- * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
72
- * configuration option is set to `true`.
73
- *
74
- * **Note**: The multi-root editor does not remove the toolbar and editable when destroyed. You can
75
- * do that yourself in the destruction chain, if you need to:
76
- *
77
- * ```ts
78
- * editor.destroy().then( () => {
79
- * // Remove the toolbar from DOM.
80
- * editor.ui.view.toolbar.element.remove();
81
- *
82
- * // Remove editable elements from DOM.
83
- * for ( const editable of Object.values( editor.ui.view.editables ) ) {
84
- * editable.element.remove();
85
- * }
86
- *
87
- * console.log( 'Editor was destroyed' );
88
- * } );
89
- * ```
90
- */
91
- destroy(): Promise<unknown>;
92
- /**
93
- * Adds a new root to the editor.
94
- *
95
- * ```ts
96
- * editor.addRoot( 'myRoot', { initialData: '<p>Initial root data.</p>' } );
97
- * ```
98
- *
99
- * After a root is added, you will be able to modify and retrieve its data.
100
- *
101
- * All root names must be unique. An error will be thrown if you will try to create a root with the name same as
102
- * an already existing, attached root. However, you can call this method for a detached root. See also {@link #detachRoot}.
103
- *
104
- * Whenever a root is added, the editor instance will fire {@link #event:addRoot `addRoot` event}. The event is also called when
105
- * the root is added indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
106
- *
107
- * Note, that this method only adds a root to the editor model. It **does not** create a DOM editable element for the new root.
108
- * Until such element is created (and attached to the root), the root is "virtual": it is not displayed anywhere and its data can
109
- * be changed only using the editor API.
110
- *
111
- * To create a DOM editable element for the root, listen to {@link #event:addRoot `addRoot` event} and call {@link #createEditable}.
112
- * Then, insert the DOM element in a desired place, that will depend on the integration with your application and your requirements.
113
- *
114
- * ```ts
115
- * editor.on( 'addRoot', ( evt, root ) => {
116
- * const editableElement = editor.createEditable( root );
117
- *
118
- * // You may want to create a more complex DOM structure here.
119
- * //
120
- * // Alternatively, you may want to create a DOM structure before
121
- * // calling `editor.addRoot()` and only append `editableElement` at
122
- * // a proper place.
123
- *
124
- * document.querySelector( '#editors' ).appendChild( editableElement );
125
- * } );
126
- *
127
- * // ...
128
- *
129
- * editor.addRoot( 'myRoot' ); // Will create a root, a DOM editable element and append it to `#editors` container element.
130
- * ```
131
- *
132
- * You can set root attributes on the new root while you add it:
133
- *
134
- * ```ts
135
- * // Add a collapsed root at fourth position from top.
136
- * // Keep in mind that these are just examples of attributes. You need to provide your own features that will handle the attributes.
137
- * editor.addRoot( 'myRoot', { modelAttributes: { isCollapsed: true, index: 4 } } );
138
- * ```
139
- *
140
- * Note that attributes added together with a root are automatically registered.
141
- *
142
- * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
143
- * {@link module:core/editor/editorconfig~RootConfig#modelAttributes `config.roots.<rootName>.modelAttributes` configuration option}.
144
- *
145
- * By setting `isUndoable` flag to `true`, you can allow for detaching the root using the undo feature.
146
- *
147
- * Additionally, you can group adding multiple roots in one undo step. This can be useful if you add multiple roots that are
148
- * combined into one, bigger UI element, and want them all to be undone together.
149
- *
150
- * ```ts
151
- * let rowId = 0;
152
- *
153
- * editor.model.change( () => {
154
- * editor.addRoot( 'left-row-' + rowId, { isUndoable: true } );
155
- * editor.addRoot( 'center-row-' + rowId, { isUndoable: true } );
156
- * editor.addRoot( 'right-row-' + rowId, { isUndoable: true } );
157
- *
158
- * rowId++;
159
- * } );
160
- * ```
161
- *
162
- * @label ROOT_CONFIG
163
- * @param rootName Name of the root to add.
164
- * @param options Additional options for the added root.
165
- */
166
- addRoot(rootName: string, options?: AddRootRootConfig): void;
167
- /**
168
- * Adds a new root to the editor.
169
- *
170
- * ```ts
171
- * editor.addRoot( 'myRoot', { data: '<p>Initial root data.</p>' } );
172
- * ```
173
- *
174
- * **Note**: This method signature is deprecated and will be removed in one of the next releases.
175
- * Use the signature with root options object instead {@link #addRoot:ROOT_CONFIG `addRoot( rootName, options )`}.
176
- *
177
- * @deprecated
178
- * @label LEGACY_ADD_ROOT_OPTIONS
179
- * @param rootName Name of the root to add.
180
- * @param options Additional options for the added root.
181
- */
182
- addRoot(rootName: string, options?: AddRootOptions): void;
183
- /**
184
- * Detaches a root from the editor.
185
- *
186
- * ```ts
187
- * editor.detachRoot( 'myRoot' );
188
- * ```
189
- *
190
- * A detached root is not entirely removed from the editor model, however it can be considered removed.
191
- *
192
- * After a root is detached all its children are removed, all markers inside it are removed, and whenever something is inserted to it,
193
- * it is automatically removed as well. Finally, a detached root is not returned by
194
- * {@link module:engine/model/document~ModelDocument#getRootNames} by default.
195
- *
196
- * It is possible to re-add a previously detached root calling {@link #addRoot}.
197
- *
198
- * Whenever a root is detached, the editor instance will fire {@link #event:detachRoot `detachRoot` event}. The event is also
199
- * called when the root is detached indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
200
- *
201
- * Note, that this method only detached a root in the editor model. It **does not** destroy the DOM editable element linked with
202
- * the root and it **does not** remove the DOM element from the DOM structure of your application.
203
- *
204
- * To properly remove a DOM editable element after a root was detached, listen to {@link #event:detachRoot `detachRoot` event}
205
- * and call {@link #detachEditable}. Then, remove the DOM element from your application.
206
- *
207
- * ```ts
208
- * editor.on( 'detachRoot', ( evt, root ) => {
209
- * const editableElement = editor.detachEditable( root );
210
- *
211
- * // You may want to do an additional DOM clean-up here.
212
- *
213
- * editableElement.remove();
214
- * } );
215
- *
216
- * // ...
217
- *
218
- * editor.detachRoot( 'myRoot' ); // Will detach the root, and remove the DOM editable element.
219
- * ```
220
- *
221
- * By setting `isUndoable` flag to `true`, you can allow for re-adding the root using the undo feature.
222
- *
223
- * Additionally, you can group detaching multiple roots in one undo step. This can be useful if the roots are combined into one,
224
- * bigger UI element, and you want them all to be re-added together.
225
- *
226
- * ```ts
227
- * editor.model.change( () => {
228
- * editor.detachRoot( 'left-row-3', true );
229
- * editor.detachRoot( 'center-row-3', true );
230
- * editor.detachRoot( 'right-row-3', true );
231
- * } );
232
- * ```
233
- *
234
- * @param rootName Name of the root to detach.
235
- * @param isUndoable Whether detaching the root can be undone (using the undo feature) or not.
236
- */
237
- detachRoot(rootName: string, isUndoable?: boolean): void;
238
- /**
239
- * Creates and returns a DOM editable element for the given root element.
240
- *
241
- * The DOM editable is attached to the model root and can be used to modify the root content.
242
- *
243
- * When `options.element` is an existing `HTMLElement`, the method uses it as-is and returns
244
- * the same element. Otherwise a fresh DOM element is created from `options.element`
245
- * (descriptor or tag name) — or a default `<div>` when the option is omitted — and the caller
246
- * is expected to append the returned element to the DOM.
247
- *
248
- * @label OPTIONS
249
- * @param root Root for which the editable element should be created.
250
- * @param options.placeholder Placeholder for the editable element. If not set, placeholder value from the
251
- * {@link module:core/editor/editorconfig~RootConfig#placeholder root configuration} will be used (if it was provided).
252
- * @param options.label The accessible label text describing the editable to the assistive technologies.
253
- * @param options.element Description of the editable element to create, or an existing `HTMLElement` to use as-is.
254
- * See {@link ~RootEditableOptions#element} for accepted forms and the real-time collaboration caveat.
255
- * @returns The DOM element for the editable.
256
- */
257
- createEditable(root: ModelRootElement, options?: RootEditableOptions): HTMLElement;
258
- /**
259
- * Creates and returns a new DOM editable element for the given root element.
260
- *
261
- * The new DOM editable is attached to the model root and can be used to modify the root content.
262
- *
263
- * **Note**: this method signature is deprecated and will be removed in one of the next releases.
264
- * Use the signature with options object instead {@link #createEditable:OPTIONS `createEditable( root, options )`}.
265
- *
266
- * @deprecated
267
- * @label LEGACY
268
- * @param root Root for which the editable element should be created.
269
- * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
270
- * {@link module:core/editor/editorconfig~RootConfig#placeholder root configuration} will be used (if it was provided).
271
- * @param label The accessible label text describing the editable to the assistive technologies.
272
- * @returns The created DOM element. Append it in a desired place in your application.
273
- */
274
- createEditable(root: ModelRootElement, placeholder?: string, label?: string): HTMLElement;
275
- /**
276
- * Detaches the DOM editable element that was attached to the given root.
277
- *
278
- * @param root Root for which the editable element should be detached.
279
- * @returns The DOM element that was detached. You may want to remove it from your application DOM structure.
280
- */
281
- detachEditable(root: ModelRootElement): HTMLElement;
282
- /**
283
- * Loads a root that has previously been declared in
284
- * {@link module:core/editor/editorconfig~EditorConfig#roots `config.roots.<rootName>.lazyLoad`} configuration option.
285
- *
286
- * **Important! Lazy roots loading is an experimental feature, and may become deprecated. Be advised of the following
287
- * known limitations:**
288
- *
289
- * * **Real-time collaboration integrations that use
290
- * [uploaded editor bundles](https://ckeditor.com/docs/cs/latest/guides/collaboration/editor-bundle.html) are not supported. Using
291
- * lazy roots will lead to unexpected behavior and data loss.**
292
- * * **Revision history feature will read and process the whole document on editor initialization, possibly defeating the purpose
293
- * of using the lazy roots loading. Additionally, when the document is loaded for the first time, all roots need to be loaded,
294
- * to make sure that the initial revision data includes all roots. Otherwise, you may experience data loss.**
295
- * * **Multiple features, that require full document data to be loaded, will produce incorrect or confusing results if not all
296
- * roots are loaded. These include: bookmarks, find and replace, word count, pagination, document exports, document outline,
297
- * and table of contents.**
298
- *
299
- * Only roots specified in the editor config can be loaded. A root cannot be loaded multiple times. A root cannot be unloaded and
300
- * loading a root cannot be reverted using the undo feature.
301
- *
302
- * When a root becomes loaded, it will be treated by the editor as though it was just added. This, among others, means that all
303
- * related events and mechanisms will be fired, including {@link ~MultiRootEditor#event:addRoot `addRoot` event},
304
- * {@link module:engine/model/document~ModelDocument#event:change `model.Document` `change` event}, model post-fixers and conversion.
305
- *
306
- * Until the root becomes loaded, all above mechanisms are suppressed.
307
- *
308
- * This method is {@link module:utils/observablemixin~Observable#decorate decorated}.
309
- *
310
- * Note that attributes loaded together with a root are automatically registered.
311
- *
312
- * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
313
- * {@link module:core/editor/editorconfig~EditorConfig#roots `config.roots.<rootName>.modelAttributes` configuration option}.
314
- *
315
- * When this method is used in real-time collaboration environment, its effects become asynchronous as the editor will first synchronize
316
- * with the remote editing session, before the root is added to the editor.
317
- *
318
- * If the root has been already loaded by any other client, the additional data passed in `loadRoot()` parameters will be ignored.
319
- *
320
- * @param rootName Name of the root to load.
321
- * @param options Additional options for the loaded root.
322
- * @fires loadRoot
323
- */
324
- loadRoot(rootName: string, { data, attributes }?: LoadRootOptions): void;
325
- /**
326
- * Returns the document data for all attached roots.
327
- *
328
- * @param options Additional configuration for the retrieved data.
329
- * Editor features may introduce more configuration options that can be set through this parameter.
330
- * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
331
- * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
332
- * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
333
- * @returns The full document data.
334
- */
335
- getFullData(options?: Record<string, unknown>): Record<string, string>;
336
- /**
337
- * Returns attributes for all attached roots.
338
- *
339
- * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
340
- * If a registered root attribute is not set for a given root, `null` will be returned.
341
- *
342
- * @returns Object with roots attributes. Keys are roots names, while values are attributes set on given root.
343
- */
344
- getRootsAttributes(): Record<string, EditorRootAttributes>;
345
- /**
346
- * Switches given editor root to the read-only mode.
347
- *
348
- * In contrary to {@link module:core/editor/editor~Editor#enableReadOnlyMode `enableReadOnlyMode()`}, which switches the whole editor
349
- * 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
350
- * editing only a part of the editor content.
351
- *
352
- * When you switch a root to the read-only mode, you need provide a unique identifier (`lockId`) that will identify this request. You
353
- * will need to provide the same `lockId` when you will want to
354
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot re-enable} the root.
355
- *
356
- * ```ts
357
- * const model = editor.model;
358
- * const myRoot = model.document.getRoot( 'myRoot' );
359
- *
360
- * editor.disableRoot( 'myRoot', 'my-lock' );
361
- * model.canEditAt( myRoot ); // `false`
362
- *
363
- * editor.disableRoot( 'myRoot', 'other-lock' );
364
- * editor.disableRoot( 'myRoot', 'other-lock' ); // Multiple locks with the same ID have no effect.
365
- * model.canEditAt( myRoot ); // `false`
366
- *
367
- * editor.enableRoot( 'myRoot', 'my-lock' );
368
- * model.canEditAt( myRoot ); // `false`
369
- *
370
- * editor.enableRoot( 'myRoot', 'other-lock' );
371
- * model.canEditAt( myRoot ); // `true`
372
- * ```
373
- *
374
- * See also {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode()`} and
375
- * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot `MultiRootEditor#enableRoot()`}.
376
- *
377
- * @param rootName Name of the root to switch to read-only mode.
378
- * @param lockId A unique ID for setting the editor to the read-only state.
379
- */
380
- disableRoot(rootName: string, lockId: string | symbol): void;
381
- /**
382
- * Removes given read-only lock from the given root.
383
- *
384
- * See {@link module:editor-multi-root/multirooteditor~MultiRootEditor#disableRoot `disableRoot()`}.
385
- *
386
- * @param rootName Name of the root to switch back from the read-only mode.
387
- * @param lockId A unique ID for setting the editor to the read-only state.
388
- */
389
- enableRoot(rootName: string, lockId: string | symbol): void;
390
- /**
391
- * Creates a new multi-root editor instance.
392
- *
393
- * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
394
- * after the editor has been initialized.
395
- *
396
- * There are a few different ways to initialize the multi-root editor.
397
- *
398
- * # Using existing DOM elements:
399
- *
400
- * ```ts
401
- * MultiRootEditor.create( {
402
- * roots: {
403
- * intro: {
404
- * element: document.querySelector( '#editor-intro' )
405
- * },
406
- * content: {
407
- * element: document.querySelector( '#editor-content' )
408
- * },
409
- * sidePanelLeft: {
410
- * element: document.querySelector( '#editor-side-left' )
411
- * },
412
- * sidePanelRight: {
413
- * element: document.querySelector( '#editor-side-right' )
414
- * },
415
- * outro: {
416
- * element: document.querySelector( '#editor-outro' )
417
- * }
418
- * }
419
- * } )
420
- * .then( editor => {
421
- * console.log( 'Editor was initialized', editor );
422
- *
423
- * // Append the toolbar inside a provided DOM element.
424
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
425
- * } )
426
- * .catch( err => {
427
- * console.error( err.stack );
428
- * } );
429
- * ```
430
- *
431
- * The elements' content will be used as the editor data and elements will become editable elements.
432
- *
433
- * # Creating a detached editor
434
- *
435
- * Alternatively, you can initialize the editor by passing the initial data directly as strings.
436
- * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
437
- *
438
- * ```ts
439
- * MultiRootEditor.create( {
440
- * roots: {
441
- * intro: {
442
- * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
443
- * },
444
- * content: {
445
- * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
446
- * },
447
- * sidePanelLeft: {
448
- * initialData: '<blockquote>Strong quotation from article.</blockquote>'
449
- * },
450
- * sidePanelRight: {
451
- * initialData: '<p>List of similar articles...</p>'
452
- * },
453
- * outro: {
454
- * initialData: '<p>Closing text.</p>'
455
- * }
456
- * }
457
- * } )
458
- * .then( editor => {
459
- * console.log( 'Editor was initialized', editor );
460
- *
461
- * // Append the toolbar inside a provided DOM element.
462
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
463
- *
464
- * // Append DOM editable elements created by the editor.
465
- * const editables = editor.ui.view.editables;
466
- * const container = document.querySelector( '#editable-container' );
467
- *
468
- * container.appendChild( editables.intro.element );
469
- * container.appendChild( editables.content.element );
470
- * container.appendChild( editables.outro.element );
471
- * } )
472
- * .catch( err => {
473
- * console.error( err.stack );
474
- * } );
475
- * ```
476
- *
477
- * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
478
- * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
479
- *
480
- * # Using an existing DOM element (and data provided in `config.roots.<rootName>.initialData`)
481
- *
482
- * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
483
- *
484
- * ```ts
485
- * MultiRootEditor.create( {
486
- * roots: {
487
- * intro: {
488
- * element: document.querySelector( '#editor-intro' ),
489
- * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
490
- * },
491
- * content: {
492
- * element: document.querySelector( '#editor-content' ),
493
- * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
494
- * },
495
- * sidePanelLeft: {
496
- * element: document.querySelector( '#editor-side-left' ),
497
- * initialData: '<blockquote>Strong quotation from article.</blockquote>'
498
- * },
499
- * sidePanelRight: {
500
- * element: document.querySelector( '#editor-side-right' ),
501
- * initialData: '<p>List of similar articles...</p>'
502
- * },
503
- * outro: {
504
- * element: document.querySelector( '#editor-outro' ),
505
- * initialData: '<p>Closing text.</p>'
506
- * }
507
- * }
508
- * } )
509
- * .then( editor => {
510
- * console.log( 'Editor was initialized', editor );
511
- *
512
- * // Append the toolbar inside a provided DOM element.
513
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
514
- * } )
515
- * .catch( err => {
516
- * console.error( err.stack );
517
- * } );
518
- * ```
519
- *
520
- * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
521
- * makes it difficult to set the content of the source element.
522
- *
523
- * # Configuring the editor
524
- *
525
- * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
526
- * customizing plugins, toolbar and more.
527
- *
528
- * @param config The editor configuration.
529
- * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
530
- */
531
- static create(config: EditorConfig): Promise<MultiRootEditor>;
532
- /**
533
- * Creates a new multi-root editor instance.
534
- *
535
- * **Note**: This method signature is deprecated and will be removed in the future release.
536
- *
537
- * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
538
- * after the editor has been initialized.
539
- *
540
- * There are a few different ways to initialize the multi-root editor.
541
- *
542
- * # Using existing DOM elements:
543
- *
544
- * ```ts
545
- * MultiRootEditor.create( {
546
- * intro: document.querySelector( '#editor-intro' ),
547
- * content: document.querySelector( '#editor-content' ),
548
- * sidePanelLeft: document.querySelector( '#editor-side-left' ),
549
- * sidePanelRight: document.querySelector( '#editor-side-right' ),
550
- * outro: document.querySelector( '#editor-outro' )
551
- * } )
552
- * .then( editor => {
553
- * console.log( 'Editor was initialized', editor );
554
- *
555
- * // Append the toolbar inside a provided DOM element.
556
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
557
- * } )
558
- * .catch( err => {
559
- * console.error( err.stack );
560
- * } );
561
- * ```
562
- *
563
- * The elements' content will be used as the editor data and elements will become editable elements.
564
- *
565
- * # Creating a detached editor
566
- *
567
- * Alternatively, you can initialize the editor by passing the initial data directly as strings.
568
- * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
569
- *
570
- * ```ts
571
- * MultiRootEditor.create( {
572
- * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
573
- * content: '<p>Lorem ipsum dolor sit amet.</p>',
574
- * sidePanelLeft: '<blockquote>Strong quotation from article.</blockquote>',
575
- * sidePanelRight: '<p>List of similar articles...</p>',
576
- * outro: '<p>Closing text.</p>'
577
- * } )
578
- * .then( editor => {
579
- * console.log( 'Editor was initialized', editor );
580
- *
581
- * // Append the toolbar inside a provided DOM element.
582
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
583
- *
584
- * // Append DOM editable elements created by the editor.
585
- * const editables = editor.ui.view.editables;
586
- * const container = document.querySelector( '#editable-container' );
587
- *
588
- * container.appendChild( editables.intro.element );
589
- * container.appendChild( editables.content.element );
590
- * container.appendChild( editables.outro.element );
591
- * } )
592
- * .catch( err => {
593
- * console.error( err.stack );
594
- * } );
595
- * ```
596
- *
597
- * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
598
- * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
599
- *
600
- * # Using an existing DOM element (and data provided in `config.roots.<rootName>.initialData`)
601
- *
602
- * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
603
- *
604
- * ```ts
605
- * MultiRootEditor.create( {
606
- * intro: document.querySelector( '#editor-intro' ),
607
- * content: document.querySelector( '#editor-content' ),
608
- * sidePanelLeft: document.querySelector( '#editor-side-left' ),
609
- * sidePanelRight: document.querySelector( '#editor-side-right' ),
610
- * outro: document.querySelector( '#editor-outro' )
611
- * }, {
612
- * roots: {
613
- * intro: {
614
- * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
615
- * },
616
- * content: {
617
- * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
618
- * },
619
- * sidePanelLeft: {
620
- * initialData: '<blockquote>Strong quotation from article.</blockquote>'
621
- * },
622
- * sidePanelRight: {
623
- * initialData: '<p>List of similar articles...</p>'
624
- * },
625
- * outro: {
626
- * initialData: '<p>Closing text.</p>'
627
- * }
628
- * }
629
- * } )
630
- * .then( editor => {
631
- * console.log( 'Editor was initialized', editor );
632
- *
633
- * // Append the toolbar inside a provided DOM element.
634
- * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
635
- * } )
636
- * .catch( err => {
637
- * console.error( err.stack );
638
- * } );
639
- * ```
640
- *
641
- * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
642
- * makes it difficult to set the content of the source element.
643
- *
644
- * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
645
- *
646
- * # Configuring the editor
647
- *
648
- * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
649
- * customizing plugins, toolbar and more.
650
- *
651
- * @deprecated
652
- * @param sourceElementsOrData The DOM elements that will be the source for the created editor
653
- * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
654
- *
655
- * If DOM elements are passed, their content will be automatically loaded to the editor upon initialization and the elements will be
656
- * 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
657
- * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy} option
658
- * is set to `true`.
659
- *
660
- * If the initial data is passed, a detached editor will be created. For each entry in the passed object, one editor root and one
661
- * editable DOM element will be created. You will need to attach the editable elements into the DOM manually. The elements are available
662
- * through the {@link module:editor-multi-root/multirooteditorui~MultiRootEditorUI#getEditableElement `editor.ui.getEditableElement()`}
663
- * method.
664
- * @param config The editor configuration.
665
- * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
666
- */
667
- static create(sourceElementsOrData: Record<string, HTMLElement> | Record<string, string>, config: EditorConfig): Promise<MultiRootEditor>;
668
- /**
669
- * @internal
670
- */
671
- private _verifyRootsWithInitialData;
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static override get editorName(): "MultiRootEditor";
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ readonly ui: MultiRootEditorUI;
35
+ /**
36
+ * The elements on which the editor has been initialized.
37
+ */
38
+ readonly sourceElements: Record<string, HTMLElement>;
39
+ /**
40
+ * A set of lock IDs for enabling or disabling particular root.
41
+ */
42
+ private readonly _readOnlyRootLocks;
43
+ /**
44
+ * Creates an instance of the multi-root editor.
45
+ *
46
+ * **Note:** Do not use the constructor to create editor instances. Use the static
47
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
48
+ *
49
+ * @param config The editor configuration.
50
+ */
51
+ protected constructor(config: EditorConfig);
52
+ /**
53
+ * Creates an instance of the multi-root editor.
54
+ *
55
+ * **Note:** Do not use the constructor to create editor instances. Use the static
56
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`} method instead.
57
+ *
58
+ * **Note**: This constructor signature is deprecated and will be removed in the future release.
59
+ *
60
+ * @deprecated
61
+ * @param sourceElementsOrData The DOM elements that will be the source for the created editor
62
+ * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
63
+ * For more information see {@link module:editor-multi-root/multirooteditor~MultiRootEditor.create `MultiRootEditor.create()`}.
64
+ * @param config The editor configuration.
65
+ */
66
+ protected constructor(sourceElementsOrData: Record<string, HTMLElement> | Record<string, string>, config: EditorConfig);
67
+ /**
68
+ * Destroys the editor instance, releasing all resources used by it.
69
+ *
70
+ * Updates the original editor element with the data if the
71
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy `updateSourceElementOnDestroy`}
72
+ * configuration option is set to `true`.
73
+ *
74
+ * **Note**: The multi-root editor does not remove the toolbar and editable when destroyed. You can
75
+ * do that yourself in the destruction chain, if you need to:
76
+ *
77
+ * ```ts
78
+ * editor.destroy().then( () => {
79
+ * // Remove the toolbar from DOM.
80
+ * editor.ui.view.toolbar.element.remove();
81
+ *
82
+ * // Remove editable elements from DOM.
83
+ * for ( const editable of Object.values( editor.ui.view.editables ) ) {
84
+ * editable.element.remove();
85
+ * }
86
+ *
87
+ * console.log( 'Editor was destroyed' );
88
+ * } );
89
+ * ```
90
+ */
91
+ override destroy(): Promise<unknown>;
92
+ /**
93
+ * Adds a new root to the editor.
94
+ *
95
+ * ```ts
96
+ * editor.addRoot( 'myRoot', { initialData: '<p>Initial root data.</p>' } );
97
+ * ```
98
+ *
99
+ * After a root is added, you will be able to modify and retrieve its data.
100
+ *
101
+ * All root names must be unique. An error will be thrown if you will try to create a root with the name same as
102
+ * an already existing, attached root. However, you can call this method for a detached root. See also {@link #detachRoot}.
103
+ *
104
+ * Whenever a root is added, the editor instance will fire {@link #event:addRoot `addRoot` event}. The event is also called when
105
+ * the root is added indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
106
+ *
107
+ * Note, that this method only adds a root to the editor model. It **does not** create a DOM editable element for the new root.
108
+ * Until such element is created (and attached to the root), the root is "virtual": it is not displayed anywhere and its data can
109
+ * be changed only using the editor API.
110
+ *
111
+ * To create a DOM editable element for the root, listen to {@link #event:addRoot `addRoot` event} and call {@link #createEditable}.
112
+ * Then, insert the DOM element in a desired place, that will depend on the integration with your application and your requirements.
113
+ *
114
+ * ```ts
115
+ * editor.on( 'addRoot', ( evt, root ) => {
116
+ * const editableElement = editor.createEditable( root );
117
+ *
118
+ * // You may want to create a more complex DOM structure here.
119
+ * //
120
+ * // Alternatively, you may want to create a DOM structure before
121
+ * // calling `editor.addRoot()` and only append `editableElement` at
122
+ * // a proper place.
123
+ *
124
+ * document.querySelector( '#editors' ).appendChild( editableElement );
125
+ * } );
126
+ *
127
+ * // ...
128
+ *
129
+ * editor.addRoot( 'myRoot' ); // Will create a root, a DOM editable element and append it to `#editors` container element.
130
+ * ```
131
+ *
132
+ * You can set root attributes on the new root while you add it:
133
+ *
134
+ * ```ts
135
+ * // Add a collapsed root at fourth position from top.
136
+ * // Keep in mind that these are just examples of attributes. You need to provide your own features that will handle the attributes.
137
+ * editor.addRoot( 'myRoot', { modelAttributes: { isCollapsed: true, index: 4 } } );
138
+ * ```
139
+ *
140
+ * Note that attributes added together with a root are automatically registered.
141
+ *
142
+ * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
143
+ * {@link module:core/editor/editorconfig~RootConfig#modelAttributes `config.roots.<rootName>.modelAttributes` configuration option}.
144
+ *
145
+ * By setting `isUndoable` flag to `true`, you can allow for detaching the root using the undo feature.
146
+ *
147
+ * Additionally, you can group adding multiple roots in one undo step. This can be useful if you add multiple roots that are
148
+ * combined into one, bigger UI element, and want them all to be undone together.
149
+ *
150
+ * ```ts
151
+ * let rowId = 0;
152
+ *
153
+ * editor.model.change( () => {
154
+ * editor.addRoot( 'left-row-' + rowId, { isUndoable: true } );
155
+ * editor.addRoot( 'center-row-' + rowId, { isUndoable: true } );
156
+ * editor.addRoot( 'right-row-' + rowId, { isUndoable: true } );
157
+ *
158
+ * rowId++;
159
+ * } );
160
+ * ```
161
+ *
162
+ * @label ROOT_CONFIG
163
+ * @param rootName Name of the root to add.
164
+ * @param options Additional options for the added root.
165
+ */
166
+ addRoot(rootName: string, options?: AddRootRootConfig): void;
167
+ /**
168
+ * Adds a new root to the editor.
169
+ *
170
+ * ```ts
171
+ * editor.addRoot( 'myRoot', { data: '<p>Initial root data.</p>' } );
172
+ * ```
173
+ *
174
+ * **Note**: This method signature is deprecated and will be removed in one of the next releases.
175
+ * Use the signature with root options object instead {@link #addRoot:ROOT_CONFIG `addRoot( rootName, options )`}.
176
+ *
177
+ * @deprecated
178
+ * @label LEGACY_ADD_ROOT_OPTIONS
179
+ * @param rootName Name of the root to add.
180
+ * @param options Additional options for the added root.
181
+ */
182
+ addRoot(rootName: string, options?: AddRootOptions): void;
183
+ /**
184
+ * Detaches a root from the editor.
185
+ *
186
+ * ```ts
187
+ * editor.detachRoot( 'myRoot' );
188
+ * ```
189
+ *
190
+ * A detached root is not entirely removed from the editor model, however it can be considered removed.
191
+ *
192
+ * After a root is detached all its children are removed, all markers inside it are removed, and whenever something is inserted to it,
193
+ * it is automatically removed as well. Finally, a detached root is not returned by
194
+ * {@link module:engine/model/document~ModelDocument#getRootNames} by default.
195
+ *
196
+ * It is possible to re-add a previously detached root calling {@link #addRoot}.
197
+ *
198
+ * Whenever a root is detached, the editor instance will fire {@link #event:detachRoot `detachRoot` event}. The event is also
199
+ * called when the root is detached indirectly, e.g. by the undo feature or on a remote client during real-time collaboration.
200
+ *
201
+ * Note, that this method only detached a root in the editor model. It **does not** destroy the DOM editable element linked with
202
+ * the root and it **does not** remove the DOM element from the DOM structure of your application.
203
+ *
204
+ * To properly remove a DOM editable element after a root was detached, listen to {@link #event:detachRoot `detachRoot` event}
205
+ * and call {@link #detachEditable}. Then, remove the DOM element from your application.
206
+ *
207
+ * ```ts
208
+ * editor.on( 'detachRoot', ( evt, root ) => {
209
+ * const editableElement = editor.detachEditable( root );
210
+ *
211
+ * // You may want to do an additional DOM clean-up here.
212
+ *
213
+ * editableElement.remove();
214
+ * } );
215
+ *
216
+ * // ...
217
+ *
218
+ * editor.detachRoot( 'myRoot' ); // Will detach the root, and remove the DOM editable element.
219
+ * ```
220
+ *
221
+ * By setting `isUndoable` flag to `true`, you can allow for re-adding the root using the undo feature.
222
+ *
223
+ * Additionally, you can group detaching multiple roots in one undo step. This can be useful if the roots are combined into one,
224
+ * bigger UI element, and you want them all to be re-added together.
225
+ *
226
+ * ```ts
227
+ * editor.model.change( () => {
228
+ * editor.detachRoot( 'left-row-3', true );
229
+ * editor.detachRoot( 'center-row-3', true );
230
+ * editor.detachRoot( 'right-row-3', true );
231
+ * } );
232
+ * ```
233
+ *
234
+ * @param rootName Name of the root to detach.
235
+ * @param isUndoable Whether detaching the root can be undone (using the undo feature) or not.
236
+ */
237
+ detachRoot(rootName: string, isUndoable?: boolean): void;
238
+ /**
239
+ * Creates and returns a DOM editable element for the given root element.
240
+ *
241
+ * The DOM editable is attached to the model root and can be used to modify the root content.
242
+ *
243
+ * When `options.element` is an existing `HTMLElement`, the method uses it as-is and returns
244
+ * the same element. Otherwise a fresh DOM element is created from `options.element`
245
+ * (descriptor or tag name) — or a default `<div>` when the option is omitted — and the caller
246
+ * is expected to append the returned element to the DOM.
247
+ *
248
+ * @label OPTIONS
249
+ * @param root Root for which the editable element should be created.
250
+ * @param options.placeholder Placeholder for the editable element. If not set, placeholder value from the
251
+ * {@link module:core/editor/editorconfig~RootConfig#placeholder root configuration} will be used (if it was provided).
252
+ * @param options.label The accessible label text describing the editable to the assistive technologies.
253
+ * @param options.element Description of the editable element to create, or an existing `HTMLElement` to use as-is.
254
+ * See {@link ~RootEditableOptions#element} for accepted forms and the real-time collaboration caveat.
255
+ * @returns The DOM element for the editable.
256
+ */
257
+ createEditable(root: ModelRootElement, options?: RootEditableOptions): HTMLElement;
258
+ /**
259
+ * Creates and returns a new DOM editable element for the given root element.
260
+ *
261
+ * The new DOM editable is attached to the model root and can be used to modify the root content.
262
+ *
263
+ * **Note**: this method signature is deprecated and will be removed in one of the next releases.
264
+ * Use the signature with options object instead {@link #createEditable:OPTIONS `createEditable( root, options )`}.
265
+ *
266
+ * @deprecated
267
+ * @label LEGACY
268
+ * @param root Root for which the editable element should be created.
269
+ * @param placeholder Placeholder for the editable element. If not set, placeholder value from the
270
+ * {@link module:core/editor/editorconfig~RootConfig#placeholder root configuration} will be used (if it was provided).
271
+ * @param label The accessible label text describing the editable to the assistive technologies.
272
+ * @returns The created DOM element. Append it in a desired place in your application.
273
+ */
274
+ createEditable(root: ModelRootElement, placeholder?: string, label?: string): HTMLElement;
275
+ /**
276
+ * Detaches the DOM editable element that was attached to the given root.
277
+ *
278
+ * @param root Root for which the editable element should be detached.
279
+ * @returns The DOM element that was detached. You may want to remove it from your application DOM structure.
280
+ */
281
+ detachEditable(root: ModelRootElement): HTMLElement;
282
+ /**
283
+ * Loads a root that has previously been declared in
284
+ * {@link module:core/editor/editorconfig~EditorConfig#roots `config.roots.<rootName>.lazyLoad`} configuration option.
285
+ *
286
+ * **Important! Lazy roots loading is an experimental feature, and may become deprecated. Be advised of the following
287
+ * known limitations:**
288
+ *
289
+ * * **Real-time collaboration integrations that use
290
+ * [uploaded editor bundles](https://ckeditor.com/docs/cs/latest/guides/collaboration/editor-bundle.html) are not supported. Using
291
+ * lazy roots will lead to unexpected behavior and data loss.**
292
+ * * **Revision history feature will read and process the whole document on editor initialization, possibly defeating the purpose
293
+ * of using the lazy roots loading. Additionally, when the document is loaded for the first time, all roots need to be loaded,
294
+ * to make sure that the initial revision data includes all roots. Otherwise, you may experience data loss.**
295
+ * * **Multiple features, that require full document data to be loaded, will produce incorrect or confusing results if not all
296
+ * roots are loaded. These include: bookmarks, find and replace, word count, pagination, document exports, document outline,
297
+ * and table of contents.**
298
+ *
299
+ * Only roots specified in the editor config can be loaded. A root cannot be loaded multiple times. A root cannot be unloaded and
300
+ * loading a root cannot be reverted using the undo feature.
301
+ *
302
+ * When a root becomes loaded, it will be treated by the editor as though it was just added. This, among others, means that all
303
+ * related events and mechanisms will be fired, including {@link ~MultiRootEditor#event:addRoot `addRoot` event},
304
+ * {@link module:engine/model/document~ModelDocument#event:change `model.Document` `change` event}, model post-fixers and conversion.
305
+ *
306
+ * Until the root becomes loaded, all above mechanisms are suppressed.
307
+ *
308
+ * This method is {@link module:utils/observablemixin~Observable#decorate decorated}.
309
+ *
310
+ * Note that attributes loaded together with a root are automatically registered.
311
+ *
312
+ * See also {@link ~MultiRootEditor#registerRootAttribute `MultiRootEditor#registerRootAttribute()`} and
313
+ * {@link module:core/editor/editorconfig~EditorConfig#roots `config.roots.<rootName>.modelAttributes` configuration option}.
314
+ *
315
+ * When this method is used in real-time collaboration environment, its effects become asynchronous as the editor will first synchronize
316
+ * with the remote editing session, before the root is added to the editor.
317
+ *
318
+ * If the root has been already loaded by any other client, the additional data passed in `loadRoot()` parameters will be ignored.
319
+ *
320
+ * @param rootName Name of the root to load.
321
+ * @param options Additional options for the loaded root.
322
+ * @fires loadRoot
323
+ */
324
+ loadRoot(rootName: string, { data, attributes }?: LoadRootOptions): void;
325
+ /**
326
+ * Returns the document data for all attached roots.
327
+ *
328
+ * @param options Additional configuration for the retrieved data.
329
+ * Editor features may introduce more configuration options that can be set through this parameter.
330
+ * @param options.trim Whether returned data should be trimmed. This option is set to `'empty'` by default,
331
+ * which means that whenever editor content is considered empty, an empty string is returned. To turn off trimming
332
+ * use `'none'`. In such cases exact content will be returned (for example `'<p>&nbsp;</p>'` for an empty editor).
333
+ * @returns The full document data.
334
+ */
335
+ getFullData(options?: Record<string, unknown>): Record<string, string>;
336
+ /**
337
+ * Returns attributes for all attached roots.
338
+ *
339
+ * Note: all and only {@link ~MultiRootEditor#registerRootAttribute registered} roots attributes will be returned.
340
+ * If a registered root attribute is not set for a given root, `null` will be returned.
341
+ *
342
+ * @returns Object with roots attributes. Keys are roots names, while values are attributes set on given root.
343
+ */
344
+ getRootsAttributes(): Record<string, EditorRootAttributes>;
345
+ /**
346
+ * Switches given editor root to the read-only mode.
347
+ *
348
+ * In contrary to {@link module:core/editor/editor~Editor#enableReadOnlyMode `enableReadOnlyMode()`}, which switches the whole editor
349
+ * 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
350
+ * editing only a part of the editor content.
351
+ *
352
+ * When you switch a root to the read-only mode, you need provide a unique identifier (`lockId`) that will identify this request. You
353
+ * will need to provide the same `lockId` when you will want to
354
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot re-enable} the root.
355
+ *
356
+ * ```ts
357
+ * const model = editor.model;
358
+ * const myRoot = model.document.getRoot( 'myRoot' );
359
+ *
360
+ * editor.disableRoot( 'myRoot', 'my-lock' );
361
+ * model.canEditAt( myRoot ); // `false`
362
+ *
363
+ * editor.disableRoot( 'myRoot', 'other-lock' );
364
+ * editor.disableRoot( 'myRoot', 'other-lock' ); // Multiple locks with the same ID have no effect.
365
+ * model.canEditAt( myRoot ); // `false`
366
+ *
367
+ * editor.enableRoot( 'myRoot', 'my-lock' );
368
+ * model.canEditAt( myRoot ); // `false`
369
+ *
370
+ * editor.enableRoot( 'myRoot', 'other-lock' );
371
+ * model.canEditAt( myRoot ); // `true`
372
+ * ```
373
+ *
374
+ * See also {@link module:core/editor/editor~Editor#enableReadOnlyMode `Editor#enableReadOnlyMode()`} and
375
+ * {@link module:editor-multi-root/multirooteditor~MultiRootEditor#enableRoot `MultiRootEditor#enableRoot()`}.
376
+ *
377
+ * @param rootName Name of the root to switch to read-only mode.
378
+ * @param lockId A unique ID for setting the editor to the read-only state.
379
+ */
380
+ disableRoot(rootName: string, lockId: string | symbol): void;
381
+ /**
382
+ * Removes given read-only lock from the given root.
383
+ *
384
+ * See {@link module:editor-multi-root/multirooteditor~MultiRootEditor#disableRoot `disableRoot()`}.
385
+ *
386
+ * @param rootName Name of the root to switch back from the read-only mode.
387
+ * @param lockId A unique ID for setting the editor to the read-only state.
388
+ */
389
+ enableRoot(rootName: string, lockId: string | symbol): void;
390
+ /**
391
+ * Creates a new multi-root editor instance.
392
+ *
393
+ * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
394
+ * after the editor has been initialized.
395
+ *
396
+ * There are a few different ways to initialize the multi-root editor.
397
+ *
398
+ * # Using existing DOM elements:
399
+ *
400
+ * ```ts
401
+ * MultiRootEditor.create( {
402
+ * roots: {
403
+ * intro: {
404
+ * element: document.querySelector( '#editor-intro' )
405
+ * },
406
+ * content: {
407
+ * element: document.querySelector( '#editor-content' )
408
+ * },
409
+ * sidePanelLeft: {
410
+ * element: document.querySelector( '#editor-side-left' )
411
+ * },
412
+ * sidePanelRight: {
413
+ * element: document.querySelector( '#editor-side-right' )
414
+ * },
415
+ * outro: {
416
+ * element: document.querySelector( '#editor-outro' )
417
+ * }
418
+ * }
419
+ * } )
420
+ * .then( editor => {
421
+ * console.log( 'Editor was initialized', editor );
422
+ *
423
+ * // Append the toolbar inside a provided DOM element.
424
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
425
+ * } )
426
+ * .catch( err => {
427
+ * console.error( err.stack );
428
+ * } );
429
+ * ```
430
+ *
431
+ * The elements' content will be used as the editor data and elements will become editable elements.
432
+ *
433
+ * # Creating a detached editor
434
+ *
435
+ * Alternatively, you can initialize the editor by passing the initial data directly as strings.
436
+ * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
437
+ *
438
+ * ```ts
439
+ * MultiRootEditor.create( {
440
+ * roots: {
441
+ * intro: {
442
+ * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
443
+ * },
444
+ * content: {
445
+ * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
446
+ * },
447
+ * sidePanelLeft: {
448
+ * initialData: '<blockquote>Strong quotation from article.</blockquote>'
449
+ * },
450
+ * sidePanelRight: {
451
+ * initialData: '<p>List of similar articles...</p>'
452
+ * },
453
+ * outro: {
454
+ * initialData: '<p>Closing text.</p>'
455
+ * }
456
+ * }
457
+ * } )
458
+ * .then( editor => {
459
+ * console.log( 'Editor was initialized', editor );
460
+ *
461
+ * // Append the toolbar inside a provided DOM element.
462
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
463
+ *
464
+ * // Append DOM editable elements created by the editor.
465
+ * const editables = editor.ui.view.editables;
466
+ * const container = document.querySelector( '#editable-container' );
467
+ *
468
+ * container.appendChild( editables.intro.element );
469
+ * container.appendChild( editables.content.element );
470
+ * container.appendChild( editables.outro.element );
471
+ * } )
472
+ * .catch( err => {
473
+ * console.error( err.stack );
474
+ * } );
475
+ * ```
476
+ *
477
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
478
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
479
+ *
480
+ * # Using an existing DOM element (and data provided in `config.roots.<rootName>.initialData`)
481
+ *
482
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
483
+ *
484
+ * ```ts
485
+ * MultiRootEditor.create( {
486
+ * roots: {
487
+ * intro: {
488
+ * element: document.querySelector( '#editor-intro' ),
489
+ * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
490
+ * },
491
+ * content: {
492
+ * element: document.querySelector( '#editor-content' ),
493
+ * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
494
+ * },
495
+ * sidePanelLeft: {
496
+ * element: document.querySelector( '#editor-side-left' ),
497
+ * initialData: '<blockquote>Strong quotation from article.</blockquote>'
498
+ * },
499
+ * sidePanelRight: {
500
+ * element: document.querySelector( '#editor-side-right' ),
501
+ * initialData: '<p>List of similar articles...</p>'
502
+ * },
503
+ * outro: {
504
+ * element: document.querySelector( '#editor-outro' ),
505
+ * initialData: '<p>Closing text.</p>'
506
+ * }
507
+ * }
508
+ * } )
509
+ * .then( editor => {
510
+ * console.log( 'Editor was initialized', editor );
511
+ *
512
+ * // Append the toolbar inside a provided DOM element.
513
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
514
+ * } )
515
+ * .catch( err => {
516
+ * console.error( err.stack );
517
+ * } );
518
+ * ```
519
+ *
520
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
521
+ * makes it difficult to set the content of the source element.
522
+ *
523
+ * # Configuring the editor
524
+ *
525
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
526
+ * customizing plugins, toolbar and more.
527
+ *
528
+ * @param config The editor configuration.
529
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
530
+ */
531
+ static override create(config: EditorConfig): Promise<MultiRootEditor>;
532
+ /**
533
+ * Creates a new multi-root editor instance.
534
+ *
535
+ * **Note**: This method signature is deprecated and will be removed in the future release.
536
+ *
537
+ * **Note:** remember that `MultiRootEditor` does not append the toolbar element to your web page, so you have to do it manually
538
+ * after the editor has been initialized.
539
+ *
540
+ * There are a few different ways to initialize the multi-root editor.
541
+ *
542
+ * # Using existing DOM elements:
543
+ *
544
+ * ```ts
545
+ * MultiRootEditor.create( {
546
+ * intro: document.querySelector( '#editor-intro' ),
547
+ * content: document.querySelector( '#editor-content' ),
548
+ * sidePanelLeft: document.querySelector( '#editor-side-left' ),
549
+ * sidePanelRight: document.querySelector( '#editor-side-right' ),
550
+ * outro: document.querySelector( '#editor-outro' )
551
+ * } )
552
+ * .then( editor => {
553
+ * console.log( 'Editor was initialized', editor );
554
+ *
555
+ * // Append the toolbar inside a provided DOM element.
556
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
557
+ * } )
558
+ * .catch( err => {
559
+ * console.error( err.stack );
560
+ * } );
561
+ * ```
562
+ *
563
+ * The elements' content will be used as the editor data and elements will become editable elements.
564
+ *
565
+ * # Creating a detached editor
566
+ *
567
+ * Alternatively, you can initialize the editor by passing the initial data directly as strings.
568
+ * In this case, you will have to manually append both the toolbar element and the editable elements to your web page.
569
+ *
570
+ * ```ts
571
+ * MultiRootEditor.create( {
572
+ * intro: '<p><strong>Exciting</strong> intro text to an article.</p>',
573
+ * content: '<p>Lorem ipsum dolor sit amet.</p>',
574
+ * sidePanelLeft: '<blockquote>Strong quotation from article.</blockquote>',
575
+ * sidePanelRight: '<p>List of similar articles...</p>',
576
+ * outro: '<p>Closing text.</p>'
577
+ * } )
578
+ * .then( editor => {
579
+ * console.log( 'Editor was initialized', editor );
580
+ *
581
+ * // Append the toolbar inside a provided DOM element.
582
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
583
+ *
584
+ * // Append DOM editable elements created by the editor.
585
+ * const editables = editor.ui.view.editables;
586
+ * const container = document.querySelector( '#editable-container' );
587
+ *
588
+ * container.appendChild( editables.intro.element );
589
+ * container.appendChild( editables.content.element );
590
+ * container.appendChild( editables.outro.element );
591
+ * } )
592
+ * .catch( err => {
593
+ * console.error( err.stack );
594
+ * } );
595
+ * ```
596
+ *
597
+ * This lets you dynamically append the editor to your web page whenever it is convenient for you. You may use this method if your
598
+ * web page content is generated on the client side and the DOM structure is not ready at the moment when you initialize the editor.
599
+ *
600
+ * # Using an existing DOM element (and data provided in `config.roots.<rootName>.initialData`)
601
+ *
602
+ * You can also mix these two ways by providing a DOM element to be used and passing the initial data through the configuration:
603
+ *
604
+ * ```ts
605
+ * MultiRootEditor.create( {
606
+ * intro: document.querySelector( '#editor-intro' ),
607
+ * content: document.querySelector( '#editor-content' ),
608
+ * sidePanelLeft: document.querySelector( '#editor-side-left' ),
609
+ * sidePanelRight: document.querySelector( '#editor-side-right' ),
610
+ * outro: document.querySelector( '#editor-outro' )
611
+ * }, {
612
+ * roots: {
613
+ * intro: {
614
+ * initialData: '<p><strong>Exciting</strong> intro text to an article.</p>'
615
+ * },
616
+ * content: {
617
+ * initialData: '<p>Lorem ipsum dolor sit amet.</p>'
618
+ * },
619
+ * sidePanelLeft: {
620
+ * initialData: '<blockquote>Strong quotation from article.</blockquote>'
621
+ * },
622
+ * sidePanelRight: {
623
+ * initialData: '<p>List of similar articles...</p>'
624
+ * },
625
+ * outro: {
626
+ * initialData: '<p>Closing text.</p>'
627
+ * }
628
+ * }
629
+ * } )
630
+ * .then( editor => {
631
+ * console.log( 'Editor was initialized', editor );
632
+ *
633
+ * // Append the toolbar inside a provided DOM element.
634
+ * document.querySelector( '#toolbar-container' ).appendChild( editor.ui.view.toolbar.element );
635
+ * } )
636
+ * .catch( err => {
637
+ * console.error( err.stack );
638
+ * } );
639
+ * ```
640
+ *
641
+ * This method can be used to initialize the editor on an existing element with the specified content in case if your integration
642
+ * makes it difficult to set the content of the source element.
643
+ *
644
+ * Note that an error will be thrown if you pass the initial data both as the first parameter and also in the configuration.
645
+ *
646
+ * # Configuring the editor
647
+ *
648
+ * See the {@link module:core/editor/editorconfig~EditorConfig editor configuration documentation} to learn more about
649
+ * customizing plugins, toolbar and more.
650
+ *
651
+ * @deprecated
652
+ * @param sourceElementsOrData The DOM elements that will be the source for the created editor
653
+ * or the editor's initial data. The editor will initialize multiple roots with names according to the keys in the passed object.
654
+ *
655
+ * If DOM elements are passed, their content will be automatically loaded to the editor upon initialization and the elements will be
656
+ * 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
657
+ * {@link module:core/editor/editorconfig~EditorConfig#updateSourceElementOnDestroy updateSourceElementOnDestroy} option
658
+ * is set to `true`.
659
+ *
660
+ * If the initial data is passed, a detached editor will be created. For each entry in the passed object, one editor root and one
661
+ * editable DOM element will be created. You will need to attach the editable elements into the DOM manually. The elements are available
662
+ * through the {@link module:editor-multi-root/multirooteditorui~MultiRootEditorUI#getEditableElement `editor.ui.getEditableElement()`}
663
+ * method.
664
+ * @param config The editor configuration.
665
+ * @returns A promise resolved once the editor is ready. The promise resolves with the created editor instance.
666
+ */
667
+ static override create(sourceElementsOrData: Record<string, HTMLElement> | Record<string, string>, config: EditorConfig): Promise<MultiRootEditor>;
668
+ /**
669
+ * @internal
670
+ */
671
+ private _verifyRootsWithInitialData;
672
672
  }
673
673
  /**
674
- * Fired whenever a root is {@link ~MultiRootEditor#addRoot added or re-added} to the editor model.
675
- *
676
- * Use this event to {@link ~MultiRootEditor#createEditable create a DOM editable} for the added root and append the DOM element
677
- * in a desired place in your application.
678
- *
679
- * The event is fired after all changes from a given batch are applied. The event is not fired, if the root was added and detached
680
- * in the same batch.
681
- *
682
- * @eventName ~MultiRootEditor#addRoot
683
- * @param root The root that was added.
684
- */
674
+ * Fired whenever a root is {@link ~MultiRootEditor#addRoot added or re-added} to the editor model.
675
+ *
676
+ * Use this event to {@link ~MultiRootEditor#createEditable create a DOM editable} for the added root and append the DOM element
677
+ * in a desired place in your application.
678
+ *
679
+ * The event is fired after all changes from a given batch are applied. The event is not fired, if the root was added and detached
680
+ * in the same batch.
681
+ *
682
+ * @eventName ~MultiRootEditor#addRoot
683
+ * @param root The root that was added.
684
+ */
685
685
  export type AddRootEvent = {
686
- name: 'addRoot';
687
- args: [root: ModelRootElement];
686
+ name: "addRoot";
687
+ args: [root: ModelRootElement];
688
688
  };
689
689
  /**
690
- * Fired whenever a root is {@link ~MultiRootEditor#detachRoot detached} from the editor model.
691
- *
692
- * Use this event to {@link ~MultiRootEditor#detachEditable destroy a DOM editable} for the detached root and remove the DOM element
693
- * from your application.
694
- *
695
- * The event is fired after all changes from a given batch are applied. The event is not fired, if the root was detached and re-added
696
- * in the same batch.
697
- *
698
- * @eventName ~MultiRootEditor#detachRoot
699
- * @param root The root that was detached.
700
- */
690
+ * Fired whenever a root is {@link ~MultiRootEditor#detachRoot detached} from the editor model.
691
+ *
692
+ * Use this event to {@link ~MultiRootEditor#detachEditable destroy a DOM editable} for the detached root and remove the DOM element
693
+ * from your application.
694
+ *
695
+ * The event is fired after all changes from a given batch are applied. The event is not fired, if the root was detached and re-added
696
+ * in the same batch.
697
+ *
698
+ * @eventName ~MultiRootEditor#detachRoot
699
+ * @param root The root that was detached.
700
+ */
701
701
  export type DetachRootEvent = {
702
- name: 'detachRoot';
703
- args: [root: ModelRootElement];
702
+ name: "detachRoot";
703
+ args: [root: ModelRootElement];
704
704
  };
705
705
  /**
706
- * Event fired when {@link ~MultiRootEditor#loadRoot} method is called.
707
- *
708
- * The {@link ~MultiRootEditor#loadRoot default action of that method} is implemented as a
709
- * listener to this event, so it can be fully customized by the features.
710
- *
711
- * @eventName ~MultiRootEditor#loadRoot
712
- * @param args The arguments passed to the original method.
713
- */
714
- export type LoadRootEvent = DecoratedMethodEvent<MultiRootEditor, 'loadRoot'>;
706
+ * Event fired when {@link ~MultiRootEditor#loadRoot} method is called.
707
+ *
708
+ * The {@link ~MultiRootEditor#loadRoot default action of that method} is implemented as a
709
+ * listener to this event, so it can be fully customized by the features.
710
+ *
711
+ * @eventName ~MultiRootEditor#loadRoot
712
+ * @param args The arguments passed to the original method.
713
+ */
714
+ export type LoadRootEvent = DecoratedMethodEvent<MultiRootEditor, "loadRoot">;
715
715
  /**
716
- * Additional options available when adding a root.
717
- *
718
- * @deprecated
719
- */
716
+ * Additional options available when adding a root.
717
+ *
718
+ * @deprecated
719
+ */
720
720
  export type AddRootOptions = {
721
- /**
722
- * Initial data for the root.
723
- */
724
- data?: string;
725
- /**
726
- * Initial attributes for the root.
727
- */
728
- attributes?: EditorRootAttributes;
729
- /**
730
- * Element name for the root element in the model. It can be used to set different schema rules for different roots.
731
- */
732
- elementName?: string;
733
- /**
734
- * Whether creating the root can be undone (using the undo feature) or not.
735
- */
736
- isUndoable?: boolean;
721
+ /**
722
+ * Initial data for the root.
723
+ */
724
+ data?: string;
725
+ /**
726
+ * Initial attributes for the root.
727
+ */
728
+ attributes?: EditorRootAttributes;
729
+ /**
730
+ * Element name for the root element in the model. It can be used to set different schema rules for different roots.
731
+ */
732
+ elementName?: string;
733
+ /**
734
+ * Whether creating the root can be undone (using the undo feature) or not.
735
+ */
736
+ isUndoable?: boolean;
737
737
  };
738
738
  /**
739
- * Declares an additional options available when adding a root.
740
- */
739
+ * Declares an additional options available when adding a root.
740
+ */
741
741
  export interface AddRootRootConfig extends RootConfig {
742
- /**
743
- * A description of the editable root element to create. May be a tag name string (e.g. `'h1'`) or a
744
- * {@link module:core/editor/editorconfig~ViewRootElementDefinition} object.
745
- *
746
- * Passing an existing DOM element is not supported - `addRoot()` only registers the model root;
747
- * the DOM editable is created later by {@link ~MultiRootEditor#createEditable `createEditable()`}.
748
- */
749
- element?: string | ViewRootElementDefinition;
750
- /**
751
- * Whether creating the root can be undone (using the undo feature) or not.
752
- */
753
- isUndoable?: boolean;
742
+ /**
743
+ * A description of the editable root element to create. May be a tag name string (e.g. `'h1'`) or a
744
+ * {@link module:core/editor/editorconfig~ViewRootElementDefinition} object.
745
+ *
746
+ * Passing an existing DOM element is not supported - `addRoot()` only registers the model root;
747
+ * the DOM editable is created later by {@link ~MultiRootEditor#createEditable:OPTIONS `createEditable()`}.
748
+ */
749
+ element?: string | ViewRootElementDefinition;
750
+ /**
751
+ * Whether creating the root can be undone (using the undo feature) or not.
752
+ */
753
+ isUndoable?: boolean;
754
754
  }
755
755
  /**
756
- * Additional options available when loading a root.
757
- */
758
- export type LoadRootOptions = Omit<AddRootOptions, 'elementName' | 'isUndoable'>;
756
+ * Additional options available when loading a root.
757
+ */
758
+ export type LoadRootOptions = Omit<AddRootOptions, "elementName" | "isUndoable">;
759
759
  /**
760
- * Additional options for the created editable element.
761
- */
760
+ * Additional options for the created editable element.
761
+ */
762
762
  export interface RootEditableOptions {
763
- /**
764
- * Placeholder for the editable element. If not set, placeholder value from the
765
- * {@link module:core/editor/editorconfig~RootConfig#placeholder editor configuration} will be used (if it was provided).
766
- */
767
- placeholder?: string;
768
- /**
769
- * The accessible label text describing the editable to the assistive technologies.
770
- */
771
- label?: string;
772
- /**
773
- * A description of the editable root element to create, or an existing DOM element to use.
774
- *
775
- * Accepted forms:
776
- *
777
- * * A tag name string (e.g. `'h1'`).
778
- * * A {@link module:core/editor/editorconfig~ViewRootElementDefinition} object.
779
- * * An existing `HTMLElement`. The element is used as-is — `createEditable()` returns the same
780
- * element instead of creating a new one, so callers do not need to append it to the DOM.
781
- *
782
- * When omitted, a default `<div>` is created.
783
- *
784
- * **Note**: an `HTMLElement` value is local to this client. It cannot be replicated through
785
- * real-time collaboration, so it is not persisted with the root. Other clients calling
786
- * `createEditable()` for the same root receive a fresh element built from the canonical
787
- * descriptor (or the default `<div>`), unless they pass their own `HTMLElement` as well.
788
- */
789
- element?: string | ViewRootElementDefinition | HTMLElement;
763
+ /**
764
+ * Placeholder for the editable element. If not set, placeholder value from the
765
+ * {@link module:core/editor/editorconfig~RootConfig#placeholder editor configuration} will be used (if it was provided).
766
+ */
767
+ placeholder?: string;
768
+ /**
769
+ * The accessible label text describing the editable to the assistive technologies.
770
+ */
771
+ label?: string;
772
+ /**
773
+ * A description of the editable root element to create, or an existing DOM element to use.
774
+ *
775
+ * Accepted forms:
776
+ *
777
+ * * A tag name string (e.g. `'h1'`).
778
+ * * A {@link module:core/editor/editorconfig~ViewRootElementDefinition} object.
779
+ * * An existing `HTMLElement`. The element is used as-is — `createEditable()` returns the same
780
+ * element instead of creating a new one, so callers do not need to append it to the DOM.
781
+ *
782
+ * When omitted, a default `<div>` is created.
783
+ *
784
+ * **Note**: an `HTMLElement` value is local to this client. It cannot be replicated through
785
+ * real-time collaboration, so it is not persisted with the root. Other clients calling
786
+ * `createEditable()` for the same root receive a fresh element built from the canonical
787
+ * descriptor (or the default `<div>`), unless they pass their own `HTMLElement` as well.
788
+ */
789
+ element?: string | ViewRootElementDefinition | HTMLElement;
790
790
  }