ViewConsumable (engine/conversion)
@ckeditor/ckeditor5-engine/src/conversion/viewconsumable
Class used for handling consumption of view elements, text nodes and document fragments. Element's name and its parts (attributes, classes and styles) can be consumed separately. Consuming an element's name does not consume its attributes, classes and styles. To add items for consumption use add method. To test items use test method. To consume items use consume method. To revert already consumed items use revert method.
Filtering
Properties
-
_consumables : Map.<(ViewElementConsumables | Boolean)>
protected
Map of consumable elements. If element is used as a key, ViewElementConsumables instance is stored as value. For text nodes and document fragments boolean value is stored as value.
Methods
-
Creates new ViewConsumable.
-
add( element, [ consumables ] = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } )
Adds view element, text node or document fragment as ready to be consumed.
Throws CKEditorError
viewconsumable-invalid-attribute
whenclass
orstyle
attribute is provided - it should be handled separately by providing actual style/class.Parameters
element : Element | Text | DocumentFragment
[ consumables ] : Object
Used only if first parameter is view element instance.
Propertiesconsumables.name : Boolean
If set to true element's name will be included.
consumables.attributes : String | Array.<String>
Attribute name or array of attribute names.
consumables.classes : String | Array.<String>
Class name or array of class names.
consumables.styles : String | Array.<String>
Style name or array of style names.
-
consume( element, [ consumables ] = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } ) → Boolean
Consumes view element, text node or document fragment. It returns
true
when all items included in method's call can be consumed, otherwise returnsfalse
.Consuming classes and styles as attribute will test if all added classes/styles can be consumed.
Parameters
element : Element | Text | DocumentFragment
[ consumables ] : Object
Used only if first parameter is view element instance.
Propertiesconsumables.name : Boolean
If set to true element's name will be included.
consumables.attributes : String | Array.<String>
Attribute name or array of attribute names.
consumables.classes : String | Array.<String>
Class name or array of class names.
consumables.styles : String | Array.<String>
Style name or array of style names.
Returns
Boolean
Returns
true
when all items included in method's call can be consumed, otherwise returnsfalse
.
-
revert( element, [ consumables ] = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } )
Reverts view element, text node or document fragment so they can be consumed once again. Method does not revert items that were never previously added for consumption, even if they are included in method's call.
Reverting classes and styles as attribute will revert all classes/styles that were previously added for consumption.
Parameters
element : Element | Text | DocumentFragment
[ consumables ] : Object
Used only if first parameter is view element instance.
Propertiesconsumables.name : Boolean
If set to true element's name will be included.
consumables.attributes : String | Array.<String>
Attribute name or array of attribute names.
consumables.classes : String | Array.<String>
Class name or array of class names.
consumables.styles : String | Array.<String>
Style name or array of style names.
-
test( element, [ consumables ] = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } ) → Boolean | null
Tests if view element, text node or document fragment can be consumed. It returns
true
when all items included in method's call can be consumed. Returnsfalse
when first already consumed item is found andnull
when first non-consumable item is found.Testing classes and styles as attribute will test if all added classes/styles can be consumed.
Parameters
element : Element | Text | DocumentFragment
[ consumables ] : Object
Used only if first parameter is view element instance.
Propertiesconsumables.name : Boolean
If set to true element's name will be included.
consumables.attributes : String | Array.<String>
Attribute name or array of attribute names.
consumables.classes : String | Array.<String>
Class name or array of class names.
consumables.styles : String | Array.<String>
Style name or array of style names.
Returns
Boolean | null
Returns
true
when all items included in method's call can be consumed. Returnsfalse
when first already consumed item is found andnull
when first non-consumable item is found.
Static methods
-
consumablesFromElement( element ) → Object
static
Creates consumable object from view element. Consumable object will include element's name and all its attributes, classes and styles.
-
createFrom( from, [ instance ] )
static
Creates ViewConsumable instance from node or document fragment. Instance will contain all elements, child nodes, attributes, styles and classes added for consumption.
Parameters
from : Node | DocumentFragment
View node or document fragment from which
ViewConsumable
will be created.[ instance ] : ViewConsumable
If provided, given
ViewConsumable
instance will be used to add all consumables. It will be returned instead of a new instance.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.