# RootOperation

class

Operation that creates (or attaches) or detaches a root element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L18)

<a id="properties">

## Properties

<a id="member-affectedSelectable">

### `affectedSelectable: ModelSelectable` _(readonly)_

A selectable that will be affected by the operation after it is executed.

The exact returned parameter differs between operation types.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L83)

<a id="member-baseVersion">

### `baseVersion: number | null` _(inherited)_

[`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied. If you try to [apply](module_engine_model_model-Model.md#function-applyOperation) operation with different base version than the [document version](module_engine_model_document-ModelDocument.md#member-version) the [model-document-applyOperation-wrong-version](module_utils_ckeditorerror-CKEditorError.md) error is thrown.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L26)

<a id="member-batch">

### `batch: Batch | null` _(inherited)_

[Batch](module_engine_model_batch-Batch.md) to which the operation is added or `null` if the operation is not added to any batch yet.

Note, that a [non-document operation](#member-isDocumentOperation) has this property always set to `null`, and is never added to any batch.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L40)

<a id="member-elementName">

### `elementName: string` _(readonly)_

Root element name.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L27)

<a id="member-isAdd">

### `isAdd: boolean` _(readonly)_

Specifies whether the operation adds (`true`) or detaches the root (`false`).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L32)

<a id="member-isDocumentOperation">

### `isDocumentOperation: boolean` _(readonly)_

Defines whether operation is executed on attached or detached [items](module_engine_model_item-ModelItem.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L31)

<a id="member-rootName">

### `rootName: string` _(readonly)_

Root name to create or detach.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L22)

<a id="member-type">

### `type: 'addRoot' | 'detachRoot'` _(readonly)_

Operation type.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L76)

<a id="member-_document">

### `_document: ModelDocument` _(private)_

Document which owns the root.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L37)

#### Static properties

<a id="static-member-className">

### `className: string` _(readonly)_

Name of the operation class used for serialization.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L122)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( rootName, elementName, isAdd, document, baseVersion )`

Creates an operation that creates or removes a root element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L48)

#### Parameters

* `rootName: string`

  Root name to create or detach.

* `elementName: string`

  Root element name.

* `isAdd: boolean`

  Specifies whether the operation adds (`true`) or detaches the root (`false`).

* `document: ModelDocument`

  Document which owns the root.

* `baseVersion: number`

  Document [`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied.

<a id="function-clone">

### `clone() → RootOperation`

Creates and returns an operation that has the same parameters as this operation.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L90)

#### Returns

* `RootOperation`

  Clone of this operation.

<a id="function-getReversed">

### `getReversed() → RootOperation`

Creates and returns a reverse operation. Reverse operation when executed right after the original operation will bring back tree model state to the point before the original operation execution. In other words, it reverses changes done by the original operation.

Keep in mind that tree model state may change since executing the original operation, so reverse operation will be "outdated". In that case you will need to transform it by all operations that were executed after the original operation.

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

#### Returns

* `RootOperation`

  Reversed operation.

<a id="function-toJSON">

### `toJSON() → unknown`

Custom toJSON method to solve child-parent circular dependencies.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L111)

#### Returns

* `unknown`

  Clone of this object with the operation property replaced with string.

<a id="function-_execute">

### `_execute() → void` _(internal)_

Executes the operation - modifications described by the operation properties will be applied to the model tree.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L104)

#### Returns

* `void`

<a id="function-_validate">

### `_validate() → void` _(internal)_

Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws an error if operation is not valid.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L99)

#### Returns

* `void`

#### Static methods

<a id="static-function-fromJSON">

### `fromJSON( json, document ) → RootOperation` _(static)_

Creates `RootOperation` object from deserialized object, i.e. from parsed JSON string.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootoperation.ts#L132)

#### Parameters

* `json: any`

  Deserialized JSON object.

* `document: ModelDocument`

  Document on which this operation will be applied.

#### Returns

* `RootOperation`

---

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