Class

ViewElementConsumables (engine/conversion)

@ckeditor/ckeditor5-engine/src/conversion/viewconsumable

class

This is a private helper-class for ViewConsumable. It represents and manipulates consumable parts of a single Element.

Filtering

Properties

  • readonly

    element : Node | DocumentFragment

  • private

    _canConsumeName : null | boolean

    Flag indicating if name of the element can be consumed.

  • private readonly

    _consumables : Record<'attributes' | 'classes' | 'styles', Map<string, boolean>>

    Contains maps of element's consumables: attributes, classes and styles.

Methods

  • constructor( from )

    Creates ViewElementConsumables instance.

    Parameters

    from : Node | DocumentFragment

    View node or document fragment from which ViewElementConsumables is being created.

  • add( consumables ) → void

    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 when class or style attribute is provided - it should be handled separately by providing style and class in consumables object.

    Parameters

    consumables : Consumables

    Object describing which parts of the element can be consumed.

    Returns

    void
  • consume( consumables ) → void

    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 : Match | Consumables

    Object describing which parts of the element should be consumed.

    Returns

    void
  • revert( consumables ) → void

    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 : Consumables

    Object describing which parts of the element should be reverted.

    Returns

    void
  • test( consumables ) → null | boolean

    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 : Match | Consumables

    Object describing which parts of the element should be tested.

    Returns

    null | boolean

    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.

  • private

    _add( type, item ) → void

    Helper method that adds consumables of a given type: attribute, class or style.

    Throws CKEditorError viewconsumable-invalid-attribute when class or style type is provided - it should be handled separately by providing actual style/class type.

    Parameters

    type : 'attributes' | 'classes' | 'styles'

    Type of the consumable item: attributes, classes or styles.

    item : ArrayOrItem<string>

    Consumable item or array of items.

    Returns

    void
  • private

    _consume( type, item ) → void

    Helper method that consumes items of a given type: attribute, class or style.

    Parameters

    type : 'attributes' | 'classes' | 'styles'

    Type of the consumable item: attributes, classes or styles.

    item : ArrayOrItem<string>

    Consumable item or array of items.

    Returns

    void
  • private

    _revert( type, item ) → void

    Helper method that reverts items of a given type: attribute, class or style.

    Parameters

    type : 'attributes' | 'classes' | 'styles'

    Type of the consumable item: attributes, classes or , styles.

    item : ArrayOrItem<string>

    Consumable item or array of items.

    Returns

    void
  • private

    _test( type, item ) → null | boolean

    Helper method that tests consumables of a given type: attribute, class or style.

    Parameters

    type : 'attributes' | 'classes' | 'styles'

    Type of the consumable item: attributes, classes or styles.

    item : ArrayOrItem<string>

    Consumable item or array of items.

    Returns

    null | boolean

    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.