@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
package/src/view/node.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
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/view/node
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
11
|
+
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
|
|
12
|
+
import mix from '@ckeditor/ckeditor5-utils/src/mix';
|
|
13
|
+
import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
|
|
14
|
+
import { clone } from 'lodash-es';
|
|
15
|
+
|
|
16
|
+
// To check if component is loaded more than once.
|
|
17
|
+
import '@ckeditor/ckeditor5-utils/src/version';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Abstract view node class.
|
|
21
|
+
*
|
|
22
|
+
* This is an abstract class. Its constructor should not be used directly.
|
|
23
|
+
* Use the {@link module:engine/view/downcastwriter~DowncastWriter} or {@link module:engine/view/upcastwriter~UpcastWriter}
|
|
24
|
+
* to create new instances of view nodes.
|
|
25
|
+
*
|
|
26
|
+
* @abstract
|
|
27
|
+
*/
|
|
28
|
+
export default class Node {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a tree view node.
|
|
31
|
+
*
|
|
32
|
+
* @protected
|
|
33
|
+
* @param {module:engine/view/document~Document} document The document instance to which this node belongs.
|
|
34
|
+
*/
|
|
35
|
+
constructor( document ) {
|
|
36
|
+
/**
|
|
37
|
+
* The document instance to which this node belongs.
|
|
38
|
+
*
|
|
39
|
+
* @readonly
|
|
40
|
+
* @member {module:engine/view/document~Document}
|
|
41
|
+
*/
|
|
42
|
+
this.document = document;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Parent element. Null by default. Set by {@link module:engine/view/element~Element#_insertChild}.
|
|
46
|
+
*
|
|
47
|
+
* @readonly
|
|
48
|
+
* @member {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
|
|
49
|
+
*/
|
|
50
|
+
this.parent = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Index of the node in the parent element or null if the node has no parent.
|
|
55
|
+
*
|
|
56
|
+
* Accessing this property throws an error if this node's parent element does not contain it.
|
|
57
|
+
* This means that view tree got broken.
|
|
58
|
+
*
|
|
59
|
+
* @readonly
|
|
60
|
+
* @type {Number|null}
|
|
61
|
+
*/
|
|
62
|
+
get index() {
|
|
63
|
+
let pos;
|
|
64
|
+
|
|
65
|
+
if ( !this.parent ) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// No parent or child doesn't exist in parent's children.
|
|
70
|
+
if ( ( pos = this.parent.getChildIndex( this ) ) == -1 ) {
|
|
71
|
+
/**
|
|
72
|
+
* The node's parent does not contain this node. It means that the document tree is corrupted.
|
|
73
|
+
*
|
|
74
|
+
* @error view-node-not-found-in-parent
|
|
75
|
+
*/
|
|
76
|
+
throw new CKEditorError( 'view-node-not-found-in-parent', this );
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return pos;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Node's next sibling, or `null` if it is the last child.
|
|
84
|
+
*
|
|
85
|
+
* @readonly
|
|
86
|
+
* @type {module:engine/view/node~Node|null}
|
|
87
|
+
*/
|
|
88
|
+
get nextSibling() {
|
|
89
|
+
const index = this.index;
|
|
90
|
+
|
|
91
|
+
return ( index !== null && this.parent.getChild( index + 1 ) ) || null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Node's previous sibling, or `null` if it is the first child.
|
|
96
|
+
*
|
|
97
|
+
* @readonly
|
|
98
|
+
* @type {module:engine/view/node~Node|null}
|
|
99
|
+
*/
|
|
100
|
+
get previousSibling() {
|
|
101
|
+
const index = this.index;
|
|
102
|
+
|
|
103
|
+
return ( index !== null && this.parent.getChild( index - 1 ) ) || null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Top-most ancestor of the node. If the node has no parent it is the root itself.
|
|
108
|
+
*
|
|
109
|
+
* @readonly
|
|
110
|
+
* @type {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
|
|
111
|
+
*/
|
|
112
|
+
get root() {
|
|
113
|
+
let root = this; // eslint-disable-line consistent-this
|
|
114
|
+
|
|
115
|
+
while ( root.parent ) {
|
|
116
|
+
root = root.parent;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return root;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
|
|
124
|
+
*
|
|
125
|
+
* @returns {Boolean}
|
|
126
|
+
*/
|
|
127
|
+
isAttached() {
|
|
128
|
+
return this.root.is( 'rootElement' );
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node,
|
|
133
|
+
* beginning from {@link module:engine/view/node~Node#root root}, down to this node's index.
|
|
134
|
+
*
|
|
135
|
+
* const abc = downcastWriter.createText( 'abc' );
|
|
136
|
+
* const foo = downcastWriter.createText( 'foo' );
|
|
137
|
+
* const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
|
|
138
|
+
* const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
|
|
139
|
+
* const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
|
|
140
|
+
* foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
|
|
141
|
+
* h1.getPath(); // Returns [ 0 ].
|
|
142
|
+
* div.getPath(); // Returns [].
|
|
143
|
+
*
|
|
144
|
+
* @returns {Array.<Number>} The path.
|
|
145
|
+
*/
|
|
146
|
+
getPath() {
|
|
147
|
+
const path = [];
|
|
148
|
+
let node = this; // eslint-disable-line consistent-this
|
|
149
|
+
|
|
150
|
+
while ( node.parent ) {
|
|
151
|
+
path.unshift( node.index );
|
|
152
|
+
node = node.parent;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return path;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns ancestors array of this node.
|
|
160
|
+
*
|
|
161
|
+
* @param {Object} options Options object.
|
|
162
|
+
* @param {Boolean} [options.includeSelf=false] When set to `true` this node will be also included in parent's array.
|
|
163
|
+
* @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from node's parent to root element,
|
|
164
|
+
* otherwise root element will be the first item in the array.
|
|
165
|
+
* @returns {Array} Array with ancestors.
|
|
166
|
+
*/
|
|
167
|
+
getAncestors( options = { includeSelf: false, parentFirst: false } ) {
|
|
168
|
+
const ancestors = [];
|
|
169
|
+
let parent = options.includeSelf ? this : this.parent;
|
|
170
|
+
|
|
171
|
+
while ( parent ) {
|
|
172
|
+
ancestors[ options.parentFirst ? 'push' : 'unshift' ]( parent );
|
|
173
|
+
parent = parent.parent;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return ancestors;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Returns a {@link module:engine/view/element~Element} or {@link module:engine/view/documentfragment~DocumentFragment}
|
|
181
|
+
* which is a common ancestor of both nodes.
|
|
182
|
+
*
|
|
183
|
+
* @param {module:engine/view/node~Node} node The second node.
|
|
184
|
+
* @param {Object} options Options object.
|
|
185
|
+
* @param {Boolean} [options.includeSelf=false] When set to `true` both nodes will be considered "ancestors" too.
|
|
186
|
+
* Which means that if e.g. node A is inside B, then their common ancestor will be B.
|
|
187
|
+
* @returns {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
|
|
188
|
+
*/
|
|
189
|
+
getCommonAncestor( node, options = {} ) {
|
|
190
|
+
const ancestorsA = this.getAncestors( options );
|
|
191
|
+
const ancestorsB = node.getAncestors( options );
|
|
192
|
+
|
|
193
|
+
let i = 0;
|
|
194
|
+
|
|
195
|
+
while ( ancestorsA[ i ] == ancestorsB[ i ] && ancestorsA[ i ] ) {
|
|
196
|
+
i++;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return i === 0 ? null : ancestorsA[ i - 1 ];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
|
|
204
|
+
* in different {@link module:engine/view/documentfragment~DocumentFragment}s).
|
|
205
|
+
*
|
|
206
|
+
* @param {module:engine/view/node~Node} node Node to compare with.
|
|
207
|
+
* @returns {Boolean}
|
|
208
|
+
*/
|
|
209
|
+
isBefore( node ) {
|
|
210
|
+
// Given node is not before this node if they are same.
|
|
211
|
+
if ( this == node ) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Return `false` if it is impossible to compare nodes.
|
|
216
|
+
if ( this.root !== node.root ) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const thisPath = this.getPath();
|
|
221
|
+
const nodePath = node.getPath();
|
|
222
|
+
|
|
223
|
+
const result = compareArrays( thisPath, nodePath );
|
|
224
|
+
|
|
225
|
+
switch ( result ) {
|
|
226
|
+
case 'prefix':
|
|
227
|
+
return true;
|
|
228
|
+
|
|
229
|
+
case 'extension':
|
|
230
|
+
return false;
|
|
231
|
+
|
|
232
|
+
default:
|
|
233
|
+
return thisPath[ result ] < nodePath[ result ];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
|
|
239
|
+
* in different {@link module:engine/view/documentfragment~DocumentFragment}s).
|
|
240
|
+
*
|
|
241
|
+
* @param {module:engine/view/node~Node} node Node to compare with.
|
|
242
|
+
* @returns {Boolean}
|
|
243
|
+
*/
|
|
244
|
+
isAfter( node ) {
|
|
245
|
+
// Given node is not before this node if they are same.
|
|
246
|
+
if ( this == node ) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Return `false` if it is impossible to compare nodes.
|
|
251
|
+
if ( this.root !== node.root ) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// In other cases, just check if the `node` is before, and return the opposite.
|
|
256
|
+
return !this.isBefore( node );
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Removes node from parent.
|
|
261
|
+
*
|
|
262
|
+
* @protected
|
|
263
|
+
*/
|
|
264
|
+
_remove() {
|
|
265
|
+
this.parent._removeChildren( this.index );
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @protected
|
|
270
|
+
* @param {module:engine/view/document~ChangeType} type Type of the change.
|
|
271
|
+
* @param {module:engine/view/node~Node} node Changed node.
|
|
272
|
+
* @fires change
|
|
273
|
+
*/
|
|
274
|
+
_fireChange( type, node ) {
|
|
275
|
+
this.fire( 'change:' + type, node );
|
|
276
|
+
|
|
277
|
+
if ( this.parent ) {
|
|
278
|
+
this.parent._fireChange( type, node );
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Custom toJSON method to solve child-parent circular dependencies.
|
|
284
|
+
*
|
|
285
|
+
* @returns {Object} Clone of this object with the parent property removed.
|
|
286
|
+
*/
|
|
287
|
+
toJSON() {
|
|
288
|
+
const json = clone( this );
|
|
289
|
+
|
|
290
|
+
// Due to circular references we need to remove parent reference.
|
|
291
|
+
delete json.parent;
|
|
292
|
+
|
|
293
|
+
return json;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Checks whether this object is of the given type.
|
|
298
|
+
*
|
|
299
|
+
* This method is useful when processing view objects that are of unknown type. For example, a function
|
|
300
|
+
* may return a {@link module:engine/view/documentfragment~DocumentFragment} or a {@link module:engine/view/node~Node}
|
|
301
|
+
* that can be either a text node or an element. This method can be used to check what kind of object is returned.
|
|
302
|
+
*
|
|
303
|
+
* someObject.is( 'element' ); // -> true if this is an element
|
|
304
|
+
* someObject.is( 'node' ); // -> true if this is a node (a text node or an element)
|
|
305
|
+
* someObject.is( 'documentFragment' ); // -> true if this is a document fragment
|
|
306
|
+
*
|
|
307
|
+
* Since this method is also available on a range of model objects, you can prefix the type of the object with
|
|
308
|
+
* `model:` or `view:` to check, for example, if this is the model's or view's element:
|
|
309
|
+
*
|
|
310
|
+
* viewElement.is( 'view:element' ); // -> true
|
|
311
|
+
* viewElement.is( 'model:element' ); // -> false
|
|
312
|
+
*
|
|
313
|
+
* By using this method it is also possible to check a name of an element:
|
|
314
|
+
*
|
|
315
|
+
* imgElement.is( 'element', 'img' ); // -> true
|
|
316
|
+
* imgElement.is( 'view:element', 'img' ); // -> same as above, but more precise
|
|
317
|
+
*
|
|
318
|
+
* The list of view objects which implement the `is()` method:
|
|
319
|
+
*
|
|
320
|
+
* * {@link module:engine/view/attributeelement~AttributeElement#is `AttributeElement#is()`}
|
|
321
|
+
* * {@link module:engine/view/containerelement~ContainerElement#is `ContainerElement#is()`}
|
|
322
|
+
* * {@link module:engine/view/documentfragment~DocumentFragment#is `DocumentFragment#is()`}
|
|
323
|
+
* * {@link module:engine/view/documentselection~DocumentSelection#is `DocumentSelection#is()`}
|
|
324
|
+
* * {@link module:engine/view/editableelement~EditableElement#is `EditableElement#is()`}
|
|
325
|
+
* * {@link module:engine/view/element~Element#is `Element#is()`}
|
|
326
|
+
* * {@link module:engine/view/emptyelement~EmptyElement#is `EmptyElement#is()`}
|
|
327
|
+
* * {@link module:engine/view/node~Node#is `Node#is()`}
|
|
328
|
+
* * {@link module:engine/view/position~Position#is `Position#is()`}
|
|
329
|
+
* * {@link module:engine/view/range~Range#is `Range#is()`}
|
|
330
|
+
* * {@link module:engine/view/rooteditableelement~RootEditableElement#is `RootEditableElement#is()`}
|
|
331
|
+
* * {@link module:engine/view/selection~Selection#is `Selection#is()`}
|
|
332
|
+
* * {@link module:engine/view/text~Text#is `Text#is()`}
|
|
333
|
+
* * {@link module:engine/view/textproxy~TextProxy#is `TextProxy#is()`}
|
|
334
|
+
* * {@link module:engine/view/uielement~UIElement#is `UIElement#is()`}
|
|
335
|
+
*
|
|
336
|
+
* @method #is
|
|
337
|
+
* @param {String} type Type to check.
|
|
338
|
+
* @returns {Boolean}
|
|
339
|
+
*/
|
|
340
|
+
is( type ) {
|
|
341
|
+
return type === 'node' || type === 'view:node';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Clones this node.
|
|
346
|
+
*
|
|
347
|
+
* @protected
|
|
348
|
+
* @method #_clone
|
|
349
|
+
* @returns {module:engine/view/node~Node} Clone of this node.
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Checks if provided node is similar to this node.
|
|
354
|
+
*
|
|
355
|
+
* @method #isSimilar
|
|
356
|
+
* @returns {Boolean} True if nodes are similar.
|
|
357
|
+
*/
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Fired when list of {@link module:engine/view/element~Element elements} children changes.
|
|
362
|
+
*
|
|
363
|
+
* Change event is bubbled – it is fired on all ancestors.
|
|
364
|
+
*
|
|
365
|
+
* @event change:children
|
|
366
|
+
* @param {module:engine/view/node~Node} changedNode
|
|
367
|
+
*/
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Fired when list of {@link module:engine/view/element~Element elements} attributes changes.
|
|
371
|
+
*
|
|
372
|
+
* Change event is bubbled – it is fired on all ancestors.
|
|
373
|
+
*
|
|
374
|
+
* @event change:attributes
|
|
375
|
+
* @param {module:engine/view/node~Node} changedNode
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Fired when {@link module:engine/view/text~Text text nodes} data changes.
|
|
380
|
+
*
|
|
381
|
+
* Change event is bubbled – it is fired on all ancestors.
|
|
382
|
+
*
|
|
383
|
+
* @event change:text
|
|
384
|
+
* @param {module:engine/view/node~Node} changedNode
|
|
385
|
+
*/
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @event change
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
mix( Node, EmitterMixin );
|
|
@@ -0,0 +1,58 @@
|
|
|
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/view/observer/arrowkeysobserver
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Observer from './observer';
|
|
11
|
+
import BubblingEventInfo from './bubblingeventinfo';
|
|
12
|
+
|
|
13
|
+
import { isArrowKeyCode } from '@ckeditor/ckeditor5-utils';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Arrow keys observer introduces the {@link module:engine/view/document~Document#event:arrowKey `Document#arrowKey`} event.
|
|
17
|
+
*
|
|
18
|
+
* Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
|
|
19
|
+
*
|
|
20
|
+
* @extends module:engine/view/observer/observer~Observer
|
|
21
|
+
*/
|
|
22
|
+
export default class ArrowKeysObserver extends Observer {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
constructor( view ) {
|
|
27
|
+
super( view );
|
|
28
|
+
|
|
29
|
+
this.document.on( 'keydown', ( event, data ) => {
|
|
30
|
+
if ( this.isEnabled && isArrowKeyCode( data.keyCode ) ) {
|
|
31
|
+
const eventInfo = new BubblingEventInfo( this.document, 'arrowKey', this.document.selection.getFirstRange() );
|
|
32
|
+
|
|
33
|
+
this.document.fire( eventInfo, data );
|
|
34
|
+
|
|
35
|
+
if ( eventInfo.stop.called ) {
|
|
36
|
+
event.stop();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} );
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @inheritDoc
|
|
44
|
+
*/
|
|
45
|
+
observe() {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Event fired when the user presses an arrow keys.
|
|
50
|
+
*
|
|
51
|
+
* Introduced by {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver}.
|
|
52
|
+
*
|
|
53
|
+
* Note that because {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver} is attached by the
|
|
54
|
+
* {@link module:engine/view/view~View} this event is available by default.
|
|
55
|
+
*
|
|
56
|
+
* @event module:engine/view/document~Document#event:arrowKey
|
|
57
|
+
* @param {module:engine/view/observer/domeventdata~DomEventData} data
|
|
58
|
+
*/
|