Make WordPress Core


Ignore:
Timestamp:
09/20/2022 03:14:54 PM (3 years ago)
Author:
gziolo
Message:

Editor: Sync changes from the Gutenberg plugin 14.1 release

Updated WordPress packages necessary for releasing WordPress 6.1 Beta 1:

  • @wordpress/a11y@3.17.1
    • @wordpress/annotations@2.17.2
    • @wordpress/api-fetch@6.14.1
    • @wordpress/autop@3.17.1
    • @wordpress/babel-plugin-import-jsx-pragma@4.0.1
    • @wordpress/babel-plugin-makepot@5.1.1
    • @wordpress/babel-preset-default@7.1.1
    • @wordpress/base-styles@4.8.1
    • @wordpress/blob@3.17.1
    • @wordpress/block-directory@3.15.2
    • @wordpress/block-editor@10.0.2
    • @wordpress/block-library@7.14.2
    • @wordpress/block-serialization-default-parser@4.17.1
    • @wordpress/block-serialization-spec-parser@4.17.1
    • @wordpress/blocks@11.16.2
    • @wordpress/browserslist-config@5.0.1
    • @wordpress/components@21.0.2
    • @wordpress/compose@5.15.2
    • @wordpress/core-data@5.0.2
    • @wordpress/create-block-tutorial-template@2.5.1
    • @wordpress/create-block@4.1.1
    • @wordpress/custom-templated-path-webpack-plugin@2.1.3
    • @wordpress/customize-widgets@3.14.2
    • @wordpress/data-controls@2.17.2
    • @wordpress/data@7.1.2
    • @wordpress/date@4.17.1
    • @wordpress/dependency-extraction-webpack-plugin@4.0.2
    • @wordpress/deprecated@3.17.1
    • @wordpress/docgen@1.26.1
    • @wordpress/dom-ready@3.17.1
    • @wordpress/dom@3.17.2
    • @wordpress/e2e-test-utils@8.1.1
    • @wordpress/e2e-tests@5.1.2
    • @wordpress/edit-post@6.14.2
    • @wordpress/edit-site@4.14.2
    • @wordpress/edit-widgets@4.14.2
    • @wordpress/editor@12.16.2
    • @wordpress/element@4.15.1
    • @wordpress/env@5.2.1
    • @wordpress/escape-html@2.17.1
    • @wordpress/eslint-plugin@13.1.1
    • @wordpress/format-library@3.15.2
    • @wordpress/hooks@3.17.1
    • @wordpress/html-entities@3.17.1
    • @wordpress/i18n@4.17.1
    • @wordpress/icons@9.8.1
    • @wordpress/interface@4.16.2
    • @wordpress/is-shallow-equal@4.17.1
    • @wordpress/jest-console@6.0.1
    • @wordpress/jest-preset-default@9.0.1
    • @wordpress/jest-puppeteer-axe@5.0.1
    • @wordpress/keyboard-shortcuts@3.15.2
    • @wordpress/keycodes@3.17.1
    • @wordpress/lazy-import@1.4.3
    • @wordpress/library-export-default-webpack-plugin@2.3.3
    • @wordpress/list-reusable-blocks@3.15.2
    • @wordpress/media-utils@4.8.1
    • @wordpress/notices@3.17.2
    • @wordpress/npm-package-json-lint-config@4.2.1
    • @wordpress/nux@5.15.2
    • @wordpress/plugins@4.15.2
    • @wordpress/postcss-plugins-preset@4.1.1
    • @wordpress/postcss-themes@5.0.1
    • @wordpress/preferences-persistence@1.9.1
    • @wordpress/preferences@2.9.2
    • @wordpress/prettier-config@2.0.1
    • @wordpress/primitives@3.15.1
    • @wordpress/priority-queue@2.17.2
    • @wordpress/project-management-automation@1.16.1
    • @wordpress/react-i18n@3.15.1
    • @wordpress/readable-js-assets-webpack-plugin@2.0.1
    • @wordpress/redux-routine@4.17.1
    • @wordpress/reusable-blocks@3.15.2
    • @wordpress/rich-text@5.15.2
    • @wordpress/scripts@24.1.2
    • @wordpress/server-side-render@3.15.2
    • @wordpress/shortcode@3.17.1
    • @wordpress/style-engine@1.0.1
    • @wordpress/stylelint-config@21.0.1
    • @wordpress/token-list@2.17.1
    • @wordpress/url@3.18.1
    • @wordpress/viewport@4.15.2
    • @wordpress/warning@2.17.1
    • @wordpress/widgets@2.15.2
    • @wordpress/wordcount@3.17.1

