@ckeditor/ckeditor5-engine 35.4.0 → 36.0.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/LICENSE.md +1 -1
- package/package.json +22 -22
- package/src/controller/datacontroller.js +5 -1
- package/src/controller/editingcontroller.js +1 -1
- package/src/conversion/conversion.js +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +1 -1
- package/src/conversion/downcasthelpers.js +1 -1
- package/src/conversion/mapper.js +1 -1
- package/src/conversion/modelconsumable.js +1 -1
- package/src/conversion/upcastdispatcher.js +1 -1
- package/src/conversion/upcasthelpers.js +8 -1
- package/src/conversion/viewconsumable.js +1 -1
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.js +1 -1
- package/src/dataprocessor/htmldataprocessor.js +1 -2
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +1 -1
- package/src/dev-utils/model.js +1 -1
- package/src/dev-utils/operationreplayer.js +1 -1
- package/src/dev-utils/utils.js +1 -1
- package/src/dev-utils/view.js +1 -1
- package/src/index.js +3 -2
- package/src/model/batch.js +9 -46
- package/src/model/differ.js +81 -174
- package/src/model/document.js +36 -92
- package/src/model/documentfragment.js +43 -96
- package/src/model/documentselection.js +151 -245
- package/src/model/element.js +47 -100
- package/src/model/history.js +15 -46
- package/src/model/item.js +1 -1
- package/src/model/liveposition.js +10 -36
- package/src/model/liverange.js +13 -36
- package/src/model/markercollection.js +40 -111
- package/src/model/model.js +212 -289
- package/src/model/node.js +35 -125
- package/src/model/nodelist.js +11 -39
- package/src/model/operation/attributeoperation.js +13 -44
- package/src/model/operation/detachoperation.js +3 -16
- package/src/model/operation/insertoperation.js +6 -34
- package/src/model/operation/markeroperation.js +9 -48
- package/src/model/operation/mergeoperation.js +8 -41
- package/src/model/operation/moveoperation.js +14 -37
- package/src/model/operation/nooperation.js +1 -7
- package/src/model/operation/operation.js +5 -63
- package/src/model/operation/operationfactory.js +3 -6
- package/src/model/operation/renameoperation.js +8 -28
- package/src/model/operation/rootattributeoperation.js +18 -47
- package/src/model/operation/splitoperation.js +9 -47
- package/src/model/operation/transform.js +109 -150
- package/src/model/operation/utils.js +36 -50
- package/src/model/position.js +117 -228
- package/src/model/range.js +145 -200
- package/src/model/rootelement.js +8 -47
- package/src/model/schema.js +236 -272
- package/src/model/selection.js +134 -192
- package/src/model/text.js +10 -37
- package/src/model/textproxy.js +15 -69
- package/src/model/treewalker.js +10 -101
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.js +11 -12
- package/src/model/utils/deletecontent.js +93 -62
- package/src/model/utils/findoptimalinsertionrange.js +24 -24
- package/src/model/utils/getselectedcontent.js +3 -6
- package/src/model/utils/insertcontent.js +36 -129
- package/src/model/utils/insertobject.js +19 -21
- package/src/model/utils/modifyselection.js +23 -33
- package/src/model/utils/selection-post-fixer.js +53 -59
- package/src/model/writer.js +208 -314
- package/src/view/attributeelement.js +1 -1
- package/src/view/containerelement.js +1 -1
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.js +1 -17
- package/src/view/documentfragment.js +49 -1
- package/src/view/documentselection.js +1 -1
- package/src/view/domconverter.js +4 -3
- package/src/view/downcastwriter.js +1 -1
- package/src/view/editableelement.js +1 -1
- package/src/view/element.js +5 -5
- package/src/view/elementdefinition.js +1 -1
- package/src/view/emptyelement.js +1 -1
- package/src/view/filler.js +1 -1
- package/src/view/item.js +1 -1
- package/src/view/matcher.js +1 -1
- package/src/view/node.js +1 -1
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +1 -1
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.js +1 -1
- package/src/view/observer/compositionobserver.js +1 -1
- package/src/view/observer/domeventdata.js +1 -1
- package/src/view/observer/domeventobserver.js +1 -1
- package/src/view/observer/fakeselectionobserver.js +1 -1
- package/src/view/observer/focusobserver.js +22 -4
- package/src/view/observer/inputobserver.js +1 -1
- package/src/view/observer/keyobserver.js +1 -1
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +1 -1
- package/src/view/observer/selectionobserver.js +13 -2
- package/src/view/observer/tabobserver.js +1 -1
- package/src/view/placeholder.js +1 -1
- package/src/view/position.js +1 -1
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +1 -1
- package/src/view/renderer.js +1 -14
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +1 -1
- package/src/view/styles/background.js +1 -1
- package/src/view/styles/border.js +1 -1
- package/src/view/styles/margin.js +1 -1
- package/src/view/styles/padding.js +1 -1
- package/src/view/styles/utils.js +1 -1
- package/src/view/stylesmap.js +1 -1
- package/src/view/text.js +1 -1
- package/src/view/textproxy.js +1 -1
- package/src/view/treewalker.js +1 -1
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.js +1 -1
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +5 -5
- package/theme/placeholder.css +1 -1
- package/theme/renderer.css +1 -1
package/src/model/text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -27,18 +27,12 @@ export default class Text extends Node {
|
|
|
27
27
|
* **Note:** Constructor of this class shouldn't be used directly in the code.
|
|
28
28
|
* Use the {@link module:engine/model/writer~Writer#createText} method instead.
|
|
29
29
|
*
|
|
30
|
-
* @
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
30
|
+
* @internal
|
|
31
|
+
* @param data Node's text.
|
|
32
|
+
* @param attrs Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
33
33
|
*/
|
|
34
34
|
constructor(data, attrs) {
|
|
35
35
|
super(attrs);
|
|
36
|
-
/**
|
|
37
|
-
* Text data contained in this text node.
|
|
38
|
-
*
|
|
39
|
-
* @protected
|
|
40
|
-
* @type {String}
|
|
41
|
-
*/
|
|
42
36
|
this._data = data || '';
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
@@ -49,9 +43,6 @@ export default class Text extends Node {
|
|
|
49
43
|
}
|
|
50
44
|
/**
|
|
51
45
|
* Returns a text data contained in the node.
|
|
52
|
-
*
|
|
53
|
-
* @readonly
|
|
54
|
-
* @type {String}
|
|
55
46
|
*/
|
|
56
47
|
get data() {
|
|
57
48
|
return this._data;
|
|
@@ -59,7 +50,7 @@ export default class Text extends Node {
|
|
|
59
50
|
/**
|
|
60
51
|
* Converts `Text` instance to plain object and returns it.
|
|
61
52
|
*
|
|
62
|
-
* @returns
|
|
53
|
+
* @returns`Text` instance converted to plain object.
|
|
63
54
|
*/
|
|
64
55
|
toJSON() {
|
|
65
56
|
const json = super.toJSON();
|
|
@@ -70,8 +61,7 @@ export default class Text extends Node {
|
|
|
70
61
|
* Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
|
|
71
62
|
*
|
|
72
63
|
* @internal
|
|
73
|
-
* @
|
|
74
|
-
* @returns {module:engine/model/text~Text} `Text` instance created using given plain object.
|
|
64
|
+
* @returns `Text` instance created using given plain object.
|
|
75
65
|
*/
|
|
76
66
|
_clone() {
|
|
77
67
|
return new Text(this.data, this.getAttributes());
|
|
@@ -79,32 +69,15 @@ export default class Text extends Node {
|
|
|
79
69
|
/**
|
|
80
70
|
* Creates a `Text` instance from given plain object (i.e. parsed JSON string).
|
|
81
71
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @returns
|
|
72
|
+
* @param json Plain object to be converted to `Text`.
|
|
73
|
+
* @returns `Text` instance created using given plain object.
|
|
84
74
|
*/
|
|
85
75
|
static fromJSON(json) {
|
|
86
76
|
return new Text(json.data, json.attributes);
|
|
87
77
|
}
|
|
88
78
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
* text.is( '$text' ); // -> true
|
|
93
|
-
* text.is( 'node' ); // -> true
|
|
94
|
-
* text.is( 'model:$text' ); // -> true
|
|
95
|
-
* text.is( 'model:node' ); // -> true
|
|
96
|
-
*
|
|
97
|
-
* text.is( 'view:$text' ); // -> false
|
|
98
|
-
* text.is( 'documentSelection' ); // -> false
|
|
99
|
-
*
|
|
100
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
101
|
-
*
|
|
102
|
-
* **Note:** Until version 20.0.0 this method wasn't accepting `'$text'` type. The legacy `'text'` type is still
|
|
103
|
-
* accepted for backward compatibility.
|
|
104
|
-
*
|
|
105
|
-
* @param {String} type Type to check.
|
|
106
|
-
* @returns {Boolean}
|
|
107
|
-
*/
|
|
79
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
80
|
+
// Proper overload would interfere with that.
|
|
108
81
|
Text.prototype.is = function (type) {
|
|
109
82
|
return type === '$text' || type === 'model:$text' ||
|
|
110
83
|
// This are legacy values kept for backward compatibility.
|
package/src/model/textproxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -41,21 +41,14 @@ export default class TextProxy extends TypeCheckable {
|
|
|
41
41
|
/**
|
|
42
42
|
* Creates a text proxy.
|
|
43
43
|
*
|
|
44
|
-
* @
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
44
|
+
* @internal
|
|
45
|
+
* @param textNode Text node which part is represented by this text proxy.
|
|
46
|
+
* @param offsetInText Offset in {@link module:engine/model/textproxy~TextProxy#textNode text node} from which the text proxy
|
|
47
47
|
* starts.
|
|
48
|
-
* @param
|
|
49
|
-
* @constructor
|
|
48
|
+
* @param length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
|
|
50
49
|
*/
|
|
51
50
|
constructor(textNode, offsetInText, length) {
|
|
52
51
|
super();
|
|
53
|
-
/**
|
|
54
|
-
* Text node which part is represented by this text proxy.
|
|
55
|
-
*
|
|
56
|
-
* @readonly
|
|
57
|
-
* @member {module:engine/model/text~Text}
|
|
58
|
-
*/
|
|
59
52
|
this.textNode = textNode;
|
|
60
53
|
if (offsetInText < 0 || offsetInText > textNode.offsetSize) {
|
|
61
54
|
/**
|
|
@@ -73,27 +66,13 @@ export default class TextProxy extends TypeCheckable {
|
|
|
73
66
|
*/
|
|
74
67
|
throw new CKEditorError('model-textproxy-wrong-length', this);
|
|
75
68
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Text data represented by this text proxy.
|
|
78
|
-
*
|
|
79
|
-
* @readonly
|
|
80
|
-
* @member {String}
|
|
81
|
-
*/
|
|
82
69
|
this.data = textNode.data.substring(offsetInText, offsetInText + length);
|
|
83
|
-
/**
|
|
84
|
-
* Offset in {@link module:engine/model/textproxy~TextProxy#textNode text node} from which the text proxy starts.
|
|
85
|
-
*
|
|
86
|
-
* @readonly
|
|
87
|
-
* @member {Number}
|
|
88
|
-
*/
|
|
89
70
|
this.offsetInText = offsetInText;
|
|
90
71
|
}
|
|
91
72
|
/**
|
|
92
73
|
* Offset at which this text proxy starts in it's parent.
|
|
93
74
|
*
|
|
94
75
|
* @see module:engine/model/node~Node#startOffset
|
|
95
|
-
* @readonly
|
|
96
|
-
* @type {Number|null}
|
|
97
76
|
*/
|
|
98
77
|
get startOffset() {
|
|
99
78
|
return this.textNode.startOffset !== null ? this.textNode.startOffset + this.offsetInText : null;
|
|
@@ -102,8 +81,6 @@ export default class TextProxy extends TypeCheckable {
|
|
|
102
81
|
* Offset size of this text proxy. Equal to the number of characters represented by the text proxy.
|
|
103
82
|
*
|
|
104
83
|
* @see module:engine/model/node~Node#offsetSize
|
|
105
|
-
* @readonly
|
|
106
|
-
* @type {Number}
|
|
107
84
|
*/
|
|
108
85
|
get offsetSize() {
|
|
109
86
|
return this.data.length;
|
|
@@ -112,8 +89,6 @@ export default class TextProxy extends TypeCheckable {
|
|
|
112
89
|
* Offset at which this text proxy ends in it's parent.
|
|
113
90
|
*
|
|
114
91
|
* @see module:engine/model/node~Node#endOffset
|
|
115
|
-
* @readonly
|
|
116
|
-
* @type {Number|null}
|
|
117
92
|
*/
|
|
118
93
|
get endOffset() {
|
|
119
94
|
return this.startOffset !== null ? this.startOffset + this.offsetSize : null;
|
|
@@ -125,27 +100,18 @@ export default class TextProxy extends TypeCheckable {
|
|
|
125
100
|
* This is `false` when text proxy starts at the very beginning of {@link module:engine/model/textproxy~TextProxy#textNode textNode}
|
|
126
101
|
* ({@link module:engine/model/textproxy~TextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
|
|
127
102
|
* text node size.
|
|
128
|
-
*
|
|
129
|
-
* @readonly
|
|
130
|
-
* @type {Boolean}
|
|
131
103
|
*/
|
|
132
104
|
get isPartial() {
|
|
133
105
|
return this.offsetSize !== this.textNode.offsetSize;
|
|
134
106
|
}
|
|
135
107
|
/**
|
|
136
108
|
* Parent of this text proxy, which is same as parent of text node represented by this text proxy.
|
|
137
|
-
*
|
|
138
|
-
* @readonly
|
|
139
|
-
* @type {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
|
|
140
109
|
*/
|
|
141
110
|
get parent() {
|
|
142
111
|
return this.textNode.parent;
|
|
143
112
|
}
|
|
144
113
|
/**
|
|
145
114
|
* Root of this text proxy, which is same as root of text node represented by this text proxy.
|
|
146
|
-
*
|
|
147
|
-
* @readonly
|
|
148
|
-
* @type {module:engine/model/node~Node|module:engine/model/documentfragment~DocumentFragment}
|
|
149
115
|
*/
|
|
150
116
|
get root() {
|
|
151
117
|
return this.textNode.root;
|
|
@@ -154,7 +120,6 @@ export default class TextProxy extends TypeCheckable {
|
|
|
154
120
|
* Gets path to this text proxy.
|
|
155
121
|
*
|
|
156
122
|
* @see module:engine/model/node~Node#getPath
|
|
157
|
-
* @returns {Array.<Number>}
|
|
158
123
|
*/
|
|
159
124
|
getPath() {
|
|
160
125
|
const path = this.textNode.getPath();
|
|
@@ -166,11 +131,11 @@ export default class TextProxy extends TypeCheckable {
|
|
|
166
131
|
/**
|
|
167
132
|
* Returns ancestors array of this text proxy.
|
|
168
133
|
*
|
|
169
|
-
* @param
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
134
|
+
* @param options Options object.
|
|
135
|
+
* @param options.includeSelf When set to `true` this text proxy will be also included in parent's array.
|
|
136
|
+
* @param options.parentFirst When set to `true`, array will be sorted from text proxy parent to root element,
|
|
172
137
|
* otherwise root element will be the first item in the array.
|
|
173
|
-
* @returns
|
|
138
|
+
* @returns Array with ancestors.
|
|
174
139
|
*/
|
|
175
140
|
getAncestors(options = {}) {
|
|
176
141
|
const ancestors = [];
|
|
@@ -184,8 +149,8 @@ export default class TextProxy extends TypeCheckable {
|
|
|
184
149
|
/**
|
|
185
150
|
* Checks if this text proxy has an attribute for given key.
|
|
186
151
|
*
|
|
187
|
-
* @param
|
|
188
|
-
* @returns
|
|
152
|
+
* @param key Key of attribute to check.
|
|
153
|
+
* @returns `true` if attribute with given key is set on text proxy, `false` otherwise.
|
|
189
154
|
*/
|
|
190
155
|
hasAttribute(key) {
|
|
191
156
|
return this.textNode.hasAttribute(key);
|
|
@@ -193,8 +158,8 @@ export default class TextProxy extends TypeCheckable {
|
|
|
193
158
|
/**
|
|
194
159
|
* Gets an attribute value for given key or `undefined` if that attribute is not set on text proxy.
|
|
195
160
|
*
|
|
196
|
-
* @param
|
|
197
|
-
* @returns
|
|
161
|
+
* @param key Key of attribute to look for.
|
|
162
|
+
* @returns Attribute value or `undefined`.
|
|
198
163
|
*/
|
|
199
164
|
getAttribute(key) {
|
|
200
165
|
return this.textNode.getAttribute(key);
|
|
@@ -204,38 +169,19 @@ export default class TextProxy extends TypeCheckable {
|
|
|
204
169
|
* items. First one is attribute key and second is attribute value.
|
|
205
170
|
*
|
|
206
171
|
* This format is accepted by native `Map` object and also can be passed in `Node` constructor.
|
|
207
|
-
*
|
|
208
|
-
* @returns {Iterable.<*>}
|
|
209
172
|
*/
|
|
210
173
|
getAttributes() {
|
|
211
174
|
return this.textNode.getAttributes();
|
|
212
175
|
}
|
|
213
176
|
/**
|
|
214
177
|
* Returns iterator that iterates over this node's attribute keys.
|
|
215
|
-
*
|
|
216
|
-
* @returns {Iterable.<String>}
|
|
217
178
|
*/
|
|
218
179
|
getAttributeKeys() {
|
|
219
180
|
return this.textNode.getAttributeKeys();
|
|
220
181
|
}
|
|
221
182
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
* textProxy.is( '$textProxy' ); // -> true
|
|
226
|
-
* textProxy.is( 'model:$textProxy' ); // -> true
|
|
227
|
-
*
|
|
228
|
-
* textProxy.is( 'view:$textProxy' ); // -> false
|
|
229
|
-
* textProxy.is( 'range' ); // -> false
|
|
230
|
-
*
|
|
231
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
232
|
-
*
|
|
233
|
-
* **Note:** Until version 20.0.0 this method wasn't accepting `'$textProxy'` type. The legacy `'textProxt'` type is still
|
|
234
|
-
* accepted for backward compatibility.
|
|
235
|
-
*
|
|
236
|
-
* @param {String} type Type to check.
|
|
237
|
-
* @returns {Boolean}
|
|
238
|
-
*/
|
|
183
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
184
|
+
// Proper overload would interfere with that.
|
|
239
185
|
TextProxy.prototype.is = function (type) {
|
|
240
186
|
return type === '$textProxy' || type === 'model:$textProxy' ||
|
|
241
187
|
// This are legacy values kept for backward compatibility.
|
package/src/model/treewalker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -17,23 +17,10 @@ export default class TreeWalker {
|
|
|
17
17
|
/**
|
|
18
18
|
* Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
19
19
|
*
|
|
20
|
-
* @
|
|
21
|
-
* @param {Object} [options={}] Object with configuration.
|
|
22
|
-
* @param {'forward'|'backward'} [options.direction='forward'] Walking direction.
|
|
23
|
-
* @param {module:engine/model/range~Range|null} [options.boundaries=null] Range to define boundaries of the iterator.
|
|
24
|
-
* @param {module:engine/model/position~Position} [options.startPosition] Starting position.
|
|
25
|
-
* @param {Boolean} [options.singleCharacters=false] Flag indicating whether all consecutive characters with the same attributes
|
|
26
|
-
* should be returned one by one as multiple {@link module:engine/model/textproxy~TextProxy} (`true`) objects or as one
|
|
27
|
-
* {@link module:engine/model/textproxy~TextProxy} (`false`).
|
|
28
|
-
* @param {Boolean} [options.shallow=false] Flag indicating whether iterator should enter elements or not. If the
|
|
29
|
-
* iterator is shallow child nodes of any iterated node will not be returned along with `elementEnd` tag.
|
|
30
|
-
* @param {Boolean} [options.ignoreElementEnd=false] Flag indicating whether iterator should ignore `elementEnd`
|
|
31
|
-
* tags. If the option is true walker will not return a parent node of start position. If this option is `true`
|
|
32
|
-
* each {@link module:engine/model/element~Element} will be returned once, while if the option is `false` they might be returned
|
|
33
|
-
* twice: for `'elementStart'` and `'elementEnd'`.
|
|
20
|
+
* @param options Object with configuration.
|
|
34
21
|
*/
|
|
35
|
-
constructor(options
|
|
36
|
-
if (!options.boundaries && !options.startPosition) {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
if (!options || (!options.boundaries && !options.startPosition)) {
|
|
37
24
|
/**
|
|
38
25
|
* Neither boundaries nor starting position of a `TreeWalker` have been defined.
|
|
39
26
|
*
|
|
@@ -50,34 +37,8 @@ export default class TreeWalker {
|
|
|
50
37
|
*/
|
|
51
38
|
throw new CKEditorError('model-tree-walker-unknown-direction', options, { direction });
|
|
52
39
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Walking direction. Defaults `'forward'`.
|
|
55
|
-
*
|
|
56
|
-
* @readonly
|
|
57
|
-
* @member {'backward'|'forward'} module:engine/model/treewalker~TreeWalker#direction
|
|
58
|
-
*/
|
|
59
40
|
this.direction = direction;
|
|
60
|
-
/**
|
|
61
|
-
* Iterator boundaries.
|
|
62
|
-
*
|
|
63
|
-
* When the iterator is walking `'forward'` on the end of boundary or is walking `'backward'`
|
|
64
|
-
* on the start of boundary, then `{ done: true }` is returned.
|
|
65
|
-
*
|
|
66
|
-
* If boundaries are not defined they are set before first and after last child of the root node.
|
|
67
|
-
*
|
|
68
|
-
* @readonly
|
|
69
|
-
* @member {module:engine/model/range~Range|null} module:engine/model/treewalker~TreeWalker#boundaries
|
|
70
|
-
*/
|
|
71
41
|
this.boundaries = options.boundaries || null;
|
|
72
|
-
/**
|
|
73
|
-
* Iterator position. This is always static position, even if the initial position was a
|
|
74
|
-
* {@link module:engine/model/liveposition~LivePosition live position}. If start position is not defined then position depends
|
|
75
|
-
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
76
|
-
* is `'backward'` position starts from the end.
|
|
77
|
-
*
|
|
78
|
-
* @readonly
|
|
79
|
-
* @member {module:engine/model/position~Position} module:engine/model/treewalker~TreeWalker#position
|
|
80
|
-
*/
|
|
81
42
|
if (options.startPosition) {
|
|
82
43
|
this.position = options.startPosition.clone();
|
|
83
44
|
}
|
|
@@ -86,53 +47,11 @@ export default class TreeWalker {
|
|
|
86
47
|
}
|
|
87
48
|
// Reset position stickiness in case it was set to other value, as the stickiness is kept after cloning.
|
|
88
49
|
this.position.stickiness = 'toNone';
|
|
89
|
-
/**
|
|
90
|
-
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
91
|
-
* returned as one {@link module:engine/model/textproxy~TextProxy} (`true`) or one by one (`false`).
|
|
92
|
-
*
|
|
93
|
-
* @readonly
|
|
94
|
-
* @member {Boolean} module:engine/model/treewalker~TreeWalker#singleCharacters
|
|
95
|
-
*/
|
|
96
50
|
this.singleCharacters = !!options.singleCharacters;
|
|
97
|
-
/**
|
|
98
|
-
* Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any
|
|
99
|
-
* iterated node will not be returned along with `elementEnd` tag.
|
|
100
|
-
*
|
|
101
|
-
* @readonly
|
|
102
|
-
* @member {Boolean} module:engine/model/treewalker~TreeWalker#shallow
|
|
103
|
-
*/
|
|
104
51
|
this.shallow = !!options.shallow;
|
|
105
|
-
/**
|
|
106
|
-
* Flag indicating whether iterator should ignore `elementEnd` tags. If the option is true walker will not
|
|
107
|
-
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~Element} will
|
|
108
|
-
* be returned once, while if the option is `false` they might be returned twice:
|
|
109
|
-
* for `'elementStart'` and `'elementEnd'`.
|
|
110
|
-
*
|
|
111
|
-
* @readonly
|
|
112
|
-
* @member {Boolean} module:engine/model/treewalker~TreeWalker#ignoreElementEnd
|
|
113
|
-
*/
|
|
114
52
|
this.ignoreElementEnd = !!options.ignoreElementEnd;
|
|
115
|
-
/**
|
|
116
|
-
* Start boundary cached for optimization purposes.
|
|
117
|
-
*
|
|
118
|
-
* @private
|
|
119
|
-
* @member {module:engine/model/element~Element} module:engine/model/treewalker~TreeWalker#_boundaryStartParent
|
|
120
|
-
*/
|
|
121
53
|
this._boundaryStartParent = this.boundaries ? this.boundaries.start.parent : null;
|
|
122
|
-
/**
|
|
123
|
-
* End boundary cached for optimization purposes.
|
|
124
|
-
*
|
|
125
|
-
* @private
|
|
126
|
-
* @member {module:engine/model/element~Element} module:engine/model/treewalker~TreeWalker#_boundaryEndParent
|
|
127
|
-
*/
|
|
128
54
|
this._boundaryEndParent = this.boundaries ? this.boundaries.end.parent : null;
|
|
129
|
-
/**
|
|
130
|
-
* Parent of the most recently visited node. Cached for optimization purposes.
|
|
131
|
-
*
|
|
132
|
-
* @private
|
|
133
|
-
* @member {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment}
|
|
134
|
-
* module:engine/model/treewalker~TreeWalker#_visitedParent
|
|
135
|
-
*/
|
|
136
55
|
this._visitedParent = this.position.parent;
|
|
137
56
|
}
|
|
138
57
|
/**
|
|
@@ -148,11 +67,13 @@ export default class TreeWalker {
|
|
|
148
67
|
*
|
|
149
68
|
* For example:
|
|
150
69
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
70
|
+
* ```ts
|
|
71
|
+
* walker.skip( value => value.type == 'text' ); // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
|
|
72
|
+
* walker.skip( () => true ); // Move the position to the end: <paragraph>[]foo</paragraph> -> <paragraph>foo</paragraph>[]
|
|
73
|
+
* walker.skip( () => false ); // Do not move the position.
|
|
74
|
+
* ```
|
|
154
75
|
*
|
|
155
|
-
* @param
|
|
76
|
+
* @param skip Callback function. Gets {@link module:engine/model/treewalker~TreeWalkerValue} and should
|
|
156
77
|
* return `true` if the value should be skipped or `false` if not.
|
|
157
78
|
*/
|
|
158
79
|
skip(skip) {
|
|
@@ -169,8 +90,6 @@ export default class TreeWalker {
|
|
|
169
90
|
}
|
|
170
91
|
/**
|
|
171
92
|
* Gets the next tree walker's value.
|
|
172
|
-
*
|
|
173
|
-
* @returns {IteratorResult} Next tree walker's value.
|
|
174
93
|
*/
|
|
175
94
|
next() {
|
|
176
95
|
if (this.direction == 'forward') {
|
|
@@ -182,11 +101,6 @@ export default class TreeWalker {
|
|
|
182
101
|
}
|
|
183
102
|
/**
|
|
184
103
|
* Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
|
|
185
|
-
*
|
|
186
|
-
* @private
|
|
187
|
-
* @returns {Object}
|
|
188
|
-
* @returns {Boolean} return.done True if iterator is done.
|
|
189
|
-
* @returns {IteratorResult} return.value Information about taken step.
|
|
190
104
|
*/
|
|
191
105
|
_next() {
|
|
192
106
|
const previousPosition = this.position;
|
|
@@ -250,11 +164,6 @@ export default class TreeWalker {
|
|
|
250
164
|
}
|
|
251
165
|
/**
|
|
252
166
|
* Makes a step backward in model. Moves the {@link #position} to the previous position and returns the encountered value.
|
|
253
|
-
*
|
|
254
|
-
* @private
|
|
255
|
-
* @returns {Object}
|
|
256
|
-
* @returns {Boolean} return.done True if iterator is done.
|
|
257
|
-
* @returns {IteratorResulte} return.value Information about taken step.
|
|
258
167
|
*/
|
|
259
168
|
_previous() {
|
|
260
169
|
const previousPosition = this.position;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
export default class TypeCheckable {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
5
|
/**
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Fixes all empty roots.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
11
|
+
* @internal
|
|
12
|
+
* @param writer The model writer.
|
|
13
|
+
* @returns `true` if any change has been applied, `false` otherwise.
|
|
14
14
|
*/
|
|
15
15
|
export function autoParagraphEmptyRoots(writer) {
|
|
16
16
|
const { schema, document } = writer.model;
|
|
@@ -33,10 +33,9 @@ export function autoParagraphEmptyRoots(writer) {
|
|
|
33
33
|
* Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position.
|
|
34
34
|
*
|
|
35
35
|
* @internal
|
|
36
|
-
* @
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param {module:engine/model/schema~Schema} schema A schema instance used for element validation.
|
|
36
|
+
* @param position The position at which to check.
|
|
37
|
+
* @param nodeOrType The child node or child type to check.
|
|
38
|
+
* @param schema A schema instance used for element validation.
|
|
40
39
|
*/
|
|
41
40
|
export function isParagraphable(position, nodeOrType, schema) {
|
|
42
41
|
const context = schema.createContext(position);
|
|
@@ -53,10 +52,10 @@ export function isParagraphable(position, nodeOrType, schema) {
|
|
|
53
52
|
/**
|
|
54
53
|
* Inserts a new paragraph at the given position and returns a position inside that paragraph.
|
|
55
54
|
*
|
|
56
|
-
* @
|
|
57
|
-
* @param
|
|
58
|
-
* @param
|
|
59
|
-
* @returns
|
|
55
|
+
* @internal
|
|
56
|
+
* @param position The position where a paragraph should be inserted.
|
|
57
|
+
* @param writer The model writer.
|
|
58
|
+
* @returns Position inside the created paragraph.
|
|
60
59
|
*/
|
|
61
60
|
export function wrapInParagraph(position, writer) {
|
|
62
61
|
const paragraph = writer.createElement('paragraph');
|