@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.
Files changed (117) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +30 -0
  3. package/package.json +70 -0
  4. package/src/controller/datacontroller.js +563 -0
  5. package/src/controller/editingcontroller.js +149 -0
  6. package/src/conversion/conversion.js +644 -0
  7. package/src/conversion/conversionhelpers.js +40 -0
  8. package/src/conversion/downcastdispatcher.js +914 -0
  9. package/src/conversion/downcasthelpers.js +1706 -0
  10. package/src/conversion/mapper.js +696 -0
  11. package/src/conversion/modelconsumable.js +329 -0
  12. package/src/conversion/upcastdispatcher.js +807 -0
  13. package/src/conversion/upcasthelpers.js +997 -0
  14. package/src/conversion/viewconsumable.js +623 -0
  15. package/src/dataprocessor/basichtmlwriter.js +32 -0
  16. package/src/dataprocessor/dataprocessor.jsdoc +64 -0
  17. package/src/dataprocessor/htmldataprocessor.js +159 -0
  18. package/src/dataprocessor/htmlwriter.js +22 -0
  19. package/src/dataprocessor/xmldataprocessor.js +161 -0
  20. package/src/dev-utils/model.js +482 -0
  21. package/src/dev-utils/operationreplayer.js +140 -0
  22. package/src/dev-utils/utils.js +103 -0
  23. package/src/dev-utils/view.js +1091 -0
  24. package/src/index.js +52 -0
  25. package/src/model/batch.js +82 -0
  26. package/src/model/differ.js +1282 -0
  27. package/src/model/document.js +483 -0
  28. package/src/model/documentfragment.js +390 -0
  29. package/src/model/documentselection.js +1261 -0
  30. package/src/model/element.js +438 -0
  31. package/src/model/history.js +138 -0
  32. package/src/model/item.jsdoc +14 -0
  33. package/src/model/liveposition.js +182 -0
  34. package/src/model/liverange.js +221 -0
  35. package/src/model/markercollection.js +553 -0
  36. package/src/model/model.js +934 -0
  37. package/src/model/node.js +507 -0
  38. package/src/model/nodelist.js +217 -0
  39. package/src/model/operation/attributeoperation.js +202 -0
  40. package/src/model/operation/detachoperation.js +103 -0
  41. package/src/model/operation/insertoperation.js +188 -0
  42. package/src/model/operation/markeroperation.js +154 -0
  43. package/src/model/operation/mergeoperation.js +216 -0
  44. package/src/model/operation/moveoperation.js +209 -0
  45. package/src/model/operation/nooperation.js +58 -0
  46. package/src/model/operation/operation.js +139 -0
  47. package/src/model/operation/operationfactory.js +49 -0
  48. package/src/model/operation/renameoperation.js +155 -0
  49. package/src/model/operation/rootattributeoperation.js +211 -0
  50. package/src/model/operation/splitoperation.js +254 -0
  51. package/src/model/operation/transform.js +2389 -0
  52. package/src/model/operation/utils.js +292 -0
  53. package/src/model/position.js +1164 -0
  54. package/src/model/range.js +1049 -0
  55. package/src/model/rootelement.js +111 -0
  56. package/src/model/schema.js +1851 -0
  57. package/src/model/selection.js +902 -0
  58. package/src/model/text.js +138 -0
  59. package/src/model/textproxy.js +279 -0
  60. package/src/model/treewalker.js +414 -0
  61. package/src/model/utils/autoparagraphing.js +77 -0
  62. package/src/model/utils/deletecontent.js +528 -0
  63. package/src/model/utils/getselectedcontent.js +150 -0
  64. package/src/model/utils/insertcontent.js +824 -0
  65. package/src/model/utils/modifyselection.js +229 -0
  66. package/src/model/utils/selection-post-fixer.js +297 -0
  67. package/src/model/writer.js +1574 -0
  68. package/src/view/attributeelement.js +274 -0
  69. package/src/view/containerelement.js +123 -0
  70. package/src/view/document.js +221 -0
  71. package/src/view/documentfragment.js +273 -0
  72. package/src/view/documentselection.js +387 -0
  73. package/src/view/domconverter.js +1437 -0
  74. package/src/view/downcastwriter.js +2121 -0
  75. package/src/view/editableelement.js +118 -0
  76. package/src/view/element.js +945 -0
  77. package/src/view/elementdefinition.jsdoc +59 -0
  78. package/src/view/emptyelement.js +119 -0
  79. package/src/view/filler.js +161 -0
  80. package/src/view/item.jsdoc +14 -0
  81. package/src/view/matcher.js +776 -0
  82. package/src/view/node.js +391 -0
  83. package/src/view/observer/arrowkeysobserver.js +58 -0
  84. package/src/view/observer/bubblingemittermixin.js +307 -0
  85. package/src/view/observer/bubblingeventinfo.js +71 -0
  86. package/src/view/observer/clickobserver.js +46 -0
  87. package/src/view/observer/compositionobserver.js +79 -0
  88. package/src/view/observer/domeventdata.js +82 -0
  89. package/src/view/observer/domeventobserver.js +99 -0
  90. package/src/view/observer/fakeselectionobserver.js +118 -0
  91. package/src/view/observer/focusobserver.js +106 -0
  92. package/src/view/observer/inputobserver.js +44 -0
  93. package/src/view/observer/keyobserver.js +83 -0
  94. package/src/view/observer/mouseobserver.js +56 -0
  95. package/src/view/observer/mutationobserver.js +345 -0
  96. package/src/view/observer/observer.js +118 -0
  97. package/src/view/observer/selectionobserver.js +242 -0
  98. package/src/view/placeholder.js +285 -0
  99. package/src/view/position.js +426 -0
  100. package/src/view/range.js +533 -0
  101. package/src/view/rawelement.js +148 -0
  102. package/src/view/renderer.js +1037 -0
  103. package/src/view/rooteditableelement.js +107 -0
  104. package/src/view/selection.js +718 -0
  105. package/src/view/styles/background.js +73 -0
  106. package/src/view/styles/border.js +362 -0
  107. package/src/view/styles/margin.js +41 -0
  108. package/src/view/styles/padding.js +40 -0
  109. package/src/view/styles/utils.js +277 -0
  110. package/src/view/stylesmap.js +938 -0
  111. package/src/view/text.js +147 -0
  112. package/src/view/textproxy.js +199 -0
  113. package/src/view/treewalker.js +496 -0
  114. package/src/view/uielement.js +238 -0
  115. package/src/view/upcastwriter.js +484 -0
  116. package/src/view/view.js +721 -0
  117. package/theme/placeholder.css +27 -0
