@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -8,36 +8,23 @@
|
|
|
8
8
|
import Operation from './operation';
|
|
9
9
|
import Range from '../range';
|
|
10
10
|
import { _remove } from './utils';
|
|
11
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils
|
|
11
|
+
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
12
12
|
// @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;
|
|
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
|
/**
|
|
@@ -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
|
/**
|
|
@@ -12,45 +12,24 @@ import MoveOperation from './moveoperation';
|
|
|
12
12
|
import { _insert, _normalizeNodes } from './utils';
|
|
13
13
|
import Text from '../text';
|
|
14
14
|
import Element from '../element';
|
|
15
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils
|
|
15
|
+
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
16
16
|
/**
|
|
17
17
|
* Operation to insert one or more nodes at given position in the model.
|
|
18
|
-
*
|
|
19
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
20
18
|
*/
|
|
21
19
|
export default class InsertOperation extends Operation {
|
|
22
20
|
/**
|
|
23
21
|
* Creates an insert operation.
|
|
24
22
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
23
|
+
* @param position Position of insertion.
|
|
24
|
+
* @param nodes The list of nodes to be inserted.
|
|
25
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
28
26
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
29
27
|
*/
|
|
30
28
|
constructor(position, nodes, baseVersion) {
|
|
31
29
|
super(baseVersion);
|
|
32
|
-
/**
|
|
33
|
-
* Position of insertion.
|
|
34
|
-
*
|
|
35
|
-
* @readonly
|
|
36
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/insertoperation~InsertOperation#position
|
|
37
|
-
*/
|
|
38
30
|
this.position = position.clone();
|
|
39
31
|
this.position.stickiness = 'toNone';
|
|
40
|
-
/**
|
|
41
|
-
* List of nodes to insert.
|
|
42
|
-
*
|
|
43
|
-
* @readonly
|
|
44
|
-
* @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
|
|
45
|
-
*/
|
|
46
32
|
this.nodes = new NodeList(_normalizeNodes(nodes));
|
|
47
|
-
/**
|
|
48
|
-
* Flag deciding how the operation should be transformed. If set to `true`, nodes might get additional attributes
|
|
49
|
-
* during operational transformation. This happens when the operation insertion position is inside of a range
|
|
50
|
-
* where attributes have changed.
|
|
51
|
-
*
|
|
52
|
-
* @member {Boolean} module:engine/model/operation/insertoperation~InsertOperation#shouldReceiveAttributes
|
|
53
|
-
*/
|
|
54
33
|
this.shouldReceiveAttributes = false;
|
|
55
34
|
}
|
|
56
35
|
/**
|
|
@@ -61,16 +40,12 @@ export default class InsertOperation extends Operation {
|
|
|
61
40
|
}
|
|
62
41
|
/**
|
|
63
42
|
* Total offset size of inserted nodes.
|
|
64
|
-
*
|
|
65
|
-
* @returns {Number}
|
|
66
43
|
*/
|
|
67
44
|
get howMany() {
|
|
68
45
|
return this.nodes.maxOffset;
|
|
69
46
|
}
|
|
70
47
|
/**
|
|
71
48
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
72
|
-
*
|
|
73
|
-
* @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.
|
|
74
49
|
*/
|
|
75
50
|
clone() {
|
|
76
51
|
const nodes = new NodeList([...this.nodes].map(node => node._clone(true)));
|
|
@@ -80,8 +55,6 @@ export default class InsertOperation extends Operation {
|
|
|
80
55
|
}
|
|
81
56
|
/**
|
|
82
57
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
83
|
-
*
|
|
84
|
-
* @returns {module:engine/model/operation/moveoperation~MoveOperation}
|
|
85
58
|
*/
|
|
86
59
|
getReversed() {
|
|
87
60
|
const graveyard = this.position.root.document.graveyard;
|
|
@@ -134,9 +107,8 @@ export default class InsertOperation extends Operation {
|
|
|
134
107
|
/**
|
|
135
108
|
* Creates `InsertOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
136
109
|
*
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @returns {module:engine/model/operation/insertoperation~InsertOperation}
|
|
110
|
+
* @param json Deserialized JSON object.
|
|
111
|
+
* @param document Document on which this operation will be applied.
|
|
140
112
|
*/
|
|
141
113
|
static fromJSON(json, document) {
|
|
142
114
|
const children = [];
|
|
@@ -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
|
/**
|
|
@@ -7,57 +7,23 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import Operation from './operation';
|
|
9
9
|
import Range from '../range';
|
|
10
|
-
/**
|
|
11
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
12
|
-
*/
|
|
13
10
|
export default class MarkerOperation extends Operation {
|
|
14
11
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
12
|
+
* @param name Marker name.
|
|
13
|
+
* @param oldRange Marker range before the change.
|
|
14
|
+
* @param newRange Marker range after the change.
|
|
15
|
+
* @param markers Marker collection on which change should be executed.
|
|
16
|
+
* @param affectsData Specifies whether the marker operation affects the data produced by the data pipeline
|
|
20
17
|
* (is persisted in the editor's data).
|
|
21
|
-
* @param
|
|
18
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
22
19
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
23
20
|
*/
|
|
24
21
|
constructor(name, oldRange, newRange, markers, affectsData, baseVersion) {
|
|
25
22
|
super(baseVersion);
|
|
26
|
-
/**
|
|
27
|
-
* Marker name.
|
|
28
|
-
*
|
|
29
|
-
* @readonly
|
|
30
|
-
* @member {String}
|
|
31
|
-
*/
|
|
32
23
|
this.name = name;
|
|
33
|
-
/**
|
|
34
|
-
* Marker range before the change.
|
|
35
|
-
*
|
|
36
|
-
* @readonly
|
|
37
|
-
* @member {module:engine/model/range~Range|null}
|
|
38
|
-
*/
|
|
39
24
|
this.oldRange = oldRange ? oldRange.clone() : null;
|
|
40
|
-
/**
|
|
41
|
-
* Marker range after the change.
|
|
42
|
-
*
|
|
43
|
-
* @readonly
|
|
44
|
-
* @member {module:engine/model/range~Range}
|
|
45
|
-
*/
|
|
46
25
|
this.newRange = newRange ? newRange.clone() : null;
|
|
47
|
-
/**
|
|
48
|
-
* Specifies whether the marker operation affects the data produced by the data pipeline
|
|
49
|
-
* (is persisted in the editor's data).
|
|
50
|
-
*
|
|
51
|
-
* @readonly
|
|
52
|
-
* @member {Boolean}
|
|
53
|
-
*/
|
|
54
26
|
this.affectsData = affectsData;
|
|
55
|
-
/**
|
|
56
|
-
* Marker collection on which change should be executed.
|
|
57
|
-
*
|
|
58
|
-
* @private
|
|
59
|
-
* @member {module:engine/model/markercollection~MarkerCollection}
|
|
60
|
-
*/
|
|
61
27
|
this._markers = markers;
|
|
62
28
|
}
|
|
63
29
|
/**
|
|
@@ -68,16 +34,12 @@ export default class MarkerOperation extends Operation {
|
|
|
68
34
|
}
|
|
69
35
|
/**
|
|
70
36
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
71
|
-
*
|
|
72
|
-
* @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.
|
|
73
37
|
*/
|
|
74
38
|
clone() {
|
|
75
39
|
return new MarkerOperation(this.name, this.oldRange, this.newRange, this._markers, this.affectsData, this.baseVersion);
|
|
76
40
|
}
|
|
77
41
|
/**
|
|
78
42
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
79
|
-
*
|
|
80
|
-
* @returns {module:engine/model/operation/markeroperation~MarkerOperation}
|
|
81
43
|
*/
|
|
82
44
|
getReversed() {
|
|
83
45
|
return new MarkerOperation(this.name, this.newRange, this.oldRange, this._markers, this.affectsData, this.baseVersion + 1);
|
|
@@ -118,9 +80,8 @@ export default class MarkerOperation extends Operation {
|
|
|
118
80
|
/**
|
|
119
81
|
* Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
120
82
|
*
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @returns {module:engine/model/operation/markeroperation~MarkerOperation}
|
|
83
|
+
* @param json Deserialized JSON object.
|
|
84
|
+
* @param document Document on which this operation will be applied.
|
|
124
85
|
*/
|
|
125
86
|
static fromJSON(json, document) {
|
|
126
87
|
return new MarkerOperation(json.name, json.oldRange ? Range.fromJSON(json.oldRange, document) : null, json.newRange ? Range.fromJSON(json.newRange, document) : null, document.model.markers, json.affectsData, 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
|
/**
|
|
@@ -10,7 +10,7 @@ import SplitOperation from './splitoperation';
|
|
|
10
10
|
import Position from '../position';
|
|
11
11
|
import Range from '../range';
|
|
12
12
|
import { _move } from './utils';
|
|
13
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils
|
|
13
|
+
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
14
14
|
/**
|
|
15
15
|
* Operation to merge two {@link module:engine/model/element~Element elements}.
|
|
16
16
|
*
|
|
@@ -18,51 +18,29 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
18
18
|
* {@link ~MergeOperation#targetPosition}. All nodes from the merged element are moved to {@link ~MergeOperation#targetPosition}.
|
|
19
19
|
*
|
|
20
20
|
* The merged element is moved to the graveyard at {@link ~MergeOperation#graveyardPosition}.
|
|
21
|
-
*
|
|
22
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
23
21
|
*/
|
|
24
22
|
export default class MergeOperation extends Operation {
|
|
25
23
|
/**
|
|
26
24
|
* Creates a merge operation.
|
|
27
25
|
*
|
|
28
|
-
* @param
|
|
26
|
+
* @param sourcePosition Position inside the merged element. All nodes from that
|
|
29
27
|
* element after that position will be moved to {@link ~#targetPosition}.
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
28
|
+
* @param howMany Summary offset size of nodes which will be moved from the merged element to the new parent.
|
|
29
|
+
* @param targetPosition Position which the nodes from the merged elements will be moved to.
|
|
30
|
+
* @param graveyardPosition Position in graveyard to which the merged element will be moved.
|
|
31
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
34
32
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
35
33
|
*/
|
|
36
34
|
constructor(sourcePosition, howMany, targetPosition, graveyardPosition, baseVersion) {
|
|
37
35
|
super(baseVersion);
|
|
38
|
-
/**
|
|
39
|
-
* Position inside the merged element. All nodes from that element after that position will be moved to {@link ~#targetPosition}.
|
|
40
|
-
*
|
|
41
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#sourcePosition
|
|
42
|
-
*/
|
|
43
36
|
this.sourcePosition = sourcePosition.clone();
|
|
44
37
|
// This is, and should always remain, the first position in its parent.
|
|
45
38
|
this.sourcePosition.stickiness = 'toPrevious';
|
|
46
|
-
/**
|
|
47
|
-
* Summary offset size of nodes which will be moved from the merged element to the new parent.
|
|
48
|
-
*
|
|
49
|
-
* @member {Number} module:engine/model/operation/mergeoperation~MergeOperation#howMany
|
|
50
|
-
*/
|
|
51
39
|
this.howMany = howMany;
|
|
52
|
-
/**
|
|
53
|
-
* Position which the nodes from the merged elements will be moved to.
|
|
54
|
-
*
|
|
55
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#targetPosition
|
|
56
|
-
*/
|
|
57
40
|
this.targetPosition = targetPosition.clone();
|
|
58
41
|
// Except of a rare scenario in `MergeOperation` x `MergeOperation` transformation,
|
|
59
42
|
// this is, and should always remain, the last position in its parent.
|
|
60
43
|
this.targetPosition.stickiness = 'toNext';
|
|
61
|
-
/**
|
|
62
|
-
* Position in graveyard to which the merged element will be moved.
|
|
63
|
-
*
|
|
64
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/mergeoperation~MergeOperation#graveyardPosition
|
|
65
|
-
*/
|
|
66
44
|
this.graveyardPosition = graveyardPosition.clone();
|
|
67
45
|
}
|
|
68
46
|
/**
|
|
@@ -73,9 +51,6 @@ export default class MergeOperation extends Operation {
|
|
|
73
51
|
}
|
|
74
52
|
/**
|
|
75
53
|
* Position before the merged element (which will be deleted).
|
|
76
|
-
*
|
|
77
|
-
* @readonly
|
|
78
|
-
* @type {module:engine/model/position~Position}
|
|
79
54
|
*/
|
|
80
55
|
get deletionPosition() {
|
|
81
56
|
return new Position(this.sourcePosition.root, this.sourcePosition.path.slice(0, -1));
|
|
@@ -83,9 +58,6 @@ export default class MergeOperation extends Operation {
|
|
|
83
58
|
/**
|
|
84
59
|
* Artificial range that contains all the nodes from the merged element that will be moved to {@link ~MergeOperation#sourcePosition}.
|
|
85
60
|
* The range starts at {@link ~MergeOperation#sourcePosition} and ends in the same parent, at `POSITIVE_INFINITY` offset.
|
|
86
|
-
*
|
|
87
|
-
* @readonly
|
|
88
|
-
* @type {module:engine/model/range~Range}
|
|
89
61
|
*/
|
|
90
62
|
get movedRange() {
|
|
91
63
|
const end = this.sourcePosition.getShiftedBy(Number.POSITIVE_INFINITY);
|
|
@@ -93,16 +65,12 @@ export default class MergeOperation extends Operation {
|
|
|
93
65
|
}
|
|
94
66
|
/**
|
|
95
67
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
96
|
-
*
|
|
97
|
-
* @returns {module:engine/model/operation/mergeoperation~MergeOperation} Clone of this operation.
|
|
98
68
|
*/
|
|
99
69
|
clone() {
|
|
100
70
|
return new MergeOperation(this.sourcePosition, this.howMany, this.targetPosition, this.graveyardPosition, this.baseVersion);
|
|
101
71
|
}
|
|
102
72
|
/**
|
|
103
73
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
104
|
-
*
|
|
105
|
-
* @returns {module:engine/model/operation/splitoperation~SplitOperation}
|
|
106
74
|
*/
|
|
107
75
|
getReversed() {
|
|
108
76
|
// Positions in this method are transformed by this merge operation because the split operation bases on
|
|
@@ -175,9 +143,8 @@ export default class MergeOperation extends Operation {
|
|
|
175
143
|
/**
|
|
176
144
|
* Creates `MergeOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
177
145
|
*
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
180
|
-
* @returns {module:engine/model/operation/mergeoperation~MergeOperation}
|
|
146
|
+
* @param json Deserialized JSON object.
|
|
147
|
+
* @param document Document on which this operation will be applied.
|
|
181
148
|
*/
|
|
182
149
|
static fromJSON(json, document) {
|
|
183
150
|
const sourcePosition = Position.fromJSON(json.sourcePosition, document);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -8,49 +8,30 @@
|
|
|
8
8
|
import Operation from './operation';
|
|
9
9
|
import Position from '../position';
|
|
10
10
|
import Range from '../range';
|
|
11
|
-
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
12
|
-
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
|
|
13
11
|
import { _move } from './utils';
|
|
12
|
+
import { CKEditorError, compareArrays } from '@ckeditor/ckeditor5-utils';
|
|
14
13
|
// @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;
|
|
15
14
|
/**
|
|
16
15
|
* Operation to move a range of {@link module:engine/model/item~Item model items}
|
|
17
16
|
* to given {@link module:engine/model/position~Position target position}.
|
|
18
|
-
*
|
|
19
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
20
17
|
*/
|
|
21
18
|
export default class MoveOperation extends Operation {
|
|
22
19
|
/**
|
|
23
20
|
* Creates a move operation.
|
|
24
21
|
*
|
|
25
|
-
* @param {module:engine/model/
|
|
26
|
-
*
|
|
27
|
-
* @param {Number} howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
|
|
22
|
+
* @param sourcePosition Position before the first {@link module:engine/model/item~Item model item} to move.
|
|
23
|
+
* @param howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
|
|
28
24
|
* `sourcePosition` with offset shifted by `howMany`.
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
25
|
+
* @param targetPosition Position at which moved nodes will be inserted.
|
|
26
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
31
27
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
32
28
|
*/
|
|
33
29
|
constructor(sourcePosition, howMany, targetPosition, baseVersion) {
|
|
34
30
|
super(baseVersion);
|
|
35
|
-
/**
|
|
36
|
-
* Position before the first {@link module:engine/model/item~Item model item} to move.
|
|
37
|
-
*
|
|
38
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/moveoperation~MoveOperation#sourcePosition
|
|
39
|
-
*/
|
|
40
31
|
this.sourcePosition = sourcePosition.clone();
|
|
41
32
|
// `'toNext'` because `sourcePosition` is a bit like a start of the moved range.
|
|
42
33
|
this.sourcePosition.stickiness = 'toNext';
|
|
43
|
-
/**
|
|
44
|
-
* Offset size of moved range.
|
|
45
|
-
*
|
|
46
|
-
* @member {Number} module:engine/model/operation/moveoperation~MoveOperation#howMany
|
|
47
|
-
*/
|
|
48
34
|
this.howMany = howMany;
|
|
49
|
-
/**
|
|
50
|
-
* Position at which moved nodes will be inserted.
|
|
51
|
-
*
|
|
52
|
-
* @member {module:engine/model/position~Position} module:engine/model/operation/moveoperation~MoveOperation#targetPosition
|
|
53
|
-
*/
|
|
54
35
|
this.targetPosition = targetPosition.clone();
|
|
55
36
|
this.targetPosition.stickiness = 'toNone';
|
|
56
37
|
}
|
|
@@ -68,8 +49,6 @@ export default class MoveOperation extends Operation {
|
|
|
68
49
|
}
|
|
69
50
|
/**
|
|
70
51
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
71
|
-
*
|
|
72
|
-
* @returns {module:engine/model/operation/moveoperation~MoveOperation} Clone of this operation.
|
|
73
52
|
*/
|
|
74
53
|
clone() {
|
|
75
54
|
return new MoveOperation(this.sourcePosition, this.howMany, this.targetPosition, this.baseVersion);
|
|
@@ -80,21 +59,19 @@ export default class MoveOperation extends Operation {
|
|
|
80
59
|
* inside the same parent but {@link module:engine/model/operation/moveoperation~MoveOperation#targetPosition targetPosition}
|
|
81
60
|
* is after {@link module:engine/model/operation/moveoperation~MoveOperation#sourcePosition sourcePosition}.
|
|
82
61
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
|
|
62
|
+
* ```
|
|
63
|
+
* vv vv
|
|
64
|
+
* abcdefg ===> adefbcg
|
|
65
|
+
* ^ ^
|
|
66
|
+
* targetPos movedRangeStart
|
|
67
|
+
* offset 6 offset 4
|
|
68
|
+
*```
|
|
90
69
|
*/
|
|
91
70
|
getMovedRangeStart() {
|
|
92
71
|
return this.targetPosition._getTransformedByDeletion(this.sourcePosition, this.howMany);
|
|
93
72
|
}
|
|
94
73
|
/**
|
|
95
74
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
96
|
-
*
|
|
97
|
-
* @returns {module:engine/model/operation/moveoperation~MoveOperation}
|
|
98
75
|
*/
|
|
99
76
|
getReversed() {
|
|
100
77
|
const newTargetPosition = this.sourcePosition._getTransformedByInsertion(this.targetPosition, this.howMany);
|
|
@@ -167,9 +144,8 @@ export default class MoveOperation extends Operation {
|
|
|
167
144
|
/**
|
|
168
145
|
* Creates `MoveOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
169
146
|
*
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
172
|
-
* @returns {module:engine/model/operation/moveoperation~MoveOperation}
|
|
147
|
+
* @param json Deserialized JSON object.
|
|
148
|
+
* @param document Document on which this operation will be applied.
|
|
173
149
|
*/
|
|
174
150
|
static fromJSON(json, document) {
|
|
175
151
|
const sourcePosition = Position.fromJSON(json.sourcePosition, document);
|
|
@@ -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,8 +13,6 @@ import Operation from './operation';
|
|
|
13
13
|
* In most cases this operation is a result of transforming operations. When transformation returns
|
|
14
14
|
* {@link module:engine/model/operation/nooperation~NoOperation} it means that changes done by the transformed operation
|
|
15
15
|
* have already been applied.
|
|
16
|
-
*
|
|
17
|
-
* @extends module:engine/model/operation/operation~Operation
|
|
18
16
|
*/
|
|
19
17
|
export default class NoOperation extends Operation {
|
|
20
18
|
get type() {
|
|
@@ -22,16 +20,12 @@ export default class NoOperation extends Operation {
|
|
|
22
20
|
}
|
|
23
21
|
/**
|
|
24
22
|
* Creates and returns an operation that has the same parameters as this operation.
|
|
25
|
-
*
|
|
26
|
-
* @returns {module:engine/model/operation/nooperation~NoOperation} Clone of this operation.
|
|
27
23
|
*/
|
|
28
24
|
clone() {
|
|
29
25
|
return new NoOperation(this.baseVersion);
|
|
30
26
|
}
|
|
31
27
|
/**
|
|
32
28
|
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
33
|
-
*
|
|
34
|
-
* @returns {module:engine/model/operation/nooperation~NoOperation}
|
|
35
29
|
*/
|
|
36
30
|
getReversed() {
|
|
37
31
|
return new NoOperation(this.baseVersion + 1);
|
|
@@ -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
|
/**
|
|
@@ -7,86 +7,31 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Abstract base operation class.
|
|
10
|
-
*
|
|
11
|
-
* @abstract
|
|
12
10
|
*/
|
|
13
11
|
export default class Operation {
|
|
14
12
|
/**
|
|
15
13
|
* Base operation constructor.
|
|
16
14
|
*
|
|
17
|
-
* @param
|
|
15
|
+
* @param baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
18
16
|
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
19
17
|
*/
|
|
20
18
|
constructor(baseVersion) {
|
|
21
|
-
/**
|
|
22
|
-
* {@link module:engine/model/document~Document#version} on which operation can be applied. If you try to
|
|
23
|
-
* {@link module:engine/model/model~Model#applyOperation apply} operation with different base version than the
|
|
24
|
-
* {@link module:engine/model/document~Document#version document version} the
|
|
25
|
-
* {@link module:utils/ckeditorerror~CKEditorError model-document-applyOperation-wrong-version} error is thrown.
|
|
26
|
-
*
|
|
27
|
-
* @member {Number|null}
|
|
28
|
-
*/
|
|
29
19
|
this.baseVersion = baseVersion;
|
|
30
|
-
/**
|
|
31
|
-
* Defines whether operation is executed on attached or detached {@link module:engine/model/item~Item items}.
|
|
32
|
-
*
|
|
33
|
-
* @readonly
|
|
34
|
-
* @member {Boolean} #isDocumentOperation
|
|
35
|
-
*/
|
|
36
20
|
this.isDocumentOperation = this.baseVersion !== null;
|
|
37
|
-
/**
|
|
38
|
-
* {@link module:engine/model/batch~Batch Batch} to which the operation is added or `null` if the operation is not
|
|
39
|
-
* added to any batch yet.
|
|
40
|
-
*
|
|
41
|
-
* @member {module:engine/model/batch~Batch|null} #batch
|
|
42
|
-
*/
|
|
43
21
|
this.batch = null;
|
|
44
|
-
/**
|
|
45
|
-
* Operation type.
|
|
46
|
-
*
|
|
47
|
-
* @readonly
|
|
48
|
-
* @member {String} #type
|
|
49
|
-
*/
|
|
50
|
-
/**
|
|
51
|
-
* Creates and returns an operation that has the same parameters as this operation.
|
|
52
|
-
*
|
|
53
|
-
* @method #clone
|
|
54
|
-
* @returns {module:engine/model/operation/operation~Operation} Clone of this operation.
|
|
55
|
-
*/
|
|
56
|
-
/**
|
|
57
|
-
* Creates and returns a reverse operation. Reverse operation when executed right after
|
|
58
|
-
* the original operation will bring back tree model state to the point before the original
|
|
59
|
-
* operation execution. In other words, it reverses changes done by the original operation.
|
|
60
|
-
*
|
|
61
|
-
* Keep in mind that tree model state may change since executing the original operation,
|
|
62
|
-
* so reverse operation will be "outdated". In that case you will need to transform it by
|
|
63
|
-
* all operations that were executed after the original operation.
|
|
64
|
-
*
|
|
65
|
-
* @method #getReversed
|
|
66
|
-
* @returns {module:engine/model/operation/operation~Operation} Reversed operation.
|
|
67
|
-
*/
|
|
68
|
-
/**
|
|
69
|
-
* Executes the operation - modifications described by the operation properties will be applied to the model tree.
|
|
70
|
-
*
|
|
71
|
-
* @protected
|
|
72
|
-
* @method #_execute
|
|
73
|
-
*/
|
|
74
22
|
}
|
|
75
23
|
/**
|
|
76
24
|
* Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws
|
|
77
25
|
* an error if operation is not valid.
|
|
78
26
|
*
|
|
79
27
|
* @internal
|
|
80
|
-
* @protected
|
|
81
|
-
* @method #_validate
|
|
82
28
|
*/
|
|
83
29
|
_validate() {
|
|
84
30
|
}
|
|
85
31
|
/**
|
|
86
32
|
* Custom toJSON method to solve child-parent circular dependencies.
|
|
87
33
|
*
|
|
88
|
-
* @
|
|
89
|
-
* @returns {Object} Clone of this object with the operation property replaced with string.
|
|
34
|
+
* @returns Clone of this object with the operation property replaced with string.
|
|
90
35
|
*/
|
|
91
36
|
toJSON() {
|
|
92
37
|
// This method creates only a shallow copy, all nested objects should be defined separately.
|
|
@@ -101,8 +46,6 @@ export default class Operation {
|
|
|
101
46
|
}
|
|
102
47
|
/**
|
|
103
48
|
* Name of the operation class used for serialization.
|
|
104
|
-
*
|
|
105
|
-
* @type {String}
|
|
106
49
|
*/
|
|
107
50
|
static get className() {
|
|
108
51
|
return 'Operation';
|
|
@@ -110,9 +53,8 @@ export default class Operation {
|
|
|
110
53
|
/**
|
|
111
54
|
* Creates Operation object from deserilized object, i.e. from parsed JSON string.
|
|
112
55
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
115
|
-
* @returns {module:engine/model/operation/operation~Operation}
|
|
56
|
+
* @param json Deserialized JSON object.
|
|
57
|
+
* @param doc Document on which this operation will be applied.
|
|
116
58
|
*/
|
|
117
59
|
static fromJSON(json, document) {
|
|
118
60
|
return new this(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
|
/**
|
|
@@ -28,16 +28,13 @@ operations[SplitOperation.className] = SplitOperation;
|
|
|
28
28
|
operations[MergeOperation.className] = MergeOperation;
|
|
29
29
|
/**
|
|
30
30
|
* A factory class for creating operations.
|
|
31
|
-
*
|
|
32
|
-
* @abstract
|
|
33
31
|
*/
|
|
34
32
|
export default class OperationFactory {
|
|
35
33
|
/**
|
|
36
34
|
* Creates an operation instance from a JSON object (parsed JSON string).
|
|
37
35
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @returns {module:engine/model/operation/operation~Operation}
|
|
36
|
+
* @param json Deserialized JSON object.
|
|
37
|
+
* @param document Document on which this operation will be applied.
|
|
41
38
|
*/
|
|
42
39
|
static fromJSON(json, document) {
|
|
43
40
|
return operations[json.__className].fromJSON(json, document);
|