Make WordPress Core


Ignore:
Timestamp:
01/29/2024 09:04:18 PM (3 years ago)
Author:
youknowriad
Message:

Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.

This patch, somewhat small brings a lot to WordPress.
This includes features like:

  • DataViews.
  • Customization tools like box shadow, background size and repeat.
  • UI improvements in the site editor.
  • Preferences sharing between the post and site editors.
  • Unified panels and editors between post and site editors.
  • Improved template mode in the post editor.
  • Iterations to multiple interactive blocks.
  • Preparing the blocks and UI for pattern overrides.
  • and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/search.php

    r56849 r57377  
    1717 * @return string The search block markup.
    1818 */
    19 function render_block_core_search( $attributes, $content, $block ) {
     19function render_block_core_search( $attributes ) {
    2020        // Older versions of the Search block defaulted the label and buttonText
    2121        // attributes to `__( 'Search' )` meaning that many posts contain `<!--
     
    3737        $button_position     = $show_button ? $attributes['buttonPosition'] : null;
    3838        $query_params        = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array();
    39         $button_behavior     = ( ! empty( $attributes['buttonBehavior'] ) ) ? $attributes['buttonBehavior'] : 'default';
    4039        $button              = '';
    4140        $query_params_markup = '';
     
    7978                $input->set_attribute( 'placeholder', $attributes['placeholder'] );
    8079
    81                 $is_expandable_searchfield = 'button-only' === $button_position && 'expand-searchfield' === $button_behavior;
     80                // If it's interactive, enqueue the script module and add the directives.
     81                $is_expandable_searchfield = 'button-only' === $button_position;
    8282                if ( $is_expandable_searchfield ) {
    83                         $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.core.search.isSearchInputVisible' );
    84                         $input->set_attribute( 'data-wp-bind--tabindex', 'selectors.core.search.tabindex' );
    85                         // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
     83                        wp_enqueue_script_module( '@wordpress/block-library/search' );
     84
     85                        $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
     86                        $input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
     87
     88                        // Adding these attributes manually is needed until the Interactivity API
     89                        // SSR logic is added to core.
    8690                        $input->set_attribute( 'aria-hidden', 'true' );
    8791                        $input->set_attribute( 'tabindex', '-1' );
    88                 }
    89 
    90                 // If the script already exists, there is no point in removing it from viewScript.
    91                 $view_js_file = 'wp-block-search-view';
    92                 if ( ! wp_script_is( $view_js_file ) ) {
    93                         $script_handles = $block->block_type->view_script_handles;
    94 
    95                         // If the script is not needed, and it is still in the `view_script_handles`, remove it.
    96                         if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) {
    97                                 $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
    98                         }
    99                         // If the script is needed, but it was previously removed, add it again.
    100                         if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) {
    101                                 $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
    102                         }
    10392                }
    10493        }
     
    145134                if ( $button->next_tag() ) {
    146135                        $button->add_class( implode( ' ', $button_classes ) );
    147                         if ( 'expand-searchfield' === $attributes['buttonBehavior'] && 'button-only' === $attributes['buttonPosition'] ) {
    148                                 $button->set_attribute( 'data-wp-bind--aria-label', 'selectors.core.search.ariaLabel' );
    149                                 $button->set_attribute( 'data-wp-bind--aria-controls', 'selectors.core.search.ariaControls' );
    150                                 $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.core.search.isSearchInputVisible' );
    151                                 $button->set_attribute( 'data-wp-bind--type', 'selectors.core.search.type' );
    152                                 $button->set_attribute( 'data-wp-on--click', 'actions.core.search.openSearchInput' );
    153                                 // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
     136                        if ( 'button-only' === $attributes['buttonPosition'] ) {
     137                                $button->set_attribute( 'data-wp-bind--aria-label', 'state.ariaLabel' );
     138                                $button->set_attribute( 'data-wp-bind--aria-controls', 'state.ariaControls' );
     139                                $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.isSearchInputVisible' );
     140                                $button->set_attribute( 'data-wp-bind--type', 'state.type' );
     141                                $button->set_attribute( 'data-wp-on--click', 'actions.openSearchInput' );
     142
     143                                // Adding these attributes manually is needed until the Interactivity
     144                                // API SSR logic is added to core.
    154145                                $button->set_attribute( 'aria-label', __( 'Expand search field' ) );
    155146                                $button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id );
     
    173164        );
    174165        $form_directives      = '';
     166
     167        // If it's interactive, add the directives.
    175168        if ( $is_expandable_searchfield ) {
    176169                $aria_label_expanded  = __( 'Submit Search' );
    177170                $aria_label_collapsed = __( 'Expand search field' );
    178171                $form_directives      = '
    179                         data-wp-interactive
    180                         data-wp-context=\'{ "core": { "search": { "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" } } }\'
    181                         data-wp-class--wp-block-search__searchfield-hidden="!context.core.search.isSearchInputVisible"
    182                         data-wp-on--keydown="actions.core.search.handleSearchKeydown"
    183                         data-wp-on--focusout="actions.core.search.handleSearchFocusout"
     172                        data-wp-interactive=\'{ "namespace": "core/search" }\'
     173                        data-wp-context=\'{ "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" }\'
     174                        data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
     175                        data-wp-on--keydown="actions.handleSearchKeydown"
     176                        data-wp-on--focusout="actions.handleSearchFocusout"
    184177                ';
    185178        }
     
    204197                )
    205198        );
     199
     200        wp_register_script_module(
     201                '@wordpress/block-library/search',
     202                defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/search.min.js' ) : includes_url( 'blocks/search/view.min.js' ),
     203                array( '@wordpress/interactivity' ),
     204                defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
     205        );
    206206}
    207207add_action( 'init', 'register_block_core_search' );
    208 
    209 /**
    210  * Ensure that the view script has the `wp-interactivity` dependency.
    211  *
    212  * @since 6.4.0
    213  *
    214  * @global WP_Scripts $wp_scripts
    215  */
    216 function block_core_search_ensure_interactivity_dependency() {
    217         global $wp_scripts;
    218         if (
    219                 isset( $wp_scripts->registered['wp-block-search-view'] ) &&
    220                 ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-search-view']->deps, true )
    221         ) {
    222                 $wp_scripts->registered['wp-block-search-view']->deps[] = 'wp-interactivity';
    223         }
    224 }
    225 
    226 add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' );
    227208
    228209/**
     
    250231
    251232                if ( 'button-only' === $attributes['buttonPosition'] ) {
    252                         $classnames[] = 'wp-block-search__button-only';
    253                         if ( ! empty( $attributes['buttonBehavior'] ) && 'expand-searchfield' === $attributes['buttonBehavior'] ) {
    254                                 $classnames[] = 'wp-block-search__button-behavior-expand wp-block-search__searchfield-hidden';
    255                         }
     233                        $classnames[] = 'wp-block-search__button-only wp-block-search__searchfield-hidden';
    256234                }
    257235        }
Note: See TracChangeset for help on using the changeset viewer.