@@ -0,0 +1,483 @@
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/document
8
+ */
9
+
10
+ import Differ from './differ';
11
+ import RootElement from './rootelement';
12
+ import History from './history';
13
+ import DocumentSelection from './documentselection';
14
+ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
15
+ import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
16
+ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
17
+ import mix from '@ckeditor/ckeditor5-utils/src/mix';
18
+ import { isInsideSurrogatePair, isInsideCombinedSymbol } from '@ckeditor/ckeditor5-utils/src/unicode';
19
+ import { clone } from 'lodash-es';
20
+
21
+ // @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );
22
+
23
+ const graveyardName = '$graveyard';
24
+
25
+ /**
26
+ * Data model's document. It contains the model's structure, its selection and the history of changes.
27
+ *
28
+ * Read more about working with the model in
29
+ * {@glink framework/guides/architecture/editing-engine#model introduction to the the editing engine's architecture}.
30
+ *
31
+ * Usually, the document contains just one {@link module:engine/model/document~Document#roots root element}, so
32
+ * you can retrieve it by just calling {@link module:engine/model/document~Document#getRoot} without specifying its name:
33
+ *
34
+ * model.document.getRoot(); // -> returns the main root
35
+ *
36
+ * However, the document may contain multiple roots – e.g. when the editor has multiple editable areas
37
+ * (e.g. a title and a body of a message).
38
+ *
39
+ * @mixes module:utils/emittermixin~EmitterMixin
40
+ */
41
+ export default class Document {
42
+ /**
43
+ * Creates an empty document instance with no {@link #roots} (other than
44
+ * the {@link #graveyard graveyard root}).
45
+ */
46
+ constructor( model ) {
47
+ /**
48
+ * The {@link module:engine/model/model~Model model} that the document is a part of.
49
+ *
50
+ * @readonly
51
+ * @type {module:engine/model/model~Model}
52
+ */
53
+ this.model = model;
54
+
55
+ /**
56
+ * The document version. It starts from `0` and every operation increases the version number. It is used to ensure that
57
+ * operations are applied on a proper document version.
58
+ *
59
+ * If the {@link module:engine/model/operation/operation~Operation#baseVersion base version} does not match the document version,
60
+ * a {@link module:utils/ckeditorerror~CKEditorError model-document-applyoperation-wrong-version} error is thrown.
61
+ *
62
+ * @type {Number}
63
+ */
64
+ this.version = 0;
65
+
66
+ /**
67
+ * The document's history.
68
+ *
69
+ * @readonly
70
+ * @type {module:engine/model/history~History}
71
+ */
72
+ this.history = new History( this );
73
+
74
+ /**
75
+ * The selection in this document.
76
+ *
77
+ * @readonly
78
+ * @type {module:engine/model/documentselection~DocumentSelection}
79
+ */
80
+ this.selection = new DocumentSelection( this );
81
+
82
+ /**
83
+ * A list of roots that are owned and managed by this document. Use {@link #createRoot} and
84
+ * {@link #getRoot} to manipulate it.
85
+ *
86
+ * @readonly
87
+ * @type {module:utils/collection~Collection}
88
+ */
89
+ this.roots = new Collection( { idProperty: 'rootName' } );
90
+
91
+ /**
92
+ * The model differ object. Its role is to buffer changes done on the model document and then calculate a diff of those changes.
93
+ *
94
+ * @readonly
95
+ * @type {module:engine/model/differ~Differ}
96
+ */
97
+ this.differ = new Differ( model.markers );
98
+
99
+ /**
100
+ * Post-fixer callbacks registered to the model document.
101
+ *
102
+ * @private
103
+ * @type {Set.<Function>}
104
+ */
105
+ this._postFixers = new Set();
106
+
107
+ /**
108
+ * A boolean indicates whether the selection has changed until
109
+ *
110
+ * @private
111
+ * @type {Boolean}
112
+ */
113
+ this._hasSelectionChangedFromTheLastChangeBlock = false;
114
+
115
+ // Graveyard tree root. Document always have a graveyard root, which stores removed nodes.
116
+ this.createRoot( '$root', graveyardName );
117
+
118
+ // First, if the operation is a document operation check if it's base version is correct.
119
+ this.listenTo( model, 'applyOperation', ( evt, args ) => {
120
+ const operation = args[ 0 ];
121
+
122
+ if ( operation.isDocumentOperation && operation.baseVersion !== this.version ) {
123
+ /**
124
+ * Only operations with matching versions can be applied.
125
+ *
126
+ * @error model-document-applyoperation-wrong-version
127
+ * @param {module:engine/model/operation/operation~Operation} operation
128
+ */
129
+ throw new CKEditorError( 'model-document-applyoperation-wrong-version', this, { operation } );
130
+ }
131
+ }, { priority: 'highest' } );
132
+
133
+ // Then, still before an operation is applied on model, buffer the change in differ.
134
+ this.listenTo( model, 'applyOperation', ( evt, args ) => {
135
+ const operation = args[ 0 ];
136
+
137
+ if ( operation.isDocumentOperation ) {
138
+ this.differ.bufferOperation( operation );
139
+ }
140
+ }, { priority: 'high' } );
141
+
142
+ // After the operation is applied, bump document's version and add the operation to the history.
143
+ this.listenTo( model, 'applyOperation', ( evt, args ) => {
144
+ const operation = args[ 0 ];
145
+
146
+ if ( operation.isDocumentOperation ) {
147
+ this.version++;
148
+ this.history.addOperation( operation );
149
+ }
150
+ }, { priority: 'low' } );
151
+
152
+ // Listen to selection changes. If selection changed, mark it.
153
+ this.listenTo( this.selection, 'change', () => {
154
+ this._hasSelectionChangedFromTheLastChangeBlock = true;
155
+ } );
156
+
157
+ // Buffer marker changes.
158
+ // This is not covered in buffering operations because markers may change outside of them (when they
159
+ // are modified using `model.markers` collection, not through `MarkerOperation`).
160
+ this.listenTo( model.markers, 'update', ( evt, marker, oldRange, newRange ) => {
161
+ // Whenever marker is updated, buffer that change.
162
+ this.differ.bufferMarkerChange( marker.name, oldRange, newRange, marker.affectsData );
163
+
164
+ if ( oldRange === null ) {
165
+ // If this is a new marker, add a listener that will buffer change whenever marker changes.
166
+ marker.on( 'change', ( evt, oldRange ) => {
167
+ this.differ.bufferMarkerChange( marker.name, oldRange, marker.getRange(), marker.affectsData );
168
+ } );
169
+ }
170
+ } );
171
+ }
172
+
173
+ /**
174
+ * The graveyard tree root. A document always has a graveyard root that stores removed nodes.
175
+ *
176
+ * @readonly
177
+ * @member {module:engine/model/rootelement~RootElement}
178
+ */
179
+ get graveyard() {
180
+ return this.getRoot( graveyardName );
181
+ }
182
+
183
+ /**
184
+ * Creates a new root.
185
+ *
186
+ * @param {String} [elementName='$root'] The element name. Defaults to `'$root'` which also has some basic schema defined
187
+ * (`$block`s are allowed inside the `$root`). Make sure to define a proper schema if you use a different name.
188
+ * @param {String} [rootName='main'] A unique root name.
189
+ * @returns {module:engine/model/rootelement~RootElement} The created root.
190
+ */
191
+ createRoot( elementName = '$root', rootName = 'main' ) {
192
+ if ( this.roots.get( rootName ) ) {
193
+ /**
194
+ * A root with the specified name already exists.
195
+ *
196
+ * @error model-document-createroot-name-exists
197
+ * @param {module:engine/model/document~Document} doc
198
+ * @param {String} name
199
+ */
200
+ throw new CKEditorError( 'model-document-createroot-name-exists', this, { name: rootName } );
201
+ }
202
+
203
+ const root = new RootElement( this, elementName, rootName );
204
+ this.roots.add( root );
205
+
206
+ return root;
207
+ }
208
+
209
+ /**
210
+ * Removes all event listeners set by the document instance.
211
+ */
212
+ destroy() {
213
+ this.selection.destroy();
214
+ this.stopListening();
215
+ }
216
+
217
+ /**
218
+ * Returns a root by its name.
219
+ *
220
+ * @param {String} [name='main'] A unique root name.
221
+ * @returns {module:engine/model/rootelement~RootElement|null} The root registered under a given name or `null` when
222
+ * there is no root with the given name.
223
+ */
224
+ getRoot( name = 'main' ) {
225
+ return this.roots.get( name );
226
+ }
227
+
228
+ /**
229
+ * Returns an array with names of all roots (without the {@link #graveyard}) added to the document.
230
+ *
231
+ * @returns {Array.<String>} Roots names.
232
+ */
233
+ getRootNames() {
234
+ return Array.from( this.roots, root => root.rootName ).filter( name => name != graveyardName );
235
+ }
236
+
237
+ /**
238
+ * Used to register a post-fixer callback. A post-fixer mechanism guarantees that the features
239
+ * will operate on a correct model state.
240
+ *
241
+ * An execution of a feature may lead to an incorrect document tree state. The callbacks are used to fix the document tree after
242
+ * it has changed. Post-fixers are fired just after all changes from the outermost change block were applied but
243
+ * before the {@link module:engine/model/document~Document#event:change change event} is fired. If a post-fixer callback made
244
+ * a change, it should return `true`. When this happens, all post-fixers are fired again to check if something else should
245
+ * not be fixed in the new document tree state.
246
+ *
247
+ * As a parameter, a post-fixer callback receives a {@link module:engine/model/writer~Writer writer} instance connected with the
248
+ * executed changes block. Thanks to that, all changes done by the callback will be added to the same
249
+ * {@link module:engine/model/batch~Batch batch} (and undo step) as the original changes. This makes post-fixer changes transparent
250
+ * for the user.
251
+ *
252
+ * An example of a post-fixer is a callback that checks if all the data were removed from the editor. If so, the
253
+ * callback should add an empty paragraph so that the editor is never empty:
254
+ *
255
+ * document.registerPostFixer( writer => {
256
+ * const changes = document.differ.getChanges();
257
+ *
258
+ * // Check if the changes lead to an empty root in the editor.
259
+ * for ( const entry of changes ) {
260
+ * if ( entry.type == 'remove' && entry.position.root.isEmpty ) {
261
+ * writer.insertElement( 'paragraph', entry.position.root, 0 );
262
+ *
263
+ * // It is fine to return early, even if multiple roots would need to be fixed.
264
+ * // All post-fixers will be fired again, so if there are more empty roots, those will be fixed, too.
265
+ * return true;
266
+ * }
267
+ * }
268
+ * } );
269
+ *
270
+ * @param {Function} postFixer
271
+ */
272
+ registerPostFixer( postFixer ) {
273
+ this._postFixers.add( postFixer );
274
+ }
275
+
276
+ /**
277
+ * A custom `toJSON()` method to solve child-parent circular dependencies.
278
+ *
279
+ * @returns {Object} A clone of this object with the document property changed to a string.
280
+ */
281
+ toJSON() {
282
+ const json = clone( this );
283
+
284
+ // Due to circular references we need to remove parent reference.
285
+ json.selection = '[engine.model.DocumentSelection]';
286
+ json.model = '[engine.model.Model]';
287
+
288
+ return json;
289
+ }
290
+
291
+ /**
292
+ * Check if there were any changes done on document, and if so, call post-fixers,
293
+ * fire `change` event for features and conversion and then reset the differ.
294
+ * Fire `change:data` event when at least one operation or buffered marker changes the data.
295
+ *
296
+ * @protected
297
+ * @fires change
298
+ * @fires change:data
299
+ * @param {module:engine/model/writer~Writer} writer The writer on which post-fixers will be called.
300
+ */
301
+ _handleChangeBlock( writer ) {
302
+ if ( this._hasDocumentChangedFromTheLastChangeBlock() ) {
303
+ this._callPostFixers( writer );
304
+
305
+ // Refresh selection attributes according to the final position in the model after the change.
306
+ this.selection.refresh();
307
+
308
+ if ( this.differ.hasDataChanges() ) {
309
+ this.fire( 'change:data', writer.batch );
310
+ } else {
311
+ this.fire( 'change', writer.batch );
312
+ }
313
+
314
+ // Theoretically, it is not necessary to refresh selection after change event because
315
+ // post-fixers are the last who should change the model, but just in case...
316
+ this.selection.refresh();
317
+
318
+ this.differ.reset();
319
+ }
320
+
321
+ this._hasSelectionChangedFromTheLastChangeBlock = false;
322
+ }
323
+
324
+ /**
325
+ * Returns whether there is a buffered change or if the selection has changed from the last
326
+ * {@link module:engine/model/model~Model#enqueueChange `enqueueChange()` block}
327
+ * or {@link module:engine/model/model~Model#change `change()` block}.
328
+ *
329
+ * @protected
330
+ * @returns {Boolean} Returns `true` if document has changed from the last `change()` or `enqueueChange()` block.
331
+ */
332
+ _hasDocumentChangedFromTheLastChangeBlock() {
333
+ return !this.differ.isEmpty || this._hasSelectionChangedFromTheLastChangeBlock;
334
+ }
335
+
336
+ /**
337
+ * Returns the default root for this document which is either the first root that was added to the document using
338
+ * {@link #createRoot} or the {@link #graveyard graveyard root} if no other roots were created.
339
+ *
340
+ * @protected
341
+ * @returns {module:engine/model/rootelement~RootElement} The default root for this document.
342
+ */
343
+ _getDefaultRoot() {
344
+ for ( const root of this.roots ) {
345
+ if ( root !== this.graveyard ) {
346
+ return root;
347
+ }
348
+ }
349
+
350
+ return this.graveyard;
351
+ }
352
+
353
+ /**
354
+ * Returns the default range for this selection. The default range is a collapsed range that starts and ends
355
+ * at the beginning of this selection's document {@link #_getDefaultRoot default root}.
356
+ *
357
+ * @protected
358
+ * @returns {module:engine/model/range~Range}
359
+ */
360
+ _getDefaultRange() {
361
+ const defaultRoot = this._getDefaultRoot();
362
+ const model = this.model;
363
+ const schema = model.schema;
364
+
365
+ // Find the first position where the selection can be put.
366
+ const position = model.createPositionFromPath( defaultRoot, [ 0 ] );
367
+ const nearestRange = schema.getNearestSelectionRange( position );
368
+
369
+ // If valid selection range is not found - return range collapsed at the beginning of the root.
370
+ return nearestRange || model.createRange( position );
371
+ }
372
+
373
+ /**
374
+ * Checks whether a given {@link module:engine/model/range~Range range} is a valid range for
375
+ * the {@link #selection document's selection}.
376
+ *
377
+ * @private
378
+ * @param {module:engine/model/range~Range} range A range to check.
379
+ * @returns {Boolean} `true` if `range` is valid, `false` otherwise.
380
+ */
381
+ _validateSelectionRange( range ) {
382
+ return validateTextNodePosition( range.start ) && validateTextNodePosition( range.end );
383
+ }
384
+
385
+ /**
386
+ * Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
387
+ *
388
+ * @private
389
+ * @param {module:engine/model/writer~Writer} writer The writer on which post-fixer callbacks will be called.
390
+ */
391
+ _callPostFixers( writer ) {
392
+ let wasFixed = false;
393
+
394
+ do {
395
+ for ( const callback of this._postFixers ) {
396
+ // Ensure selection attributes are up to date before each post-fixer.
397
+ // https://github.com/ckeditor/ckeditor5-engine/issues/1673.
398
+ //
399
+ // It might be good to refresh the selection after each operation but at the moment it leads
400
+ // to losing attributes for composition or and spell checking
401
+ // https://github.com/ckeditor/ckeditor5-typing/issues/188
402
+ this.selection.refresh();
403
+
404
+ wasFixed = callback( writer );
405
+
406
+ if ( wasFixed ) {
407
+ break;
408
+ }
409
+ }
410
+ } while ( wasFixed );
411
+ }
412
+
413
+ /**
414
+ * Fired after each {@link module:engine/model/model~Model#enqueueChange `enqueueChange()` block} or the outermost
415
+ * {@link module:engine/model/model~Model#change `change()` block} was executed and the document was changed
416
+ * during that block's execution.
417
+ *
418
+ * The changes which this event will cover include:
419
+ *
420
+ * * document structure changes,
421
+ * * selection changes,
422
+ * * marker changes.
423
+ *
424
+ * If you want to be notified about all these changes, then simply listen to this event like this:
425
+ *
426
+ * model.document.on( 'change', () => {
427
+ * console.log( 'The document has changed!' );
428
+ * } );
429
+ *
430
+ * If, however, you only want to be notified about the data changes, then use the
431
+ * {@link module:engine/model/document~Document#event:change:data change:data} event,
432
+ * which is fired for document structure changes and marker changes (which affects the data).
433
+ *
434
+ * model.document.on( 'change:data', () => {
435
+ * console.log( 'The data has changed!' );
436
+ * } );
437
+ *
438
+ * @event change
439
+ * @param {module:engine/model/batch~Batch} batch The batch that was used in the executed changes block.
440
+ */
441
+
442
+ /**
443
+ * It is a narrower version of the {@link #event:change} event. It is fired for changes which
444
+ * affect the editor data. This is:
445
+ *
446
+ * * document structure changes,
447
+ * * marker changes (which affects the data).
448
+ *
449
+ * If you want to be notified about the data changes, then listen to this event:
450
+ *
451
+ * model.document.on( 'change:data', () => {
452
+ * console.log( 'The data has changed!' );
453
+ * } );
454
+ *
455
+ * If you would like to listen to all document changes, then check out the
456
+ * {@link module:engine/model/document~Document#event:change change} event.
457
+ *
458
+ * @event change:data
459
+ * @param {module:engine/model/batch~Batch} batch The batch that was used in the executed changes block.
460
+ */
461
+
462
+ // @if CK_DEBUG_ENGINE // log( version = null ) {
463
+ // @if CK_DEBUG_ENGINE // version = version === null ? this.version : version;
464
+ // @if CK_DEBUG_ENGINE // logDocument( this, version );
465
+ // @if CK_DEBUG_ENGINE // }
466
+ }
467
+
468
+ mix( Document, EmitterMixin );
469
+
470
+ // Checks whether given range boundary position is valid for document selection, meaning that is not between
471
+ // unicode surrogate pairs or base character and combining marks.
472
+ function validateTextNodePosition( rangeBoundary ) {
473
+ const textNode = rangeBoundary.textNode;
474
+
475
+ if ( textNode ) {
476
+ const data = textNode.data;
477
+ const offset = rangeBoundary.offset - textNode.startOffset;
478
+
479
+ return !isInsideSurrogatePair( data, offset ) && !isInsideCombinedSymbol( data, offset );
480
+ }
481
+
482
+ return true;
483
+ }