Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,32 @@ export default {
style,
blockName,
hasBlockGapSupport,
globalBlockGapValue,
layoutDefinitions = LAYOUT_DEFINITIONS,
} ) {
const { orientation = 'horizontal' } = layout;

// Determine the fallback gap value using global styles (theme.json),
// falling back to '0.5em' for backwards compatibility.
let fallbackGapValue = '0.5em';
if ( globalBlockGapValue ) {
// Process the global gap value to handle preset values
const processedGlobalGap = getGapCSSValue(
globalBlockGapValue,
'0.5em'
);
// Use the column gap value (second value if two values exist)
const gapParts = processedGlobalGap.split( ' ' );
fallbackGapValue =
gapParts.length > 1 ? gapParts[ 1 ] : gapParts[ 0 ];
}

// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
const blockGapValue =
style?.spacing?.blockGap &&
! shouldSkipSerialization( blockName, 'spacing', 'blockGap' )
? getGapCSSValue( style?.spacing?.blockGap, '0.5em' )
? getGapCSSValue( style?.spacing?.blockGap, fallbackGapValue )
: undefined;
const justifyContent = justifyContentMap[ layout.justifyContent ];
const flexWrap = flexWrapOptions.includes( layout.flexWrap )
Expand Down
20 changes: 10 additions & 10 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,8 @@ export default {
}
}

// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
const blockGapValue =
style?.spacing?.blockGap &&
! shouldSkipSerialization( blockName, 'spacing', 'blockGap' )
? getGapCSSValue( style?.spacing?.blockGap, '0.5em' )
: undefined;

// Use the global blockGap value for grid column calculations when available
// If the gap value has both top and left (separated by space), use the left value for horizontal calculations
// Use the global blockGap value as fallback when available.
// If the gap value has both top and left (separated by space), use the left value for horizontal calculations.
let fallbackGapValue = '1.2rem';
if ( globalBlockGapValue ) {
const processedGap = getGapCSSValue( globalBlockGapValue, '0.5em' );
Expand All @@ -157,6 +149,14 @@ export default {
gapParts.length > 1 ? gapParts[ 1 ] : gapParts[ 0 ];
}

// If a block's block.json skips serialization for spacing or spacing.blockGap,
// don't apply the user-defined value to the styles.
const blockGapValue =
style?.spacing?.blockGap &&
! shouldSkipSerialization( blockName, 'spacing', 'blockGap' )
? getGapCSSValue( style?.spacing?.blockGap, fallbackGapValue )
: undefined;

let output = '';
const rules = [];

Expand Down
Loading