@ckeditor/ckeditor5-engine 35.0.1 → 35.1.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/CHANGELOG.md +4 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +175 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +899 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +654 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +191 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
package/src/view/text.js
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/view/text
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Node from './node';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Tree view text node.
|
|
14
11
|
*
|
|
@@ -21,127 +18,106 @@ import Node from './node';
|
|
|
21
18
|
* @extends module:engine/view/node~Node
|
|
22
19
|
*/
|
|
23
20
|
export default class Text extends Node {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @type {String}
|
|
100
|
-
*/
|
|
101
|
-
get _data() {
|
|
102
|
-
return this.data;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
set _data( data ) {
|
|
106
|
-
this._fireChange( 'text', this );
|
|
107
|
-
|
|
108
|
-
this._textData = data;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Checks if this text node is similar to other text node.
|
|
113
|
-
* Both nodes should have the same data to be considered as similar.
|
|
114
|
-
*
|
|
115
|
-
* @param {module:engine/view/text~Text} otherNode Node to check if it is same as this node.
|
|
116
|
-
* @returns {Boolean}
|
|
117
|
-
*/
|
|
118
|
-
isSimilar( otherNode ) {
|
|
119
|
-
if ( !( otherNode instanceof Text ) ) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return this === otherNode || this.data === otherNode.data;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Clones this node.
|
|
128
|
-
*
|
|
129
|
-
* @protected
|
|
130
|
-
* @returns {module:engine/view/text~Text} Text node that is a clone of this node.
|
|
131
|
-
*/
|
|
132
|
-
_clone() {
|
|
133
|
-
return new Text( this.document, this.data );
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// @if CK_DEBUG_ENGINE // toString() {
|
|
137
|
-
// @if CK_DEBUG_ENGINE // return `#${ this.data }`;
|
|
138
|
-
// @if CK_DEBUG_ENGINE // }
|
|
139
|
-
|
|
140
|
-
// @if CK_DEBUG_ENGINE // log() {
|
|
141
|
-
// @if CK_DEBUG_ENGINE // console.log( 'ViewText: ' + this );
|
|
142
|
-
// @if CK_DEBUG_ENGINE // }
|
|
143
|
-
|
|
144
|
-
// @if CK_DEBUG_ENGINE // logExtended() {
|
|
145
|
-
// @if CK_DEBUG_ENGINE // console.log( 'ViewText: ' + this );
|
|
146
|
-
// @if CK_DEBUG_ENGINE // }
|
|
21
|
+
/**
|
|
22
|
+
* Creates a tree view text node.
|
|
23
|
+
*
|
|
24
|
+
* @protected
|
|
25
|
+
* @param {module:engine/view/document~Document} document The document instance to which this text node belongs.
|
|
26
|
+
* @param {String} data The text's data.
|
|
27
|
+
*/
|
|
28
|
+
constructor(document, data) {
|
|
29
|
+
super(document);
|
|
30
|
+
/**
|
|
31
|
+
* The text content.
|
|
32
|
+
*
|
|
33
|
+
* Setting the data fires the {@link module:engine/view/node~Node#event:change:text change event}.
|
|
34
|
+
*
|
|
35
|
+
* @protected
|
|
36
|
+
* @member {String} module:engine/view/text~Text#_textData
|
|
37
|
+
*/
|
|
38
|
+
this._textData = data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The text content.
|
|
42
|
+
*
|
|
43
|
+
* @readonly
|
|
44
|
+
* @type {String}
|
|
45
|
+
*/
|
|
46
|
+
get data() {
|
|
47
|
+
return this._textData;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The `_data` property is controlled by a getter and a setter.
|
|
51
|
+
*
|
|
52
|
+
* The getter is required when using the addition assignment operator on protected property:
|
|
53
|
+
*
|
|
54
|
+
* const foo = downcastWriter.createText( 'foo' );
|
|
55
|
+
* const bar = downcastWriter.createText( 'bar' );
|
|
56
|
+
*
|
|
57
|
+
* foo._data += bar.data; // executes: `foo._data = foo._data + bar.data`
|
|
58
|
+
* console.log( foo.data ); // prints: 'foobar'
|
|
59
|
+
*
|
|
60
|
+
* If the protected getter didn't exist, `foo._data` will return `undefined` and result of the merge will be invalid.
|
|
61
|
+
*
|
|
62
|
+
* The setter sets data and fires the {@link module:engine/view/node~Node#event:change:text change event}.
|
|
63
|
+
*
|
|
64
|
+
* @protected
|
|
65
|
+
* @type {String}
|
|
66
|
+
*/
|
|
67
|
+
get _data() {
|
|
68
|
+
return this.data;
|
|
69
|
+
}
|
|
70
|
+
set _data(data) {
|
|
71
|
+
this._fireChange('text', this);
|
|
72
|
+
this._textData = data;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks if this text node is similar to other text node.
|
|
76
|
+
* Both nodes should have the same data to be considered as similar.
|
|
77
|
+
*
|
|
78
|
+
* @param {module:engine/view/node~Node} otherNode Node to check if it is same as this node.
|
|
79
|
+
* @returns {Boolean}
|
|
80
|
+
*/
|
|
81
|
+
isSimilar(otherNode) {
|
|
82
|
+
if (!(otherNode instanceof Text)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return this === otherNode || this.data === otherNode.data;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Clones this node.
|
|
89
|
+
*
|
|
90
|
+
* @protected
|
|
91
|
+
* @returns {module:engine/view/text~Text} Text node that is a clone of this node.
|
|
92
|
+
*/
|
|
93
|
+
_clone() {
|
|
94
|
+
return new Text(this.document, this.data);
|
|
95
|
+
}
|
|
147
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Checks whether this object is of the given type.
|
|
99
|
+
*
|
|
100
|
+
* text.is( '$text' ); // -> true
|
|
101
|
+
* text.is( 'node' ); // -> true
|
|
102
|
+
* text.is( 'view:$text' ); // -> true
|
|
103
|
+
* text.is( 'view:node' ); // -> true
|
|
104
|
+
*
|
|
105
|
+
* text.is( 'model:$text' ); // -> false
|
|
106
|
+
* text.is( 'element' ); // -> false
|
|
107
|
+
* text.is( 'range' ); // -> false
|
|
108
|
+
*
|
|
109
|
+
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
110
|
+
*
|
|
111
|
+
* **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
|
|
112
|
+
* accepted for backward compatibility.
|
|
113
|
+
*
|
|
114
|
+
* @param {String} type Type to check.
|
|
115
|
+
* @returns {Boolean}
|
|
116
|
+
*/
|
|
117
|
+
Text.prototype.is = function (type) {
|
|
118
|
+
return type === '$text' || type === 'view:$text' ||
|
|
119
|
+
// This are legacy values kept for backward compatibility.
|
|
120
|
+
type === 'text' || type === 'view:text' ||
|
|
121
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
122
|
+
type === 'node' || type === 'view:node';
|
|
123
|
+
};
|
package/src/view/textproxy.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/view/textproxy
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
import TypeCheckable from './typecheckable';
|
|
10
9
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
11
|
-
|
|
12
10
|
/**
|
|
13
11
|
* TextProxy is a wrapper for substring of {@link module:engine/view/text~Text}. Instance of this class is created by
|
|
14
12
|
* {@link module:engine/view/treewalker~TreeWalker} when only a part of {@link module:engine/view/text~Text} needs to be returned.
|
|
@@ -29,171 +27,147 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
29
27
|
* `TextProxy` instances are created by {@link module:engine/view/treewalker~TreeWalker view tree walker}. You should not need to create
|
|
30
28
|
* an instance of this class by your own.
|
|
31
29
|
*/
|
|
32
|
-
export default class TextProxy {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
154
|
-
*
|
|
155
|
-
* **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxy'` type is still
|
|
156
|
-
* accepted for backward compatibility.
|
|
157
|
-
*
|
|
158
|
-
* @param {String} type Type to check.
|
|
159
|
-
* @returns {Boolean}
|
|
160
|
-
*/
|
|
161
|
-
is( type ) {
|
|
162
|
-
return type === '$textProxy' || type === 'view:$textProxy' ||
|
|
163
|
-
// This are legacy values kept for backward compatibility.
|
|
164
|
-
type === 'textProxy' || type === 'view:textProxy';
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Returns ancestors array of this text proxy.
|
|
169
|
-
*
|
|
170
|
-
* @param {Object} options Options object.
|
|
171
|
-
* @param {Boolean} [options.includeSelf=false] When set to `true` {#textNode} will be also included in parent's array.
|
|
172
|
-
* @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from text proxy parent to
|
|
173
|
-
* root element, otherwise root element will be the first item in the array.
|
|
174
|
-
* @returns {Array} Array with ancestors.
|
|
175
|
-
*/
|
|
176
|
-
getAncestors( options = { includeSelf: false, parentFirst: false } ) {
|
|
177
|
-
const ancestors = [];
|
|
178
|
-
let parent = options.includeSelf ? this.textNode : this.parent;
|
|
179
|
-
|
|
180
|
-
while ( parent !== null ) {
|
|
181
|
-
ancestors[ options.parentFirst ? 'push' : 'unshift' ]( parent );
|
|
182
|
-
parent = parent.parent;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return ancestors;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// @if CK_DEBUG_ENGINE // toString() {
|
|
189
|
-
// @if CK_DEBUG_ENGINE // return `#${ this.data }`;
|
|
190
|
-
// @if CK_DEBUG_ENGINE // }
|
|
191
|
-
|
|
192
|
-
// @if CK_DEBUG_ENGINE // log() {
|
|
193
|
-
// @if CK_DEBUG_ENGINE // console.log( 'ViewTextProxy: ' + this );
|
|
194
|
-
// @if CK_DEBUG_ENGINE // }
|
|
195
|
-
|
|
196
|
-
// @if CK_DEBUG_ENGINE // logExtended() {
|
|
197
|
-
// @if CK_DEBUG_ENGINE // console.log( 'ViewTextProxy: ' + this );
|
|
198
|
-
// @if CK_DEBUG_ENGINE // }
|
|
30
|
+
export default class TextProxy extends TypeCheckable {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a text proxy.
|
|
33
|
+
*
|
|
34
|
+
* @protected
|
|
35
|
+
* @param {module:engine/view/text~Text} textNode Text node which part is represented by this text proxy.
|
|
36
|
+
* @param {Number} offsetInText Offset in {@link module:engine/view/textproxy~TextProxy#textNode text node}
|
|
37
|
+
* from which the text proxy starts.
|
|
38
|
+
* @param {Number} length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
|
|
39
|
+
* @constructor
|
|
40
|
+
*/
|
|
41
|
+
constructor(textNode, offsetInText, length) {
|
|
42
|
+
super();
|
|
43
|
+
/**
|
|
44
|
+
* Reference to the {@link module:engine/view/text~Text} element which TextProxy is a substring.
|
|
45
|
+
*
|
|
46
|
+
* @readonly
|
|
47
|
+
* @member {module:engine/view/text~Text} module:engine/view/textproxy~TextProxy#textNode
|
|
48
|
+
*/
|
|
49
|
+
this.textNode = textNode;
|
|
50
|
+
if (offsetInText < 0 || offsetInText > textNode.data.length) {
|
|
51
|
+
/**
|
|
52
|
+
* Given offsetInText value is incorrect.
|
|
53
|
+
*
|
|
54
|
+
* @error view-textproxy-wrong-offsetintext
|
|
55
|
+
*/
|
|
56
|
+
throw new CKEditorError('view-textproxy-wrong-offsetintext', this);
|
|
57
|
+
}
|
|
58
|
+
if (length < 0 || offsetInText + length > textNode.data.length) {
|
|
59
|
+
/**
|
|
60
|
+
* Given length value is incorrect.
|
|
61
|
+
*
|
|
62
|
+
* @error view-textproxy-wrong-length
|
|
63
|
+
*/
|
|
64
|
+
throw new CKEditorError('view-textproxy-wrong-length', this);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Text data represented by this text proxy.
|
|
68
|
+
*
|
|
69
|
+
* @readonly
|
|
70
|
+
* @member {String} module:engine/view/textproxy~TextProxy#data
|
|
71
|
+
*/
|
|
72
|
+
this.data = textNode.data.substring(offsetInText, offsetInText + length);
|
|
73
|
+
/**
|
|
74
|
+
* Offset in the `textNode` where this `TextProxy` instance starts.
|
|
75
|
+
*
|
|
76
|
+
* @readonly
|
|
77
|
+
* @member {Number} module:engine/view/textproxy~TextProxy#offsetInText
|
|
78
|
+
*/
|
|
79
|
+
this.offsetInText = offsetInText;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Offset size of this node.
|
|
83
|
+
*
|
|
84
|
+
* @readonly
|
|
85
|
+
* @type {Number}
|
|
86
|
+
*/
|
|
87
|
+
get offsetSize() {
|
|
88
|
+
return this.data.length;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Flag indicating whether `TextProxy` instance covers only part of the original {@link module:engine/view/text~Text text node}
|
|
92
|
+
* (`true`) or the whole text node (`false`).
|
|
93
|
+
*
|
|
94
|
+
* This is `false` when text proxy starts at the very beginning of {@link module:engine/view/textproxy~TextProxy#textNode textNode}
|
|
95
|
+
* ({@link module:engine/view/textproxy~TextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
|
|
96
|
+
* text node size.
|
|
97
|
+
*
|
|
98
|
+
* @readonly
|
|
99
|
+
* @type {Boolean}
|
|
100
|
+
*/
|
|
101
|
+
get isPartial() {
|
|
102
|
+
return this.data.length !== this.textNode.data.length;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parent of this text proxy, which is same as parent of text node represented by this text proxy.
|
|
106
|
+
*
|
|
107
|
+
* @readonly
|
|
108
|
+
* @type {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
|
|
109
|
+
*/
|
|
110
|
+
get parent() {
|
|
111
|
+
return this.textNode.parent;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Root of this text proxy, which is same as root of text node represented by this text proxy.
|
|
115
|
+
*
|
|
116
|
+
* @readonly
|
|
117
|
+
* @type {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
|
|
118
|
+
*/
|
|
119
|
+
get root() {
|
|
120
|
+
return this.textNode.root;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* {@link module:engine/view/document~Document View document} that owns this text proxy, or `null` if the text proxy is inside
|
|
124
|
+
* {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
|
|
125
|
+
*
|
|
126
|
+
* @readonly
|
|
127
|
+
* @type {module:engine/view/document~Document|null}
|
|
128
|
+
*/
|
|
129
|
+
get document() {
|
|
130
|
+
return this.textNode.document;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns ancestors array of this text proxy.
|
|
134
|
+
*
|
|
135
|
+
* @param {Object} options Options object.
|
|
136
|
+
* @param {Boolean} [options.includeSelf=false] When set to `true` {#textNode} will be also included in parent's array.
|
|
137
|
+
* @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from text proxy parent to
|
|
138
|
+
* root element, otherwise root element will be the first item in the array.
|
|
139
|
+
* @returns {Array} Array with ancestors.
|
|
140
|
+
*/
|
|
141
|
+
getAncestors(options = {}) {
|
|
142
|
+
const ancestors = [];
|
|
143
|
+
let parent = options.includeSelf ? this.textNode : this.parent;
|
|
144
|
+
while (parent !== null) {
|
|
145
|
+
ancestors[options.parentFirst ? 'push' : 'unshift'](parent);
|
|
146
|
+
parent = parent.parent;
|
|
147
|
+
}
|
|
148
|
+
return ancestors;
|
|
149
|
+
}
|
|
199
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Checks whether this object is of the given type.
|
|
153
|
+
*
|
|
154
|
+
* textProxy.is( '$textProxy' ); // -> true
|
|
155
|
+
* textProxy.is( 'view:$textProxy' ); // -> true
|
|
156
|
+
*
|
|
157
|
+
* textProxy.is( 'model:$textProxy' ); // -> false
|
|
158
|
+
* textProxy.is( 'element' ); // -> false
|
|
159
|
+
* textProxy.is( 'range' ); // -> false
|
|
160
|
+
*
|
|
161
|
+
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
162
|
+
*
|
|
163
|
+
* **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxy'` type is still
|
|
164
|
+
* accepted for backward compatibility.
|
|
165
|
+
*
|
|
166
|
+
* @param {String} type Type to check.
|
|
167
|
+
* @returns {Boolean}
|
|
168
|
+
*/
|
|
169
|
+
TextProxy.prototype.is = function (type) {
|
|
170
|
+
return type === '$textProxy' || type === 'view:$textProxy' ||
|
|
171
|
+
// This are legacy values kept for backward compatibility.
|
|
172
|
+
type === 'textProxy' || type === 'view:textProxy';
|
|
173
|
+
};
|