@ckeditor/ckeditor5-engine 36.0.0 → 37.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -23
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +62 -109
  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 +499 -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 +177 -0
  24. package/src/conversion/viewconsumable.js +157 -162
  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 +105 -0
  42. package/src/index.js +1 -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 +245 -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 +812 -0
  57. package/src/model/model.js +59 -30
  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/moveoperation.d.ts +91 -0
  66. package/src/model/operation/nooperation.d.ts +33 -0
  67. package/src/model/operation/operation.d.ts +89 -0
  68. package/src/model/operation/operationfactory.d.ts +18 -0
  69. package/src/model/operation/renameoperation.d.ts +78 -0
  70. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  71. package/src/model/operation/rootattributeoperation.js +1 -1
  72. package/src/model/operation/splitoperation.d.ts +104 -0
  73. package/src/model/operation/transform.d.ts +100 -0
  74. package/src/model/operation/utils.d.ts +71 -0
  75. package/src/model/position.d.ts +539 -0
  76. package/src/model/position.js +1 -1
  77. package/src/model/range.d.ts +458 -0
  78. package/src/model/range.js +1 -1
  79. package/src/model/rootelement.d.ts +40 -0
  80. package/src/model/schema.d.ts +1176 -0
  81. package/src/model/schema.js +15 -15
  82. package/src/model/selection.d.ts +472 -0
  83. package/src/model/text.d.ts +66 -0
  84. package/src/model/text.js +0 -2
  85. package/src/model/textproxy.d.ts +144 -0
  86. package/src/model/treewalker.d.ts +186 -0
  87. package/src/model/treewalker.js +19 -10
  88. package/src/model/typecheckable.d.ts +255 -0
  89. package/src/model/utils/autoparagraphing.d.ts +37 -0
  90. package/src/model/utils/deletecontent.d.ts +58 -0
  91. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  92. package/src/model/utils/getselectedcontent.d.ts +30 -0
  93. package/src/model/utils/insertcontent.d.ts +46 -0
  94. package/src/model/utils/insertcontent.js +2 -12
  95. package/src/model/utils/insertobject.d.ts +44 -0
  96. package/src/model/utils/insertobject.js +3 -14
  97. package/src/model/utils/modifyselection.d.ts +48 -0
  98. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  99. package/src/model/writer.d.ts +726 -0
  100. package/src/model/writer.js +6 -4
  101. package/src/view/attributeelement.d.ts +108 -0
  102. package/src/view/attributeelement.js +25 -69
  103. package/src/view/containerelement.d.ts +49 -0
  104. package/src/view/containerelement.js +10 -43
  105. package/src/view/datatransfer.d.ts +75 -0
  106. package/src/view/datatransfer.js +24 -27
  107. package/src/view/document.d.ts +184 -0
  108. package/src/view/document.js +15 -84
  109. package/src/view/documentfragment.d.ts +150 -0
  110. package/src/view/documentfragment.js +40 -81
  111. package/src/view/documentselection.d.ts +219 -0
  112. package/src/view/documentselection.js +75 -121
  113. package/src/view/domconverter.d.ts +620 -0
  114. package/src/view/domconverter.js +159 -276
  115. package/src/view/downcastwriter.d.ts +804 -0
  116. package/src/view/downcastwriter.js +336 -380
  117. package/src/view/editableelement.d.ts +52 -0
  118. package/src/view/editableelement.js +9 -49
  119. package/src/view/element.d.ts +466 -0
  120. package/src/view/element.js +150 -222
  121. package/src/view/elementdefinition.d.ts +87 -0
  122. package/src/view/emptyelement.d.ts +41 -0
  123. package/src/view/emptyelement.js +11 -44
  124. package/src/view/filler.d.ts +111 -0
  125. package/src/view/filler.js +24 -21
  126. package/src/view/item.d.ts +14 -0
  127. package/src/view/matcher.d.ts +486 -0
  128. package/src/view/matcher.js +247 -218
  129. package/src/view/node.d.ts +160 -0
  130. package/src/view/node.js +26 -100
  131. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  132. package/src/view/observer/arrowkeysobserver.js +0 -13
  133. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  134. package/src/view/observer/bubblingemittermixin.js +36 -25
  135. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  136. package/src/view/observer/bubblingeventinfo.js +3 -29
  137. package/src/view/observer/clickobserver.d.ts +43 -0
  138. package/src/view/observer/clickobserver.js +9 -19
  139. package/src/view/observer/compositionobserver.d.ts +82 -0
  140. package/src/view/observer/compositionobserver.js +13 -42
  141. package/src/view/observer/domeventdata.d.ts +50 -0
  142. package/src/view/observer/domeventdata.js +5 -30
  143. package/src/view/observer/domeventobserver.d.ts +69 -0
  144. package/src/view/observer/domeventobserver.js +19 -21
  145. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  146. package/src/view/observer/fakeselectionobserver.js +2 -15
  147. package/src/view/observer/focusobserver.d.ts +82 -0
  148. package/src/view/observer/focusobserver.js +14 -40
  149. package/src/view/observer/inputobserver.d.ts +86 -0
  150. package/src/view/observer/inputobserver.js +18 -64
  151. package/src/view/observer/keyobserver.d.ts +67 -0
  152. package/src/view/observer/keyobserver.js +8 -42
  153. package/src/view/observer/mouseobserver.d.ts +89 -0
  154. package/src/view/observer/mouseobserver.js +8 -28
  155. package/src/view/observer/mutationobserver.d.ts +82 -0
  156. package/src/view/observer/mutationobserver.js +7 -37
  157. package/src/view/observer/observer.d.ts +84 -0
  158. package/src/view/observer/observer.js +12 -25
  159. package/src/view/observer/selectionobserver.d.ts +143 -0
  160. package/src/view/observer/selectionobserver.js +9 -99
  161. package/src/view/observer/tabobserver.d.ts +42 -0
  162. package/src/view/observer/tabobserver.js +0 -14
  163. package/src/view/placeholder.d.ts +85 -0
  164. package/src/view/placeholder.js +26 -43
  165. package/src/view/position.d.ts +189 -0
  166. package/src/view/position.js +36 -83
  167. package/src/view/range.d.ts +279 -0
  168. package/src/view/range.js +79 -122
  169. package/src/view/rawelement.d.ts +73 -0
  170. package/src/view/rawelement.js +34 -48
  171. package/src/view/renderer.d.ts +265 -0
  172. package/src/view/renderer.js +105 -193
  173. package/src/view/rooteditableelement.d.ts +41 -0
  174. package/src/view/rooteditableelement.js +12 -40
  175. package/src/view/selection.d.ts +375 -0
  176. package/src/view/selection.js +79 -153
  177. package/src/view/styles/background.d.ts +33 -0
  178. package/src/view/styles/background.js +14 -12
  179. package/src/view/styles/border.d.ts +43 -0
  180. package/src/view/styles/border.js +58 -48
  181. package/src/view/styles/margin.d.ts +29 -0
  182. package/src/view/styles/margin.js +13 -11
  183. package/src/view/styles/padding.d.ts +29 -0
  184. package/src/view/styles/padding.js +13 -11
  185. package/src/view/styles/utils.d.ts +93 -0
  186. package/src/view/styles/utils.js +22 -48
  187. package/src/view/stylesmap.d.ts +675 -0
  188. package/src/view/stylesmap.js +249 -244
  189. package/src/view/text.d.ts +74 -0
  190. package/src/view/text.js +16 -46
  191. package/src/view/textproxy.d.ts +97 -0
  192. package/src/view/textproxy.js +10 -59
  193. package/src/view/treewalker.d.ts +195 -0
  194. package/src/view/treewalker.js +43 -106
  195. package/src/view/typecheckable.d.ts +401 -0
  196. package/src/view/uielement.d.ts +96 -0
  197. package/src/view/uielement.js +28 -62
  198. package/src/view/upcastwriter.d.ts +328 -0
  199. package/src/view/upcastwriter.js +124 -134
  200. package/src/view/view.d.ts +327 -0
  201. package/src/view/view.js +79 -150
