-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try "constrained" content width as new layout type #42763
Changes from all commits
6fbc632
81768a3
464139b
5e8010d
20499c0
93a985a
f2fc2bb
f748fee
f4e7d10
f54f812
6af5ecd
f52ba94
86f5ed9
b6b2483
454195f
47464ac
7f5874b
155885e
5d3573f
6096d7d
de61635
09756f3
772906a
1f516f1
17124fb
f22bee0
abd1baf
78a3ed5
49b12fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,31 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support | |
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default'; | ||
$layout_styles = array(); | ||
if ( 'default' === $layout_type ) { | ||
if ( $has_block_gap_support ) { | ||
if ( is_array( $gap_value ) ) { | ||
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null; | ||
} | ||
if ( $gap_value && ! $should_skip_gap_serialization ) { | ||
array_push( | ||
$layout_styles, | ||
array( | ||
'selector' => "$selector > *", | ||
'declarations' => array( | ||
'margin-block-start' => '0', | ||
'margin-block-end' => '0', | ||
), | ||
), | ||
array( | ||
'selector' => "$selector$selector > * + *", | ||
'declarations' => array( | ||
'margin-block-start' => $gap_value, | ||
'margin-block-end' => '0', | ||
), | ||
) | ||
); | ||
} | ||
} | ||
} elseif ( 'constrained' === $layout_type ) { | ||
$content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : ''; | ||
$wide_size = isset( $layout['wideSize'] ) ? $layout['wideSize'] : ''; | ||
|
||
|
@@ -254,11 +279,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { | |
$has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false; | ||
$default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); | ||
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; | ||
|
||
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a nit, could this be moved up to just after the $used_layout declaration as it seems like the other declarations are not needed if this returns early?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that makes sense! |
||
if ( ! $global_layout_settings ) { | ||
return $block_content; | ||
} | ||
$used_layout = $global_layout_settings; | ||
} | ||
|
||
$class_names = array(); | ||
|
@@ -268,6 +293,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { | |
$layout_classname = ''; | ||
$use_global_padding = gutenberg_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) && ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ); | ||
|
||
// Set the correct layout type for blocks using legacy content width. | ||
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) { | ||
$used_layout['type'] = 'constrained'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocks with |
||
|
||
if ( $use_global_padding ) { | ||
$class_names[] = 'has-global-padding'; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,18 +758,6 @@ function( $pseudo_selector ) use ( $selector ) { | |
} | ||
} | ||
|
||
/* | ||
* Reset default browser margin on the root body element. | ||
* This is set on the root selector **before** generating the ruleset | ||
* from the `theme.json`. This is to ensure that if the `theme.json` declares | ||
* `margin` in its `spacing` declaration for the `body` element then these | ||
* user-generated values take precedence in the CSS cascade. | ||
* @link https://github.com/WordPress/gutenberg/issues/36147. | ||
*/ | ||
if ( static::ROOT_BLOCK_SELECTOR === $selector ) { | ||
$block_rules .= 'body { margin: 0; }'; | ||
} | ||
|
||
// 2. Generate and append the rules that use the general selector. | ||
$block_rules .= static::to_ruleset( $selector, $declarations ); | ||
|
||
|
@@ -793,6 +781,34 @@ function( $pseudo_selector ) use ( $selector ) { | |
} | ||
|
||
if ( static::ROOT_BLOCK_SELECTOR === $selector ) { | ||
/* | ||
* Reset default browser margin on the root body element. | ||
* This is set on the root selector **before** generating the ruleset | ||
* from the `theme.json`. This is to ensure that if the `theme.json` declares | ||
* `margin` in its `spacing` declaration for the `body` element then these | ||
* user-generated values take precedence in the CSS cascade. | ||
* @link https://github.com/WordPress/gutenberg/issues/36147. | ||
*/ | ||
$block_rules .= 'body { margin: 0;'; | ||
|
||
/* | ||
* If there are content and wide widths in theme.json, output them | ||
* as custom properties on the body element so all blocks can use them. | ||
*/ | ||
if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) { | ||
$content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize']; | ||
$content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial'; | ||
$wide_size = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize']; | ||
$wide_size = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial'; | ||
$block_rules .= '--wp--style--global--content-size: ' . $content_size . ';'; | ||
$block_rules .= '--wp--style--global--wide-size: ' . $wide_size . ';'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
$block_rules .= '}'; | ||
} | ||
|
||
if ( static::ROOT_BLOCK_SELECTOR === $selector ) { | ||
|
||
if ( $use_root_padding ) { | ||
$block_rules .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }'; | ||
$block_rules .= '.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; | ||
|
@@ -804,6 +820,7 @@ function( $pseudo_selector ) use ( $selector ) { | |
$block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; | ||
$block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'; | ||
|
||
$block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' ); | ||
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; | ||
if ( $has_block_gap_support ) { | ||
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) ); | ||
|
@@ -1295,7 +1312,7 @@ protected function get_layout_styles( $block_metadata ) { | |
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support. | ||
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); | ||
$layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() ); | ||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, and child combinator selectors. | ||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors. | ||
|
||
// Gap styles will only be output if the theme has block gap support, or supports a fallback gap. | ||
// Default layout gap styles will be skipped for themes that do not explicitly opt-in to blockGap with a `true` or `false` value. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to existing Group blocks with the default layout type, that set
contentSize
orwideSize
?