@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.
- package/README.md +1 -1
- package/package.json +24 -23
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +62 -109
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +499 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +177 -0
- package/src/conversion/viewconsumable.js +157 -162
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +105 -0
- package/src/index.js +1 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +245 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +812 -0
- package/src/model/model.js +59 -30
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +15 -15
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +255 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +726 -0
- package/src/model/writer.js +6 -4
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/datatransfer.js +24 -27
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +150 -0
- package/src/view/documentfragment.js +40 -81
- package/src/view/documentselection.d.ts +219 -0
- package/src/view/documentselection.js +75 -121
- package/src/view/domconverter.d.ts +620 -0
- package/src/view/domconverter.js +159 -276
- package/src/view/downcastwriter.d.ts +804 -0
- package/src/view/downcastwriter.js +336 -380
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +466 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +160 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +46 -0
- package/src/view/observer/fakeselectionobserver.js +2 -15
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +67 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +143 -0
- package/src/view/observer/selectionobserver.js +9 -99
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +401 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +28 -62
- package/src/view/upcastwriter.d.ts +328 -0
- package/src/view/upcastwriter.js +124 -134
- package/src/view/view.d.ts +327 -0
- package/src/view/view.js +79 -150
package/src/view/matcher.js
CHANGED
|
@@ -12,53 +12,41 @@ export default class Matcher {
|
|
|
12
12
|
/**
|
|
13
13
|
* Creates new instance of Matcher.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
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
|
-
*
|
|
30
|
-
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* // String.
|
|
26
|
+
* matcher.add( 'div' );
|
|
31
27
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
28
|
+
* // Regular expression.
|
|
29
|
+
* matcher.add( /^\w/ );
|
|
34
30
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
-
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* matcher.add( 'div', { classes: 'foobar' } );
|
|
43
|
+
* ```
|
|
45
44
|
*
|
|
46
|
-
* @param
|
|
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
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
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
|
|
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
|
|
123
|
-
* @returns
|
|
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
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
|
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
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
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
|
|
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
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
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
|
|
505
|
+
* @param pattern Pattern with missing properties.
|
|
477
506
|
* @error matcher-pattern-deprecated-attributes-class-key
|
|
478
507
|
*/
|