From 911d8cf7f0cef94454eefaff2a1e5d92afcf5faa Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 18 May 2021 12:45:06 +0200 Subject: [PATCH] Simplify further --- packages/block-editor/src/hooks/style.js | 42 ++++++++++-------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/packages/block-editor/src/hooks/style.js b/packages/block-editor/src/hooks/style.js index e7b323e5805d6..de7ac89d601cc 100644 --- a/packages/block-editor/src/hooks/style.js +++ b/packages/block-editor/src/hooks/style.js @@ -4,6 +4,7 @@ import { capitalize, find, + forEach, get, has, isEqual, @@ -107,29 +108,22 @@ function addAttribute( settings ) { return settings; } -const skipSerializationPaths = [ - { - indicator: `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization`, - path: [ 'border' ], - }, - { - indicator: `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization`, - path: [ COLOR_SUPPORT_KEY ], - }, - { - indicator: `__experimentalSkipFontSizeSerialization`, - path: [ 'typography', 'fontSize' ], - }, - { - indicator: `__experimentalSkipTypographySerialization`, - path: without( TYPOGRAPHY_SUPPORT_KEYS, FONT_SIZE_SUPPORT_KEY ).map( - ( feature ) => - find( STYLE_PROPERTY, ( property ) => - isEqual( property.support, [ feature ] ) - )?.value - ), - }, -]; +const skipSerializationPaths = { + [ `${ BORDER_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ 'border' ], + [ `${ COLOR_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [ + COLOR_SUPPORT_KEY, + ], + [ `__experimentalSkipFontSizeSerialization` ]: [ 'typography', 'fontSize' ], + [ `__experimentalSkipTypographySerialization` ]: without( + TYPOGRAPHY_SUPPORT_KEYS, + FONT_SIZE_SUPPORT_KEY + ).map( + ( feature ) => + find( STYLE_PROPERTY, ( property ) => + isEqual( property.support, [ feature ] ) + )?.value + ), +}; /** * Override props assigned to save component to inject the CSS variables definition. @@ -146,7 +140,7 @@ export function addSaveProps( props, blockType, attributes ) { let { style } = attributes; - skipSerializationPaths.forEach( ( { indicator, path } ) => { + forEach( skipSerializationPaths, ( path, indicator ) => { if ( getBlockSupport( blockType, indicator ) ) { style = omit( style, path ); }