@ckeditor/ckeditor5-engine 35.0.1 → 35.2.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/CHANGELOG.md +4 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +176 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +980 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +757 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +199 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
|
@@ -2,138 +2,119 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/model/operation/operation
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Abstract base operation class.
|
|
12
10
|
*
|
|
13
11
|
* @abstract
|
|
14
12
|
*/
|
|
15
13
|
export default class Operation {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return 'Operation';
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Creates Operation object from deserilized object, i.e. from parsed JSON string.
|
|
127
|
-
*
|
|
128
|
-
* @param {Object} json Deserialized JSON object.
|
|
129
|
-
* @param {module:engine/model/document~Document} doc Document on which this operation will be applied.
|
|
130
|
-
* @returns {module:engine/model/operation/operation~Operation}
|
|
131
|
-
*/
|
|
132
|
-
static fromJSON( json ) {
|
|
133
|
-
return new this( json.baseVersion );
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// @if CK_DEBUG_ENGINE // log() {
|
|
137
|
-
// @if CK_DEBUG_ENGINE // console.log( this.toString() );
|
|
138
|
-
// @if CK_DEBUG_ENGINE // }
|
|
14
|
+
/**
|
|
15
|
+
* Base operation constructor.
|
|
16
|
+
*
|
|
17
|
+
* @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
18
|
+
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
19
|
+
*/
|
|
20
|
+
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
|
+
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
|
+
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
|
+
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
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws
|
|
77
|
+
* an error if operation is not valid.
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
* @protected
|
|
81
|
+
* @method #_validate
|
|
82
|
+
*/
|
|
83
|
+
_validate() {
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Custom toJSON method to solve child-parent circular dependencies.
|
|
87
|
+
*
|
|
88
|
+
* @method #toJSON
|
|
89
|
+
* @returns {Object} Clone of this object with the operation property replaced with string.
|
|
90
|
+
*/
|
|
91
|
+
toJSON() {
|
|
92
|
+
// This method creates only a shallow copy, all nested objects should be defined separately.
|
|
93
|
+
// See https://github.com/ckeditor/ckeditor5-engine/issues/1477.
|
|
94
|
+
const json = Object.assign({}, this);
|
|
95
|
+
json.__className = this.constructor.className;
|
|
96
|
+
// Remove reference to the parent `Batch` to avoid circular dependencies.
|
|
97
|
+
delete json.batch;
|
|
98
|
+
// Only document operations are shared with other clients so it is not necessary to keep this information.
|
|
99
|
+
delete json.isDocumentOperation;
|
|
100
|
+
return json;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Name of the operation class used for serialization.
|
|
104
|
+
*
|
|
105
|
+
* @type {String}
|
|
106
|
+
*/
|
|
107
|
+
static get className() {
|
|
108
|
+
return 'Operation';
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates Operation object from deserilized object, i.e. from parsed JSON string.
|
|
112
|
+
*
|
|
113
|
+
* @param {Object} json Deserialized JSON object.
|
|
114
|
+
* @param {module:engine/model/document~Document} doc Document on which this operation will be applied.
|
|
115
|
+
* @returns {module:engine/model/operation/operation~Operation}
|
|
116
|
+
*/
|
|
117
|
+
static fromJSON(json, document) {
|
|
118
|
+
return new this(json.baseVersion);
|
|
119
|
+
}
|
|
139
120
|
}
|
|
@@ -2,48 +2,44 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/model/operation/operationfactory
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import MergeOperation from '../operation/mergeoperation';
|
|
20
|
-
|
|
8
|
+
import AttributeOperation from './attributeoperation';
|
|
9
|
+
import InsertOperation from './insertoperation';
|
|
10
|
+
import MarkerOperation from './markeroperation';
|
|
11
|
+
import MoveOperation from './moveoperation';
|
|
12
|
+
import NoOperation from './nooperation';
|
|
13
|
+
import Operation from './operation';
|
|
14
|
+
import RenameOperation from './renameoperation';
|
|
15
|
+
import RootAttributeOperation from './rootattributeoperation';
|
|
16
|
+
import SplitOperation from './splitoperation';
|
|
17
|
+
import MergeOperation from './mergeoperation';
|
|
21
18
|
const operations = {};
|
|
22
|
-
operations[
|
|
23
|
-
operations[
|
|
24
|
-
operations[
|
|
25
|
-
operations[
|
|
26
|
-
operations[
|
|
27
|
-
operations[
|
|
28
|
-
operations[
|
|
29
|
-
operations[
|
|
30
|
-
operations[
|
|
31
|
-
operations[
|
|
32
|
-
|
|
19
|
+
operations[AttributeOperation.className] = AttributeOperation;
|
|
20
|
+
operations[InsertOperation.className] = InsertOperation;
|
|
21
|
+
operations[MarkerOperation.className] = MarkerOperation;
|
|
22
|
+
operations[MoveOperation.className] = MoveOperation;
|
|
23
|
+
operations[NoOperation.className] = NoOperation;
|
|
24
|
+
operations[Operation.className] = Operation;
|
|
25
|
+
operations[RenameOperation.className] = RenameOperation;
|
|
26
|
+
operations[RootAttributeOperation.className] = RootAttributeOperation;
|
|
27
|
+
operations[SplitOperation.className] = SplitOperation;
|
|
28
|
+
operations[MergeOperation.className] = MergeOperation;
|
|
33
29
|
/**
|
|
34
30
|
* A factory class for creating operations.
|
|
35
31
|
*
|
|
36
32
|
* @abstract
|
|
37
33
|
*/
|
|
38
34
|
export default class OperationFactory {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Creates an operation instance from a JSON object (parsed JSON string).
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} json Deserialized JSON object.
|
|
39
|
+
* @param {module:engine/model/document~Document} document Document on which this operation will be applied.
|
|
40
|
+
* @returns {module:engine/model/operation/operation~Operation}
|
|
41
|
+
*/
|
|
42
|
+
static fromJSON(json, document) {
|
|
43
|
+
return operations[json.__className].fromJSON(json, document);
|
|
44
|
+
}
|
|
49
45
|
}
|
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, 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
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/model/operation/renameoperation
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Operation from './operation';
|
|
11
9
|
import Element from '../element';
|
|
12
10
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
13
11
|
import Position from '../position';
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* Operation to change element's name.
|
|
17
14
|
*
|
|
@@ -20,136 +17,113 @@ import Position from '../position';
|
|
|
20
17
|
* @extends module:engine/model/operation/operation~Operation
|
|
21
18
|
*/
|
|
22
19
|
export default class RenameOperation extends Operation {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @inheritDoc
|
|
135
|
-
*/
|
|
136
|
-
static get className() {
|
|
137
|
-
return 'RenameOperation';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Creates `RenameOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
142
|
-
*
|
|
143
|
-
* @param {Object} json Deserialized JSON object.
|
|
144
|
-
* @param {module:engine/model/document~Document} document Document on which this operation will be applied.
|
|
145
|
-
* @returns {module:engine/model/operation/attributeoperation~AttributeOperation}
|
|
146
|
-
*/
|
|
147
|
-
static fromJSON( json, document ) {
|
|
148
|
-
return new RenameOperation( Position.fromJSON( json.position, document ), json.oldName, json.newName, json.baseVersion );
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// @if CK_DEBUG_ENGINE // toString() {
|
|
152
|
-
// @if CK_DEBUG_ENGINE // return `RenameOperation( ${ this.baseVersion } ): ` +
|
|
153
|
-
// @if CK_DEBUG_ENGINE // `${ this.position }: "${ this.oldName }" -> "${ this.newName }"`;
|
|
154
|
-
// @if CK_DEBUG_ENGINE // }
|
|
20
|
+
/**
|
|
21
|
+
* Creates an operation that changes element's name.
|
|
22
|
+
*
|
|
23
|
+
* @param {module:engine/model/position~Position} position Position before an element to change.
|
|
24
|
+
* @param {String} oldName Current name of the element.
|
|
25
|
+
* @param {String} newName New name for the element.
|
|
26
|
+
* @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
27
|
+
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
28
|
+
*/
|
|
29
|
+
constructor(position, oldName, newName, baseVersion) {
|
|
30
|
+
super(baseVersion);
|
|
31
|
+
/**
|
|
32
|
+
* Position before an element to change.
|
|
33
|
+
*
|
|
34
|
+
* @member {module:engine/model/position~Position} module:engine/model/operation/renameoperation~RenameOperation#position
|
|
35
|
+
*/
|
|
36
|
+
this.position = position;
|
|
37
|
+
// This position sticks to the next node because it is a position before the node that we want to change.
|
|
38
|
+
this.position.stickiness = 'toNext';
|
|
39
|
+
/**
|
|
40
|
+
* Current name of the element.
|
|
41
|
+
*
|
|
42
|
+
* @member {String} module:engine/model/operation/renameoperation~RenameOperation#oldName
|
|
43
|
+
*/
|
|
44
|
+
this.oldName = oldName;
|
|
45
|
+
/**
|
|
46
|
+
* New name for the element.
|
|
47
|
+
*
|
|
48
|
+
* @member {String} module:engine/model/operation/renameoperation~RenameOperation#newName
|
|
49
|
+
*/
|
|
50
|
+
this.newName = newName;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
get type() {
|
|
56
|
+
return 'rename';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates and returns an operation that has the same parameters as this operation.
|
|
60
|
+
*
|
|
61
|
+
* @returns {module:engine/model/operation/renameoperation~RenameOperation} Clone of this operation.
|
|
62
|
+
*/
|
|
63
|
+
clone() {
|
|
64
|
+
return new RenameOperation(this.position.clone(), this.oldName, this.newName, this.baseVersion);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
68
|
+
*
|
|
69
|
+
* @returns {module:engine/model/operation/renameoperation~RenameOperation}
|
|
70
|
+
*/
|
|
71
|
+
getReversed() {
|
|
72
|
+
return new RenameOperation(this.position.clone(), this.newName, this.oldName, this.baseVersion + 1);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @inheritDoc
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
_validate() {
|
|
79
|
+
const element = this.position.nodeAfter;
|
|
80
|
+
if (!(element instanceof Element)) {
|
|
81
|
+
/**
|
|
82
|
+
* Given position is invalid or node after it is not instance of Element.
|
|
83
|
+
*
|
|
84
|
+
* @error rename-operation-wrong-position
|
|
85
|
+
*/
|
|
86
|
+
throw new CKEditorError('rename-operation-wrong-position', this);
|
|
87
|
+
}
|
|
88
|
+
else if (element.name !== this.oldName) {
|
|
89
|
+
/**
|
|
90
|
+
* Element to change has different name than operation's old name.
|
|
91
|
+
*
|
|
92
|
+
* @error rename-operation-wrong-name
|
|
93
|
+
*/
|
|
94
|
+
throw new CKEditorError('rename-operation-wrong-name', this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @inheritDoc
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
_execute() {
|
|
102
|
+
const element = this.position.nodeAfter;
|
|
103
|
+
element.name = this.newName;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @inheritDoc
|
|
107
|
+
*/
|
|
108
|
+
toJSON() {
|
|
109
|
+
const json = super.toJSON();
|
|
110
|
+
json.position = this.position.toJSON();
|
|
111
|
+
return json;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @inheritDoc
|
|
115
|
+
*/
|
|
116
|
+
static get className() {
|
|
117
|
+
return 'RenameOperation';
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates `RenameOperation` object from deserialized object, i.e. from parsed JSON string.
|
|
121
|
+
*
|
|
122
|
+
* @param {Object} json Deserialized JSON object.
|
|
123
|
+
* @param {module:engine/model/document~Document} document Document on which this operation will be applied.
|
|
124
|
+
* @returns {module:engine/model/operation/attributeoperation~AttributeOperation}
|
|
125
|
+
*/
|
|
126
|
+
static fromJSON(json, document) {
|
|
127
|
+
return new RenameOperation(Position.fromJSON(json.position, document), json.oldName, json.newName, json.baseVersion);
|
|
128
|
+
}
|
|
155
129
|
}
|