ViewElementConsumables (engine/conversion)
@ckeditor/ckeditor5-engine/src/conversion/viewconsumable
This is a private helper-class for ViewConsumable
.
It represents and manipulates consumable parts of a single Element
.
Filtering
Properties
-
element : Node | DocumentFragment
module:engine/conversion/viewconsumable~ViewElementConsumables#element
readonly
-
_canConsumeName : Boolean
module:engine/conversion/viewconsumable~ViewElementConsumables#_canConsumeName
private
Flag indicating if name of the element can be consumed.
-
_consumables : Object
module:engine/conversion/viewconsumable~ViewElementConsumables#_consumables
private
Contains maps of element's consumables: attributes, classes and styles.
Methods
-
constructor( from )
module:engine/conversion/viewconsumable~ViewElementConsumables#constructor
Creates ViewElementConsumables instance.
Parameters
from : Node | DocumentFragment
View node or document fragment from which
ViewElementConsumables
is being created.
-
add( consumables = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } )
module:engine/conversion/viewconsumable~ViewElementConsumables#add
Adds 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 } );
Attributes classes and styles:
consumables.add( { attributes: 'title', classes: 'foo', styles: 'color' } ); consumables.add( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
Throws CKEditorError
viewconsumable-invalid-attribute
whenclass
orstyle
attribute is provided - it should be handled separately by providingstyle
andclass
in consumables object.Parameters
consumables : Object
Object describing which parts of the element can be consumed.
Propertiesconsumables.name : Boolean
If set to
true
element's name will be added as consumable.consumables.attributes : String | Array.<String>
Attribute name or array of attribute names to add as consumable.
consumables.classes : String | Array.<String>
Class name or array of class names to add as consumable.
consumables.styles : String | Array.<String>
Style name or array of style names to add as consumable.
-
consume( consumables = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } )
module:engine/conversion/viewconsumable~ViewElementConsumables#consume
Consumes parts of view element. This function does not check if consumable item is already consumed - it consumes all consumable items provided. Element's name can be consumed:
consumables.consume( { name: true } );
Attributes classes and styles:
consumables.consume( { attributes: 'title', classes: 'foo', styles: 'color' } ); consumables.consume( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
Parameters
consumables : Object
Object describing which parts of the element should be consumed.
Propertiesconsumables.name : Boolean
If set to
true
element's name will be consumed.consumables.attributes : String | Array.<String>
Attribute name or array of attribute names to consume.
consumables.classes : String | Array.<String>
Class name or array of class names to consume.
consumables.styles : String | Array.<String>
Style name or array of style names to consume.
-
revert( consumables = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } )
module:engine/conversion/viewconsumable~ViewElementConsumables#revert
Revert already consumed parts of view Element, so they can be consumed once again. Element's name can be reverted:
consumables.revert( { name: true } );
Attributes classes and styles:
consumables.revert( { attributes: 'title', classes: 'foo', styles: 'color' } ); consumables.revert( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
Parameters
consumables : Object
Object describing which parts of the element should be reverted.
Propertiesconsumables.name : Boolean
If set to
true
element's name will be reverted.consumables.attributes : String | Array.<String>
Attribute name or array of attribute names to revert.
consumables.classes : String | Array.<String>
Class name or array of class names to revert.
consumables.styles : String | Array.<String>
Style name or array of style names to revert.
-
test( consumables = { consumables.name, consumables.attributes, consumables.classes, consumables.styles } ) → Boolean | null
module:engine/conversion/viewconsumable~ViewElementConsumables#test
Tests if parts of the view node can be consumed.
Element's name can be tested:
consumables.test( { name: true } );
Attributes classes and styles:
consumables.test( { attributes: 'title', classes: 'foo', styles: 'color' } ); consumables.test( { attributes: [ 'title', 'name' ], classes: [ 'foo', 'bar' ] );
Parameters
consumables : Object
Object describing which parts of the element should be tested.
Propertiesconsumables.name : Boolean
If set to
true
element's name will be tested.consumables.attributes : String | Array.<String>
Attribute name or array of attribute names to test.
consumables.classes : String | Array.<String>
Class name or array of class names to test.
consumables.styles : String | Array.<String>
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 andfalse
when even one of the items was already consumed.
-
_add( type, item )
module:engine/conversion/viewconsumable~ViewElementConsumables#_add
private
Helper method that adds consumables of a given type: attribute, class or style.
Throws CKEditorError
viewconsumable-invalid-attribute
whenclass
orstyle
type is provided - it should be handled separately by providing actual style/class type.Parameters
type : String
Type of the consumable item:
attributes
,classes
orstyles
.item : String | Array.<String>
Consumable item or array of items.
-
_consume( type, item )
module:engine/conversion/viewconsumable~ViewElementConsumables#_consume
private
Helper method that consumes items of a given type: attribute, class or style.
Parameters
type : String
Type of the consumable item:
attributes
,classes
orstyles
.item : String | Array.<String>
Consumable item or array of items.
-
_revert( type, item )
module:engine/conversion/viewconsumable~ViewElementConsumables#_revert
private
Helper method that reverts items of a given type: attribute, class or style.
Parameters
type : String
Type of the consumable item:
attributes
,classes
or ,styles
.item : String | Array.<String>
Consumable item or array of items.
-
_test( type, item ) → Boolean | null
module:engine/conversion/viewconsumable~ViewElementConsumables#_test
private
Helper method that tests consumables of a given type: attribute, class or style.
Parameters
type : String
Type of the consumable item:
attributes
,classes
orstyles
.item : String | Array.<String>
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 andfalse
when one of the items is already consumed.
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.