Selaa lähdekoodia

Merge branch 'master' into t/ckeditor5-engine/1210

Szymon Kupś 7 vuotta sitten
vanhempi
commit
4b1dd99175

+ 15 - 13
packages/ckeditor5-widget/src/highlightstack.js

@@ -11,12 +11,14 @@ import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 
 /**
- * Class used to handle correct order of
- * {@link module:engine/conversion/buildmodelconverter~ModelConverterBuilder#toHighlight highlights} on
- * elements. When different highlights are applied to same element correct order should be preserved:
+ * Class used to handle correct order of highlights on elements.
+ *
+ * When different highlights are applied to same element correct order should be preserved:
+ *
  * * highlight with highest priority should be applied,
  * * if two highlights have same priority - sort by CSS class provided in
- * {@link module:engine/conversion/model-to-view-converters~HighlightDescriptor}.
+ * {@link module:engine/conversion/downcast-converters~HighlightDescriptor}.
+ *
  * This way, highlight will be applied with the same rules it is applied on texts.
  */
 export default class HighlightStack {
@@ -31,7 +33,7 @@ export default class HighlightStack {
 	 * Adds highlight descriptor to the stack.
 	 *
 	 * @fires change:top
-	 * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
+	 * @param {module:engine/conversion/downcast-converters~HighlightDescriptor} descriptor
 	 */
 	add( descriptor ) {
 		const stack = this._stack;
@@ -77,7 +79,7 @@ export default class HighlightStack {
 	 * descriptor with same id is already present.
 	 *
 	 * @private
-	 * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} descriptor
+	 * @param {module:engine/conversion/downcast-converters~HighlightDescriptor} descriptor
 	 */
 	_insertDescriptor( descriptor ) {
 		const stack = this._stack;
@@ -125,8 +127,8 @@ mix( HighlightStack, EmitterMixin );
 
 // Compares two descriptors by checking their priority and class list.
 //
-// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} a
-// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} b
+// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} a
+// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} b
 // @returns {Boolean} Returns true if both descriptors are defined and have same priority and classes.
 function compareDescriptors( a, b ) {
 	return a && b && a.priority == b.priority && classesToString( a.class ) == classesToString( b.class );
@@ -134,8 +136,8 @@ function compareDescriptors( a, b ) {
 
 // Checks whenever first descriptor should be placed in the stack before second one.
 //
-// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} a
-// @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} b
+// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} a
+// @param {module:engine/conversion/downcast-converters~HighlightDescriptor} b
 // @returns {Boolean}
 function shouldABeBeforeB( a, b ) {
 	if ( a.priority > b.priority ) {
@@ -148,7 +150,7 @@ function shouldABeBeforeB( a, b ) {
 	return classesToString( a.class ) > classesToString( b.class );
 }
 
-// Converts CSS classes passed with {@link module:engine/conversion/model-to-view-converters~HighlightDescriptor} to
+// Converts CSS classes passed with {@link module:engine/conversion/downcast-converters~HighlightDescriptor} to
 // sorted string.
 //
 // @param {String|Array<String>} descriptor
@@ -162,8 +164,8 @@ function classesToString( classes ) {
  *
  * @event change:top
  * @param {Object} data Additional information about the change.
- * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} [data.newDescriptor] New highlight
+ * @param {module:engine/conversion/downcast-converters~HighlightDescriptor} [data.newDescriptor] New highlight
  * descriptor. It will be `undefined` when last descriptor is removed from the stack.
- * @param {module:engine/conversion/model-to-view-converters~HighlightDescriptor} [data.oldDescriptor] Old highlight
+ * @param {module:engine/conversion/downcast-converters~HighlightDescriptor} [data.oldDescriptor] Old highlight
  * descriptor. It will be `undefined` when first descriptor is added to the stack.
  */

+ 1 - 1
packages/ckeditor5-widget/src/widget.js

@@ -55,7 +55,7 @@ export default class Widget extends Plugin {
 
 		// Model to view selection converter.
 		// Converts selection placed over widget element to fake selection
-		this.editor.editing.modelToView.on( 'selection', ( evt, data, consumable, conversionApi ) => {
+		this.editor.editing.downcastDispatcher.on( 'selection', ( evt, data, consumable, conversionApi ) => {
 			// Remove selected class from previously selected widgets.
 			this._clearPreviouslySelectedWidgets();
 

+ 24 - 37
packages/ckeditor5-widget/tests/widget.js

@@ -7,7 +7,7 @@ import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtest
 import Widget from '../src/widget';
 import Typing from '@ckeditor/ckeditor5-typing/src/typing';
 import MouseObserver from '@ckeditor/ckeditor5-engine/src/view/observer/mouseobserver';
-import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
+import { downcastElementToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
 import { toWidget } from '../src/utils';
 import ViewContainer from '@ckeditor/ckeditor5-engine/src/view/containerelement';
 import ViewEditable from '@ckeditor/ckeditor5-engine/src/view/editableelement';
@@ -71,42 +71,29 @@ describe( 'Widget', () => {
 					allowIn: [ 'blockQuote', 'div' ]
 				} );
 
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'paragraph' )
-					.toElement( 'p' );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'widget' )
-					.toElement( () => {
-						const b = new AttributeContainer( 'b' );
-						const div = new ViewContainer( 'div', null, b );
-
-						return toWidget( div, { label: 'element label' } );
-					} );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'inline' )
-					.toElement( 'figure' );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'nested' )
-					.toElement( () => new ViewEditable( 'figcaption', { contenteditable: true } ) );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'editable' )
-					.toElement( () => new ViewEditable( 'figcaption', { contenteditable: true } ) );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'image' )
-					.toElement( 'img' );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'blockQuote' )
-					.toElement( 'blockquote' );
-
-				buildModelConverter().for( editor.editing.modelToView )
-					.fromElement( 'div' )
-					.toElement( 'div' );
+				editor.conversion.for( 'downcast' )
+					.add( downcastElementToElement( { model: 'paragraph', view: 'p' } ) )
+					.add( downcastElementToElement( { model: 'inline', view: 'figure' } ) )
+					.add( downcastElementToElement( { model: 'image', view: 'img' } ) )
+					.add( downcastElementToElement( { model: 'blockQuote', view: 'blockquote' } ) )
+					.add( downcastElementToElement( { model: 'div', view: 'div' } ) )
+					.add( downcastElementToElement( {
+						model: 'widget',
+						view: () => {
+							const b = new AttributeContainer( 'b' );
+							const div = new ViewContainer( 'div', null, b );
+
+							return toWidget( div, { label: 'element label' } );
+						}
+					} ) )
+					.add( downcastElementToElement( {
+						model: 'nested',
+						view: () => new ViewEditable( 'figcaption', { contenteditable: true } )
+					} ) )
+					.add( downcastElementToElement( {
+						model: 'editable',
+						view: () => new ViewEditable( 'figcaption', { contenteditable: true } )
+					} ) );
 			} );
 	} );