From a902662991e19ddb4cfe52204557ea6a329dde80 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:50:41 +0700 Subject: [PATCH] Global Styles: Allow referenced zero value and simplify getValueFromObjectPath calls (#64836) Co-authored-by: aaronrobertshaw Co-authored-by: ramonjd --- .../src/components/global-styles/test/utils.js | 10 ++++++++++ .../block-editor/src/components/global-styles/utils.js | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/test/utils.js b/packages/block-editor/src/components/global-styles/test/utils.js index 08ed1f18e80402..57a157662969e1 100644 --- a/packages/block-editor/src/components/global-styles/test/utils.js +++ b/packages/block-editor/src/components/global-styles/test/utils.js @@ -73,6 +73,11 @@ describe( 'editor utils', () => { dimensions: { minHeight: '100px', }, + spacing: { + padding: { + top: 0, + }, + }, }, }, }, @@ -444,6 +449,11 @@ describe( 'editor utils', () => { { url: 'file:./assets/image.jpg' }, themeJson, ], + [ + { ref: 'styles.blocks.core/group.spacing.padding.top' }, + 0, + themeJson, + ], [ { ref: 'styles.blocks.core/group.background.backgroundImage', diff --git a/packages/block-editor/src/components/global-styles/utils.js b/packages/block-editor/src/components/global-styles/utils.js index 59799c9032c67f..f5dc157d1df8eb 100644 --- a/packages/block-editor/src/components/global-styles/utils.js +++ b/packages/block-editor/src/components/global-styles/utils.js @@ -306,9 +306,8 @@ function getValueFromCustomVariable( features, blockName, variable, path ) { */ export function getValueFromVariable( features, blockName, variable ) { if ( ! variable || typeof variable !== 'string' ) { - if ( variable?.ref && typeof variable?.ref === 'string' ) { - const refPath = variable.ref.split( '.' ); - variable = getValueFromObjectPath( features, refPath ); + if ( typeof variable?.ref === 'string' ) { + variable = getValueFromObjectPath( features, variable.ref ); // Presence of another ref indicates a reference to another dynamic value. // Pointing to another dynamic value is not supported. if ( ! variable || !! variable?.ref ) { @@ -568,9 +567,8 @@ export function getResolvedRefValue( ruleValue, tree ) { * For example: { "ref": "style.color.background" } => "#fff". */ if ( typeof ruleValue !== 'string' && ruleValue?.ref ) { - const refPath = ruleValue.ref.split( '.' ); const resolvedRuleValue = getCSSValueFromRawStyle( - getValueFromObjectPath( tree, refPath ) + getValueFromObjectPath( tree, ruleValue.ref ) ); /* @@ -581,7 +579,7 @@ export function getResolvedRefValue( ruleValue, tree ) { return undefined; } - if ( ! resolvedRuleValue ) { + if ( resolvedRuleValue === undefined ) { return ruleValue; }