@ckeditor/ckeditor5-engine 30.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/README.md +30 -0
- package/package.json +70 -0
- package/src/controller/datacontroller.js +563 -0
- package/src/controller/editingcontroller.js +149 -0
- package/src/conversion/conversion.js +644 -0
- package/src/conversion/conversionhelpers.js +40 -0
- package/src/conversion/downcastdispatcher.js +914 -0
- package/src/conversion/downcasthelpers.js +1706 -0
- package/src/conversion/mapper.js +696 -0
- package/src/conversion/modelconsumable.js +329 -0
- package/src/conversion/upcastdispatcher.js +807 -0
- package/src/conversion/upcasthelpers.js +997 -0
- package/src/conversion/viewconsumable.js +623 -0
- package/src/dataprocessor/basichtmlwriter.js +32 -0
- package/src/dataprocessor/dataprocessor.jsdoc +64 -0
- package/src/dataprocessor/htmldataprocessor.js +159 -0
- package/src/dataprocessor/htmlwriter.js +22 -0
- package/src/dataprocessor/xmldataprocessor.js +161 -0
- package/src/dev-utils/model.js +482 -0
- package/src/dev-utils/operationreplayer.js +140 -0
- package/src/dev-utils/utils.js +103 -0
- package/src/dev-utils/view.js +1091 -0
- package/src/index.js +52 -0
- package/src/model/batch.js +82 -0
- package/src/model/differ.js +1282 -0
- package/src/model/document.js +483 -0
- package/src/model/documentfragment.js +390 -0
- package/src/model/documentselection.js +1261 -0
- package/src/model/element.js +438 -0
- package/src/model/history.js +138 -0
- package/src/model/item.jsdoc +14 -0
- package/src/model/liveposition.js +182 -0
- package/src/model/liverange.js +221 -0
- package/src/model/markercollection.js +553 -0
- package/src/model/model.js +934 -0
- package/src/model/node.js +507 -0
- package/src/model/nodelist.js +217 -0
- package/src/model/operation/attributeoperation.js +202 -0
- package/src/model/operation/detachoperation.js +103 -0
- package/src/model/operation/insertoperation.js +188 -0
- package/src/model/operation/markeroperation.js +154 -0
- package/src/model/operation/mergeoperation.js +216 -0
- package/src/model/operation/moveoperation.js +209 -0
- package/src/model/operation/nooperation.js +58 -0
- package/src/model/operation/operation.js +139 -0
- package/src/model/operation/operationfactory.js +49 -0
- package/src/model/operation/renameoperation.js +155 -0
- package/src/model/operation/rootattributeoperation.js +211 -0
- package/src/model/operation/splitoperation.js +254 -0
- package/src/model/operation/transform.js +2389 -0
- package/src/model/operation/utils.js +292 -0
- package/src/model/position.js +1164 -0
- package/src/model/range.js +1049 -0
- package/src/model/rootelement.js +111 -0
- package/src/model/schema.js +1851 -0
- package/src/model/selection.js +902 -0
- package/src/model/text.js +138 -0
- package/src/model/textproxy.js +279 -0
- package/src/model/treewalker.js +414 -0
- package/src/model/utils/autoparagraphing.js +77 -0
- package/src/model/utils/deletecontent.js +528 -0
- package/src/model/utils/getselectedcontent.js +150 -0
- package/src/model/utils/insertcontent.js +824 -0
- package/src/model/utils/modifyselection.js +229 -0
- package/src/model/utils/selection-post-fixer.js +297 -0
- package/src/model/writer.js +1574 -0
- package/src/view/attributeelement.js +274 -0
- package/src/view/containerelement.js +123 -0
- package/src/view/document.js +221 -0
- package/src/view/documentfragment.js +273 -0
- package/src/view/documentselection.js +387 -0
- package/src/view/domconverter.js +1437 -0
- package/src/view/downcastwriter.js +2121 -0
- package/src/view/editableelement.js +118 -0
- package/src/view/element.js +945 -0
- package/src/view/elementdefinition.jsdoc +59 -0
- package/src/view/emptyelement.js +119 -0
- package/src/view/filler.js +161 -0
- package/src/view/item.jsdoc +14 -0
- package/src/view/matcher.js +776 -0
- package/src/view/node.js +391 -0
- package/src/view/observer/arrowkeysobserver.js +58 -0
- package/src/view/observer/bubblingemittermixin.js +307 -0
- package/src/view/observer/bubblingeventinfo.js +71 -0
- package/src/view/observer/clickobserver.js +46 -0
- package/src/view/observer/compositionobserver.js +79 -0
- package/src/view/observer/domeventdata.js +82 -0
- package/src/view/observer/domeventobserver.js +99 -0
- package/src/view/observer/fakeselectionobserver.js +118 -0
- package/src/view/observer/focusobserver.js +106 -0
- package/src/view/observer/inputobserver.js +44 -0
- package/src/view/observer/keyobserver.js +83 -0
- package/src/view/observer/mouseobserver.js +56 -0
- package/src/view/observer/mutationobserver.js +345 -0
- package/src/view/observer/observer.js +118 -0
- package/src/view/observer/selectionobserver.js +242 -0
- package/src/view/placeholder.js +285 -0
- package/src/view/position.js +426 -0
- package/src/view/range.js +533 -0
- package/src/view/rawelement.js +148 -0
- package/src/view/renderer.js +1037 -0
- package/src/view/rooteditableelement.js +107 -0
- package/src/view/selection.js +718 -0
- package/src/view/styles/background.js +73 -0
- package/src/view/styles/border.js +362 -0
- package/src/view/styles/margin.js +41 -0
- package/src/view/styles/padding.js +40 -0
- package/src/view/styles/utils.js +277 -0
- package/src/view/stylesmap.js +938 -0
- package/src/view/text.js +147 -0
- package/src/view/textproxy.js +199 -0
- package/src/view/treewalker.js +496 -0
- package/src/view/uielement.js +238 -0
- package/src/view/upcastwriter.js +484 -0
- package/src/view/view.js +721 -0
- package/theme/placeholder.css +27 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/model/liveposition
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Position from './position';
|
|
11
|
+
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
12
|
+
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
13
|
+
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* `LivePosition` is a type of {@link module:engine/model/position~Position Position}
|
|
17
|
+
* that updates itself as {@link module:engine/model/document~Document document}
|
|
18
|
+
* is changed through operations. It may be used as a bookmark.
|
|
19
|
+
*
|
|
20
|
+
* **Note:** Contrary to {@link module:engine/model/position~Position}, `LivePosition` works only in roots that are
|
|
21
|
+
* {@link module:engine/model/rootelement~RootElement}.
|
|
22
|
+
* If {@link module:engine/model/documentfragment~DocumentFragment} is passed, error will be thrown.
|
|
23
|
+
*
|
|
24
|
+
* **Note:** Be very careful when dealing with `LivePosition`. Each `LivePosition` instance bind events that might
|
|
25
|
+
* have to be unbound.
|
|
26
|
+
* Use {@link module:engine/model/liveposition~LivePosition#detach} whenever you don't need `LivePosition` anymore.
|
|
27
|
+
*
|
|
28
|
+
* @extends module:engine/model/position~Position
|
|
29
|
+
*/
|
|
30
|
+
export default class LivePosition extends Position {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a live position.
|
|
33
|
+
*
|
|
34
|
+
* @see module:engine/model/position~Position
|
|
35
|
+
* @param {module:engine/model/rootelement~RootElement} root
|
|
36
|
+
* @param {Array.<Number>} path
|
|
37
|
+
* @param {module:engine/model/position~PositionStickiness} [stickiness]
|
|
38
|
+
*/
|
|
39
|
+
constructor( root, path, stickiness = 'toNone' ) {
|
|
40
|
+
super( root, path, stickiness );
|
|
41
|
+
|
|
42
|
+
if ( !this.root.is( 'rootElement' ) ) {
|
|
43
|
+
/**
|
|
44
|
+
* LivePosition's root has to be an instance of RootElement.
|
|
45
|
+
*
|
|
46
|
+
* @error model-liveposition-root-not-rootelement
|
|
47
|
+
*/
|
|
48
|
+
throw new CKEditorError( 'model-liveposition-root-not-rootelement', root );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
bindWithDocument.call( this );
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Unbinds all events previously bound by `LivePosition`. Use it whenever you don't need `LivePosition` instance
|
|
56
|
+
* anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was
|
|
57
|
+
* referring to it).
|
|
58
|
+
*/
|
|
59
|
+
detach() {
|
|
60
|
+
this.stopListening();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether this object is of the given.
|
|
65
|
+
*
|
|
66
|
+
* livePosition.is( 'position' ); // -> true
|
|
67
|
+
* livePosition.is( 'model:position' ); // -> true
|
|
68
|
+
* livePosition.is( 'liveposition' ); // -> true
|
|
69
|
+
* livePosition.is( 'model:livePosition' ); // -> true
|
|
70
|
+
*
|
|
71
|
+
* livePosition.is( 'view:position' ); // -> false
|
|
72
|
+
* livePosition.is( 'documentSelection' ); // -> false
|
|
73
|
+
*
|
|
74
|
+
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
75
|
+
*
|
|
76
|
+
* @param {String} type
|
|
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
|
+
*/
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Binds this `LivePosition` to the {@link module:engine/model/document~Document document} that owns
|
|
145
|
+
// this position's {@link module:engine/model/position~Position#root root}.
|
|
146
|
+
//
|
|
147
|
+
// @private
|
|
148
|
+
function bindWithDocument() {
|
|
149
|
+
this.listenTo(
|
|
150
|
+
this.root.document.model,
|
|
151
|
+
'applyOperation',
|
|
152
|
+
( event, args ) => {
|
|
153
|
+
const operation = args[ 0 ];
|
|
154
|
+
|
|
155
|
+
if ( !operation.isDocumentOperation ) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
transform.call( this, operation );
|
|
160
|
+
},
|
|
161
|
+
{ priority: 'low' }
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Updates this position accordingly to the updates applied to the model. Bases on change events.
|
|
166
|
+
//
|
|
167
|
+
// @private
|
|
168
|
+
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
169
|
+
function transform( operation ) {
|
|
170
|
+
const result = this.getTransformedByOperation( operation );
|
|
171
|
+
|
|
172
|
+
if ( !this.isEqual( result ) ) {
|
|
173
|
+
const oldPosition = this.toPosition();
|
|
174
|
+
|
|
175
|
+
this.path = result.path;
|
|
176
|
+
this.root = result.root;
|
|
177
|
+
|
|
178
|
+
this.fire( 'change', oldPosition );
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
mix( LivePosition, EmitterMixin );
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module engine/model/liverange
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Range from './range';
|
|
11
|
+
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
12
|
+
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `LiveRange` is a type of {@link module:engine/model/range~Range Range}
|
|
16
|
+
* that updates itself as {@link module:engine/model/document~Document document}
|
|
17
|
+
* is changed through operations. It may be used as a bookmark.
|
|
18
|
+
*
|
|
19
|
+
* **Note:** Be very careful when dealing with `LiveRange`. Each `LiveRange` instance bind events that might
|
|
20
|
+
* have to be unbound. Use {@link module:engine/model/liverange~LiveRange#detach detach} whenever you don't need `LiveRange` anymore.
|
|
21
|
+
*/
|
|
22
|
+
export default class LiveRange extends Range {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a live range.
|
|
25
|
+
*
|
|
26
|
+
* @see module:engine/model/range~Range
|
|
27
|
+
*/
|
|
28
|
+
constructor( start, end ) {
|
|
29
|
+
super( start, end );
|
|
30
|
+
|
|
31
|
+
bindWithDocument.call( this );
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Unbinds all events previously bound by `LiveRange`. Use it whenever you don't need `LiveRange` instance
|
|
36
|
+
* anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was
|
|
37
|
+
* referring to it).
|
|
38
|
+
*/
|
|
39
|
+
detach() {
|
|
40
|
+
this.stopListening();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether this object is of the given.
|
|
45
|
+
*
|
|
46
|
+
* liveRange.is( 'range' ); // -> true
|
|
47
|
+
* liveRange.is( 'model:range' ); // -> true
|
|
48
|
+
* liveRange.is( 'liveRange' ); // -> true
|
|
49
|
+
* liveRange.is( 'model:liveRange' ); // -> true
|
|
50
|
+
*
|
|
51
|
+
* liveRange.is( 'view:range' ); // -> false
|
|
52
|
+
* liveRange.is( 'documentSelection' ); // -> false
|
|
53
|
+
*
|
|
54
|
+
* {@link module:engine/model/node~Node#is Check the entire list of model objects} which implement the `is()` method.
|
|
55
|
+
*
|
|
56
|
+
* @param {String} type
|
|
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
|
+
*/
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Binds this `LiveRange` to the {@link module:engine/model/document~Document document}
|
|
138
|
+
// that owns this range's {@link module:engine/model/range~Range#root root}.
|
|
139
|
+
//
|
|
140
|
+
// @private
|
|
141
|
+
function bindWithDocument() {
|
|
142
|
+
this.listenTo(
|
|
143
|
+
this.root.document.model,
|
|
144
|
+
'applyOperation',
|
|
145
|
+
( event, args ) => {
|
|
146
|
+
const operation = args[ 0 ];
|
|
147
|
+
|
|
148
|
+
if ( !operation.isDocumentOperation ) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
transform.call( this, operation );
|
|
153
|
+
},
|
|
154
|
+
{ priority: 'low' }
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Updates this range accordingly to the updates applied to the model. Bases on change events.
|
|
159
|
+
//
|
|
160
|
+
// @private
|
|
161
|
+
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
162
|
+
function transform( operation ) {
|
|
163
|
+
// Transform the range by the operation. Join the result ranges if needed.
|
|
164
|
+
const ranges = this.getTransformedByOperation( operation );
|
|
165
|
+
const result = Range._createFromRanges( ranges );
|
|
166
|
+
|
|
167
|
+
const boundariesChanged = !result.isEqual( this );
|
|
168
|
+
const contentChanged = doesOperationChangeRangeContent( this, operation );
|
|
169
|
+
|
|
170
|
+
let deletionPosition = null;
|
|
171
|
+
|
|
172
|
+
if ( boundariesChanged ) {
|
|
173
|
+
// If range boundaries have changed, fire `change:range` event.
|
|
174
|
+
//
|
|
175
|
+
if ( result.root.rootName == '$graveyard' ) {
|
|
176
|
+
// If the range was moved to the graveyard root, set `deletionPosition`.
|
|
177
|
+
if ( operation.type == 'remove' ) {
|
|
178
|
+
deletionPosition = operation.sourcePosition;
|
|
179
|
+
} else {
|
|
180
|
+
// Merge operation.
|
|
181
|
+
deletionPosition = operation.deletionPosition;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const oldRange = this.toRange();
|
|
186
|
+
|
|
187
|
+
this.start = result.start;
|
|
188
|
+
this.end = result.end;
|
|
189
|
+
|
|
190
|
+
this.fire( 'change:range', oldRange, { deletionPosition } );
|
|
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
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Checks whether given operation changes something inside the range (even if it does not change boundaries).
|
|
198
|
+
//
|
|
199
|
+
// @private
|
|
200
|
+
// @param {module:engine/model/range~Range} range Range to check.
|
|
201
|
+
// @param {module:engine/model/operation/operation~Operation} operation Executed operation.
|
|
202
|
+
// @returns {Boolean}
|
|
203
|
+
function doesOperationChangeRangeContent( range, operation ) {
|
|
204
|
+
switch ( operation.type ) {
|
|
205
|
+
case 'insert':
|
|
206
|
+
return range.containsPosition( operation.position );
|
|
207
|
+
case 'move':
|
|
208
|
+
case 'remove':
|
|
209
|
+
case 'reinsert':
|
|
210
|
+
case 'merge':
|
|
211
|
+
return range.containsPosition( operation.sourcePosition ) ||
|
|
212
|
+
range.start.isEqual( operation.sourcePosition ) ||
|
|
213
|
+
range.containsPosition( operation.targetPosition );
|
|
214
|
+
case 'split':
|
|
215
|
+
return range.containsPosition( operation.splitPosition ) || range.containsPosition( operation.insertionPosition );
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
mix( LiveRange, EmitterMixin );
|