Block Editor: Include the fixes targetted for WordPress 5.8 RC3.

This includes the following fixes:
 - Safari: see if compositing layer size is more reasonable when position fixed divs are not inserted into content.
 - Site Logo Block: update Site Logo block UI and option syncing.
 - Fix moving inner blocks in the Widgets Customizer.
 - Allow themes to provide empty values for color.duotone and spacing.units
 - Update getTermsInfo() to workaround parsing issue for translatable strings.
 - Specify what settings can be part of settings.layout.
 - Update conditions to hide duotone panel.
 - Prevent entering invalid values in the Query Loop block config.
 - Prevent color panel from showing as empty.
 - Avoid calling gutenberg_ functions within code shipped through WordPress Core.

Props desrosj.
See #53397.


git-svn-id: https://develop.svn.wordpress.org/trunk@51421 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Riad Benguella 2021-07-13 16:39:05 +00:00
parent 013b0c11f0
commit bed9d00fbd
12 changed files with 359 additions and 429 deletions

544
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -82,52 +82,52 @@
"@wordpress/api-fetch": "5.1.1",
"@wordpress/autop": "3.1.1",
"@wordpress/blob": "3.1.1",
"@wordpress/block-directory": "2.1.16",
"@wordpress/block-editor": "6.1.9",
"@wordpress/block-library": "3.2.14",
"@wordpress/block-directory": "2.1.17",
"@wordpress/block-editor": "6.1.10",
"@wordpress/block-library": "3.2.15",
"@wordpress/block-serialization-default-parser": "4.1.1",
"@wordpress/blocks": "9.1.5",
"@wordpress/components": "14.1.6",
"@wordpress/components": "14.1.7",
"@wordpress/compose": "4.1.3",
"@wordpress/core-data": "3.1.9",
"@wordpress/customize-widgets": "1.0.15",
"@wordpress/customize-widgets": "1.0.16",
"@wordpress/data": "5.1.3",
"@wordpress/data-controls": "2.1.3",
"@wordpress/date": "4.1.1",
"@wordpress/deprecated": "3.1.1",
"@wordpress/dom": "3.1.2",
"@wordpress/dom-ready": "3.1.1",
"@wordpress/edit-post": "4.1.16",
"@wordpress/edit-widgets": "2.1.16",
"@wordpress/editor": "10.1.12",
"@wordpress/edit-post": "4.1.17",
"@wordpress/edit-widgets": "2.1.17",
"@wordpress/editor": "10.1.13",
"@wordpress/element": "3.1.1",
"@wordpress/escape-html": "2.1.1",
"@wordpress/format-library": "2.1.9",
"@wordpress/format-library": "2.1.10",
"@wordpress/hooks": "3.1.1",
"@wordpress/html-entities": "3.1.1",
"@wordpress/i18n": "4.1.1",
"@wordpress/icons": "4.0.2",
"@wordpress/interface": "3.1.7",
"@wordpress/interface": "3.1.8",
"@wordpress/is-shallow-equal": "4.1.1",
"@wordpress/keyboard-shortcuts": "2.1.3",
"@wordpress/keycodes": "3.1.1",
"@wordpress/list-reusable-blocks": "2.1.6",
"@wordpress/list-reusable-blocks": "2.1.7",
"@wordpress/media-utils": "2.1.1",
"@wordpress/notices": "3.1.3",
"@wordpress/nux": "4.1.6",
"@wordpress/nux": "4.1.7",
"@wordpress/plugins": "3.1.3",
"@wordpress/primitives": "2.1.1",
"@wordpress/priority-queue": "2.1.1",
"@wordpress/redux-routine": "4.1.1",
"@wordpress/reusable-blocks": "2.1.12",
"@wordpress/reusable-blocks": "2.1.13",
"@wordpress/rich-text": "4.1.3",
"@wordpress/server-side-render": "2.1.7",
"@wordpress/server-side-render": "2.1.8",
"@wordpress/shortcode": "3.1.1",
"@wordpress/token-list": "2.1.1",
"@wordpress/url": "3.1.1",
"@wordpress/viewport": "3.1.3",
"@wordpress/warning": "2.1.1",
"@wordpress/widgets": "1.1.14",
"@wordpress/widgets": "1.1.15",
"@wordpress/wordcount": "3.1.1",
"backbone": "1.4.0",
"clipboard": "2.0.8",

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,13 @@ function render_block_core_legacy_widget( $attributes ) {
$widget_key = $wp_widget_factory->get_widget_key( $id_base );
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
} else {
/*
* This file is copied from the published @wordpress/widgets package when WordPress
* Core is built. Because the package is a dependency of both WordPress Core and the
* Gutenberg plugin where the block editor is developed, this fallback condition is
* required until the minimum required version of WordPress for the plugin is raised
* to 5.8.
*/
$widget_key = gutenberg_get_widget_key( $id_base );
$widget_object = gutenberg_get_widget_object( $id_base );
}

