@ckeditor/ckeditor5-engine 34.2.0 → 35.1.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +823 -0
  2. package/LICENSE.md +4 -0
  3. package/package.json +32 -25
  4. package/src/controller/datacontroller.js +467 -561
  5. package/src/controller/editingcontroller.js +168 -204
  6. package/src/conversion/conversion.js +541 -565
  7. package/src/conversion/conversionhelpers.js +24 -28
  8. package/src/conversion/downcastdispatcher.js +457 -686
  9. package/src/conversion/downcasthelpers.js +1583 -1965
  10. package/src/conversion/mapper.js +518 -707
  11. package/src/conversion/modelconsumable.js +240 -283
  12. package/src/conversion/upcastdispatcher.js +372 -718
  13. package/src/conversion/upcasthelpers.js +707 -818
  14. package/src/conversion/viewconsumable.js +524 -581
  15. package/src/dataprocessor/basichtmlwriter.js +12 -16
  16. package/src/dataprocessor/dataprocessor.js +5 -0
  17. package/src/dataprocessor/htmldataprocessor.js +101 -117
  18. package/src/dataprocessor/htmlwriter.js +1 -18
  19. package/src/dataprocessor/xmldataprocessor.js +117 -138
  20. package/src/dev-utils/model.js +260 -352
  21. package/src/dev-utils/operationreplayer.js +106 -126
  22. package/src/dev-utils/utils.js +34 -51
  23. package/src/dev-utils/view.js +632 -753
  24. package/src/index.js +0 -11
  25. package/src/model/batch.js +111 -127
  26. package/src/model/differ.js +988 -1233
  27. package/src/model/document.js +340 -449
  28. package/src/model/documentfragment.js +327 -364
  29. package/src/model/documentselection.js +996 -1189
  30. package/src/model/element.js +306 -410
  31. package/src/model/history.js +224 -262
  32. package/src/model/item.js +5 -0
  33. package/src/model/liveposition.js +84 -145
  34. package/src/model/liverange.js +108 -185
  35. package/src/model/markercollection.js +379 -480
  36. package/src/model/model.js +883 -1034
  37. package/src/model/node.js +419 -463
  38. package/src/model/nodelist.js +175 -201
  39. package/src/model/operation/attributeoperation.js +153 -182
  40. package/src/model/operation/detachoperation.js +64 -83
  41. package/src/model/operation/insertoperation.js +135 -166
  42. package/src/model/operation/markeroperation.js +114 -140
  43. package/src/model/operation/mergeoperation.js +163 -191
  44. package/src/model/operation/moveoperation.js +157 -187
  45. package/src/model/operation/nooperation.js +28 -38
  46. package/src/model/operation/operation.js +106 -125
  47. package/src/model/operation/operationfactory.js +30 -34
  48. package/src/model/operation/renameoperation.js +109 -135
  49. package/src/model/operation/rootattributeoperation.js +155 -188
  50. package/src/model/operation/splitoperation.js +196 -232
  51. package/src/model/operation/transform.js +1833 -2204
  52. package/src/model/operation/utils.js +140 -204
  53. package/src/model/position.js +899 -1053
  54. package/src/model/range.js +910 -1028
  55. package/src/model/rootelement.js +77 -97
  56. package/src/model/schema.js +1189 -1835
  57. package/src/model/selection.js +745 -862
  58. package/src/model/text.js +90 -114
  59. package/src/model/textproxy.js +204 -240
  60. package/src/model/treewalker.js +316 -397
  61. package/src/model/typecheckable.js +16 -0
  62. package/src/model/utils/autoparagraphing.js +32 -44
  63. package/src/model/utils/deletecontent.js +334 -418
  64. package/src/model/utils/findoptimalinsertionrange.js +25 -36
  65. package/src/model/utils/getselectedcontent.js +96 -118
  66. package/src/model/utils/insertcontent.js +654 -773
  67. package/src/model/utils/insertobject.js +96 -119
  68. package/src/model/utils/modifyselection.js +120 -158
  69. package/src/model/utils/selection-post-fixer.js +153 -201
  70. package/src/model/writer.js +1305 -1474
  71. package/src/view/attributeelement.js +189 -225
  72. package/src/view/containerelement.js +75 -85
  73. package/src/view/document.js +172 -215
  74. package/src/view/documentfragment.js +200 -249
  75. package/src/view/documentselection.js +338 -367
  76. package/src/view/domconverter.js +1371 -1613
  77. package/src/view/downcastwriter.js +1747 -2076
  78. package/src/view/editableelement.js +81 -97
  79. package/src/view/element.js +739 -890
  80. package/src/view/elementdefinition.js +5 -0
  81. package/src/view/emptyelement.js +82 -92
  82. package/src/view/filler.js +35 -50
  83. package/src/view/item.js +5 -0
  84. package/src/view/matcher.js +260 -559
  85. package/src/view/node.js +274 -360
  86. package/src/view/observer/arrowkeysobserver.js +19 -28
  87. package/src/view/observer/bubblingemittermixin.js +120 -263
  88. package/src/view/observer/bubblingeventinfo.js +47 -55
  89. package/src/view/observer/clickobserver.js +7 -13
  90. package/src/view/observer/compositionobserver.js +14 -24
  91. package/src/view/observer/domeventdata.js +57 -67
  92. package/src/view/observer/domeventobserver.js +40 -64
  93. package/src/view/observer/fakeselectionobserver.js +81 -96
  94. package/src/view/observer/focusobserver.js +45 -61
  95. package/src/view/observer/inputobserver.js +7 -13
  96. package/src/view/observer/keyobserver.js +17 -27
  97. package/src/view/observer/mouseobserver.js +7 -14
  98. package/src/view/observer/mutationobserver.js +220 -315
  99. package/src/view/observer/observer.js +81 -102
  100. package/src/view/observer/selectionobserver.js +191 -246
  101. package/src/view/observer/tabobserver.js +23 -36
  102. package/src/view/placeholder.js +128 -173
  103. package/src/view/position.js +350 -401
  104. package/src/view/range.js +453 -513
  105. package/src/view/rawelement.js +85 -112
  106. package/src/view/renderer.js +874 -1014
  107. package/src/view/rooteditableelement.js +80 -90
  108. package/src/view/selection.js +608 -689
  109. package/src/view/styles/background.js +43 -44
  110. package/src/view/styles/border.js +220 -276
  111. package/src/view/styles/margin.js +8 -17
  112. package/src/view/styles/padding.js +8 -16
  113. package/src/view/styles/utils.js +127 -160
  114. package/src/view/stylesmap.js +728 -905
  115. package/src/view/text.js +102 -126
  116. package/src/view/textproxy.js +144 -170
  117. package/src/view/treewalker.js +383 -479
  118. package/src/view/typecheckable.js +19 -0
  119. package/src/view/uielement.js +166 -187
  120. package/src/view/upcastwriter.js +395 -449
  121. package/src/view/view.js +569 -664
  122. package/src/dataprocessor/dataprocessor.jsdoc +0 -64
  123. package/src/model/item.jsdoc +0 -14
  124. package/src/view/elementdefinition.jsdoc +0 -59
  125. package/src/view/item.jsdoc +0 -14
@@ -2,11 +2,9 @@
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/insertoperation
8
7
  */
9
-
10
8
  import Operation from './operation';
11
9
  import Position from '../position';
12
10
  import NodeList from '../nodelist';
@@ -15,174 +13,145 @@ import { _insert, _normalizeNodes } from './utils';
15
13
  import Text from '../text';
16
14
  import Element from '../element';
17
15
  import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
18
-
19
16
  /**
20
17
  * Operation to insert one or more nodes at given position in the model.
21
18
  *
22
19
  * @extends module:engine/model/operation/operation~Operation
23
20
  */
24
21
  export default class InsertOperation extends Operation {
25
- /**
26
- * Creates an insert operation.
27
- *
28
- * @param {module:engine/model/position~Position} position Position of insertion.
29
- * @param {module:engine/model/node~NodeSet} nodes The list of nodes to be inserted.
30
- * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
31
- * can be applied or `null` if the operation operates on detached (non-document) tree.
32
- */
33
- constructor( position, nodes, baseVersion ) {
34
- super( baseVersion );
35
-
36
- /**
37
- * Position of insertion.
38
- *
39
- * @readonly
40
- * @member {module:engine/model/position~Position} module:engine/model/operation/insertoperation~InsertOperation#position
41
- */
42
- this.position = position.clone();
43
- this.position.stickiness = 'toNone';
44
-
45
- /**
46
- * List of nodes to insert.
47
- *
48
- * @readonly
49
- * @member {module:engine/model/nodelist~NodeList} module:engine/model/operation/insertoperation~InsertOperation#nodeList
50
- */
51
- this.nodes = new NodeList( _normalizeNodes( nodes ) );
52
-
53
- /**
54
- * Flag deciding how the operation should be transformed. If set to `true`, nodes might get additional attributes
55
- * during operational transformation. This happens when the operation insertion position is inside of a range
56
- * where attributes have changed.
57
- *
58
- * @member {Boolean} module:engine/model/operation/insertoperation~InsertOperation#shouldReceiveAttributes
59
- */
60
- this.shouldReceiveAttributes = false;
61
- }
62
-
63
- /**
64
- * @inheritDoc
65
- */
66
- get type() {
67
- return 'insert';
68
- }
69
-
70
- /**
71
- * Total offset size of inserted nodes.
72
- *
73
- * @returns {Number}
74
- */
75
- get howMany() {
76
- return this.nodes.maxOffset;
77
- }
78
-
79
- /**
80
- * Creates and returns an operation that has the same parameters as this operation.
81
- *
82
- * @returns {module:engine/model/operation/insertoperation~InsertOperation} Clone of this operation.
83
- */
84
- clone() {
85
- const nodes = new NodeList( [ ...this.nodes ].map( node => node._clone( true ) ) );
86
- const insert = new InsertOperation( this.position, nodes, this.baseVersion );
87
-
88
- insert.shouldReceiveAttributes = this.shouldReceiveAttributes;
89
-
90
- return insert;
91
- }
92
-
93
- /**
94
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
95
- *
96
- * @returns {module:engine/model/operation/moveoperation~MoveOperation}
97
- */
98
- getReversed() {
99
- const graveyard = this.position.root.document.graveyard;
100
- const gyPosition = new Position( graveyard, [ 0 ] );
101
-
102
- return new MoveOperation( this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1 );
103
- }
104
-
105
- /**
106
- * @inheritDoc
107
- */
108
- _validate() {
109
- const targetElement = this.position.parent;
110
-
111
- if ( !targetElement || targetElement.maxOffset < this.position.offset ) {
112
- /**
113
- * Insertion position is invalid.
114
- *
115
- * @error insert-operation-position-invalid
116
- */
117
- throw new CKEditorError(
118
- 'insert-operation-position-invalid',
119
- this
120
- );
121
- }
122
- }
123
-
124
- /**
125
- * @inheritDoc
126
- */
127
- _execute() {
128
- // What happens here is that we want original nodes be passed to writer because we want original nodes
129
- // to be inserted to the model. But in InsertOperation, we want to keep those nodes as they were added
130
- // to the operation, not modified. For example, text nodes can get merged or cropped while Elements can
131
- // get children. It is important that InsertOperation has the copy of original nodes in intact state.
132
- const originalNodes = this.nodes;
133
- this.nodes = new NodeList( [ ...originalNodes ].map( node => node._clone( true ) ) );
134
-
135
- _insert( this.position, originalNodes );
136
- }
137
-
138
- /**
139
- * @inheritDoc
140
- */
141
- toJSON() {
142
- const json = super.toJSON();
143
-
144
- json.position = this.position.toJSON();
145
- json.nodes = this.nodes.toJSON();
146
-
147
- return json;
148
- }
149
-
150
- /**
151
- * @inheritDoc
152
- */
153
- static get className() {
154
- return 'InsertOperation';
155
- }
156
-
157
- /**
158
- * Creates `InsertOperation` object from deserilized object, i.e. from parsed JSON string.
159
- *
160
- * @param {Object} json Deserialized JSON object.
161
- * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
162
- * @returns {module:engine/model/operation/insertoperation~InsertOperation}
163
- */
164
- static fromJSON( json, document ) {
165
- const children = [];
166
-
167
- for ( const child of json.nodes ) {
168
- if ( child.name ) {
169
- // If child has name property, it is an Element.
170
- children.push( Element.fromJSON( child ) );
171
- } else {
172
- // Otherwise, it is a Text node.
173
- children.push( Text.fromJSON( child ) );
174
- }
175
- }
176
-
177
- const insert = new InsertOperation( Position.fromJSON( json.position, document ), children, json.baseVersion );
178
- insert.shouldReceiveAttributes = json.shouldReceiveAttributes;
179
-
180
- return insert;
181
- }
182
-
183
- // @if CK_DEBUG_ENGINE // toString() {
184
- // @if CK_DEBUG_ENGINE // const nodeString = this.nodes.length > 1 ? `[ ${ this.nodes.length } ]` : this.nodes.getNode( 0 );
185
-
186
- // @if CK_DEBUG_ENGINE // return `InsertOperation( ${ this.baseVersion } ): ${ nodeString } -> ${ this.position }`;
187
- // @if CK_DEBUG_ENGINE // }
22
+ /**
23
+ * Creates an insert operation.
24
+ *
25
+ * @param {module:engine/model/position~Position} position Position of insertion.
26
+ * @param {module:engine/model/node~NodeSet} nodes The list of nodes to be inserted.
27
+ * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
28
+ * can be applied or `null` if the operation operates on detached (non-document) tree.
29
+ */
30
+ constructor(position, nodes, baseVersion) {
31
+ 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
+ this.position = position.clone();
39
+ 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
+ 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
+ this.shouldReceiveAttributes = false;
55
+ }
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ get type() {
60
+ return 'insert';
61
+ }
62
+ /**
63
+ * Total offset size of inserted nodes.
64
+ *
65
+ * @returns {Number}
66
+ */
67
+ get howMany() {
68
+ return this.nodes.maxOffset;
69
+ }
70
+ /**
71
+ * 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
+ */
75
+ clone() {
76
+ const nodes = new NodeList([...this.nodes].map(node => node._clone(true)));
77
+ const insert = new InsertOperation(this.position, nodes, this.baseVersion);
78
+ insert.shouldReceiveAttributes = this.shouldReceiveAttributes;
79
+ return insert;
80
+ }
81
+ /**
82
+ * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
83
+ *
84
+ * @returns {module:engine/model/operation/moveoperation~MoveOperation}
85
+ */
86
+ getReversed() {
87
+ const graveyard = this.position.root.document.graveyard;
88
+ const gyPosition = new Position(graveyard, [0]);
89
+ return new MoveOperation(this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1);
90
+ }
91
+ /**
92
+ * @inheritDoc
93
+ * @internal
94
+ */
95
+ _validate() {
96
+ const targetElement = this.position.parent;
97
+ if (!targetElement || targetElement.maxOffset < this.position.offset) {
98
+ /**
99
+ * Insertion position is invalid.
100
+ *
101
+ * @error insert-operation-position-invalid
102
+ */
103
+ throw new CKEditorError('insert-operation-position-invalid', this);
104
+ }
105
+ }
106
+ /**
107
+ * @inheritDoc
108
+ * @internal
109
+ */
110
+ _execute() {
111
+ // What happens here is that we want original nodes be passed to writer because we want original nodes
112
+ // to be inserted to the model. But in InsertOperation, we want to keep those nodes as they were added
113
+ // to the operation, not modified. For example, text nodes can get merged or cropped while Elements can
114
+ // get children. It is important that InsertOperation has the copy of original nodes in intact state.
115
+ const originalNodes = this.nodes;
116
+ this.nodes = new NodeList([...originalNodes].map(node => node._clone(true)));
117
+ _insert(this.position, originalNodes);
118
+ }
119
+ /**
120
+ * @inheritDoc
121
+ */
122
+ toJSON() {
123
+ const json = super.toJSON();
124
+ json.position = this.position.toJSON();
125
+ json.nodes = this.nodes.toJSON();
126
+ return json;
127
+ }
128
+ /**
129
+ * @inheritDoc
130
+ */
131
+ static get className() {
132
+ return 'InsertOperation';
133
+ }
134
+ /**
135
+ * Creates `InsertOperation` object from deserilized object, i.e. from parsed JSON string.
136
+ *
137
+ * @param {Object} json Deserialized JSON object.
138
+ * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
139
+ * @returns {module:engine/model/operation/insertoperation~InsertOperation}
140
+ */
141
+ static fromJSON(json, document) {
142
+ const children = [];
143
+ for (const child of json.nodes) {
144
+ if (child.name) {
145
+ // If child has name property, it is an Element.
146
+ children.push(Element.fromJSON(child));
147
+ }
148
+ else {
149
+ // Otherwise, it is a Text node.
150
+ children.push(Text.fromJSON(child));
151
+ }
152
+ }
153
+ const insert = new InsertOperation(Position.fromJSON(json.position, document), children, json.baseVersion);
154
+ insert.shouldReceiveAttributes = json.shouldReceiveAttributes;
155
+ return insert;
156
+ }
188
157
  }
