From 0aee9c535db7c530fc42a915da5a343bf05b0dc2 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Tue, 18 Feb 2020 16:16:48 +0100 Subject: [PATCH 1/6] Styles Processor must be unique across the entire editor instance. --- src/editor/editor.js | 13 +++++++++++-- tests/_utils/virtualtesteditor.js | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/editor/editor.js b/src/editor/editor.js index f399bcac..0ebd3f93 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -20,6 +20,7 @@ import EditingKeystrokeHandler from '../editingkeystrokehandler'; import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin'; import mix from '@ckeditor/ckeditor5-utils/src/mix'; import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror'; +import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap'; /** * The class representing a basic, generic editor. @@ -161,6 +162,14 @@ export default class Editor { */ this.model = new Model(); + /** + * StylesProcessor is responsible for writing and reading a normalized styles object. + * + * @readonly + * @member {module:engine/view/stylesmap~StylesProcessor} + */ + this.stylesProcessor = new StylesProcessor(); + /** * The {@link module:engine/controller/datacontroller~DataController data controller}. * Used e.g. for setting and retrieving the editor data. @@ -168,7 +177,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/datacontroller~DataController} */ - this.data = new DataController( this.model ); + this.data = new DataController( this.model, this.stylesProcessor ); /** * The {@link module:engine/controller/editingcontroller~EditingController editing controller}. @@ -177,7 +186,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/editingcontroller~EditingController} */ - this.editing = new EditingController( this.model ); + this.editing = new EditingController( this.model, this.stylesProcessor ); this.editing.view.document.bind( 'isReadOnly' ).to( this ); /** diff --git a/tests/_utils/virtualtesteditor.js b/tests/_utils/virtualtesteditor.js index a3f1a108..f877e51f 100644 --- a/tests/_utils/virtualtesteditor.js +++ b/tests/_utils/virtualtesteditor.js @@ -21,7 +21,7 @@ export default class VirtualTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor(); + this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); From ccdec088818226f38fdf0b8d609ab51b1f4510d5 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Wed, 19 Feb 2020 14:06:07 +0100 Subject: [PATCH 2/6] Aligned changes to API in engine. --- tests/_utils/classictesteditor.js | 2 +- tests/_utils/modeltesteditor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/_utils/classictesteditor.js b/tests/_utils/classictesteditor.js index e10f5b27..d44d6bdc 100644 --- a/tests/_utils/classictesteditor.js +++ b/tests/_utils/classictesteditor.js @@ -34,7 +34,7 @@ export default class ClassicTestEditor extends Editor { } // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor(); + this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); diff --git a/tests/_utils/modeltesteditor.js b/tests/_utils/modeltesteditor.js index 98e93423..b80f1a73 100644 --- a/tests/_utils/modeltesteditor.js +++ b/tests/_utils/modeltesteditor.js @@ -21,7 +21,7 @@ export default class ModelTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor(); + this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); // Disable editing pipeline. this.editing.destroy(); From 52b331e06531a7d9e56f196ca38f36a941e501df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Go=C5=82aszewski?= Date: Wed, 19 Feb 2020 15:42:10 +0100 Subject: [PATCH 3/6] Add missing StylesProcessor instance. --- tests/editor/utils/attachtoform.js | 2 +- tests/editor/utils/dataapimixin.js | 2 +- tests/editor/utils/elementapimixin.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/editor/utils/attachtoform.js b/tests/editor/utils/attachtoform.js index 6af19f92..94d5221f 100644 --- a/tests/editor/utils/attachtoform.js +++ b/tests/editor/utils/attachtoform.js @@ -31,7 +31,7 @@ describe( 'attachToForm()', () => { mix( CustomEditor, ElementApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor(); + editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); editor.model.document.createRoot(); editor.model.schema.extend( '$text', { allowIn: '$root' } ); editor.fire( 'ready' ); diff --git a/tests/editor/utils/dataapimixin.js b/tests/editor/utils/dataapimixin.js index d847913a..51904cbd 100644 --- a/tests/editor/utils/dataapimixin.js +++ b/tests/editor/utils/dataapimixin.js @@ -18,7 +18,7 @@ describe( 'DataApiMixin', () => { mix( CustomEditor, DataApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor(); + editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); editor.model.document.createRoot( '$root', 'main' ); editor.model.document.createRoot( '$root', 'secondRoot' ); editor.model.schema.extend( '$text', { allowIn: '$root' } ); diff --git a/tests/editor/utils/elementapimixin.js b/tests/editor/utils/elementapimixin.js index eb2cbbc8..5ed8579e 100644 --- a/tests/editor/utils/elementapimixin.js +++ b/tests/editor/utils/elementapimixin.js @@ -19,7 +19,7 @@ describe( 'ElementApiMixin', () => { mix( CustomEditor, ElementApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor(); + editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); editor.model.document.createRoot(); editor.model.schema.extend( '$text', { allowIn: '$root' } ); } ); From 045557c1c7cd744c2244bc1517425c28d91f2e21 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Thu, 20 Feb 2020 13:52:54 +0100 Subject: [PATCH 4/6] StylesProcessor is no longer a property of the core Editor class. --- src/editor/editor.js | 14 ++++---------- tests/_utils/classictesteditor.js | 2 +- tests/_utils/modeltesteditor.js | 2 +- tests/_utils/virtualtesteditor.js | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/editor/editor.js b/src/editor/editor.js index 0ebd3f93..c5ad8fd7 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -52,6 +52,8 @@ export default class Editor { * @param {Object} [config={}] The editor configuration. */ constructor( config = {} ) { + const stylesProcessor = new StylesProcessor(); + /** * The editor context. * When it is not provided through the configuration, the editor creates it. @@ -162,14 +164,6 @@ export default class Editor { */ this.model = new Model(); - /** - * StylesProcessor is responsible for writing and reading a normalized styles object. - * - * @readonly - * @member {module:engine/view/stylesmap~StylesProcessor} - */ - this.stylesProcessor = new StylesProcessor(); - /** * The {@link module:engine/controller/datacontroller~DataController data controller}. * Used e.g. for setting and retrieving the editor data. @@ -177,7 +171,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/datacontroller~DataController} */ - this.data = new DataController( this.model, this.stylesProcessor ); + this.data = new DataController( this.model, stylesProcessor ); /** * The {@link module:engine/controller/editingcontroller~EditingController editing controller}. @@ -186,7 +180,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/editingcontroller~EditingController} */ - this.editing = new EditingController( this.model, this.stylesProcessor ); + this.editing = new EditingController( this.model, stylesProcessor ); this.editing.view.document.bind( 'isReadOnly' ).to( this ); /** diff --git a/tests/_utils/classictesteditor.js b/tests/_utils/classictesteditor.js index d44d6bdc..15f9f866 100644 --- a/tests/_utils/classictesteditor.js +++ b/tests/_utils/classictesteditor.js @@ -34,7 +34,7 @@ export default class ClassicTestEditor extends Editor { } // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); diff --git a/tests/_utils/modeltesteditor.js b/tests/_utils/modeltesteditor.js index b80f1a73..8d051baa 100644 --- a/tests/_utils/modeltesteditor.js +++ b/tests/_utils/modeltesteditor.js @@ -21,7 +21,7 @@ export default class ModelTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); // Disable editing pipeline. this.editing.destroy(); diff --git a/tests/_utils/virtualtesteditor.js b/tests/_utils/virtualtesteditor.js index f877e51f..59ba76b2 100644 --- a/tests/_utils/virtualtesteditor.js +++ b/tests/_utils/virtualtesteditor.js @@ -21,7 +21,7 @@ export default class VirtualTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); From 0e3dd2d7e6aa33ad9476d2774c754595ea362f6f Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 24 Feb 2020 16:14:30 +0100 Subject: [PATCH 5/6] Requested changes during the review. --- src/editor/editor.js | 2 +- tests/_utils/classictesteditor.js | 2 +- tests/_utils/modeltesteditor.js | 2 +- tests/_utils/virtualtesteditor.js | 2 +- tests/editor/utils/attachtoform.js | 2 +- tests/editor/utils/dataapimixin.js | 2 +- tests/editor/utils/elementapimixin.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/editor/editor.js b/src/editor/editor.js index c5ad8fd7..cea52ee1 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -171,7 +171,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/datacontroller~DataController} */ - this.data = new DataController( this.model, stylesProcessor ); + this.data = new DataController( stylesProcessor, this.model ); /** * The {@link module:engine/controller/editingcontroller~EditingController editing controller}. diff --git a/tests/_utils/classictesteditor.js b/tests/_utils/classictesteditor.js index 15f9f866..0bc3e80f 100644 --- a/tests/_utils/classictesteditor.js +++ b/tests/_utils/classictesteditor.js @@ -34,7 +34,7 @@ export default class ClassicTestEditor extends Editor { } // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.editing.view.document ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); diff --git a/tests/_utils/modeltesteditor.js b/tests/_utils/modeltesteditor.js index 8d051baa..55e6ec5a 100644 --- a/tests/_utils/modeltesteditor.js +++ b/tests/_utils/modeltesteditor.js @@ -21,7 +21,7 @@ export default class ModelTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.editing.view.document ); // Disable editing pipeline. this.editing.destroy(); diff --git a/tests/_utils/virtualtesteditor.js b/tests/_utils/virtualtesteditor.js index 59ba76b2..527604e1 100644 --- a/tests/_utils/virtualtesteditor.js +++ b/tests/_utils/virtualtesteditor.js @@ -21,7 +21,7 @@ export default class VirtualTestEditor extends Editor { super( config ); // Use the HTML data processor in this editor. - this.data.processor = new HtmlDataProcessor( this.data.stylesProcessor ); + this.data.processor = new HtmlDataProcessor( this.editing.view.document ); // Create the ("main") root element of the model tree. this.model.document.createRoot(); diff --git a/tests/editor/utils/attachtoform.js b/tests/editor/utils/attachtoform.js index 94d5221f..8a66b111 100644 --- a/tests/editor/utils/attachtoform.js +++ b/tests/editor/utils/attachtoform.js @@ -31,7 +31,7 @@ describe( 'attachToForm()', () => { mix( CustomEditor, ElementApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); + editor.data.processor = new HtmlDataProcessor( editor.editing.view.document ); editor.model.document.createRoot(); editor.model.schema.extend( '$text', { allowIn: '$root' } ); editor.fire( 'ready' ); diff --git a/tests/editor/utils/dataapimixin.js b/tests/editor/utils/dataapimixin.js index 51904cbd..05013429 100644 --- a/tests/editor/utils/dataapimixin.js +++ b/tests/editor/utils/dataapimixin.js @@ -18,7 +18,7 @@ describe( 'DataApiMixin', () => { mix( CustomEditor, DataApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); + editor.data.processor = new HtmlDataProcessor( editor.editing.view.document ); editor.model.document.createRoot( '$root', 'main' ); editor.model.document.createRoot( '$root', 'secondRoot' ); editor.model.schema.extend( '$text', { allowIn: '$root' } ); diff --git a/tests/editor/utils/elementapimixin.js b/tests/editor/utils/elementapimixin.js index 5ed8579e..69ec0e12 100644 --- a/tests/editor/utils/elementapimixin.js +++ b/tests/editor/utils/elementapimixin.js @@ -19,7 +19,7 @@ describe( 'ElementApiMixin', () => { mix( CustomEditor, ElementApiMixin ); editor = new CustomEditor(); - editor.data.processor = new HtmlDataProcessor( editor.stylesProcessor ); + editor.data.processor = new HtmlDataProcessor( editor.editing.view.document ); editor.model.document.createRoot(); editor.model.schema.extend( '$text', { allowIn: '$root' } ); } ); From 1d6c93927638d6b6088b78873eba093a042445c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Tue, 3 Mar 2020 12:31:57 +0100 Subject: [PATCH 6/6] Aligned to changes in the engine. --- src/editor/editor.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/editor/editor.js b/src/editor/editor.js index cea52ee1..bbca39ee 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -52,8 +52,6 @@ export default class Editor { * @param {Object} [config={}] The editor configuration. */ constructor( config = {} ) { - const stylesProcessor = new StylesProcessor(); - /** * The editor context. * When it is not provided through the configuration, the editor creates it. @@ -164,6 +162,8 @@ export default class Editor { */ this.model = new Model(); + const stylesProcessor = new StylesProcessor(); + /** * The {@link module:engine/controller/datacontroller~DataController data controller}. * Used e.g. for setting and retrieving the editor data. @@ -171,7 +171,7 @@ export default class Editor { * @readonly * @member {module:engine/controller/datacontroller~DataController} */ - this.data = new DataController( stylesProcessor, this.model ); + this.data = new DataController( this.model, stylesProcessor ); /** * The {@link module:engine/controller/editingcontroller~EditingController editing controller}.