@ckeditor/ckeditor5-html-support 35.1.0 → 35.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-html-support",
3
- "version": "35.1.0",
3
+ "version": "35.2.1",
4
4
  "description": "HTML Support feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -16,39 +16,39 @@
16
16
  ],
17
17
  "main": "src/index.js",
18
18
  "dependencies": {
19
- "ckeditor5": "^35.1.0",
19
+ "ckeditor5": "^35.2.1",
20
20
  "lodash-es": "^4.17.15"
21
21
  },
22
22
  "devDependencies": {
23
- "@ckeditor/ckeditor5-alignment": "^35.1.0",
24
- "@ckeditor/ckeditor5-basic-styles": "^35.1.0",
25
- "@ckeditor/ckeditor5-block-quote": "^35.1.0",
26
- "@ckeditor/ckeditor5-cloud-services": "^35.1.0",
27
- "@ckeditor/ckeditor5-code-block": "^35.1.0",
28
- "@ckeditor/ckeditor5-core": "^35.1.0",
29
- "@ckeditor/ckeditor5-dev-utils": "^30.0.0",
30
- "@ckeditor/ckeditor5-easy-image": "^35.1.0",
31
- "@ckeditor/ckeditor5-editor-classic": "^35.1.0",
32
- "@ckeditor/ckeditor5-engine": "^35.1.0",
33
- "@ckeditor/ckeditor5-enter": "^35.1.0",
34
- "@ckeditor/ckeditor5-essentials": "^35.1.0",
35
- "@ckeditor/ckeditor5-font": "^35.1.0",
36
- "@ckeditor/ckeditor5-heading": "^35.1.0",
37
- "@ckeditor/ckeditor5-highlight": "^35.1.0",
38
- "@ckeditor/ckeditor5-horizontal-line": "^35.1.0",
39
- "@ckeditor/ckeditor5-html-embed": "^35.1.0",
40
- "@ckeditor/ckeditor5-image": "^35.1.0",
41
- "@ckeditor/ckeditor5-indent": "^35.1.0",
42
- "@ckeditor/ckeditor5-link": "^35.1.0",
43
- "@ckeditor/ckeditor5-list": "^35.1.0",
44
- "@ckeditor/ckeditor5-media-embed": "^35.1.0",
45
- "@ckeditor/ckeditor5-page-break": "^35.1.0",
46
- "@ckeditor/ckeditor5-paragraph": "^35.1.0",
47
- "@ckeditor/ckeditor5-paste-from-office": "^35.1.0",
48
- "@ckeditor/ckeditor5-source-editing": "^35.1.0",
49
- "@ckeditor/ckeditor5-table": "^35.1.0",
50
- "@ckeditor/ckeditor5-theme-lark": "^35.1.0",
51
- "@ckeditor/ckeditor5-utils": "^35.1.0",
23
+ "@ckeditor/ckeditor5-alignment": "^35.2.1",
24
+ "@ckeditor/ckeditor5-basic-styles": "^35.2.1",
25
+ "@ckeditor/ckeditor5-block-quote": "^35.2.1",
26
+ "@ckeditor/ckeditor5-cloud-services": "^35.2.1",
27
+ "@ckeditor/ckeditor5-code-block": "^35.2.1",
28
+ "@ckeditor/ckeditor5-core": "^35.2.1",
29
+ "@ckeditor/ckeditor5-dev-utils": "^31.0.0",
30
+ "@ckeditor/ckeditor5-easy-image": "^35.2.1",
31
+ "@ckeditor/ckeditor5-editor-classic": "^35.2.1",
32
+ "@ckeditor/ckeditor5-engine": "^35.2.1",
33
+ "@ckeditor/ckeditor5-enter": "^35.2.1",
34
+ "@ckeditor/ckeditor5-essentials": "^35.2.1",
35
+ "@ckeditor/ckeditor5-font": "^35.2.1",
36
+ "@ckeditor/ckeditor5-heading": "^35.2.1",
37
+ "@ckeditor/ckeditor5-highlight": "^35.2.1",
38
+ "@ckeditor/ckeditor5-horizontal-line": "^35.2.1",
39
+ "@ckeditor/ckeditor5-html-embed": "^35.2.1",
40
+ "@ckeditor/ckeditor5-image": "^35.2.1",
41
+ "@ckeditor/ckeditor5-indent": "^35.2.1",
42
+ "@ckeditor/ckeditor5-link": "^35.2.1",
43
+ "@ckeditor/ckeditor5-list": "^35.2.1",
44
+ "@ckeditor/ckeditor5-media-embed": "^35.2.1",
45
+ "@ckeditor/ckeditor5-page-break": "^35.2.1",
46
+ "@ckeditor/ckeditor5-paragraph": "^35.2.1",
47
+ "@ckeditor/ckeditor5-paste-from-office": "^35.2.1",
48
+ "@ckeditor/ckeditor5-source-editing": "^35.2.1",
49
+ "@ckeditor/ckeditor5-table": "^35.2.1",
50
+ "@ckeditor/ckeditor5-theme-lark": "^35.2.1",
51
+ "@ckeditor/ckeditor5-utils": "^35.2.1",
52
52
  "webpack": "^5.58.1",
53
53
  "webpack-cli": "^4.9.0"
54
54
  },
