@ckeditor/ckeditor5-engine 48.2.0 → 48.3.0-alpha.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 (129) hide show
  1. package/dist/controller/datacontroller.d.ts +329 -328
  2. package/dist/controller/editingcontroller.d.ts +95 -94
  3. package/dist/conversion/comparemarkers.d.ts +45 -45
  4. package/dist/conversion/conversion.d.ts +474 -474
  5. package/dist/conversion/conversionhelpers.d.ts +21 -21
  6. package/dist/conversion/downcastdispatcher.d.ts +539 -538
  7. package/dist/conversion/downcasthelpers.d.ts +1129 -1129
  8. package/dist/conversion/mapper.d.ts +692 -697
  9. package/dist/conversion/modelconsumable.d.ts +196 -196
  10. package/dist/conversion/upcastdispatcher.d.ts +483 -482
  11. package/dist/conversion/upcasthelpers.d.ts +491 -491
  12. package/dist/conversion/viewconsumable.d.ts +330 -330
  13. package/dist/dataprocessor/basichtmlwriter.d.ts +15 -15
  14. package/dist/dataprocessor/dataprocessor.d.ts +57 -57
  15. package/dist/dataprocessor/htmldataprocessor.d.ts +72 -72
  16. package/dist/dataprocessor/htmlwriter.d.ts +11 -11
  17. package/dist/dataprocessor/xmldataprocessor.d.ts +86 -86
  18. package/dist/dev-utils/model.d.ts +128 -123
  19. package/dist/dev-utils/operationreplayer.d.ts +49 -49
  20. package/dist/dev-utils/utils.d.ts +33 -33
  21. package/dist/dev-utils/view.d.ts +314 -309
  22. package/dist/engineconfig.d.ts +39 -39
  23. package/dist/index.css.map +1 -1
  24. package/dist/index.d.ts +150 -150
  25. package/dist/index.js +34026 -40107
  26. package/dist/index.js.map +1 -1
  27. package/dist/legacyerrors.d.ts +0 -4
  28. package/dist/model/batch.d.ts +86 -86
  29. package/dist/model/differ.d.ts +504 -504
  30. package/dist/model/document.d.ts +265 -268
  31. package/dist/model/documentfragment.d.ts +214 -214
  32. package/dist/model/documentselection.d.ts +406 -410
  33. package/dist/model/element.d.ts +182 -182
  34. package/dist/model/history.d.ts +109 -109
  35. package/dist/model/item.d.ts +9 -9
  36. package/dist/model/liveposition.d.ts +70 -69
  37. package/dist/model/liverange.d.ts +93 -92
  38. package/dist/model/markercollection.d.ts +317 -324
  39. package/dist/model/model.d.ts +889 -909
  40. package/dist/model/node.d.ts +254 -254
  41. package/dist/model/nodelist.d.ts +110 -110
  42. package/dist/model/operation/attributeoperation.d.ts +98 -98
  43. package/dist/model/operation/detachoperation.d.ts +57 -57
  44. package/dist/model/operation/insertoperation.d.ts +85 -85
  45. package/dist/model/operation/markeroperation.d.ts +87 -87
  46. package/dist/model/operation/mergeoperation.d.ts +95 -95
  47. package/dist/model/operation/moveoperation.d.ts +97 -97
  48. package/dist/model/operation/nooperation.d.ts +33 -33
  49. package/dist/model/operation/operation.d.ts +94 -94
  50. package/dist/model/operation/operationfactory.d.ts +14 -14
  51. package/dist/model/operation/renameoperation.d.ts +78 -78
  52. package/dist/model/operation/rootattributeoperation.d.ts +93 -93
  53. package/dist/model/operation/rootoperation.d.ts +71 -71
  54. package/dist/model/operation/splitoperation.d.ts +104 -104
  55. package/dist/model/operation/transform.d.ts +91 -91
  56. package/dist/model/operation/utils.d.ts +58 -58
  57. package/dist/model/position.d.ts +535 -535
  58. package/dist/model/range.d.ts +458 -453
  59. package/dist/model/rootelement.d.ts +55 -55
  60. package/dist/model/schema.d.ts +1325 -1327
  61. package/dist/model/selection.d.ts +452 -471
  62. package/dist/model/text.d.ts +62 -62
  63. package/dist/model/textproxy.d.ts +140 -140
  64. package/dist/model/treewalker.d.ts +190 -190
  65. package/dist/model/typecheckable.d.ts +281 -281
  66. package/dist/model/utils/autoparagraphing.d.ts +29 -29
  67. package/dist/model/utils/deletecontent.d.ts +68 -68
  68. package/dist/model/utils/getselectedcontent.d.ts +27 -27
  69. package/dist/model/utils/insertcontent.d.ts +42 -42
  70. package/dist/model/utils/insertobject.d.ts +41 -41
  71. package/dist/model/utils/modifyselection.d.ts +44 -44
  72. package/dist/model/utils/selection-post-fixer.d.ts +71 -71
  73. package/dist/model/writer.d.ts +854 -854
  74. package/dist/view/attributeelement.d.ts +123 -123
  75. package/dist/view/containerelement.d.ts +49 -49
  76. package/dist/view/datatransfer.d.ts +70 -70
  77. package/dist/view/document.d.ts +175 -177
  78. package/dist/view/documentfragment.d.ts +158 -157
  79. package/dist/view/documentselection.d.ts +308 -307
  80. package/dist/view/domconverter.d.ts +612 -657
  81. package/dist/view/downcastwriter.d.ts +1006 -1006
  82. package/dist/view/editableelement.d.ts +64 -63
  83. package/dist/view/element.d.ts +754 -754
  84. package/dist/view/elementdefinition.d.ts +79 -79
  85. package/dist/view/emptyelement.d.ts +42 -42
  86. package/dist/view/filler.d.ts +75 -75
  87. package/dist/view/item.d.ts +9 -9
  88. package/dist/view/matcher.d.ts +412 -487
  89. package/dist/view/node.d.ts +164 -163
  90. package/dist/view/observer/arrowkeysobserver.d.ts +37 -37
  91. package/dist/view/observer/bubblingemittermixin.d.ts +163 -153
  92. package/dist/view/observer/bubblingeventinfo.d.ts +45 -42
  93. package/dist/view/observer/clickobserver.d.ts +36 -36
  94. package/dist/view/observer/compositionobserver.d.ts +67 -67
  95. package/dist/view/observer/domeventdata.d.ts +46 -46
  96. package/dist/view/observer/domeventobserver.d.ts +77 -74
  97. package/dist/view/observer/fakeselectionobserver.d.ts +42 -42
  98. package/dist/view/observer/focusobserver.d.ts +84 -84
  99. package/dist/view/observer/inputobserver.d.ts +76 -76
  100. package/dist/view/observer/keyobserver.d.ts +53 -53
  101. package/dist/view/observer/mouseobserver.d.ts +73 -73
  102. package/dist/view/observer/mutationobserver.d.ts +101 -101
  103. package/dist/view/observer/observer.d.ts +84 -83
  104. package/dist/view/observer/pointerobserver.d.ts +63 -63
  105. package/dist/view/observer/selectionobserver.d.ts +136 -136
  106. package/dist/view/observer/tabobserver.d.ts +38 -38
  107. package/dist/view/observer/touchobserver.d.ts +60 -60
  108. package/dist/view/placeholder.d.ts +80 -80
  109. package/dist/view/position.d.ts +187 -187
  110. package/dist/view/range.d.ts +282 -282
  111. package/dist/view/rawelement.d.ts +72 -72
  112. package/dist/view/renderer.d.ts +270 -272
  113. package/dist/view/rooteditableelement.d.ts +43 -43
  114. package/dist/view/selection.d.ts +356 -369
  115. package/dist/view/styles/background.d.ts +15 -15
  116. package/dist/view/styles/border.d.ts +27 -27
  117. package/dist/view/styles/margin.d.ts +12 -12
  118. package/dist/view/styles/padding.d.ts +12 -12
  119. package/dist/view/styles/utils.d.ts +72 -72
  120. package/dist/view/stylesmap.d.ts +715 -715
  121. package/dist/view/text.d.ts +75 -75
  122. package/dist/view/textproxy.d.ts +92 -92
  123. package/dist/view/tokenlist.d.ts +104 -104
  124. package/dist/view/treewalker.d.ts +201 -201
  125. package/dist/view/typecheckable.d.ts +445 -445
  126. package/dist/view/uielement.d.ts +93 -93
  127. package/dist/view/upcastwriter.d.ts +412 -412
  128. package/dist/view/view.d.ts +466 -469
  129. package/package.json +2 -2
