@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,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
- * 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
- */
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
- 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
- );
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( 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
- }
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 );
@@ -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
- * 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
- */
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
- 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
- );
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( 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
- }
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( 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;
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 );