Make WordPress Core


Ignore:
Timestamp:
02/06/2020 09:01:16 PM (7 years ago)
Author:
jorgefilipecosta
Message:

Block Editor: Update WordPress Packages.

The following package versions were changed:
@wordpress/a11y: 2.6.0 -> 2.7.0
@wordpress/annotations: 1.10.0 -> 1.11.0
@wordpress/api-fetch: 3.9.0 -> 3.10.0
@wordpress/autop: 2.5.1 -> 2.6.0
@wordpress/blob: 2.6.0 -> 2.7.0
@wordpress/block-directory: 1.3.0 -> 1.4.0
@wordpress/block-editor: 3.5.0 -> 3.6.0
@wordpress/block-library: 2.12.0 -> 2.13.0
@wordpress/block-serialization-default-parser: 3.4.1 -> 3.5.0
@wordpress/blocks: 6.10.0 -> 6.11.0
@wordpress/components: 9.0.0 -> 9.1.0
@wordpress/compose: 3.10.0 -> 3.11.0
@wordpress/core-data: 2.10.0 -> 2.11.0
@wordpress/custom-templated-path-webpack-plugin: 1.5.0 -> 1.6.0
@wordpress/data: 4.12.0 -> 4.13.0
@wordpress/data-controls: 1.6.0 -> 1.7.0
@wordpress/date: 3.7.0 -> 3.8.0
@wordpress/dependency-extraction-webpack-plugin: 2.1.0 -> 2.2.0
@wordpress/deprecated: 2.6.1 -> 2.7.0
@wordpress/dom: 2.7.0 -> 2.8.0
@wordpress/dom-ready: 2.6.0 -> 2.7.0
@wordpress/e2e-test-utils: 4.1.0 -> 4.2.0
@wordpress/edit-post: 3.11.0 -> 3.12.0
@wordpress/editor: 9.10.0 -> 9.11.0
@wordpress/element: 2.10.0 -> 2.11.0
@wordpress/escape-html: 1.6.0 -> 1.7.0
@wordpress/format-library: 1.12.0 -> 1.13.0
@wordpress/hooks: 2.6.0 -> 2.7.0
@wordpress/html-entities: 2.5.0 -> 2.6.0
@wordpress/i18n: 3.8.0 -> 3.9.0
@wordpress/is-shallow-equal: 1.7.0 -> 1.8.0
@wordpress/keyboard-shortcuts: 0.2.0 -> 1.0.0
@wordpress/keycodes: 2.8.0 -> 2.9.0
@wordpress/library-export-default-webpack-plugin: 1.5.0 -> 1.6.0
@wordpress/list-reusable-blocks: 1.11.0 -> 1.12.0
@wordpress/media-utils: 1.5.0 -> 1.6.0
@wordpress/notices: 1.11.0 -> 1.12.0
@wordpress/nux: 3.10.0 -> 3.11.0
@wordpress/plugins: 2.10.0 -> 2.11.0
@wordpress/priority-queue: 1.4.0 -> 1.5.0
@wordpress/redux-routine: 3.6.2 -> 3.7.0
@wordpress/rich-text: 3.10.0 -> 3.11.0
@wordpress/scripts: 6.2.0 -> 7.0.0
@wordpress/server-side-render: 1.6.0 -> 1.7.0
@wordpress/shortcode: 2.5.0 -> 2.6.0
@wordpress/token-list: 1.8.0 -> 1.9.0
@wordpress/url: 2.9.0 -> 2.10.0
@wordpress/viewport: 2.11.0 -> 2.12.0
@wordpress/wordcount: 2.6.2 -> 2.7.0
Added these new packages:
@wordpress/warning
@wordpress/primitives
@wordpress/icons
Re-added keyboard-shortcuts to script loader removed by mistake on revision 47198.

Props gziolo, itsjonq, youknowriad, mcsf, andraganescu.
Fixes #49358.

File:
1 edited

