Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1807 from ckeditor/i/3287
Browse files Browse the repository at this point in the history
Feature: Introduced CSS style normalization for conversion. Closes ckeditor/ckeditor5#6047.
  • Loading branch information
Reinmar committed Jan 21, 2020
2 parents fe24bf4 + 13e5f7f commit b2a8189
Show file tree
Hide file tree
Showing 24 changed files with 3,274 additions and 209 deletions.
2 changes: 1 addition & 1 deletion src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default class DowncastHelpers extends ConversionHelpers {
* view: modelAttributeValue => ( { key: 'class', value: 'styled-' + modelAttributeValue } )
* } );
*
* *Note:* Downcasting to a style property requires providing `value` as an object:
* **Note**: Downcasting to a style property requires providing `value` as an object:
*
* editor.conversion.for( 'downcast' ).attributeToAttribute( {
* model: 'lineHeight',
Expand Down
13 changes: 13 additions & 0 deletions src/conversion/viewconsumable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { isArray } from 'lodash-es';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import StylesMap from '../view/stylesmap';

/**
* Class used for handling consumption of view {@link module:engine/view/element~Element elements},
Expand Down Expand Up @@ -507,6 +508,12 @@ class ViewElementConsumables {
}

consumables.set( name, true );

if ( type === 'styles' ) {
for ( const alsoName of StylesMap.getRelatedStyles( name ) ) {
consumables.set( alsoName, true );
}
}
}
}

Expand Down Expand Up @@ -568,6 +575,12 @@ class ViewElementConsumables {
this._consume( consumableName, [ ...this._consumables[ consumableName ].keys() ] );
} else {
consumables.set( name, false );

if ( type == 'styles' ) {
for ( const toConsume of StylesMap.getRelatedStyles( name ) ) {
consumables.set( toConsume, false );
}
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/view/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DocumentSelection from './documentselection';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
import StylesMap from './stylesmap';

// @if CK_DEBUG_ENGINE // const { logDocument } = require( '../dev-utils/utils' );

Expand Down Expand Up @@ -160,6 +161,22 @@ export default class Document {
this.stopListening();
}

/**
* Adds a style processor normalization rules.
*
* The available style processors:
*
* * background: {@link module:engine/view/styles/background~addBackgroundRules}
* * border: {@link module:engine/view/styles/border~addBorderRules}
* * margin: {@link module:engine/view/styles/margin~addMarginRules}
* * padding: {@link module:engine/view/styles/padding~addPaddingRules}
*
* @param {Function} callback
*/
addStyleProcessorRules( callback ) {
callback( StylesMap._styleProcessor );
}

/**
* Performs post-fixer loops. Executes post-fixer callbacks as long as none of them has done any changes to the model.
*
Expand Down
10 changes: 9 additions & 1 deletion src/view/downcastwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ export default class DowncastWriter {
* position: 'fixed'
* }, element );
*
* **Note**: The passed style can be normalized if
* {@link module:engine/view/document~Document#addStyleProcessorRules a particular style processor rule is enabled}.
* See {@link module:engine/view/stylesmap~StylesMap#set `StylesMap#set()`} for details.
*
* @param {String|Object} property Property name or object with key - value pairs.
* @param {String} [value] Value to set. This parameter is ignored if object is provided as the first parameter.
* @param {module:engine/view/element~Element} element Element to set styles on.
Expand All @@ -339,9 +343,13 @@ export default class DowncastWriter {
/**
* Removes specified style from the element.
*
* writer.removeStyle( 'color', element ); // Removes 'color' style.
* writer.removeStyle( 'color', element ); // Removes 'color' style.
* writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
*
* **Note**: This method can work with normalized style names if
* {@link module:engine/view/document~Document#addStyleProcessorRules a particular style processor rule is enabled}.
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
*
* @param {Array.<String>|String} property
* @param {module:engine/view/element~Element} element
*/
Expand Down
Loading

0 comments on commit b2a8189

Please sign in to comment.