package/src/datafilter.js CHANGED
@@ -102,6 +102,15 @@ export default class DataFilter extends Plugin {
102
102
  */
103
103
  this._allowedElements = new Set();
104
104
 
105
+ /**
106
+ * Disallowed element names by {@link module:html-support/datafilter~DataFilter#disallowElement} method.
107
+ *
108
+ * @readonly
109
+ * @private
110
+ * @member {Set.<String>} #_disallowedElements
111
+ */
112
+ this._disallowedElements = new Set();
113
+
105
114
  /**
106
115
  * Indicates if {@link module:engine/controller/datacontroller~DataController editor's data controller}
107
116
  * data has been already initialized.
@@ -142,21 +151,46 @@ export default class DataFilter extends Plugin {
142
151
  /**
143
152
  * Load a configuration of one or many elements, where their attributes should be allowed.
144
153
  *
154
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
155
+ *
145
156
  * @param {Array.<module:engine/view/matcher~MatcherPattern>} config Configuration of elements
146
157
  * that should have their attributes accepted in the editor.
147
158
  */
148
159
  loadAllowedConfig( config ) {
149
- this._loadConfig( config, pattern => this.allowAttributes( pattern ) );
160
+ for ( const pattern of config ) {
161
+ // MatcherPattern allows omitting `name` to widen the search of elements.
162
+ // Let's keep it consistent and match every element if a `name` has not been provided.
163
+ const elementName = pattern.name || /[\s\S]+/;
164
+ const rules = splitRules( pattern );
165
+
166
+ this.allowElement( elementName );
167
+
168
+ rules.forEach( pattern => this.allowAttributes( pattern ) );
169
+ }
150
170
  }
151
171
 
152
172
  /**
153
173
  * Load a configuration of one or many elements, where their attributes should be disallowed.
154
174
  *
175
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
176
+ *
155
177
  * @param {Array.<module:engine/view/matcher~MatcherPattern>} config Configuration of elements
156
178
  * that should have their attributes rejected from the editor.
157
179
  */
158
180
  loadDisallowedConfig( config ) {
159
- this._loadConfig( config, pattern => this.disallowAttributes( pattern ) );
181
+ for ( const pattern of config ) {
182
+ // MatcherPattern allows omitting `name` to widen the search of elements.
183
+ // Let's keep it consistent and match every element if a `name` has not been provided.
184
+ const elementName = pattern.name || /[\s\S]+/;
185
+ const rules = splitRules( pattern );
186
+
187
+ // Disallow element itself if there is no other rules.
188
+ if ( rules.length == 0 ) {
189
+ this.disallowElement( elementName );
190
+ } else {
191
+ rules.forEach( pattern => this.disallowAttributes( pattern ) );
192
+ }
193
+ }
160
194
  }
161
195
 
162
196
  /**
@@ -165,6 +199,8 @@ export default class DataFilter extends Plugin {
165
199
  * This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
166
200
  * to create data filter.
167
201
  *
202
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
203
+ *
168
204
  * @param {String|RegExp} viewName String or regular expression matching view name.
169
205
  */
170
206
  allowElement( viewName ) {
@@ -180,7 +216,15 @@ export default class DataFilter extends Plugin {
180
216
  // If the data has not been initialized yet, _registerElementsAfterInit() method will take care of
181
217
  // registering elements.
182
218
  if ( this._dataInitialized ) {
183
- this._fireRegisterEvent( definition );
219
+ // Defer registration to the next data pipeline data set so any disallow rules could be applied
220
+ // even if added after allow rule (disallowElement).
221
+ this.editor.data.once( 'set', () => {
222
+ this._fireRegisterEvent( definition );
223
+ }, {
224
+ // With the highest priority listener we are able to register elements right before
225
+ // running data conversion.
226
+ priority: priorities.get( 'highest' ) + 1
227
+ } );
184
228
  }
185
229
 
186
230
  // Reset cached map to recalculate it on the next usage.
@@ -188,6 +232,20 @@ export default class DataFilter extends Plugin {
188
232
  }
189
233
  }
190
234
 
235
+ /**
236
+ * Disallow the given element in the editor context.
237
+ *
238
+ * This method will only disallow elements described by the {@link module:html-support/dataschema~DataSchema} used
239
+ * to create data filter.
240
+ *
241
+ * @param {String|RegExp} viewName String or regular expression matching view name.
242
+ */
243
+ disallowElement( viewName ) {
244
+ for ( const definition of this._dataSchema.getDefinitionsForView( viewName, false ) ) {
245
+ this._disallowedElements.add( definition.view );
246
+ }
247
+ }
248
+
191
249
  /**
192
250
  * Allow the given attributes for view element allowed by {@link #allowElement} method.
193
251
  *
@@ -206,25 +264,6 @@ export default class DataFilter extends Plugin {
206
264
  this._disallowedAttributes.add( config );
207
265
  }
208
266
 
209
- /**
210
- * Batch load of the filtering configuration.
211
- *
212
- * @private
213
- * @param {Array.<module:engine/view/matcher~MatcherPattern>} config Filtering configuration.
214
- * @param {Function} handleAttributes Callback handling the way the attributes should be processed.
215
- */
216
- _loadConfig( config, handleAttributes ) {
217
- for ( const pattern of config ) {
218
- // MatcherPattern allows omitting `name` to widen the search of elements.
219
- // Let's keep it consistent and match every element if a `name` has not been provided.
220
- const elementName = pattern.name || /[\s\S]+/;
221
-
222
- this.allowElement( elementName );
223
-
224
- splitRules( pattern ).forEach( handleAttributes );
225
- }
226
- }
227
-
228
267
  /**
229
268
  * Processes all allowed and disallowed attributes on the view element by consuming them and returning the allowed ones.
230
269
  *
@@ -411,6 +450,10 @@ export default class DataFilter extends Plugin {
411
450
  * @param {module:html-support/dataschema~DataSchemaDefinition} definition
412
451
  */
413
452
  _fireRegisterEvent( definition ) {
453
+ if ( definition.view && this._disallowedElements.has( definition.view ) ) {
454
+ return;
455
+ }
456
+
414
457
  this.fire( definition.view ? `register:${ definition.view }` : 'register', definition );
415
458
  }
416
459
 
@@ -135,7 +135,7 @@ export default {
135
135
  view: 'tbody',
136
136
  modelSchema: {
137
137
  allowIn: 'htmlTable',
138
- isBlock: true
138
+ isBlock: false
139
139
  }
140
140
  },
141
141
  {
@@ -143,7 +143,7 @@ export default {
143
143
  view: 'thead',
144
144
  modelSchema: {
145
145
  allowIn: 'htmlTable',
146
- isBlock: true
146
+ isBlock: false
147
147
  }
148
148
  },
149
149
  {
@@ -151,7 +151,7 @@ export default {
151
151
  view: 'tfoot',
152
152
  modelSchema: {
153
153
  allowIn: 'htmlTable',
154
- isBlock: true
154
+ isBlock: false
155
155
  }
156
156
  },
157
157
  {
@@ -160,7 +160,7 @@ export default {
160
160
  modelSchema: {
161
161
  allowIn: 'htmlTable',
162
162
  allowChildren: '$text',
163
- isBlock: true
163
+ isBlock: false
164
164
  }
165
165
  },
166
166
  {
@@ -169,7 +169,7 @@ export default {
169
169
  modelSchema: {
170
170
  allowIn: 'htmlTable',
171
171
  allowChildren: 'col',
172
- isBlock: true
172
+ isBlock: false
173
173
  }
174
174
  },
175
175
  {
@@ -177,14 +177,15 @@ export default {
177
177
  view: 'col',
178
178
  modelSchema: {
179
179
  allowIn: 'htmlColgroup',
180
- isBlock: true
180
+ isBlock: false
181
181
  }
182
182
  },
183
183
  {
184
184
  model: 'htmlTr',
185
185
  view: 'tr',
186
186
  modelSchema: {
187
- allowIn: [ 'htmlTable', 'htmlThead', 'htmlTbody' ]
187
+ allowIn: [ 'htmlTable', 'htmlThead', 'htmlTbody' ],
188
+ isLimit: true
188
189
  }
189
190
  },
190
191
  // TODO can also include text.
@@ -193,7 +194,9 @@ export default {
193
194
  view: 'td',
194
195
  modelSchema: {
195
196
  allowIn: 'htmlTr',
196
- allowContentOf: '$container'
197
+ allowContentOf: '$container',
198
+ isLimit: true,
199
+ isBlock: false
197
200
  }
198
201
  },
199
202
  // TODO can also include text.
@@ -202,7 +205,9 @@ export default {
202
205
  view: 'th',
203
206
  modelSchema: {
204
207
  allowIn: 'htmlTr',
205
- allowContentOf: '$container'
208
+ allowContentOf: '$container',
209
+ isLimit: true,
210
+ isBlock: false
206
211
  }
207
212
  },
208
213
  // TODO can also include text.
@@ -211,7 +216,7 @@ export default {
211
216
  view: 'figure',
212
217
  modelSchema: {
213
218
  inheritAllFrom: '$container',
214
- isBlock: true
219
+ isBlock: false
215
220
  }
216
221
  },
217
222
  // TODO can also include other block elements.
@@ -221,7 +226,7 @@ export default {
221
226
  modelSchema: {
222
227
  allowIn: 'htmlFigure',
223
228
  allowChildren: '$text',
224
- isBlock: true
229
+ isBlock: false
225
230
  }
226
231
  },
227
232
  // TODO can also include text.
@@ -230,7 +235,7 @@ export default {
230
235
  view: 'address',
231
236
  modelSchema: {
232
237
  inheritAllFrom: '$container',
233
- isBlock: true
238
+ isBlock: false
234
239
  }
235
240
  },
236
241
  // TODO can also include text.
@@ -239,7 +244,7 @@ export default {
239
244
  view: 'aside',
240
245
  modelSchema: {
241
246
  inheritAllFrom: '$container',
242
- isBlock: true
247
+ isBlock: false
243
248
  }
244
249
  },
245
250
  // TODO can also include text.
@@ -248,7 +253,7 @@ export default {
248
253
  view: 'main',
249
254
  modelSchema: {
250
255
  inheritAllFrom: '$container',
251
- isBlock: true
256
+ isBlock: false
252
257
  }
253
258
  },
254
259
  // TODO can also include text.
@@ -257,7 +262,7 @@ export default {
257
262
  view: 'details',
258
263
  modelSchema: {
259
264
  inheritAllFrom: '$container',
260
- isBlock: true
265
+ isBlock: false
261
266
  }
262
267
  },
263
268
  {
@@ -266,7 +271,7 @@ export default {
266
271
  modelSchema: {
267
272
  allowChildren: '$text',
268
273
  allowIn: 'htmlDetails',
269
- isBlock: true
274
+ isBlock: false
270
275
  }
271
276
  },
272
277
  {
@@ -283,7 +288,7 @@ export default {
283
288
  view: 'fieldset',
284
289
  modelSchema: {
285
290
  inheritAllFrom: '$container',
286
- isBlock: true
291
+ isBlock: false
287
292
  }
288
293
  },
289
294
  // TODO can also include h1-h6.
@@ -301,7 +306,7 @@ export default {
301
306
  view: 'header',
302
307
  modelSchema: {
303
308
  inheritAllFrom: '$container',
304
- isBlock: true
309
+ isBlock: false
305
310
  }
306
311
  },
307
312
  // TODO can also include text.
@@ -310,7 +315,7 @@ export default {
310
315
  view: 'footer',
311
316
  modelSchema: {
312
317
  inheritAllFrom: '$container',
313
- isBlock: true
318
+ isBlock: false
314
319
  }
315
320
  },
316
321
  // TODO can also include text.
@@ -334,7 +339,7 @@ export default {
334
339
  'htmlH5',
335
340
  'htmlH6'
336
341
  ],
337
- isBlock: true
342
+ isBlock: false
338
343
  }
339
344
  },
340
345
  {
@@ -384,7 +389,7 @@ export default {
384
389
  modelSchema: {
385
390
  allowWhere: '$container',
386
391
  allowChildren: [ '$htmlList', 'htmlLi' ],
387
- isBlock: true
392
+ isBlock: false
388
393
  }
389
394
  },
390
395
  {
@@ -422,7 +427,7 @@ export default {
422
427
  modelSchema: {
423
428
  allowIn: '$htmlList',
424
429
  allowChildren: '$text',
425
- isBlock: true
430
+ isBlock: false
426
431
  }
427
432
  },
428
433
  {
@@ -437,7 +442,7 @@ export default {
437
442
  view: 'article',
438
443
  modelSchema: {
439
444
  inheritAllFrom: '$container',
440
- isBlock: true
445
+ isBlock: false
441
446
  }
442
447
  },
443
448
  {
@@ -445,7 +450,7 @@ export default {
445
450
  view: 'section',
446
451
  modelSchema: {
447
452
  inheritAllFrom: '$container',
448
- isBlock: true
453
+ isBlock: false
449
454
  }
450
455
  },
451
456
  // TODO can also include text.
@@ -454,7 +459,7 @@ export default {
454
459
  view: 'nav',
455
460
  modelSchema: {
456
461
  inheritAllFrom: '$container',
457
- isBlock: true
462
+ isBlock: false
458
463
  }
459
464
  },
460
465
  {
@@ -463,7 +468,7 @@ export default {
463
468
  modelSchema: {
464
469
  allowWhere: '$container',
465
470
  allowChildren: [ 'htmlDt', 'htmlDd' ],
466
- isBlock: true
471
+ isBlock: false
467
472
  }
468
473
  },
469
474
  {
@@ -471,7 +476,7 @@ export default {
471
476
  view: 'dt',
472
477
  modelSchema: {
473
478
  allowChildren: '$block',
474
- isBlock: true
479
+ isBlock: false
475
480
  }
476
481
  },
477
482
  {
@@ -479,7 +484,7 @@ export default {
479
484
  view: 'dd',
480
485
  modelSchema: {
481
486
  allowChildren: '$block',
482
- isBlock: true
487
+ isBlock: false
483
488
  }
484
489
  },
485
490
  {
@@ -487,7 +492,7 @@ export default {
487
492
  view: 'center',
488
493
  modelSchema: {
489
494
  inheritAllFrom: '$container',
490
- isBlock: true
495
+ isBlock: false
491
496
  }
492
497
  }
493
498
  ],