8
0
فهرست منبع

Rename StylesMap.removeProperty() to remove().

Maciej Gołaszewski 6 سال پیش
والد
کامیت
e315e45cdc

+ 1 - 1
packages/ckeditor5-engine/src/view/element.js

@@ -759,7 +759,7 @@ export default class Element extends Node {
 		this._fireChange( 'attributes', this );
 
 		property = Array.isArray( property ) ? property : [ property ];
-		property.forEach( name => this._styles.removeProperty( name ) );
+		property.forEach( name => this._styles.remove( name ) );
 	}
 
 	/**

+ 27 - 9
packages/ckeditor5-engine/src/view/stylesmap.js

@@ -90,27 +90,27 @@ export default class StylesMap {
 	 *		styles.has( 'margin-top' );     // returns true
 	 *		styles.has( 'margin-left' );    // returns true
 	 *
-	 *		styles.removeProperty( 'margin-top' );
+	 *		styles.remove( 'margin-top' );
 	 *
 	 *		styles.has( 'margin' );         // returns false
 	 *		styles.has( 'margin-top' );     // returns false
 	 *		styles.has( 'margin-left' );    // returns true
 	 *
-	 * @param {String} propertyName
+	 * @param {String} name
 	 * @returns {Boolean}
 	 */
-	has( propertyName ) {
-		const normalized = this._styleProcessor.getNormalized( propertyName, this._styles );
+	has( name ) {
+		const normalized = this._styleProcessor.getNormalized( name, this._styles );
 
 		if ( !normalized ) {
 			// Try return styles set directly - values that are not parsed.
-			return this._styles[ propertyName ] !== undefined;
+			return this._styles[ name ] !== undefined;
 		}
 
 		if ( isObject( normalized ) ) {
-			const styles = this._styleProcessor.getReducedForm( propertyName, normalized );
+			const styles = this._styleProcessor.getReducedForm( name, normalized );
 
-			const propertyDescriptor = styles.find( ( [ property ] ) => property === propertyName );
+			const propertyDescriptor = styles.find( ( [ property ] ) => property === name );
 
 			// Only return a value if it is set;
 			return Array.isArray( propertyDescriptor );
@@ -165,11 +165,29 @@ export default class StylesMap {
 	}
 
 	/**
-	 * Removes styles property.
+	 * Removes given style.
+	 *
+	 *		styles.setTo( 'background:#foo;margin-right:2px;' );
+	 *
+	 *		styles.remove( 'background' );
+	 *
+	 *		styles.toString();   // returns 'margin-right:2px;'
+	 *
+	 * *Note:* This method supports normalized styles if defined.
+	 *
+	 *		// Enable 'margin' shorthand processing:
+	 *		editor.editing.view.document.addStyleProcessorRules( addMarginStylesProcessor );
+	 *
+	 *		styles.setTo( 'margin:1px' );
+	 *
+	 *		styles.remove( 'margin-top' );
+	 *		styles.remove( 'margin-right' );
+	 *
+	 *		styles.toString();   // returns 'margin-bottom:1px;margin-left:1px;'
 	 *
 	 * @param name
 	 */
-	removeProperty( name ) {
+	remove( name ) {
 		unset( this._styles, toPath( name ) );
 		delete this._styles[ name ];
 	}

+ 1 - 1
packages/ckeditor5-engine/tests/view/styles/borderstyles.js

@@ -150,7 +150,7 @@ describe( 'Border styles normalization', () => {
 
 	it( 'should output', () => {
 		styles.setTo( 'border:1px solid blue;' );
-		styles.removeProperty( 'border-color' );
+		styles.remove( 'border-color' );
 
 		expect( styles.getInlineStyle() ).to.equal(
 			'border-bottom:1px solid;' +

+ 4 - 4
packages/ckeditor5-engine/tests/view/stylesmap.js

@@ -210,16 +210,16 @@ describe( 'StylesMap', () => {
 		} );
 	} );
 
-	describe( 'removeProperty()', () => {
+	describe( 'remove()', () => {
 		it( 'should do nothing if property is not set', () => {
-			stylesMap.removeProperty( 'color' );
+			stylesMap.remove( 'color' );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.be.undefined;
 		} );
 
 		it( 'should insert new property (other properties are set)', () => {
 			stylesMap.setTo( 'color:blue' );
-			stylesMap.removeProperty( 'color' );
+			stylesMap.remove( 'color' );
 
 			expect( stylesMap.getInlineProperty( 'color' ) ).to.be.undefined;
 		} );
@@ -227,7 +227,7 @@ describe( 'StylesMap', () => {
 		it( 'should remove normalized property', () => {
 			stylesMap.setTo( 'margin:1px' );
 
-			stylesMap.removeProperty( 'margin-top' );
+			stylesMap.remove( 'margin-top' );
 
 			expect( stylesMap.getInlineProperty( 'margin-top' ) ).to.be.undefined;
 		} );