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 Feb 17, 2022
1 parent 4c3e282 commit f192859
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 @@ -611,13 +611,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 @@ -218,6 +218,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 @@ -248,7 +261,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 f192859

Please sign in to comment.