@ckeditor/ckeditor5-engine 48.2.0 → 48.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/controller/datacontroller.d.ts +329 -328
  2. package/dist/controller/editingcontroller.d.ts +95 -94
  3. package/dist/conversion/comparemarkers.d.ts +45 -45
  4. package/dist/conversion/conversion.d.ts +474 -474
  5. package/dist/conversion/conversionhelpers.d.ts +21 -21
  6. package/dist/conversion/downcastdispatcher.d.ts +539 -538
  7. package/dist/conversion/downcasthelpers.d.ts +1129 -1129
  8. package/dist/conversion/mapper.d.ts +692 -697
  9. package/dist/conversion/modelconsumable.d.ts +196 -196
  10. package/dist/conversion/upcastdispatcher.d.ts +483 -482
  11. package/dist/conversion/upcasthelpers.d.ts +491 -491
  12. package/dist/conversion/viewconsumable.d.ts +330 -330
  13. package/dist/dataprocessor/basichtmlwriter.d.ts +15 -15
  14. package/dist/dataprocessor/dataprocessor.d.ts +57 -57
  15. package/dist/dataprocessor/htmldataprocessor.d.ts +72 -72
  16. package/dist/dataprocessor/htmlwriter.d.ts +11 -11
  17. package/dist/dataprocessor/xmldataprocessor.d.ts +86 -86
  18. package/dist/dev-utils/model.d.ts +128 -123
  19. package/dist/dev-utils/operationreplayer.d.ts +49 -49
  20. package/dist/dev-utils/utils.d.ts +33 -33
  21. package/dist/dev-utils/view.d.ts +314 -309
  22. package/dist/engineconfig.d.ts +39 -39
  23. package/dist/index.css.map +1 -1
  24. package/dist/index.d.ts +150 -150
  25. package/dist/index.js +34026 -40107
  26. package/dist/index.js.map +1 -1
  27. package/dist/legacyerrors.d.ts +0 -4
  28. package/dist/model/batch.d.ts +86 -86
  29. package/dist/model/differ.d.ts +504 -504
  30. package/dist/model/document.d.ts +265 -268
  31. package/dist/model/documentfragment.d.ts +214 -214
  32. package/dist/model/documentselection.d.ts +406 -410
  33. package/dist/model/element.d.ts +182 -182
  34. package/dist/model/history.d.ts +109 -109
  35. package/dist/model/item.d.ts +9 -9
  36. package/dist/model/liveposition.d.ts +70 -69
  37. package/dist/model/liverange.d.ts +93 -92
  38. package/dist/model/markercollection.d.ts +317 -324
  39. package/dist/model/model.d.ts +889 -909
  40. package/dist/model/node.d.ts +254 -254
  41. package/dist/model/nodelist.d.ts +110 -110
  42. package/dist/model/operation/attributeoperation.d.ts +98 -98
  43. package/dist/model/operation/detachoperation.d.ts +57 -57
  44. package/dist/model/operation/insertoperation.d.ts +85 -85
  45. package/dist/model/operation/markeroperation.d.ts +87 -87
  46. package/dist/model/operation/mergeoperation.d.ts +95 -95
  47. package/dist/model/operation/moveoperation.d.ts +97 -97
  48. package/dist/model/operation/nooperation.d.ts +33 -33
  49. package/dist/model/operation/operation.d.ts +94 -94
  50. package/dist/model/operation/operationfactory.d.ts +14 -14
  51. package/dist/model/operation/renameoperation.d.ts +78 -78
  52. package/dist/model/operation/rootattributeoperation.d.ts +93 -93
  53. package/dist/model/operation/rootoperation.d.ts +71 -71
  54. package/dist/model/operation/splitoperation.d.ts +104 -104
  55. package/dist/model/operation/transform.d.ts +91 -91
  56. package/dist/model/operation/utils.d.ts +58 -58
  57. package/dist/model/position.d.ts +535 -535
  58. package/dist/model/range.d.ts +458 -453
  59. package/dist/model/rootelement.d.ts +55 -55
  60. package/dist/model/schema.d.ts +1325 -1327
  61. package/dist/model/selection.d.ts +452 -471
  62. package/dist/model/text.d.ts +62 -62
  63. package/dist/model/textproxy.d.ts +140 -140
  64. package/dist/model/treewalker.d.ts +190 -190
  65. package/dist/model/typecheckable.d.ts +281 -281
  66. package/dist/model/utils/autoparagraphing.d.ts +29 -29
  67. package/dist/model/utils/deletecontent.d.ts +68 -68
  68. package/dist/model/utils/getselectedcontent.d.ts +27 -27
  69. package/dist/model/utils/insertcontent.d.ts +42 -42
  70. package/dist/model/utils/insertobject.d.ts +41 -41
  71. package/dist/model/utils/modifyselection.d.ts +44 -44
  72. package/dist/model/utils/selection-post-fixer.d.ts +71 -71
  73. package/dist/model/writer.d.ts +854 -854
  74. package/dist/view/attributeelement.d.ts +123 -123
  75. package/dist/view/containerelement.d.ts +49 -49
  76. package/dist/view/datatransfer.d.ts +70 -70
  77. package/dist/view/document.d.ts +175 -177
  78. package/dist/view/documentfragment.d.ts +158 -157
  79. package/dist/view/documentselection.d.ts +308 -307
  80. package/dist/view/domconverter.d.ts +612 -657
  81. package/dist/view/downcastwriter.d.ts +1006 -1006
  82. package/dist/view/editableelement.d.ts +64 -63
  83. package/dist/view/element.d.ts +754 -754
  84. package/dist/view/elementdefinition.d.ts +79 -79
  85. package/dist/view/emptyelement.d.ts +42 -42
  86. package/dist/view/filler.d.ts +75 -75
  87. package/dist/view/item.d.ts +9 -9
  88. package/dist/view/matcher.d.ts +412 -487
  89. package/dist/view/node.d.ts +164 -163
  90. package/dist/view/observer/arrowkeysobserver.d.ts +37 -37
  91. package/dist/view/observer/bubblingemittermixin.d.ts +163 -153
  92. package/dist/view/observer/bubblingeventinfo.d.ts +45 -42
  93. package/dist/view/observer/clickobserver.d.ts +36 -36
  94. package/dist/view/observer/compositionobserver.d.ts +67 -67
  95. package/dist/view/observer/domeventdata.d.ts +46 -46
  96. package/dist/view/observer/domeventobserver.d.ts +77 -74
  97. package/dist/view/observer/fakeselectionobserver.d.ts +42 -42
  98. package/dist/view/observer/focusobserver.d.ts +84 -84
  99. package/dist/view/observer/inputobserver.d.ts +76 -76
  100. package/dist/view/observer/keyobserver.d.ts +53 -53
  101. package/dist/view/observer/mouseobserver.d.ts +73 -73
  102. package/dist/view/observer/mutationobserver.d.ts +101 -101
  103. package/dist/view/observer/observer.d.ts +84 -83
  104. package/dist/view/observer/pointerobserver.d.ts +63 -63
  105. package/dist/view/observer/selectionobserver.d.ts +136 -136
  106. package/dist/view/observer/tabobserver.d.ts +38 -38
  107. package/dist/view/observer/touchobserver.d.ts +60 -60
  108. package/dist/view/placeholder.d.ts +80 -80
  109. package/dist/view/position.d.ts +187 -187
  110. package/dist/view/range.d.ts +282 -282
  111. package/dist/view/rawelement.d.ts +72 -72
  112. package/dist/view/renderer.d.ts +270 -272
  113. package/dist/view/rooteditableelement.d.ts +43 -43
  114. package/dist/view/selection.d.ts +356 -369
  115. package/dist/view/styles/background.d.ts +15 -15
  116. package/dist/view/styles/border.d.ts +27 -27
  117. package/dist/view/styles/margin.d.ts +12 -12
  118. package/dist/view/styles/padding.d.ts +12 -12
  119. package/dist/view/styles/utils.d.ts +72 -72
  120. package/dist/view/stylesmap.d.ts +715 -715
  121. package/dist/view/text.d.ts +75 -75
  122. package/dist/view/textproxy.d.ts +92 -92
  123. package/dist/view/tokenlist.d.ts +104 -104
  124. package/dist/view/treewalker.d.ts +201 -201
  125. package/dist/view/typecheckable.d.ts +445 -445
  126. package/dist/view/uielement.d.ts +93 -93
  127. package/dist/view/upcastwriter.d.ts +412 -412
  128. package/dist/view/view.d.ts +466 -469
  129. package/package.json +2 -2
