@ckeditor/ckeditor5-engine 45.2.1-alpha.9 → 46.0.0-alpha.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.
- package/dist/index.js +2563 -2257
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.d.ts +33 -32
- package/src/controller/datacontroller.js +29 -28
- package/src/controller/editingcontroller.d.ts +8 -8
- package/src/controller/editingcontroller.js +10 -10
- package/src/conversion/conversion.d.ts +18 -19
- package/src/conversion/conversion.js +4 -4
- package/src/conversion/conversionhelpers.d.ts +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.d.ts +63 -69
- package/src/conversion/downcastdispatcher.js +16 -16
- package/src/conversion/downcasthelpers.d.ts +94 -83
- package/src/conversion/downcasthelpers.js +63 -53
- package/src/conversion/mapper.d.ts +27 -27
- package/src/conversion/mapper.js +15 -15
- package/src/conversion/modelconsumable.d.ts +26 -26
- package/src/conversion/modelconsumable.js +23 -23
- package/src/conversion/upcastdispatcher.d.ts +33 -32
- package/src/conversion/upcastdispatcher.js +19 -19
- package/src/conversion/upcasthelpers.d.ts +46 -38
- package/src/conversion/upcasthelpers.js +33 -24
- package/src/conversion/viewconsumable.d.ts +50 -45
- package/src/conversion/viewconsumable.js +32 -27
- package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
- package/src/dataprocessor/basichtmlwriter.js +3 -1
- package/src/dataprocessor/dataprocessor.d.ts +7 -6
- package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/htmldataprocessor.js +6 -6
- package/src/dataprocessor/htmlwriter.d.ts +1 -1
- package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/xmldataprocessor.js +6 -6
- package/src/dev-utils/model.d.ts +25 -26
- package/src/dev-utils/model.js +35 -36
- package/src/dev-utils/operationreplayer.d.ts +5 -3
- package/src/dev-utils/operationreplayer.js +4 -2
- package/src/dev-utils/utils.d.ts +8 -0
- package/src/dev-utils/utils.js +8 -0
- package/src/dev-utils/view.d.ts +66 -63
- package/src/dev-utils/view.js +144 -134
- package/src/index.d.ts +135 -106
- package/src/index.js +120 -71
- package/src/legacyerrors.d.ts +5 -0
- package/src/legacyerrors.js +17 -0
- package/src/model/batch.d.ts +2 -15
- package/src/model/batch.js +1 -23
- package/src/model/differ.d.ts +54 -31
- package/src/model/differ.js +15 -15
- package/src/model/document.d.ts +31 -31
- package/src/model/document.js +13 -13
- package/src/model/documentfragment.d.ts +45 -45
- package/src/model/documentfragment.js +40 -40
- package/src/model/documentselection.d.ts +92 -92
- package/src/model/documentselection.js +71 -70
- package/src/model/element.d.ts +31 -31
- package/src/model/element.js +29 -29
- package/src/model/history.d.ts +3 -3
- package/src/model/history.js +2 -2
- package/src/model/item.d.ts +4 -5
- package/src/model/liveposition.d.ts +31 -31
- package/src/model/liveposition.js +18 -18
- package/src/model/liverange.d.ts +42 -38
- package/src/model/liverange.js +17 -16
- package/src/model/markercollection.d.ts +41 -40
- package/src/model/markercollection.js +22 -20
- package/src/model/model.d.ts +82 -81
- package/src/model/model.js +54 -54
- package/src/model/node.d.ts +48 -48
- package/src/model/node.js +31 -31
- package/src/model/nodelist.d.ts +17 -17
- package/src/model/nodelist.js +11 -11
- package/src/model/operation/attributeoperation.d.ts +10 -10
- package/src/model/operation/attributeoperation.js +7 -7
- package/src/model/operation/detachoperation.d.ts +11 -9
- package/src/model/operation/detachoperation.js +8 -6
- package/src/model/operation/insertoperation.d.ts +13 -13
- package/src/model/operation/insertoperation.js +15 -15
- package/src/model/operation/markeroperation.d.ts +12 -12
- package/src/model/operation/markeroperation.js +5 -5
- package/src/model/operation/mergeoperation.d.ts +16 -16
- package/src/model/operation/mergeoperation.js +18 -18
- package/src/model/operation/moveoperation.d.ts +16 -16
- package/src/model/operation/moveoperation.js +18 -15
- package/src/model/operation/nooperation.d.ts +4 -4
- package/src/model/operation/nooperation.js +2 -2
- package/src/model/operation/operation.d.ts +10 -10
- package/src/model/operation/operation.js +5 -5
- package/src/model/operation/operationfactory.d.ts +4 -4
- package/src/model/operation/operationfactory.js +12 -12
- package/src/model/operation/renameoperation.d.ts +10 -10
- package/src/model/operation/renameoperation.js +7 -7
- package/src/model/operation/rootattributeoperation.d.ts +12 -12
- package/src/model/operation/rootattributeoperation.js +8 -8
- package/src/model/operation/rootoperation.d.ts +8 -8
- package/src/model/operation/rootoperation.js +3 -3
- package/src/model/operation/splitoperation.d.ts +17 -17
- package/src/model/operation/splitoperation.js +19 -19
- package/src/model/operation/transform.d.ts +11 -8
- package/src/model/operation/transform.js +66 -49
- package/src/model/operation/utils.d.ts +24 -23
- package/src/model/operation/utils.js +20 -20
- package/src/model/position.d.ts +101 -97
- package/src/model/position.js +69 -64
- package/src/model/range.d.ts +90 -90
- package/src/model/range.js +87 -87
- package/src/model/rootelement.d.ts +11 -11
- package/src/model/rootelement.js +9 -9
- package/src/model/schema.d.ts +158 -154
- package/src/model/schema.js +93 -90
- package/src/model/selection.d.ts +73 -73
- package/src/model/selection.js +62 -62
- package/src/model/text.d.ts +11 -10
- package/src/model/text.js +11 -10
- package/src/model/textproxy.d.ts +39 -38
- package/src/model/textproxy.js +31 -30
- package/src/model/treewalker.d.ts +37 -37
- package/src/model/treewalker.js +14 -14
- package/src/model/typecheckable.d.ts +45 -45
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.d.ts +7 -7
- package/src/model/utils/deletecontent.d.ts +7 -5
- package/src/model/utils/deletecontent.js +13 -11
- package/src/model/utils/getselectedcontent.d.ts +6 -5
- package/src/model/utils/getselectedcontent.js +2 -1
- package/src/model/utils/insertcontent.d.ts +9 -8
- package/src/model/utils/insertcontent.js +41 -40
- package/src/model/utils/insertobject.d.ts +9 -9
- package/src/model/utils/insertobject.js +4 -4
- package/src/model/utils/modifyselection.d.ts +5 -4
- package/src/model/utils/modifyselection.js +12 -11
- package/src/model/utils/selection-post-fixer.d.ts +12 -8
- package/src/model/utils/selection-post-fixer.js +15 -11
- package/src/model/writer.d.ts +102 -101
- package/src/model/writer.js +99 -98
- package/src/view/attributeelement.d.ts +29 -29
- package/src/view/attributeelement.js +25 -25
- package/src/view/containerelement.d.ts +16 -15
- package/src/view/containerelement.js +15 -14
- package/src/view/datatransfer.d.ts +7 -7
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.d.ts +25 -25
- package/src/view/document.js +15 -15
- package/src/view/documentfragment.d.ts +21 -21
- package/src/view/documentfragment.js +14 -14
- package/src/view/documentselection.d.ts +65 -63
- package/src/view/documentselection.js +27 -25
- package/src/view/domconverter.d.ts +94 -89
- package/src/view/domconverter.js +78 -73
- package/src/view/downcastwriter.d.ts +185 -181
- package/src/view/downcastwriter.js +222 -210
- package/src/view/editableelement.d.ts +13 -13
- package/src/view/editableelement.js +8 -8
- package/src/view/element.d.ts +75 -74
- package/src/view/element.js +58 -58
- package/src/view/elementdefinition.d.ts +3 -4
- package/src/view/emptyelement.d.ts +13 -13
- package/src/view/emptyelement.js +13 -13
- package/src/view/filler.d.ts +14 -3
- package/src/view/filler.js +12 -1
- package/src/view/item.d.ts +4 -5
- package/src/view/matcher.d.ts +22 -19
- package/src/view/matcher.js +6 -6
- package/src/view/node.d.ts +33 -33
- package/src/view/node.js +9 -9
- package/src/view/observer/arrowkeysobserver.d.ts +10 -10
- package/src/view/observer/arrowkeysobserver.js +5 -5
- package/src/view/observer/bubblingemittermixin.d.ts +5 -5
- package/src/view/observer/bubblingemittermixin.js +2 -9
- package/src/view/observer/bubblingeventinfo.d.ts +9 -9
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.d.ts +8 -8
- package/src/view/observer/clickobserver.js +4 -4
- package/src/view/observer/compositionobserver.d.ts +19 -19
- package/src/view/observer/compositionobserver.js +6 -6
- package/src/view/observer/domeventdata.d.ts +9 -9
- package/src/view/observer/domeventdata.js +2 -2
- package/src/view/observer/domeventobserver.d.ts +3 -3
- package/src/view/observer/domeventobserver.js +5 -5
- package/src/view/observer/fakeselectionobserver.d.ts +9 -9
- package/src/view/observer/fakeselectionobserver.js +8 -8
- package/src/view/observer/focusobserver.d.ts +16 -16
- package/src/view/observer/focusobserver.js +7 -7
- package/src/view/observer/inputobserver.d.ts +18 -18
- package/src/view/observer/inputobserver.js +5 -5
- package/src/view/observer/keyobserver.d.ts +11 -11
- package/src/view/observer/keyobserver.js +3 -3
- package/src/view/observer/mouseobserver.d.ts +16 -16
- package/src/view/observer/mouseobserver.js +3 -3
- package/src/view/observer/mutationobserver.d.ts +21 -21
- package/src/view/observer/mutationobserver.js +7 -7
- package/src/view/observer/observer.d.ts +12 -12
- package/src/view/observer/observer.js +6 -6
- package/src/view/observer/selectionobserver.d.ts +33 -33
- package/src/view/observer/selectionobserver.js +14 -14
- package/src/view/observer/tabobserver.d.ts +10 -10
- package/src/view/observer/tabobserver.js +5 -5
- package/src/view/observer/touchobserver.d.ts +13 -13
- package/src/view/observer/touchobserver.js +3 -3
- package/src/view/placeholder.d.ts +21 -21
- package/src/view/placeholder.js +23 -23
- package/src/view/position.d.ts +49 -49
- package/src/view/position.js +42 -42
- package/src/view/range.d.ts +76 -74
- package/src/view/range.js +67 -65
- package/src/view/rawelement.d.ts +19 -19
- package/src/view/rawelement.js +16 -16
- package/src/view/renderer.d.ts +14 -14
- package/src/view/renderer.js +7 -7
- package/src/view/rooteditableelement.d.ts +8 -7
- package/src/view/rooteditableelement.js +7 -6
- package/src/view/selection.d.ts +66 -64
- package/src/view/selection.js +50 -48
- package/src/view/styles/background.d.ts +2 -2
- package/src/view/styles/background.js +9 -9
- package/src/view/styles/border.d.ts +2 -2
- package/src/view/styles/border.js +13 -13
- package/src/view/styles/margin.d.ts +2 -2
- package/src/view/styles/margin.js +5 -5
- package/src/view/styles/padding.d.ts +2 -2
- package/src/view/styles/padding.js +5 -5
- package/src/view/styles/utils.d.ts +24 -24
- package/src/view/styles/utils.js +25 -25
- package/src/view/stylesmap.d.ts +28 -32
- package/src/view/stylesmap.js +52 -39
- package/src/view/text.d.ts +11 -11
- package/src/view/text.js +10 -10
- package/src/view/textproxy.d.ts +33 -32
- package/src/view/textproxy.js +23 -22
- package/src/view/tokenlist.d.ts +14 -14
- package/src/view/tokenlist.js +10 -10
- package/src/view/treewalker.d.ts +42 -40
- package/src/view/treewalker.js +36 -35
- package/src/view/typecheckable.d.ts +76 -75
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.d.ts +22 -21
- package/src/view/uielement.js +17 -16
- package/src/view/upcastwriter.d.ts +70 -70
- package/src/view/upcastwriter.js +42 -42
- package/src/view/view.d.ts +70 -69
- package/src/view/view.js +56 -55
package/src/model/position.js
CHANGED
|
@@ -5,37 +5,37 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/position
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
8
|
+
import { ModelTypeCheckable } from './typecheckable.js';
|
|
9
|
+
import { ModelTreeWalker } from './treewalker.js';
|
|
10
10
|
import { CKEditorError, compareArrays } from '@ckeditor/ckeditor5-utils';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a position in the model tree.
|
|
13
13
|
*
|
|
14
|
-
* A position is represented by its {@link module:engine/model/position~
|
|
15
|
-
* a {@link module:engine/model/position~
|
|
14
|
+
* A position is represented by its {@link module:engine/model/position~ModelPosition#root} and
|
|
15
|
+
* a {@link module:engine/model/position~ModelPosition#path} in that root.
|
|
16
16
|
*
|
|
17
17
|
* You can create position instances via its constructor or the `createPosition*()` factory methods of
|
|
18
|
-
* {@link module:engine/model/model~Model} and {@link module:engine/model/writer~
|
|
18
|
+
* {@link module:engine/model/model~Model} and {@link module:engine/model/writer~ModelWriter}.
|
|
19
19
|
*
|
|
20
20
|
* **Note:** Position is based on offsets, not indexes. This means that a position between two text nodes
|
|
21
|
-
* `foo` and `bar` has offset `3`, not `1`. See {@link module:engine/model/position~
|
|
21
|
+
* `foo` and `bar` has offset `3`, not `1`. See {@link module:engine/model/position~ModelPosition#path} for more information.
|
|
22
22
|
*
|
|
23
|
-
* Since a position in the model is represented by a {@link module:engine/model/position~
|
|
24
|
-
* {@link module:engine/model/position~
|
|
23
|
+
* Since a position in the model is represented by a {@link module:engine/model/position~ModelPosition#root position root} and
|
|
24
|
+
* {@link module:engine/model/position~ModelPosition#path position path} it is possible to create positions placed in non-existing places.
|
|
25
25
|
* This requirement is important for operational transformation algorithms.
|
|
26
26
|
*
|
|
27
27
|
* Also, {@link module:engine/model/operation/operation~Operation operations}
|
|
28
|
-
* kept in the {@link module:engine/model/document~
|
|
28
|
+
* kept in the {@link module:engine/model/document~ModelDocument#history document history}
|
|
29
29
|
* are storing positions (and ranges) which were correct when those operations were applied, but may not be correct
|
|
30
30
|
* after the document has changed.
|
|
31
31
|
*
|
|
32
|
-
* When changes are applied to the model, it may also happen that {@link module:engine/model/position~
|
|
32
|
+
* When changes are applied to the model, it may also happen that {@link module:engine/model/position~ModelPosition#parent position parent}
|
|
33
33
|
* will change even if position path has not changed. Keep in mind, that if a position leads to non-existing element,
|
|
34
|
-
* {@link module:engine/model/position~
|
|
34
|
+
* {@link module:engine/model/position~ModelPosition#parent} and some other properties and methods will throw errors.
|
|
35
35
|
*
|
|
36
36
|
* In most cases, position with wrong path is caused by an error in code, but it is sometimes needed, as described above.
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
38
|
+
export class ModelPosition extends ModelTypeCheckable {
|
|
39
39
|
/**
|
|
40
40
|
* Root of the position path.
|
|
41
41
|
*/
|
|
@@ -43,9 +43,9 @@ export default class Position extends TypeCheckable {
|
|
|
43
43
|
/**
|
|
44
44
|
* Position of the node in the tree. **Path contains offsets, not indexes.**
|
|
45
45
|
*
|
|
46
|
-
* Position can be placed before, after or in a {@link module:engine/model/node~
|
|
47
|
-
* {@link module:engine/model/node~
|
|
48
|
-
* {@link module:engine/model/node~
|
|
46
|
+
* Position can be placed before, after or in a {@link module:engine/model/node~ModelNode node} if that node has
|
|
47
|
+
* {@link module:engine/model/node~ModelNode#offsetSize} greater than `1`. Items in position path are
|
|
48
|
+
* {@link module:engine/model/node~ModelNode#startOffset starting offsets} of position ancestors, starting from direct root children,
|
|
49
49
|
* down to the position offset in it's parent.
|
|
50
50
|
*
|
|
51
51
|
* ```
|
|
@@ -58,7 +58,7 @@ export default class Position extends TypeCheckable {
|
|
|
58
58
|
* |- bar before: [ 1, 1, 0 ] after: [ 1, 1, 3 ]
|
|
59
59
|
* ```
|
|
60
60
|
*
|
|
61
|
-
* `foo` and `bar` are representing {@link module:engine/model/text~
|
|
61
|
+
* `foo` and `bar` are representing {@link module:engine/model/text~ModelText text nodes}. Since text nodes has offset size
|
|
62
62
|
* greater than `1` you can place position offset between their start and end:
|
|
63
63
|
*
|
|
64
64
|
* ```
|
|
@@ -73,15 +73,15 @@ export default class Position extends TypeCheckable {
|
|
|
73
73
|
*/
|
|
74
74
|
path;
|
|
75
75
|
/**
|
|
76
|
-
* Position stickiness. See {@link module:engine/model/position~
|
|
76
|
+
* Position stickiness. See {@link module:engine/model/position~ModelPositionStickiness}.
|
|
77
77
|
*/
|
|
78
78
|
stickiness;
|
|
79
79
|
/**
|
|
80
80
|
* Creates a position.
|
|
81
81
|
*
|
|
82
82
|
* @param root Root of the position.
|
|
83
|
-
* @param path Position path. See {@link module:engine/model/position~
|
|
84
|
-
* @param stickiness Position stickiness. See {@link module:engine/model/position~
|
|
83
|
+
* @param path Position path. See {@link module:engine/model/position~ModelPosition#path}.
|
|
84
|
+
* @param stickiness Position stickiness. See {@link module:engine/model/position~ModelPositionStickiness}.
|
|
85
85
|
*/
|
|
86
86
|
constructor(root, path, stickiness = 'toNone') {
|
|
87
87
|
super();
|
|
@@ -117,8 +117,8 @@ export default class Position extends TypeCheckable {
|
|
|
117
117
|
this.stickiness = stickiness;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Offset at which this position is located in its {@link module:engine/model/position~
|
|
121
|
-
* to the last item in position {@link module:engine/model/position~
|
|
120
|
+
* Offset at which this position is located in its {@link module:engine/model/position~ModelPosition#parent parent}. It is equal
|
|
121
|
+
* to the last item in position {@link module:engine/model/position~ModelPosition#path path}.
|
|
122
122
|
*
|
|
123
123
|
* @type {Number}
|
|
124
124
|
*/
|
|
@@ -132,7 +132,7 @@ export default class Position extends TypeCheckable {
|
|
|
132
132
|
* Parent element of this position.
|
|
133
133
|
*
|
|
134
134
|
* Keep in mind that `parent` value is calculated when the property is accessed.
|
|
135
|
-
* If {@link module:engine/model/position~
|
|
135
|
+
* If {@link module:engine/model/position~ModelPosition#path position path}
|
|
136
136
|
* leads to a non-existing element, `parent` property will throw error.
|
|
137
137
|
*
|
|
138
138
|
* Also it is a good idea to cache `parent` property if it is used frequently in an algorithm (i.e. in a long loop).
|
|
@@ -147,15 +147,16 @@ export default class Position extends TypeCheckable {
|
|
|
147
147
|
* a correct place in the tree and hence, some of its methods and getters cannot work correctly.
|
|
148
148
|
*
|
|
149
149
|
* **Note**: Unlike DOM and view positions, in the model, the
|
|
150
|
-
* {@link module:engine/model/position~
|
|
151
|
-
* The last offset in the
|
|
150
|
+
* {@link module:engine/model/position~ModelPosition#parent position's parent} is always an element or a document fragment.
|
|
151
|
+
* The last offset in the
|
|
152
|
+
* {@link module:engine/model/position~ModelPosition#path position's path} is the point in this element
|
|
152
153
|
* where this position points.
|
|
153
154
|
*
|
|
154
155
|
* Read more about model positions and offsets in
|
|
155
156
|
* the {@glink framework/architecture/editing-engine#indexes-and-offsets Editing engine architecture} guide.
|
|
156
157
|
*
|
|
157
158
|
* @error model-position-path-incorrect
|
|
158
|
-
* @param {module:engine/model/position~
|
|
159
|
+
* @param {module:engine/model/position~ModelPosition} position The incorrect position.
|
|
159
160
|
*/
|
|
160
161
|
throw new CKEditorError('model-position-path-incorrect', this, { position: this });
|
|
161
162
|
}
|
|
@@ -166,15 +167,15 @@ export default class Position extends TypeCheckable {
|
|
|
166
167
|
return parent;
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
169
|
-
* Position {@link module:engine/model/position~
|
|
170
|
-
* equal to the {@link module:engine/model/node~
|
|
170
|
+
* Position {@link module:engine/model/position~ModelPosition#offset offset} converted to an index in position's parent node. It is
|
|
171
|
+
* equal to the {@link module:engine/model/node~ModelNode#index index} of a node after this position. If position is placed
|
|
171
172
|
* in text node, position index is equal to the index of that text node.
|
|
172
173
|
*/
|
|
173
174
|
get index() {
|
|
174
175
|
return this.parent.offsetToIndex(this.offset);
|
|
175
176
|
}
|
|
176
177
|
/**
|
|
177
|
-
* Returns {@link module:engine/model/text~
|
|
178
|
+
* Returns {@link module:engine/model/text~ModelText text node} instance in which this position is placed or `null` if this
|
|
178
179
|
* position is not in a text node.
|
|
179
180
|
*/
|
|
180
181
|
get textNode() {
|
|
@@ -197,13 +198,13 @@ export default class Position extends TypeCheckable {
|
|
|
197
198
|
return getNodeBeforePosition(this, parent, getTextNodeAtPosition(this, parent));
|
|
198
199
|
}
|
|
199
200
|
/**
|
|
200
|
-
* Is `true` if position is at the beginning of its {@link module:engine/model/position~
|
|
201
|
+
* Is `true` if position is at the beginning of its {@link module:engine/model/position~ModelPosition#parent parent}, `false` otherwise.
|
|
201
202
|
*/
|
|
202
203
|
get isAtStart() {
|
|
203
204
|
return this.offset === 0;
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
* Is `true` if position is at the end of its {@link module:engine/model/position~
|
|
207
|
+
* Is `true` if position is at the end of its {@link module:engine/model/position~ModelPosition#parent parent}, `false` otherwise.
|
|
207
208
|
*/
|
|
208
209
|
get isAtEnd() {
|
|
209
210
|
return this.offset == this.parent.maxOffset;
|
|
@@ -247,7 +248,7 @@ export default class Position extends TypeCheckable {
|
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
249
250
|
* Gets the farthest position which matches the callback using
|
|
250
|
-
* {@link module:engine/model/treewalker~
|
|
251
|
+
* {@link module:engine/model/treewalker~ModelTreeWalker TreeWalker}.
|
|
251
252
|
*
|
|
252
253
|
* For example:
|
|
253
254
|
*
|
|
@@ -262,21 +263,21 @@ export default class Position extends TypeCheckable {
|
|
|
262
263
|
* // Do not move the position.
|
|
263
264
|
* ```
|
|
264
265
|
*
|
|
265
|
-
* @param skip Callback function. Gets {@link module:engine/model/treewalker~
|
|
266
|
+
* @param skip Callback function. Gets {@link module:engine/model/treewalker~ModelTreeWalkerValue} and should
|
|
266
267
|
* return `true` if the value should be skipped or `false` if not.
|
|
267
|
-
* @param options Object with configuration options. See {@link module:engine/model/treewalker~
|
|
268
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
268
269
|
*
|
|
269
270
|
* @returns The position after the last item which matches the `skip` callback test.
|
|
270
271
|
*/
|
|
271
272
|
getLastMatchingPosition(skip, options = {}) {
|
|
272
273
|
options.startPosition = this;
|
|
273
|
-
const treeWalker = new
|
|
274
|
+
const treeWalker = new ModelTreeWalker(options);
|
|
274
275
|
treeWalker.skip(skip);
|
|
275
276
|
return treeWalker.position;
|
|
276
277
|
}
|
|
277
278
|
/**
|
|
278
|
-
* Returns a path to this position's parent. Parent path is equal to position
|
|
279
|
-
* but without the last item.
|
|
279
|
+
* Returns a path to this position's parent. Parent path is equal to position
|
|
280
|
+
* {@link module:engine/model/position~ModelPosition#path path} but without the last item.
|
|
280
281
|
*
|
|
281
282
|
* This method is safe to use it on non-existing positions (for example during operational transformation).
|
|
282
283
|
*
|
|
@@ -331,7 +332,7 @@ export default class Position extends TypeCheckable {
|
|
|
331
332
|
return this.path.slice(0, diffAt);
|
|
332
333
|
}
|
|
333
334
|
/**
|
|
334
|
-
* Returns an {@link module:engine/model/element~
|
|
335
|
+
* Returns an {@link module:engine/model/element~ModelElement} or {@link module:engine/model/documentfragment~ModelDocumentFragment}
|
|
335
336
|
* which is a common ancestor of both positions. The {@link #root roots} of these two positions must be identical.
|
|
336
337
|
*
|
|
337
338
|
* @param position The second position.
|
|
@@ -365,7 +366,7 @@ export default class Position extends TypeCheckable {
|
|
|
365
366
|
*
|
|
366
367
|
* This method is safe to use it on non-existing positions (for example during operational transformation).
|
|
367
368
|
*
|
|
368
|
-
* @see module:engine/model/position~
|
|
369
|
+
* @see module:engine/model/position~ModelPosition#isBefore
|
|
369
370
|
* @param otherPosition Position to compare with.
|
|
370
371
|
* @returns True if this position is after given position.
|
|
371
372
|
*/
|
|
@@ -496,7 +497,7 @@ export default class Position extends TypeCheckable {
|
|
|
496
497
|
*
|
|
497
498
|
* The new position's parameters are updated accordingly to the effect of the `operation`.
|
|
498
499
|
*
|
|
499
|
-
* For example, if `n` nodes are inserted before the position, the returned position {@link ~
|
|
500
|
+
* For example, if `n` nodes are inserted before the position, the returned position {@link ~ModelPosition#offset} will be
|
|
500
501
|
* increased by `n`. If the position was in a merged element, it will be accordingly moved to the new element, etc.
|
|
501
502
|
*
|
|
502
503
|
* This method is safe to use it on non-existing positions (for example during operational transformation).
|
|
@@ -522,7 +523,7 @@ export default class Position extends TypeCheckable {
|
|
|
522
523
|
result = this._getTransformedByMergeOperation(operation);
|
|
523
524
|
break;
|
|
524
525
|
default:
|
|
525
|
-
result =
|
|
526
|
+
result = ModelPosition._createAt(this);
|
|
526
527
|
break;
|
|
527
528
|
}
|
|
528
529
|
return result;
|
|
@@ -581,7 +582,7 @@ export default class Position extends TypeCheckable {
|
|
|
581
582
|
}
|
|
582
583
|
}
|
|
583
584
|
else if (this.isEqual(operation.deletionPosition)) {
|
|
584
|
-
pos =
|
|
585
|
+
pos = ModelPosition._createAt(operation.deletionPosition);
|
|
585
586
|
}
|
|
586
587
|
else {
|
|
587
588
|
pos = this._getTransformedByMove(operation.deletionPosition, operation.graveyardPosition, 1);
|
|
@@ -598,7 +599,7 @@ export default class Position extends TypeCheckable {
|
|
|
598
599
|
* @returns Transformed position or `null`.
|
|
599
600
|
*/
|
|
600
601
|
_getTransformedByDeletion(deletePosition, howMany) {
|
|
601
|
-
const transformed =
|
|
602
|
+
const transformed = ModelPosition._createAt(this);
|
|
602
603
|
// This position can't be affected if deletion was in a different root.
|
|
603
604
|
if (this.root != deletePosition.root) {
|
|
604
605
|
return transformed;
|
|
@@ -644,7 +645,7 @@ export default class Position extends TypeCheckable {
|
|
|
644
645
|
* @returns Transformed position.
|
|
645
646
|
*/
|
|
646
647
|
_getTransformedByInsertion(insertPosition, howMany) {
|
|
647
|
-
const transformed =
|
|
648
|
+
const transformed = ModelPosition._createAt(this);
|
|
648
649
|
// This position can't be affected if insertion was in a different root.
|
|
649
650
|
if (this.root != insertPosition.root) {
|
|
650
651
|
return transformed;
|
|
@@ -682,7 +683,7 @@ export default class Position extends TypeCheckable {
|
|
|
682
683
|
targetPosition = targetPosition._getTransformedByDeletion(sourcePosition, howMany);
|
|
683
684
|
if (sourcePosition.isEqual(targetPosition)) {
|
|
684
685
|
// If `targetPosition` is equal to `sourcePosition` this isn't really any move. Just return position as it is.
|
|
685
|
-
return
|
|
686
|
+
return ModelPosition._createAt(this);
|
|
686
687
|
}
|
|
687
688
|
// Moving a range removes nodes from their original position. We acknowledge this by proper transformation.
|
|
688
689
|
const transformed = this._getTransformedByDeletion(sourcePosition, howMany);
|
|
@@ -733,7 +734,7 @@ export default class Position extends TypeCheckable {
|
|
|
733
734
|
_getCombined(source, target) {
|
|
734
735
|
const i = source.path.length - 1;
|
|
735
736
|
// The first part of a path to combined position is a path to the place where nodes were moved.
|
|
736
|
-
const combined =
|
|
737
|
+
const combined = ModelPosition._createAt(target);
|
|
737
738
|
combined.stickiness = this.stickiness;
|
|
738
739
|
// Then we have to update the rest of the path.
|
|
739
740
|
// Fix the offset because this position might be after `from` position and we have to reflect that.
|
|
@@ -762,23 +763,24 @@ export default class Position extends TypeCheckable {
|
|
|
762
763
|
/**
|
|
763
764
|
* Creates position at the given location. The location can be specified as:
|
|
764
765
|
*
|
|
765
|
-
* * a {@link module:engine/model/position~
|
|
766
|
+
* * a {@link module:engine/model/position~ModelPosition position},
|
|
766
767
|
* * parent element and offset (offset defaults to `0`),
|
|
767
768
|
* * parent element and `'end'` (sets position at the end of that element),
|
|
768
|
-
* * {@link module:engine/model/item~
|
|
769
|
+
* * {@link module:engine/model/item~ModelItem model item} and `'before'` or `'after'` (sets position before or after given model item).
|
|
769
770
|
*
|
|
770
771
|
* This method is a shortcut to other factory methods such as:
|
|
771
772
|
*
|
|
772
|
-
* * {@link module:engine/model/position~
|
|
773
|
-
* * {@link module:engine/model/position~
|
|
773
|
+
* * {@link module:engine/model/position~ModelPosition._createBefore},
|
|
774
|
+
* * {@link module:engine/model/position~ModelPosition._createAfter}.
|
|
774
775
|
*
|
|
775
776
|
* @internal
|
|
776
|
-
* @param offset Offset or one of the flags. Used only when the first parameter
|
|
777
|
-
*
|
|
777
|
+
* @param offset Offset or one of the flags. Used only when the first parameter
|
|
778
|
+
* is a {@link module:engine/model/item~ModelItem model item}.
|
|
779
|
+
* @param stickiness Position stickiness. Used only when the first parameter is a {@link module:engine/model/item~ModelItem model item}.
|
|
778
780
|
*/
|
|
779
781
|
static _createAt(itemOrPosition, offset, stickiness = 'toNone') {
|
|
780
782
|
if (itemOrPosition.is('model:position')) {
|
|
781
|
-
return new
|
|
783
|
+
return new ModelPosition(itemOrPosition.root, itemOrPosition.path, itemOrPosition.stickiness);
|
|
782
784
|
}
|
|
783
785
|
else {
|
|
784
786
|
const node = itemOrPosition;
|
|
@@ -814,7 +816,7 @@ export default class Position extends TypeCheckable {
|
|
|
814
816
|
}
|
|
815
817
|
}
|
|
816
818
|
/**
|
|
817
|
-
* Creates a new position, after given {@link module:engine/model/item~
|
|
819
|
+
* Creates a new position, after given {@link module:engine/model/item~ModelItem model item}.
|
|
818
820
|
*
|
|
819
821
|
* @internal
|
|
820
822
|
* @param item Item after which the position should be placed.
|
|
@@ -826,14 +828,14 @@ export default class Position extends TypeCheckable {
|
|
|
826
828
|
* You cannot make a position after a root element.
|
|
827
829
|
*
|
|
828
830
|
* @error model-position-after-root
|
|
829
|
-
* @param {module:engine/model/rootelement~
|
|
831
|
+
* @param {module:engine/model/rootelement~ModelRootElement} root The root element..
|
|
830
832
|
*/
|
|
831
833
|
throw new CKEditorError('model-position-after-root', [this, item], { root: item });
|
|
832
834
|
}
|
|
833
835
|
return this._createAt(item.parent, item.endOffset, stickiness);
|
|
834
836
|
}
|
|
835
837
|
/**
|
|
836
|
-
* Creates a new position, before the given {@link module:engine/model/item~
|
|
838
|
+
* Creates a new position, before the given {@link module:engine/model/item~ModelItem model item}.
|
|
837
839
|
*
|
|
838
840
|
* @internal
|
|
839
841
|
* @param item Item before which the position should be placed.
|
|
@@ -845,7 +847,7 @@ export default class Position extends TypeCheckable {
|
|
|
845
847
|
* You cannot make a position before a root element.
|
|
846
848
|
*
|
|
847
849
|
* @error model-position-before-root
|
|
848
|
-
* @param {module:engine/model/rootelement~
|
|
850
|
+
* @param {module:engine/model/rootelement~ModelRootElement} root The root element..
|
|
849
851
|
*/
|
|
850
852
|
throw new CKEditorError('model-position-before-root', item, { root: item });
|
|
851
853
|
}
|
|
@@ -860,7 +862,7 @@ export default class Position extends TypeCheckable {
|
|
|
860
862
|
*/
|
|
861
863
|
static fromJSON(json, doc) {
|
|
862
864
|
if (json.root === '$graveyard') {
|
|
863
|
-
const pos = new
|
|
865
|
+
const pos = new ModelPosition(doc.graveyard, json.path);
|
|
864
866
|
pos.stickiness = json.stickiness;
|
|
865
867
|
return pos;
|
|
866
868
|
}
|
|
@@ -873,12 +875,12 @@ export default class Position extends TypeCheckable {
|
|
|
873
875
|
*/
|
|
874
876
|
throw new CKEditorError('model-position-fromjson-no-root', doc, { rootName: json.root });
|
|
875
877
|
}
|
|
876
|
-
return new
|
|
878
|
+
return new ModelPosition(doc.getRoot(json.root), json.path, json.stickiness);
|
|
877
879
|
}
|
|
878
880
|
}
|
|
879
881
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
880
882
|
// Proper overload would interfere with that.
|
|
881
|
-
|
|
883
|
+
ModelPosition.prototype.is = function (type) {
|
|
882
884
|
return type === 'position' || type === 'model:position';
|
|
883
885
|
};
|
|
884
886
|
/**
|
|
@@ -886,8 +888,8 @@ Position.prototype.is = function (type) {
|
|
|
886
888
|
*
|
|
887
889
|
* This is a helper function optimized to reuse the position parent instance for performance reasons.
|
|
888
890
|
*
|
|
889
|
-
* Normally, you should use {@link module:engine/model/position~
|
|
890
|
-
* If you start hitting performance issues with {@link module:engine/model/position~
|
|
891
|
+
* Normally, you should use {@link module:engine/model/position~ModelPosition#textNode `Position#textNode`}.
|
|
892
|
+
* If you start hitting performance issues with {@link module:engine/model/position~ModelPosition#parent `Position#parent`}
|
|
891
893
|
* check if your algorithm does not access it multiple times (which can happen directly or indirectly via other position properties).
|
|
892
894
|
*
|
|
893
895
|
* See https://github.com/ckeditor/ckeditor5/issues/6579.
|
|
@@ -899,6 +901,7 @@ Position.prototype.is = function (type) {
|
|
|
899
901
|
*
|
|
900
902
|
* @param position
|
|
901
903
|
* @param positionParent The parent of the given position.
|
|
904
|
+
* @internal
|
|
902
905
|
*/
|
|
903
906
|
export function getTextNodeAtPosition(position, positionParent) {
|
|
904
907
|
const node = positionParent.getChildAtOffset(position.offset);
|
|
@@ -913,9 +916,9 @@ export function getTextNodeAtPosition(position, positionParent) {
|
|
|
913
916
|
* This is a helper function optimized to reuse the position parent instance and the calculation of the text node at the
|
|
914
917
|
* specific position for performance reasons.
|
|
915
918
|
*
|
|
916
|
-
* Normally, you should use {@link module:engine/model/position~
|
|
917
|
-
* If you start hitting performance issues with {@link module:engine/model/position~
|
|
918
|
-
* {@link module:engine/model/position~
|
|
919
|
+
* Normally, you should use {@link module:engine/model/position~ModelPosition#nodeAfter `Position#nodeAfter`}.
|
|
920
|
+
* If you start hitting performance issues with {@link module:engine/model/position~ModelPosition#parent `Position#parent`} and/or
|
|
921
|
+
* {@link module:engine/model/position~ModelPosition#textNode `Position#textNode`}
|
|
919
922
|
* check if your algorithm does not access those properties multiple times
|
|
920
923
|
* (which can happen directly or indirectly via other position properties).
|
|
921
924
|
*
|
|
@@ -929,6 +932,7 @@ export function getTextNodeAtPosition(position, positionParent) {
|
|
|
929
932
|
* @param position Position to check.
|
|
930
933
|
* @param positionParent The parent of the given position.
|
|
931
934
|
* @param textNode Text node at the given position.
|
|
935
|
+
* @internal
|
|
932
936
|
*/
|
|
933
937
|
export function getNodeAfterPosition(position, positionParent, textNode) {
|
|
934
938
|
if (textNode !== null) {
|
|
@@ -949,6 +953,7 @@ export function getNodeAfterPosition(position, positionParent, textNode) {
|
|
|
949
953
|
* @param position Position to check.
|
|
950
954
|
* @param positionParent The parent of the given position.
|
|
951
955
|
* @param textNode Text node at the given position.
|
|
956
|
+
* @internal
|
|
952
957
|
*/
|
|
953
958
|
export function getNodeBeforePosition(position, positionParent, textNode) {
|
|
954
959
|
if (textNode !== null) {
|