Props bernhard-reiter, cbravobernal, czapla, oandregal, isabel_brison, andrewserong, mciampini.
See #56467.

File:
1 edited

Legend:

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

    r53879 r54257  
    1414 */
    1515function render_block_core_search( $attributes ) {
    16     static $instance_id = 0;
    17 
    1816    // Older versions of the Search block defaulted the label and buttonText
    1917    // attributes to `__( 'Search' )` meaning that many posts contain `<!--
     
    2826    );
    2927
    30     $input_id         = 'wp-block-search__input-' . ++$instance_id;
    31     $classnames       = classnames_for_block_core_search( $attributes );
    32     $show_label       = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
    33     $use_icon_button  = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
    34     $show_input       = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
    35     $show_button      = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
    36     $input_markup     = '';
    37     $button_markup    = '';
    38     $inline_styles    = styles_for_block_core_search( $attributes );
    39     $color_classes    = get_color_classes_for_block_core_search( $attributes );
    40     $is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
     28    $input_id            = wp_unique_id( 'wp-block-search__input-' );
     29    $classnames          = classnames_for_block_core_search( $attributes );
     30    $show_label          = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
     31    $use_icon_button     = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
     32    $show_input          = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
     33    $show_button         = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
     34    $query_params        = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array();
     35    $input_markup        = '';
     36    $button_markup       = '';
     37    $query_params_markup = '';
     38    $inline_styles       = styles_for_block_core_search( $attributes );
     39    $color_classes       = get_color_classes_for_block_core_search( $attributes );
     40    $typography_classes  = get_typography_classes_for_block_core_search( $attributes );
     41    $is_button_inside    = ! empty( $attributes['buttonPosition'] ) &&
    4142        'button-inside' === $attributes['buttonPosition'];
    4243    // Border color classes need to be applied to the elements that have a border color.
     
    5152    );
    5253    if ( $show_label && ! empty( $attributes['label'] ) ) {
     54        $label_classes = array( 'wp-block-search__label' );
     55        if ( ! empty( $typography_classes ) ) {
     56            $label_classes[] = $typography_classes;
     57        }
    5358        $label_markup = sprintf(
    54             '<label for="%1$s" class="wp-block-search__label">%2$s</label>',
    55             $input_id,
     59            '<label for="%1$s" class="%2$s" %3$s>%4$s</label>',
     60            esc_attr( $input_id ),
     61            esc_attr( implode( ' ', $label_classes ) ),
     62            $inline_styles['label'],
    5663            $label_inner_html
    5764        );
     
    5966
    6067    if ( $show_input ) {
    61         $input_classes = ! $is_button_inside ? $border_color_classes : '';
    62         $input_markup  = sprintf(
     68        $input_classes = array( 'wp-block-search__input' );
     69        if ( $is_button_inside ) {
     70            $input_classes[] = $border_color_classes;
     71        }
     72        if ( ! empty( $typography_classes ) ) {
     73            $input_classes[] = $typography_classes;
     74        }
     75        $input_markup = sprintf(
    6376            '<input type="search" id="%s" class="wp-block-search__input %s" name="s" value="%s" placeholder="%s" %s required />',
    6477            $input_id,
    65             esc_attr( $input_classes ),
    66             esc_attr( get_search_query() ),
     78            esc_attr( implode( ' ', $input_classes ) ),
     79            get_search_query(),
    6780            esc_attr( $attributes['placeholder'] ),
    6881            $inline_styles['input']
     
    7083    }
    7184
     85    if ( count( $query_params ) > 0 ) {
     86        foreach ( $query_params as $param => $value ) {
     87            $query_params_markup .= sprintf(
     88                '<input type="hidden" name="%s" value="%s" />',
     89                esc_attr( $param ),
     90                esc_attr( $value )
     91            );
     92        }
     93    }
     94
    7295    if ( $show_button ) {
     96        $button_classes         = array( 'wp-block-search__button' );
    7397        $button_internal_markup = '';
    74         $button_classes         = $color_classes;
    75         $aria_label             = '';
    76 
    77         if ( ! $is_button_inside ) {
    78             $button_classes .= ' ' . $border_color_classes;
     98        if ( ! empty( $color_classes ) ) {
     99            $button_classes[] = $color_classes;
     100        }
     101        if ( ! empty( $typography_classes ) ) {
     102            $button_classes[] = $typography_classes;
     103        }
     104        $aria_label = '';
     105
     106        if ( ! $is_button_inside && ! empty( $border_color_classes ) ) {
     107            $button_classes[] = $border_color_classes;
    79108        }
    80109        if ( ! $use_icon_button ) {
     
    83112            }
    84113        } else {
    85             $aria_label      = sprintf( 'aria-label="%s"', esc_attr( wp_strip_all_tags( $attributes['buttonText'] ) ) );
    86             $button_classes .= ' has-icon';
     114            $aria_label       = sprintf( 'aria-label="%s"', esc_attr( wp_strip_all_tags( $attributes['buttonText'] ) ) );
     115            $button_classes[] = 'has-icon';
    87116
    88117            $button_internal_markup =
    89                 '<svg id="search-icon" class="search-icon" viewBox="0 0 24 24" width="24" height="24">
     118                '<svg class="search-icon" viewBox="0 0 24 24" width="24" height="24">
    90119                    <path d="M13.5 6C10.5 6 8 8.5 8 11.5c0 1.1.3 2.1.9 3l-3.4 3 1 1.1 3.4-2.9c1 .9 2.2 1.4 3.6 1.4 3 0 5.5-2.5 5.5-5.5C19 8.5 16.5 6 13.5 6zm0 9.5c-2.2 0-4-1.8-4-4s1.8-4 4-4 4 1.8 4 4-1.8 4-4 4z"></path>
    91120                </svg>';
    92121        }
    93122
    94         $button_markup = sprintf(
    95             '<button type="submit" class="wp-block-search__button %s" %s %s>%s</button>',
    96             esc_attr( $button_classes ),
     123        // Include the button element class.
     124        $button_classes[] = wp_theme_get_element_class_name( 'button' );
     125        $button_markup    = sprintf(
     126            '<button type="submit" class="%s" %s %s>%s</button>',
     127            esc_attr( implode( ' ', $button_classes ) ),
    97128            $inline_styles['button'],
    98129            $aria_label,
     
    106137        esc_attr( $field_markup_classes ),
    107138        $inline_styles['wrapper'],
    108         $input_markup . $button_markup
    109     );
    110     $wrapper_attributes   = get_block_wrapper_attributes( array( 'class' => $classnames ) );
     139        $input_markup . $query_params_markup . $button_markup
     140    );
     141    $wrapper_attributes   = get_block_wrapper_attributes(
     142        array( 'class' => $classnames )
     143    );
    111144
    112145    return sprintf(
     
    173206
    174207/**
     208 * This generates a CSS rule for the given border property and side if provided.
     209 * Based on whether the Search block is configured to display the button inside
     210 * or not, the generated rule is injected into the appropriate collection of
     211 * styles for later application in the block's markup.
     212 *
     213 * @param array  $attributes     The block attributes.
     214 * @param string $property       Border property to generate rule for e.g. width or color.
     215 * @param string $side           Optional side border. The dictates the value retrieved and final CSS property.
     216 * @param array  $wrapper_styles Current collection of wrapper styles.
     217 * @param array  $button_styles  Current collection of button styles.
     218 * @param array  $input_styles   Current collection of input styles.
     219 *
     220 * @return void
     221 */
     222function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) {
     223    $is_button_inside = 'button-inside' === _wp_array_get( $attributes, array( 'buttonPosition' ), false );
     224
     225    $path = array( 'style', 'border', $property );
     226
     227    if ( $side ) {
     228        array_splice( $path, 2, 0, $side );
     229    }
     230
     231    $value = _wp_array_get( $attributes, $path, false );
     232
     233    if ( empty( $value ) ) {
     234        return;
     235    }
     236
     237    if ( 'color' === $property && $side ) {
     238        $has_color_preset = str_contains( $value, 'var:preset|color|' );
     239        if ( $has_color_preset ) {
     240            $named_color_value = substr( $value, strrpos( $value, '|' ) + 1 );
     241            $value             = sprintf( 'var(--wp--preset--color--%s)', $named_color_value );
     242        }
     243    }
     244
     245    $property_suffix = $side ? sprintf( '%s-%s', $side, $property ) : $property;
     246
     247    if ( $is_button_inside ) {
     248        $wrapper_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
     249    } else {
     250        $button_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
     251        $input_styles[]  = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) );
     252    }
     253}
     254
     255/**
     256 * This adds CSS rules for a given border property e.g. width or color. It
     257 * injects rules into the provided wrapper, button and input style arrays for
     258 * uniform "flat" borders or those with individual sides configured.
     259 *
     260 * @param array  $attributes     The block attributes.
     261 * @param string $property       Border property to generate rule for e.g. width or color.
     262 * @param array  $wrapper_styles Current collection of wrapper styles.
     263 * @param array  $button_styles  Current collection of button styles.
     264 * @param array  $input_styles   Current collection of input styles.
     265 *
     266 * @return void
     267 */
     268function apply_block_core_search_border_styles( $attributes, $property, &$wrapper_styles, &$button_styles, &$input_styles ) {
     269    apply_block_core_search_border_style( $attributes, $property, null, $wrapper_styles, $button_styles, $input_styles );
     270    apply_block_core_search_border_style( $attributes, $property, 'top', $wrapper_styles, $button_styles, $input_styles );
     271    apply_block_core_search_border_style( $attributes, $property, 'right', $wrapper_styles, $button_styles, $input_styles );
     272    apply_block_core_search_border_style( $attributes, $property, 'bottom', $wrapper_styles, $button_styles, $input_styles );
     273    apply_block_core_search_border_style( $attributes, $property, 'left', $wrapper_styles, $button_styles, $input_styles );
     274}
     275
     276/**
    175277 * Builds an array of inline styles for the search block.
    176278 *
     
    187289    $button_styles    = array();
    188290    $input_styles     = array();
     291    $label_styles     = array();
    189292    $is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
    190293        'button-inside' === $attributes['buttonPosition'];
     294    $show_label       = ( isset( $attributes['showLabel'] ) ) && false !== $attributes['showLabel'];
    191295
    192296    // Add width styles.
     
    202306    }
    203307
    204     // Add border width styles.
    205     $has_border_width = ! empty( $attributes['style']['border']['width'] );
    206 
    207     if ( $has_border_width ) {
    208         $border_width = $attributes['style']['border']['width'];
    209 
    210         if ( $is_button_inside ) {
    211             $wrapper_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
    212         } else {
    213             $button_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
    214             $input_styles[]  = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
    215         }
    216     }
     308    // Add border width and color styles.
     309    apply_block_core_search_border_styles( $attributes, 'width', $wrapper_styles, $button_styles, $input_styles );
     310    apply_block_core_search_border_styles( $attributes, 'color', $wrapper_styles, $button_styles, $input_styles );
     311    apply_block_core_search_border_styles( $attributes, 'style', $wrapper_styles, $button_styles, $input_styles );
    217312
    218313    // Add border radius styles.
     
    270365    }
    271366
    272     // Add border color styles.
    273     $has_border_color = ! empty( $attributes['style']['border']['color'] );
    274 
    275     if ( $has_border_color ) {
    276         $border_color = $attributes['style']['border']['color'];
    277 
    278         // Apply wrapper border color if button placed inside.
    279         if ( $is_button_inside ) {
    280             $wrapper_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
    281         } else {
    282             $button_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
    283             $input_styles[]  = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
    284         }
    285     }
    286 
    287367    // Add color styles.
    288368    $has_text_color = ! empty( $attributes['style']['color']['text'] );
     
    301381    }
    302382
     383    // Get typography styles to be shared across inner elements.
     384    $typography_styles = get_typography_styles_for_block_core_search( $attributes );
     385    if ( ! empty( $typography_styles ) ) {
     386        $label_styles [] = $typography_styles;
     387        $button_styles[] = $typography_styles;
     388        $input_styles [] = $typography_styles;
     389    }
     390
     391    // Typography text-decoration is only applied to the label and button.
     392    if ( ! empty( $attributes['style']['typography']['textDecoration'] ) ) {
     393        $text_decoration_value = sprintf( 'text-decoration: %s;', esc_attr( $attributes['style']['typography']['textDecoration'] ) );
     394        $button_styles[]       = $text_decoration_value;
     395        // Input opts out of text decoration.
     396        if ( $show_label ) {
     397            $label_styles[] = $text_decoration_value;
     398        }
     399    }
     400
    303401    return array(
    304402        'input'   => ! empty( $input_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $input_styles ) ) ) : '',
    305403        'button'  => ! empty( $button_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $button_styles ) ) ) : '',
    306404        'wrapper' => ! empty( $wrapper_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $wrapper_styles ) ) ) : '',
    307     );
     405        'label'   => ! empty( $label_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $label_styles ) ) ) ) : '',
     406    );
     407}
     408
     409/**
     410 * Returns typography classnames depending on whether there are named font sizes/families .
     411 *
     412 * @param array $attributes The block attributes.
     413 *
     414 * @return string The typography color classnames to be applied to the block elements.
     415 */
     416function get_typography_classes_for_block_core_search( $attributes ) {
     417    $typography_classes    = array();
     418    $has_named_font_family = ! empty( $attributes['fontFamily'] );
     419    $has_named_font_size   = ! empty( $attributes['fontSize'] );
     420
     421    if ( $has_named_font_size ) {
     422        $typography_classes[] = sprintf( 'has-%s-font-size', esc_attr( $attributes['fontSize'] ) );
     423    }
     424
     425    if ( $has_named_font_family ) {
     426        $typography_classes[] = sprintf( 'has-%s-font-family', esc_attr( $attributes['fontFamily'] ) );
     427    }
     428
     429    return implode( ' ', $typography_classes );
     430}
     431
     432/**
     433 * Returns typography styles to be included in an HTML style tag.
     434 * This excludes text-decoration, which is applied only to the label and button elements of the search block.
     435 *
     436 * @param array $attributes The block attributes.
     437 *
     438 * @return string A string of typography CSS declarations.
     439 */
     440function get_typography_styles_for_block_core_search( $attributes ) {
     441    $typography_styles = array();
     442
     443    // Add typography styles.
     444    if ( ! empty( $attributes['style']['typography']['fontSize'] ) ) {
     445        $typography_styles[] = sprintf( 'font-size: %s;', esc_attr( $attributes['style']['typography']['fontSize'] ) );
     446    }
     447
     448    if ( ! empty( $attributes['style']['typography']['fontFamily'] ) ) {
     449        $typography_styles[] = sprintf( 'font-family: %s;', esc_attr( $attributes['style']['typography']['fontFamily'] ) );
     450    }
     451
     452    if ( ! empty( $attributes['style']['typography']['letterSpacing'] ) ) {
     453        $typography_styles[] = sprintf( 'letter-spacing: %s;', esc_attr( $attributes['style']['typography']['letterSpacing'] ) );
     454    }
     455
     456    if ( ! empty( $attributes['style']['typography']['fontWeight'] ) ) {
     457        $typography_styles[] = sprintf( 'font-weight: %s;', esc_attr( $attributes['style']['typography']['fontWeight'] ) );
     458    }
     459
     460    if ( ! empty( $attributes['style']['typography']['fontStyle'] ) ) {
     461        $typography_styles[] = sprintf( 'font-style: %s;', esc_attr( $attributes['style']['typography']['fontStyle'] ) );
     462    }
     463
     464    if ( ! empty( $attributes['style']['typography']['lineHeight'] ) ) {
     465        $typography_styles[] = sprintf( 'line-height: %s;', esc_attr( $attributes['style']['typography']['lineHeight'] ) );
     466    }
     467
     468    if ( ! empty( $attributes['style']['typography']['textTransform'] ) ) {
     469        $typography_styles[] = sprintf( 'text-transform: %s;', esc_attr( $attributes['style']['typography']['textTransform'] ) );
     470    }
     471
     472    return implode( '', $typography_styles );
    308473}
    309474
     
    316481 */
    317482function get_border_color_classes_for_block_core_search( $attributes ) {
     483    $border_color_classes    = array();
    318484    $has_custom_border_color = ! empty( $attributes['style']['border']['color'] );
    319     $border_color_classes    = ! empty( $attributes['borderColor'] ) ? sprintf( 'has-border-color has-%s-border-color', $attributes['borderColor'] ) : '';
    320     // If there's a border color style and no `borderColor` text string, we still want to add the generic `has-border-color` class name to the element.
    321     if ( $has_custom_border_color && empty( $attributes['borderColor'] ) ) {
    322         $border_color_classes = 'has-border-color';
    323     }
    324     return $border_color_classes;
     485    $has_named_border_color  = ! empty( $attributes['borderColor'] );
     486
     487    if ( $has_custom_border_color || $has_named_border_color ) {
     488        $border_color_classes[] = 'has-border-color';
     489    }
     490
     491    if ( $has_named_border_color ) {
     492        $border_color_classes[] = sprintf( 'has-%s-border-color', esc_attr( $attributes['borderColor'] ) );
     493    }
     494
     495    return implode( ' ', $border_color_classes );
    325496}
    326497
Note: See TracChangeset for help on using the changeset viewer.