@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +25 -24
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +72 -116
  5. package/src/controller/editingcontroller.d.ts +98 -0
  6. package/src/controller/editingcontroller.js +22 -46
  7. package/src/conversion/conversion.d.ts +476 -0
  8. package/src/conversion/conversion.js +328 -347
  9. package/src/conversion/conversionhelpers.d.ts +26 -0
  10. package/src/conversion/conversionhelpers.js +1 -5
  11. package/src/conversion/downcastdispatcher.d.ts +547 -0
  12. package/src/conversion/downcastdispatcher.js +74 -152
  13. package/src/conversion/downcasthelpers.d.ts +1226 -0
  14. package/src/conversion/downcasthelpers.js +843 -762
  15. package/src/conversion/mapper.d.ts +503 -0
  16. package/src/conversion/mapper.js +84 -99
  17. package/src/conversion/modelconsumable.d.ts +201 -0
  18. package/src/conversion/modelconsumable.js +96 -99
  19. package/src/conversion/upcastdispatcher.d.ts +492 -0
  20. package/src/conversion/upcastdispatcher.js +73 -100
  21. package/src/conversion/upcasthelpers.d.ts +499 -0
  22. package/src/conversion/upcasthelpers.js +406 -373
  23. package/src/conversion/viewconsumable.d.ts +369 -0
  24. package/src/conversion/viewconsumable.js +139 -173
  25. package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
  26. package/src/dataprocessor/basichtmlwriter.js +0 -9
  27. package/src/dataprocessor/dataprocessor.d.ts +61 -0
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
  29. package/src/dataprocessor/htmldataprocessor.js +6 -28
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -0
  31. package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
  32. package/src/dataprocessor/xmldataprocessor.js +8 -40
  33. package/src/dev-utils/model.d.ts +124 -0
  34. package/src/dev-utils/model.js +41 -38
  35. package/src/dev-utils/operationreplayer.d.ts +51 -0
  36. package/src/dev-utils/operationreplayer.js +6 -14
  37. package/src/dev-utils/utils.d.ts +37 -0
  38. package/src/dev-utils/utils.js +5 -18
  39. package/src/dev-utils/view.d.ts +319 -0
  40. package/src/dev-utils/view.js +205 -226
  41. package/src/index.d.ts +108 -0
  42. package/src/index.js +4 -0
  43. package/src/model/batch.d.ts +106 -0
  44. package/src/model/differ.d.ts +329 -0
  45. package/src/model/document.d.ts +246 -0
  46. package/src/model/document.js +1 -1
  47. package/src/model/documentfragment.d.ts +196 -0
  48. package/src/model/documentfragment.js +2 -2
  49. package/src/model/documentselection.d.ts +420 -0
  50. package/src/model/element.d.ts +165 -0
  51. package/src/model/history.d.ts +114 -0
  52. package/src/model/item.d.ts +14 -0
  53. package/src/model/liveposition.d.ts +77 -0
  54. package/src/model/liverange.d.ts +102 -0
  55. package/src/model/markercollection.d.ts +335 -0
  56. package/src/model/model.d.ts +885 -0
  57. package/src/model/model.js +59 -81
  58. package/src/model/node.d.ts +256 -0
  59. package/src/model/nodelist.d.ts +91 -0
  60. package/src/model/operation/attributeoperation.d.ts +98 -0
  61. package/src/model/operation/detachoperation.d.ts +55 -0
  62. package/src/model/operation/insertoperation.d.ts +85 -0
  63. package/src/model/operation/markeroperation.d.ts +86 -0
  64. package/src/model/operation/mergeoperation.d.ts +95 -0
  65. package/src/model/operation/mergeoperation.js +1 -1
  66. package/src/model/operation/moveoperation.d.ts +91 -0
  67. package/src/model/operation/nooperation.d.ts +33 -0
  68. package/src/model/operation/operation.d.ts +89 -0
  69. package/src/model/operation/operationfactory.d.ts +18 -0
  70. package/src/model/operation/renameoperation.d.ts +78 -0
  71. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  72. package/src/model/operation/rootattributeoperation.js +1 -1
  73. package/src/model/operation/splitoperation.d.ts +104 -0
  74. package/src/model/operation/splitoperation.js +1 -1
  75. package/src/model/operation/transform.d.ts +100 -0
  76. package/src/model/operation/utils.d.ts +71 -0
  77. package/src/model/operation/utils.js +1 -1
  78. package/src/model/position.d.ts +539 -0
  79. package/src/model/position.js +1 -1
  80. package/src/model/range.d.ts +458 -0
  81. package/src/model/range.js +1 -1
  82. package/src/model/rootelement.d.ts +40 -0
  83. package/src/model/schema.d.ts +1176 -0
  84. package/src/model/schema.js +19 -19
  85. package/src/model/selection.d.ts +472 -0
  86. package/src/model/text.d.ts +66 -0
  87. package/src/model/text.js +0 -2
  88. package/src/model/textproxy.d.ts +144 -0
  89. package/src/model/treewalker.d.ts +186 -0
  90. package/src/model/treewalker.js +19 -10
  91. package/src/model/typecheckable.d.ts +285 -0
  92. package/src/model/utils/autoparagraphing.d.ts +37 -0
  93. package/src/model/utils/deletecontent.d.ts +58 -0
  94. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  95. package/src/model/utils/getselectedcontent.d.ts +30 -0
  96. package/src/model/utils/insertcontent.d.ts +46 -0
  97. package/src/model/utils/insertcontent.js +2 -12
  98. package/src/model/utils/insertobject.d.ts +44 -0
  99. package/src/model/utils/insertobject.js +3 -14
  100. package/src/model/utils/modifyselection.d.ts +48 -0
  101. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  102. package/src/model/writer.d.ts +823 -0
  103. package/src/model/writer.js +6 -61
  104. package/src/view/attributeelement.d.ts +108 -0
  105. package/src/view/attributeelement.js +25 -69
  106. package/src/view/containerelement.d.ts +49 -0
  107. package/src/view/containerelement.js +10 -43
  108. package/src/view/datatransfer.d.ts +75 -0
  109. package/src/view/document.d.ts +184 -0
  110. package/src/view/document.js +15 -84
  111. package/src/view/documentfragment.d.ts +149 -0
  112. package/src/view/documentfragment.js +39 -81
  113. package/src/view/documentselection.d.ts +306 -0
  114. package/src/view/documentselection.js +42 -143
  115. package/src/view/domconverter.d.ts +650 -0
  116. package/src/view/domconverter.js +157 -283
  117. package/src/view/downcastwriter.d.ts +996 -0
  118. package/src/view/downcastwriter.js +259 -426
  119. package/src/view/editableelement.d.ts +52 -0
  120. package/src/view/editableelement.js +9 -49
  121. package/src/view/element.d.ts +468 -0
  122. package/src/view/element.js +150 -222
  123. package/src/view/elementdefinition.d.ts +87 -0
  124. package/src/view/emptyelement.d.ts +41 -0
  125. package/src/view/emptyelement.js +11 -44
  126. package/src/view/filler.d.ts +111 -0
  127. package/src/view/filler.js +24 -21
  128. package/src/view/item.d.ts +14 -0
  129. package/src/view/matcher.d.ts +486 -0
  130. package/src/view/matcher.js +247 -218
  131. package/src/view/node.d.ts +163 -0
  132. package/src/view/node.js +26 -100
  133. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  134. package/src/view/observer/arrowkeysobserver.js +0 -13
  135. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  136. package/src/view/observer/bubblingemittermixin.js +36 -25
  137. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  138. package/src/view/observer/bubblingeventinfo.js +3 -29
  139. package/src/view/observer/clickobserver.d.ts +43 -0
  140. package/src/view/observer/clickobserver.js +9 -19
  141. package/src/view/observer/compositionobserver.d.ts +82 -0
  142. package/src/view/observer/compositionobserver.js +13 -42
  143. package/src/view/observer/domeventdata.d.ts +50 -0
  144. package/src/view/observer/domeventdata.js +5 -30
  145. package/src/view/observer/domeventobserver.d.ts +69 -0
  146. package/src/view/observer/domeventobserver.js +19 -21
  147. package/src/view/observer/fakeselectionobserver.d.ts +43 -0
  148. package/src/view/observer/fakeselectionobserver.js +0 -16
  149. package/src/view/observer/focusobserver.d.ts +82 -0
  150. package/src/view/observer/focusobserver.js +14 -40
  151. package/src/view/observer/inputobserver.d.ts +86 -0
  152. package/src/view/observer/inputobserver.js +18 -64
  153. package/src/view/observer/keyobserver.d.ts +66 -0
  154. package/src/view/observer/keyobserver.js +8 -42
  155. package/src/view/observer/mouseobserver.d.ts +89 -0
  156. package/src/view/observer/mouseobserver.js +8 -28
  157. package/src/view/observer/mutationobserver.d.ts +82 -0
  158. package/src/view/observer/mutationobserver.js +7 -37
  159. package/src/view/observer/observer.d.ts +84 -0
  160. package/src/view/observer/observer.js +12 -25
  161. package/src/view/observer/selectionobserver.d.ts +144 -0
  162. package/src/view/observer/selectionobserver.js +17 -107
  163. package/src/view/observer/tabobserver.d.ts +42 -0
  164. package/src/view/observer/tabobserver.js +0 -14
  165. package/src/view/placeholder.d.ts +85 -0
  166. package/src/view/placeholder.js +26 -43
  167. package/src/view/position.d.ts +189 -0
  168. package/src/view/position.js +36 -83
  169. package/src/view/range.d.ts +279 -0
  170. package/src/view/range.js +79 -122
  171. package/src/view/rawelement.d.ts +73 -0
  172. package/src/view/rawelement.js +34 -48
  173. package/src/view/renderer.d.ts +265 -0
  174. package/src/view/renderer.js +105 -193
  175. package/src/view/rooteditableelement.d.ts +41 -0
  176. package/src/view/rooteditableelement.js +12 -40
  177. package/src/view/selection.d.ts +375 -0
  178. package/src/view/selection.js +79 -153
  179. package/src/view/styles/background.d.ts +33 -0
  180. package/src/view/styles/background.js +14 -12
  181. package/src/view/styles/border.d.ts +43 -0
  182. package/src/view/styles/border.js +58 -48
  183. package/src/view/styles/margin.d.ts +29 -0
  184. package/src/view/styles/margin.js +13 -11
  185. package/src/view/styles/padding.d.ts +29 -0
  186. package/src/view/styles/padding.js +13 -11
  187. package/src/view/styles/utils.d.ts +93 -0
  188. package/src/view/styles/utils.js +22 -48
  189. package/src/view/stylesmap.d.ts +675 -0
  190. package/src/view/stylesmap.js +249 -244
  191. package/src/view/text.d.ts +74 -0
  192. package/src/view/text.js +16 -46
  193. package/src/view/textproxy.d.ts +97 -0
  194. package/src/view/textproxy.js +10 -59
  195. package/src/view/treewalker.d.ts +195 -0
  196. package/src/view/treewalker.js +43 -106
  197. package/src/view/typecheckable.d.ts +448 -0
  198. package/src/view/uielement.d.ts +96 -0
  199. package/src/view/uielement.js +29 -63
  200. package/src/view/upcastwriter.d.ts +417 -0
  201. package/src/view/upcastwriter.js +86 -157
  202. package/src/view/view.d.ts +417 -0
  203. package/src/view/view.js +47 -175
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module engine/view/position
7
+ */
8
+ import TypeCheckable from './typecheckable';
9
+ import EditableElement from './editableelement';
10
+ import '@ckeditor/ckeditor5-utils/src/version';
11
+ import type DocumentFragment from './documentfragment';
12
+ import type Item from './item';
13
+ import type Node from './node';
14
+ import { default as TreeWalker, type TreeWalkerValue, type TreeWalkerOptions } from './treewalker';
15
+ /**
16
+ * Position in the view tree. Position is represented by its parent node and an offset in this parent.
17
+ *
18
+ * In order to create a new position instance use the `createPosition*()` factory methods available in:
19
+ *
20
+ * * {@link module:engine/view/view~View}
21
+ * * {@link module:engine/view/downcastwriter~DowncastWriter}
22
+ * * {@link module:engine/view/upcastwriter~UpcastWriter}
23
+ */
24
+ export default class Position extends TypeCheckable {
25
+ /**
26
+ * Position parent.
27
+ */
28
+ readonly parent: Node | DocumentFragment;
29
+ /**
30
+ * Position offset.
31
+ */
32
+ offset: number;
33
+ /**
34
+ * Creates a position.
35
+ *
36
+ * @param parent Position parent.
37
+ * @param offset Position offset.
38
+ */
39
+ constructor(parent: Node | DocumentFragment, offset: number);
40
+ /**
41
+ * Node directly after the position. Equals `null` when there is no node after position or position is located
42
+ * inside text node.
43
+ */
44
+ get nodeAfter(): Node | null;
45
+ /**
46
+ * Node directly before the position. Equals `null` when there is no node before position or position is located
47
+ * inside text node.
48
+ */
49
+ get nodeBefore(): Node | null;
50
+ /**
51
+ * Is `true` if position is at the beginning of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
52
+ */
53
+ get isAtStart(): boolean;
54
+ /**
55
+ * Is `true` if position is at the end of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
56
+ */
57
+ get isAtEnd(): boolean;
58
+ /**
59
+ * Position's root, that is the root of the position's parent element.
60
+ */
61
+ get root(): Node | DocumentFragment;
62
+ /**
63
+ * {@link module:engine/view/editableelement~EditableElement EditableElement} instance that contains this position, or `null` if
64
+ * position is not inside an editable element.
65
+ */
66
+ get editableElement(): EditableElement | null;
67
+ /**
68
+ * Returns a new instance of Position with offset incremented by `shift` value.
69
+ *
70
+ * @param shift How position offset should get changed. Accepts negative values.
71
+ * @returns Shifted position.
72
+ */
73
+ getShiftedBy(shift: number): Position;
74
+ /**
75
+ * Gets the farthest position which matches the callback using
76
+ * {@link module:engine/view/treewalker~TreeWalker TreeWalker}.
77
+ *
78
+ * For example:
79
+ *
80
+ * ```ts
81
+ * getLastMatchingPosition( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p>
82
+ * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } ); // <p>foo[]</p> -> <p>{}foo</p>
83
+ * getLastMatchingPosition( value => false ); // Do not move the position.
84
+ * ```
85
+ *
86
+ * @param skip Callback function. Gets {@link module:engine/view/treewalker~TreeWalkerValue} and should
87
+ * return `true` if the value should be skipped or `false` if not.
88
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
89
+ * @returns The position after the last item which matches the `skip` callback test.
90
+ */
91
+ getLastMatchingPosition(skip: (value: TreeWalkerValue) => boolean, options?: TreeWalkerOptions): Position;
92
+ /**
93
+ * Returns ancestors array of this position, that is this position's parent and it's ancestors.
94
+ *
95
+ * @returns Array with ancestors.
96
+ */
97
+ getAncestors(): Array<Node | DocumentFragment>;
98
+ /**
99
+ * Returns a {@link module:engine/view/node~Node} or {@link module:engine/view/documentfragment~DocumentFragment}
100
+ * which is a common ancestor of both positions.
101
+ */
102
+ getCommonAncestor(position: Position): Node | DocumentFragment | null;
103
+ /**
104
+ * Checks whether this position equals given position.
105
+ *
106
+ * @param otherPosition Position to compare with.
107
+ * @returns True if positions are same.
108
+ */
109
+ isEqual(otherPosition: Position): boolean;
110
+ /**
111
+ * Checks whether this position is located before given position. When method returns `false` it does not mean that
112
+ * this position is after give one. Two positions may be located inside separate roots and in that situation this
113
+ * method will still return `false`.
114
+ *
115
+ * @see module:engine/view/position~Position#isAfter
116
+ * @see module:engine/view/position~Position#compareWith
117
+ * @param otherPosition Position to compare with.
118
+ * @returns Returns `true` if this position is before given position.
119
+ */
120
+ isBefore(otherPosition: Position): boolean;
121
+ /**
122
+ * Checks whether this position is located after given position. When method returns `false` it does not mean that
123
+ * this position is before give one. Two positions may be located inside separate roots and in that situation this
124
+ * method will still return `false`.
125
+ *
126
+ * @see module:engine/view/position~Position#isBefore
127
+ * @see module:engine/view/position~Position#compareWith
128
+ * @param otherPosition Position to compare with.
129
+ * @returns Returns `true` if this position is after given position.
130
+ */
131
+ isAfter(otherPosition: Position): boolean;
132
+ /**
133
+ * Checks whether this position is before, after or in same position that other position. Two positions may be also
134
+ * different when they are located in separate roots.
135
+ *
136
+ * @param otherPosition Position to compare with.
137
+ */
138
+ compareWith(otherPosition: Position): PositionRelation;
139
+ /**
140
+ * Creates a {@link module:engine/view/treewalker~TreeWalker TreeWalker} instance with this positions as a start position.
141
+ *
142
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}
143
+ */
144
+ getWalker(options?: TreeWalkerOptions): TreeWalker;
145
+ /**
146
+ * Clones this position.
147
+ */
148
+ clone(): Position;
149
+ /**
150
+ * Creates position at the given location. The location can be specified as:
151
+ *
152
+ * * a {@link module:engine/view/position~Position position},
153
+ * * parent element and offset (offset defaults to `0`),
154
+ * * parent element and `'end'` (sets position at the end of that element),
155
+ * * {@link module:engine/view/item~Item view item} and `'before'` or `'after'` (sets position before or after given view item).
156
+ *
157
+ * This method is a shortcut to other constructors such as:
158
+ *
159
+ * * {@link module:engine/view/position~Position._createBefore},
160
+ * * {@link module:engine/view/position~Position._createAfter}.
161
+ *
162
+ * @internal
163
+ * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~Item view item}.
164
+ */
165
+ static _createAt(itemOrPosition: Item | Position, offset?: PositionOffset): Position;
166
+ /**
167
+ * Creates a new position after given view item.
168
+ *
169
+ * @internal
170
+ * @param item View item after which the position should be located.
171
+ */
172
+ static _createAfter(item: Item): Position;
173
+ /**
174
+ * Creates a new position before given view item.
175
+ *
176
+ * @internal
177
+ * @param item View item before which the position should be located.
178
+ */
179
+ static _createBefore(item: Item): Position;
180
+ }
181
+ /**
182
+ * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
183
+ * If positions are in different roots `'different'` flag is returned.
184
+ */
185
+ export type PositionRelation = 'before' | 'after' | 'same' | 'different';
186
+ /**
187
+ * Offset or one of the flags.
188
+ */
189
+ export type PositionOffset = number | 'before' | 'after' | 'end';
@@ -24,33 +24,17 @@ export default class Position extends TypeCheckable {
24
24
  /**
25
25
  * Creates a position.
26
26
  *
27
- * @param {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment} parent Position parent.
28
- * @param {Number} offset Position offset.
27
+ * @param parent Position parent.
28
+ * @param offset Position offset.
29
29
  */
30
30
  constructor(parent, offset) {
31
31
  super();
32
- /**
33
- * Position parent.
34
- *
35
- * @readonly
36
- * @member {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
37
- * module:engine/view/position~Position#parent
38
- */
39
32
  this.parent = parent;
40
- /**
41
- * Position offset.
42
- *
43
- * @readonly
44
- * @member {Number} module:engine/view/position~Position#offset
45
- */
46
33
  this.offset = offset;
47
34
  }
48
35
  /**
49
36
  * Node directly after the position. Equals `null` when there is no node after position or position is located
50
37
  * inside text node.
51
- *
52
- * @readonly
53
- * @type {module:engine/view/node~Node|null}
54
38
  */
55
39
  get nodeAfter() {
56
40
  if (this.parent.is('$text')) {
@@ -61,9 +45,6 @@ export default class Position extends TypeCheckable {
61
45
  /**
62
46
  * Node directly before the position. Equals `null` when there is no node before position or position is located
63
47
  * inside text node.
64
- *
65
- * @readonly
66
- * @type {module:engine/view/node~Node|null}
67
48
  */
68
49
  get nodeBefore() {
69
50
  if (this.parent.is('$text')) {
@@ -73,18 +54,12 @@ export default class Position extends TypeCheckable {
73
54
  }
74
55
  /**
75
56
  * Is `true` if position is at the beginning of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
76
- *
77
- * @readonly
78
- * @type {Boolean}
79
57
  */
80
58
  get isAtStart() {
81
59
  return this.offset === 0;
82
60
  }
83
61
  /**
84
62
  * Is `true` if position is at the end of its {@link module:engine/view/position~Position#parent parent}, `false` otherwise.
85
- *
86
- * @readonly
87
- * @type {Boolean}
88
63
  */
89
64
  get isAtEnd() {
90
65
  const endOffset = this.parent.is('$text') ? this.parent.data.length : this.parent.childCount;
@@ -92,9 +67,6 @@ export default class Position extends TypeCheckable {
92
67
  }
93
68
  /**
94
69
  * Position's root, that is the root of the position's parent element.
95
- *
96
- * @readonly
97
- * @type {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
98
70
  */
99
71
  get root() {
100
72
  return this.parent.root;
@@ -102,8 +74,6 @@ export default class Position extends TypeCheckable {
102
74
  /**
103
75
  * {@link module:engine/view/editableelement~EditableElement EditableElement} instance that contains this position, or `null` if
104
76
  * position is not inside an editable element.
105
- *
106
- * @type {module:engine/view/editableelement~EditableElement|null}
107
77
  */
108
78
  get editableElement() {
109
79
  let editable = this.parent;
@@ -120,8 +90,8 @@ export default class Position extends TypeCheckable {
120
90
  /**
121
91
  * Returns a new instance of Position with offset incremented by `shift` value.
122
92
  *
123
- * @param {Number} shift How position offset should get changed. Accepts negative values.
124
- * @returns {module:engine/view/position~Position} Shifted position.
93
+ * @param shift How position offset should get changed. Accepts negative values.
94
+ * @returns Shifted position.
125
95
  */
126
96
  getShiftedBy(shift) {
127
97
  const shifted = Position._createAt(this);
@@ -135,15 +105,16 @@ export default class Position extends TypeCheckable {
135
105
  *
136
106
  * For example:
137
107
  *
138
- * getLastMatchingPosition( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p>
139
- * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } ); // <p>foo[]</p> -> <p>{}foo</p>
140
- * getLastMatchingPosition( value => false ); // Do not move the position.
108
+ * ```ts
109
+ * getLastMatchingPosition( value => value.type == 'text' ); // <p>{}foo</p> -> <p>foo[]</p>
110
+ * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } ); // <p>foo[]</p> -> <p>{}foo</p>
111
+ * getLastMatchingPosition( value => false ); // Do not move the position.
112
+ * ```
141
113
  *
142
- * @param {Function} skip Callback function. Gets {@link module:engine/view/treewalker~type TreeWalkerValue} and should
114
+ * @param skip Callback function. Gets {@link module:engine/view/treewalker~TreeWalkerValue} and should
143
115
  * return `true` if the value should be skipped or `false` if not.
144
- * @param {Object} options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
145
- *
146
- * @returns {module:engine/view/position~Position} The position after the last item which matches the `skip` callback test.
116
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}.
117
+ * @returns The position after the last item which matches the `skip` callback test.
147
118
  */
148
119
  getLastMatchingPosition(skip, options = {}) {
149
120
  options.startPosition = this;
@@ -154,7 +125,7 @@ export default class Position extends TypeCheckable {
154
125
  /**
155
126
  * Returns ancestors array of this position, that is this position's parent and it's ancestors.
156
127
  *
157
- * @returns {Array} Array with ancestors.
128
+ * @returns Array with ancestors.
158
129
  */
159
130
  getAncestors() {
160
131
  if (this.parent.is('documentFragment')) {
@@ -167,9 +138,6 @@ export default class Position extends TypeCheckable {
167
138
  /**
168
139
  * Returns a {@link module:engine/view/node~Node} or {@link module:engine/view/documentfragment~DocumentFragment}
169
140
  * which is a common ancestor of both positions.
170
- *
171
- * @param {module:engine/view/position~Position} position
172
- * @returns {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment|null}
173
141
  */
174
142
  getCommonAncestor(position) {
175
143
  const ancestorsA = this.getAncestors();
@@ -183,8 +151,8 @@ export default class Position extends TypeCheckable {
183
151
  /**
184
152
  * Checks whether this position equals given position.
185
153
  *
186
- * @param {module:engine/view/position~Position} otherPosition Position to compare with.
187
- * @returns {Boolean} True if positions are same.
154
+ * @param otherPosition Position to compare with.
155
+ * @returns True if positions are same.
188
156
  */
189
157
  isEqual(otherPosition) {
190
158
  return (this.parent == otherPosition.parent && this.offset == otherPosition.offset);
@@ -196,8 +164,8 @@ export default class Position extends TypeCheckable {
196
164
  *
197
165
  * @see module:engine/view/position~Position#isAfter
198
166
  * @see module:engine/view/position~Position#compareWith
199
- * @param {module:engine/view/position~Position} otherPosition Position to compare with.
200
- * @returns {Boolean} Returns `true` if this position is before given position.
167
+ * @param otherPosition Position to compare with.
168
+ * @returns Returns `true` if this position is before given position.
201
169
  */
202
170
  isBefore(otherPosition) {
203
171
  return this.compareWith(otherPosition) == 'before';
@@ -209,8 +177,8 @@ export default class Position extends TypeCheckable {
209
177
  *
210
178
  * @see module:engine/view/position~Position#isBefore
211
179
  * @see module:engine/view/position~Position#compareWith
212
- * @param {module:engine/view/position~Position} otherPosition Position to compare with.
213
- * @returns {Boolean} Returns `true` if this position is after given position.
180
+ * @param otherPosition Position to compare with.
181
+ * @returns Returns `true` if this position is after given position.
214
182
  */
215
183
  isAfter(otherPosition) {
216
184
  return this.compareWith(otherPosition) == 'after';
@@ -219,8 +187,7 @@ export default class Position extends TypeCheckable {
219
187
  * Checks whether this position is before, after or in same position that other position. Two positions may be also
220
188
  * different when they are located in separate roots.
221
189
  *
222
- * @param {module:engine/view/position~Position} otherPosition Position to compare with.
223
- * @returns {module:engine/view/position~PositionRelation}
190
+ * @param otherPosition Position to compare with.
224
191
  */
225
192
  compareWith(otherPosition) {
226
193
  if (this.root !== otherPosition.root) {
@@ -242,6 +209,10 @@ export default class Position extends TypeCheckable {
242
209
  return 'before';
243
210
  case 'extension':
244
211
  return 'after';
212
+ /* istanbul ignore next */
213
+ case 'same':
214
+ // Already covered by `this.isEqual` above. Added so TypeScript can infer `result` as number in `default` case.
215
+ return 'same';
245
216
  default:
246
217
  return thisPath[result] < otherPath[result] ? 'before' : 'after';
247
218
  }
@@ -249,16 +220,15 @@ export default class Position extends TypeCheckable {
249
220
  /**
250
221
  * Creates a {@link module:engine/view/treewalker~TreeWalker TreeWalker} instance with this positions as a start position.
251
222
  *
252
- * @param {Object} options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}
253
- * @param {module:engine/view/range~Range} [options.boundaries=null] Range to define boundaries of the iterator.
254
- * @param {Boolean} [options.singleCharacters=false]
255
- * @param {Boolean} [options.shallow=false]
256
- * @param {Boolean} [options.ignoreElementEnd=false]
223
+ * @param options Object with configuration options. See {@link module:engine/view/treewalker~TreeWalker}
257
224
  */
258
225
  getWalker(options = {}) {
259
226
  options.startPosition = this;
260
227
  return new TreeWalker(options);
261
228
  }
229
+ /**
230
+ * Clones this position.
231
+ */
262
232
  clone() {
263
233
  return new Position(this.parent, this.offset);
264
234
  }
@@ -275,10 +245,8 @@ export default class Position extends TypeCheckable {
275
245
  * * {@link module:engine/view/position~Position._createBefore},
276
246
  * * {@link module:engine/view/position~Position._createAfter}.
277
247
  *
278
- * @protected
279
- * @param {module:engine/view/item~Item|module:engine/view/position~Position} itemOrPosition
280
- * @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
281
- * first parameter is a {@link module:engine/view/item~Item view item}.
248
+ * @internal
249
+ * @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~Item view item}.
282
250
  */
283
251
  static _createAt(itemOrPosition, offset) {
284
252
  if (itemOrPosition instanceof Position) {
@@ -310,9 +278,8 @@ export default class Position extends TypeCheckable {
310
278
  /**
311
279
  * Creates a new position after given view item.
312
280
  *
313
- * @protected
314
- * @param {module:engine/view/item~Item} item View item after which the position should be located.
315
- * @returns {module:engine/view/position~Position}
281
+ * @internal
282
+ * @param item View item after which the position should be located.
316
283
  */
317
284
  static _createAfter(item) {
318
285
  // TextProxy is not a instance of Node so we need do handle it in specific way.
@@ -333,9 +300,8 @@ export default class Position extends TypeCheckable {
333
300
  /**
334
301
  * Creates a new position before given view item.
335
302
  *
336
- * @protected
337
- * @param {module:engine/view/item~Item} item View item before which the position should be located.
338
- * @returns {module:engine/view/position~Position}
303
+ * @internal
304
+ * @param item View item before which the position should be located.
339
305
  */
340
306
  static _createBefore(item) {
341
307
  // TextProxy is not a instance of Node so we need do handle it in specific way.
@@ -354,21 +320,8 @@ export default class Position extends TypeCheckable {
354
320
  return new Position(item.parent, item.index);
355
321
  }
356
322
  }
357
- /**
358
- * Checks whether this object is of the given type.
359
- *
360
- * position.is( 'position' ); // -> true
361
- * position.is( 'view:position' ); // -> true
362
- *
363
- * position.is( 'model:position' ); // -> false
364
- * position.is( 'element' ); // -> false
365
- * position.is( 'range' ); // -> false
366
- *
367
- * {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
368
- *
369
- * @param {String} type
370
- * @returns {Boolean}
371
- */
323
+ // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
324
+ // Proper overload would interfere with that.
372
325
  Position.prototype.is = function (type) {
373
326
  return type === 'position' || type === 'view:position';
374
327
  };