@ckeditor/ckeditor5-engine 39.0.2 → 40.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/package.json +2 -2
  2. package/src/controller/datacontroller.d.ts +334 -334
  3. package/src/controller/datacontroller.js +481 -481
  4. package/src/controller/editingcontroller.d.ts +98 -98
  5. package/src/controller/editingcontroller.js +191 -191
  6. package/src/conversion/conversion.d.ts +478 -478
  7. package/src/conversion/conversion.js +601 -601
  8. package/src/conversion/conversionhelpers.d.ts +26 -26
  9. package/src/conversion/conversionhelpers.js +32 -32
  10. package/src/conversion/downcastdispatcher.d.ts +562 -562
  11. package/src/conversion/downcastdispatcher.js +547 -547
  12. package/src/conversion/downcasthelpers.d.ts +1226 -1226
  13. package/src/conversion/downcasthelpers.js +2183 -2183
  14. package/src/conversion/mapper.d.ts +503 -503
  15. package/src/conversion/mapper.js +536 -536
  16. package/src/conversion/modelconsumable.d.ts +201 -201
  17. package/src/conversion/modelconsumable.js +333 -333
  18. package/src/conversion/upcastdispatcher.d.ts +492 -492
  19. package/src/conversion/upcastdispatcher.js +460 -460
  20. package/src/conversion/upcasthelpers.d.ts +499 -499
  21. package/src/conversion/upcasthelpers.js +950 -950
  22. package/src/conversion/viewconsumable.d.ts +369 -369
  23. package/src/conversion/viewconsumable.js +532 -532
  24. package/src/dataprocessor/basichtmlwriter.d.ts +18 -18
  25. package/src/dataprocessor/basichtmlwriter.js +19 -19
  26. package/src/dataprocessor/dataprocessor.d.ts +61 -61
  27. package/src/dataprocessor/dataprocessor.js +5 -5
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -76
  29. package/src/dataprocessor/htmldataprocessor.js +96 -96
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -16
  31. package/src/dataprocessor/htmlwriter.js +5 -5
  32. package/src/dataprocessor/xmldataprocessor.d.ts +90 -90
  33. package/src/dataprocessor/xmldataprocessor.js +108 -108
  34. package/src/dev-utils/model.d.ts +124 -124
  35. package/src/dev-utils/model.js +395 -395
  36. package/src/dev-utils/operationreplayer.d.ts +51 -51
  37. package/src/dev-utils/operationreplayer.js +112 -112
  38. package/src/dev-utils/utils.d.ts +37 -37
  39. package/src/dev-utils/utils.js +73 -73
  40. package/src/dev-utils/view.d.ts +319 -319
  41. package/src/dev-utils/view.js +967 -967
  42. package/src/index.d.ts +114 -114
  43. package/src/index.js +78 -78
  44. package/src/model/batch.d.ts +106 -106
  45. package/src/model/batch.js +96 -96
  46. package/src/model/differ.d.ts +387 -387
  47. package/src/model/differ.js +1149 -1149
  48. package/src/model/document.d.ts +272 -272
  49. package/src/model/document.js +361 -361
  50. package/src/model/documentfragment.d.ts +200 -200
  51. package/src/model/documentfragment.js +306 -306
  52. package/src/model/documentselection.d.ts +420 -420
  53. package/src/model/documentselection.js +993 -993
  54. package/src/model/element.d.ts +165 -165
  55. package/src/model/element.js +281 -281
  56. package/src/model/history.d.ts +114 -114
  57. package/src/model/history.js +207 -207
  58. package/src/model/item.d.ts +14 -14
  59. package/src/model/item.js +5 -5
  60. package/src/model/liveposition.d.ts +77 -77
  61. package/src/model/liveposition.js +93 -93
  62. package/src/model/liverange.d.ts +102 -102
  63. package/src/model/liverange.js +120 -120
  64. package/src/model/markercollection.d.ts +335 -335
  65. package/src/model/markercollection.js +403 -403
  66. package/src/model/model.d.ts +919 -919
  67. package/src/model/model.js +842 -842
  68. package/src/model/node.d.ts +256 -256
  69. package/src/model/node.js +375 -375
  70. package/src/model/nodelist.d.ts +91 -91
  71. package/src/model/nodelist.js +163 -163
  72. package/src/model/operation/attributeoperation.d.ts +103 -103
  73. package/src/model/operation/attributeoperation.js +148 -148
  74. package/src/model/operation/detachoperation.d.ts +60 -60
  75. package/src/model/operation/detachoperation.js +77 -77
  76. package/src/model/operation/insertoperation.d.ts +90 -90
  77. package/src/model/operation/insertoperation.js +135 -135
  78. package/src/model/operation/markeroperation.d.ts +91 -91
  79. package/src/model/operation/markeroperation.js +107 -107
  80. package/src/model/operation/mergeoperation.d.ts +100 -100
  81. package/src/model/operation/mergeoperation.js +167 -167
  82. package/src/model/operation/moveoperation.d.ts +96 -96
  83. package/src/model/operation/moveoperation.js +164 -164
  84. package/src/model/operation/nooperation.d.ts +38 -38
  85. package/src/model/operation/nooperation.js +48 -48
  86. package/src/model/operation/operation.d.ts +96 -96
  87. package/src/model/operation/operation.js +62 -62
  88. package/src/model/operation/operationfactory.d.ts +18 -18
  89. package/src/model/operation/operationfactory.js +44 -44
  90. package/src/model/operation/renameoperation.d.ts +83 -83
  91. package/src/model/operation/renameoperation.js +115 -115
  92. package/src/model/operation/rootattributeoperation.d.ts +98 -98
  93. package/src/model/operation/rootattributeoperation.js +155 -155
  94. package/src/model/operation/rootoperation.d.ts +76 -76
  95. package/src/model/operation/rootoperation.js +90 -90
  96. package/src/model/operation/splitoperation.d.ts +109 -109
  97. package/src/model/operation/splitoperation.js +194 -194
  98. package/src/model/operation/transform.d.ts +100 -100
  99. package/src/model/operation/transform.js +1985 -1985
  100. package/src/model/operation/utils.d.ts +71 -71
  101. package/src/model/operation/utils.js +213 -213
  102. package/src/model/position.d.ts +539 -539
  103. package/src/model/position.js +979 -979
  104. package/src/model/range.d.ts +458 -458
  105. package/src/model/range.js +875 -875
  106. package/src/model/rootelement.d.ts +60 -60
  107. package/src/model/rootelement.js +74 -74
  108. package/src/model/schema.d.ts +1186 -1186
  109. package/src/model/schema.js +1242 -1242
  110. package/src/model/selection.d.ts +482 -482
  111. package/src/model/selection.js +789 -789
  112. package/src/model/text.d.ts +66 -66
  113. package/src/model/text.js +85 -85
  114. package/src/model/textproxy.d.ts +144 -144
  115. package/src/model/textproxy.js +189 -189
  116. package/src/model/treewalker.d.ts +186 -186
  117. package/src/model/treewalker.js +244 -244
  118. package/src/model/typecheckable.d.ts +285 -285
  119. package/src/model/typecheckable.js +16 -16
  120. package/src/model/utils/autoparagraphing.d.ts +37 -37
  121. package/src/model/utils/autoparagraphing.js +63 -63
  122. package/src/model/utils/deletecontent.d.ts +58 -58
  123. package/src/model/utils/deletecontent.js +488 -488
  124. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -32
  125. package/src/model/utils/findoptimalinsertionrange.js +57 -57
  126. package/src/model/utils/getselectedcontent.d.ts +30 -30
  127. package/src/model/utils/getselectedcontent.js +125 -125
  128. package/src/model/utils/insertcontent.d.ts +46 -46
  129. package/src/model/utils/insertcontent.js +705 -705
  130. package/src/model/utils/insertobject.d.ts +44 -44
  131. package/src/model/utils/insertobject.js +139 -139
  132. package/src/model/utils/modifyselection.d.ts +48 -48
  133. package/src/model/utils/modifyselection.js +186 -186
  134. package/src/model/utils/selection-post-fixer.d.ts +74 -74
  135. package/src/model/utils/selection-post-fixer.js +260 -260
  136. package/src/model/writer.d.ts +851 -851
  137. package/src/model/writer.js +1306 -1306
  138. package/src/view/attributeelement.d.ts +108 -108
  139. package/src/view/attributeelement.js +184 -184
  140. package/src/view/containerelement.d.ts +49 -49
  141. package/src/view/containerelement.js +80 -80
  142. package/src/view/datatransfer.d.ts +79 -79
  143. package/src/view/datatransfer.js +98 -98
  144. package/src/view/document.d.ts +184 -184
  145. package/src/view/document.js +120 -120
  146. package/src/view/documentfragment.d.ts +149 -149
  147. package/src/view/documentfragment.js +228 -228
  148. package/src/view/documentselection.d.ts +306 -306
  149. package/src/view/documentselection.js +256 -256
  150. package/src/view/domconverter.d.ts +640 -640
  151. package/src/view/domconverter.js +1450 -1425
  152. package/src/view/downcastwriter.d.ts +996 -996
  153. package/src/view/downcastwriter.js +1696 -1696
  154. package/src/view/editableelement.d.ts +62 -62
  155. package/src/view/editableelement.js +62 -62
  156. package/src/view/element.d.ts +468 -468
  157. package/src/view/element.js +724 -724
  158. package/src/view/elementdefinition.d.ts +87 -87
  159. package/src/view/elementdefinition.js +5 -5
  160. package/src/view/emptyelement.d.ts +41 -41
  161. package/src/view/emptyelement.js +73 -73
  162. package/src/view/filler.d.ts +111 -111
  163. package/src/view/filler.js +150 -150
  164. package/src/view/item.d.ts +14 -14
  165. package/src/view/item.js +5 -5
  166. package/src/view/matcher.d.ts +486 -486
  167. package/src/view/matcher.js +507 -507
  168. package/src/view/node.d.ts +163 -163
  169. package/src/view/node.js +228 -228
  170. package/src/view/observer/arrowkeysobserver.d.ts +45 -45
  171. package/src/view/observer/arrowkeysobserver.js +40 -40
  172. package/src/view/observer/bubblingemittermixin.d.ts +166 -166
  173. package/src/view/observer/bubblingemittermixin.js +172 -172
  174. package/src/view/observer/bubblingeventinfo.d.ts +47 -47
  175. package/src/view/observer/bubblingeventinfo.js +37 -37
  176. package/src/view/observer/clickobserver.d.ts +43 -43
  177. package/src/view/observer/clickobserver.js +29 -29
  178. package/src/view/observer/compositionobserver.d.ts +82 -82
  179. package/src/view/observer/compositionobserver.js +60 -60
  180. package/src/view/observer/domeventdata.d.ts +50 -50
  181. package/src/view/observer/domeventdata.js +47 -47
  182. package/src/view/observer/domeventobserver.d.ts +73 -73
  183. package/src/view/observer/domeventobserver.js +79 -79
  184. package/src/view/observer/fakeselectionobserver.d.ts +47 -47
  185. package/src/view/observer/fakeselectionobserver.js +91 -91
  186. package/src/view/observer/focusobserver.d.ts +82 -82
  187. package/src/view/observer/focusobserver.js +86 -86
  188. package/src/view/observer/inputobserver.d.ts +86 -86
  189. package/src/view/observer/inputobserver.js +164 -164
  190. package/src/view/observer/keyobserver.d.ts +66 -66
  191. package/src/view/observer/keyobserver.js +39 -39
  192. package/src/view/observer/mouseobserver.d.ts +89 -89
  193. package/src/view/observer/mouseobserver.js +29 -29
  194. package/src/view/observer/mutationobserver.d.ts +86 -86
  195. package/src/view/observer/mutationobserver.js +206 -206
  196. package/src/view/observer/observer.d.ts +89 -89
  197. package/src/view/observer/observer.js +84 -84
  198. package/src/view/observer/selectionobserver.d.ts +148 -148
  199. package/src/view/observer/selectionobserver.js +202 -202
  200. package/src/view/observer/tabobserver.d.ts +46 -46
  201. package/src/view/observer/tabobserver.js +42 -42
  202. package/src/view/placeholder.d.ts +96 -96
  203. package/src/view/placeholder.js +267 -267
  204. package/src/view/position.d.ts +189 -189
  205. package/src/view/position.js +324 -324
  206. package/src/view/range.d.ts +279 -279
  207. package/src/view/range.js +430 -430
  208. package/src/view/rawelement.d.ts +73 -73
  209. package/src/view/rawelement.js +105 -105
  210. package/src/view/renderer.d.ts +265 -265
  211. package/src/view/renderer.js +999 -999
  212. package/src/view/rooteditableelement.d.ts +41 -41
  213. package/src/view/rooteditableelement.js +69 -69
  214. package/src/view/selection.d.ts +375 -375
  215. package/src/view/selection.js +559 -559
  216. package/src/view/styles/background.d.ts +33 -33
  217. package/src/view/styles/background.js +74 -74
  218. package/src/view/styles/border.d.ts +43 -43
  219. package/src/view/styles/border.js +316 -316
  220. package/src/view/styles/margin.d.ts +29 -29
  221. package/src/view/styles/margin.js +34 -34
  222. package/src/view/styles/padding.d.ts +29 -29
  223. package/src/view/styles/padding.js +34 -34
  224. package/src/view/styles/utils.d.ts +93 -93
  225. package/src/view/styles/utils.js +219 -219
  226. package/src/view/stylesmap.d.ts +675 -675
  227. package/src/view/stylesmap.js +766 -766
  228. package/src/view/text.d.ts +74 -74
  229. package/src/view/text.js +93 -93
  230. package/src/view/textproxy.d.ts +97 -97
  231. package/src/view/textproxy.js +124 -124
  232. package/src/view/treewalker.d.ts +195 -195
  233. package/src/view/treewalker.js +327 -327
  234. package/src/view/typecheckable.d.ts +448 -448
  235. package/src/view/typecheckable.js +19 -19
  236. package/src/view/uielement.d.ts +96 -96
  237. package/src/view/uielement.js +182 -182
  238. package/src/view/upcastwriter.d.ts +417 -417
  239. package/src/view/upcastwriter.js +359 -359
  240. package/src/view/view.d.ts +487 -487
  241. package/src/view/view.js +546 -546
