Skip to content

Commit

Permalink
Skip enforcing inline color styles and fix gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jan 24, 2022
1 parent e445a23 commit 9865b77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,19 @@ export const withColorPaletteStyles = createHigherOrderComponent(
}
const extraStyles = {};

if ( textColor ) {
if (
textColor &&
! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'text' )
) {
extraStyles.color = getColorObjectByAttributeValues(
colors,
textColor
)?.color;
}
if ( backgroundColor ) {
if (
backgroundColor &&
! shouldSkipSerialization( name, COLOR_SUPPORT_KEY, 'background' )
) {
extraStyles.backgroundColor = getColorObjectByAttributeValues(
colors,
backgroundColor
Expand Down
16 changes: 15 additions & 1 deletion packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ const skipSerializationPathsSave = {
[ `${ SPACING_SUPPORT_KEY }` ]: [ 'spacing.blockGap' ],
};

/**
* A dictionary used to normalize feature names between support flags, style
* object properties and __experimentSkipSerialization configuration arrays.
*
* This allows not having to provide a migration for a support flag and possible
* backwards compatibility bridges, while still achieving consistency between
* the support flag and the skip serialization array.
*
* @constant
* @type {Record<string, string>}
*/
const renamedFeatures = { gradients: 'gradient' };

/**
* Override props assigned to save component to inject the CSS variables definition.
*
Expand Down Expand Up @@ -233,7 +246,8 @@ export function addSaveProps(
}

if ( Array.isArray( skipSerialization ) ) {
skipSerialization.forEach( ( feature ) => {
skipSerialization.forEach( ( featureName ) => {
const feature = renamedFeatures[ featureName ] || featureName;
style = omit( style, [ [ ...path, feature ] ] );
} );
}
Expand Down

0 comments on commit 9865b77

Please sign in to comment.