@ckeditor/ckeditor5-html-support 35.0.1 → 35.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-html-support",
3
- "version": "35.0.1",
3
+ "version": "35.2.0",
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.0.1",
19
+ "ckeditor5": "^35.2.0",
20
20
  "lodash-es": "^4.17.15"
21
21
  },
22
22
  "devDependencies": {
23
- "@ckeditor/ckeditor5-alignment": "^35.0.1",
24
- "@ckeditor/ckeditor5-basic-styles": "^35.0.1",
25
- "@ckeditor/ckeditor5-block-quote": "^35.0.1",
26
- "@ckeditor/ckeditor5-cloud-services": "^35.0.1",
27
- "@ckeditor/ckeditor5-code-block": "^35.0.1",
28
- "@ckeditor/ckeditor5-core": "^35.0.1",
29
- "@ckeditor/ckeditor5-dev-utils": "^30.0.0",
30
- "@ckeditor/ckeditor5-easy-image": "^35.0.1",
31
- "@ckeditor/ckeditor5-editor-classic": "^35.0.1",
32
- "@ckeditor/ckeditor5-engine": "^35.0.1",
33
- "@ckeditor/ckeditor5-enter": "^35.0.1",
34
- "@ckeditor/ckeditor5-essentials": "^35.0.1",
35
- "@ckeditor/ckeditor5-font": "^35.0.1",
36
- "@ckeditor/ckeditor5-heading": "^35.0.1",
37
- "@ckeditor/ckeditor5-highlight": "^35.0.1",
38
- "@ckeditor/ckeditor5-horizontal-line": "^35.0.1",
39
- "@ckeditor/ckeditor5-html-embed": "^35.0.1",
40
- "@ckeditor/ckeditor5-image": "^35.0.1",
41
- "@ckeditor/ckeditor5-indent": "^35.0.1",
42
- "@ckeditor/ckeditor5-link": "^35.0.1",
43
- "@ckeditor/ckeditor5-list": "^35.0.1",
44
- "@ckeditor/ckeditor5-media-embed": "^35.0.1",
45
- "@ckeditor/ckeditor5-page-break": "^35.0.1",
46
- "@ckeditor/ckeditor5-paragraph": "^35.0.1",
47
- "@ckeditor/ckeditor5-paste-from-office": "^35.0.1",
48
- "@ckeditor/ckeditor5-source-editing": "^35.0.1",
49
- "@ckeditor/ckeditor5-table": "^35.0.1",
50
- "@ckeditor/ckeditor5-theme-lark": "^35.0.1",
51
- "@ckeditor/ckeditor5-utils": "^35.0.1",
23
+ "@ckeditor/ckeditor5-alignment": "^35.2.0",
24
+ "@ckeditor/ckeditor5-basic-styles": "^35.2.0",
25
+ "@ckeditor/ckeditor5-block-quote": "^35.2.0",
26
+ "@ckeditor/ckeditor5-cloud-services": "^35.2.0",
27
+ "@ckeditor/ckeditor5-code-block": "^35.2.0",
28
+ "@ckeditor/ckeditor5-core": "^35.2.0",
29
+ "@ckeditor/ckeditor5-dev-utils": "^31.0.0",
30
+ "@ckeditor/ckeditor5-easy-image": "^35.2.0",
31
+ "@ckeditor/ckeditor5-editor-classic": "^35.2.0",
32
+ "@ckeditor/ckeditor5-engine": "^35.2.0",
33
+ "@ckeditor/ckeditor5-enter": "^35.2.0",
34
+ "@ckeditor/ckeditor5-essentials": "^35.2.0",
35
+ "@ckeditor/ckeditor5-font": "^35.2.0",
36
+ "@ckeditor/ckeditor5-heading": "^35.2.0",
37
+ "@ckeditor/ckeditor5-highlight": "^35.2.0",
38
+ "@ckeditor/ckeditor5-horizontal-line": "^35.2.0",
39
+ "@ckeditor/ckeditor5-html-embed": "^35.2.0",
40
+ "@ckeditor/ckeditor5-image": "^35.2.0",
41
+ "@ckeditor/ckeditor5-indent": "^35.2.0",
42
+ "@ckeditor/ckeditor5-link": "^35.2.0",
43
+ "@ckeditor/ckeditor5-list": "^35.2.0",
44
+ "@ckeditor/ckeditor5-media-embed": "^35.2.0",
45
+ "@ckeditor/ckeditor5-page-break": "^35.2.0",
46
+ "@ckeditor/ckeditor5-paragraph": "^35.2.0",
47
+ "@ckeditor/ckeditor5-paste-from-office": "^35.2.0",
48
+ "@ckeditor/ckeditor5-source-editing": "^35.2.0",
49
+ "@ckeditor/ckeditor5-table": "^35.2.0",
50
+ "@ckeditor/ckeditor5-theme-lark": "^35.2.0",
51
+ "@ckeditor/ckeditor5-utils": "^35.2.0",
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,14 +160,32 @@ export default {
160
160
  modelSchema: {
161
161
  allowIn: 'htmlTable',
162
162
  allowChildren: '$text',
163
- isBlock: true
163
+ isBlock: false
164
+ }
165
+ },
166
+ {
167
+ model: 'htmlColgroup',
168
+ view: 'colgroup',
169
+ modelSchema: {
170
+ allowIn: 'htmlTable',
171
+ allowChildren: 'col',
172
+ isBlock: false
173
+ }
174
+ },
175
+ {
176
+ model: 'htmlCol',
177
+ view: 'col',
178
+ modelSchema: {
179
+ allowIn: 'htmlColgroup',
180
+ isBlock: false
164
181
  }
165
182
  },
166
183
  {
167
184
  model: 'htmlTr',
168
185
  view: 'tr',
169
186
  modelSchema: {
170
- allowIn: [ 'htmlTable', 'htmlThead', 'htmlTbody' ]
187
+ allowIn: [ 'htmlTable', 'htmlThead', 'htmlTbody' ],
188
+ isLimit: true
171
189
  }
172
190
  },
173
191
  // TODO can also include text.
@@ -176,7 +194,9 @@ export default {
176
194
  view: 'td',
177
195
  modelSchema: {
178
196
  allowIn: 'htmlTr',
179
- allowContentOf: '$container'
197
+ allowContentOf: '$container',
198
+ isLimit: true,
199
+ isBlock: false
180
200
  }
181
201
  },
182
202
  // TODO can also include text.
@@ -185,7 +205,9 @@ export default {
185
205
  view: 'th',
186
206
  modelSchema: {
187
207
  allowIn: 'htmlTr',
188
- allowContentOf: '$container'
208
+ allowContentOf: '$container',
209
+ isLimit: true,
210
+ isBlock: false
189
211
  }
190
212
  },
191
213
  // TODO can also include text.
@@ -194,7 +216,7 @@ export default {
194
216
  view: 'figure',
195
217
  modelSchema: {
196
218
  inheritAllFrom: '$container',
197
- isBlock: true
219
+ isBlock: false
198
220
  }
199
221
  },
200
222
  // TODO can also include other block elements.
@@ -204,7 +226,7 @@ export default {
204
226
  modelSchema: {
205
227
  allowIn: 'htmlFigure',
206
228
  allowChildren: '$text',
207
- isBlock: true
229
+ isBlock: false
208
230
  }
209
231
  },
210
232
  // TODO can also include text.
@@ -213,7 +235,7 @@ export default {
213
235
  view: 'address',
214
236
  modelSchema: {
215
237
  inheritAllFrom: '$container',
216
- isBlock: true
238
+ isBlock: false
217
239
  }
218
240
  },
219
241
  // TODO can also include text.
@@ -222,7 +244,7 @@ export default {
222
244
  view: 'aside',
223
245
  modelSchema: {
224
246
  inheritAllFrom: '$container',
225
- isBlock: true
247
+ isBlock: false
226
248
  }
227
249
  },
228
250
  // TODO can also include text.
@@ -231,7 +253,7 @@ export default {
231
253
  view: 'main',
232
254
  modelSchema: {
233
255
  inheritAllFrom: '$container',
234
- isBlock: true
256
+ isBlock: false
235
257
  }
236
258
  },
237
259
  // TODO can also include text.
@@ -240,7 +262,7 @@ export default {
240
262
  view: 'details',
241
263
  modelSchema: {
242
264
  inheritAllFrom: '$container',
243
- isBlock: true
265
+ isBlock: false
244
266
  }
245
267
  },
246
268
  {
@@ -249,7 +271,7 @@ export default {
249
271
  modelSchema: {
250
272
  allowChildren: '$text',
251
273
  allowIn: 'htmlDetails',
252
- isBlock: true
274
+ isBlock: false
253
275
  }
254
276
  },
255
277
  {
@@ -266,7 +288,7 @@ export default {
266
288
  view: 'fieldset',
267
289
  modelSchema: {
268
290
  inheritAllFrom: '$container',
269
- isBlock: true
291
+ isBlock: false
270
292
  }
271
293
  },
272
294
  // TODO can also include h1-h6.
@@ -284,7 +306,7 @@ export default {
284
306
  view: 'header',
285
307
  modelSchema: {
286
308
  inheritAllFrom: '$container',
287
- isBlock: true
309
+ isBlock: false
288
310
  }
289
311
  },
290
312
  // TODO can also include text.
@@ -293,7 +315,7 @@ export default {
293
315
  view: 'footer',
294
316
  modelSchema: {
295
317
  inheritAllFrom: '$container',
296
- isBlock: true
318
+ isBlock: false
297
319
  }
298
320
  },
299
321
  // TODO can also include text.
@@ -317,7 +339,7 @@ export default {
317
339
  'htmlH5',
318
340
  'htmlH6'
319
341
  ],
320
- isBlock: true
342
+ isBlock: false
321
343
  }
322
344
  },
323
345
  {
@@ -367,7 +389,7 @@ export default {
367
389
  modelSchema: {
368
390
  allowWhere: '$container',
369
391
  allowChildren: [ '$htmlList', 'htmlLi' ],
370
- isBlock: true
392
+ isBlock: false
371
393
  }
372
394
  },
373
395
  {
@@ -405,7 +427,7 @@ export default {
405
427
  modelSchema: {
406
428
  allowIn: '$htmlList',
407
429
  allowChildren: '$text',
408
- isBlock: true
430
+ isBlock: false
409
431
  }
410
432
  },
411
433
  {
@@ -420,7 +442,7 @@ export default {
420
442
  view: 'article',
421
443
  modelSchema: {
422
444
  inheritAllFrom: '$container',
423
- isBlock: true
445
+ isBlock: false
424
446
  }
425
447
  },
426
448
  {
@@ -428,7 +450,7 @@ export default {
428
450
  view: 'section',
429
451
  modelSchema: {
430
452
  inheritAllFrom: '$container',
431
- isBlock: true
453
+ isBlock: false
432
454
  }
433
455
  },
434
456
  // TODO can also include text.
@@ -437,7 +459,7 @@ export default {
437
459
  view: 'nav',
438
460
  modelSchema: {
439
461
  inheritAllFrom: '$container',
440
- isBlock: true
462
+ isBlock: false
441
463
  }
442
464
  },
443
465
  {
@@ -446,7 +468,7 @@ export default {
446
468
  modelSchema: {
447
469
  allowWhere: '$container',
448
470
  allowChildren: [ 'htmlDt', 'htmlDd' ],
449
- isBlock: true
471
+ isBlock: false
450
472
  }
451
473
  },
452
474
  {
@@ -454,7 +476,7 @@ export default {
454
476
  view: 'dt',
455
477
  modelSchema: {
456
478
  allowChildren: '$block',
457
- isBlock: true
479
+ isBlock: false
458
480
  }
459
481
  },
460
482
  {
@@ -462,7 +484,7 @@ export default {
462
484
  view: 'dd',
463
485
  modelSchema: {
464
486
  allowChildren: '$block',
465
- isBlock: true
487
+ isBlock: false
466
488
  }
467
489
  },
468
490
  {
@@ -470,7 +492,7 @@ export default {
470
492
  view: 'center',
471
493
  modelSchema: {
472
494
  inheritAllFrom: '$container',
473
- isBlock: true
495
+ isBlock: false
474
496
  }
475
497
  }
476
498
  ],