@ckeditor/ckeditor5-engine 39.0.1 → 40.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/LICENSE.md +1 -1
  3. package/README.md +8 -8
  4. package/package.json +2 -6
  5. package/src/controller/datacontroller.d.ts +334 -334
  6. package/src/controller/datacontroller.js +481 -481
  7. package/src/controller/editingcontroller.d.ts +98 -98
  8. package/src/controller/editingcontroller.js +191 -191
  9. package/src/conversion/conversion.d.ts +478 -478
  10. package/src/conversion/conversion.js +601 -601
  11. package/src/conversion/conversionhelpers.d.ts +26 -26
  12. package/src/conversion/conversionhelpers.js +32 -32
  13. package/src/conversion/downcastdispatcher.d.ts +562 -562
  14. package/src/conversion/downcastdispatcher.js +547 -547
  15. package/src/conversion/downcasthelpers.d.ts +1226 -1226
  16. package/src/conversion/downcasthelpers.js +2183 -2183
  17. package/src/conversion/mapper.d.ts +503 -503
  18. package/src/conversion/mapper.js +536 -536
  19. package/src/conversion/modelconsumable.d.ts +201 -201
  20. package/src/conversion/modelconsumable.js +333 -333
  21. package/src/conversion/upcastdispatcher.d.ts +492 -492
  22. package/src/conversion/upcastdispatcher.js +460 -460
  23. package/src/conversion/upcasthelpers.d.ts +499 -499
  24. package/src/conversion/upcasthelpers.js +950 -950
  25. package/src/conversion/viewconsumable.d.ts +369 -369
  26. package/src/conversion/viewconsumable.js +532 -532
  27. package/src/dataprocessor/basichtmlwriter.d.ts +18 -18
  28. package/src/dataprocessor/basichtmlwriter.js +19 -19
  29. package/src/dataprocessor/dataprocessor.d.ts +61 -61
  30. package/src/dataprocessor/dataprocessor.js +5 -5
  31. package/src/dataprocessor/htmldataprocessor.d.ts +76 -76
  32. package/src/dataprocessor/htmldataprocessor.js +96 -96
  33. package/src/dataprocessor/htmlwriter.d.ts +16 -16
  34. package/src/dataprocessor/htmlwriter.js +5 -5
  35. package/src/dataprocessor/xmldataprocessor.d.ts +90 -90
  36. package/src/dataprocessor/xmldataprocessor.js +108 -108
  37. package/src/dev-utils/model.d.ts +124 -124
  38. package/src/dev-utils/model.js +395 -395
  39. package/src/dev-utils/operationreplayer.d.ts +51 -51
  40. package/src/dev-utils/operationreplayer.js +112 -112
  41. package/src/dev-utils/utils.d.ts +37 -37
  42. package/src/dev-utils/utils.js +73 -73
  43. package/src/dev-utils/view.d.ts +319 -319
  44. package/src/dev-utils/view.js +967 -967
  45. package/src/index.d.ts +114 -114
  46. package/src/index.js +78 -78
  47. package/src/model/batch.d.ts +106 -106
  48. package/src/model/batch.js +96 -96
  49. package/src/model/differ.d.ts +387 -387
  50. package/src/model/differ.js +1149 -1149
  51. package/src/model/document.d.ts +272 -272
  52. package/src/model/document.js +361 -361
  53. package/src/model/documentfragment.d.ts +200 -200
  54. package/src/model/documentfragment.js +306 -306
  55. package/src/model/documentselection.d.ts +420 -420
  56. package/src/model/documentselection.js +993 -993
  57. package/src/model/element.d.ts +165 -165
  58. package/src/model/element.js +281 -281
  59. package/src/model/history.d.ts +114 -114
  60. package/src/model/history.js +207 -207
  61. package/src/model/item.d.ts +14 -14
  62. package/src/model/item.js +5 -5
  63. package/src/model/liveposition.d.ts +77 -77
  64. package/src/model/liveposition.js +93 -93
  65. package/src/model/liverange.d.ts +102 -102
  66. package/src/model/liverange.js +120 -120
  67. package/src/model/markercollection.d.ts +335 -335
  68. package/src/model/markercollection.js +403 -403
  69. package/src/model/model.d.ts +919 -919
  70. package/src/model/model.js +842 -842
  71. package/src/model/node.d.ts +256 -256
  72. package/src/model/node.js +375 -375
  73. package/src/model/nodelist.d.ts +91 -91
  74. package/src/model/nodelist.js +163 -163
  75. package/src/model/operation/attributeoperation.d.ts +103 -103
  76. package/src/model/operation/attributeoperation.js +148 -148
  77. package/src/model/operation/detachoperation.d.ts +60 -60
  78. package/src/model/operation/detachoperation.js +77 -77
  79. package/src/model/operation/insertoperation.d.ts +90 -90
  80. package/src/model/operation/insertoperation.js +135 -135
  81. package/src/model/operation/markeroperation.d.ts +91 -91
  82. package/src/model/operation/markeroperation.js +107 -107
  83. package/src/model/operation/mergeoperation.d.ts +100 -100
  84. package/src/model/operation/mergeoperation.js +167 -167
  85. package/src/model/operation/moveoperation.d.ts +96 -96
  86. package/src/model/operation/moveoperation.js +164 -164
  87. package/src/model/operation/nooperation.d.ts +38 -38
  88. package/src/model/operation/nooperation.js +48 -48
  89. package/src/model/operation/operation.d.ts +96 -96
  90. package/src/model/operation/operation.js +62 -62
  91. package/src/model/operation/operationfactory.d.ts +18 -18
  92. package/src/model/operation/operationfactory.js +44 -44
  93. package/src/model/operation/renameoperation.d.ts +83 -83
  94. package/src/model/operation/renameoperation.js +115 -115
  95. package/src/model/operation/rootattributeoperation.d.ts +98 -98
  96. package/src/model/operation/rootattributeoperation.js +155 -155
  97. package/src/model/operation/rootoperation.d.ts +76 -76
  98. package/src/model/operation/rootoperation.js +90 -90
  99. package/src/model/operation/splitoperation.d.ts +109 -109
  100. package/src/model/operation/splitoperation.js +194 -194
  101. package/src/model/operation/transform.d.ts +100 -100
  102. package/src/model/operation/transform.js +1985 -1985
  103. package/src/model/operation/utils.d.ts +71 -71
  104. package/src/model/operation/utils.js +213 -213
  105. package/src/model/position.d.ts +539 -539
  106. package/src/model/position.js +979 -979
  107. package/src/model/range.d.ts +458 -458
  108. package/src/model/range.js +875 -875
  109. package/src/model/rootelement.d.ts +60 -60
  110. package/src/model/rootelement.js +74 -74
  111. package/src/model/schema.d.ts +1186 -1186
  112. package/src/model/schema.js +1242 -1242
  113. package/src/model/selection.d.ts +482 -482
  114. package/src/model/selection.js +789 -789
  115. package/src/model/text.d.ts +66 -66
  116. package/src/model/text.js +85 -85
  117. package/src/model/textproxy.d.ts +144 -144
  118. package/src/model/textproxy.js +189 -189
  119. package/src/model/treewalker.d.ts +186 -186
  120. package/src/model/treewalker.js +244 -244
  121. package/src/model/typecheckable.d.ts +285 -285
  122. package/src/model/typecheckable.js +16 -16
  123. package/src/model/utils/autoparagraphing.d.ts +37 -37
  124. package/src/model/utils/autoparagraphing.js +63 -63
  125. package/src/model/utils/deletecontent.d.ts +58 -58
  126. package/src/model/utils/deletecontent.js +488 -488
  127. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -32
  128. package/src/model/utils/findoptimalinsertionrange.js +57 -57
  129. package/src/model/utils/getselectedcontent.d.ts +30 -30
  130. package/src/model/utils/getselectedcontent.js +125 -125
  131. package/src/model/utils/insertcontent.d.ts +46 -46
  132. package/src/model/utils/insertcontent.js +705 -705
  133. package/src/model/utils/insertobject.d.ts +44 -44
  134. package/src/model/utils/insertobject.js +139 -139
  135. package/src/model/utils/modifyselection.d.ts +48 -48
  136. package/src/model/utils/modifyselection.js +186 -186
  137. package/src/model/utils/selection-post-fixer.d.ts +74 -74
  138. package/src/model/utils/selection-post-fixer.js +260 -260
  139. package/src/model/writer.d.ts +851 -851
  140. package/src/model/writer.js +1306 -1306
  141. package/src/view/attributeelement.d.ts +108 -108
  142. package/src/view/attributeelement.js +184 -184
  143. package/src/view/containerelement.d.ts +49 -49
  144. package/src/view/containerelement.js +80 -80
  145. package/src/view/datatransfer.d.ts +79 -79
  146. package/src/view/datatransfer.js +98 -98
  147. package/src/view/document.d.ts +184 -184
  148. package/src/view/document.js +120 -120
  149. package/src/view/documentfragment.d.ts +149 -149
  150. package/src/view/documentfragment.js +228 -228
  151. package/src/view/documentselection.d.ts +306 -306
  152. package/src/view/documentselection.js +256 -256
  153. package/src/view/domconverter.d.ts +640 -640
  154. package/src/view/domconverter.js +1450 -1425
  155. package/src/view/downcastwriter.d.ts +996 -996
  156. package/src/view/downcastwriter.js +1696 -1696
  157. package/src/view/editableelement.d.ts +62 -62
  158. package/src/view/editableelement.js +62 -62
  159. package/src/view/element.d.ts +468 -468
  160. package/src/view/element.js +724 -724
  161. package/src/view/elementdefinition.d.ts +87 -87
  162. package/src/view/elementdefinition.js +5 -5
  163. package/src/view/emptyelement.d.ts +41 -41
  164. package/src/view/emptyelement.js +73 -73
  165. package/src/view/filler.d.ts +111 -111
  166. package/src/view/filler.js +150 -150
  167. package/src/view/item.d.ts +14 -14
  168. package/src/view/item.js +5 -5
  169. package/src/view/matcher.d.ts +486 -486
  170. package/src/view/matcher.js +507 -507
  171. package/src/view/node.d.ts +163 -163
  172. package/src/view/node.js +228 -228
  173. package/src/view/observer/arrowkeysobserver.d.ts +45 -45
  174. package/src/view/observer/arrowkeysobserver.js +40 -40
  175. package/src/view/observer/bubblingemittermixin.d.ts +166 -166
  176. package/src/view/observer/bubblingemittermixin.js +172 -172
  177. package/src/view/observer/bubblingeventinfo.d.ts +47 -47
  178. package/src/view/observer/bubblingeventinfo.js +37 -37
  179. package/src/view/observer/clickobserver.d.ts +43 -43
  180. package/src/view/observer/clickobserver.js +29 -29
  181. package/src/view/observer/compositionobserver.d.ts +82 -82
  182. package/src/view/observer/compositionobserver.js +60 -60
  183. package/src/view/observer/domeventdata.d.ts +50 -50
  184. package/src/view/observer/domeventdata.js +47 -47
  185. package/src/view/observer/domeventobserver.d.ts +73 -73
  186. package/src/view/observer/domeventobserver.js +79 -79
  187. package/src/view/observer/fakeselectionobserver.d.ts +47 -47
  188. package/src/view/observer/fakeselectionobserver.js +91 -91
  189. package/src/view/observer/focusobserver.d.ts +82 -82
  190. package/src/view/observer/focusobserver.js +86 -86
  191. package/src/view/observer/inputobserver.d.ts +86 -86
  192. package/src/view/observer/inputobserver.js +164 -164
  193. package/src/view/observer/keyobserver.d.ts +66 -66
  194. package/src/view/observer/keyobserver.js +39 -39
  195. package/src/view/observer/mouseobserver.d.ts +89 -89
  196. package/src/view/observer/mouseobserver.js +29 -29
  197. package/src/view/observer/mutationobserver.d.ts +86 -86
  198. package/src/view/observer/mutationobserver.js +206 -206
  199. package/src/view/observer/observer.d.ts +89 -89
  200. package/src/view/observer/observer.js +84 -84
  201. package/src/view/observer/selectionobserver.d.ts +148 -148
  202. package/src/view/observer/selectionobserver.js +202 -202
  203. package/src/view/observer/tabobserver.d.ts +46 -46
  204. package/src/view/observer/tabobserver.js +42 -42
  205. package/src/view/placeholder.d.ts +96 -96
  206. package/src/view/placeholder.js +267 -267
  207. package/src/view/position.d.ts +189 -189
  208. package/src/view/position.js +324 -324
  209. package/src/view/range.d.ts +279 -279
  210. package/src/view/range.js +430 -430
  211. package/src/view/rawelement.d.ts +73 -73
  212. package/src/view/rawelement.js +105 -105
  213. package/src/view/renderer.d.ts +265 -265
  214. package/src/view/renderer.js +999 -999
  215. package/src/view/rooteditableelement.d.ts +41 -41
  216. package/src/view/rooteditableelement.js +69 -69
  217. package/src/view/selection.d.ts +375 -375
  218. package/src/view/selection.js +559 -559
  219. package/src/view/styles/background.d.ts +33 -33
  220. package/src/view/styles/background.js +74 -74
  221. package/src/view/styles/border.d.ts +43 -43
  222. package/src/view/styles/border.js +316 -316
  223. package/src/view/styles/margin.d.ts +29 -29
  224. package/src/view/styles/margin.js +34 -34
  225. package/src/view/styles/padding.d.ts +29 -29
  226. package/src/view/styles/padding.js +34 -34
  227. package/src/view/styles/utils.d.ts +93 -93
  228. package/src/view/styles/utils.js +219 -219
  229. package/src/view/stylesmap.d.ts +675 -675
  230. package/src/view/stylesmap.js +766 -766
  231. package/src/view/text.d.ts +74 -74
  232. package/src/view/text.js +93 -93
  233. package/src/view/textproxy.d.ts +97 -97
  234. package/src/view/textproxy.js +124 -124
  235. package/src/view/treewalker.d.ts +195 -195
  236. package/src/view/treewalker.js +327 -327
  237. package/src/view/typecheckable.d.ts +448 -448
  238. package/src/view/typecheckable.js +19 -19
  239. package/src/view/uielement.d.ts +96 -96
  240. package/src/view/uielement.js +182 -182
  241. package/src/view/upcastwriter.d.ts +417 -417
  242. package/src/view/upcastwriter.js +359 -359
  243. package/src/view/view.d.ts +487 -487
  244. package/src/view/view.js +546 -546
