# list/list/utils/model

module

<a id="classes">

## Classes

<a id="class-ListItemUid">

### [ListItemUid](module_list_list_utils_model-ListItemUid.md) _(internal)_

<a id="interfaces">

## Interfaces

<a id="interface-ListElement">

### `ListElement`

<a id="functions">

## Functions

<a id="function-canBecomeSimpleListItem">

### `canBecomeSimpleListItem( block, schema ) → boolean` _(internal)_

Checks whether the given block can be replaced by a listItem.

Note that this is possible only when multiBlock = false option is set in feature config.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L589)

#### Parameters

* `block: ModelElement`

  A block to be tested.

* `schema: ModelSchema`

  The schema of the document.

#### Returns

* `boolean`

<a id="function-expandListBlocksToCompleteItems">

### `expandListBlocksToCompleteItems( blocks, options = { options.withNested? } ) → Array<ListElement>` _(internal)_

Expands the given list of selected blocks to include the leading and tailing blocks of partially selected list items.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L201)

#### Parameters

* `blocks: ArrayOrItem<ModelElement>`

  The list of selected blocks.

* `options: object`

  Properties

  * `options.withNested?: boolean`

    Whether should include nested list items.

  Defaults to `{}`

#### Returns

* `Array<ListElement>`

<a id="function-expandListBlocksToCompleteList">

### `expandListBlocksToCompleteList( blocks ) → Array<ListElement>` _(internal)_

Expands the given list of selected blocks to include all the items of the lists they're in.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L225)

#### Parameters

* `blocks: ArrayOrItem<ModelElement>`

  The list of selected blocks.

#### Returns

* `Array<ListElement>`

<a id="function-getAllListItemBlocks">

### `getAllListItemBlocks( listItem, options = { options.higherIndent? } ) → Array<ListElement>` _(internal)_

Returns an array with all elements that represents the same list item.

It means that values for `listIndent`, and `listItemId` for all items are equal.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L73)

#### Parameters

* `listItem: ModelNode`

  Starting list item element.

* `options: object`

  Properties

  * `options.higherIndent?: boolean`

    Whether blocks with a higher indent level than the start block should be included in the result.

  Defaults to `{}`

#### Returns

* `Array<ListElement>`

<a id="function-getListItemBlocks">

### `getListItemBlocks( listItem, options = { options.direction?, options.higherIndent? } ) → Array<ListElement>` _(internal)_

Returns an array with elements that represents the same list item in the specified direction.

It means that values for `listIndent` and `listItemId` for all items are equal.

**Note**: For backward search the provided item is not included, but for forward search it is included in the result.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L97)

#### Parameters

* `listItem: ModelNode`

  Starting list item element.

* `options: object`

  Properties

  * `options.direction?: 'forward' | 'backward'`

    Walking direction.

  * `options.higherIndent?: boolean`

    Whether blocks with a higher indent level than the start block should be included in the result.

  Defaults to `{}`

#### Returns

* `Array<ListElement>`

<a id="function-getListItems">

### `getListItems( listItem, options? ) → Array<ListElement>` _(internal)_

Returns array of all blocks/items of the same list as given block (same indent, same type and properties).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L135)

#### Parameters

* `listItem: ModelElement`

  Starting list item element.

* `options?: ListWalkerOptions`

  Additional list walker options to modify the range of returned list items.

#### Returns

* `Array<ListElement>`

<a id="function-getNestedListBlocks">

### `getNestedListBlocks( listItem ) → Array<ListElement>` _(internal)_

Returns a list items nested inside the given list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L121)

#### Parameters

* `listItem: ModelElement`

#### Returns

* `Array<ListElement>`

<a id="function-getSelectedBlockObject">

### `getSelectedBlockObject( model ) → ModelElement | null` _(internal)_

Returns a selected block object. If a selected object is inline or when there is no selected object, `null` is returned.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L566)

#### Parameters

* `model: Model`

  The instance of editor model.

#### Returns

* `ModelElement | null`

  Selected block object or `null`.

<a id="function-indentBlocks">

### `indentBlocks( blocks, writer, options = { options.attributeNames, options.expand?, options.indentBy? } ) → Array<ListElement>` _(internal)_

Increases indentation of given list blocks.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L303)

#### Parameters

* `blocks: ArrayOrItem<ListElement>`

  The block or iterable of blocks.

* `writer: ModelWriter`

  The model writer.

* `options: object`

  Additional options.

  Properties

  * `options.attributeNames: Array<string>`

    List of attribute names to remove when a block leaves the list (when blockIndent < 0).

  * `options.expand?: boolean`

    Whether should expand the list of blocks to include complete list items.

  * `options.indentBy?: number`

    The number of levels the indentation should change (could be negative).

    Defaults to `1`

#### Returns

* `Array<ListElement>`

<a id="function-isFirstBlockOfListItem">

### `isFirstBlockOfListItem( listBlock ) → boolean` _(internal)_

Check if the given block is the first in the list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L162)

#### Parameters

* `listBlock: ModelNode`

  The list block element.

#### Returns

* `boolean`

<a id="function-isFirstListItemInList">

