@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.
- package/CHANGELOG.md +823 -0
- package/LICENSE.md +4 -0
- package/package.json +32 -25
- 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 +101 -117
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +117 -138
- 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 +175 -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 +899 -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 +654 -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 +1371 -1613
- 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 +191 -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 -1014
- 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,19 +2,15 @@
|
|
|
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/splitoperation
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Operation from './operation';
|
|
11
9
|
import MergeOperation from './mergeoperation';
|
|
12
10
|
import Position from '../position';
|
|
13
11
|
import Range from '../range';
|
|
14
12
|
import { _insert, _move } from './utils';
|
|
15
|
-
|
|
16
13
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
17
|
-
|
|
18
14
|
/**
|
|
19
15
|
* Operation to split {@link module:engine/model/element~Element an element} at given
|
|
20
16
|
* {@link module:engine/model/operation/splitoperation~SplitOperation#splitPosition split position} into two elements,
|
|
@@ -23,232 +19,200 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
23
19
|
* @extends module:engine/model/operation/operation~Operation
|
|
24
20
|
*/
|
|
25
21
|
export default class SplitOperation extends Operation {
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
* position is after the split element.
|
|
223
|
-
*
|
|
224
|
-
* @param {module:engine/model/position~Position} splitPosition
|
|
225
|
-
* @returns {module:engine/model/position~Position}
|
|
226
|
-
*/
|
|
227
|
-
static getInsertionPosition( splitPosition ) {
|
|
228
|
-
const path = splitPosition.path.slice( 0, -1 );
|
|
229
|
-
path[ path.length - 1 ]++;
|
|
230
|
-
|
|
231
|
-
return new Position( splitPosition.root, path, 'toPrevious' );
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Creates `SplitOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
236
|
-
*
|
|
237
|
-
* @param {Object} json Deserialized JSON object.
|
|
238
|
-
* @param {module:engine/model/document~Document} document Document on which this operation will be applied.
|
|
239
|
-
* @returns {module:engine/model/operation/splitoperation~SplitOperation}
|
|
240
|
-
*/
|
|
241
|
-
static fromJSON( json, document ) {
|
|
242
|
-
const splitPosition = Position.fromJSON( json.splitPosition, document );
|
|
243
|
-
const insertionPosition = Position.fromJSON( json.insertionPosition, document );
|
|
244
|
-
const graveyardPosition = json.graveyardPosition ? Position.fromJSON( json.graveyardPosition, document ) : null;
|
|
245
|
-
|
|
246
|
-
return new this( splitPosition, json.howMany, insertionPosition, graveyardPosition, json.baseVersion );
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// @if CK_DEBUG_ENGINE // toString() {
|
|
250
|
-
// @if CK_DEBUG_ENGINE // return `SplitOperation( ${ this.baseVersion } ): ${ this.splitPosition } ` +
|
|
251
|
-
// @if CK_DEBUG_ENGINE // `( ${ this.howMany } ) -> ${ this.insertionPosition }` +
|
|
252
|
-
// @if CK_DEBUG_ENGINE // `${ this.graveyardPosition ? ' with ' + this.graveyardPosition : '' }`;
|
|
253
|
-
// @if CK_DEBUG_ENGINE // }
|
|
22
|
+
/**
|
|
23
|
+
* Creates a split operation.
|
|
24
|
+
*
|
|
25
|
+
* @param {module:engine/model/position~Position} splitPosition Position at which an element should be split.
|
|
26
|
+
* @param {Number} howMany Total offset size of elements that are in the split element after `position`.
|
|
27
|
+
* @param {module:engine/model/position~Position} insertionPosition Position at which the clone of split element
|
|
28
|
+
* (or element from graveyard) will be inserted.
|
|
29
|
+
* @param {module:engine/model/position~Position|null} graveyardPosition Position in the graveyard root before the element which
|
|
30
|
+
* should be used as a parent of the nodes after `position`. If it is not set, a copy of the the `position` parent will be used.
|
|
31
|
+
* @param {Number|null} baseVersion Document {@link module:engine/model/document~Document#version} on which operation
|
|
32
|
+
* can be applied or `null` if the operation operates on detached (non-document) tree.
|
|
33
|
+
*/
|
|
34
|
+
constructor(splitPosition, howMany, insertionPosition, graveyardPosition, baseVersion) {
|
|
35
|
+
super(baseVersion);
|
|
36
|
+
/**
|
|
37
|
+
* Position at which an element should be split.
|
|
38
|
+
*
|
|
39
|
+
* @member {module:engine/model/position~Position} module:engine/model/operation/splitoperation~SplitOperation#splitPosition
|
|
40
|
+
*/
|
|
41
|
+
this.splitPosition = splitPosition.clone();
|
|
42
|
+
// Keep position sticking to the next node. This way any new content added at the place where the element is split
|
|
43
|
+
// will be left in the original element.
|
|
44
|
+
this.splitPosition.stickiness = 'toNext';
|
|
45
|
+
/**
|
|
46
|
+
* Total offset size of elements that are in the split element after `position`.
|
|
47
|
+
*
|
|
48
|
+
* @member {Number} module:engine/model/operation/splitoperation~SplitOperation#howMany
|
|
49
|
+
*/
|
|
50
|
+
this.howMany = howMany;
|
|
51
|
+
/**
|
|
52
|
+
* Position at which the clone of split element (or element from graveyard) will be inserted.
|
|
53
|
+
*
|
|
54
|
+
* @member {module:engine/model/position~Position} module:engine/model/operation/splitoperation~SplitOperation#insertionPosition
|
|
55
|
+
*/
|
|
56
|
+
this.insertionPosition = insertionPosition;
|
|
57
|
+
/**
|
|
58
|
+
* Position in the graveyard root before the element which should be used as a parent of the nodes after `position`.
|
|
59
|
+
* If it is not set, a copy of the the `position` parent will be used.
|
|
60
|
+
*
|
|
61
|
+
* The default behavior is to clone the split element. Element from graveyard is used during undo.
|
|
62
|
+
*
|
|
63
|
+
* @member {module:engine/model/position~Position|null} #graveyardPosition
|
|
64
|
+
*/
|
|
65
|
+
this.graveyardPosition = graveyardPosition ? graveyardPosition.clone() : null;
|
|
66
|
+
if (this.graveyardPosition) {
|
|
67
|
+
this.graveyardPosition.stickiness = 'toNext';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @inheritDoc
|
|
72
|
+
*/
|
|
73
|
+
get type() {
|
|
74
|
+
return 'split';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Position inside the new clone of a split element.
|
|
78
|
+
*
|
|
79
|
+
* This is a position where nodes that are after the split position will be moved to.
|
|
80
|
+
*
|
|
81
|
+
* @readonly
|
|
82
|
+
* @type {module:engine/model/position~Position}
|
|
83
|
+
*/
|
|
84
|
+
get moveTargetPosition() {
|
|
85
|
+
const path = this.insertionPosition.path.slice();
|
|
86
|
+
path.push(0);
|
|
87
|
+
return new Position(this.insertionPosition.root, path);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Artificial range that contains all the nodes from the split element that will be moved to the new element.
|
|
91
|
+
* The range starts at {@link ~#splitPosition} and ends in the same parent, at `POSITIVE_INFINITY` offset.
|
|
92
|
+
*
|
|
93
|
+
* @readonly
|
|
94
|
+
* @type {module:engine/model/range~Range}
|
|
95
|
+
*/
|
|
96
|
+
get movedRange() {
|
|
97
|
+
const end = this.splitPosition.getShiftedBy(Number.POSITIVE_INFINITY);
|
|
98
|
+
return new Range(this.splitPosition, end);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates and returns an operation that has the same parameters as this operation.
|
|
102
|
+
*
|
|
103
|
+
* @returns {module:engine/model/operation/splitoperation~SplitOperation} Clone of this operation.
|
|
104
|
+
*/
|
|
105
|
+
clone() {
|
|
106
|
+
return new SplitOperation(this.splitPosition, this.howMany, this.insertionPosition, this.graveyardPosition, this.baseVersion);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
|
|
110
|
+
*
|
|
111
|
+
* @returns {module:engine/model/operation/mergeoperation~MergeOperation}
|
|
112
|
+
*/
|
|
113
|
+
getReversed() {
|
|
114
|
+
const graveyard = this.splitPosition.root.document.graveyard;
|
|
115
|
+
const graveyardPosition = new Position(graveyard, [0]);
|
|
116
|
+
return new MergeOperation(this.moveTargetPosition, this.howMany, this.splitPosition, graveyardPosition, this.baseVersion + 1);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @inheritDoc
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
_validate() {
|
|
123
|
+
const element = this.splitPosition.parent;
|
|
124
|
+
const offset = this.splitPosition.offset;
|
|
125
|
+
// Validate whether split operation has correct parameters.
|
|
126
|
+
if (!element || element.maxOffset < offset) {
|
|
127
|
+
/**
|
|
128
|
+
* Split position is invalid.
|
|
129
|
+
*
|
|
130
|
+
* @error split-operation-position-invalid
|
|
131
|
+
*/
|
|
132
|
+
throw new CKEditorError('split-operation-position-invalid', this);
|
|
133
|
+
}
|
|
134
|
+
else if (!element.parent) {
|
|
135
|
+
/**
|
|
136
|
+
* Cannot split root element.
|
|
137
|
+
*
|
|
138
|
+
* @error split-operation-split-in-root
|
|
139
|
+
*/
|
|
140
|
+
throw new CKEditorError('split-operation-split-in-root', this);
|
|
141
|
+
}
|
|
142
|
+
else if (this.howMany != element.maxOffset - this.splitPosition.offset) {
|
|
143
|
+
/**
|
|
144
|
+
* Split operation specifies wrong number of nodes to move.
|
|
145
|
+
*
|
|
146
|
+
* @error split-operation-how-many-invalid
|
|
147
|
+
*/
|
|
148
|
+
throw new CKEditorError('split-operation-how-many-invalid', this);
|
|
149
|
+
}
|
|
150
|
+
else if (this.graveyardPosition && !this.graveyardPosition.nodeAfter) {
|
|
151
|
+
/**
|
|
152
|
+
* Graveyard position invalid.
|
|
153
|
+
*
|
|
154
|
+
* @error split-operation-graveyard-position-invalid
|
|
155
|
+
*/
|
|
156
|
+
throw new CKEditorError('split-operation-graveyard-position-invalid', this);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @inheritDoc
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
_execute() {
|
|
164
|
+
const splitElement = this.splitPosition.parent;
|
|
165
|
+
if (this.graveyardPosition) {
|
|
166
|
+
_move(Range._createFromPositionAndShift(this.graveyardPosition, 1), this.insertionPosition);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
const newElement = splitElement._clone();
|
|
170
|
+
_insert(this.insertionPosition, newElement);
|
|
171
|
+
}
|
|
172
|
+
const sourceRange = new Range(Position._createAt(splitElement, this.splitPosition.offset), Position._createAt(splitElement, splitElement.maxOffset));
|
|
173
|
+
_move(sourceRange, this.moveTargetPosition);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @inheritDoc
|
|
177
|
+
*/
|
|
178
|
+
toJSON() {
|
|
179
|
+
const json = super.toJSON();
|
|
180
|
+
json.splitPosition = this.splitPosition.toJSON();
|
|
181
|
+
json.insertionPosition = this.insertionPosition.toJSON();
|
|
182
|
+
if (this.graveyardPosition) {
|
|
183
|
+
json.graveyardPosition = this.graveyardPosition.toJSON();
|
|
184
|
+
}
|
|
185
|
+
return json;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @inheritDoc
|
|
189
|
+
*/
|
|
190
|
+
static get className() {
|
|
191
|
+
return 'SplitOperation';
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Helper function that returns a default insertion position basing on given `splitPosition`. The default insertion
|
|
195
|
+
* position is after the split element.
|
|
196
|
+
*
|
|
197
|
+
* @param {module:engine/model/position~Position} splitPosition
|
|
198
|
+
* @returns {module:engine/model/position~Position}
|
|
199
|
+
*/
|
|
200
|
+
static getInsertionPosition(splitPosition) {
|
|
201
|
+
const path = splitPosition.path.slice(0, -1);
|
|
202
|
+
path[path.length - 1]++;
|
|
203
|
+
return new Position(splitPosition.root, path, 'toPrevious');
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates `SplitOperation` object from deserilized object, i.e. from parsed JSON string.
|
|
207
|
+
*
|
|
208
|
+
* @param {Object} json Deserialized JSON object.
|
|
209
|
+
* @param {module:engine/model/document~Document} document Document on which this operation will be applied.
|
|
210
|
+
* @returns {module:engine/model/operation/splitoperation~SplitOperation}
|
|
211
|
+
*/
|
|
212
|
+
static fromJSON(json, document) {
|
|
213
|
+
const splitPosition = Position.fromJSON(json.splitPosition, document);
|
|
214
|
+
const insertionPosition = Position.fromJSON(json.insertionPosition, document);
|
|
215
|
+
const graveyardPosition = json.graveyardPosition ? Position.fromJSON(json.graveyardPosition, document) : null;
|
|
216
|
+
return new this(splitPosition, json.howMany, insertionPosition, graveyardPosition, json.baseVersion);
|
|
217
|
+
}
|
|
254
218
|
}
|