Skip to content

Commit

Permalink
Block Supports: Allow skipping serialization of typography attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Apr 28, 2021
1 parent a4003a0 commit 0ce473d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
return array();
}

$skip_typography_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipTypographySerialization' ), false );
if ( $skip_typography_serialization ) {
return array();
}

$classes = array();
$styles = array();

Expand Down
37 changes: 33 additions & 4 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/**
* External dependencies
*/
import { capitalize, get, has, omit, omitBy, startsWith } from 'lodash';
import {
capitalize,
get,
has,
omit,
omitBy,
startsWith,
without,
} from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -133,14 +141,35 @@ export function addSaveProps( props, blockType, attributes ) {
[ COLOR_SUPPORT_KEY ]: getBlockSupport( blockType, COLOR_SUPPORT_KEY ),
} );

let typographyFeaturesToRemove = [];
if (
getBlockSupport(
blockType,
'__experimentalSkipTypographySerialization'
)
) {
// Font size is handled separately.
typographyFeaturesToRemove = without(
TYPOGRAPHY_SUPPORT_KEYS,
FONT_SIZE_SUPPORT_KEY
);
}

if (
getBlockSupport( blockType, '__experimentalSkipFontSizeSerialization' )
) {
filteredStyle = omit( filteredStyle, [
[ 'typography', FONT_SIZE_SUPPORT_KEY ],
] );
typographyFeaturesToRemove = [
...typographyFeaturesToRemove,
FONT_SIZE_SUPPORT_KEY,
];
}

const { typography, ...otherStyle } = filteredStyle;
filteredStyle = {
typography: omit( typography, typographyFeaturesToRemove ),
...otherStyle,
};

props.style = {
...getInlineStyles( filteredStyle ),
...props.style,
Expand Down

0 comments on commit 0ce473d

Please sign in to comment.