Skip to content

Commit

Permalink
prep build 04/19
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Apr 19, 2024
2 parents d3f4ff5 + 8deb8f9 commit 8d6edd6
Show file tree
Hide file tree
Showing 65 changed files with 360 additions and 1,094 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This is done by setting the `target` on `<PluginSidebarMoreMenuItem>` to match t

```js
import { registerPlugin } from '@wordpress/plugins';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
import { image } from '@wordpress/icons';

const PluginSidebarMoreMenuItemTest = () => (
Expand Down
18 changes: 9 additions & 9 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function gutenberg_get_layout_definitions() {
),
'spacingStyles' => array(
array(
'selector' => ' > :first-child:first-child',
'selector' => ' > :first-child',
'rules' => array(
'margin-block-start' => '0',
),
),
array(
'selector' => ' > :last-child:last-child',
'selector' => ' > :last-child',
'rules' => array(
'margin-block-end' => '0',
),
Expand Down Expand Up @@ -112,13 +112,13 @@ function gutenberg_get_layout_definitions() {
),
'spacingStyles' => array(
array(
'selector' => ' > :first-child:first-child',
'selector' => ' > :first-child',
'rules' => array(
'margin-block-start' => '0',
),
),
array(
'selector' => ' > :last-child:last-child',
'selector' => ' > :last-child',
'rules' => array(
'margin-block-end' => '0',
),
Expand Down Expand Up @@ -146,7 +146,7 @@ function gutenberg_get_layout_definitions() {
),
),
array(
'selector' => ' > *',
'selector' => ' > :is(*, div)', // :is(*, div) instead of just * increases the specificity by 001.
'rules' => array(
'margin' => '0',
),
Expand All @@ -168,7 +168,7 @@ function gutenberg_get_layout_definitions() {
'displayMode' => 'grid',
'baseStyles' => array(
array(
'selector' => ' > *',
'selector' => ' > :is(*, div)', // :is(*, div) instead of just * increases the specificity by 001.
'rules' => array(
'margin' => '0',
),
Expand Down Expand Up @@ -248,7 +248,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
),
),
array(
'selector' => "$selector$selector > * + *",
'selector' => "$selector > * + *",
'declarations' => array(
'margin-block-start' => $gap_value,
'margin-block-end' => '0',
Expand Down Expand Up @@ -357,7 +357,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
),
),
array(
'selector' => "$selector$selector > * + *",
'selector' => "$selector > * + *",
'declarations' => array(
'margin-block-start' => $gap_value,
'margin-block-end' => '0',
Expand Down Expand Up @@ -799,7 +799,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$has_block_gap_support = isset( $block_gap );

$style = gutenberg_get_layout_style(
".$container_class.$container_class",
".$container_class",
$used_layout,
$has_block_gap_support,
$gap_value,
Expand Down
20 changes: 12 additions & 8 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets'
);

foreach ( $base_styles_nodes as $base_style_node ) {
$stylesheet .= $this->get_layout_styles( $base_style_node );
$stylesheet .= $this->get_layout_styles( $base_style_node, $types );
}
}

Expand Down Expand Up @@ -1465,7 +1465,7 @@ protected function get_block_classes( $style_nodes ) {
* @param array $block_metadata Metadata about the block to get styles for.
* @return string Layout styles for the block.
*/
protected function get_layout_styles( $block_metadata ) {
protected function get_layout_styles( $block_metadata, $types = array() ) {
$block_rules = '';
$block_type = null;

Expand All @@ -1486,7 +1486,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 = gutenberg_get_layout_definitions();
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class 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.
Expand Down Expand Up @@ -1557,7 +1557,7 @@ protected function get_layout_styles( $block_metadata ) {
$spacing_rule['selector']
);
} else {
$format = static::ROOT_BLOCK_SELECTOR === $selector ? ':where(%s .%s) %s' : '%s-%s%s';
$format = static::ROOT_BLOCK_SELECTOR === $selector ? ':where(.%2$s) %3$s' : ':where(%1$s-%2$s) %3$s';
$layout_selector = sprintf(
$format,
$selector,
Expand Down Expand Up @@ -1611,6 +1611,11 @@ protected function get_layout_styles( $block_metadata ) {
foreach ( $base_style_rules as $base_style_rule ) {
$declarations = array();

// Skip outputting base styles for flow and constrained layout types if theme doesn't support theme.json. The 'base-layout-styles' type flags this.
if ( in_array( 'base-layout-styles', $types, true ) && ( 'default' === $layout_definition['name'] || 'constrained' === $layout_definition['name'] ) ) {
continue;
}

if (
isset( $base_style_rule['selector'] ) &&
preg_match( $layout_selector_pattern, $base_style_rule['selector'] ) &&
Expand All @@ -1636,8 +1641,7 @@ protected function get_layout_styles( $block_metadata ) {
}

$layout_selector = sprintf(
'%s .%s%s',
$selector,
'.%s%s',
$class_name,
$base_style_rule['selector']
);
Expand Down Expand Up @@ -2787,8 +2791,8 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
$css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";
$css .= ':where(.wp-site-blocks) > :first-child:first-child { margin-block-start: 0; }';
$css .= ':where(.wp-site-blocks) > :last-child:last-child { margin-block-end: 0; }';
$css .= ':where(.wp-site-blocks) > :first-child { margin-block-start: 0; }';
$css .= ':where(.wp-site-blocks) > :last-child { margin-block-end: 0; }';

// For backwards compatibility, ensure the legacy block gap CSS variable is still available.
$css .= static::ROOT_CSS_PROPERTIES_SELECTOR . " { --wp--style--block-gap: $block_gap_value; }";
Expand Down
39 changes: 39 additions & 0 deletions lib/compat/wordpress-6.5/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,42 @@ function gutenberg_add_use_customizer_site_logo_url_flag() {
}

add_action( 'admin_init', 'gutenberg_add_use_customizer_site_logo_url_flag' );

/**
* Add a Patterns submenu (wp-admin/edit.php?post_type=wp_block) under the Appearance menu
* for the Classic theme. This function should not be backported to core, and should be
* removed when the required WP core version for Gutenberg is >= 6.5.0.
*
* @global array $submenu
*/
function gutenberg_add_patterns_page_submenu_item() {
if ( ! is_wp_version_compatible( '6.5' ) && ! wp_is_block_theme() ) {
// Move the Themes submenu forward and inject a Patterns submenu.
global $submenu;
$submenu['themes.php'][4] = $submenu['themes.php'][5];
$submenu['themes.php'][5] = array( __( 'Patterns', 'gutenberg' ), 'edit_theme_options', 'edit.php?post_type=wp_block' );
ksort( $submenu['themes.php'], SORT_NUMERIC );
}
}
add_action( 'admin_init', 'gutenberg_add_patterns_page_submenu_item' );

/**
* Filter the `wp_die_handler` to allow access to the Site Editor's Patterns page
* (wp-admin/site-editor.php?path=%2Fpatterns) internally for the Classic theme. This
* function should not be backported to core, and should be removed when the required
* WP core version for Gutenberg is >= 6.5.0.
*
* @param callable $default_handler The default handler.
* @return callable The default handler or a custom handler.
*/
function gutenberg_patterns_page_wp_die_handler( $default_handler ) {
if ( ! is_wp_version_compatible( '6.5' ) && ! wp_is_block_theme() && str_contains( $_SERVER['REQUEST_URI'], 'site-editor.php' ) ) {
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] );
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] );
if ( $is_patterns || $is_patterns_path ) {
return '__return_false';
}
}
return $default_handler;
}
add_filter( 'wp_die_handler', 'gutenberg_patterns_page_wp_die_handler' );
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// Such shifts happen when the bottom margin of the Title block has been set to less than the default 1em margin of paragraphs.
:where(body .is-layout-constrained) &,
:where(.wp-site-blocks) & {
> :first-child:first-child {
> :first-child {
margin-block-start: 0;
margin-block-end: 0;
}
Expand Down
Loading

0 comments on commit 8d6edd6

Please sign in to comment.