@@ -1,1226 +1,1226 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * Contains downcast (model-to-view) converters for {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}.
7
- *
8
- * @module engine/conversion/downcasthelpers
9
- */
10
- import ModelRange from '../model/range';
11
- import ModelSelection from '../model/selection';
12
- import ModelDocumentSelection from '../model/documentselection';
13
- import ModelElement from '../model/element';
14
- import ModelPosition from '../model/position';
15
- import ViewAttributeElement from '../view/attributeelement';
16
- import ConversionHelpers from './conversionhelpers';
17
- import type { default as DowncastDispatcher, DowncastConversionApi } from './downcastdispatcher';
18
- import type ModelConsumable from './modelconsumable';
19
- import type ModelNode from '../model/node';
20
- import type ModelItem from '../model/item';
21
- import type ModelTextProxy from '../model/textproxy';
22
- import type ModelText from '../model/text';
23
- import type DowncastWriter from '../view/downcastwriter';
24
- import type ElementDefinition from '../view/elementdefinition';
25
- import type UIElement from '../view/uielement';
26
- import type ViewElement from '../view/element';
27
- import { type EventInfo, type PriorityString } from '@ckeditor/ckeditor5-utils';
28
- /**
29
- * Downcast conversion helper functions.
30
- *
31
- * Learn more about {@glink framework/deep-dive/conversion/downcast downcast helpers}.
32
- *
33
- * @extends module:engine/conversion/conversionhelpers~ConversionHelpers
34
- */
35
- export default class DowncastHelpers extends ConversionHelpers<DowncastDispatcher> {
36
- /**
37
- * Model element to view element conversion helper.
38
- *
39
- * This conversion results in creating a view element. For example, model `<paragraph>Foo</paragraph>` becomes `<p>Foo</p>` in the view.
40
- *
41
- * ```ts
42
- * editor.conversion.for( 'downcast' ).elementToElement( {
43
- * model: 'paragraph',
44
- * view: 'p'
45
- * } );
46
- *
47
- * editor.conversion.for( 'downcast' ).elementToElement( {
48
- * model: 'paragraph',
49
- * view: 'div',
50
- * converterPriority: 'high'
51
- * } );
52
- *
53
- * editor.conversion.for( 'downcast' ).elementToElement( {
54
- * model: 'fancyParagraph',
55
- * view: {
56
- * name: 'p',
57
- * classes: 'fancy'
58
- * }
59
- * } );
60
- *
61
- * editor.conversion.for( 'downcast' ).elementToElement( {
62
- * model: 'heading',
63
- * view: ( modelElement, conversionApi ) => {
64
- * const { writer } = conversionApi;
65
- *
66
- * return writer.createContainerElement( 'h' + modelElement.getAttribute( 'level' ) );
67
- * }
68
- * } );
69
- * ```
70
- *
71
- * The element-to-element conversion supports the reconversion mechanism. It can be enabled by using either the `attributes` or
72
- * the `children` props on a model description. You will find a couple examples below.
73
- *
74
- * In order to reconvert an element if any of its direct children have been added or removed, use the `children` property on a `model`
75
- * description. For example, this model:
76
- *
77
- * ```xml
78
- * <box>
79
- * <paragraph>Some text.</paragraph>
80
- * </box>
81
- * ```
82
- *
83
- * will be converted into this structure in the view:
84
- *
85
- * ```html
86
- * <div class="box" data-type="single">
87
- * <p>Some text.</p>
88
- * </div>
89
- * ```
90
- *
91
- * But if more items were inserted in the model:
92
- *
93
- * ```xml
94
- * <box>
95
- * <paragraph>Some text.</paragraph>
96
- * <paragraph>Other item.</paragraph>
97
- * </box>
98
- * ```
99
- *
100
- * it will be converted into this structure in the view (note the element `data-type` change):
101
- *
102
- * ```html
103
- * <div class="box" data-type="multiple">
104
- * <p>Some text.</p>
105
- * <p>Other item.</p>
106
- * </div>
107
- * ```
108
- *
109
- * Such a converter would look like this (note that the `paragraph` elements are converted separately):
110
- *
111
- * ```ts
112
- * editor.conversion.for( 'downcast' ).elementToElement( {
113
- * model: {
114
- * name: 'box',
115
- * children: true
116
- * },
117
- * view: ( modelElement, conversionApi ) => {
118
- * const { writer } = conversionApi;
119
- *
120
- * return writer.createContainerElement( 'div', {
121
- * class: 'box',
122
- * 'data-type': modelElement.childCount == 1 ? 'single' : 'multiple'
123
- * } );
124
- * }
125
- * } );
126
- * ```
127
- *
128
- * In order to reconvert element if any of its attributes have been updated, use the `attributes` property on a `model`
129
- * description. For example, this model:
130
- *
131
- * ```xml
132
- * <heading level="2">Some text.</heading>
133
- * ```
134
- *
135
- * will be converted into this structure in the view:
136
- *
137
- * ```html
138
- * <h2>Some text.</h2>
139
- * ```
140
- *
141
- * But if the `heading` element's `level` attribute has been updated to `3` for example, then
142
- * it will be converted into this structure in the view:
143
- *
144
- * ```html
145
- * <h3>Some text.</h3>
146
- * ```
147
- *
148
- * Such a converter would look as follows:
149
- *
150
- * ```ts
151
- * editor.conversion.for( 'downcast' ).elementToElement( {
152
- * model: {
153
- * name: 'heading',
154
- * attributes: 'level'
155
- * },
156
- * view: ( modelElement, conversionApi ) => {
157
- * const { writer } = conversionApi;
158
- *
159
- * return writer.createContainerElement( 'h' + modelElement.getAttribute( 'level' ) );
160
- * }
161
- * } );
162
- * ```
163
- *
164
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
165
- * to the conversion process.
166
- *
167
- * You can read more about the element-to-element conversion in the
168
- * {@glink framework/deep-dive/conversion/downcast downcast conversion} guide.
169
- *
170
- * @param config Conversion configuration.
171
- * @param config.model The description or a name of the model element to convert.
172
- * @param config.model.attributes The list of attribute names that should be consumed while creating
173
- * the view element. Note that the view will be reconverted if any of the listed attributes changes.
174
- * @param config.model.children Specifies whether the view element requires reconversion if the list
175
- * of the model child nodes changed.
176
- * @param config.view A view element definition or a function that takes the model element and
177
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
178
- * as parameters and returns a view container element.
179
- */
180
- elementToElement(config: {
181
- model: string | {
182
- name: string;
183
- attributes?: string | Array<string>;
184
- children?: boolean;
185
- };
186
- view: ElementDefinition | ElementCreatorFunction;
187
- converterPriority?: PriorityString;
188
- }): this;
189
- /**
190
- * The model element to view structure (several elements) conversion helper.
191
- *
192
- * This conversion results in creating a view structure with one or more slots defined for the child nodes.
193
- * For example, a model `<table>` may become this structure in the view:
194
- *
195
- * ```html
196
- * <figure class="table">
197
- * <table>
198
- * <tbody>${ slot for table rows }</tbody>
199
- * </table>
200
- * </figure>
201
- * ```
202
- *
203
- * The children of the model's `<table>` element will be inserted into the `<tbody>` element.
204
- * If the `elementToElement()` helper was used, the children would be inserted into the `<figure>`.
205
- *
206
- * An example converter that converts the following model structure:
207
- *
208
- * ```xml
209
- * <wrappedParagraph>Some text.</wrappedParagraph>
210
- * ```
211
- *
212
- * into this structure in the view:
213
- *
214
- * ```html
215
- * <div class="wrapper">
216
- * <p>Some text.</p>
217
- * </div>
218
- * ```
219
- *
220
- * would look like this:
221
- *
222
- * ```ts
223
- * editor.conversion.for( 'downcast' ).elementToStructure( {
224
- * model: 'wrappedParagraph',
225
- * view: ( modelElement, conversionApi ) => {
226
- * const { writer } = conversionApi;
227
- *
228
- * const wrapperViewElement = writer.createContainerElement( 'div', { class: 'wrapper' } );
229
- * const paragraphViewElement = writer.createContainerElement( 'p' );
230
- *
231
- * writer.insert( writer.createPositionAt( wrapperViewElement, 0 ), paragraphViewElement );
232
- * writer.insert( writer.createPositionAt( paragraphViewElement, 0 ), writer.createSlot() );
233
- *
234
- * return wrapperViewElement;
235
- * }
236
- * } );
237
- * ```
238
- *
239
- * The `createSlot()` function can also take a callback that allows filtering which children of the model element
240
- * should be converted into this slot.
241
- *
242
- * Imagine a table feature where for this model structure:
243
- *
244
- * ```xml
245
- * <table headingRows="1">
246
- * <tableRow> ... table cells 1 ... </tableRow>
247
- * <tableRow> ... table cells 2 ... </tableRow>
248
- * <tableRow> ... table cells 3 ... </tableRow>
249
- * <caption>Caption text</caption>
250
- * </table>
251
- * ```
252
- *
253
- * we want to generate this view structure:
254
- *
255
- * ```html
256
- * <figure class="table">
257
- * <table>
258
- * <thead>
259
- * <tr> ... table cells 1 ... </tr>
260
- * </thead>
261
- * <tbody>
262
- * <tr> ... table cells 2 ... </tr>
263
- * <tr> ... table cells 3 ... </tr>
264
- * </tbody>
265
- * </table>
266
- * <figcaption>Caption text</figcaption>
267
- * </figure>
268
- * ```
269
- *
270
- * The converter has to take the `headingRows` attribute into consideration when allocating the `<tableRow>` elements
271
- * into the `<tbody>` and `<thead>` elements. Hence, we need two slots and need to define proper filter callbacks for them.
272
- *
273
- * Additionally, all elements other than `<tableRow>` should be placed outside the `<table>` tag.
274
- * In the example above, this will handle the table caption.
275
- *
276
- * Such a converter would look like this:
277
- *
278
- * ```ts
279
- * editor.conversion.for( 'downcast' ).elementToStructure( {
280
- * model: {
281
- * name: 'table',
282
- * attributes: [ 'headingRows' ]
283
- * },
284
- * view: ( modelElement, conversionApi ) => {
285
- * const { writer } = conversionApi;
286
- *
287
- * const figureElement = writer.createContainerElement( 'figure', { class: 'table' } );
288
- * const tableElement = writer.createContainerElement( 'table' );
289
- *
290
- * writer.insert( writer.createPositionAt( figureElement, 0 ), tableElement );
291
- *
292
- * const headingRows = modelElement.getAttribute( 'headingRows' ) || 0;
293
- *
294
- * if ( headingRows > 0 ) {
295
- * const tableHead = writer.createContainerElement( 'thead' );
296
- *
297
- * const headSlot = writer.createSlot( node => node.is( 'element', 'tableRow' ) && node.index < headingRows );
298
- *
299
- * writer.insert( writer.createPositionAt( tableElement, 'end' ), tableHead );
300
- * writer.insert( writer.createPositionAt( tableHead, 0 ), headSlot );
301
- * }
302
- *
303
- * if ( headingRows < tableUtils.getRows( table ) ) {
304
- * const tableBody = writer.createContainerElement( 'tbody' );
305
- *
306
- * const bodySlot = writer.createSlot( node => node.is( 'element', 'tableRow' ) && node.index >= headingRows );
307
- *
308
- * writer.insert( writer.createPositionAt( tableElement, 'end' ), tableBody );
309
- * writer.insert( writer.createPositionAt( tableBody, 0 ), bodySlot );
310
- * }
311
- *
312
- * const restSlot = writer.createSlot( node => !node.is( 'element', 'tableRow' ) );
313
- *
314
- * writer.insert( writer.createPositionAt( figureElement, 'end' ), restSlot );
315
- *
316
- * return figureElement;
317
- * }
318
- * } );
319
- * ```
320
- *
321
- * Note: The children of a model element that's being converted must be allocated in the same order in the view
322
- * in which they are placed in the model.
323
- *
324
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
325
- * to the conversion process.
326
- *
327
- * @param config Conversion configuration.
328
- * @param config.model The description or a name of the model element to convert.
329
- * @param config.model.name The name of the model element to convert.
330
- * @param config.model.attributes The list of attribute names that should be consumed while creating
331
- * the view structure. Note that the view will be reconverted if any of the listed attributes will change.
332
- * @param config.view A function that takes the model element and
333
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters
334
- * and returns a view container element with slots for model child nodes to be converted into.
335
- */
336
- elementToStructure(config: {
337
- model: string | {
338
- name: string;
339
- attributes?: string | Array<string>;
340
- };
341
- view: StructureCreatorFunction;
342
- converterPriority?: PriorityString;
343
- }): this;
344
- /**
345
- * Model attribute to view element conversion helper.
346
- *
347
- * This conversion results in wrapping view nodes with a view attribute element. For example, a model text node with
348
- * `"Foo"` as data and the `bold` attribute becomes `<strong>Foo</strong>` in the view.
349
- *
350
- * ```ts
351
- * editor.conversion.for( 'downcast' ).attributeToElement( {
352
- * model: 'bold',
353
- * view: 'strong'
354
- * } );
355
- *
356
- * editor.conversion.for( 'downcast' ).attributeToElement( {
357
- * model: 'bold',
358
- * view: 'b',
359
- * converterPriority: 'high'
360
- * } );
361
- *
362
- * editor.conversion.for( 'downcast' ).attributeToElement( {
363
- * model: 'invert',
364
- * view: {
365
- * name: 'span',
366
- * classes: [ 'font-light', 'bg-dark' ]
367
- * }
368
- * } );
369
- *
370
- * editor.conversion.for( 'downcast' ).attributeToElement( {
371
- * model: {
372
- * key: 'fontSize',
373
- * values: [ 'big', 'small' ]
374
- * },
375
- * view: {
376
- * big: {
377
- * name: 'span',
378
- * styles: {
379
- * 'font-size': '1.2em'
380
- * }
381
- * },
382
- * small: {
383
- * name: 'span',
384
- * styles: {
385
- * 'font-size': '0.8em'
386
- * }
387
- * }
388
- * }
389
- * } );
390
- *
391
- * editor.conversion.for( 'downcast' ).attributeToElement( {
392
- * model: 'bold',
393
- * view: ( modelAttributeValue, conversionApi ) => {
394
- * const { writer } = conversionApi;
395
- *
396
- * return writer.createAttributeElement( 'span', {
397
- * style: 'font-weight:' + modelAttributeValue
398
- * } );
399
- * }
400
- * } );
401
- *
402
- * editor.conversion.for( 'downcast' ).attributeToElement( {
403
- * model: {
404
- * key: 'color',
405
- * name: '$text'
406
- * },
407
- * view: ( modelAttributeValue, conversionApi ) => {
408
- * const { writer } = conversionApi;
409
- *
410
- * return writer.createAttributeElement( 'span', {
411
- * style: 'color:' + modelAttributeValue
412
- * } );
413
- * }
414
- * } );
415
- * ```
416
- *
417
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
418
- * to the conversion process.
419
- *
420
- * @param config Conversion configuration.
421
- * @param config.model The key of the attribute to convert from or a `{ key, values }` object. `values` is an array
422
- * of `String`s with possible values if the model attribute is an enumerable.
423
- * @param config.view A view element definition or a function
424
- * that takes the model attribute value and
425
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters and returns a view
426
- * attribute element. If `config.model.values` is given, `config.view` should be an object assigning values from `config.model.values`
427
- * to view element definitions or functions.
428
- * @param config.converterPriority Converter priority.
429
- */
430
- attributeToElement<TValues extends string>(config: {
431
- model: string | {
432
- key: string;
433
- name?: string;
434
- };
435
- view: ElementDefinition | AttributeElementCreatorFunction;
436
- converterPriority?: PriorityString;
437
- } | {
438
- model: {
439
- key: string;
440
- name?: string;
441
- values: Array<TValues>;
442
- };
443
- view: Record<TValues, ElementDefinition | AttributeElementCreatorFunction>;
444
- converterPriority?: PriorityString;
445
- }): this;
446
- /**
447
- * Model attribute to view attribute conversion helper.
448
- *
449
- * This conversion results in adding an attribute to a view node, basing on an attribute from a model node. For example,
450
- * `<imageInline src='foo.jpg'></imageInline>` is converted to `<img src='foo.jpg'></img>`.
451
- *
452
- * ```ts
453
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
454
- * model: 'source',
455
- * view: 'src'
456
- * } );
457
- *
458
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
459
- * model: 'source',
460
- * view: 'href',
461
- * converterPriority: 'high'
462
- * } );
463
- *
464
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
465
- * model: {
466
- * name: 'imageInline',
467
- * key: 'source'
468
- * },
469
- * view: 'src'
470
- * } );
471
- *
472
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
473
- * model: {
474
- * name: 'styled',
475
- * values: [ 'dark', 'light' ]
476
- * },
477
- * view: {
478
- * dark: {
479
- * key: 'class',
480
- * value: [ 'styled', 'styled-dark' ]
481
- * },
482
- * light: {
483
- * key: 'class',
484
- * value: [ 'styled', 'styled-light' ]
485
- * }
486
- * }
487
- * } );
488
- *
489
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
490
- * model: 'styled',
491
- * view: modelAttributeValue => ( {
492
- * key: 'class',
493
- * value: 'styled-' + modelAttributeValue
494
- * } )
495
- * } );
496
- * ```
497
- *
498
- * **Note**: Downcasting to a style property requires providing `value` as an object:
499
- *
500
- * ```ts
501
- * editor.conversion.for( 'downcast' ).attributeToAttribute( {
502
- * model: 'lineHeight',
503
- * view: modelAttributeValue => ( {
504
- * key: 'style',
505
- * value: {
506
- * 'line-height': modelAttributeValue,
507
- * 'border-bottom': '1px dotted #ba2'
508
- * }
509
- * } )
510
- * } );
511
- * ```
512
- *
513
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
514
- * to the conversion process.
515
- *
516
- * @param config Conversion configuration.
517
- * @param config.model The key of the attribute to convert from or a `{ key, values, [ name ] }` object describing
518
- * the attribute key, possible values and, optionally, an element name to convert from.
519
- * @param config.view A view attribute key, or a `{ key, value }` object or a function that takes the model attribute value and
520
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
521
- * as parameters and returns a `{ key, value }` object. If the `key` is `'class'`, the `value` can be a `String` or an
522
- * array of `String`s. If the `key` is `'style'`, the `value` is an object with key-value pairs. In other cases, `value` is a `String`.
523
- * If `config.model.values` is set, `config.view` should be an object assigning values from `config.model.values` to
524
- * `{ key, value }` objects or a functions.
525
- * @param config.converterPriority Converter priority.
526
- */
527
- attributeToAttribute<TValues extends string>(config: {
528
- model: string | {
529
- key: string;
530
- name?: string;
531
- };
532
- view: string | AttributeDescriptor | AttributeCreatorFunction;
533
- converterPriority?: PriorityString;
534
- } | {
535
- model: {
536
- key: string;
537
- name?: string;
538
- values?: Array<TValues>;
539
- };
540
- view: Record<TValues, AttributeDescriptor | AttributeCreatorFunction>;
541
- converterPriority?: PriorityString;
542
- }): this;
543
- /**
544
- * Model marker to view element conversion helper.
545
- *
546
- * **Note**: This method should be used mainly for editing the downcast and it is recommended
547
- * to use the {@link #markerToData `#markerToData()`} helper instead.
548
- *
549
- * This helper may produce invalid HTML code (e.g. a span between table cells).
550
- * It should only be used when you are sure that the produced HTML will be semantically correct.
551
- *
552
- * This conversion results in creating a view element on the boundaries of the converted marker. If the converted marker
553
- * is collapsed, only one element is created. For example, a model marker set like this: `<paragraph>F[oo b]ar</paragraph>`
554
- * becomes `<p>F<span data-marker="search"></span>oo b<span data-marker="search"></span>ar</p>` in the view.
555
- *
556
- * ```ts
557
- * editor.conversion.for( 'editingDowncast' ).markerToElement( {
558
- * model: 'search',
559
- * view: 'marker-search'
560
- * } );
561
- *
562
- * editor.conversion.for( 'editingDowncast' ).markerToElement( {
563
- * model: 'search',
564
- * view: 'search-result',
565
- * converterPriority: 'high'
566
- * } );
567
- *
568
- * editor.conversion.for( 'editingDowncast' ).markerToElement( {
569
- * model: 'search',
570
- * view: {
571
- * name: 'span',
572
- * attributes: {
573
- * 'data-marker': 'search'
574
- * }
575
- * }
576
- * } );
577
- *
578
- * editor.conversion.for( 'editingDowncast' ).markerToElement( {
579
- * model: 'search',
580
- * view: ( markerData, conversionApi ) => {
581
- * const { writer } = conversionApi;
582
- *
583
- * return writer.createUIElement( 'span', {
584
- * 'data-marker': 'search',
585
- * 'data-start': markerData.isOpening
586
- * } );
587
- * }
588
- * } );
589
- * ```
590
- *
591
- * If a function is passed as the `config.view` parameter, it will be used to generate both boundary elements. The function
592
- * receives the `data` object and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
593
- * as a parameters and should return an instance of the
594
- * {@link module:engine/view/uielement~UIElement view UI element}. The `data` object and
595
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi `conversionApi`} are passed from
596
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:addMarker}. Additionally,
597
- * the `data.isOpening` parameter is passed, which is set to `true` for the marker start boundary element, and `false` for
598
- * the marker end boundary element.
599
- *
600
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
601
- * to the conversion process.
602
- *
603
- * @param config Conversion configuration.
604
- * @param config.model The name of the model marker (or model marker group) to convert.
605
- * @param config.view A view element definition or a function that takes the model marker data and
606
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as a parameters
607
- * and returns a view UI element.
608
- * @param config.converterPriority Converter priority.
609
- */
610
- markerToElement(config: {
611
- model: string;
612
- view: ElementDefinition | MarkerElementCreatorFunction;
613
- converterPriority?: PriorityString;
614
- }): this;
615
- /**
616
- * Model marker to highlight conversion helper.
617
- *
618
- * This conversion results in creating a highlight on view nodes. For this kind of conversion,
619
- * the {@link module:engine/conversion/downcasthelpers~HighlightDescriptor} should be provided.
620
- *
621
- * For text nodes, a `<span>` {@link module:engine/view/attributeelement~AttributeElement} is created and it wraps all text nodes
622
- * in the converted marker range. For example, a model marker set like this: `<paragraph>F[oo b]ar</paragraph>` becomes
623
- * `<p>F<span class="comment">oo b</span>ar</p>` in the view.
624
- *
625
- * {@link module:engine/view/containerelement~ContainerElement} may provide a custom way of handling highlight. Most often,
626
- * the element itself is given classes and attributes described in the highlight descriptor (instead of being wrapped in `<span>`).
627
- * For example, a model marker set like this:
628
- * `[<imageInline src="foo.jpg"></imageInline>]` becomes `<img src="foo.jpg" class="comment"></img>` in the view.
629
- *
630
- * For container elements, the conversion is two-step. While the converter processes the highlight descriptor and passes it
631
- * to a container element, it is the container element instance itself that applies values from the highlight descriptor.
632
- * So, in a sense, the converter takes care of stating what should be applied on what, while the element decides how to apply that.
633
- *
634
- * ```ts
635
- * editor.conversion.for( 'downcast' ).markerToHighlight( { model: 'comment', view: { classes: 'comment' } } );
636
- *
637
- * editor.conversion.for( 'downcast' ).markerToHighlight( {
638
- * model: 'comment',
639
- * view: { classes: 'comment' },
640
- * converterPriority: 'high'
641
- * } );
642
- *
643
- * editor.conversion.for( 'downcast' ).markerToHighlight( {
644
- * model: 'comment',
645
- * view: ( data, conversionApi ) => {
646
- * // Assuming that the marker name is in a form of comment:commentType:commentId.
647
- * const [ , commentType, commentId ] = data.markerName.split( ':' );
648
- *
649
- * return {
650
- * classes: [ 'comment', 'comment-' + commentType ],
651
- * attributes: { 'data-comment-id': commentId }
652
- * };
653
- * }
654
- * } );
655
- * ```
656
- *
657
- * If a function is passed as the `config.view` parameter, it will be used to generate the highlight descriptor. The function
658
- * receives the `data` object and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
659
- * as the parameters and should return a
660
- * {@link module:engine/conversion/downcasthelpers~HighlightDescriptor highlight descriptor}.
661
- * The `data` object properties are passed from {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:addMarker}.
662
- *
663
- * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
664
- * to the conversion process.
665
- *
666
- * @param config Conversion configuration.
667
- * @param config.model The name of the model marker (or model marker group) to convert.
668
- * @param config.view A highlight descriptor that will be used for highlighting or a function that takes the model marker data and
669
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as a parameters
670
- * and returns a highlight descriptor.
671
- * @param config.converterPriority Converter priority.
672
- */
673
- markerToHighlight(config: {
674
- model: string;
675
- view: HighlightDescriptor | HighlightDescriptorCreatorFunction;
676
- converterPriority?: PriorityString;
677
- }): this;
678
- /**
679
- * Model marker converter for data downcast.
680
- *
681
- * This conversion creates a representation for model marker boundaries in the view:
682
- *
683
- * * If the marker boundary is before or after a model element, a view attribute is set on a corresponding view element.
684
- * * In other cases, a view element with the specified tag name is inserted at the corresponding view position.
685
- *
686
- * Typically, the marker names use the `group:uniqueId:otherData` convention. For example: `comment:e34zfk9k2n459df53sjl34:zx32c`.
687
- * The default configuration for this conversion is that the first part is the `group` part and the rest of
688
- * the marker name becomes the `name` part.
689
- *
690
- * Tag and attribute names and values are generated from the marker name:
691
- *
692
- * * The templates for attributes are `data-[group]-start-before="[name]"`, `data-[group]-start-after="[name]"`,
693
- * `data-[group]-end-before="[name]"` and `data-[group]-end-after="[name]"`.
694
- * * The templates for view elements are `<[group]-start name="[name]">` and `<[group]-end name="[name]">`.
695
- *
696
- * Attributes mark whether the given marker's start or end boundary is before or after the given element.
697
- * The `data-[group]-start-before` and `data-[group]-end-after` attributes are favored.
698
- * The other two are used when the former two cannot be used.
699
- *
700
- * The conversion configuration can take a function that will generate different group and name parts.
701
- * If such a function is set as the `config.view` parameter, it is passed a marker name and it is expected to return an object with two
702
- * properties: `group` and `name`. If the function returns a falsy value, the conversion will not take place.
703
- *
704
- * Basic usage:
705
- *
706
- * ```ts
707
- * // Using the default conversion.
708
- * // In this case, all markers with names starting with 'comment:' will be converted.
709
- * // The `group` parameter will be set to `comment`.
710
- * // The `name` parameter will be the rest of the marker name (without the `:`).
711
- * editor.conversion.for( 'dataDowncast' ).markerToData( {
712
- * model: 'comment'
713
- * } );
714
- * ```
715
- *
716
- * An example of a view that may be generated by this conversion (assuming a marker with the name `comment:commentId:uid` marked
717
- * by `[]`):
718
- *
719
- * ```
720
- * // Model:
721
- * <paragraph>Foo[bar</paragraph>
722
- * <imageBlock src="abc.jpg"></imageBlock>]
723
- *
724
- * // View:
725
- * <p>Foo<comment-start name="commentId:uid"></comment-start>bar</p>
726
- * <figure data-comment-end-after="commentId:uid" class="image"><img src="abc.jpg" /></figure>
727
- * ```
728
- *
729
- * In the example above, the comment starts before "bar" and ends after the image.
730
- *
731
- * If the `name` part is empty, the following view may be generated:
732
- *
733
- * ```html
734
- * <p>Foo <myMarker-start></myMarker-start>bar</p>
735
- * <figure data-myMarker-end-after="" class="image"><img src="abc.jpg" /></figure>
736
- * ```
737
- *
738
- * **Note:** A situation where some markers have the `name` part and some do not, is incorrect and should be avoided.
739
- *
740
- * Examples where `data-group-start-after` and `data-group-end-before` are used:
741
- *
742
- * ```
743
- * // Model:
744
- * <blockQuote>[]<paragraph>Foo</paragraph></blockQuote>
745
- *
746
- * // View:
747
- * <blockquote><p data-group-end-before="name" data-group-start-before="name">Foo</p></blockquote>
748
- * ```
749
- *
750
- * Similarly, when a marker is collapsed after the last element:
751
- *
752
- * ```
753
- * // Model:
754
- * <blockQuote><paragraph>Foo</paragraph>[]</blockQuote>
755
- *
756
- * // View:
757
- * <blockquote><p data-group-end-after="name" data-group-start-after="name">Foo</p></blockquote>
758
- * ```
759
- *
760
- * When there are multiple markers from the same group stored in the same attribute of the same element, their
761
- * name parts are put together in the attribute value, for example: `data-group-start-before="name1,name2,name3"`.
762
- *
763
- * Other examples of usage:
764
- *
765
- * ```ts
766
- * // Using a custom function which is the same as the default conversion:
767
- * editor.conversion.for( 'dataDowncast' ).markerToData( {
768
- * model: 'comment',
769
- * view: markerName => ( {
770
- * group: 'comment',
771
- * name: markerName.substr( 8 ) // Removes 'comment:' part.
772
- * } )
773
- * } );
774
- *
775
- * // Using the converter priority:
776
- * editor.conversion.for( 'dataDowncast' ).markerToData( {
777
- * model: 'comment',
778
- * view: markerName => ( {
779
- * group: 'comment',
780
- * name: markerName.substr( 8 ) // Removes 'comment:' part.
781
- * } ),
782
- * converterPriority: 'high'
783
- * } );
784
- * ```
785
- *
786
- * This kind of conversion is useful for saving data into the database, so it should be used in the data conversion pipeline.
787
- *
788
- * See the {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} API guide to learn how to
789
- * add a converter to the conversion process.
790
- *
791
- * @param config Conversion configuration.
792
- * @param config.model The name of the model marker (or the model marker group) to convert.
793
- * @param config.view A function that takes the model marker name and
794
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as the parameters
795
- * and returns an object with the `group` and `name` properties.
796
- * @param config.converterPriority Converter priority.
797
- */
798
- markerToData(config: {
799
- model: string;
800
- view?: MarkerDataCreatorFunction;
801
- converterPriority?: PriorityString;
802
- }): this;
803
- }
804
- /**
805
- * Function factory that creates a default downcast converter for text insertion changes.
806
- *
807
- * The converter automatically consumes the corresponding value from the consumables list and stops the event (see
808
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
809
- *
810
- * ```ts
811
- * modelDispatcher.on( 'insert:$text', insertText() );
812
- * ```
813
- *
814
- * @returns Insert text event converter.
815
- */
816
- export declare function insertText(): (evt: EventInfo, data: {
817
- item: ModelText | ModelTextProxy;
818
- range: ModelRange;
819
- }, conversionApi: DowncastConversionApi) => void;
820
- /**
821
- * Function factory that creates a default downcast converter for triggering attributes and children conversion.
822
- *
823
- * @returns The converter.
824
- */
825
- export declare function insertAttributesAndChildren(): (evt: unknown, data: {
826
- item: ModelItem;
827
- reconversion?: boolean;
828
- }, conversionApi: DowncastConversionApi) => void;
829
- /**
830
- * Function factory that creates a default downcast converter for node remove changes.
831
- *
832
- * ```ts
833
- * modelDispatcher.on( 'remove', remove() );
834
- * ```
835
- *
836
- * @returns Remove event converter.
837
- */
838
- export declare function remove(): (evt: unknown, data: {
839
- position: ModelPosition;
840
- length: number;
841
- }, conversionApi: DowncastConversionApi) => void;
842
- /**
843
- * Creates a `<span>` {@link module:engine/view/attributeelement~AttributeElement view attribute element} from the information
844
- * provided by the {@link module:engine/conversion/downcasthelpers~HighlightDescriptor highlight descriptor} object. If the priority
845
- * is not provided in the descriptor, the default priority will be used.
846
- */
847
- export declare function createViewElementFromHighlightDescriptor(writer: DowncastWriter, descriptor: HighlightDescriptor): ViewAttributeElement;
848
- /**
849
- * Function factory that creates a converter which converts a non-collapsed {@link module:engine/model/selection~Selection model selection}
850
- * to a {@link module:engine/view/documentselection~DocumentSelection view selection}. The converter consumes appropriate
851
- * value from the `consumable` object and maps model positions from the selection to view positions.
852
- *
853
- * ```ts
854
- * modelDispatcher.on( 'selection', convertRangeSelection() );
855
- * ```
856
- *
857
- * @returns Selection converter.
858
- */
859
- export declare function convertRangeSelection(): (evt: EventInfo, data: {
860
- selection: ModelSelection | ModelDocumentSelection;
861
- }, conversionApi: DowncastConversionApi) => void;
862
- /**
863
- * Function factory that creates a converter which converts a collapsed {@link module:engine/model/selection~Selection model selection} to
864
- * a {@link module:engine/view/documentselection~DocumentSelection view selection}. The converter consumes appropriate
865
- * value from the `consumable` object, maps the model selection position to the view position and breaks
866
- * {@link module:engine/view/attributeelement~AttributeElement attribute elements} at the selection position.
867
- *
868
- * ```ts
869
- * modelDispatcher.on( 'selection', convertCollapsedSelection() );
870
- * ```
871
- *
872
- * An example of the view state before and after converting the collapsed selection:
873
- *
874
- * ```
875
- * <p><strong>f^oo<strong>bar</p>
876
- * -> <p><strong>f</strong>^<strong>oo</strong>bar</p>
877
- * ```
878
- *
879
- * By breaking attribute elements like `<strong>`, the selection is in a correct element. Then, when the selection attribute is
880
- * converted, broken attributes might be merged again, or the position where the selection is may be wrapped
881
- * with different, appropriate attribute elements.
882
- *
883
- * See also {@link module:engine/conversion/downcasthelpers~cleanSelection} which does a clean-up
884
- * by merging attributes.
885
- *
886
- * @returns Selection converter.
887
- */
888
- export declare function convertCollapsedSelection(): (evt: EventInfo, data: {
889
- selection: ModelSelection | ModelDocumentSelection;
890
- }, conversionApi: DowncastConversionApi) => void;
891
- /**
892
- * Function factory that creates a converter which cleans artifacts after the previous
893
- * {@link module:engine/model/selection~Selection model selection} conversion. It removes all empty
894
- * {@link module:engine/view/attributeelement~AttributeElement view attribute elements} and merges sibling attributes at all start and end
895
- * positions of all ranges.
896
- *
897
- * ```
898
- * <p><strong>^</strong></p>
899
- * -> <p>^</p>
900
- *
901
- * <p><strong>foo</strong>^<strong>bar</strong>bar</p>
902
- * -> <p><strong>foo^bar<strong>bar</p>
903
- *
904
- * <p><strong>foo</strong><em>^</em><strong>bar</strong>bar</p>
905
- * -> <p><strong>foo^bar<strong>bar</p>
906
- * ```
907
- *
908
- * This listener should be assigned before any converter for the new selection:
909
- *
910
- * ```ts
911
- * modelDispatcher.on( 'cleanSelection', cleanSelection() );
912
- * ```
913
- *
914
- * See {@link module:engine/conversion/downcasthelpers~convertCollapsedSelection}
915
- * which does the opposite by breaking attributes in the selection position.
916
- *
917
- * @returns Selection converter.
918
- */
919
- export declare function cleanSelection(): (evt: EventInfo, data: unknown, conversionApi: DowncastConversionApi) => void;
920
- /**
921
- * Function factory that creates a converter which converts the set/change/remove attribute changes from the model to the view.
922
- * It can also be used to convert selection attributes. In that case, an empty attribute element will be created and the
923
- * selection will be put inside it.
924
- *
925
- * Attributes from the model are converted to a view element that will be wrapping these view nodes that are bound to
926
- * model elements having the given attribute. This is useful for attributes like `bold` that may be set on text nodes in the model
927
- * but are represented as an element in the view:
928
- *
929
- * ```
930
- * [paragraph] MODEL ====> VIEW <p>
931
- * |- a {bold: true} |- <b>
932
- * |- b {bold: true} | |- ab
933
- * |- c |- c
934
- * ```
935
- *
936
- * Passed `Function` will be provided with the attribute value and then all the parameters of the
937
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute` event}.
938
- * It is expected that the function returns an {@link module:engine/view/element~Element}.
939
- * The result of the function will be the wrapping element.
940
- * When the provided `Function` does not return any element, no conversion will take place.
941
- *
942
- * The converter automatically consumes the corresponding value from the consumables list and stops the event (see
943
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
944
- *
945
- * ```ts
946
- * modelDispatcher.on( 'attribute:bold', wrap( ( modelAttributeValue, { writer } ) => {
947
- * return writer.createAttributeElement( 'strong' );
948
- * } );
949
- * ```
950
- *
951
- * @internal
952
- * @param elementCreator Function returning a view element that will be used for wrapping.
953
- * @returns Set/change attribute converter.
954
- */
955
- export declare function wrap(elementCreator: AttributeElementCreatorFunction): (evt: EventInfo, data: {
956
- item: ModelItem | ModelSelection | ModelDocumentSelection;
957
- range: ModelRange;
958
- attributeKey: string;
959
- attributeOldValue: unknown;
960
- attributeNewValue: unknown;
961
- }, conversionApi: DowncastConversionApi) => void;
962
- /**
963
- * Function factory that creates a converter which converts node insertion changes from the model to the view.
964
- * The function passed will be provided with all the parameters of the dispatcher's
965
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert` event}.
966
- * It is expected that the function returns an {@link module:engine/view/element~Element}.
967
- * The result of the function will be inserted into the view.
968
- *
969
- * The converter automatically consumes the corresponding value from the consumables list and binds the model and view elements.
970
- *
971
- * ```ts
972
- * downcastDispatcher.on(
973
- * 'insert:myElem',
974
- * insertElement( ( modelItem, { writer } ) => {
975
- * const text = writer.createText( 'myText' );
976
- * const myElem = writer.createElement( 'myElem', { myAttr: 'my-' + modelItem.getAttribute( 'myAttr' ) }, text );
977
- *
978
- * // Do something fancy with `myElem` using `modelItem` or other parameters.
979
- *
980
- * return myElem;
981
- * }
982
- * ) );
983
- * ```
984
- *
985
- * @internal
986
- * @param elementCreator Function returning a view element, which will be inserted.
987
- * @param consumer Function defining element consumption process.
988
- * By default this function just consume passed item insertion.
989
- * @returns Insert element event converter.
990
- */
991
- export declare function insertElement(elementCreator: ElementCreatorFunction, consumer?: ConsumerFunction): (evt: unknown, data: {
992
- item: ModelElement;
993
- range: ModelRange;
994
- reconversion?: boolean;
995
- }, conversionApi: DowncastConversionApi) => void;
996
- /**
997
- * Function factory that creates a converter which converts a single model node insertion to a view structure.
998
- *
999
- * It is expected that the passed element creator function returns an {@link module:engine/view/element~Element} with attached slots
1000
- * created with `writer.createSlot()` to indicate where child nodes should be converted.
1001
- *
1002
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1003
- *
1004
- * @internal
1005
- * @param elementCreator Function returning a view structure, which will be inserted.
1006
- * @param consumer A callback that is expected to consume all the consumables
1007
- * that were used by the element creator.
1008
- * @returns Insert element event converter.
1009
- */
1010
- export declare function insertStructure(elementCreator: StructureCreatorFunction, consumer: ConsumerFunction): (evt: unknown, data: {
1011
- item: ModelElement;
1012
- range: ModelRange;
1013
- reconversion?: boolean;
1014
- }, conversionApi: DowncastConversionApi) => void;
1015
- /**
1016
- * Function factory that creates a converter which converts marker adding change to the
1017
- * {@link module:engine/view/uielement~UIElement view UI element}.
1018
- *
1019
- * The view UI element that will be added to the view depends on the passed parameter. See {@link ~insertElement}.
1020
- * In case of a non-collapsed range, the UI element will not wrap nodes but separate elements will be placed at the beginning
1021
- * and at the end of the range.
1022
- *
1023
- * This converter binds created UI elements with the marker name using {@link module:engine/conversion/mapper~Mapper#bindElementToMarker}.
1024
- *
1025
- * @internal
1026
- * @param elementCreator A view UI element or a function returning the view element that will be inserted.
1027
- * @returns Insert element event converter.
1028
- */
1029
- export declare function insertUIElement(elementCreator: MarkerElementCreatorFunction): (evt: EventInfo, data: {
1030
- markerRange: ModelRange;
1031
- markerName: string;
1032
- isOpening?: boolean;
1033
- }, conversionApi: DowncastConversionApi) => void;
1034
- /**
1035
- * An object describing how the marker highlight should be represented in the view.
1036
- *
1037
- * Each text node contained in a highlighted range will be wrapped in a `<span>`
1038
- * {@link module:engine/view/attributeelement~AttributeElement view attribute element} with CSS class(es), attributes and a priority
1039
- * described by this object.
1040
- *
1041
- * Additionally, each {@link module:engine/view/containerelement~ContainerElement container element} can handle displaying the highlight
1042
- * separately by providing the `addHighlight` and `removeHighlight` custom properties. In this case:
1043
- *
1044
- * * The `HighlightDescriptor` object is passed to the `addHighlight` function upon conversion and should be used to apply the highlight to
1045
- * the element.
1046
- * * The descriptor `id` is passed to the `removeHighlight` function upon conversion and should be used to remove the highlight with the
1047
- * given ID from the element.
1048
- */
1049
- export interface HighlightDescriptor {
1050
- /**
1051
- * A CSS class or an array of classes to set. If the descriptor is used to
1052
- * create an {@link module:engine/view/attributeelement~AttributeElement attribute element} over text nodes, these classes will be set
1053
- * on that attribute element. If the descriptor is applied to an element, usually these classes will be set on that element, however,
1054
- * this depends on how the element converts the descriptor.
1055
- */
1056
- classes: string | Array<string>;
1057
- /**
1058
- * Descriptor identifier. If not provided, it defaults to the converted marker's name.
1059
- */
1060
- id?: string;
1061
- /**
1062
- * Descriptor priority. If not provided, it defaults to `10`. If the descriptor is used to create
1063
- * an {@link module:engine/view/attributeelement~AttributeElement attribute element}, it will be that element's
1064
- * {@link module:engine/view/attributeelement~AttributeElement#priority priority}. If the descriptor is applied to an element,
1065
- * the priority will be used to determine which descriptor is more important.
1066
- */
1067
- priority?: number;
1068
- /**
1069
- * Attributes to set. If the descriptor is used to create
1070
- * an {@link module:engine/view/attributeelement~AttributeElement attribute element} over text nodes, these attributes will be set
1071
- * on that attribute element. If the descriptor is applied to an element, usually these attributes will be set on that element, however,
1072
- * this depends on how the element converts the descriptor.
1073
- */
1074
- attributes?: Record<string, string>;
1075
- }
1076
- /**
1077
- * A filtering function used to choose model child nodes to be downcasted into the specific view
1078
- * {@link module:engine/view/downcastwriter~DowncastWriter#createSlot "slot"} while executing the
1079
- * {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`} converter.
1080
- *
1081
- * @callback module:engine/conversion/downcasthelpers~SlotFilter
1082
- *
1083
- * @param node A model node.
1084
- * @returns Whether the provided model node should be downcasted into this slot.
1085
- *
1086
- * @see module:engine/view/downcastwriter~DowncastWriter#createSlot
1087
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1088
- * @see module:engine/conversion/downcasthelpers~insertStructure
1089
- */
1090
- export type SlotFilter = (node: ModelNode) => boolean;
1091
- /**
1092
- * A view element creator function that takes the model element and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi
1093
- * downcast conversion API} as parameters and returns a view container element.
1094
- *
1095
- * @callback module:engine/conversion/downcasthelpers~ElementCreatorFunction
1096
- *
1097
- * @param element The model element to be converted to the view structure.
1098
- * @param conversionApi The conversion interface.
1099
- * @param data Additional information about the change (same as for
1100
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert`} event).
1101
- * @param data.item Inserted item.
1102
- * @param data.range Range spanning over inserted item.
1103
- * @returns The view element.
1104
- *
1105
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement
1106
- * @see module:engine/conversion/downcasthelpers~insertElement
1107
- */
1108
- export type ElementCreatorFunction = (element: ModelElement, conversionApi: DowncastConversionApi, data: {
1109
- item: ModelItem;
1110
- range: ModelRange;
1111
- }) => ViewElement | null;
1112
- /**
1113
- * A function that takes the model element and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast
1114
- * conversion API} as parameters and returns a view container element with slots for model child nodes to be converted into.
1115
- *
1116
- * @callback module:engine/conversion/downcasthelpers~StructureCreatorFunction
1117
- *
1118
- * @param element The model element to be converted to the view structure.
1119
- * @param conversionApi The conversion interface.
1120
- * @param data Additional information about the change (same as for
1121
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert`} event).
1122
- * @param data.item Inserted item.
1123
- * @param data.range Range spanning over inserted item.
1124
- * @returns The view structure with slots for model child nodes.
1125
- *
1126
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1127
- * @see module:engine/conversion/downcasthelpers~insertStructure
1128
- */
1129
- export type StructureCreatorFunction = ElementCreatorFunction;
1130
- /**
1131
- * A view element creator function that takes the model attribute value and
1132
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters and returns a view
1133
- * attribute element.
1134
- *
1135
- * @callback module:engine/conversion/downcasthelpers~AttributeElementCreatorFunction
1136
- *
1137
- * @param attributeValue The model attribute value to be converted to the view attribute element.
1138
- * @param conversionApi The conversion interface.
1139
- * @param data Additional information about the change (same as for
1140
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute`} event).
1141
- * @param data.item Changed item or converted selection.
1142
- * @param data.range Range spanning over changed item or selection range.
1143
- * @param data.attributeKey Attribute key.
1144
- * @param data.attributeOldValue Attribute value before the change. This is `null` when selection attribute is converted.
1145
- * @param data.attributeNewValue New attribute value.
1146
- * @returns The view attribute element.
1147
- *
1148
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement
1149
- * @see module:engine/conversion/downcasthelpers~wrap
1150
- */
1151
- export type AttributeElementCreatorFunction = (attributeValue: any, conversionApi: DowncastConversionApi, data: {
1152
- item: ModelItem | ModelSelection | ModelDocumentSelection;
1153
- range: ModelRange;
1154
- attributeKey: string;
1155
- attributeOldValue: unknown;
1156
- attributeNewValue: unknown;
1157
- }) => ViewAttributeElement | null;
1158
- /**
1159
- * A function that takes the model attribute value and
1160
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
1161
- * as parameters.
1162
- *
1163
- * @callback module:engine/conversion/downcasthelpers~AttributeCreatorFunction
1164
- *
1165
- * @param attributeValue The model attribute value to be converted to the view attribute element.
1166
- * @param conversionApi The conversion interface.
1167
- * @param data Additional information about the change (same as for
1168
- * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute`} event).
1169
- * @param data.item Changed item or converted selection.
1170
- * @param data.range Range spanning over changed item or selection range.
1171
- * @param data.attributeKey Attribute key.
1172
- * @param data.attributeOldValue Attribute value before the change. This is `null` when selection attribute is converted.
1173
- * @param data.attributeNewValue New attribute value.
1174
- * @returns A `{ key, value }` object. If `key` is `'class'`, `value` can be a `String` or an
1175
- * array of `String`s. If `key` is `'style'`, `value` is an object with key-value pairs. In other cases, `value` is a `String`.
1176
- *
1177
- * @see module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToAttribute
1178
- */
1179
- export type AttributeCreatorFunction = (attributeValue: unknown, conversionApi: DowncastConversionApi, data: {
1180
- item: ModelItem;
1181
- range: ModelRange;
1182
- attributeKey: string;
1183
- attributeOldValue: unknown;
1184
- attributeNewValue: unknown;
1185
- }) => AttributeDescriptor | null;
1186
- export type AttributeDescriptor = {
1187
- key: 'class';
1188
- value: string | Array<string>;
1189
- } | {
1190
- key: 'style';
1191
- value: Record<string, string>;
1192
- } | {
1193
- key: Exclude<string, 'class' | 'style'>;
1194
- value: string;
1195
- };
1196
- export type MarkerElementCreatorFunction = (data: {
1197
- markerRange: ModelRange;
1198
- markerName: string;
1199
- isOpening?: boolean;
1200
- }, conversionApi: DowncastConversionApi) => UIElement | null;
1201
- export type HighlightDescriptorCreatorFunction = (data: {
1202
- markerRange: ModelRange;
1203
- markerName: string;
1204
- }, conversionApi: DowncastConversionApi) => HighlightDescriptor | null;
1205
- export type AddHighlightCallback = (viewElement: ViewElement, descriptor: HighlightDescriptor, writer: DowncastWriter) => void;
1206
- export type RemoveHighlightCallback = (viewElement: ViewElement, id: string, writer: DowncastWriter) => void;
1207
- export type MarkerDataCreatorFunction = (markerName: string, conversionApi: DowncastConversionApi) => {
1208
- name: string;
1209
- group: string;
1210
- } | null;
1211
- /**
1212
- * A function that is expected to consume all the consumables that were used by the element creator.
1213
- *
1214
- * @callback module:engine/conversion/downcasthelpers~ConsumerFunction
1215
- *
1216
- * @param element The model element to be converted to the view structure.
1217
- * @param consumable The `ModelConsumable` same as in
1218
- * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi#consumable `DowncastConversionApi.consumable`}.
1219
- * @param options.preflight Whether should consume or just check if can be consumed.
1220
- * @returns `true` if all consumable values were available and were consumed, `false` otherwise.
1221
- *
1222
- * @see module:engine/conversion/downcasthelpers~insertStructure
1223
- */
1224
- export type ConsumerFunction = (element: ModelElement, consumable: ModelConsumable, options?: {
1225
- preflight?: boolean;
1226
- }) => boolean | null;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * Contains downcast (model-to-view) converters for {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}.
7
+ *
8
+ * @module engine/conversion/downcasthelpers
9
+ */
10
+ import ModelRange from '../model/range';
11
+ import ModelSelection from '../model/selection';
12
+ import ModelDocumentSelection from '../model/documentselection';
13
+ import ModelElement from '../model/element';
14
+ import ModelPosition from '../model/position';
15
+ import ViewAttributeElement from '../view/attributeelement';
16
+ import ConversionHelpers from './conversionhelpers';
17
+ import type { default as DowncastDispatcher, DowncastConversionApi } from './downcastdispatcher';
18
+ import type ModelConsumable from './modelconsumable';
19
+ import type ModelNode from '../model/node';
20
+ import type ModelItem from '../model/item';
21
+ import type ModelTextProxy from '../model/textproxy';
22
+ import type ModelText from '../model/text';
23
+ import type DowncastWriter from '../view/downcastwriter';
24
+ import type ElementDefinition from '../view/elementdefinition';
25
+ import type UIElement from '../view/uielement';
26
+ import type ViewElement from '../view/element';
27
+ import { type EventInfo, type PriorityString } from '@ckeditor/ckeditor5-utils';
28
+ /**
29
+ * Downcast conversion helper functions.
30
+ *
31
+ * Learn more about {@glink framework/deep-dive/conversion/downcast downcast helpers}.
32
+ *
33
+ * @extends module:engine/conversion/conversionhelpers~ConversionHelpers
34
+ */
35
+ export default class DowncastHelpers extends ConversionHelpers<DowncastDispatcher> {
36
+ /**
37
+ * Model element to view element conversion helper.
38
+ *
39
+ * This conversion results in creating a view element. For example, model `<paragraph>Foo</paragraph>` becomes `<p>Foo</p>` in the view.
40
+ *
41
+ * ```ts
42
+ * editor.conversion.for( 'downcast' ).elementToElement( {
43
+ * model: 'paragraph',
44
+ * view: 'p'
45
+ * } );
46
+ *
47
+ * editor.conversion.for( 'downcast' ).elementToElement( {
48
+ * model: 'paragraph',
49
+ * view: 'div',
50
+ * converterPriority: 'high'
51
+ * } );
52
+ *
53
+ * editor.conversion.for( 'downcast' ).elementToElement( {
54
+ * model: 'fancyParagraph',
55
+ * view: {
56
+ * name: 'p',
57
+ * classes: 'fancy'
58
+ * }
59
+ * } );
60
+ *
61
+ * editor.conversion.for( 'downcast' ).elementToElement( {
62
+ * model: 'heading',
63
+ * view: ( modelElement, conversionApi ) => {
64
+ * const { writer } = conversionApi;
65
+ *
66
+ * return writer.createContainerElement( 'h' + modelElement.getAttribute( 'level' ) );
67
+ * }
68
+ * } );
69
+ * ```
70
+ *
71
+ * The element-to-element conversion supports the reconversion mechanism. It can be enabled by using either the `attributes` or
72
+ * the `children` props on a model description. You will find a couple examples below.
73
+ *
74
+ * In order to reconvert an element if any of its direct children have been added or removed, use the `children` property on a `model`
75
+ * description. For example, this model:
76
+ *
77
+ * ```xml
78
+ * <box>
79
+ * <paragraph>Some text.</paragraph>
80
+ * </box>
81
+ * ```
82
+ *
83
+ * will be converted into this structure in the view:
84
+ *
85
+ * ```html
86
+ * <div class="box" data-type="single">
87
+ * <p>Some text.</p>
88
+ * </div>
89
+ * ```
90
+ *
91
+ * But if more items were inserted in the model:
92
+ *
93
+ * ```xml
94
+ * <box>
95
+ * <paragraph>Some text.</paragraph>
96
+ * <paragraph>Other item.</paragraph>
97
+ * </box>
98
+ * ```
99
+ *
100
+ * it will be converted into this structure in the view (note the element `data-type` change):
101
+ *
102
+ * ```html
103
+ * <div class="box" data-type="multiple">
104
+ * <p>Some text.</p>
105
+ * <p>Other item.</p>
106
+ * </div>
107
+ * ```
108
+ *
109
+ * Such a converter would look like this (note that the `paragraph` elements are converted separately):
110
+ *
111
+ * ```ts
112
+ * editor.conversion.for( 'downcast' ).elementToElement( {
113
+ * model: {
114
+ * name: 'box',
115
+ * children: true
116
+ * },
117
+ * view: ( modelElement, conversionApi ) => {
118
+ * const { writer } = conversionApi;
119
+ *
120
+ * return writer.createContainerElement( 'div', {
121
+ * class: 'box',
122
+ * 'data-type': modelElement.childCount == 1 ? 'single' : 'multiple'
123
+ * } );
124
+ * }
125
+ * } );
126
+ * ```
127
+ *
128
+ * In order to reconvert element if any of its attributes have been updated, use the `attributes` property on a `model`
129
+ * description. For example, this model:
130
+ *
131
+ * ```xml
132
+ * <heading level="2">Some text.</heading>
133
+ * ```
134
+ *
135
+ * will be converted into this structure in the view:
136
+ *
137
+ * ```html
138
+ * <h2>Some text.</h2>
139
+ * ```
140
+ *
141
+ * But if the `heading` element's `level` attribute has been updated to `3` for example, then
142
+ * it will be converted into this structure in the view:
143
+ *
144
+ * ```html
145
+ * <h3>Some text.</h3>
146
+ * ```
147
+ *
148
+ * Such a converter would look as follows:
149
+ *
150
+ * ```ts
151
+ * editor.conversion.for( 'downcast' ).elementToElement( {
152
+ * model: {
153
+ * name: 'heading',
154
+ * attributes: 'level'
155
+ * },
156
+ * view: ( modelElement, conversionApi ) => {
157
+ * const { writer } = conversionApi;
158
+ *
159
+ * return writer.createContainerElement( 'h' + modelElement.getAttribute( 'level' ) );
160
+ * }
161
+ * } );
162
+ * ```
163
+ *
164
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
165
+ * to the conversion process.
166
+ *
167
+ * You can read more about the element-to-element conversion in the
168
+ * {@glink framework/deep-dive/conversion/downcast downcast conversion} guide.
169
+ *
170
+ * @param config Conversion configuration.
171
+ * @param config.model The description or a name of the model element to convert.
172
+ * @param config.model.attributes The list of attribute names that should be consumed while creating
173
+ * the view element. Note that the view will be reconverted if any of the listed attributes changes.
174
+ * @param config.model.children Specifies whether the view element requires reconversion if the list
175
+ * of the model child nodes changed.
176
+ * @param config.view A view element definition or a function that takes the model element and
177
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
178
+ * as parameters and returns a view container element.
179
+ */
180
+ elementToElement(config: {
181
+ model: string | {
182
+ name: string;
183
+ attributes?: string | Array<string>;
184
+ children?: boolean;
185
+ };
186
+ view: ElementDefinition | ElementCreatorFunction;
187
+ converterPriority?: PriorityString;
188
+ }): this;
189
+ /**
190
+ * The model element to view structure (several elements) conversion helper.
191
+ *
192
+ * This conversion results in creating a view structure with one or more slots defined for the child nodes.
193
+ * For example, a model `<table>` may become this structure in the view:
194
+ *
195
+ * ```html
196
+ * <figure class="table">
197
+ * <table>
198
+ * <tbody>${ slot for table rows }</tbody>
199
+ * </table>
200
+ * </figure>
201
+ * ```
202
+ *
203
+ * The children of the model's `<table>` element will be inserted into the `<tbody>` element.
204
+ * If the `elementToElement()` helper was used, the children would be inserted into the `<figure>`.
205
+ *
206
+ * An example converter that converts the following model structure:
207
+ *
208
+ * ```xml
209
+ * <wrappedParagraph>Some text.</wrappedParagraph>
210
+ * ```
211
+ *
212
+ * into this structure in the view:
213
+ *
214
+ * ```html
215
+ * <div class="wrapper">
216
+ * <p>Some text.</p>
217
+ * </div>
218
+ * ```
219
+ *
220
+ * would look like this:
221
+ *
222
+ * ```ts
223
+ * editor.conversion.for( 'downcast' ).elementToStructure( {
224
+ * model: 'wrappedParagraph',
225
+ * view: ( modelElement, conversionApi ) => {
226
+ * const { writer } = conversionApi;
227
+ *
228
+ * const wrapperViewElement = writer.createContainerElement( 'div', { class: 'wrapper' } );
229
+ * const paragraphViewElement = writer.createContainerElement( 'p' );
230
+ *
231
+ * writer.insert( writer.createPositionAt( wrapperViewElement, 0 ), paragraphViewElement );
232
+ * writer.insert( writer.createPositionAt( paragraphViewElement, 0 ), writer.createSlot() );
233
+ *
234
+ * return wrapperViewElement;
235
+ * }
236
+ * } );
237
+ * ```
238
+ *
239
+ * The `createSlot()` function can also take a callback that allows filtering which children of the model element
240
+ * should be converted into this slot.
241
+ *
242
+ * Imagine a table feature where for this model structure:
243
+ *
244
+ * ```xml
245
+ * <table headingRows="1">
246
+ * <tableRow> ... table cells 1 ... </tableRow>
247
+ * <tableRow> ... table cells 2 ... </tableRow>
248
+ * <tableRow> ... table cells 3 ... </tableRow>
249
+ * <caption>Caption text</caption>
250
+ * </table>
251
+ * ```
252
+ *
253
+ * we want to generate this view structure:
254
+ *
255
+ * ```html
256
+ * <figure class="table">
257
+ * <table>
258
+ * <thead>
259
+ * <tr> ... table cells 1 ... </tr>
260
+ * </thead>
261
+ * <tbody>
262
+ * <tr> ... table cells 2 ... </tr>
263
+ * <tr> ... table cells 3 ... </tr>
264
+ * </tbody>
265
+ * </table>
266
+ * <figcaption>Caption text</figcaption>
267
+ * </figure>
268
+ * ```
269
+ *
270
+ * The converter has to take the `headingRows` attribute into consideration when allocating the `<tableRow>` elements
271
+ * into the `<tbody>` and `<thead>` elements. Hence, we need two slots and need to define proper filter callbacks for them.
272
+ *
273
+ * Additionally, all elements other than `<tableRow>` should be placed outside the `<table>` tag.
274
+ * In the example above, this will handle the table caption.
275
+ *
276
+ * Such a converter would look like this:
277
+ *
278
+ * ```ts
279
+ * editor.conversion.for( 'downcast' ).elementToStructure( {
280
+ * model: {
281
+ * name: 'table',
282
+ * attributes: [ 'headingRows' ]
283
+ * },
284
+ * view: ( modelElement, conversionApi ) => {
285
+ * const { writer } = conversionApi;
286
+ *
287
+ * const figureElement = writer.createContainerElement( 'figure', { class: 'table' } );
288
+ * const tableElement = writer.createContainerElement( 'table' );
289
+ *
290
+ * writer.insert( writer.createPositionAt( figureElement, 0 ), tableElement );
291
+ *
292
+ * const headingRows = modelElement.getAttribute( 'headingRows' ) || 0;
293
+ *
294
+ * if ( headingRows > 0 ) {
295
+ * const tableHead = writer.createContainerElement( 'thead' );
296
+ *
297
+ * const headSlot = writer.createSlot( node => node.is( 'element', 'tableRow' ) && node.index < headingRows );
298
+ *
299
+ * writer.insert( writer.createPositionAt( tableElement, 'end' ), tableHead );
300
+ * writer.insert( writer.createPositionAt( tableHead, 0 ), headSlot );
301
+ * }
302
+ *
303
+ * if ( headingRows < tableUtils.getRows( table ) ) {
304
+ * const tableBody = writer.createContainerElement( 'tbody' );
305
+ *
306
+ * const bodySlot = writer.createSlot( node => node.is( 'element', 'tableRow' ) && node.index >= headingRows );
307
+ *
308
+ * writer.insert( writer.createPositionAt( tableElement, 'end' ), tableBody );
309
+ * writer.insert( writer.createPositionAt( tableBody, 0 ), bodySlot );
310
+ * }
311
+ *
312
+ * const restSlot = writer.createSlot( node => !node.is( 'element', 'tableRow' ) );
313
+ *
314
+ * writer.insert( writer.createPositionAt( figureElement, 'end' ), restSlot );
315
+ *
316
+ * return figureElement;
317
+ * }
318
+ * } );
319
+ * ```
320
+ *
321
+ * Note: The children of a model element that's being converted must be allocated in the same order in the view
322
+ * in which they are placed in the model.
323
+ *
324
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
325
+ * to the conversion process.
326
+ *
327
+ * @param config Conversion configuration.
328
+ * @param config.model The description or a name of the model element to convert.
329
+ * @param config.model.name The name of the model element to convert.
330
+ * @param config.model.attributes The list of attribute names that should be consumed while creating
331
+ * the view structure. Note that the view will be reconverted if any of the listed attributes will change.
332
+ * @param config.view A function that takes the model element and
333
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters
334
+ * and returns a view container element with slots for model child nodes to be converted into.
335
+ */
336
+ elementToStructure(config: {
337
+ model: string | {
338
+ name: string;
339
+ attributes?: string | Array<string>;
340
+ };
341
+ view: StructureCreatorFunction;
342
+ converterPriority?: PriorityString;
343
+ }): this;
344
+ /**
345
+ * Model attribute to view element conversion helper.
346
+ *
347
+ * This conversion results in wrapping view nodes with a view attribute element. For example, a model text node with
348
+ * `"Foo"` as data and the `bold` attribute becomes `<strong>Foo</strong>` in the view.
349
+ *
350
+ * ```ts
351
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
352
+ * model: 'bold',
353
+ * view: 'strong'
354
+ * } );
355
+ *
356
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
357
+ * model: 'bold',
358
+ * view: 'b',
359
+ * converterPriority: 'high'
360
+ * } );
361
+ *
362
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
363
+ * model: 'invert',
364
+ * view: {
365
+ * name: 'span',
366
+ * classes: [ 'font-light', 'bg-dark' ]
367
+ * }
368
+ * } );
369
+ *
370
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
371
+ * model: {
372
+ * key: 'fontSize',
373
+ * values: [ 'big', 'small' ]
374
+ * },
375
+ * view: {
376
+ * big: {
377
+ * name: 'span',
378
+ * styles: {
379
+ * 'font-size': '1.2em'
380
+ * }
381
+ * },
382
+ * small: {
383
+ * name: 'span',
384
+ * styles: {
385
+ * 'font-size': '0.8em'
386
+ * }
387
+ * }
388
+ * }
389
+ * } );
390
+ *
391
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
392
+ * model: 'bold',
393
+ * view: ( modelAttributeValue, conversionApi ) => {
394
+ * const { writer } = conversionApi;
395
+ *
396
+ * return writer.createAttributeElement( 'span', {
397
+ * style: 'font-weight:' + modelAttributeValue
398
+ * } );
399
+ * }
400
+ * } );
401
+ *
402
+ * editor.conversion.for( 'downcast' ).attributeToElement( {
403
+ * model: {
404
+ * key: 'color',
405
+ * name: '$text'
406
+ * },
407
+ * view: ( modelAttributeValue, conversionApi ) => {
408
+ * const { writer } = conversionApi;
409
+ *
410
+ * return writer.createAttributeElement( 'span', {
411
+ * style: 'color:' + modelAttributeValue
412
+ * } );
413
+ * }
414
+ * } );
415
+ * ```
416
+ *
417
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
418
+ * to the conversion process.
419
+ *
420
+ * @param config Conversion configuration.
421
+ * @param config.model The key of the attribute to convert from or a `{ key, values }` object. `values` is an array
422
+ * of `String`s with possible values if the model attribute is an enumerable.
423
+ * @param config.view A view element definition or a function
424
+ * that takes the model attribute value and
425
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters and returns a view
426
+ * attribute element. If `config.model.values` is given, `config.view` should be an object assigning values from `config.model.values`
427
+ * to view element definitions or functions.
428
+ * @param config.converterPriority Converter priority.
429
+ */
430
+ attributeToElement<TValues extends string>(config: {
431
+ model: string | {
432
+ key: string;
433
+ name?: string;
434
+ };
435
+ view: ElementDefinition | AttributeElementCreatorFunction;
436
+ converterPriority?: PriorityString;
437
+ } | {
438
+ model: {
439
+ key: string;
440
+ name?: string;
441
+ values: Array<TValues>;
442
+ };
443
+ view: Record<TValues, ElementDefinition | AttributeElementCreatorFunction>;
444
+ converterPriority?: PriorityString;
445
+ }): this;
446
+ /**
447
+ * Model attribute to view attribute conversion helper.
448
+ *
449
+ * This conversion results in adding an attribute to a view node, basing on an attribute from a model node. For example,
450
+ * `<imageInline src='foo.jpg'></imageInline>` is converted to `<img src='foo.jpg'></img>`.
451
+ *
452
+ * ```ts
453
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
454
+ * model: 'source',
455
+ * view: 'src'
456
+ * } );
457
+ *
458
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
459
+ * model: 'source',
460
+ * view: 'href',
461
+ * converterPriority: 'high'
462
+ * } );
463
+ *
464
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
465
+ * model: {
466
+ * name: 'imageInline',
467
+ * key: 'source'
468
+ * },
469
+ * view: 'src'
470
+ * } );
471
+ *
472
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
473
+ * model: {
474
+ * name: 'styled',
475
+ * values: [ 'dark', 'light' ]
476
+ * },
477
+ * view: {
478
+ * dark: {
479
+ * key: 'class',
480
+ * value: [ 'styled', 'styled-dark' ]
481
+ * },
482
+ * light: {
483
+ * key: 'class',
484
+ * value: [ 'styled', 'styled-light' ]
485
+ * }
486
+ * }
487
+ * } );
488
+ *
489
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
490
+ * model: 'styled',
491
+ * view: modelAttributeValue => ( {
492
+ * key: 'class',
493
+ * value: 'styled-' + modelAttributeValue
494
+ * } )
495
+ * } );
496
+ * ```
497
+ *
498
+ * **Note**: Downcasting to a style property requires providing `value` as an object:
499
+ *
500
+ * ```ts
501
+ * editor.conversion.for( 'downcast' ).attributeToAttribute( {
502
+ * model: 'lineHeight',
503
+ * view: modelAttributeValue => ( {
504
+ * key: 'style',
505
+ * value: {
506
+ * 'line-height': modelAttributeValue,
507
+ * 'border-bottom': '1px dotted #ba2'
508
+ * }
509
+ * } )
510
+ * } );
511
+ * ```
512
+ *
513
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
514
+ * to the conversion process.
515
+ *
516
+ * @param config Conversion configuration.
517
+ * @param config.model The key of the attribute to convert from or a `{ key, values, [ name ] }` object describing
518
+ * the attribute key, possible values and, optionally, an element name to convert from.
519
+ * @param config.view A view attribute key, or a `{ key, value }` object or a function that takes the model attribute value and
520
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
521
+ * as parameters and returns a `{ key, value }` object. If the `key` is `'class'`, the `value` can be a `String` or an
522
+ * array of `String`s. If the `key` is `'style'`, the `value` is an object with key-value pairs. In other cases, `value` is a `String`.
523
+ * If `config.model.values` is set, `config.view` should be an object assigning values from `config.model.values` to
524
+ * `{ key, value }` objects or a functions.
525
+ * @param config.converterPriority Converter priority.
526
+ */
527
+ attributeToAttribute<TValues extends string>(config: {
528
+ model: string | {
529
+ key: string;
530
+ name?: string;
531
+ };
532
+ view: string | AttributeDescriptor | AttributeCreatorFunction;
533
+ converterPriority?: PriorityString;
534
+ } | {
535
+ model: {
536
+ key: string;
537
+ name?: string;
538
+ values?: Array<TValues>;
539
+ };
540
+ view: Record<TValues, AttributeDescriptor | AttributeCreatorFunction>;
541
+ converterPriority?: PriorityString;
542
+ }): this;
543
+ /**
544
+ * Model marker to view element conversion helper.
545
+ *
546
+ * **Note**: This method should be used mainly for editing the downcast and it is recommended
547
+ * to use the {@link #markerToData `#markerToData()`} helper instead.
548
+ *
549
+ * This helper may produce invalid HTML code (e.g. a span between table cells).
550
+ * It should only be used when you are sure that the produced HTML will be semantically correct.
551
+ *
552
+ * This conversion results in creating a view element on the boundaries of the converted marker. If the converted marker
553
+ * is collapsed, only one element is created. For example, a model marker set like this: `<paragraph>F[oo b]ar</paragraph>`
554
+ * becomes `<p>F<span data-marker="search"></span>oo b<span data-marker="search"></span>ar</p>` in the view.
555
+ *
556
+ * ```ts
557
+ * editor.conversion.for( 'editingDowncast' ).markerToElement( {
558
+ * model: 'search',
559
+ * view: 'marker-search'
560
+ * } );
561
+ *
562
+ * editor.conversion.for( 'editingDowncast' ).markerToElement( {
563
+ * model: 'search',
564
+ * view: 'search-result',
565
+ * converterPriority: 'high'
566
+ * } );
567
+ *
568
+ * editor.conversion.for( 'editingDowncast' ).markerToElement( {
569
+ * model: 'search',
570
+ * view: {
571
+ * name: 'span',
572
+ * attributes: {
573
+ * 'data-marker': 'search'
574
+ * }
575
+ * }
576
+ * } );
577
+ *
578
+ * editor.conversion.for( 'editingDowncast' ).markerToElement( {
579
+ * model: 'search',
580
+ * view: ( markerData, conversionApi ) => {
581
+ * const { writer } = conversionApi;
582
+ *
583
+ * return writer.createUIElement( 'span', {
584
+ * 'data-marker': 'search',
585
+ * 'data-start': markerData.isOpening
586
+ * } );
587
+ * }
588
+ * } );
589
+ * ```
590
+ *
591
+ * If a function is passed as the `config.view` parameter, it will be used to generate both boundary elements. The function
592
+ * receives the `data` object and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
593
+ * as a parameters and should return an instance of the
594
+ * {@link module:engine/view/uielement~UIElement view UI element}. The `data` object and
595
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi `conversionApi`} are passed from
596
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:addMarker}. Additionally,
597
+ * the `data.isOpening` parameter is passed, which is set to `true` for the marker start boundary element, and `false` for
598
+ * the marker end boundary element.
599
+ *
600
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
601
+ * to the conversion process.
602
+ *
603
+ * @param config Conversion configuration.
604
+ * @param config.model The name of the model marker (or model marker group) to convert.
605
+ * @param config.view A view element definition or a function that takes the model marker data and
606
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as a parameters
607
+ * and returns a view UI element.
608
+ * @param config.converterPriority Converter priority.
609
+ */
610
+ markerToElement(config: {
611
+ model: string;
612
+ view: ElementDefinition | MarkerElementCreatorFunction;
613
+ converterPriority?: PriorityString;
614
+ }): this;
615
+ /**
616
+ * Model marker to highlight conversion helper.
617
+ *
618
+ * This conversion results in creating a highlight on view nodes. For this kind of conversion,
619
+ * the {@link module:engine/conversion/downcasthelpers~HighlightDescriptor} should be provided.
620
+ *
621
+ * For text nodes, a `<span>` {@link module:engine/view/attributeelement~AttributeElement} is created and it wraps all text nodes
622
+ * in the converted marker range. For example, a model marker set like this: `<paragraph>F[oo b]ar</paragraph>` becomes
623
+ * `<p>F<span class="comment">oo b</span>ar</p>` in the view.
624
+ *
625
+ * {@link module:engine/view/containerelement~ContainerElement} may provide a custom way of handling highlight. Most often,
626
+ * the element itself is given classes and attributes described in the highlight descriptor (instead of being wrapped in `<span>`).
627
+ * For example, a model marker set like this:
628
+ * `[<imageInline src="foo.jpg"></imageInline>]` becomes `<img src="foo.jpg" class="comment"></img>` in the view.
629
+ *
630
+ * For container elements, the conversion is two-step. While the converter processes the highlight descriptor and passes it
631
+ * to a container element, it is the container element instance itself that applies values from the highlight descriptor.
632
+ * So, in a sense, the converter takes care of stating what should be applied on what, while the element decides how to apply that.
633
+ *
634
+ * ```ts
635
+ * editor.conversion.for( 'downcast' ).markerToHighlight( { model: 'comment', view: { classes: 'comment' } } );
636
+ *
637
+ * editor.conversion.for( 'downcast' ).markerToHighlight( {
638
+ * model: 'comment',
639
+ * view: { classes: 'comment' },
640
+ * converterPriority: 'high'
641
+ * } );
642
+ *
643
+ * editor.conversion.for( 'downcast' ).markerToHighlight( {
644
+ * model: 'comment',
645
+ * view: ( data, conversionApi ) => {
646
+ * // Assuming that the marker name is in a form of comment:commentType:commentId.
647
+ * const [ , commentType, commentId ] = data.markerName.split( ':' );
648
+ *
649
+ * return {
650
+ * classes: [ 'comment', 'comment-' + commentType ],
651
+ * attributes: { 'data-comment-id': commentId }
652
+ * };
653
+ * }
654
+ * } );
655
+ * ```
656
+ *
657
+ * If a function is passed as the `config.view` parameter, it will be used to generate the highlight descriptor. The function
658
+ * receives the `data` object and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
659
+ * as the parameters and should return a
660
+ * {@link module:engine/conversion/downcasthelpers~HighlightDescriptor highlight descriptor}.
661
+ * The `data` object properties are passed from {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:addMarker}.
662
+ *
663
+ * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
664
+ * to the conversion process.
665
+ *
666
+ * @param config Conversion configuration.
667
+ * @param config.model The name of the model marker (or model marker group) to convert.
668
+ * @param config.view A highlight descriptor that will be used for highlighting or a function that takes the model marker data and
669
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as a parameters
670
+ * and returns a highlight descriptor.
671
+ * @param config.converterPriority Converter priority.
672
+ */
673
+ markerToHighlight(config: {
674
+ model: string;
675
+ view: HighlightDescriptor | HighlightDescriptorCreatorFunction;
676
+ converterPriority?: PriorityString;
677
+ }): this;
678
+ /**
679
+ * Model marker converter for data downcast.
680
+ *
681
+ * This conversion creates a representation for model marker boundaries in the view:
682
+ *
683
+ * * If the marker boundary is before or after a model element, a view attribute is set on a corresponding view element.
684
+ * * In other cases, a view element with the specified tag name is inserted at the corresponding view position.
685
+ *
686
+ * Typically, the marker names use the `group:uniqueId:otherData` convention. For example: `comment:e34zfk9k2n459df53sjl34:zx32c`.
687
+ * The default configuration for this conversion is that the first part is the `group` part and the rest of
688
+ * the marker name becomes the `name` part.
689
+ *
690
+ * Tag and attribute names and values are generated from the marker name:
691
+ *
692
+ * * The templates for attributes are `data-[group]-start-before="[name]"`, `data-[group]-start-after="[name]"`,
693
+ * `data-[group]-end-before="[name]"` and `data-[group]-end-after="[name]"`.
694
+ * * The templates for view elements are `<[group]-start name="[name]">` and `<[group]-end name="[name]">`.
695
+ *
696
+ * Attributes mark whether the given marker's start or end boundary is before or after the given element.
697
+ * The `data-[group]-start-before` and `data-[group]-end-after` attributes are favored.
698
+ * The other two are used when the former two cannot be used.
699
+ *
700
+ * The conversion configuration can take a function that will generate different group and name parts.
701
+ * If such a function is set as the `config.view` parameter, it is passed a marker name and it is expected to return an object with two
702
+ * properties: `group` and `name`. If the function returns a falsy value, the conversion will not take place.
703
+ *
704
+ * Basic usage:
705
+ *
706
+ * ```ts
707
+ * // Using the default conversion.
708
+ * // In this case, all markers with names starting with 'comment:' will be converted.
709
+ * // The `group` parameter will be set to `comment`.
710
+ * // The `name` parameter will be the rest of the marker name (without the `:`).
711
+ * editor.conversion.for( 'dataDowncast' ).markerToData( {
712
+ * model: 'comment'
713
+ * } );
714
+ * ```
715
+ *
716
+ * An example of a view that may be generated by this conversion (assuming a marker with the name `comment:commentId:uid` marked
717
+ * by `[]`):
718
+ *
719
+ * ```
720
+ * // Model:
721
+ * <paragraph>Foo[bar</paragraph>
722
+ * <imageBlock src="abc.jpg"></imageBlock>]
723
+ *
724
+ * // View:
725
+ * <p>Foo<comment-start name="commentId:uid"></comment-start>bar</p>
726
+ * <figure data-comment-end-after="commentId:uid" class="image"><img src="abc.jpg" /></figure>
727
+ * ```
728
+ *
729
+ * In the example above, the comment starts before "bar" and ends after the image.
730
+ *
731
+ * If the `name` part is empty, the following view may be generated:
732
+ *
733
+ * ```html
734
+ * <p>Foo <myMarker-start></myMarker-start>bar</p>
735
+ * <figure data-myMarker-end-after="" class="image"><img src="abc.jpg" /></figure>
736
+ * ```
737
+ *
738
+ * **Note:** A situation where some markers have the `name` part and some do not, is incorrect and should be avoided.
739
+ *
740
+ * Examples where `data-group-start-after` and `data-group-end-before` are used:
741
+ *
742
+ * ```
743
+ * // Model:
744
+ * <blockQuote>[]<paragraph>Foo</paragraph></blockQuote>
745
+ *
746
+ * // View:
747
+ * <blockquote><p data-group-end-before="name" data-group-start-before="name">Foo</p></blockquote>
748
+ * ```
749
+ *
750
+ * Similarly, when a marker is collapsed after the last element:
751
+ *
752
+ * ```
753
+ * // Model:
754
+ * <blockQuote><paragraph>Foo</paragraph>[]</blockQuote>
755
+ *
756
+ * // View:
757
+ * <blockquote><p data-group-end-after="name" data-group-start-after="name">Foo</p></blockquote>
758
+ * ```
759
+ *
760
+ * When there are multiple markers from the same group stored in the same attribute of the same element, their
761
+ * name parts are put together in the attribute value, for example: `data-group-start-before="name1,name2,name3"`.
762
+ *
763
+ * Other examples of usage:
764
+ *
765
+ * ```ts
766
+ * // Using a custom function which is the same as the default conversion:
767
+ * editor.conversion.for( 'dataDowncast' ).markerToData( {
768
+ * model: 'comment',
769
+ * view: markerName => ( {
770
+ * group: 'comment',
771
+ * name: markerName.substr( 8 ) // Removes 'comment:' part.
772
+ * } )
773
+ * } );
774
+ *
775
+ * // Using the converter priority:
776
+ * editor.conversion.for( 'dataDowncast' ).markerToData( {
777
+ * model: 'comment',
778
+ * view: markerName => ( {
779
+ * group: 'comment',
780
+ * name: markerName.substr( 8 ) // Removes 'comment:' part.
781
+ * } ),
782
+ * converterPriority: 'high'
783
+ * } );
784
+ * ```
785
+ *
786
+ * This kind of conversion is useful for saving data into the database, so it should be used in the data conversion pipeline.
787
+ *
788
+ * See the {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} API guide to learn how to
789
+ * add a converter to the conversion process.
790
+ *
791
+ * @param config Conversion configuration.
792
+ * @param config.model The name of the model marker (or the model marker group) to convert.
793
+ * @param config.view A function that takes the model marker name and
794
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as the parameters
795
+ * and returns an object with the `group` and `name` properties.
796
+ * @param config.converterPriority Converter priority.
797
+ */
798
+ markerToData(config: {
799
+ model: string;
800
+ view?: MarkerDataCreatorFunction;
801
+ converterPriority?: PriorityString;
802
+ }): this;
803
+ }
804
+ /**
805
+ * Function factory that creates a default downcast converter for text insertion changes.
806
+ *
807
+ * The converter automatically consumes the corresponding value from the consumables list and stops the event (see
808
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
809
+ *
810
+ * ```ts
811
+ * modelDispatcher.on( 'insert:$text', insertText() );
812
+ * ```
813
+ *
814
+ * @returns Insert text event converter.
815
+ */
816
+ export declare function insertText(): (evt: EventInfo, data: {
817
+ item: ModelText | ModelTextProxy;
818
+ range: ModelRange;
819
+ }, conversionApi: DowncastConversionApi) => void;
820
+ /**
821
+ * Function factory that creates a default downcast converter for triggering attributes and children conversion.
822
+ *
823
+ * @returns The converter.
824
+ */
825
+ export declare function insertAttributesAndChildren(): (evt: unknown, data: {
826
+ item: ModelItem;
827
+ reconversion?: boolean;
828
+ }, conversionApi: DowncastConversionApi) => void;
829
+ /**
830
+ * Function factory that creates a default downcast converter for node remove changes.
831
+ *
832
+ * ```ts
833
+ * modelDispatcher.on( 'remove', remove() );
834
+ * ```
835
+ *
836
+ * @returns Remove event converter.
837
+ */
838
+ export declare function remove(): (evt: unknown, data: {
839
+ position: ModelPosition;
840
+ length: number;
841
+ }, conversionApi: DowncastConversionApi) => void;
842
+ /**
843
+ * Creates a `<span>` {@link module:engine/view/attributeelement~AttributeElement view attribute element} from the information
844
+ * provided by the {@link module:engine/conversion/downcasthelpers~HighlightDescriptor highlight descriptor} object. If the priority
845
+ * is not provided in the descriptor, the default priority will be used.
846
+ */
847
+ export declare function createViewElementFromHighlightDescriptor(writer: DowncastWriter, descriptor: HighlightDescriptor): ViewAttributeElement;
848
+ /**
849
+ * Function factory that creates a converter which converts a non-collapsed {@link module:engine/model/selection~Selection model selection}
850
+ * to a {@link module:engine/view/documentselection~DocumentSelection view selection}. The converter consumes appropriate
851
+ * value from the `consumable` object and maps model positions from the selection to view positions.
852
+ *
853
+ * ```ts
854
+ * modelDispatcher.on( 'selection', convertRangeSelection() );
855
+ * ```
856
+ *
857
+ * @returns Selection converter.
858
+ */
859
+ export declare function convertRangeSelection(): (evt: EventInfo, data: {
860
+ selection: ModelSelection | ModelDocumentSelection;
861
+ }, conversionApi: DowncastConversionApi) => void;
862
+ /**
863
+ * Function factory that creates a converter which converts a collapsed {@link module:engine/model/selection~Selection model selection} to
864
+ * a {@link module:engine/view/documentselection~DocumentSelection view selection}. The converter consumes appropriate
865
+ * value from the `consumable` object, maps the model selection position to the view position and breaks
866
+ * {@link module:engine/view/attributeelement~AttributeElement attribute elements} at the selection position.
867
+ *
868
+ * ```ts
869
+ * modelDispatcher.on( 'selection', convertCollapsedSelection() );
870
+ * ```
871
+ *
872
+ * An example of the view state before and after converting the collapsed selection:
873
+ *
874
+ * ```
875
+ * <p><strong>f^oo<strong>bar</p>
876
+ * -> <p><strong>f</strong>^<strong>oo</strong>bar</p>
877
+ * ```
878
+ *
879
+ * By breaking attribute elements like `<strong>`, the selection is in a correct element. Then, when the selection attribute is
880
+ * converted, broken attributes might be merged again, or the position where the selection is may be wrapped
881
+ * with different, appropriate attribute elements.
882
+ *
883
+ * See also {@link module:engine/conversion/downcasthelpers~cleanSelection} which does a clean-up
884
+ * by merging attributes.
885
+ *
886
+ * @returns Selection converter.
887
+ */
888
+ export declare function convertCollapsedSelection(): (evt: EventInfo, data: {
889
+ selection: ModelSelection | ModelDocumentSelection;
890
+ }, conversionApi: DowncastConversionApi) => void;
891
+ /**
892
+ * Function factory that creates a converter which cleans artifacts after the previous
893
+ * {@link module:engine/model/selection~Selection model selection} conversion. It removes all empty
894
+ * {@link module:engine/view/attributeelement~AttributeElement view attribute elements} and merges sibling attributes at all start and end
895
+ * positions of all ranges.
896
+ *
897
+ * ```
898
+ * <p><strong>^</strong></p>
899
+ * -> <p>^</p>
900
+ *
901
+ * <p><strong>foo</strong>^<strong>bar</strong>bar</p>
902
+ * -> <p><strong>foo^bar<strong>bar</p>
903
+ *
904
+ * <p><strong>foo</strong><em>^</em><strong>bar</strong>bar</p>
905
+ * -> <p><strong>foo^bar<strong>bar</p>
906
+ * ```
907
+ *
908
+ * This listener should be assigned before any converter for the new selection:
909
+ *
910
+ * ```ts
911
+ * modelDispatcher.on( 'cleanSelection', cleanSelection() );
912
+ * ```
913
+ *
914
+ * See {@link module:engine/conversion/downcasthelpers~convertCollapsedSelection}
915
+ * which does the opposite by breaking attributes in the selection position.
916
+ *
917
+ * @returns Selection converter.
918
+ */
919
+ export declare function cleanSelection(): (evt: EventInfo, data: unknown, conversionApi: DowncastConversionApi) => void;
920
+ /**
921
+ * Function factory that creates a converter which converts the set/change/remove attribute changes from the model to the view.
922
+ * It can also be used to convert selection attributes. In that case, an empty attribute element will be created and the
923
+ * selection will be put inside it.
924
+ *
925
+ * Attributes from the model are converted to a view element that will be wrapping these view nodes that are bound to
926
+ * model elements having the given attribute. This is useful for attributes like `bold` that may be set on text nodes in the model
927
+ * but are represented as an element in the view:
928
+ *
929
+ * ```
930
+ * [paragraph] MODEL ====> VIEW <p>
931
+ * |- a {bold: true} |- <b>
932
+ * |- b {bold: true} | |- ab
933
+ * |- c |- c
934
+ * ```
935
+ *
936
+ * Passed `Function` will be provided with the attribute value and then all the parameters of the
937
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute` event}.
938
+ * It is expected that the function returns an {@link module:engine/view/element~Element}.
939
+ * The result of the function will be the wrapping element.
940
+ * When the provided `Function` does not return any element, no conversion will take place.
941
+ *
942
+ * The converter automatically consumes the corresponding value from the consumables list and stops the event (see
943
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}).
944
+ *
945
+ * ```ts
946
+ * modelDispatcher.on( 'attribute:bold', wrap( ( modelAttributeValue, { writer } ) => {
947
+ * return writer.createAttributeElement( 'strong' );
948
+ * } );
949
+ * ```
950
+ *
951
+ * @internal
952
+ * @param elementCreator Function returning a view element that will be used for wrapping.
953
+ * @returns Set/change attribute converter.
954
+ */
955
+ export declare function wrap(elementCreator: AttributeElementCreatorFunction): (evt: EventInfo, data: {
956
+ item: ModelItem | ModelSelection | ModelDocumentSelection;
957
+ range: ModelRange;
958
+ attributeKey: string;
959
+ attributeOldValue: unknown;
960
+ attributeNewValue: unknown;
961
+ }, conversionApi: DowncastConversionApi) => void;
962
+ /**
963
+ * Function factory that creates a converter which converts node insertion changes from the model to the view.
964
+ * The function passed will be provided with all the parameters of the dispatcher's
965
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert` event}.
966
+ * It is expected that the function returns an {@link module:engine/view/element~Element}.
967
+ * The result of the function will be inserted into the view.
968
+ *
969
+ * The converter automatically consumes the corresponding value from the consumables list and binds the model and view elements.
970
+ *
971
+ * ```ts
972
+ * downcastDispatcher.on(
973
+ * 'insert:myElem',
974
+ * insertElement( ( modelItem, { writer } ) => {
975
+ * const text = writer.createText( 'myText' );
976
+ * const myElem = writer.createElement( 'myElem', { myAttr: 'my-' + modelItem.getAttribute( 'myAttr' ) }, text );
977
+ *
978
+ * // Do something fancy with `myElem` using `modelItem` or other parameters.
979
+ *
980
+ * return myElem;
981
+ * }
982
+ * ) );
983
+ * ```
984
+ *
985
+ * @internal
986
+ * @param elementCreator Function returning a view element, which will be inserted.
987
+ * @param consumer Function defining element consumption process.
988
+ * By default this function just consume passed item insertion.
989
+ * @returns Insert element event converter.
990
+ */
991
+ export declare function insertElement(elementCreator: ElementCreatorFunction, consumer?: ConsumerFunction): (evt: unknown, data: {
992
+ item: ModelElement;
993
+ range: ModelRange;
994
+ reconversion?: boolean;
995
+ }, conversionApi: DowncastConversionApi) => void;
996
+ /**
997
+ * Function factory that creates a converter which converts a single model node insertion to a view structure.
998
+ *
999
+ * It is expected that the passed element creator function returns an {@link module:engine/view/element~Element} with attached slots
1000
+ * created with `writer.createSlot()` to indicate where child nodes should be converted.
1001
+ *
1002
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1003
+ *
1004
+ * @internal
1005
+ * @param elementCreator Function returning a view structure, which will be inserted.
1006
+ * @param consumer A callback that is expected to consume all the consumables
1007
+ * that were used by the element creator.
1008
+ * @returns Insert element event converter.
1009
+ */
1010
+ export declare function insertStructure(elementCreator: StructureCreatorFunction, consumer: ConsumerFunction): (evt: unknown, data: {
1011
+ item: ModelElement;
1012
+ range: ModelRange;
1013
+ reconversion?: boolean;
1014
+ }, conversionApi: DowncastConversionApi) => void;
1015
+ /**
1016
+ * Function factory that creates a converter which converts marker adding change to the
1017
+ * {@link module:engine/view/uielement~UIElement view UI element}.
1018
+ *
1019
+ * The view UI element that will be added to the view depends on the passed parameter. See {@link ~insertElement}.
1020
+ * In case of a non-collapsed range, the UI element will not wrap nodes but separate elements will be placed at the beginning
1021
+ * and at the end of the range.
1022
+ *
1023
+ * This converter binds created UI elements with the marker name using {@link module:engine/conversion/mapper~Mapper#bindElementToMarker}.
1024
+ *
1025
+ * @internal
1026
+ * @param elementCreator A view UI element or a function returning the view element that will be inserted.
1027
+ * @returns Insert element event converter.
1028
+ */
1029
+ export declare function insertUIElement(elementCreator: MarkerElementCreatorFunction): (evt: EventInfo, data: {
1030
+ markerRange: ModelRange;
1031
+ markerName: string;
1032
+ isOpening?: boolean;
1033
+ }, conversionApi: DowncastConversionApi) => void;
1034
+ /**
1035
+ * An object describing how the marker highlight should be represented in the view.
1036
+ *
1037
+ * Each text node contained in a highlighted range will be wrapped in a `<span>`
1038
+ * {@link module:engine/view/attributeelement~AttributeElement view attribute element} with CSS class(es), attributes and a priority
1039
+ * described by this object.
1040
+ *
1041
+ * Additionally, each {@link module:engine/view/containerelement~ContainerElement container element} can handle displaying the highlight
1042
+ * separately by providing the `addHighlight` and `removeHighlight` custom properties. In this case:
1043
+ *
1044
+ * * The `HighlightDescriptor` object is passed to the `addHighlight` function upon conversion and should be used to apply the highlight to
1045
+ * the element.
1046
+ * * The descriptor `id` is passed to the `removeHighlight` function upon conversion and should be used to remove the highlight with the
1047
+ * given ID from the element.
1048
+ */
1049
+ export interface HighlightDescriptor {
1050
+ /**
1051
+ * A CSS class or an array of classes to set. If the descriptor is used to
1052
+ * create an {@link module:engine/view/attributeelement~AttributeElement attribute element} over text nodes, these classes will be set
1053
+ * on that attribute element. If the descriptor is applied to an element, usually these classes will be set on that element, however,
1054
+ * this depends on how the element converts the descriptor.
1055
+ */
1056
+ classes: string | Array<string>;
1057
+ /**
1058
+ * Descriptor identifier. If not provided, it defaults to the converted marker's name.
1059
+ */
1060
+ id?: string;
1061
+ /**
1062
+ * Descriptor priority. If not provided, it defaults to `10`. If the descriptor is used to create
1063
+ * an {@link module:engine/view/attributeelement~AttributeElement attribute element}, it will be that element's
1064
+ * {@link module:engine/view/attributeelement~AttributeElement#priority priority}. If the descriptor is applied to an element,
1065
+ * the priority will be used to determine which descriptor is more important.
1066
+ */
1067
+ priority?: number;
1068
+ /**
1069
+ * Attributes to set. If the descriptor is used to create
1070
+ * an {@link module:engine/view/attributeelement~AttributeElement attribute element} over text nodes, these attributes will be set
1071
+ * on that attribute element. If the descriptor is applied to an element, usually these attributes will be set on that element, however,
1072
+ * this depends on how the element converts the descriptor.
1073
+ */
1074
+ attributes?: Record<string, string>;
1075
+ }
1076
+ /**
1077
+ * A filtering function used to choose model child nodes to be downcasted into the specific view
1078
+ * {@link module:engine/view/downcastwriter~DowncastWriter#createSlot "slot"} while executing the
1079
+ * {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`} converter.
1080
+ *
1081
+ * @callback module:engine/conversion/downcasthelpers~SlotFilter
1082
+ *
1083
+ * @param node A model node.
1084
+ * @returns Whether the provided model node should be downcasted into this slot.
1085
+ *
1086
+ * @see module:engine/view/downcastwriter~DowncastWriter#createSlot
1087
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1088
+ * @see module:engine/conversion/downcasthelpers~insertStructure
1089
+ */
1090
+ export type SlotFilter = (node: ModelNode) => boolean;
1091
+ /**
1092
+ * A view element creator function that takes the model element and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi
1093
+ * downcast conversion API} as parameters and returns a view container element.
1094
+ *
1095
+ * @callback module:engine/conversion/downcasthelpers~ElementCreatorFunction
1096
+ *
1097
+ * @param element The model element to be converted to the view structure.
1098
+ * @param conversionApi The conversion interface.
1099
+ * @param data Additional information about the change (same as for
1100
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert`} event).
1101
+ * @param data.item Inserted item.
1102
+ * @param data.range Range spanning over inserted item.
1103
+ * @returns The view element.
1104
+ *
1105
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement
1106
+ * @see module:engine/conversion/downcasthelpers~insertElement
1107
+ */
1108
+ export type ElementCreatorFunction = (element: ModelElement, conversionApi: DowncastConversionApi, data: {
1109
+ item: ModelItem;
1110
+ range: ModelRange;
1111
+ }) => ViewElement | null;
1112
+ /**
1113
+ * A function that takes the model element and {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast
1114
+ * conversion API} as parameters and returns a view container element with slots for model child nodes to be converted into.
1115
+ *
1116
+ * @callback module:engine/conversion/downcasthelpers~StructureCreatorFunction
1117
+ *
1118
+ * @param element The model element to be converted to the view structure.
1119
+ * @param conversionApi The conversion interface.
1120
+ * @param data Additional information about the change (same as for
1121
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:insert `insert`} event).
1122
+ * @param data.item Inserted item.
1123
+ * @param data.range Range spanning over inserted item.
1124
+ * @returns The view structure with slots for model child nodes.
1125
+ *
1126
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
1127
+ * @see module:engine/conversion/downcasthelpers~insertStructure
1128
+ */
1129
+ export type StructureCreatorFunction = ElementCreatorFunction;
1130
+ /**
1131
+ * A view element creator function that takes the model attribute value and
1132
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API} as parameters and returns a view
1133
+ * attribute element.
1134
+ *
1135
+ * @callback module:engine/conversion/downcasthelpers~AttributeElementCreatorFunction
1136
+ *
1137
+ * @param attributeValue The model attribute value to be converted to the view attribute element.
1138
+ * @param conversionApi The conversion interface.
1139
+ * @param data Additional information about the change (same as for
1140
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute`} event).
1141
+ * @param data.item Changed item or converted selection.
1142
+ * @param data.range Range spanning over changed item or selection range.
1143
+ * @param data.attributeKey Attribute key.
1144
+ * @param data.attributeOldValue Attribute value before the change. This is `null` when selection attribute is converted.
1145
+ * @param data.attributeNewValue New attribute value.
1146
+ * @returns The view attribute element.
1147
+ *
1148
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement
1149
+ * @see module:engine/conversion/downcasthelpers~wrap
1150
+ */
1151
+ export type AttributeElementCreatorFunction = (attributeValue: any, conversionApi: DowncastConversionApi, data: {
1152
+ item: ModelItem | ModelSelection | ModelDocumentSelection;
1153
+ range: ModelRange;
1154
+ attributeKey: string;
1155
+ attributeOldValue: unknown;
1156
+ attributeNewValue: unknown;
1157
+ }) => ViewAttributeElement | null;
1158
+ /**
1159
+ * A function that takes the model attribute value and
1160
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi downcast conversion API}
1161
+ * as parameters.
1162
+ *
1163
+ * @callback module:engine/conversion/downcasthelpers~AttributeCreatorFunction
1164
+ *
1165
+ * @param attributeValue The model attribute value to be converted to the view attribute element.
1166
+ * @param conversionApi The conversion interface.
1167
+ * @param data Additional information about the change (same as for
1168
+ * {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher#event:attribute `attribute`} event).
1169
+ * @param data.item Changed item or converted selection.
1170
+ * @param data.range Range spanning over changed item or selection range.
1171
+ * @param data.attributeKey Attribute key.
1172
+ * @param data.attributeOldValue Attribute value before the change. This is `null` when selection attribute is converted.
1173
+ * @param data.attributeNewValue New attribute value.
1174
+ * @returns A `{ key, value }` object. If `key` is `'class'`, `value` can be a `String` or an
1175
+ * array of `String`s. If `key` is `'style'`, `value` is an object with key-value pairs. In other cases, `value` is a `String`.
1176
+ *
1177
+ * @see module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToAttribute
1178
+ */
1179
+ export type AttributeCreatorFunction = (attributeValue: unknown, conversionApi: DowncastConversionApi, data: {
1180
+ item: ModelItem;
1181
+ range: ModelRange;
1182
+ attributeKey: string;
1183
+ attributeOldValue: unknown;
1184
+ attributeNewValue: unknown;
1185
+ }) => AttributeDescriptor | null;
1186
+ export type AttributeDescriptor = {
1187
+ key: 'class';
1188
+ value: string | Array<string>;
1189
+ } | {
1190
+ key: 'style';
1191
+ value: Record<string, string>;
1192
+ } | {
1193
+ key: Exclude<string, 'class' | 'style'>;
1194
+ value: string;
1195
+ };
1196
+ export type MarkerElementCreatorFunction = (data: {
1197
+ markerRange: ModelRange;
1198
+ markerName: string;
1199
+ isOpening?: boolean;
1200
+ }, conversionApi: DowncastConversionApi) => UIElement | null;
1201
+ export type HighlightDescriptorCreatorFunction = (data: {
1202
+ markerRange: ModelRange;
1203
+ markerName: string;
1204
+ }, conversionApi: DowncastConversionApi) => HighlightDescriptor | null;
1205
+ export type AddHighlightCallback = (viewElement: ViewElement, descriptor: HighlightDescriptor, writer: DowncastWriter) => void;
1206
+ export type RemoveHighlightCallback = (viewElement: ViewElement, id: string, writer: DowncastWriter) => void;
1207
+ export type MarkerDataCreatorFunction = (markerName: string, conversionApi: DowncastConversionApi) => {
1208
+ name: string;
1209
+ group: string;
1210
+ } | null;
1211
+ /**
1212
+ * A function that is expected to consume all the consumables that were used by the element creator.
1213
+ *
1214
+ * @callback module:engine/conversion/downcasthelpers~ConsumerFunction
1215
+ *
1216
+ * @param element The model element to be converted to the view structure.
1217
+ * @param consumable The `ModelConsumable` same as in
1218
+ * {@link module:engine/conversion/downcastdispatcher~DowncastConversionApi#consumable `DowncastConversionApi.consumable`}.
1219
+ * @param options.preflight Whether should consume or just check if can be consumed.
1220
+ * @returns `true` if all consumable values were available and were consumed, `false` otherwise.
1221
+ *
1222
+ * @see module:engine/conversion/downcasthelpers~insertStructure
1223
+ */
1224
+ export type ConsumerFunction = (element: ModelElement, consumable: ModelConsumable, options?: {
1225
+ preflight?: boolean;
1226
+ }) => boolean | null;