@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1

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 (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +25 -24
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +72 -116
  5. package/src/controller/editingcontroller.d.ts +98 -0
  6. package/src/controller/editingcontroller.js +22 -46
  7. package/src/conversion/conversion.d.ts +476 -0
  8. package/src/conversion/conversion.js +328 -347
  9. package/src/conversion/conversionhelpers.d.ts +26 -0
  10. package/src/conversion/conversionhelpers.js +1 -5
  11. package/src/conversion/downcastdispatcher.d.ts +547 -0
  12. package/src/conversion/downcastdispatcher.js +74 -152
  13. package/src/conversion/downcasthelpers.d.ts +1226 -0
  14. package/src/conversion/downcasthelpers.js +843 -762
  15. package/src/conversion/mapper.d.ts +503 -0
  16. package/src/conversion/mapper.js +84 -99
  17. package/src/conversion/modelconsumable.d.ts +201 -0
  18. package/src/conversion/modelconsumable.js +96 -99
  19. package/src/conversion/upcastdispatcher.d.ts +492 -0
  20. package/src/conversion/upcastdispatcher.js +73 -100
  21. package/src/conversion/upcasthelpers.d.ts +499 -0
  22. package/src/conversion/upcasthelpers.js +406 -373
  23. package/src/conversion/viewconsumable.d.ts +369 -0
  24. package/src/conversion/viewconsumable.js +139 -173
  25. package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
  26. package/src/dataprocessor/basichtmlwriter.js +0 -9
  27. package/src/dataprocessor/dataprocessor.d.ts +61 -0
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
  29. package/src/dataprocessor/htmldataprocessor.js +6 -28
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -0
  31. package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
  32. package/src/dataprocessor/xmldataprocessor.js +8 -40
  33. package/src/dev-utils/model.d.ts +124 -0
  34. package/src/dev-utils/model.js +41 -38
  35. package/src/dev-utils/operationreplayer.d.ts +51 -0
  36. package/src/dev-utils/operationreplayer.js +6 -14
  37. package/src/dev-utils/utils.d.ts +37 -0
  38. package/src/dev-utils/utils.js +5 -18
  39. package/src/dev-utils/view.d.ts +319 -0
  40. package/src/dev-utils/view.js +205 -226
  41. package/src/index.d.ts +108 -0
  42. package/src/index.js +4 -0
  43. package/src/model/batch.d.ts +106 -0
  44. package/src/model/differ.d.ts +329 -0
  45. package/src/model/document.d.ts +246 -0
  46. package/src/model/document.js +1 -1
  47. package/src/model/documentfragment.d.ts +196 -0
  48. package/src/model/documentfragment.js +2 -2
  49. package/src/model/documentselection.d.ts +420 -0
  50. package/src/model/element.d.ts +165 -0
  51. package/src/model/history.d.ts +114 -0
  52. package/src/model/item.d.ts +14 -0
  53. package/src/model/liveposition.d.ts +77 -0
  54. package/src/model/liverange.d.ts +102 -0
  55. package/src/model/markercollection.d.ts +335 -0
  56. package/src/model/model.d.ts +885 -0
  57. package/src/model/model.js +59 -81
  58. package/src/model/node.d.ts +256 -0
  59. package/src/model/nodelist.d.ts +91 -0
  60. package/src/model/operation/attributeoperation.d.ts +98 -0
  61. package/src/model/operation/detachoperation.d.ts +55 -0
  62. package/src/model/operation/insertoperation.d.ts +85 -0
  63. package/src/model/operation/markeroperation.d.ts +86 -0
  64. package/src/model/operation/mergeoperation.d.ts +95 -0
  65. package/src/model/operation/mergeoperation.js +1 -1
  66. package/src/model/operation/moveoperation.d.ts +91 -0
  67. package/src/model/operation/nooperation.d.ts +33 -0
  68. package/src/model/operation/operation.d.ts +89 -0
  69. package/src/model/operation/operationfactory.d.ts +18 -0
  70. package/src/model/operation/renameoperation.d.ts +78 -0
  71. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  72. package/src/model/operation/rootattributeoperation.js +1 -1
  73. package/src/model/operation/splitoperation.d.ts +104 -0
  74. package/src/model/operation/splitoperation.js +1 -1
  75. package/src/model/operation/transform.d.ts +100 -0
  76. package/src/model/operation/utils.d.ts +71 -0
  77. package/src/model/operation/utils.js +1 -1
  78. package/src/model/position.d.ts +539 -0
  79. package/src/model/position.js +1 -1
  80. package/src/model/range.d.ts +458 -0
  81. package/src/model/range.js +1 -1
  82. package/src/model/rootelement.d.ts +40 -0
  83. package/src/model/schema.d.ts +1176 -0
  84. package/src/model/schema.js +19 -19
  85. package/src/model/selection.d.ts +472 -0
  86. package/src/model/text.d.ts +66 -0
  87. package/src/model/text.js +0 -2
  88. package/src/model/textproxy.d.ts +144 -0
  89. package/src/model/treewalker.d.ts +186 -0
  90. package/src/model/treewalker.js +19 -10
  91. package/src/model/typecheckable.d.ts +285 -0
  92. package/src/model/utils/autoparagraphing.d.ts +37 -0
  93. package/src/model/utils/deletecontent.d.ts +58 -0
  94. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  95. package/src/model/utils/getselectedcontent.d.ts +30 -0
  96. package/src/model/utils/insertcontent.d.ts +46 -0
  97. package/src/model/utils/insertcontent.js +2 -12
  98. package/src/model/utils/insertobject.d.ts +44 -0
  99. package/src/model/utils/insertobject.js +3 -14
  100. package/src/model/utils/modifyselection.d.ts +48 -0
  101. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  102. package/src/model/writer.d.ts +823 -0
  103. package/src/model/writer.js +6 -61
  104. package/src/view/attributeelement.d.ts +108 -0
  105. package/src/view/attributeelement.js +25 -69
  106. package/src/view/containerelement.d.ts +49 -0
  107. package/src/view/containerelement.js +10 -43
  108. package/src/view/datatransfer.d.ts +75 -0
  109. package/src/view/document.d.ts +184 -0
  110. package/src/view/document.js +15 -84
  111. package/src/view/documentfragment.d.ts +149 -0
  112. package/src/view/documentfragment.js +39 -81
  113. package/src/view/documentselection.d.ts +306 -0
  114. package/src/view/documentselection.js +42 -143
  115. package/src/view/domconverter.d.ts +650 -0
  116. package/src/view/domconverter.js +157 -283
  117. package/src/view/downcastwriter.d.ts +996 -0
  118. package/src/view/downcastwriter.js +259 -426
  119. package/src/view/editableelement.d.ts +52 -0
  120. package/src/view/editableelement.js +9 -49
  121. package/src/view/element.d.ts +468 -0
  122. package/src/view/element.js +150 -222
  123. package/src/view/elementdefinition.d.ts +87 -0
  124. package/src/view/emptyelement.d.ts +41 -0
  125. package/src/view/emptyelement.js +11 -44
  126. package/src/view/filler.d.ts +111 -0
  127. package/src/view/filler.js +24 -21
  128. package/src/view/item.d.ts +14 -0
  129. package/src/view/matcher.d.ts +486 -0
  130. package/src/view/matcher.js +247 -218
  131. package/src/view/node.d.ts +163 -0
  132. package/src/view/node.js +26 -100
  133. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  134. package/src/view/observer/arrowkeysobserver.js +0 -13
  135. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  136. package/src/view/observer/bubblingemittermixin.js +36 -25
  137. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  138. package/src/view/observer/bubblingeventinfo.js +3 -29
  139. package/src/view/observer/clickobserver.d.ts +43 -0
  140. package/src/view/observer/clickobserver.js +9 -19
  141. package/src/view/observer/compositionobserver.d.ts +82 -0
  142. package/src/view/observer/compositionobserver.js +13 -42
  143. package/src/view/observer/domeventdata.d.ts +50 -0
  144. package/src/view/observer/domeventdata.js +5 -30
  145. package/src/view/observer/domeventobserver.d.ts +69 -0
  146. package/src/view/observer/domeventobserver.js +19 -21
  147. package/src/view/observer/fakeselectionobserver.d.ts +43 -0
  148. package/src/view/observer/fakeselectionobserver.js +0 -16
  149. package/src/view/observer/focusobserver.d.ts +82 -0
  150. package/src/view/observer/focusobserver.js +14 -40
  151. package/src/view/observer/inputobserver.d.ts +86 -0
  152. package/src/view/observer/inputobserver.js +18 -64
  153. package/src/view/observer/keyobserver.d.ts +66 -0
  154. package/src/view/observer/keyobserver.js +8 -42
  155. package/src/view/observer/mouseobserver.d.ts +89 -0
  156. package/src/view/observer/mouseobserver.js +8 -28
  157. package/src/view/observer/mutationobserver.d.ts +82 -0
  158. package/src/view/observer/mutationobserver.js +7 -37
  159. package/src/view/observer/observer.d.ts +84 -0
  160. package/src/view/observer/observer.js +12 -25
  161. package/src/view/observer/selectionobserver.d.ts +144 -0
  162. package/src/view/observer/selectionobserver.js +17 -107
  163. package/src/view/observer/tabobserver.d.ts +42 -0
  164. package/src/view/observer/tabobserver.js +0 -14
  165. package/src/view/placeholder.d.ts +85 -0
  166. package/src/view/placeholder.js +26 -43
  167. package/src/view/position.d.ts +189 -0
  168. package/src/view/position.js +36 -83
  169. package/src/view/range.d.ts +279 -0
  170. package/src/view/range.js +79 -122
  171. package/src/view/rawelement.d.ts +73 -0
  172. package/src/view/rawelement.js +34 -48
  173. package/src/view/renderer.d.ts +265 -0
  174. package/src/view/renderer.js +105 -193
  175. package/src/view/rooteditableelement.d.ts +41 -0
  176. package/src/view/rooteditableelement.js +12 -40
  177. package/src/view/selection.d.ts +375 -0
  178. package/src/view/selection.js +79 -153
  179. package/src/view/styles/background.d.ts +33 -0
  180. package/src/view/styles/background.js +14 -12
  181. package/src/view/styles/border.d.ts +43 -0
  182. package/src/view/styles/border.js +58 -48
  183. package/src/view/styles/margin.d.ts +29 -0
  184. package/src/view/styles/margin.js +13 -11
  185. package/src/view/styles/padding.d.ts +29 -0
  186. package/src/view/styles/padding.js +13 -11
  187. package/src/view/styles/utils.d.ts +93 -0
  188. package/src/view/styles/utils.js +22 -48
  189. package/src/view/stylesmap.d.ts +675 -0
  190. package/src/view/stylesmap.js +249 -244
  191. package/src/view/text.d.ts +74 -0
  192. package/src/view/text.js +16 -46
  193. package/src/view/textproxy.d.ts +97 -0
  194. package/src/view/textproxy.js +10 -59
  195. package/src/view/treewalker.d.ts +195 -0
  196. package/src/view/treewalker.js +43 -106
  197. package/src/view/typecheckable.d.ts +448 -0
  198. package/src/view/uielement.d.ts +96 -0
  199. package/src/view/uielement.js +29 -63
  200. package/src/view/upcastwriter.d.ts +417 -0
  201. package/src/view/upcastwriter.js +86 -157
  202. package/src/view/view.d.ts +417 -0
  203. package/src/view/view.js +47 -175
@@ -16,7 +16,7 @@ import { cloneDeep } from 'lodash-es';
16
16
  /**
17
17
  * Upcast conversion helper functions.
18
18
  *
19
- * Learn more about {@glink framework/guides/deep-dive/conversion/upcast upcast helpers}.
19
+ * Learn more about {@glink framework/deep-dive/conversion/upcast upcast helpers}.
20
20
  *
21
21
  * @extends module:engine/conversion/conversionhelpers~ConversionHelpers
22
22
  */
@@ -30,49 +30,49 @@ export default class UpcastHelpers extends ConversionHelpers {
30
30
  * Keep in mind that the element will be inserted only if it is allowed
31
31
  * by {@link module:engine/model/schema~Schema schema} configuration.
32
32
  *
33
- * editor.conversion.for( 'upcast' ).elementToElement( {
34
- * view: 'p',
35
- * model: 'paragraph'
36
- * } );
37
- *
38
- * editor.conversion.for( 'upcast' ).elementToElement( {
39
- * view: 'p',
40
- * model: 'paragraph',
41
- * converterPriority: 'high'
42
- * } );
43
- *
44
- * editor.conversion.for( 'upcast' ).elementToElement( {
45
- * view: {
46
- * name: 'p',
47
- * classes: 'fancy'
48
- * },
49
- * model: 'fancyParagraph'
50
- * } );
51
- *
52
- * editor.conversion.for( 'upcast' ).elementToElement( {
53
- * view: {
54
- * name: 'p',
55
- * classes: 'heading'
56
- * },
57
- * model: ( viewElement, conversionApi ) => {
58
- * const modelWriter = conversionApi.writer;
59
- *
60
- * return modelWriter.createElement( 'heading', { level: viewElement.getAttribute( 'data-level' ) } );
61
- * }
62
- * } );
33
+ * ```ts
34
+ * editor.conversion.for( 'upcast' ).elementToElement( {
35
+ * view: 'p',
36
+ * model: 'paragraph'
37
+ * } );
38
+ *
39
+ * editor.conversion.for( 'upcast' ).elementToElement( {
40
+ * view: 'p',
41
+ * model: 'paragraph',
42
+ * converterPriority: 'high'
43
+ * } );
44
+ *
45
+ * editor.conversion.for( 'upcast' ).elementToElement( {
46
+ * view: {
47
+ * name: 'p',
48
+ * classes: 'fancy'
49
+ * },
50
+ * model: 'fancyParagraph'
51
+ * } );
52
+ *
53
+ * editor.conversion.for( 'upcast' ).elementToElement( {
54
+ * view: {
55
+ * name: 'p',
56
+ * classes: 'heading'
57
+ * },
58
+ * model: ( viewElement, conversionApi ) => {
59
+ * const modelWriter = conversionApi.writer;
60
+ *
61
+ * return modelWriter.createElement( 'heading', { level: viewElement.getAttribute( 'data-level' ) } );
62
+ * }
63
+ * } );
64
+ * ```
63
65
  *
64
66
  * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
65
67
  * to the conversion process.
66
68
  *
67
- * @method #elementToElement
68
- * @param {Object} config Conversion configuration.
69
- * @param {module:engine/view/matcher~MatcherPattern} [config.view] Pattern matching all view elements which should be converted. If not
70
- * set, the converter will fire for every view element.
71
- * @param {String|module:engine/model/element~Element|Function} config.model Name of the model element, a model element instance or a
72
- * function that takes a view element and {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API}
69
+ * @param config Conversion configuration.
70
+ * @param config.view Pattern matching all view elements which should be converted. If not set, the converter
71
+ * will fire for every view element.
72
+ * @param config.model Name of the model element, a model element instance or a function that takes a view element
73
+ * and {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API}
73
74
  * and returns a model element. The model element will be inserted in the model.
74
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
75
- * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
75
+ * @param config.converterPriority Converter priority.
76
76
  */
77
77
  elementToElement(config) {
78
78
  return this.add(upcastElementToElement(config));
@@ -85,7 +85,9 @@ export default class UpcastHelpers extends ConversionHelpers {
85
85
  *
86
86
  * This helper is meant to set a model attribute on all the elements that are inside the converted element:
87
87
  *
88
- * <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
88
+ * ```
89
+ * <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
90
+ * ```
89
91
  *
90
92
  * Above is a sample of HTML code, that goes through autoparagraphing (first step) and then is converted (second step).
91
93
  * Even though `<strong>` is over `<p>` element, `bold="true"` was added to the text. See
@@ -93,72 +95,72 @@ export default class UpcastHelpers extends ConversionHelpers {
93
95
  *
94
96
  * Keep in mind that the attribute will be set only if it is allowed by {@link module:engine/model/schema~Schema schema} configuration.
95
97
  *
96
- * editor.conversion.for( 'upcast' ).elementToAttribute( {
97
- * view: 'strong',
98
- * model: 'bold'
99
- * } );
100
- *
101
- * editor.conversion.for( 'upcast' ).elementToAttribute( {
102
- * view: 'strong',
103
- * model: 'bold',
104
- * converterPriority: 'high'
105
- * } );
106
- *
107
- * editor.conversion.for( 'upcast' ).elementToAttribute( {
108
- * view: {
109
- * name: 'span',
110
- * classes: 'bold'
111
- * },
112
- * model: 'bold'
113
- * } );
114
- *
115
- * editor.conversion.for( 'upcast' ).elementToAttribute( {
116
- * view: {
117
- * name: 'span',
118
- * classes: [ 'styled', 'styled-dark' ]
119
- * },
120
- * model: {
121
- * key: 'styled',
122
- * value: 'dark'
123
- * }
124
- * } );
125
- *
126
- * editor.conversion.for( 'upcast' ).elementToAttribute( {
127
- * view: {
128
- * name: 'span',
129
- * styles: {
130
- * 'font-size': /[\s\S]+/
131
- * }
132
- * },
133
- * model: {
134
- * key: 'fontSize',
135
- * value: ( viewElement, conversionApi ) => {
136
- * const fontSize = viewElement.getStyle( 'font-size' );
137
- * const value = fontSize.substr( 0, fontSize.length - 2 );
138
- *
139
- * if ( value <= 10 ) {
140
- * return 'small';
141
- * } else if ( value > 12 ) {
142
- * return 'big';
143
- * }
144
- *
145
- * return null;
146
- * }
147
- * }
148
- * } );
98
+ * ```ts
99
+ * editor.conversion.for( 'upcast' ).elementToAttribute( {
100
+ * view: 'strong',
101
+ * model: 'bold'
102
+ * } );
103
+ *
104
+ * editor.conversion.for( 'upcast' ).elementToAttribute( {
105
+ * view: 'strong',
106
+ * model: 'bold',
107
+ * converterPriority: 'high'
108
+ * } );
109
+ *
110
+ * editor.conversion.for( 'upcast' ).elementToAttribute( {
111
+ * view: {
112
+ * name: 'span',
113
+ * classes: 'bold'
114
+ * },
115
+ * model: 'bold'
116
+ * } );
117
+ *
118
+ * editor.conversion.for( 'upcast' ).elementToAttribute( {
119
+ * view: {
120
+ * name: 'span',
121
+ * classes: [ 'styled', 'styled-dark' ]
122
+ * },
123
+ * model: {
124
+ * key: 'styled',
125
+ * value: 'dark'
126
+ * }
127
+ * } );
128
+ *
129
+ * editor.conversion.for( 'upcast' ).elementToAttribute( {
130
+ * view: {
131
+ * name: 'span',
132
+ * styles: {
133
+ * 'font-size': /[\s\S]+/
134
+ * }
135
+ * },
136
+ * model: {
137
+ * key: 'fontSize',
138
+ * value: ( viewElement, conversionApi ) => {
139
+ * const fontSize = viewElement.getStyle( 'font-size' );
140
+ * const value = fontSize.substr( 0, fontSize.length - 2 );
141
+ *
142
+ * if ( value <= 10 ) {
143
+ * return 'small';
144
+ * } else if ( value > 12 ) {
145
+ * return 'big';
146
+ * }
147
+ *
148
+ * return null;
149
+ * }
150
+ * }
151
+ * } );
152
+ * ```
149
153
  *
150
154
  * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
151
155
  * to the conversion process.
152
156
  *
153
- * @method #elementToAttribute
154
- * @param {Object} config Conversion configuration.
155
- * @param {module:engine/view/matcher~MatcherPattern} config.view Pattern matching all view elements which should be converted.
156
- * @param {String|Object} config.model Model attribute key or an object with `key` and `value` properties, describing
157
+ * @param config Conversion configuration.
158
+ * @param config.view Pattern matching all view elements which should be converted.
159
+ * @param config.model Model attribute key or an object with `key` and `value` properties, describing
157
160
  * the model attribute. `value` property may be set as a function that takes a view element and
158
161
  * {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the value.
159
162
  * If `String` is given, the model attribute value will be set to `true`.
160
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='low'] Converter priority.
161
- * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
163
+ * @param config.converterPriority Converter priority. Defaults to `low`.
162
164
  */
163
165
  elementToAttribute(config) {
164
166
  return this.add(upcastElementToAttribute(config));
@@ -172,114 +174,120 @@ export default class UpcastHelpers extends ConversionHelpers {
172
174
  * This helper is meant to convert view attributes from view elements which got converted to the model, so the view attribute
173
175
  * is set only on the corresponding model node:
174
176
  *
175
- * <div class="dark"><div>foo</div></div> --> <div dark="true"><div>foo</div></div>
177
+ * ```
178
+ * <div class="dark"><div>foo</div></div> --> <div dark="true"><div>foo</div></div>
179
+ * ```
176
180
  *
177
181
  * Above, `class="dark"` attribute is added only to the `<div>` elements that has it. This is in contrary to
178
182
  * {@link module:engine/conversion/upcasthelpers~UpcastHelpers#elementToAttribute} which sets attributes for
179
183
  * all the children in the model:
180
184
  *
181
- * <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
185
+ * ```
186
+ * <strong>Foo</strong> --> <strong><p>Foo</p></strong> --> <paragraph><$text bold="true">Foo</$text></paragraph>
187
+ * ```
182
188
  *
183
189
  * Above is a sample of HTML code, that goes through autoparagraphing (first step) and then is converted (second step).
184
190
  * Even though `<strong>` is over `<p>` element, `bold="true"` was added to the text.
185
191
  *
186
192
  * Keep in mind that the attribute will be set only if it is allowed by {@link module:engine/model/schema~Schema schema} configuration.
187
193
  *
188
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
189
- * view: 'src',
190
- * model: 'source'
191
- * } );
192
- *
193
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
194
- * view: { key: 'src' },
195
- * model: 'source'
196
- * } );
197
- *
198
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
199
- * view: { key: 'src' },
200
- * model: 'source',
201
- * converterPriority: 'normal'
202
- * } );
203
- *
204
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
205
- * view: {
206
- * key: 'data-style',
207
- * value: /[\s\S]+/
208
- * },
209
- * model: 'styled'
210
- * } );
211
- *
212
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
213
- * view: {
214
- * name: 'img',
215
- * key: 'class',
216
- * value: 'styled-dark'
217
- * },
218
- * model: {
219
- * key: 'styled',
220
- * value: 'dark'
221
- * }
222
- * } );
223
- *
224
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
225
- * view: {
226
- * key: 'class',
227
- * value: /styled-[\S]+/
228
- * },
229
- * model: {
230
- * key: 'styled'
231
- * value: ( viewElement, conversionApi ) => {
232
- * const regexp = /styled-([\S]+)/;
233
- * const match = viewElement.getAttribute( 'class' ).match( regexp );
234
- *
235
- * return match[ 1 ];
236
- * }
237
- * }
238
- * } );
194
+ * ```ts
195
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
196
+ * view: 'src',
197
+ * model: 'source'
198
+ * } );
199
+ *
200
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
201
+ * view: { key: 'src' },
202
+ * model: 'source'
203
+ * } );
204
+ *
205
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
206
+ * view: { key: 'src' },
207
+ * model: 'source',
208
+ * converterPriority: 'normal'
209
+ * } );
210
+ *
211
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
212
+ * view: {
213
+ * key: 'data-style',
214
+ * value: /[\s\S]+/
215
+ * },
216
+ * model: 'styled'
217
+ * } );
218
+ *
219
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
220
+ * view: {
221
+ * name: 'img',
222
+ * key: 'class',
223
+ * value: 'styled-dark'
224
+ * },
225
+ * model: {
226
+ * key: 'styled',
227
+ * value: 'dark'
228
+ * }
229
+ * } );
230
+ *
231
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
232
+ * view: {
233
+ * key: 'class',
234
+ * value: /styled-[\S]+/
235
+ * },
236
+ * model: {
237
+ * key: 'styled'
238
+ * value: ( viewElement, conversionApi ) => {
239
+ * const regexp = /styled-([\S]+)/;
240
+ * const match = viewElement.getAttribute( 'class' ).match( regexp );
241
+ *
242
+ * return match[ 1 ];
243
+ * }
244
+ * }
245
+ * } );
246
+ * ```
239
247
  *
