Creates a data controller instance.
Data model.
The styles processor instance.
ReadonlydowncastDowncast dispatcher used by the #get get method. Downcast converters should be attached to it.
ReadonlyhtmlData processor used specifically for HTML conversion.
ReadonlymapperMapper used for the conversion. It has no permanent bindings, because these are created while getting data and
are cleared directly after the data are converted. However, the mapper is defined as a class property, because
it needs to be passed to the DowncastDispatcher as a conversion API.
ReadonlymodelData model.
Data processor used during the conversion. Same instance as #htmlProcessor by default. Can be replaced at run time to handle different format, e.g. XML or Markdown.
ReadonlystylesStyles processor used during the conversion.
ReadonlyupcastUpcast dispatcher used by the #set set method. Upcast converters should be attached to it.
ReadonlyviewThe view document used by the data controller.
Adds the style processor normalization rules.
You can implement your own rules as well as use one of the available processor rules:
Removes all event listeners set by the DataController.
Returns the model's data converted by downcast dispatchers attached to #downcastDispatcher and formatted by the #processor data processor.
A warning is logged when you try to retrieve data for a detached root, as most probably this is a mistake. A detached root should be treated like it is removed, and you should not save its data. Note, that the detached root data is always an empty string.
Optionaloptions: { rootName?: string; trim?: "empty" | "none"; [key: string]: unknown }
Additional configuration for the retrieved data. DataController provides two optional
properties: rootName and trim. Other properties of this object are specified by various editor features.
OptionalrootName?: stringRoot name. Default 'main'.
Optionaltrim?: "empty" | "none"Whether returned data should be trimmed. This option is set to empty by default,
which means whenever editor content is considered empty, an empty string will be returned. To turn off trimming completely
use 'none'. In such cases the exact content will be returned (for example a <p> </p> for an empty editor).
Output data.
Sets the initial input data parsed by the #processor data processor and converted by the #upcastDispatcher view-to-model converters. Initial data can be only set to a document whose module:engine/model/document~ModelDocument#version is equal 0.
Note This method is module:utils/observablemixin~Observable#decorate decorated which is used by e.g. collaborative editing plugin that syncs remote data on init.
When data is passed as a string, it is initialized on the default main root:
dataController.init( '<p>Foo</p>' ); // Initializes data on the `main` root only, as no other is specified.
To initialize data on a different root or multiple roots at once, an object containing rootName - data pairs should be passed:
dataController.init( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Initializes data on both the `main` and `title` roots.
Input data as a string or an object containing the rootName - data
pairs to initialize data on multiple roots at once.
Promise that is resolved after the data is set on the editor.
Returns the data parsed by the #processor data processor and then converted by upcast converters attached to the #upcastDispatcher.
Note: The default context value is '$root', which only matches the generic root. When the editor uses a
custom root module:core/editor/editorconfig~RootConfig#modelElement modelElement, pass the target
module:engine/model/rootelement~ModelRootElement root element (or its configured model element name)
explicitly, otherwise the conversion result may be wrong.
See the {@glink framework/deep-dive/schema#custom-root-elements Custom root elements} section of the
{@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
Data to parse.
Optionalcontext: ModelSchemaContextDefinition
Base context in which the view will be converted to the model. See: module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert.
Parsed data.
Registers a module:engine/view/matcher~MatcherPattern on an #htmlProcessor htmlProcessor and a #processor processor for view elements whose content should be treated as raw data and not processed during the conversion from DOM to view elements.
The raw data can be later accessed by the
module:engine/view/element~ViewElement#getCustomProperty view element custom property
"$rawContent".
Pattern matching all view elements whose content should be treated as a raw data.
Sets the input data parsed by the #processor data processor and converted by the #upcastDispatcher view-to-model converters. This method can be used any time to replace existing editor data with the new one without clearing the module:engine/model/document~ModelDocument#history document history.
This method also creates a batch with all the changes applied. If all you need is to parse data, use the #parse method.
When data is passed as a string it is set on the default main root:
dataController.set( '<p>Foo</p>' ); // Sets data on the `main` root, as no other is specified.
To set data on a different root or multiple roots at once, an object containing rootName - data pairs should be passed:
dataController.set( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Sets data on the `main` and `title` roots as specified.
To set the data with a preserved undo stack and add the change to the undo stack, set { isUndoable: true } as a batchType option.
dataController.set( '<p>Foo</p>', { batchType: { isUndoable: true } } );
Input data as a string or an object containing the rootName - data
pairs to set data on multiple roots at once.
Optionaloptions: { batchType?: BatchType; [key: string]: unknown }
Options for setting data.
OptionalbatchType?: BatchTypeThe batch type that will be used to create a batch for the changes applied by this method.
By default, the batch will be set as module:engine/model/batch~Batch#isUndoable not undoable and the undo stack will be
cleared after the new data is applied (all undo steps will be removed). If the batch type isUndoable flag is be set to true,
the undo stack will be preserved instead and not cleared when new data is applied.
Returns the content of the given module:engine/model/element~ModelElement model's element or module:engine/model/documentfragment~ModelDocumentFragment model document fragment converted by the downcast converters attached to the #downcastDispatcher and formatted by the #processor data processor.
The element whose content will be stringified.
Optionaloptions: Record<string, unknown>
Additional configuration passed to the conversion process.
Output data.
Returns the result of the given module:engine/view/element~ViewElement view element or module:engine/view/documentfragment~ViewDocumentFragment view document fragment converted by the #upcastDispatcher view-to-model converters, wrapped by module:engine/model/documentfragment~ModelDocumentFragment.
When marker elements were converted during the conversion process, it will be set as a document fragment's module:engine/model/documentfragment~ModelDocumentFragment#markers static markers map.
Note: The default context value is '$root', which only matches the generic root. When the editor uses a
custom root module:core/editor/editorconfig~RootConfig#modelElement modelElement, pass the target
module:engine/model/rootelement~ModelRootElement root element (or its configured model element name)
explicitly, otherwise the conversion result may be wrong.
See the {@glink framework/deep-dive/schema#custom-root-elements Custom root elements} section of the
{@glink framework/deep-dive/schema Schema deep-dive} guide for more details.
The element or document fragment whose content will be converted.
Optionalcontext: ModelSchemaContextDefinition
Base context in which the view will be converted to the model. See: module:engine/conversion/upcastdispatcher~UpcastDispatcher#convert.
Output document fragment.
Returns the content of the given module:engine/model/element~ModelElement model element or module:engine/model/documentfragment~ModelDocumentFragment model document fragment converted by the downcast converters attached to #downcastDispatcher into a module:engine/view/documentfragment~ViewDocumentFragment view document fragment.
Element or document fragment whose content will be converted.
Optionaloptions: Record<string, unknown>
Additional configuration that will be available through the module:engine/conversion/downcastdispatcher~DowncastConversionApi#options during the conversion process.
Output view ModelDocumentFragment.
Controller for the data pipeline. The data pipeline controls how data is retrieved from the document and set inside it. Hence, the controller features two methods which allow to ~DataController#get get and ~DataController#set set data of the ~DataController#model model using the given:
An instance of the data controller is always available in the module:core/editor/editor~Editor#data
editor.dataproperty: