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