@@ -1,530 +1,530 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module engine/model/differ
7
- */
8
- import { ModelPosition } from './position.js';
9
- import { ModelRange } from './range.js';
10
- import type { MarkerCollection, MarkerData } from './markercollection.js';
11
- import { type ModelItem } from './item.js';
12
- import { type ModelNode } from './node.js';
13
- import { type ModelRootElement } from './rootelement.js';
14
- import { type Operation } from './operation/operation.js';
6
+ * @module engine/model/differ
7
+ */
8
+ import { ModelPosition } from "./position.js";
9
+ import { ModelRange } from "./range.js";
10
+ import type { MarkerCollection, MarkerData } from "./markercollection.js";
11
+ import { type ModelItem } from "./item.js";
12
+ import { type ModelNode } from "./node.js";
13
+ import { type ModelRootElement } from "./rootelement.js";
14
+ import { type Operation } from "./operation/operation.js";
15
15
  /**
16
- * Calculates the difference between two model states.
17
- *
18
- * Receives operations that are to be applied on the model document. Marks parts of the model document tree which
19
- * are changed and saves the state of these elements before the change. Then, it compares saved elements with the
20
- * changed elements, after all changes are applied on the model document. Calculates the diff between saved
21
- * elements and new ones and returns a change set.
22
- */
16
+ * Calculates the difference between two model states.
17
+ *
18
+ * Receives operations that are to be applied on the model document. Marks parts of the model document tree which
19
+ * are changed and saves the state of these elements before the change. Then, it compares saved elements with the
20
+ * changed elements, after all changes are applied on the model document. Calculates the diff between saved
21
+ * elements and new ones and returns a change set.
22
+ */
23
23
  export declare class Differ {
24
- /**
25
- * Priority of the {@link ~Differ#_elementState element states}. States on higher indexes of the array can overwrite states on the lower
26
- * indexes.
27
- */
28
- private static readonly _statesPriority;
29
- /**
30
- * Reference to the model's marker collection.
31
- */
32
- private readonly _markerCollection;
33
- /**
34
- * A map that stores changes that happened in a given element.
35
- *
36
- * The keys of the map are references to the model elements.
37
- * The values of the map are arrays with changes that were done on this element.
38
- */
39
- private readonly _changesInElement;
40
- /**
41
- * Stores a snapshot for these model nodes that might have changed.
42
- *
43
- * This complements {@link ~Differ#_elementChildrenSnapshots `_elementChildrenSnapshots`}.
44
- *
45
- * See also {@link ~DifferSnapshot}.
46
- */
47
- private readonly _elementsSnapshots;
48
- /**
49
- * For each element or document fragment inside which there was a change, it stores a snapshot of the child nodes list (an array
50
- * of children snapshots that represent the state in the element / fragment before any change has happened).
51
- *
52
- * This complements {@link ~Differ#_elementsSnapshots `_elementsSnapshots`}.
53
- *
54
- * See also {@link ~DifferSnapshot}.
55
- */
56
- private readonly _elementChildrenSnapshots;
57
- /**
58
- * Keeps the state for a given element, describing how the element was changed so far. It is used to evaluate the `action` property
59
- * of diff items returned by {@link ~Differ#getChanges}.
60
- *
61
- * Possible values, in the order from the lowest priority to the highest priority:
62
- *
63
- * * `'refresh'` - element was refreshed,
64
- * * `'rename'` - element was renamed,
65
- * * `'move'` - element was moved (or, usually, removed, that is moved to the graveyard).
66
- *
67
- * Element that was refreshed, may change its state to `'rename'` if it was later renamed, or to `'move'` if it was removed.
68
- * But the element cannot change its state from `'move'` to `'rename'`, or from `'rename'` to `'refresh'`.
69
- *
70
- * Only already existing elements are registered in `_elementState`. If a new element was inserted as a result of a buffered operation,
71
- * it is not be registered in `_elementState`.
72
- */
73
- private readonly _elementState;
74
- /**
75
- * A map that stores all changed markers.
76
- *
77
- * The keys of the map are marker names.
78
- *
79
- * The values of the map are objects with the following properties:
80
- *
81
- * * `oldMarkerData`,
82
- * * `newMarkerData`.
83
- */
84
- private readonly _changedMarkers;
85
- /**
86
- * A map that stores all roots that have been changed.
87
- *
88
- * The keys are the names of the roots while value represents the changes.
89
- */
90
- private readonly _changedRoots;
91
- /**
92
- * Stores the number of changes that were processed. Used to order the changes chronologically. It is important
93
- * when changes are sorted.
94
- */
95
- private _changeCount;
96
- /**
97
- * For efficiency purposes, `Differ` stores the change set returned by the differ after {@link #getChanges} call.
98
- * Cache is reset each time a new operation is buffered. If the cache has not been reset, {@link #getChanges} will
99
- * return the cached value instead of calculating it again.
100
- *
101
- * This property stores those changes that did not take place in graveyard root.
102
- */
103
- private _cachedChanges;
104
- /**
105
- * For efficiency purposes, `Differ` stores the change set returned by the differ after the {@link #getChanges} call.
106
- * The cache is reset each time a new operation is buffered. If the cache has not been reset, {@link #getChanges} will
107
- * return the cached value instead of calculating it again.
108
- *
109
- * This property stores all changes evaluated by `Differ`, including those that took place in the graveyard.
110
- */
111
- private _cachedChangesWithGraveyard;
112
- /**
113
- * Set of model items that were marked to get refreshed in {@link #_refreshItem}.
114
- */
115
- private _refreshedItems;
116
- /**
117
- * Creates a `Differ` instance.
118
- *
119
- * @param markerCollection Model's marker collection.
120
- */
121
- constructor(markerCollection: MarkerCollection);
122
- /**
123
- * Informs whether there are any changes buffered in `Differ`.
124
- */
125
- get isEmpty(): boolean;
126
- /**
127
- * Buffers the given operation. **An operation has to be buffered before it is executed.**
128
- *
129
- * @param operationToBuffer An operation to buffer.
130
- */
131
- bufferOperation(operationToBuffer: Operation): void;
132
- /**
133
- * Buffers a marker change.
134
- *
135
- * @param markerName The name of the marker that changed.
136
- * @param oldMarkerData Marker data before the change.
137
- * @param newMarkerData Marker data after the change.
138
- */
139
- bufferMarkerChange(markerName: string, oldMarkerData: MarkerData, newMarkerData: MarkerData): void;
140
- /**
141
- * Returns all markers that should be removed as a result of buffered changes.
142
- *
143
- * @returns Markers to remove. Each array item is an object containing the `name` and `range` properties.
144
- */
145
- getMarkersToRemove(): Array<{
146
- name: string;
147
- range: ModelRange;
148
- }>;
149
- /**
150
- * Returns all markers which should be added as a result of buffered changes.
151
- *
152
- * @returns Markers to add. Each array item is an object containing the `name` and `range` properties.
153
- */
154
- getMarkersToAdd(): Array<{
155
- name: string;
156
- range: ModelRange;
157
- }>;
158
- /**
159
- * Returns all markers which changed.
160
- */
161
- getChangedMarkers(): Array<{
162
- name: string;
163
- data: {
164
- oldRange: ModelRange | null;
165
- newRange: ModelRange | null;
166
- };
167
- }>;
168
- /**
169
- * Checks whether some of the buffered changes affect the editor data.
170
- *
171
- * Types of changes which affect the editor data:
172
- *
173
- * * model structure changes,
174
- * * attribute changes,
175
- * * a root is added or detached,
176
- * * changes of markers which were defined as `affectsData`,
177
- * * changes of markers' `affectsData` property.
178
- */
179
- hasDataChanges(): boolean;
180
- /**
181
- * Calculates the diff between the old model tree state (the state before the first buffered operations since the last {@link #reset}
182
- * call) and the new model tree state (actual one). It should be called after all buffered operations are executed.
183
- *
184
- * The diff set is returned as an array of {@link module:engine/model/differ~DifferItem diff items}, each describing a change done
185
- * on the model. The items are sorted by the position on which the change happened. If a position
186
- * {@link module:engine/model/position~ModelPosition#isBefore is before} another one, it will be on an earlier index in the diff set.
187
- *
188
- * **Note**: Elements inside inserted element will not have a separate diff item, only the top most element change will be reported.
189
- *
190
- * Because calculating the diff is a costly operation, the result is cached. If no new operation was buffered since the
191
- * previous {@link #getChanges} call, the next call will return the cached value.
192
- *
193
- * @param options Additional options.
194
- * @param options.includeChangesInGraveyard If set to `true`, also changes that happened
195
- * in the graveyard root will be returned. By default, changes in the graveyard root are not returned.
196
- * @returns Diff between the old and the new model tree state.
197
- */
198
- getChanges(options?: {
199
- includeChangesInGraveyard?: boolean;
200
- }): Array<DifferItem>;
201
- /**
202
- * Returns all roots that have changed (either were attached, or detached, or their attributes changed).
203
- *
204
- * @returns Diff between the old and the new roots state.
205
- */
206
- getChangedRoots(): Array<DifferItemRoot>;
207
- /**
208
- * Returns a set of model items that were marked to get refreshed.
209
- */
210
- getRefreshedItems(): Set<ModelItem>;
211
- /**
212
- * Resets `Differ`. Removes all buffered changes.
213
- */
214
- reset(): void;
215
- /**
216
- * Marks the given `item` in differ to be "refreshed". It means that the item will be marked as removed and inserted
217
- * in the differ changes set, so it will be effectively re-converted when the differ changes are handled by a dispatcher.
218
- *
219
- * @internal
220
- * @param item Item to refresh.
221
- */
222
- _refreshItem(item: ModelItem): void;
223
- /**
224
- * Buffers all the data related to given root like it was all just added to the editor.
225
- *
226
- * Following changes are buffered:
227
- *
228
- * * root is attached,
229
- * * all root content is inserted,
230
- * * all root attributes are added,
231
- * * all markers inside the root are added.
232
- *
233
- * @internal
234
- */
235
- _bufferRootLoad(root: ModelRootElement): void;
236
- /**
237
- * Buffers the root state change after the root was attached or detached
238
- */
239
- private _bufferRootStateChange;
240
- /**
241
- * Buffers a root attribute change.
242
- */
243
- private _bufferRootAttributeChange;
244
- /**
245
- * Saves and handles an insert change.
246
- */
247
- private _markInsert;
248
- /**
249
- * Saves and handles a remove change.
250
- */
251
- private _markRemove;
252
- /**
253
- * Saves and handles an attribute change.
254
- */
255
- private _markAttribute;
256
- /**
257
- * Saves and handles a model change.
258
- */
259
- private _markChange;
260
- /**
261
- * Tries to set given state for given item.
262
- *
263
- * This method does simple validation (it sets the state only for model elements, not for text proxy nodes). It also follows state
264
- * setting rules, that is, `'refresh'` cannot overwrite `'rename'`, and `'rename'` cannot overwrite `'move'`.
265
- */
266
- private _setElementState;
267
- /**
268
- * Returns a value for {@link ~DifferItemAction `action`} property for diff items returned by {@link ~Differ#getChanges}.
269
- * This method aims to return `'rename'` or `'refresh'` when it should, and `diffItemType` ("default action") in all other cases.
270
- *
271
- * It bases on a few factors:
272
- *
273
- * * for text nodes, the method always returns `diffItemType`,
274
- * * for newly inserted element, the method returns `diffItemType`,
275
- * * if {@link ~Differ#_elementState element state} was not recorded, the method returns `diffItemType`,
276
- * * if state was recorded, and it was `'move'` (default action), the method returns `diffItemType`,
277
- * * finally, if state was `'refresh'` or `'rename'`, the method returns the state value.
278
- */
279
- private _getDiffActionForNode;
280
- /**
281
- * Gets an array of changes that have already been saved for a given element.
282
- */
283
- private _getChangesForElement;
284
- /**
285
- * Creates and saves a snapshot for all children of the given element.
286
- */
287
- private _makeSnapshots;
288
- /**
289
- * For a given newly saved change, compares it with a change already done on the element and modifies the incoming
290
- * change and/or the old change.
291
- *
292
- * @param inc Incoming (new) change.
293
- * @param changes An array containing all the changes done on that element.
294
- */
295
- private _handleChange;
296
- /**
297
- * Returns an object with a single insert change description.
298
- *
299
- * @param parent The element in which the change happened.
300
- * @param offset The offset at which change happened.
301
- * @param action Further specifies what kind of action led to generating this change.
302
- * @param elementSnapshot Snapshot of the inserted node after changes.
303
- * @param elementSnapshotBefore Snapshot of the inserted node before changes.
304
- * @returns The diff item.
305
- */
306
- private _getInsertDiff;
307
- /**
308
- * Returns an object with a single remove change description.
309
- *
310
- * @param parent The element in which change happened.
311
- * @param offset The offset at which change happened.
312
- * @param action Further specifies what kind of action led to generating this change.
313
- * @param elementSnapshot The snapshot of the removed node before changes.
314
- * @returns The diff item.
315
- */
316
- private _getRemoveDiff;
317
- /**
318
- * Returns an array of objects where each one is a single attribute change description.
319
- *
320
- * @param range The range where the change happened.
321
- * @param oldAttributes A map, map iterator or compatible object that contains attributes before the change.
322
- * @param newAttributes A map, map iterator or compatible object that contains attributes after the change.
323
- * @returns An array containing one or more diff items.
324
- */
325
- private _getAttributesDiff;
326
- /**
327
- * Checks whether given element or any of its parents is an element that is buffered as an inserted element.
328
- */
329
- private _isInInsertedElement;
330
- /**
331
- * Removes deeply all buffered changes that are registered in elements from range specified by `parent`, `offset`
332
- * and `howMany`.
333
- */
334
- private _removeAllNestedChanges;
24
+ /**
25
+ * Priority of the {@link ~Differ#_elementState element states}. States on higher indexes of the array can overwrite states on the lower
26
+ * indexes.
27
+ */
28
+ private static readonly _statesPriority;
29
+ /**
30
+ * Reference to the model's marker collection.
31
+ */
32
+ private readonly _markerCollection;
33
+ /**
34
+ * A map that stores changes that happened in a given element.
35
+ *
36
+ * The keys of the map are references to the model elements.
37
+ * The values of the map are arrays with changes that were done on this element.
38
+ */
39
+ private readonly _changesInElement;
40
+ /**
41
+ * Stores a snapshot for these model nodes that might have changed.
42
+ *
43
+ * This complements {@link ~Differ#_elementChildrenSnapshots `_elementChildrenSnapshots`}.
44
+ *
45
+ * See also {@link ~DifferSnapshot}.
46
+ */
47
+ private readonly _elementsSnapshots;
48
+ /**
49
+ * For each element or document fragment inside which there was a change, it stores a snapshot of the child nodes list (an array
50
+ * of children snapshots that represent the state in the element / fragment before any change has happened).
51
+ *
52
+ * This complements {@link ~Differ#_elementsSnapshots `_elementsSnapshots`}.
53
+ *
54
+ * See also {@link ~DifferSnapshot}.
55
+ */
56
+ private readonly _elementChildrenSnapshots;
57
+ /**
58
+ * Keeps the state for a given element, describing how the element was changed so far. It is used to evaluate the `action` property
59
+ * of diff items returned by {@link ~Differ#getChanges}.
60
+ *
61
+ * Possible values, in the order from the lowest priority to the highest priority:
62
+ *
63
+ * * `'refresh'` - element was refreshed,
64
+ * * `'rename'` - element was renamed,
65
+ * * `'move'` - element was moved (or, usually, removed, that is moved to the graveyard).
66
+ *
67
+ * Element that was refreshed, may change its state to `'rename'` if it was later renamed, or to `'move'` if it was removed.
68
+ * But the element cannot change its state from `'move'` to `'rename'`, or from `'rename'` to `'refresh'`.
69
+ *
70
+ * Only already existing elements are registered in `_elementState`. If a new element was inserted as a result of a buffered operation,
71
+ * it is not be registered in `_elementState`.
72
+ */
73
+ private readonly _elementState;
74
+ /**
75
+ * A map that stores all changed markers.
76
+ *
77
+ * The keys of the map are marker names.
78
+ *
79
+ * The values of the map are objects with the following properties:
80
+ *
81
+ * * `oldMarkerData`,
82
+ * * `newMarkerData`.
83
+ */
84
+ private readonly _changedMarkers;
85
+ /**
86
+ * A map that stores all roots that have been changed.
87
+ *
88
+ * The keys are the names of the roots while value represents the changes.
89
+ */
90
+ private readonly _changedRoots;
91
+ /**
92
+ * Stores the number of changes that were processed. Used to order the changes chronologically. It is important
93
+ * when changes are sorted.
94
+ */
95
+ private _changeCount;
96
+ /**
97
+ * For efficiency purposes, `Differ` stores the change set returned by the differ after {@link #getChanges} call.
98
+ * Cache is reset each time a new operation is buffered. If the cache has not been reset, {@link #getChanges} will
99
+ * return the cached value instead of calculating it again.
100
+ *
101
+ * This property stores those changes that did not take place in graveyard root.
102
+ */
103
+ private _cachedChanges;
104
+ /**
105
+ * For efficiency purposes, `Differ` stores the change set returned by the differ after the {@link #getChanges} call.
106
+ * The cache is reset each time a new operation is buffered. If the cache has not been reset, {@link #getChanges} will
107
+ * return the cached value instead of calculating it again.
108
+ *
109
+ * This property stores all changes evaluated by `Differ`, including those that took place in the graveyard.
110
+ */
111
+ private _cachedChangesWithGraveyard;
112
+ /**
113
+ * Set of model items that were marked to get refreshed in {@link #_refreshItem}.
114
+ */
115
+ private _refreshedItems;
116
+ /**
117
+ * Creates a `Differ` instance.
118
+ *
119
+ * @param markerCollection Model's marker collection.
120
+ */
121
+ constructor(markerCollection: MarkerCollection);
122
+ /**
123
+ * Informs whether there are any changes buffered in `Differ`.
124
+ */
125
+ get isEmpty(): boolean;
126
+ /**
127
+ * Buffers the given operation. **An operation has to be buffered before it is executed.**
128
+ *
129
+ * @param operationToBuffer An operation to buffer.
130
+ */
131
+ bufferOperation(operationToBuffer: Operation): void;
132
+ /**
133
+ * Buffers a marker change.
134
+ *
135
+ * @param markerName The name of the marker that changed.
136
+ * @param oldMarkerData Marker data before the change.
137
+ * @param newMarkerData Marker data after the change.
138
+ */
139
+ bufferMarkerChange(markerName: string, oldMarkerData: MarkerData, newMarkerData: MarkerData): void;
140
+ /**
141
+ * Returns all markers that should be removed as a result of buffered changes.
142
+ *
143
+ * @returns Markers to remove. Each array item is an object containing the `name` and `range` properties.
144
+ */
145
+ getMarkersToRemove(): Array<{
146
+ name: string;
147
+ range: ModelRange;
148
+ }>;
149
+ /**
150
+ * Returns all markers which should be added as a result of buffered changes.
151
+ *
152
+ * @returns Markers to add. Each array item is an object containing the `name` and `range` properties.
153
+ */
154
+ getMarkersToAdd(): Array<{
155
+ name: string;
156
+ range: ModelRange;
157
+ }>;
158
+ /**
159
+ * Returns all markers which changed.
160
+ */
161
+ getChangedMarkers(): Array<{
162
+ name: string;
163
+ data: {
164
+ oldRange: ModelRange | null;
165
+ newRange: ModelRange | null;
166
+ };
167
+ }>;
168
+ /**
169
+ * Checks whether some of the buffered changes affect the editor data.
170
+ *
171
+ * Types of changes which affect the editor data:
172
+ *
173
+ * * model structure changes,
174
+ * * attribute changes,
175
+ * * a root is added or detached,
176
+ * * changes of markers which were defined as `affectsData`,
177
+ * * changes of markers' `affectsData` property.
178
+ */
179
+ hasDataChanges(): boolean;
180
+ /**
181
+ * Calculates the diff between the old model tree state (the state before the first buffered operations since the last {@link #reset}
182
+ * call) and the new model tree state (actual one). It should be called after all buffered operations are executed.
183
+ *
184
+ * The diff set is returned as an array of {@link module:engine/model/differ~DifferItem diff items}, each describing a change done
185
+ * on the model. The items are sorted by the position on which the change happened. If a position
186
+ * {@link module:engine/model/position~ModelPosition#isBefore is before} another one, it will be on an earlier index in the diff set.
187
+ *
188
+ * **Note**: Elements inside inserted element will not have a separate diff item, only the top most element change will be reported.
189
+ *
190
+ * Because calculating the diff is a costly operation, the result is cached. If no new operation was buffered since the
191
+ * previous {@link #getChanges} call, the next call will return the cached value.
192
+ *
193
+ * @param options Additional options.
194
+ * @param options.includeChangesInGraveyard If set to `true`, also changes that happened
195
+ * in the graveyard root will be returned. By default, changes in the graveyard root are not returned.
196
+ * @returns Diff between the old and the new model tree state.
197
+ */
198
+ getChanges(options?: {
199
+ includeChangesInGraveyard?: boolean;
200
+ }): Array<DifferItem>;
201
+ /**
202
+ * Returns all roots that have changed (either were attached, or detached, or their attributes changed).
203
+ *
204
+ * @returns Diff between the old and the new roots state.
205
+ */
206
+ getChangedRoots(): Array<DifferItemRoot>;
207
+ /**
208
+ * Returns a set of model items that were marked to get refreshed.
209
+ */
210
+ getRefreshedItems(): Set<ModelItem>;
211
+ /**
212
+ * Resets `Differ`. Removes all buffered changes.
213
+ */
214
+ reset(): void;
215
+ /**
216
+ * Marks the given `item` in differ to be "refreshed". It means that the item will be marked as removed and inserted
217
+ * in the differ changes set, so it will be effectively re-converted when the differ changes are handled by a dispatcher.
218
+ *
219
+ * @internal
220
+ * @param item Item to refresh.
221
+ */
222
+ _refreshItem(item: ModelItem): void;
223
+ /**
224
+ * Buffers all the data related to given root like it was all just added to the editor.
225
+ *
226
+ * Following changes are buffered:
227
+ *
228
+ * * root is attached,
229
+ * * all root content is inserted,
230
+ * * all root attributes are added,
231
+ * * all markers inside the root are added.
232
+ *
233
+ * @internal
234
+ */
235
+ _bufferRootLoad(root: ModelRootElement): void;
236
+ /**
237
+ * Buffers the root state change after the root was attached or detached
238
+ */
239
+ private _bufferRootStateChange;
240
+ /**
241
+ * Buffers a root attribute change.
242
+ */
243
+ private _bufferRootAttributeChange;
244
+ /**
245
+ * Saves and handles an insert change.
246
+ */
247
+ private _markInsert;
248
+ /**
249
+ * Saves and handles a remove change.
250
+ */
251
+ private _markRemove;
252
+ /**
253
+ * Saves and handles an attribute change.
254
+ */
255
+ private _markAttribute;
256
+ /**
257
+ * Saves and handles a model change.
258
+ */
259
+ private _markChange;
260
+ /**
261
+ * Tries to set given state for given item.
262
+ *
263
+ * This method does simple validation (it sets the state only for model elements, not for text proxy nodes). It also follows state
264
+ * setting rules, that is, `'refresh'` cannot overwrite `'rename'`, and `'rename'` cannot overwrite `'move'`.
265
+ */
266
+ private _setElementState;
267
+ /**
268
+ * Returns a value for {@link ~DifferItemAction `action`} property for diff items returned by {@link ~Differ#getChanges}.
269
+ * This method aims to return `'rename'` or `'refresh'` when it should, and `diffItemType` ("default action") in all other cases.
270
+ *
271
+ * It bases on a few factors:
272
+ *
273
+ * * for text nodes, the method always returns `diffItemType`,
274
+ * * for newly inserted element, the method returns `diffItemType`,
275
+ * * if {@link ~Differ#_elementState element state} was not recorded, the method returns `diffItemType`,
276
+ * * if state was recorded, and it was `'move'` (default action), the method returns `diffItemType`,
277
+ * * finally, if state was `'refresh'` or `'rename'`, the method returns the state value.
278
+ */
279
+ private _getDiffActionForNode;
280
+ /**
281
+ * Gets an array of changes that have already been saved for a given element.
282
+ */
283
+ private _getChangesForElement;
284
+ /**
285
+ * Creates and saves a snapshot for all children of the given element.
286
+ */
287
+ private _makeSnapshots;
288
+ /**
289
+ * For a given newly saved change, compares it with a change already done on the element and modifies the incoming
290
+ * change and/or the old change.
291
+ *
292
+ * @param inc Incoming (new) change.
293
+ * @param changes An array containing all the changes done on that element.
294
+ */
295
+ private _handleChange;
296
+ /**
297
+ * Returns an object with a single insert change description.
298
+ *
299
+ * @param parent The element in which the change happened.
300
+ * @param offset The offset at which change happened.
301
+ * @param action Further specifies what kind of action led to generating this change.
302
+ * @param elementSnapshot Snapshot of the inserted node after changes.
303
+ * @param elementSnapshotBefore Snapshot of the inserted node before changes.
304
+ * @returns The diff item.
305
+ */
306
+ private _getInsertDiff;
307
+ /**
308
+ * Returns an object with a single remove change description.
309
+ *
310
+ * @param parent The element in which change happened.
311
+ * @param offset The offset at which change happened.
312
+ * @param action Further specifies what kind of action led to generating this change.
313
+ * @param elementSnapshot The snapshot of the removed node before changes.
314
+ * @returns The diff item.
315
+ */
316
+ private _getRemoveDiff;
317
+ /**
318
+ * Returns an array of objects where each one is a single attribute change description.
319
+ *
320
+ * @param range The range where the change happened.
321
+ * @param oldAttributes A map, map iterator or compatible object that contains attributes before the change.
322
+ * @param newAttributes A map, map iterator or compatible object that contains attributes after the change.
323
+ * @returns An array containing one or more diff items.
324
+ */
325
+ private _getAttributesDiff;
326
+ /**
327
+ * Checks whether given element or any of its parents is an element that is buffered as an inserted element.
328
+ */
329
+ private _isInInsertedElement;
330
+ /**
331
+ * Removes deeply all buffered changes that are registered in elements from range specified by `parent`, `offset`
332
+ * and `howMany`.
333
+ */
334
+ private _removeAllNestedChanges;
335
335
  }
336
336
  /**
337
- * Further specifies what kind of action led to generating a change:
338
- *
339
- * * `'insert'` if element was inserted,
340
- * * `'remove'` if element was removed,
341
- * * `'rename'` if element got renamed (e.g. `writer.rename()`),
342
- * * `'refresh'` if element got refreshed (e.g. `model.editing.reconvertItem()`).
343
- */
344
- export type DifferItemAction = 'insert' | 'remove' | 'rename' | 'refresh';
337
+ * Further specifies what kind of action led to generating a change:
338
+ *
339
+ * * `'insert'` if element was inserted,
340
+ * * `'remove'` if element was removed,
341
+ * * `'rename'` if element got renamed (e.g. `writer.rename()`),
342
+ * * `'refresh'` if element got refreshed (e.g. `model.editing.reconvertItem()`).
343
+ */
344
+ export type DifferItemAction = "insert" | "remove" | "rename" | "refresh";
345
345
  /**
346
- * A snapshot is representing state of a given element before the first change was applied on that element.
347
- *
348
- * @internal
349
- */
346
+ * A snapshot is representing state of a given element before the first change was applied on that element.
347
+ *
348
+ * @internal
349
+ */
350
350
  export interface DifferSnapshot {
351
- /**
352
- * Node for which was snapshot was made.
353
- */
354
- node: ModelNode;
355
- /**
356
- * Name of the element at the time when the snapshot was made. For text node snapshots, it is set to `'$text'`.
357
- */
358
- name: string;
359
- /**
360
- * Attributes of the node at the time when the snapshot was made.
361
- */
362
- attributes: Map<string, unknown>;
351
+ /**
352
+ * Node for which was snapshot was made.
353
+ */
354
+ node: ModelNode;
355
+ /**
356
+ * Name of the element at the time when the snapshot was made. For text node snapshots, it is set to `'$text'`.
357
+ */
358
+ name: string;
359
+ /**
360
+ * Attributes of the node at the time when the snapshot was made.
361
+ */
362
+ attributes: Map<string, unknown>;
363
363
  }
364
364
  /**
365
- * The single diff item.
366
- *
367
- * Could be one of:
368
- *
369
- * * {@link module:engine/model/differ~DifferItemInsert `DifferItemInsert`},
370
- * * {@link module:engine/model/differ~DifferItemRemove `DifferItemRemove`},
371
- * * {@link module:engine/model/differ~DifferItemAttribute `DifferItemAttribute`}.
372
- */
365
+ * The single diff item.
366
+ *
367
+ * Could be one of:
368
+ *
369
+ * * {@link module:engine/model/differ~DifferItemInsert `DifferItemInsert`},
370
+ * * {@link module:engine/model/differ~DifferItemRemove `DifferItemRemove`},
371
+ * * {@link module:engine/model/differ~DifferItemAttribute `DifferItemAttribute`}.
372
+ */
373
373
  export type DifferItem = DifferItemInsert | DifferItemRemove | DifferItemAttribute;
374
374
  /**
375
- * A single diff item for inserted nodes.
376
- */
375
+ * A single diff item for inserted nodes.
376
+ */
377
377
  export interface DifferItemInsert {
378
- /**
379
- * The type of diff item.
380
- */
381
- type: 'insert';
382
- /**
383
- * Further specifies what kind of action led to generating this change.
384
- *
385
- * The action is set in relation to the document state before any change. It means that, for example, if an element was added and
386
- * then renamed (during the same {@link module:engine/model/batch~Batch batch}), the action will be set to `'insert'`, because when
387
- * compared to the document state before changes, a new element was inserted, and the renaming does not matter from this point of view.
388
- */
389
- action: DifferItemAction;
390
- /**
391
- * The name of the inserted elements or `'$text'` for a text node.
392
- */
393
- name: string;
394
- /**
395
- * Map of attributes of the inserted element.
396
- */
397
- attributes: Map<string, unknown>;
398
- /**
399
- * The position where the node was inserted.
400
- */
401
- position: ModelPosition;
402
- /**
403
- * The length of an inserted text node. For elements, it is always 1 as each inserted element is counted as a one.
404
- */
405
- length: number;
406
- /**
407
- * Holds information about the element state before all changes happened.
408
- *
409
- * For example, when `<paragraph textAlign="right">` was changed to `<codeBlock language="plaintext">`,
410
- * `before.name` will be equal to `'paragraph'` and `before.attributes` map will have one entry: `'textAlign' -> 'right'`.
411
- *
412
- * The property is available only if the insertion change was due to element rename or refresh (when `action` property is `'rename'`
413
- * or `'refresh'`). As such, `before` property is never available for text node changes.
414
- */
415
- before?: {
416
- /**
417
- * The name of the inserted element before all changes.
418
- */
419
- name: string;
420
- /**
421
- * Map of the attributes of the inserted element before all changes.
422
- */
423
- attributes: Map<string, unknown>;
424
- };
378
+ /**
379
+ * The type of diff item.
380
+ */
381
+ type: "insert";
382
+ /**
383
+ * Further specifies what kind of action led to generating this change.
384
+ *
385
+ * The action is set in relation to the document state before any change. It means that, for example, if an element was added and
386
+ * then renamed (during the same {@link module:engine/model/batch~Batch batch}), the action will be set to `'insert'`, because when
387
+ * compared to the document state before changes, a new element was inserted, and the renaming does not matter from this point of view.
388
+ */
389
+ action: DifferItemAction;
390
+ /**
391
+ * The name of the inserted elements or `'$text'` for a text node.
392
+ */
393
+ name: string;
394
+ /**
395
+ * Map of attributes of the inserted element.
396
+ */
397
+ attributes: Map<string, unknown>;
398
+ /**
399
+ * The position where the node was inserted.
400
+ */
401
+ position: ModelPosition;
402
+ /**
403
+ * The length of an inserted text node. For elements, it is always 1 as each inserted element is counted as a one.
404
+ */
405
+ length: number;
406
+ /**
407
+ * Holds information about the element state before all changes happened.
408
+ *
409
+ * For example, when `<paragraph textAlign="right">` was changed to `<codeBlock language="plaintext">`,
410
+ * `before.name` will be equal to `'paragraph'` and `before.attributes` map will have one entry: `'textAlign' -> 'right'`.
411
+ *
412
+ * The property is available only if the insertion change was due to element rename or refresh (when `action` property is `'rename'`
413
+ * or `'refresh'`). As such, `before` property is never available for text node changes.
414
+ */
415
+ before?: {
416
+ /**
417
+ * The name of the inserted element before all changes.
418
+ */
419
+ name: string;
420
+ /**
421
+ * Map of the attributes of the inserted element before all changes.
422
+ */
423
+ attributes: Map<string, unknown>;
424
+ };
425
425
  }
