@ckeditor/ckeditor5-engine 48.8.1-alpha.3 → 49.0.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 (135) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/controller/datacontroller.d.ts +329 -314
  3. package/dist/controller/editingcontroller.d.ts +95 -94
  4. package/dist/conversion/comparemarkers.d.ts +45 -45
  5. package/dist/conversion/conversion.d.ts +474 -474
  6. package/dist/conversion/conversionhelpers.d.ts +21 -21
  7. package/dist/conversion/downcastdispatcher.d.ts +539 -538
  8. package/dist/conversion/downcasthelpers.d.ts +1129 -1129
  9. package/dist/conversion/mapper.d.ts +692 -697
  10. package/dist/conversion/modelconsumable.d.ts +196 -196
  11. package/dist/conversion/upcastdispatcher.d.ts +483 -475
  12. package/dist/conversion/upcasthelpers.d.ts +491 -491
  13. package/dist/conversion/viewconsumable.d.ts +330 -330
  14. package/dist/dataprocessor/basichtmlwriter.d.ts +15 -15
  15. package/dist/dataprocessor/dataprocessor.d.ts +57 -57
  16. package/dist/dataprocessor/htmldataprocessor.d.ts +72 -72
  17. package/dist/dataprocessor/htmlwriter.d.ts +11 -11
  18. package/dist/dataprocessor/xmldataprocessor.d.ts +86 -86
  19. package/dist/dev-utils/model.d.ts +128 -116
  20. package/dist/dev-utils/operationreplayer.d.ts +49 -49
  21. package/dist/dev-utils/utils.d.ts +33 -33
  22. package/dist/dev-utils/view.d.ts +314 -309
  23. package/dist/engineconfig.d.ts +39 -39
  24. package/dist/index-content.css +3 -0
  25. package/dist/index-content.css.map +1 -0
  26. package/dist/index-editor.css +33 -29
  27. package/dist/index-editor.css.map +1 -0
  28. package/dist/index.css +26 -24
  29. package/dist/index.css.map +1 -1
  30. package/dist/index.d.ts +152 -150
  31. package/dist/index.js +34246 -40050
  32. package/dist/index.js.map +1 -1
  33. package/dist/legacyerrors.d.ts +0 -4
  34. package/dist/model/batch.d.ts +86 -86
  35. package/dist/model/differ.d.ts +504 -504
  36. package/dist/model/document.d.ts +265 -262
  37. package/dist/model/documentfragment.d.ts +214 -214
  38. package/dist/model/documentselection.d.ts +412 -410
  39. package/dist/model/element.d.ts +182 -182
  40. package/dist/model/history.d.ts +109 -109
  41. package/dist/model/item.d.ts +9 -9
  42. package/dist/model/liveposition.d.ts +81 -69
  43. package/dist/model/liverange.d.ts +118 -92
  44. package/dist/model/markercollection.d.ts +317 -324
  45. package/dist/model/model.d.ts +889 -909
  46. package/dist/model/node.d.ts +254 -254
  47. package/dist/model/nodelist.d.ts +110 -110
  48. package/dist/model/operation/attributeoperation.d.ts +98 -98
  49. package/dist/model/operation/detachoperation.d.ts +57 -57
  50. package/dist/model/operation/insertoperation.d.ts +85 -85
  51. package/dist/model/operation/markeroperation.d.ts +87 -87
  52. package/dist/model/operation/mergeoperation.d.ts +95 -95
  53. package/dist/model/operation/moveoperation.d.ts +97 -91
  54. package/dist/model/operation/nooperation.d.ts +33 -33
  55. package/dist/model/operation/operation.d.ts +94 -94
  56. package/dist/model/operation/operationfactory.d.ts +14 -14
  57. package/dist/model/operation/renameoperation.d.ts +78 -78
  58. package/dist/model/operation/rootattributeoperation.d.ts +93 -93
  59. package/dist/model/operation/rootoperation.d.ts +71 -71
  60. package/dist/model/operation/splitoperation.d.ts +104 -104
  61. package/dist/model/operation/transform.d.ts +91 -91
  62. package/dist/model/operation/utils.d.ts +58 -58
  63. package/dist/model/position.d.ts +542 -535
  64. package/dist/model/range.d.ts +467 -453
  65. package/dist/model/rootelement.d.ts +55 -55
  66. package/dist/model/schema.d.ts +1325 -1327
  67. package/dist/model/selection.d.ts +452 -471
  68. package/dist/model/text.d.ts +62 -62
  69. package/dist/model/textproxy.d.ts +140 -140
  70. package/dist/model/treewalker.d.ts +190 -190
  71. package/dist/model/typecheckable.d.ts +281 -281
  72. package/dist/model/utils/autoparagraphing.d.ts +29 -29
  73. package/dist/model/utils/deletecontent.d.ts +68 -68
  74. package/dist/model/utils/getselectedcontent.d.ts +27 -27
  75. package/dist/model/utils/insertcontent.d.ts +42 -42
  76. package/dist/model/utils/insertobject.d.ts +41 -41
  77. package/dist/model/utils/modifyselection.d.ts +44 -44
  78. package/dist/model/utils/selection-post-fixer.d.ts +71 -71
  79. package/dist/model/writer.d.ts +857 -848
  80. package/dist/view/attributeelement.d.ts +123 -123
  81. package/dist/view/containerelement.d.ts +49 -49
  82. package/dist/view/datatransfer.d.ts +70 -70
  83. package/dist/view/document.d.ts +175 -177
  84. package/dist/view/documentfragment.d.ts +158 -157
  85. package/dist/view/documentselection.d.ts +308 -307
  86. package/dist/view/domconverter.d.ts +614 -658
  87. package/dist/view/downcastwriter.d.ts +1012 -1006
  88. package/dist/view/editableelement.d.ts +64 -63
  89. package/dist/view/element.d.ts +754 -754
  90. package/dist/view/elementdefinition.d.ts +79 -79
  91. package/dist/view/emptyelement.d.ts +42 -42
  92. package/dist/view/filler.d.ts +75 -75
  93. package/dist/view/item.d.ts +9 -9
  94. package/dist/view/matcher.d.ts +412 -487
  95. package/dist/view/node.d.ts +164 -163
  96. package/dist/view/observer/arrowkeysobserver.d.ts +37 -37
  97. package/dist/view/observer/bubblingemittermixin.d.ts +163 -153
  98. package/dist/view/observer/bubblingeventinfo.d.ts +45 -42
  99. package/dist/view/observer/clickobserver.d.ts +36 -36
  100. package/dist/view/observer/compositionobserver.d.ts +67 -67
  101. package/dist/view/observer/domeventdata.d.ts +46 -46
  102. package/dist/view/observer/domeventobserver.d.ts +77 -74
  103. package/dist/view/observer/fakeselectionobserver.d.ts +42 -42
  104. package/dist/view/observer/focusobserver.d.ts +84 -84
  105. package/dist/view/observer/inputobserver.d.ts +76 -76
  106. package/dist/view/observer/keyobserver.d.ts +53 -53
  107. package/dist/view/observer/mouseobserver.d.ts +73 -73
  108. package/dist/view/observer/mutationobserver.d.ts +101 -101
  109. package/dist/view/observer/observer.d.ts +84 -83
  110. package/dist/view/observer/pointerobserver.d.ts +63 -63
  111. package/dist/view/observer/selectionobserver.d.ts +141 -137
  112. package/dist/view/observer/tabobserver.d.ts +38 -38
  113. package/dist/view/observer/touchobserver.d.ts +60 -60
  114. package/dist/view/placeholder.d.ts +77 -81
  115. package/dist/view/position.d.ts +187 -187
  116. package/dist/view/range.d.ts +282 -282
  117. package/dist/view/rawelement.d.ts +72 -72
  118. package/dist/view/renderer.d.ts +282 -273
  119. package/dist/view/rooteditableelement.d.ts +43 -43
  120. package/dist/view/selection.d.ts +356 -369
  121. package/dist/view/styles/background.d.ts +15 -15
  122. package/dist/view/styles/border.d.ts +27 -27
  123. package/dist/view/styles/margin.d.ts +12 -12
  124. package/dist/view/styles/padding.d.ts +12 -12
  125. package/dist/view/styles/utils.d.ts +72 -72
  126. package/dist/view/stylesmap.d.ts +715 -715
  127. package/dist/view/text.d.ts +75 -75
  128. package/dist/view/textproxy.d.ts +92 -92
  129. package/dist/view/tokenlist.d.ts +104 -104
  130. package/dist/view/treewalker.d.ts +201 -201
  131. package/dist/view/typecheckable.d.ts +445 -445
  132. package/dist/view/uielement.d.ts +93 -93
  133. package/dist/view/upcastwriter.d.ts +412 -412
  134. package/dist/view/view.d.ts +466 -468
  135. package/package.json +3 -3