@@ -2,153 +2,127 @@
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/markeroperation
8
7
  */
9
-
10
8
  import Operation from './operation';
11
9
  import Range from '../range';
12
-
13
10
  /**
14
11
  * @extends module:engine/model/operation/operation~Operation
15
12
  */
16
13
  export default class MarkerOperation extends Operation {
17
- /**
18
- * @param {String} name Marker name.
19
- * @param {module:engine/model/range~Range} oldRange Marker range before the change.
20
- * @param {module:engine/model/range~Range} newRange Marker range after the change.
21
- * @param {module:engine/model/markercollection~MarkerCollection} markers Marker collection on which change should be executed.
22
- * @param {Boolean} affectsData Specifies whether the marker operation affects the data produced by the data pipeline
23
- * (is persisted in the editor's data).
24
- * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
25
- * can be applied or `null` if the operation operates on detached (non-document) tree.
26
- */
27
- constructor( name, oldRange, newRange, markers, affectsData, baseVersion ) {
28
- super( baseVersion );
29
-
30
- /**
31
- * Marker name.
32
- *
33
- * @readonly
34
- * @member {String}
35
- */
36
- this.name = name;
37
-
38
- /**
39
- * Marker range before the change.
40
- *
41
- * @readonly
42
- * @member {module:engine/model/range~Range}
43
- */
44
- this.oldRange = oldRange ? oldRange.clone() : null;
45
-
46
- /**
47
- * Marker range after the change.
48
- *
49
- * @readonly
50
- * @member {module:engine/model/range~Range}
51
- */
52
- this.newRange = newRange ? newRange.clone() : null;
53
-
54
- /**
55
- * Specifies whether the marker operation affects the data produced by the data pipeline
56
- * (is persisted in the editor's data).
57
- *
58
- * @readonly
59
- * @member {Boolean}
60
- */
61
- this.affectsData = affectsData;
62
-
63
- /**
64
- * Marker collection on which change should be executed.
65
- *
66
- * @private
67
- * @member {module:engine/model/markercollection~MarkerCollection}
68
- */
69
- this._markers = markers;
70
- }
71
-
72
- /**
73
- * @inheritDoc
74
- */
75
- get type() {
76
- return 'marker';
77
- }
78
-
79
- /**
80
- * Creates and returns an operation that has the same parameters as this operation.
81
- *
82
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation} Clone of this operation.
83
- */
84
- clone() {
85
- return new MarkerOperation( this.name, this.oldRange, this.newRange, this._markers, this.affectsData, this.baseVersion );
86
- }
87
-
88
- /**
89
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
90
- *
91
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
92
- */
93
- getReversed() {
94
- return new MarkerOperation( this.name, this.newRange, this.oldRange, this._markers, this.affectsData, this.baseVersion + 1 );
95
- }
96
-
97
- /**
98
- * @inheritDoc
99
- */
100
- _execute() {
101
- const type = this.newRange ? '_set' : '_remove';
102
-
103
- this._markers[ type ]( this.name, this.newRange, true, this.affectsData );
104
- }
105
-
106
- /**
107
- * @inheritDoc
108
- */
109
- toJSON() {
110
- const json = super.toJSON();
111
-
112
- if ( this.oldRange ) {
113
- json.oldRange = this.oldRange.toJSON();
114
- }
115
-
116
- if ( this.newRange ) {
117
- json.newRange = this.newRange.toJSON();
118
- }
119
-
120
- delete json._markers;
121
-
122
- return json;
123
- }
124
-
125
- /**
126
- * @inheritDoc
127
- */
128
- static get className() {
129
- return 'MarkerOperation';
130
- }
131
-
132
- /**
133
- * Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
134
- *
135
- * @param {Object} json Deserialized JSON object.
136
- * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
137
- * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
138
- */
139
- static fromJSON( json, document ) {
140
- return new MarkerOperation(
141
- json.name,
142
- json.oldRange ? Range.fromJSON( json.oldRange, document ) : null,
143
- json.newRange ? Range.fromJSON( json.newRange, document ) : null,
144
- document.model.markers,
145
- json.affectsData,
146
- json.baseVersion
147
- );
148
- }
149
-
150
- // @if CK_DEBUG_ENGINE // toString() {
151
- // @if CK_DEBUG_ENGINE // return `MarkerOperation( ${ this.baseVersion } ): ` +
152
- // @if CK_DEBUG_ENGINE // `"${ this.name }": ${ this.oldRange } -> ${ this.newRange }`;
153
- // @if CK_DEBUG_ENGINE // }
14
+ /**
15
+ * @param {String} name Marker name.
16
+ * @param {module:engine/model/range~Range|null} oldRange Marker range before the change.
17
+ * @param {module:engine/model/range~Range|null} newRange Marker range after the change.
18
+ * @param {module:engine/model/markercollection~MarkerCollection} markers Marker collection on which change should be executed.
19
+ * @param {Boolean} affectsData Specifies whether the marker operation affects the data produced by the data pipeline
20
+ * (is persisted in the editor's data).
21
+ * @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
22
+ * can be applied or `null` if the operation operates on detached (non-document) tree.
23
+ */
24
+ constructor(name, oldRange, newRange, markers, affectsData, baseVersion) {
25
+ super(baseVersion);
26
+ /**
27
+ * Marker name.
28
+ *
29
+ * @readonly
30
+ * @member {String}
31
+ */
32
+ this.name = name;
33
+ /**
34
+ * Marker range before the change.
35
+ *
36
+ * @readonly
37
+ * @member {module:engine/model/range~Range|null}
38
+ */
39
+ 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
+ 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
+ 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
+ this._markers = markers;
62
+ }
63
+ /**
64
+ * @inheritDoc
65
+ */
66
+ get type() {
67
+ return 'marker';
68
+ }
69
+ /**
70
+ * 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
+ */
74
+ clone() {
75
+ return new MarkerOperation(this.name, this.oldRange, this.newRange, this._markers, this.affectsData, this.baseVersion);
76
+ }
77
+ /**
78
+ * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
79
+ *
80
+ * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
81
+ */
82
+ getReversed() {
83
+ return new MarkerOperation(this.name, this.newRange, this.oldRange, this._markers, this.affectsData, this.baseVersion + 1);
84
+ }
85
+ /**
86
+ * @inheritDoc
87
+ * @internal
88
+ */
89
+ _execute() {
90
+ if (this.newRange) {
91
+ this._markers._set(this.name, this.newRange, true, this.affectsData);
92
+ }
93
+ else {
94
+ this._markers._remove(this.name);
95
+ }
96
+ }
97
+ /**
98
+ * @inheritDoc
99
+ * @internal
100
+ */
101
+ toJSON() {
102
+ const json = super.toJSON();
103
+ if (this.oldRange) {
104
+ json.oldRange = this.oldRange.toJSON();
105
+ }
106
+ if (this.newRange) {
107
+ json.newRange = this.newRange.toJSON();
108
+ }
109
+ delete json._markers;
110
+ return json;
111
+ }
112
+ /**
113
+ * @inheritDoc
114
+ */
115
+ static get className() {
116
+ return 'MarkerOperation';
117
+ }
118
+ /**
119
+ * Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
120
+ *
121
+ * @param {Object} json Deserialized JSON object.
122
+ * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
123
+ * @returns {module:engine/model/operation/markeroperation~MarkerOperation}
124
+ */
125
+ static fromJSON(json, document) {
126
+ 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);
127
+ }
154
128
  }