@ckeditor/ckeditor5-engine 35.4.0 → 36.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +25 -28
- 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/node.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
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
@@ -44,8 +44,7 @@ export default class Node extends TypeCheckable {
|
|
|
44
44
|
*
|
|
45
45
|
* This is an abstract class, so this constructor should not be used directly.
|
|
46
46
|
*
|
|
47
|
-
* @
|
|
48
|
-
* @param {Object} [attrs] Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
47
|
+
* @param attrs Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
49
48
|
*/
|
|
50
49
|
constructor(attrs) {
|
|
51
50
|
super();
|
|
@@ -53,24 +52,12 @@ export default class Node extends TypeCheckable {
|
|
|
53
52
|
* Parent of this node. It could be {@link module:engine/model/element~Element}
|
|
54
53
|
* or {@link module:engine/model/documentfragment~DocumentFragment}.
|
|
55
54
|
* Equals to `null` if the node has no parent.
|
|
56
|
-
*
|
|
57
|
-
* @readonly
|
|
58
|
-
* @member {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
|
|
59
55
|
*/
|
|
60
56
|
this.parent = null;
|
|
61
|
-
/**
|
|
62
|
-
* Attributes set on this node.
|
|
63
|
-
*
|
|
64
|
-
* @private
|
|
65
|
-
* @member {Map} module:engine/model/node~Node#_attrs
|
|
66
|
-
*/
|
|
67
57
|
this._attrs = toMap(attrs);
|
|
68
58
|
}
|
|
69
59
|
/**
|
|
70
60
|
* {@link module:engine/model/document~Document Document} that owns this root element.
|
|
71
|
-
*
|
|
72
|
-
* @readonly
|
|
73
|
-
* @type {module:engine/model/document~Document|null}
|
|
74
61
|
*/
|
|
75
62
|
get document() {
|
|
76
63
|
return null;
|
|
@@ -80,9 +67,6 @@ export default class Node extends TypeCheckable {
|
|
|
80
67
|
*
|
|
81
68
|
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
82
69
|
* This means that model tree got broken.
|
|
83
|
-
*
|
|
84
|
-
* @readonly
|
|
85
|
-
* @type {Number|null}
|
|
86
70
|
*/
|
|
87
71
|
get index() {
|
|
88
72
|
let pos;
|
|
@@ -100,9 +84,6 @@ export default class Node extends TypeCheckable {
|
|
|
100
84
|
*
|
|
101
85
|
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
102
86
|
* This means that model tree got broken.
|
|
103
|
-
*
|
|
104
|
-
* @readonly
|
|
105
|
-
* @type {Number|null}
|
|
106
87
|
*/
|
|
107
88
|
get startOffset() {
|
|
108
89
|
let pos;
|
|
@@ -119,9 +100,6 @@ export default class Node extends TypeCheckable {
|
|
|
119
100
|
* It is important for {@link module:engine/model/position~Position position}. When node has `offsetSize` greater than `1`, position
|
|
120
101
|
* can be placed between that node start and end. `offsetSize` greater than `1` is for nodes that represents more
|
|
121
102
|
* than one entity, i.e. {@link module:engine/model/text~Text text node}.
|
|
122
|
-
*
|
|
123
|
-
* @readonly
|
|
124
|
-
* @type {Number}
|
|
125
103
|
*/
|
|
126
104
|
get offsetSize() {
|
|
127
105
|
return 1;
|
|
@@ -130,9 +108,6 @@ export default class Node extends TypeCheckable {
|
|
|
130
108
|
* Offset at which this node ends in it's parent. It is equal to the sum of this node's
|
|
131
109
|
* {@link module:engine/model/node~Node#startOffset start offset} and {@link #offsetSize offset size}.
|
|
132
110
|
* Equals to `null` if the node has no parent.
|
|
133
|
-
*
|
|
134
|
-
* @readonly
|
|
135
|
-
* @type {Number|null}
|
|
136
111
|
*/
|
|
137
112
|
get endOffset() {
|
|
138
113
|
if (!this.parent) {
|
|
@@ -142,9 +117,6 @@ export default class Node extends TypeCheckable {
|
|
|
142
117
|
}
|
|
143
118
|
/**
|
|
144
119
|
* Node's next sibling or `null` if the node is a last child of it's parent or if the node has no parent.
|
|
145
|
-
*
|
|
146
|
-
* @readonly
|
|
147
|
-
* @type {module:engine/model/node~Node|null}
|
|
148
120
|
*/
|
|
149
121
|
get nextSibling() {
|
|
150
122
|
const index = this.index;
|
|
@@ -152,9 +124,6 @@ export default class Node extends TypeCheckable {
|
|
|
152
124
|
}
|
|
153
125
|
/**
|
|
154
126
|
* Node's previous sibling or `null` if the node is a first child of it's parent or if the node has no parent.
|
|
155
|
-
*
|
|
156
|
-
* @readonly
|
|
157
|
-
* @type {module:engine/model/node~Node|null}
|
|
158
127
|
*/
|
|
159
128
|
get previousSibling() {
|
|
160
129
|
const index = this.index;
|
|
@@ -163,9 +132,6 @@ export default class Node extends TypeCheckable {
|
|
|
163
132
|
/**
|
|
164
133
|
* The top-most ancestor of the node. If node has no parent it is the root itself. If the node is a part
|
|
165
134
|
* of {@link module:engine/model/documentfragment~DocumentFragment}, it's `root` is equal to that `DocumentFragment`.
|
|
166
|
-
*
|
|
167
|
-
* @readonly
|
|
168
|
-
* @type {module:engine/model/node~Node|module:engine/model/documentfragment~DocumentFragment}
|
|
169
135
|
*/
|
|
170
136
|
get root() {
|
|
171
137
|
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
@@ -177,8 +143,6 @@ export default class Node extends TypeCheckable {
|
|
|
177
143
|
}
|
|
178
144
|
/**
|
|
179
145
|
* Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
|
|
180
|
-
*
|
|
181
|
-
* @returns {Boolean}
|
|
182
146
|
*/
|
|
183
147
|
isAttached() {
|
|
184
148
|
return this.root.is('rootElement');
|
|
@@ -188,16 +152,16 @@ export default class Node extends TypeCheckable {
|
|
|
188
152
|
* beginning from {@link module:engine/model/node~Node#root root}, down to this node's starting offset. The path can be used to
|
|
189
153
|
* create {@link module:engine/model/position~Position Position} instance.
|
|
190
154
|
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* const abc = new Text( 'abc' );
|
|
157
|
+
* const foo = new Text( 'foo' );
|
|
158
|
+
* const h1 = new Element( 'h1', null, new Text( 'header' ) );
|
|
159
|
+
* const p = new Element( 'p', null, [ abc, foo ] );
|
|
160
|
+
* const div = new Element( 'div', null, [ h1, p ] );
|
|
161
|
+
* foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
|
|
162
|
+
* h1.getPath(); // Returns [ 0 ].
|
|
163
|
+
* div.getPath(); // Returns [].
|
|
164
|
+
* ```
|
|
201
165
|
*/
|
|
202
166
|
getPath() {
|
|
203
167
|
const path = [];
|
|
@@ -212,11 +176,11 @@ export default class Node extends TypeCheckable {
|
|
|
212
176
|
/**
|
|
213
177
|
* Returns ancestors array of this node.
|
|
214
178
|
*
|
|
215
|
-
* @param
|
|
216
|
-
* @param
|
|
217
|
-
* @param
|
|
179
|
+
* @param options Options object.
|
|
180
|
+
* @param options.includeSelf When set to `true` this node will be also included in parent's array.
|
|
181
|
+
* @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
|
|
218
182
|
* otherwise root element will be the first item in the array.
|
|
219
|
-
* @returns
|
|
183
|
+
* @returns Array with ancestors.
|
|
220
184
|
*/
|
|
221
185
|
getAncestors(options = {}) {
|
|
222
186
|
const ancestors = [];
|
|
@@ -231,11 +195,10 @@ export default class Node extends TypeCheckable {
|
|
|
231
195
|
* Returns a {@link module:engine/model/element~Element} or {@link module:engine/model/documentfragment~DocumentFragment}
|
|
232
196
|
* which is a common ancestor of both nodes.
|
|
233
197
|
*
|
|
234
|
-
* @param
|
|
235
|
-
* @param
|
|
236
|
-
* @param
|
|
198
|
+
* @param node The second node.
|
|
199
|
+
* @param options Options object.
|
|
200
|
+
* @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
|
|
237
201
|
* Which means that if e.g. node A is inside B, then their common ancestor will be B.
|
|
238
|
-
* @returns {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment|null}
|
|
239
202
|
*/
|
|
240
203
|
getCommonAncestor(node, options = {}) {
|
|
241
204
|
const ancestorsA = this.getAncestors(options);
|
|
@@ -250,8 +213,7 @@ export default class Node extends TypeCheckable {
|
|
|
250
213
|
* Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
|
|
251
214
|
* in different {@link module:engine/model/documentfragment~DocumentFragment}s).
|
|
252
215
|
*
|
|
253
|
-
* @param
|
|
254
|
-
* @returns {Boolean}
|
|
216
|
+
* @param node Node to compare with.
|
|
255
217
|
*/
|
|
256
218
|
isBefore(node) {
|
|
257
219
|
// Given node is not before this node if they are same.
|
|
@@ -278,8 +240,7 @@ export default class Node extends TypeCheckable {
|
|
|
278
240
|
* Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
|
|
279
241
|
* in different {@link module:engine/model/documentfragment~DocumentFragment}s).
|
|
280
242
|
*
|
|
281
|
-
* @param
|
|
282
|
-
* @returns {Boolean}
|
|
243
|
+
* @param node Node to compare with.
|
|
283
244
|
*/
|
|
284
245
|
isAfter(node) {
|
|
285
246
|
// Given node is not before this node if they are same.
|
|
@@ -296,8 +257,8 @@ export default class Node extends TypeCheckable {
|
|
|
296
257
|
/**
|
|
297
258
|
* Checks if the node has an attribute with given key.
|
|
298
259
|
*
|
|
299
|
-
* @param
|
|
300
|
-
* @returns
|
|
260
|
+
* @param key Key of attribute to check.
|
|
261
|
+
* @returns `true` if attribute with given key is set on node, `false` otherwise.
|
|
301
262
|
*/
|
|
302
263
|
hasAttribute(key) {
|
|
303
264
|
return this._attrs.has(key);
|
|
@@ -305,8 +266,8 @@ export default class Node extends TypeCheckable {
|
|
|
305
266
|
/**
|
|
306
267
|
* Gets an attribute value for given key or `undefined` if that attribute is not set on node.
|
|
307
268
|
*
|
|
308
|
-
* @param
|
|
309
|
-
* @returns
|
|
269
|
+
* @param key Key of attribute to look for.
|
|
270
|
+
* @returns Attribute value or `undefined`.
|
|
310
271
|
*/
|
|
311
272
|
getAttribute(key) {
|
|
312
273
|
return this._attrs.get(key);
|
|
@@ -316,16 +277,12 @@ export default class Node extends TypeCheckable {
|
|
|
316
277
|
*
|
|
317
278
|
* Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
|
|
318
279
|
* This format is accepted by native `Map` object and also can be passed in `Node` constructor.
|
|
319
|
-
*
|
|
320
|
-
* @returns {Iterable.<*>}
|
|
321
280
|
*/
|
|
322
281
|
getAttributes() {
|
|
323
282
|
return this._attrs.entries();
|
|
324
283
|
}
|
|
325
284
|
/**
|
|
326
285
|
* Returns iterator that iterates over this node's attribute keys.
|
|
327
|
-
*
|
|
328
|
-
* @returns {Iterable.<String>}
|
|
329
286
|
*/
|
|
330
287
|
getAttributeKeys() {
|
|
331
288
|
return this._attrs.keys();
|
|
@@ -333,7 +290,7 @@ export default class Node extends TypeCheckable {
|
|
|
333
290
|
/**
|
|
334
291
|
* Converts `Node` to plain object and returns it.
|
|
335
292
|
*
|
|
336
|
-
* @returns
|
|
293
|
+
* @returns `Node` converted to plain object.
|
|
337
294
|
*/
|
|
338
295
|
toJSON() {
|
|
339
296
|
const json = {};
|
|
@@ -351,18 +308,16 @@ export default class Node extends TypeCheckable {
|
|
|
351
308
|
* Creates a copy of this node, that is a node with exactly same attributes, and returns it.
|
|
352
309
|
*
|
|
353
310
|
* @internal
|
|
354
|
-
* @
|
|
355
|
-
* @returns {module:engine/model/node~Node} Node with same attributes as this node.
|
|
311
|
+
* @returns Node with same attributes as this node.
|
|
356
312
|
*/
|
|
357
313
|
_clone(_deep) {
|
|
358
|
-
return new
|
|
314
|
+
return new this.constructor(this._attrs);
|
|
359
315
|
}
|
|
360
316
|
/**
|
|
361
317
|
* Removes this node from it's parent.
|
|
362
318
|
*
|
|
363
319
|
* @internal
|
|
364
320
|
* @see module:engine/model/writer~Writer#remove
|
|
365
|
-
* @protected
|
|
366
321
|
*/
|
|
367
322
|
_remove() {
|
|
368
323
|
this.parent._removeChildren(this.index);
|
|
@@ -372,9 +327,8 @@ export default class Node extends TypeCheckable {
|
|
|
372
327
|
*
|
|
373
328
|
* @see module:engine/model/writer~Writer#setAttribute
|
|
374
329
|
* @internal
|
|
375
|
-
* @
|
|
376
|
-
* @param
|
|
377
|
-
* @param {*} value Attribute value.
|
|
330
|
+
* @param key Key of attribute to set.
|
|
331
|
+
* @param value Attribute value.
|
|
378
332
|
*/
|
|
379
333
|
_setAttribute(key, value) {
|
|
380
334
|
this._attrs.set(key, value);
|
|
@@ -384,8 +338,7 @@ export default class Node extends TypeCheckable {
|
|
|
384
338
|
*
|
|
385
339
|
* @see module:engine/model/writer~Writer#setAttributes
|
|
386
340
|
* @internal
|
|
387
|
-
* @
|
|
388
|
-
* @param {Object} [attrs] Attributes to set. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
341
|
+
* @param attrs Attributes to set. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
389
342
|
*/
|
|
390
343
|
_setAttributesTo(attrs) {
|
|
391
344
|
this._attrs = toMap(attrs);
|
|
@@ -395,9 +348,8 @@ export default class Node extends TypeCheckable {
|
|
|
395
348
|
*
|
|
396
349
|
* @see module:engine/model/writer~Writer#removeAttribute
|
|
397
350
|
* @internal
|
|
398
|
-
* @
|
|
399
|
-
* @
|
|
400
|
-
* @returns {Boolean} `true` if the attribute was set on the element, `false` otherwise.
|
|
351
|
+
* @param key Key of attribute to remove.
|
|
352
|
+
* @returns `true` if the attribute was set on the element, `false` otherwise.
|
|
401
353
|
*/
|
|
402
354
|
_removeAttribute(key) {
|
|
403
355
|
return this._attrs.delete(key);
|
|
@@ -407,55 +359,13 @@ export default class Node extends TypeCheckable {
|
|
|
407
359
|
*
|
|
408
360
|
* @see module:engine/model/writer~Writer#clearAttributes
|
|
409
361
|
* @internal
|
|
410
|
-
* @protected
|
|
411
362
|
*/
|
|
412
363
|
_clearAttributes() {
|
|
413
364
|
this._attrs.clear();
|
|
414
365
|
}
|
|
415
366
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
*
|
|
419
|
-
* This method is useful when processing model objects that are of unknown type. For example, a function
|
|
420
|
-
* may return a {@link module:engine/model/documentfragment~DocumentFragment} or a {@link module:engine/model/node~Node}
|
|
421
|
-
* that can be either a text node or an element. This method can be used to check what kind of object is returned.
|
|
422
|
-
*
|
|
423
|
-
* someObject.is( 'element' ); // -> true if this is an element
|
|
424
|
-
* someObject.is( 'node' ); // -> true if this is a node (a text node or an element)
|
|
425
|
-
* someObject.is( 'documentFragment' ); // -> true if this is a document fragment
|
|
426
|
-
*
|
|
427
|
-
* Since this method is also available on a range of view objects, you can prefix the type of the object with
|
|
428
|
-
* `model:` or `view:` to check, for example, if this is the model's or view's element:
|
|
429
|
-
*
|
|
430
|
-
* modelElement.is( 'model:element' ); // -> true
|
|
431
|
-
* modelElement.is( 'view:element' ); // -> false
|
|
432
|
-
*
|
|
433
|
-
* By using this method it is also possible to check a name of an element:
|
|
434
|
-
*
|
|
435
|
-
* imageElement.is( 'element', 'imageBlock' ); // -> true
|
|
436
|
-
* imageElement.is( 'element', 'imageBlock' ); // -> same as above
|
|
437
|
-
* imageElement.is( 'model:element', 'imageBlock' ); // -> same as above, but more precise
|
|
438
|
-
*
|
|
439
|
-
* The list of model objects which implement the `is()` method:
|
|
440
|
-
*
|
|
441
|
-
* * {@link module:engine/model/node~Node#is `Node#is()`}
|
|
442
|
-
* * {@link module:engine/model/text~Text#is `Text#is()`}
|
|
443
|
-
* * {@link module:engine/model/element~Element#is `Element#is()`}
|
|
444
|
-
* * {@link module:engine/model/rootelement~RootElement#is `RootElement#is()`}
|
|
445
|
-
* * {@link module:engine/model/position~Position#is `Position#is()`}
|
|
446
|
-
* * {@link module:engine/model/liveposition~LivePosition#is `LivePosition#is()`}
|
|
447
|
-
* * {@link module:engine/model/range~Range#is `Range#is()`}
|
|
448
|
-
* * {@link module:engine/model/liverange~LiveRange#is `LiveRange#is()`}
|
|
449
|
-
* * {@link module:engine/model/documentfragment~DocumentFragment#is `DocumentFragment#is()`}
|
|
450
|
-
* * {@link module:engine/model/selection~Selection#is `Selection#is()`}
|
|
451
|
-
* * {@link module:engine/model/documentselection~DocumentSelection#is `DocumentSelection#is()`}
|
|
452
|
-
* * {@link module:engine/model/markercollection~Marker#is `Marker#is()`}
|
|
453
|
-
* * {@link module:engine/model/textproxy~TextProxy#is `TextProxy#is()`}
|
|
454
|
-
*
|
|
455
|
-
* @method #is
|
|
456
|
-
* @param {String} type Type to check.
|
|
457
|
-
* @returns {Boolean}
|
|
458
|
-
*/
|
|
367
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
368
|
+
// Proper overload would interfere with that.
|
|
459
369
|
Node.prototype.is = function (type) {
|
|
460
370
|
return type === 'node' || type === 'model:node';
|
|
461
371
|
};
|
package/src/model/nodelist.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
|
/**
|
|
@@ -16,15 +16,12 @@ export default class NodeList {
|
|
|
16
16
|
/**
|
|
17
17
|
* Creates an empty node list.
|
|
18
18
|
*
|
|
19
|
-
* @
|
|
20
|
-
* @param
|
|
19
|
+
* @internal
|
|
20
|
+
* @param nodes Nodes contained in this node list.
|
|
21
21
|
*/
|
|
22
22
|
constructor(nodes) {
|
|
23
23
|
/**
|
|
24
24
|
* Nodes contained in this node list.
|
|
25
|
-
*
|
|
26
|
-
* @private
|
|
27
|
-
* @member {Array.<module:engine/model/node~Node>}
|
|
28
25
|
*/
|
|
29
26
|
this._nodes = [];
|
|
30
27
|
if (nodes) {
|
|
@@ -35,44 +32,30 @@ export default class NodeList {
|
|
|
35
32
|
* Iterable interface.
|
|
36
33
|
*
|
|
37
34
|
* Iterates over all nodes contained inside this node list.
|
|
38
|
-
*
|
|
39
|
-
* @returns {Iterator.<module:engine/model/node~Node>}
|
|
40
35
|
*/
|
|
41
36
|
[Symbol.iterator]() {
|
|
42
37
|
return this._nodes[Symbol.iterator]();
|
|
43
38
|
}
|
|
44
39
|
/**
|
|
45
40
|
* Number of nodes contained inside this node list.
|
|
46
|
-
*
|
|
47
|
-
* @readonly
|
|
48
|
-
* @type {Number}
|
|
49
41
|
*/
|
|
50
42
|
get length() {
|
|
51
43
|
return this._nodes.length;
|
|
52
44
|
}
|
|
53
45
|
/**
|
|
54
46
|
* Sum of {@link module:engine/model/node~Node#offsetSize offset sizes} of all nodes contained inside this node list.
|
|
55
|
-
*
|
|
56
|
-
* @readonly
|
|
57
|
-
* @type {Number}
|
|
58
47
|
*/
|
|
59
48
|
get maxOffset() {
|
|
60
49
|
return this._nodes.reduce((sum, node) => sum + node.offsetSize, 0);
|
|
61
50
|
}
|
|
62
51
|
/**
|
|
63
52
|
* Gets the node at the given index. Returns `null` if incorrect index was passed.
|
|
64
|
-
*
|
|
65
|
-
* @param {Number} index Index of node.
|
|
66
|
-
* @returns {module:engine/model/node~Node|null} Node at given index.
|
|
67
53
|
*/
|
|
68
54
|
getNode(index) {
|
|
69
55
|
return this._nodes[index] || null;
|
|
70
56
|
}
|
|
71
57
|
/**
|
|
72
58
|
* Returns an index of the given node. Returns `null` if given node is not inside this node list.
|
|
73
|
-
*
|
|
74
|
-
* @param {module:engine/model/node~Node} node Child node to look for.
|
|
75
|
-
* @returns {Number|null} Child node's index.
|
|
76
59
|
*/
|
|
77
60
|
getNodeIndex(node) {
|
|
78
61
|
const index = this._nodes.indexOf(node);
|
|
@@ -81,9 +64,6 @@ export default class NodeList {
|
|
|
81
64
|
/**
|
|
82
65
|
* Returns the starting offset of given node. Starting offset is equal to the sum of
|
|
83
66
|
* {@link module:engine/model/node~Node#offsetSize offset sizes} of all nodes that are before this node in this node list.
|
|
84
|
-
*
|
|
85
|
-
* @param {module:engine/model/node~Node} node Node to look for.
|
|
86
|
-
* @returns {Number|null} Node's starting offset.
|
|
87
67
|
*/
|
|
88
68
|
getNodeStartOffset(node) {
|
|
89
69
|
const index = this.getNodeIndex(node);
|
|
@@ -94,9 +74,6 @@ export default class NodeList {
|
|
|
94
74
|
*
|
|
95
75
|
* Returns starting offset of a node that is at given index. Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
|
|
96
76
|
* `model-nodelist-index-out-of-bounds` if given index is less than `0` or more than {@link #length}.
|
|
97
|
-
*
|
|
98
|
-
* @param {Number} index Node's index.
|
|
99
|
-
* @returns {Number} Node's starting offset.
|
|
100
77
|
*/
|
|
101
78
|
indexToOffset(index) {
|
|
102
79
|
if (index == this._nodes.length) {
|
|
@@ -118,9 +95,6 @@ export default class NodeList {
|
|
|
118
95
|
*
|
|
119
96
|
* Returns index of a node that occupies given offset. Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError}
|
|
120
97
|
* `model-nodelist-offset-out-of-bounds` if given offset is less than `0` or more than {@link #maxOffset}.
|
|
121
|
-
*
|
|
122
|
-
* @param {Number} offset Offset to look for.
|
|
123
|
-
* @returns {Number} Index of a node that occupies given offset.
|
|
124
98
|
*/
|
|
125
99
|
offsetToIndex(offset) {
|
|
126
100
|
let totalOffset = 0;
|
|
@@ -135,8 +109,8 @@ export default class NodeList {
|
|
|
135
109
|
* Given offset cannot be found in the node list.
|
|
136
110
|
*
|
|
137
111
|
* @error model-nodelist-offset-out-of-bounds
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
112
|
+
* @param offset
|
|
113
|
+
* @param nodeList Stringified node list.
|
|
140
114
|
*/
|
|
141
115
|
throw new CKEditorError('model-nodelist-offset-out-of-bounds', this, {
|
|
142
116
|
offset,
|
|
@@ -149,9 +123,8 @@ export default class NodeList {
|
|
|
149
123
|
* Inserts given nodes at given index.
|
|
150
124
|
*
|
|
151
125
|
* @internal
|
|
152
|
-
* @
|
|
153
|
-
* @param
|
|
154
|
-
* @param {Iterable.<module:engine/model/node~Node>} nodes Nodes to be inserted.
|
|
126
|
+
* @param index Index at which nodes should be inserted.
|
|
127
|
+
* @param nodes Nodes to be inserted.
|
|
155
128
|
*/
|
|
156
129
|
_insertNodes(index, nodes) {
|
|
157
130
|
// Validation.
|
|
@@ -171,10 +144,9 @@ export default class NodeList {
|
|
|
171
144
|
* Removes one or more nodes starting at the given index.
|
|
172
145
|
*
|
|
173
146
|
* @internal
|
|
174
|
-
* @
|
|
175
|
-
* @param
|
|
176
|
-
* @
|
|
177
|
-
* @returns {Array.<module:engine/model/node~Node>} Array containing removed nodes.
|
|
147
|
+
* @param indexStart Index of the first node to remove.
|
|
148
|
+
* @param howMany Number of nodes to remove.
|
|
149
|
+
* @returns Array containing removed nodes.
|
|
178
150
|
*/
|
|
179
151
|
_removeNodes(indexStart, howMany = 1) {
|
|
180
152
|
return this._nodes.splice(indexStart, howMany);
|
|
@@ -183,7 +155,7 @@ export default class NodeList {
|
|
|
183
155
|
* Converts `NodeList` instance to an array containing nodes that were inserted in the node list. Nodes
|
|
184
156
|
* are also converted to their plain object representation.
|
|
185
157
|
*
|
|
186
|
-
* @returns
|
|
158
|
+
* @returns `NodeList` instance converted to `Array`.
|
|
187
159
|
*/
|
|
188
160
|
toJSON() {
|
|
189
161
|
return this._nodes.map(node => node.toJSON());
|
|
@@ -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
|
/**
|
|
@@ -14,8 +14,6 @@ import { isEqual } from 'lodash-es';
|
|
|
14
14
|
* Operation to change nodes' attribute.
|
|
15
15
|
*
|
|
16
16
|
* Using this class you can add, remove or change value of the attribute.
|
|
17
|
-
*
|
|
18
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
19
17
|
*/
|
|
20
18
|
export default class AttributeOperation extends Operation {
|
|
21
19
|
/**
|
|
@@ -30,42 +28,18 @@ export default class AttributeOperation extends Operation {
|
|
|
30
28
|
* If both `newValue` and `oldValue` are set, then the operation will change the attribute value. Note that all nodes in
|
|
31
29
|
* operation's ranges must already have an attribute with given key and `oldValue` as value
|
|
32
30
|
*
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
31
|
+
* @param range Range on which the operation should be applied. Must be a flat range.
|
|
32
|
+
* @param key Key of an attribute to change or remove.
|
|
33
|
+
* @param oldValue Old value of the attribute with given key or `null`, if attribute was not set before.
|
|
34
|
+
* @param newValue New value of the attribute with given key or `null`, if operation should remove attribute.
|
|
35
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
38
36
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
39
37
|
*/
|
|
40
38
|
constructor(range, key, oldValue, newValue, baseVersion) {
|
|
41
39
|
super(baseVersion);
|
|
42
|
-
/**
|
|
43
|
-
* Range on which operation should be applied.
|
|
44
|
-
*
|
|
45
|
-
* @readonly
|
|
46
|
-
* @member {module:engine/model/range~Range}
|
|
47
|
-
*/
|
|
48
40
|
this.range = range.clone();
|
|
49
|
-
/**
|
|
50
|
-
* Key of an attribute to change or remove.
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
53
|
-
* @member {String}
|
|
54
|
-
*/
|
|
55
41
|
this.key = key;
|
|
56
|
-
/**
|
|
57
|
-
* Old value of the attribute with given key or `null`, if attribute was not set before.
|
|
58
|
-
*
|
|
59
|
-
* @readonly
|
|
60
|
-
* @member {*}
|
|
61
|
-
*/
|
|
62
42
|
this.oldValue = oldValue === undefined ? null : oldValue;
|
|
63
|
-
/**
|
|
64
|
-
* New value of the attribute with given key or `null`, if operation should remove attribute.
|
|
65
|
-
*
|
|
66
|
-
* @readonly
|
|
67
|
-
* @member {*}
|
|
68
|
-
*/
|
|
69
43
|
this.newValue = newValue === undefined ? null : newValue;
|
|
70
44
|
}
|
|
71
45
|
/**
|
|
@@ -84,16 +58,12 @@ export default class AttributeOperation extends Operation {
|
|
|
84
58
|
}
|
|
85
59
|
/**
|
|
86
60
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
87
|
-
*
|
|
88
|
-
* @returns {module:engine/model/operation/attributeoperation~AttributeOperation} Clone of this operation.
|
|
89
61
|
*/
|
|
90
62
|
clone() {
|
|
91
63
|
return new AttributeOperation(this.range, this.key, this.oldValue, this.newValue, this.baseVersion);
|
|
92
64
|
}
|
|
93
65
|
/**
|
|
94
66
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
95
|
-
*
|
|
96
|
-
* @returns {module:engine/model/operation/attributeoperation~AttributeOperation}
|
|
97
67
|
*/
|
|
98
68
|
getReversed() {
|
|
99
69
|
return new AttributeOperation(this.range, this.key, this.newValue, this.oldValue, this.baseVersion + 1);
|
|
@@ -125,9 +95,9 @@ export default class AttributeOperation extends Operation {
|
|
|
125
95
|
* Changed node has different attribute value than operation's old attribute value.
|
|
126
96
|
*
|
|
127
97
|
* @error attribute-operation-wrong-old-value
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @param
|
|
98
|
+
* @param item
|
|
99
|
+
* @param key
|
|
100
|
+
* @param value
|
|
131
101
|
*/
|
|
132
102
|
throw new CKEditorError('attribute-operation-wrong-old-value', this, { item, key: this.key, value: this.oldValue });
|
|
133
103
|
}
|
|
@@ -136,8 +106,8 @@ export default class AttributeOperation extends Operation {
|
|
|
136
106
|
* The attribute with given key already exists for the given node.
|
|
137
107
|
*
|
|
138
108
|
* @error attribute-operation-attribute-exists
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
109
|
+
* @param node
|
|
110
|
+
* @param key
|
|
141
111
|
*/
|
|
142
112
|
throw new CKEditorError('attribute-operation-attribute-exists', this, { node: item, key: this.key });
|
|
143
113
|
}
|
|
@@ -163,9 +133,8 @@ export default class AttributeOperation extends Operation {
|
|
|
163
133
|
/**
|
|
164
134
|
* Creates `AttributeOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
165
135
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @returns {module:engine/model/operation/attributeoperation~AttributeOperation}
|
|
136
|
+
* @param json Deserialized JSON object.
|
|
137
|
+
* @param document Document on which this operation will be applied.
|
|
169
138
|
*/
|
|
170
139
|
static fromJSON(json, document) {
|
|
171
140
|
return new AttributeOperation(Range.fromJSON(json.range, document), json.key, json.oldValue, json.newValue, json.baseVersion);
|
|
@@ -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
|
/**
|
|
@@ -13,31 +13,18 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
|
13
13
|
/**
|
|
14
14
|
* Operation to permanently remove node from detached root.
|
|
15
15
|
* Note this operation is only a local operation and won't be send to the other clients.
|
|
16
|
-
*
|
|
17
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
18
16
|
*/
|
|
19
17
|
export default class DetachOperation extends Operation {
|
|
20
18
|
/**
|
|
21
19
|
* Creates an insert operation.
|
|
22
20
|
*
|
|
23
|
-
* @param {module:engine/model/
|
|
24
|
-
*
|
|
25
|
-
* @param {Number} howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
|
|
21
|
+
* @param sourcePosition Position before the first {@link module:engine/model/item~Item model item} to move.
|
|
22
|
+
* @param howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
|
|
26
23
|
* `sourcePosition` with offset shifted by `howMany`.
|
|
27
24
|
*/
|
|
28
25
|
constructor(sourcePosition, howMany) {
|
|
29
26
|
super(null);
|
|
30
|
-
/**
|
|
31
|
-
* Position before the first {@link module:engine/model/item~Item model item} to detach.
|
|
32
|
-
*
|
|
33
|
-
* @member {module:engine/model/position~Position} #sourcePosition
|
|
34
|
-
*/
|
|
35
27
|
this.sourcePosition = sourcePosition.clone();
|
|
36
|
-
/**
|
|
37
|
-
* Offset size of moved range.
|
|
38
|
-
*
|
|
39
|
-
* @member {Number} #howMany
|
|
40
|
-
*/
|
|
41
28
|
this.howMany = howMany;
|
|
42
29
|
}
|
|
43
30
|
/**
|