Selaa lähdekoodia

Styles Processor must be unique across the entire editor instance.

Kamil Piechaczek 6 vuotta sitten
vanhempi
sitoutus
c5b34869b7

+ 11 - 2
packages/ckeditor5-engine/src/controller/datacontroller.js

@@ -47,10 +47,11 @@ export default class DataController {
 	 * Creates a data controller instance.
 	 *
 	 * @param {module:engine/model/model~Model} model Data model.
+	 * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor.
 	 * @param {module:engine/dataprocessor/dataprocessor~DataProcessor} [dataProcessor] Data processor that should be used
 	 * by the controller.
 	 */
-	constructor( model, dataProcessor ) {
+	constructor( model, stylesProcessor, dataProcessor ) {
 		/**
 		 * Data model.
 		 *
@@ -59,6 +60,14 @@ export default class DataController {
 		 */
 		this.model = model;
 
+		/**
+		 * Styles processor.
+		 *
+		 * @readonly
+		 * @member {module:engine/view/stylesmap~StylesProcessor}
+		 */
+		this.stylesProcessor = stylesProcessor;
+
 		/**
 		 * Data processor used during the conversion.
 		 *
@@ -187,7 +196,7 @@ export default class DataController {
 
 		// First, convert elements.
 		const modelRange = ModelRange._createIn( modelElementOrFragment );
-		const viewDocument = new ViewDocument();
+		const viewDocument = new ViewDocument( this.stylesProcessor );
 
 		const viewDocumentFragment = new ViewDocumentFragment( viewDocument );
 

+ 3 - 2
packages/ckeditor5-engine/src/controller/editingcontroller.js

@@ -31,8 +31,9 @@ export default class EditingController {
 	 * Creates an editing controller instance.
 	 *
 	 * @param {module:engine/model/model~Model} model Editing model.
+	 * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor.
 	 */
-	constructor( model ) {
+	constructor( model, stylesProcessor ) {
 		/**
 		 * Editor model.
 		 *
@@ -47,7 +48,7 @@ export default class EditingController {
 		 * @readonly
 		 * @member {module:engine/view/view~View}
 		 */
-		this.view = new View();
+		this.view = new View( stylesProcessor );
 
 		/**
 		 * Mapper which describes the model-view binding.

+ 12 - 2
packages/ckeditor5-engine/src/dataprocessor/htmldataprocessor.js

@@ -22,8 +22,18 @@ import ViewDocument from '../view/document';
 export default class HtmlDataProcessor {
 	/**
 	 * Creates a new instance of the HTML data processor class.
+	 *
+	 * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor.
 	 */
-	constructor() {
+	constructor( stylesProcessor ) {
+		/**
+		 * Styles processor.
+		 *
+		 * @readonly
+		 * @member {module:engine/view/stylesmap~StylesProcessor}
+		 */
+		this.stylesProcessor = stylesProcessor;
+
 		/**
 		 * A DOM parser instance used to parse an HTML string to an HTML document.
 		 *
@@ -73,7 +83,7 @@ export default class HtmlDataProcessor {
 	toView( data ) {
 		// Convert input HTML data to DOM DocumentFragment.
 		const domFragment = this._toDom( data );
-		const viewDocument = new ViewDocument();
+		const viewDocument = new ViewDocument( this.stylesProcessor );
 
 		// Convert DOM DocumentFragment to view DocumentFragment.
 		return this._domConverter.domToView( viewDocument, domFragment );

+ 4 - 3
packages/ckeditor5-engine/src/view/document.js

@@ -11,7 +11,6 @@ import DocumentSelection from './documentselection';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
-import { StylesProcessor } from './stylesmap';
 
 // @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );
 
@@ -24,8 +23,10 @@ import { StylesProcessor } from './stylesmap';
 export default class Document {
 	/**
 	 * Creates a Document instance.
+	 *
+	 * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor.
 	 */
-	constructor() {
+	constructor( stylesProcessor ) {
 		/**
 		 * Selection done on this document.
 		 *
@@ -53,7 +54,7 @@ export default class Document {
 		 * @readonly
 		 * @member {module:engine/view/stylesmap~StylesProcessor}
 		 */
-		this.stylesProcessor = new StylesProcessor();
+		this.stylesProcessor = stylesProcessor;
 
 		/**
 		 * Defines whether document is in read-only mode.

+ 5 - 2
packages/ckeditor5-engine/src/view/view.js

@@ -62,14 +62,17 @@ import env from '@ckeditor/ckeditor5-utils/src/env';
  * @mixes module:utils/observablemixin~ObservableMixin
  */
 export default class View {
-	constructor() {
+	/**
+	 * @param {module:engine/view/stylesmap~StylesProcessor} stylesProcessor Styles processor.
+	 */
+	constructor( stylesProcessor ) {
 		/**
 		 * Instance of the {@link module:engine/view/document~Document} associated with this view controller.
 		 *
 		 * @readonly
 		 * @type {module:engine/view/document~Document}
 		 */
-		this.document = new Document();
+		this.document = new Document( stylesProcessor );
 
 		/**
 		 * Instance of the {@link module:engine/view/domconverter~DomConverter domConverter} used by