@@ -1,493 +1,501 @@
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/upcastdispatcher
7
- */
8
- import { ViewConsumable } from './viewconsumable.js';
9
- import { ModelRange } from '../model/range.js';
10
- import { ModelPosition } from '../model/position.js';
11
- import { type ModelElement } from '../model/element.js';
12
- import { type ModelNode } from '../model/node.js';
13
- import { type ViewElement } from '../view/element.js';
14
- import { type ViewText } from '../view/text.js';
15
- import { type ViewDocumentFragment } from '../view/documentfragment.js';
16
- import { type ModelDocumentFragment } from '../model/documentfragment.js';
17
- import type { ModelSchema, ModelSchemaContextDefinition } from '../model/schema.js';
18
- import { type ModelWriter } from '../model/writer.js';
19
- import { type ViewItem } from '../view/item.js';
20
- declare const UpcastDispatcher_base: {
21
- new (): import("@ckeditor/ckeditor5-utils").Emitter;
22
- prototype: import("@ckeditor/ckeditor5-utils").Emitter;
23
- };
6
+ * @module engine/conversion/upcastdispatcher
7
+ */
8
+ import { ViewConsumable } from "./viewconsumable.js";
9
+ import { ModelRange } from "../model/range.js";
10
+ import { ModelPosition } from "../model/position.js";
11
+ import { type ModelElement } from "../model/element.js";
12
+ import { type ModelNode } from "../model/node.js";
13
+ import { type ViewElement } from "../view/element.js";
14
+ import { type ViewText } from "../view/text.js";
15
+ import { type ViewDocumentFragment } from "../view/documentfragment.js";
16
+ import { type ModelDocumentFragment } from "../model/documentfragment.js";
17
+ import type { ModelSchema, ModelSchemaContextDefinition } from "../model/schema.js";
18
+ import { type ModelWriter } from "../model/writer.js";
19
+ import { type ViewItem } from "../view/item.js";
20
+ import { type EmitterMixinConstructor } from "@ckeditor/ckeditor5-utils";
21
+ declare const UpcastDispatcherBase: EmitterMixinConstructor;
24
22
  /**
25
- * Upcast dispatcher is a central point of the view-to-model conversion, which is a process of
26
- * converting a given {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment} or
27
- * {@link module:engine/view/element~ViewElement view element} into a correct model structure.
28
- *
29
- * During the conversion process, the dispatcher fires events for all {@link module:engine/view/node~ViewNode view nodes}
30
- * from the converted view document fragment.
31
- * Special callbacks called "converters" should listen to these events in order to convert the view nodes.
32
- *
33
- * The second parameter of the callback is the `data` object with the following properties:
34
- *
35
- * * `data.viewItem` contains a {@link module:engine/view/node~ViewNode view node} or a
36
- * {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment}
37
- * that is converted at the moment and might be handled by the callback.
38
- * * `data.modelRange` is used to point to the result
39
- * of the current conversion (e.g. the element that is being inserted)
40
- * and is always a {@link module:engine/model/range~ModelRange} when the conversion succeeds.
41
- * * `data.modelCursor` is a {@link module:engine/model/position~ModelPosition position} on which the converter should insert
42
- * the newly created items.
43
- *
44
- * The third parameter of the callback is an instance of {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi}
45
- * which provides additional tools for converters.
46
- *
47
- * You can read more about conversion in the {@glink framework/deep-dive/conversion/upcast Upcast conversion} guide.
48
- *
49
- * Examples of event-based converters:
50
- *
51
- * ```ts
52
- * // A converter for links (<a>).
53
- * editor.data.upcastDispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
54
- * if ( conversionApi.consumable.consume( data.viewItem, { name: true, attributes: [ 'href' ] } ) ) {
55
- * // The <a> element is inline and is represented by an attribute in the model.
56
- * // This is why you need to convert only children.
57
- * const { modelRange } = conversionApi.convertChildren( data.viewItem, data.modelCursor );
58
- *
59
- * for ( let item of modelRange.getItems() ) {
60
- * if ( conversionApi.schema.checkAttribute( item, 'linkHref' ) ) {
61
- * conversionApi.writer.setAttribute( 'linkHref', data.viewItem.getAttribute( 'href' ), item );
62
- * }
63
- * }
64
- * }
65
- * } );
66
- *
67
- * // Convert <p> element's font-size style.
68
- * // Note: You should use a low-priority observer in order to ensure that
69
- * // it is executed after the element-to-element converter.
70
- * editor.data.upcastDispatcher.on( 'element:p', ( evt, data, conversionApi ) => {
71
- * const { consumable, schema, writer } = conversionApi;
72
- *
73
- * if ( !consumable.consume( data.viewItem, { style: 'font-size' } ) ) {
74
- * return;
75
- * }
76
- *
77
- * const fontSize = data.viewItem.getStyle( 'font-size' );
78
- *
79
- * // Do not go for the model element after data.modelCursor because it might happen
80
- * // that a single view element was converted to multiple model elements. Get all of them.
81
- * for ( const item of data.modelRange.getItems( { shallow: true } ) ) {
82
- * if ( schema.checkAttribute( item, 'fontSize' ) ) {
83
- * writer.setAttribute( 'fontSize', fontSize, item );
84
- * }
85
- * }
86
- * }, { priority: 'low' } );
87
- *
88
- * // Convert all elements which have no custom converter into a paragraph (autoparagraphing).
89
- * editor.data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
90
- * // Check if an element can be converted.
91
- * if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
92
- * // When an element is already consumed by higher priority converters, do nothing.
93
- * return;
94
- * }
95
- *
96
- * const paragraph = conversionApi.writer.createElement( 'paragraph' );
97
- *
98
- * // Try to safely insert a paragraph at the model cursor - it will find an allowed parent for the current element.
99
- * if ( !conversionApi.safeInsert( paragraph, data.modelCursor ) ) {
100
- * // When an element was not inserted, it means that you cannot insert a paragraph at this position.
101
- * return;
102
- * }
103
- *
104
- * // Consume the inserted element.
105
- * conversionApi.consumable.consume( data.viewItem, { name: data.viewItem.name } ) );
106
- *
107
- * // Convert the children to a paragraph.
108
- * const { modelRange } = conversionApi.convertChildren( data.viewItem, paragraph ) );
109
- *
110
- * // Update `modelRange` and `modelCursor` in the `data` as a conversion result.
111
- * conversionApi.updateConversionResult( paragraph, data );
112
- * }, { priority: 'low' } );
113
- * ```
114
- *
115
- * @fires viewCleanup
116
- * @fires element
117
- * @fires text
118
- * @fires documentFragment
119
- */
120
- export declare class UpcastDispatcher extends /* #__PURE__ */ UpcastDispatcher_base {
121
- /**
122
- * An interface passed by the dispatcher to the event callbacks.
123
- */
124
- conversionApi: UpcastConversionApi;
125
- /**
126
- * The list of elements that were created during splitting.
127
- *
128
- * After the conversion process, the list is cleared.
129
- */
130
- private _splitParts;
131
- /**
132
- * The list of cursor parent elements that were created during splitting.
133
- *
134
- * After the conversion process the list is cleared.
135
- */
136
- private _cursorParents;
137
- /**
138
- * The position in the temporary structure where the converted content is inserted. The structure reflects the context of
139
- * the target position where the content will be inserted. This property is built based on the context parameter of the
140
- * convert method.
141
- */
142
- private _modelCursor;
143
- /**
144
- * The list of elements that were created during the splitting but should not get removed on conversion end even if they are empty.
145
- *
146
- * The list is cleared after the conversion process.
147
- */
148
- private _emptyElementsToKeep;
149
- /**
150
- * Creates an upcast dispatcher that operates using the passed API.
151
- *
152
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi
153
- * @param conversionApi Additional properties for an interface that will be passed to events fired
154
- * by the upcast dispatcher.
155
- */
156
- constructor(conversionApi: Pick<UpcastConversionApi, 'schema'>);
157
- /**
158
- * Starts the conversion process. The entry point for the conversion.
159
- *
160
- * @fires element
161
- * @fires text
162
- * @fires documentFragment
163
- * @param viewElement The part of the view to be converted.
164
- * @param writer An instance of the model writer.
165
- * @param context Elements will be converted according to this context.
166
- * @returns Model data that is the result of the conversion process
167
- * wrapped in `DocumentFragment`. Converted marker elements will be set as the document fragment's
168
- * {@link module:engine/model/documentfragment~ModelDocumentFragment#markers static markers map}.
169
- */
170
- convert(viewElement: ViewElement | ViewDocumentFragment, writer: ModelWriter, context?: ModelSchemaContextDefinition): ModelDocumentFragment;
171
- /**
172
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertItem
173
- */
174
- private _convertItem;
175
- /**
176
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertChildren
177
- */
178
- private _convertChildren;
179
- /**
180
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#safeInsert
181
- */
182
- private _safeInsert;
183
- /**
184
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#updateConversionResult
185
- */
186
- private _updateConversionResult;
187
- /**
188
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#splitToAllowedParent
189
- */
190
- private _splitToAllowedParent;
191
- /**
192
- * Registers that a `splitPart` element is a split part of the `originalPart` element.
193
- *
194
- * The data set by this method is used by {@link #_getSplitParts} and {@link #_removeEmptyElements}.
195
- */
196
- private _registerSplitPair;
197
- /**
198
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#getSplitParts
199
- */
200
- private _getSplitParts;
201
- /**
202
- * Mark an element that were created during the splitting to not get removed on conversion end even if it is empty.
203
- */
204
- private _keepEmptyElement;
205
- /**
206
- * Checks if there are any empty elements created while splitting and removes them.
207
- *
208
- * This method works recursively to re-check empty elements again after at least one element was removed in the initial call,
209
- * as some elements might have become empty after other empty elements were removed from them.
210
- */
211
- private _removeEmptyElements;
23
+ * Upcast dispatcher is a central point of the view-to-model conversion, which is a process of
24
+ * converting a given {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment} or
25
+ * {@link module:engine/view/element~ViewElement view element} into a correct model structure.
26
+ *
27
+ * During the conversion process, the dispatcher fires events for all {@link module:engine/view/node~ViewNode view nodes}
28
+ * from the converted view document fragment.
29
+ * Special callbacks called "converters" should listen to these events in order to convert the view nodes.
30
+ *
31
+ * The second parameter of the callback is the `data` object with the following properties:
32
+ *
33
+ * * `data.viewItem` contains a {@link module:engine/view/node~ViewNode view node} or a
34
+ * {@link module:engine/view/documentfragment~ViewDocumentFragment view document fragment}
35
+ * that is converted at the moment and might be handled by the callback.
36
+ * * `data.modelRange` is used to point to the result
37
+ * of the current conversion (e.g. the element that is being inserted)
38
+ * and is always a {@link module:engine/model/range~ModelRange} when the conversion succeeds.
39
+ * * `data.modelCursor` is a {@link module:engine/model/position~ModelPosition position} on which the converter should insert
40
+ * the newly created items.
41
+ *
42
+ * The third parameter of the callback is an instance of {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi}
43
+ * which provides additional tools for converters.
44
+ *
45
+ * You can read more about conversion in the {@glink framework/deep-dive/conversion/upcast Upcast conversion} guide.
46
+ *
47
+ * Examples of event-based converters:
48
+ *
49
+ * ```ts
50
+ * // A converter for links (<a>).
51
+ * editor.data.upcastDispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
52
+ * if ( conversionApi.consumable.consume( data.viewItem, { name: true, attributes: [ 'href' ] } ) ) {
53
+ * // The <a> element is inline and is represented by an attribute in the model.
54
+ * // This is why you need to convert only children.
55
+ * const { modelRange } = conversionApi.convertChildren( data.viewItem, data.modelCursor );
56
+ *
57
+ * for ( let item of modelRange.getItems() ) {
58
+ * if ( conversionApi.schema.checkAttribute( item, 'linkHref' ) ) {
59
+ * conversionApi.writer.setAttribute( 'linkHref', data.viewItem.getAttribute( 'href' ), item );
60
+ * }
61
+ * }
62
+ * }
63
+ * } );
64
+ *
65
+ * // Convert <p> element's font-size style.
66
+ * // Note: You should use a low-priority observer in order to ensure that
67
+ * // it is executed after the element-to-element converter.
68
+ * editor.data.upcastDispatcher.on( 'element:p', ( evt, data, conversionApi ) => {
69
+ * const { consumable, schema, writer } = conversionApi;
70
+ *
71
+ * if ( !consumable.consume( data.viewItem, { style: 'font-size' } ) ) {
72
+ * return;
73
+ * }
74
+ *
75
+ * const fontSize = data.viewItem.getStyle( 'font-size' );
76
+ *
77
+ * // Do not go for the model element after data.modelCursor because it might happen
78
+ * // that a single view element was converted to multiple model elements. Get all of them.
79
+ * for ( const item of data.modelRange.getItems( { shallow: true } ) ) {
80
+ * if ( schema.checkAttribute( item, 'fontSize' ) ) {
81
+ * writer.setAttribute( 'fontSize', fontSize, item );
82
+ * }
83
+ * }
84
+ * }, { priority: 'low' } );
85
+ *
86
+ * // Convert all elements which have no custom converter into a paragraph (autoparagraphing).
87
+ * editor.data.upcastDispatcher.on( 'element', ( evt, data, conversionApi ) => {
88
+ * // Check if an element can be converted.
89
+ * if ( !conversionApi.consumable.test( data.viewItem, { name: data.viewItem.name } ) ) {
90
+ * // When an element is already consumed by higher priority converters, do nothing.
91
+ * return;
92
+ * }
93
+ *
94
+ * const paragraph = conversionApi.writer.createElement( 'paragraph' );
95
+ *
96
+ * // Try to safely insert a paragraph at the model cursor - it will find an allowed parent for the current element.
97
+ * if ( !conversionApi.safeInsert( paragraph, data.modelCursor ) ) {
98
+ * // When an element was not inserted, it means that you cannot insert a paragraph at this position.
99
+ * return;
100
+ * }
101
+ *
102
+ * // Consume the inserted element.
103
+ * conversionApi.consumable.consume( data.viewItem, { name: data.viewItem.name } ) );
104
+ *
105
+ * // Convert the children to a paragraph.
106
+ * const { modelRange } = conversionApi.convertChildren( data.viewItem, paragraph ) );
107
+ *
108
+ * // Update `modelRange` and `modelCursor` in the `data` as a conversion result.
109
+ * conversionApi.updateConversionResult( paragraph, data );
110
+ * }, { priority: 'low' } );
111
+ * ```
112
+ *
113
+ * @fires viewCleanup
114
+ * @fires element
115
+ * @fires text
116
+ * @fires documentFragment
117
+ */
118
+ export declare class UpcastDispatcher extends UpcastDispatcherBase {
119
+ /**
120
+ * An interface passed by the dispatcher to the event callbacks.
121
+ */
122
+ conversionApi: UpcastConversionApi;
123
+ /**
124
+ * The list of elements that were created during splitting.
125
+ *
126
+ * After the conversion process, the list is cleared.
127
+ */
128
+ private _splitParts;
129
+ /**
130
+ * The list of cursor parent elements that were created during splitting.
131
+ *
132
+ * After the conversion process the list is cleared.
133
+ */
134
+ private _cursorParents;
135
+ /**
136
+ * The position in the temporary structure where the converted content is inserted. The structure reflects the context of
137
+ * the target position where the content will be inserted. This property is built based on the context parameter of the
138
+ * convert method.
139
+ */
140
+ private _modelCursor;
141
+ /**
142
+ * The list of elements that were created during the splitting but should not get removed on conversion end even if they are empty.
143
+ *
144
+ * The list is cleared after the conversion process.
145
+ */
146
+ private _emptyElementsToKeep;
147
+ /**
148
+ * Creates an upcast dispatcher that operates using the passed API.
149
+ *
150
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi
151
+ * @param conversionApi Additional properties for an interface that will be passed to events fired
152
+ * by the upcast dispatcher.
153
+ */
154
+ constructor(conversionApi: Pick<UpcastConversionApi, "schema">);
155
+ /**
156
+ * Starts the conversion process. The entry point for the conversion.
157
+ *
158
+ * **Note:** The default `context` value is `[ '$root' ]`, which only matches the generic root. When the editor uses
159
+ * a custom root {@link module:core/editor/editorconfig~RootConfig#modelElement `modelElement`}, pass the target
160
+ * {@link module:engine/model/rootelement~ModelRootElement root element} (or its configured model element name)
161
+ * explicitly, otherwise the conversion result may be wrong.
162
+ * See the {@glink framework/deep-dive/schema#custom-root-elements Custom root elements} section of the
163
+ * {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
164
+ *
165
+ * @fires element
166
+ * @fires text
167
+ * @fires documentFragment
168
+ * @param viewElement The part of the view to be converted.
169
+ * @param writer An instance of the model writer.
170
+ * @param context Elements will be converted according to this context.
171
+ * @returns Model data that is the result of the conversion process
172
+ * wrapped in `DocumentFragment`. Converted marker elements will be set as the document fragment's
173
+ * {@link module:engine/model/documentfragment~ModelDocumentFragment#markers static markers map}.
174
+ */
175
+ convert(viewElement: ViewElement | ViewDocumentFragment, writer: ModelWriter, context?: ModelSchemaContextDefinition): ModelDocumentFragment;
176
+ /**
177
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertItem
178
+ */
179
+ private _convertItem;
180
+ /**
181
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertChildren
182
+ */
183
+ private _convertChildren;
184
+ /**
185
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#safeInsert
186
+ */
187
+ private _safeInsert;
188
+ /**
189
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#updateConversionResult
190
+ */
191
+ private _updateConversionResult;
192
+ /**
193
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#splitToAllowedParent
194
+ */
195
+ private _splitToAllowedParent;
196
+ /**
197
+ * Registers that a `splitPart` element is a split part of the `originalPart` element.
198
+ *
199
+ * The data set by this method is used by {@link #_getSplitParts} and {@link #_removeEmptyElements}.
200
+ */
201
+ private _registerSplitPair;
202
+ /**
203
+ * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#getSplitParts
204
+ */
205
+ private _getSplitParts;
206
+ /**
207
+ * Mark an element that were created during the splitting to not get removed on conversion end even if it is empty.
208
+ */
209
+ private _keepEmptyElement;
210
+ /**
211
+ * Checks if there are any empty elements created while splitting and removes them.
212
+ *
213
+ * This method works recursively to re-check empty elements again after at least one element was removed in the initial call,
214
+ * as some elements might have become empty after other empty elements were removed from them.
215
+ */
216
+ private _removeEmptyElements;
212
217
  }
213
218
  /**
214
- * Fired before the first conversion event, at the beginning of the upcast (view-to-model conversion) process.
215
- *
216
- * @eventName ~UpcastDispatcher#viewCleanup
217
- * @param viewItem A part of the view to be converted.
218
- */
219
+ * Fired before the first conversion event, at the beginning of the upcast (view-to-model conversion) process.
220
+ *
221
+ * @eventName ~UpcastDispatcher#viewCleanup
222
+ * @param viewItem A part of the view to be converted.
223
+ */
219
224
  export type UpcastViewCleanupEvent = {
220
- name: 'viewCleanup';
221
- args: [ViewElement | ViewDocumentFragment];
225
+ name: "viewCleanup";
226
+ args: [ViewElement | ViewDocumentFragment];
222
227
  };
223
- export type UpcastEvent<TName extends string, TItem extends ViewItem | ViewDocumentFragment> = {
224
- name: TName | `${TName}:${string}`;
225
- args: [data: UpcastConversionData<TItem>, conversionApi: UpcastConversionApi];
228
+ export type UpcastEvent<
229
+ TName extends string,
230
+ TItem extends ViewItem | ViewDocumentFragment
231
+ > = {
232
+ name: TName | `${TName}:${string}`;
233
+ args: [data: UpcastConversionData<TItem>, conversionApi: UpcastConversionApi];
226
234
  };
227
235
  /**
228
- * Conversion data.
229
- *
230
- * **Note:** Keep in mind that this object is shared by reference between all conversion callbacks that will be called.
231
- * This means that callbacks can override values if needed, and these values will be available in other callbacks.
232
- */
236
+ * Conversion data.
237
+ *
238
+ * **Note:** Keep in mind that this object is shared by reference between all conversion callbacks that will be called.
239
+ * This means that callbacks can override values if needed, and these values will be available in other callbacks.
240
+ */
233
241
  export interface UpcastConversionData<TItem extends ViewItem | ViewDocumentFragment = ViewItem | ViewDocumentFragment> {
234
- /**
235
- * The converted item.
236
- */
237
- viewItem: TItem;
238
- /**
239
- * The position where the converter should start changes.
240
- * Change this value for the next converter to tell where the conversion should continue.
241
- */
242
- modelCursor: ModelPosition;
243
- /**
244
- * The current state of conversion result. Every change to
245
- * the converted element should be reflected by setting or modifying this property.
246
- */
247
- modelRange: ModelRange | null;
242
+ /**
243
+ * The converted item.
244
+ */
245
+ viewItem: TItem;
246
+ /**
247
+ * The position where the converter should start changes.
248
+ * Change this value for the next converter to tell where the conversion should continue.
249
+ */
250
+ modelCursor: ModelPosition;
251
+ /**
252
+ * The current state of conversion result. Every change to
253
+ * the converted element should be reflected by setting or modifying this property.
254
+ */
255
+ modelRange: ModelRange | null;
248
256
  }
249
257
  /**
250
- * Fired when an {@link module:engine/view/element~ViewElement} is converted.
251
- *
252
- * `element` is a namespace event for a class of events. Names of actually called events follow the pattern of
253
- * `element:<elementName>` where `elementName` is the name of the converted element. This way listeners may listen to
254
- * a conversion of all or just specific elements.
255
- *
256
- * @eventName ~UpcastDispatcher#element
257
- * @param data The conversion data. Keep in mind that this object is shared by reference between all callbacks
258
- * that will be called. This means that callbacks can override values if needed, and these values
259
- * will be available in other callbacks.
260
- * @param conversionApi Conversion utilities to be used by the callback.
261
- */
262
- export type UpcastElementEvent = UpcastEvent<'element', ViewElement>;
258
+ * Fired when an {@link module:engine/view/element~ViewElement} is converted.
259
+ *
260
+ * `element` is a namespace event for a class of events. Names of actually called events follow the pattern of
261
+ * `element:<elementName>` where `elementName` is the name of the converted element. This way listeners may listen to
262
+ * a conversion of all or just specific elements.
263
+ *
264
+ * @eventName ~UpcastDispatcher#element
265
+ * @param data The conversion data. Keep in mind that this object is shared by reference between all callbacks
266
+ * that will be called. This means that callbacks can override values if needed, and these values
267
+ * will be available in other callbacks.
268
+ * @param conversionApi Conversion utilities to be used by the callback.
269
+ */
270
+ export type UpcastElementEvent = UpcastEvent<"element", ViewElement>;
263
271
  /**
264
- * Fired when a {@link module:engine/view/text~ViewText} is converted.
265
- *
266
- * @eventName ~UpcastDispatcher#text
267
- * @see ~UpcastDispatcher#event:element
268
- */
269
- export type UpcastTextEvent = UpcastEvent<'text', ViewText>;
272
+ * Fired when a {@link module:engine/view/text~ViewText} is converted.
273
+ *
274
+ * @eventName ~UpcastDispatcher#text
275
+ * @see ~UpcastDispatcher#event:element
276
+ */
277
+ export type UpcastTextEvent = UpcastEvent<"text", ViewText>;
270
278
  /**
271
- * Fired when a {@link module:engine/view/documentfragment~ViewDocumentFragment} is converted.
272
- *
273
- * @eventName ~UpcastDispatcher#documentFragment
274
- * @see ~UpcastDispatcher#event:element
275
- */
276
- export type UpcastDocumentFragmentEvent = UpcastEvent<'documentFragment', ViewDocumentFragment>;
279
+ * Fired when a {@link module:engine/view/documentfragment~ViewDocumentFragment} is converted.
280
+ *
281
+ * @eventName ~UpcastDispatcher#documentFragment
282
+ * @see ~UpcastDispatcher#event:element
283
+ */
284
+ export type UpcastDocumentFragmentEvent = UpcastEvent<"documentFragment", ViewDocumentFragment>;
277
285
  /**
278
- * A set of conversion utilities available as the third parameter of the
279
- * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher upcast dispatcher}'s events.
280
- */
286
+ * A set of conversion utilities available as the third parameter of the
287
+ * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher upcast dispatcher}'s events.
288
+ */
281
289
  export interface UpcastConversionApi {
282
- /**
283
- * Stores information about what parts of the processed view item are still waiting to be handled. After a piece of view item
284
- * was converted, an appropriate consumable value should be
285
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume consumed}.
286
- */
287
- consumable: ViewConsumable;
288
- /**
289
- * The model's schema instance.
290
- */
291
- schema: ModelSchema;
292
- /**
293
- * The {@link module:engine/model/writer~ModelWriter} instance used to manipulate the data during conversion.
294
- */
295
- writer: ModelWriter;
296
- /**
297
- * Custom data stored by converters for the conversion process. Custom properties of this object can be defined and use to
298
- * pass parameters between converters.
299
- *
300
- * The difference between this property and the `data` parameter of
301
- * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element} is that the `data` parameters allow you
302
- * to pass parameters within a single event and `store` within the whole conversion.
303
- */
304
- store: unknown;
305
- /**
306
- * Starts the conversion of a given item by firing an appropriate event.
307
- *
308
- * Every fired event is passed (as the first parameter) an object with the `modelRange` property. Every event may set and/or
309
- * modify that property. When all callbacks are done, the final value of the `modelRange` property is returned by this method.
310
- * The `modelRange` must be a {@link module:engine/model/range~ModelRange model range} or `null` (as set by default).
311
- *
312
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
313
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
314
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
315
- * @param viewItem Item to convert.
316
- * @param modelCursor The conversion position.
317
- * @returns The conversion result:
318
- * * `result.modelRange` The model range containing the result of the item conversion,
319
- * created and modified by callbacks attached to the fired event, or `null` if the conversion result was incorrect.
320
- * * `result.modelCursor` The position where the conversion should be continued.
321
- */
322
- convertItem(viewItem: ViewItem, modelCursor: ModelPosition): {
323
- modelRange: ModelRange | null;
324
- modelCursor: ModelPosition;
325
- };
326
- /**
327
- * Starts the conversion of all children of a given item by firing appropriate events for all the children.
328
- *
329
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
330
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
331
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
332
- * @param viewElement An element whose children should be converted.
333
- * @param positionOrElement A position or an element of
334
- * the conversion.
335
- * @returns The conversion result:
336
- * * `result.modelRange` The model range containing the results of the conversion of all children
337
- * of the given item. When no child was converted, the range is collapsed.
338
- * * `result.modelCursor` The position where the conversion should be continued.
339
- */
340
- convertChildren(viewElement: ViewElement | ViewDocumentFragment, positionOrElement: ModelPosition | ModelElement): {
341
- modelRange: ModelRange | null;
342
- modelCursor: ModelPosition;
343
- };
344
- /**
345
- * Safely inserts an element to the document, checking the
346
- * {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent
347
- * for an element that you are going to insert, starting from the given position. If the current parent does not allow to insert
348
- * the element but one of the ancestors does, then splits the nodes to allowed parent.
349
- *
350
- * If the schema allows to insert the node in a given position, nothing is split.
351
- *
352
- * If it was not possible to find an allowed parent, `false` is returned and nothing is split.
353
- *
354
- * Otherwise, ancestors are split.
355
- *
356
- * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
357
- *
358
- * ```
359
- * <paragraph>foo[]bar</paragraph>
360
- *
361
- * -> safe insert for `<imageBlock>` will split ->
362
- *
363
- * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
364
- *```
365
- *
366
- * Example usage:
367
- *
368
- * ```
369
- * const myElement = conversionApi.writer.createElement( 'myElement' );
370
- *
371
- * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
372
- * return;
373
- * }
374
- *```
375
- *
376
- * The split result is saved and {@link #updateConversionResult} should be used to update the
377
- * {@link module:engine/conversion/upcastdispatcher~UpcastConversionData conversion data}.
378
- *
379
- * @param modelNode The node to insert.
380
- * @param position The position where an element is going to be inserted.
381
- * @returns The split result. If it was not possible to find an allowed position, `false` is returned.
382
- */
383
- safeInsert(modelNode: ModelNode, position: ModelPosition): boolean;
384
- /**
385
- * Updates the conversion result and sets a proper {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelRange} and
386
- * the next {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelCursor} after the conversion.
387
- * Used together with {@link #safeInsert}, it enables you to easily convert elements without worrying if the node was split
388
- * during the conversion of its children.
389
- *
390
- * A usage example in converter code:
391
- *
392
- * ```ts
393
- * const myElement = conversionApi.writer.createElement( 'myElement' );
394
- *
395
- * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
396
- * return;
397
- * }
398
- *
399
- * // Children conversion may split `myElement`.
400
- * conversionApi.convertChildren( data.viewItem, myElement );
401
- *
402
- * conversionApi.updateConversionResult( myElement, data );
403
- * ```
404
- */
405
- updateConversionResult(modelElement: ModelElement, data: UpcastConversionData): void;
406
- /**
407
- * Checks the {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent for an element
408
- * that is going to be inserted starting from the given position. If the current parent does not allow
409
- * inserting an element but one of the ancestors does, the method splits nodes to allowed parent.
410
- *
411
- * If the schema allows inserting the node in the given position, nothing is split and an object with that position is returned.
412
- *
413
- * If it was not possible to find an allowed parent, `null` is returned and nothing is split.
414
- *
415
- * Otherwise, ancestors are split and an object with a position and the copy of the split element is returned.
416
- *
417
- * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
418
- *
419
- * ```
420
- * <paragraph>foo[]bar</paragraph>
421
- *
422
- * -> split for `<imageBlock>` ->
423
- *
424
- * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
425
- * ```
426
- *
427
- * In the example above, the position between `<paragraph>` elements will be returned as `position` and the second `paragraph`
428
- * as `cursorParent`.
429
- *
430
- * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
431
- *
432
- * @param modelNode The node to insert.
433
- * @param modelCursor The position where the element is going to be inserted.
434
- * @returns The split result. If it was not possible to find an allowed position, `null` is returned.
435
- * * `position` The position between split elements.
436
- * * `cursorParent` The element inside which the cursor should be placed to
437
- * continue the conversion. When the element is not defined it means that there was no split.
438
- */
439
- splitToAllowedParent(modelNode: ModelNode, modelCursor: ModelPosition): {
440
- position: ModelPosition;
441
- cursorParent?: ModelElement | ModelDocumentFragment;
442
- } | null;
443
- /**
444
- * Returns all the split parts of the given `element` that were created during upcasting through using {@link #splitToAllowedParent}.
445
- * It enables you to easily track these elements and continue processing them after they are split during the conversion of their
446
- * children.
447
- *
448
- * ```
449
- * <paragraph>Foo<imageBlock />bar<imageBlock />baz</paragraph> ->
450
- * <paragraph>Foo</paragraph><imageBlock /><paragraph>bar</paragraph><imageBlock /><paragraph>baz</paragraph>
451
- * ```
452
- *
453
- * For a reference to any of above paragraphs, the function will return all three paragraphs (the original element included),
454
- * sorted in the order of their creation (the original element is the first one).
455
- *
456
- * If the given `element` was not split, an array with a single element is returned.
457
- *
458
- * A usage example in the converter code:
459
- *
460
- * ```ts
461
- * const myElement = conversionApi.writer.createElement( 'myElement' );
462
- *
463
- * // Children conversion may split `myElement`.
464
- * conversionApi.convertChildren( data.viewItem, data.modelCursor );
465
- *
466
- * const splitParts = conversionApi.getSplitParts( myElement );
467
- * const lastSplitPart = splitParts[ splitParts.length - 1 ];
468
- *
469
- * // Setting `data.modelRange` basing on split parts:
470
- * data.modelRange = conversionApi.writer.createRange(
471
- * conversionApi.writer.createPositionBefore( myElement ),
472
- * conversionApi.writer.createPositionAfter( lastSplitPart )
473
- * );
474
- *
475
- * // Setting `data.modelCursor` to continue after the last split element:
476
- * data.modelCursor = conversionApi.writer.createPositionAfter( lastSplitPart );
477
- * ```
478
- *
479
- * **Tip:** If you are unable to get a reference to the original element (for example because the code is split into multiple converters
480
- * or even classes) but it has already been converted, you may want to check the first element in `data.modelRange`. This is a common
481
- * situation if an attribute converter is separated from an element converter.
482
- *
483
- * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
484
- */
485
- getSplitParts(modelElement: ModelElement): Array<ModelElement>;
486
- /**
487
- * Mark an element that was created during splitting to not get removed on conversion end even if it is empty.
488
- *
489
- * **Note:** This is an advanced method. For most cases you will not need to keep the split empty element.
490
- */
491
- keepEmptyElement(modelElement: ModelElement): void;
290
+ /**
291
+ * Stores information about what parts of the processed view item are still waiting to be handled. After a piece of view item
292
+ * was converted, an appropriate consumable value should be
293
+ * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume consumed}.
294
+ */
295
+ consumable: ViewConsumable;
296
+ /**
297
+ * The model's schema instance.
298
+ */
299
+ schema: ModelSchema;
300
+ /**
301
+ * The {@link module:engine/model/writer~ModelWriter} instance used to manipulate the data during conversion.
302
+ */
303
+ writer: ModelWriter;
304
+ /**
305
+ * Custom data stored by converters for the conversion process. Custom properties of this object can be defined and use to
306
+ * pass parameters between converters.
307
+ *
308
+ * The difference between this property and the `data` parameter of
309
+ * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element} is that the `data` parameters allow you
310
+ * to pass parameters within a single event and `store` within the whole conversion.
311
+ */
312
+ store: unknown;
313
+ /**
314
+ * Starts the conversion of a given item by firing an appropriate event.
315
+ *
316
+ * Every fired event is passed (as the first parameter) an object with the `modelRange` property. Every event may set and/or
317
+ * modify that property. When all callbacks are done, the final value of the `modelRange` property is returned by this method.
318
+ * The `modelRange` must be a {@link module:engine/model/range~ModelRange model range} or `null` (as set by default).
319
+ *
320
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
321
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
322
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
323
+ * @param viewItem Item to convert.
324
+ * @param modelCursor The conversion position.
325
+ * @returns The conversion result:
326
+ * * `result.modelRange` The model range containing the result of the item conversion,
327
+ * created and modified by callbacks attached to the fired event, or `null` if the conversion result was incorrect.
328
+ * * `result.modelCursor` The position where the conversion should be continued.
329
+ */
330
+ convertItem(viewItem: ViewItem, modelCursor: ModelPosition): {
331
+ modelRange: ModelRange | null;
332
+ modelCursor: ModelPosition;
333
+ };
334
+ /**
335
+ * Starts the conversion of all children of a given item by firing appropriate events for all the children.
336
+ *
337
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
338
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
339
+ * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
340
+ * @param viewElement An element whose children should be converted.
341
+ * @param positionOrElement A position or an element of
342
+ * the conversion.
343
+ * @returns The conversion result:
344
+ * * `result.modelRange` The model range containing the results of the conversion of all children
345
+ * of the given item. When no child was converted, the range is collapsed.
346
+ * * `result.modelCursor` The position where the conversion should be continued.
347
+ */
348
+ convertChildren(viewElement: ViewElement | ViewDocumentFragment, positionOrElement: ModelPosition | ModelElement): {
349
+ modelRange: ModelRange | null;
350
+ modelCursor: ModelPosition;
351
+ };
352
+ /**
353
+ * Safely inserts an element to the document, checking the
354
+ * {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent
355
+ * for an element that you are going to insert, starting from the given position. If the current parent does not allow to insert
356
+ * the element but one of the ancestors does, then splits the nodes to allowed parent.
357
+ *
358
+ * If the schema allows to insert the node in a given position, nothing is split.
359
+ *
360
+ * If it was not possible to find an allowed parent, `false` is returned and nothing is split.
361
+ *
362
+ * Otherwise, ancestors are split.
363
+ *
364
+ * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
365
+ *
366
+ * ```
367
+ * <paragraph>foo[]bar</paragraph>
368
+ *
369
+ * -> safe insert for `<imageBlock>` will split ->
370
+ *
371
+ * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
372
+ *```
373
+ *
374
+ * Example usage:
375
+ *
376
+ * ```
377
+ * const myElement = conversionApi.writer.createElement( 'myElement' );
378
+ *
379
+ * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
380
+ * return;
381
+ * }
382
+ *```
383
+ *
384
+ * The split result is saved and {@link #updateConversionResult} should be used to update the
385
+ * {@link module:engine/conversion/upcastdispatcher~UpcastConversionData conversion data}.
386
+ *
387
+ * @param modelNode The node to insert.
388
+ * @param position The position where an element is going to be inserted.
389
+ * @returns The split result. If it was not possible to find an allowed position, `false` is returned.
390
+ */
391
+ safeInsert(modelNode: ModelNode, position: ModelPosition): boolean;
392
+ /**
393
+ * Updates the conversion result and sets a proper {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelRange} and
394
+ * the next {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelCursor} after the conversion.
395
+ * Used together with {@link #safeInsert}, it enables you to easily convert elements without worrying if the node was split
396
+ * during the conversion of its children.
397
+ *
398
+ * A usage example in converter code:
399
+ *
400
+ * ```ts
401
+ * const myElement = conversionApi.writer.createElement( 'myElement' );
402
+ *
403
+ * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
404
+ * return;
405
+ * }
406
+ *
407
+ * // Children conversion may split `myElement`.
408
+ * conversionApi.convertChildren( data.viewItem, myElement );
409
+ *
410
+ * conversionApi.updateConversionResult( myElement, data );
411
+ * ```
412
+ */
413
+ updateConversionResult(modelElement: ModelElement, data: UpcastConversionData): void;
414
+ /**
415
+ * Checks the {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent for an element
416
+ * that is going to be inserted starting from the given position. If the current parent does not allow
417
+ * inserting an element but one of the ancestors does, the method splits nodes to allowed parent.
418
+ *
419
+ * If the schema allows inserting the node in the given position, nothing is split and an object with that position is returned.
420
+ *
421
+ * If it was not possible to find an allowed parent, `null` is returned and nothing is split.
422
+ *
423
+ * Otherwise, ancestors are split and an object with a position and the copy of the split element is returned.
424
+ *
425
+ * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
426
+ *
427
+ * ```
428
+ * <paragraph>foo[]bar</paragraph>
429
+ *
430
+ * -> split for `<imageBlock>` ->
431
+ *
432
+ * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
433
+ * ```
434
+ *
435
+ * In the example above, the position between `<paragraph>` elements will be returned as `position` and the second `paragraph`
436
+ * as `cursorParent`.
437
+ *
438
+ * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
439
+ *
440
+ * @param modelNode The node to insert.
441
+ * @param modelCursor The position where the element is going to be inserted.
442
+ * @returns The split result. If it was not possible to find an allowed position, `null` is returned.
443
+ * * `position` The position between split elements.
444
+ * * `cursorParent` The element inside which the cursor should be placed to
445
+ * continue the conversion. When the element is not defined it means that there was no split.
446
+ */
447
+ splitToAllowedParent(modelNode: ModelNode, modelCursor: ModelPosition): {
448
+ position: ModelPosition;
449
+ cursorParent?: ModelElement | ModelDocumentFragment;
450
+ } | null;
451
+ /**
452
+ * Returns all the split parts of the given `element` that were created during upcasting through using {@link #splitToAllowedParent}.
453
+ * It enables you to easily track these elements and continue processing them after they are split during the conversion of their
454
+ * children.
455
+ *
456
+ * ```
457
+ * <paragraph>Foo<imageBlock />bar<imageBlock />baz</paragraph> ->
458
+ * <paragraph>Foo</paragraph><imageBlock /><paragraph>bar</paragraph><imageBlock /><paragraph>baz</paragraph>
459
+ * ```
460
+ *
461
+ * For a reference to any of above paragraphs, the function will return all three paragraphs (the original element included),
462
+ * sorted in the order of their creation (the original element is the first one).
463
+ *
464
+ * If the given `element` was not split, an array with a single element is returned.
465
+ *
466
+ * A usage example in the converter code:
467
+ *
468
+ * ```ts
469
+ * const myElement = conversionApi.writer.createElement( 'myElement' );
470
+ *
471
+ * // Children conversion may split `myElement`.
472
+ * conversionApi.convertChildren( data.viewItem, data.modelCursor );
473
+ *
474
+ * const splitParts = conversionApi.getSplitParts( myElement );
475
+ * const lastSplitPart = splitParts[ splitParts.length - 1 ];
476
+ *
477
+ * // Setting `data.modelRange` basing on split parts:
478
+ * data.modelRange = conversionApi.writer.createRange(
479
+ * conversionApi.writer.createPositionBefore( myElement ),
480
+ * conversionApi.writer.createPositionAfter( lastSplitPart )
481
+ * );
482
+ *
483
+ * // Setting `data.modelCursor` to continue after the last split element:
484
+ * data.modelCursor = conversionApi.writer.createPositionAfter( lastSplitPart );
485
+ * ```
486
+ *
487
+ * **Tip:** If you are unable to get a reference to the original element (for example because the code is split into multiple converters
488
+ * or even classes) but it has already been converted, you may want to check the first element in `data.modelRange`. This is a common
489
+ * situation if an attribute converter is separated from an element converter.
490
+ *
491
+ * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
492
+ */
493
+ getSplitParts(modelElement: ModelElement): Array<ModelElement>;
494
+ /**
495
+ * Mark an element that was created during splitting to not get removed on conversion end even if it is empty.
496
+ *
497
+ * **Note:** This is an advanced method. For most cases you will not need to keep the split empty element.
498
+ */
499
+ keepEmptyElement(modelElement: ModelElement): void;
492
500
  }
493
501
  export {};