240
248
  * Converting styles works a bit differently as it requires `view.styles` to be an object and by default
241
249
  * a model attribute will be set to `true` by such a converter. You can set the model attribute to any value by providing the `value`
242
250
  * callback that returns the desired value.
243
251
  *
244
- * // Default conversion of font-weight style will result in setting bold attribute to true.
245
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
246
- * view: {
247
- * styles: {
248
- * 'font-weight': 'bold'
249
- * }
250
- * },
251
- * model: 'bold'
252
- * } );
253
- *
254
- * // This converter will pass any style value to the `lineHeight` model attribute.
255
- * editor.conversion.for( 'upcast' ).attributeToAttribute( {
256
- * view: {
257
- * styles: {
258
- * 'line-height': /[\s\S]+/
259
- * }
260
- * },
261
- * model: {
262
- * key: 'lineHeight',
263
- * value: ( viewElement, conversionApi ) => viewElement.getStyle( 'line-height' )
264
- * }
265
- * } );
252
+ * ```ts
253
+ * // Default conversion of font-weight style will result in setting bold attribute to true.
254
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
255
+ * view: {
256
+ * styles: {
257
+ * 'font-weight': 'bold'
258
+ * }
259
+ * },
260
+ * model: 'bold'
261
+ * } );
262
+ *
263
+ * // This converter will pass any style value to the `lineHeight` model attribute.
264
+ * editor.conversion.for( 'upcast' ).attributeToAttribute( {
265
+ * view: {
266
+ * styles: {
267
+ * 'line-height': /[\s\S]+/
268
+ * }
269
+ * },
270
+ * model: {
271
+ * key: 'lineHeight',
272
+ * value: ( viewElement, conversionApi ) => viewElement.getStyle( 'line-height' )
273
+ * }
274
+ * } );
275
+ * ```
266
276
  *
