diff --git a/src/conversion/viewconsumable.js b/src/conversion/viewconsumable.js index ce6c3752b..fd66a696f 100644 --- a/src/conversion/viewconsumable.js +++ b/src/conversion/viewconsumable.js @@ -72,9 +72,9 @@ export default class ViewConsumable { * @param {module:engine/view/element~Element|module:engine/view/text~Text|module:engine/view/documentfragment~DocumentFragment} element * @param {Object} [consumables] Used only if first parameter is {@link module:engine/view/element~Element view element} instance. * @param {Boolean} consumables.name If set to true element's name will be included. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names. - * @param {String|Array.} consumables.class Class name or array of class names. - * @param {String|Array.} consumables.style Style name or array of style names. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names. + * @param {String|Array.} consumables.classes Class name or array of class names. + * @param {String|Array.} consumables.styles Style name or array of style names. */ add( element, consumables ) { let elementConsumables; @@ -120,9 +120,9 @@ export default class ViewConsumable { * @param {module:engine/view/element~Element|module:engine/view/text~Text|module:engine/view/documentfragment~DocumentFragment} element * @param {Object} [consumables] Used only if first parameter is {@link module:engine/view/element~Element view element} instance. * @param {Boolean} consumables.name If set to true element's name will be included. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names. - * @param {String|Array.} consumables.class Class name or array of class names. - * @param {String|Array.} consumables.style Style name or array of style names. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names. + * @param {String|Array.} consumables.classes Class name or array of class names. + * @param {String|Array.} consumables.styles Style name or array of style names. * @returns {Boolean|null} Returns `true` when all items included in method's call can be consumed. Returns `false` * when first already consumed item is found and `null` when first non-consumable item is found. */ @@ -164,9 +164,9 @@ export default class ViewConsumable { * @param {module:engine/view/element~Element|module:engine/view/text~Text|module:engine/view/documentfragment~DocumentFragment} element * @param {Object} [consumables] Used only if first parameter is {@link module:engine/view/element~Element view element} instance. * @param {Boolean} consumables.name If set to true element's name will be included. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names. - * @param {String|Array.} consumables.class Class name or array of class names. - * @param {String|Array.} consumables.style Style name or array of style names. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names. + * @param {String|Array.} consumables.classes Class name or array of class names. + * @param {String|Array.} consumables.styles Style name or array of style names. * @returns {Boolean} Returns `true` when all items included in method's call can be consumed, * otherwise returns `false`. */ @@ -210,9 +210,9 @@ export default class ViewConsumable { * @param {module:engine/view/element~Element|module:engine/view/text~Text|module:engine/view/documentfragment~DocumentFragment} element * @param {Object} [consumables] Used only if first parameter is {@link module:engine/view/element~Element view element} instance. * @param {Boolean} consumables.name If set to true element's name will be included. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names. - * @param {String|Array.} consumables.class Class name or array of class names. - * @param {String|Array.} consumables.style Style name or array of style names. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names. + * @param {String|Array.} consumables.classes Class name or array of class names. + * @param {String|Array.} consumables.styles Style name or array of style names. */ revert( element, consumables ) { const elementConsumables = this._consumables.get( element ); @@ -337,13 +337,7 @@ class ViewElementConsumables { this._consumables = { attributes: new Map(), styles: new Map(), - get style() { - return this.styles; - }, - classes: new Map(), - get class() { - return this.classes; - } + classes: new Map() }; } @@ -364,9 +358,9 @@ class ViewElementConsumables { * * @param {Object} consumables Object describing which parts of the element can be consumed. * @param {Boolean} consumables.name If set to `true` element's name will be added as consumable. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names to add as consumable. - * @param {String|Array.} consumables.class Class name or array of class names to add as consumable. - * @param {String|Array.} consumables.style Style name or array of style names to add as consumable. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names to add as consumable. + * @param {String|Array.} consumables.classes Class name or array of class names to add as consumable. + * @param {String|Array.} consumables.styles Style name or array of style names to add as consumable. */ add( consumables ) { if ( consumables.name ) { @@ -394,9 +388,9 @@ class ViewElementConsumables { * * @param {Object} consumables Object describing which parts of the element should be tested. * @param {Boolean} consumables.name If set to `true` element's name will be tested. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names to test. - * @param {String|Array.} consumables.class Class name or array of class names to test. - * @param {String|Array.} consumables.style Style name or array of style names to test. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names to test. + * @param {String|Array.} consumables.classes Class name or array of class names to test. + * @param {String|Array.} consumables.styles Style name or array of style names to test. * @returns {Boolean|null} `true` when all tested items can be consumed, `null` when even one of the items * was never marked for consumption and `false` when even one of the items was already consumed. */ @@ -434,9 +428,9 @@ class ViewElementConsumables { * * @param {Object} consumables Object describing which parts of the element should be consumed. * @param {Boolean} consumables.name If set to `true` element's name will be consumed. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names to consume. - * @param {String|Array.} consumables.class Class name or array of class names to consume. - * @param {String|Array.} consumables.style Style name or array of style names to consume. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names to consume. + * @param {String|Array.} consumables.classes Class name or array of class names to consume. + * @param {String|Array.} consumables.styles Style name or array of style names to consume. */ consume( consumables ) { if ( consumables.name ) { @@ -463,9 +457,9 @@ class ViewElementConsumables { * * @param {Object} consumables Object describing which parts of the element should be reverted. * @param {Boolean} consumables.name If set to `true` element's name will be reverted. - * @param {String|Array.} consumables.attribute Attribute name or array of attribute names to revert. - * @param {String|Array.} consumables.class Class name or array of class names to revert. - * @param {String|Array.} consumables.style Style name or array of style names to revert. + * @param {String|Array.} consumables.attributes Attribute name or array of attribute names to revert. + * @param {String|Array.} consumables.classes Class name or array of class names to revert. + * @param {String|Array.} consumables.styles Style name or array of style names to revert. */ revert( consumables ) { if ( consumables.name ) { @@ -486,7 +480,7 @@ class ViewElementConsumables { * type is provided - it should be handled separately by providing actual style/class type. * * @private - * @param {String} type Type of the consumable item: `attribute`, `class` or `style`. + * @param {String} type Type of the consumable item: `attributes`, `classes` or `styles`. * @param {String|Array.} item Consumable item or array of items. */ _add( type, item ) { @@ -520,7 +514,7 @@ class ViewElementConsumables { * Helper method that tests consumables of a given type: attribute, class or style. * * @private - * @param {String} type Type of the consumable item: `attribute`, `class` or `style`. + * @param {String} type Type of the consumable item: `attributes`, `classes` or `styles`. * @param {String|Array.} item Consumable item or array of items. * @returns {Boolean|null} Returns `true` if all items can be consumed, `null` when one of the items cannot be * consumed and `false` when one of the items is already consumed. @@ -531,8 +525,10 @@ class ViewElementConsumables { for ( const name of items ) { if ( type === 'attributes' && ( name === 'class' || name === 'style' ) ) { + const consumableName = name == 'class' ? 'classes' : 'styles'; + // Check all classes/styles if class/style attribute is tested. - const value = this._test( name, [ ...this._consumables[ name ].keys() ] ); + const value = this._test( consumableName, [ ...this._consumables[ consumableName ].keys() ] ); if ( value !== true ) { return value; @@ -557,7 +553,7 @@ class ViewElementConsumables { * Helper method that consumes items of a given type: attribute, class or style. * * @private - * @param {String} type Type of the consumable item: `attribute`, `class` or `style`. + * @param {String} type Type of the consumable item: `attributes`, `classes` or `styles`. * @param {String|Array.} item Consumable item or array of items. */ _consume( type, item ) { @@ -566,8 +562,10 @@ class ViewElementConsumables { for ( const name of items ) { if ( type === 'attributes' && ( name === 'class' || name === 'style' ) ) { + const consumableName = name == 'class' ? 'classes' : 'styles'; + // If class or style is provided for consumption - consume them all. - this._consume( name, [ ...this._consumables[ name ].keys() ] ); + this._consume( consumableName, [ ...this._consumables[ consumableName ].keys() ] ); } else { consumables.set( name, false ); } @@ -578,7 +576,7 @@ class ViewElementConsumables { * Helper method that reverts items of a given type: attribute, class or style. * * @private - * @param {String} type Type of the consumable item: `attribute`, `class` or , `style`. + * @param {String} type Type of the consumable item: `attributes`, `classes` or , `styles`. * @param {String|Array.} item Consumable item or array of items. */ _revert( type, item ) { @@ -587,8 +585,10 @@ class ViewElementConsumables { for ( const name of items ) { if ( type === 'attributes' && ( name === 'class' || name === 'style' ) ) { + const consumableName = name == 'class' ? 'classes' : 'styles'; + // If class or style is provided for reverting - revert them all. - this._revert( name, [ ...this._consumables[ name ].keys() ] ); + this._revert( consumableName, [ ...this._consumables[ consumableName ].keys() ] ); } else { const value = consumables.get( name );