ソースを参照

Remove underscore from private functions.

Maciej Gołaszewski 7 年 前
コミット
5afccd72b2

+ 27 - 27
packages/ckeditor5-engine/src/conversion/downcasthelpers.js

@@ -69,7 +69,7 @@ export default class DowncastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers}
 	 */
 	elementToElement( config ) {
-		return this.add( _downcastElementToElement( config ) );
+		return this.add( downcastElementToElement( config ) );
 	}
 
 	/**
@@ -154,7 +154,7 @@ export default class DowncastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers}
 	 */
 	attributeToElement( config ) {
-		return this.add( _downcastAttributeToElement( config ) );
+		return this.add( downcastAttributeToElement( config ) );
 	}
 
 	/**
@@ -220,7 +220,7 @@ export default class DowncastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers}
 	 */
 	attributeToAttribute( config ) {
-		return this.add( _downcastAttributeToAttribute( config ) );
+		return this.add( downcastAttributeToAttribute( config ) );
 	}
 
 	/**
@@ -282,7 +282,7 @@ export default class DowncastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers}
 	 */
 	markerToElement( config ) {
-		return this.add( _downcastMarkerToElement( config ) );
+		return this.add( downcastMarkerToElement( config ) );
 	}
 
 	/**
@@ -341,7 +341,7 @@ export default class DowncastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/downcasthelpers~DowncastHelpers}
 	 */
 	markerToHighlight( config ) {
-		return this.add( _downcastMarkerToHighlight( config ) );
+		return this.add( downcastMarkerToHighlight( config ) );
 	}
 }
 
@@ -781,7 +781,7 @@ function highlightText( highlightDescriptor ) {
 			return;
 		}
 
