@ckeditor/ckeditor5-engine 48.2.0-alpha.7 → 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,719 +1,714 @@
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/conversion/mapper
7
- */
8
- import { ModelPosition } from '../model/position.js';
9
- import { ModelRange } from '../model/range.js';
10
- import { ViewPosition } from '../view/position.js';
11
- import { ViewRange } from '../view/range.js';
12
- import { type ViewDocumentFragment } from '../view/documentfragment.js';
13
- import { type ViewElement } from '../view/element.js';
14
- import { type ModelElement } from '../model/element.js';
15
- import { type ModelDocumentFragment } from '../model/documentfragment.js';
16
- import type { ViewNode } from '../view/node.js';
17
- declare const Mapper_base: {
18
- new (): import("@ckeditor/ckeditor5-utils").Emitter;
19
- prototype: import("@ckeditor/ckeditor5-utils").Emitter;
20
- };
6
+ * @module engine/conversion/mapper
7
+ */
8
+ import { ModelPosition } from "../model/position.js";
9
+ import { ModelRange } from "../model/range.js";
10
+ import { ViewPosition } from "../view/position.js";
11
+ import { ViewRange } from "../view/range.js";
12
+ import { type EmitterMixinConstructor } from "@ckeditor/ckeditor5-utils";
13
+ import { type ViewDocumentFragment } from "../view/documentfragment.js";
14
+ import { type ViewElement } from "../view/element.js";
15
+ import { type ModelElement } from "../model/element.js";
16
+ import { type ModelDocumentFragment } from "../model/documentfragment.js";
17
+ import type { ViewNode } from "../view/node.js";
18
+ declare const MapperBase: EmitterMixinConstructor;
19
+ declare const MapperCacheBase: EmitterMixinConstructor;
21
20
  /**
22
- * Maps elements, positions and markers between the {@link module:engine/view/document~ViewDocument view} and
23
- * the {@link module:engine/model/model model}.
24
- *
25
- * The instance of the Mapper used for the editing pipeline is available in
26
- * {@link module:engine/controller/editingcontroller~EditingController#mapper `editor.editing.mapper`}.
27
- *
28
- * Mapper uses bound elements to find corresponding elements and positions, so, to get proper results,
29
- * all model elements should be {@link module:engine/conversion/mapper~Mapper#bindElements bound}.
30
- *
31
- * To map the complex model to/from view relations, you may provide custom callbacks for the
32
- * {@link module:engine/conversion/mapper~Mapper#event:modelToViewPosition modelToViewPosition event} and
33
- * {@link module:engine/conversion/mapper~Mapper#event:viewToModelPosition viewToModelPosition event} that are fired whenever
34
- * a position mapping request occurs.
35
- * Those events are fired by the {@link module:engine/conversion/mapper~Mapper#toViewPosition toViewPosition}
36
- * and {@link module:engine/conversion/mapper~Mapper#toModelPosition toModelPosition} methods. `Mapper` adds its own default callbacks
37
- * with `'lowest'` priority. To override default `Mapper` mapping, add custom callback with higher priority and
38
- * stop the event.
39
- */
40
- export declare class Mapper extends /* #__PURE__ */ Mapper_base {
41
- /**
42
- * Model element to view element mapping.
43
- */
44
- private _modelToViewMapping;
45
- /**
46
- * View element to model element mapping.
47
- */
48
- private _viewToModelMapping;
49
- /**
50
- * A map containing callbacks between view element names and functions evaluating length of view elements
51
- * in model.
52
- */
53
- private _viewToModelLengthCallbacks;
54
- /**
55
- * Model marker name to view elements mapping.
56
- *
57
- * Keys are `String`s while values are `Set`s with {@link module:engine/view/element~ViewElement view elements}.
58
- * One marker (name) can be mapped to multiple elements.
59
- */
60
- private _markerNameToElements;
61
- /**
62
- * View element to model marker names mapping.
63
- *
64
- * This is reverse to {@link ~Mapper#_markerNameToElements} map.
65
- */
66
- private _elementToMarkerNames;
67
- /**
68
- * The map of removed view elements with their current root (used for deferred unbinding).
69
- */
70
- private _deferredBindingRemovals;
71
- /**
72
- * Stores marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
73
- * has been removed, moved or renamed).
74
- */
75
- private _unboundMarkerNames;
76
- /**
77
- * Manages dynamic cache for the `Mapper` to improve the performance.
78
- */
79
- private _cache;
80
- /**
81
- * Creates an instance of the mapper.
82
- */
83
- constructor();
84
- /**
85
- * Marks model and view elements as corresponding. Corresponding elements can be retrieved by using
86
- * the {@link module:engine/conversion/mapper~Mapper#toModelElement toModelElement} and
87
- * {@link module:engine/conversion/mapper~Mapper#toViewElement toViewElement} methods.
88
- * The information that elements are bound is also used to translate positions.
89
- *
90
- * @param modelElement Model element.
91
- * @param viewElement View element.
92
- */
93
- bindElements(modelElement: ModelElement | ModelDocumentFragment, viewElement: ViewElement | ViewDocumentFragment): void;
94
- /**
95
- * Unbinds the given {@link module:engine/view/element~ViewElement view element} from the map.
96
- *
97
- * **Note:** view-to-model binding will be removed, if it existed. However, corresponding model-to-view binding
98
- * will be removed only if model element is still bound to the passed `viewElement`.
99
- *
100
- * This behavior allows for re-binding model element to another view element without fear of losing the new binding
101
- * when the previously bound view element is unbound.
102
- *
103
- * @param viewElement View element to unbind.
104
- * @param options The options object.
105
- * @param options.defer Controls whether the binding should be removed immediately or deferred until a
106
- * {@link #flushDeferredBindings `flushDeferredBindings()`} call.
107
- */
108
- unbindViewElement(viewElement: ViewElement, options?: {
109
- defer?: boolean;
110
- }): void;
111
- /**
112
- * Unbinds the given {@link module:engine/model/element~ModelElement model element} from the map.
113
- *
114
- * **Note:** the model-to-view binding will be removed, if it existed. However, the corresponding view-to-model binding
115
- * will be removed only if the view element is still bound to the passed `modelElement`.
116
- *
117
- * This behavior lets for re-binding view element to another model element without fear of losing the new binding
118
- * when the previously bound model element is unbound.
119
- *
120
- * @param modelElement Model element to unbind.
121
- */
122
- unbindModelElement(modelElement: ModelElement): void;
123
- /**
124
- * Binds the given marker name with the given {@link module:engine/view/element~ViewElement view element}. The element
125
- * will be added to the current set of elements bound with the given marker name.
126
- *
127
- * @param element Element to bind.
128
- * @param name Marker name.
129
- */
130
- bindElementToMarker(element: ViewElement, name: string): void;
131
- /**
132
- * Unbinds an element from given marker name.
133
- *
134
- * @param element Element to unbind.
135
- * @param name Marker name.
136
- */
137
- unbindElementFromMarkerName(element: ViewElement, name: string): void;
138
- /**
139
- * Returns all marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
140
- * has been removed, moved or renamed) since the last flush. After returning, the marker names list is cleared.
141
- */
142
- flushUnboundMarkerNames(): Array<string>;
143
- /**
144
- * Unbinds all deferred binding removals of view elements that in the meantime were not re-attached to some root or document fragment.
145
- *
146
- * See: {@link #unbindViewElement `unbindViewElement()`}.
147
- */
148
- flushDeferredBindings(): void;
149
- /**
150
- * Removes all model to view and view to model bindings.
151
- */
152
- clearBindings(): void;
153
- /**
154
- * Gets the corresponding model element.
155
- *
156
- * **Note:** {@link module:engine/view/uielement~ViewUIElement} does not have corresponding element in model.
157
- *
158
- * @label ELEMENT
159
- * @param viewElement View element.
160
- * @returns Corresponding model element or `undefined` if not found.
161
- */
162
- toModelElement(viewElement: ViewElement): ModelElement | undefined;
163
- /**
164
- * Gets the corresponding model document fragment.
165
- *
166
- * @label DOCUMENT_FRAGMENT
167
- * @param viewDocumentFragment View document fragment.
168
- * @returns Corresponding model document fragment or `undefined` if not found.
169
- */
170
- toModelElement(viewDocumentFragment: ViewDocumentFragment): ModelDocumentFragment | undefined;
171
- /**
172
- * Gets the corresponding view element.
173
- *
174
- * @label ELEMENT
175
- * @param modelElement Model element.
176
- * @returns Corresponding view element or `undefined` if not found.
177
- */
178
- toViewElement(modelElement: ModelElement): ViewElement | undefined;
179
- /**
180
- * Gets the corresponding view document fragment.
181
- *
182
- * @label DOCUMENT_FRAGMENT
183
- * @param modelDocumentFragment Model document fragment.
184
- * @returns Corresponding view document fragment or `undefined` if not found.
185
- */
186
- toViewElement(modelDocumentFragment: ModelDocumentFragment): ViewDocumentFragment | undefined;
187
- /**
188
- * Gets the corresponding model range.
189
- *
190
- * @param viewRange View range.
191
- * @returns Corresponding model range.
192
- */
193
- toModelRange(viewRange: ViewRange): ModelRange;
194
- /**
195
- * Gets the corresponding view range.
196
- *
197
- * @param modelRange Model range.
198
- * @returns Corresponding view range.
199
- */
200
- toViewRange(modelRange: ModelRange): ViewRange;
201
- /**
202
- * Gets the corresponding model position.
203
- *
204
- * @fires viewToModelPosition
205
- * @param viewPosition View position.
206
- * @returns Corresponding model position.
207
- */
208
- toModelPosition(viewPosition: ViewPosition): ModelPosition;
209
- /**
210
- * Gets the corresponding view position.
211
- *
212
- * @fires modelToViewPosition
213
- * @param modelPosition Model position.
214
- * @param options Additional options for position mapping process.
215
- * @param options.isPhantom Should be set to `true` if the model position to map is pointing to a place
216
- * in model tree which no longer exists. For example, it could be an end of a removed model range.
217
- * @returns Corresponding view position.
218
- */
219
- toViewPosition(modelPosition: ModelPosition, options?: {
220
- isPhantom?: boolean;
221
- }): ViewPosition;
222
- /**
223
- * Gets all view elements bound to the given marker name.
224
- *
225
- * @param name Marker name.
226
- * @returns View elements bound with the given marker name or `null`
227
- * if no elements are bound to the given marker name.
228
- */
229
- markerNameToElements(name: string): Set<ViewElement> | null;
230
- /**
231
- * **This method is deprecated and will be removed in one of the future CKEditor 5 releases.**
232
- *
233
- * **Using this method will turn off `Mapper` caching system and may degrade performance when operating on bigger documents.**
234
- *
235
- * Registers a callback that evaluates the length in the model of a view element with the given name.
236
- *
237
- * The callback is fired with one argument, which is a view element instance. The callback is expected to return
238
- * a number representing the length of the view element in the model.
239
- *
240
- * ```ts
241
- * // List item in view may contain nested list, which have other list items. In model though,
242
- * // the lists are represented by flat structure. Because of those differences, length of list view element
243
- * // may be greater than one. In the callback it's checked how many nested list items are in evaluated list item.
244
- *
245
- * function getViewListItemLength( element ) {
246
- * let length = 1;
247
- *
248
- * for ( let child of element.getChildren() ) {
249
- * if ( child.name == 'ul' || child.name == 'ol' ) {
250
- * for ( let item of child.getChildren() ) {
251
- * length += getViewListItemLength( item );
252
- * }
253
- * }
254
- * }
255
- *
256
- * return length;
257
- * }
258
- *
259
- * mapper.registerViewToModelLength( 'li', getViewListItemLength );
260
- * ```
261
- *
262
- * @param viewElementName Name of view element for which callback is registered.
263
- * @param lengthCallback Function return a length of view element instance in model.
264
- * @deprecated
265
- */
266
- registerViewToModelLength(viewElementName: string, lengthCallback: (element: ViewElement) => number): void;
267
- /**
268
- * For the given `viewPosition`, finds and returns the closest ancestor of this position that has a mapping to
269
- * the model.
270
- *
271
- * @param viewPosition Position for which a mapped ancestor should be found.
272
- */
273
- findMappedViewAncestor(viewPosition: ViewPosition): ViewElement;
274
- /**
275
- * Calculates model offset based on the view position and the block element.
276
- *
277
- * Example:
278
- *
279
- * ```html
280
- * <p>foo<b>ba|r</b></p> // _toModelOffset( b, 2, p ) -> 5
281
- * ```
282
- *
283
- * Is a sum of:
284
- *
285
- * ```html
286
- * <p>foo|<b>bar</b></p> // _toModelOffset( p, 3, p ) -> 3
287
- * <p>foo<b>ba|r</b></p> // _toModelOffset( b, 2, b ) -> 2
288
- * ```
289
- *
290
- * @param viewParent Position parent.
291
- * @param viewOffset Position offset.
292
- * @param viewBlock Block used as a base to calculate offset.
293
- * @returns Offset in the model.
294
- */
295
- private _toModelOffset;
296
- /**
297
- * Gets the length of the view element in the model.
298
- *
299
- * The length is calculated as follows:
300
- * * if a {@link #registerViewToModelLength length mapping callback} is provided for the given `viewNode`, it is used to
301
- * evaluate the model length (`viewNode` is used as first and only parameter passed to the callback),
302
- * * length of a {@link module:engine/view/text~ViewText text node} is equal to the length of its
303
- * {@link module:engine/view/text~ViewText#data data},
304
- * * length of a {@link module:engine/view/uielement~ViewUIElement ui element} is equal to 0,
305
- * * length of a mapped {@link module:engine/view/element~ViewElement element} is equal to 1,
306
- * * length of a non-mapped {@link module:engine/view/element~ViewElement element} is equal to the length of its children.
307
- *
308
- * Examples:
309
- *
310
- * ```
311
- * foo -> 3 // Text length is equal to its data length.
312
- * <p>foo</p> -> 1 // Length of an element which is mapped is by default equal to 1.
313
- * <b>foo</b> -> 3 // Length of an element which is not mapped is a length of its children.
314
- * <div><p>x</p><p>y</p></div> -> 2 // Assuming that <div> is not mapped and <p> are mapped.
315
- * ```
316
- *
317
- * @param viewNode View node.
318
- * @returns Length of the node in the tree model.
319
- */
320
- getModelLength(viewNode: ViewNode | ViewDocumentFragment): number;
321
- /**
322
- * Finds the position in a view element or view document fragment node (or in its children) with the expected model offset.
323
- *
324
- * If the passed `viewContainer` is bound to model, `Mapper` will use caching mechanism to improve performance.
325
- *
326
- * @param viewContainer Tree view element in which we are looking for the position.
327
- * @param modelOffset Expected offset.
328
- * @returns Found position.
329
- */
330
- findPositionIn(viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): ViewPosition;
331
- /**
332
- * Performs most of the logic for `Mapper#findPositionIn()`.
333
- *
334
- * It allows to start looking for the requested model offset from a given starting position, to enable caching. Using the cache,
335
- * you can set the starting point and skip all the calculations that were already previously done.
336
- *
337
- * This method uses recursion to find positions inside deep structures. Example:
338
- *
339
- * ```
340
- * <p>fo<b>bar</b>bom</p> -> target offset: 4
341
- * <p>|fo<b>bar</b>bom</p> -> target offset: 4, traversed offset: 0
342
- * <p>fo|<b>bar</b>bom</p> -> target offset: 4, traversed offset: 2
343
- * <p>fo<b>bar</b>|bom</p> -> target offset: 4, traversed offset: 5 -> we are too far, look recursively in <b>.
344
- *
345
- * <p>fo<b>|bar</b>bom</p> -> target offset: 4, traversed offset: 2
346
- * <p>fo<b>bar|</b>bom</p> -> target offset: 4, traversed offset: 5 -> we are too far, look inside "bar".
347
- *
348
- * <p>fo<b>ba|r</b>bom</p> -> target offset: 4, traversed offset: 2 -> position is inside text node at offset 4-2 = 2.
349
- * ```
350
- *
351
- * @param startViewPosition View position to start looking from.
352
- * @param startModelOffset Model offset related to `startViewPosition`.
353
- * @param targetModelOffset Target model offset to find.
354
- * @param viewContainer Mapped ancestor of `startViewPosition`. `startModelOffset` is the offset inside a model element or model
355
- * document fragment mapped to `viewContainer`.
356
- * @param useCache Whether `Mapper` should cache positions while traversing the view tree looking for `expectedModelOffset`.
357
- * @returns View position mapped to `targetModelOffset`.
358
- */
359
- private _findPositionStartingFrom;
360
- /**
361
- * Gets the length of the view element in the model and updates cache values after each view item it visits.
362
- *
363
- * See also {@link #getModelLength}.
364
- *
365
- * @param viewNode View node.
366
- * @param viewContainer Ancestor of `viewNode` that is a mapped view element.
367
- * @param modelOffset Model offset at which the `viewNode` starts.
368
- * @returns Length of the node in the tree model.
369
- */
370
- private _getModelLengthAndCache;
371
- /**
372
- * Because we prefer positions in the text nodes over positions next to text nodes, if the view position was next to a text node,
373
- * it moves it into the text node instead.
374
- *
375
- * ```
376
- * <p>[]<b>foo</b></p> -> <p>[]<b>foo</b></p> // do not touch if position is not directly next to text
377
- * <p>foo[]<b>foo</b></p> -> <p>foo{}<b>foo</b></p> // move to text node
378
- * <p><b>[]foo</b></p> -> <p><b>{}foo</b></p> // move to text node
379
- * ```
380
- *
381
- * @param viewPosition Position potentially next to the text node.
382
- * @returns Position in the text node if possible.
383
- */
384
- private _moveViewPositionToTextNode;
21
+ * Maps elements, positions and markers between the {@link module:engine/view/document~ViewDocument view} and
22
+ * the {@link module:engine/model/model model}.
23
+ *
24
+ * The instance of the Mapper used for the editing pipeline is available in
25
+ * {@link module:engine/controller/editingcontroller~EditingController#mapper `editor.editing.mapper`}.
26
+ *
27
+ * Mapper uses bound elements to find corresponding elements and positions, so, to get proper results,
28
+ * all model elements should be {@link module:engine/conversion/mapper~Mapper#bindElements bound}.
29
+ *
30
+ * To map the complex model to/from view relations, you may provide custom callbacks for the
31
+ * {@link module:engine/conversion/mapper~Mapper#event:modelToViewPosition modelToViewPosition event} and
32
+ * {@link module:engine/conversion/mapper~Mapper#event:viewToModelPosition viewToModelPosition event} that are fired whenever
33
+ * a position mapping request occurs.
34
+ * Those events are fired by the {@link module:engine/conversion/mapper~Mapper#toViewPosition toViewPosition}
35
+ * and {@link module:engine/conversion/mapper~Mapper#toModelPosition toModelPosition} methods. `Mapper` adds its own default callbacks
36
+ * with `'lowest'` priority. To override default `Mapper` mapping, add custom callback with higher priority and
37
+ * stop the event.
38
+ */
39
+ export declare class Mapper extends MapperBase {
40
+ /**
41
+ * Model element to view element mapping.
42
+ */
43
+ private _modelToViewMapping;
44
+ /**
45
+ * View element to model element mapping.
46
+ */
47
+ private _viewToModelMapping;
48
+ /**
49
+ * A map containing callbacks between view element names and functions evaluating length of view elements
50
+ * in model.
51
+ */
52
+ private _viewToModelLengthCallbacks;
53
+ /**
54
+ * Model marker name to view elements mapping.
55
+ *
56
+ * Keys are `String`s while values are `Set`s with {@link module:engine/view/element~ViewElement view elements}.
57
+ * One marker (name) can be mapped to multiple elements.
58
+ */
59
+ private _markerNameToElements;
60
+ /**
61
+ * View element to model marker names mapping.
62
+ *
63
+ * This is reverse to {@link ~Mapper#_markerNameToElements} map.
64
+ */
65
+ private _elementToMarkerNames;
66
+ /**
67
+ * The map of removed view elements with their current root (used for deferred unbinding).
68
+ */
69
+ private _deferredBindingRemovals;
70
+ /**
71
+ * Stores marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
72
+ * has been removed, moved or renamed).
73
+ */
74
+ private _unboundMarkerNames;
75
+ /**
76
+ * Manages dynamic cache for the `Mapper` to improve the performance.
77
+ */
78
+ private _cache;
79
+ /**
80
+ * Creates an instance of the mapper.
81
+ */
82
+ constructor();
83
+ /**
84
+ * Marks model and view elements as corresponding. Corresponding elements can be retrieved by using
85
+ * the {@link module:engine/conversion/mapper~Mapper#toModelElement toModelElement} and
86
+ * {@link module:engine/conversion/mapper~Mapper#toViewElement toViewElement} methods.
87
+ * The information that elements are bound is also used to translate positions.
88
+ *
89
+ * @param modelElement Model element.
90
+ * @param viewElement View element.
91
+ */
92
+ bindElements(modelElement: ModelElement | ModelDocumentFragment, viewElement: ViewElement | ViewDocumentFragment): void;
93
+ /**
94
+ * Unbinds the given {@link module:engine/view/element~ViewElement view element} from the map.
95
+ *
96
+ * **Note:** view-to-model binding will be removed, if it existed. However, corresponding model-to-view binding
97
+ * will be removed only if model element is still bound to the passed `viewElement`.
98
+ *
99
+ * This behavior allows for re-binding model element to another view element without fear of losing the new binding
100
+ * when the previously bound view element is unbound.
101
+ *
102
+ * @param viewElement View element to unbind.
103
+ * @param options The options object.
104
+ * @param options.defer Controls whether the binding should be removed immediately or deferred until a
105
+ * {@link #flushDeferredBindings `flushDeferredBindings()`} call.
106
+ */
107
+ unbindViewElement(viewElement: ViewElement, options?: {
108
+ defer?: boolean;
109
+ }): void;
110
+ /**
111
+ * Unbinds the given {@link module:engine/model/element~ModelElement model element} from the map.
112
+ *
113
+ * **Note:** the model-to-view binding will be removed, if it existed. However, the corresponding view-to-model binding
114
+ * will be removed only if the view element is still bound to the passed `modelElement`.
115
+ *
116
+ * This behavior lets for re-binding view element to another model element without fear of losing the new binding
117
+ * when the previously bound model element is unbound.
118
+ *
119
+ * @param modelElement Model element to unbind.
120
+ */
121
+ unbindModelElement(modelElement: ModelElement): void;
122
+ /**
123
+ * Binds the given marker name with the given {@link module:engine/view/element~ViewElement view element}. The element
124
+ * will be added to the current set of elements bound with the given marker name.
125
+ *
126
+ * @param element Element to bind.
127
+ * @param name Marker name.
128
+ */
129
+ bindElementToMarker(element: ViewElement, name: string): void;
130
+ /**
131
+ * Unbinds an element from given marker name.
132
+ *
133
+ * @param element Element to unbind.
134
+ * @param name Marker name.
135
+ */
136
+ unbindElementFromMarkerName(element: ViewElement, name: string): void;
137
+ /**
138
+ * Returns all marker names of markers which have changed due to unbinding a view element (so it is assumed that the view element
139
+ * has been removed, moved or renamed) since the last flush. After returning, the marker names list is cleared.
140
+ */
141
+ flushUnboundMarkerNames(): Array<string>;
142
+ /**
143
+ * Unbinds all deferred binding removals of view elements that in the meantime were not re-attached to some root or document fragment.
144
+ *
145
+ * See: {@link #unbindViewElement `unbindViewElement()`}.
146
+ */
147
+ flushDeferredBindings(): void;
148
+ /**
149
+ * Removes all model to view and view to model bindings.
150
+ */
151
+ clearBindings(): void;
152
+ /**
153
+ * Gets the corresponding model element.
154
+ *
155
+ * **Note:** {@link module:engine/view/uielement~ViewUIElement} does not have corresponding element in model.
156
+ *
157
+ * @label ELEMENT
158
+ * @param viewElement View element.
159
+ * @returns Corresponding model element or `undefined` if not found.
160
+ */
161
+ toModelElement(viewElement: ViewElement): ModelElement | undefined;
162
+ /**
163
+ * Gets the corresponding model document fragment.
164
+ *
165
+ * @label DOCUMENT_FRAGMENT
166
+ * @param viewDocumentFragment View document fragment.
167
+ * @returns Corresponding model document fragment or `undefined` if not found.
168
+ */
169
+ toModelElement(viewDocumentFragment: ViewDocumentFragment): ModelDocumentFragment | undefined;
170
+ /**
171
+ * Gets the corresponding view element.
172
+ *
173
+ * @label ELEMENT
174
+ * @param modelElement Model element.
175
+ * @returns Corresponding view element or `undefined` if not found.
176
+ */
177
+ toViewElement(modelElement: ModelElement): ViewElement | undefined;
178
+ /**
179
+ * Gets the corresponding view document fragment.
180
+ *
181
+ * @label DOCUMENT_FRAGMENT
182
+ * @param modelDocumentFragment Model document fragment.
183
+ * @returns Corresponding view document fragment or `undefined` if not found.
184
+ */
185
+ toViewElement(modelDocumentFragment: ModelDocumentFragment): ViewDocumentFragment | undefined;
186
+ /**
187
+ * Gets the corresponding model range.
188
+ *
189
+ * @param viewRange View range.
190
+ * @returns Corresponding model range.
191
+ */
192
+ toModelRange(viewRange: ViewRange): ModelRange;
193
+ /**
194
+ * Gets the corresponding view range.
195
+ *
196
+ * @param modelRange Model range.
197
+ * @returns Corresponding view range.
198
+ */
199
+ toViewRange(modelRange: ModelRange): ViewRange;
200
+ /**
201
+ * Gets the corresponding model position.
202
+ *
203
+ * @fires viewToModelPosition
204
+ * @param viewPosition View position.
205
+ * @returns Corresponding model position.
206
+ */
207
+ toModelPosition(viewPosition: ViewPosition): ModelPosition;
208
+ /**
209
+ * Gets the corresponding view position.
210
+ *
211
+ * @fires modelToViewPosition
212
+ * @param modelPosition Model position.
213
+ * @param options Additional options for position mapping process.
214
+ * @param options.isPhantom Should be set to `true` if the model position to map is pointing to a place
215
+ * in model tree which no longer exists. For example, it could be an end of a removed model range.
216
+ * @returns Corresponding view position.
217
+ */
218
+ toViewPosition(modelPosition: ModelPosition, options?: {
219
+ isPhantom?: boolean;
220
+ }): ViewPosition;
221
+ /**
222
+ * Gets all view elements bound to the given marker name.
223
+ *
224
+ * @param name Marker name.
225
+ * @returns View elements bound with the given marker name or `null`
226
+ * if no elements are bound to the given marker name.
227
+ */
228
+ markerNameToElements(name: string): Set<ViewElement> | null;
229
+ /**
230
+ * **This method is deprecated and will be removed in one of the future CKEditor 5 releases.**
231
+ *
232
+ * **Using this method will turn off `Mapper` caching system and may degrade performance when operating on bigger documents.**
233
+ *
234
+ * Registers a callback that evaluates the length in the model of a view element with the given name.
235
+ *
236
+ * The callback is fired with one argument, which is a view element instance. The callback is expected to return
237
+ * a number representing the length of the view element in the model.
238
+ *
239
+ * ```ts
240
+ * // List item in view may contain nested list, which have other list items. In model though,
241
+ * // the lists are represented by flat structure. Because of those differences, length of list view element
242
+ * // may be greater than one. In the callback it's checked how many nested list items are in evaluated list item.
243
+ *
244
+ * function getViewListItemLength( element ) {
245
+ * let length = 1;
246
+ *
247
+ * for ( let child of element.getChildren() ) {
248
+ * if ( child.name == 'ul' || child.name == 'ol' ) {
249
+ * for ( let item of child.getChildren() ) {
250
+ * length += getViewListItemLength( item );
251
+ * }
252
+ * }
253
+ * }
254
+ *
255
+ * return length;
256
+ * }
257
+ *
258
+ * mapper.registerViewToModelLength( 'li', getViewListItemLength );
259
+ * ```
260
+ *
261
+ * @param viewElementName Name of view element for which callback is registered.
262
+ * @param lengthCallback Function return a length of view element instance in model.
263
+ * @deprecated
264
+ */
265
+ registerViewToModelLength(viewElementName: string, lengthCallback: (element: ViewElement) => number): void;
266
+ /**
267
+ * For the given `viewPosition`, finds and returns the closest ancestor of this position that has a mapping to
268
+ * the model.
269
+ *
270
+ * @param viewPosition Position for which a mapped ancestor should be found.
271
+ */
272
+ findMappedViewAncestor(viewPosition: ViewPosition): ViewElement;
273
+ /**
274
+ * Calculates model offset based on the view position and the block element.
275
+ *
276
+ * Example:
277
+ *
278
+ * ```html
279
+ * <p>foo<b>ba|r</b></p> // _toModelOffset( b, 2, p ) -> 5
280
+ * ```
281
+ *
282
+ * Is a sum of:
283
+ *
284
+ * ```html
285
+ * <p>foo|<b>bar</b></p> // _toModelOffset( p, 3, p ) -> 3
286
+ * <p>foo<b>ba|r</b></p> // _toModelOffset( b, 2, b ) -> 2
287
+ * ```
288
+ *
289
+ * @param viewParent Position parent.
290
+ * @param viewOffset Position offset.
291
+ * @param viewBlock Block used as a base to calculate offset.
292
+ * @returns Offset in the model.
293
+ */
294
+ private _toModelOffset;
295
+ /**
296
+ * Gets the length of the view element in the model.
297
+ *
298
+ * The length is calculated as follows:
299
+ * * if a {@link #registerViewToModelLength length mapping callback} is provided for the given `viewNode`, it is used to
300
+ * evaluate the model length (`viewNode` is used as first and only parameter passed to the callback),
301
+ * * length of a {@link module:engine/view/text~ViewText text node} is equal to the length of its
302
+ * {@link module:engine/view/text~ViewText#data data},
303
+ * * length of a {@link module:engine/view/uielement~ViewUIElement ui element} is equal to 0,
304
+ * * length of a mapped {@link module:engine/view/element~ViewElement element} is equal to 1,
305
+ * * length of a non-mapped {@link module:engine/view/element~ViewElement element} is equal to the length of its children.
306
+ *
307
+ * Examples:
308
+ *
309
+ * ```
310
+ * foo -> 3 // Text length is equal to its data length.
311
+ * <p>foo</p> -> 1 // Length of an element which is mapped is by default equal to 1.
312
+ * <b>foo</b> -> 3 // Length of an element which is not mapped is a length of its children.
313
+ * <div><p>x</p><p>y</p></div> -> 2 // Assuming that <div> is not mapped and <p> are mapped.
314
+ * ```
315
+ *
316
+ * @param viewNode View node.
317
+ * @returns Length of the node in the tree model.
318
+ */
319
+ getModelLength(viewNode: ViewNode | ViewDocumentFragment): number;
320
+ /**
321
+ * Finds the position in a view element or view document fragment node (or in its children) with the expected model offset.
322
+ *
323
+ * If the passed `viewContainer` is bound to model, `Mapper` will use caching mechanism to improve performance.
324
+ *
325
+ * @param viewContainer Tree view element in which we are looking for the position.
326
+ * @param modelOffset Expected offset.
327
+ * @returns Found position.
328
+ */
329
+ findPositionIn(viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): ViewPosition;
330
+ /**
331
+ * Performs most of the logic for `Mapper#findPositionIn()`.
332
+ *
333
+ * It allows to start looking for the requested model offset from a given starting position, to enable caching. Using the cache,
334
+ * you can set the starting point and skip all the calculations that were already previously done.
335
+ *
336
+ * This method uses recursion to find positions inside deep structures. Example:
337
+ *
338
+ * ```
339
+ * <p>fo<b>bar</b>bom</p> -> target offset: 4
340
+ * <p>|fo<b>bar</b>bom</p> -> target offset: 4, traversed offset: 0
341
+ * <p>fo|<b>bar</b>bom</p> -> target offset: 4, traversed offset: 2
342
+ * <p>fo<b>bar</b>|bom</p> -> target offset: 4, traversed offset: 5 -> we are too far, look recursively in <b>.
343
+ *
344
+ * <p>fo<b>|bar</b>bom</p> -> target offset: 4, traversed offset: 2
345
+ * <p>fo<b>bar|</b>bom</p> -> target offset: 4, traversed offset: 5 -> we are too far, look inside "bar".
346
+ *
347
+ * <p>fo<b>ba|r</b>bom</p> -> target offset: 4, traversed offset: 2 -> position is inside text node at offset 4-2 = 2.
348
+ * ```
349
+ *
350
+ * @param startViewPosition View position to start looking from.
351
+ * @param startModelOffset Model offset related to `startViewPosition`.
352
+ * @param targetModelOffset Target model offset to find.
353
+ * @param viewContainer Mapped ancestor of `startViewPosition`. `startModelOffset` is the offset inside a model element or model
354
+ * document fragment mapped to `viewContainer`.
355
+ * @param useCache Whether `Mapper` should cache positions while traversing the view tree looking for `expectedModelOffset`.
356
+ * @returns View position mapped to `targetModelOffset`.
357
+ */
358
+ private _findPositionStartingFrom;
359
+ /**
360
+ * Gets the length of the view element in the model and updates cache values after each view item it visits.
361
+ *
362
+ * See also {@link #getModelLength}.
363
+ *
364
+ * @param viewNode View node.
365
+ * @param viewContainer Ancestor of `viewNode` that is a mapped view element.
366
+ * @param modelOffset Model offset at which the `viewNode` starts.
367
+ * @returns Length of the node in the tree model.
368
+ */
369
+ private _getModelLengthAndCache;
370
+ /**
371
+ * Because we prefer positions in the text nodes over positions next to text nodes, if the view position was next to a text node,
372
+ * it moves it into the text node instead.
373
+ *
374
+ * ```
375
+ * <p>[]<b>foo</b></p> -> <p>[]<b>foo</b></p> // do not touch if position is not directly next to text
376
+ * <p>foo[]<b>foo</b></p> -> <p>foo{}<b>foo</b></p> // move to text node
377
+ * <p><b>[]foo</b></p> -> <p><b>{}foo</b></p> // move to text node
378
+ * ```
379
+ *
380
+ * @param viewPosition Position potentially next to the text node.
381
+ * @returns Position in the text node if possible.
382
+ */
383
+ private _moveViewPositionToTextNode;
385
384
  }
386
- declare const MapperCache_base: {
387
- new (): import("@ckeditor/ckeditor5-utils").Emitter;
388
- prototype: import("@ckeditor/ckeditor5-utils").Emitter;
389
- };
390
385
  /**
391
- * Cache mechanism for {@link module:engine/conversion/mapper~Mapper Mapper}.
392
- *
393
- * `MapperCache` improves performance for model-to-view position mapping, which is the main `Mapper` task. Asking for a mapping is much
394
- * more frequent than actually performing changes, and even if the change happens, we can still partially keep the cache. This makes
395
- * caching a useful strategy for `Mapper`.
396
- *
397
- * `MapperCache` will store some data for view elements or view document fragments that are mapped by the `Mapper`. These view items
398
- * are "tracked" by the `MapperCache`. For such view items, we will keep entries of model offsets inside their mapped counterpart. For
399
- * the cached model offsets, we will keep a view position that is inside the tracked item. This allows us to either get the mapping
400
- * instantly, or at least in less steps than when calculating it from the beginning.
401
- *
402
- * Important problem related to caching is invalidating the cache. The cache must be invalidated each time the tracked view item changes.
403
- * Additionally, we should invalidate as small part of the cache as possible. Since all the logic is encapsulated inside `MapperCache`,
404
- * the `MapperCache` listens to view items {@link module:engine/view/node~ViewNodeChangeEvent `change` event} and reacts to it.
405
- * Then, it invalidates just the part of the cache that is "after" the changed part of the view.
406
- *
407
- * As mentioned, `MapperCache` currently is used only for model-to-view position mapping as it was much bigger problem than view-to-model
408
- * mapping. However, it should be possible to use it also for view-to-model.
409
- *
410
- * The main assumptions regarding `MapperCache` are:
411
- *
412
- * * it is an internal tool, used by `Mapper`, transparent to the outside (no additional effort when developing a plugin or a converter),
413
- * * it stores all the necessary data internally, which makes it easier to disable or debug,
414
- * * it is optimized for initial downcast process (long insertions), which is crucial for editor init and data save,
415
- * * it does not save all possible positions mapping for memory considerations, although it is a possible improvement, which may increase
416
- * performance, as well as simplify some parts of the `MapperCache` logic.
417
- *
418
- * @internal
419
- */
420
- export declare class MapperCache extends /* #__PURE__ */ MapperCache_base {
421
- /**
422
- * For every view element or document fragment tracked by `MapperCache`, it holds currently cached data, or more precisely,
423
- * model offset to view position mappings. See also `MappingCache` and `CacheItem`.
424
- *
425
- * If an item is tracked by `MapperCache` it has an entry in this structure, so this structure can be used to check which items
426
- * are tracked by `MapperCache`. When an item is no longer tracked, it is removed from this structure.
427
- *
428
- * Although `MappingCache` and `CacheItem` structures allows for caching any model offsets and view positions, we only cache
429
- * values for model offsets that are after a view node. So, in essence, positions inside text nodes are not cached. However, it takes
430
- * from one to at most a few steps, to get from a cached position to a position that is inside a view text node.
431
- *
432
- * Additionally, only one item per `modelOffset` is cached. There can be several view positions that map to the same `modelOffset`.
433
- * Only the first save for `modelOffset` is stored.
434
- */
435
- private _cachedMapping;
436
- /**
437
- * When `MapperCache` {@link ~MapperCache#save saves} view position -> model offset mapping, a `CacheItem` is inserted into certain
438
- * `MappingCache#cacheList` at some index. Additionally, we store that index with the view node that is before the cached view position.
439
- *
440
- * This allows to quickly get a cache list item related to certain view node, and hence, for fast cache invalidation.
441
- *
442
- * For example, consider view: `<p>Some <strong>bold</strong> text.</p>`, where `<p>` is a view element tracked by `MapperCache`.
443
- * If all `<p>` children were visited by `MapperCache`, then `<p>` cache list would have four items, related to following model offsets:
444
- * `0`, `5`, `9`, `15`. Then, view node `"Some "` would have index `1`, `<strong>` index `2`, and `" text." index `3`.
445
- *
446
- * Note that the index related with a node is always greater than `0`. The first item in cache list is always for model offset `0`
447
- * (and view offset `0`), and it is not related to any node.
448
- */
449
- private _nodeToCacheListIndex;
450
- /**
451
- * Callback fired whenever there is a direct or indirect children change in tracked view element or tracked view document fragment.
452
- *
453
- * This is specified as a property to make it easier to set as an event callback and to later turn off that event.
454
- */
455
- private _invalidateOnChildrenChangeCallback;
456
- /**
457
- * Callback fired whenever a view text node directly or indirectly inside a tracked view element or tracked view document fragment
458
- * changes its text data.
459
- *
460
- * This is specified as a property to make it easier to set as an event callback and to later turn off that event.
461
- */
462
- private _invalidateOnTextChangeCallback;
463
- /**
464
- * Saves cache for given view position mapping <-> model offset mapping. The view position should be after a node (i.e. it cannot
465
- * be the first position inside its parent, or in other words, `viewOffset` must be greater than `0`).
466
- *
467
- * Note, that if `modelOffset` for given `viewContainer` was already saved, the stored view position (i.e. parent+offset) will not
468
- * be overwritten. However, it is important to still save it, as we still store additional data related to cached view positions.
469
- *
470
- * @param viewParent View position parent.
471
- * @param viewOffset View position offset. Must be greater than `0`.
472
- * @param viewContainer Tracked view position ascendant (it may be the direct parent of the view position).
473
- * @param modelOffset Model offset in the model element or document fragment which is mapped to `viewContainer`.
474
- */
475
- save(viewParent: ViewElement | ViewDocumentFragment, viewOffset: number, viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): void;
476
- /**
477
- * For given `modelOffset` inside a model element mapped to given `viewContainer`, it returns the closest saved cache item
478
- * (view position and related model offset) to the requested one.
479
- *
480
- * It can be exactly the requested mapping, or it can be mapping that is the closest starting point to look for the requested mapping.
481
- *
482
- * `viewContainer` must be a view element or document fragment that is mapped by the {@link ~Mapper Mapper}.
483
- *
484
- * If `viewContainer` is not yet tracked by the `MapperCache`, it will be automatically tracked after calling this method.
485
- *
486
- * Note: this method will automatically "hoist" cached positions, i.e. it will return a position that is closest to the tracked element.
487
- *
488
- * For example, if `<p>` is tracked element, and `^` is cached position:
489
- *
490
- * ```
491
- * <p>This is <strong>some <em>heavily <u>formatted</u>^</em></strong> text.</p>
492
- * ```
493
- *
494
- * If this position would be returned, instead, a position directly in `<p>` would be returned:
495
- *
496
- * ```
497
- * <p>This is <strong>some <em>heavily <u>formatted</u></em></strong>^ text.</p>
498
- * ```
499
- *
500
- * Note, that `modelOffset` for both positions is the same.
501
- *
502
- * @param viewContainer Tracked view element or document fragment, which cache will be used.
503
- * @param modelOffset Model offset in a model element or document fragment, which is mapped to `viewContainer`.
504
- */
505
- getClosest(viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): CacheItem;
506
- /**
507
- * Starts tracking given `viewContainer`, which must be mapped to a model element or model document fragment.
508
- *
509
- * Note, that this method is automatically called by
510
- * {@link module:engine/conversion/mapper~MapperCache#getClosest `MapperCache#getClosest()`} and there is no need to call it manually.
511
- *
512
- * This method initializes the cache for `viewContainer` and adds callbacks for
513
- * {@link module:engine/view/node~ViewNodeChangeEvent `change` event} fired by `viewContainer`. `MapperCache` listens to `change` event
514
- * on the tracked elements to invalidate the stored cache.
515
- */
516
- startTracking(viewContainer: ViewElement | ViewDocumentFragment): CacheItem;
517
- /**
518
- * Stops tracking given `viewContainer`.
519
- *
520
- * It removes the cached data and stops listening to {@link module:engine/view/node~ViewNodeChangeEvent `change` event} on the
521
- * `viewContainer`.
522
- */
523
- stopTracking(viewContainer: ViewElement | ViewDocumentFragment): void;
524
- /**
525
- * Invalidates cache inside `viewParent`, starting from given `index` in that parent.
526
- *
527
- * This method may clear a bit more cache than just what was saved after given `index`, but it is guaranteed that at least it
528
- * will invalidate everything after `index`.
529
- */
530
- private _clearCacheInsideParent;
531
- /**
532
- * Clears all the cache for given tracked `viewContainer`.
533
- */
534
- private _clearCacheAll;
535
- /**
536
- * Clears all the stored cache that is after given `viewNode`. The `viewNode` can be any node that is inside a tracked view element
537
- * or view document fragment.
538
- *
539
- * In reality, this function may clear a bit more cache than just "starting after" `viewNode`, but it is guaranteed that at least
540
- * all cache after `viewNode` is invalidated.
541
- */
542
- private _clearCacheAfter;
543
- /**
544
- * Clears all the cache in the cache list related to given `viewContainer`, starting from `index` (inclusive).
545
- */
546
- private _clearCacheFromCacheIndex;
547
- /**
548
- * Finds a cache item in the given cache list, which `modelOffset` is closest (but smaller or equal) to given `offset`.
549
- *
550
- * Since `cacheList` is a sorted array, this uses binary search to retrieve the item quickly.
551
- */
552
- private _findInCacheList;
386
+ * Cache mechanism for {@link module:engine/conversion/mapper~Mapper Mapper}.
387
+ *
388
+ * `MapperCache` improves performance for model-to-view position mapping, which is the main `Mapper` task. Asking for a mapping is much
389
+ * more frequent than actually performing changes, and even if the change happens, we can still partially keep the cache. This makes
390
+ * caching a useful strategy for `Mapper`.
391
+ *
392
+ * `MapperCache` will store some data for view elements or view document fragments that are mapped by the `Mapper`. These view items
393
+ * are "tracked" by the `MapperCache`. For such view items, we will keep entries of model offsets inside their mapped counterpart. For
394
+ * the cached model offsets, we will keep a view position that is inside the tracked item. This allows us to either get the mapping
395
+ * instantly, or at least in less steps than when calculating it from the beginning.
396
+ *
397
+ * Important problem related to caching is invalidating the cache. The cache must be invalidated each time the tracked view item changes.
398
+ * Additionally, we should invalidate as small part of the cache as possible. Since all the logic is encapsulated inside `MapperCache`,
399
+ * the `MapperCache` listens to view items {@link module:engine/view/node~ViewNodeChangeEvent `change` event} and reacts to it.
400
+ * Then, it invalidates just the part of the cache that is "after" the changed part of the view.
401
+ *
402
+ * As mentioned, `MapperCache` currently is used only for model-to-view position mapping as it was much bigger problem than view-to-model
403
+ * mapping. However, it should be possible to use it also for view-to-model.
404
+ *
405
+ * The main assumptions regarding `MapperCache` are:
406
+ *
407
+ * * it is an internal tool, used by `Mapper`, transparent to the outside (no additional effort when developing a plugin or a converter),
408
+ * * it stores all the necessary data internally, which makes it easier to disable or debug,
409
+ * * it is optimized for initial downcast process (long insertions), which is crucial for editor init and data save,
410
+ * * it does not save all possible positions mapping for memory considerations, although it is a possible improvement, which may increase
411
+ * performance, as well as simplify some parts of the `MapperCache` logic.
412
+ *
413
+ * @internal
414
+ */
415
+ export declare class MapperCache extends MapperCacheBase {
416
+ /**
417
+ * For every view element or document fragment tracked by `MapperCache`, it holds currently cached data, or more precisely,
418
+ * model offset to view position mappings. See also `MappingCache` and `CacheItem`.
419
+ *
420
+ * If an item is tracked by `MapperCache` it has an entry in this structure, so this structure can be used to check which items
421
+ * are tracked by `MapperCache`. When an item is no longer tracked, it is removed from this structure.
422
+ *
423
+ * Although `MappingCache` and `CacheItem` structures allows for caching any model offsets and view positions, we only cache
424
+ * values for model offsets that are after a view node. So, in essence, positions inside text nodes are not cached. However, it takes
425
+ * from one to at most a few steps, to get from a cached position to a position that is inside a view text node.
426
+ *
427
+ * Additionally, only one item per `modelOffset` is cached. There can be several view positions that map to the same `modelOffset`.
428
+ * Only the first save for `modelOffset` is stored.
429
+ */
430
+ private _cachedMapping;
431
+ /**
432
+ * When `MapperCache` {@link ~MapperCache#save saves} view position -> model offset mapping, a `CacheItem` is inserted into certain
433
+ * `MappingCache#cacheList` at some index. Additionally, we store that index with the view node that is before the cached view position.
434
+ *
435
+ * This allows to quickly get a cache list item related to certain view node, and hence, for fast cache invalidation.
436
+ *
437
+ * For example, consider view: `<p>Some <strong>bold</strong> text.</p>`, where `<p>` is a view element tracked by `MapperCache`.
438
+ * If all `<p>` children were visited by `MapperCache`, then `<p>` cache list would have four items, related to following model offsets:
439
+ * `0`, `5`, `9`, `15`. Then, view node `"Some "` would have index `1`, `<strong>` index `2`, and `" text." index `3`.
440
+ *
441
+ * Note that the index related with a node is always greater than `0`. The first item in cache list is always for model offset `0`
442
+ * (and view offset `0`), and it is not related to any node.
443
+ */
444
+ private _nodeToCacheListIndex;
445
+ /**
446
+ * Callback fired whenever there is a direct or indirect children change in tracked view element or tracked view document fragment.
447
+ *
448
+ * This is specified as a property to make it easier to set as an event callback and to later turn off that event.
449
+ */
450
+ private _invalidateOnChildrenChangeCallback;
451
+ /**
452
+ * Callback fired whenever a view text node directly or indirectly inside a tracked view element or tracked view document fragment
453
+ * changes its text data.
454
+ *
455
+ * This is specified as a property to make it easier to set as an event callback and to later turn off that event.
456
+ */
457
+ private _invalidateOnTextChangeCallback;
458
+ /**
459
+ * Saves cache for given view position mapping <-> model offset mapping. The view position should be after a node (i.e. it cannot
460
+ * be the first position inside its parent, or in other words, `viewOffset` must be greater than `0`).
461
+ *
462
+ * Note, that if `modelOffset` for given `viewContainer` was already saved, the stored view position (i.e. parent+offset) will not
463
+ * be overwritten. However, it is important to still save it, as we still store additional data related to cached view positions.
464
+ *
465
+ * @param viewParent View position parent.
466
+ * @param viewOffset View position offset. Must be greater than `0`.
467
+ * @param viewContainer Tracked view position ascendant (it may be the direct parent of the view position).
468
+ * @param modelOffset Model offset in the model element or document fragment which is mapped to `viewContainer`.
469
+ */
470
+ save(viewParent: ViewElement | ViewDocumentFragment, viewOffset: number, viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): void;
471
+ /**
472
+ * For given `modelOffset` inside a model element mapped to given `viewContainer`, it returns the closest saved cache item
473
+ * (view position and related model offset) to the requested one.
474
+ *
475
+ * It can be exactly the requested mapping, or it can be mapping that is the closest starting point to look for the requested mapping.
476
+ *
477
+ * `viewContainer` must be a view element or document fragment that is mapped by the {@link ~Mapper Mapper}.
478
+ *
479
+ * If `viewContainer` is not yet tracked by the `MapperCache`, it will be automatically tracked after calling this method.
480
+ *
481
+ * Note: this method will automatically "hoist" cached positions, i.e. it will return a position that is closest to the tracked element.
482
+ *
483
+ * For example, if `<p>` is tracked element, and `^` is cached position:
484
+ *
485
+ * ```
486
+ * <p>This is <strong>some <em>heavily <u>formatted</u>^</em></strong> text.</p>
487
+ * ```
488
+ *
489
+ * If this position would be returned, instead, a position directly in `<p>` would be returned:
490
+ *
491
+ * ```
492
+ * <p>This is <strong>some <em>heavily <u>formatted</u></em></strong>^ text.</p>
493
+ * ```
494
+ *
495
+ * Note, that `modelOffset` for both positions is the same.
496
+ *
497
+ * @param viewContainer Tracked view element or document fragment, which cache will be used.
498
+ * @param modelOffset Model offset in a model element or document fragment, which is mapped to `viewContainer`.
499
+ */
500
+ getClosest(viewContainer: ViewElement | ViewDocumentFragment, modelOffset: number): CacheItem;
501
+ /**
502
+ * Starts tracking given `viewContainer`, which must be mapped to a model element or model document fragment.
503
+ *
504
+ * Note, that this method is automatically called by
505
+ * {@link module:engine/conversion/mapper~MapperCache#getClosest `MapperCache#getClosest()`} and there is no need to call it manually.
506
+ *
507
+ * This method initializes the cache for `viewContainer` and adds callbacks for
508
+ * {@link module:engine/view/node~ViewNodeChangeEvent `change` event} fired by `viewContainer`. `MapperCache` listens to `change` event
509
+ * on the tracked elements to invalidate the stored cache.
510
+ */
511
+ startTracking(viewContainer: ViewElement | ViewDocumentFragment): CacheItem;
512
+ /**
513
+ * Stops tracking given `viewContainer`.
514
+ *
515
+ * It removes the cached data and stops listening to {@link module:engine/view/node~ViewNodeChangeEvent `change` event} on the
516
+ * `viewContainer`.
517
+ */
518
+ stopTracking(viewContainer: ViewElement | ViewDocumentFragment): void;
519
+ /**
520
+ * Invalidates cache inside `viewParent`, starting from given `index` in that parent.
521
+ *
522
+ * This method may clear a bit more cache than just what was saved after given `index`, but it is guaranteed that at least it
523
+ * will invalidate everything after `index`.
524
+ */
525
+ private _clearCacheInsideParent;
526
+ /**
527
+ * Clears all the cache for given tracked `viewContainer`.
528
+ */
529
+ private _clearCacheAll;
530
+ /**
531
+ * Clears all the stored cache that is after given `viewNode`. The `viewNode` can be any node that is inside a tracked view element
532
+ * or view document fragment.
533
+ *
534
+ * In reality, this function may clear a bit more cache than just "starting after" `viewNode`, but it is guaranteed that at least
535
+ * all cache after `viewNode` is invalidated.
536
+ */
537
+ private _clearCacheAfter;
538
+ /**
539
+ * Clears all the cache in the cache list related to given `viewContainer`, starting from `index` (inclusive).
540
+ */
541
+ private _clearCacheFromCacheIndex;
542
+ /**
543
+ * Finds a cache item in the given cache list, which `modelOffset` is closest (but smaller or equal) to given `offset`.
544
+ *
545
+ * Since `cacheList` is a sorted array, this uses binary search to retrieve the item quickly.
546
+ */
547
+ private _findInCacheList;
553
548
  }
554
549
  /**
555
- * Fired for each model-to-view position mapping request. The purpose of this event is to enable custom model-to-view position
556
- * mapping. Callbacks added to this event take {@link module:engine/model/position~ModelPosition model position} and are expected to
557
- * calculate the {@link module:engine/view/position~ViewPosition view position}. The calculated view position should be added as
558
- * a `viewPosition` value in the `data` object that is passed as one of parameters to the event callback.
559
- *
560
- * ```ts
561
- * // Assume that "captionedImage" model element is converted to <img> and following <span> elements in view,
562
- * // and the model element is bound to <img> element. Force mapping model positions inside "captionedImage" to that
563
- * // <span> element.
564
- * mapper.on( 'modelToViewPosition', ( evt, data ) => {
565
- * const positionParent = modelPosition.parent;
566
- *
567
- * if ( positionParent.name == 'captionedImage' ) {
568
- * const viewImg = data.mapper.toViewElement( positionParent );
569
- * const viewCaption = viewImg.nextSibling; // The <span> element.
570
- *
571
- * data.viewPosition = new ViewPosition( viewCaption, modelPosition.offset );
572
- *
573
- * // Stop the event if other callbacks should not modify calculated value.
574
- * evt.stop();
575
- * }
576
- * } );
577
- * ```
578
- *
579
- * **Note:** keep in mind that sometimes a "phantom" model position is being converted. A "phantom" model position is
580
- * a position that points to a nonexistent place in model. Such a position might still be valid for conversion, though
581
- * (it would point to a correct place in the view when converted). One example of such a situation is when a range is
582
- * removed from the model, there may be a need to map the range's end (which is no longer a valid model position). To
583
- * handle such situations, check the `data.isPhantom` flag:
584
- *
585
- * ```ts
586
- * // Assume that there is a "customElement" model element and whenever the position is before it,
587
- * // we want to move it to the inside of the view element bound to "customElement".
588
- * mapper.on( 'modelToViewPosition', ( evt, data ) => {
589
- * if ( data.isPhantom ) {
590
- * return;
591
- * }
592
- *
593
- * // Below line might crash for phantom position that does not exist in model.
594
- * const sibling = data.modelPosition.nodeBefore;
595
- *
596
- * // Check if this is the element we are interested in.
597
- * if ( !sibling.is( 'element', 'customElement' ) ) {
598
- * return;
599
- * }
600
- *
601
- * const viewElement = data.mapper.toViewElement( sibling );
602
- *
603
- * data.viewPosition = new ViewPosition( sibling, 0 );
604
- *
605
- * evt.stop();
606
- * } );
607
- * ```
608
- *
609
- * **Note:** the default mapping callback is provided with a `low` priority setting and does not cancel the event, so it is possible to
610
- * attach a custom callback after a default callback and also use `data.viewPosition` calculated by the default callback
611
- * (for example to fix it).
612
- *
613
- * **Note:** the default mapping callback will not fire if `data.viewPosition` is already set.
614
- *
615
- * **Note:** these callbacks are called **very often**. For efficiency reasons, it is advised to use them only when position
616
- * mapping between the given model and view elements is unsolvable by using just elements mapping and default algorithm.
617
- * Also, the condition that checks if a special case scenario happened should be as simple as possible.
618
- *
619
- * @eventName ~Mapper#modelToViewPosition
620
- */
550
+ * Fired for each model-to-view position mapping request. The purpose of this event is to enable custom model-to-view position
551
+ * mapping. Callbacks added to this event take {@link module:engine/model/position~ModelPosition model position} and are expected to
552
+ * calculate the {@link module:engine/view/position~ViewPosition view position}. The calculated view position should be added as
553
+ * a `viewPosition` value in the `data` object that is passed as one of parameters to the event callback.
554
+ *
555
+ * ```ts
556
+ * // Assume that "captionedImage" model element is converted to <img> and following <span> elements in view,
557
+ * // and the model element is bound to <img> element. Force mapping model positions inside "captionedImage" to that
558
+ * // <span> element.
559
+ * mapper.on( 'modelToViewPosition', ( evt, data ) => {
560
+ * const positionParent = modelPosition.parent;
561
+ *
562
+ * if ( positionParent.name == 'captionedImage' ) {
563
+ * const viewImg = data.mapper.toViewElement( positionParent );
564
+ * const viewCaption = viewImg.nextSibling; // The <span> element.
565
+ *
566
+ * data.viewPosition = new ViewPosition( viewCaption, modelPosition.offset );
567
+ *
568
+ * // Stop the event if other callbacks should not modify calculated value.
569
+ * evt.stop();
570
+ * }
571
+ * } );
572
+ * ```
573
+ *
574
+ * **Note:** keep in mind that sometimes a "phantom" model position is being converted. A "phantom" model position is
575
+ * a position that points to a nonexistent place in model. Such a position might still be valid for conversion, though
576
+ * (it would point to a correct place in the view when converted). One example of such a situation is when a range is
577
+ * removed from the model, there may be a need to map the range's end (which is no longer a valid model position). To
578
+ * handle such situations, check the `data.isPhantom` flag:
579
+ *
580
+ * ```ts
581
+ * // Assume that there is a "customElement" model element and whenever the position is before it,
582
+ * // we want to move it to the inside of the view element bound to "customElement".
583
+ * mapper.on( 'modelToViewPosition', ( evt, data ) => {
584
+ * if ( data.isPhantom ) {
585
+ * return;
586
+ * }
587
+ *
588
+ * // Below line might crash for phantom position that does not exist in model.
589
+ * const sibling = data.modelPosition.nodeBefore;
590
+ *
591
+ * // Check if this is the element we are interested in.
592
+ * if ( !sibling.is( 'element', 'customElement' ) ) {
593
+ * return;
594
+ * }
595
+ *
596
+ * const viewElement = data.mapper.toViewElement( sibling );
597
+ *
598
+ * data.viewPosition = new ViewPosition( sibling, 0 );
599
+ *
600
+ * evt.stop();
601
+ * } );
602
+ * ```
603
+ *
604
+ * **Note:** the default mapping callback is provided with a `low` priority setting and does not cancel the event, so it is possible to
605
+ * attach a custom callback after a default callback and also use `data.viewPosition` calculated by the default callback
606
+ * (for example to fix it).
607
+ *
608
+ * **Note:** the default mapping callback will not fire if `data.viewPosition` is already set.
609
+ *
610
+ * **Note:** these callbacks are called **very often**. For efficiency reasons, it is advised to use them only when position
611
+ * mapping between the given model and view elements is unsolvable by using just elements mapping and default algorithm.
612
+ * Also, the condition that checks if a special case scenario happened should be as simple as possible.
613
+ *
614
+ * @eventName ~Mapper#modelToViewPosition
615
+ */
621
616
  export type MapperModelToViewPositionEvent = {
622
- name: 'modelToViewPosition';
623
- args: [MapperModelToViewPositionEventData];
617
+ name: "modelToViewPosition";
618
+ args: [MapperModelToViewPositionEventData];
624
619
  };
625
620
  /**
626
- * Data pipeline object that can store and pass data between callbacks. The callback should add
627
- * the `viewPosition` value to that object with calculated the {@link module:engine/view/position~ViewPosition view position}.
628
- */
621
+ * Data pipeline object that can store and pass data between callbacks. The callback should add
622
+ * the `viewPosition` value to that object with calculated the {@link module:engine/view/position~ViewPosition view position}.
623
+ */
629
624
  export type MapperModelToViewPositionEventData = {
630
- /**
631
- * Mapper instance that fired the event.
632
- */
633
- mapper: Mapper;
634
- /**
635
- * The model position.
636
- */
637
- modelPosition: ModelPosition;
638
- /**
639
- * The callback should add the `viewPosition` value to that object with calculated the
640
- * {@link module:engine/view/position~ViewPosition view position}.
641
- */
642
- viewPosition?: ViewPosition;
643
- /**
644
- * Should be set to `true` if the model position to map is pointing to a place
645
- * in model tree which no longer exists. For example, it could be an end of a removed model range.
646
- */
647
- isPhantom?: boolean;
625
+ /**
626
+ * Mapper instance that fired the event.
627
+ */
628
+ mapper: Mapper;
629
+ /**
630
+ * The model position.
631
+ */
632
+ modelPosition: ModelPosition;
633
+ /**
634
+ * The callback should add the `viewPosition` value to that object with calculated the
635
+ * {@link module:engine/view/position~ViewPosition view position}.
636
+ */
637
+ viewPosition?: ViewPosition;
638
+ /**
639
+ * Should be set to `true` if the model position to map is pointing to a place
640
+ * in model tree which no longer exists. For example, it could be an end of a removed model range.
641
+ */
642
+ isPhantom?: boolean;
648
643
  };
649
644
  /**
650
- * Fired for each view-to-model position mapping request. See {@link module:engine/conversion/mapper~Mapper#event:modelToViewPosition}.
651
- *
652
- * ```ts
653
- * // See example in `modelToViewPosition` event description.
654
- * // This custom mapping will map positions from <span> element next to <img> to the "captionedImage" element.
655
- * mapper.on( 'viewToModelPosition', ( evt, data ) => {
656
- * const positionParent = viewPosition.parent;
657
- *
658
- * if ( positionParent.hasClass( 'image-caption' ) ) {
659
- * const viewImg = positionParent.previousSibling;
660
- * const modelImg = data.mapper.toModelElement( viewImg );
661
- *
662
- * data.modelPosition = new ModelPosition( modelImg, viewPosition.offset );
663
- * evt.stop();
664
- * }
665
- * } );
666
- * ```
667
- *
668
- * **Note:** the default mapping callback is provided with a `low` priority setting and does not cancel the event, so it is possible to
669
- * attach a custom callback after the default callback and also use `data.modelPosition` calculated by the default callback
670
- * (for example to fix it).
671
- *
672
- * **Note:** the default mapping callback will not fire if `data.modelPosition` is already set.
673
- *
674
- * **Note:** these callbacks are called **very often**. For efficiency reasons, it is advised to use them only when position
675
- * mapping between the given model and view elements is unsolvable by using just elements mapping and default algorithm.
676
- * Also, the condition that checks if special case scenario happened should be as simple as possible.
677
- *
678
- * @eventName ~Mapper#viewToModelPosition
679
- */
645
+ * Fired for each view-to-model position mapping request. See {@link module:engine/conversion/mapper~Mapper#event:modelToViewPosition}.
646
+ *
647
+ * ```ts
648
+ * // See example in `modelToViewPosition` event description.
649
+ * // This custom mapping will map positions from <span> element next to <img> to the "captionedImage" element.
650
+ * mapper.on( 'viewToModelPosition', ( evt, data ) => {
651
+ * const positionParent = viewPosition.parent;
652
+ *
653
+ * if ( positionParent.hasClass( 'image-caption' ) ) {
654
+ * const viewImg = positionParent.previousSibling;
655
+ * const modelImg = data.mapper.toModelElement( viewImg );
656
+ *
657
+ * data.modelPosition = new ModelPosition( modelImg, viewPosition.offset );
658
+ * evt.stop();
659
+ * }
660
+ * } );
661
+ * ```
662
+ *
663
+ * **Note:** the default mapping callback is provided with a `low` priority setting and does not cancel the event, so it is possible to
664
+ * attach a custom callback after the default callback and also use `data.modelPosition` calculated by the default callback
665
+ * (for example to fix it).
666
+ *
667
+ * **Note:** the default mapping callback will not fire if `data.modelPosition` is already set.
668
+ *
669
+ * **Note:** these callbacks are called **very often**. For efficiency reasons, it is advised to use them only when position
670
+ * mapping between the given model and view elements is unsolvable by using just elements mapping and default algorithm.
671
+ * Also, the condition that checks if special case scenario happened should be as simple as possible.
672
+ *
673
+ * @eventName ~Mapper#viewToModelPosition
674
+ */
680
675
  export type MapperViewToModelPositionEvent = {
681
- name: 'viewToModelPosition';
682
- args: [MapperViewToModelPositionEventData];
676
+ name: "viewToModelPosition";
677
+ args: [MapperViewToModelPositionEventData];
683
678
  };
684
679
  /**
685
- * Data pipeline object that can store and pass data between callbacks. The callback should add
686
- * `modelPosition` value to that object with calculated {@link module:engine/model/position~ModelPosition model position}.
687
- */
680
+ * Data pipeline object that can store and pass data between callbacks. The callback should add
681
+ * `modelPosition` value to that object with calculated {@link module:engine/model/position~ModelPosition model position}.
682
+ */
688
683
  export type MapperViewToModelPositionEventData = {
689
- /**
690
- * Mapper instance that fired the event.
691
- */
692
- mapper: Mapper;
693
- /**
694
- * The callback should add `modelPosition` value to that object with calculated
695
- * {@link module:engine/model/position~ModelPosition model position}.
696
- */
697
- modelPosition?: ModelPosition;
698
- /**
699
- * The view position.
700
- */
701
- viewPosition: ViewPosition;
684
+ /**
685
+ * Mapper instance that fired the event.
686
+ */
687
+ mapper: Mapper;
688
+ /**
689
+ * The callback should add `modelPosition` value to that object with calculated
690
+ * {@link module:engine/model/position~ModelPosition model position}.
691
+ */
692
+ modelPosition?: ModelPosition;
693
+ /**
694
+ * The view position.
695
+ */
696
+ viewPosition: ViewPosition;
702
697
  };
703
698
  /**
704
- * Informs that given `viewPosition` corresponds to given `modelOffset` (with the assumption that the model offset is in a model element
705
- * mapped to the `viewPosition` parent or its ancestor).
706
- *
707
- * For example, for model `<paragraph>Some <$text bold=true>bold</$text> text</paragraph>` and view `<p>Some <strong>bold</strong> text</p>`
708
- * and assuming `<paragraph>` and `<p>` are mapped, following example `CacheItem`s are possible:
709
- *
710
- * * `viewPosition` = `<p>`, 1; `modelOffset` = 5
711
- * * `viewPosition` = `<strong>, 1; `modelOffset` = 9
712
- * * `viewPosition` = `<p>`, 2; `modelOffset` = 9
713
- * * `viewPosition` = `<p>`, 3; `modelOffset` = 14
714
- */
699
+ * Informs that given `viewPosition` corresponds to given `modelOffset` (with the assumption that the model offset is in a model element
700
+ * mapped to the `viewPosition` parent or its ancestor).
701
+ *
702
+ * For example, for model `<paragraph>Some <$text bold=true>bold</$text> text</paragraph>` and view `<p>Some <strong>bold</strong> text</p>`
703
+ * and assuming `<paragraph>` and `<p>` are mapped, following example `CacheItem`s are possible:
704
+ *
705
+ * * `viewPosition` = `<p>`, 1; `modelOffset` = 5
706
+ * * `viewPosition` = `<strong>, 1; `modelOffset` = 9
707
+ * * `viewPosition` = `<p>`, 2; `modelOffset` = 9
708
+ * * `viewPosition` = `<p>`, 3; `modelOffset` = 14
709
+ */
715
710
  type CacheItem = {
716
- viewPosition: ViewPosition;
717
- modelOffset: number;
711
+ viewPosition: ViewPosition;
712
+ modelOffset: number;
718
713
  };
719
714
  export {};