# ViewElementConsumables

class

This is a private helper-class for [`ViewConsumable`](module_engine_conversion_viewconsumable-ViewConsumable.md). It represents and manipulates consumable parts of a single [`ViewElement`](module_engine_view_element-ViewElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L336)

<a id="properties">

## Properties

<a id="member-element">

### `element: ViewElement` _(readonly)_

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L337)

<a id="member-_attributes">

### `_attributes: Map<string, boolean | Map<string, boolean>>` _(private)_

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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L350)

<a id="member-_canConsumeName">

### `_canConsumeName: boolean | null` _(private)_

Flag indicating if name of the element can be consumed.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L342)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( from )`

Creates ViewElementConsumables instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L357)

#### Parameters

* `from: ViewElement`

  View element from which `ViewElementConsumables` is being created.

<a id="function-add">

### `add( consumables ) → void`

Adds consumable parts of the [view element](module_engine_view_element-ViewElement.md). 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):

```typescript
consumables.add( { name: true } );
```

Attributes classes and styles:

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

Note: This method accepts only [`ViewNormalizedConsumables`](module_engine_view_element-ViewNormalizedConsumables.md). You can use [`normalizeConsumables`](module_engine_conversion_viewconsumable.md#function-normalizeConsumables) helper to convert from [`Consumables`](module_engine_conversion_viewconsumable-Consumables.md) to `ViewNormalizedConsumables`.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `viewconsumable-invalid-attribute` when `class` or `style` attribute is provided - it should be handled separately by providing `style` and `class` in consumables object.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L386)

#### Parameters

* `consumables: ViewNormalizedConsumables`

  Object describing which parts of the element can be consumed.

#### Returns

* `void`

<a id="function-consume">

### `consume( consumables ) → boolean`

Tests if parts of the [view element](module_engine_view_element-ViewElement.md) 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:

```typescript
consumables.consume( { name: true } );
```

Attributes classes and styles:

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L520)

#### 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.

<a id="function-revert">

### `revert( consumables ) → void`

Revert already consumed parts of [view Element](module_engine_view_element-ViewElement.md), so they can be consumed once again. Element's name can be reverted:

```typescript
consumables.revert( { name: true } );
```

Attributes classes and styles:

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L572)

#### Parameters

* `consumables: ViewNormalizedConsumables`

  Object describing which parts of the element should be reverted.

#### Returns

* `void`

<a id="function-test">

### `test( consumables ) → boolean | null`

Tests if parts of the [view element](module_engine_view_element-ViewElement.md) can be consumed.

Element's name can be tested:

```typescript
consumables.test( { name: true } );
```

Attributes classes and styles:

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/viewconsumable.ts#L449)

#### Parameters

* `consumables: ViewNormalizedConsumables`

  Object describing which parts of the element should be tested.

#### Returns

* `boolean | null`

  `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.

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