426
426
  /**
427
- * A single diff item for re-inserted nodes.
428
- */
427
+ * A single diff item for re-inserted nodes.
428
+ */
429
429
  export interface DifferItemReinsert {
430
- /**
431
- * The type of diff item.
432
- */
433
- type: 'reinsert';
434
- /**
435
- * The name of the re-inserted elements or `'$text'` for a text node.
436
- */
437
- name: string;
438
- /**
439
- * The position where the node was reinserted.
440
- */
441
- position: ModelPosition;
442
- /**
443
- * The length of a re-inserted text node. For elements, it is always 1 as each re-inserted element is counted as a one.
444
- */
445
- length: number;
430
+ /**
431
+ * The type of diff item.
432
+ */
433
+ type: "reinsert";
434
+ /**
435
+ * The name of the re-inserted elements or `'$text'` for a text node.
436
+ */
437
+ name: string;
438
+ /**
439
+ * The position where the node was reinserted.
440
+ */
441
+ position: ModelPosition;
442
+ /**
443
+ * The length of a re-inserted text node. For elements, it is always 1 as each re-inserted element is counted as a one.
444
+ */
445
+ length: number;
446
446
  }
447
447
  /**
448
- * A single diff item for removed nodes.
449
- */
448
+ * A single diff item for removed nodes.
449
+ */
450
450
  export interface DifferItemRemove {
451
- /**
452
- * The type of diff item.
453
- */
454
- type: 'remove';
455
- /**
456
- * Further specifies what kind of action led to generating this change.
457
- *
458
- * The action is set in relation to the document state before any change. It means that, for example, if an element was renamed and
459
- * then removed (during the same {@link module:engine/model/batch~Batch batch}), the action will be set to `'remove'`, because when
460
- * compared to the document state before changes, the element was removed, and it does not matter that it was also renamed at one point.
461
- */
462
- action: DifferItemAction;
463
- /**
464
- * The name of the removed element or `'$text'` for a text node.
465
- */
466
- name: string;
467
- /**
468
- * Map of attributes that were set on the item while it was removed.
469
- */
470
- attributes: Map<string, unknown>;
471
- /**
472
- * The position where the node was removed.
473
- */
474
- position: ModelPosition;
475
- /**
476
- * The length of a removed text node. For elements, it is always 1, as each removed element is counted as a one.
477
- */
478
- length: number;
451
+ /**
452
+ * The type of diff item.
453
+ */
454
+ type: "remove";
455
+ /**
456
+ * Further specifies what kind of action led to generating this change.
457
+ *
458
+ * The action is set in relation to the document state before any change. It means that, for example, if an element was renamed and
459
+ * then removed (during the same {@link module:engine/model/batch~Batch batch}), the action will be set to `'remove'`, because when
460
+ * compared to the document state before changes, the element was removed, and it does not matter that it was also renamed at one point.
461
+ */
462
+ action: DifferItemAction;
463
+ /**
464
+ * The name of the removed element or `'$text'` for a text node.
465
+ */
466
+ name: string;
467
+ /**
468
+ * Map of attributes that were set on the item while it was removed.
469
+ */
470
+ attributes: Map<string, unknown>;
471
+ /**
472
+ * The position where the node was removed.
473
+ */
474
+ position: ModelPosition;
475
+ /**
476
+ * The length of a removed text node. For elements, it is always 1, as each removed element is counted as a one.
477
+ */
478
+ length: number;
479
479
  }
