@ckeditor/ckeditor5-engine 35.3.2 → 36.0.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.
Files changed (123) hide show
  1. package/LICENSE.md +1 -1
  2. package/package.json +22 -22
  3. package/src/controller/datacontroller.js +10 -8
  4. package/src/controller/editingcontroller.js +3 -4
  5. package/src/conversion/conversion.js +2 -3
  6. package/src/conversion/conversionhelpers.js +1 -1
  7. package/src/conversion/downcastdispatcher.js +3 -3
  8. package/src/conversion/downcasthelpers.js +2 -3
  9. package/src/conversion/mapper.js +3 -4
  10. package/src/conversion/modelconsumable.js +2 -2
  11. package/src/conversion/upcastdispatcher.js +3 -4
  12. package/src/conversion/upcasthelpers.js +10 -3
  13. package/src/conversion/viewconsumable.js +2 -2
  14. package/src/dataprocessor/basichtmlwriter.js +1 -1
  15. package/src/dataprocessor/dataprocessor.js +1 -1
  16. package/src/dataprocessor/htmldataprocessor.js +3 -3
  17. package/src/dataprocessor/htmlwriter.js +1 -1
  18. package/src/dataprocessor/xmldataprocessor.js +6 -2
  19. package/src/dev-utils/model.js +3 -3
  20. package/src/dev-utils/operationreplayer.js +1 -1
  21. package/src/dev-utils/utils.js +1 -1
  22. package/src/dev-utils/view.js +1 -1
  23. package/src/index.js +13 -3
  24. package/src/model/batch.js +10 -47
  25. package/src/model/differ.js +81 -174
  26. package/src/model/document.js +38 -97
  27. package/src/model/documentfragment.js +44 -97
  28. package/src/model/documentselection.js +152 -251
  29. package/src/model/element.js +48 -101
  30. package/src/model/history.js +15 -46
  31. package/src/model/item.js +1 -1
  32. package/src/model/liveposition.js +11 -39
  33. package/src/model/liverange.js +14 -38
  34. package/src/model/markercollection.js +42 -115
  35. package/src/model/model.js +214 -292
  36. package/src/model/node.js +36 -128
  37. package/src/model/nodelist.js +12 -41
  38. package/src/model/operation/attributeoperation.js +14 -45
  39. package/src/model/operation/detachoperation.js +4 -17
  40. package/src/model/operation/insertoperation.js +7 -35
  41. package/src/model/operation/markeroperation.js +9 -48
  42. package/src/model/operation/mergeoperation.js +9 -42
  43. package/src/model/operation/moveoperation.js +15 -39
  44. package/src/model/operation/nooperation.js +1 -7
  45. package/src/model/operation/operation.js +5 -63
  46. package/src/model/operation/operationfactory.js +3 -6
  47. package/src/model/operation/renameoperation.js +9 -29
  48. package/src/model/operation/rootattributeoperation.js +19 -48
  49. package/src/model/operation/splitoperation.js +10 -48
  50. package/src/model/operation/transform.js +110 -151
  51. package/src/model/operation/utils.js +37 -52
  52. package/src/model/position.js +118 -230
  53. package/src/model/range.js +146 -202
  54. package/src/model/rootelement.js +8 -47
  55. package/src/model/schema.js +245 -282
  56. package/src/model/selection.js +135 -196
  57. package/src/model/text.js +10 -37
  58. package/src/model/textproxy.js +16 -70
  59. package/src/model/treewalker.js +11 -102
  60. package/src/model/typecheckable.js +1 -1
  61. package/src/model/utils/autoparagraphing.js +11 -12
  62. package/src/model/utils/deletecontent.js +93 -62
  63. package/src/model/utils/findoptimalinsertionrange.js +25 -25
  64. package/src/model/utils/getselectedcontent.js +3 -6
  65. package/src/model/utils/insertcontent.js +37 -130
  66. package/src/model/utils/insertobject.js +40 -40
  67. package/src/model/utils/modifyselection.js +24 -34
  68. package/src/model/utils/selection-post-fixer.js +53 -59
  69. package/src/model/writer.js +209 -316
  70. package/src/view/attributeelement.js +2 -2
  71. package/src/view/containerelement.js +1 -1
  72. package/src/view/datatransfer.js +1 -1
  73. package/src/view/document.js +3 -5
  74. package/src/view/documentfragment.js +50 -4
  75. package/src/view/documentselection.js +2 -3
  76. package/src/view/domconverter.js +4 -8
  77. package/src/view/downcastwriter.js +2 -3
  78. package/src/view/editableelement.js +2 -3
  79. package/src/view/element.js +6 -8
  80. package/src/view/elementdefinition.js +1 -1
  81. package/src/view/emptyelement.js +2 -2
  82. package/src/view/filler.js +2 -3
  83. package/src/view/item.js +1 -1
  84. package/src/view/matcher.js +2 -2
  85. package/src/view/node.js +2 -5
  86. package/src/view/observer/arrowkeysobserver.js +1 -1
  87. package/src/view/observer/bubblingemittermixin.js +3 -6
  88. package/src/view/observer/bubblingeventinfo.js +2 -2
  89. package/src/view/observer/clickobserver.js +1 -1
  90. package/src/view/observer/compositionobserver.js +1 -1
  91. package/src/view/observer/domeventdata.js +1 -1
  92. package/src/view/observer/domeventobserver.js +1 -1
  93. package/src/view/observer/fakeselectionobserver.js +2 -2
  94. package/src/view/observer/focusobserver.js +25 -3
  95. package/src/view/observer/inputobserver.js +2 -2
  96. package/src/view/observer/keyobserver.js +2 -2
  97. package/src/view/observer/mouseobserver.js +1 -1
  98. package/src/view/observer/mutationobserver.js +1 -1
  99. package/src/view/observer/observer.js +3 -3
  100. package/src/view/observer/selectionobserver.js +21 -3
  101. package/src/view/observer/tabobserver.js +2 -2
  102. package/src/view/placeholder.js +1 -1
  103. package/src/view/position.js +2 -3
  104. package/src/view/range.js +1 -1
  105. package/src/view/rawelement.js +2 -2
  106. package/src/view/renderer.js +3 -12
  107. package/src/view/rooteditableelement.js +1 -1
  108. package/src/view/selection.js +2 -6
  109. package/src/view/styles/background.js +1 -1
  110. package/src/view/styles/border.js +1 -1
  111. package/src/view/styles/margin.js +1 -1
  112. package/src/view/styles/padding.js +1 -1
  113. package/src/view/styles/utils.js +1 -1
  114. package/src/view/stylesmap.js +1 -1
  115. package/src/view/text.js +1 -1
  116. package/src/view/textproxy.js +2 -2
  117. package/src/view/treewalker.js +2 -2
  118. package/src/view/typecheckable.js +1 -1
  119. package/src/view/uielement.js +2 -3
  120. package/src/view/upcastwriter.js +1 -1
  121. package/src/view/view.js +7 -7
  122. package/theme/placeholder.css +1 -1
  123. package/theme/renderer.css +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, 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
5
  /**
@@ -21,54 +21,20 @@ import getSelectedContent from './utils/getselectedcontent';
21
21
  import insertContent from './utils/insertcontent';
22
22
  import insertObject from './utils/insertobject';
23
23
  import modifySelection from './utils/modifyselection';
24
- import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
25
- import { Observable } from '@ckeditor/ckeditor5-utils/src/observablemixin';
24
+ import { CKEditorError, ObservableMixin } from '@ckeditor/ckeditor5-utils';
26
25
  // @if CK_DEBUG_ENGINE // const { dumpTrees } = require( '../dev-utils/utils' );
27
26
  // @if CK_DEBUG_ENGINE // const { OperationReplayer } = require( '../dev-utils/operationreplayer' ).default;
28
27
  /**
29
28
  * Editor's data model. Read about the model in the
30
29
  * {@glink framework/guides/architecture/editing-engine engine architecture guide}.
31
- *
32
- * @mixes module:utils/observablemixin~ObservableMixin
33
30
  */
34
- export default class Model extends Observable {
31
+ export default class Model extends ObservableMixin() {
35
32
  constructor() {
36
33
  super();
37
- /**
38
- * Model's marker collection.
39
- *
40
- * @readonly
41
- * @member {module:engine/model/markercollection~MarkerCollection}
42
- */
43
34
  this.markers = new MarkerCollection();
44
- /**
45
- * Model's document.
46
- *
47
- * @readonly
48
- * @member {module:engine/model/document~Document}
49
- */
50
35
  this.document = new Document(this);
51
- /**
52
- * Model's schema.
53
- *
54
- * @readonly
55
- * @member {module:engine/model/schema~Schema}
56
- */
57
36
  this.schema = new Schema();
58
- /**
59
- * All callbacks added by {@link module:engine/model/model~Model#change} or
60
- * {@link module:engine/model/model~Model#enqueueChange} methods waiting to be executed.
61
- *
62
- * @private
63
- * @type {Array.<Function>}
64
- */
65
37
  this._pendingChanges = [];
66
- /**
67
- * The last created and currently used writer instance.
68
- *
69
- * @private
70
- * @member {module:engine/model/writer~Writer}
71
- */
72
38
  this._currentWriter = null;
73
39
  ['insertContent', 'insertObject', 'deleteContent', 'modifySelection', 'getSelectedContent', 'applyOperation']
74
40
  .forEach(methodName => this.decorate(methodName));
@@ -138,34 +104,40 @@ export default class Model extends Observable {
138
104
  * the {@link module:engine/model/document~Document#selection document's selection}, and
139
105
  * {@link module:engine/model/model~Model#markers model markers}.
140
106
  *
141
- * model.change( writer => {
142
- * writer.insertText( 'foo', paragraph, 'end' );
143
- * } );
107
+ * ```ts
108
+ * model.change( writer => {
109
+ * writer.insertText( 'foo', paragraph, 'end' );
110
+ * } );
111
+ * ```
144
112
  *
145
113
  * All changes inside the change block use the same {@link module:engine/model/batch~Batch} so they are combined
146
114
  * into a single undo step.
147
115
  *
148
- * model.change( writer => {
149
- * writer.insertText( 'foo', paragraph, 'end' ); // foo.
116
+ * ```ts
117
+ * model.change( writer => {
118
+ * writer.insertText( 'foo', paragraph, 'end' ); // foo.
150
119
  *
151
- * model.change( writer => {
152
- * writer.insertText( 'bar', paragraph, 'end' ); // foobar.
153
- * } );
120
+ * model.change( writer => {
121
+ * writer.insertText( 'bar', paragraph, 'end' ); // foobar.
122
+ * } );
154
123
  *
155
- * writer.insertText( 'bom', paragraph, 'end' ); // foobarbom.
156
- * } );
124
+ * writer.insertText( 'bom', paragraph, 'end' ); // foobarbom.
125
+ * } );
126
+ * ```
157
127
  *
158
128
  * The callback of the `change()` block is executed synchronously.
159
129
  *
160
130
  * You can also return a value from the change block.
161
131
  *
162
- * const img = model.change( writer => {
163
- * return writer.createElement( 'img' );
164
- * } );
132
+ * ```ts
133
+ * const img = model.change( writer => {
134
+ * return writer.createElement( 'img' );
135
+ * } );
136
+ * ```
165
137
  *
166
138
  * @see #enqueueChange
167
- * @param {Function} callback Callback function which may modify the model.
168
- * @returns {*} Value returned by the callback.
139
+ * @typeParam TReturn The return type of the provided callback.
140
+ * @param callback Callback function which may modify the model.
169
141
  */
170
142
  change(callback) {
171
143
  try {
@@ -185,49 +157,6 @@ export default class Model extends Observable {
185
157
  CKEditorError.rethrowUnexpectedError(err, this);
186
158
  }
187
159
  }
188
- /**
189
- * The `enqueueChange()` method performs similar task as the {@link #change `change()` method}, with two major differences.
190
- *
191
- * First, the callback of `enqueueChange()` is executed when all other enqueued changes are done. It might be executed
192
- * immediately if it is not nested in any other change block, but if it is nested in another (enqueue)change block,
193
- * it will be delayed and executed after the outermost block.
194
- *
195
- * model.change( writer => {
196
- * console.log( 1 );
197
- *
198
- * model.enqueueChange( writer => {
199
- * console.log( 2 );
200
- * } );
201
- *
202
- * console.log( 3 );
203
- * } ); // Will log: 1, 3, 2.
204
- *
205
- * In addition to that, the changes enqueued with `enqueueChange()` will be converted separately from the changes
206
- * done in the outer `change()` block.
207
- *
208
- * Second, it lets you define the {@link module:engine/model/batch~Batch} into which you want to add your changes.
209
- * By default, a new batch with the default {@link module:engine/model/batch~Batch#constructor batch type} is created.
210
- * In the sample above, the `change` and `enqueueChange` blocks will use a different batch (and a different
211
- * {@link module:engine/model/writer~Writer} instance since each of them operates on a separate batch).
212
- *
213
- * model.enqueueChange( { isUndoable: false }, writer => {
214
- * writer.insertText( 'foo', paragraph, 'end' );
215
- * } );
216
- *
217
- * When using the `enqueueChange()` block you can also add some changes to the batch you used before.
218
- *
219
- * model.enqueueChange( batch, writer => {
220
- * writer.insertText( 'foo', paragraph, 'end' );
221
- * } );
222
- *
223
- * In order to make a nested `enqueueChange()` create a single undo step together with the changes done in the outer `change()`
224
- * block, you can obtain the batch instance from the {@link module:engine/model/writer~Writer#batch writer} of the outer block.
225
- *
226
- * @param {module:engine/model/batch~Batch|Object} [batchOrType] A batch or a
227
- * {@link module:engine/model/batch~Batch#constructor batch type} that should be used in the callback. If not defined, a new batch with
228
- * the default type will be created.
229
- * @param {Function} callback Callback function which may modify the model.
230
- */
231
160
  enqueueChange(batchOrType, callback) {
232
161
  try {
233
162
  if (!batchOrType) {
@@ -252,7 +181,7 @@ export default class Model extends Observable {
252
181
  }
253
182
  }
254
183
  /**
255
- * {@link module:utils/observablemixin~ObservableMixin#decorate Decorated} function for applying
184
+ * {@link module:utils/observablemixin~Observable#decorate Decorated} function for applying
256
185
  * {@link module:engine/model/operation/operation~Operation operations} to the model.
257
186
  *
258
187
  * This is a low-level way of changing the model. It is exposed for very specific use cases (like the undo feature).
@@ -260,7 +189,7 @@ export default class Model extends Observable {
260
189
  * See also {@glink framework/guides/architecture/editing-engine#changing-the-model Changing the model} section
261
190
  * of the {@glink framework/guides/architecture/editing-engine Editing architecture} guide.
262
191
  *
263
- * @param {module:engine/model/operation/operation~Operation} operation The operation to apply.
192
+ * @param operation The operation to apply.
264
193
  */
265
194
  applyOperation(operation) {
266
195
  // @if CK_DEBUG_ENGINE // console.log( 'Applying ' + operation );
@@ -317,104 +246,112 @@ export default class Model extends Observable {
317
246
  *
318
247
  * Using `insertContent()` with a manually created model structure:
319
248
  *
320
- * // Let's create a document fragment containing such content as:
321
- * //
322
- * // <paragraph>foo</paragraph>
323
- * // <blockQuote>
324
- * // <paragraph>bar</paragraph>
325
- * // </blockQuote>
326
- * const docFrag = editor.model.change( writer => {
327
- * const p1 = writer.createElement( 'paragraph' );
328
- * const p2 = writer.createElement( 'paragraph' );
329
- * const blockQuote = writer.createElement( 'blockQuote' );
330
- * const docFrag = writer.createDocumentFragment();
331
- *
332
- * writer.append( p1, docFrag );
333
- * writer.append( blockQuote, docFrag );
334
- * writer.append( p2, blockQuote );
335
- * writer.insertText( 'foo', p1 );
336
- * writer.insertText( 'bar', p2 );
337
- *
338
- * return docFrag;
339
- * } );
340
- *
341
- * // insertContent() does not have to be used in a change() block. It can, though,
342
- * // so this code could be moved to the callback defined above.
343
- * editor.model.insertContent( docFrag );
249
+ * ```ts
250
+ * // Let's create a document fragment containing such content as:
251
+ * //
252
+ * // <paragraph>foo</paragraph>
253
+ * // <blockQuote>
254
+ * // <paragraph>bar</paragraph>
255
+ * // </blockQuote>
256
+ * const docFrag = editor.model.change( writer => {
257
+ * const p1 = writer.createElement( 'paragraph' );
258
+ * const p2 = writer.createElement( 'paragraph' );
259
+ * const blockQuote = writer.createElement( 'blockQuote' );
260
+ * const docFrag = writer.createDocumentFragment();
261
+ *
262
+ * writer.append( p1, docFrag );
263
+ * writer.append( blockQuote, docFrag );
264
+ * writer.append( p2, blockQuote );
265
+ * writer.insertText( 'foo', p1 );
266
+ * writer.insertText( 'bar', p2 );
267
+ *
268
+ * return docFrag;
269
+ * } );
270
+ *
271
+ * // insertContent() does not have to be used in a change() block. It can, though,
272
+ * // so this code could be moved to the callback defined above.
273
+ * editor.model.insertContent( docFrag );
274
+ * ```
344
275
  *
345
276
  * Using `insertContent()` with an HTML string converted to a model document fragment (similar to the pasting mechanism):
346
277
  *
347
- * // You can create your own HtmlDataProcessor instance or use editor.data.processor
348
- * // if you have not overridden the default one (which is the HtmlDataProcessor instance).
349
- * const htmlDP = new HtmlDataProcessor( viewDocument );
350
- *
351
- * // Convert an HTML string to a view document fragment:
352
- * const viewFragment = htmlDP.toView( htmlString );
353
- *
354
- * // Convert the view document fragment to a model document fragment
355
- * // in the context of $root. This conversion takes the schema into
356
- * // account so if, for example, the view document fragment contained a bare text node,
357
- * // this text node cannot be a child of $root, so it will be automatically
358
- * // wrapped with a <paragraph>. You can define the context yourself (in the second parameter),
359
- * // and e.g. convert the content like it would happen in a <paragraph>.
360
- * // Note: The clipboard feature uses a custom context called $clipboardHolder
361
- * // which has a loosened schema.
362
- * const modelFragment = editor.data.toModel( viewFragment );
363
- *
364
- * editor.model.insertContent( modelFragment );
278
+ * ```ts
279
+ * // You can create your own HtmlDataProcessor instance or use editor.data.processor
280
+ * // if you have not overridden the default one (which is the HtmlDataProcessor instance).
281
+ * const htmlDP = new HtmlDataProcessor( viewDocument );
282
+ *
283
+ * // Convert an HTML string to a view document fragment:
284
+ * const viewFragment = htmlDP.toView( htmlString );
285
+ *
286
+ * // Convert the view document fragment to a model document fragment
287
+ * // in the context of $root. This conversion takes the schema into
288
+ * // account so if, for example, the view document fragment contained a bare text node,
289
+ * // this text node cannot be a child of $root, so it will be automatically
290
+ * // wrapped with a <paragraph>. You can define the context yourself (in the second parameter),
291
+ * // and e.g. convert the content like it would happen in a <paragraph>.
292
+ * // Note: The clipboard feature uses a custom context called $clipboardHolder
293
+ * // which has a loosened schema.
294
+ * const modelFragment = editor.data.toModel( viewFragment );
295
+ *
296
+ * editor.model.insertContent( modelFragment );
297
+ * ```
365
298
  *
366
299
  * By default this method will use the document selection but it can also be used with a position, range or selection instance.
367
300
  *
368
- * // Insert text at the current document selection position.
369
- * editor.model.change( writer => {
370
- * editor.model.insertContent( writer.createText( 'x' ) );
371
- * } );
301
+ * ```ts
302
+ * // Insert text at the current document selection position.
303
+ * editor.model.change( writer => {
304
+ * editor.model.insertContent( writer.createText( 'x' ) );
305
+ * } );
372
306
  *
373
- * // Insert text at a given position - the document selection will not be modified.
374
- * editor.model.change( writer => {
375
- * editor.model.insertContent( writer.createText( 'x' ), doc.getRoot(), 2 );
307
+ * // Insert text at a given position - the document selection will not be modified.
308
+ * editor.model.change( writer => {
309
+ * editor.model.insertContent( writer.createText( 'x' ), doc.getRoot(), 2 );
376
310
  *
377
- * // Which is a shorthand for:
378
- * editor.model.insertContent( writer.createText( 'x' ), writer.createPositionAt( doc.getRoot(), 2 ) );
379
- * } );
311
+ * // Which is a shorthand for:
312
+ * editor.model.insertContent( writer.createText( 'x' ), writer.createPositionAt( doc.getRoot(), 2 ) );
313
+ * } );
314
+ * ```
380
315
  *
381
316
  * If you want the document selection to be moved to the inserted content, use the
382
317
  * {@link module:engine/model/writer~Writer#setSelection `setSelection()`} method of the writer after inserting
383
318
  * the content:
384
319
  *
385
- * editor.model.change( writer => {
386
- * const paragraph = writer.createElement( 'paragraph' );
320
+ * ```ts
321
+ * editor.model.change( writer => {
322
+ * const paragraph = writer.createElement( 'paragraph' );
387
323
  *
388
- * // Insert an empty paragraph at the beginning of the root.
389
- * editor.model.insertContent( paragraph, writer.createPositionAt( editor.model.document.getRoot(), 0 ) );
324
+ * // Insert an empty paragraph at the beginning of the root.
325
+ * editor.model.insertContent( paragraph, writer.createPositionAt( editor.model.document.getRoot(), 0 ) );
390
326
  *
391
- * // Move the document selection to the inserted paragraph.
392
- * writer.setSelection( paragraph, 'in' );
393
- * } );
327
+ * // Move the document selection to the inserted paragraph.
328
+ * writer.setSelection( paragraph, 'in' );
329
+ * } );
330
+ * ```
394
331
  *
395
332
  * If an instance of the {@link module:engine/model/selection~Selection model selection} is passed as `selectable`,
396
333
  * the new content will be inserted at the passed selection (instead of document selection):
397
334
  *
398
- * editor.model.change( writer => {
399
- * // Create a selection in a paragraph that will be used as a place of insertion.
400
- * const selection = writer.createSelection( paragraph, 'in' );
335
+ * ```ts
336
+ * editor.model.change( writer => {
337
+ * // Create a selection in a paragraph that will be used as a place of insertion.
338
+ * const selection = writer.createSelection( paragraph, 'in' );
401
339
  *
402
- * // Insert the new text at the created selection.
403
- * editor.model.insertContent( writer.createText( 'x' ), selection );
340
+ * // Insert the new text at the created selection.
341
+ * editor.model.insertContent( writer.createText( 'x' ), selection );
404
342
  *
405
- * // insertContent() modifies the passed selection instance so it can be used to set the document selection.
406
- * // Note: This is not necessary when you passed the document selection to insertContent().
407
- * writer.setSelection( selection );
408
- * } );
343
+ * // insertContent() modifies the passed selection instance so it can be used to set the document selection.
344
+ * // Note: This is not necessary when you passed the document selection to insertContent().
345
+ * writer.setSelection( selection );
346
+ * } );
347
+ * ```
409
348
  *
410
349
  * @fires insertContent
411
- * @param {module:engine/model/documentfragment~DocumentFragment|module:engine/model/item~Item} content The content to insert.
412
- * @param {module:engine/model/selection~Selectable} [selectable=model.document.selection]
413
- * The selection into which the content should be inserted. If not provided the current model document selection will be used.
414
- * @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] To be used when a model item was passed as `selectable`.
350
+ * @param content The content to insert.
351
+ * @param selectable The selection into which the content should be inserted.
352
+ * If not provided the current model document selection will be used.
353
+ * @param placeOrOffset To be used when a model item was passed as `selectable`.
415
354
  * This param defines a position in relation to that item.
416
- * @returns {module:engine/model/range~Range} Range which contains all the performed changes. This is a range that, if removed,
417
- * would return the model to the state before the insertion. If no changes were preformed by `insertContent`, returns a range collapsed
418
355
  * at the insertion position.
419
356
  */
420
357
  insertContent(content, selectable, placeOrOffset) {
@@ -447,56 +384,60 @@ export default class Model extends Observable {
447
384
  *
448
385
  * Use the following code to insert an object at the current selection and keep the selection on the inserted element:
449
386
  *
450
- * const rawHtmlEmbedElement = writer.createElement( 'rawHtml' );
387
+ * ```ts
388
+ * const rawHtmlEmbedElement = writer.createElement( 'rawHtml' );
451
389
  *
452
- * model.insertObject( rawHtmlEmbedElement, null, null, {
453
- * setSelection: 'on'
454
- * } );
390
+ * model.insertObject( rawHtmlEmbedElement, null, null, {
391
+ * setSelection: 'on'
392
+ * } );
393
+ * ```
455
394
  *
456
395
  * Use the following code to insert an object at the current selection and nudge the selection after the inserted object:
457
396
  *
458
- * const pageBreakElement = writer.createElement( 'pageBreak' );
397
+ * ```ts
398
+ * const pageBreakElement = writer.createElement( 'pageBreak' );
459
399
  *
460
- * model.insertObject( pageBreakElement, null, null, {
461
- * setSelection: 'after'
462
- * } );
400
+ * model.insertObject( pageBreakElement, null, null, {
401
+ * setSelection: 'after'
402
+ * } );
403
+ * ```
463
404
  *
464
405
  * Use the following code to insert an object at the current selection and avoid splitting the content (non-destructive insertion):
465
406
  *
466
- * const tableElement = writer.createElement( 'table' );
407
+ * ```ts
408
+ * const tableElement = writer.createElement( 'table' );
467
409
  *
468
- * model.insertObject( tableElement, null, null, {
469
- * findOptimalPosition: 'auto'
470
- * } );
410
+ * model.insertObject( tableElement, null, null, {
411
+ * findOptimalPosition: 'auto'
412
+ * } );
413
+ * ```
471
414
  *
472
415
  * Use the following code to insert an object at the specific range (also: replace the content of the range):
473
416
  *
474
- * const tableElement = writer.createElement( 'table' );
475
- * const range = model.createRangeOn( model.document.getRoot().getChild( 1 ) );
417
+ * ```ts
418
+ * const tableElement = writer.createElement( 'table' );
419
+ * const range = model.createRangeOn( model.document.getRoot().getChild( 1 ) );
476
420
  *
477
- * model.insertObject( tableElement, range );
421
+ * model.insertObject( tableElement, range );
422
+ * ```
478
423
  *
479
- * @param {module:engine/model/element~Element} object An object to be inserted into the model document.
480
- * @param {module:engine/model/selection~Selectable} [selectable=model.document.selection]
481
- * A selectable where the content should be inserted. If not specified, the current
424
+ * @param object An object to be inserted into the model document.
425
+ * @param selectable A selectable where the content should be inserted. If not specified, the current
482
426
  * {@link module:engine/model/document~Document#selection document selection} will be used instead.
483
- * @param {Number|'before'|'end'|'after'|'on'|'in'} placeOrOffset Specifies the exact place or offset for the insertion to take place,
484
- * relative to `selectable`.
485
- * @param {Object} [options] Additional options.
486
- * @param {'auto'|'before'|'after'} [options.findOptimalPosition] An option that, when set, adjusts the insertion position (relative to
427
+ * @param placeOrOffset Specifies the exact place or offset for the insertion to take place, relative to `selectable`.
428
+ * @param options Additional options.
429
+ * @param options.findOptimalPosition An option that, when set, adjusts the insertion position (relative to
487
430
  * `selectable` and `placeOrOffset`) so that the content of `selectable` is not split upon insertion (a.k.a. non-destructive insertion).
488
431
  * * When `'auto'`, the algorithm will decide whether to insert the object before or after `selectable` to avoid content splitting.
489
432
  * * When `'before'`, the closest position before `selectable` will be used that will not result in content splitting.
490
433
  * * When `'after'`, the closest position after `selectable` will be used that will not result in content splitting.
491
434
  *
492
435
  * Note that this option only works for block objects. Inline objects are inserted into text and do not split blocks.
493
- * @param {'on'|'after'} [options.setSelection] An option that, when set, moves the
436
+ * @param options.setSelection An option that, when set, moves the
494
437
  * {@link module:engine/model/document~Document#selection document selection} after inserting the object.
495
438
  * * When `'on'`, the document selection will be set on the inserted object.
496
439
  * * When `'after'`, the document selection will move to the closest text node after the inserted object. If there is no
497
440
  * such text node, a paragraph will be created and the document selection will be moved inside it.
498
- * @returns {module:engine/model/range~Range} A range which contains all the performed changes. This is a range that, if removed,
499
- * would return the model to the state before the insertion. If no changes were preformed by `insertObject()`, returns a range collapsed
500
441
  * at the insertion position.
501
442
  */
502
443
  insertObject(object, selectable, placeOrOffset, options) {
@@ -514,10 +455,8 @@ export default class Model extends Observable {
514
455
  * That needs to be done in order to ensure that other features which use `deleteContent()` will work well with tables.
515
456
  *
516
457
  * @fires deleteContent
517
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
518
- * Selection of which the content should be deleted.
519
- * @param {Object} [options]
520
- * @param {Boolean} [options.leaveUnmerged=false] Whether to merge elements after removing the content of the selection.
458
+ * @param selection Selection of which the content should be deleted.
459
+ * @param options.leaveUnmerged Whether to merge elements after removing the content of the selection.
521
460
  *
522
461
  * For example `<heading1>x[x</heading1><paragraph>y]y</paragraph>` will become:
523
462
  *
@@ -527,7 +466,7 @@ export default class Model extends Observable {
527
466
  * Note: {@link module:engine/model/schema~Schema#isObject object} and {@link module:engine/model/schema~Schema#isLimit limit}
528
467
  * elements will not be merged.
529
468
  *
530
- * @param {Boolean} [options.doNotResetEntireContent=false] Whether to skip replacing the entire content with a
469
+ * @param options.doNotResetEntireContent Whether to skip replacing the entire content with a
531
470
  * paragraph when the entire content was selected.
532
471
  *
533
472
  * For example `<heading1>[x</heading1><paragraph>y]</paragraph>` will become:
@@ -535,7 +474,7 @@ export default class Model extends Observable {
535
474
  * * `<paragraph>^</paragraph>` with the option disabled (`doNotResetEntireContent == false`)
536
475
  * * `<heading1>^</heading1>` with enabled (`doNotResetEntireContent == true`)
537
476
  *
538
- * @param {Boolean} [options.doNotAutoparagraph=false] Whether to create a paragraph if after content deletion selection is moved
477
+ * @param options.doNotAutoparagraph Whether to create a paragraph if after content deletion selection is moved
539
478
  * to a place where text cannot be inserted.
540
479
  *
541
480
  * For example `<paragraph>x</paragraph>[<imageBlock src="foo.jpg"></imageBlock>]` will become:
@@ -547,7 +486,7 @@ export default class Model extends Observable {
547
486
  *
548
487
  * `[<imageBlock src="foo.jpg"></imageBlock>]` -> `<paragraph>[]</paragraph>`.
549
488
  *
550
- * @param {'forward'|'backward'} [options.direction='backward'] The direction in which the content is being consumed.
489
+ * @param options.direction The direction in which the content is being consumed.
551
490
  * Deleting backward corresponds to using the <kbd>Backspace</kbd> key, while deleting content forward corresponds to
552
491
  * the <kbd>Shift</kbd>+<kbd>Backspace</kbd> keystroke.
553
492
  */
@@ -577,12 +516,10 @@ export default class Model extends Observable {
577
516
  * **Note:** if you extend a forward selection in a backward direction you will in fact shrink it.
578
517
  *
579
518
  * @fires modifySelection
580
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
581
- * The selection to modify.
582
- * @param {Object} [options]
583
- * @param {'forward'|'backward'} [options.direction='forward'] The direction in which the selection should be modified.
584
- * @param {'character'|'codePoint'|'word'} [options.unit='character'] The unit by which selection should be modified.
585
- * @param {Boolean} [options.treatEmojiAsSingleUnit=false] Whether multi-characer emoji sequences should be handled as single unit.
519
+ * @param selection The selection to modify.
520
+ * @param options.direction The direction in which the selection should be modified.
521
+ * @param options.unit The unit by which selection should be modified.
522
+ * @param options.treatEmojiAsSingleUnit Whether multi-characer emoji sequences should be handled as single unit.
586
523
  */
587
524
  modifySelection(selection, options) {
588
525
  modifySelection(this, selection, options);
@@ -595,8 +532,8 @@ export default class Model extends Observable {
595
532
  * ```html
596
533
  * <paragraph>x</paragraph>
597
534
  * <blockQuote>
598
- * <paragraph>y</paragraph>
599
- * <heading1>fir[st</heading1>
535
+ * <paragraph>y</paragraph>
536
+ * <heading1>fir[st</heading1>
600
537
  * </blockQuote>
601
538
  * <paragraph>se]cond</paragraph>
602
539
  * <paragraph>z</paragraph>
@@ -606,15 +543,13 @@ export default class Model extends Observable {
606
543
  *
607
544
  * ```html
608
545
  * <blockQuote>
609
- * <heading1>st</heading1>
546
+ * <heading1>st</heading1>
610
547
  * </blockQuote>
611
548
  * <paragraph>se</paragraph>
612
549
  * ```
613
550
  *
614
551
  * @fires getSelectedContent
615
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
616
- * The selection of which content will be returned.
617
- * @returns {module:engine/model/documentfragment~DocumentFragment}
552
+ * @param selection The selection of which content will be returned.
618
553
  */
619
554
  getSelectedContent(selection) {
620
555
  return getSelectedContent(this, selection);
@@ -635,11 +570,9 @@ export default class Model extends Observable {
635
570
  * However, a range containing an `<imageBlock></imageBlock>` (which would normally be marked in the schema as an object element)
636
571
  * is considered non-empty.
637
572
  *
638
- * @param {module:engine/model/range~Range|module:engine/model/element~Element} rangeOrElement Range or element to check.
639
- * @param {Object} [options]
640
- * @param {Boolean} [options.ignoreWhitespaces] Whether text node with whitespaces only should be considered empty.
641
- * @param {Boolean} [options.ignoreMarkers] Whether markers should be ignored.
642
- * @returns {Boolean}
573
+ * @param rangeOrElement Range or element to check.
574
+ * @param options.ignoreWhitespaces Whether text node with whitespaces only should be considered empty.
575
+ * @param options.ignoreMarkers Whether markers should be ignored.
643
576
  */
644
577
  hasContent(rangeOrElement, options = {}) {
645
578
  const range = rangeOrElement instanceof ModelRange ? rangeOrElement : ModelRange._createIn(rangeOrElement);
@@ -678,11 +611,9 @@ export default class Model extends Observable {
678
611
  * Note: This method is also available as
679
612
  * {@link module:engine/model/writer~Writer#createPositionFromPath `Writer#createPositionFromPath()`}.
680
613
  *
681
- * @param {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment} root Root of the position.
682
- * @param {Array.<Number>} path Position path. See {@link module:engine/model/position~Position#path}.
683
- * @param {module:engine/model/position~PositionStickiness} [stickiness='toNone'] Position stickiness.
684
- * See {@link module:engine/model/position~PositionStickiness}.
685
- * @returns {module:engine/model/position~Position}
614
+ * @param root Root of the position.
615
+ * @param path Position path. See {@link module:engine/model/position~Position#path}.
616
+ * @param stickiness Position stickiness. See {@link module:engine/model/position~PositionStickiness}.
686
617
  */
687
618
  createPositionFromPath(root, path, stickiness) {
688
619
  return new ModelPosition(root, path, stickiness);
@@ -704,9 +635,8 @@ export default class Model extends Observable {
704
635
  * Note: This method is also available as
705
636
  * {@link module:engine/model/writer~Writer#createPositionAt `Writer#createPositionAt()`},
706
637
  *
707
- * @param {module:engine/model/item~Item|module:engine/model/position~Position} itemOrPosition
708
- * @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
709
- * first parameter is a {@link module:engine/model/item~Item model item}.
638
+ * @param itemOrPosition
639
+ * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/model/item~Item model item}.
710
640
  */
711
641
  createPositionAt(itemOrPosition, offset) {
712
642
  return ModelPosition._createAt(itemOrPosition, offset);
@@ -717,8 +647,7 @@ export default class Model extends Observable {
717
647
  * Note: This method is also available as
718
648
  * {@link module:engine/model/writer~Writer#createPositionAfter `Writer#createPositionAfter()`}.
719
649
  *
720
- * @param {module:engine/model/item~Item} item Item after which the position should be placed.
721
- * @returns {module:engine/model/position~Position}
650
+ * @param item Item after which the position should be placed.
722
651
  */
723
652
  createPositionAfter(item) {
724
653
  return ModelPosition._createAfter(item);
@@ -729,8 +658,7 @@ export default class Model extends Observable {
729
658
  * Note: This method is also available as
730
659
  * {@link module:engine/model/writer~Writer#createPositionBefore `Writer#createPositionBefore()`}.
731
660
  *
732
- * @param {module:engine/model/item~Item} item Item before which the position should be placed.
733
- * @returns {module:engine/model/position~Position}
661
+ * @param item Item before which the position should be placed.
734
662
  */
735
663
  createPositionBefore(item) {
736
664
  return ModelPosition._createBefore(item);
@@ -741,14 +669,14 @@ export default class Model extends Observable {
741
669
  * Note: This method is also available as
742
670
  * {@link module:engine/model/writer~Writer#createRange `Writer#createRange()`}:
743
671
  *
744
- * model.change( writer => {
745
- * const range = writer.createRange( start, end );
746
- * } );
672
+ * ```ts
673
+ * model.change( writer => {
674
+ * const range = writer.createRange( start, end );
675
+ * } );
676
+ * ```
747
677
  *
748
- * @param {module:engine/model/position~Position} start Start position.
749
- * @param {module:engine/model/position~Position} [end] End position. If not set, the range will be collapsed
750
- * to the `start` position.
751
- * @returns {module:engine/model/range~Range}
678
+ * @param start Start position.
679
+ * @param end End position. If not set, the range will be collapsed to the `start` position.
752
680
  */
753
681
  createRange(start, end) {
754
682
  return new ModelRange(start, end);
@@ -760,12 +688,13 @@ export default class Model extends Observable {
760
688
  * Note: This method is also available as
761
689
  * {@link module:engine/model/writer~Writer#createRangeIn `Writer#createRangeIn()`}:
762
690
  *
763
- * model.change( writer => {
764
- * const range = writer.createRangeIn( paragraph );
765
- * } );
691
+ * ```ts
692
+ * model.change( writer => {
693
+ * const range = writer.createRangeIn( paragraph );
694
+ * } );
695
+ * ```
766
696
  *
767
- * @param {module:engine/model/element~Element} element Element which is a parent for the range.
768
- * @returns {module:engine/model/range~Range}
697
+ * @param element Element which is a parent for the range.
769
698
  */
770
699
  createRangeIn(element) {
771
700
  return ModelRange._createIn(element);
@@ -776,12 +705,13 @@ export default class Model extends Observable {
776
705
  * Note: This method is also available on `writer` instance as
777
706
  * {@link module:engine/model/writer~Writer#createRangeOn `Writer.createRangeOn()`}:
778
707
  *
779
- * model.change( writer => {
780
- * const range = writer.createRangeOn( paragraph );
781
- * } );
708
+ * ```ts
709
+ * model.change( writer => {
710
+ * const range = writer.createRangeOn( paragraph );
711
+ * } );
712
+ * ```
782
713
  *
783
- * @param {module:engine/model/item~Item} item
784
- * @returns {module:engine/model/range~Range}
714
+ * @param item
785
715
  */
786
716
  createRangeOn(item) {
787
717
  return ModelRange._createOn(item);
@@ -793,53 +723,49 @@ export default class Model extends Observable {
793
723
  * Note: This method is also available as
794
724
  * {@link module:engine/model/writer~Writer#createSelection `Writer#createSelection()`}.
795
725
  *
796
- * // Creates empty selection without ranges.
797
- * const selection = writer.createSelection();
726
+ * ```ts
727
+ * // Creates empty selection without ranges.
728
+ * const selection = writer.createSelection();
798
729
  *
799
- * // Creates selection at the given range.
800
- * const range = writer.createRange( start, end );
801
- * const selection = writer.createSelection( range );
730
+ * // Creates selection at the given range.
731
+ * const range = writer.createRange( start, end );
732
+ * const selection = writer.createSelection( range );
802
733
  *
803
- * // Creates selection at the given ranges
804
- * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
805
- * const selection = writer.createSelection( ranges );
734
+ * // Creates selection at the given ranges
735
+ * const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
736
+ * const selection = writer.createSelection( ranges );
806
737
  *
807
- * // Creates selection from the other selection.
808
- * // Note: It doesn't copies selection attributes.
809
- * const otherSelection = writer.createSelection();
810
- * const selection = writer.createSelection( otherSelection );
738
+ * // Creates selection from the other selection.
739
+ * // Note: It doesn't copies selection attributes.
740
+ * const otherSelection = writer.createSelection();
741
+ * const selection = writer.createSelection( otherSelection );
811
742
  *
812
- * // Creates selection from the given document selection.
813
- * // Note: It doesn't copies selection attributes.
814
- * const documentSelection = model.document.selection;
815
- * const selection = writer.createSelection( documentSelection );
743
+ * // Creates selection from the given document selection.
744
+ * // Note: It doesn't copies selection attributes.
745
+ * const documentSelection = model.document.selection;
746
+ * const selection = writer.createSelection( documentSelection );
816
747
  *
817
- * // Creates selection at the given position.
818
- * const position = writer.createPositionFromPath( root, path );
819
- * const selection = writer.createSelection( position );
748
+ * // Creates selection at the given position.
749
+ * const position = writer.createPositionFromPath( root, path );
750
+ * const selection = writer.createSelection( position );
820
751
  *
821
- * // Creates selection at the given offset in the given element.
822
- * const paragraph = writer.createElement( 'paragraph' );
823
- * const selection = writer.createSelection( paragraph, offset );
752
+ * // Creates selection at the given offset in the given element.
753
+ * const paragraph = writer.createElement( 'paragraph' );
754
+ * const selection = writer.createSelection( paragraph, offset );
824
755
  *
825
- * // Creates a range inside an {@link module:engine/model/element~Element element} which starts before the
826
- * // first child of that element and ends after the last child of that element.
827
- * const selection = writer.createSelection( paragraph, 'in' );
756
+ * // Creates a range inside an {@link module:engine/model/element~Element element} which starts before the
757
+ * // first child of that element and ends after the last child of that element.
758
+ * const selection = writer.createSelection( paragraph, 'in' );
828
759
  *
829
- * // Creates a range on an {@link module:engine/model/item~Item item} which starts before the item and ends
830
- * // just after the item.
831
- * const selection = writer.createSelection( paragraph, 'on' );
760
+ * // Creates a range on an {@link module:engine/model/item~Item item} which starts before the item and ends
761
+ * // just after the item.
762
+ * const selection = writer.createSelection( paragraph, 'on' );
832
763
  *
833
- * // Additional options (`'backward'`) can be specified as the last argument.
764
+ * // Additional options (`'backward'`) can be specified as the last argument.
834
765
  *
835
- * // Creates backward selection.
836
- * const selection = writer.createSelection( range, { backward: true } );
837
- *
838
- * @param {module:engine/model/selection~Selectable} selectable
839
- * @param {Number|'before'|'end'|'after'|'on'|'in'} [optionsOrPlaceOrOffset] Sets place or offset of the selection.
840
- * @param {Object} [options]
841
- * @param {Boolean} [options.backward] Sets this selection instance to be backward.
842
- * @returns {module:engine/model/selection~Selection}
766
+ * // Creates backward selection.
767
+ * const selection = writer.createSelection( range, { backward: true } );
768
+ * ```
843
769
  */
844
770
  createSelection(...args) {
845
771
  return new ModelSelection(...args);
@@ -852,8 +778,7 @@ export default class Model extends Observable {
852
778
  * * {@link #change `change()`},
853
779
  * * {@link #enqueueChange `enqueueChange()`}.
854
780
  *
855
- * @param {Object} [type] {@link module:engine/model/batch~Batch#constructor The type} of the batch.
856
- * @returns {module:engine/model/batch~Batch}
781
+ * @param type {@link module:engine/model/batch~Batch#constructor The type} of the batch.
857
782
  */
858
783
  createBatch(type) {
859
784
  return new Batch(type);
@@ -863,8 +788,7 @@ export default class Model extends Observable {
863
788
  *
864
789
  * This is an alias for {@link module:engine/model/operation/operationfactory~OperationFactory.fromJSON `OperationFactory.fromJSON()`}.
865
790
  *
866
- * @param {Object} json Deserialized JSON object.
867
- * @returns {module:engine/model/operation/operation~Operation}
791
+ * @param json Deserialized JSON object.
868
792
  */
869
793
  createOperationFromJSON(json) {
870
794
  return OperationFactory.fromJSON(json, this.document);
@@ -880,8 +804,6 @@ export default class Model extends Observable {
880
804
  * Common part of {@link module:engine/model/model~Model#change} and {@link module:engine/model/model~Model#enqueueChange}
881
805
  * which calls callbacks and returns array of values returned by these callbacks.
882
806
  *
883
- * @private
884
- * @returns {Array.<*>} Array of values returned by callbacks.
885
807
  */
886
808
  _runPendingChanges() {
887
809
  const ret = [];