@@ -1,539 +1,539 @@
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/model/position
7
- */
8
- import TypeCheckable from './typecheckable';
9
- import { type TreeWalkerOptions, type TreeWalkerValue } from './treewalker';
10
- import type Document from './document';
11
- import type DocumentFragment from './documentfragment';
12
- import type Element from './element';
13
- import type InsertOperation from './operation/insertoperation';
14
- import type Item from './item';
15
- import type MergeOperation from './operation/mergeoperation';
16
- import type MoveOperation from './operation/moveoperation';
17
- import type Node from './node';
18
- import type Operation from './operation/operation';
19
- import type SplitOperation from './operation/splitoperation';
20
- import type Text from './text';
21
- import '@ckeditor/ckeditor5-utils/src/version';
22
- /**
23
- * Represents a position in the model tree.
24
- *
25
- * A position is represented by its {@link module:engine/model/position~Position#root} and
26
- * a {@link module:engine/model/position~Position#path} in that root.
27
- *
28
- * You can create position instances via its constructor or the `createPosition*()` factory methods of
29
- * {@link module:engine/model/model~Model} and {@link module:engine/model/writer~Writer}.
30
- *
31
- * **Note:** Position is based on offsets, not indexes. This means that a position between two text nodes
32
- * `foo` and `bar` has offset `3`, not `1`. See {@link module:engine/model/position~Position#path} for more information.
33
- *
34
- * Since a position in the model is represented by a {@link module:engine/model/position~Position#root position root} and
35
- * {@link module:engine/model/position~Position#path position path} it is possible to create positions placed in non-existing places.
36
- * This requirement is important for operational transformation algorithms.
37
- *
38
- * Also, {@link module:engine/model/operation/operation~Operation operations}
39
- * kept in the {@link module:engine/model/document~Document#history document history}
40
- * are storing positions (and ranges) which were correct when those operations were applied, but may not be correct
41
- * after the document has changed.
42
- *
43
- * When changes are applied to the model, it may also happen that {@link module:engine/model/position~Position#parent position parent}
44
- * will change even if position path has not changed. Keep in mind, that if a position leads to non-existing element,
45
- * {@link module:engine/model/position~Position#parent} and some other properties and methods will throw errors.
46
- *
47
- * In most cases, position with wrong path is caused by an error in code, but it is sometimes needed, as described above.
48
- */
49
- export default class Position extends TypeCheckable {
50
- /**
51
- * Root of the position path.
52
- */
53
- readonly root: Element | DocumentFragment;
54
- /**
55
- * Position of the node in the tree. **Path contains offsets, not indexes.**
56
- *
57
- * Position can be placed before, after or in a {@link module:engine/model/node~Node node} if that node has
58
- * {@link module:engine/model/node~Node#offsetSize} greater than `1`. Items in position path are
59
- * {@link module:engine/model/node~Node#startOffset starting offsets} of position ancestors, starting from direct root children,
60
- * down to the position offset in it's parent.
61
- *
62
- * ```
63
- * ROOT
64
- * |- P before: [ 0 ] after: [ 1 ]
65
- * |- UL before: [ 1 ] after: [ 2 ]
66
- * |- LI before: [ 1, 0 ] after: [ 1, 1 ]
67
- * | |- foo before: [ 1, 0, 0 ] after: [ 1, 0, 3 ]
68
- * |- LI before: [ 1, 1 ] after: [ 1, 2 ]
69
- * |- bar before: [ 1, 1, 0 ] after: [ 1, 1, 3 ]
70
- * ```
71
- *
72
- * `foo` and `bar` are representing {@link module:engine/model/text~Text text nodes}. Since text nodes has offset size
73
- * greater than `1` you can place position offset between their start and end:
74
- *
75
- * ```
76
- * ROOT
77
- * |- P
78
- * |- UL
79
- * |- LI
80
- * | |- f^o|o ^ has path: [ 1, 0, 1 ] | has path: [ 1, 0, 2 ]
81
- * |- LI
82
- * |- b^a|r ^ has path: [ 1, 1, 1 ] | has path: [ 1, 1, 2 ]
83
- * ```
84
- */
85
- readonly path: ReadonlyArray<number>;
86
- /**
87
- * Position stickiness. See {@link module:engine/model/position~PositionStickiness}.
88
- */
89
- stickiness: PositionStickiness;
90
- /**
91
- * Creates a position.
92
- *
93
- * @param root Root of the position.
94
- * @param path Position path. See {@link module:engine/model/position~Position#path}.
95
- * @param stickiness Position stickiness. See {@link module:engine/model/position~PositionStickiness}.
96
- */
97
- constructor(root: Element | DocumentFragment, path: ReadonlyArray<number>, stickiness?: PositionStickiness);
98
- /**
99
- * Offset at which this position is located in its {@link module:engine/model/position~Position#parent parent}. It is equal
100
- * to the last item in position {@link module:engine/model/position~Position#path path}.
101
- *
102
- * @type {Number}
103
- */
104
- get offset(): number;
105
- set offset(newOffset: number);
106
- /**
107
- * Parent element of this position.
108
- *
109
- * Keep in mind that `parent` value is calculated when the property is accessed.
110
- * If {@link module:engine/model/position~Position#path position path}
111
- * leads to a non-existing element, `parent` property will throw error.
112
- *
113
- * Also it is a good idea to cache `parent` property if it is used frequently in an algorithm (i.e. in a long loop).
114
- */
115
- get parent(): Element | DocumentFragment;
116
- /**
117
- * Position {@link module:engine/model/position~Position#offset offset} converted to an index in position's parent node. It is
118
- * equal to the {@link module:engine/model/node~Node#index index} of a node after this position. If position is placed
119
- * in text node, position index is equal to the index of that text node.
120
- */
121
- get index(): number;
122
- /**
123
- * Returns {@link module:engine/model/text~Text text node} instance in which this position is placed or `null` if this
124
- * position is not in a text node.
125
- */
126
- get textNode(): Text | null;
127
- /**
128
- * Node directly after this position or `null` if this position is in text node.
129
- */
130
- get nodeAfter(): Node | null;
131
- /**
132
- * Node directly before this position or `null` if this position is in text node.
133
- */
134
- get nodeBefore(): Node | null;
135
- /**
136
- * Is `true` if position is at the beginning of its {@link module:engine/model/position~Position#parent parent}, `false` otherwise.
137
- */
138
- get isAtStart(): boolean;
139
- /**
140
- * Is `true` if position is at the end of its {@link module:engine/model/position~Position#parent parent}, `false` otherwise.
141
- */
142
- get isAtEnd(): boolean;
143
- /**
144
- * Checks whether this position is before or after given position.
145
- *
146
- * This method is safe to use it on non-existing positions (for example during operational transformation).
147
- */
148
- compareWith(otherPosition: Position): PositionRelation;
149
- /**
150
- * Gets the farthest position which matches the callback using
151
- * {@link module:engine/model/treewalker~TreeWalker TreeWalker}.
152
- *
153
- * For example:
154
- *
155
- * ```ts
156
- * getLastMatchingPosition( value => value.type == 'text' );
157
- * // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
158
- *
159
- * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } );
160
- * // <paragraph>foo[]</paragraph> -> <paragraph>[]foo</paragraph>
161
- *
162
- * getLastMatchingPosition( value => false );
163
- * // Do not move the position.
164
- * ```
165
- *
166
- * @param skip Callback function. Gets {@link module:engine/model/treewalker~TreeWalkerValue} and should
167
- * return `true` if the value should be skipped or `false` if not.
168
- * @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
169
- *
170
- * @returns The position after the last item which matches the `skip` callback test.
171
- */
172
- getLastMatchingPosition(skip: (value: TreeWalkerValue) => boolean, options?: TreeWalkerOptions): Position;
173
- /**
174
- * Returns a path to this position's parent. Parent path is equal to position {@link module:engine/model/position~Position#path path}
175
- * but without the last item.
176
- *
177
- * This method is safe to use it on non-existing positions (for example during operational transformation).
178
- *
179
- * @returns Path to the parent.
180
- */
181
- getParentPath(): Array<number>;
182
- /**
183
- * Returns ancestors array of this position, that is this position's parent and its ancestors.
184
- *
185
- * @returns Array with ancestors.
186
- */
187
- getAncestors(): Array<Element | DocumentFragment>;
188
- /**
189
- * Returns the parent element of the given name. Returns null if the position is not inside the desired parent.
190
- *
191
- * @param parentName The name of the parent element to find.
192
- */
193
- findAncestor(parentName: string): Element | null;
194
- /**
195
- * Returns the slice of two position {@link #path paths} which is identical. The {@link #root roots}
196
- * of these two paths must be identical.
197
- *
198
- * This method is safe to use it on non-existing positions (for example during operational transformation).
199
- *
200
- * @param position The second position.
201
- * @returns The common path.
202
- */
203
- getCommonPath(position: Position): Array<number>;
204
- /**
205
- * Returns an {@link module:engine/model/element~Element} or {@link module:engine/model/documentfragment~DocumentFragment}
206
- * which is a common ancestor of both positions. The {@link #root roots} of these two positions must be identical.
207
- *
208
- * @param position The second position.
209
- */
210
- getCommonAncestor(position: Position): Element | DocumentFragment | null;
211
- /**
212
- * Returns a new instance of `Position`, that has same {@link #parent parent} but it's offset
213
- * is shifted by `shift` value (can be a negative value).
214
- *
215
- * This method is safe to use it on non-existing positions (for example during operational transformation).
216
- *
217
- * @param shift Offset shift. Can be a negative value.
218
- * @returns Shifted position.
219
- */
220
- getShiftedBy(shift: number): Position;
221
- /**
222
- * Checks whether this position is after given position.
223
- *
224
- * This method is safe to use it on non-existing positions (for example during operational transformation).
225
- *
226
- * @see module:engine/model/position~Position#isBefore
227
- * @param otherPosition Position to compare with.
228
- * @returns True if this position is after given position.
229
- */
230
- isAfter(otherPosition: Position): boolean;
231
- /**
232
- * Checks whether this position is before given position.
233
- *
234
- * **Note:** watch out when using negation of the value returned by this method, because the negation will also
235
- * be `true` if positions are in different roots and you might not expect this. You should probably use
236
- * `a.isAfter( b ) || a.isEqual( b )` or `!a.isBefore( p ) && a.root == b.root` in most scenarios. If your
237
- * condition uses multiple `isAfter` and `isBefore` checks, build them so they do not use negated values, i.e.:
238
- *
239
- * ```ts
240
- * if ( a.isBefore( b ) && c.isAfter( d ) ) {
241
- * // do A.
242
- * } else {
243
- * // do B.
244
- * }
245
- * ```
246
- *
247
- * or, if you have only one if-branch:
248
- *
249
- * ```ts
250
- * if ( !( a.isBefore( b ) && c.isAfter( d ) ) {
251
- * // do B.
252
- * }
253
- * ```
254
- *
255
- * rather than:
256
- *
257
- * ```ts
258
- * if ( !a.isBefore( b ) || && !c.isAfter( d ) ) {
259
- * // do B.
260
- * } else {
261
- * // do A.
262
- * }
263
- * ```
264
- *
265
- * This method is safe to use it on non-existing positions (for example during operational transformation).
266
- *
267
- * @param otherPosition Position to compare with.
268
- * @returns True if this position is before given position.
269
- */
270
- isBefore(otherPosition: Position): boolean;
271
- /**
272
- * Checks whether this position is equal to given position.
273
- *
274
- * This method is safe to use it on non-existing positions (for example during operational transformation).
275
- *
276
- * @param otherPosition Position to compare with.
277
- * @returns True if positions are same.
278
- */
279
- isEqual(otherPosition: Position): boolean;
280
- /**
281
- * Checks whether this position is touching given position. Positions touch when there are no text nodes
282
- * or empty nodes in a range between them. Technically, those positions are not equal but in many cases
283
- * they are very similar or even indistinguishable.
284
- *
285
- * @param otherPosition Position to compare with.
286
- * @returns True if positions touch.
287
- */
288
- isTouching(otherPosition: Position): boolean;
289
- /**
290
- * Checks if two positions are in the same parent.
291
- *
292
- * This method is safe to use it on non-existing positions (for example during operational transformation).
293
- *
294
- * @param position Position to compare with.
295
- * @returns `true` if positions have the same parent, `false` otherwise.
296
- */
297
- hasSameParentAs(position: Position): boolean;
298
- /**
299
- * Returns a copy of this position that is transformed by given `operation`.
300
- *
301
- * The new position's parameters are updated accordingly to the effect of the `operation`.
302
- *
303
- * For example, if `n` nodes are inserted before the position, the returned position {@link ~Position#offset} will be
304
- * increased by `n`. If the position was in a merged element, it will be accordingly moved to the new element, etc.
305
- *
306
- * This method is safe to use it on non-existing positions (for example during operational transformation).
307
- *
308
- * @param operation Operation to transform by.
309
- * @returns Transformed position.
310
- */
311
- getTransformedByOperation(operation: Operation): Position;
312
- /**
313
- * Returns a copy of this position transformed by an insert operation.
314
- *
315
- * @internal
316
- */
317
- _getTransformedByInsertOperation(operation: InsertOperation): Position;
318
- /**
319
- * Returns a copy of this position transformed by a move operation.
320
- *
321
- * @internal
322
- */
323
- _getTransformedByMoveOperation(operation: MoveOperation): Position;
324
- /**
325
- * Returns a copy of this position transformed by a split operation.
326
- *
327
- * @internal
328
- */
329
- _getTransformedBySplitOperation(operation: SplitOperation): Position;
330
- /**
331
- * Returns a copy of this position transformed by merge operation.
332
- *
333
- * @internal
334
- */
335
- _getTransformedByMergeOperation(operation: MergeOperation): Position;
336
- /**
337
- * Returns a copy of this position that is updated by removing `howMany` nodes starting from `deletePosition`.
338
- * It may happen that this position is in a removed node. If that is the case, `null` is returned instead.
339
- *
340
- * @internal
341
- * @param deletePosition Position before the first removed node.
342
- * @param howMany How many nodes are removed.
343
- * @returns Transformed position or `null`.
344
- */
345
- _getTransformedByDeletion(deletePosition: Position, howMany: number): Position | null;
346
- /**
347
- * Returns a copy of this position that is updated by inserting `howMany` nodes at `insertPosition`.
348
- *
349
- * @internal
350
- * @param insertPosition Position where nodes are inserted.
351
- * @param howMany How many nodes are inserted.
352
- * @returns Transformed position.
353
- */
354
- _getTransformedByInsertion(insertPosition: Position, howMany: number): Position;
355
- /**
356
- * Returns a copy of this position that is updated by moving `howMany` nodes from `sourcePosition` to `targetPosition`.
357
- *
358
- * @internal
359
- * @param sourcePosition Position before the first element to move.
360
- * @param targetPosition Position where moved elements will be inserted.
361
- * @param howMany How many consecutive nodes to move, starting from `sourcePosition`.
362
- * @returns Transformed position.
363
- */
364
- _getTransformedByMove(sourcePosition: Position, targetPosition: Position, howMany: number): Position;
365
- /**
366
- * Returns a new position that is a combination of this position and given positions.
367
- *
368
- * The combined position is a copy of this position transformed by moving a range starting at `source` position
369
- * to the `target` position. It is expected that this position is inside the moved range.
370
- *
371
- * Example:
372
- *
373
- * ```ts
374
- * let original = model.createPositionFromPath( root, [ 2, 3, 1 ] );
375
- * let source = model.createPositionFromPath( root, [ 2, 2 ] );
376
- * let target = model.createPositionFromPath( otherRoot, [ 1, 1, 3 ] );
377
- * original._getCombined( source, target ); // path is [ 1, 1, 4, 1 ], root is `otherRoot`
378
- * ```
379
- *
380
- * Explanation:
381
- *
382
- * We have a position `[ 2, 3, 1 ]` and move some nodes from `[ 2, 2 ]` to `[ 1, 1, 3 ]`. The original position
383
- * was inside moved nodes and now should point to the new place. The moved nodes will be after
384
- * positions `[ 1, 1, 3 ]`, `[ 1, 1, 4 ]`, `[ 1, 1, 5 ]`. Since our position was in the second moved node,
385
- * the transformed position will be in a sub-tree of a node at `[ 1, 1, 4 ]`. Looking at original path, we
386
- * took care of `[ 2, 3 ]` part of it. Now we have to add the rest of the original path to the transformed path.
387
- * Finally, the transformed position will point to `[ 1, 1, 4, 1 ]`.
388
- *
389
- * @internal
390
- * @param source Beginning of the moved range.
391
- * @param target Position where the range is moved.
392
- * @returns Combined position.
393
- */
394
- _getCombined(source: Position, target: Position): Position;
395
- /**
396
- * @inheritDoc
397
- */
398
- toJSON(): unknown;
399
- /**
400
- * Returns a new position that is equal to current position.
401
- */
402
- clone(): this;
403
- /**
404
- * Creates position at the given location. The location can be specified as:
405
- *
406
- * * a {@link module:engine/model/position~Position position},
407
- * * parent element and offset (offset defaults to `0`),
408
- * * parent element and `'end'` (sets position at the end of that element),
409
- * * {@link module:engine/model/item~Item model item} and `'before'` or `'after'` (sets position before or after given model item).
410
- *
411
- * This method is a shortcut to other factory methods such as:
412
- *
413
- * * {@link module:engine/model/position~Position._createBefore},
414
- * * {@link module:engine/model/position~Position._createAfter}.
415
- *
416
- * @internal
417
- * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/model/item~Item model item}.
418
- * @param stickiness Position stickiness. Used only when the first parameter is a {@link module:engine/model/item~Item model item}.
419
- */
420
- static _createAt(itemOrPosition: Item | Position | DocumentFragment, offset?: PositionOffset, stickiness?: PositionStickiness): Position;
421
- /**
422
- * Creates a new position, after given {@link module:engine/model/item~Item model item}.
423
- *
424
- * @internal
425
- * @param item Item after which the position should be placed.
426
- * @param stickiness Position stickiness.
427
- */
428
- static _createAfter(item: Item | DocumentFragment, stickiness?: PositionStickiness): Position;
429
- /**
430
- * Creates a new position, before the given {@link module:engine/model/item~Item model item}.
431
- *
432
- * @internal
433
- * @param item Item before which the position should be placed.
434
- * @param stickiness Position stickiness.
435
- */
436
- static _createBefore(item: Item | DocumentFragment, stickiness?: PositionStickiness): Position;
437
- /**
438
- * Creates a `Position` instance from given plain object (i.e. parsed JSON string).
439
- *
440
- * @param json Plain object to be converted to `Position`.
441
- * @param doc Document object that will be position owner.
442
- * @returns `Position` instance created using given plain object.
443
- */
444
- static fromJSON(json: any, doc: Document): Position;
445
- }
446
- /**
447
- * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
448
- * If positions are in different roots `'different'` flag is returned.
449
- */
450
- export type PositionRelation = 'before' | 'after' | 'same' | 'different';
451
- /**
452
- * Offset or one of the flags.
453
- */
454
- export type PositionOffset = number | 'before' | 'after' | 'end';
455
- /**
456
- * Represents how position is "sticking" with neighbour nodes. Used to define how position should be transformed (moved)
457
- * in edge cases. Possible values: `'toNone'`, `'toNext'`, `'toPrevious'`.
458
- *
459
- * Examples:
460
- *
461
- * ```
462
- * Insert. Position is at | and nodes are inserted at the same position, marked as ^:
463
- *
464
- * - sticks to none: <p>f^|oo</p> -> <p>fbar|oo</p>
465
- * - sticks to next node: <p>f^|oo</p> -> <p>fbar|oo</p>
466
- * - sticks to previous node: <p>f|^oo</p> -> <p>f|baroo</p>
467
- * ```
468
- *
469
- *
470
- * Move. Position is at | and range [oo] is moved to position ^:
471
- *
472
- * ```
473
- * - sticks to none: <p>f|[oo]</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
474
- * - sticks to none: <p>f[oo]|</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
475
- *
476
- * - sticks to next node: <p>f|[oo]</p><p>b^ar</p> -> <p>f</p><p>b|ooar</p>
477
- * - sticks to next node: <p>f[oo]|</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
478
- *
479
- * - sticks to previous node: <p>f|[oo]</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
480
- * - sticks to previous node: <p>f[oo]|</p><p>b^ar</p> -> <p>f</p><p>boo|ar</p>
481
- * ```
482
- */
483
- export type PositionStickiness = 'toNone' | 'toNext' | 'toPrevious';
484
- /**
485
- * Returns a text node at the given position.
486
- *
487
- * This is a helper function optimized to reuse the position parent instance for performance reasons.
488
- *
489
- * Normally, you should use {@link module:engine/model/position~Position#textNode `Position#textNode`}.
490
- * If you start hitting performance issues with {@link module:engine/model/position~Position#parent `Position#parent`}
491
- * check if your algorithm does not access it multiple times (which can happen directly or indirectly via other position properties).
492
- *
493
- * See https://github.com/ckeditor/ckeditor5/issues/6579.
494
- *
495
- * See also:
496
- *
497
- * * {@link module:engine/model/position~getNodeAfterPosition}
498
- * * {@link module:engine/model/position~getNodeBeforePosition}
499
- *
500
- * @param positionParent The parent of the given position.
501
- */
502
- export declare function getTextNodeAtPosition(position: Position, positionParent: Element | DocumentFragment): Text | null;
503
- /**
504
- * Returns the node after the given position.
505
- *
506
- * This is a helper function optimized to reuse the position parent instance and the calculation of the text node at the
507
- * specific position for performance reasons.
508
- *
509
- * Normally, you should use {@link module:engine/model/position~Position#nodeAfter `Position#nodeAfter`}.
510
- * If you start hitting performance issues with {@link module:engine/model/position~Position#parent `Position#parent`} and/or
511
- * {@link module:engine/model/position~Position#textNode `Position#textNode`}
512
- * check if your algorithm does not access those properties multiple times
513
- * (which can happen directly or indirectly via other position properties).
514
- *
515
- * See https://github.com/ckeditor/ckeditor5/issues/6579 and https://github.com/ckeditor/ckeditor5/issues/6582.
516
- *
517
- * See also:
518
- *
519
- * * {@link module:engine/model/position~getTextNodeAtPosition}
520
- * * {@link module:engine/model/position~getNodeBeforePosition}
521
- *
522
- * @param positionParent The parent of the given position.
523
- * @param textNode Text node at the given position.
524
- */
525
- export declare function getNodeAfterPosition(position: Position, positionParent: Element | DocumentFragment, textNode: Text | null): Node | null;
526
- /**
527
- * Returns the node before the given position.
528
- *
529
- * Refer to {@link module:engine/model/position~getNodeBeforePosition} for documentation on when to use this util method.
530
- *
531
- * See also:
532
- *
533
- * * {@link module:engine/model/position~getTextNodeAtPosition}
534
- * * {@link module:engine/model/position~getNodeAfterPosition}
535
- *
536
- * @param positionParent The parent of the given position.
537
- * @param textNode Text node at the given position.
538
- */
539
- export declare function getNodeBeforePosition(position: Position, positionParent: Element | DocumentFragment, textNode: Text | null): Node | null;
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/model/position
7
+ */
8
+ import TypeCheckable from './typecheckable';
9
+ import { type TreeWalkerOptions, type TreeWalkerValue } from './treewalker';
10
+ import type Document from './document';
11
+ import type DocumentFragment from './documentfragment';
12
+ import type Element from './element';
13
+ import type InsertOperation from './operation/insertoperation';
14
+ import type Item from './item';
15
+ import type MergeOperation from './operation/mergeoperation';
16
+ import type MoveOperation from './operation/moveoperation';
17
+ import type Node from './node';
18
+ import type Operation from './operation/operation';
19
+ import type SplitOperation from './operation/splitoperation';
20
+ import type Text from './text';
21
+ import '@ckeditor/ckeditor5-utils/src/version';
22
+ /**
23
+ * Represents a position in the model tree.
24
+ *
25
+ * A position is represented by its {@link module:engine/model/position~Position#root} and
26
+ * a {@link module:engine/model/position~Position#path} in that root.
27
+ *
28
+ * You can create position instances via its constructor or the `createPosition*()` factory methods of
29
+ * {@link module:engine/model/model~Model} and {@link module:engine/model/writer~Writer}.
30
+ *
31
+ * **Note:** Position is based on offsets, not indexes. This means that a position between two text nodes
32
+ * `foo` and `bar` has offset `3`, not `1`. See {@link module:engine/model/position~Position#path} for more information.
33
+ *
34
+ * Since a position in the model is represented by a {@link module:engine/model/position~Position#root position root} and
35
+ * {@link module:engine/model/position~Position#path position path} it is possible to create positions placed in non-existing places.
36
+ * This requirement is important for operational transformation algorithms.
37
+ *
38
+ * Also, {@link module:engine/model/operation/operation~Operation operations}
39
+ * kept in the {@link module:engine/model/document~Document#history document history}
40
+ * are storing positions (and ranges) which were correct when those operations were applied, but may not be correct
41
+ * after the document has changed.
42
+ *
43
+ * When changes are applied to the model, it may also happen that {@link module:engine/model/position~Position#parent position parent}
44
+ * will change even if position path has not changed. Keep in mind, that if a position leads to non-existing element,
45
+ * {@link module:engine/model/position~Position#parent} and some other properties and methods will throw errors.
46
+ *
47
+ * In most cases, position with wrong path is caused by an error in code, but it is sometimes needed, as described above.
48
+ */
49
+ export default class Position extends TypeCheckable {
50
+ /**
51
+ * Root of the position path.
52
+ */
53
+ readonly root: Element | DocumentFragment;
54
+ /**
55
+ * Position of the node in the tree. **Path contains offsets, not indexes.**
56
+ *
57
+ * Position can be placed before, after or in a {@link module:engine/model/node~Node node} if that node has
58
+ * {@link module:engine/model/node~Node#offsetSize} greater than `1`. Items in position path are
59
+ * {@link module:engine/model/node~Node#startOffset starting offsets} of position ancestors, starting from direct root children,
60
+ * down to the position offset in it's parent.
61
+ *
62
+ * ```
63
+ * ROOT
64
+ * |- P before: [ 0 ] after: [ 1 ]
65
+ * |- UL before: [ 1 ] after: [ 2 ]
66
+ * |- LI before: [ 1, 0 ] after: [ 1, 1 ]
67
+ * | |- foo before: [ 1, 0, 0 ] after: [ 1, 0, 3 ]
68
+ * |- LI before: [ 1, 1 ] after: [ 1, 2 ]
69
+ * |- bar before: [ 1, 1, 0 ] after: [ 1, 1, 3 ]
70
+ * ```
71
+ *
72
+ * `foo` and `bar` are representing {@link module:engine/model/text~Text text nodes}. Since text nodes has offset size
73
+ * greater than `1` you can place position offset between their start and end:
74
+ *
75
+ * ```
76
+ * ROOT
77
+ * |- P
78
+ * |- UL
79
+ * |- LI
80
+ * | |- f^o|o ^ has path: [ 1, 0, 1 ] | has path: [ 1, 0, 2 ]
81
+ * |- LI
82
+ * |- b^a|r ^ has path: [ 1, 1, 1 ] | has path: [ 1, 1, 2 ]
83
+ * ```
84
+ */
85
+ readonly path: ReadonlyArray<number>;
86
+ /**
87
+ * Position stickiness. See {@link module:engine/model/position~PositionStickiness}.
88
+ */
89
+ stickiness: PositionStickiness;
90
+ /**
91
+ * Creates a position.
92
+ *
93
+ * @param root Root of the position.
94
+ * @param path Position path. See {@link module:engine/model/position~Position#path}.
95
+ * @param stickiness Position stickiness. See {@link module:engine/model/position~PositionStickiness}.
96
+ */
97
+ constructor(root: Element | DocumentFragment, path: ReadonlyArray<number>, stickiness?: PositionStickiness);
98
+ /**
99
+ * Offset at which this position is located in its {@link module:engine/model/position~Position#parent parent}. It is equal
100
+ * to the last item in position {@link module:engine/model/position~Position#path path}.
101
+ *
102
+ * @type {Number}
103
+ */
104
+ get offset(): number;
105
+ set offset(newOffset: number);
106
+ /**
107
+ * Parent element of this position.
108
+ *
109
+ * Keep in mind that `parent` value is calculated when the property is accessed.
110
+ * If {@link module:engine/model/position~Position#path position path}
111
+ * leads to a non-existing element, `parent` property will throw error.
112
+ *
113
+ * Also it is a good idea to cache `parent` property if it is used frequently in an algorithm (i.e. in a long loop).
114
+ */
115
+ get parent(): Element | DocumentFragment;
116
+ /**
117
+ * Position {@link module:engine/model/position~Position#offset offset} converted to an index in position's parent node. It is
118
+ * equal to the {@link module:engine/model/node~Node#index index} of a node after this position. If position is placed
119
+ * in text node, position index is equal to the index of that text node.
120
+ */
121
+ get index(): number;
122
+ /**
123
+ * Returns {@link module:engine/model/text~Text text node} instance in which this position is placed or `null` if this
124
+ * position is not in a text node.
125
+ */
126
+ get textNode(): Text | null;
127
+ /**
128
+ * Node directly after this position or `null` if this position is in text node.
129
+ */
130
+ get nodeAfter(): Node | null;
131
+ /**
132
+ * Node directly before this position or `null` if this position is in text node.
133
+ */
134
+ get nodeBefore(): Node | null;
135
+ /**
136
+ * Is `true` if position is at the beginning of its {@link module:engine/model/position~Position#parent parent}, `false` otherwise.
137
+ */
138
+ get isAtStart(): boolean;
139
+ /**
140
+ * Is `true` if position is at the end of its {@link module:engine/model/position~Position#parent parent}, `false` otherwise.
141
+ */
142
+ get isAtEnd(): boolean;
143
+ /**
144
+ * Checks whether this position is before or after given position.
145
+ *
146
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
147
+ */
148
+ compareWith(otherPosition: Position): PositionRelation;
149
+ /**
150
+ * Gets the farthest position which matches the callback using
151
+ * {@link module:engine/model/treewalker~TreeWalker TreeWalker}.
152
+ *
153
+ * For example:
154
+ *
155
+ * ```ts
156
+ * getLastMatchingPosition( value => value.type == 'text' );
157
+ * // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
158
+ *
159
+ * getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } );
160
+ * // <paragraph>foo[]</paragraph> -> <paragraph>[]foo</paragraph>
161
+ *
162
+ * getLastMatchingPosition( value => false );
163
+ * // Do not move the position.
164
+ * ```
165
+ *
166
+ * @param skip Callback function. Gets {@link module:engine/model/treewalker~TreeWalkerValue} and should
167
+ * return `true` if the value should be skipped or `false` if not.
168
+ * @param options Object with configuration options. See {@link module:engine/model/treewalker~TreeWalker}.
169
+ *
170
+ * @returns The position after the last item which matches the `skip` callback test.
171
+ */
172
+ getLastMatchingPosition(skip: (value: TreeWalkerValue) => boolean, options?: TreeWalkerOptions): Position;
173
+ /**
174
+ * Returns a path to this position's parent. Parent path is equal to position {@link module:engine/model/position~Position#path path}
175
+ * but without the last item.
176
+ *
177
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
178
+ *
179
+ * @returns Path to the parent.
180
+ */
181
+ getParentPath(): Array<number>;
182
+ /**
183
+ * Returns ancestors array of this position, that is this position's parent and its ancestors.
184
+ *
185
+ * @returns Array with ancestors.
186
+ */
187
+ getAncestors(): Array<Element | DocumentFragment>;
188
+ /**
189
+ * Returns the parent element of the given name. Returns null if the position is not inside the desired parent.
190
+ *
191
+ * @param parentName The name of the parent element to find.
192
+ */
193
+ findAncestor(parentName: string): Element | null;
194
+ /**
195
+ * Returns the slice of two position {@link #path paths} which is identical. The {@link #root roots}
196
+ * of these two paths must be identical.
197
+ *
198
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
199
+ *
200
+ * @param position The second position.
201
+ * @returns The common path.
202
+ */
203
+ getCommonPath(position: Position): Array<number>;
204
+ /**
205
+ * Returns an {@link module:engine/model/element~Element} or {@link module:engine/model/documentfragment~DocumentFragment}
206
+ * which is a common ancestor of both positions. The {@link #root roots} of these two positions must be identical.
207
+ *
208
+ * @param position The second position.
209
+ */
210
+ getCommonAncestor(position: Position): Element | DocumentFragment | null;
211
+ /**
212
+ * Returns a new instance of `Position`, that has same {@link #parent parent} but it's offset
213
+ * is shifted by `shift` value (can be a negative value).
214
+ *
215
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
216
+ *
217
+ * @param shift Offset shift. Can be a negative value.
218
+ * @returns Shifted position.
219
+ */
220
+ getShiftedBy(shift: number): Position;
221
+ /**
222
+ * Checks whether this position is after given position.
223
+ *
224
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
225
+ *
226
+ * @see module:engine/model/position~Position#isBefore
227
+ * @param otherPosition Position to compare with.
228
+ * @returns True if this position is after given position.
229
+ */
230
+ isAfter(otherPosition: Position): boolean;
231
+ /**
232
+ * Checks whether this position is before given position.
233
+ *
234
+ * **Note:** watch out when using negation of the value returned by this method, because the negation will also
235
+ * be `true` if positions are in different roots and you might not expect this. You should probably use
236
+ * `a.isAfter( b ) || a.isEqual( b )` or `!a.isBefore( p ) && a.root == b.root` in most scenarios. If your
237
+ * condition uses multiple `isAfter` and `isBefore` checks, build them so they do not use negated values, i.e.:
238
+ *
239
+ * ```ts
240
+ * if ( a.isBefore( b ) && c.isAfter( d ) ) {
241
+ * // do A.
242
+ * } else {
243
+ * // do B.
244
+ * }
245
+ * ```
246
+ *
247
+ * or, if you have only one if-branch:
248
+ *
249
+ * ```ts
250
+ * if ( !( a.isBefore( b ) && c.isAfter( d ) ) {
251
+ * // do B.
252
+ * }
253
+ * ```
254
+ *
255
+ * rather than:
256
+ *
257
+ * ```ts
258
+ * if ( !a.isBefore( b ) || && !c.isAfter( d ) ) {
259
+ * // do B.
260
+ * } else {
261
+ * // do A.
262
+ * }
263
+ * ```
264
+ *
265
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
266
+ *
267
+ * @param otherPosition Position to compare with.
268
+ * @returns True if this position is before given position.
269
+ */
270
+ isBefore(otherPosition: Position): boolean;
271
+ /**
272
+ * Checks whether this position is equal to given position.
273
+ *
274
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
275
+ *
276
+ * @param otherPosition Position to compare with.
277
+ * @returns True if positions are same.
278
+ */
279
+ isEqual(otherPosition: Position): boolean;
280
+ /**
281
+ * Checks whether this position is touching given position. Positions touch when there are no text nodes
282
+ * or empty nodes in a range between them. Technically, those positions are not equal but in many cases
283
+ * they are very similar or even indistinguishable.
284
+ *
285
+ * @param otherPosition Position to compare with.
286
+ * @returns True if positions touch.
287
+ */
288
+ isTouching(otherPosition: Position): boolean;
289
+ /**
290
+ * Checks if two positions are in the same parent.
291
+ *
292
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
293
+ *
294
+ * @param position Position to compare with.
295
+ * @returns `true` if positions have the same parent, `false` otherwise.
296
+ */
297
+ hasSameParentAs(position: Position): boolean;
298
+ /**
299
+ * Returns a copy of this position that is transformed by given `operation`.
300
+ *
301
+ * The new position's parameters are updated accordingly to the effect of the `operation`.
302
+ *
303
+ * For example, if `n` nodes are inserted before the position, the returned position {@link ~Position#offset} will be
304
+ * increased by `n`. If the position was in a merged element, it will be accordingly moved to the new element, etc.
305
+ *
306
+ * This method is safe to use it on non-existing positions (for example during operational transformation).
307
+ *
308
+ * @param operation Operation to transform by.
309
+ * @returns Transformed position.
310
+ */
311
+ getTransformedByOperation(operation: Operation): Position;
312
+ /**
313
+ * Returns a copy of this position transformed by an insert operation.
314
+ *
315
+ * @internal
316
+ */
317
+ _getTransformedByInsertOperation(operation: InsertOperation): Position;
318
+ /**
319
+ * Returns a copy of this position transformed by a move operation.
320
+ *
321
+ * @internal
322
+ */
323
+ _getTransformedByMoveOperation(operation: MoveOperation): Position;
324
+ /**
325
+ * Returns a copy of this position transformed by a split operation.
326
+ *
327
+ * @internal
328
+ */
329
+ _getTransformedBySplitOperation(operation: SplitOperation): Position;
330
+ /**
331
+ * Returns a copy of this position transformed by merge operation.
332
+ *
333
+ * @internal
334
+ */
335
+ _getTransformedByMergeOperation(operation: MergeOperation): Position;
336
+ /**
337
+ * Returns a copy of this position that is updated by removing `howMany` nodes starting from `deletePosition`.
338
+ * It may happen that this position is in a removed node. If that is the case, `null` is returned instead.
339
+ *
340
+ * @internal
341
+ * @param deletePosition Position before the first removed node.
342
+ * @param howMany How many nodes are removed.
343
+ * @returns Transformed position or `null`.
344
+ */
345
+ _getTransformedByDeletion(deletePosition: Position, howMany: number): Position | null;
346
+ /**
347
+ * Returns a copy of this position that is updated by inserting `howMany` nodes at `insertPosition`.
348
+ *
349
+ * @internal
350
+ * @param insertPosition Position where nodes are inserted.
351
+ * @param howMany How many nodes are inserted.
352
+ * @returns Transformed position.
353
+ */
354
+ _getTransformedByInsertion(insertPosition: Position, howMany: number): Position;
355
+ /**
356
+ * Returns a copy of this position that is updated by moving `howMany` nodes from `sourcePosition` to `targetPosition`.
357
+ *
358
+ * @internal
359
+ * @param sourcePosition Position before the first element to move.
360
+ * @param targetPosition Position where moved elements will be inserted.
361
+ * @param howMany How many consecutive nodes to move, starting from `sourcePosition`.
362
+ * @returns Transformed position.
363
+ */
364
+ _getTransformedByMove(sourcePosition: Position, targetPosition: Position, howMany: number): Position;
365
+ /**
366
+ * Returns a new position that is a combination of this position and given positions.
367
+ *
368
+ * The combined position is a copy of this position transformed by moving a range starting at `source` position
369
+ * to the `target` position. It is expected that this position is inside the moved range.
370
+ *
371
+ * Example:
372
+ *
373
+ * ```ts
374
+ * let original = model.createPositionFromPath( root, [ 2, 3, 1 ] );
375
+ * let source = model.createPositionFromPath( root, [ 2, 2 ] );
376
+ * let target = model.createPositionFromPath( otherRoot, [ 1, 1, 3 ] );
377
+ * original._getCombined( source, target ); // path is [ 1, 1, 4, 1 ], root is `otherRoot`
378
+ * ```
379
+ *
380
+ * Explanation:
381
+ *
382
+ * We have a position `[ 2, 3, 1 ]` and move some nodes from `[ 2, 2 ]` to `[ 1, 1, 3 ]`. The original position
383
+ * was inside moved nodes and now should point to the new place. The moved nodes will be after
384
+ * positions `[ 1, 1, 3 ]`, `[ 1, 1, 4 ]`, `[ 1, 1, 5 ]`. Since our position was in the second moved node,
385
+ * the transformed position will be in a sub-tree of a node at `[ 1, 1, 4 ]`. Looking at original path, we
386
+ * took care of `[ 2, 3 ]` part of it. Now we have to add the rest of the original path to the transformed path.
387
+ * Finally, the transformed position will point to `[ 1, 1, 4, 1 ]`.
388
+ *
389
+ * @internal
390
+ * @param source Beginning of the moved range.
391
+ * @param target Position where the range is moved.
392
+ * @returns Combined position.
393
+ */
394
+ _getCombined(source: Position, target: Position): Position;
395
+ /**
396
+ * @inheritDoc
397
+ */
398
+ toJSON(): unknown;
399
+ /**
400
+ * Returns a new position that is equal to current position.
401
+ */
402
+ clone(): this;
403
+ /**
404
+ * Creates position at the given location. The location can be specified as:
405
+ *
406
+ * * a {@link module:engine/model/position~Position position},
407
+ * * parent element and offset (offset defaults to `0`),
408
+ * * parent element and `'end'` (sets position at the end of that element),
409
+ * * {@link module:engine/model/item~Item model item} and `'before'` or `'after'` (sets position before or after given model item).
410
+ *
411
+ * This method is a shortcut to other factory methods such as:
412
+ *
413
+ * * {@link module:engine/model/position~Position._createBefore},
414
+ * * {@link module:engine/model/position~Position._createAfter}.
415
+ *
416
+ * @internal
417
+ * @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/model/item~Item model item}.
418
+ * @param stickiness Position stickiness. Used only when the first parameter is a {@link module:engine/model/item~Item model item}.
419
+ */
420
+ static _createAt(itemOrPosition: Item | Position | DocumentFragment, offset?: PositionOffset, stickiness?: PositionStickiness): Position;
421
+ /**
422
+ * Creates a new position, after given {@link module:engine/model/item~Item model item}.
423
+ *
424
+ * @internal
425
+ * @param item Item after which the position should be placed.
426
+ * @param stickiness Position stickiness.
427
+ */
428
+ static _createAfter(item: Item | DocumentFragment, stickiness?: PositionStickiness): Position;
429
+ /**
430
+ * Creates a new position, before the given {@link module:engine/model/item~Item model item}.
431
+ *
432
+ * @internal
433
+ * @param item Item before which the position should be placed.
434
+ * @param stickiness Position stickiness.
435
+ */
436
+ static _createBefore(item: Item | DocumentFragment, stickiness?: PositionStickiness): Position;
437
+ /**
438
+ * Creates a `Position` instance from given plain object (i.e. parsed JSON string).
439
+ *
440
+ * @param json Plain object to be converted to `Position`.
441
+ * @param doc Document object that will be position owner.
442
+ * @returns `Position` instance created using given plain object.
443
+ */
444
+ static fromJSON(json: any, doc: Document): Position;
445
+ }
446
+ /**
447
+ * A flag indicating whether this position is `'before'` or `'after'` or `'same'` as given position.
448
+ * If positions are in different roots `'different'` flag is returned.
449
+ */
450
+ export type PositionRelation = 'before' | 'after' | 'same' | 'different';
451
+ /**
452
+ * Offset or one of the flags.
453
+ */
454
+ export type PositionOffset = number | 'before' | 'after' | 'end';
455
+ /**
456
+ * Represents how position is "sticking" with neighbour nodes. Used to define how position should be transformed (moved)
457
+ * in edge cases. Possible values: `'toNone'`, `'toNext'`, `'toPrevious'`.
458
+ *
459
+ * Examples:
460
+ *
461
+ * ```
462
+ * Insert. Position is at | and nodes are inserted at the same position, marked as ^:
463
+ *
464
+ * - sticks to none: <p>f^|oo</p> -> <p>fbar|oo</p>
465
+ * - sticks to next node: <p>f^|oo</p> -> <p>fbar|oo</p>
466
+ * - sticks to previous node: <p>f|^oo</p> -> <p>f|baroo</p>
467
+ * ```
468
+ *
469
+ *
470
+ * Move. Position is at | and range [oo] is moved to position ^:
471
+ *
472
+ * ```
473
+ * - sticks to none: <p>f|[oo]</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
474
+ * - sticks to none: <p>f[oo]|</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
475
+ *
476
+ * - sticks to next node: <p>f|[oo]</p><p>b^ar</p> -> <p>f</p><p>b|ooar</p>
477
+ * - sticks to next node: <p>f[oo]|</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
478
+ *
479
+ * - sticks to previous node: <p>f|[oo]</p><p>b^ar</p> -> <p>f|</p><p>booar</p>
480
+ * - sticks to previous node: <p>f[oo]|</p><p>b^ar</p> -> <p>f</p><p>boo|ar</p>
481
+ * ```
482
+ */
483
+ export type PositionStickiness = 'toNone' | 'toNext' | 'toPrevious';
484
+ /**
485
+ * Returns a text node at the given position.
486
+ *
487
+ * This is a helper function optimized to reuse the position parent instance for performance reasons.
488
+ *
489
+ * Normally, you should use {@link module:engine/model/position~Position#textNode `Position#textNode`}.
490
+ * If you start hitting performance issues with {@link module:engine/model/position~Position#parent `Position#parent`}
491
+ * check if your algorithm does not access it multiple times (which can happen directly or indirectly via other position properties).
492
+ *
493
+ * See https://github.com/ckeditor/ckeditor5/issues/6579.
494
+ *
495
+ * See also:
496
+ *
497
+ * * {@link module:engine/model/position~getNodeAfterPosition}
498
+ * * {@link module:engine/model/position~getNodeBeforePosition}
499
+ *
500
+ * @param positionParent The parent of the given position.
501
+ */
502
+ export declare function getTextNodeAtPosition(position: Position, positionParent: Element | DocumentFragment): Text | null;
503
+ /**
504
+ * Returns the node after the given position.
505
+ *
506
+ * This is a helper function optimized to reuse the position parent instance and the calculation of the text node at the
507
+ * specific position for performance reasons.
508
+ *
509
+ * Normally, you should use {@link module:engine/model/position~Position#nodeAfter `Position#nodeAfter`}.
510
+ * If you start hitting performance issues with {@link module:engine/model/position~Position#parent `Position#parent`} and/or
511
+ * {@link module:engine/model/position~Position#textNode `Position#textNode`}
512
+ * check if your algorithm does not access those properties multiple times
513
+ * (which can happen directly or indirectly via other position properties).
514
+ *
515
+ * See https://github.com/ckeditor/ckeditor5/issues/6579 and https://github.com/ckeditor/ckeditor5/issues/6582.
516
+ *
517
+ * See also:
518
+ *
519
+ * * {@link module:engine/model/position~getTextNodeAtPosition}
520
+ * * {@link module:engine/model/position~getNodeBeforePosition}
521
+ *
522
+ * @param positionParent The parent of the given position.
523
+ * @param textNode Text node at the given position.
524
+ */
525
+ export declare function getNodeAfterPosition(position: Position, positionParent: Element | DocumentFragment, textNode: Text | null): Node | null;
526
+ /**
527
+ * Returns the node before the given position.
528
+ *
529
+ * Refer to {@link module:engine/model/position~getNodeBeforePosition} for documentation on when to use this util method.
530
+ *
531
+ * See also:
532
+ *
533
+ * * {@link module:engine/model/position~getTextNodeAtPosition}
534
+ * * {@link module:engine/model/position~getNodeAfterPosition}
535
+ *
536
+ * @param positionParent The parent of the given position.
537
+ * @param textNode Text node at the given position.
538
+ */
539
+ export declare function getNodeBeforePosition(position: Position, positionParent: Element | DocumentFragment, textNode: Text | null): Node | null;