480
480
  /**
481
- * A single diff item for attribute change.
482
- */
481
+ * A single diff item for attribute change.
482
+ */
483
483
  export interface DifferItemAttribute {
484
- /**
485
- * The type of diff item.
486
- */
487
- type: 'attribute';
488
- /**
489
- * The name of the changed attribute.
490
- */
491
- attributeKey: string;
492
- /**
493
- * An attribute previous value (before change).
494
- */
495
- attributeOldValue: unknown;
496
- /**
497
- * An attribute new value (after change).
498
- */
499
- attributeNewValue: unknown;
500
- /**
501
- * The range where the change happened.
502
- */
503
- range: ModelRange;
484
+ /**
485
+ * The type of diff item.
486
+ */
487
+ type: "attribute";
488
+ /**
489
+ * The name of the changed attribute.
490
+ */
491
+ attributeKey: string;
492
+ /**
493
+ * An attribute previous value (before change).
494
+ */
495
+ attributeOldValue: unknown;
496
+ /**
497
+ * An attribute new value (after change).
498
+ */
499
+ attributeNewValue: unknown;
500
+ /**
501
+ * The range where the change happened.
502
+ */
503
+ range: ModelRange;
504
504
  }
505
505
  /**
506
- * A single diff item for a changed root.
507
- */
506
+ * A single diff item for a changed root.
507
+ */
508
508
  export interface DifferItemRoot {
509
- /**
510
- * Name of the changed root.
511
- */
512
- name: string;
513
- /**
514
- * Set accordingly if the root got attached or detached. Otherwise, not set.
515
- */
516
- state?: 'attached' | 'detached';
517
- /**
518
- * Keeps all attribute changes that happened on the root.
519
- *
520
- * The keys are keys of the changed attributes. The values are objects containing the attribute value before the change
521
- * (`oldValue`) and after the change (`newValue`).
522
- *
523
- * Note, that if the root state changed (`state` is set), then `attributes` property will not be set. All attributes should be
524
- * handled together with the root being attached or detached.
525
- */
526
- attributes?: Record<string, {
527
- oldValue: unknown;
528
- newValue: unknown;
529
- }>;
509
+ /**
510
+ * Name of the changed root.
511
+ */
512
+ name: string;
513
+ /**
514
+ * Set accordingly if the root got attached or detached. Otherwise, not set.
515
+ */
516
+ state?: "attached" | "detached";
517
+ /**
518
+ * Keeps all attribute changes that happened on the root.
519
+ *
520
+ * The keys are keys of the changed attributes. The values are objects containing the attribute value before the change
521
+ * (`oldValue`) and after the change (`newValue`).
522
+ *
523
+ * Note, that if the root state changed (`state` is set), then `attributes` property will not be set. All attributes should be
524
+ * handled together with the root being attached or detached.
525
+ */
526
+ attributes?: Record<string, {
527
+ oldValue: unknown;
528
+ newValue: unknown;
529
+ }>;
530
530
  }