267
277
  * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
268
278
  * to the conversion process.
269
279
  *
270
- * @method #attributeToAttribute
271
- * @param {Object} config Conversion configuration.
272
- * @param {String|Object} config.view Specifies which view attribute will be converted. If a `String` is passed,
280
+ * @param config Conversion configuration.
281
+ * @param config.view Specifies which view attribute will be converted. If a `String` is passed,
273
282
  * attributes with given key will be converted. If an `Object` is passed, it must have a required `key` property,
274
283
  * specifying view attribute key, and may have an optional `value` property, specifying view attribute value and optional `name`
275
284
  * property specifying a view element name from/on which the attribute should be converted. `value` can be given as a `String`,
276
285
  * a `RegExp` or a function callback, that takes view attribute value as the only parameter and returns `Boolean`.
277
- * @param {String|Object} config.model Model attribute key or an object with `key` and `value` properties, describing
286
+ * @param config.model Model attribute key or an object with `key` and `value` properties, describing
278
287
  * the model attribute. `value` property may be set as a function that takes a view element and
279
288
  * {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the value.
280
289
  * If `String` is given, the model attribute value will be same as view attribute value.
281
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='low'] Converter priority.
282
- * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
290
+ * @param config.converterPriority Converter priority. Defaults to `low`.
283
291
  */