@@ -12,53 +12,41 @@ export default class Matcher {
12
12
  /**
13
13
  * Creates new instance of Matcher.
14
14
  *
15
- * @param {String|RegExp|Object|Function} [pattern] Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for
16
- * more information.
15
+ * @param pattern Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for more information.
17
16
  */
18
17
  constructor(...pattern) {
19
- /**
20
- * @private
21
- * @type {Array<Object|Function>}
22
- */
23
18
  this._patterns = [];
24
19
  this.add(...pattern);
25
20
  }
26
21
  /**
27
22
  * Adds pattern or patterns to matcher instance.
28
23
  *
29
- * // String.
30
- * matcher.add( 'div' );
24
+ * ```ts
25
+ * // String.
26
+ * matcher.add( 'div' );
31
27
  *
32
- * // Regular expression.
33
- * matcher.add( /^\w/ );
28
+ * // Regular expression.
29
+ * matcher.add( /^\w/ );
34
30
  *
35
- * // Single class.
36
- * matcher.add( {
37
- * classes: 'foobar'
38
- * } );
31
+ * // Single class.
32
+ * matcher.add( {
33
+ * classes: 'foobar'
34
+ * } );
35
+ * ```
39
36
  *
40
37
  * See {@link module:engine/view/matcher~MatcherPattern} for more examples.
41
38
  *
42
39
  * Multiple patterns can be added in one call:
43
40
  *
44
- * matcher.add( 'div', { classes: 'foobar' } );
41
+ * ```ts
42
+ * matcher.add( 'div', { classes: 'foobar' } );
43
+ * ```
45
44
  *
46
- * @param {Object|String|RegExp|Function} pattern Object describing pattern details. If string or regular expression
45
+ * @param pattern Object describing pattern details. If string or regular expression
47
46
  * is provided it will be used to match element's name. Pattern can be also provided in a form
48
47
  * of a function - then this function will be called with each {@link module:engine/view/element~Element element} as a parameter.
49
48
  * Function's return value will be stored under `match` key of the object returned from
50
49
  * {@link module:engine/view/matcher~Matcher#match match} or {@link module:engine/view/matcher~Matcher#matchAll matchAll} methods.
51
- * @param {String|RegExp} [pattern.name] Name or regular expression to match element's name.
52
- * @param {Object} [pattern.attributes] Object with key-value pairs representing attributes to match. Each object key
53
- * represents attribute name. Value under that key can be either:
54
- * * `true` - then attribute is just required (can be empty),
55
- * * a string - then attribute has to be equal, or
56
- * * a regular expression - then attribute has to match the expression.
57
- * @param {String|RegExp|Array} [pattern.classes] Class name or array of class names to match. Each name can be
58
- * provided in a form of string or regular expression.
59
- * @param {Object} [pattern.styles] Object with key-value pairs representing styles to match. Each object key
60
- * represents style name. Value under that key can be either a string or a regular expression and it will be used
61
- * to match style value.
62
50
  */
63
51
  add(...pattern) {
64
52
  for (let item of pattern) {
@@ -75,28 +63,22 @@ export default class Matcher {
75
63
  *
76
64
  * Example of returned object:
77
65
  *
78
- * {
79
- * element: <instance of found element>,
80
- * pattern: <pattern used to match found element>,
81
- * match: {
82
- * name: true,
83
- * attributes: [ 'title', 'href' ],
84
- * classes: [ 'foo' ],
85
- * styles: [ 'color', 'position' ]
86
- * }
87
- * }
66
+ * ```ts
67
+ * {
68
+ * element: <instance of found element>,
69
+ * pattern: <pattern used to match found element>,
70
+ * match: {
71
+ * name: true,
72
+ * attributes: [ 'title', 'href' ],
73
+ * classes: [ 'foo' ],
74
+ * styles: [ 'color', 'position' ]
75
+ * }
76
+ * }
77
+ * ```
88
78
  *
89
79
  * @see module:engine/view/matcher~Matcher#add
90
80
  * @see module:engine/view/matcher~Matcher#matchAll
91
- * @param {...module:engine/view/element~Element} element View element to match against stored patterns.
92
- * @returns {Object|null} result
93
- * @returns {module:engine/view/element~Element} result.element Matched view element.
94
- * @returns {Object|String|RegExp|Function} result.pattern Pattern that was used to find matched element.
95
- * @returns {Object} result.match Object representing matched element parts.
96
- * @returns {Boolean} [result.match.name] True if name of the element was matched.
97
- * @returns {Array} [result.match.attributes] Array with matched attribute names.
98
- * @returns {Array} [result.match.classes] Array with matched class names.
99
- * @returns {Array} [result.match.styles] Array with matched style names.
81
+ * @param element View element to match against stored patterns.
100
82
  */
101
83
  match(...element) {
102
84
  for (const singleElement of element) {
@@ -119,8 +101,8 @@ export default class Matcher {
119
101
  *
120
102
  * @see module:engine/view/matcher~Matcher#add
121
103
  * @see module:engine/view/matcher~Matcher#match
122
- * @param {...module:engine/view/element~Element} element View element to match against stored patterns.
123
- * @returns {Array.<Object>|null} Array with match information about found elements or `null`. For more information
104
+ * @param element View element to match against stored patterns.
105
+ * @returns Array with match information about found elements or `null`. For more information
124
106
  * see {@link module:engine/view/matcher~Matcher#match match method} description.
125
107
  */
126
108
  matchAll(...element) {
@@ -143,7 +125,7 @@ export default class Matcher {
143
125
  * Returns the name of the element to match if there is exactly one pattern added to the matcher instance
144
126
  * and it matches element name defined by `string` (not `RegExp`). Otherwise, returns `null`.
145
127
  *
146
- * @returns {String|null} Element name trying to match.
128
+ * @returns Element name trying to match.
147
129
  */
148
130
  getElementName() {
149
131
  if (this._patterns.length !== 1) {
@@ -154,12 +136,12 @@ export default class Matcher {
154
136
  return (typeof pattern != 'function' && name && !(name instanceof RegExp)) ? name : null;
155
137
  }
156
138
  }
157
- // Returns match information if {@link module:engine/view/element~Element element} is matching provided pattern.
158
- // If element cannot be matched to provided pattern - returns `null`.
159
- //
160
- // @param {module:engine/view/element~Element} element
161
- // @param {Object|String|RegExp|Function} pattern
162
- // @returns {Object|null} Returns object with match information or null if element is not matching.
139
+ /**
140
+ * Returns match information if {@link module:engine/view/element~Element element} is matching provided pattern.
141
+ * If element cannot be matched to provided pattern - returns `null`.
142
+ *
143
+ * @returns Returns object with match information or null if element is not matching.
144
+ */
163
145
  function isElementMatching(element, pattern) {
164
146
  // If pattern is provided as function - return result of that function;
165
147
  if (typeof pattern == 'function') {
@@ -196,11 +178,11 @@ function isElementMatching(element, pattern) {
196
178
  }
197
179
  return match;
198
180
  }
199
- // Checks if name can be matched by provided pattern.
200
- //
201
- // @param {String|RegExp} pattern
202
- // @param {String} name
203
- // @returns {Boolean} Returns `true` if name can be matched, `false` otherwise.
181
+ /**
182
+ * Checks if name can be matched by provided pattern.
183
+ *
184
+ * @returns Returns `true` if name can be matched, `false` otherwise.
185
+ */
204
186
  function matchName(pattern, name) {
205
187
  // If pattern is provided as RegExp - test against this regexp.
206
188
  if (pattern instanceof RegExp) {
@@ -208,56 +190,72 @@ function matchName(pattern, name) {
208
190
  }
209
191
  return pattern === name;
210
192
  }
211
- // Checks if an array of key/value pairs can be matched against provided patterns.
212
- //
213
- // Patterns can be provided in a following ways:
214
- // - a boolean value matches any attribute with any value (or no value):
215
- //
216
- // pattern: true
217
- //
218
- // - a RegExp expression or object matches any attribute name:
219
- //
220
- // pattern: /h[1-6]/
221
- //
222
- // - an object matches any attribute that has the same name as the object item's key, where object item's value is:
223
- // - equal to `true`, which matches any attribute value:
224
- //
225
- // pattern: {
226
- // required: true
227
- // }
228
- //
229
- // - a string that is equal to attribute value:
230
- //
231
- // pattern: {
232
- // rel: 'nofollow'
233
- // }
234
- //
235
- // - a regular expression that matches attribute value,
236
- //
237
- // pattern: {
238
- // src: /https.*/
239
- // }
240
- //
241
- // - an array with items, where the item is:
242
- // - a string that is equal to attribute value:
243
- //
244
- // pattern: [ 'data-property-1', 'data-property-2' ],
245
- //
246
- // - an object with `key` and `value` property, where `key` is a regular expression matching attribute name and
247
- // `value` is either regular expression matching attribute value or a string equal to attribute value:
248
- //
249
- // pattern: [
250
- // { key: /data-property-.*/, value: true },
251
- // // or:
252
- // { key: /data-property-.*/, value: 'foobar' },
253
- // // or:
254
- // { key: /data-property-.*/, value: /foo.*/ }
255
- // ]
256
- //
257
- // @param {Object} patterns Object with information about attributes to match.
258
- // @param {Iterable.<String>} keys Attribute, style or class keys.
259
- // @param {Function} valueGetter A function providing value for a given item key.
260
- // @returns {Array|null} Returns array with matched attribute names or `null` if no attributes were matched.
193
+ /**
194
+ * Checks if an array of key/value pairs can be matched against provided patterns.
195
+ *
196
+ * Patterns can be provided in a following ways:
197
+ * - a boolean value matches any attribute with any value (or no value):
198
+ *
199
+ * ```ts
200
+ * pattern: true
201
+ * ```
202
+ *
203
+ * - a RegExp expression or object matches any attribute name:
204
+ *
205
+ * ```ts
206
+ * pattern: /h[1-6]/
207
+ * ```
208
+ *
209
+ * - an object matches any attribute that has the same name as the object item's key, where object item's value is:
210
+ * - equal to `true`, which matches any attribute value:
211
+ *
212
+ * ```ts
213
+ * pattern: {
214
+ * required: true
215
+ * }
216
+ * ```
217
+ *
218
+ * - a string that is equal to attribute value:
219
+ *
220
+ * ```ts
221
+ * pattern: {
222
+ * rel: 'nofollow'
223
+ * }
224
+ * ```
225
+ *
226
+ * - a regular expression that matches attribute value,
227
+ *
228
+ * ```ts
229
+ * pattern: {
230
+ * src: /^https/
231
+ * }
232
+ * ```
233
+ *
234
+ * - an array with items, where the item is:
235
+ * - a string that is equal to attribute value:
236
+ *
237
+ * ```ts
238
+ * pattern: [ 'data-property-1', 'data-property-2' ],
239
+ * ```
240
+ *
241
+ * - an object with `key` and `value` property, where `key` is a regular expression matching attribute name and
242
+ * `value` is either regular expression matching attribute value or a string equal to attribute value:
243
+ *
244
+ * ```ts
245
+ * pattern: [
246
+ * { key: /^data-property-/, value: true },
247
+ * // or:
248
+ * { key: /^data-property-/, value: 'foobar' },
249
+ * // or:
250
+ * { key: /^data-property-/, value: /^foo/ }
251
+ * ]
252
+ * ```
253
+ *
254
+ * @param patterns Object with information about attributes to match.
255
+ * @param keys Attribute, style or class keys.
256
+ * @param valueGetter A function providing value for a given item key.
257
+ * @returns Returns array with matched attribute names or `null` if no attributes were matched.
258
+ */
261
259
  function matchPatterns(patterns, keys, valueGetter) {
262
260
  const normalizedPatterns = normalizePatterns(patterns);
263
261
  const normalizedItems = Array.from(keys);
@@ -277,53 +275,72 @@ function matchPatterns(patterns, keys, valueGetter) {
277
275
  }
278
276
  return match;
279
277
  }
280
- // Bring all the possible pattern forms to an array of arrays where first item is a key and second is a value.
281
- //
282
- // Examples:
283
- //
284
- // Boolean pattern value:
285
- //
286
- // true
287
- //
288
- // to
289
- //
290
- // [ [ true, true ] ]
291
- //
292
- // Textual pattern value:
293
- //
294
- // 'attribute-name-or-class-or-style'
295
- //
296
- // to
297
- //
298
- // [ [ 'attribute-name-or-class-or-style', true ] ]
299
- //
300
- // Regular expression:
301
- //
302
- // /^data-.*$/
303
- //
304
- // to
305
- //
306
- // [ [ /^data-.*$/, true ] ]
307
- //
308
- // Objects (plain or with `key` and `value` specified explicitly):
309
- //
310
- // {
311
- // src: /^https:.*$/
312
- // }
313
- //
314
- // or
315
- //
316
- // [ {
317
- // key: 'src',
318
- // value: /^https:.*$/
319
- // } ]
320
- //
321
- // to:
322
- //
323
- // [ [ 'src', /^https:.*$/ ] ]
324
- //
325
- // @param {Object|Array} patterns
326
- // @returns {Array|null} Returns an array of objects or null if provided patterns were not in an expected form.
278
+ /**
279
+ * Bring all the possible pattern forms to an array of arrays where first item is a key and second is a value.
280
+ *
281
+ * Examples:
282
+ *
283
+ * Boolean pattern value:
284
+ *
285
+ * ```ts
286
+ * true
287
+ * ```
288
+ *
289
+ * to
290
+ *
291
+ * ```ts
292
+ * [ [ true, true ] ]
293
+ * ```
294
+ *
295
+ * Textual pattern value:
296
+ *
297
+ * ```ts
298
+ * 'attribute-name-or-class-or-style'
299
+ * ```
300
+ *
301
+ * to
302
+ *
303
+ * ```ts
304
+ * [ [ 'attribute-name-or-class-or-style', true ] ]
305
+ * ```
306
+ *
307
+ * Regular expression:
308
+ *
309
+ * ```ts
310
+ * /^data-.*$/
311
+ * ```
312
+ *
313
+ * to
314
+ *
315
+ * ```ts
316
+ * [ [ /^data-.*$/, true ] ]
317
+ * ```
318
+ *
319
+ * Objects (plain or with `key` and `value` specified explicitly):
320
+ *
321
+ * ```ts
322
+ * {
323
+ * src: /^https:.*$/
324
+ * }
325
+ * ```
326
+ *
327
+ * or
328
+ *
329
+ * ```ts
330
+ * [ {
331
+ * key: 'src',
332
+ * value: /^https:.*$/
333
+ * } ]
334
+ * ```
335
+ *
336
+ * to:
337
+ *
338
+ * ```ts
339
+ * [ [ 'src', /^https:.*$/ ] ]
340
+ * ```
341
+ *
342
+ * @returns Returns an array of objects or null if provided patterns were not in an expected form.
343
+ */
327
344
  function normalizePatterns(patterns) {
328
345
  if (Array.isArray(patterns)) {
329
346
  return patterns.map((pattern) => {
@@ -344,18 +361,20 @@ function normalizePatterns(patterns) {
344
361
  // Other cases (true, string or regexp).
345
362
  return [[patterns, true]];
346
363
  }
347
- // @param {String|RegExp} patternKey A pattern representing a key we want to match.
348
- // @param {String} itemKey An actual item key (e.g. `'src'`, `'background-color'`, `'ck-widget'`) we're testing against pattern.
349
- // @returns {Boolean}
364
+ /**
365
+ * @param patternKey A pattern representing a key we want to match.
366
+ * @param itemKey An actual item key (e.g. `'src'`, `'background-color'`, `'ck-widget'`) we're testing against pattern.
367
+ */
350
368
  function isKeyMatched(patternKey, itemKey) {
351
369
  return patternKey === true ||
352
370
  patternKey === itemKey ||
353
371
  patternKey instanceof RegExp && itemKey.match(patternKey);
354
372
  }
355
- // @param {String|RegExp} patternValue A pattern representing a value we want to match.
356
- // @param {String} itemKey An item key, e.g. `background`, `href`, 'rel', etc.
357
- // @param {Function} valueGetter A function used to provide a value for a given `itemKey`.
358
- // @returns {Boolean}
373
+ /**
374
+ * @param patternValue A pattern representing a value we want to match.
375
+ * @param itemKey An item key, e.g. `background`, `href`, 'rel', etc.
376
+ * @param valueGetter A function used to provide a value for a given `itemKey`.
377
+ */
359
378
  function isValueMatched(patternValue, itemKey, valueGetter) {
360
379
  if (patternValue === true) {
361
380
  return true;
@@ -367,12 +386,14 @@ function isValueMatched(patternValue, itemKey, valueGetter) {
367
386
  return patternValue === itemValue ||
368
387
  patternValue instanceof RegExp && !!String(itemValue).match(patternValue);
369
388
  }
370
- // Checks if attributes of provided element can be matched against provided patterns.
371
- //
372
- // @param {Object} patterns Object with information about attributes to match. Each key of the object will be
373
- // used as attribute name. Value of each key can be a string or regular expression to match against attribute value.
374
- // @param {module:engine/view/element~Element} element Element which attributes will be tested.
375
- // @returns {Array|null} Returns array with matched attribute names or `null` if no attributes were matched.
389
+ /**
390
+ * Checks if attributes of provided element can be matched against provided patterns.
391
+ *
392
+ * @param patterns Object with information about attributes to match. Each key of the object will be
393
+ * used as attribute name. Value of each key can be a string or regular expression to match against attribute value.
394
+ * @param element Element which attributes will be tested.
395
+ * @returns Returns array with matched attribute names or `null` if no attributes were matched.
396
+ */
376
397
  function matchAttributes(patterns, element) {
377
398
  const attributeKeys = new Set(element.getAttributeKeys());
378
399
  // `style` and `class` attribute keys are deprecated. Only allow them in object pattern
@@ -393,21 +414,25 @@ function matchAttributes(patterns, element) {
393
414
  }
394
415
  return matchPatterns(patterns, attributeKeys, key => element.getAttribute(key));
395
416
  }
396
- // Checks if classes of provided element can be matched against provided patterns.
397
- //
398
- // @param {Array.<String|RegExp>} patterns Array of strings or regular expressions to match against element's classes.
399
- // @param {module:engine/view/element~Element} element Element which classes will be tested.
400
- // @returns {Array|null} Returns array with matched class names or `null` if no classes were matched.
417
+ /**
418
+ * Checks if classes of provided element can be matched against provided patterns.
419
+ *
420
+ * @param patterns Array of strings or regular expressions to match against element's classes.
421
+ * @param element Element which classes will be tested.
422
+ * @returns Returns array with matched class names or `null` if no classes were matched.
423
+ */
401
424
  function matchClasses(patterns, element) {
402
425
  // We don't need `getter` here because patterns for classes are always normalized to `[ className, true ]`.
403
426
  return matchPatterns(patterns, element.getClassNames(), /* istanbul ignore next */ () => { });
404
427
  }
405
- // Checks if styles of provided element can be matched against provided patterns.
406
- //
407
- // @param {Object} patterns Object with information about styles to match. Each key of the object will be
408
- // used as style name. Value of each key can be a string or regular expression to match against style value.
409
- // @param {module:engine/view/element~Element} element Element which styles will be tested.
410
- // @returns {Array|null} Returns array with matched style names or `null` if no styles were matched.
428
+ /**
429
+ * Checks if styles of provided element can be matched against provided patterns.
430
+ *
431
+ * @param patterns Object with information about styles to match. Each key of the object will be
432
+ * used as style name. Value of each key can be a string or regular expression to match against style value.
433
+ * @param element Element which styles will be tested.
434
+ * @returns Returns array with matched style names or `null` if no styles were matched.
435
+ */
411
436
  function matchStyles(patterns, element) {
412
437
  return matchPatterns(patterns, element.getStyleNames(true), key => element.getStyle(key));
413
438
  }
@@ -415,7 +440,7 @@ function matchStyles(patterns, element) {
415
440
  * The key-value matcher pattern is missing key or value. Both must be present.
416
441
  * Refer the documentation: {@link module:engine/view/matcher~MatcherPattern}.
417
442
  *
418
- * @param {Object} pattern Pattern with missing properties.
443
+ * @param pattern Pattern with missing properties.
419
444
  * @error matcher-pattern-missing-key-or-value
420
445
  */
421
446
  /**
@@ -423,28 +448,30 @@ function matchStyles(patterns, element) {
423
448
  *
424
449
  * Use `styles` matcher pattern option instead:
425
450
  *
426
- * // Instead of:
427
- * const pattern = {
428
- * attributes: {
429
- * key1: 'value1',
430
- * key2: 'value2',
431
- * style: /^border.*$/
432
- * }
433
- * }
434
- *
435
- * // Use:
436
- * const pattern = {
437
- * attributes: {
438
- * key1: 'value1',
439
- * key2: 'value2'
440
- * },
441
- * styles: /^border.*$/
442
- * }
451
+ * ```ts
452
+ * // Instead of:
453
+ * const pattern = {
454
+ * attributes: {
455
+ * key1: 'value1',
456
+ * key2: 'value2',
457
+ * style: /^border.*$/
458
+ * }
459
+ * }
460
+ *
461
+ * // Use:
462
+ * const pattern = {
463
+ * attributes: {
464
+ * key1: 'value1',
465
+ * key2: 'value2'
466
+ * },
467
+ * styles: /^border.*$/
468
+ * }
469
+ * ```
443
470
  *
444
471
  * Refer to the {@glink updating/migration-to-29##migration-to-ckeditor-5-v2910 Migration to v29.1.0} guide
445
472
  * and {@link module:engine/view/matcher~MatcherPattern} documentation.
446
473
  *
447
- * @param {Object} pattern Pattern with missing properties.
474
+ * @param pattern Pattern with missing properties.
448
475
  * @error matcher-pattern-deprecated-attributes-style-key
449
476
  */
450
477
  /**
@@ -452,27 +479,29 @@ function matchStyles(patterns, element) {
452
479
  *
453
480
  * Use `classes` matcher pattern option instead:
454
481
  *
455
- * // Instead of:
456
- * const pattern = {
457
- * attributes: {
458
- * key1: 'value1',
459
- * key2: 'value2',
460
- * class: 'foobar'
461
- * }
462
- * }
463
- *
464
- * // Use:
465
- * const pattern = {
466
- * attributes: {
467
- * key1: 'value1',
468
- * key2: 'value2'
469
- * },
470
- * classes: 'foobar'
471
- * }
482
+ * ```ts
483
+ * // Instead of:
484
+ * const pattern = {
485
+ * attributes: {
486
+ * key1: 'value1',
487
+ * key2: 'value2',
488
+ * class: 'foobar'
489
+ * }
490
+ * }
491
+ *
492
+ * // Use:
493
+ * const pattern = {
494
+ * attributes: {
495
+ * key1: 'value1',
496
+ * key2: 'value2'
497
+ * },
498
+ * classes: 'foobar'
499
+ * }
500
+ * ```
472
501
  *
473
502
  * Refer to the {@glink updating/migration-to-29##migration-to-ckeditor-5-v2910 Migration to v29.1.0} guide
474
503
  * and the {@link module:engine/view/matcher~MatcherPattern} documentation.
475
504
  *
476
- * @param {Object} pattern Pattern with missing properties.
505
+ * @param pattern Pattern with missing properties.
477
506
  * @error matcher-pattern-deprecated-attributes-class-key
478
507
  */