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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47199 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jorge Costa 2020-02-06 21:01:16 +00:00
parent e72fff9cef
commit 8640eaa96e
11 changed files with 1427 additions and 985 deletions

2059
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,10 @@
"last 2 Opera versions"
],
"devDependencies": {
"@wordpress/custom-templated-path-webpack-plugin": "1.5.0",
"@wordpress/dependency-extraction-webpack-plugin": "2.1.0",
"@wordpress/e2e-test-utils": "4.1.0",
"@wordpress/library-export-default-webpack-plugin": "1.5.0",
"@wordpress/custom-templated-path-webpack-plugin": "1.6.0",
"@wordpress/dependency-extraction-webpack-plugin": "2.2.0",
"@wordpress/e2e-test-utils": "4.2.0",
"@wordpress/library-export-default-webpack-plugin": "1.6.0",
"@wordpress/scripts": "6.2.0",
"autoprefixer": "9.6.2",
"check-node-version": "4.0.1",
@ -72,50 +72,53 @@
},
"dependencies": {
"@babel/polyfill": "7.4.4",
"@wordpress/a11y": "2.6.0",
"@wordpress/annotations": "1.10.0",
"@wordpress/api-fetch": "3.9.0",
"@wordpress/autop": "2.5.1",
"@wordpress/blob": "2.6.0",
"@wordpress/block-directory": "1.3.0",
"@wordpress/block-editor": "3.5.0",
"@wordpress/block-library": "2.12.0",
"@wordpress/block-serialization-default-parser": "3.4.1",
"@wordpress/blocks": "6.10.0",
"@wordpress/components": "9.0.0",
"@wordpress/compose": "3.10.0",
"@wordpress/core-data": "2.10.0",
"@wordpress/data": "4.12.0",
"@wordpress/data-controls": "1.6.0",
"@wordpress/date": "3.7.0",
"@wordpress/deprecated": "2.6.1",
"@wordpress/dom": "2.7.0",
"@wordpress/dom-ready": "2.6.0",
"@wordpress/edit-post": "3.11.0",
"@wordpress/editor": "9.10.0",
"@wordpress/element": "2.10.0",
"@wordpress/escape-html": "1.6.0",
"@wordpress/format-library": "1.12.0",
"@wordpress/hooks": "2.6.0",
"@wordpress/html-entities": "2.5.0",
"@wordpress/i18n": "3.8.0",
"@wordpress/is-shallow-equal": "1.7.0",
"@wordpress/keyboard-shortcuts": "0.2.0",
"@wordpress/keycodes": "2.8.0",
"@wordpress/list-reusable-blocks": "1.11.0",
"@wordpress/media-utils": "1.5.0",
"@wordpress/notices": "1.11.0",
"@wordpress/nux": "3.10.0",
"@wordpress/plugins": "2.10.0",
"@wordpress/priority-queue": "1.4.0",
"@wordpress/redux-routine": "3.6.2",
"@wordpress/rich-text": "3.10.0",
"@wordpress/server-side-render": "1.6.0",
"@wordpress/shortcode": "2.5.0",
"@wordpress/token-list": "1.8.0",
"@wordpress/url": "2.9.0",
"@wordpress/viewport": "2.11.0",
"@wordpress/wordcount": "2.6.2",
"@wordpress/a11y": "2.7.0",
"@wordpress/annotations": "1.11.0",
"@wordpress/api-fetch": "3.10.0",
"@wordpress/autop": "2.6.0",
"@wordpress/blob": "2.7.0",
"@wordpress/block-directory": "1.4.0",
"@wordpress/block-editor": "3.6.0",
"@wordpress/block-library": "2.13.0",
"@wordpress/block-serialization-default-parser": "3.5.0",
"@wordpress/blocks": "6.11.0",
"@wordpress/components": "9.1.0",
"@wordpress/compose": "3.11.0",
"@wordpress/core-data": "2.11.0",
"@wordpress/data": "4.13.0",
"@wordpress/data-controls": "1.7.0",
"@wordpress/date": "3.8.0",
"@wordpress/deprecated": "2.7.0",
"@wordpress/dom": "2.8.0",
"@wordpress/dom-ready": "2.7.0",
"@wordpress/edit-post": "3.12.0",
"@wordpress/editor": "9.11.0",
"@wordpress/element": "2.11.0",
"@wordpress/escape-html": "1.7.0",
"@wordpress/format-library": "1.13.0",
"@wordpress/hooks": "2.7.0",
"@wordpress/html-entities": "2.6.0",
"@wordpress/i18n": "3.9.0",
"@wordpress/icons": "1.0.0",
"@wordpress/is-shallow-equal": "1.8.0",
"@wordpress/keyboard-shortcuts": "1.0.0",
"@wordpress/keycodes": "2.9.0",
"@wordpress/list-reusable-blocks": "1.12.0",
"@wordpress/media-utils": "1.6.0",
"@wordpress/notices": "1.12.0",
"@wordpress/nux": "3.11.0",
"@wordpress/plugins": "2.11.0",
"@wordpress/primitives": "1.0.0",
"@wordpress/priority-queue": "1.5.0",
"@wordpress/redux-routine": "3.7.0",
"@wordpress/rich-text": "3.11.0",
"@wordpress/server-side-render": "1.7.0",
"@wordpress/shortcode": "2.6.0",
"@wordpress/token-list": "1.9.0",
"@wordpress/url": "2.10.0",
"@wordpress/viewport": "2.12.0",
"@wordpress/warning": "1.0.0",
"@wordpress/wordcount": "2.7.0",
"backbone": "1.4.0",
"clipboard": "2.0.4",
"element-closest": "^2.0.2",

View File

@ -13,12 +13,12 @@
* @return array Colors CSS classes and inline styles.
*/
function build_css_colors( $attributes ) {
// CSS classes.
$colors = array(
'css_classes' => array(),
'inline_styles' => '',
);
// Text color.
$has_named_text_color = array_key_exists( 'textColor', $attributes );
$has_custom_text_color = array_key_exists( 'customTextColor', $attributes );
@ -33,7 +33,25 @@ function build_css_colors( $attributes ) {
$colors['css_classes'][] = sprintf( 'has-%s-color', $attributes['textColor'] );
} elseif ( $has_custom_text_color ) {
// Add the custom color inline style.
$colors['inline_styles'] = sprintf( 'color: %s;', $attributes['customTextColor'] );
$colors['inline_styles'] .= sprintf( 'color: %s;', $attributes['customTextColor'] );
}
// Background color.
$has_named_background_color = array_key_exists( 'backgroundColor', $attributes );
$has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes );
// If has background color.
if ( $has_custom_background_color || $has_named_background_color ) {
// Add has-background-color class.
$colors['css_classes'][] = 'has-background-color';
}
if ( $has_named_background_color ) {
// Add the background-color class.
$colors['css_classes'][] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] );
} elseif ( $has_custom_background_color ) {
// Add the custom background-color inline style.
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] );
}
return $colors;
@ -67,16 +85,61 @@ function build_css_font_sizes( $attributes ) {
return $font_sizes;
}
/**
* Recursively filters out links with no labels to build a clean navigation block structure.
*
* @param array $blocks Navigation link inner blocks from the Navigation block.
* @return array Blocks that had valid labels
*/
function gutenberg_remove_empty_navigation_links_recursive( $blocks ) {
$blocks = array_filter(
$blocks,
function( $block ) {
return ! empty( $block['attrs']['label'] );
}
);
if ( ! empty( $blocks ) ) {
foreach ( $blocks as $key => $block ) {
if ( ! empty( $block['innerBlocks'] ) ) {
$blocks[ $key ]['innerBlocks'] = gutenberg_remove_empty_navigation_links_recursive( $block['innerBlocks'] );
}
}
}
return $blocks;
}
/**
* Returns the top-level submenu SVG chevron icon.
*
* @return string
*/
function render_submenu_icon() {
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>';
}
/**
* Renders the `core/navigation` block on server.
*
* @param array $attributes The block attributes.
* @param array $content The saved content.
* @param array $block The parsed block.
*
* @return string Returns the post content with the legacy widget added.
*/
function render_block_navigation( $attributes, $content, $block ) {
function render_block_navigation( $content, $block ) {
if ( 'core/navigation' !== $block['blockName'] ) {
return $content;
}
$attributes = $block['attrs'];
$block['innerBlocks'] = gutenberg_remove_empty_navigation_links_recursive( $block['innerBlocks'] );
if ( empty( $block['innerBlocks'] ) ) {
return '';
}
$colors = build_css_colors( $attributes );
$font_sizes = build_css_font_sizes( $attributes );
$classes = array_merge(
@ -96,20 +159,22 @@ function render_block_navigation( $attributes, $content, $block ) {
'<nav %1$s %2$s>%3$s</nav>',
$class_attribute,
$style_attribute,
build_navigation_html( $block, $colors, $font_sizes )
build_navigation_html( $attributes, $block, $colors, $font_sizes, true )
);
}
/**
* Walks the inner block structure and returns an HTML list for it.
*
* @param array $block The block.
* @param array $attributes The Navigation block attributes.
* @param array $block The NavigationItem block.
* @param array $colors Contains inline styles and CSS classes to apply to navigation item.
* @param array $font_sizes Contains inline styles and CSS classes to apply to navigation item.
* @param bool $is_level_zero True whether is main menu (level zero). Otherwise, False.
*
* @return string Returns an HTML list from innerBlocks.
*/
function build_navigation_html( $block, $colors, $font_sizes ) {
function build_navigation_html( $attributes, $block, $colors, $font_sizes, $is_level_zero = true ) {
$html = '';
$classes = array_merge(
$colors['css_classes'],
@ -122,9 +187,14 @@ function build_navigation_html( $block, $colors, $font_sizes ) {
: '';
foreach ( (array) $block['innerBlocks'] as $key => $block ) {
$has_submenu = count( (array) $block['innerBlocks'] ) > 0;
$html .= '<li class="wp-block-navigation-link">' .
'<a' . $class_attribute . $style_attribute;
$html .= '<li class="wp-block-navigation-link' . ( $has_submenu ? ' has-submenu' : '' ) . '">' .
'<a';
if ( $is_level_zero ) {
$html .= $class_attribute . $style_attribute;
}
// Start appending HTML attributes to anchor tag.
if ( isset( $block['attrs']['url'] ) ) {
@ -140,15 +210,44 @@ function build_navigation_html( $block, $colors, $font_sizes ) {
// End appending HTML attributes to anchor tag.
// Start anchor tag content.
$html .= '>';
$html .= '>' .
// Wrap title with span to isolate it from submenu icon.
'<span class="wp-block-navigation-link__label">';
if ( isset( $block['attrs']['label'] ) ) {
$html .= esc_html( $block['attrs']['label'] );
$html .= wp_kses(
$block['attrs']['label'],
array(
'code' => array(),
'em' => array(),
'img' => array(
'scale' => array(),
'class' => array(),
'style' => array(),
'src' => array(),
'alt' => array(),
),
's' => array(),
'span' => array(
'style' => array(),
),
'strong' => array(),
)
);
}
$html .= '</span>';
// Append submenu icon to top-level item.
if ( ! empty( $attributes['showSubmenuIcon'] ) && $is_level_zero && $has_submenu ) {
$html .= '<span class="wp-block-navigation-link__submenu-icon">' . render_submenu_icon() . '</span>';
}
$html .= '</a>';
// End anchor tag content.
if ( count( (array) $block['innerBlocks'] ) > 0 ) {
$html .= build_navigation_html( $block, $colors, $font_sizes );
if ( $has_submenu ) {
$html .= build_navigation_html( $attributes, $block, $colors, $font_sizes, false );
}
$html .= '</li>';
@ -177,6 +276,12 @@ function register_block_core_navigation() {
'customTextColor' => array(
'type' => 'string',
),
'backgroundColor' => array(
'type' => 'string',
),
'customBackgroundColor' => array(
'type' => 'string',
),
'fontSize' => array(
'type' => 'string',
),
@ -186,10 +291,13 @@ function register_block_core_navigation() {
'itemsJustification' => array(
'type' => 'string',
),
'showSubmenuIcon' => array(
'type' => 'boolean',
'default' => false,
),
),
'render_callback' => 'render_block_navigation',
)
);
}
add_action( 'init', 'register_block_core_navigation' );
add_filter( 'render_block', 'render_block_navigation', 10, 2 );

View File

@ -20,10 +20,6 @@ function render_block_core_rss( $attributes ) {
}
if ( ! $rss->get_item_quantity() ) {
// PHP 5.2 compatibility. See: http://simplepie.org/wiki/faq/i_m_getting_memory_leaks.
$rss->__destruct();
unset( $rss );
return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</div></div>';
}
@ -96,13 +92,7 @@ function render_block_core_rss( $attributes ) {
$class .= ' ' . $attributes['className'];
}
$list_items_markup = "<ul class='{$class}'>{$list_items}</ul>";
// PHP 5.2 compatibility. See: http://simplepie.org/wiki/faq/i_m_getting_memory_leaks.
$rss->__destruct();
unset( $rss );
return $list_items_markup;
return "<ul class='{$class}'>{$list_items}</ul>";
}
/**

View File

@ -25,10 +25,16 @@ function render_block_core_search( $attributes ) {
$input_id,
$attributes['label']
);
} else {
$label_markup = sprintf(
'<label for="%s" class="wp-block-search__label screen-reader-text">%s</label>',
$input_id,
__( 'Search' )
);
}
$input_markup = sprintf(
'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" />',
'<input type="search" id="%s" class="wp-block-search__input" name="s" value="%s" placeholder="%s" required />',
$input_id,
esc_attr( get_search_query() ),
esc_attr( $attributes['placeholder'] )
@ -45,7 +51,6 @@ function render_block_core_search( $attributes ) {
if ( isset( $attributes['className'] ) ) {
$class .= ' ' . $attributes['className'];
}
if ( isset( $attributes['align'] ) ) {
$class .= ' align' . $attributes['align'];
}

View File

@ -21,17 +21,16 @@ function render_block_core_shortcode( $attributes, $content ) {
* Registers the `core/shortcode` block on server.
*/
function register_block_core_shortcode() {
$path = __DIR__ . '/shortcode/block.json';
$metadata = json_decode( file_get_contents( $path ), true );
register_block_type(
'core/shortcode',
$metadata['name'],
array_merge(
$metadata,
array(
'attributes' => array(
'text' => array(
'type' => 'string',
'source' => 'html',
),
),
'render_callback' => 'render_block_core_shortcode',
)
)
);
}
add_action( 'init', 'register_block_core_shortcode' );

View File

@ -0,0 +1,10 @@
{
"name": "core/shortcode",
"category": "widgets",
"attributes": {
"text": {
"type": "string",
"source": "html"
}
}
}

View File

@ -254,12 +254,14 @@ function wp_default_packages_scripts( &$scripts ) {
'html-entities',
'i18n',
'is-shallow-equal',
'keyboard-shortcuts',
'keycodes',
'list-reusable-blocks',
'media-utils',
'notices',
'nux',
'plugins',
'primitives',
'priority-queue',
'redux-routine',
'rich-text',
@ -268,6 +270,7 @@ function wp_default_packages_scripts( &$scripts ) {
'token-list',
'url',
'viewport',
'warning',
'wordcount',
);

View File

@ -126,7 +126,6 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
'/wp/v2/block-renderer/(?P<name>core/categories)',
'/wp/v2/block-renderer/(?P<name>core/latest-comments)',
'/wp/v2/block-renderer/(?P<name>core/latest-posts)',
'/wp/v2/block-renderer/(?P<name>core/navigation)',
'/wp/v2/block-renderer/(?P<name>core/rss)',
'/wp/v2/block-renderer/(?P<name>core/search)',
'/wp/v2/block-renderer/(?P<name>core/shortcode)',

View File

@ -4632,46 +4632,6 @@ mockedApiResponse.Schema = {
}
]
},
"/wp/v2/block-renderer/(?P<name>core/navigation)": {
"namespace": "wp/v2",
"methods": [
"GET"
],
"endpoints": [
{
"methods": [
"GET"
],
"args": {
"name": {
"required": false,
"description": "Unique registered name for the block.",
"type": "string"
},
"context": {
"required": false,
"default": "view",
"enum": [
"edit"
],
"description": "Scope under which the request is made; determines fields present in response.",
"type": "string"
},
"attributes": {
"required": false,
"default": [],
"description": "Attributes for core/navigation block",
"type": "object"
},
"post_id": {
"required": false,
"description": "ID of the post context.",
"type": "integer"
}
}
}
]
},
"/wp/v2/block-renderer/(?P<name>core/rss)": {
"namespace": "wp/v2",
"methods": [

View File

@ -63,8 +63,12 @@ module.exports = function( env = { environment: 'production', watch: false, buil
buildTarget = buildTarget + '/wp-includes';
const WORDPRESS_NAMESPACE = '@wordpress/';
const BUNDLED_PACKAGES = [ '@wordpress/icons' ];
const packages = Object.keys( dependencies )
.filter( ( packageName ) => packageName.startsWith( WORDPRESS_NAMESPACE ) )
.filter( ( packageName ) =>
! BUNDLED_PACKAGES.includes( packageName ) &&
packageName.startsWith( WORDPRESS_NAMESPACE )
)
.map( ( packageName ) => packageName.replace( WORDPRESS_NAMESPACE, '' ) );
const vendors = {