@ckeditor/ckeditor5-engine 45.2.1 → 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/range.js
CHANGED
|
@@ -5,20 +5,20 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/range
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import { ModelTypeCheckable } from './typecheckable.js';
|
|
9
|
+
import { ModelPosition } from './position.js';
|
|
10
|
+
import { ModelTreeWalker } from './treewalker.js';
|
|
11
11
|
import { CKEditorError, compareArrays } from '@ckeditor/ckeditor5-utils';
|
|
12
12
|
/**
|
|
13
13
|
* Represents a range in the model tree.
|
|
14
14
|
*
|
|
15
|
-
* A range is defined by its {@link module:engine/model/range~
|
|
15
|
+
* A range is defined by its {@link module:engine/model/range~ModelRange#start} and {@link module:engine/model/range~ModelRange#end}
|
|
16
16
|
* positions.
|
|
17
17
|
*
|
|
18
18
|
* You can create range instances via its constructor or the `createRange*()` factory methods of
|
|
19
|
-
* {@link module:engine/model/model~Model} and {@link module:engine/model/writer~
|
|
19
|
+
* {@link module:engine/model/model~Model} and {@link module:engine/model/writer~ModelWriter}.
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export class ModelRange extends ModelTypeCheckable {
|
|
22
22
|
/**
|
|
23
23
|
* Start position.
|
|
24
24
|
*/
|
|
@@ -35,8 +35,8 @@ export default class Range extends TypeCheckable {
|
|
|
35
35
|
*/
|
|
36
36
|
constructor(start, end) {
|
|
37
37
|
super();
|
|
38
|
-
this.start =
|
|
39
|
-
this.end = end ?
|
|
38
|
+
this.start = ModelPosition._createAt(start);
|
|
39
|
+
this.end = end ? ModelPosition._createAt(end) : ModelPosition._createAt(start);
|
|
40
40
|
// If the range is collapsed, treat in a similar way as a position and set its boundaries stickiness to 'toNone'.
|
|
41
41
|
// In other case, make the boundaries stick to the "inside" of the range.
|
|
42
42
|
this.start.stickiness = this.isCollapsed ? 'toNone' : 'toNext';
|
|
@@ -45,17 +45,17 @@ export default class Range extends TypeCheckable {
|
|
|
45
45
|
/**
|
|
46
46
|
* Iterable interface.
|
|
47
47
|
*
|
|
48
|
-
* Iterates over all {@link module:engine/model/item~
|
|
49
|
-
* them together with additional information like length or {@link module:engine/model/position~
|
|
50
|
-
* grouped as {@link module:engine/model/treewalker~
|
|
51
|
-
* It iterates over all {@link module:engine/model/textproxy~
|
|
52
|
-
* and all the {@link module:engine/model/element~
|
|
48
|
+
* Iterates over all {@link module:engine/model/item~ModelItem items} that are in this range and returns
|
|
49
|
+
* them together with additional information like length or {@link module:engine/model/position~ModelPosition positions},
|
|
50
|
+
* grouped as {@link module:engine/model/treewalker~ModelTreeWalkerValue}.
|
|
51
|
+
* It iterates over all {@link module:engine/model/textproxy~ModelTextProxy text contents} that are inside the range
|
|
52
|
+
* and all the {@link module:engine/model/element~ModelElement}s that are entered into when iterating over this range.
|
|
53
53
|
*
|
|
54
|
-
* This iterator uses {@link module:engine/model/treewalker~
|
|
54
|
+
* This iterator uses {@link module:engine/model/treewalker~ModelTreeWalker} with `boundaries` set to this range
|
|
55
55
|
* and `ignoreElementEnd` option set to `true`.
|
|
56
56
|
*/
|
|
57
57
|
*[Symbol.iterator]() {
|
|
58
|
-
yield* new
|
|
58
|
+
yield* new ModelTreeWalker({ boundaries: this, ignoreElementEnd: true });
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Describes whether the range is collapsed, that is if {@link #start} and
|
|
@@ -66,7 +66,7 @@ export default class Range extends TypeCheckable {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Describes whether this range is flat, that is if {@link #start} position and
|
|
69
|
-
* {@link #end} position are in the same {@link module:engine/model/position~
|
|
69
|
+
* {@link #end} position are in the same {@link module:engine/model/position~ModelPosition#parent}.
|
|
70
70
|
*/
|
|
71
71
|
get isFlat() {
|
|
72
72
|
const startParentPath = this.start.getParentPath();
|
|
@@ -80,23 +80,23 @@ export default class Range extends TypeCheckable {
|
|
|
80
80
|
return this.start.root;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
* Checks whether this range contains given {@link module:engine/model/position~
|
|
83
|
+
* Checks whether this range contains given {@link module:engine/model/position~ModelPosition position}.
|
|
84
84
|
*
|
|
85
85
|
* @param position Position to check.
|
|
86
|
-
* @returns `true` if given {@link module:engine/model/position~
|
|
86
|
+
* @returns `true` if given {@link module:engine/model/position~ModelPosition position} is contained
|
|
87
87
|
* in this range,`false` otherwise.
|
|
88
88
|
*/
|
|
89
89
|
containsPosition(position) {
|
|
90
90
|
return position.isAfter(this.start) && position.isBefore(this.end);
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
|
-
* Checks whether this range contains given {@link ~
|
|
93
|
+
* Checks whether this range contains given {@link ~ModelRange range}.
|
|
94
94
|
*
|
|
95
95
|
* @param otherRange Range to check.
|
|
96
96
|
* @param loose Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
|
|
97
97
|
* start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
|
|
98
98
|
* even be equal to this range. Note that collapsed ranges are always compared in strict mode.
|
|
99
|
-
* @returns {Boolean} `true` if given {@link ~
|
|
99
|
+
* @returns {Boolean} `true` if given {@link ~ModelRange range} boundaries are contained by this range, `false` otherwise.
|
|
100
100
|
*/
|
|
101
101
|
containsRange(otherRange, loose = false) {
|
|
102
102
|
if (otherRange.isCollapsed) {
|
|
@@ -107,10 +107,10 @@ export default class Range extends TypeCheckable {
|
|
|
107
107
|
return containsStart && containsEnd;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
* Checks whether given {@link module:engine/model/item~
|
|
110
|
+
* Checks whether given {@link module:engine/model/item~ModelItem} is inside this range.
|
|
111
111
|
*/
|
|
112
112
|
containsItem(item) {
|
|
113
|
-
const pos =
|
|
113
|
+
const pos = ModelPosition._createBefore(item);
|
|
114
114
|
return this.containsPosition(pos) || this.start.isEqual(pos);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -132,8 +132,8 @@ export default class Range extends TypeCheckable {
|
|
|
132
132
|
return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
|
-
* Computes which part(s) of this {@link ~
|
|
136
|
-
* Returned array contains zero, one or two {@link ~
|
|
135
|
+
* Computes which part(s) of this {@link ~ModelRange range} is not a part of given {@link ~ModelRange range}.
|
|
136
|
+
* Returned array contains zero, one or two {@link ~ModelRange ranges}.
|
|
137
137
|
*
|
|
138
138
|
* Examples:
|
|
139
139
|
*
|
|
@@ -165,22 +165,22 @@ export default class Range extends TypeCheckable {
|
|
|
165
165
|
if (this.containsPosition(otherRange.start)) {
|
|
166
166
|
// Given range start is inside this range. This means that we have to
|
|
167
167
|
// add shrunken range - from the start to the middle of this range.
|
|
168
|
-
ranges.push(new
|
|
168
|
+
ranges.push(new ModelRange(this.start, otherRange.start));
|
|
169
169
|
}
|
|
170
170
|
if (this.containsPosition(otherRange.end)) {
|
|
171
171
|
// Given range end is inside this range. This means that we have to
|
|
172
172
|
// add shrunken range - from the middle of this range to the end.
|
|
173
|
-
ranges.push(new
|
|
173
|
+
ranges.push(new ModelRange(otherRange.end, this.end));
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
177
|
// Ranges do not intersect, return the original range.
|
|
178
|
-
ranges.push(new
|
|
178
|
+
ranges.push(new ModelRange(this.start, this.end));
|
|
179
179
|
}
|
|
180
180
|
return ranges;
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
|
-
* Returns an intersection of this {@link ~
|
|
183
|
+
* Returns an intersection of this {@link ~ModelRange range} and given {@link ~ModelRange range}.
|
|
184
184
|
* Intersection is a common part of both of those ranges. If ranges has no common part, returns `null`.
|
|
185
185
|
*
|
|
186
186
|
* Examples:
|
|
@@ -216,13 +216,13 @@ export default class Range extends TypeCheckable {
|
|
|
216
216
|
// shrink common range to the given range end.
|
|
217
217
|
commonRangeEnd = otherRange.end;
|
|
218
218
|
}
|
|
219
|
-
return new
|
|
219
|
+
return new ModelRange(commonRangeStart, commonRangeEnd);
|
|
220
220
|
}
|
|
221
221
|
// Ranges do not intersect, so they do not have common part.
|
|
222
222
|
return null;
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
225
|
-
* Returns a range created by joining this {@link ~
|
|
225
|
+
* Returns a range created by joining this {@link ~ModelRange range} with the given {@link ~ModelRange range}.
|
|
226
226
|
* If ranges have no common part, returns `null`.
|
|
227
227
|
*
|
|
228
228
|
* Examples:
|
|
@@ -248,7 +248,7 @@ export default class Range extends TypeCheckable {
|
|
|
248
248
|
* @param otherRange Range to be joined.
|
|
249
249
|
* @param loose Whether the intersection check is loose or strict. If the check is strict (`false`),
|
|
250
250
|
* ranges are tested for intersection or whether start/end positions are equal. If the check is loose (`true`),
|
|
251
|
-
* compared range is also checked if it's {@link module:engine/model/position~
|
|
251
|
+
* compared range is also checked if it's {@link module:engine/model/position~ModelPosition#isTouching touching} current range.
|
|
252
252
|
* @returns A sum of given ranges or `null` if ranges have no common part.
|
|
253
253
|
*/
|
|
254
254
|
getJoined(otherRange, loose = false) {
|
|
@@ -272,7 +272,7 @@ export default class Range extends TypeCheckable {
|
|
|
272
272
|
if (otherRange.end.isAfter(endPosition)) {
|
|
273
273
|
endPosition = otherRange.end;
|
|
274
274
|
}
|
|
275
|
-
return new
|
|
275
|
+
return new ModelRange(startPosition, endPosition);
|
|
276
276
|
}
|
|
277
277
|
/**
|
|
278
278
|
* Computes and returns the smallest set of {@link #isFlat flat} ranges, that covers this range in whole.
|
|
@@ -309,7 +309,7 @@ export default class Range extends TypeCheckable {
|
|
|
309
309
|
* ( [ 3, 0, 0 ], [ 3, 0, 2 ] ) = "se"
|
|
310
310
|
* ```
|
|
311
311
|
*
|
|
312
|
-
* **Note:** if an {@link module:engine/model/element~
|
|
312
|
+
* **Note:** if an {@link module:engine/model/element~ModelElement element} is not wholly contained in this range, it won't be returned
|
|
313
313
|
* in any of the returned flat ranges. See in the example how `H` elements at the beginning and at the end of the range
|
|
314
314
|
* were omitted. Only their parts that were wholly in the range were returned.
|
|
315
315
|
*
|
|
@@ -320,13 +320,13 @@ export default class Range extends TypeCheckable {
|
|
|
320
320
|
getMinimalFlatRanges() {
|
|
321
321
|
const ranges = [];
|
|
322
322
|
const diffAt = this.start.getCommonPath(this.end).length;
|
|
323
|
-
const pos =
|
|
323
|
+
const pos = ModelPosition._createAt(this.start);
|
|
324
324
|
let posParent = pos.parent;
|
|
325
325
|
// Go up.
|
|
326
326
|
while (pos.path.length > diffAt + 1) {
|
|
327
327
|
const howMany = posParent.maxOffset - pos.offset;
|
|
328
328
|
if (howMany !== 0) {
|
|
329
|
-
ranges.push(new
|
|
329
|
+
ranges.push(new ModelRange(pos, pos.getShiftedBy(howMany)));
|
|
330
330
|
}
|
|
331
331
|
pos.path = pos.path.slice(0, -1);
|
|
332
332
|
pos.offset++;
|
|
@@ -337,7 +337,7 @@ export default class Range extends TypeCheckable {
|
|
|
337
337
|
const offset = this.end.path[pos.path.length - 1];
|
|
338
338
|
const howMany = offset - pos.offset;
|
|
339
339
|
if (howMany !== 0) {
|
|
340
|
-
ranges.push(new
|
|
340
|
+
ranges.push(new ModelRange(pos, pos.getShiftedBy(howMany)));
|
|
341
341
|
}
|
|
342
342
|
pos.offset = offset;
|
|
343
343
|
pos.path.push(0);
|
|
@@ -345,7 +345,7 @@ export default class Range extends TypeCheckable {
|
|
|
345
345
|
return ranges;
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
* Creates a {@link module:engine/model/treewalker~
|
|
348
|
+
* Creates a {@link module:engine/model/treewalker~ModelTreeWalker TreeWalker} instance with this range as a boundary.
|
|
349
349
|
*
|
|
350
350
|
* For example, to iterate over all items in the entire document root:
|
|
351
351
|
*
|
|
@@ -359,48 +359,48 @@ export default class Range extends TypeCheckable {
|
|
|
359
359
|
* }
|
|
360
360
|
* ```
|
|
361
361
|
*
|
|
362
|
-
* @param options Object with configuration options. See {@link module:engine/model/treewalker~
|
|
362
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
363
363
|
*/
|
|
364
364
|
getWalker(options = {}) {
|
|
365
365
|
options.boundaries = this;
|
|
366
|
-
return new
|
|
366
|
+
return new ModelTreeWalker(options);
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
|
-
* Returns an iterator that iterates over all {@link module:engine/model/item~
|
|
369
|
+
* Returns an iterator that iterates over all {@link module:engine/model/item~ModelItem items} that are in this range and returns
|
|
370
370
|
* them.
|
|
371
371
|
*
|
|
372
|
-
* This method uses {@link module:engine/model/treewalker~
|
|
373
|
-
* set to `true`. However it returns only {@link module:engine/model/item~
|
|
374
|
-
* not {@link module:engine/model/treewalker~
|
|
372
|
+
* This method uses {@link module:engine/model/treewalker~ModelTreeWalker} with `boundaries` set to this range and
|
|
373
|
+
* `ignoreElementEnd` option set to `true`. However it returns only {@link module:engine/model/item~ModelItem model items},
|
|
374
|
+
* not {@link module:engine/model/treewalker~ModelTreeWalkerValue}.
|
|
375
375
|
*
|
|
376
|
-
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~
|
|
376
|
+
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~ModelTreeWalker} for
|
|
377
377
|
* a full list of available options.
|
|
378
378
|
*
|
|
379
|
-
* @param options Object with configuration options. See {@link module:engine/model/treewalker~
|
|
379
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
380
380
|
*/
|
|
381
381
|
*getItems(options = {}) {
|
|
382
382
|
options.boundaries = this;
|
|
383
383
|
options.ignoreElementEnd = true;
|
|
384
|
-
const treeWalker = new
|
|
384
|
+
const treeWalker = new ModelTreeWalker(options);
|
|
385
385
|
for (const value of treeWalker) {
|
|
386
386
|
yield value.item;
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
390
|
-
* Returns an iterator that iterates over all {@link module:engine/model/position~
|
|
390
|
+
* Returns an iterator that iterates over all {@link module:engine/model/position~ModelPosition positions} that are boundaries or
|
|
391
391
|
* contained in this range.
|
|
392
392
|
*
|
|
393
|
-
* This method uses {@link module:engine/model/treewalker~
|
|
394
|
-
* {@link module:engine/model/position~
|
|
393
|
+
* This method uses {@link module:engine/model/treewalker~ModelTreeWalker} with `boundaries` set to this range. However it returns only
|
|
394
|
+
* {@link module:engine/model/position~ModelPosition positions}, not {@link module:engine/model/treewalker~ModelTreeWalkerValue}.
|
|
395
395
|
*
|
|
396
|
-
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~
|
|
396
|
+
* You may specify additional options for the tree walker. See {@link module:engine/model/treewalker~ModelTreeWalker} for
|
|
397
397
|
* a full list of available options.
|
|
398
398
|
*
|
|
399
|
-
* @param options Object with configuration options. See {@link module:engine/model/treewalker~
|
|
399
|
+
* @param options Object with configuration options. See {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
400
400
|
*/
|
|
401
401
|
*getPositions(options = {}) {
|
|
402
402
|
options.boundaries = this;
|
|
403
|
-
const treeWalker = new
|
|
403
|
+
const treeWalker = new ModelTreeWalker(options);
|
|
404
404
|
yield treeWalker.position;
|
|
405
405
|
for (const value of treeWalker) {
|
|
406
406
|
yield value.nextPosition;
|
|
@@ -429,17 +429,17 @@ export default class Range extends TypeCheckable {
|
|
|
429
429
|
case 'merge':
|
|
430
430
|
return [this._getTransformedByMergeOperation(operation)];
|
|
431
431
|
}
|
|
432
|
-
return [new
|
|
432
|
+
return [new ModelRange(this.start, this.end)];
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
435
|
* Returns a range that is a result of transforming this range by multiple `operations`.
|
|
436
436
|
*
|
|
437
|
-
* @see ~
|
|
437
|
+
* @see ~ModelRange#getTransformedByOperation
|
|
438
438
|
* @param operations Operations to transform the range by.
|
|
439
439
|
* @returns Range which is the result of transformation.
|
|
440
440
|
*/
|
|
441
441
|
getTransformedByOperations(operations) {
|
|
442
|
-
const ranges = [new
|
|
442
|
+
const ranges = [new ModelRange(this.start, this.end)];
|
|
443
443
|
for (const operation of operations) {
|
|
444
444
|
for (let i = 0; i < ranges.length; i++) {
|
|
445
445
|
const result = ranges[i].getTransformedByOperation(operation);
|
|
@@ -463,14 +463,14 @@ export default class Range extends TypeCheckable {
|
|
|
463
463
|
return ranges;
|
|
464
464
|
}
|
|
465
465
|
/**
|
|
466
|
-
* Returns an {@link module:engine/model/element~
|
|
466
|
+
* Returns an {@link module:engine/model/element~ModelElement} or {@link module:engine/model/documentfragment~ModelDocumentFragment}
|
|
467
467
|
* which is a common ancestor of the range's both ends (in which the entire range is contained).
|
|
468
468
|
*/
|
|
469
469
|
getCommonAncestor() {
|
|
470
470
|
return this.start.getCommonAncestor(this.end);
|
|
471
471
|
}
|
|
472
472
|
/**
|
|
473
|
-
* Returns an {@link module:engine/model/element~
|
|
473
|
+
* Returns an {@link module:engine/model/element~ModelElement Element} contained by the range.
|
|
474
474
|
* The element will be returned when it is the **only** node within the range and **fully–contained**
|
|
475
475
|
* at the same time.
|
|
476
476
|
*/
|
|
@@ -544,7 +544,7 @@ export default class Range extends TypeCheckable {
|
|
|
544
544
|
// Fix it by using old `end` which has proper `root`.
|
|
545
545
|
end = this.end.getShiftedBy(-1);
|
|
546
546
|
}
|
|
547
|
-
return new
|
|
547
|
+
return new ModelRange(start, end);
|
|
548
548
|
}
|
|
549
549
|
/**
|
|
550
550
|
* Returns a result of transforming a copy of this range by merge operation.
|
|
@@ -566,7 +566,7 @@ export default class Range extends TypeCheckable {
|
|
|
566
566
|
// <p>F{}z</p>
|
|
567
567
|
//
|
|
568
568
|
if (this.start.isEqual(operation.targetPosition) && this.end.isEqual(operation.deletionPosition)) {
|
|
569
|
-
return new
|
|
569
|
+
return new ModelRange(this.start);
|
|
570
570
|
}
|
|
571
571
|
let start = this.start._getTransformedByMergeOperation(operation);
|
|
572
572
|
let end = this.end._getTransformedByMergeOperation(operation);
|
|
@@ -604,7 +604,7 @@ export default class Range extends TypeCheckable {
|
|
|
604
604
|
//
|
|
605
605
|
if (operation.sourcePosition.isBefore(operation.targetPosition)) {
|
|
606
606
|
// Case 1.
|
|
607
|
-
start =
|
|
607
|
+
start = ModelPosition._createAt(end);
|
|
608
608
|
start.offset = 0;
|
|
609
609
|
}
|
|
610
610
|
else {
|
|
@@ -615,14 +615,14 @@ export default class Range extends TypeCheckable {
|
|
|
615
615
|
// In both case 2 and 3 start is at the end of the merge-to element.
|
|
616
616
|
start = operation.targetPosition;
|
|
617
617
|
}
|
|
618
|
-
return new
|
|
618
|
+
return new ModelRange(start, end);
|
|
619
619
|
}
|
|
620
|
-
return new
|
|
620
|
+
return new ModelRange(start, end);
|
|
621
621
|
}
|
|
622
622
|
/**
|
|
623
|
-
* Returns an array containing one or two {@link ~
|
|
624
|
-
* {@link ~
|
|
625
|
-
* returned if the insertion was inside this {@link ~
|
|
623
|
+
* Returns an array containing one or two {@link ~ModelRange ranges} that are a result of transforming this
|
|
624
|
+
* {@link ~ModelRange range} by inserting `howMany` nodes at `insertPosition`. Two {@link ~ModelRange ranges} are
|
|
625
|
+
* returned if the insertion was inside this {@link ~ModelRange range} and `spread` is set to `true`.
|
|
626
626
|
*
|
|
627
627
|
* Examples:
|
|
628
628
|
*
|
|
@@ -657,20 +657,20 @@ export default class Range extends TypeCheckable {
|
|
|
657
657
|
// The other part is from spread point to the original end, but transformed by
|
|
658
658
|
// insertion to reflect insertion changes.
|
|
659
659
|
return [
|
|
660
|
-
new
|
|
661
|
-
new
|
|
660
|
+
new ModelRange(this.start, insertPosition),
|
|
661
|
+
new ModelRange(insertPosition.getShiftedBy(howMany), this.end._getTransformedByInsertion(insertPosition, howMany))
|
|
662
662
|
];
|
|
663
663
|
}
|
|
664
664
|
else {
|
|
665
|
-
const range = new
|
|
665
|
+
const range = new ModelRange(this.start, this.end);
|
|
666
666
|
range.start = range.start._getTransformedByInsertion(insertPosition, howMany);
|
|
667
667
|
range.end = range.end._getTransformedByInsertion(insertPosition, howMany);
|
|
668
668
|
return [range];
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
671
|
/**
|
|
672
|
-
* Returns an array containing {@link ~
|
|
673
|
-
* {@link ~
|
|
672
|
+
* Returns an array containing {@link ~ModelRange ranges} that are a result of transforming this
|
|
673
|
+
* {@link ~ModelRange range} by moving `howMany` nodes from `sourcePosition` to `targetPosition`.
|
|
674
674
|
*
|
|
675
675
|
* @internal
|
|
676
676
|
* @param sourcePosition Position from which nodes are moved.
|
|
@@ -683,7 +683,7 @@ export default class Range extends TypeCheckable {
|
|
|
683
683
|
// Special case for transforming a collapsed range. Just transform it like a position.
|
|
684
684
|
if (this.isCollapsed) {
|
|
685
685
|
const newPos = this.start._getTransformedByMove(sourcePosition, targetPosition, howMany);
|
|
686
|
-
return [new
|
|
686
|
+
return [new ModelRange(newPos)];
|
|
687
687
|
}
|
|
688
688
|
// Special case for transformation when a part of the range is moved towards the range.
|
|
689
689
|
//
|
|
@@ -697,13 +697,13 @@ export default class Range extends TypeCheckable {
|
|
|
697
697
|
// <div><p>ab</p><p>c[d</p></div><p>e]f</p> --> <div><p>ab</p>{</div>}<p>c[d</p><p>e]f</p>
|
|
698
698
|
//
|
|
699
699
|
// This special case is applied only if the range is to be kept together (not spread).
|
|
700
|
-
const moveRange =
|
|
700
|
+
const moveRange = ModelRange._createFromPositionAndShift(sourcePosition, howMany);
|
|
701
701
|
const insertPosition = targetPosition._getTransformedByDeletion(sourcePosition, howMany);
|
|
702
702
|
if (this.containsPosition(targetPosition) && !spread) {
|
|
703
703
|
if (moveRange.containsPosition(this.start) || moveRange.containsPosition(this.end)) {
|
|
704
704
|
const start = this.start._getTransformedByMove(sourcePosition, targetPosition, howMany);
|
|
705
705
|
const end = this.end._getTransformedByMove(sourcePosition, targetPosition, howMany);
|
|
706
|
-
return [new
|
|
706
|
+
return [new ModelRange(start, end)];
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
709
|
// Default algorithm.
|
|
@@ -713,11 +713,11 @@ export default class Range extends TypeCheckable {
|
|
|
713
713
|
const common = this.getIntersection(moveRange);
|
|
714
714
|
if (differenceSet.length == 1) {
|
|
715
715
|
// `moveRange` and this range may intersect but may be separate.
|
|
716
|
-
difference = new
|
|
716
|
+
difference = new ModelRange(differenceSet[0].start._getTransformedByDeletion(sourcePosition, howMany), differenceSet[0].end._getTransformedByDeletion(sourcePosition, howMany));
|
|
717
717
|
}
|
|
718
718
|
else if (differenceSet.length == 2) {
|
|
719
719
|
// `moveRange` is inside this range.
|
|
720
|
-
difference = new
|
|
720
|
+
difference = new ModelRange(this.start, this.end._getTransformedByDeletion(sourcePosition, howMany));
|
|
721
721
|
} // else, `moveRange` contains this range.
|
|
722
722
|
if (difference) {
|
|
723
723
|
result = difference._getTransformedByInsertion(insertPosition, howMany, common !== null || spread);
|
|
@@ -726,7 +726,7 @@ export default class Range extends TypeCheckable {
|
|
|
726
726
|
result = [];
|
|
727
727
|
}
|
|
728
728
|
if (common) {
|
|
729
|
-
const transformedCommon = new
|
|
729
|
+
const transformedCommon = new ModelRange(common.start._getCombined(moveRange.start, insertPosition), common.end._getCombined(moveRange.start, insertPosition));
|
|
730
730
|
if (result.length == 2) {
|
|
731
731
|
result.splice(1, 0, transformedCommon);
|
|
732
732
|
}
|
|
@@ -760,10 +760,10 @@ export default class Range extends TypeCheckable {
|
|
|
760
760
|
if (newEnd == null) {
|
|
761
761
|
newEnd = deletePosition;
|
|
762
762
|
}
|
|
763
|
-
return new
|
|
763
|
+
return new ModelRange(newStart, newEnd);
|
|
764
764
|
}
|
|
765
765
|
/**
|
|
766
|
-
* Creates a new range, spreading from specified {@link module:engine/model/position~
|
|
766
|
+
* Creates a new range, spreading from specified {@link module:engine/model/position~ModelPosition position} to a position moved by
|
|
767
767
|
* given `shift`. If `shift` is a negative value, shifted position is treated as the beginning of the range.
|
|
768
768
|
*
|
|
769
769
|
* @internal
|
|
@@ -776,22 +776,22 @@ export default class Range extends TypeCheckable {
|
|
|
776
776
|
return shift > 0 ? new this(start, end) : new this(end, start);
|
|
777
777
|
}
|
|
778
778
|
/**
|
|
779
|
-
* Creates a range inside an {@link module:engine/model/element~
|
|
779
|
+
* Creates a range inside an {@link module:engine/model/element~ModelElement element} which starts before the first child of
|
|
780
780
|
* that element and ends after the last child of that element.
|
|
781
781
|
*
|
|
782
782
|
* @internal
|
|
783
783
|
* @param element Element which is a parent for the range.
|
|
784
784
|
*/
|
|
785
785
|
static _createIn(element) {
|
|
786
|
-
return new this(
|
|
786
|
+
return new this(ModelPosition._createAt(element, 0), ModelPosition._createAt(element, element.maxOffset));
|
|
787
787
|
}
|
|
788
788
|
/**
|
|
789
|
-
* Creates a range that starts before given {@link module:engine/model/item~
|
|
789
|
+
* Creates a range that starts before given {@link module:engine/model/item~ModelItem model item} and ends after it.
|
|
790
790
|
*
|
|
791
791
|
* @internal
|
|
792
792
|
*/
|
|
793
793
|
static _createOn(item) {
|
|
794
|
-
return this._createFromPositionAndShift(
|
|
794
|
+
return this._createFromPositionAndShift(ModelPosition._createBefore(item), item.offsetSize);
|
|
795
795
|
}
|
|
796
796
|
/**
|
|
797
797
|
* Combines all ranges from the passed array into a one range. At least one range has to be passed.
|
|
@@ -815,7 +815,7 @@ export default class Range extends TypeCheckable {
|
|
|
815
815
|
if (ranges.length === 0) {
|
|
816
816
|
/**
|
|
817
817
|
* At least one range has to be passed to
|
|
818
|
-
* {@link module:engine/model/range~
|
|
818
|
+
* {@link module:engine/model/range~ModelRange._createFromRanges `Range._createFromRanges()`}.
|
|
819
819
|
*
|
|
820
820
|
* @error range-create-from-ranges-empty-array
|
|
821
821
|
*/
|
|
@@ -842,7 +842,7 @@ export default class Range extends TypeCheckable {
|
|
|
842
842
|
// Since ranges are sorted, start with the range with index that is closest to reference range index.
|
|
843
843
|
for (let i = refIndex - 1; i >= 0; i--) {
|
|
844
844
|
if (ranges[i].end.isEqual(result.start)) {
|
|
845
|
-
result.start =
|
|
845
|
+
result.start = ModelPosition._createAt(ranges[i].start);
|
|
846
846
|
}
|
|
847
847
|
else {
|
|
848
848
|
// If ranges are not starting/ending at the same position there is no point in looking further.
|
|
@@ -853,7 +853,7 @@ export default class Range extends TypeCheckable {
|
|
|
853
853
|
// Since ranges are sorted, start with the range with index that is closest to reference range index.
|
|
854
854
|
for (let i = refIndex + 1; i < ranges.length; i++) {
|
|
855
855
|
if (ranges[i].start.isEqual(result.end)) {
|
|
856
|
-
result.end =
|
|
856
|
+
result.end = ModelPosition._createAt(ranges[i].end);
|
|
857
857
|
}
|
|
858
858
|
else {
|
|
859
859
|
// If ranges are not starting/ending at the same position there is no point in looking further.
|
|
@@ -870,11 +870,11 @@ export default class Range extends TypeCheckable {
|
|
|
870
870
|
* @returns `Range` instance created using given plain object.
|
|
871
871
|
*/
|
|
872
872
|
static fromJSON(json, doc) {
|
|
873
|
-
return new this(
|
|
873
|
+
return new this(ModelPosition.fromJSON(json.start, doc), ModelPosition.fromJSON(json.end, doc));
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
877
877
|
// Proper overload would interfere with that.
|
|
878
|
-
|
|
878
|
+
ModelRange.prototype.is = function (type) {
|
|
879
879
|
return type === 'range' || type === 'model:range';
|
|
880
880
|
};
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/rootelement
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import type
|
|
8
|
+
import { ModelElement } from './element.js';
|
|
9
|
+
import { type ModelDocument } from './document.js';
|
|
10
10
|
/**
|
|
11
|
-
* Type of {@link module:engine/model/element~
|
|
11
|
+
* Type of {@link module:engine/model/element~ModelElement} that is a root of a model tree.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export declare class ModelRootElement extends ModelElement {
|
|
14
14
|
/**
|
|
15
|
-
* Unique root name used to identify this root element by {@link module:engine/model/document~
|
|
15
|
+
* Unique root name used to identify this root element by {@link module:engine/model/document~ModelDocument}.
|
|
16
16
|
*/
|
|
17
17
|
readonly rootName: string;
|
|
18
18
|
/**
|
|
@@ -34,21 +34,21 @@ export default class RootElement extends Element {
|
|
|
34
34
|
*
|
|
35
35
|
* @param document Document that is an owner of this root.
|
|
36
36
|
* @param name Node name.
|
|
37
|
-
* @param rootName Unique root name used to identify this root element by {@link module:engine/model/document~
|
|
37
|
+
* @param rootName Unique root name used to identify this root element by {@link module:engine/model/document~ModelDocument}.
|
|
38
38
|
*/
|
|
39
|
-
constructor(document:
|
|
39
|
+
constructor(document: ModelDocument, name: string, rootName?: string);
|
|
40
40
|
/**
|
|
41
|
-
* {@link module:engine/model/document~
|
|
41
|
+
* {@link module:engine/model/document~ModelDocument Document} that owns this root element.
|
|
42
42
|
*/
|
|
43
|
-
get document():
|
|
43
|
+
get document(): ModelDocument;
|
|
44
44
|
/**
|
|
45
45
|
* Informs if the root element is currently attached to the document, or not.
|
|
46
46
|
*
|
|
47
47
|
* A detached root is equivalent to being removed and cannot contain any children or markers.
|
|
48
48
|
*
|
|
49
49
|
* By default, a newly added root is attached. It can be detached using
|
|
50
|
-
* {@link module:engine/model/writer~
|
|
51
|
-
* {@link module:engine/model/writer~
|
|
50
|
+
* {@link module:engine/model/writer~ModelWriter#detachRoot `Writer#detachRoot`}. A detached root can be re-attached again using
|
|
51
|
+
* {@link module:engine/model/writer~ModelWriter#addRoot `Writer#addRoot`}.
|
|
52
52
|
*/
|
|
53
53
|
isAttached(): boolean;
|
|
54
54
|
/**
|
package/src/model/rootelement.js
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/rootelement
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import { ModelElement } from './element.js';
|
|
9
9
|
/**
|
|
10
|
-
* Type of {@link module:engine/model/element~
|
|
10
|
+
* Type of {@link module:engine/model/element~ModelElement} that is a root of a model tree.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export class ModelRootElement extends ModelElement {
|
|
13
13
|
/**
|
|
14
|
-
* Unique root name used to identify this root element by {@link module:engine/model/document~
|
|
14
|
+
* Unique root name used to identify this root element by {@link module:engine/model/document~ModelDocument}.
|
|
15
15
|
*/
|
|
16
16
|
rootName;
|
|
17
17
|
/**
|
|
@@ -33,7 +33,7 @@ export default class RootElement extends Element {
|
|
|
33
33
|
*
|
|
34
34
|
* @param document Document that is an owner of this root.
|
|
35
35
|
* @param name Node name.
|
|
36
|
-
* @param rootName Unique root name used to identify this root element by {@link module:engine/model/document~
|
|
36
|
+
* @param rootName Unique root name used to identify this root element by {@link module:engine/model/document~ModelDocument}.
|
|
37
37
|
*/
|
|
38
38
|
constructor(document, name, rootName = 'main') {
|
|
39
39
|
super(name);
|
|
@@ -41,7 +41,7 @@ export default class RootElement extends Element {
|
|
|
41
41
|
this.rootName = rootName;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* {@link module:engine/model/document~
|
|
44
|
+
* {@link module:engine/model/document~ModelDocument Document} that owns this root element.
|
|
45
45
|
*/
|
|
46
46
|
get document() {
|
|
47
47
|
return this._document;
|
|
@@ -52,8 +52,8 @@ export default class RootElement extends Element {
|
|
|
52
52
|
* A detached root is equivalent to being removed and cannot contain any children or markers.
|
|
53
53
|
*
|
|
54
54
|
* By default, a newly added root is attached. It can be detached using
|
|
55
|
-
* {@link module:engine/model/writer~
|
|
56
|
-
* {@link module:engine/model/writer~
|
|
55
|
+
* {@link module:engine/model/writer~ModelWriter#detachRoot `Writer#detachRoot`}. A detached root can be re-attached again using
|
|
56
|
+
* {@link module:engine/model/writer~ModelWriter#addRoot `Writer#addRoot`}.
|
|
57
57
|
*/
|
|
58
58
|
isAttached() {
|
|
59
59
|
return this._isAttached;
|
|
@@ -69,7 +69,7 @@ export default class RootElement extends Element {
|
|
|
69
69
|
}
|
|
70
70
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
71
71
|
// Proper overload would interfere with that.
|
|
72
|
-
|
|
72
|
+
ModelRootElement.prototype.is = function (type, name) {
|
|
73
73
|
if (!name) {
|
|
74
74
|
return type === 'rootElement' || type === 'model:rootElement' ||
|
|
75
75
|
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|