@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/element.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,8 +16,6 @@ import { isIterable } from '@ckeditor/ckeditor5-utils';
|
|
|
16
16
|
* {@link module:engine/model/element~Element#getChildren child nodes}.
|
|
17
17
|
*
|
|
18
18
|
* **Important**: see {@link module:engine/model/node~Node} to read about restrictions using `Element` and `Node` API.
|
|
19
|
-
*
|
|
20
|
-
* @extends module:engine/model/node~Node
|
|
21
19
|
*/
|
|
22
20
|
export default class Element extends Node {
|
|
23
21
|
/**
|
|
@@ -26,72 +24,48 @@ export default class Element extends Node {
|
|
|
26
24
|
* **Note:** Constructor of this class shouldn't be used directly in the code.
|
|
27
25
|
* Use the {@link module:engine/model/writer~Writer#createElement} method instead.
|
|
28
26
|
*
|
|
29
|
-
* @
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* One or more nodes to be inserted as children of created element.
|
|
27
|
+
* @internal
|
|
28
|
+
* @param name Element's name.
|
|
29
|
+
* @param attrs Element's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
30
|
+
* @param children One or more nodes to be inserted as children of created element.
|
|
34
31
|
*/
|
|
35
32
|
constructor(name, attrs, children) {
|
|
36
33
|
super(attrs);
|
|
37
|
-
/**
|
|
38
|
-
* Element name.
|
|
39
|
-
*
|
|
40
|
-
* @readonly
|
|
41
|
-
* @member {String} module:engine/model/element~Element#name
|
|
42
|
-
*/
|
|
43
|
-
this.name = name;
|
|
44
34
|
/**
|
|
45
35
|
* List of children nodes.
|
|
46
|
-
*
|
|
47
|
-
* @private
|
|
48
|
-
* @member {module:engine/model/nodelist~NodeList} module:engine/model/element~Element#_children
|
|
49
36
|
*/
|
|
50
37
|
this._children = new NodeList();
|
|
38
|
+
this.name = name;
|
|
51
39
|
if (children) {
|
|
52
40
|
this._insertChild(0, children);
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
44
|
* Number of this element's children.
|
|
57
|
-
*
|
|
58
|
-
* @readonly
|
|
59
|
-
* @type {Number}
|
|
60
45
|
*/
|
|
61
46
|
get childCount() {
|
|
62
47
|
return this._children.length;
|
|
63
48
|
}
|
|
64
49
|
/**
|
|
65
50
|
* Sum of {@link module:engine/model/node~Node#offsetSize offset sizes} of all of this element's children.
|
|
66
|
-
*
|
|
67
|
-
* @readonly
|
|
68
|
-
* @type {Number}
|
|
69
51
|
*/
|
|
70
52
|
get maxOffset() {
|
|
71
53
|
return this._children.maxOffset;
|
|
72
54
|
}
|
|
73
55
|
/**
|
|
74
56
|
* Is `true` if there are no nodes inside this element, `false` otherwise.
|
|
75
|
-
*
|
|
76
|
-
* @readonly
|
|
77
|
-
* @type {Boolean}
|
|
78
57
|
*/
|
|
79
58
|
get isEmpty() {
|
|
80
59
|
return this.childCount === 0;
|
|
81
60
|
}
|
|
82
61
|
/**
|
|
83
62
|
* Gets the child at the given index.
|
|
84
|
-
*
|
|
85
|
-
* @param {Number} index Index of child.
|
|
86
|
-
* @returns {module:engine/model/node~Node|null} Child node.
|
|
87
63
|
*/
|
|
88
64
|
getChild(index) {
|
|
89
65
|
return this._children.getNode(index);
|
|
90
66
|
}
|
|
91
67
|
/**
|
|
92
68
|
* Returns an iterator that iterates over all of this element's children.
|
|
93
|
-
*
|
|
94
|
-
* @returns {Iterable.<module:engine/model/node~Node>}
|
|
95
69
|
*/
|
|
96
70
|
getChildren() {
|
|
97
71
|
return this._children[Symbol.iterator]();
|
|
@@ -99,8 +73,8 @@ export default class Element extends Node {
|
|
|
99
73
|
/**
|
|
100
74
|
* Returns an index of the given child node. Returns `null` if given node is not a child of this element.
|
|
101
75
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @returns
|
|
76
|
+
* @param node Child node to look for.
|
|
77
|
+
* @returns Child node's index in this element.
|
|
104
78
|
*/
|
|
105
79
|
getChildIndex(node) {
|
|
106
80
|
return this._children.getNodeIndex(node);
|
|
@@ -110,8 +84,8 @@ export default class Element extends Node {
|
|
|
110
84
|
* {@link module:engine/model/node~Node#offsetSize offset sizes} of all node's siblings that are before it. Returns `null` if
|
|
111
85
|
* given node is not a child of this element.
|
|
112
86
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @returns
|
|
87
|
+
* @param node Child node to look for.
|
|
88
|
+
* @returns Child node's starting offset.
|
|
115
89
|
*/
|
|
116
90
|
getChildStartOffset(node) {
|
|
117
91
|
return this._children.getNodeStartOffset(node);
|
|
@@ -120,18 +94,17 @@ export default class Element extends Node {
|
|
|
120
94
|
* Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
|
|
121
95
|
* too high, returns {@link module:engine/model/element~Element#getChildIndex index after last child}.
|
|
122
96
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @returns {Number}
|
|
97
|
+
* ```ts
|
|
98
|
+
* const textNode = new Text( 'foo' );
|
|
99
|
+
* const pElement = new Element( 'p' );
|
|
100
|
+
* const divElement = new Element( [ textNode, pElement ] );
|
|
101
|
+
* divElement.offsetToIndex( -1 ); // Returns 0, because offset is too low.
|
|
102
|
+
* divElement.offsetToIndex( 0 ); // Returns 0, because offset 0 is taken by `textNode` which is at index 0.
|
|
103
|
+
* divElement.offsetToIndex( 1 ); // Returns 0, because `textNode` has `offsetSize` equal to 3, so it occupies offset 1 too.
|
|
104
|
+
* divElement.offsetToIndex( 2 ); // Returns 0.
|
|
105
|
+
* divElement.offsetToIndex( 3 ); // Returns 1.
|
|
106
|
+
* divElement.offsetToIndex( 4 ); // Returns 2. There are no nodes at offset 4, so last available index is returned.
|
|
107
|
+
* ```
|
|
135
108
|
*/
|
|
136
109
|
offsetToIndex(offset) {
|
|
137
110
|
return this._children.offsetToIndex(offset);
|
|
@@ -139,13 +112,14 @@ export default class Element extends Node {
|
|
|
139
112
|
/**
|
|
140
113
|
* Returns a descendant node by its path relative to this element.
|
|
141
114
|
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* // <this>a<b>c</b></this>
|
|
117
|
+
* this.getNodeByPath( [ 0 ] ); // -> "a"
|
|
118
|
+
* this.getNodeByPath( [ 1 ] ); // -> <b>
|
|
119
|
+
* this.getNodeByPath( [ 1, 0 ] ); // -> "c"
|
|
120
|
+
* ```
|
|
146
121
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @returns {module:engine/model/node~Node}
|
|
122
|
+
* @param relativePath Path of the node to find, relative to this element.
|
|
149
123
|
*/
|
|
150
124
|
getNodeByPath(relativePath) {
|
|
151
125
|
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
@@ -158,10 +132,9 @@ export default class Element extends Node {
|
|
|
158
132
|
/**
|
|
159
133
|
* Returns the parent element of the given name. Returns null if the element is not inside the desired parent.
|
|
160
134
|
*
|
|
161
|
-
* @param
|
|
162
|
-
* @param
|
|
163
|
-
* @param
|
|
164
|
-
* @returns {module:engine/model/element~Element|null}
|
|
135
|
+
* @param parentName The name of the parent element to find.
|
|
136
|
+
* @param options Options object.
|
|
137
|
+
* @param options.includeSelf When set to `true` this node will be also included while searching.
|
|
165
138
|
*/
|
|
166
139
|
findAncestor(parentName, options = {}) {
|
|
167
140
|
let parent = options.includeSelf ? this : this.parent;
|
|
@@ -176,7 +149,7 @@ export default class Element extends Node {
|
|
|
176
149
|
/**
|
|
177
150
|
* Converts `Element` instance to plain object and returns it. Takes care of converting all of this element's children.
|
|
178
151
|
*
|
|
179
|
-
* @returns
|
|
152
|
+
* @returns `Element` instance converted to plain object.
|
|
180
153
|
*/
|
|
181
154
|
toJSON() {
|
|
182
155
|
const json = super.toJSON();
|
|
@@ -194,8 +167,7 @@ export default class Element extends Node {
|
|
|
194
167
|
* If clone is deep, the original element's children are also cloned. If not, then empty element is returned.
|
|
195
168
|
*
|
|
196
169
|
* @internal
|
|
197
|
-
* @
|
|
198
|
-
* @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
|
|
170
|
+
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
199
171
|
* element will be cloned without any child.
|
|
200
172
|
*/
|
|
201
173
|
_clone(deep = false) {
|
|
@@ -207,8 +179,7 @@ export default class Element extends Node {
|
|
|
207
179
|
*
|
|
208
180
|
* @see module:engine/model/writer~Writer#append
|
|
209
181
|
* @internal
|
|
210
|
-
* @
|
|
211
|
-
* @param {String|module:engine/model/item~Item|Iterable.<String|module:engine/model/item~Item>} nodes Nodes to be inserted.
|
|
182
|
+
* @param nodes Nodes to be inserted.
|
|
212
183
|
*/
|
|
213
184
|
_appendChild(nodes) {
|
|
214
185
|
this._insertChild(this.childCount, nodes);
|
|
@@ -219,9 +190,8 @@ export default class Element extends Node {
|
|
|
219
190
|
*
|
|
220
191
|
* @see module:engine/model/writer~Writer#insert
|
|
221
192
|
* @internal
|
|
222
|
-
* @
|
|
223
|
-
* @param
|
|
224
|
-
* @param {String|module:engine/model/item~Item|Iterable.<String|module:engine/model/item~Item>} items Items to be inserted.
|
|
193
|
+
* @param index Index at which nodes should be inserted.
|
|
194
|
+
* @param items Items to be inserted.
|
|
225
195
|
*/
|
|
226
196
|
_insertChild(index, items) {
|
|
227
197
|
const nodes = normalize(items);
|
|
@@ -239,10 +209,10 @@ export default class Element extends Node {
|
|
|
239
209
|
* {@link module:engine/model/node~Node#parent parent} of these nodes to `null`.
|
|
240
210
|
*
|
|
241
211
|
* @see module:engine/model/writer~Writer#remove
|
|
242
|
-
* @
|
|
243
|
-
* @param
|
|
244
|
-
* @param
|
|
245
|
-
* @returns
|
|
212
|
+
* @internal
|
|
213
|
+
* @param index Index of the first node to remove.
|
|
214
|
+
* @param howMany Number of nodes to remove.
|
|
215
|
+
* @returns Array containing removed nodes.
|
|
246
216
|
*/
|
|
247
217
|
_removeChildren(index, howMany = 1) {
|
|
248
218
|
const nodes = this._children._removeNodes(index, howMany);
|
|
@@ -255,8 +225,8 @@ export default class Element extends Node {
|
|
|
255
225
|
* Creates an `Element` instance from given plain object (i.e. parsed JSON string).
|
|
256
226
|
* Converts `Element` children to proper nodes.
|
|
257
227
|
*
|
|
258
|
-
* @param
|
|
259
|
-
* @returns
|
|
228
|
+
* @param json Plain object to be converted to `Element`.
|
|
229
|
+
* @returns `Element` instance created using given plain object.
|
|
260
230
|
*/
|
|
261
231
|
static fromJSON(json) {
|
|
262
232
|
let children;
|
|
@@ -276,30 +246,8 @@ export default class Element extends Node {
|
|
|
276
246
|
return new Element(json.name, json.attributes, children);
|
|
277
247
|
}
|
|
278
248
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*
|
|
282
|
-
* element.is( 'element' ); // -> true
|
|
283
|
-
* element.is( 'node' ); // -> true
|
|
284
|
-
* element.is( 'model:element' ); // -> true
|
|
285
|
-
* element.is( 'model:node' ); // -> true
|
|
286
|
-
*
|
|
287
|
-
* element.is( 'view:element' ); // -> false
|
|
288
|
-
* element.is( 'documentSelection' ); // -> false
|
|
289
|
-
*
|
|
290
|
-
* Assuming that the object being checked is an element, you can also check its
|
|
291
|
-
* {@link module:engine/model/element~Element#name name}:
|
|
292
|
-
*
|
|
293
|
-
* element.is( 'element', 'imageBlock' ); // -> true if this is an <imageBlock> element
|
|
294
|
-
* element.is( 'element', 'imageBlock' ); // -> same as above
|
|
295
|
-
* text.is( 'element', 'imageBlock' ); -> false
|
|
296
|
-
*
|
|
297
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
298
|
-
*
|
|
299
|
-
* @param {String} type Type to check.
|
|
300
|
-
* @param {String} [name] Element name.
|
|
301
|
-
* @returns {Boolean}
|
|
302
|
-
*/
|
|
249
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
250
|
+
// Proper overload would interfere with that.
|
|
303
251
|
Element.prototype.is = function (type, name) {
|
|
304
252
|
if (!name) {
|
|
305
253
|
return type === 'element' || type === 'model:element' ||
|
|
@@ -308,10 +256,9 @@ Element.prototype.is = function (type, name) {
|
|
|
308
256
|
}
|
|
309
257
|
return name === this.name && (type === 'element' || type === 'model:element');
|
|
310
258
|
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
// @returns {Iterable.<module:engine/model/node~Node>}
|
|
259
|
+
/**
|
|
260
|
+
* Converts strings to Text and non-iterables to arrays.
|
|
261
|
+
*/
|
|
315
262
|
function normalize(nodes) {
|
|
316
263
|
// Separate condition because string is iterable.
|
|
317
264
|
if (typeof nodes == 'string') {
|
package/src/model/history.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
|
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
@@ -10,16 +10,9 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
|
10
10
|
* `History` keeps the track of all the operations applied to the {@link module:engine/model/document~Document document}.
|
|
11
11
|
*/
|
|
12
12
|
export default class History {
|
|
13
|
-
/**
|
|
14
|
-
* Creates an empty History instance.
|
|
15
|
-
*/
|
|
16
13
|
constructor() {
|
|
17
14
|
/**
|
|
18
15
|
* Operations added to the history.
|
|
19
|
-
*
|
|
20
|
-
* @private
|
|
21
|
-
* @readonly
|
|
22
|
-
* @type {Array.<module:engine/model/operation/operation~Operation>}
|
|
23
16
|
*/
|
|
24
17
|
this._operations = [];
|
|
25
18
|
/**
|
|
@@ -28,30 +21,18 @@ export default class History {
|
|
|
28
21
|
*
|
|
29
22
|
* Keys of the map are "undoing operations", that is operations that undone some other operations. For each key, the
|
|
30
23
|
* value is an operation that has been undone by the "undoing operation".
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @member {Map} module:engine/model/history~History#_undoPairs
|
|
34
24
|
*/
|
|
35
25
|
this._undoPairs = new Map();
|
|
36
26
|
/**
|
|
37
27
|
* Holds all undone operations.
|
|
38
|
-
*
|
|
39
|
-
* @private
|
|
40
|
-
* @type {Set.<module:engine/model/operation/operation~Operation>}
|
|
41
28
|
*/
|
|
42
29
|
this._undoneOperations = new Set();
|
|
43
30
|
/**
|
|
44
31
|
* A map that allows retrieving the operations fast based on the given base version.
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
|
-
* @type Map.<Number,Number>
|
|
48
32
|
*/
|
|
49
33
|
this._baseVersionToOperationIndex = new Map();
|
|
50
34
|
/**
|
|
51
35
|
* The history version.
|
|
52
|
-
*
|
|
53
|
-
* @private
|
|
54
|
-
* @type {Number}
|
|
55
36
|
*/
|
|
56
37
|
this._version = 0;
|
|
57
38
|
/**
|
|
@@ -59,9 +40,6 @@ export default class History {
|
|
|
59
40
|
*
|
|
60
41
|
* Anytime the `history.version` is set to a version larger than `history.version + 1`,
|
|
61
42
|
* a new <lastHistoryVersion, newHistoryVersion> entry is added to the map.
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @type Map.<number,number>
|
|
65
43
|
*/
|
|
66
44
|
this._gaps = new Map();
|
|
67
45
|
}
|
|
@@ -72,8 +50,6 @@ export default class History {
|
|
|
72
50
|
* Setting the version manually should be done only in rare circumstances when a gap is planned
|
|
73
51
|
* between history versions. When doing so, a gap will be created and the history will accept adding
|
|
74
52
|
* an operation with base version equal to the new history version.
|
|
75
|
-
*
|
|
76
|
-
* @type {Number}
|
|
77
53
|
*/
|
|
78
54
|
get version() {
|
|
79
55
|
return this._version;
|
|
@@ -88,9 +64,6 @@ export default class History {
|
|
|
88
64
|
}
|
|
89
65
|
/**
|
|
90
66
|
* The last history operation.
|
|
91
|
-
*
|
|
92
|
-
* @readonly
|
|
93
|
-
* @type {module:engine/model/operation/operation~Operation|undefined}
|
|
94
67
|
*/
|
|
95
68
|
get lastOperation() {
|
|
96
69
|
return this._operations[this._operations.length - 1];
|
|
@@ -99,8 +72,6 @@ export default class History {
|
|
|
99
72
|
* Adds an operation to the history and increments the history version.
|
|
100
73
|
*
|
|
101
74
|
* The operation's base version should be equal to the history version. Otherwise an error is thrown.
|
|
102
|
-
*
|
|
103
|
-
* @param {module:engine/model/operation/operation~Operation} operation Operation to add.
|
|
104
75
|
*/
|
|
105
76
|
addOperation(operation) {
|
|
106
77
|
if (operation.baseVersion !== this.version) {
|
|
@@ -108,7 +79,7 @@ export default class History {
|
|
|
108
79
|
* Only operations with matching versions can be added to the history.
|
|
109
80
|
*
|
|
110
81
|
* @error model-document-history-addoperation-incorrect-version
|
|
111
|
-
* @param
|
|
82
|
+
* @param errorData The operation and the current document history version.
|
|
112
83
|
*/
|
|
113
84
|
throw new CKEditorError('model-document-history-addoperation-incorrect-version', this, {
|
|
114
85
|
operation,
|
|
@@ -124,9 +95,9 @@ export default class History {
|
|
|
124
95
|
*
|
|
125
96
|
* Note that there may be gaps in operations base versions.
|
|
126
97
|
*
|
|
127
|
-
* @param
|
|
128
|
-
* @param
|
|
129
|
-
* @returns
|
|
98
|
+
* @param fromBaseVersion Base version from which operations should be returned (inclusive).
|
|
99
|
+
* @param toBaseVersion Base version up to which operations should be returned (exclusive).
|
|
100
|
+
* @returns History operations for the given range, in chronological order.
|
|
130
101
|
*/
|
|
131
102
|
getOperations(fromBaseVersion, toBaseVersion = this.version) {
|
|
132
103
|
// When there is no operation in the history, return an empty array.
|
|
@@ -174,9 +145,8 @@ export default class History {
|
|
|
174
145
|
/**
|
|
175
146
|
* Returns operation from the history that bases on given `baseVersion`.
|
|
176
147
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @returns
|
|
179
|
-
* there is no such operation in history.
|
|
148
|
+
* @param baseVersion Base version of the operation to get.
|
|
149
|
+
* @returns Operation with given base version or `undefined` if there is no such operation in history.
|
|
180
150
|
*/
|
|
181
151
|
getOperation(baseVersion) {
|
|
182
152
|
const operationIndex = this._baseVersionToOperationIndex.get(baseVersion);
|
|
@@ -189,8 +159,8 @@ export default class History {
|
|
|
189
159
|
* Marks in history that one operation is an operation that is undoing the other operation. By marking operation this way,
|
|
190
160
|
* history is keeping more context information about operations, which helps in operational transformation.
|
|
191
161
|
*
|
|
192
|
-
* @param
|
|
193
|
-
* @param
|
|
162
|
+
* @param undoneOperation Operation which is undone by `undoingOperation`.
|
|
163
|
+
* @param undoingOperation Operation which undoes `undoneOperation`.
|
|
194
164
|
*/
|
|
195
165
|
setOperationAsUndone(undoneOperation, undoingOperation) {
|
|
196
166
|
this._undoPairs.set(undoingOperation, undoneOperation);
|
|
@@ -199,8 +169,8 @@ export default class History {
|
|
|
199
169
|
/**
|
|
200
170
|
* Checks whether given `operation` is undoing any other operation.
|
|
201
171
|
*
|
|
202
|
-
* @param
|
|
203
|
-
* @returns
|
|
172
|
+
* @param operation Operation to check.
|
|
173
|
+
* @returns `true` if given `operation` is undoing any other operation, `false` otherwise.
|
|
204
174
|
*/
|
|
205
175
|
isUndoingOperation(operation) {
|
|
206
176
|
return this._undoPairs.has(operation);
|
|
@@ -208,8 +178,8 @@ export default class History {
|
|
|
208
178
|
/**
|
|
209
179
|
* Checks whether given `operation` has been undone by any other operation.
|
|
210
180
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @returns
|
|
181
|
+
* @param operation Operation to check.
|
|
182
|
+
* @returns `true` if given `operation` has been undone any other operation, `false` otherwise.
|
|
213
183
|
*/
|
|
214
184
|
isUndoneOperation(operation) {
|
|
215
185
|
return this._undoneOperations.has(operation);
|
|
@@ -217,9 +187,8 @@ export default class History {
|
|
|
217
187
|
/**
|
|
218
188
|
* For given `undoingOperation`, returns the operation which has been undone by it.
|
|
219
189
|
*
|
|
220
|
-
* @
|
|
221
|
-
*
|
|
222
|
-
* `undoingOperation` or `undefined` if given `undoingOperation` is not undoing any other operation.
|
|
190
|
+
* @returns Operation that has been undone by given `undoingOperation` or `undefined`
|
|
191
|
+
* if given `undoingOperation` is not undoing any other operation.
|
|
223
192
|
*/
|
|
224
193
|
getUndoneOperation(undoingOperation) {
|
|
225
194
|
return this._undoPairs.get(undoingOperation);
|
package/src/model/item.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
|
export {};
|
|
@@ -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
|
/**
|
|
@@ -19,17 +19,12 @@ import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
|
19
19
|
* **Note:** Be very careful when dealing with `LivePosition`. Each `LivePosition` instance bind events that might
|
|
20
20
|
* have to be unbound.
|
|
21
21
|
* Use {@link module:engine/model/liveposition~LivePosition#detach} whenever you don't need `LivePosition` anymore.
|
|
22
|
-
*
|
|
23
|
-
* @extends module:engine/model/position~Position
|
|
24
22
|
*/
|
|
25
23
|
export default class LivePosition extends EmitterMixin(Position) {
|
|
26
24
|
/**
|
|
27
25
|
* Creates a live position.
|
|
28
26
|
*
|
|
29
27
|
* @see module:engine/model/position~Position
|
|
30
|
-
* @param {module:engine/model/rootelement~RootElement} root
|
|
31
|
-
* @param {Array.<Number>} path
|
|
32
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
33
28
|
*/
|
|
34
29
|
constructor(root, path, stickiness = 'toNone') {
|
|
35
30
|
super(root, path, stickiness);
|
|
@@ -53,48 +48,28 @@ export default class LivePosition extends EmitterMixin(Position) {
|
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
50
|
* Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position.
|
|
56
|
-
*
|
|
57
|
-
* @returns {module:engine/model/position~Position}
|
|
58
51
|
*/
|
|
59
52
|
toPosition() {
|
|
60
53
|
return new Position(this.root, this.path.slice(), this.stickiness);
|
|
61
54
|
}
|
|
62
55
|
/**
|
|
63
56
|
* Creates a `LivePosition` instance that is equal to position.
|
|
64
|
-
*
|
|
65
|
-
* @param {module:engine/model/position~Position} position
|
|
66
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
67
|
-
* @returns {module:engine/model/liveposition~LivePosition}
|
|
68
57
|
*/
|
|
69
58
|
static fromPosition(position, stickiness) {
|
|
70
59
|
return new this(position.root, position.path.slice(), stickiness ? stickiness : position.stickiness);
|
|
71
60
|
}
|
|
72
61
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
* livePosition.is( 'position' ); // -> true
|
|
77
|
-
* livePosition.is( 'model:position' ); // -> true
|
|
78
|
-
* livePosition.is( 'liveposition' ); // -> true
|
|
79
|
-
* livePosition.is( 'model:livePosition' ); // -> true
|
|
80
|
-
*
|
|
81
|
-
* livePosition.is( 'view:position' ); // -> false
|
|
82
|
-
* livePosition.is( 'documentSelection' ); // -> false
|
|
83
|
-
*
|
|
84
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
85
|
-
*
|
|
86
|
-
* @param {String} type
|
|
87
|
-
* @returns {Boolean}
|
|
88
|
-
*/
|
|
62
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
63
|
+
// Proper overload would interfere with that.
|
|
89
64
|
LivePosition.prototype.is = function (type) {
|
|
90
65
|
return type === 'livePosition' || type === 'model:livePosition' ||
|
|
91
66
|
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
92
67
|
type == 'position' || type === 'model:position';
|
|
93
68
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Binds this `LivePosition` to the {@link module:engine/model/document~Document document} that owns
|
|
71
|
+
* this position's {@link module:engine/model/position~Position#root root}.
|
|
72
|
+
*/
|
|
98
73
|
function bindWithDocument() {
|
|
99
74
|
this.listenTo(this.root.document.model, 'applyOperation', (event, args) => {
|
|
100
75
|
const operation = args[0];
|
|
@@ -104,10 +79,9 @@ function bindWithDocument() {
|
|
|
104
79
|
transform.call(this, operation);
|
|
105
80
|
}, { priority: 'low' });
|
|
106
81
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
82
|
+
/**
|
|
83
|
+
* Updates this position accordingly to the updates applied to the model. Bases on change events.
|
|
84
|
+
*/
|
|
111
85
|
function transform(operation) {
|
|
112
86
|
const result = this.getTransformedByOperation(operation);
|
|
113
87
|
if (!this.isEqual(result)) {
|
package/src/model/liverange.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
|
/**
|
|
@@ -35,47 +35,28 @@ export default class LiveRange extends EmitterMixin(Range) {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Creates a {@link module:engine/model/range~Range range instance} that is equal to this live range.
|
|
38
|
-
*
|
|
39
|
-
* @returns {module:engine/model/range~Range}
|
|
40
38
|
*/
|
|
41
39
|
toRange() {
|
|
42
40
|
return new Range(this.start, this.end);
|
|
43
41
|
}
|
|
44
42
|
/**
|
|
45
43
|
* Creates a `LiveRange` instance that is equal to the given range.
|
|
46
|
-
*
|
|
47
|
-
* @param {module:engine/model/range~Range} range
|
|
48
|
-
* @returns {module:engine/model/liverange~LiveRange}
|
|
49
44
|
*/
|
|
50
45
|
static fromRange(range) {
|
|
51
46
|
return new LiveRange(range.start, range.end);
|
|
52
47
|
}
|
|
53
48
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* liveRange.is( 'range' ); // -> true
|
|
58
|
-
* liveRange.is( 'model:range' ); // -> true
|
|
59
|
-
* liveRange.is( 'liveRange' ); // -> true
|
|
60
|
-
* liveRange.is( 'model:liveRange' ); // -> true
|
|
61
|
-
*
|
|
62
|
-
* liveRange.is( 'view:range' ); // -> false
|
|
63
|
-
* liveRange.is( 'documentSelection' ); // -> false
|
|
64
|
-
*
|
|
65
|
-
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
66
|
-
*
|
|
67
|
-
* @param {String} type
|
|
68
|
-
* @returns {Boolean}
|
|
69
|
-
*/
|
|
49
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
50
|
+
// Proper overload would interfere with that.
|
|
70
51
|
LiveRange.prototype.is = function (type) {
|
|
71
52
|
return type === 'liveRange' || type === 'model:liveRange' ||
|
|
72
53
|
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
73
54
|
type == 'range' || type === 'model:range';
|
|
74
55
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Binds this `LiveRange` to the {@link module:engine/model/document~Document document}
|
|
58
|
+
* that owns this range's {@link module:engine/model/range~Range#root root}.
|
|
59
|
+
*/
|
|
79
60
|
function bindWithDocument() {
|
|
80
61
|
this.listenTo(this.root.document.model, 'applyOperation', (event, args) => {
|
|
81
62
|
const operation = args[0];
|
|
@@ -85,10 +66,9 @@ function bindWithDocument() {
|
|
|
85
66
|
transform.call(this, operation);
|
|
86
67
|
}, { priority: 'low' });
|
|
87
68
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
69
|
+
/**
|
|
70
|
+
* Updates this range accordingly to the updates applied to the model. Bases on change events.
|
|
71
|
+
*/
|
|
92
72
|
function transform(operation) {
|
|
93
73
|
// Transform the range by the operation. Join the result ranges if needed.
|
|
94
74
|
const ranges = this.getTransformedByOperation(operation);
|
|
@@ -119,12 +99,9 @@ function transform(operation) {
|
|
|
119
99
|
this.fire('change:content', this.toRange(), { deletionPosition });
|
|
120
100
|
}
|
|
121
101
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// @param {module:engine/model/range~Range} range Range to check.
|
|
126
|
-
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
127
|
-
// @returns {Boolean}
|
|
102
|
+
/**
|
|
103
|
+
* Checks whether given operation changes something inside the range (even if it does not change boundaries).
|
|
104
|
+
*/
|
|
128
105
|
function doesOperationChangeRangeContent(range, operation) {
|
|
129
106
|
switch (operation.type) {
|
|
130
107
|
case 'insert':
|