@@ -1,513 +1,438 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
2
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
+ */
5
5
  /**
6
- * @module engine/view/matcher
7
- */
8
- import { type ViewElement } from './element.js';
9
- import { type Consumables } from '../conversion/viewconsumable.js';
6
+ * @module engine/view/matcher
7
+ */
8
+ import { type ViewElement } from "./element.js";
9
+ import { type Consumables } from "../conversion/viewconsumable.js";
10
10
  /**
11
- * View matcher class.
12
- * Instance of this class can be used to find {@link module:engine/view/element~ViewElement elements} that match given pattern.
13
- */
11
+ * View matcher class.
12
+ * Instance of this class can be used to find {@link module:engine/view/element~ViewElement elements} that match given pattern.
13
+ */
14
14
  export declare class Matcher {
15
- private readonly _patterns;
16
- /**
17
- * Creates new instance of Matcher.
18
- *
19
- * @param pattern Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for more information.
20
- */
21
- constructor(...pattern: Array<MatcherPattern>);
22
- /**
23
- * Adds pattern or patterns to matcher instance.
24
- *
25
- * ```ts
26
- * // String.
27
- * matcher.add( 'div' );
28
- *
29
- * // Regular expression.
30
- * matcher.add( /^\w/ );
31
- *
32
- * // Single class.
33
- * matcher.add( {
34
- * classes: 'foobar'
35
- * } );
36
- * ```
37
- *
38
- * See {@link module:engine/view/matcher~MatcherPattern} for more examples.
39
- *
40
- * Multiple patterns can be added in one call:
41
- *
42
- * ```ts
43
- * matcher.add( 'div', { classes: 'foobar' } );
44
- * ```
45
- *
46
- * @param pattern Object describing pattern details. If string or regular expression
47
- * is provided it will be used to match element's name. Pattern can be also provided in a form
48
- * of a function - then this function will be called with each {@link module:engine/view/element~ViewElement element} as a parameter.
49
- * Function's return value will be stored under `match` key of the object returned from
50
- * {@link module:engine/view/matcher~Matcher#match match} or {@link module:engine/view/matcher~Matcher#matchAll matchAll} methods.
51
- */
52
- add(...pattern: Array<MatcherPattern>): void;
53
- /**
54
- * Matches elements for currently stored patterns. Returns match information about first found
55
- * {@link module:engine/view/element~ViewElement element}, otherwise returns `null`.
56
- *
57
- * Example of returned object:
58
- *
59
- * ```ts
60
- * {
61
- * element: <instance of found element>,
62
- * pattern: <pattern used to match found element>,
63
- * match: {
64
- * name: true,
65
- * attributes: [
66
- * [ 'title' ],
67
- * [ 'href' ],
68
- * [ 'class', 'foo' ],
69
- * [ 'style', 'color' ],
70
- * [ 'style', 'position' ]
71
- * ]
72
- * }
73
- * }
74
- * ```
75
- *
76
- * You could use the `match` field from the above returned object as an input for the
77
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#test `ViewConsumable#test()`} and
78
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume `ViewConsumable#consume()`} methods.
79
- *
80
- * @see module:engine/view/matcher~Matcher#add
81
- * @see module:engine/view/matcher~Matcher#matchAll
82
- * @param element View element to match against stored patterns.
83
- * @returns The match information about found element or `null`.
84
- */
85
- match(...element: Array<ViewElement>): MatchResult | null;
86
- /**
87
- * Matches elements for currently stored patterns. Returns array of match information with all found
88
- * {@link module:engine/view/element~ViewElement elements}. If no element is found - returns `null`.
89
- *
90
- * @see module:engine/view/matcher~Matcher#add
91
- * @see module:engine/view/matcher~Matcher#match
92
- * @param element View element to match against stored patterns.
93
- * @returns Array with match information about found elements or `null`. For more information
94
- * see {@link module:engine/view/matcher~Matcher#match match method} description.
95
- */
96
- matchAll(...element: Array<ViewElement>): Array<MatchResult> | null;
97
- /**
98
- * Returns the name of the element to match if there is exactly one pattern added to the matcher instance
99
- * and it matches element name defined by `string` (not `RegExp`). Otherwise, returns `null`.
100
- *
101
- * @returns Element name trying to match.
102
- */
103
- getElementName(): string | null;
104
- /**
105
- * Returns match information if {@link module:engine/view/element~ViewElement element} is matching provided pattern.
106
- * If element cannot be matched to provided pattern - returns `null`.
107
- *
108
- * @returns Returns object with match information or null if element is not matching.
109
- */
110
- private _isElementMatching;
15
+ private readonly _patterns;
16
+ /**
17
+ * Creates new instance of Matcher.
18
+ *
19
+ * @param pattern Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for more information.
20
+ */
21
+ constructor(...pattern: Array<MatcherPattern>);
22
+ /**
23
+ * Adds pattern or patterns to matcher instance.
24
+ *
25
+ * ```ts
26
+ * // String.
27
+ * matcher.add( 'div' );
28
+ *
29
+ * // Regular expression.
30
+ * matcher.add( /^\w/ );
31
+ *
32
+ * // Single class.
33
+ * matcher.add( {
34
+ * classes: 'foobar'
35
+ * } );
36
+ * ```
37
+ *
38
+ * See {@link module:engine/view/matcher~MatcherPattern} for more examples.
39
+ *
40
+ * Multiple patterns can be added in one call:
41
+ *
42
+ * ```ts
43
+ * matcher.add( 'div', { classes: 'foobar' } );
44
+ * ```
45
+ *
46
+ * @param pattern Object describing pattern details. If string or regular expression
47
+ * is provided it will be used to match element's name. Pattern can be also provided in a form
48
+ * of a function - then this function will be called with each {@link module:engine/view/element~ViewElement element} as a parameter.
49
+ * Function's return value will be stored under `match` key of the object returned from
50
+ * {@link module:engine/view/matcher~Matcher#match match} or {@link module:engine/view/matcher~Matcher#matchAll matchAll} methods.
51
+ */
52
+ add(...pattern: Array<MatcherPattern>): void;
53
+ /**
54
+ * Matches elements for currently stored patterns. Returns match information about first found
55
+ * {@link module:engine/view/element~ViewElement element}, otherwise returns `null`.
56
+ *
57
+ * Example of returned object:
58
+ *
59
+ * ```ts
60
+ * {
61
+ * element: <instance of found element>,
62
+ * pattern: <pattern used to match found element>,
63
+ * match: {
64
+ * name: true,
65
+ * attributes: [
66
+ * [ 'title' ],
67
+ * [ 'href' ],
68
+ * [ 'class', 'foo' ],
69
+ * [ 'style', 'color' ],
70
+ * [ 'style', 'position' ]
71
+ * ]
72
+ * }
73
+ * }
74
+ * ```
75
+ *
76
+ * You could use the `match` field from the above returned object as an input for the
77
+ * {@link module:engine/conversion/viewconsumable~ViewConsumable#test `ViewConsumable#test()`} and
78
+ * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume `ViewConsumable#consume()`} methods.
79
+ *
80
+ * @see module:engine/view/matcher~Matcher#add
81
+ * @see module:engine/view/matcher~Matcher#matchAll
82
+ * @param element View element to match against stored patterns.
83
+ * @returns The match information about found element or `null`.
84
+ */
85
+ match(...element: Array<ViewElement>): MatchResult | null;
86
+ /**
87
+ * Matches elements for currently stored patterns. Returns array of match information with all found
88
+ * {@link module:engine/view/element~ViewElement elements}. If no element is found - returns `null`.
89
+ *
90
+ * @see module:engine/view/matcher~Matcher#add
91
+ * @see module:engine/view/matcher~Matcher#match
92
+ * @param element View element to match against stored patterns.
93
+ * @returns Array with match information about found elements or `null`. For more information
94
+ * see {@link module:engine/view/matcher~Matcher#match match method} description.
95
+ */
96
+ matchAll(...element: Array<ViewElement>): Array<MatchResult> | null;
97
+ /**
98
+ * Returns the name of the element to match if there is exactly one pattern added to the matcher instance
99
+ * and it matches element name defined by `string` (not `RegExp`). Otherwise, returns `null`.
100
+ *
101
+ * @returns Element name trying to match.
102
+ */
103
+ getElementName(): string | null;
104
+ /**
105
+ * Returns match information if {@link module:engine/view/element~ViewElement element} is matching provided pattern.
106
+ * If element cannot be matched to provided pattern - returns `null`.
107
+ *
108
+ * @returns Returns object with match information or null if element is not matching.
109
+ */
110
+ private _isElementMatching;
111
111
  }