### `isFirstListItemInList( listItem ) → boolean`

Checks if the given list item block is the first block of the first item in its list at the given indent.

Walks back over previous siblings and returns:

* `true` if it reaches a non-list block or a list block at a lower indent (a new list begins here),
* `false` if it finds a same-indent block of the same `listItemId` (a continuation of the current item) or of the same `listType` (the visible list already has earlier items),
* `true` if it finds a same-indent block of a different `listType` and a different `listItemId` (a different list ends; ours starts here),
* `false` if the loop ends (it reaches the first non-list-item block, or no more previous siblings) while passing only higher-indent blocks (those blocks live inside an intermediate skip-level `<li style="list-style-type:none">` wrapper at our indent).

For example, in the model:

```
'  # aaa'
'# bbb'
```

`bbb` is preceded by a higher-indent block `aaa`, which in the view is rendered inside an intermediate skip-level wrapper at indent 0:

```html
<ol>
  <li style="list-style-type:none">
	<ol>
	  <li>aaa</li>
	</ol>
  </li>
  <li>bbb</li>
</ol>
```

So `bbb` is the second visible item in the outer list and the function returns `false`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L640)

#### Parameters

* `listItem: ModelElement`

#### Returns

* `boolean`

<a id="function-isLastBlockOfListItem">

### `isLastBlockOfListItem( listBlock ) → boolean` _(internal)_

Check if the given block is the last in the list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L180)

#### Parameters

* `listBlock: ModelElement`

#### Returns

* `boolean`

<a id="function-isListItemBlock">

### `isListItemBlock( node ) → node is ListElement` _(internal)_

Returns true if the given model node is a list item block.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L59)

#### Parameters

* `node: ModelDocumentFragment | ModelItem | null`

#### Returns

* `node is ListElement`

<a id="function-isNumberedListType">

### `isNumberedListType( listType ) → boolean` _(internal)_

Returns true if listType is of type `numbered` or `customNumbered`.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L600)

#### Parameters

* `listType: ListType`

#### Returns

* `boolean`

<a id="function-isSingleListItem">

### `isSingleListItem( blocks ) → boolean` _(internal)_

Checks whether the given blocks are related to a single list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L444)

#### Parameters

* `blocks: Array<ModelNode>`

  The list block elements.

#### Returns

* `boolean`

<a id="function-mergeListItemBefore">

### `mergeListItemBefore( listBlock, parentBlock, writer ) → Array<ListElement>` _(internal)_

Merges the list item with the parent list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L270)

#### Parameters

* `listBlock: ModelNode`

  The list block element.

* `parentBlock: ModelElement`

  The list block element to merge with.

* `writer: ModelWriter`

  The model writer.

#### Returns

* `Array<ListElement>`

  The array of updated blocks.

<a id="function-outdentBlocksWithMerge">

### `outdentBlocksWithMerge( blocks, writer, options = { options.attributeNames } ) → Array<ListElement>` _(internal)_

Decreases indentation of given list of blocks. If the indentation of some blocks matches the indentation of surrounding blocks, they get merged together.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L344)

#### Parameters

* `blocks: ArrayOrItem<ListElement>`

  The block or iterable of blocks.

* `writer: ModelWriter`

  The model writer.

* `options: object`

  Additional options.

  Properties

  * `options.attributeNames: Array<string>`

    List of attribute names to remove when a block leaves the list (when blockIndent < 0).

#### Returns

* `Array<ListElement>`

<a id="function-outdentFollowingItems">

### `outdentFollowingItems( lastBlock, writer ) → Array<ListElement>` _(internal)_

Modifies the indents of list blocks following the given list block so the indentation is valid after the given block is no longer a list item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L467)

#### Parameters

* `lastBlock: ModelElement`

  The last list block that has become a non-list element.

* `writer: ModelWriter`

  The model writer.

#### Returns

* `Array<ListElement>`

  Array of altered blocks.

<a id="function-removeListAttributes">

### `removeListAttributes( blocks, writer, attributeNames ) → Array<ModelElement>` _(internal)_

Removes all list attributes from the given blocks.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L412)

#### Parameters

* `blocks: ArrayOrItem<ModelElement>`

  The block or iterable of blocks.

* `writer: ModelWriter`

  The model writer.

* `attributeNames: Array<string>`

  List of attribute names to remove.

#### Returns

* `Array<ModelElement>`

  Array of altered blocks.

<a id="function-sortBlocks">

### `sortBlocks( blocks ) → Array<T>` _(internal)_

Returns the array of given blocks sorted by model indexes (document order).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L552)

#### Type parameters

* `T: extends ModelElement`

#### Parameters

* `blocks: Iterable<T>`

#### Returns

* `Array<T>`

<a id="function-splitListItemBefore">

### `splitListItemBefore( listBlock, writer ) → Array<ListElement>` _(internal)_

Splits the list item just before the provided list block.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/list/utils/model.ts#L247)

#### Parameters

* `listBlock: ModelElement`

  The list block element.

* `writer: ModelWriter`

  The model writer.

#### Returns

* `Array<ListElement>`

  The array of updated blocks.

---

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