ViewElementConsumables
This is a private helper-class for ViewConsumable. It represents and manipulates consumable parts of a single ViewElement.
Properties
element : ViewElementreadonlymodule:engine/conversion/viewconsumable~ViewElementConsumables#element_attributes : Map<string, boolean | Map<string, boolean>>privatereadonlymodule:engine/conversion/viewconsumable~ViewElementConsumables#_attributesA map of element's consumables.
- For plain attributes the value is a boolean indicating whether the attribute is available to consume.
- For token based attributes (like class list and style) the value is a map of tokens to booleans indicating whether the token is available to consume on the given attribute.
_canConsumeName : null | booleanprivatemodule:engine/conversion/viewconsumable~ViewElementConsumables#_canConsumeNameFlag indicating if name of the element can be consumed.
Methods
constructor( from )module:engine/conversion/viewconsumable~ViewElementConsumables#constructorCreates ViewElementConsumables instance.
Parameters
from : ViewElementView element from which
ViewElementConsumablesis being created.
add( consumables ) → voidmodule:engine/conversion/viewconsumable~ViewElementConsumables#addAdds consumable parts of the view element. Element's name itself can be marked to be consumed (when element's name is consumed its attributes, classes and styles still could be consumed):
consumables.add( { name: true } );Copy codeAttributes classes and styles:
consumables.add( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color'] ] } ); consumables.add( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );Copy codeNote: This method accepts only
ViewNormalizedConsumables. You can usenormalizeConsumableshelper to convert fromConsumablestoViewNormalizedConsumables.Throws CKEditorError
viewconsumable-invalid-attributewhenclassorstyleattribute is provided - it should be handled separately by providingstyleandclassin consumables object.Parameters
consumables : ViewNormalizedConsumablesObject describing which parts of the element can be consumed.
Returns
void
consume( consumables ) → booleanmodule:engine/conversion/viewconsumable~ViewElementConsumables#consumeTests if parts of the view element can be consumed and consumes them if available. It returns
truewhen all items included in method's call can be consumed, otherwise returnsfalse.Element's name can be consumed:
consumables.consume( { name: true } );Copy codeAttributes classes and styles:
consumables.consume( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } ); consumables.consume( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );Copy codeParameters
consumables : ViewNormalizedConsumablesObject describing which parts of the element should be consumed.
Returns
booleantruewhen all tested items can be consumed andfalsewhen even one of the items could not be consumed.
revert( consumables ) → voidmodule:engine/conversion/viewconsumable~ViewElementConsumables#revertRevert already consumed parts of view Element, so they can be consumed once again. Element's name can be reverted:
consumables.revert( { name: true } );Copy codeAttributes classes and styles:
consumables.revert( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } ); consumables.revert( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );Copy codeParameters
consumables : ViewNormalizedConsumablesObject describing which parts of the element should be reverted.
Returns
void
test( consumables ) → null | booleanmodule:engine/conversion/viewconsumable~ViewElementConsumables#testTests if parts of the view element can be consumed.
Element's name can be tested:
consumables.test( { name: true } );Copy codeAttributes classes and styles:
consumables.test( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } ); consumables.test( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );Copy codeParameters
consumables : ViewNormalizedConsumablesObject describing which parts of the element should be tested.
Returns
null | booleantruewhen all tested items can be consumed,nullwhen even one of the items was never marked for consumption andfalsewhen even one of the items was already consumed.