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 15, 2021
1 parent 6ff5d53 commit 481fd01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 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_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipTypographySerialization' ), false );
if ( $skip_serialization ) {
return array();
}

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

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

/**
* WordPress dependencies
Expand Down Expand Up @@ -127,10 +127,20 @@ export function addSaveProps( props, blockType, attributes ) {
}

const { style } = attributes;
const filteredStyle = omitKeysNotToSerialize( style, {
let filteredStyle = omitKeysNotToSerialize( style, {
border: getBlockSupport( blockType, BORDER_SUPPORT_KEY ),
[ COLOR_SUPPORT_KEY ]: getBlockSupport( blockType, COLOR_SUPPORT_KEY ),
} );

if (
getBlockSupport(
blockType,
'__experimentalSkipTypographySerialization'
)
) {
filteredStyle = omit( filteredStyle, TYPOGRAPHY_SUPPORT_KEYS );
}

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

0 comments on commit 481fd01

Please sign in to comment.