Sign up (with export icon)

ViewElementConsumables

Api-class icon class

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

Properties

  • element : ViewElement
    readonly

  • Chevron-right icon

    _attributes : Map<string, boolean | Map<string, boolean>>
    Lock icon privatereadonly

    A 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.
  • Chevron-right icon

    _canConsumeName : null | boolean
    Lock icon private

    Flag indicating if name of the element can be consumed.

Methods

  • Chevron-right icon

    constructor( from )

    Creates ViewElementConsumables instance.

    Parameters

    from : ViewElement

    View element from which ViewElementConsumables is being created.

  • Chevron-right icon

    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 } );
    
    Copy code

    Attributes classes and styles:

    consumables.add( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color'] ] } );
    consumables.add( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
    
    Copy code

    Note: This method accepts only ViewNormalizedConsumables. You can use normalizeConsumables helper to convert from Consumables to ViewNormalizedConsumables.

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

    Object describing which parts of the element can be consumed.

    Returns

    void
  • Chevron-right icon

    consume( consumables ) → boolean

    Tests if parts of the view element can be consumed and consumes them if available. It returns true when all items included in method's call can be consumed, otherwise returns false.

    Element's name can be consumed:

    consumables.consume( { name: true } );
    
    Copy code

    Attributes classes and styles:

    consumables.consume( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
    consumables.consume( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
    
    Copy code

    Parameters

    consumables : ViewNormalizedConsumables

    Object describing which parts of the element should be consumed.

    Returns

    boolean

    true when all tested items can be consumed and false when even one of the items could not be consumed.

  • Chevron-right icon

    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 } );
    
    Copy code

    Attributes classes and styles:

    consumables.revert( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
    consumables.revert( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
    
    Copy code

    Parameters

    consumables : ViewNormalizedConsumables

    Object describing which parts of the element should be reverted.

    Returns

    void
  • Chevron-right icon

    test( consumables ) → null | boolean

    Tests if parts of the view element can be consumed.

    Element's name can be tested:

    consumables.test( { name: true } );
    
    Copy code

    Attributes classes and styles:

    consumables.test( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
    consumables.test( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
    
    Copy code

    Parameters

    consumables : ViewNormalizedConsumables

    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.