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:
Delegates selected events to another module:utils/emittermixin~Emitter. For instance:
emitterA.delegate( 'eventX' ).to( emitterB );
emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
then eventX is delegated (fired by) emitterB and emitterC along with data:
emitterA.fire( 'eventX', data );
and eventY is delegated (fired by) emitterC along with data:
emitterA.fire( 'eventY', data );
Event names that will be delegated to another emitter.
Removes all event listeners set by the DataController.
Fires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an module:utils/eventinfo~EventInfo object,
followed by the optional args provided in the fire() method call.
The type describing the event. See module:utils/emittermixin~BaseEvent.
The name of the event or EventInfo object if event is delegated.
Additional arguments to be passed to the callbacks.
By default the method returns undefined. However, the return value can be changed by listeners
through modification of the module:utils/eventinfo~EventInfo#return evt.return's property (the event info
is the first param of every callback).
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.
Registers a callback function to be executed when an event is fired in a specific (emitter) object.
Events can be grouped in namespaces using :.
When namespaced event is fired, it additionally fires all callbacks for that namespace.
// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
myEmitter.on( 'myGroup', genericCallback );
myEmitter.on( 'myGroup:myEvent', specificCallback );
// genericCallback is fired.
myEmitter.fire( 'myGroup' );
// both genericCallback and specificCallback are fired.
myEmitter.fire( 'myGroup:myEvent' );
// genericCallback is fired even though there are no callbacks for "foo".
myEmitter.fire( 'myGroup:foo' );
An event callback can module:utils/eventinfo~EventInfo#stop stop the event and set the module:utils/eventinfo~EventInfo#return return value of the #fire method.
The type describing the event. See module:utils/emittermixin~BaseEvent.
The object that fires the event.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Stops executing the callback on the given event.
Shorthand for #stopListening this.stopListening( this, event, callback ).
The name of the event.
The function to stop being called.
Registers a callback function to be executed when an event is fired.
Shorthand for #listenTo this.listenTo( this, event, callback, options ) (it makes the emitter
listen on itself).
The type descibing the event. See module:utils/emittermixin~BaseEvent.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Registers a callback function to be executed on the next time the event is fired only. This is similar to calling #on followed by #off in the callback.
The type descibing the event. See module:utils/emittermixin~BaseEvent.
The name of the event.
The function to be called on event.
Optionaloptions: GetCallbackOptions<TEvent>Additional options.
Returns the data parsed by the #processor data processor and then converted by upcast converters attached to the #upcastDispatcher.
Data to parse.
Optionalcontext: ModelSchemaContextDefinitionBase 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.
Stops delegating events. It can be used at different levels:
Optionalevent: stringThe name of the event to stop delegating. If omitted, stops it all delegations.
Optionalemitter: Emitter(requires event) The object to stop delegating a particular event to.
If omitted, stops delegation of event to all emitters.
Stops listening for events. It can be used at different levels:
Optionalemitter: EmitterThe object to stop listening to. If omitted, stops it for all objects.
Optionalevent: string(Requires the emitter) The name of the event to stop listening to. If omitted, stops it
for all events from emitter.
Optionalcallback: Function(Requires the event) The function to be removed from the call list for the given
event.
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.
The element or document fragment whose content will be converted.
Optionalcontext: ModelSchemaContextDefinitionBase 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: