@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
  /**
@@ -22,25 +22,12 @@ export default class Range extends TypeCheckable {
22
22
  /**
23
23
  * Creates a range spanning from `start` position to `end` position.
24
24
  *
25
- * @param {module:engine/model/position~Position} start The start position.
26
- * @param {module:engine/model/position~Position|null} [end] The end position. If not set,
27
- * the range will be collapsed at the `start` position.
25
+ * @param start The start position.
26
+ * @param end The end position. If not set, the range will be collapsed at the `start` position.
28
27
  */
29
28
  constructor(start, end) {
30
29
  super();
31
- /**
32
- * Start position.
33
- *
34
- * @readonly
35
- * @member {module:engine/model/position~Position}
36
- */
37
30
  this.start = Position._createAt(start);
38
- /**
39
- * End position.
40
- *
41
- * @readonly
42
- * @member {module:engine/model/position~Position}
43
- */
44
31
  this.end = end ? Position._createAt(end) : Position._createAt(start);
45
32
  // If the range is collapsed, treat in a similar way as a position and set its boundaries stickiness to 'toNone'.
46
33
  // In other case, make the boundaries stick to the "inside" of the range.
@@ -58,26 +45,20 @@ export default class Range extends TypeCheckable {
58
45
  *
59
46
  * This iterator uses {@link module:engine/model/treewalker~TreeWalker} with `boundaries` set to this range
60
47
  * and `ignoreElementEnd` option set to `true`.
61
- *
62
- * @returns {Iterator.<module:engine/model/treewalker~TreeWalkerValue>}
63
48
  */
64
49
  *[Symbol.iterator]() {
65
50
  yield* new TreeWalker({ boundaries: this, ignoreElementEnd: true });
66
51
  }
67
52
  /**
68
- * Returns whether the range is collapsed, that is if {@link #start} and
53
+ * Describes whether the range is collapsed, that is if {@link #start} and
69
54
  * {@link #end} positions are equal.
70
- *
71
- * @type {Boolean}
72
55
  */
73
56
  get isCollapsed() {
74
57
  return this.start.isEqual(this.end);
75
58
  }
76
59
  /**
77
- * Returns whether this range is flat, that is if {@link #start} position and
60
+ * Describes whether this range is flat, that is if {@link #start} position and
78
61
  * {@link #end} position are in the same {@link module:engine/model/position~Position#parent}.
79
- *
80
- * @type {Boolean}
81
62
  */
82
63
  get isFlat() {
83
64
  const startParentPath = this.start.getParentPath();
@@ -86,8 +67,6 @@ export default class Range extends TypeCheckable {
86
67
  }
87
68
  /**
88
69
  * Range root element.
89
- *
90
- * @type {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment}
91
70
  */
92
71
  get root() {
93
72
  return this.start.root;
@@ -95,8 +74,8 @@ export default class Range extends TypeCheckable {
95
74
  /**
96
75
  * Checks whether this range contains given {@link module:engine/model/position~Position position}.
97
76
  *
98
- * @param {module:engine/model/position~Position} position Position to check.
99
- * @returns {Boolean} `true` if given {@link module:engine/model/position~Position position} is contained
77
+ * @param position Position to check.
78
+ * @returns `true` if given {@link module:engine/model/position~Position position} is contained
100
79
  * in this range,`false` otherwise.
101
80
  */
102
81
  containsPosition(position) {
@@ -105,8 +84,8 @@ export default class Range extends TypeCheckable {
105
84
  /**
106
85
  * Checks whether this range contains given {@link ~Range range}.
107
86
  *
108
- * @param {module:engine/model/range~Range} otherRange Range to check.
109
- * @param {Boolean} [loose=false] Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
87
+ * @param otherRange Range to check.
88
+ * @param loose Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
110
89
  * start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
111
90
  * even be equal to this range. Note that collapsed ranges are always compared in strict mode.
112
91
  * @returns {Boolean} `true` if given {@link ~Range range} boundaries are contained by this range, `false` otherwise.
@@ -121,8 +100,6 @@ export default class Range extends TypeCheckable {
121
100
  }
122
101
  /**
123
102
  * Checks whether given {@link module:engine/model/item~Item} is inside this range.
124
- *
125
- * @param {module:engine/model/item~Item} item Model item to check.
126
103
  */
127
104
  containsItem(item) {
128
105
  const pos = Position._createBefore(item);
@@ -131,8 +108,8 @@ export default class Range extends TypeCheckable {
131
108
  /**
132
109
  * Two ranges are equal if their {@link #start} and {@link #end} positions are equal.
133
110
  *
134
- * @param {module:engine/model/range~Range} otherRange Range to compare with.
135
- * @returns {Boolean} `true` if ranges are equal, `false` otherwise.
111
+ * @param otherRange Range to compare with.
112
+ * @returns `true` if ranges are equal, `false` otherwise.
136
113
  */
137
114
  isEqual(otherRange) {
138
115
  return this.start.isEqual(otherRange.start) && this.end.isEqual(otherRange.end);
@@ -140,8 +117,8 @@ export default class Range extends TypeCheckable {
140
117
  /**
141
118
  * Checks and returns whether this range intersects with given range.
142
119
  *
143
- * @param {module:engine/model/range~Range} otherRange Range to compare with.
144
- * @returns {Boolean} `true` if ranges intersect, `false` otherwise.
120
+ * @param otherRange Range to compare with.
121
+ * @returns `true` if ranges intersect, `false` otherwise.
145
122
  */
146
123
  isIntersecting(otherRange) {
147
124
  return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
@@ -152,24 +129,26 @@ export default class Range extends TypeCheckable {
152
129
  *
153
130
  * Examples:
154
131
  *
155
- * let range = model.createRange(
156
- * model.createPositionFromPath( root, [ 2, 7 ] ),
157
- * model.createPositionFromPath( root, [ 4, 0, 1 ] )
158
- * );
159
- * let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 5 ] ) );
160
- * let transformed = range.getDifference( otherRange );
161
- * // transformed array has no ranges because `otherRange` contains `range`
132
+ * ```ts
133
+ * let range = model.createRange(
134
+ * model.createPositionFromPath( root, [ 2, 7 ] ),
135
+ * model.createPositionFromPath( root, [ 4, 0, 1 ] )
136
+ * );
137
+ * let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 5 ] ) );
138
+ * let transformed = range.getDifference( otherRange );
139
+ * // transformed array has no ranges because `otherRange` contains `range`
162
140
  *
163
- * otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 3 ] ) );
164
- * transformed = range.getDifference( otherRange );
165
- * // transformed array has one range: from [ 3 ] to [ 4, 0, 1 ]
141
+ * otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 3 ] ) );
142
+ * transformed = range.getDifference( otherRange );
143
+ * // transformed array has one range: from [ 3 ] to [ 4, 0, 1 ]
166
144
  *
167
- * otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 4 ] ) );
168
- * transformed = range.getDifference( otherRange );
169
- * // transformed array has two ranges: from [ 2, 7 ] to [ 3 ] and from [ 4 ] to [ 4, 0, 1 ]
145
+ * otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 4 ] ) );
146
+ * transformed = range.getDifference( otherRange );
147
+ * // transformed array has two ranges: from [ 2, 7 ] to [ 3 ] and from [ 4 ] to [ 4, 0, 1 ]
148
+ * ```
170
149
  *
171
- * @param {module:engine/model/range~Range} otherRange Range to differentiate against.
172
- * @returns {Array.<module:engine/model/range~Range>} The difference between ranges.
150
+ * @param otherRange Range to differentiate against.
151
+ * @returns The difference between ranges.
173
152
  */
174
153
  getDifference(otherRange) {
175
154
  const ranges = [];
@@ -198,18 +177,20 @@ export default class Range extends TypeCheckable {
198
177
  *
199
178
  * Examples:
200
179
  *
201
- * let range = model.createRange(
202
- * model.createPositionFromPath( root, [ 2, 7 ] ),
203
- * model.createPositionFromPath( root, [ 4, 0, 1 ] )
204
- * );
205
- * let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 2 ] ) );
206
- * let transformed = range.getIntersection( otherRange ); // null - ranges have no common part
180
+ * ```ts
181
+ * let range = model.createRange(
182
+ * model.createPositionFromPath( root, [ 2, 7 ] ),
183
+ * model.createPositionFromPath( root, [ 4, 0, 1 ] )
184
+ * );
185
+ * let otherRange = model.createRange( model.createPositionFromPath( root, [ 1 ] ), model.createPositionFromPath( root, [ 2 ] ) );
186
+ * let transformed = range.getIntersection( otherRange ); // null - ranges have no common part
207
187
  *
208
- * otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 5 ] ) );
209
- * transformed = range.getIntersection( otherRange ); // range from [ 3 ] to [ 4, 0, 1 ]
188
+ * otherRange = model.createRange( model.createPositionFromPath( root, [ 3 ] ), model.createPositionFromPath( root, [ 5 ] ) );
189
+ * transformed = range.getIntersection( otherRange ); // range from [ 3 ] to [ 4, 0, 1 ]
190
+ * ```
210
191
  *
211
- * @param {module:engine/model/range~Range} otherRange Range to check for intersection.
212
- * @returns {module:engine/model/range~Range|null} A common part of given ranges or `null` if ranges have no common part.
192
+ * @param otherRange Range to check for intersection.
193
+ * @returns A common part of given ranges or `null` if ranges have no common part.
213
194
  */
214
195
  getIntersection(otherRange) {
215
196
  if (this.isIntersecting(otherRange)) {
@@ -238,27 +219,29 @@ export default class Range extends TypeCheckable {
238
219
  *
239
220
  * Examples:
240
221
  *
241
- * let range = model.createRange(
242
- * model.createPositionFromPath( root, [ 2, 7 ] ),
243
- * model.createPositionFromPath( root, [ 4, 0, 1 ] )
244
- * );
245
- * let otherRange = model.createRange(
246
- * model.createPositionFromPath( root, [ 1 ] ),
247
- * model.createPositionFromPath( root, [ 2 ] )
248
- * );
249
- * let transformed = range.getJoined( otherRange ); // null - ranges have no common part
250
- *
251
- * otherRange = model.createRange(
252
- * model.createPositionFromPath( root, [ 3 ] ),
253
- * model.createPositionFromPath( root, [ 5 ] )
254
- * );
255
- * transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]
256
- *
257
- * @param {module:engine/model/range~Range} otherRange Range to be joined.
258
- * @param {Boolean} [loose=false] Whether the intersection check is loose or strict. If the check is strict (`false`),
222
+ * ```ts
223
+ * let range = model.createRange(
224
+ * model.createPositionFromPath( root, [ 2, 7 ] ),
225
+ * model.createPositionFromPath( root, [ 4, 0, 1 ] )
226
+ * );
227
+ * let otherRange = model.createRange(
228
+ * model.createPositionFromPath( root, [ 1 ] ),
229
+ * model.createPositionFromPath( root, [ 2 ] )
230
+ * );
231
+ * let transformed = range.getJoined( otherRange ); // null - ranges have no common part
232
+ *
233
+ * otherRange = model.createRange(
234
+ * model.createPositionFromPath( root, [ 3 ] ),
235
+ * model.createPositionFromPath( root, [ 5 ] )
236
+ * );
237
+ * transformed = range.getJoined( otherRange ); // range from [ 2, 7 ] to [ 5 ]
238
+ * ```
239
+ *
240
+ * @param otherRange Range to be joined.
241
+ * @param loose Whether the intersection check is loose or strict. If the check is strict (`false`),
259
242
  * ranges are tested for intersection or whether start/end positions are equal. If the check is loose (`true`),
260
243
  * compared range is also checked if it's {@link module:engine/model/position~Position#isTouching touching} current range.
261
- * @returns {module:engine/model/range~Range|null} A sum of given ranges or `null` if ranges have no common part.
244
+ * @returns A sum of given ranges or `null` if ranges have no common part.
262
245
  */
263
246
  getJoined(otherRange, loose = false) {
264
247
  let shouldJoin = this.isIntersecting(otherRange);
@@ -288,31 +271,35 @@ export default class Range extends TypeCheckable {
288
271
  *
289
272
  * See an example of a model structure (`[` and `]` are range boundaries):
290
273
  *
291
- * root root
292
- * |- element DIV DIV P2 P3 DIV
293
- * | |- element H H P1 f o o b a r H P4
294
- * | | |- "fir[st" fir[st lorem se]cond ipsum
295
- * | |- element P1
296
- * | | |- "lorem" ||
297
- * |- element P2 ||
298
- * | |- "foo" VV
299
- * |- element P3
300
- * | |- "bar" root
301
- * |- element DIV DIV [P2 P3] DIV
302
- * | |- element H H [P1] f o o b a r H P4
303
- * | | |- "se]cond" fir[st] lorem [se]cond ipsum
304
- * | |- element P4
305
- * | | |- "ipsum"
274
+ * ```
275
+ * root root
276
+ * |- element DIV DIV P2 P3 DIV
277
+ * | |- element H H P1 f o o b a r H P4
278
+ * | | |- "fir[st" fir[st lorem se]cond ipsum
279
+ * | |- element P1
280
+ * | | |- "lorem" ||
281
+ * |- element P2 ||
282
+ * | |- "foo" VV
283
+ * |- element P3
284
+ * | |- "bar" root
285
+ * |- element DIV DIV [P2 P3] DIV
286
+ * | |- element H H [P1] f o o b a r H P4
287
+ * | | |- "se]cond" fir[st] lorem [se]cond ipsum
288
+ * | |- element P4
289
+ * | | |- "ipsum"
290
+ * ```
306
291
  *
307
292
  * As it can be seen, letters contained in the range are: `stloremfoobarse`, spread across different parents.
308
293
  * We are looking for minimal set of flat ranges that contains the same nodes.
309
294
  *
310
295
  * Minimal flat ranges for above range `( [ 0, 0, 3 ], [ 3, 0, 2 ] )` will be:
311
296
  *
312
- * ( [ 0, 0, 3 ], [ 0, 0, 5 ] ) = "st"
313
- * ( [ 0, 1 ], [ 0, 2 ] ) = element P1 ("lorem")
314
- * ( [ 1 ], [ 3 ] ) = element P2, element P3 ("foobar")
315
- * ( [ 3, 0, 0 ], [ 3, 0, 2 ] ) = "se"
297
+ * ```
298
+ * ( [ 0, 0, 3 ], [ 0, 0, 5 ] ) = "st"
299
+ * ( [ 0, 1 ], [ 0, 2 ] ) = element P1 ("lorem")
300
+ * ( [ 1 ], [ 3 ] ) = element P2, element P3 ("foobar")
301
+ * ( [ 3, 0, 0 ], [ 3, 0, 2 ] ) = "se"
302
+ * ```
316
303
  *
317
304
  * **Note:** if an {@link module:engine/model/element~Element element} is not wholly contained in this range, it won't be returned
318
305
  * in any of the returned flat ranges. See in the example how `H` elements at the beginning and at the end of the range
@@ -320,7 +307,7 @@ export default class Range extends TypeCheckable {
320
307
  *
321
308
  * **Note:** this method is not returning flat ranges that contain no nodes.
322
309
  *
323
- * @returns {Array.<module:engine/model/range~Range>} Array of flat ranges covering this range.
310
+ * @returns Array of flat ranges covering this range.
324
311
  */
325
312
  getMinimalFlatRanges() {
326
313
  const ranges = [];
@@ -354,20 +341,17 @@ export default class Range extends TypeCheckable {
354
341
  *
355
342
  * For example, to iterate over all items in the entire document root:
356
343
  *
357
- * // Create a range spanning over the entire root content:
358
- * const range = editor.model.createRangeIn( editor.model.document.getRoot() );
344
+ * ```ts
345
+ * // Create a range spanning over the entire root content:
346
+ * const range = editor.model.createRangeIn( editor.model.document.getRoot() );
359
347
  *
360
- * // Iterate over all items in this range:
361
- * for ( const value of range.getWalker() ) {
362
- * console.log( value.item );
363
- * }
348
+ * // Iterate over all items in this range:
349
+ * for ( const value of range.getWalker() ) {
350
+ * console.log( value.item );
351
+ * }
352
+ * ```
364
353
  *
365
- * @param {Object} options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
366
- * @param {module:engine/model/position~Position} [options.startPosition]
367
- * @param {Boolean} [options.singleCharacters=false]
368
- * @param {Boolean} [options.shallow=false]
369
- * @param {Boolean} [options.ignoreElementEnd=false]
370
- * @returns {module:engine/model/treewalker~TreeWalker}
354
+ * @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
371
355
  */
372
356
  getWalker(options = {}) {
373
357
  options.boundaries = this;
@@ -384,8 +368,7 @@ export default class Range extends TypeCheckable {
384
368
  * You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~TreeWalker} for
385
369
  * a full list of available options.
386
370
  *
387
- * @param {Object} [options] Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
388
- * @returns {Iterable.<module:engine/model/item~Item>}
371
+ * @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
389
372
  */
390
373
  *getItems(options = {}) {
391
374
  options.boundaries = this;
@@ -405,8 +388,7 @@ export default class Range extends TypeCheckable {
405
388
  * You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~TreeWalker} for
406
389
  * a full list of available options.
407
390
  *
408
- * @param {Object} options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
409
- * @returns {Iterable.<module:engine/model/position~Position>}
391
+ * @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
410
392
  */
411
393
  *getPositions(options = {}) {
412
394
  options.boundaries = this;
@@ -423,8 +405,8 @@ export default class Range extends TypeCheckable {
423
405
  * moved to a different part of document tree). For this reason, an array is returned by this method and it
424
406
  * may contain one or more `Range` instances.
425
407
  *
426
- * @param {module:engine/model/operation/operation~Operation} operation Operation to transform range by.
427
- * @returns {Array.<module:engine/model/range~Range>} Range which is the result of transformation.
408
+ * @param operation Operation to transform range by.
409
+ * @returns Range which is the result of transformation.
428
410
  */
429
411
  getTransformedByOperation(operation) {
430
412
  switch (operation.type) {
@@ -445,8 +427,8 @@ export default class Range extends TypeCheckable {
445
427
  * Returns a range that is a result of transforming this range by multiple `operations`.
446
428
  *
447
429
  * @see ~Range#getTransformedByOperation
448
- * @param {Iterable.<module:engine/model/operation/operation~Operation>} operations Operations to transform the range by.
449
- * @returns {Array.<module:engine/model/range~Range>} Range which is the result of transformation.
430
+ * @param operations Operations to transform the range by.
431
+ * @returns Range which is the result of transformation.
450
432
  */
451
433
  getTransformedByOperations(operations) {
452
434
  const ranges = [new Range(this.start, this.end)];
@@ -475,8 +457,6 @@ export default class Range extends TypeCheckable {
475
457
  /**
476
458
  * Returns an {@link module:engine/model/element~Element} or {@link module:engine/model/documentfragment~DocumentFragment}
477
459
  * which is a common ancestor of the range's both ends (in which the entire range is contained).
478
- *
479
- * @returns {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
480
460
  */
481
461
  getCommonAncestor() {
482
462
  return this.start.getCommonAncestor(this.end);
@@ -485,8 +465,6 @@ export default class Range extends TypeCheckable {
485
465
  * Returns an {@link module:engine/model/element~Element Element} contained by the range.
486
466
  * The element will be returned when it is the **only** node within the range and **fully–contained**
487
467
  * at the same time.
488
- *
489
- * @returns {module:engine/model/element~Element|null}
490
468
  */
491
469
  getContainedElement() {
492
470
  if (this.isCollapsed) {
@@ -502,7 +480,7 @@ export default class Range extends TypeCheckable {
502
480
  /**
503
481
  * Converts `Range` to plain object and returns it.
504
482
  *
505
- * @returns {Object} `Node` converted to plain object.
483
+ * @returns `Node` converted to plain object.
506
484
  */
507
485
  toJSON() {
508
486
  return {
@@ -512,8 +490,6 @@ export default class Range extends TypeCheckable {
512
490
  }
513
491
  /**
514
492
  * Returns a new range that is equal to current range.
515
- *
516
- * @returns {module:engine/model/range~Range}
517
493
  */
518
494
  clone() {
519
495
  return new this.constructor(this.start, this.end);
@@ -524,9 +500,6 @@ export default class Range extends TypeCheckable {
524
500
  * One or more ranges may be returned as a result of this transformation.
525
501
  *
526
502
  * @internal
527
- * @protected
528
- * @param {module:engine/model/operation/insertoperation~InsertOperation} operation
529
- * @returns {Array.<module:engine/model/range~Range>}
530
503
  */
531
504
  _getTransformedByInsertOperation(operation, spread = false) {
532
505
  return this._getTransformedByInsertion(operation.position, operation.howMany, spread);
@@ -537,9 +510,6 @@ export default class Range extends TypeCheckable {
537
510
  * One or more ranges may be returned as a result of this transformation.
538
511
  *
539
512
  * @internal
540
- * @protected
541
- * @param {module:engine/model/operation/moveoperation~MoveOperation} operation
542
- * @returns {Array.<module:engine/model/range~Range>}
543
513
  */
544
514
  _getTransformedByMoveOperation(operation, spread = false) {
545
515
  const sourcePosition = operation.sourcePosition;
@@ -553,9 +523,6 @@ export default class Range extends TypeCheckable {
553
523
  * Always one range is returned. The transformation is done in a way to not break the range.
554
524
  *
555
525
  * @internal
556
- * @protected
557
- * @param {module:engine/model/operation/splitoperation~SplitOperation} operation
558
- * @returns {module:engine/model/range~Range}
559
526
  */
560
527
  _getTransformedBySplitOperation(operation) {
561
528
  const start = this.start._getTransformedBySplitOperation(operation);
@@ -577,9 +544,6 @@ export default class Range extends TypeCheckable {
577
544
  * Always one range is returned. The transformation is done in a way to not break the range.
578
545
  *
579
546
  * @internal
580
- * @protected
581
- * @param {module:engine/model/operation/mergeoperation~MergeOperation} operation
582
- * @returns {module:engine/model/range~Range}
583
547
  */
584
548
  _getTransformedByMergeOperation(operation) {
585
549
  // Special case when the marker is set on "the closing tag" of an element. Marker can be set like that during
@@ -654,29 +618,30 @@ export default class Range extends TypeCheckable {
654
618
  *
655
619
  * Examples:
656
620
  *
657
- * let range = model.createRange(
658
- * model.createPositionFromPath( root, [ 2, 7 ] ),
659
- * model.createPositionFromPath( root, [ 4, 0, 1 ] )
660
- * );
661
- * let transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 1 ] ), 2 );
662
- * // transformed array has one range from [ 4, 7 ] to [ 6, 0, 1 ]
621
+ * ```ts
622
+ * let range = model.createRange(
623
+ * model.createPositionFromPath( root, [ 2, 7 ] ),
624
+ * model.createPositionFromPath( root, [ 4, 0, 1 ] )
625
+ * );
626
+ * let transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 1 ] ), 2 );
627
+ * // transformed array has one range from [ 4, 7 ] to [ 6, 0, 1 ]
663
628
  *
664
- * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 4, 0, 0 ] ), 4 );
665
- * // transformed array has one range from [ 2, 7 ] to [ 4, 0, 5 ]
629
+ * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 4, 0, 0 ] ), 4 );
630
+ * // transformed array has one range from [ 2, 7 ] to [ 4, 0, 5 ]
666
631
  *
667
- * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4 );
668
- * // transformed array has one range, which is equal to original range
632
+ * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4 );
633
+ * // transformed array has one range, which is equal to original range
669
634
  *
670
- * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4, true );
671
- * // transformed array has two ranges: from [ 2, 7 ] to [ 3, 2 ] and from [ 3, 6 ] to [ 4, 0, 1 ]
635
+ * transformed = range._getTransformedByInsertion( model.createPositionFromPath( root, [ 3, 2 ] ), 4, true );
636
+ * // transformed array has two ranges: from [ 2, 7 ] to [ 3, 2 ] and from [ 3, 6 ] to [ 4, 0, 1 ]
637
+ * ```
672
638
  *
673
639
  * @internal
674
- * @protected
675
- * @param {module:engine/model/position~Position} insertPosition Position where nodes are inserted.
676
- * @param {Number} howMany How many nodes are inserted.
677
- * @param {Boolean} [spread] Flag indicating whether this {~Range range} should be spread if insertion
640
+ * @param insertPosition Position where nodes are inserted.
641
+ * @param howMany How many nodes are inserted.
642
+ * @param spread Flag indicating whether this {~Range range} should be spread if insertion
678
643
  * was inside the range. Defaults to `false`.
679
- * @returns {Array.<module:engine/model/range~Range>} Result of the transformation.
644
+ * @returns Result of the transformation.
680
645
  */
681
646
  _getTransformedByInsertion(insertPosition, howMany, spread = false) {
682
647
  if (spread && this.containsPosition(insertPosition)) {
@@ -700,12 +665,11 @@ export default class Range extends TypeCheckable {
700
665
  * {@link ~Range range} by moving `howMany` nodes from `sourcePosition` to `targetPosition`.
701
666
  *
702
667
  * @internal
703
- * @protected
704
- * @param {module:engine/model/position~Position} sourcePosition Position from which nodes are moved.
705
- * @param {module:engine/model/position~Position} targetPosition Position to where nodes are moved.
706
- * @param {Number} howMany How many nodes are moved.
707
- * @param {Boolean} [spread=false] Whether the range should be spread if the move points inside the range.
708
- * @returns {Array.<module:engine/model/range~Range>} Result of the transformation.
668
+ * @param sourcePosition Position from which nodes are moved.
669
+ * @param targetPosition Position to where nodes are moved.
670
+ * @param howMany How many nodes are moved.
671
+ * @param spread Whether the range should be spread if the move points inside the range.
672
+ * @returns Result of the transformation.
709
673
  */
710
674
  _getTransformedByMove(sourcePosition, targetPosition, howMany, spread = false) {
711
675
  // Special case for transforming a collapsed range. Just transform it like a position.
@@ -772,10 +736,9 @@ export default class Range extends TypeCheckable {
772
736
  * If the deleted range contains transformed range, `null` will be returned.
773
737
  *
774
738
  * @internal
775
- * @protected
776
- * @param {module:engine/model/position~Position} deletionPosition Position from which nodes are removed.
777
- * @param {Number} howMany How many nodes are removed.
778
- * @returns {module:engine/model/range~Range|null} Result of the transformation.
739
+ * @param deletionPosition Position from which nodes are removed.
740
+ * @param howMany How many nodes are removed.
741
+ * @returns Result of the transformation.
779
742
  */
780
743
  _getTransformedByDeletion(deletePosition, howMany) {
781
744
  let newStart = this.start._getTransformedByDeletion(deletePosition, howMany);
@@ -796,10 +759,8 @@ export default class Range extends TypeCheckable {
796
759
  * given `shift`. If `shift` is a negative value, shifted position is treated as the beginning of the range.
797
760
  *
798
761
  * @internal
799
- * @protected
800
- * @param {module:engine/model/position~Position} position Beginning of the range.
801
- * @param {Number} shift How long the range should be.
802
- * @returns {module:engine/model/range~Range}
762
+ * @param position Beginning of the range.
763
+ * @param shift How long the range should be.
803
764
  */
804
765
  static _createFromPositionAndShift(position, shift) {
805
766
  const start = position;
@@ -811,9 +772,7 @@ export default class Range extends TypeCheckable {
811
772
  * that element and ends after the last child of that element.
812
773
  *
813
774
  * @internal
814
- * @protected
815
- * @param {module:engine/model/element~Element} element Element which is a parent for the range.
816
- * @returns {module:engine/model/range~Range}
775
+ * @param element Element which is a parent for the range.
817
776
  */
818
777
  static _createIn(element) {
819
778
  return new this(Position._createAt(element, 0), Position._createAt(element, element.maxOffset));
@@ -822,9 +781,6 @@ export default class Range extends TypeCheckable {
822
781
  * Creates a range that starts before given {@link module:engine/model/item~Item model item} and ends after it.
823
782
  *
824
783
  * @internal
825
- * @protected
826
- * @param {module:engine/model/item~Item} item
827
- * @returns {module:engine/model/range~Range}
828
784
  */
829
785
  static _createOn(item) {
830
786
  return this._createFromPositionAndShift(Position._createBefore(item), item.offsetSize);
@@ -836,15 +792,16 @@ export default class Range extends TypeCheckable {
836
792
  * The first range from the array is a reference range. If other ranges start or end on the exactly same position where
837
793
  * the reference range, they get combined into one range.
838
794
  *
839
- * [ ][] [ ][ ][ ][ ][] [ ] // Passed ranges, shown sorted
840
- * [ ] // The result of the function if the first range was a reference range.
841
- * [ ] // The result of the function if the third-to-seventh range was a reference range.
842
- * [ ] // The result of the function if the last range was a reference range.
795
+ * ```
796
+ * [ ][] [ ][ ][ ][ ][] [ ] // Passed ranges, shown sorted
797
+ * [ ] // The result of the function if the first range was a reference range.
798
+ * [ ] // The result of the function if the third-to-seventh range was a reference range.
799
+ * [ ] // The result of the function if the last range was a reference range.
800
+ * ```
843
801
  *
844
802
  * @internal
845
- * @protected
846
- * @param {Array.<module:engine/model/range~Range>} ranges Ranges to combine.
847
- * @returns {module:engine/model/range~Range} Combined range.
803
+ * @param ranges Ranges to combine.
804
+ * @returns Combined range.
848
805
  */
849
806
  static _createFromRanges(ranges) {
850
807
  if (ranges.length === 0) {
@@ -903,28 +860,16 @@ export default class Range extends TypeCheckable {
903
860
  /**
904
861
  * Creates a `Range` instance from given plain object (i.e. parsed JSON string).
905
862
  *
906
- * @param {Object} json Plain object to be converted to `Range`.
907
- * @param {module:engine/model/document~Document} doc Document object that will be range owner.
908
- * @returns {module:engine/model/range~Range} `Range` instance created using given plain object.
863
+ * @param json Plain object to be converted to `Range`.
864
+ * @param doc Document object that will be range owner.
865
+ * @returns `Range` instance created using given plain object.
909
866
  */
910
867
  static fromJSON(json, doc) {
911
868
  return new this(Position.fromJSON(json.start, doc), Position.fromJSON(json.end, doc));
912
869
  }
913
870
  }
914
- /**
915
- * Checks whether this object is of the given.
916
- *
917
- * range.is( 'range' ); // -> true
918
- * range.is( 'model:range' ); // -> true
919
- *
920
- * range.is( 'view:range' ); // -> false
921
- * range.is( 'documentSelection' ); // -> false
922
- *
923
- * {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
924
- *
925
- * @param {String} type
926
- * @returns {Boolean}
927
- */
871
+ // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
872
+ // Proper overload would interfere with that.
928
873
  Range.prototype.is = function (type) {
929
874
  return type === 'range' || type === 'model:range';
930
875
  };