@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,500 +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
- * **Note:** The default `context` value is `[ '$root' ]`, which only matches the generic root. When the editor uses
161
- * a custom root {@link module:core/editor/editorconfig~RootConfig#modelElement `modelElement`}, pass the target
162
- * {@link module:engine/model/rootelement~ModelRootElement root element} (or its configured model element name)
163
- * explicitly, otherwise the conversion result may be wrong.
164
- * See the {@glink framework/deep-dive/schema#custom-root-elements Custom root elements} section of the
165
- * {@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
166
- *
167
- * @fires element
168
- * @fires text
169
- * @fires documentFragment
170
- * @param viewElement The part of the view to be converted.
171
- * @param writer An instance of the model writer.
172
- * @param context Elements will be converted according to this context.
173
- * @returns Model data that is the result of the conversion process
174
- * wrapped in `DocumentFragment`. Converted marker elements will be set as the document fragment's
175
- * {@link module:engine/model/documentfragment~ModelDocumentFragment#markers static markers map}.
176
- */
177
- convert(viewElement: ViewElement | ViewDocumentFragment, writer: ModelWriter, context?: ModelSchemaContextDefinition): ModelDocumentFragment;
178
- /**
179
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertItem
180
- */
181
- private _convertItem;
182
- /**
183
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#convertChildren
184
- */
185
- private _convertChildren;
186
- /**
187
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#safeInsert
188
- */
189
- private _safeInsert;
190
- /**
191
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#updateConversionResult
192
- */
193
- private _updateConversionResult;
194
- /**
195
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#splitToAllowedParent
196
- */
197
- private _splitToAllowedParent;
198
- /**
199
- * Registers that a `splitPart` element is a split part of the `originalPart` element.
200
- *
201
- * The data set by this method is used by {@link #_getSplitParts} and {@link #_removeEmptyElements}.
202
- */
203
- private _registerSplitPair;
204
- /**
205
- * @see module:engine/conversion/upcastdispatcher~UpcastConversionApi#getSplitParts
206
- */
207
- private _getSplitParts;
208
- /**
209
- * Mark an element that were created during the splitting to not get removed on conversion end even if it is empty.
210
- */
211
- private _keepEmptyElement;
212
- /**
213
- * Checks if there are any empty elements created while splitting and removes them.
214
- *
215
- * This method works recursively to re-check empty elements again after at least one element was removed in the initial call,
216
- * as some elements might have become empty after other empty elements were removed from them.
217
- */
218
- 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;
219
217
  }
220
218
  /**
221
- * Fired before the first conversion event, at the beginning of the upcast (view-to-model conversion) process.
222
- *
223
- * @eventName ~UpcastDispatcher#viewCleanup
224
- * @param viewItem A part of the view to be converted.
225
- */
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
+ */
226
224
  export type UpcastViewCleanupEvent = {
227
- name: 'viewCleanup';
228
- args: [ViewElement | ViewDocumentFragment];
225
+ name: "viewCleanup";
226
+ args: [ViewElement | ViewDocumentFragment];
229
227
  };
230
- export type UpcastEvent<TName extends string, TItem extends ViewItem | ViewDocumentFragment> = {
231
- name: TName | `${TName}:${string}`;
232
- 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];
233
234
  };
234
235
  /**
235
- * Conversion data.
236
- *
237
- * **Note:** Keep in mind that this object is shared by reference between all conversion callbacks that will be called.
238
- * This means that callbacks can override values if needed, and these values will be available in other callbacks.
239
- */
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
+ */
240
241
  export interface UpcastConversionData<TItem extends ViewItem | ViewDocumentFragment = ViewItem | ViewDocumentFragment> {
241
- /**
242
- * The converted item.
243
- */
244
- viewItem: TItem;
245
- /**
246
- * The position where the converter should start changes.
247
- * Change this value for the next converter to tell where the conversion should continue.
248
- */
249
- modelCursor: ModelPosition;
250
- /**
251
- * The current state of conversion result. Every change to
252
- * the converted element should be reflected by setting or modifying this property.
253
- */
254
- 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;
255
256
  }
256
257
  /**
257
- * Fired when an {@link module:engine/view/element~ViewElement} is converted.
258
- *
259
- * `element` is a namespace event for a class of events. Names of actually called events follow the pattern of
260
- * `element:<elementName>` where `elementName` is the name of the converted element. This way listeners may listen to
261
- * a conversion of all or just specific elements.
262
- *
263
- * @eventName ~UpcastDispatcher#element
264
- * @param data The conversion data. Keep in mind that this object is shared by reference between all callbacks
265
- * that will be called. This means that callbacks can override values if needed, and these values
266
- * will be available in other callbacks.
267
- * @param conversionApi Conversion utilities to be used by the callback.
268
- */
269
- 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>;
270
271
  /**
271
- * Fired when a {@link module:engine/view/text~ViewText} is converted.
272
- *
273
- * @eventName ~UpcastDispatcher#text
274
- * @see ~UpcastDispatcher#event:element
275
- */
276
- 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>;
277
278
  /**
278
- * Fired when a {@link module:engine/view/documentfragment~ViewDocumentFragment} is converted.
279
- *
280
- * @eventName ~UpcastDispatcher#documentFragment
281
- * @see ~UpcastDispatcher#event:element
282
- */
283
- 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>;
284
285
  /**
285
- * A set of conversion utilities available as the third parameter of the
286
- * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher upcast dispatcher}'s events.
287
- */
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
+ */
288
289
  export interface UpcastConversionApi {
289
- /**
290
- * Stores information about what parts of the processed view item are still waiting to be handled. After a piece of view item
291
- * was converted, an appropriate consumable value should be
292
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume consumed}.
293
- */
294
- consumable: ViewConsumable;
295
- /**
296
- * The model's schema instance.
297
- */
298
- schema: ModelSchema;
299
- /**
300
- * The {@link module:engine/model/writer~ModelWriter} instance used to manipulate the data during conversion.
301
- */
302
- writer: ModelWriter;
303
- /**
304
- * Custom data stored by converters for the conversion process. Custom properties of this object can be defined and use to
305
- * pass parameters between converters.
306
- *
307
- * The difference between this property and the `data` parameter of
308
- * {@link module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element} is that the `data` parameters allow you
309
- * to pass parameters within a single event and `store` within the whole conversion.
310
- */
311
- store: unknown;
312
- /**
313
- * Starts the conversion of a given item by firing an appropriate event.
314
- *
315
- * Every fired event is passed (as the first parameter) an object with the `modelRange` property. Every event may set and/or
316
- * modify that property. When all callbacks are done, the final value of the `modelRange` property is returned by this method.
317
- * The `modelRange` must be a {@link module:engine/model/range~ModelRange model range} or `null` (as set by default).
318
- *
319
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
320
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
321
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
322
- * @param viewItem Item to convert.
323
- * @param modelCursor The conversion position.
324
- * @returns The conversion result:
325
- * * `result.modelRange` The model range containing the result of the item conversion,
326
- * created and modified by callbacks attached to the fired event, or `null` if the conversion result was incorrect.
327
- * * `result.modelCursor` The position where the conversion should be continued.
328
- */
329
- convertItem(viewItem: ViewItem, modelCursor: ModelPosition): {
330
- modelRange: ModelRange | null;
331
- modelCursor: ModelPosition;
332
- };
333
- /**
334
- * Starts the conversion of all children of a given item by firing appropriate events for all the children.
335
- *
336
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
337
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:text
338
- * @fires module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:documentFragment
339
- * @param viewElement An element whose children should be converted.
340
- * @param positionOrElement A position or an element of
341
- * the conversion.
342
- * @returns The conversion result:
343
- * * `result.modelRange` The model range containing the results of the conversion of all children
344
- * of the given item. When no child was converted, the range is collapsed.
345
- * * `result.modelCursor` The position where the conversion should be continued.
346
- */
347
- convertChildren(viewElement: ViewElement | ViewDocumentFragment, positionOrElement: ModelPosition | ModelElement): {
348
- modelRange: ModelRange | null;
349
- modelCursor: ModelPosition;
350
- };
351
- /**
352
- * Safely inserts an element to the document, checking the
353
- * {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent
354
- * for an element that you are going to insert, starting from the given position. If the current parent does not allow to insert
355
- * the element but one of the ancestors does, then splits the nodes to allowed parent.
356
- *
357
- * If the schema allows to insert the node in a given position, nothing is split.
358
- *
359
- * If it was not possible to find an allowed parent, `false` is returned and nothing is split.
360
- *
361
- * Otherwise, ancestors are split.
362
- *
363
- * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
364
- *
365
- * ```
366
- * <paragraph>foo[]bar</paragraph>
367
- *
368
- * -> safe insert for `<imageBlock>` will split ->
369
- *
370
- * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
371
- *```
372
- *
373
- * Example usage:
374
- *
375
- * ```
376
- * const myElement = conversionApi.writer.createElement( 'myElement' );
377
- *
378
- * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
379
- * return;
380
- * }
381
- *```
382
- *
383
- * The split result is saved and {@link #updateConversionResult} should be used to update the
384
- * {@link module:engine/conversion/upcastdispatcher~UpcastConversionData conversion data}.
385
- *
386
- * @param modelNode The node to insert.
387
- * @param position The position where an element is going to be inserted.
388
- * @returns The split result. If it was not possible to find an allowed position, `false` is returned.
389
- */
390
- safeInsert(modelNode: ModelNode, position: ModelPosition): boolean;
391
- /**
392
- * Updates the conversion result and sets a proper {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelRange} and
393
- * the next {@link module:engine/conversion/upcastdispatcher~UpcastConversionData#modelCursor} after the conversion.
394
- * Used together with {@link #safeInsert}, it enables you to easily convert elements without worrying if the node was split
395
- * during the conversion of its children.
396
- *
397
- * A usage example in converter code:
398
- *
399
- * ```ts
400
- * const myElement = conversionApi.writer.createElement( 'myElement' );
401
- *
402
- * if ( !conversionApi.safeInsert( myElement, data.modelCursor ) ) {
403
- * return;
404
- * }
405
- *
406
- * // Children conversion may split `myElement`.
407
- * conversionApi.convertChildren( data.viewItem, myElement );
408
- *
409
- * conversionApi.updateConversionResult( myElement, data );
410
- * ```
411
- */
412
- updateConversionResult(modelElement: ModelElement, data: UpcastConversionData): void;
413
- /**
414
- * Checks the {@link module:engine/model/schema~ModelSchema schema} to find an allowed parent for an element
415
- * that is going to be inserted starting from the given position. If the current parent does not allow
416
- * inserting an element but one of the ancestors does, the method splits nodes to allowed parent.
417
- *
418
- * If the schema allows inserting the node in the given position, nothing is split and an object with that position is returned.
419
- *
420
- * If it was not possible to find an allowed parent, `null` is returned and nothing is split.
421
- *
422
- * Otherwise, ancestors are split and an object with a position and the copy of the split element is returned.
423
- *
424
- * For instance, if `<imageBlock>` is not allowed in `<paragraph>` but is allowed in `$root`:
425
- *
426
- * ```
427
- * <paragraph>foo[]bar</paragraph>
428
- *
429
- * -> split for `<imageBlock>` ->
430
- *
431
- * <paragraph>foo</paragraph>[]<paragraph>bar</paragraph>
432
- * ```
433
- *
434
- * In the example above, the position between `<paragraph>` elements will be returned as `position` and the second `paragraph`
435
- * as `cursorParent`.
436
- *
437
- * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
438
- *
439
- * @param modelNode The node to insert.
440
- * @param modelCursor The position where the element is going to be inserted.
441
- * @returns The split result. If it was not possible to find an allowed position, `null` is returned.
442
- * * `position` The position between split elements.
443
- * * `cursorParent` The element inside which the cursor should be placed to
444
- * continue the conversion. When the element is not defined it means that there was no split.
445
- */
446
- splitToAllowedParent(modelNode: ModelNode, modelCursor: ModelPosition): {
447
- position: ModelPosition;
448
- cursorParent?: ModelElement | ModelDocumentFragment;
449
- } | null;
450
- /**
451
- * Returns all the split parts of the given `element` that were created during upcasting through using {@link #splitToAllowedParent}.
452
- * It enables you to easily track these elements and continue processing them after they are split during the conversion of their
453
- * children.
454
- *
455
- * ```
456
- * <paragraph>Foo<imageBlock />bar<imageBlock />baz</paragraph> ->
457
- * <paragraph>Foo</paragraph><imageBlock /><paragraph>bar</paragraph><imageBlock /><paragraph>baz</paragraph>
458
- * ```
459
- *
460
- * For a reference to any of above paragraphs, the function will return all three paragraphs (the original element included),
461
- * sorted in the order of their creation (the original element is the first one).
462
- *
463
- * If the given `element` was not split, an array with a single element is returned.
464
- *
465
- * A usage example in the converter code:
466
- *
467
- * ```ts
468
- * const myElement = conversionApi.writer.createElement( 'myElement' );
469
- *
470
- * // Children conversion may split `myElement`.
471
- * conversionApi.convertChildren( data.viewItem, data.modelCursor );
472
- *
473
- * const splitParts = conversionApi.getSplitParts( myElement );
474
- * const lastSplitPart = splitParts[ splitParts.length - 1 ];
475
- *
476
- * // Setting `data.modelRange` basing on split parts:
477
- * data.modelRange = conversionApi.writer.createRange(
478
- * conversionApi.writer.createPositionBefore( myElement ),
479
- * conversionApi.writer.createPositionAfter( lastSplitPart )
480
- * );
481
- *
482
- * // Setting `data.modelCursor` to continue after the last split element:
483
- * data.modelCursor = conversionApi.writer.createPositionAfter( lastSplitPart );
484
- * ```
485
- *
486
- * **Tip:** If you are unable to get a reference to the original element (for example because the code is split into multiple converters
487
- * or even classes) but it has already been converted, you may want to check the first element in `data.modelRange`. This is a common
488
- * situation if an attribute converter is separated from an element converter.
489
- *
490
- * **Note:** This is an advanced method. For most cases {@link #safeInsert} and {@link #updateConversionResult} should be used.
491
- */
492
- getSplitParts(modelElement: ModelElement): Array<ModelElement>;
493
- /**
494
- * Mark an element that was created during splitting to not get removed on conversion end even if it is empty.
495
- *
496
- * **Note:** This is an advanced method. For most cases you will not need to keep the split empty element.
497
- */
498
- 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;
499
500
  }
500
501
  export {};