112
112
  /**
113
- * Returns true if the given `item` matches the pattern.
114
- *
115
- * @internal
116
- * @param pattern A pattern representing a key/value we want to match.
117
- * @param item An actual item key/value (e.g. `'src'`, `'background-color'`, `'ck-widget'`) we're testing against pattern.
118
- */
113
+ * Returns true if the given `item` matches the pattern.
114
+ *
115
+ * @internal
116
+ * @param pattern A pattern representing a key/value we want to match.
117
+ * @param item An actual item key/value (e.g. `'src'`, `'background-color'`, `'ck-widget'`) we're testing against pattern.
118
+ */
119
119
  export declare function isPatternMatched(pattern: true | string | RegExp, item: string): unknown;
120
120
  /**
121
- * An entity that is a valid pattern recognized by a matcher. `MatcherPattern` is used by {@link ~Matcher} to recognize
122
- * if a view element fits in a group of view elements described by the pattern.
123
- *
124
- * `MatcherPattern` can be given as a `String`, a `RegExp`, an `Object` or a `Function`.
125
- *
126
- * If `MatcherPattern` is given as a `String` or `RegExp`, it will match any view element that has a matching name:
127
- *
128
- * ```ts
129
- * // Match any element with name equal to 'div'.
130
- * const pattern = 'div';
131
- *
132
- * // Match any element which name starts on 'p'.
133
- * const pattern = /^p/;
134
- * ```
135
- *
136
- * If `MatcherPattern` is given as an `Object`, all the object's properties will be matched with view element properties.
137
- * If the view element does not meet all of the object's pattern properties, the match will not happen.
138
- * Available `Object` matching properties:
139
- *
140
- * Matching view element:
141
- *
142
- * ```ts
143
- * // Match view element's name using String:
144
- * const pattern = { name: 'p' };
145
- *
146
- * // or by providing RegExp:
147
- * const pattern = { name: /^(ul|ol)$/ };
148
- *
149
- * // The name can also be skipped to match any view element with matching attributes:
150
- * const pattern = {
151
- * attributes: {
152
- * 'title': true
153
- * }
154
- * };
155
- * ```
156
- *
157
- * Matching view element attributes:
158
- *
159
- * ```ts
160
- * // Match view element with any attribute value.
161
- * const pattern = {
162
- * name: 'p',
163
- * attributes: true
164
- * };
165
- *
166
- * // Match view element which has matching attributes (String).
167
- * const pattern = {
168
- * name: 'figure',
169
- * attributes: 'title' // Match title attribute (can be empty).
170
- * };
171
- *
172
- * // Match view element which has matching attributes (RegExp).
173
- * const pattern = {
174
- * name: 'figure',
175
- * attributes: /^data-.*$/ // Match attributes starting with `data-` e.g. `data-foo` with any value (can be empty).
176
- * };
177
- *
178
- * // Match view element which has matching attributes (Object).
179
- * const pattern = {
180
- * name: 'figure',
181
- * attributes: {
182
- * title: 'foobar', // Match `title` attribute with 'foobar' value.
183
- * alt: true, // Match `alt` attribute with any value (can be empty).
184
- * 'data-type': /^(jpg|png)$/ // Match `data-type` attribute with `jpg` or `png` value.
185
- * }
186
- * };
187
- *
188
- * // Match view element which has matching attributes (Array).
189
- * const pattern = {
190
- * name: 'figure',
191
- * attributes: [
192
- * 'title', // Match `title` attribute (can be empty).
193
- * /^data-*$/ // Match attributes starting with `data-` e.g. `data-foo` with any value (can be empty).
194
- * ]
195
- * };
196
- *
197
- * // Match view element which has matching attributes (key-value pairs).
198
- * const pattern = {
199
- * name: 'input',
200
- * attributes: [
201
- * {
202
- * key: 'type', // Match `type` as an attribute key.
203
- * value: /^(text|number|date)$/ // Match `text`, `number` or `date` values.
204
- * },
205
- * {
206
- * key: /^data-.*$/, // Match attributes starting with `data-` e.g. `data-foo`.
207
- * value: true // Match any value (can be empty).
208
- * }
209
- * ]
210
- * };
211
- * ```
212
- *
213
- * Matching view element styles:
214
- *
215
- * ```ts
216
- * // Match view element with any style.
217
- * const pattern = {
218
- * name: 'p',
219
- * styles: true
220
- * };
221
- *
222
- * // Match view element which has matching styles (String).
223
- * const pattern = {
224
- * name: 'p',
225
- * styles: 'color' // Match attributes with `color` style.
226
- * };
227
- *
228
- * // Match view element which has matching styles (RegExp).
229
- * const pattern = {
230
- * name: 'p',
231
- * styles: /^border.*$/ // Match view element with any border style.
232
- * };
233
- *
234
- * // Match view element which has matching styles (Object).
235
- * const pattern = {
236
- * name: 'p',
237
- * styles: {
238
- * color: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/, // Match `color` in RGB format only.
239
- * 'font-weight': 600, // Match `font-weight` only if it's `600`.
240
- * 'text-decoration': true // Match any text decoration.
241
- * }
242
- * };
243
- *
244
- * // Match view element which has matching styles (Array).
245
- * const pattern = {
246
- * name: 'p',
247
- * styles: [
248
- * 'color', // Match `color` with any value.
249
- * /^border.*$/ // Match all border properties.
250
- * ]
251
- * };
252
- *
253
- * // Match view element which has matching styles (key-value pairs).
254
- * const pattern = {
255
- * name: 'p',
256
- * styles: [
257
- * {
258
- * key: 'color', // Match `color` as an property key.
259
- * value: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/ // Match RGB format only.
260
- * },
261
- * {
262
- * key: /^border.*$/, // Match any border style.
263
- * value: true // Match any value.
264
- * }
265
- * ]
266
- * };
267
- * ```
268
- *
269
- * Matching view element classes:
270
- *
271
- * ```ts
272
- * // Match view element with any class.
273
- * const pattern = {
274
- * name: 'p',
275
- * classes: true
276
- * };
277
- *
278
- * // Match view element which has matching class (String).
279
- * const pattern = {
280
- * name: 'p',
281
- * classes: 'highlighted' // Match `highlighted` class.
282
- * };
283
- *
284
- * // Match view element which has matching classes (RegExp).
285
- * const pattern = {
286
- * name: 'figure',
287
- * classes: /^image-side-(left|right)$/ // Match `image-side-left` or `image-side-right` class.
288
- * };
289
- *
290
- * // Match view element which has matching classes (Object).
291
- * const pattern = {
292
- * name: 'p',
293
- * classes: {
294
- * highlighted: true, // Match `highlighted` class.
295
- * marker: true // Match `marker` class.
296
- * }
297
- * };
298
- *
299
- * // Match view element which has matching classes (Array).
300
- * const pattern = {
301
- * name: 'figure',
302
- * classes: [
303
- * 'image', // Match `image` class.
304
- * /^image-side-(left|right)$/ // Match `image-side-left` or `image-side-right` class.
305
- * ]
306
- * };
307
- *
308
- * // Match view element which has matching classes (key-value pairs).
309
- * const pattern = {
310
- * name: 'figure',
311
- * classes: [
312
- * {
313
- * key: 'image', // Match `image` class.
314
- * value: true
315
- * },
316
- * {
317
- * key: /^image-side-(left|right)$/, // Match `image-side-left` or `image-side-right` class.
318
- * value: true
319
- * }
320
- * ]
321
- * };
322
- * ```
323
- *
324
- * Pattern can combine multiple properties allowing for more complex view element matching:
325
- *
326
- * ```ts
327
- * const pattern = {
328
- * name: 'span',
329
- * attributes: [ 'title' ],
330
- * styles: {
331
- * 'font-weight': 'bold'
332
- * },
333
- * classes: 'highlighted'
334
- * };
335
- * ```
336
- *
337
- * If `MatcherPattern` is given as a `Function`, the function takes a view element as a first and only parameter and
338
- * the function should decide whether that element matches. If so, it should return what part of the view element has been matched.
339
- * Otherwise, the function should return `null`. The returned result will be included in `match` property of the object
340
- * returned by {@link ~Matcher#match} call.
341
- *
342
- * ```ts
343
- * // Match an empty <div> element.
344
- * const pattern = element => {
345
- * if ( element.name == 'div' && element.childCount > 0 ) {
346
- * // Return which part of the element was matched.
347
- * return { name: true };
348
- * }
349
- *
350
- * return null;
351
- * };
352
- *
353
- * // Match a <p> element with big font ("heading-like" element).
354
- * const pattern = element => {
355
- * if ( element.name == 'p' ) {
356
- * const fontSize = element.getStyle( 'font-size' );
357
- * const size = fontSize.match( /(\d+)/px );
358
- *
359
- * if ( size && Number( size[ 1 ] ) > 26 ) {
360
- * return { name: true, styles: [ 'font-size' ] };
361
- * }
362
- * }
363
- *
364
- * return null;
365
- * };
366
- * ```
367
- *
368
- * `MatcherPattern` is defined in a way that it is a superset of {@link module:engine/view/elementdefinition~ViewElementDefinition},
369
- * that is, every `ElementDefinition` also can be used as a `MatcherPattern`.
370
- */
121
+ * An entity that is a valid pattern recognized by a matcher. `MatcherPattern` is used by {@link ~Matcher} to recognize
122
+ * if a view element fits in a group of view elements described by the pattern.
123
+ *
124
+ * `MatcherPattern` can be given as a `String`, a `RegExp`, an `Object` or a `Function`.
125
+ *
126
+ * If `MatcherPattern` is given as a `String` or `RegExp`, it will match any view element that has a matching name:
127
+ *
128
+ * ```ts
129
+ * // Match any element with name equal to 'div'.
130
+ * const pattern = 'div';
131
+ *
132
+ * // Match any element which name starts on 'p'.
133
+ * const pattern = /^p/;
134
+ * ```
135
+ *
136
+ * If `MatcherPattern` is given as an `Object`, all the object's properties will be matched with view element properties.
137
+ * If the view element does not meet all of the object's pattern properties, the match will not happen.
138
+ * Available `Object` matching properties:
139
+ *
140
+ * Matching view element:
141
+ *
142
+ * ```ts
143
+ * // Match view element's name using String:
144
+ * const pattern = { name: 'p' };
145
+ *
146
+ * // or by providing RegExp:
147
+ * const pattern = { name: /^(ul|ol)$/ };
148
+ *
149
+ * // The name can also be skipped to match any view element with matching attributes:
150
+ * const pattern = {
151
+ * attributes: {
152
+ * 'title': true
153
+ * }
154
+ * };
155
+ * ```
156
+ *
157
+ * Matching view element attributes:
158
+ *
159
+ * ```ts
160
+ * // Match view element with any attribute value.
161
+ * const pattern = {
162
+ * name: 'p',
163
+ * attributes: true
164
+ * };
165
+ *
166
+ * // Match view element which has matching attributes (String).
167
+ * const pattern = {
168
+ * name: 'figure',
169
+ * attributes: 'title' // Match title attribute (can be empty).
170
+ * };
171
+ *
172
+ * // Match view element which has matching attributes (RegExp).
173
+ * const pattern = {
174
+ * name: 'figure',
175
+ * attributes: /^data-.*$/ // Match attributes starting with `data-` e.g. `data-foo` with any value (can be empty).
176
+ * };
177
+ *
178
+ * // Match view element which has matching attributes (Object).
179
+ * const pattern = {
180
+ * name: 'figure',
181
+ * attributes: {
182
+ * title: 'foobar', // Match `title` attribute with 'foobar' value.
183
+ * alt: true, // Match `alt` attribute with any value (can be empty).
184
+ * 'data-type': /^(jpg|png)$/ // Match `data-type` attribute with `jpg` or `png` value.
185
+ * }
186
+ * };
187
+ *
188
+ * // Match view element which has matching attributes (Array).
189
+ * const pattern = {
190
+ * name: 'figure',
191
+ * attributes: [
192
+ * 'title', // Match `title` attribute (can be empty).
193
+ * /^data-*$/ // Match attributes starting with `data-` e.g. `data-foo` with any value (can be empty).
194
+ * ]
195
+ * };
196
+ *
197
+ * // Match view element which has matching attributes (key-value pairs).
198
+ * const pattern = {
199
+ * name: 'input',
200
+ * attributes: [
201
+ * {
202
+ * key: 'type', // Match `type` as an attribute key.
203
+ * value: /^(text|number|date)$/ // Match `text`, `number` or `date` values.
204
+ * },
205
+ * {
206
+ * key: /^data-.*$/, // Match attributes starting with `data-` e.g. `data-foo`.
207
+ * value: true // Match any value (can be empty).
208
+ * }
209
+ * ]
210
+ * };
211
+ * ```
212
+ *
213
+ * Matching view element styles:
214
+ *
215
+ * ```ts
216
+ * // Match view element with any style.
217
+ * const pattern = {
218
+ * name: 'p',
219
+ * styles: true
220
+ * };
221
+ *
222
+ * // Match view element which has matching styles (String).
223
+ * const pattern = {
224
+ * name: 'p',
225
+ * styles: 'color' // Match attributes with `color` style.
226
+ * };
227
+ *
228
+ * // Match view element which has matching styles (RegExp).
229
+ * const pattern = {
230
+ * name: 'p',
231
+ * styles: /^border.*$/ // Match view element with any border style.
232
+ * };
233
+ *
234
+ * // Match view element which has matching styles (Object).
235
+ * const pattern = {
236
+ * name: 'p',
237
+ * styles: {
238
+ * color: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/, // Match `color` in RGB format only.
239
+ * 'font-weight': 600, // Match `font-weight` only if it's `600`.
240
+ * 'text-decoration': true // Match any text decoration.
241
+ * }
242
+ * };
243
+ *
244
+ * // Match view element which has matching styles (Array).
245
+ * const pattern = {
246
+ * name: 'p',
247
+ * styles: [
248
+ * 'color', // Match `color` with any value.
249
+ * /^border.*$/ // Match all border properties.
250
+ * ]
251
+ * };
252
+ *
253
+ * // Match view element which has matching styles (key-value pairs).
254
+ * const pattern = {
255
+ * name: 'p',
256
+ * styles: [
257
+ * {
258
+ * key: 'color', // Match `color` as an property key.
259
+ * value: /rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)/ // Match RGB format only.
260
+ * },
261
+ * {
262
+ * key: /^border.*$/, // Match any border style.
263
+ * value: true // Match any value.
264
+ * }
265
+ * ]
266
+ * };
267
+ * ```
268
+ *
269
+ * Matching view element classes:
270
+ *
271
+ * ```ts
272
+ * // Match view element with any class.
273
+ * const pattern = {
274
+ * name: 'p',
275
+ * classes: true
276
+ * };
277
+ *
278
+ * // Match view element which has matching class (String).
279
+ * const pattern = {
280
+ * name: 'p',
281
+ * classes: 'highlighted' // Match `highlighted` class.
282
+ * };
283
+ *
284
+ * // Match view element which has matching classes (RegExp).
285
+ * const pattern = {
286
+ * name: 'figure',
287
+ * classes: /^image-side-(left|right)$/ // Match `image-side-left` or `image-side-right` class.
288
+ * };
289
+ *
290
+ * // Match view element which has matching classes (Object).
291
+ * const pattern = {
292
+ * name: 'p',
293
+ * classes: {
294
+ * highlighted: true, // Match `highlighted` class.
295
+ * marker: true // Match `marker` class.
296
+ * }
297
+ * };
298
+ *
299
+ * // Match view element which has matching classes (Array).
300
+ * const pattern = {
301
+ * name: 'figure',
302
+ * classes: [
303
+ * 'image', // Match `image` class.
304
+ * /^image-side-(left|right)$/ // Match `image-side-left` or `image-side-right` class.
305
+ * ]
306
+ * };
307
+ *
308
+ * // Match view element which has matching classes (key-value pairs).
309
+ * const pattern = {
310
+ * name: 'figure',
311
+ * classes: [
312
+ * {
313
+ * key: 'image', // Match `image` class.
314
+ * value: true
315
+ * },
316
+ * {
317
+ * key: /^image-side-(left|right)$/, // Match `image-side-left` or `image-side-right` class.
318
+ * value: true
319
+ * }
320
+ * ]
321
+ * };
322
+ * ```
323
+ *
324
+ * Pattern can combine multiple properties allowing for more complex view element matching:
325
+ *
326
+ * ```ts
327
+ * const pattern = {
328
+ * name: 'span',
329
+ * attributes: [ 'title' ],
330
+ * styles: {
331
+ * 'font-weight': 'bold'
332
+ * },
333
+ * classes: 'highlighted'
334
+ * };
335
+ * ```
336
+ *
337
+ * If `MatcherPattern` is given as a `Function`, the function takes a view element as a first and only parameter and
338
+ * the function should decide whether that element matches. If so, it should return what part of the view element has been matched.
339
+ * Otherwise, the function should return `null`. The returned result will be included in `match` property of the object
340
+ * returned by {@link ~Matcher#match} call.
341
+ *
342
+ * ```ts
343
+ * // Match an empty <div> element.
344
+ * const pattern = element => {
345
+ * if ( element.name == 'div' && element.childCount > 0 ) {
346
+ * // Return which part of the element was matched.
347
+ * return { name: true };
348
+ * }
349
+ *
350
+ * return null;
351
+ * };
352
+ *
353
+ * // Match a <p> element with big font ("heading-like" element).
354
+ * const pattern = element => {
355
+ * if ( element.name == 'p' ) {
356
+ * const fontSize = element.getStyle( 'font-size' );
357
+ * const size = fontSize.match( /(\d+)/px );
358
+ *
359
+ * if ( size && Number( size[ 1 ] ) > 26 ) {
360
+ * return { name: true, styles: [ 'font-size' ] };
361
+ * }
362
+ * }
363
+ *
364
+ * return null;
365
+ * };
366
+ * ```
367
+ *
368
+ * `MatcherPattern` is defined in a way that it is a superset of {@link module:engine/view/elementdefinition~ViewElementDefinition},
369
+ * that is, every `ElementDefinition` also can be used as a `MatcherPattern`.
370
+ */
371
371
  export type MatcherPattern = string | RegExp | MatcherFunctionPattern | MatcherObjectPattern;
372
372
  /**
373
- * A function describing `MatcherPattern`. See {@link ~MatcherPattern} for examples and other options.
374
- */
373
+ * A function describing `MatcherPattern`. See {@link ~MatcherPattern} for examples and other options.
374
+ */
375
375
  export type MatcherFunctionPattern = (element: ViewElement) => Match | Consumables | null;
376
376
  /**
377
- * An object describing `MatcherPattern`. See {@link ~MatcherPattern} for examples and other options.
378
- */
377
+ * An object describing `MatcherPattern`. See {@link ~MatcherPattern} for examples and other options.
378
+ */
379
379
  export interface MatcherObjectPattern {
380
- /**
381
- * View element name to match.
382
- */
383
- name?: string | RegExp;
384
- /**
385
- * View element's classes to match.
386
- */
387
- classes?: MatchClassPatterns;
388
- /**
389
- * View element's styles to match.
390
- */
391
- styles?: MatchStylePatterns;
392
- /**
393
- * View element's attributes to match.
394
- */
395
- attributes?: MatchAttributePatterns;
380
+ /**
381
+ * View element name to match.
382
+ */
383
+ name?: string | RegExp;
384
+ /**
385
+ * View element's classes to match.
386
+ */
387
+ classes?: MatchClassPatterns;
388
+ /**
389
+ * View element's styles to match.
390
+ */
391
+ styles?: MatchStylePatterns;
392
+ /**
393
+ * View element's attributes to match.
394
+ */
395
+ attributes?: MatchAttributePatterns;
396
396
  }
397
397
  /**
398
- * An object representing matched element parts.
399
- */
398
+ * An object representing matched element parts.
399
+ */
400
400
  export interface Match {
401
- /**
402
- * True if name of the element was matched.
403
- */
404
- name?: boolean;
405
- /**
406
- * Array of matching tuples: attribute name, and optional token for tokenized attributes.
407
- * Note that there could be multiple entries for the same attribute with different tokens (class names or style properties).
408
- */
409
- attributes?: Array<[string, string?]>;
401
+ /**
402
+ * True if name of the element was matched.
403
+ */
404
+ name?: boolean;
405
+ /**
406
+ * Array of matching tuples: attribute name, and optional token for tokenized attributes.
407
+ * Note that there could be multiple entries for the same attribute with different tokens (class names or style properties).
408
+ */
409
+ attributes?: Array<[string, string?]>;
410
410
  }
411
411
  /**
412
- * The result of {@link ~Matcher#match}.
413
- */
412
+ * The result of {@link ~Matcher#match}.
413
+ */
414
414
  export interface MatchResult {
415
- /**
416
- * Matched view element.
417
- */
418
- element: ViewElement;
419
- /**
420
- * Pattern that was used to find matched element.
421
- */
422
- pattern: MatcherFunctionPattern | MatcherObjectPattern;
423
- /**
424
- * An object representing matched element parts.
425
- */
426
- match: Match;
415
+ /**
416
+ * Matched view element.
417
+ */
418
+ element: ViewElement;
419
+ /**
420
+ * Pattern that was used to find matched element.
421
+ */
422
+ pattern: MatcherFunctionPattern | MatcherObjectPattern;
423
+ /**
424
+ * An object representing matched element parts.
425
+ */
426
+ match: Match;
427
427
  }
428
428
  export type MatchPropertyPatterns<ValuePattern = string | RegExp> = true | string | RegExp | Record<string, true | ValuePattern> | Array<string | RegExp | {
429
- key: string | RegExp;
430
- value: true | ValuePattern;
429
+ key: string | RegExp;
430
+ value: true | ValuePattern;
431
431
  }>;
432
432
  export type MatchAttributePatterns = MatchPropertyPatterns;
433
433
  export type MatchStylePatterns = MatchPropertyPatterns;
434
434
  export type MatchClassPatterns = MatchPropertyPatterns<never>;
435
435
  /**
436
- * @internal
437
- */
438
- export type NormalizedPropertyPattern = [
439
- true | string | RegExp,
440
- true | string | RegExp,
441
- (true | string | RegExp)?
442
- ];
443
- /**
444
- * The key-value matcher pattern is missing key or value. Both must be present.
445
- * Refer the documentation: {@link module:engine/view/matcher~MatcherPattern}.
446
- *
447
- * @param pattern Pattern with missing properties.
448
- * @error matcher-pattern-missing-key-or-value
449
- */
450
- /**
451
- * The key-value matcher pattern for `attributes` option is using deprecated `style` key.
452
- *
453
- * Use `styles` matcher pattern option instead:
454
- *
455
- * ```ts
456
- * // Instead of:
457
- * const pattern = {
458
- * attributes: {
459
- * key1: 'value1',
460
- * key2: 'value2',
461
- * style: /^border.*$/
462
- * }
463
- * }
464
- *
465
- * // Use:
466
- * const pattern = {
467
- * attributes: {
468
- * key1: 'value1',
469
- * key2: 'value2'
470
- * },
471
- * styles: /^border.*$/
472
- * }
473
- * ```
474
- *
475
- * Refer to the `#update-to-ckeditor-5-v2910` section in the `Update to v29.x` section in the
476
- * {@glink updating/guides/updating-from-older-versions updating from older versions} guide
477
- * and {@link module:engine/view/matcher~MatcherPattern} documentation.
478
- *
479
- * @param pattern Pattern with missing properties.
480
- * @error matcher-pattern-deprecated-attributes-style-key
481
- */
482
- /**
483
- * The key-value matcher pattern for `attributes` option is using deprecated `class` key.
484
- *
485
- * Use `classes` matcher pattern option instead:
486
- *
487
- * ```ts
488
- * // Instead of:
489
- * const pattern = {
490
- * attributes: {
491
- * key1: 'value1',
492
- * key2: 'value2',
493
- * class: 'foobar'
494
- * }
495
- * }
496
- *
497
- * // Use:
498
- * const pattern = {
499
- * attributes: {
500
- * key1: 'value1',
501
- * key2: 'value2'
502
- * },
503
- * classes: 'foobar'
504
- * }
505
- * ```
506
- *
507
- * Refer to the `#update-to-ckeditor-5-v2910` paragraph in the Update to v29.x guide in the
508
- * {@glink updating/guides/updating-from-older-versions updating from older versions} guide
509
- * and the {@link module:engine/view/matcher~MatcherPattern} documentation.
510
- *
511
- * @param pattern Pattern with missing properties.
512
- * @error matcher-pattern-deprecated-attributes-class-key
513
- */
436
+ * @internal
437
+ */
438
+ export type NormalizedPropertyPattern = [true | string | RegExp, true | string | RegExp, (true | string | RegExp)?];