|
|
@@ -3,6 +3,10 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
|
|
|
|
+/**
|
|
|
+ * @module engine/controller/datacontroller
|
|
|
+ */
|
|
|
+
|
|
|
import mix from '../../utils/mix.js';
|
|
|
import EmitterMixin from '../../utils/emittermixin.js';
|
|
|
|
|
|
@@ -25,30 +29,29 @@ import modifySelection from './modifyselection.js';
|
|
|
|
|
|
/**
|
|
|
* 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 {@link engine.controller.DataController#get get}
|
|
|
- * and {@link engine.controller.DataController#set set} data of the {@link engine.controller.DataController#model model}
|
|
|
+ * and set inside it. Hence, the controller features two methods which allow to {@link #get get}
|
|
|
+ * and {@link #set set} data of the {@link #model model}
|
|
|
* using given:
|
|
|
*
|
|
|
- * * {@link engine.dataProcessor.DataProcessor data processor},
|
|
|
- * * {@link engine.conversion.ModelConversionDispatcher model to view} and
|
|
|
- * * {@link engine.conversion.ViewConversionDispatcher view to model} converters.
|
|
|
+ * * {@link module:engine/dataProcessor.DataProcessor data processor},
|
|
|
+ * * {@link module:engine/conversion/modelconversiondispatcher~ModelConversionDispatcher model to view} and
|
|
|
+ * * {@link module:engine/conversion/viewconversiondispatcher~ViewConversionDispatcher view to model} converters.
|
|
|
*
|
|
|
- * @memberOf engine.controller
|
|
|
- * @mixes utils.EmitterMixin
|
|
|
+ * @mixes module:utils/emittermixin~EmitterMixin
|
|
|
*/
|
|
|
export default class DataController {
|
|
|
/**
|
|
|
* Creates data controller instance.
|
|
|
*
|
|
|
- * @param {engine.model.Document} model Document model.
|
|
|
- * @param {engine.dataProcessor.DataProcessor} [dataProcessor] Data processor which should used by the controller.
|
|
|
+ * @param {module:engine/model/document~Document} model Document model.
|
|
|
+ * @param {module:engine/dataProcessor~DataProcessor} [dataProcessor] Data processor which should used by the controller.
|
|
|
*/
|
|
|
constructor( model, dataProcessor ) {
|
|
|
/**
|
|
|
* Document model.
|
|
|
*
|
|
|
* @readonly
|
|
|
- * @member {engine.model.document} engine.controller.DataController#model
|
|
|
+ * @member {module:engine/model/document}
|
|
|
*/
|
|
|
this.model = model;
|
|
|
|
|
|
@@ -56,7 +59,7 @@ export default class DataController {
|
|
|
* Data processor used during the conversion.
|
|
|
*
|
|
|
* @readonly
|
|
|
- * @member {engine.dataProcessor.DataProcessor} engine.controller.DataController#processor
|
|
|
+ * @member {engine.dataProcessor.DataProcessor}
|
|
|
*/
|
|
|
this.processor = dataProcessor;
|
|
|
|
|
|
@@ -65,12 +68,12 @@ export default class DataController {
|
|
|
* cleared directly after data are converted. However, the mapper is defined as class property, because
|
|
|
* it needs to be passed to the `ModelConversionDispatcher` as a conversion API.
|
|
|
*
|
|
|
- * @member {engine.conversion.Mapper} engine.controller.DataController#_mapper
|
|
|
+ * @member {engine.conversion.Mapper}
|
|
|
*/
|
|
|
this.mapper = new Mapper();
|
|
|
|
|
|
/**
|
|
|
- * Model to view conversion dispatcher used by the {@link engine.controller.DataController#get get method}.
|
|
|
+ * Model to view conversion dispatcher used by the {@link #get get method}.
|
|
|
* To attach model to view converter to the data pipeline you need to add lister to this property:
|
|
|
*
|
|
|
* data.modelToView( 'insert:$element', customInsertConverter );
|
|
|
@@ -80,7 +83,7 @@ export default class DataController {
|
|
|
* buildModelConverter().for( data.modelToView ).fromAttribute( 'bold' ).toElement( 'b' );
|
|
|
*
|
|
|
* @readonly
|
|
|
- * @member {engine.conversion.ModelConversionDispatcher} engine.controller.DataController#modelToView
|
|
|
+ * @member {engine.conversion.ModelConversionDispatcher}
|
|
|
*/
|
|
|
this.modelToView = new ModelConversionDispatcher( {
|
|
|
mapper: this.mapper
|
|
|
@@ -88,7 +91,7 @@ export default class DataController {
|
|
|
this.modelToView.on( 'insert:$text', insertText(), { priority: 'lowest' } );
|
|
|
|
|
|
/**
|
|
|
- * View to model conversion dispatcher used by the {@link engine.controller.DataController#set set method}.
|
|
|
+ * View to model conversion dispatcher used by the {@link #set set method}.
|
|
|
* To attach view to model converter to the data pipeline you need to add lister to this property:
|
|
|
*
|
|
|
* data.viewToModel( 'element', customElementConverter );
|
|
|
@@ -98,7 +101,7 @@ export default class DataController {
|
|
|
* buildViewConverter().for( data.viewToModel ).fromElement( 'b' ).toAttribute( 'bold', 'true' );
|
|
|
*
|
|
|
* @readonly
|
|
|
- * @member {engine.conversion.ViewConversionDispatcher} engine.controller.DataController#viewToModel
|
|
|
+ * @member {engine.conversion.ViewConversionDispatcher}
|
|
|
*/
|
|
|
this.viewToModel = new ViewConversionDispatcher( {
|
|
|
schema: model.schema
|
|
|
@@ -119,8 +122,8 @@ export default class DataController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns model's data converted by the {@link engine.controller.DataController#modelToView model to view converters} and
|
|
|
- * formatted by the {@link engine.controller.DataController#processor data processor}.
|
|
|
+ * Returns model's data converted by the {@link #modelToView model to view converters} and
|
|
|
+ * formatted by the {@link #processor data processor}.
|
|
|
*
|
|
|
* @param {String} [rootName='main'] Root name.
|
|
|
* @returns {String} Output data.
|
|
|
@@ -131,11 +134,11 @@ export default class DataController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns the content of the given {@link engine.model.Element model's element} converted by the
|
|
|
- * {@link engine.controller.DataController#modelToView model to view converters} and formatted by the
|
|
|
- * {@link engine.controller.DataController#processor data processor}.
|
|
|
+ * Returns the content of the given {@link module:engine/model/Element model's element} converted by the
|
|
|
+ * {@link #modelToView model to view converters} and formatted by the
|
|
|
+ * {@link #processor data processor}.
|
|
|
*
|
|
|
- * @param {engine.model.Element} modelElement Element which content will be stringified.
|
|
|
+ * @param {module:engine/model/Element} modelElement Element which content will be stringified.
|
|
|
* @returns {String} Output data.
|
|
|
*/
|
|
|
stringify( modelElement ) {
|
|
|
@@ -147,11 +150,11 @@ export default class DataController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns the content of the given {@link engine.model.Element model's element} converted by the
|
|
|
- * {@link engine.controller.DataController#modelToView model to view converters} to the
|
|
|
+ * Returns the content of the given {@link module:engine/model/Element model's element} converted by the
|
|
|
+ * {@link #modelToView model to view converters} to the
|
|
|
* {@link engine.view.DocumentFragment view DocumentFragment}.
|
|
|
*
|
|
|
- * @param {engine.model.Element} modelElement Element which content will be stringified.
|
|
|
+ * @param {module:engine/model/Element} modelElement Element which content will be stringified.
|
|
|
* @returns {engine.view.DocumentFragment} Output view DocumentFragment.
|
|
|
*/
|
|
|
toView( modelElement ) {
|
|
|
@@ -168,11 +171,11 @@ export default class DataController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Sets input data parsed by the {@link engine.controller.DataController#processor data processor} and
|
|
|
- * converted by the {@link engine.controller.DataController#viewToModel view to model converters}.
|
|
|
+ * Sets input data parsed by the {@link #processor data processor} and
|
|
|
+ * converted by the {@link #viewToModel view to model converters}.
|
|
|
*
|
|
|
* This method also creates a batch with all the changes applied. If all you need is to parse data use
|
|
|
- * the {@link engine.controller.DataController#parse} method.
|
|
|
+ * the {@link #parse} method.
|
|
|
*
|
|
|
* @param {String} data Input data.
|
|
|
* @param {String} [rootName='main'] Root name.
|
|
|
@@ -195,14 +198,14 @@ export default class DataController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns data parsed by the {@link engine.controller.DataController#processor data processor} and then
|
|
|
- * converted by the {@link engine.controller.DataController#viewToModel view to model converters}.
|
|
|
+ * Returns data parsed by the {@link #processor data processor} and then
|
|
|
+ * converted by the {@link #viewToModel view to model converters}.
|
|
|
*
|
|
|
- * @see engine.controller.DataController#set
|
|
|
+ * @see #set
|
|
|
* @param {String} data Data to parse.
|
|
|
* @param {String} [context='$root'] Base context in which view will be converted to the model. See:
|
|
|
* {@link engine.conversion.ViewConversionDispatcher#convert}.
|
|
|
- * @returns {engine.model.DocumentFragment} Parsed data.
|
|
|
+ * @returns {module:engine/model/DocumentFragment} Parsed data.
|
|
|
*/
|
|
|
parse( data, context = '$root' ) {
|
|
|
// data -> view
|
|
|
@@ -220,10 +223,10 @@ export default class DataController {
|
|
|
/**
|
|
|
* See {@link engine.controller.insertContent}.
|
|
|
*
|
|
|
- * @fires engine.controller.DataController#insertContent
|
|
|
- * @param {engine.model.DocumentFragment} content The content to insert.
|
|
|
- * @param {engine.model.Selection} selection Selection into which the content should be inserted.
|
|
|
- * @param {engine.model.Batch} [batch] Batch to which deltas will be added. If not specified, then
|
|
|
+ * @fires insertContent
|
|
|
+ * @param {module:engine/model/DocumentFragment} content The content to insert.
|
|
|
+ * @param {module:engine/model/Selection} selection Selection into which the content should be inserted.
|
|
|
+ * @param {module:engine/model/Batch} [batch] Batch to which deltas will be added. If not specified, then
|
|
|
* changes will be added to a new batch.
|
|
|
*/
|
|
|
insertContent( content, selection, batch ) {
|
|
|
@@ -241,9 +244,9 @@ export default class DataController {
|
|
|
* the selection inside the last selected cell" or "delete the row and collapse selection somewhere near".
|
|
|
* That needs to be done in order to ensure that other features which use `deleteContent()` will work well with tables.
|
|
|
*
|
|
|
- * @fires engine.controller.DataController#deleteContent
|
|
|
- * @param {engine.model.Selection} selection Selection of which the content should be deleted.
|
|
|
- * @param {engine.model.Batch} batch Batch to which deltas will be added.
|
|
|
+ * @fires deleteContent
|
|
|
+ * @param {module:engine/model/Selection} selection Selection of which the content should be deleted.
|
|
|
+ * @param {module:engine/model/Batch} batch Batch to which deltas will be added.
|
|
|
* @param {Object} options See {@link engine.controller.deleteContent}'s options.
|
|
|
*/
|
|
|
deleteContent( selection, batch, options ) {
|
|
|
@@ -253,8 +256,8 @@ export default class DataController {
|
|
|
/**
|
|
|
* See {@link engine.controller.modifySelection}.
|
|
|
*
|
|
|
- * @fires engine.controller.DataController#modifySelection
|
|
|
- * @param {engine.model.Selection} The selection to modify.
|
|
|
+ * @fires modifySelection
|
|
|
+ * @param {module:engine/model/Selection} The selection to modify.
|
|
|
* @param {Object} options See {@link engine.controller.modifySelection}'s options.
|
|
|
*/
|
|
|
modifySelection( selection, options ) {
|
|
|
@@ -265,36 +268,36 @@ export default class DataController {
|
|
|
mix( DataController, EmitterMixin );
|
|
|
|
|
|
/**
|
|
|
- * Event fired when {@link engine.controller.DataController#insertContent} method is called.
|
|
|
- * The {@link engine.controller.dataController.insertContent default action of that method} is implemented as a
|
|
|
+ * Event fired when {@link #insertContent} method is called.
|
|
|
+ * The {@link .insertContent default action of that method} is implemented as a
|
|
|
* listener to this event so it can be fully customized by the features.
|
|
|
*
|
|
|
- * @event engine.controller.DataController#insertContent
|
|
|
+ * @event insertContent
|
|
|
* @param {Object} data
|
|
|
* @param {engine.view.DocumentFragment} data.content The content to insert.
|
|
|
- * @param {engine.model.Selection} data.selection Selection into which the content should be inserted.
|
|
|
- * @param {engine.model.Batch} [data.batch] Batch to which deltas will be added.
|
|
|
+ * @param {module:engine/model/Selection} data.selection Selection into which the content should be inserted.
|
|
|
+ * @param {module:engine/model/Batch} [data.batch] Batch to which deltas will be added.
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Event fired when {@link engine.controller.DataController#deleteContent} method is called.
|
|
|
+ * Event fired when {@link #deleteContent} method is called.
|
|
|
* The {@link engine.controller.deleteContent default action of that method} is implemented as a
|
|
|
* listener to this event so it can be fully customized by the features.
|
|
|
*
|
|
|
- * @event engine.controller.DataController#deleteContent
|
|
|
+ * @event deleteContent
|
|
|
* @param {Object} data
|
|
|
- * @param {engine.model.Batch} data.batch
|
|
|
- * @param {engine.model.Selection} data.selection
|
|
|
+ * @param {module:engine/model/Batch} data.batch
|
|
|
+ * @param {module:engine/model/Selection} data.selection
|
|
|
* @param {Object} data.options See {@link engine.controller.deleteContent}'s options.
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Event fired when {@link engine.controller.DataController#modifySelection} method is called.
|
|
|
- * The {@link engine.controller.modifySelection default action of that method} is implemented as a
|
|
|
+ * Event fired when {@link #modifySelection} method is called.
|
|
|
+ * The {@link module:engine/controller/modifyselection~modifySelection default action of that method} is implemented as a
|
|
|
* listener to this event so it can be fully customized by the features.
|
|
|
*
|
|
|
- * @event engine.controller.DataController#modifySelection
|
|
|
+ * @event modifySelection
|
|
|
* @param {Object} data
|
|
|
- * @param {engine.model.Selection} data.selection
|
|
|
- * @param {Object} data.options See {@link engine.controller.modifySelection}'s options.
|
|
|
+ * @param {module:engine/model/Selection} data.selection
|
|
|
+ * @param {Object} data.options See {@link module:engine/controller/modifyselection~modifySelection}'s options.
|
|
|
*/
|