@ckeditor/ckeditor5-engine 35.4.0 → 36.0.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.
Files changed (123) hide show
  1. package/LICENSE.md +1 -1
  2. package/package.json +22 -22
  3. package/src/controller/datacontroller.js +5 -1
  4. package/src/controller/editingcontroller.js +1 -1
  5. package/src/conversion/conversion.js +1 -1
  6. package/src/conversion/conversionhelpers.js +1 -1
  7. package/src/conversion/downcastdispatcher.js +1 -1
  8. package/src/conversion/downcasthelpers.js +1 -1
  9. package/src/conversion/mapper.js +1 -1
  10. package/src/conversion/modelconsumable.js +1 -1
  11. package/src/conversion/upcastdispatcher.js +1 -1
  12. package/src/conversion/upcasthelpers.js +8 -1
  13. package/src/conversion/viewconsumable.js +1 -1
  14. package/src/dataprocessor/basichtmlwriter.js +1 -1
  15. package/src/dataprocessor/dataprocessor.js +1 -1
  16. package/src/dataprocessor/htmldataprocessor.js +1 -2
  17. package/src/dataprocessor/htmlwriter.js +1 -1
  18. package/src/dataprocessor/xmldataprocessor.js +1 -1
  19. package/src/dev-utils/model.js +1 -1
  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 +3 -2
  24. package/src/model/batch.js +9 -46
  25. package/src/model/differ.js +81 -174
  26. package/src/model/document.js +36 -92
  27. package/src/model/documentfragment.js +43 -96
  28. package/src/model/documentselection.js +151 -245
  29. package/src/model/element.js +47 -100
  30. package/src/model/history.js +15 -46
  31. package/src/model/item.js +1 -1
  32. package/src/model/liveposition.js +10 -36
  33. package/src/model/liverange.js +13 -36
  34. package/src/model/markercollection.js +40 -111
  35. package/src/model/model.js +212 -289
  36. package/src/model/node.js +35 -125
  37. package/src/model/nodelist.js +11 -39
  38. package/src/model/operation/attributeoperation.js +13 -44
  39. package/src/model/operation/detachoperation.js +3 -16
  40. package/src/model/operation/insertoperation.js +6 -34
  41. package/src/model/operation/markeroperation.js +9 -48
  42. package/src/model/operation/mergeoperation.js +8 -41
  43. package/src/model/operation/moveoperation.js +14 -37
  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 +8 -28
  48. package/src/model/operation/rootattributeoperation.js +18 -47
  49. package/src/model/operation/splitoperation.js +9 -47
  50. package/src/model/operation/transform.js +109 -150
  51. package/src/model/operation/utils.js +36 -50
  52. package/src/model/position.js +117 -228
  53. package/src/model/range.js +145 -200
  54. package/src/model/rootelement.js +8 -47
  55. package/src/model/schema.js +236 -272
  56. package/src/model/selection.js +134 -192
  57. package/src/model/text.js +10 -37
  58. package/src/model/textproxy.js +15 -69
  59. package/src/model/treewalker.js +10 -101
  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 +24 -24
  64. package/src/model/utils/getselectedcontent.js +3 -6
  65. package/src/model/utils/insertcontent.js +36 -129
  66. package/src/model/utils/insertobject.js +19 -21
  67. package/src/model/utils/modifyselection.js +23 -33
  68. package/src/model/utils/selection-post-fixer.js +53 -59
  69. package/src/model/writer.js +208 -314
  70. package/src/view/attributeelement.js +1 -1
  71. package/src/view/containerelement.js +1 -1
  72. package/src/view/datatransfer.js +25 -28
  73. package/src/view/document.js +1 -17
  74. package/src/view/documentfragment.js +49 -1
  75. package/src/view/documentselection.js +1 -1
  76. package/src/view/domconverter.js +4 -3
  77. package/src/view/downcastwriter.js +1 -1
  78. package/src/view/editableelement.js +1 -1
  79. package/src/view/element.js +5 -5
  80. package/src/view/elementdefinition.js +1 -1
  81. package/src/view/emptyelement.js +1 -1
  82. package/src/view/filler.js +1 -1
  83. package/src/view/item.js +1 -1
  84. package/src/view/matcher.js +1 -1
  85. package/src/view/node.js +1 -1
  86. package/src/view/observer/arrowkeysobserver.js +1 -1
  87. package/src/view/observer/bubblingemittermixin.js +1 -1
  88. package/src/view/observer/bubblingeventinfo.js +1 -1
  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 +1 -1
  94. package/src/view/observer/focusobserver.js +22 -4
  95. package/src/view/observer/inputobserver.js +1 -1
  96. package/src/view/observer/keyobserver.js +1 -1
  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 +1 -1
  100. package/src/view/observer/selectionobserver.js +13 -2
  101. package/src/view/observer/tabobserver.js +1 -1
  102. package/src/view/placeholder.js +1 -1
  103. package/src/view/position.js +1 -1
  104. package/src/view/range.js +1 -1
  105. package/src/view/rawelement.js +1 -1
  106. package/src/view/renderer.js +1 -14
  107. package/src/view/rooteditableelement.js +1 -1
  108. package/src/view/selection.js +1 -1
  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 +1 -1
  117. package/src/view/treewalker.js +1 -1
  118. package/src/view/typecheckable.js +1 -1
  119. package/src/view/uielement.js +1 -1
  120. package/src/view/upcastwriter.js +1 -1
  121. package/src/view/view.js +5 -5
  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
  /**
@@ -23,8 +23,6 @@ import { CKEditorError, ObservableMixin } from '@ckeditor/ckeditor5-utils';
23
23
  * * The {@glink framework/guides/architecture/editing-engine#schema schema section} of the
24
24
  * {@glink framework/guides/architecture/editing-engine Introduction to the Editing engine architecture} guide.
25
25
  * * The {@glink framework/guides/deep-dive/schema Schema deep-dive guide}.
26
- *
27
- * @mixes module:utils/observablemixin~ObservableMixin
28
26
  */
29
27
  export default class Schema extends ObservableMixin() {
30
28
  /**
@@ -35,9 +33,6 @@ export default class Schema extends ObservableMixin() {
35
33
  this._sourceDefinitions = {};
36
34
  /**
37
35
  * A dictionary containing attribute properties.
38
- *
39
- * @private
40
- * @member {Object.<String,AttributeProperties>}
41
36
  */
42
37
  this._attributeProperties = {};
43
38
  this.decorate('checkChild');
@@ -53,12 +48,11 @@ export default class Schema extends ObservableMixin() {
53
48
  /**
54
49
  * Registers a schema item. Can only be called once for every item name.
55
50
  *
56
- * schema.register( 'paragraph', {
57
- * inheritAllFrom: '$block'
58
- * } );
59
- *
60
- * @param {String} itemName
61
- * @param {module:engine/model/schema~SchemaItemDefinition} definition
51
+ * ```ts
52
+ * schema.register( 'paragraph', {
53
+ * inheritAllFrom: '$block'
54
+ * } );
55
+ * ```
62
56
  */
63
57
  register(itemName, definition) {
64
58
  if (this._sourceDefinitions[itemName]) {
@@ -96,23 +90,22 @@ export default class Schema extends ObservableMixin() {
96
90
  * Extending properties such as `allowIn` will add more items to the existing properties,
97
91
  * while redefining properties such as `isBlock` will override the previously defined ones.
98
92
  *
99
- * schema.register( 'foo', {
100
- * allowIn: '$root',
101
- * isBlock: true;
102
- * } );
103
- * schema.extend( 'foo', {
104
- * allowIn: 'blockQuote',
105
- * isBlock: false
106
- * } );
107
- *
108
- * schema.getDefinition( 'foo' );
109
- * // {
110
- * // allowIn: [ '$root', 'blockQuote' ],
111
- * // isBlock: false
112
- * // }
113
- *
114
- * @param {String} itemName
115
- * @param {module:engine/model/schema~SchemaItemDefinition} definition
93
+ * ```ts
94
+ * schema.register( 'foo', {
95
+ * allowIn: '$root',
96
+ * isBlock: true;
97
+ * } );
98
+ * schema.extend( 'foo', {
99
+ * allowIn: 'blockQuote',
100
+ * isBlock: false
101
+ * } );
102
+ *
103
+ * schema.getDefinition( 'foo' );
104
+ * // {
105
+ * // allowIn: [ '$root', 'blockQuote' ],
106
+ * // isBlock: false
107
+ * // }
108
+ * ```
116
109
  */
117
110
  extend(itemName, definition) {
118
111
  if (!this._sourceDefinitions[itemName]) {
@@ -139,8 +132,6 @@ export default class Schema extends ObservableMixin() {
139
132
  * checking a list of all block elements, etc).
140
133
  * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
141
134
  * in other cases.
142
- *
143
- * @returns {Object.<String,module:engine/model/schema~SchemaCompiledItemDefinition>}
144
135
  */
145
136
  getDefinitions() {
146
137
  if (!this._compiledDefinitions) {
@@ -155,9 +146,6 @@ export default class Schema extends ObservableMixin() {
155
146
  * checking a list of all block elements, etc).
156
147
  * Use specific methods (such as {@link #checkChild `checkChild()`} or {@link #isLimit `isLimit()`})
157
148
  * in other cases.
158
- *
159
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
160
- * @returns {module:engine/model/schema~SchemaCompiledItemDefinition}
161
149
  */
162
150
  getDefinition(item) {
163
151
  let itemName;
@@ -176,12 +164,11 @@ export default class Schema extends ObservableMixin() {
176
164
  /**
177
165
  * Returns `true` if the given item is registered in the schema.
178
166
  *
179
- * schema.isRegistered( 'paragraph' ); // -> true
180
- * schema.isRegistered( editor.model.document.getRoot() ); // -> true
181
- * schema.isRegistered( 'foo' ); // -> false
182
- *
183
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
184
- * @returns {Boolean}
167
+ * ```ts
168
+ * schema.isRegistered( 'paragraph' ); // -> true
169
+ * schema.isRegistered( editor.model.document.getRoot() ); // -> true
170
+ * schema.isRegistered( 'foo' ); // -> false
171
+ * ```
185
172
  */
186
173
  isRegistered(item) {
187
174
  return !!this.getDefinition(item);
@@ -190,17 +177,16 @@ export default class Schema extends ObservableMixin() {
190
177
  * Returns `true` if the given item is defined to be
191
178
  * a block by the {@link module:engine/model/schema~SchemaItemDefinition}'s `isBlock` property.
192
179
  *
193
- * schema.isBlock( 'paragraph' ); // -> true
194
- * schema.isBlock( '$root' ); // -> false
180
+ * ```ts
181
+ * schema.isBlock( 'paragraph' ); // -> true
182
+ * schema.isBlock( '$root' ); // -> false
195
183
  *
196
- * const paragraphElement = writer.createElement( 'paragraph' );
197
- * schema.isBlock( paragraphElement ); // -> true
184
+ * const paragraphElement = writer.createElement( 'paragraph' );
185
+ * schema.isBlock( paragraphElement ); // -> true
186
+ * ```
198
187
  *
199
188
  * See the {@glink framework/guides/deep-dive/schema#block-elements Block elements} section of
200
189
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
201
- *
202
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
203
- * @returns {Boolean}
204
190
  */
205
191
  isBlock(item) {
206
192
  const def = this.getDefinition(item);
@@ -215,16 +201,15 @@ export default class Schema extends ObservableMixin() {
215
201
  * {@link module:engine/model/schema~SchemaItemDefinition#isObject `isObject`} property
216
202
  * was set to `true`.
217
203
  *
218
- * schema.isLimit( 'paragraph' ); // -> false
219
- * schema.isLimit( '$root' ); // -> true
220
- * schema.isLimit( editor.model.document.getRoot() ); // -> true
221
- * schema.isLimit( 'imageBlock' ); // -> true
204
+ * ```ts
205
+ * schema.isLimit( 'paragraph' ); // -> false
206
+ * schema.isLimit( '$root' ); // -> true
207
+ * schema.isLimit( editor.model.document.getRoot() ); // -> true
208
+ * schema.isLimit( 'imageBlock' ); // -> true
209
+ * ```
222
210
  *
223
211
  * See the {@glink framework/guides/deep-dive/schema#limit-elements Limit elements} section of
224
212
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
225
- *
226
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
227
- * @returns {Boolean}
228
213
  */
229
214
  isLimit(item) {
230
215
  const def = this.getDefinition(item);
@@ -241,17 +226,16 @@ export default class Schema extends ObservableMixin() {
241
226
  * {@link module:engine/model/schema~SchemaItemDefinition#isObject `isObject`} property
242
227
  * was set to `true`.
243
228
  *
244
- * schema.isObject( 'paragraph' ); // -> false
245
- * schema.isObject( 'imageBlock' ); // -> true
229
+ * ```ts
230
+ * schema.isObject( 'paragraph' ); // -> false
231
+ * schema.isObject( 'imageBlock' ); // -> true
246
232
  *
247
- * const imageElement = writer.createElement( 'imageBlock' );
248
- * schema.isObject( imageElement ); // -> true
233
+ * const imageElement = writer.createElement( 'imageBlock' );
234
+ * schema.isObject( imageElement ); // -> true
235
+ * ```
249
236
  *
250
237
  * See the {@glink framework/guides/deep-dive/schema#object-elements Object elements} section of
251
238
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
252
- *
253
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
254
- * @returns {Boolean}
255
239
  */
256
240
  isObject(item) {
257
241
  const def = this.getDefinition(item);
@@ -266,17 +250,16 @@ export default class Schema extends ObservableMixin() {
266
250
  * Returns `true` if the given item is defined to be
267
251
  * an inline element by the {@link module:engine/model/schema~SchemaItemDefinition}'s `isInline` property.
268
252
  *
269
- * schema.isInline( 'paragraph' ); // -> false
270
- * schema.isInline( 'softBreak' ); // -> true
253
+ * ```ts
254
+ * schema.isInline( 'paragraph' ); // -> false
255
+ * schema.isInline( 'softBreak' ); // -> true
271
256
  *
272
- * const text = writer.createText( 'foo' );
273
- * schema.isInline( text ); // -> true
257
+ * const text = writer.createText( 'foo' );
258
+ * schema.isInline( text ); // -> true
259
+ * ```
274
260
  *
275
261
  * See the {@glink framework/guides/deep-dive/schema#inline-elements Inline elements} section of
276
262
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
277
- *
278
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
279
- * @returns {Boolean}
280
263
  */
281
264
  isInline(item) {
282
265
  const def = this.getDefinition(item);
@@ -286,19 +269,18 @@ export default class Schema extends ObservableMixin() {
286
269
  * Returns `true` if the given item is defined to be
287
270
  * a selectable element by the {@link module:engine/model/schema~SchemaItemDefinition}'s `isSelectable` property.
288
271
  *
289
- * schema.isSelectable( 'paragraph' ); // -> false
290
- * schema.isSelectable( 'heading1' ); // -> false
291
- * schema.isSelectable( 'imageBlock' ); // -> true
292
- * schema.isSelectable( 'tableCell' ); // -> true
272
+ * ```ts
273
+ * schema.isSelectable( 'paragraph' ); // -> false
274
+ * schema.isSelectable( 'heading1' ); // -> false
275
+ * schema.isSelectable( 'imageBlock' ); // -> true
276
+ * schema.isSelectable( 'tableCell' ); // -> true
293
277
  *
294
- * const text = writer.createText( 'foo' );
295
- * schema.isSelectable( text ); // -> false
278
+ * const text = writer.createText( 'foo' );
279
+ * schema.isSelectable( text ); // -> false
280
+ * ```
296
281
  *
297
282
  * See the {@glink framework/guides/deep-dive/schema#selectable-elements Selectable elements section} of
298
283
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
299
- *
300
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
301
- * @returns {Boolean}
302
284
  */
303
285
  isSelectable(item) {
304
286
  const def = this.getDefinition(item);
@@ -311,19 +293,18 @@ export default class Schema extends ObservableMixin() {
311
293
  * Returns `true` if the given item is defined to be
312
294
  * a content by the {@link module:engine/model/schema~SchemaItemDefinition}'s `isContent` property.
313
295
  *
314
- * schema.isContent( 'paragraph' ); // -> false
315
- * schema.isContent( 'heading1' ); // -> false
316
- * schema.isContent( 'imageBlock' ); // -> true
317
- * schema.isContent( 'horizontalLine' ); // -> true
296
+ * ```ts
297
+ * schema.isContent( 'paragraph' ); // -> false
298
+ * schema.isContent( 'heading1' ); // -> false
299
+ * schema.isContent( 'imageBlock' ); // -> true
300
+ * schema.isContent( 'horizontalLine' ); // -> true
318
301
  *
319
- * const text = writer.createText( 'foo' );
320
- * schema.isContent( text ); // -> true
302
+ * const text = writer.createText( 'foo' );
303
+ * schema.isContent( text ); // -> true
304
+ * ```
321
305
  *
322
306
  * See the {@glink framework/guides/deep-dive/schema#content-elements Content elements section} of
323
307
  * the {@glink framework/guides/deep-dive/schema Schema deep-dive guide} for more details.
324
- *
325
- * @param {module:engine/model/item~Item|module:engine/model/schema~SchemaContextItem|String} item
326
- * @returns {Boolean}
327
308
  */
328
309
  isContent(item) {
329
310
  const def = this.getDefinition(item);
@@ -335,12 +316,14 @@ export default class Schema extends ObservableMixin() {
335
316
  /**
336
317
  * Checks whether the given node (`child`) can be a child of the given context.
337
318
  *
338
- * schema.checkChild( model.document.getRoot(), paragraph ); // -> false
319
+ * ```ts
320
+ * schema.checkChild( model.document.getRoot(), paragraph ); // -> false
339
321
  *
340
- * schema.register( 'paragraph', {
341
- * allowIn: '$root'
342
- * } );
343
- * schema.checkChild( model.document.getRoot(), paragraph ); // -> true
322
+ * schema.register( 'paragraph', {
323
+ * allowIn: '$root'
324
+ * } );
325
+ * schema.checkChild( model.document.getRoot(), paragraph ); // -> true
326
+ * ```
344
327
  *
345
328
  * Note: When verifying whether the given node can be a child of the given context, the
346
329
  * schema also verifies the entire context &mdash; from its root to its last element. Therefore, it is possible
@@ -348,9 +331,8 @@ export default class Schema extends ObservableMixin() {
348
331
  * It happens if one of the context's elements does not allow its child.
349
332
  *
350
333
  * @fires checkChild
351
- * @param {module:engine/model/schema~SchemaContextDefinition} context The context in which the child will be checked.
352
- * @param {module:engine/model/node~Node|String} def The child to check.
353
- * @returns {Boolean}
334
+ * @param context The context in which the child will be checked.
335
+ * @param def The child to check.
354
336
  */
355
337
  checkChild(context, def) {
356
338
  // Note: context and child are already normalized here to a SchemaContext and SchemaCompiledItemDefinition.
@@ -363,17 +345,17 @@ export default class Schema extends ObservableMixin() {
363
345
  * Checks whether the given attribute can be applied in the given context (on the last
364
346
  * item of the context).
365
347
  *
366
- * schema.checkAttribute( textNode, 'bold' ); // -> false
348
+ * ```ts
349
+ * schema.checkAttribute( textNode, 'bold' ); // -> false
367
350
  *
368
- * schema.extend( '$text', {
369
- * allowAttributes: 'bold'
370
- * } );
371
- * schema.checkAttribute( textNode, 'bold' ); // -> true
351
+ * schema.extend( '$text', {
352
+ * allowAttributes: 'bold'
353
+ * } );
354
+ * schema.checkAttribute( textNode, 'bold' ); // -> true
355
+ * ```
372
356
  *
373
357
  * @fires checkAttribute
374
- * @param {module:engine/model/schema~SchemaContextDefinition} context The context in which the attribute will be checked.
375
- * @param {String} attributeName
376
- * @returns {Boolean}
358
+ * @param context The context in which the attribute will be checked.
377
359
  */
378
360
  checkAttribute(context, attributeName) {
379
361
  const def = this.getDefinition(context.last);
@@ -393,10 +375,8 @@ export default class Schema extends ObservableMixin() {
393
375
  * Instead of elements, you can pass the instance of the {@link module:engine/model/position~Position} class as the
394
376
  * `positionOrBaseElement`. It means that the elements before and after the position will be checked whether they can be merged.
395
377
  *
396
- * @param {module:engine/model/position~Position|module:engine/model/element~Element} positionOrBaseElement The position or base
397
- * element to which the `elementToMerge` will be merged.
398
- * @param {module:engine/model/element~Element} elementToMerge The element to merge. Required if `positionOrBaseElement` is an element.
399
- * @returns {Boolean}
378
+ * @param positionOrBaseElement The position or base element to which the `elementToMerge` will be merged.
379
+ * @param elementToMerge The element to merge. Required if `positionOrBaseElement` is an element.
400
380
  */
401
381
  checkMerge(positionOrBaseElement, elementToMerge) {
402
382
  if (positionOrBaseElement instanceof Position) {
@@ -439,28 +419,32 @@ export default class Schema extends ObservableMixin() {
439
419
  *
440
420
  * Example:
441
421
  *
442
- * // Disallow heading1 directly inside a blockQuote.
443
- * schema.addChildCheck( ( context, childDefinition ) => {
444
- * if ( context.endsWith( 'blockQuote' ) && childDefinition.name == 'heading1' ) {
445
- * return false;
446
- * }
447
- * } );
422
+ * ```ts
423
+ * // Disallow heading1 directly inside a blockQuote.
424
+ * schema.addChildCheck( ( context, childDefinition ) => {
425
+ * if ( context.endsWith( 'blockQuote' ) && childDefinition.name == 'heading1' ) {
426
+ * return false;
427
+ * }
428
+ * } );
429
+ * ```
448
430
  *
449
431
  * Which translates to:
450
432
  *
451
- * schema.on( 'checkChild', ( evt, args ) => {
452
- * const context = args[ 0 ];
453
- * const childDefinition = args[ 1 ];
454
- *
455
- * if ( context.endsWith( 'blockQuote' ) && childDefinition && childDefinition.name == 'heading1' ) {
456
- * // Prevent next listeners from being called.
457
- * evt.stop();
458
- * // Set the checkChild()'s return value.
459
- * evt.return = false;
460
- * }
461
- * }, { priority: 'high' } );
462
- *
463
- * @param {Function} callback The callback to be called. It is called with two parameters:
433
+ * ```ts
434
+ * schema.on( 'checkChild', ( evt, args ) => {
435
+ * const context = args[ 0 ];
436
+ * const childDefinition = args[ 1 ];
437
+ *
438
+ * if ( context.endsWith( 'blockQuote' ) && childDefinition && childDefinition.name == 'heading1' ) {
439
+ * // Prevent next listeners from being called.
440
+ * evt.stop();
441
+ * // Set the checkChild()'s return value.
442
+ * evt.return = false;
443
+ * }
444
+ * }, { priority: 'high' } );
445
+ * ```
446
+ *
447
+ * @param callback The callback to be called. It is called with two parameters:
464
448
  * {@link module:engine/model/schema~SchemaContext} (context) instance and
465
449
  * {@link module:engine/model/schema~SchemaCompiledItemDefinition} (child-to-check definition).
466
450
  * The callback may return `true/false` to override `checkChild()`'s return value. If it does not return
@@ -494,28 +478,32 @@ export default class Schema extends ObservableMixin() {
494
478
  *
495
479
  * Example:
496
480
  *
497
- * // Disallow bold on $text inside heading1.
498
- * schema.addAttributeCheck( ( context, attributeName ) => {
499
- * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
500
- * return false;
501
- * }
502
- * } );
481
+ * ```ts
482
+ * // Disallow bold on $text inside heading1.
483
+ * schema.addAttributeCheck( ( context, attributeName ) => {
484
+ * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
485
+ * return false;
486
+ * }
487
+ * } );
488
+ * ```
503
489
  *
504
490
  * Which translates to:
505
491
  *
506
- * schema.on( 'checkAttribute', ( evt, args ) => {
507
- * const context = args[ 0 ];
508
- * const attributeName = args[ 1 ];
509
- *
510
- * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
511
- * // Prevent next listeners from being called.
512
- * evt.stop();
513
- * // Set the checkAttribute()'s return value.
514
- * evt.return = false;
515
- * }
516
- * }, { priority: 'high' } );
517
- *
518
- * @param {Function} callback The callback to be called. It is called with two parameters:
492
+ * ```ts
493
+ * schema.on( 'checkAttribute', ( evt, args ) => {
494
+ * const context = args[ 0 ];
495
+ * const attributeName = args[ 1 ];
496
+ *
497
+ * if ( context.endsWith( 'heading1 $text' ) && attributeName == 'bold' ) {
498
+ * // Prevent next listeners from being called.
499
+ * evt.stop();
500
+ * // Set the checkAttribute()'s return value.
501
+ * evt.return = false;
502
+ * }
503
+ * }, { priority: 'high' } );
504
+ * ```
505
+ *
506
+ * @param callback The callback to be called. It is called with two parameters:
519
507
  * {@link module:engine/model/schema~SchemaContext} (context) instance and attribute name.
520
508
  * The callback may return `true/false` to override `checkAttribute()`'s return value. If it does not return
521
509
  * a boolean value, the default algorithm (or other callbacks) will define `checkAttribute()`'s return value.
@@ -534,38 +522,44 @@ export default class Schema extends ObservableMixin() {
534
522
  * {@link module:engine/model/schema~AttributeProperties `AttributeProperties#isFormatting` property} is
535
523
  * used to mark formatting attributes (like `bold` or `italic`).
536
524
  *
537
- * // Mark bold as a formatting attribute.
538
- * schema.setAttributeProperties( 'bold', {
539
- * isFormatting: true
540
- * } );
525
+ * ```ts
526
+ * // Mark bold as a formatting attribute.
527
+ * schema.setAttributeProperties( 'bold', {
528
+ * isFormatting: true
529
+ * } );
541
530
  *
542
- * // Override code not to be considered a formatting markup.
543
- * schema.setAttributeProperties( 'code', {
544
- * isFormatting: false
545
- * } );
531
+ * // Override code not to be considered a formatting markup.
532
+ * schema.setAttributeProperties( 'code', {
533
+ * isFormatting: false
534
+ * } );
535
+ * ```
546
536
  *
547
537
  * Properties are not limited to members defined in the
548
538
  * {@link module:engine/model/schema~AttributeProperties `AttributeProperties` type} and you can also use custom properties:
549
539
  *
550
- * schema.setAttributeProperties( 'blockQuote', {
551
- * customProperty: 'value'
552
- * } );
540
+ * ```ts
541
+ * schema.setAttributeProperties( 'blockQuote', {
542
+ * customProperty: 'value'
543
+ * } );
544
+ * ```
553
545
  *
554
546
  * Subsequent calls with the same attribute will extend its custom properties:
555
547
  *
556
- * schema.setAttributeProperties( 'blockQuote', {
557
- * one: 1
558
- * } );
548
+ * ```ts
549
+ * schema.setAttributeProperties( 'blockQuote', {
550
+ * one: 1
551
+ * } );
559
552
  *
560
- * schema.setAttributeProperties( 'blockQuote', {
561
- * two: 2
562
- * } );
553
+ * schema.setAttributeProperties( 'blockQuote', {
554
+ * two: 2
555
+ * } );
563
556
  *
564
- * console.log( schema.getAttributeProperties( 'blockQuote' ) );
565
- * // Logs: { one: 1, two: 2 }
557
+ * console.log( schema.getAttributeProperties( 'blockQuote' ) );
558
+ * // Logs: { one: 1, two: 2 }
559
+ * ```
566
560
  *
567
- * @param {String} attributeName A name of the attribute to receive the properties.
568
- * @param {module:engine/model/schema~AttributeProperties} properties A dictionary of properties.
561
+ * @param attributeName A name of the attribute to receive the properties.
562
+ * @param properties A dictionary of properties.
569
563
  */
570
564
  setAttributeProperties(attributeName, properties) {
571
565
  this._attributeProperties[attributeName] = Object.assign(this.getAttributeProperties(attributeName), properties);
@@ -573,8 +567,7 @@ export default class Schema extends ObservableMixin() {
573
567
  /**
574
568
  * Returns properties associated with a given model attribute. See {@link #setAttributeProperties `setAttributeProperties()`}.
575
569
  *
576
- * @param {String} attributeName A name of the attribute.
577
- * @returns {module:engine/model/schema~AttributeProperties}
570
+ * @param attributeName A name of the attribute.
578
571
  */
579
572
  getAttributeProperties(attributeName) {
580
573
  return this._attributeProperties[attributeName] || {};
@@ -583,11 +576,8 @@ export default class Schema extends ObservableMixin() {
583
576
  * Returns the lowest {@link module:engine/model/schema~Schema#isLimit limit element} containing the entire
584
577
  * selection/range/position or the root otherwise.
585
578
  *
586
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection|
587
- * module:engine/model/range~Range|module:engine/model/position~Position} selectionOrRangeOrPosition
588
- * The selection/range/position to check.
589
- * @returns {module:engine/model/element~Element} The lowest limit element containing
590
- * the entire `selectionOrRangeOrPosition`.
579
+ * @param selectionOrRangeOrPosition The selection/range/position to check.
580
+ * @returns The lowest limit element containing the entire `selectionOrRangeOrPosition`.
591
581
  */
592
582
  getLimitElement(selectionOrRangeOrPosition) {
593
583
  let element;
@@ -625,10 +615,8 @@ export default class Schema extends ObservableMixin() {
625
615
  * * if the selection is collapsed, then checks if on the selection position there's a text with the
626
616
  * specified attribute allowed.
627
617
  *
628
- * @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection
629
- * Selection which will be checked.
630
- * @param {String} attribute The name of the attribute to check.
631
- * @returns {Boolean}
618
+ * @param selection Selection which will be checked.
619
+ * @param attribute The name of the attribute to check.
632
620
  */
633
621
  checkAttributeInSelection(selection, attribute) {
634
622
  if (selection.isCollapsed) {
@@ -658,9 +646,9 @@ export default class Schema extends ObservableMixin() {
658
646
  /**
659
647
  * Transforms the given set of ranges into a set of ranges where the given attribute is allowed (and can be applied).
660
648
  *
661
- * @param {Iterable.<module:engine/model/range~Range>} ranges Ranges to be validated.
662
- * @param {String} attribute The name of the attribute to check.
663
- * @returns {Iterable.<module:engine/model/range~Range>} Ranges in which the attribute is allowed.
649
+ * @param ranges Ranges to be validated.
650
+ * @param attribute The name of the attribute to check.
651
+ * @returns Ranges in which the attribute is allowed.
664
652
  */
665
653
  *getValidRanges(ranges, attribute) {
666
654
  ranges = convertToMinimalFlatRanges(ranges);
@@ -684,9 +672,9 @@ export default class Schema extends ObservableMixin() {
684
672
  *
685
673
  * When valid selection range cannot be found, `null` is returned.
686
674
  *
687
- * @param {module:engine/model/position~Position} position Reference position where new selection range should be looked for.
688
- * @param {'both'|'forward'|'backward'} [direction='both'] Search direction.
689
- * @returns {module:engine/model/range~Range|null} Nearest selection range or `null` if one cannot be found.
675
+ * @param position Reference position where new selection range should be looked for.
676
+ * @param direction Search direction.
677
+ * @returns Nearest selection range or `null` if one cannot be found.
690
678
  */
691
679
  getNearestSelectionRange(position, direction = 'both') {
692
680
  // Return collapsed range if provided position is valid.
@@ -728,9 +716,9 @@ export default class Schema extends ObservableMixin() {
728
716
  * as long as a {@link module:engine/model/schema~Schema#isLimit limit element}, an
729
717
  * {@link module:engine/model/schema~Schema#isObject object element} or a topmost ancestor is not reached.
730
718
  *
731
- * @param {module:engine/model/position~Position} position The position that the search will start from.
732
- * @param {module:engine/model/node~Node|String} node The node for which an allowed parent should be found or its name.
733
- * @returns {module:engine/model/element~Element|null} element Allowed parent or null if nothing was found.
719
+ * @param position The position that the search will start from.
720
+ * @param node The node for which an allowed parent should be found or its name.
721
+ * @returns Allowed parent or null if nothing was found.
734
722
  */
735
723
  findAllowedParent(position, node) {
736
724
  let parent = position.parent;
@@ -749,9 +737,9 @@ export default class Schema extends ObservableMixin() {
749
737
  /**
750
738
  * Sets attributes allowed by the schema on a given node.
751
739
  *
752
- * @param {module:engine/model/node~Node} node A node to set attributes on.
753
- * @param {Object} attributes Attributes keys and values.
754
- * @param {module:engine/model/writer~Writer} writer An instance of the model writer.
740
+ * @param node A node to set attributes on.
741
+ * @param attributes Attributes keys and values.
742
+ * @param writer An instance of the model writer.
755
743
  */
756
744
  setAllowedAttributes(node, attributes, writer) {
757
745
  const model = writer.model;
@@ -764,8 +752,7 @@ export default class Schema extends ObservableMixin() {
764
752
  /**
765
753
  * Removes attributes disallowed by the schema.
766
754
  *
767
- * @param {Iterable.<module:engine/model/node~Node>} nodes Nodes that will be filtered.
768
- * @param {module:engine/model/writer~Writer} writer
755
+ * @param nodes Nodes that will be filtered.
769
756
  */
770
757
  removeDisallowedAttributes(nodes, writer) {
771
758
  for (const node of nodes) {
@@ -790,12 +777,12 @@ export default class Schema extends ObservableMixin() {
790
777
  /**
791
778
  * Gets attributes of a node that have a given property.
792
779
  *
793
- * @param {module:engine/model/node~Node} node Node to get attributes from.
794
- * @param {String} propertyName Name of the property that attribute must have to return it.
795
- * @param {Boolean|Symbol|String|Number|Object|null|undefined} propertyValue Desired value of the property that we want to check.
780
+ * @param node Node to get attributes from.
781
+ * @param propertyName Name of the property that attribute must have to return it.
782
+ * @param propertyValue Desired value of the property that we want to check.
796
783
  * When `undefined` attributes will be returned if they have set a given property no matter what the value is. If specified it will
797
784
  * return attributes which given property's value is equal to this parameter.
798
- * @returns {Object} Object with attributes' names as key and attributes' values as value.
785
+ * @returns Object with attributes' names as key and attributes' values as value.
799
786
  */
800
787
  getAttributesWithProperty(node, propertyName, propertyValue) {
801
788
  const attributes = {};
@@ -812,22 +799,13 @@ export default class Schema extends ObservableMixin() {
812
799
  }
813
800
  /**
814
801
  * Creates an instance of the schema context.
815
- *
816
- * @param {module:engine/model/schema~SchemaContextDefinition} context
817
- * @returns {module:engine/model/schema~SchemaContext}
818
802
  */
819
803
  createContext(context) {
820
804
  return new SchemaContext(context);
821
805
  }
822
- /**
823
- * @private
824
- */
825
806
  _clearCache() {
826
807
  this._compiledDefinitions = null;
827
808
  }
828
- /**
829
- * @private
830
- */
831
809
  _compile() {
832
810
  const compiledDefinitions = {};
833
811
  const sourceRules = this._sourceDefinitions;
@@ -855,12 +833,6 @@ export default class Schema extends ObservableMixin() {
855
833
  }
856
834
  this._compiledDefinitions = compiledDefinitions;
857
835
  }
858
- /**
859
- * @private
860
- * @param {module:engine/model/schema~SchemaCompiledItemDefinition} def
861
- * @param {module:engine/model/schema~SchemaContext} context
862
- * @param {Number} contextItemIndex
863
- */
864
836
  _checkContextMatch(def, context, contextItemIndex = context.length - 1) {
865
837
  const contextItem = context.getItem(contextItemIndex);
866
838
  if (def.allowIn.includes(contextItem.name)) {
@@ -882,10 +854,9 @@ export default class Schema extends ObservableMixin() {
882
854
  *
883
855
  * This is a helper function for {@link ~Schema#getValidRanges}.
884
856
  *
885
- * @private
886
- * @param {module:engine/model/range~Range} range The range to process.
887
- * @param {String} attribute The name of the attribute to check.
888
- * @returns {Iterable.<module:engine/model/range~Range>} Ranges in which the attribute is allowed.
857
+ * @param range The range to process.
858
+ * @param attribute The name of the attribute to check.
859
+ * @returns Ranges in which the attribute is allowed.
889
860
  */
890
861
  *_getValidRangesForRange(range, attribute) {
891
862
  let start = range.start;
@@ -912,13 +883,15 @@ export default class Schema extends ObservableMixin() {
912
883
  *
913
884
  * Considering such position:
914
885
  *
915
- * <$root>
916
- * <blockQuote>
917
- * <paragraph>
918
- * ^
919
- * </paragraph>
920
- * </blockQuote>
921
- * </$root>
886
+ * ```xml
887
+ * <$root>
888
+ * <blockQuote>
889
+ * <paragraph>
890
+ * ^
891
+ * </paragraph>
892
+ * </blockQuote>
893
+ * </$root>
894
+ * ```
922
895
  *
923
896
  * The context of this position is its {@link module:engine/model/position~Position#getAncestors lists of ancestors}:
924
897
  *
@@ -934,8 +907,6 @@ export default class Schema extends ObservableMixin() {
934
907
  export class SchemaContext {
935
908
  /**
936
909
  * Creates an instance of the context.
937
- *
938
- * @param {module:engine/model/schema~SchemaContextDefinition} context
939
910
  */
940
911
  constructor(context) {
941
912
  if (context instanceof SchemaContext) {
@@ -957,16 +928,12 @@ export class SchemaContext {
957
928
  }
958
929
  /**
959
930
  * The number of items.
960
- *
961
- * @type {Number}
962
931
  */
963
932
  get length() {
964
933
  return this._items.length;
965
934
  }
966
935
  /**
967
936
  * The last item (the lowest node).
968
- *
969
- * @type {module:engine/model/schema~SchemaContextItem}
970
937
  */
971
938
  get last() {
972
939
  return this._items[this._items.length - 1];
@@ -975,8 +942,6 @@ export class SchemaContext {
975
942
  * Iterable interface.
976
943
  *
977
944
  * Iterates over all context items.
978
- *
979
- * @returns {Iterable.<module:engine/model/schema~SchemaContextItem>}
980
945
  */
981
946
  [Symbol.iterator]() {
982
947
  return this._items[Symbol.iterator]();
@@ -986,25 +951,26 @@ export class SchemaContext {
986
951
  *
987
952
  * Item can be added as:
988
953
  *
989
- * const context = new SchemaContext( [ '$root' ] );
954
+ * ```ts
955
+ * const context = new SchemaContext( [ '$root' ] );
990
956
  *
991
- * // An element.
992
- * const fooElement = writer.createElement( 'fooElement' );
993
- * const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
957
+ * // An element.
958
+ * const fooElement = writer.createElement( 'fooElement' );
959
+ * const newContext = context.push( fooElement ); // [ '$root', 'fooElement' ]
994
960
  *
995
- * // A text node.
996
- * const text = writer.createText( 'foobar' );
997
- * const newContext = context.push( text ); // [ '$root', '$text' ]
961
+ * // A text node.
962
+ * const text = writer.createText( 'foobar' );
963
+ * const newContext = context.push( text ); // [ '$root', '$text' ]
998
964
  *
999
- * // A string (element name).
1000
- * const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
965
+ * // A string (element name).
966
+ * const newContext = context.push( 'barElement' ); // [ '$root', 'barElement' ]
967
+ * ```
1001
968
  *
1002
969
  * **Note** {@link module:engine/model/node~Node} that is already in the model tree will be added as the only item
1003
970
  * (without ancestors).
1004
971
  *
1005
- * @param {String|module:engine/model/node~Node} item An item that will be added
1006
- * to the current context.
1007
- * @returns {module:engine/model/schema~SchemaContext} A new schema context instance with an additional item.
972
+ * @param item An item that will be added to the current context.
973
+ * @returns A new schema context instance with an additional item.
1008
974
  */
1009
975
  push(item) {
1010
976
  const ctx = new SchemaContext([item]);
@@ -1013,16 +979,12 @@ export class SchemaContext {
1013
979
  }
1014
980
  /**
1015
981
  * Gets an item on the given index.
1016
- *
1017
- * @returns {module:engine/model/schema~SchemaContextItem}
1018
982
  */
1019
983
  getItem(index) {
1020
984
  return this._items[index];
1021
985
  }
1022
986
  /**
1023
987
  * Returns the names of items.
1024
- *
1025
- * @returns {Iterable.<String>}
1026
988
  */
1027
989
  *getNames() {
1028
990
  yield* this._items.map(item => item.name);
@@ -1030,15 +992,14 @@ export class SchemaContext {
1030
992
  /**
1031
993
  * Checks whether the context ends with the given nodes.
1032
994
  *
1033
- * const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] );
1034
- *
1035
- * ctx.endsWith( '$text' ); // -> true
1036
- * ctx.endsWith( 'paragraph $text' ); // -> true
1037
- * ctx.endsWith( '$root' ); // -> false
1038
- * ctx.endsWith( 'paragraph' ); // -> false
995
+ * ```ts
996
+ * const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] );
1039
997
  *
1040
- * @param {String} query
1041
- * @returns {Boolean}
998
+ * ctx.endsWith( '$text' ); // -> true
999
+ * ctx.endsWith( 'paragraph $text' ); // -> true
1000
+ * ctx.endsWith( '$root' ); // -> false
1001
+ * ctx.endsWith( 'paragraph' ); // -> false
1002
+ * ```
1042
1003
  */
1043
1004
  endsWith(query) {
1044
1005
  return Array.from(this.getNames()).join(' ').endsWith(query);
@@ -1046,15 +1007,14 @@ export class SchemaContext {
1046
1007
  /**
1047
1008
  * Checks whether the context starts with the given nodes.
1048
1009
  *
1049
- * const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] );
1050
- *
1051
- * ctx.endsWith( '$root' ); // -> true
1052
- * ctx.endsWith( '$root paragraph' ); // -> true
1053
- * ctx.endsWith( '$text' ); // -> false
1054
- * ctx.endsWith( 'paragraph' ); // -> false
1010
+ * ```ts
1011
+ * const ctx = new SchemaContext( [ rootElement, paragraphElement, textNode ] );
1055
1012
  *
1056
- * @param {String} query
1057
- * @returns {Boolean}
1013
+ * ctx.endsWith( '$root' ); // -> true
1014
+ * ctx.endsWith( '$root paragraph' ); // -> true
1015
+ * ctx.endsWith( '$text' ); // -> false
1016
+ * ctx.endsWith( 'paragraph' ); // -> false
1017
+ * ```
1058
1018
  */
1059
1019
  startsWith(query) {
1060
1020
  return Array.from(this.getNames()).join(' ').startsWith(query);
@@ -1221,13 +1181,15 @@ function mapContextItem(ctxItem) {
1221
1181
  };
1222
1182
  }
1223
1183
  }
1224
- // Generator function returning values from provided walkers, switching between them at each iteration. If only one walker
1225
- // is provided it will return data only from that walker.
1226
- //
1227
- // @param {module:engine/module/treewalker~TreeWalker} [backward] Walker iterating in backward direction.
1228
- // @param {module:engine/module/treewalker~TreeWalker} [forward] Walker iterating in forward direction.
1229
- // @returns {Iterable.<Object>} Object returned at each iteration contains `value` and `walker` (informing which walker returned
1230
- // given value) fields.
1184
+ /**
1185
+ * Generator function returning values from provided walkers, switching between them at each iteration. If only one walker
1186
+ * is provided it will return data only from that walker.
1187
+ *
1188
+ * @param backward Walker iterating in backward direction.
1189
+ * @param forward Walker iterating in forward direction.
1190
+ * @returns Object returned at each iteration contains `value` and `walker` (informing which walker returned
1191
+ * given value) fields.
1192
+ */
1231
1193
  function* combineWalkers(backward, forward) {
1232
1194
  let done = false;
1233
1195
  while (!done) {
@@ -1254,11 +1216,13 @@ function* combineWalkers(backward, forward) {
1254
1216
  }
1255
1217
  }
1256
1218
  }
1257
- // Takes an array of non-intersecting ranges. For each of them gets minimal flat ranges covering that range and returns
1258
- // all those minimal flat ranges.
1259
- //
1260
- // @param {Array.<module:engine/model/range~Range>} ranges Ranges to process.
1261
- // @returns {Iterable.<module:engine/model/range~Range>} Minimal flat ranges of given `ranges`.
1219
+ /**
1220
+ * Takes an array of non-intersecting ranges. For each of them gets minimal flat ranges covering that range and returns
1221
+ * all those minimal flat ranges.
1222
+ *
1223
+ * @param ranges Ranges to process.
1224
+ * @returns Minimal flat ranges of given `ranges`.
1225
+ */
1262
1226
  function* convertToMinimalFlatRanges(ranges) {
1263
1227
  for (const range of ranges) {
1264
1228
  yield* range.getMinimalFlatRanges();