@ckeditor/ckeditor5-engine 41.0.0 → 41.1.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-engine",
3
- "version": "41.0.0",
3
+ "version": "41.1.0",
4
4
  "description": "The editing engine of CKEditor 5 – the best browser-based rich text editor.",
5
5
  "keywords": [
6
6
  "wysiwyg",
@@ -24,7 +24,7 @@
24
24
  "type": "module",
25
25
  "main": "src/index.js",
26
26
  "dependencies": {
27
- "@ckeditor/ckeditor5-utils": "41.0.0",
27
+ "@ckeditor/ckeditor5-utils": "41.1.0",
28
28
  "lodash-es": "4.17.21"
29
29
  },
30
30
  "author": "CKSource (http://cksource.com/)",
@@ -194,6 +194,7 @@ export default class DataController extends DataController_base {
194
194
  */
195
195
  set(data: string | Record<string, string>, options?: {
196
196
  batchType?: BatchType;
197
+ [key: string]: unknown;
197
198
  }): void;
198
199
  /**
199
200
  * Returns the data parsed by the {@link #processor data processor} and then converted by upcast converters
@@ -14,6 +14,7 @@ import ModelElement from '../model/element.js';
14
14
  import ModelPosition from '../model/position.js';
15
15
  import ViewAttributeElement from '../view/attributeelement.js';
16
16
  import ConversionHelpers from './conversionhelpers.js';
17
+ import StylesMap from '../view/stylesmap.js';
17
18
  import { CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
18
19
  import { cloneDeep } from 'lodash-es';
19
20
  /**
@@ -1353,15 +1354,24 @@ function changeAttribute(attributeCreator) {
1353
1354
  // First remove the old attribute if there was one.
1354
1355
  if (data.attributeOldValue !== null && oldAttribute) {
1355
1356
  if (oldAttribute.key == 'class') {
1356
- const classes = toArray(oldAttribute.value);
1357
+ const classes = typeof oldAttribute.value == 'string' ? oldAttribute.value.split(/\s+/) : oldAttribute.value;
1357
1358
  for (const className of classes) {
1358
1359
  viewWriter.removeClass(className, viewElement);
1359
1360
  }
1360
1361
  }
1361
1362
  else if (oldAttribute.key == 'style') {
1362
- const keys = Object.keys(oldAttribute.value);
1363
- for (const key of keys) {
1364
- viewWriter.removeStyle(key, viewElement);
1363
+ if (typeof oldAttribute.value == 'string') {
1364
+ const styles = new StylesMap(viewWriter.document.stylesProcessor);
1365
+ styles.setTo(oldAttribute.value);
1366
+ for (const [key] of styles.getStylesEntries()) {
1367
+ viewWriter.removeStyle(key, viewElement);
1368
+ }
1369
+ }
1370
+ else {
1371
+ const keys = Object.keys(oldAttribute.value);
1372
+ for (const key of keys) {
1373
+ viewWriter.removeStyle(key, viewElement);
1374
+ }
1365
1375
  }
1366
1376
  }
1367
1377
  else {
@@ -1371,15 +1381,24 @@ function changeAttribute(attributeCreator) {
1371
1381
  // Then set the new attribute.
1372
1382
  if (data.attributeNewValue !== null && newAttribute) {
1373
1383
  if (newAttribute.key == 'class') {
1374
- const classes = toArray(newAttribute.value);
1384
+ const classes = typeof newAttribute.value == 'string' ? newAttribute.value.split(/\s+/) : newAttribute.value;
1375
1385
  for (const className of classes) {
1376
1386
  viewWriter.addClass(className, viewElement);
1377
1387
  }
1378
1388
  }
1379
1389
  else if (newAttribute.key == 'style') {
1380
- const keys = Object.keys(newAttribute.value);
1381
- for (const key of keys) {
1382
- viewWriter.setStyle(key, newAttribute.value[key], viewElement);
1390
+ if (typeof newAttribute.value == 'string') {
1391
+ const styles = new StylesMap(viewWriter.document.stylesProcessor);
1392
+ styles.setTo(newAttribute.value);
1393
+ for (const [key, value] of styles.getStylesEntries()) {
1394
+ viewWriter.setStyle(key, value, viewElement);
1395
+ }
1396
+ }
1397
+ else {
1398
+ const keys = Object.keys(newAttribute.value);
1399
+ for (const key of keys) {
1400
+ viewWriter.setStyle(key, newAttribute.value[key], viewElement);
1401
+ }
1383
1402
  }
1384
1403
  }
1385
1404
  else {
@@ -776,15 +776,15 @@ function normalizeViewAttributeKeyValueConfig(config) {
776
776
  config.view = { key: config.view };
777
777
  }
778
778
  const key = config.view.key;
779
+ const value = typeof config.view.value == 'undefined' ? /[\s\S]*/ : config.view.value;
779
780
  let normalized;
780
781
  if (key == 'class' || key == 'style') {
781
782
  const keyName = key == 'class' ? 'classes' : 'styles';
782
783
  normalized = {
783
- [keyName]: config.view.value
784
+ [keyName]: value
784
785
  };
785
786
  }
786
787
  else {
787
- const value = typeof config.view.value == 'undefined' ? /[\s\S]*/ : config.view.value;
788
788
  normalized = {
789
789
  attributes: {
790
790
  [key]: value
@@ -312,7 +312,7 @@ export default class StylesMap {
312
312
  /**
313
313
  * Returns normalized styles entries for further processing.
314
314
  */
315
- private _getStylesEntries;
315
+ getStylesEntries(): Array<PropertyDescriptor>;
316
316
  /**
317
317
  * Removes empty objects upon removing an entry from internal object.
318
318
  */
@@ -190,7 +190,7 @@ export default class StylesMap {
190
190
  if (this.isEmpty) {
191
191
  return '';
192
192
  }
193
- return this._getStylesEntries()
193
+ return this.getStylesEntries()
194
194
  .map(arr => arr.join(':'))
195
195
  .sort()
196
196
  .join(';') + ';';
@@ -290,7 +290,7 @@ export default class StylesMap {
290
290
  if (expand) {
291
291
  return this._styleProcessor.getStyleNames(this._styles);
292
292
  }
293
- const entries = this._getStylesEntries();
293
+ const entries = this.getStylesEntries();
294
294
  return entries.map(([key]) => key);
295
295
  }
296
296
  /**
@@ -302,7 +302,7 @@ export default class StylesMap {
302
302
  /**
303
303
  * Returns normalized styles entries for further processing.
304
304
  */
305
- _getStylesEntries() {
305
+ getStylesEntries() {
306
306
  const parsed = [];
307
307
  const keys = Object.keys(this._styles);
308
308
  for (const key of keys) {