Kaynağa Gözat

Other: Rename ViewElementDefinition attributes to plural names.

Maciej Gołaszewski 8 yıl önce
ebeveyn
işleme
69f4ba2d5b

+ 5 - 0
packages/ckeditor5-engine/src/conversion/attributeconverters.js

@@ -7,6 +7,11 @@ import AttributeElement from '../view/attributeelement';
 import buildModelConverter from './buildmodelconverter';
 import { defineConverter, parseDefinition } from './utils';
 
+/**
+ * @param {String} attributeName
+ * @param {module:engine/view/viewelementdefinition~ViewElementDefinition} definition
+ * @param dispatchers
+ */
 export function modelAttributeToView( attributeName, definition, dispatchers ) {
 	const { model: attributeValue, viewDefinition } = parseDefinition( definition );
 

+ 3 - 3
packages/ckeditor5-engine/src/conversion/utils.js

@@ -19,9 +19,9 @@ export function parseDefinition( definition ) {
 
 export function definitionToPattern( viewDefinition ) {
 	const name = viewDefinition.name;
-	const classes = viewDefinition.class;
-	const styles = viewDefinition.style;
-	const attributes = viewDefinition.attribute;
+	const classes = viewDefinition.classes;
+	const styles = viewDefinition.styles;
+	const attributes = viewDefinition.attributes;
 
 	const pattern = { name };
 

+ 18 - 8
packages/ckeditor5-engine/src/view/element.js

@@ -712,24 +712,34 @@ export default class Element extends Node {
 			( attributes == '' ? '' : ` ${ attributes }` );
 	}
 
-	static fromViewDefinition( viewDefinition ) {
+	/**
+	 * Creates element instance from provided viewElementDefinition.
+	 *
+	 * @param {module:engine/view/viewelementdefinition~ViewElementDefinition} viewElementDefinition
+	 * @returns {Element}
+	 */
+	static fromViewDefinition( viewElementDefinition ) {
 		const attributes = {};
 
-		const classes = viewDefinition.class;
+		const classes = viewElementDefinition.classes;
 
-		if ( viewDefinition.class ) {
+		if ( classes ) {
 			attributes.class = Array.isArray( classes ) ? classes.join( ' ' ) : classes;
 		}
 
-		if ( viewDefinition.style ) {
-			attributes.style = toStylesString( viewDefinition.style );
+		const stylesObject = viewElementDefinition.styles;
+
+		if ( stylesObject ) {
+			attributes.style = toStylesString( stylesObject );
 		}
 
-		if ( viewDefinition.attribute ) {
-			attributes.attribute = viewDefinition.attribute;
+		const attributesObject = viewElementDefinition.attributes;
+
+		if ( attributesObject ) {
+			attributes.attribute = attributesObject;
 		}
 
-		return new this( viewDefinition.name, attributes );
+		return new this( viewElementDefinition.name, attributes );
 
 		function toStylesString( stylesObject ) {
 			const styles = [];

+ 3 - 3
packages/ckeditor5-engine/src/view/viewelementdefinition.jsdoc

@@ -13,10 +13,10 @@
  * @typedef {Object} module:engine/view/viewelementdefinition~ViewElementDefinition
  *
  * @property {String} name View element attribute name.
- * @property {String|Array.<String>} [class] Class name or array of class names to match. Each name can be
+ * @property {String|Array.<String>} [classes] Class name or array of class names to match. Each name can be
  * provided in a form of string.
- * @property {Object} [style] Object with key-value pairs representing styles to match. Each object key
+ * @property {Object} [styles] Object with key-value pairs representing styles to match. Each object key
  * represents style name. Value under that key must be a string.
- * @property {Object} [attribute] Object with key-value pairs representing attributes to match. Each object key
+ * @property {Object} [attributes] Object with key-value pairs representing attributes to match. Each object key
  * represents attribute name. Value under that key must be a string.
  */