Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/67107-color-clear-button
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfra authored Nov 20, 2024
2 parents 50d781e + 41f5eb2 commit bdb36e2
Show file tree
Hide file tree
Showing 63 changed files with 1,323 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rnmobile-android-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: npm run native test:e2e:setup

- name: Gradle cache
uses: gradle/actions/setup-gradle@473878a77f1b98e2b5ac4af93489d1656a80a5ed # v4.2.0
uses: gradle/actions/setup-gradle@cc4fc85e6b35bafd578d5ffbc76a5518407e1af0 # v4.2.1

# AVD cache disabled as it caused emulator termination to hang indefinitely.
# https://github.com/ReactiveCircus/android-emulator-runner/issues/385
Expand Down
1 change: 1 addition & 0 deletions backport-changelog/6.8/7069.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/7069

* https://github.com/WordPress/gutenberg/pull/63401
* https://github.com/WordPress/gutenberg/pull/66918
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7129.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7129

* https://github.com/WordPress/gutenberg/pull/62304
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7825.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7825

* https://github.com/WordPress/gutenberg/pull/67061
28 changes: 14 additions & 14 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function gutenberg_register_border_support( $block_type ) {
$block_type->attributes = array();
}

if ( block_has_support( $block_type, array( '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
if ( block_has_support( $block_type, array( 'border' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
$block_type->attributes['style'] = array(
'type' => 'object',
);
Expand Down Expand Up @@ -52,7 +52,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
if (
gutenberg_has_border_feature_support( $block_type, 'radius' ) &&
isset( $block_attributes['style']['border']['radius'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' )
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'radius' )
) {
$border_radius = $block_attributes['style']['border']['radius'];

Expand All @@ -67,7 +67,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
if (
gutenberg_has_border_feature_support( $block_type, 'style' ) &&
isset( $block_attributes['style']['border']['style'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' )
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' )
) {
$border_block_styles['style'] = $block_attributes['style']['border']['style'];
}
Expand All @@ -76,7 +76,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
if (
$has_border_width_support &&
isset( $block_attributes['style']['border']['width'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' )
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' )
) {
$border_width = $block_attributes['style']['border']['width'];

Expand All @@ -91,7 +91,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
// Border color.
if (
$has_border_color_support &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'color' )
) {
$preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
$custom_border_color = $block_attributes['style']['border']['color'] ?? null;
Expand All @@ -103,9 +103,9 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
$border = $block_attributes['style']['border'][ $side ] ?? null;
$border_side_values = array(
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null,
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' ) ? $border['width'] : null,
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'color' ) ? $border['color'] : null,
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' ) ? $border['style'] : null,
);
$border_block_styles[ $side ] = $border_side_values;
}
Expand All @@ -129,9 +129,9 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
/**
* Checks whether the current block type supports the border feature requested.
*
* If the `__experimentalBorder` support flag is a boolean `true` all border
* If the `border` support flag is a boolean `true` all border
* support features are available. Otherwise, the specific feature's support
* flag nested under `experimentalBorder` must be enabled for the feature
* flag nested under `border` must be enabled for the feature
* to be opted into.
*
* @param WP_Block_Type $block_type Block type to check for support.
Expand All @@ -141,17 +141,17 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
* @return boolean Whether or not the feature is supported.
*/
function gutenberg_has_border_feature_support( $block_type, $feature, $default_value = false ) {
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
// Check if all border support features have been opted into via `"border": true`.
if ( $block_type instanceof WP_Block_Type ) {
$block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value;
$block_type_supports_border = $block_type->supports['border'] ?? $default_value;
if ( true === $block_type_supports_border ) {
return true;
}
}

// Check if the specific feature has been opted into individually
// via nested flag under `__experimentalBorder`.
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value );
// via nested flag under `border`.
return block_has_support( $block_type, array( 'border', $feature ), $default_value );
}

// Register the block support.
Expand Down
18 changes: 12 additions & 6 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,10 @@ class WP_Theme_JSON_Gutenberg {
* @var string[]
*/
const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = array(
'__experimentalBorder' => 'border',
'color' => 'color',
'spacing' => 'spacing',
'typography' => 'typography',
'border' => 'border',
'color' => 'color',
'spacing' => 'spacing',
'typography' => 'typography',
);

/**
Expand Down Expand Up @@ -2874,8 +2874,14 @@ public function get_styles_for_block( $block_metadata ) {

// Combine selectors with style variation's selector and add to overall style variation declarations.
foreach ( $variation_declarations as $current_selector => $new_declarations ) {
// If current selector includes block classname, remove it but leave the whitespace in.
$shortened_selector = str_replace( $block_metadata['selector'] . ' ', ' ', $current_selector );
/*
* Clean up any whitespace between comma separated selectors.
* This prevents these spaces breaking compound selectors such as:
* - `.wp-block-list:not(.wp-block-list .wp-block-list)`
* - `.wp-block-image img, .wp-block-image.my-class img`
*/
$clean_current_selector = preg_replace( '/,\s+/', ',', $current_selector );
$shortened_selector = str_replace( $block_metadata['selector'], '', $clean_current_selector );

// Prepend the variation selector to the current selector.
$split_selectors = explode( ',', $shortened_selector );
Expand Down
92 changes: 73 additions & 19 deletions lib/compat/wordpress-6.8/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,94 @@
*/

/**
* Filters the block type arguments during registration to stabilize experimental block supports.
* Filters the block type arguments during registration to stabilize
* experimental block supports.
*
* This is a temporary compatibility shim as the approach in core is for this to be handled
* within the WP_Block_Type class rather than requiring a filter.
* This is a temporary compatibility shim as the approach in core is for this
* to be handled within the WP_Block_Type class rather than requiring a filter.
*
* @param array $args Array of arguments for registering a block type.
* @return array Array of arguments for registering a block type.
*/
function gutenberg_stabilize_experimental_block_supports( $args ) {
if ( empty( $args['supports']['typography'] ) ) {
if ( empty( $args['supports'] ) ) {
return $args;
}

$experimental_typography_supports_to_stable = array(
'__experimentalFontFamily' => 'fontFamily',
'__experimentalFontStyle' => 'fontStyle',
'__experimentalFontWeight' => 'fontWeight',
'__experimentalLetterSpacing' => 'letterSpacing',
'__experimentalTextDecoration' => 'textDecoration',
'__experimentalTextTransform' => 'textTransform',
$experimental_to_stable_keys = array(
'typography' => array(
'__experimentalFontFamily' => 'fontFamily',
'__experimentalFontStyle' => 'fontStyle',
'__experimentalFontWeight' => 'fontWeight',
'__experimentalLetterSpacing' => 'letterSpacing',
'__experimentalTextDecoration' => 'textDecoration',
'__experimentalTextTransform' => 'textTransform',
),
'__experimentalBorder' => 'border',
);

$current_typography_supports = $args['supports']['typography'];
$stable_typography_supports = array();
$updated_supports = array();
foreach ( $args['supports'] as $support => $config ) {
// Add the support's config as is when it's not in need of stabilization.
if ( empty( $experimental_to_stable_keys[ $support ] ) ) {
$updated_supports[ $support ] = $config;
continue;
}

// Stabilize the support's key if needed e.g. __experimentalBorder => border.
if ( is_string( $experimental_to_stable_keys[ $support ] ) ) {
$stabilized_key = $experimental_to_stable_keys[ $support ];

// If there is no stabilized key present, use the experimental config as is.
if ( ! array_key_exists( $stabilized_key, $args['supports'] ) ) {
$updated_supports[ $stabilized_key ] = $config;
continue;
}

/*
* Determine the order of keys, so the last defined can be preferred.
*
* The reason for preferring the last defined key is that after filters
* are applied, the last inserted key is likely the most up-to-date value.
* We cannot determine with certainty which value was "last modified" so
* the insertion order is the best guess. The extreme edge case of multiple
* filters tweaking the same support property will become less over time as
* extenders migrate existing blocks and plugins to stable keys.
*/
$key_positions = array_flip( array_keys( $args['supports'] ) );
$experimental_index = $key_positions[ $support ] ?? -1;
$stabilized_index = $key_positions[ $stabilized_key ] ?? -1;
$experimental_first = $experimental_index < $stabilized_index;

// Update support config, prefer the last defined value.
if ( is_array( $config ) ) {
$updated_supports[ $stabilized_key ] = $experimental_first
? array_merge( $config, $args['supports'][ $stabilized_key ] )
: array_merge( $args['supports'][ $stabilized_key ], $config );
} else {
$updated_supports[ $stabilized_key ] = $experimental_first
? $args['supports'][ $stabilized_key ]
: $config;
}

continue;
}

foreach ( $current_typography_supports as $key => $value ) {
if ( array_key_exists( $key, $experimental_typography_supports_to_stable ) ) {
$stable_typography_supports[ $experimental_typography_supports_to_stable[ $key ] ] = $value;
} else {
$stable_typography_supports[ $key ] = $value;
// Stabilize individual support feature keys e.g. __experimentalFontFamily => fontFamily.
if ( is_array( $experimental_to_stable_keys[ $support ] ) ) {
$stable_support_config = array();
foreach ( $config as $key => $value ) {
if ( array_key_exists( $key, $experimental_to_stable_keys[ $support ] ) ) {
$stable_support_config[ $experimental_to_stable_keys[ $support ][ $key ] ] = $value;
} else {
$stable_support_config[ $key ] = $value;
}
}
$updated_supports[ $support ] = $stable_support_config;
}
}

$args['supports']['typography'] = $stable_typography_supports;
$args['supports'] = $updated_supports;

return $args;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* REST API: Gutenberg_REST_Post_Types_Controller_6_8 class
*
* @package gutenberg
*/

/**
* Gutenberg_REST_Post_Types_Controller_6_8 class
*
* Add Block Editor default rendering mode to the post type response
* to allow enabling/disabling at the post type level.
*/
class Gutenberg_REST_Post_Types_Controller_6_8 extends WP_REST_Post_Types_Controller {
/**
* Add Block Editor default rendering mode setting to the response.
*
* @param WP_Post_Type $item Post type object.
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response Response object.
*/
public function prepare_item_for_response( $item, $request ) {
$response = parent::prepare_item_for_response( $item, $request );
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';

// Property will only exist if the post type supports the block editor.
if ( 'edit' === $context && property_exists( $item, 'default_rendering_mode' ) ) {
/**
* Filters the block editor rendering mode for a post type.
*
* @since 6.8.0
* @param string $default_rendering_mode Default rendering mode for the post type.
* @param WP_Post_Type $post_type Post type name.
* @return string Default rendering mode for the post type.
*/
$rendering_mode = apply_filters( 'post_type_default_rendering_mode', $item->default_rendering_mode, $item );

/**
* Filters the block editor rendering mode for a specific post type.
* Applied after the generic `post_type_default_rendering_mode` filter.
*
* The dynamic portion of the hook name, `$item->name`, refers to the post type slug.
*
* @since 6.8.0
* @param string $default_rendering_mode Default rendering mode for the post type.
* @param WP_Post_Type $post_type Post type object.
* @return string Default rendering mode for the post type.
*/
$rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $rendering_mode, $item );

// Validate the filtered rendering mode.
if ( ! in_array( $rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) {
$rendering_mode = 'post-only';
}

$response->data['default_rendering_mode'] = $rendering_mode;
}

return rest_ensure_response( $response );
}
}
57 changes: 57 additions & 0 deletions lib/compat/wordpress-6.8/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Temporary compatibility shims for block APIs present in Gutenberg.
*
* @package gutenberg
*/

/**
* Get the available rendering modes for the Block Editor.
*
* post-only: This mode extracts the post blocks from the template and renders only those.
* The idea is to allow the user to edit the post/page in isolation without the wrapping template.
*
* template-locked: This mode renders both the template and the post blocks
* but the template blocks are locked and can't be edited. The post blocks are editable.
*
* @return array Array of available rendering modes.
*/
function gutenberg_post_type_rendering_modes() {
return array(
'post-only',
'template-locked',
);
}

/**
* Add the default_rendering_mode property to the WP_Post_Type object.
* This property can be overwritten by using the post_type_default_rendering_mode filter.
*
* @param array $args Array of post type arguments.
* @param string $post_type Post type key.
* @return array Updated array of post type arguments.
*/
function gutenberg_post_type_default_rendering_mode( $args, $post_type ) {
$rendering_mode = 'page' === $post_type ? 'template-locked' : 'post-only';
$rendering_modes = gutenberg_post_type_rendering_modes();

// Make sure the post type supports the block editor.
if (
wp_is_block_theme() &&
( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) &&
( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) )
) {
// Validate the supplied rendering mode.
if (
isset( $args['default_rendering_mode'] ) &&
in_array( $args['default_rendering_mode'], $rendering_modes, true )
) {
$rendering_mode = $args['default_rendering_mode'];
}

$args['default_rendering_mode'] = $rendering_mode;
}

return $args;
}
add_filter( 'register_post_type_args', 'gutenberg_post_type_default_rendering_mode', 10, 2 );
Loading

0 comments on commit bdb36e2

Please sign in to comment.