Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second batch of backports for WP 5.8 beta 1 #32484

Merged
merged 25 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
442a9c7
Link to widgets.php instead of themes.php?page=gutenberg-widgets (#32…
noisysocks May 31, 2021
9afce78
Fix legacy widget block preview iframe in plugin (#32300)
noisysocks Jun 1, 2021
9efe447
Generate classes from preset slugs in the same way (server & client) …
nosolosw Jun 1, 2021
bde39f7
Widgets editor: Fix error when saving empty Legacy Widget block (#32359)
noisysocks Jun 1, 2021
cde3a5a
Update the appearance of the template details popover (#32042)
jameskoster Jun 1, 2021
29c3626
Fix deselecting block when inspector is opened (#32361)
kevin940726 Jun 2, 2021
4af1b88
Display wide widgets as popovers in Customizer (#31736)
tellthemachines Jun 2, 2021
7bb8d1d
Prevent saving the post before previewing in locked/read-only mode. (…
desaiuditd Jun 2, 2021
e4e4a62
Fix allowed patterns check (#32376)
youknowriad Jun 2, 2021
1029bcb
SuggestionsList: Try to use a unique "key" (#32344)
Mamaduka Jun 2, 2021
0b4b117
Buttons: move options to constants to avoid unneeded renders (#32356)
gwwar Jun 1, 2021
14d4ba6
Try: Fix notices below block toolbars. (#32238)
jasmussen Jun 2, 2021
ab6be5d
Allow non-latin characters in slugs (#32232)
aristath Jun 2, 2021
4bbea09
Experimental Layout: pass the same object when no data changes (#32380)
gwwar Jun 2, 2021
bbc0041
Fixed random collapse of the color settings section (#32388)
thisissandip Jun 3, 2021
b9d9d71
Fix the layout definition in the template mode (#32425)
youknowriad Jun 3, 2021
ebfe9f7
Group typographic block supports under a `typography` key (#32252)
jorgefilipecosta Jun 2, 2021
fcf8da8
Fix site-logo not getting removed on remove_theme_mod (#32370)
aristath Jun 4, 2021
7fbf2b4
Make syntax errors in `theme.json` visible to users (#32404)
nosolosw Jun 4, 2021
3ada871
Update: Skip typography serialization (#32444)
jorgefilipecosta Jun 4, 2021
b978190
Fix alligned blocks (#32454)
youknowriad Jun 7, 2021
09339db
Letter spacing should also respect skip serialization flag (#32459)
nosolosw Jun 4, 2021
61ce1f4
Fix block toolbar overlap with header (#32424)
Mamaduka Jun 3, 2021
476b88f
Fixed loss of list content when switching list types. (#32432)
torounit Jun 7, 2021
9117c0c
Avoid keeping the same client ID when transforming blocks (#32453)
youknowriad Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 42 additions & 42 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ function gutenberg_register_typography_support( $block_type ) {
return;
}

$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );

$has_typography_support = $has_font_size_support
|| $has_font_weight_support
$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
if ( ! $typography_supports ) {
return;
}

$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

$has_typography_support = $has_font_family_support
|| $has_font_size_support
|| $has_font_style_support
|| $has_font_weight_support
|| $has_line_height_support
|| $has_text_transform_support
|| $has_text_decoration_support;
|| $has_text_decoration_support
|| $has_text_transform_support;

if ( ! $block_type->attributes ) {
$block_type->attributes = array();
Expand Down Expand Up @@ -61,40 +68,41 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
return array();
}

$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
if ( ! $typography_supports ) {
return array();
}

$skip_typography_serialization = _wp_array_get( $typography_supports, array( '__experimentalSkipSerialization' ), false );
if ( $skip_typography_serialization ) {
return array();
}

$attributes = array();
$classes = array();
$styles = array();

$has_font_family_support = _wp_array_get( $block_type->supports, array( '__experimentalFontFamily' ), false );
$has_font_style_support = _wp_array_get( $block_type->supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $block_type->supports, array( '__experimentalFontWeight' ), false );
$has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
$has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $block_type->supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $block_type->supports, array( '__experimentalTextTransform' ), false );

$skip_font_size_support_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipFontSizeSerialization' ), false );

// Covers all typography features _except_ font size.
$skip_typography_serialization = _wp_array_get( $block_type->supports, array( '__experimentalSkipTypographySerialization' ), false );
$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );

// Font Size.
if ( $has_font_size_support && ! $skip_font_size_support_serialization ) {
if ( $has_font_size_support ) {
$has_named_font_size = array_key_exists( 'fontSize', $block_attributes );
$has_custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] );

// Apply required class or style.
if ( $has_named_font_size ) {
$classes[] = sprintf( 'has-%s-font-size', $block_attributes['fontSize'] );
} elseif ( $has_custom_font_size ) {
$styles[] = sprintf( 'font-size: %s;', $block_attributes['style']['typography']['fontSize'] );
}
}

// Font Family.
if ( $has_font_family_support && ! $skip_typography_serialization ) {
if ( $has_font_family_support ) {
$has_font_family = isset( $block_attributes['style']['typography']['fontFamily'] );
// Apply required class and style.
if ( $has_font_family ) {
$font_family = $block_attributes['style']['typography']['fontFamily'];
if ( strpos( $font_family, 'var:preset|font-family' ) !== false ) {
Expand All @@ -108,43 +116,35 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
}
}

// Font style.
if ( $has_font_style_support && ! $skip_typography_serialization ) {
// Apply font style.
if ( $has_font_style_support ) {
$font_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontStyle', 'font-style' );
if ( $font_style ) {
$styles[] = $font_style;
}
}

// Font weight.
if ( $has_font_weight_support && ! $skip_typography_serialization ) {
// Apply font weight.
if ( $has_font_weight_support ) {
$font_weight = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'fontWeight', 'font-weight' );
if ( $font_weight ) {
$styles[] = $font_weight;
}
}

// Line Height.
if ( $has_line_height_support && ! $skip_typography_serialization ) {
if ( $has_line_height_support ) {
$has_line_height = isset( $block_attributes['style']['typography']['lineHeight'] );
// Add the style (no classes for line-height).
if ( $has_line_height ) {
$styles[] = sprintf( 'line-height: %s;', $block_attributes['style']['typography']['lineHeight'] );
}
}

// Text Decoration.
if ( $has_text_decoration_support && ! $skip_typography_serialization ) {
if ( $has_text_decoration_support ) {
$text_decoration_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textDecoration', 'text-decoration' );
if ( $text_decoration_style ) {
$styles[] = $text_decoration_style;
}
}

// Text Transform.
if ( $has_text_transform_support && ! $skip_typography_serialization ) {
if ( $has_text_transform_support ) {
$text_transform_style = gutenberg_typography_get_css_variable_inline_style( $block_attributes, 'textTransform', 'text-transform' );
if ( $text_transform_style ) {
$styles[] = $text_transform_style;
Expand Down
56 changes: 56 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
* @package gutenberg
*/

/*
* Fixes the priority of register_block_core_legacy_widget().
*
* This hook was incorrectly added to Core with priority 20. #32300 fixes this
* but causes block registration warnings in the Gutenberg plugin until the
* changes are made in Core.
*
* This temporary fix can be removed after the changes to
* @wordpress/block-library in #32300 have been published to npm and updated in
* Core.
*
* See https://github.com/WordPress/gutenberg/pull/32300.
*/
if ( 20 === has_action( 'init', 'register_block_core_legacy_widget' ) ) {
remove_action( 'init', 'register_block_core_legacy_widget', 20 );
add_action( 'init', 'register_block_core_legacy_widget', 10 );
}

/**
* Substitutes the implementation of a core-registered block type, if exists,
* with the built result from the plugin.
Expand Down Expand Up @@ -412,3 +430,41 @@ function gutenberg_block_has_support( $block_type, $feature, $default = false )

return true === $block_support || is_array( $block_support );
}

/**
* Updates the shape of supports for declaring fontSize and lineHeight.
*
* @param array $metadata Metadata for registering a block type.
* @return array Metadata for registering a block type with the supports shape updated.
*/
function gutenberg_migrate_old_typography_shape( $metadata ) {
// Temporarily disable migrations from core blocks until core block.json are updated.
if ( isset( $metadata['supports'] ) && false === strpos( $metadata['file'], '/wp-includes/blocks/' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After core json files are updared we should remove this check && false === strpos( $metadata['file'], '/wp-includes/blocks/'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorgefilipecosta mind doing a follow-up commit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm, was perhaps something wrong with the merging? I remember having removed that check and actually the function had a different name wp_migrate_old_typography_sahpe youknowriad/wordpress-develop@4fb3e5a#diff-8c99af92e4ec0fdb307ddd9b42be1e1ef1efe4a9f31287c23f346244dddd1ce9R959

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, this is the gutenberg repo 😅 So many places to check that I was confused for a moment.

$typography_keys = array(
'__experimentalFontFamily',
'__experimentalFontStyle',
'__experimentalFontWeight',
'__experimentalLetterSpacing',
'__experimentalTextDecoration',
'__experimentalTextTransform',
'fontSize',
'lineHeight',
);
foreach ( $typography_keys as $typography_key ) {
$support_for_key = _wp_array_get( $metadata['supports'], array( $typography_key ), null );
if ( null !== $support_for_key ) {
trigger_error(
/* translators: %1$s: Block type, %2$s: typography supports key e.g: fontSize, lineHeight etc... */
sprintf( __( 'Block %1$s is declaring %2$s support on block.json under supports.%2$s. %2$s support is now declared under supports.typography.%2$s.', 'gutenberg' ), $metadata['name'], $typography_key ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
gutenberg_experimental_set( $metadata['supports'], array( 'typography', $typography_key ), $support_for_key );
unset( $metadata['supports'][ $typography_key ] );
}
}
}
return $metadata;
}


add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );
6 changes: 5 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,11 @@ private static function compute_preset_classes( $settings, $selector ) {
foreach ( $values as $value ) {
foreach ( $preset['classes'] as $class ) {
$stylesheet .= self::to_ruleset(
self::append_to_selector( $selector, '.has-' . $value['slug'] . '-' . $class['class_suffix'] ),
// We don't want to use kebabCase here,
// see https://github.com/WordPress/gutenberg/issues/32347
// However, we need to make sure the generated class
// doesn't contain spaces.
self::append_to_selector( $selector, '.has-' . preg_replace( '/\s+/', '-', $value['slug'] ) . '-' . $class['class_suffix'] ),
array(
array(
'name' => $class['property_name'],
Expand Down
4 changes: 2 additions & 2 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static function read_json_file( $file_path ) {

$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
error_log( 'Error when decoding file schema: ' . json_last_error_msg() );
trigger_error( "Error when decoding a theme.json schema at path $file_path " . json_last_error_msg() );
return $config;
}

Expand Down Expand Up @@ -367,7 +367,7 @@ public static function get_user_data() {

$json_decoding_error = json_last_error();
if ( JSON_ERROR_NONE !== $json_decoding_error ) {
error_log( 'Error when decoding user schema: ' . json_last_error_msg() );
trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() );
return new WP_Theme_JSON_Gutenberg( $config );
}

Expand Down
16 changes: 13 additions & 3 deletions lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function gutenberg_menu() {
'gutenberg'
);

if ( gutenberg_use_widgets_block_editor() ) {
if (
gutenberg_use_widgets_block_editor() &&
! function_exists( 'wp_use_widgets_block_editor' )
) {
add_theme_page(
__( 'Widgets', 'gutenberg' ),
__( 'Widgets', 'gutenberg' ),
Expand Down Expand Up @@ -113,7 +116,11 @@ function gutenberg_site_editor_menu() {
* @param WP_Admin_Bar $wp_admin_bar Core class used to implement the Toolbar API.
*/
function modify_admin_bar( $wp_admin_bar ) {
if ( gutenberg_use_widgets_block_editor() && $wp_admin_bar->get_node( 'widgets' ) !== null ) {
if (
gutenberg_use_widgets_block_editor() &&
! function_exists( 'wp_use_widgets_block_editor' ) &&
$wp_admin_bar->get_node( 'widgets' ) !== null
) {
$wp_admin_bar->add_menu(
array(
'id' => 'widgets',
Expand All @@ -137,7 +144,10 @@ function modify_welcome_panel() {
ob_start();
wp_welcome_panel();
$welcome_panel = ob_get_clean();
if ( gutenberg_use_widgets_block_editor() ) {
if (
gutenberg_use_widgets_block_editor() &&
! function_exists( 'wp_use_widgets_block_editor' )
) {
echo str_replace(
admin_url( 'widgets.php' ),
admin_url( 'themes.php?page=gutenberg-widgets' ),
Expand Down
4 changes: 0 additions & 4 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ $z-layers: (
// Show the FSE template previews above the editor and any open block toolbars
".edit-site-navigation-panel__preview": 32,

// Show notices below expanded editor bar
// .edit-post-header { z-index: 30 }
".components-notice-list": 29,

// Above the block list and the header.
".block-editor-block-list__block-popover": 31,

Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ _Parameters_

_Returns_

- `string`: String with the class corresponding to the fontSize passed. The class is generated by appending 'has-' followed by fontSizeSlug in kebabCase and ending with '-font-size'.
- `string`: String with the class corresponding to the fontSize passed. The class is generated by appending 'has-' followed by fontSizeSlug and ending with '-font-size'.

<a name="getFontSizeObjectByValue" href="#getFontSizeObjectByValue">#</a> **getFontSizeObjectByValue**

Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function BlockListBlock( {
clientId,
className,
wrapperProps: omit( wrapperProps, [ 'data-align' ] ),
isAligned,
};
const memoizedValue = useMemo( () => value, Object.values( value ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const BLOCK_ANIMATION_THRESHOLD = 200;
* @return {Object} Props to pass to the element to mark as a block.
*/
export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
const { clientId, className, wrapperProps = {} } = useContext(
const { clientId, className, wrapperProps = {}, isAligned } = useContext(
BlockListBlockContext
);
const {
Expand Down Expand Up @@ -141,7 +141,9 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
'data-title': blockTitle,
className: classnames(
// The wp-block className is important for editor styles.
'wp-block block-editor-block-list__block',
classnames( 'block-editor-block-list__block', {
'wp-block': ! isAligned,
} ),
className,
props.className,
wrapperProps.className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@ function usePatternsSetup( clientId, blockName, filterPatternsFn ) {
const {
getBlockRootClientId,
__experimentalGetPatternsByBlockTypes,
__experimentalGetParsedPattern,
__experimentalGetAllowedPatterns,
} = select( blockEditorStore );
const rootClientId = getBlockRootClientId( clientId );
let patterns = [];
if ( filterPatternsFn ) {
patterns = __experimentalGetAllowedPatterns(
rootClientId
).filter( filterPatternsFn );
} else {
patterns = __experimentalGetPatternsByBlockTypes(
blockName,
rootClientId
return __experimentalGetAllowedPatterns( rootClientId ).filter(
filterPatternsFn
);
}
return patterns.map( ( { name } ) =>
__experimentalGetParsedPattern( name )
return __experimentalGetPatternsByBlockTypes(
blockName,
rootClientId
);
},
[ clientId, blockName, filterPatternsFn ]
Expand Down
Loading