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

Commit

Permalink
Merge branch 'master' into i/353
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jan 21, 2020
2 parents 5f02b4d + e8ac10e commit f4ccf7a
Showing 1 changed file with 2 additions and 53 deletions.
55 changes: 2 additions & 53 deletions src/indentblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import IndentBlockCommand from './indentblockcommand';
import IndentUsingOffset from './indentcommandbehavior/indentusingoffset';
import IndentUsingClasses from './indentcommandbehavior/indentusingclasses';
import { addMarginRules } from '@ckeditor/ckeditor5-engine/src/view/styles/margin';

/**
* The block indentation feature.
Expand Down Expand Up @@ -56,6 +57,7 @@ export default class IndentBlock extends Plugin {
const outdentConfig = Object.assign( { direction: 'backward' }, configuration );

if ( useOffsetConfig ) {
editor.editing.view.document.addStyleProcessorRules( addMarginRules );
this._setupConversionUsingOffset( editor.conversion );

editor.commands.add( 'indentBlock', new IndentBlockCommand( editor, new IndentUsingOffset( indentConfig ) ) );
Expand Down Expand Up @@ -112,19 +114,6 @@ export default class IndentBlock extends Plugin {
}
} );

// The margin shorthand should also work.
conversion.for( 'upcast' ).attributeToAttribute( {
view: {
styles: {
'margin': /[\s\S]+/
}
},
model: {
key: 'blockIndent',
value: viewElement => normalizeToMarginSideStyle( viewElement.getStyle( 'margin' ), marginProperty )
}
} );

conversion.for( 'downcast' ).attributeToAttribute( {
model: 'blockIndent',
view: modelAttributeValue => {
Expand Down Expand Up @@ -165,46 +154,6 @@ export default class IndentBlock extends Plugin {
}
}

// Normalizes the margin shorthand value to the value of margin-left or margin-right CSS property.
//
// As such it will return:
//
// - '1em' -> '1em'
// - '2px 1em' -> '1em'
// - '2px 1em 3px' -> '1em'
// - '2px 10px 3px 1em'
// -> '1em' (side "margin-left")
// -> '10px' (side "margin-right")
//
// @param {String} marginStyleValue Margin style value.
// @param {String} side "margin-left" or "margin-right" depending on which margin should be returned.
// @returns {String} Extracted value of margin-left or margin-right.
function normalizeToMarginSideStyle( marginStyleValue, side ) {
// Splits the margin shorthand, ie margin: 2em 4em.
const marginEntries = marginStyleValue.split( ' ' );

let marginValue;

// If only one value defined, ie: `margin: 1px`.
marginValue = marginEntries[ 0 ];

// If only two values defined, ie: `margin: 1px 2px`.
if ( marginEntries[ 1 ] ) {
marginValue = marginEntries[ 1 ];
}

// If four values defined, ie: `margin: 1px 2px 3px 4px`.
if ( marginEntries[ 3 ] ) {
if ( side === 'margin-left' ) {
marginValue = marginEntries[ 3 ];
} else {
marginValue = marginEntries[ 1 ];
}
}

return marginValue;
}

/**
* The configuration of the {@link module:indent/indentblock~IndentBlock block indentation feature}.
*
Expand Down

0 comments on commit f4ccf7a

Please sign in to comment.