284
292
  attributeToAttribute(config) {
285
293
  return this.add(upcastAttributeToAttribute(config));
@@ -298,42 +306,42 @@ export default class UpcastHelpers extends ConversionHelpers {
298
306
  *
299
307
  * In most of the cases, the {@link #dataToMarker} should be used instead.
300
308
  *
301
- * editor.conversion.for( 'upcast' ).elementToMarker( {
302
- * view: 'marker-search',
303
- * model: 'search'
304
- * } );
305
- *
306
- * editor.conversion.for( 'upcast' ).elementToMarker( {
307
- * view: 'marker-search',
308
- * model: 'search',
309
- * converterPriority: 'high'
310
- * } );
311
- *
312
- * editor.conversion.for( 'upcast' ).elementToMarker( {
313
- * view: 'marker-search',
314
- * model: ( viewElement, conversionApi ) => 'comment:' + viewElement.getAttribute( 'data-comment-id' )
315
- * } );
316
- *
317
- * editor.conversion.for( 'upcast' ).elementToMarker( {
318
- * view: {
319
- * name: 'span',
320
- * attributes: {
321
- * 'data-marker': 'search'
322
- * }
323
- * },
324
- * model: 'search'
325
- * } );
309
+ * ```ts
310
+ * editor.conversion.for( 'upcast' ).elementToMarker( {
311
+ * view: 'marker-search',
312
+ * model: 'search'
313
+ * } );
314
+ *
315
+ * editor.conversion.for( 'upcast' ).elementToMarker( {
316
+ * view: 'marker-search',
317
+ * model: 'search',
318
+ * converterPriority: 'high'
319
+ * } );
320
+ *
321
+ * editor.conversion.for( 'upcast' ).elementToMarker( {
322
+ * view: 'marker-search',
323
+ * model: ( viewElement, conversionApi ) => 'comment:' + viewElement.getAttribute( 'data-comment-id' )
324
+ * } );
325
+ *
326
+ * editor.conversion.for( 'upcast' ).elementToMarker( {
327
+ * view: {
328
+ * name: 'span',
329
+ * attributes: {
330
+ * 'data-marker': 'search'
331
+ * }
332
+ * },
333
+ * model: 'search'
334
+ * } );
335
+ * ```
326
336
  *
327
337
  * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
328
338
  * to the conversion process.
329
339
  *
330
- * @method #elementToMarker
331
- * @param {Object} config Conversion configuration.
332
- * @param {module:engine/view/matcher~MatcherPattern} config.view Pattern matching all view elements which should be converted.
333
- * @param {String|Function} config.model Name of the model marker, or a function that takes a view element and returns
340
+ * @param config Conversion configuration.
341
+ * @param config.view Pattern matching all view elements which should be converted.
342
+ * @param config.model Name of the model marker, or a function that takes a view element and returns
334
343
  * a model marker name.
335
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
336
- * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
344
+ * @param config.converterPriority Converter priority.
337
345
  */
338
346
  elementToMarker(config) {
339
347
  return this.add(upcastElementToMarker(config));
@@ -358,52 +366,56 @@ export default class UpcastHelpers extends ConversionHelpers {
358
366
  *
359
367
  * Basic usage:
360
368
  *
361
- * // Using the default conversion.
362
- * // In this case, all markers from the `comment` group will be converted.
363
- * // The conversion will look for `<comment-start>` and `<comment-end>` tags and
364
- * // `data-comment-start-before`, `data-comment-start-after`,
365
- * // `data-comment-end-before` and `data-comment-end-after` attributes.
366
- * editor.conversion.for( 'upcast' ).dataToMarker( {
367
- * view: 'comment'
368
- * } );
369
+ * ```ts
370
+ * // Using the default conversion.
371
+ * // In this case, all markers from the `comment` group will be converted.
372
+ * // The conversion will look for `<comment-start>` and `<comment-end>` tags and
373
+ * // `data-comment-start-before`, `data-comment-start-after`,
374
+ * // `data-comment-end-before` and `data-comment-end-after` attributes.
375
+ * editor.conversion.for( 'upcast' ).dataToMarker( {
376
+ * view: 'comment'
377
+ * } );
378
+ * ```
369
379
  *
370
380
  * An example of a model that may be generated by this conversion:
371
381
  *
372
- * // View:
373
- * <p>Foo<comment-start name="commentId:uid"></comment-start>bar</p>
374
- * <figure data-comment-end-after="commentId:uid" class="image"><img src="abc.jpg" /></figure>
382
+ * ```
383
+ * // View:
384
+ * <p>Foo<comment-start name="commentId:uid"></comment-start>bar</p>
385
+ * <figure data-comment-end-after="commentId:uid" class="image"><img src="abc.jpg" /></figure>
375
386
  *
376
- * // Model:
377
- * <paragraph>Foo[bar</paragraph>
378
- * <imageBlock src="abc.jpg"></imageBlock>]
387
+ * // Model:
388
+ * <paragraph>Foo[bar</paragraph>
389
+ * <imageBlock src="abc.jpg"></imageBlock>]
390
+ * ```
379
391
  *
380
392
  * Where `[]` are boundaries of a marker that will receive the `comment:commentId:uid` name.
381
393
  *
382
394
  * Other examples of usage:
383
395
  *
384
- * // Using a custom function which is the same as the default conversion:
385
- * editor.conversion.for( 'upcast' ).dataToMarker( {
386
- * view: 'comment',
387
- * model: ( name, conversionApi ) => 'comment:' + name,
388
- * } );
389
- *
390
- * // Using the converter priority:
391
- * editor.conversion.for( 'upcast' ).dataToMarker( {
392
- * view: 'comment',
393
- * model: ( name, conversionApi ) => 'comment:' + name,
394
- * converterPriority: 'high'
395
- * } );
396
+ * ```ts
397
+ * // Using a custom function which is the same as the default conversion:
398
+ * editor.conversion.for( 'upcast' ).dataToMarker( {
399
+ * view: 'comment',
400
+ * model: ( name, conversionApi ) => 'comment:' + name,
401
+ * } );
402
+ *
403
+ * // Using the converter priority:
404
+ * editor.conversion.for( 'upcast' ).dataToMarker( {
405
+ * view: 'comment',
406
+ * model: ( name, conversionApi ) => 'comment:' + name,
407
+ * converterPriority: 'high'
408
+ * } );
409
+ * ```
396
410
  *
397
411
  * See {@link module:engine/conversion/conversion~Conversion#for `conversion.for()`} to learn how to add a converter
398
412
  * to the conversion process.
399
413
  *
400
- * @method #dataToMarker
401
- * @param {Object} config Conversion configuration.
402
- * @param {String} config.view The marker group name to convert.
403
- * @param {Function} [config.model] A function that takes the `name` part from the view element or attribute and
414
+ * @param config Conversion configuration.
415
+ * @param config.view The marker group name to convert.
416
+ * @param config.model A function that takes the `name` part from the view element or attribute and
404
417
  * {@link module:engine/conversion/upcastdispatcher~UpcastConversionApi upcast conversion API} and returns the marker name.
405
- * @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
406
- * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
418
+ * @param config.converterPriority Converter priority.
407
419
  */
408
420
  dataToMarker(config) {
409
421
  return this.add(upcastDataToMarker(config));
@@ -420,7 +432,7 @@ export default class UpcastHelpers extends ConversionHelpers {
420
432
  * When a view element is being converted to the model but it does not have converter specified, that view element
421
433
  * will be converted to {@link module:engine/model/documentfragment~DocumentFragment model document fragment} and returned.
422
434
  *
423
- * @returns {Function} Universal converter for view {@link module:engine/view/documentfragment~DocumentFragment fragments} and
435
+ * @returns Universal converter for view {@link module:engine/view/documentfragment~DocumentFragment fragments} and
424
436
  * {@link module:engine/view/element~Element elements} that returns
425
437
  * {@link module:engine/model/documentfragment~DocumentFragment model fragment} with children of converted view item.
426
438
  */
@@ -437,7 +449,7 @@ export function convertToModelFragment() {
437
449
  /**
438
450
  * Function factory, creates a converter that converts {@link module:engine/view/text~Text} to {@link module:engine/model/text~Text}.
439
451
  *
440
- * @returns {Function} {@link module:engine/view/text~Text View text} converter.
452
+ * @returns {@link module:engine/view/text~Text View text} converter.
441
453
  */
442
454
  export function convertText() {
443
455
  return (evt, data, { schema, consumable, writer }) => {
@@ -478,11 +490,13 @@ export function convertText() {
478
490
  * **Note**: because there is no view selection change dispatcher nor any other advanced view selection to model
479
491
  * conversion mechanism, the callback should be set directly on view document.
480
492
  *
481
- * view.document.on( 'selectionChange', convertSelectionChange( modelDocument, mapper ) );
493
+ * ```ts
494
+ * view.document.on( 'selectionChange', convertSelectionChange( modelDocument, mapper ) );
495
+ * ```
482
496
  *
483
- * @param {module:engine/model/model~Model} model Data model.
484
- * @param {module:engine/conversion/mapper~Mapper} mapper Conversion mapper.
485
- * @returns {Function} {@link module:engine/view/document~Document#event:selectionChange} callback function.
497
+ * @param model Data model.
498
+ * @param mapper Conversion mapper.
499
+ * @returns {@link module:engine/view/document~Document#event:selectionChange} callback function.
486
500
  */
487
501
  export function convertSelectionChange(model, mapper) {
488
502
  return (evt, data) => {
@@ -499,17 +513,19 @@ export function convertSelectionChange(model, mapper) {
499
513
  }
500
514
  };
501
515
  }
502
- // View element to model element conversion helper.
503
- //
504
- // See {@link ~UpcastHelpers#elementToElement `.elementToElement()` upcast helper} for examples.
505
- //
506
- // @param {Object} config Conversion configuration.
507
- // @param {module:engine/view/matcher~MatcherPattern} [config.view] Pattern matching all view elements which should be converted. If not
508
- // set, the converter will fire for every view element.
509
- // @param {String|module:engine/model/element~Element|Function} config.model Name of the model element, a model element
510
- // instance or a function that takes a view element and returns a model element. The model element will be inserted in the model.
511
- // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
512
- // @returns {Function} Conversion helper.
516
+ /**
517
+ * View element to model element conversion helper.
518
+ *
519
+ * See {@link ~UpcastHelpers#elementToElement `.elementToElement()` upcast helper} for examples.
520
+ *
521
+ * @param config Conversion configuration.
522
+ * @param config.view Pattern matching all view elements which should be converted. If not
523
+ * set, the converter will fire for every view element.
524
+ * @param config.model Name of the model element, a model element
525
+ * instance or a function that takes a view element and returns a model element. The model element will be inserted in the model.
526
+ * @param config.converterPriority Converter priority.
527
+ * @returns Conversion helper.
528
+ */
513
529
  function upcastElementToElement(config) {
514
530
  config = cloneDeep(config);
515
531
  const converter = prepareToElementConverter(config);
@@ -519,17 +535,19 @@ function upcastElementToElement(config) {
519
535
  dispatcher.on(eventName, converter, { priority: config.converterPriority || 'normal' });
520
536
  };
521
537
  }
522
- // View element to model attribute conversion helper.
523
- //
524
- // See {@link ~UpcastHelpers#elementToAttribute `.elementToAttribute()` upcast helper} for examples.
525
- //
526
- // @param {Object} config Conversion configuration.
527
- // @param {module:engine/view/matcher~MatcherPattern} config.view Pattern matching all view elements which should be converted.
528
- // @param {String|Object} config.model Model attribute key or an object with `key` and `value` properties, describing
529
- // the model attribute. `value` property may be set as a function that takes a view element and returns the value.
530
- // If `String` is given, the model attribute value will be set to `true`.
531
- // @param {module:utils/priorities~PriorityString} [config.converterPriority='low'] Converter priority.
532
- // @returns {Function} Conversion helper.
538
+ /**
539
+ * View element to model attribute conversion helper.
540
+ *
541
+ * See {@link ~UpcastHelpers#elementToAttribute `.elementToAttribute()` upcast helper} for examples.
542
+ *
543
+ * @param config Conversion configuration.
544
+ * @param config.view Pattern matching all view elements which should be converted.
545
+ * @param config.model Model attribute key or an object with `key` and `value` properties, describing
546
+ * the model attribute. `value` property may be set as a function that takes a view element and returns the value.
547
+ * If `String` is given, the model attribute value will be set to `true`.
548
+ * @param config.converterPriority Converter priority. Defaults to `low`.
549
+ * @returns Conversion helper.
550
+ */
533
551
  function upcastElementToAttribute(config) {
534
552
  config = cloneDeep(config);
535
553
  normalizeModelAttributeConfig(config);
@@ -540,21 +558,23 @@ function upcastElementToAttribute(config) {
540
558
  dispatcher.on(eventName, converter, { priority: config.converterPriority || 'low' });
541
559
  };
542
560
  }
543
- // View attribute to model attribute conversion helper.
544
- //
545
- // See {@link ~UpcastHelpers#attributeToAttribute `.attributeToAttribute()` upcast helper} for examples.
546
- //
547
- // @param {Object} config Conversion configuration.
548
- // @param {String|Object} config.view Specifies which view attribute will be converted. If a `String` is passed,
549
- // attributes with given key will be converted. If an `Object` is passed, it must have a required `key` property,
550
- // specifying view attribute key, and may have an optional `value` property, specifying view attribute value and optional `name`
551
- // property specifying a view element name from/on which the attribute should be converted. `value` can be given as a `String`,
552
- // a `RegExp` or a function callback, that takes view attribute value as the only parameter and returns `Boolean`.
553
- // @param {String|Object} config.model Model attribute key or an object with `key` and `value` properties, describing
554
- // the model attribute. `value` property may be set as a function that takes a view element and returns the value.
555
- // If `String` is given, the model attribute value will be same as view attribute value.
556
- // @param {module:utils/priorities~PriorityString} [config.converterPriority='low'] Converter priority.
557
- // @returns {Function} Conversion helper.
561
+ /**
562
+ * View attribute to model attribute conversion helper.
563
+ *
564
+ * See {@link ~UpcastHelpers#attributeToAttribute `.attributeToAttribute()` upcast helper} for examples.
565
+ *
566
+ * @param config Conversion configuration.
567
+ * @param config.view Specifies which view attribute will be converted. If a `String` is passed,
568
+ * attributes with given key will be converted. If an `Object` is passed, it must have a required `key` property,
569
+ * specifying view attribute key, and may have an optional `value` property, specifying view attribute value and optional `name`
570
+ * property specifying a view element name from/on which the attribute should be converted. `value` can be given as a `String`,
571
+ * a `RegExp` or a function callback, that takes view attribute value as the only parameter and returns `Boolean`.
572
+ * @param config.model Model attribute key or an object with `key` and `value` properties, describing
573
+ * the model attribute. `value` property may be set as a function that takes a view element and returns the value.
574
+ * If `String` is given, the model attribute value will be same as view attribute value.
575
+ * @param config.converterPriority Converter priority. Defaults to `low`.
576
+ * @returns Conversion helper.
577
+ */
558
578
  function upcastAttributeToAttribute(config) {
559
579
  config = cloneDeep(config);
560
580
  let viewKey = null;
@@ -567,29 +587,29 @@ function upcastAttributeToAttribute(config) {
567
587
  dispatcher.on('element', converter, { priority: config.converterPriority || 'low' });
568
588
  };
569
589
  }
570
- // View element to model marker conversion helper.
571
- //
572
- // See {@link ~UpcastHelpers#elementToMarker `.elementToMarker()` upcast helper} for examples.
573
- //
574
- // @param {Object} config Conversion configuration.
575
- // @param {module:engine/view/matcher~MatcherPattern} config.view Pattern matching all view elements which should be converted.
576
- // @param {String|Function} config.model Name of the model marker, or a function that takes a view element and returns
577
- // a model marker name.
578
- // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
579
- // @returns {Function} Conversion helper.
590
+ /**
591
+ * View element to model marker conversion helper.
592
+ *
593
+ * See {@link ~UpcastHelpers#elementToMarker `.elementToMarker()` upcast helper} for examples.
594
+ *
595
+ * @param config Conversion configuration.
596
+ * @param config.view Pattern matching all view elements which should be converted.
597
+ * @param config.model Name of the model marker, or a function that takes a view element and returns
598
+ * a model marker name.
599
+ * @param config.converterPriority Converter priority.
600
+ * @returns Conversion helper.
601
+ */
580
602
  function upcastElementToMarker(config) {
581
603
  const model = normalizeElementToMarkerModelConfig(config.model);
582
604
  return upcastElementToElement({ ...config, model });
583
605
  }
584
- // View data to model marker conversion helper.
585
- //
586
- // See {@link ~UpcastHelpers#dataToMarker} to learn more.
587
- //
588
- // @param {Object} config
589
- // @param {String} config.view
590
- // @param {Function} [config.model]
591
- // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal']
592
- // @returns {Function} Conversion helper.
606
+ /**
607
+ * View data to model marker conversion helper.
608
+ *
609
+ * See {@link ~UpcastHelpers#dataToMarker} to learn more.
610
+ *
611
+ * @returns Conversion helper.
612
+ */
593
613
  function upcastDataToMarker(config) {
594
614
  config = cloneDeep(config);
595
615
  // Default conversion.
@@ -625,16 +645,15 @@ function upcastDataToMarker(config) {
625
645
  dispatcher.on('element', upcastAttributeToMarker(normalizedConfig), { priority: basePriority + priorityFactor });
626
646
  };
627
647
  }
628
- // Function factory, returns a callback function which converts view attributes to a model marker.
629
- //
630
- // The converter looks for elements with `data-group-start-before`, `data-group-start-after`, `data-group-end-before`
631
- // and `data-group-end-after` attributes and inserts `$marker` model elements before/after those elements.
632
- // `group` part is specified in `config.view`.
633
- //
634
- // @param {Object} config
635
- // @param {String} config.view
636
- // @param {Function} [config.model]
637
- // @returns {Function} Marker converter.
648
+ /**
649
+ * Function factory, returns a callback function which converts view attributes to a model marker.
650
+ *
651
+ * The converter looks for elements with `data-group-start-before`, `data-group-start-after`, `data-group-end-before`
652
+ * and `data-group-end-after` attributes and inserts `$marker` model elements before/after those elements.
653
+ * `group` part is specified in `config.view`.
654
+ *
655
+ * @returns Marker converter.
656
+ */
638
657
  function upcastAttributeToMarker(config) {
639
658
  return (evt, data, conversionApi) => {
640
659
  const attrName = `data-${config.view}`;
@@ -681,11 +700,13 @@ function upcastAttributeToMarker(config) {
681
700
  }
682
701
  };
683
702
  }
684
- // Helper function for from-view-element conversion. Checks if `config.view` directly specifies converted view element's name
685
- // and if so, returns it.
686
- //
687
- // @param {Object} config Conversion view config.
688
- // @returns {String|null} View element name or `null` if name is not directly set.
703
+ /**
704
+ * Helper function for from-view-element conversion. Checks if `config.view` directly specifies converted view element's name
705
+ * and if so, returns it.
706
+ *
707
+ * @param config Conversion view config.
708
+ * @returns View element name or `null` if name is not directly set.
709
+ */
689
710
  function getViewElementNameFromConfig(viewConfig) {
690
711
  if (typeof viewConfig == 'string') {
691
712
  return viewConfig;
@@ -695,10 +716,12 @@ function getViewElementNameFromConfig(viewConfig) {
695
716
  }
696
717
  return null;
697
718
  }
698
- // Helper for to-model-element conversion. Takes a config object and returns a proper converter function.
699
- //
700
- // @param {Object} config Conversion configuration.
701
- // @returns {Function} View to model converter.
719
+ /**
720
+ * Helper for to-model-element conversion. Takes a config object and returns a proper converter function.
721
+ *
722
+ * @param config Conversion configuration.
723
+ * @returns View to model converter.
724
+ */
702
725
  function prepareToElementConverter(config) {
703
726
  const matcher = new Matcher(config.view);
704
727
  return (evt, data, conversionApi) => {
@@ -724,12 +747,14 @@ function prepareToElementConverter(config) {
724
747
  conversionApi.updateConversionResult(modelElement, data);
725
748
  };
726
749
  }
727
- // Helper function for upcasting-to-element converter. Takes the model configuration, the converted view element
728
- // and a writer instance and returns a model element instance to be inserted in the model.
729
- //
730
- // @param {String|Function|module:engine/model/element~Element} model Model conversion configuration.
731
- // @param {module:engine/view/node~Node} input The converted view node.
732
- // @param {module:engine/conversion/upcastdispatcher~UpcastConversionApi} conversionApi The upcast conversion API.
750
+ /**
751
+ * Helper function for upcasting-to-element converter. Takes the model configuration, the converted view element
752
+ * and a writer instance and returns a model element instance to be inserted in the model.
753
+ *
754
+ * @param model Model conversion configuration.
755
+ * @param input The converted view node.
756
+ * @param conversionApi The upcast conversion API.
757
+ */
733
758
  function getModelElement(model, input, conversionApi) {
734
759
  if (model instanceof Function) {
735
760
  return model(input, conversionApi);
@@ -738,12 +763,14 @@ function getModelElement(model, input, conversionApi) {
738
763
  return conversionApi.writer.createElement(model);
739
764
  }
740
765
  }
741
- // Helper function view-attribute-to-model-attribute helper. Normalizes `config.view` which was set as `String` or
742
- // as an `Object` with `key`, `value` and `name` properties. Normalized `config.view` has is compatible with
743
- // {@link module:engine/view/matcher~MatcherPattern}.
744
- //
745
- // @param {Object} config Conversion config.
746
- // @returns {String} Key of the converted view attribute.
766
+ /**
767
+ * Helper function view-attribute-to-model-attribute helper. Normalizes `config.view` which was set as `String` or
768
+ * as an `Object` with `key`, `value` and `name` properties. Normalized `config.view` has is compatible with
769
+ * {@link module:engine/view/matcher~MatcherPattern}.
770
+ *
771
+ * @param config Conversion config.
772
+ * @returns Key of the converted view attribute.
773
+ */
747
774
  function normalizeViewAttributeKeyValueConfig(config) {
748
775
  if (typeof config.view == 'string') {
749
776
  config.view = { key: config.view };
@@ -770,13 +797,15 @@ function normalizeViewAttributeKeyValueConfig(config) {
770
797
  config.view = normalized;
771
798
  return key;
772
799
  }
773
- // Helper function that normalizes `config.model` in from-model-attribute conversion. `config.model` can be set
774
- // as a `String`, an `Object` with only `key` property or an `Object` with `key` and `value` properties. Normalized
775
- // `config.model` is an `Object` with `key` and `value` properties.
776
- //
777
- // @param {Object} config Conversion config.
778
- // @param {String} viewAttributeKeyToCopy Key of the converted view attribute. If it is set, model attribute value
779
- // will be equal to view attribute value.
800
+ /**
801
+ * Helper function that normalizes `config.model` in from-model-attribute conversion. `config.model` can be set
802
+ * as a `String`, an `Object` with only `key` property or an `Object` with `key` and `value` properties. Normalized
803
+ * `config.model` is an `Object` with `key` and `value` properties.
804
+ *
805
+ * @param config Conversion config.
806
+ * @param viewAttributeKeyToCopy Key of the converted view attribute. If it is set, model attribute value
807
+ * will be equal to view attribute value.
808
+ */
780
809
  function normalizeModelAttributeConfig(config, viewAttributeKeyToCopy = null) {
781
810
  const defaultModelValue = viewAttributeKeyToCopy === null ? true :
782
811
  (viewElement) => viewElement.getAttribute(viewAttributeKeyToCopy);
@@ -784,13 +813,14 @@ function normalizeModelAttributeConfig(config, viewAttributeKeyToCopy = null) {
784
813
  const value = typeof config.model != 'object' || typeof config.model.value == 'undefined' ? defaultModelValue : config.model.value;
785
814
  config.model = { key, value };
786
815
  }
787
- // Helper for to-model-attribute conversion. Takes the model attribute name and conversion configuration and returns
788
- // a proper converter function.
789
- //
790
- // @param {String} modelAttributeKey The key of the model attribute to set on a model node.
791
- // @param {Object|Array.<Object>} config Conversion configuration. It is possible to provide multiple configurations in an array.
792
- // @param {Boolean} shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
793
- // on all elements in the range.
816
+ /**
817
+ * Helper for to-model-attribute conversion. Takes the model attribute name and conversion configuration and returns
818
+ * a proper converter function.
819
+ *
820
+ * @param config Conversion configuration. It is possible to provide multiple configurations in an array.
821
+ * @param shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
822
+ * on all elements in the range.
823
+ */
794
824
  function prepareToAttributeConverter(config, shallow) {
795
825
  const matcher = new Matcher(config.view);
796
826
  return (evt, data, conversionApi) => {
@@ -847,10 +877,11 @@ function prepareToAttributeConverter(config, shallow) {
847
877
  }
848
878
  };
849
879
  }
850
- // Helper function that checks if element name should be consumed in attribute converters.
851
- //
852
- // @param {Object} config Conversion view config.
853
- // @returns {Boolean}
880
+ /**
881
+ * Helper function that checks if element name should be consumed in attribute converters.
882
+ *
883
+ * @param viewConfig Conversion view config.
884
+ */
854
885
  function onlyViewNameIsDefined(viewConfig, viewItem) {
855
886
  // https://github.com/ckeditor/ckeditor5-engine/issues/1786
856
887
  const configToTest = typeof viewConfig == 'function' ? viewConfig(viewItem) : viewConfig;
@@ -859,17 +890,19 @@ function onlyViewNameIsDefined(viewConfig, viewItem) {
859
890
  }
860
891
  return !configToTest.classes && !configToTest.attributes && !configToTest.styles;
861
892
  }
862
- // Helper function for to-model-attribute converter. Sets model attribute on given range. Checks {@link module:engine/model/schema~Schema}
863
- // to ensure proper model structure.
864
- //
865
- // If any node on the given range has already defined an attribute with the same name, its value will not be updated.
866
- //
867
- // @param {module:engine/model/range~Range} modelRange Model range on which attribute should be set.
868
- // @param {Object} modelAttribute Model attribute to set.
869
- // @param {module:engine/conversion/upcastdispatcher~UpcastConversionApi} conversionApi Conversion API.
870
- // @param {Boolean} shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
871
- // on all elements in the range.
872
- // @returns {Boolean} `true` if attribute was set on at least one node from given `modelRange`.
893
+ /**
894
+ * Helper function for to-model-attribute converter. Sets model attribute on given range. Checks {@link module:engine/model/schema~Schema}
895
+ * to ensure proper model structure.
896
+ *
897
+ * If any node on the given range has already defined an attribute with the same name, its value will not be updated.
898
+ *
899
+ * @param modelRange Model range on which attribute should be set.
900
+ * @param modelAttribute Model attribute to set.
901
+ * @param conversionApi Conversion API.
902
+ * @param shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
903
+ * on all elements in the range.
904
+ * @returns `true` if attribute was set on at least one node from given `modelRange`.
905
+ */
873
906
  function setAttributeOn(modelRange, modelAttribute, shallow, conversionApi) {
874
907
  let result = false;
875
908
  // Set attribute on each item in range according to Schema.
@@ -889,20 +922,20 @@ function setAttributeOn(modelRange, modelAttribute, shallow, conversionApi) {
889
922
  }
890
923
  return result;
891
924
  }
892
- // Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastElementToMarker()`
893
- // function and converts it to a format that is supported by `upcastElementToElement()` function.
894
- //
895
- // @param {Object} config Conversion configuration.
925
+ /**
926
+ * Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastElementToMarker()`
927
+ * function and converts it to a format that is supported by `upcastElementToElement()` function.
928
+ */
896
929
  function normalizeElementToMarkerModelConfig(model) {
897
930
  return (viewElement, conversionApi) => {
898
931
  const markerName = typeof model == 'string' ? model : model(viewElement, conversionApi);
899
932
  return conversionApi.writer.createElement('$marker', { 'data-name': markerName });
900
933
  };
901
934
  }
902
- // Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastDataToMarker()`
903
- // function and converts it to a format that is supported by `upcastElementToElement()` function.
904
- //
905
- // @param {Object} config Conversion configuration.
935
+ /**
936
+ * Helper function for upcasting-to-marker conversion. Takes the config in a format requested by `upcastDataToMarker()`
937
+ * function and converts it to a format that is supported by `upcastElementToElement()` function.
938
+ */
906
939
  function normalizeDataToMarkerConfig(config, type) {
907
940
  const elementCreatorFunction = (viewElement, conversionApi) => {
908
941
  const viewName = viewElement.getAttribute('name');