@ckeditor/ckeditor5-engine 35.0.1 → 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 +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 +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 +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 +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 -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,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
|
-
|
|
5
|
+
/* eslint-disable new-cap */
|
|
6
6
|
/**
|
|
7
7
|
* @module engine/model/liveposition
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
import Position from './position';
|
|
11
10
|
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
12
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
13
11
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
14
|
-
|
|
15
12
|
/**
|
|
16
13
|
* `LivePosition` is a type of {@link module:engine/model/position~Position Position}
|
|
17
14
|
* that updates itself as {@link module:engine/model/document~Document document}
|
|
@@ -27,156 +24,98 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
27
24
|
*
|
|
28
25
|
* @extends module:engine/model/position~Position
|
|
29
26
|
*/
|
|
30
|
-
export default class LivePosition extends Position {
|
|
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
|
-
* @returns {Boolean}
|
|
78
|
-
*/
|
|
79
|
-
is( type ) {
|
|
80
|
-
return type === 'livePosition' || type === 'model:livePosition' ||
|
|
81
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
82
|
-
type == 'position' || type === 'model:position';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position.
|
|
87
|
-
*
|
|
88
|
-
* @returns {module:engine/model/position~Position}
|
|
89
|
-
*/
|
|
90
|
-
toPosition() {
|
|
91
|
-
return new Position( this.root, this.path.slice(), this.stickiness );
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Creates a `LivePosition` instance that is equal to position.
|
|
96
|
-
*
|
|
97
|
-
* @param {module:engine/model/position~Position} position
|
|
98
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
99
|
-
* @returns {module:engine/model/liveposition~LivePosition}
|
|
100
|
-
*/
|
|
101
|
-
static fromPosition( position, stickiness ) {
|
|
102
|
-
return new this( position.root, position.path.slice(), stickiness ? stickiness : position.stickiness );
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @static
|
|
107
|
-
* @protected
|
|
108
|
-
* @method module:engine/model/liveposition~LivePosition._createAfter
|
|
109
|
-
* @see module:engine/model/position~Position._createAfter
|
|
110
|
-
* @param {module:engine/model/node~Node} node
|
|
111
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness='toNone']
|
|
112
|
-
* @returns {module:engine/model/liveposition~LivePosition}
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @static
|
|
117
|
-
* @protected
|
|
118
|
-
* @method module:engine/model/liveposition~LivePosition._createBefore
|
|
119
|
-
* @see module:engine/model/position~Position._createBefore
|
|
120
|
-
* @param {module:engine/model/node~Node} node
|
|
121
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness='toNone']
|
|
122
|
-
* @returns {module:engine/model/liveposition~LivePosition}
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @static
|
|
127
|
-
* @protected
|
|
128
|
-
* @method module:engine/model/liveposition~LivePosition._createAt
|
|
129
|
-
* @see module:engine/model/position~Position._createAt
|
|
130
|
-
* @param {module:engine/model/item~Item|module:engine/model/position~Position} itemOrPosition
|
|
131
|
-
* @param {Number|'end'|'before'|'after'} [offset]
|
|
132
|
-
* @param {module:engine/model/position~PositionStickiness} [stickiness='toNone']
|
|
133
|
-
* @returns {module:engine/model/liveposition~LivePosition}
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Fired when `LivePosition` instance is changed due to changes on {@link module:engine/model/document~Document}.
|
|
138
|
-
*
|
|
139
|
-
* @event module:engine/model/liveposition~LivePosition#change
|
|
140
|
-
* @param {module:engine/model/position~Position} oldPosition Position equal to this live position before it got changed.
|
|
141
|
-
*/
|
|
27
|
+
export default class LivePosition extends EmitterMixin(Position) {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a live position.
|
|
30
|
+
*
|
|
31
|
+
* @see module:engine/model/position~Position
|
|
32
|
+
* @param {module:engine/model/rootelement~RootElement} root
|
|
33
|
+
* @param {Array.<Number>} path
|
|
34
|
+
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
35
|
+
*/
|
|
36
|
+
constructor(root, path, stickiness = 'toNone') {
|
|
37
|
+
super(root, path, stickiness);
|
|
38
|
+
if (!this.root.is('rootElement')) {
|
|
39
|
+
/**
|
|
40
|
+
* LivePosition's root has to be an instance of RootElement.
|
|
41
|
+
*
|
|
42
|
+
* @error model-liveposition-root-not-rootelement
|
|
43
|
+
*/
|
|
44
|
+
throw new CKEditorError('model-liveposition-root-not-rootelement', root);
|
|
45
|
+
}
|
|
46
|
+
bindWithDocument.call(this);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Unbinds all events previously bound by `LivePosition`. Use it whenever you don't need `LivePosition` instance
|
|
50
|
+
* anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was
|
|
51
|
+
* referring to it).
|
|
52
|
+
*/
|
|
53
|
+
detach() {
|
|
54
|
+
this.stopListening();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position.
|
|
58
|
+
*
|
|
59
|
+
* @returns {module:engine/model/position~Position}
|
|
60
|
+
*/
|
|
61
|
+
toPosition() {
|
|
62
|
+
return new Position(this.root, this.path.slice(), this.stickiness);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a `LivePosition` instance that is equal to position.
|
|
66
|
+
*
|
|
67
|
+
* @param {module:engine/model/position~Position} position
|
|
68
|
+
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
69
|
+
* @returns {module:engine/model/liveposition~LivePosition}
|
|
70
|
+
*/
|
|
71
|
+
static fromPosition(position, stickiness) {
|
|
72
|
+
return new this(position.root, position.path.slice(), stickiness ? stickiness : position.stickiness);
|
|
73
|
+
}
|
|
142
74
|
}
|
|
143
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether this object is of the given.
|
|
77
|
+
*
|
|
78
|
+
* livePosition.is( 'position' ); // -> true
|
|
79
|
+
* livePosition.is( 'model:position' ); // -> true
|
|
80
|
+
* livePosition.is( 'liveposition' ); // -> true
|
|
81
|
+
* livePosition.is( 'model:livePosition' ); // -> true
|
|
82
|
+
*
|
|
83
|
+
* livePosition.is( 'view:position' ); // -> false
|
|
84
|
+
* livePosition.is( 'documentSelection' ); // -> false
|
|
85
|
+
*
|
|
86
|
+
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
87
|
+
*
|
|
88
|
+
* @param {String} type
|
|
89
|
+
* @returns {Boolean}
|
|
90
|
+
*/
|
|
91
|
+
LivePosition.prototype.is = function (type) {
|
|
92
|
+
return type === 'livePosition' || type === 'model:livePosition' ||
|
|
93
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
94
|
+
type == 'position' || type === 'model:position';
|
|
95
|
+
};
|
|
144
96
|
// Binds this `LivePosition` to the {@link module:engine/model/document~Document document} that owns
|
|
145
97
|
// this position's {@link module:engine/model/position~Position#root root}.
|
|
146
98
|
//
|
|
147
99
|
// @private
|
|
148
100
|
function bindWithDocument() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
transform.call( this, operation );
|
|
160
|
-
},
|
|
161
|
-
{ priority: 'low' }
|
|
162
|
-
);
|
|
101
|
+
this.listenTo(this.root.document.model, 'applyOperation', (event, args) => {
|
|
102
|
+
const operation = args[0];
|
|
103
|
+
if (!operation.isDocumentOperation) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
transform.call(this, operation);
|
|
107
|
+
}, { priority: 'low' });
|
|
163
108
|
}
|
|
164
|
-
|
|
165
109
|
// Updates this position accordingly to the updates applied to the model. Bases on change events.
|
|
166
110
|
//
|
|
167
111
|
// @private
|
|
168
112
|
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
169
|
-
function transform(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
this.fire( 'change', oldPosition );
|
|
179
|
-
}
|
|
113
|
+
function transform(operation) {
|
|
114
|
+
const result = this.getTransformedByOperation(operation);
|
|
115
|
+
if (!this.isEqual(result)) {
|
|
116
|
+
const oldPosition = this.toPosition();
|
|
117
|
+
this.path = result.path;
|
|
118
|
+
this.root = result.root;
|
|
119
|
+
this.fire('change', oldPosition);
|
|
120
|
+
}
|
|
180
121
|
}
|
|
181
|
-
|
|
182
|
-
mix( LivePosition, EmitterMixin );
|
package/src/model/liverange.js
CHANGED
|
@@ -2,15 +2,12 @@
|
|
|
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
|
-
|
|
5
|
+
/* eslint-disable new-cap */
|
|
6
6
|
/**
|
|
7
7
|
* @module engine/model/liverange
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
9
|
import Range from './range';
|
|
11
10
|
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
12
|
-
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* `LiveRange` is a type of {@link module:engine/model/range~Range Range}
|
|
16
13
|
* that updates itself as {@link module:engine/model/document~Document document}
|
|
@@ -19,203 +16,129 @@ import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
|
19
16
|
* **Note:** Be very careful when dealing with `LiveRange`. Each `LiveRange` instance bind events that might
|
|
20
17
|
* have to be unbound. Use {@link module:engine/model/liverange~LiveRange#detach detach} whenever you don't need `LiveRange` anymore.
|
|
21
18
|
*/
|
|
22
|
-
export default class LiveRange extends Range {
|
|
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
|
-
* @returns {Boolean}
|
|
58
|
-
*/
|
|
59
|
-
is( type ) {
|
|
60
|
-
return type === 'liveRange' || type === 'model:liveRange' ||
|
|
61
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
62
|
-
type == 'range' || type === 'model:range';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Creates a {@link module:engine/model/range~Range range instance} that is equal to this live range.
|
|
67
|
-
*
|
|
68
|
-
* @returns {module:engine/model/range~Range}
|
|
69
|
-
*/
|
|
70
|
-
toRange() {
|
|
71
|
-
return new Range( this.start, this.end );
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Creates a `LiveRange` instance that is equal to the given range.
|
|
76
|
-
*
|
|
77
|
-
* @param {module:engine/model/range~Range} range
|
|
78
|
-
* @returns {module:engine/model/liverange~LiveRange}
|
|
79
|
-
*/
|
|
80
|
-
static fromRange( range ) {
|
|
81
|
-
return new LiveRange( range.start, range.end );
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @see module:engine/model/range~Range._createIn
|
|
86
|
-
* @static
|
|
87
|
-
* @protected
|
|
88
|
-
* @method module:engine/model/liverange~LiveRange._createIn
|
|
89
|
-
* @param {module:engine/model/element~Element} element
|
|
90
|
-
* @returns {module:engine/model/liverange~LiveRange}
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @see module:engine/model/range~Range._createOn
|
|
95
|
-
* @static
|
|
96
|
-
* @protected
|
|
97
|
-
* @method module:engine/model/liverange~LiveRange._createOn
|
|
98
|
-
* @param {module:engine/model/element~Element} element
|
|
99
|
-
* @returns {module:engine/model/liverange~LiveRange}
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @see module:engine/model/range~Range._createFromPositionAndShift
|
|
104
|
-
* @static
|
|
105
|
-
* @protected
|
|
106
|
-
* @method module:engine/model/liverange~LiveRange._createFromPositionAndShift
|
|
107
|
-
* @param {module:engine/model/position~Position} position
|
|
108
|
-
* @param {Number} shift
|
|
109
|
-
* @returns {module:engine/model/liverange~LiveRange}
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Fired when `LiveRange` instance boundaries have changed due to changes in the
|
|
114
|
-
* {@link module:engine/model/document~Document document}.
|
|
115
|
-
*
|
|
116
|
-
* @event change:range
|
|
117
|
-
* @param {module:engine/model/range~Range} oldRange Range with start and end position equal to start and end position of this live
|
|
118
|
-
* range before it got changed.
|
|
119
|
-
* @param {Object} data Object with additional information about the change.
|
|
120
|
-
* @param {module:engine/model/position~Position|null} data.deletionPosition Source position for remove and merge changes.
|
|
121
|
-
* Available if the range was moved to the graveyard root, `null` otherwise.
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Fired when `LiveRange` instance boundaries have not changed after a change in {@link module:engine/model/document~Document document}
|
|
126
|
-
* but the change took place inside the range, effectively changing its content.
|
|
127
|
-
*
|
|
128
|
-
* @event change:content
|
|
129
|
-
* @param {module:engine/model/range~Range} range Range with start and end position equal to start and end position of
|
|
130
|
-
* change range.
|
|
131
|
-
* @param {Object} data Object with additional information about the change.
|
|
132
|
-
* @param {null} data.deletionPosition Due to the nature of this event, this property is always set to `null`. It is passed
|
|
133
|
-
* for compatibility with the {@link module:engine/model/liverange~LiveRange#event:change:range} event.
|
|
134
|
-
*/
|
|
19
|
+
export default class LiveRange extends EmitterMixin(Range) {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a live range.
|
|
22
|
+
*
|
|
23
|
+
* @see module:engine/model/range~Range
|
|
24
|
+
*/
|
|
25
|
+
constructor(start, end) {
|
|
26
|
+
super(start, end);
|
|
27
|
+
bindWithDocument.call(this);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Unbinds all events previously bound by `LiveRange`. Use it whenever you don't need `LiveRange` instance
|
|
31
|
+
* anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was
|
|
32
|
+
* referring to it).
|
|
33
|
+
*/
|
|
34
|
+
detach() {
|
|
35
|
+
this.stopListening();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a {@link module:engine/model/range~Range range instance} that is equal to this live range.
|
|
39
|
+
*
|
|
40
|
+
* @returns {module:engine/model/range~Range}
|
|
41
|
+
*/
|
|
42
|
+
toRange() {
|
|
43
|
+
return new Range(this.start, this.end);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a `LiveRange` instance that is equal to the given range.
|
|
47
|
+
*
|
|
48
|
+
* @param {module:engine/model/range~Range} range
|
|
49
|
+
* @returns {module:engine/model/liverange~LiveRange}
|
|
50
|
+
*/
|
|
51
|
+
static fromRange(range) {
|
|
52
|
+
return new LiveRange(range.start, range.end);
|
|
53
|
+
}
|
|
135
54
|
}
|
|
136
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether this object is of the given.
|
|
57
|
+
*
|
|
58
|
+
* liveRange.is( 'range' ); // -> true
|
|
59
|
+
* liveRange.is( 'model:range' ); // -> true
|
|
60
|
+
* liveRange.is( 'liveRange' ); // -> true
|
|
61
|
+
* liveRange.is( 'model:liveRange' ); // -> true
|
|
62
|
+
*
|
|
63
|
+
* liveRange.is( 'view:range' ); // -> false
|
|
64
|
+
* liveRange.is( 'documentSelection' ); // -> false
|
|
65
|
+
*
|
|
66
|
+
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
67
|
+
*
|
|
68
|
+
* @param {String} type
|
|
69
|
+
* @returns {Boolean}
|
|
70
|
+
*/
|
|
71
|
+
LiveRange.prototype.is = function (type) {
|
|
72
|
+
return type === 'liveRange' || type === 'model:liveRange' ||
|
|
73
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
74
|
+
type == 'range' || type === 'model:range';
|
|
75
|
+
};
|
|
137
76
|
// Binds this `LiveRange` to the {@link module:engine/model/document~Document document}
|
|
138
77
|
// that owns this range's {@link module:engine/model/range~Range#root root}.
|
|
139
78
|
//
|
|
140
79
|
// @private
|
|
141
80
|
function bindWithDocument() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
transform.call( this, operation );
|
|
153
|
-
},
|
|
154
|
-
{ priority: 'low' }
|
|
155
|
-
);
|
|
81
|
+
this.listenTo(this.root.document.model, 'applyOperation', (event, args) => {
|
|
82
|
+
const operation = args[0];
|
|
83
|
+
if (!operation.isDocumentOperation) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
transform.call(this, operation);
|
|
87
|
+
}, { priority: 'low' });
|
|
156
88
|
}
|
|
157
|
-
|
|
158
89
|
// Updates this range accordingly to the updates applied to the model. Bases on change events.
|
|
159
90
|
//
|
|
160
91
|
// @private
|
|
161
92
|
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
162
|
-
function transform(
|
|
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
|
-
} else if ( contentChanged ) {
|
|
192
|
-
// If range boundaries have not changed, but there was change inside the range, fire `change:content` event.
|
|
193
|
-
this.fire( 'change:content', this.toRange(), { deletionPosition } );
|
|
194
|
-
}
|
|
93
|
+
function transform(operation) {
|
|
94
|
+
// Transform the range by the operation. Join the result ranges if needed.
|
|
95
|
+
const ranges = this.getTransformedByOperation(operation);
|
|
96
|
+
const result = Range._createFromRanges(ranges);
|
|
97
|
+
const boundariesChanged = !result.isEqual(this);
|
|
98
|
+
const contentChanged = doesOperationChangeRangeContent(this, operation);
|
|
99
|
+
let deletionPosition = null;
|
|
100
|
+
if (boundariesChanged) {
|
|
101
|
+
// If range boundaries have changed, fire `change:range` event.
|
|
102
|
+
//
|
|
103
|
+
if (result.root.rootName == '$graveyard') {
|
|
104
|
+
// If the range was moved to the graveyard root, set `deletionPosition`.
|
|
105
|
+
if (operation.type == 'remove') {
|
|
106
|
+
deletionPosition = operation.sourcePosition;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Merge operation.
|
|
110
|
+
deletionPosition = operation.deletionPosition;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const oldRange = this.toRange();
|
|
114
|
+
this.start = result.start;
|
|
115
|
+
this.end = result.end;
|
|
116
|
+
this.fire('change:range', oldRange, { deletionPosition });
|
|
117
|
+
}
|
|
118
|
+
else if (contentChanged) {
|
|
119
|
+
// If range boundaries have not changed, but there was change inside the range, fire `change:content` event.
|
|
120
|
+
this.fire('change:content', this.toRange(), { deletionPosition });
|
|
121
|
+
}
|
|
195
122
|
}
|
|
196
|
-
|
|
197
123
|
// Checks whether given operation changes something inside the range (even if it does not change boundaries).
|
|
198
124
|
//
|
|
199
125
|
// @private
|
|
200
126
|
// @param {module:engine/model/range~Range} range Range to check.
|
|
201
127
|
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
202
128
|
// @returns {Boolean}
|
|
203
|
-
function doesOperationChangeRangeContent(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return false;
|
|
129
|
+
function doesOperationChangeRangeContent(range, operation) {
|
|
130
|
+
switch (operation.type) {
|
|
131
|
+
case 'insert':
|
|
132
|
+
return range.containsPosition(operation.position);
|
|
133
|
+
case 'move':
|
|
134
|
+
case 'remove':
|
|
135
|
+
case 'reinsert':
|
|
136
|
+
case 'merge':
|
|
137
|
+
return range.containsPosition(operation.sourcePosition) ||
|
|
138
|
+
range.start.isEqual(operation.sourcePosition) ||
|
|
139
|
+
range.containsPosition(operation.targetPosition);
|
|
140
|
+
case 'split':
|
|
141
|
+
return range.containsPosition(operation.splitPosition) || range.containsPosition(operation.insertionPosition);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
219
144
|
}
|
|
220
|
-
|
|
221
|
-
mix( LiveRange, EmitterMixin );
|