View File

@ -86,63 +86,3 @@ function register_block_core_post_template() {
);
}
add_action( 'init', 'register_block_core_post_template' );
/**
* Renders the legacy `core/query-loop` block on the server.
* It triggers a developer warning and then calls the renamed
* block's `render_callback` function output.
*
* This can be removed when WordPress 5.9 is released.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
*
* @return string Returns the output of the query, structured using the layout defined by the block's inner blocks.
*/
function render_legacy_query_loop_block( $attributes, $content, $block ) {
trigger_error(
/* translators: %1$s: Block type */
sprintf( __( 'Block %1$s has been renamed to Post Template. %1$s will be supported until WordPress version 5.9.' ), $block->name ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
return render_block_core_post_template( $attributes, $content, $block );
}
/**
* Complements the renaming of `Query Loop` to `Post Template`.
* This ensures backwards compatibility for any users running the Gutenberg
* plugin who have used Query Loop prior to its renaming.
*
* This can be removed when WordPress 5.9 is released.
*
* @see https://github.com/WordPress/gutenberg/pull/32514
*/
function gutenberg_register_legacy_query_loop_block() {
$registry = WP_Block_Type_Registry::get_instance();
if ( $registry->is_registered( 'core/query-loop' ) ) {
unregister_block_type( 'core/query-loop' );
}
register_block_type(
'core/query-loop',
array(
'category' => 'design',
'uses_context' => array(
'queryId',
'query',
'queryContext',
'displayLayout',
'templateSlug',
),
'supports' => array(
'reusable' => false,
'html' => false,
'align' => true,
),
'style' => 'wp-block-post-template',
'render_callback' => 'render_legacy_query_loop_block',
'skip_inner_blocks' => true,
)
);
}
add_action( 'init', 'gutenberg_register_legacy_query_loop_block' );

View File

@ -14,7 +14,7 @@
*/
function render_block_core_site_logo( $attributes ) {
$adjust_width_height_filter = function ( $image ) use ( $attributes ) {
if ( empty( $attributes['width'] ) ) {
if ( empty( $attributes['width'] ) || empty( $image ) ) {
return $image;
}
$height = (float) $attributes['width'] / ( (float) $image[1] / (float) $image[2] );
@ -111,54 +111,52 @@ add_filter( 'theme_mod_custom_logo', '_override_custom_logo_theme_mod' );
/**
* Updates the site_logo option when the custom_logo theme-mod gets updated.
*
* This function is hooked on "update_option_theme_mods_$theme" and not
* "pre_set_theme_mod_custom_logo" because by hooking in `update_option`
* the function accounts for remove_theme_mod() as well.
*
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
* @param mixed $value Attachment ID of the custom logo or an empty value.
* @return mixed
*/
function _sync_custom_logo_to_site_logo( $old_value, $value ) {
// Delete the option when the custom logo does not exist or was removed.
// This step ensures the option stays in sync.
if ( empty( $value['custom_logo'] ) ) {
function _sync_custom_logo_to_site_logo( $value ) {
if ( empty( $value ) ) {
delete_option( 'site_logo' );
} else {
remove_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo' );
update_option( 'site_logo', $value['custom_logo'] );
add_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo', 10, 2 );
update_option( 'site_logo', $value );
}
return $value;
}
add_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' );
/**
* Deletes the site_logo when the custom_logo theme mod is removed.
*
* @param array $old_value Previous theme mod settings.
* @param array $value Updated theme mod settings.
*/
function _delete_site_logo_on_remove_custom_logo( $old_value, $value ) {
// If the custom_logo is being unset, it's being removed from theme mods.
if ( isset( $old_value['custom_logo'] ) && ! isset( $value['custom_logo'] ) ) {
delete_option( 'site_logo' );
}
}
/**
* Hooks `_sync_custom_logo_to_site_logo` in `update_option_theme_mods_$theme`.
* Deletes the site logo when all theme mods are being removed.
*/
function _delete_site_logo_on_remove_theme_mods() {
if ( false !== get_theme_support( 'custom-logo' ) ) {
delete_option( 'site_logo' );
}
}
/**
* Hooks `_delete_site_logo_on_remove_custom_logo` in `update_option_theme_mods_$theme`.
* Hooks `_delete_site_logo_on_remove_theme_mods` in `delete_option_theme_mods_$theme`.
*
* Runs on `setup_theme` to account for dynamically-switched themes in the Customizer.
*/
function _sync_custom_logo_to_site_logo_on_setup_theme() {
function _delete_site_logo_on_remove_custom_logo_on_setup_theme() {
$theme = get_option( 'stylesheet' );
add_action( "update_option_theme_mods_$theme", '_sync_custom_logo_to_site_logo', 10, 2 );
add_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10, 2 );
add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' );
}
add_action( 'setup_theme', '_sync_custom_logo_to_site_logo_on_setup_theme', 11 );
/**
* Updates the custom_logo theme-mod when the site_logo option gets updated.
*
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
*
* @return void
*/
function _sync_site_logo_to_custom_logo( $old_value, $value ) {
// Delete the option when the custom logo does not exist or was removed.
// This step ensures the option stays in sync.
if ( empty( $value ) ) {
remove_theme_mod( 'custom_logo' );
} else {
remove_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' );
set_theme_mod( 'custom_logo', $value );
add_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' );
}
}
add_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo', 10, 2 );
add_action( 'setup_theme', '_delete_site_logo_on_remove_custom_logo_on_setup_theme', 11 );

View File

@ -100,14 +100,17 @@
max-width: 100%;
}
.wp-block-site-logo .components-placeholder {
justify-content: flex-start;
min-height: auto;
height: 120px;
padding: 8px;
padding: 12px;
}
.wp-block-site-logo .components-placeholder .components-placeholder__label {
margin-top: 12px;
white-space: nowrap;
}
.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon {
.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon,
.wp-block-site-logo .components-placeholder .components-placeholder__label > svg {
margin-left: 4px;
}
.wp-block-site-logo .components-placeholder .components-form-file-upload {
@ -126,23 +129,4 @@
}
.wp-block-site-logo .components-placeholder .components-drop-zone__content-text {
display: none;
}
.editor-styles-wrapper .site-logo_placeholder {
display: flex;
flex-direction: row;
align-items: flex-start;
border-radius: 2px;
background-color: #fff;
box-shadow: inset 0 0 0 1px #1e1e1e;
padding: 12px;
}
.editor-styles-wrapper .site-logo_placeholder svg {
margin-left: 12px;
}
.editor-styles-wrapper .site-logo_placeholder p {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 13px;
margin: 0;
line-height: initial;
}

View File

@ -1 +1 @@
.wp-block[data-align=center]>.wp-block-site-logo{margin-right:auto;margin-left:auto;text-align:center}.wp-block-site-logo a{pointer-events:none}.wp-block-site-logo:not(.is-default-size){display:table}.wp-block-site-logo.is-default-size{width:120px}.wp-block-site-logo.is-default-size img{width:100%}.wp-block-site-logo .custom-logo-link{cursor:inherit}.wp-block-site-logo .custom-logo-link:focus{box-shadow:none}.wp-block-site-logo .custom-logo-link.is-transient img{opacity:.3}.wp-block-site-logo img{display:block;max-width:100%}.wp-block-site-logo .components-placeholder{min-height:auto;height:120px;padding:8px}.wp-block-site-logo .components-placeholder .components-placeholder__label{white-space:nowrap}.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon{margin-left:4px}.wp-block-site-logo .components-placeholder .components-form-file-upload{display:none}.wp-block-site-logo .components-placeholder .components-placeholder__preview{position:absolute;top:4px;left:4px;bottom:4px;right:4px;background:hsla(0,0%,100%,.8);display:flex;align-items:center;justify-content:center}.wp-block-site-logo .components-placeholder .components-drop-zone__content-text{display:none}.editor-styles-wrapper .site-logo_placeholder{display:flex;flex-direction:row;align-items:flex-start;border-radius:2px;background-color:#fff;box-shadow:inset 0 0 0 1px #1e1e1e;padding:12px}.editor-styles-wrapper .site-logo_placeholder svg{margin-left:12px}.editor-styles-wrapper .site-logo_placeholder p{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px;margin:0;line-height:normal}
.wp-block[data-align=center]>.wp-block-site-logo{margin-right:auto;margin-left:auto;text-align:center}.wp-block-site-logo a{pointer-events:none}.wp-block-site-logo:not(.is-default-size){display:table}.wp-block-site-logo.is-default-size{width:120px}.wp-block-site-logo.is-default-size img{width:100%}.wp-block-site-logo .custom-logo-link{cursor:inherit}.wp-block-site-logo .custom-logo-link:focus{box-shadow:none}.wp-block-site-logo .custom-logo-link.is-transient img{opacity:.3}.wp-block-site-logo img{display:block;max-width:100%}.wp-block-site-logo .components-placeholder{justify-content:flex-start;min-height:auto;height:120px;padding:12px}.wp-block-site-logo .components-placeholder .components-placeholder__label{margin-top:12px;white-space:nowrap}.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon,.wp-block-site-logo .components-placeholder .components-placeholder__label>svg{margin-left:4px}.wp-block-site-logo .components-placeholder .components-form-file-upload{display:none}.wp-block-site-logo .components-placeholder .components-placeholder__preview{position:absolute;top:4px;left:4px;bottom:4px;right:4px;background:hsla(0,0%,100%,.8);display:flex;align-items:center;justify-content:center}.wp-block-site-logo .components-placeholder .components-drop-zone__content-text{display:none}

View File

@ -100,14 +100,17 @@
max-width: 100%;
}
.wp-block-site-logo .components-placeholder {
justify-content: flex-start;
min-height: auto;
height: 120px;
padding: 8px;
padding: 12px;
}
.wp-block-site-logo .components-placeholder .components-placeholder__label {
margin-top: 12px;
white-space: nowrap;
}
.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon {
.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon,
.wp-block-site-logo .components-placeholder .components-placeholder__label > svg {
margin-right: 4px;
}
.wp-block-site-logo .components-placeholder .components-form-file-upload {
@ -126,23 +129,4 @@
}
.wp-block-site-logo .components-placeholder .components-drop-zone__content-text {
display: none;
}
.editor-styles-wrapper .site-logo_placeholder {
display: flex;
flex-direction: row;
align-items: flex-start;
border-radius: 2px;
background-color: #fff;
box-shadow: inset 0 0 0 1px #1e1e1e;
padding: 12px;
}
.editor-styles-wrapper .site-logo_placeholder svg {
margin-right: 12px;
}
.editor-styles-wrapper .site-logo_placeholder p {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
font-size: 13px;
margin: 0;
line-height: initial;
}

View File

@ -1 +1 @@
.wp-block[data-align=center]>.wp-block-site-logo{margin-left:auto;margin-right:auto;text-align:center}.wp-block-site-logo a{pointer-events:none}.wp-block-site-logo:not(.is-default-size){display:table}.wp-block-site-logo.is-default-size{width:120px}.wp-block-site-logo.is-default-size img{width:100%}.wp-block-site-logo .custom-logo-link{cursor:inherit}.wp-block-site-logo .custom-logo-link:focus{box-shadow:none}.wp-block-site-logo .custom-logo-link.is-transient img{opacity:.3}.wp-block-site-logo img{display:block;max-width:100%}.wp-block-site-logo .components-placeholder{min-height:auto;height:120px;padding:8px}.wp-block-site-logo .components-placeholder .components-placeholder__label{white-space:nowrap}.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon{margin-right:4px}.wp-block-site-logo .components-placeholder .components-form-file-upload{display:none}.wp-block-site-logo .components-placeholder .components-placeholder__preview{position:absolute;top:4px;right:4px;bottom:4px;left:4px;background:hsla(0,0%,100%,.8);display:flex;align-items:center;justify-content:center}.wp-block-site-logo .components-placeholder .components-drop-zone__content-text{display:none}.editor-styles-wrapper .site-logo_placeholder{display:flex;flex-direction:row;align-items:flex-start;border-radius:2px;background-color:#fff;box-shadow:inset 0 0 0 1px #1e1e1e;padding:12px}.editor-styles-wrapper .site-logo_placeholder svg{margin-right:12px}.editor-styles-wrapper .site-logo_placeholder p{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px;margin:0;line-height:normal}
.wp-block[data-align=center]>.wp-block-site-logo{margin-left:auto;margin-right:auto;text-align:center}.wp-block-site-logo a{pointer-events:none}.wp-block-site-logo:not(.is-default-size){display:table}.wp-block-site-logo.is-default-size{width:120px}.wp-block-site-logo.is-default-size img{width:100%}.wp-block-site-logo .custom-logo-link{cursor:inherit}.wp-block-site-logo .custom-logo-link:focus{box-shadow:none}.wp-block-site-logo .custom-logo-link.is-transient img{opacity:.3}.wp-block-site-logo img{display:block;max-width:100%}.wp-block-site-logo .components-placeholder{justify-content:flex-start;min-height:auto;height:120px;padding:12px}.wp-block-site-logo .components-placeholder .components-placeholder__label{margin-top:12px;white-space:nowrap}.wp-block-site-logo .components-placeholder .components-placeholder__label .block-editor-block-icon,.wp-block-site-logo .components-placeholder .components-placeholder__label>svg{margin-right:4px}.wp-block-site-logo .components-placeholder .components-form-file-upload{display:none}.wp-block-site-logo .components-placeholder .components-placeholder__preview{position:absolute;top:4px;right:4px;bottom:4px;left:4px;background:hsla(0,0%,100%,.8);display:flex;align-items:center;justify-content:center}.wp-block-site-logo .components-placeholder .components-drop-zone__content-text{display:none}

View File

@ -181,6 +181,7 @@ class WP_Theme_JSON {
const ALLOWED_SETTINGS = array(
'color' => array(
'custom' => null,
'customDuotone' => null,
'customGradient' => null,
'duotone' => null,
'gradients' => null,
@ -188,7 +189,10 @@ class WP_Theme_JSON {
'palette' => null,
),
'custom' => null,
'layout' => null,
'layout' => array(
'contentSize' => null,
'wideSize' => null,
),
'spacing' => array(
'customMargin' => null,
'customPadding' => null,

View File

@ -3,7 +3,9 @@
"settings": {
"color": {
"custom": true,
"customGradient": true,
"customDuotone": true,
"customGradient": true,
"link": false,
"duotone": [
{
"name": "Dark grayscale" ,
@ -108,7 +110,6 @@
"slug": "midnight"
}
],
"link": false,
"palette": [
{
"name": "Black",