@ckeditor/ckeditor5-engine 43.2.0 → 43.3.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.css.map +1 -1
- package/dist/index.js +149 -72
- package/dist/index.js.map +1 -1
- package/dist/model/documentfragment.d.ts +8 -1
- package/dist/model/element.d.ts +11 -1
- package/dist/model/node.d.ts +20 -17
- package/dist/model/nodelist.d.ts +23 -8
- package/dist/model/position.d.ts +9 -2
- package/package.json +2 -2
- package/src/model/document.js +2 -1
- package/src/model/documentfragment.d.ts +8 -1
- package/src/model/documentfragment.js +12 -3
- package/src/model/element.d.ts +11 -1
- package/src/model/element.js +15 -3
- package/src/model/node.d.ts +20 -17
- package/src/model/node.js +24 -30
- package/src/model/nodelist.d.ts +23 -8
- package/src/model/nodelist.js +78 -30
- package/src/model/position.d.ts +9 -2
- package/src/model/position.js +24 -5
- package/src/view/domconverter.js +3 -1
|
@@ -97,10 +97,17 @@ export default class DocumentFragment extends TypeCheckable implements Iterable<
|
|
|
97
97
|
/**
|
|
98
98
|
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
99
99
|
*
|
|
100
|
-
* @param index Index
|
|
100
|
+
* @param index Index in this document fragment.
|
|
101
101
|
* @returns Child node.
|
|
102
102
|
*/
|
|
103
103
|
getChild(index: number): Node | null;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
106
|
+
*
|
|
107
|
+
* @param offset Offset in this document fragment.
|
|
108
|
+
* @returns Child node.
|
|
109
|
+
*/
|
|
110
|
+
getChildAtOffset(offset: number): Node | null;
|
|
104
111
|
/**
|
|
105
112
|
* Returns an iterator that iterates over all of this document fragment's children.
|
|
106
113
|
*/
|
package/dist/model/element.d.ts
CHANGED
|
@@ -51,9 +51,19 @@ export default class Element extends Node {
|
|
|
51
51
|
*/
|
|
52
52
|
get isEmpty(): boolean;
|
|
53
53
|
/**
|
|
54
|
-
* Gets the child at the given index.
|
|
54
|
+
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
55
|
+
*
|
|
56
|
+
* @param index Index in this element.
|
|
57
|
+
* @returns Child node.
|
|
55
58
|
*/
|
|
56
59
|
getChild(index: number): Node | null;
|
|
60
|
+
/**
|
|
61
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
62
|
+
*
|
|
63
|
+
* @param offset Offset in this element.
|
|
64
|
+
* @returns Child node.
|
|
65
|
+
*/
|
|
66
|
+
getChildAtOffset(offset: number): Node | null;
|
|
57
67
|
/**
|
|
58
68
|
* Returns an iterator that iterates over all of this element's children.
|
|
59
69
|
*/
|
package/dist/model/node.d.ts
CHANGED
|
@@ -56,6 +56,18 @@ export default abstract class Node extends TypeCheckable {
|
|
|
56
56
|
* Attributes set on this node.
|
|
57
57
|
*/
|
|
58
58
|
private _attrs;
|
|
59
|
+
/**
|
|
60
|
+
* Index of this node in its parent or `null` if the node has no parent.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
_index: number | null;
|
|
65
|
+
/**
|
|
66
|
+
* Offset at which this node starts in its parent or `null` if the node has no parent.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
_startOffset: number | null;
|
|
59
71
|
/**
|
|
60
72
|
* Creates a model node.
|
|
61
73
|
*
|
|
@@ -70,28 +82,24 @@ export default abstract class Node extends TypeCheckable {
|
|
|
70
82
|
get document(): Document | null;
|
|
71
83
|
/**
|
|
72
84
|
* Index of this node in its parent or `null` if the node has no parent.
|
|
73
|
-
*
|
|
74
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
75
|
-
* This means that model tree got broken.
|
|
76
85
|
*/
|
|
77
86
|
get index(): number | null;
|
|
78
87
|
/**
|
|
79
88
|
* Offset at which this node starts in its parent. It is equal to the sum of {@link #offsetSize offsetSize}
|
|
80
89
|
* of all its previous siblings. Equals to `null` if node has no parent.
|
|
81
|
-
*
|
|
82
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
83
|
-
* This means that model tree got broken.
|
|
84
90
|
*/
|
|
85
91
|
get startOffset(): number | null;
|
|
86
92
|
/**
|
|
87
|
-
* Offset size of this node.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
93
|
+
* Offset size of this node.
|
|
94
|
+
*
|
|
95
|
+
* Represents how much "offset space" is occupied by the node in its parent. It is important for
|
|
96
|
+
* {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position can be placed between
|
|
97
|
+
* that node start and end. `offsetSize` greater than `1` is for nodes that represents more than one entity, i.e.
|
|
98
|
+
* a {@link module:engine/model/text~Text text node}.
|
|
91
99
|
*/
|
|
92
100
|
get offsetSize(): number;
|
|
93
101
|
/**
|
|
94
|
-
* Offset at which this node ends in
|
|
102
|
+
* Offset at which this node ends in its parent. It is equal to the sum of this node's
|
|
95
103
|
* {@link module:engine/model/node~Node#startOffset start offset} and {@link #offsetSize offset size}.
|
|
96
104
|
* Equals to `null` if the node has no parent.
|
|
97
105
|
*/
|
|
@@ -208,7 +216,7 @@ export default abstract class Node extends TypeCheckable {
|
|
|
208
216
|
*/
|
|
209
217
|
_clone(_deep?: boolean): Node;
|
|
210
218
|
/**
|
|
211
|
-
* Removes this node from
|
|
219
|
+
* Removes this node from its parent.
|
|
212
220
|
*
|
|
213
221
|
* @internal
|
|
214
222
|
* @see module:engine/model/writer~Writer#remove
|
|
@@ -248,11 +256,6 @@ export default abstract class Node extends TypeCheckable {
|
|
|
248
256
|
*/
|
|
249
257
|
_clearAttributes(): void;
|
|
250
258
|
}
|
|
251
|
-
/**
|
|
252
|
-
* The node's parent does not contain this node.
|
|
253
|
-
*
|
|
254
|
-
* @error model-node-not-found-in-parent
|
|
255
|
-
*/
|
|
256
259
|
/**
|
|
257
260
|
* Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
258
261
|
*/
|
package/dist/model/nodelist.d.ts
CHANGED
|
@@ -21,7 +21,15 @@ export default class NodeList implements Iterable<Node> {
|
|
|
21
21
|
*/
|
|
22
22
|
private _nodes;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* This array maps numbers (offsets) to node that is placed at that offset.
|
|
25
|
+
*
|
|
26
|
+
* This array is similar to `_nodes` with the difference that one node may occupy multiple consecutive items in the array.
|
|
27
|
+
*
|
|
28
|
+
* This array is needed to quickly retrieve a node that is placed at given offset.
|
|
29
|
+
*/
|
|
30
|
+
private _offsetToNode;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a node list.
|
|
25
33
|
*
|
|
26
34
|
* @internal
|
|
27
35
|
* @param nodes Nodes contained in this node list.
|
|
@@ -46,26 +54,33 @@ export default class NodeList implements Iterable<Node> {
|
|
|
46
54
|
*/
|
|
47
55
|
getNode(index: number): Node | null;
|
|
48
56
|
/**
|
|
49
|
-
*
|
|
57
|
+
* Gets the node at the given offset. Returns `null` if incorrect offset was passed.
|
|
58
|
+
*/
|
|
59
|
+
getNodeAtOffset(offset: number): Node | null;
|
|
60
|
+
/**
|
|
61
|
+
* Returns an index of the given node or `null` if given node does not have a parent.
|
|
62
|
+
*
|
|
63
|
+
* This is an alias to {@link module:engine/model/node~Node#index}.
|
|
50
64
|
*/
|
|
51
65
|
getNodeIndex(node: Node): number | null;
|
|
52
66
|
/**
|
|
53
|
-
* Returns the
|
|
54
|
-
*
|
|
67
|
+
* Returns the offset at which given node is placed in its parent or `null` if given node does not have a parent.
|
|
68
|
+
*
|
|
69
|
+
* This is an alias to {@link module:engine/model/node~Node#startOffset}.
|
|
55
70
|
*/
|
|
56
71
|
getNodeStartOffset(node: Node): number | null;
|
|
57
72
|
/**
|
|
58
73
|
* Converts index to offset in node list.
|
|
59
74
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
75
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-index-out-of-bounds` if given index is less
|
|
76
|
+
* than `0` or more than {@link #length}.
|
|
62
77
|
*/
|
|
63
78
|
indexToOffset(index: number): number;
|
|
64
79
|
/**
|
|
65
80
|
* Converts offset in node list to index.
|
|
66
81
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
82
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-offset-out-of-bounds` if given offset is less
|
|
83
|
+
* than `0` or more than {@link #maxOffset}.
|
|
69
84
|
*/
|
|
70
85
|
offsetToIndex(offset: number): number;
|
|
71
86
|
/**
|
package/dist/model/position.d.ts
CHANGED
|
@@ -128,11 +128,11 @@ export default class Position extends TypeCheckable {
|
|
|
128
128
|
*/
|
|
129
129
|
get textNode(): Text | null;
|
|
130
130
|
/**
|
|
131
|
-
* Node directly after this position
|
|
131
|
+
* Node directly after this position. Returns `null` if this position is at the end of its parent, or if it is in a text node.
|
|
132
132
|
*/
|
|
133
133
|
get nodeAfter(): Node | null;
|
|
134
134
|
/**
|
|
135
|
-
* Node directly before this position
|
|
135
|
+
* Node directly before this position. Returns `null` if this position is at the start of its parent, or if it is in a text node.
|
|
136
136
|
*/
|
|
137
137
|
get nodeBefore(): Node | null;
|
|
138
138
|
/**
|
|
@@ -143,6 +143,10 @@ export default class Position extends TypeCheckable {
|
|
|
143
143
|
* Is `true` if position is at the end of its {@link module:engine/model/position~Position#parent parent}, `false` otherwise.
|
|
144
144
|
*/
|
|
145
145
|
get isAtEnd(): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Checks whether the position is valid in current model tree, that is whether it points to an existing place in the model.
|
|
148
|
+
*/
|
|
149
|
+
isValid(): boolean;
|
|
146
150
|
/**
|
|
147
151
|
* Checks whether this position is before or after given position.
|
|
148
152
|
*
|
|
@@ -500,6 +504,7 @@ export type PositionStickiness = 'toNone' | 'toNext' | 'toPrevious';
|
|
|
500
504
|
* * {@link module:engine/model/position~getNodeAfterPosition}
|
|
501
505
|
* * {@link module:engine/model/position~getNodeBeforePosition}
|
|
502
506
|
*
|
|
507
|
+
* @param position
|
|
503
508
|
* @param positionParent The parent of the given position.
|
|
504
509
|
*/
|
|
505
510
|
export declare function getTextNodeAtPosition(position: Position, positionParent: Element | DocumentFragment): Text | null;
|
|
@@ -522,6 +527,7 @@ export declare function getTextNodeAtPosition(position: Position, positionParent
|
|
|
522
527
|
* * {@link module:engine/model/position~getTextNodeAtPosition}
|
|
523
528
|
* * {@link module:engine/model/position~getNodeBeforePosition}
|
|
524
529
|
*
|
|
530
|
+
* @param position Position to check.
|
|
525
531
|
* @param positionParent The parent of the given position.
|
|
526
532
|
* @param textNode Text node at the given position.
|
|
527
533
|
*/
|
|
@@ -536,6 +542,7 @@ export declare function getNodeAfterPosition(position: Position, positionParent:
|
|
|
536
542
|
* * {@link module:engine/model/position~getTextNodeAtPosition}
|
|
537
543
|
* * {@link module:engine/model/position~getNodeAfterPosition}
|
|
538
544
|
*
|
|
545
|
+
* @param position Position to check.
|
|
539
546
|
* @param positionParent The parent of the given position.
|
|
540
547
|
* @param textNode Text node at the given position.
|
|
541
548
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-engine",
|
|
3
|
-
"version": "43.
|
|
3
|
+
"version": "43.3.0-alpha.0",
|
|
4
4
|
"description": "The editing engine of CKEditor 5 – the best browser-based rich text editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wysiwyg",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"type": "module",
|
|
25
25
|
"main": "src/index.js",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@ckeditor/ckeditor5-utils": "43.
|
|
27
|
+
"@ckeditor/ckeditor5-utils": "43.3.0-alpha.0",
|
|
28
28
|
"lodash-es": "4.17.21"
|
|
29
29
|
},
|
|
30
30
|
"author": "CKSource (http://cksource.com/)",
|
package/src/model/document.js
CHANGED
|
@@ -319,7 +319,8 @@ export default class Document extends /* #__PURE__ */ EmitterMixin() {
|
|
|
319
319
|
* @returns `true` if `range` is valid, `false` otherwise.
|
|
320
320
|
*/
|
|
321
321
|
_validateSelectionRange(range) {
|
|
322
|
-
return
|
|
322
|
+
return range.start.isValid() && range.end.isValid() &&
|
|
323
|
+
validateTextNodePosition(range.start) && validateTextNodePosition(range.end);
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
325
326
|
* Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
|
|
@@ -93,10 +93,17 @@ export default class DocumentFragment extends TypeCheckable implements Iterable<
|
|
|
93
93
|
/**
|
|
94
94
|
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
95
95
|
*
|
|
96
|
-
* @param index Index
|
|
96
|
+
* @param index Index in this document fragment.
|
|
97
97
|
* @returns Child node.
|
|
98
98
|
*/
|
|
99
99
|
getChild(index: number): Node | null;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
102
|
+
*
|
|
103
|
+
* @param offset Offset in this document fragment.
|
|
104
|
+
* @returns Child node.
|
|
105
|
+
*/
|
|
106
|
+
getChildAtOffset(offset: number): Node | null;
|
|
100
107
|
/**
|
|
101
108
|
* Returns an iterator that iterates over all of this document fragment's children.
|
|
102
109
|
*/
|
|
@@ -115,12 +115,21 @@ export default class DocumentFragment extends TypeCheckable {
|
|
|
115
115
|
/**
|
|
116
116
|
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
117
117
|
*
|
|
118
|
-
* @param index Index
|
|
118
|
+
* @param index Index in this document fragment.
|
|
119
119
|
* @returns Child node.
|
|
120
120
|
*/
|
|
121
121
|
getChild(index) {
|
|
122
122
|
return this._children.getNode(index);
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
126
|
+
*
|
|
127
|
+
* @param offset Offset in this document fragment.
|
|
128
|
+
* @returns Child node.
|
|
129
|
+
*/
|
|
130
|
+
getChildAtOffset(offset) {
|
|
131
|
+
return this._children.getNodeAtOffset(offset);
|
|
132
|
+
}
|
|
124
133
|
/**
|
|
125
134
|
* Returns an iterator that iterates over all of this document fragment's children.
|
|
126
135
|
*/
|
|
@@ -168,8 +177,8 @@ export default class DocumentFragment extends TypeCheckable {
|
|
|
168
177
|
getNodeByPath(relativePath) {
|
|
169
178
|
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
170
179
|
let node = this;
|
|
171
|
-
for (const
|
|
172
|
-
node = node.
|
|
180
|
+
for (const offset of relativePath) {
|
|
181
|
+
node = node.getChildAtOffset(offset);
|
|
173
182
|
}
|
|
174
183
|
return node;
|
|
175
184
|
}
|
package/src/model/element.d.ts
CHANGED
|
@@ -47,9 +47,19 @@ export default class Element extends Node {
|
|
|
47
47
|
*/
|
|
48
48
|
get isEmpty(): boolean;
|
|
49
49
|
/**
|
|
50
|
-
* Gets the child at the given index.
|
|
50
|
+
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
51
|
+
*
|
|
52
|
+
* @param index Index in this element.
|
|
53
|
+
* @returns Child node.
|
|
51
54
|
*/
|
|
52
55
|
getChild(index: number): Node | null;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
58
|
+
*
|
|
59
|
+
* @param offset Offset in this element.
|
|
60
|
+
* @returns Child node.
|
|
61
|
+
*/
|
|
62
|
+
getChildAtOffset(offset: number): Node | null;
|
|
53
63
|
/**
|
|
54
64
|
* Returns an iterator that iterates over all of this element's children.
|
|
55
65
|
*/
|
package/src/model/element.js
CHANGED
|
@@ -59,11 +59,23 @@ export default class Element extends Node {
|
|
|
59
59
|
return this.childCount === 0;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Gets the child at the given index.
|
|
62
|
+
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
63
|
+
*
|
|
64
|
+
* @param index Index in this element.
|
|
65
|
+
* @returns Child node.
|
|
63
66
|
*/
|
|
64
67
|
getChild(index) {
|
|
65
68
|
return this._children.getNode(index);
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
72
|
+
*
|
|
73
|
+
* @param offset Offset in this element.
|
|
74
|
+
* @returns Child node.
|
|
75
|
+
*/
|
|
76
|
+
getChildAtOffset(offset) {
|
|
77
|
+
return this._children.getNodeAtOffset(offset);
|
|
78
|
+
}
|
|
67
79
|
/**
|
|
68
80
|
* Returns an iterator that iterates over all of this element's children.
|
|
69
81
|
*/
|
|
@@ -124,8 +136,8 @@ export default class Element extends Node {
|
|
|
124
136
|
getNodeByPath(relativePath) {
|
|
125
137
|
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
126
138
|
let node = this;
|
|
127
|
-
for (const
|
|
128
|
-
node = node.
|
|
139
|
+
for (const offset of relativePath) {
|
|
140
|
+
node = node.getChildAtOffset(offset);
|
|
129
141
|
}
|
|
130
142
|
return node;
|
|
131
143
|
}
|
package/src/model/node.d.ts
CHANGED
|
@@ -52,6 +52,18 @@ export default abstract class Node extends TypeCheckable {
|
|
|
52
52
|
* Attributes set on this node.
|
|
53
53
|
*/
|
|
54
54
|
private _attrs;
|
|
55
|
+
/**
|
|
56
|
+
* Index of this node in its parent or `null` if the node has no parent.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
_index: number | null;
|
|
61
|
+
/**
|
|
62
|
+
* Offset at which this node starts in its parent or `null` if the node has no parent.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
_startOffset: number | null;
|
|
55
67
|
/**
|
|
56
68
|
* Creates a model node.
|
|
57
69
|
*
|
|
@@ -66,28 +78,24 @@ export default abstract class Node extends TypeCheckable {
|
|
|
66
78
|
get document(): Document | null;
|
|
67
79
|
/**
|
|
68
80
|
* Index of this node in its parent or `null` if the node has no parent.
|
|
69
|
-
*
|
|
70
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
71
|
-
* This means that model tree got broken.
|
|
72
81
|
*/
|
|
73
82
|
get index(): number | null;
|
|
74
83
|
/**
|
|
75
84
|
* Offset at which this node starts in its parent. It is equal to the sum of {@link #offsetSize offsetSize}
|
|
76
85
|
* of all its previous siblings. Equals to `null` if node has no parent.
|
|
77
|
-
*
|
|
78
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
79
|
-
* This means that model tree got broken.
|
|
80
86
|
*/
|
|
81
87
|
get startOffset(): number | null;
|
|
82
88
|
/**
|
|
83
|
-
* Offset size of this node.
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
89
|
+
* Offset size of this node.
|
|
90
|
+
*
|
|
91
|
+
* Represents how much "offset space" is occupied by the node in its parent. It is important for
|
|
92
|
+
* {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position can be placed between
|
|
93
|
+
* that node start and end. `offsetSize` greater than `1` is for nodes that represents more than one entity, i.e.
|
|
94
|
+
* a {@link module:engine/model/text~Text text node}.
|
|
87
95
|
*/
|
|
88
96
|
get offsetSize(): number;
|
|
89
97
|
/**
|
|
90
|
-
* Offset at which this node ends in
|
|
98
|
+
* Offset at which this node ends in its parent. It is equal to the sum of this node's
|
|
91
99
|
* {@link module:engine/model/node~Node#startOffset start offset} and {@link #offsetSize offset size}.
|
|
92
100
|
* Equals to `null` if the node has no parent.
|
|
93
101
|
*/
|
|
@@ -204,7 +212,7 @@ export default abstract class Node extends TypeCheckable {
|
|
|
204
212
|
*/
|
|
205
213
|
_clone(_deep?: boolean): Node;
|
|
206
214
|
/**
|
|
207
|
-
* Removes this node from
|
|
215
|
+
* Removes this node from its parent.
|
|
208
216
|
*
|
|
209
217
|
* @internal
|
|
210
218
|
* @see module:engine/model/writer~Writer#remove
|
|
@@ -244,11 +252,6 @@ export default abstract class Node extends TypeCheckable {
|
|
|
244
252
|
*/
|
|
245
253
|
_clearAttributes(): void;
|
|
246
254
|
}
|
|
247
|
-
/**
|
|
248
|
-
* The node's parent does not contain this node.
|
|
249
|
-
*
|
|
250
|
-
* @error model-node-not-found-in-parent
|
|
251
|
-
*/
|
|
252
255
|
/**
|
|
253
256
|
* Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
254
257
|
*/
|
package/src/model/node.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module engine/model/node
|
|
8
8
|
*/
|
|
9
9
|
import TypeCheckable from './typecheckable.js';
|
|
10
|
-
import {
|
|
10
|
+
import { compareArrays, toMap } from '@ckeditor/ckeditor5-utils';
|
|
11
11
|
/**
|
|
12
12
|
* Model node. Most basic structure of model tree.
|
|
13
13
|
*
|
|
@@ -52,6 +52,18 @@ export default class Node extends TypeCheckable {
|
|
|
52
52
|
* Equals to `null` if the node has no parent.
|
|
53
53
|
*/
|
|
54
54
|
this.parent = null;
|
|
55
|
+
/**
|
|
56
|
+
* Index of this node in its parent or `null` if the node has no parent.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
this._index = null;
|
|
61
|
+
/**
|
|
62
|
+
* Offset at which this node starts in its parent or `null` if the node has no parent.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
this._startOffset = null;
|
|
55
67
|
this._attrs = toMap(attrs);
|
|
56
68
|
}
|
|
57
69
|
/**
|
|
@@ -62,53 +74,35 @@ export default class Node extends TypeCheckable {
|
|
|
62
74
|
}
|
|
63
75
|
/**
|
|
64
76
|
* Index of this node in its parent or `null` if the node has no parent.
|
|
65
|
-
*
|
|
66
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
67
|
-
* This means that model tree got broken.
|
|
68
77
|
*/
|
|
69
78
|
get index() {
|
|
70
|
-
|
|
71
|
-
if (!this.parent) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if ((pos = this.parent.getChildIndex(this)) === null) {
|
|
75
|
-
throw new CKEditorError('model-node-not-found-in-parent', this);
|
|
76
|
-
}
|
|
77
|
-
return pos;
|
|
79
|
+
return this._index;
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
82
|
* Offset at which this node starts in its parent. It is equal to the sum of {@link #offsetSize offsetSize}
|
|
81
83
|
* of all its previous siblings. Equals to `null` if node has no parent.
|
|
82
|
-
*
|
|
83
|
-
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
84
|
-
* This means that model tree got broken.
|
|
85
84
|
*/
|
|
86
85
|
get startOffset() {
|
|
87
|
-
|
|
88
|
-
if (!this.parent) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
if ((pos = this.parent.getChildStartOffset(this)) === null) {
|
|
92
|
-
throw new CKEditorError('model-node-not-found-in-parent', this);
|
|
93
|
-
}
|
|
94
|
-
return pos;
|
|
86
|
+
return this._startOffset;
|
|
95
87
|
}
|
|
96
88
|
/**
|
|
97
|
-
* Offset size of this node.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
89
|
+
* Offset size of this node.
|
|
90
|
+
*
|
|
91
|
+
* Represents how much "offset space" is occupied by the node in its parent. It is important for
|
|
92
|
+
* {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position can be placed between
|
|
93
|
+
* that node start and end. `offsetSize` greater than `1` is for nodes that represents more than one entity, i.e.
|
|
94
|
+
* a {@link module:engine/model/text~Text text node}.
|
|
101
95
|
*/
|
|
102
96
|
get offsetSize() {
|
|
103
97
|
return 1;
|
|
104
98
|
}
|
|
105
99
|
/**
|
|
106
|
-
* Offset at which this node ends in
|
|
100
|
+
* Offset at which this node ends in its parent. It is equal to the sum of this node's
|
|
107
101
|
* {@link module:engine/model/node~Node#startOffset start offset} and {@link #offsetSize offset size}.
|
|
108
102
|
* Equals to `null` if the node has no parent.
|
|
109
103
|
*/
|
|
110
104
|
get endOffset() {
|
|
111
|
-
if (
|
|
105
|
+
if (this.startOffset === null) {
|
|
112
106
|
return null;
|
|
113
107
|
}
|
|
114
108
|
return this.startOffset + this.offsetSize;
|
|
@@ -316,7 +310,7 @@ export default class Node extends TypeCheckable {
|
|
|
316
310
|
return new this.constructor(this._attrs);
|
|
317
311
|
}
|
|
318
312
|
/**
|
|
319
|
-
* Removes this node from
|
|
313
|
+
* Removes this node from its parent.
|
|
320
314
|
*
|
|
321
315
|
* @internal
|
|
322
316
|
* @see module:engine/model/writer~Writer#remove
|
package/src/model/nodelist.d.ts
CHANGED
|
@@ -17,7 +17,15 @@ export default class NodeList implements Iterable<Node> {
|
|
|
17
17
|
*/
|
|
18
18
|
private _nodes;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* This array maps numbers (offsets) to node that is placed at that offset.
|
|
21
|
+
*
|
|
22
|
+
* This array is similar to `_nodes` with the difference that one node may occupy multiple consecutive items in the array.
|
|
23
|
+
*
|
|
24
|
+
* This array is needed to quickly retrieve a node that is placed at given offset.
|
|
25
|
+
*/
|
|
26
|
+
private _offsetToNode;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a node list.
|
|
21
29
|
*
|
|
22
30
|
* @internal
|
|
23
31
|
* @param nodes Nodes contained in this node list.
|
|
@@ -42,26 +50,33 @@ export default class NodeList implements Iterable<Node> {
|
|
|
42
50
|
*/
|
|
43
51
|
getNode(index: number): Node | null;
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
53
|
+
* Gets the node at the given offset. Returns `null` if incorrect offset was passed.
|
|
54
|
+
*/
|
|
55
|
+
getNodeAtOffset(offset: number): Node | null;
|
|
56
|
+
/**
|
|
57
|
+
* Returns an index of the given node or `null` if given node does not have a parent.
|
|
58
|
+
*
|
|
59
|
+
* This is an alias to {@link module:engine/model/node~Node#index}.
|
|
46
60
|
*/
|
|
47
61
|
getNodeIndex(node: Node): number | null;
|
|
48
62
|
/**
|
|
49
|
-
* Returns the
|
|
50
|
-
*
|
|
63
|
+
* Returns the offset at which given node is placed in its parent or `null` if given node does not have a parent.
|
|
64
|
+
*
|
|
65
|
+
* This is an alias to {@link module:engine/model/node~Node#startOffset}.
|
|
51
66
|
*/
|
|
52
67
|
getNodeStartOffset(node: Node): number | null;
|
|
53
68
|
/**
|
|
54
69
|
* Converts index to offset in node list.
|
|
55
70
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
71
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-index-out-of-bounds` if given index is less
|
|
72
|
+
* than `0` or more than {@link #length}.
|
|
58
73
|
*/
|
|
59
74
|
indexToOffset(index: number): number;
|
|
60
75
|
/**
|
|
61
76
|
* Converts offset in node list to index.
|
|
62
77
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
78
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-offset-out-of-bounds` if given offset is less
|
|
79
|
+
* than `0` or more than {@link #maxOffset}.
|
|
65
80
|
*/
|
|
66
81
|
offsetToIndex(offset: number): number;
|
|
67
82
|
/**
|