@ckeditor/ckeditor5-engine 35.3.2 → 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 +10 -8
- package/src/controller/editingcontroller.js +3 -4
- package/src/conversion/conversion.js +2 -3
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +3 -3
- package/src/conversion/downcasthelpers.js +2 -3
- package/src/conversion/mapper.js +3 -4
- package/src/conversion/modelconsumable.js +2 -2
- package/src/conversion/upcastdispatcher.js +3 -4
- package/src/conversion/upcasthelpers.js +10 -3
- package/src/conversion/viewconsumable.js +2 -2
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.js +1 -1
- package/src/dataprocessor/htmldataprocessor.js +3 -3
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +6 -2
- package/src/dev-utils/model.js +3 -3
- 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 +13 -3
- package/src/model/batch.js +10 -47
- package/src/model/differ.js +81 -174
- package/src/model/document.js +38 -97
- package/src/model/documentfragment.js +44 -97
- package/src/model/documentselection.js +152 -251
- package/src/model/element.js +48 -101
- package/src/model/history.js +15 -46
- package/src/model/item.js +1 -1
- package/src/model/liveposition.js +11 -39
- package/src/model/liverange.js +14 -38
- package/src/model/markercollection.js +42 -115
- package/src/model/model.js +214 -292
- package/src/model/node.js +36 -128
- package/src/model/nodelist.js +12 -41
- package/src/model/operation/attributeoperation.js +14 -45
- package/src/model/operation/detachoperation.js +4 -17
- package/src/model/operation/insertoperation.js +7 -35
- package/src/model/operation/markeroperation.js +9 -48
- package/src/model/operation/mergeoperation.js +9 -42
- package/src/model/operation/moveoperation.js +15 -39
- 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 +9 -29
- package/src/model/operation/rootattributeoperation.js +19 -48
- package/src/model/operation/splitoperation.js +10 -48
- package/src/model/operation/transform.js +110 -151
- package/src/model/operation/utils.js +37 -52
- package/src/model/position.js +118 -230
- package/src/model/range.js +146 -202
- package/src/model/rootelement.js +8 -47
- package/src/model/schema.js +245 -282
- package/src/model/selection.js +135 -196
- package/src/model/text.js +10 -37
- package/src/model/textproxy.js +16 -70
- package/src/model/treewalker.js +11 -102
- 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 +25 -25
- package/src/model/utils/getselectedcontent.js +3 -6
- package/src/model/utils/insertcontent.js +37 -130
- package/src/model/utils/insertobject.js +40 -40
- package/src/model/utils/modifyselection.js +24 -34
- package/src/model/utils/selection-post-fixer.js +53 -59
- package/src/model/writer.js +209 -316
- package/src/view/attributeelement.js +2 -2
- package/src/view/containerelement.js +1 -1
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.js +3 -5
- package/src/view/documentfragment.js +50 -4
- package/src/view/documentselection.js +2 -3
- package/src/view/domconverter.js +4 -8
- package/src/view/downcastwriter.js +2 -3
- package/src/view/editableelement.js +2 -3
- package/src/view/element.js +6 -8
- package/src/view/elementdefinition.js +1 -1
- package/src/view/emptyelement.js +2 -2
- package/src/view/filler.js +2 -3
- package/src/view/item.js +1 -1
- package/src/view/matcher.js +2 -2
- package/src/view/node.js +2 -5
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +3 -6
- package/src/view/observer/bubblingeventinfo.js +2 -2
- 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 +2 -2
- package/src/view/observer/focusobserver.js +25 -3
- package/src/view/observer/inputobserver.js +2 -2
- package/src/view/observer/keyobserver.js +2 -2
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +3 -3
- package/src/view/observer/selectionobserver.js +21 -3
- package/src/view/observer/tabobserver.js +2 -2
- package/src/view/placeholder.js +1 -1
- package/src/view/position.js +2 -3
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +2 -2
- package/src/view/renderer.js +3 -12
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +2 -6
- 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 +2 -2
- package/src/view/treewalker.js +2 -2
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.js +2 -3
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +7 -7
- package/theme/placeholder.css +1 -1
- package/theme/renderer.css +1 -1
package/src/model/batch.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
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
|
/**
|
|
6
6
|
* @module engine/model/batch
|
|
7
7
|
*/
|
|
8
|
-
import { logWarning } from '@ckeditor/ckeditor5-utils
|
|
8
|
+
import { logWarning } from '@ckeditor/ckeditor5-utils';
|
|
9
9
|
/**
|
|
10
10
|
* A batch instance groups model changes ({@link module:engine/model/operation/operation~Operation operations}). All operations
|
|
11
11
|
* grouped in a single batch can be reverted together, so you can also think about a batch as of a single undo step. If you want
|
|
12
12
|
* to extend a given undo step, you can add more changes to the batch using {@link module:engine/model/model~Model#enqueueChange}:
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* model.enqueueChange( batch, writer => {
|
|
16
|
+
* writer.insertText( 'foo', paragraph, 'end' );
|
|
17
|
+
* } );
|
|
18
|
+
* ```
|
|
17
19
|
*
|
|
18
20
|
* @see module:engine/model/model~Model#enqueueChange
|
|
19
21
|
* @see module:engine/model/model~Model#change
|
|
@@ -24,13 +26,8 @@ export default class Batch {
|
|
|
24
26
|
*
|
|
25
27
|
* @see module:engine/model/model~Model#enqueueChange
|
|
26
28
|
* @see module:engine/model/model~Model#change
|
|
27
|
-
* @param
|
|
29
|
+
* @param type A set of flags that specify the type of the batch. Batch type can alter how some of the features work
|
|
28
30
|
* when encountering a given `Batch` instance (for example, when a feature listens to applied operations).
|
|
29
|
-
* @param {Boolean} [type.isUndoable=true] Whether a batch can be undone through undo feature.
|
|
30
|
-
* @param {Boolean} [type.isLocal=true] Whether a batch includes operations created locally (`true`) or operations created on
|
|
31
|
-
* other, remote editors (`false`).
|
|
32
|
-
* @param {Boolean} [type.isUndo=false] Whether a batch was created by the undo feature and undoes other operations.
|
|
33
|
-
* @param {Boolean} [type.isTyping=false] Whether a batch includes operations connected with a typing action.
|
|
34
31
|
*/
|
|
35
32
|
constructor(type = {}) {
|
|
36
33
|
if (typeof type === 'string') {
|
|
@@ -45,40 +42,10 @@ export default class Batch {
|
|
|
45
42
|
logWarning('batch-constructor-deprecated-string-type');
|
|
46
43
|
}
|
|
47
44
|
const { isUndoable = true, isLocal = true, isUndo = false, isTyping = false } = type;
|
|
48
|
-
/**
|
|
49
|
-
* An array of operations that compose this batch.
|
|
50
|
-
*
|
|
51
|
-
* @readonly
|
|
52
|
-
* @type {Array.<module:engine/model/operation/operation~Operation>}
|
|
53
|
-
*/
|
|
54
45
|
this.operations = [];
|
|
55
|
-
/**
|
|
56
|
-
* Whether the batch can be undone through the undo feature.
|
|
57
|
-
*
|
|
58
|
-
* @readonly
|
|
59
|
-
* @type {Boolean}
|
|
60
|
-
*/
|
|
61
46
|
this.isUndoable = isUndoable;
|
|
62
|
-
/**
|
|
63
|
-
* Whether the batch includes operations created locally (`true`) or operations created on other, remote editors (`false`).
|
|
64
|
-
*
|
|
65
|
-
* @readonly
|
|
66
|
-
* @type {Boolean}
|
|
67
|
-
*/
|
|
68
47
|
this.isLocal = isLocal;
|
|
69
|
-
/**
|
|
70
|
-
* Whether the batch was created by the undo feature and undoes other operations.
|
|
71
|
-
*
|
|
72
|
-
* @readonly
|
|
73
|
-
* @type {Boolean}
|
|
74
|
-
*/
|
|
75
48
|
this.isUndo = isUndo;
|
|
76
|
-
/**
|
|
77
|
-
* Whether the batch includes operations connected with typing.
|
|
78
|
-
*
|
|
79
|
-
* @readonly
|
|
80
|
-
* @type {Boolean}
|
|
81
|
-
*/
|
|
82
49
|
this.isTyping = isTyping;
|
|
83
50
|
}
|
|
84
51
|
/**
|
|
@@ -92,7 +59,6 @@ export default class Batch {
|
|
|
92
59
|
* changes.
|
|
93
60
|
*
|
|
94
61
|
* @deprecated
|
|
95
|
-
* @type {'default'}
|
|
96
62
|
*/
|
|
97
63
|
get type() {
|
|
98
64
|
/**
|
|
@@ -107,9 +73,6 @@ export default class Batch {
|
|
|
107
73
|
/**
|
|
108
74
|
* Returns the base version of this batch, which is equal to the base version of the first operation in the batch.
|
|
109
75
|
* If there are no operations in the batch or neither operation has the base version set, it returns `null`.
|
|
110
|
-
*
|
|
111
|
-
* @readonly
|
|
112
|
-
* @type {Number|null}
|
|
113
76
|
*/
|
|
114
77
|
get baseVersion() {
|
|
115
78
|
for (const op of this.operations) {
|
|
@@ -122,8 +85,8 @@ export default class Batch {
|
|
|
122
85
|
/**
|
|
123
86
|
* Adds an operation to the batch instance.
|
|
124
87
|
*
|
|
125
|
-
* @param
|
|
126
|
-
* @returns
|
|
88
|
+
* @param operation An operation to add.
|
|
89
|
+
* @returns The added operation.
|
|
127
90
|
*/
|
|
128
91
|
addOperation(operation) {
|
|
129
92
|
operation.batch = this;
|
package/src/model/differ.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
|
/**
|
|
@@ -19,33 +19,20 @@ export default class Differ {
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates a `Differ` instance.
|
|
21
21
|
*
|
|
22
|
-
* @param
|
|
22
|
+
* @param markerCollection Model's marker collection.
|
|
23
23
|
*/
|
|
24
24
|
constructor(markerCollection) {
|
|
25
|
-
/**
|
|
26
|
-
* Reference to the model's marker collection.
|
|
27
|
-
*
|
|
28
|
-
* @private
|
|
29
|
-
* @type {module:engine/model/markercollection~MarkerCollection}
|
|
30
|
-
*/
|
|
31
|
-
this._markerCollection = markerCollection;
|
|
32
25
|
/**
|
|
33
26
|
* A map that stores changes that happened in a given element.
|
|
34
27
|
*
|
|
35
28
|
* The keys of the map are references to the model elements.
|
|
36
29
|
* The values of the map are arrays with changes that were done on this element.
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
* @type {Map}
|
|
40
30
|
*/
|
|
41
31
|
this._changesInElement = new Map();
|
|
42
32
|
/**
|
|
43
33
|
* A map that stores "element's children snapshots". A snapshot is representing children of a given element before
|
|
44
34
|
* the first change was applied on that element. Snapshot items are objects with two properties: `name`,
|
|
45
35
|
* containing the element name (or `'$text'` for a text node) and `attributes` which is a map of the node's attributes.
|
|
46
|
-
*
|
|
47
|
-
* @private
|
|
48
|
-
* @type {Map}
|
|
49
36
|
*/
|
|
50
37
|
this._elementSnapshots = new Map();
|
|
51
38
|
/**
|
|
@@ -55,17 +42,11 @@ export default class Differ {
|
|
|
55
42
|
* The values of the map are objects with the following properties:
|
|
56
43
|
* - `oldMarkerData`,
|
|
57
44
|
* - `newMarkerData`.
|
|
58
|
-
*
|
|
59
|
-
* @private
|
|
60
|
-
* @type {Map.<String, Object>}
|
|
61
45
|
*/
|
|
62
46
|
this._changedMarkers = new Map();
|
|
63
47
|
/**
|
|
64
48
|
* Stores the number of changes that were processed. Used to order the changes chronologically. It is important
|
|
65
49
|
* when changes are sorted.
|
|
66
|
-
*
|
|
67
|
-
* @private
|
|
68
|
-
* @type {Number}
|
|
69
50
|
*/
|
|
70
51
|
this._changeCount = 0;
|
|
71
52
|
/**
|
|
@@ -74,9 +55,6 @@ export default class Differ {
|
|
|
74
55
|
* return the cached value instead of calculating it again.
|
|
75
56
|
*
|
|
76
57
|
* This property stores those changes that did not take place in graveyard root.
|
|
77
|
-
*
|
|
78
|
-
* @private
|
|
79
|
-
* @type {Array.<Object>|null}
|
|
80
58
|
*/
|
|
81
59
|
this._cachedChanges = null;
|
|
82
60
|
/**
|
|
@@ -85,24 +63,16 @@ export default class Differ {
|
|
|
85
63
|
* return the cached value instead of calculating it again.
|
|
86
64
|
*
|
|
87
65
|
* This property stores all changes evaluated by `Differ`, including those that took place in the graveyard.
|
|
88
|
-
*
|
|
89
|
-
* @private
|
|
90
|
-
* @type {Array.<Object>|null}
|
|
91
66
|
*/
|
|
92
67
|
this._cachedChangesWithGraveyard = null;
|
|
93
68
|
/**
|
|
94
69
|
* Set of model items that were marked to get refreshed in {@link #_refreshItem}.
|
|
95
|
-
*
|
|
96
|
-
* @private
|
|
97
|
-
* @type {Set.<module:engine/model/item~Item>}
|
|
98
70
|
*/
|
|
99
71
|
this._refreshedItems = new Set();
|
|
72
|
+
this._markerCollection = markerCollection;
|
|
100
73
|
}
|
|
101
74
|
/**
|
|
102
75
|
* Informs whether there are any changes buffered in `Differ`.
|
|
103
|
-
*
|
|
104
|
-
* @readonly
|
|
105
|
-
* @type {Boolean}
|
|
106
76
|
*/
|
|
107
77
|
get isEmpty() {
|
|
108
78
|
return this._changesInElement.size == 0 && this._changedMarkers.size == 0;
|
|
@@ -113,7 +83,7 @@ export default class Differ {
|
|
|
113
83
|
* Operation type is checked and it is checked which nodes it will affect. These nodes are then stored in `Differ`
|
|
114
84
|
* in the state before the operation is executed.
|
|
115
85
|
*
|
|
116
|
-
* @param
|
|
86
|
+
* @param operationToBuffer An operation to buffer.
|
|
117
87
|
*/
|
|
118
88
|
bufferOperation(operationToBuffer) {
|
|
119
89
|
// Below we take an operation, check its type, then use its parameters in marking (private) methods.
|
|
@@ -211,9 +181,9 @@ export default class Differ {
|
|
|
211
181
|
/**
|
|
212
182
|
* Buffers a marker change.
|
|
213
183
|
*
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
216
|
-
* @param
|
|
184
|
+
* @param markerName The name of the marker that changed.
|
|
185
|
+
* @param oldMarkerData Marker data before the change.
|
|
186
|
+
* @param newMarkerData Marker data after the change.
|
|
217
187
|
*/
|
|
218
188
|
bufferMarkerChange(markerName, oldMarkerData, newMarkerData) {
|
|
219
189
|
const buffered = this._changedMarkers.get(markerName);
|
|
@@ -235,7 +205,7 @@ export default class Differ {
|
|
|
235
205
|
/**
|
|
236
206
|
* Returns all markers that should be removed as a result of buffered changes.
|
|
237
207
|
*
|
|
238
|
-
* @returns
|
|
208
|
+
* @returns Markers to remove. Each array item is an object containing the `name` and `range` properties.
|
|
239
209
|
*/
|
|
240
210
|
getMarkersToRemove() {
|
|
241
211
|
const result = [];
|
|
@@ -249,7 +219,7 @@ export default class Differ {
|
|
|
249
219
|
/**
|
|
250
220
|
* Returns all markers which should be added as a result of buffered changes.
|
|
251
221
|
*
|
|
252
|
-
* @returns
|
|
222
|
+
* @returns Markers to add. Each array item is an object containing the `name` and `range` properties.
|
|
253
223
|
*/
|
|
254
224
|
getMarkersToAdd() {
|
|
255
225
|
const result = [];
|
|
@@ -262,8 +232,6 @@ export default class Differ {
|
|
|
262
232
|
}
|
|
263
233
|
/**
|
|
264
234
|
* Returns all markers which changed.
|
|
265
|
-
*
|
|
266
|
-
* @returns {Array.<Object>}
|
|
267
235
|
*/
|
|
268
236
|
getChangedMarkers() {
|
|
269
237
|
return Array.from(this._changedMarkers).map(([name, change]) => ({
|
|
@@ -283,8 +251,6 @@ export default class Differ {
|
|
|
283
251
|
* * attribute changes,
|
|
284
252
|
* * changes of markers which were defined as `affectsData`,
|
|
285
253
|
* * changes of markers' `affectsData` property.
|
|
286
|
-
*
|
|
287
|
-
* @returns {Boolean}
|
|
288
254
|
*/
|
|
289
255
|
hasDataChanges() {
|
|
290
256
|
if (this._changesInElement.size > 0) {
|
|
@@ -318,10 +284,10 @@ export default class Differ {
|
|
|
318
284
|
* Because calculating the diff is a costly operation, the result is cached. If no new operation was buffered since the
|
|
319
285
|
* previous {@link #getChanges} call, the next call will return the cached value.
|
|
320
286
|
*
|
|
321
|
-
* @param
|
|
322
|
-
* @param
|
|
287
|
+
* @param options Additional options.
|
|
288
|
+
* @param options.includeChangesInGraveyard If set to `true`, also changes that happened
|
|
323
289
|
* in the graveyard root will be returned. By default, changes in the graveyard root are not returned.
|
|
324
|
-
* @returns
|
|
290
|
+
* @returns Diff between the old and the new model tree state.
|
|
325
291
|
*/
|
|
326
292
|
getChanges(options = {}) {
|
|
327
293
|
// If there are cached changes, just return them instead of calculating changes again.
|
|
@@ -465,8 +431,6 @@ export default class Differ {
|
|
|
465
431
|
}
|
|
466
432
|
/**
|
|
467
433
|
* Returns a set of model items that were marked to get refreshed.
|
|
468
|
-
*
|
|
469
|
-
* @return {Set.<module:engine/model/item~Item>}
|
|
470
434
|
*/
|
|
471
435
|
getRefreshedItems() {
|
|
472
436
|
return new Set(this._refreshedItems);
|
|
@@ -485,9 +449,8 @@ export default class Differ {
|
|
|
485
449
|
* Marks the given `item` in differ to be "refreshed". It means that the item will be marked as removed and inserted
|
|
486
450
|
* in the differ changes set, so it will be effectively re-converted when the differ changes are handled by a dispatcher.
|
|
487
451
|
*
|
|
488
|
-
* @protected
|
|
489
452
|
* @internal
|
|
490
|
-
* @param
|
|
453
|
+
* @param item Item to refresh.
|
|
491
454
|
*/
|
|
492
455
|
_refreshItem(item) {
|
|
493
456
|
if (this._isInInsertedElement(item.parent)) {
|
|
@@ -506,11 +469,6 @@ export default class Differ {
|
|
|
506
469
|
}
|
|
507
470
|
/**
|
|
508
471
|
* Saves and handles an insert change.
|
|
509
|
-
*
|
|
510
|
-
* @private
|
|
511
|
-
* @param {module:engine/model/element~Element} parent
|
|
512
|
-
* @param {Number} offset
|
|
513
|
-
* @param {Number} howMany
|
|
514
472
|
*/
|
|
515
473
|
_markInsert(parent, offset, howMany) {
|
|
516
474
|
const changeItem = { type: 'insert', offset, howMany, count: this._changeCount++ };
|
|
@@ -518,11 +476,6 @@ export default class Differ {
|
|
|
518
476
|
}
|
|
519
477
|
/**
|
|
520
478
|
* Saves and handles a remove change.
|
|
521
|
-
*
|
|
522
|
-
* @private
|
|
523
|
-
* @param {module:engine/model/element~Element} parent
|
|
524
|
-
* @param {Number} offset
|
|
525
|
-
* @param {Number} howMany
|
|
526
479
|
*/
|
|
527
480
|
_markRemove(parent, offset, howMany) {
|
|
528
481
|
const changeItem = { type: 'remove', offset, howMany, count: this._changeCount++ };
|
|
@@ -531,9 +484,6 @@ export default class Differ {
|
|
|
531
484
|
}
|
|
532
485
|
/**
|
|
533
486
|
* Saves and handles an attribute change.
|
|
534
|
-
*
|
|
535
|
-
* @private
|
|
536
|
-
* @param {module:engine/model/item~Item} item
|
|
537
487
|
*/
|
|
538
488
|
_markAttribute(item) {
|
|
539
489
|
const changeItem = { type: 'attribute', offset: item.startOffset, howMany: item.offsetSize, count: this._changeCount++ };
|
|
@@ -541,10 +491,6 @@ export default class Differ {
|
|
|
541
491
|
}
|
|
542
492
|
/**
|
|
543
493
|
* Saves and handles a model change.
|
|
544
|
-
*
|
|
545
|
-
* @private
|
|
546
|
-
* @param {module:engine/model/element~Element} parent
|
|
547
|
-
* @param {Object} changeItem
|
|
548
494
|
*/
|
|
549
495
|
_markChange(parent, changeItem) {
|
|
550
496
|
// First, make a snapshot of this parent's children (it will be made only if it was not made before).
|
|
@@ -566,10 +512,6 @@ export default class Differ {
|
|
|
566
512
|
}
|
|
567
513
|
/**
|
|
568
514
|
* Gets an array of changes that have already been saved for a given element.
|
|
569
|
-
*
|
|
570
|
-
* @private
|
|
571
|
-
* @param {module:engine/model/element~Element} element
|
|
572
|
-
* @returns {Array.<Object>}
|
|
573
515
|
*/
|
|
574
516
|
_getChangesForElement(element) {
|
|
575
517
|
let changes;
|
|
@@ -584,9 +526,6 @@ export default class Differ {
|
|
|
584
526
|
}
|
|
585
527
|
/**
|
|
586
528
|
* Saves a children snapshot for a given element.
|
|
587
|
-
*
|
|
588
|
-
* @private
|
|
589
|
-
* @param {module:engine/model/element~Element} element
|
|
590
529
|
*/
|
|
591
530
|
_makeSnapshot(element) {
|
|
592
531
|
if (!this._elementSnapshots.has(element)) {
|
|
@@ -597,9 +536,8 @@ export default class Differ {
|
|
|
597
536
|
* For a given newly saved change, compares it with a change already done on the element and modifies the incoming
|
|
598
537
|
* change and/or the old change.
|
|
599
538
|
*
|
|
600
|
-
* @
|
|
601
|
-
* @param
|
|
602
|
-
* @param {Array.<Object>} changes An array containing all the changes done on that element.
|
|
539
|
+
* @param inc Incoming (new) change.
|
|
540
|
+
* @param changes An array containing all the changes done on that element.
|
|
603
541
|
*/
|
|
604
542
|
_handleChange(inc, changes) {
|
|
605
543
|
// We need a helper variable that will store how many nodes are to be still handled for this change item.
|
|
@@ -807,11 +745,10 @@ export default class Differ {
|
|
|
807
745
|
/**
|
|
808
746
|
* Returns an object with a single insert change description.
|
|
809
747
|
*
|
|
810
|
-
* @
|
|
811
|
-
* @param
|
|
812
|
-
* @param
|
|
813
|
-
* @
|
|
814
|
-
* @returns {Object} The diff item.
|
|
748
|
+
* @param parent The element in which the change happened.
|
|
749
|
+
* @param offset The offset at which change happened.
|
|
750
|
+
* @param elementSnapshot The snapshot of the removed element a character.
|
|
751
|
+
* @returns The diff item.
|
|
815
752
|
*/
|
|
816
753
|
_getInsertDiff(parent, offset, elementSnapshot) {
|
|
817
754
|
return {
|
|
@@ -826,11 +763,10 @@ export default class Differ {
|
|
|
826
763
|
/**
|
|
827
764
|
* Returns an object with a single remove change description.
|
|
828
765
|
*
|
|
829
|
-
* @
|
|
830
|
-
* @param
|
|
831
|
-
* @param
|
|
832
|
-
* @
|
|
833
|
-
* @returns {Object} The diff item.
|
|
766
|
+
* @param parent The element in which change happened.
|
|
767
|
+
* @param offset The offset at which change happened.
|
|
768
|
+
* @param elementSnapshot The snapshot of the removed element a character.
|
|
769
|
+
* @returns The diff item.
|
|
834
770
|
*/
|
|
835
771
|
_getRemoveDiff(parent, offset, elementSnapshot) {
|
|
836
772
|
return {
|
|
@@ -845,11 +781,10 @@ export default class Differ {
|
|
|
845
781
|
/**
|
|
846
782
|
* Returns an array of objects where each one is a single attribute change description.
|
|
847
783
|
*
|
|
848
|
-
* @
|
|
849
|
-
* @param
|
|
850
|
-
* @param
|
|
851
|
-
* @
|
|
852
|
-
* @returns {Array.<Object>} An array containing one or more diff items.
|
|
784
|
+
* @param range The range where the change happened.
|
|
785
|
+
* @param oldAttributes A map, map iterator or compatible object that contains attributes before the change.
|
|
786
|
+
* @param newAttributes A map, map iterator or compatible object that contains attributes after the change.
|
|
787
|
+
* @returns An array containing one or more diff items.
|
|
853
788
|
*/
|
|
854
789
|
_getAttributesDiff(range, oldAttributes, newAttributes) {
|
|
855
790
|
// Results holder.
|
|
@@ -895,10 +830,6 @@ export default class Differ {
|
|
|
895
830
|
}
|
|
896
831
|
/**
|
|
897
832
|
* Checks whether given element or any of its parents is an element that is buffered as an inserted element.
|
|
898
|
-
*
|
|
899
|
-
* @private
|
|
900
|
-
* @param {module:engine/model/element~Element} element Element to check.
|
|
901
|
-
* @returns {Boolean}
|
|
902
833
|
*/
|
|
903
834
|
_isInInsertedElement(element) {
|
|
904
835
|
const parent = element.parent;
|
|
@@ -919,11 +850,6 @@ export default class Differ {
|
|
|
919
850
|
/**
|
|
920
851
|
* Removes deeply all buffered changes that are registered in elements from range specified by `parent`, `offset`
|
|
921
852
|
* and `howMany`.
|
|
922
|
-
*
|
|
923
|
-
* @private
|
|
924
|
-
* @param {module:engine/model/element~Element} parent
|
|
925
|
-
* @param {Number} offset
|
|
926
|
-
* @param {Number} howMany
|
|
927
853
|
*/
|
|
928
854
|
_removeAllNestedChanges(parent, offset, howMany) {
|
|
929
855
|
const range = new Range(Position._createAt(parent, offset), Position._createAt(parent, offset + howMany));
|
|
@@ -936,8 +862,10 @@ export default class Differ {
|
|
|
936
862
|
}
|
|
937
863
|
}
|
|
938
864
|
}
|
|
939
|
-
|
|
940
|
-
|
|
865
|
+
/**
|
|
866
|
+
* Returns an array that is a copy of passed child list with the exception that text nodes are split to one or more
|
|
867
|
+
* objects, each representing one character and attributes set on that character.
|
|
868
|
+
*/
|
|
941
869
|
function _getChildrenSnapshot(children) {
|
|
942
870
|
const snapshot = [];
|
|
943
871
|
for (const child of children) {
|
|
@@ -958,51 +886,53 @@ function _getChildrenSnapshot(children) {
|
|
|
958
886
|
}
|
|
959
887
|
return snapshot;
|
|
960
888
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
889
|
+
/**
|
|
890
|
+
* Generates array of actions for given changes set.
|
|
891
|
+
* It simulates what `diff` function does.
|
|
892
|
+
* Generated actions are:
|
|
893
|
+
* - 'e' for 'equal' - when item at that position did not change,
|
|
894
|
+
* - 'i' for 'insert' - when item at that position was inserted,
|
|
895
|
+
* - 'r' for 'remove' - when item at that position was removed,
|
|
896
|
+
* - 'a' for 'attribute' - when item at that position has it attributes changed.
|
|
897
|
+
*
|
|
898
|
+
* Example (assume that uppercase letters have bold attribute, compare with function code):
|
|
899
|
+
*
|
|
900
|
+
* children before: fooBAR
|
|
901
|
+
* children after: foxybAR
|
|
902
|
+
*
|
|
903
|
+
* changes: type: remove, offset: 1, howMany: 1
|
|
904
|
+
* type: insert, offset: 2, howMany: 2
|
|
905
|
+
* type: attribute, offset: 4, howMany: 1
|
|
906
|
+
*
|
|
907
|
+
* expected actions: equal (f), remove (o), equal (o), insert (x), insert (y), attribute (b), equal (A), equal (R)
|
|
908
|
+
*
|
|
909
|
+
* steps taken by th script:
|
|
910
|
+
*
|
|
911
|
+
* 1. change = "type: remove, offset: 1, howMany: 1"; offset = 0; oldChildrenHandled = 0
|
|
912
|
+
* 1.1 between this change and the beginning is one not-changed node, fill with one equal action, one old child has been handled
|
|
913
|
+
* 1.2 this change removes one node, add one remove action
|
|
914
|
+
* 1.3 change last visited `offset` to 1
|
|
915
|
+
* 1.4 since an old child has been removed, one more old child has been handled
|
|
916
|
+
* 1.5 actions at this point are: equal, remove
|
|
917
|
+
*
|
|
918
|
+
* 2. change = "type: insert, offset: 2, howMany: 2"; offset = 1; oldChildrenHandled = 2
|
|
919
|
+
* 2.1 between this change and previous change is one not-changed node, add equal action, another one old children has been handled
|
|
920
|
+
* 2.2 this change inserts two nodes, add two insert actions
|
|
921
|
+
* 2.3 change last visited offset to the end of the inserted range, that is 4
|
|
922
|
+
* 2.4 actions at this point are: equal, remove, equal, insert, insert
|
|
923
|
+
*
|
|
924
|
+
* 3. change = "type: attribute, offset: 4, howMany: 1"; offset = 4, oldChildrenHandled = 3
|
|
925
|
+
* 3.1 between this change and previous change are no not-changed nodes
|
|
926
|
+
* 3.2 this change changes one node, add one attribute action
|
|
927
|
+
* 3.3 change last visited `offset` to the end of change range, that is 5
|
|
928
|
+
* 3.4 since an old child has been changed, one more old child has been handled
|
|
929
|
+
* 3.5 actions at this point are: equal, remove, equal, insert, insert, attribute
|
|
930
|
+
*
|
|
931
|
+
* 4. after loop oldChildrenHandled = 4, oldChildrenLength = 6 (fooBAR is 6 characters)
|
|
932
|
+
* 4.1 fill up with two equal actions
|
|
933
|
+
*
|
|
934
|
+
* The result actions are: equal, remove, equal, insert, insert, attribute, equal, equal.
|
|
935
|
+
*/
|
|
1006
936
|
function _generateActionsFromChanges(oldChildrenLength, changes) {
|
|
1007
937
|
const actions = [];
|
|
1008
938
|
let offset = 0;
|
|
@@ -1050,34 +980,11 @@ function _generateActionsFromChanges(oldChildrenLength, changes) {
|
|
|
1050
980
|
}
|
|
1051
981
|
return actions;
|
|
1052
982
|
}
|
|
1053
|
-
|
|
983
|
+
/**
|
|
984
|
+
* Filter callback for Array.filter that filters out change entries that are in graveyard.
|
|
985
|
+
*/
|
|
1054
986
|
function _changesInGraveyardFilter(entry) {
|
|
1055
987
|
const posInGy = 'position' in entry && entry.position.root.rootName == '$graveyard';
|
|
1056
988
|
const rangeInGy = 'range' in entry && entry.range.root.rootName == '$graveyard';
|
|
1057
989
|
return !posInGy && !rangeInGy;
|
|
1058
990
|
}
|
|
1059
|
-
/**
|
|
1060
|
-
* The type of diff item.
|
|
1061
|
-
*
|
|
1062
|
-
* @member {'attribute'} module:engine/model/differ~DiffItemAttribute#type
|
|
1063
|
-
*/
|
|
1064
|
-
/**
|
|
1065
|
-
* The name of the changed attribute.
|
|
1066
|
-
*
|
|
1067
|
-
* @member {String} module:engine/model/differ~DiffItemAttribute#attributeKey
|
|
1068
|
-
*/
|
|
1069
|
-
/**
|
|
1070
|
-
* An attribute previous value (before change).
|
|
1071
|
-
*
|
|
1072
|
-
* @member {String} module:engine/model/differ~DiffItemAttribute#attributeOldValue
|
|
1073
|
-
*/
|
|
1074
|
-
/**
|
|
1075
|
-
* An attribute new value (after change).
|
|
1076
|
-
*
|
|
1077
|
-
* @member {String} module:engine/model/differ~DiffItemAttribute#attributeNewValue
|
|
1078
|
-
*/
|
|
1079
|
-
/**
|
|
1080
|
-
* The range where the change happened.
|
|
1081
|
-
*
|
|
1082
|
-
* @member {module:engine/model/range~Range} module:engine/model/differ~DiffItemAttribute#range
|
|
1083
|
-
*/
|