-		const descriptor = _prepareDescriptor( highlightDescriptor, data, conversionApi );
+		const descriptor = prepareDescriptor( highlightDescriptor, data, conversionApi );
 
 		if ( !descriptor ) {
 			return;
@@ -844,7 +844,7 @@ function highlightElement( highlightDescriptor ) {
 			return;
 		}
 
-		const descriptor = _prepareDescriptor( highlightDescriptor, data, conversionApi );
+		const descriptor = prepareDescriptor( highlightDescriptor, data, conversionApi );
 
 		if ( !descriptor ) {
 			return;
@@ -903,7 +903,7 @@ function removeHighlight( highlightDescriptor ) {
 			return;
 		}
 
-		const descriptor = _prepareDescriptor( highlightDescriptor, data, conversionApi );
+		const descriptor = prepareDescriptor( highlightDescriptor, data, conversionApi );
 
 		if ( !descriptor ) {
 			return;
@@ -946,10 +946,10 @@ function removeHighlight( highlightDescriptor ) {
 // that takes the model element and {@link module:engine/view/downcastwriter~DowncastWriter view downcast writer}
 // as parameters and returns a view container element.
 // @returns {Function} Conversion helper.
-function _downcastElementToElement( config ) {
+function downcastElementToElement( config ) {
 	config = cloneDeep( config );
 
-	config.view = _normalizeToElementConfig( config.view, 'container' );
+	config.view = normalizeToElementConfig( config.view, 'container' );
 
 	return dispatcher => {
 		dispatcher.on( 'insert:' + config.model, insertElement( config.view ), { priority: config.converterPriority || 'normal' } );
@@ -969,7 +969,7 @@ function _downcastElementToElement( config ) {
 // given, `config.view` should be an object assigning values from `config.model.values` to view element definitions or functions.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _downcastAttributeToElement( config ) {
+function downcastAttributeToElement( config ) {
 	config = cloneDeep( config );
 
 	const modelKey = config.model.key ? config.model.key : config.model;
@@ -981,13 +981,13 @@ function _downcastAttributeToElement( config ) {
 
 	if ( config.model.values ) {
 		for ( const modelValue of config.model.values ) {
-			config.view[ modelValue ] = _normalizeToElementConfig( config.view[ modelValue ], 'attribute' );
+			config.view[ modelValue ] = normalizeToElementConfig( config.view[ modelValue ], 'attribute' );
 		}
 	} else {
-		config.view = _normalizeToElementConfig( config.view, 'attribute' );
+		config.view = normalizeToElementConfig( config.view, 'attribute' );
 	}
 
-	const elementCreator = _getFromAttributeCreator( config );
+	const elementCreator = getFromAttributeCreator( config );
 
 	return dispatcher => {
 		dispatcher.on( eventName, wrap( elementCreator ), { priority: config.converterPriority || 'normal' } );
@@ -1008,7 +1008,7 @@ function _downcastAttributeToElement( config ) {
 // `{ key, value }` objects or a functions.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _downcastAttributeToAttribute( config ) {
+function downcastAttributeToAttribute( config ) {
 	config = cloneDeep( config );
 
 	const modelKey = config.model.key ? config.model.key : config.model;
@@ -1020,13 +1020,13 @@ function _downcastAttributeToAttribute( config ) {
 
 	if ( config.model.values ) {
 		for ( const modelValue of config.model.values ) {
-			config.view[ modelValue ] = _normalizeToAttributeConfig( config.view[ modelValue ] );
+			config.view[ modelValue ] = normalizeToAttributeConfig( config.view[ modelValue ] );
 		}
 	} else {
-		config.view = _normalizeToAttributeConfig( config.view );
+		config.view = normalizeToAttributeConfig( config.view );
 	}
 
-	const elementCreator = _getFromAttributeCreator( config );
+	const elementCreator = getFromAttributeCreator( config );
 
 	return dispatcher => {
 		dispatcher.on( eventName, changeAttribute( elementCreator ), { priority: config.converterPriority || 'normal' } );
@@ -1043,10 +1043,10 @@ function _downcastAttributeToAttribute( config ) {
 // that takes the model marker data as a parameter and returns a view UI element.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _downcastMarkerToElement( config ) {
+function downcastMarkerToElement( config ) {
 	config = cloneDeep( config );
 
-	config.view = _normalizeToElementConfig( config.view, 'ui' );
+	config.view = normalizeToElementConfig( config.view, 'ui' );
 
 	return dispatcher => {
 		dispatcher.on( 'addMarker:' + config.model, insertUIElement( config.view ), { priority: config.converterPriority || 'normal' } );
@@ -1064,7 +1064,7 @@ function _downcastMarkerToElement( config ) {
 // that will be used for highlighting or a function that takes the model marker data as a parameter and returns a highlight descriptor.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _downcastMarkerToHighlight( config ) {
+function downcastMarkerToHighlight( config ) {
 	return dispatcher => {
 		dispatcher.on( 'addMarker:' + config.model, highlightText( config.view ), { priority: config.converterPriority || 'normal' } );
 		dispatcher.on( 'addMarker:' + config.model, highlightElement( config.view ), { priority: config.converterPriority || 'normal' } );
@@ -1078,13 +1078,13 @@ function _downcastMarkerToHighlight( config ) {
 // @param {module:engine/view/elementdefinition~ElementDefinition|Function} view View configuration.
 // @param {'container'|'attribute'|'ui'} viewElementType View element type to create.
 // @returns {Function} Element creator function to use in lower level converters.
-function _normalizeToElementConfig( view, viewElementType ) {
+function normalizeToElementConfig( view, viewElementType ) {
 	if ( typeof view == 'function' ) {
 		// If `view` is already a function, don't do anything.
 		return view;
 	}
 
-	return ( modelData, viewWriter ) => _createViewElementFromDefinition( view, viewWriter, viewElementType );
+	return ( modelData, viewWriter ) => createViewElementFromDefinition( view, viewWriter, viewElementType );
 }
 
 // Creates a view element instance from the provided {@link module:engine/view/elementdefinition~ElementDefinition} and class.
@@ -1093,7 +1093,7 @@ function _normalizeToElementConfig( view, viewElementType ) {
 // @param {module:engine/view/downcastwriter~DowncastWriter} viewWriter
 // @param {'container'|'attribute'|'ui'} viewElementType
 // @returns {module:engine/view/element~Element}
-function _createViewElementFromDefinition( viewElementDefinition, viewWriter, viewElementType ) {
+function createViewElementFromDefinition( viewElementDefinition, viewWriter, viewElementType ) {
 	if ( typeof viewElementDefinition == 'string' ) {
 		// If `viewElementDefinition` is given as a `String`, normalize it to an object with `name` property.
 		viewElementDefinition = { name: viewElementDefinition };
@@ -1138,7 +1138,7 @@ function _createViewElementFromDefinition( viewElementDefinition, viewWriter, vi
 	return element;
 }
 
-function _getFromAttributeCreator( config ) {
+function getFromAttributeCreator( config ) {
 	if ( config.model.values ) {
 		return ( modelAttributeValue, viewWriter ) => {
 			const view = config.view[ modelAttributeValue ];
@@ -1158,7 +1158,7 @@ function _getFromAttributeCreator( config ) {
 // for generating a view attribute.
 //
 // @param {Object} view View configuration.
-function _normalizeToAttributeConfig( view ) {
+function normalizeToAttributeConfig( view ) {
 	if ( typeof view == 'string' ) {
 		return modelAttributeValue => ( { key: view, value: modelAttributeValue } );
 	} else if ( typeof view == 'object' ) {
@@ -1177,7 +1177,7 @@ function _normalizeToAttributeConfig( view ) {
 }
 
 // Helper function for `highlight`. Prepares the actual descriptor object using value passed to the converter.
-function _prepareDescriptor( highlightDescriptor, data, conversionApi ) {
+function prepareDescriptor( highlightDescriptor, data, conversionApi ) {
 	// If passed descriptor is a creator function, call it. If not, just use passed value.
 	const descriptor = typeof highlightDescriptor == 'function' ?
 		highlightDescriptor( data, conversionApi ) :

+ 31 - 31
packages/ckeditor5-engine/src/conversion/upcasthelpers.js

@@ -72,7 +72,7 @@ export default class UpcastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
 	 */
 	elementToElement( config ) {
-		return this.add( _upcastElementToElement( config ) );
+		return this.add( upcastElementToElement( config ) );
 	}
 
 	/**
@@ -158,7 +158,7 @@ export default class UpcastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
 	 */
 	elementToAttribute( config ) {
-		return this.add( _upcastElementToAttribute( config ) );
+		return this.add( upcastElementToAttribute( config ) );
 	}
 
 	/**
@@ -252,7 +252,7 @@ export default class UpcastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
 	 */
 	attributeToAttribute( config ) {
-		return this.add( _upcastAttributeToAttribute( config ) );
+		return this.add( upcastAttributeToAttribute( config ) );
 	}
 
 	/**
@@ -301,7 +301,7 @@ export default class UpcastHelpers extends ConversionHelpers {
 	 * @returns {module:engine/conversion/upcasthelpers~UpcastHelpers}
 	 */
 	elementToMarker( config ) {
-		return this.add( _upcastElementToMarker( config ) );
+		return this.add( upcastElementToMarker( config ) );
 	}
 }
 
@@ -362,12 +362,12 @@ export function convertText() {
 // instance or a function that takes a view element and returns a model element. The model element will be inserted in the model.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _upcastElementToElement( config ) {
+function upcastElementToElement( config ) {
 	config = cloneDeep( config );
 
-	const converter = _prepareToElementConverter( config );
+	const converter = prepareToElementConverter( config );
 
-	const elementName = _getViewElementNameFromConfig( config );
+	const elementName = getViewElementNameFromConfig( config );
 	const eventName = elementName ? 'element:' + elementName : 'element';
 
 	return dispatcher => {
@@ -386,14 +386,14 @@ function _upcastElementToElement( config ) {
 // If `String` is given, the model attribute value will be set to `true`.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _upcastElementToAttribute( config ) {
+function upcastElementToAttribute( config ) {
 	config = cloneDeep( config );
 
-	_normalizeModelAttributeConfig( config );
+	normalizeModelAttributeConfig( config );
 
-	const converter = _prepareToAttributeConverter( config, false );
+	const converter = prepareToAttributeConverter( config, false );
 
-	const elementName = _getViewElementNameFromConfig( config );
+	const elementName = getViewElementNameFromConfig( config );
 	const eventName = elementName ? 'element:' + elementName : 'element';
 
 	return dispatcher => {
@@ -416,18 +416,18 @@ function _upcastElementToAttribute( config ) {
 // If `String` is given, the model attribute value will be same as view attribute value.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='low'] Converter priority.
 // @returns {Function} Conversion helper.
-function _upcastAttributeToAttribute( config ) {
+function upcastAttributeToAttribute( config ) {
 	config = cloneDeep( config );
 
 	let viewKey = null;
 
 	if ( typeof config.view == 'string' || config.view.key ) {
-		viewKey = _normalizeViewAttributeKeyValueConfig( config );
+		viewKey = normalizeViewAttributeKeyValueConfig( config );
 	}
 
-	_normalizeModelAttributeConfig( config, viewKey );
+	normalizeModelAttributeConfig( config, viewKey );
 
-	const converter = _prepareToAttributeConverter( config, true );
+	const converter = prepareToAttributeConverter( config, true );
 
 	return dispatcher => {
 		dispatcher.on( 'element', converter, { priority: config.converterPriority || 'low' } );
@@ -444,12 +444,12 @@ function _upcastAttributeToAttribute( config ) {
 // a model marker name.
 // @param {module:utils/priorities~PriorityString} [config.converterPriority='normal'] Converter priority.
 // @returns {Function} Conversion helper.
-function _upcastElementToMarker( config ) {
+function upcastElementToMarker( config ) {
 	config = cloneDeep( config );
 
-	_normalizeToMarkerConfig( config );
+	normalizeToMarkerConfig( config );
 
-	return _upcastElementToElement( config );
+	return upcastElementToElement( config );
 }
 
 // Helper function for from-view-element conversion. Checks if `config.view` directly specifies converted view element's name
@@ -457,7 +457,7 @@ function _upcastElementToMarker( config ) {
 //
 // @param {Object} config Conversion config.
 // @returns {String|null} View element name or `null` if name is not directly set.
-function _getViewElementNameFromConfig( config ) {
+function getViewElementNameFromConfig( config ) {
 	if ( typeof config.view == 'string' ) {
 		return config.view;
 	}
@@ -473,7 +473,7 @@ function _getViewElementNameFromConfig( config ) {
 //
 // @param {Object} config Conversion configuration.
 // @returns {Function} View to model converter.
-function _prepareToElementConverter( config ) {
+function prepareToElementConverter( config ) {
 	const matcher = new Matcher( config.view );
 
 	return ( evt, data, conversionApi ) => {
@@ -489,7 +489,7 @@ function _prepareToElementConverter( config ) {
 		match.match.name = true;
 
 		// Create model element basing on config.
-		const modelElement = _getModelElement( config.model, data.viewItem, conversionApi.writer );
+		const modelElement = getModelElement( config.model, data.viewItem, conversionApi.writer );
 
 		// Do not convert if element building function returned falsy value.
 		if ( !modelElement ) {
@@ -552,7 +552,7 @@ function _prepareToElementConverter( config ) {
 // @param {String|Function|module:engine/model/element~Element} model Model conversion configuration.
 // @param {module:engine/view/node~Node} input The converted view node.
 // @param {module:engine/model/writer~Writer} writer A writer instance to use to create the model element.
-function _getModelElement( model, input, writer ) {
+function getModelElement( model, input, writer ) {
 	if ( model instanceof Function ) {
 		return model( input, writer );
 	} else {
@@ -566,7 +566,7 @@ function _getModelElement( model, input, writer ) {
 //
 // @param {Object} config Conversion config.
 // @returns {String} Key of the converted view attribute.
-function _normalizeViewAttributeKeyValueConfig( config ) {
+function normalizeViewAttributeKeyValueConfig( config ) {
 	if ( typeof config.view == 'string' ) {
 		config.view = { key: config.view };
 	}
@@ -606,7 +606,7 @@ function _normalizeViewAttributeKeyValueConfig( config ) {
 // @param {Object} config Conversion config.
 // @param {String} viewAttributeKeyToCopy Key of the converted view attribute. If it is set, model attribute value
 // will be equal to view attribute value.
-function _normalizeModelAttributeConfig( config, viewAttributeKeyToCopy = null ) {
+function normalizeModelAttributeConfig( config, viewAttributeKeyToCopy = null ) {
 	const defaultModelValue = viewAttributeKeyToCopy === null ? true : viewElement => viewElement.getAttribute( viewAttributeKeyToCopy );
 
 	const key = typeof config.model != 'object' ? config.model : config.model.key;
@@ -622,7 +622,7 @@ function _normalizeModelAttributeConfig( config, viewAttributeKeyToCopy = null )
 // @param {Object|Array.<Object>} config Conversion configuration. It is possible to provide multiple configurations in an array.
 // @param {Boolean} shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
 // on all elements in the range.
-function _prepareToAttributeConverter( config, shallow ) {
+function prepareToAttributeConverter( config, shallow ) {
 	const matcher = new Matcher( config.view );
 
 	return ( evt, data, conversionApi ) => {
@@ -641,7 +641,7 @@ function _prepareToAttributeConverter( config, shallow ) {
 			return;
 		}
 
-		if ( _onlyViewNameIsDefined( config ) ) {
+		if ( onlyViewNameIsDefined( config ) ) {
 			match.match.name = true;
 		} else {
 			// Do not test or consume `name` consumable.
@@ -661,7 +661,7 @@ function _prepareToAttributeConverter( config, shallow ) {
 		}
 
 		// Set attribute on current `output`. `Schema` is checked inside this helper function.
-		const attributeWasSet = _setAttributeOn( data.modelRange, { key: modelKey, value: modelValue }, shallow, conversionApi );
+		const attributeWasSet = setAttributeOn( data.modelRange, { key: modelKey, value: modelValue }, shallow, conversionApi );
 
 		if ( attributeWasSet ) {
 			conversionApi.consumable.consume( data.viewItem, match.match );
@@ -673,8 +673,8 @@ function _prepareToAttributeConverter( config, shallow ) {
 //
 // @param {Object} config Conversion config.
 // @returns {Boolean}
-function _onlyViewNameIsDefined( config ) {
-	if ( typeof config.view == 'object' && !_getViewElementNameFromConfig( config ) ) {
+function onlyViewNameIsDefined( config ) {
+	if ( typeof config.view == 'object' && !getViewElementNameFromConfig( config ) ) {
 		return false;
 	}
 
@@ -690,7 +690,7 @@ function _onlyViewNameIsDefined( config ) {
 // @param {Boolean} shallow If set to `true` the attribute will be set only on top-level nodes. Otherwise, it will be set
 // on all elements in the range.
 // @returns {Boolean} `true` if attribute was set on at least one node from given `modelRange`.
-function _setAttributeOn( modelRange, modelAttribute, shallow, conversionApi ) {
+function setAttributeOn( modelRange, modelAttribute, shallow, conversionApi ) {
 	let result = false;
 
 	// Set attribute on each item in range according to Schema.
@@ -709,7 +709,7 @@ function _setAttributeOn( modelRange, modelAttribute, shallow, conversionApi ) {
 // function and converts it to a format that is supported by `_upcastElementToElement()` function.
 //
 // @param {Object} config Conversion configuration.
-function _normalizeToMarkerConfig( config ) {
+function normalizeToMarkerConfig( config ) {
 	const oldModel = config.model;
 
 	config.model = ( viewElement, modelWriter ) => {