Legend:

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

    r47176 r47199  
    1414 */
    1515function build_css_colors( $attributes ) {
    16         // CSS classes.
    1716        $colors = array(
    1817                'css_classes'   => array(),
     
    2019        );
    2120
     21        // Text color.
    2222        $has_named_text_color  = array_key_exists( 'textColor', $attributes );
    2323        $has_custom_text_color = array_key_exists( 'customTextColor', $attributes );
     
    3434        } elseif ( $has_custom_text_color ) {
    3535                // Add the custom color inline style.
    36                 $colors['inline_styles'] = sprintf( 'color: %s;', $attributes['customTextColor'] );
     36                $colors['inline_styles'] .= sprintf( 'color: %s;', $attributes['customTextColor'] );
     37        }
     38
     39        // Background color.
     40        $has_named_background_color  = array_key_exists( 'backgroundColor', $attributes );
     41        $has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes );
     42
     43        // If has background color.
     44        if ( $has_custom_background_color || $has_named_background_color ) {
     45                // Add has-background-color class.
     46                $colors['css_classes'][] = 'has-background-color';
     47        }
     48
     49        if ( $has_named_background_color ) {
     50                // Add the background-color class.
     51                $colors['css_classes'][] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] );
     52        } elseif ( $has_custom_background_color ) {
     53                // Add the custom background-color inline style.
     54                $colors['inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] );
    3755        }
    3856
     
    6987
    7088/**
     89 * Recursively filters out links with no labels to build a clean navigation block structure.
     90 *
     91 * @param array $blocks Navigation link inner blocks from the Navigation block.
     92 * @return array Blocks that had valid labels
     93 */
     94function gutenberg_remove_empty_navigation_links_recursive( $blocks ) {
     95        $blocks = array_filter(
     96                $blocks,
     97                function( $block ) {
     98                        return ! empty( $block['attrs']['label'] );
     99                }
     100        );
     101
     102        if ( ! empty( $blocks ) ) {
     103                foreach ( $blocks as $key => $block ) {
     104                        if ( ! empty( $block['innerBlocks'] ) ) {
     105                                $blocks[ $key ]['innerBlocks'] = gutenberg_remove_empty_navigation_links_recursive( $block['innerBlocks'] );
     106                        }
     107                }
     108        }
     109
     110        return $blocks;
     111}
     112
     113/**
     114 * Returns the top-level submenu SVG chevron icon.
     115 *
     116 * @return string
     117 */
     118function render_submenu_icon() {
     119        return '<svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><polygon points="9,13.5 14.7,7.9 13.2,6.5 9,10.7 4.8,6.5 3.3,7.9 "></polygon></svg>';
     120}
     121
     122/**
    71123 * Renders the `core/navigation` block on server.
    72124 *
    73  * @param array $attributes The block attributes.
    74125 * @param array $content The saved content.
    75126 * @param array $block The parsed block.
     
    77128 * @return string Returns the post content with the legacy widget added.
    78129 */
    79 function render_block_navigation( $attributes, $content, $block ) {
     130function render_block_navigation( $content, $block ) {
     131
     132        if ( 'core/navigation' !== $block['blockName'] ) {
     133                return $content;
     134        }
     135
     136        $attributes           = $block['attrs'];
     137        $block['innerBlocks'] = gutenberg_remove_empty_navigation_links_recursive( $block['innerBlocks'] );
     138
     139        if ( empty( $block['innerBlocks'] ) ) {
     140                return '';
     141        }
     142
    80143        $colors          = build_css_colors( $attributes );
    81144        $font_sizes      = build_css_font_sizes( $attributes );
     
    97160                $class_attribute,
    98161                $style_attribute,
    99                 build_navigation_html( $block, $colors, $font_sizes )
     162                build_navigation_html( $attributes, $block, $colors, $font_sizes, true )
    100163        );
    101164}
     
    104167 * Walks the inner block structure and returns an HTML list for it.
    105168 *
    106  * @param array $block      The block.
    107  * @param array $colors     Contains inline styles and CSS classes to apply to navigation item.
    108  * @param array $font_sizes Contains inline styles and CSS classes to apply to navigation item.
     169 * @param array $attributes    The Navigation block attributes.
     170 * @param array $block         The NavigationItem block.
     171 * @param array $colors        Contains inline styles and CSS classes to apply to navigation item.
     172 * @param array $font_sizes    Contains inline styles and CSS classes to apply to navigation item.
     173 * @param bool  $is_level_zero True whether is main menu (level zero). Otherwise, False.
    109174 *
    110175 * @return string Returns  an HTML list from innerBlocks.
    111176 */
    112 function build_navigation_html( $block, $colors, $font_sizes ) {
     177function build_navigation_html( $attributes, $block, $colors, $font_sizes, $is_level_zero = true ) {
    113178        $html            = '';
    114179        $classes         = array_merge(
     
    123188
    124189        foreach ( (array) $block['innerBlocks'] as $key => $block ) {
    125 
    126                 $html .= '<li class="wp-block-navigation-link">' .
    127                         '<a' . $class_attribute . $style_attribute;
     190                $has_submenu = count( (array) $block['innerBlocks'] ) > 0;
     191
     192                $html .= '<li class="wp-block-navigation-link' . ( $has_submenu ? ' has-submenu' : '' ) . '">' .
     193                        '<a';
     194
     195                if ( $is_level_zero ) {
     196                        $html .= $class_attribute . $style_attribute;
     197                }
    128198
    129199                // Start appending HTML attributes to anchor tag.
     
    141211
    142212                // Start anchor tag content.
    143                 $html .= '>';
     213                $html .= '>' .
     214                        // Wrap title with span to isolate it from submenu icon.
     215                        '<span class="wp-block-navigation-link__label">';
     216
    144217                if ( isset( $block['attrs']['label'] ) ) {
    145                         $html .= esc_html( $block['attrs']['label'] );
    146                 }
     218                        $html .= wp_kses(
     219                                $block['attrs']['label'],
     220                                array(
     221                                        'code'   => array(),
     222                                        'em'     => array(),
     223                                        'img'    => array(
     224                                                'scale' => array(),
     225                                                'class' => array(),
     226                                                'style' => array(),
     227                                                'src'   => array(),
     228                                                'alt'   => array(),
     229                                        ),
     230                                        's'      => array(),
     231                                        'span'   => array(
     232                                                'style' => array(),
     233                                        ),
     234                                        'strong' => array(),
     235                                )
     236                        );
     237                }
     238
     239                $html .= '</span>';
     240
     241                // Append submenu icon to top-level item.
     242                if ( ! empty( $attributes['showSubmenuIcon'] ) && $is_level_zero && $has_submenu ) {
     243                        $html .= '<span class="wp-block-navigation-link__submenu-icon">' . render_submenu_icon() . '</span>';
     244                }
     245
    147246                $html .= '</a>';
    148247                // End anchor tag content.
    149248
    150                 if ( count( (array) $block['innerBlocks'] ) > 0 ) {
    151                         $html .= build_navigation_html( $block, $colors, $font_sizes );
     249                if ( $has_submenu ) {
     250                        $html .= build_navigation_html( $attributes, $block, $colors, $font_sizes, false );
    152251                }
    153252
     
    168267                'core/navigation',
    169268                array(
    170                         'attributes'      => array(
    171                                 'className'          => array(
    172                                         'type' => 'string',
    173                                 ),
    174                                 'textColor'          => array(
    175                                         'type' => 'string',
    176                                 ),
    177                                 'customTextColor'    => array(
    178                                         'type' => 'string',
    179                                 ),
    180                                 'fontSize'           => array(
    181                                         'type' => 'string',
    182                                 ),
    183                                 'customFontSize'     => array(
     269                        'attributes' => array(
     270                                'className'             => array(
     271                                        'type' => 'string',
     272                                ),
     273                                'textColor'             => array(
     274                                        'type' => 'string',
     275                                ),
     276                                'customTextColor'       => array(
     277                                        'type' => 'string',
     278                                ),
     279                                'backgroundColor'       => array(
     280                                        'type' => 'string',
     281                                ),
     282                                'customBackgroundColor' => array(
     283                                        'type' => 'string',
     284                                ),
     285                                'fontSize'              => array(
     286                                        'type' => 'string',
     287                                ),
     288                                'customFontSize'        => array(
    184289                                        'type' => 'number',
    185290                                ),
    186                                 'itemsJustification' => array(
    187                                         'type' => 'string',
     291                                'itemsJustification'    => array(
     292                                        'type' => 'string',
     293                                ),
     294                                'showSubmenuIcon'       => array(
     295                                        'type'    => 'boolean',
     296                                        'default' => false,
    188297                                ),
    189298                        ),
    190 
    191                         'render_callback' => 'render_block_navigation',
    192299                )
    193300        );
    194301}
    195302add_action( 'init', 'register_block_core_navigation' );
     303add_filter( 'render_block', 'render_block_navigation', 10, 2 );
Note: See TracChangeset for help on using the changeset viewer.