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

Backport Beta 4 fixes to WordPress Core. #32956

Merged
merged 26 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b7e51e7
Add optional chaining to prevent exception if activeFormats not defin…
glendaviesnz Jun 21, 2021
7307227
Block Library: Ensure there is no direct import from core/editor stor…
gziolo Jun 22, 2021
1ae85c0
Testing: Fix failing PHPUnit test caused by changes in WP core (#32888)
gziolo Jun 22, 2021
93f6563
Fix a regression where `custom-units` are forced as an array. (#32898)
desrosj Jun 23, 2021
ec414b1
TemplatePanel: Fixed a problem that when a new template is created, t…
torounit Jun 22, 2021
abdd11e
Fix collapsing appender when paragraph disabled. (#32894)
jasmussen Jun 23, 2021
e42aaef
Query Loop Patterns: Use plain `div` for wrapper element (#32867)
ryelle Jun 23, 2021
7d83e7c
Don't display admin notices on widgets screen. (#32877)
tellthemachines Jun 23, 2021
b7ccbbf
Fix scroll jitter in Customize Widgets (#32479)
stokesman Jun 24, 2021
6c81984
Fix legacy widget edit style bleed (#32871)
tellthemachines Jun 24, 2021
06d889b
Stretch Widgets editor layout to full height (#32905)
tellthemachines Jun 24, 2021
5a9b396
Image Block: Correctly set image size slug (#32364)
Mamaduka Jun 24, 2021
c3f3fed
Avoid flash of background color by moving gray background color to el…
gwwar Jun 23, 2021
942fe13
Disable "FSE" blocks in Widgets Editor (#32761)
getdave Jun 24, 2021
437ca8e
Fix broken the post-template-editor test. (#32904)
torounit Jun 23, 2021
3ede3a2
Block Library: Unify handling for block view scripts (#32814)
gziolo Jun 23, 2021
c16b1d7
Update webpack.config.js
youknowriad Jun 24, 2021
789c167
Global Styles: Allow custom properties to merge (#31840)
scruffian Jun 24, 2021
187ed1c
Update lib/blocks.php
youknowriad Jun 24, 2021
a47f4e5
Update packages/e2e-tests/specs/experiments/blocks/navigation.test.js
youknowriad Jun 24, 2021
fe467b5
Update packages/e2e-tests/specs/experiments/blocks/navigation.test.js
youknowriad Jun 24, 2021
3b32539
Update packages/e2e-tests/specs/experiments/blocks/navigation.test.js
youknowriad Jun 24, 2021
b9ffaeb
Update packages/e2e-tests/specs/experiments/blocks/navigation.test.js
youknowriad Jun 24, 2021
7ab23e3
Fix linting issues
youknowriad Jun 24, 2021
a7312c5
[E2E Tests]: Fix WP editor metabox test (#32915)
Mamaduka Jun 23, 2021
3ffeb4f
Disable Android e2e tests while we investigate foundational breakage …
dcalhoun Jun 23, 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
3 changes: 3 additions & 0 deletions .github/workflows/rnmobile-android-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ concurrency:
jobs:
test:
runs-on: macos-latest
# The false value below disables the test while we investigate a
# foundational error causing failures
if: ${{ false }}
strategy:
matrix:
native-test-name: [gutenberg-editor-initial-html]
Expand Down
10 changes: 5 additions & 5 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ function register_gutenberg_patterns() {
'content' => '<!-- wp:query {"query":{"perPage":6,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"flex","columns":3}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:post-title {"isLink":true} /-->
<!-- wp:group {"style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<div class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:post-title {"isLink":true} /-->
<!-- wp:post-excerpt {"wordCount":20} /-->
<!-- wp:post-date /--></div>
<!-- /wp:group -->
Expand Down Expand Up @@ -136,8 +136,8 @@ function register_gutenberg_patterns() {
'title' => __( 'Offset', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:group {"tagName":"main","style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<main class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:columns -->
'content' => '<!-- wp:group {"style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
<div class="wp-block-group" style="padding-top:30px;padding-right:30px;padding-bottom:30px;padding-left:30px"><!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:query {"query":{"perPage":2,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"list"}} -->
<div class="wp-block-query"><!-- wp:post-template -->
Expand All @@ -162,7 +162,7 @@ function register_gutenberg_patterns() {
<!-- /wp:post-template --></div>
<!-- /wp:query --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></main>
<!-- /wp:columns --></div>
<!-- /wp:group -->',
)
);
Expand Down
40 changes: 33 additions & 7 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function gutenberg_reregister_core_block_types() {
$registry->unregister( $metadata['name'] );
}

gutenberg_register_core_block_styles( $folder_name );
gutenberg_register_core_block_assets( $folder_name );
register_block_type_from_metadata( $block_json_file );
}

Expand All @@ -147,7 +147,7 @@ function gutenberg_reregister_core_block_types() {
if ( $registry->is_registered( $block_name ) ) {
$registry->unregister( $block_name );
}
gutenberg_register_core_block_styles( $block_name );
gutenberg_register_core_block_assets( $block_name );
}

require_once $blocks_dir . $file;
Expand All @@ -164,13 +164,39 @@ function gutenberg_reregister_core_block_types() {
*
* @return void
*/
function gutenberg_register_core_block_styles( $block_name ) {
function gutenberg_register_core_block_assets( $block_name ) {
$block_name = str_replace( 'core/', '', $block_name );

// When in production, use the plugin's version as the default asset version;
// else (for development or test) default to use the current time.
$default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time();
$script_suffix = '.js';

$view_script_path = "build/block-library/blocks/$block_name/view$script_suffix";
if ( file_exists( gutenberg_dir_path() . $view_script_path ) ) {
$view_script_handle = "wp-block-{$block_name}-view";
wp_deregister_script( $view_script_handle );

// Replace suffix and extension with `.asset.php` to find the generated dependencies file.
$view_asset_file = substr( $view_script_path, 0, -( strlen( $script_suffix ) ) ) . '.asset.php';
$view_asset = file_exists( gutenberg_dir_path() . $view_asset_file )
? require( gutenberg_dir_path() . $view_asset_file )
: null;
$view_script_dependencies = isset( $view_asset['dependencies'] ) ? $view_asset['dependencies'] : array();
$view_script_version = isset( $view_asset['version'] ) ? $view_asset['version'] : $default_version;

wp_register_script(
$view_script_handle,
gutenberg_url( $view_script_path ),
$view_script_dependencies,
$view_script_version
);
}

if ( ! gutenberg_should_load_separate_block_assets() ) {
return;
}

$block_name = str_replace( 'core/', '', $block_name );

$style_path = "build/block-library/blocks/$block_name/style.css";
$editor_style_path = "build/block-library/blocks/$block_name/style-editor.css";

Expand All @@ -180,7 +206,7 @@ function gutenberg_register_core_block_styles( $block_name ) {
"wp-block-{$block_name}",
gutenberg_url( $style_path ),
array(),
filemtime( gutenberg_dir_path() . $style_path )
$default_version
);
wp_style_add_data( "wp-block-{$block_name}", 'rtl', 'replace' );

Expand All @@ -196,7 +222,7 @@ function gutenberg_register_core_block_styles( $block_name ) {
"wp-block-{$block_name}-editor",
gutenberg_url( $editor_style_path ),
array(),
filemtime( gutenberg_dir_path() . $editor_style_path )
$default_version
);
wp_style_add_data( "wp-block-{$block_name}-editor", 'rtl', 'replace' );
} else {
Expand Down
1 change: 0 additions & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ public function merge( $incoming ) {
// For leaf values that are arrays it will use the numeric indexes for replacement.
// In those cases, we want to replace the existing with the incoming value, if it exists.
$to_replace = array();
$to_replace[] = array( 'custom' );
$to_replace[] = array( 'spacing', 'units' );
$to_replace[] = array( 'color', 'duotone' );
foreach ( self::VALID_ORIGINS as $origin ) {
Expand Down
7 changes: 1 addition & 6 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
unset( $settings['__experimentalFeatures']['typography']['customLineHeight'] );
}
if ( isset( $settings['__experimentalFeatures']['spacing']['units'] ) ) {
if ( ! is_array( $settings['__experimentalFeatures']['spacing']['units'] ) ) {
$settings['enableCustomUnits'] = false;
} else {
$settings['enableCustomUnits'] = count( $settings['__experimentalFeatures']['spacing']['units'] ) > 0;
}
unset( $settings['__experimentalFeatures']['spacing']['units'] );
$settings['enableCustomUnits'] = $settings['__experimentalFeatures']['spacing']['units'];
}
if ( isset( $settings['__experimentalFeatures']['spacing']['customPadding'] ) ) {
$settings['enableCustomSpacing'] = $settings['__experimentalFeatures']['spacing']['customPadding'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
background-color: $gray-900;
color: $white;
border-radius: $radius-block-ui;
flex: 1 0 auto;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function useDarkThemeBodyClassName( styles ) {
// DOM, so calculate the background color by creating a fake
// wrapper.
const tempCanvas = ownerDocument.createElement( 'div' );
tempCanvas.classList.add( EDITOR_STYLES_SELECTOR );
tempCanvas.classList.add( 'editor-styles-wrapper' );
body.appendChild( tempCanvas );

backgroundColor = defaultView
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/rich-text/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { regexp } from '@wordpress/shortcode';
import deprecated from '@wordpress/deprecated';

export function addActiveFormats( value, activeFormats ) {
if ( activeFormats.length ) {
if ( activeFormats?.length ) {
let index = value.formats.length;

while ( index-- ) {
Expand Down
26 changes: 13 additions & 13 deletions packages/block-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ _This package assumes that your code will run in an **ES2015+** environment. If

## Building JavaScript for the browser

If a `frontend.js` file is present in the block's directory, this file will be built along other assets, making it available to load from the browser.
If a `view.js` file is present in the block's directory, this file will be built along other assets, making it available to load from the browser.

This enables us to, for instance, load this file when the block is present on the page in two ways:

1. Using the block's `render_callback`:

```php
function render_my_block() {
$script_path = __DIR__ . '/block-name/frontend.js';
function render_block_my_block() {
$script_path = __DIR__ . '/my-block/view.js';

if ( file_exists( $script_path ) ) {
wp_enqueue_script(
'my_block_frontend_script',
plugins_url( 'frontend.js', $script_path ),
'wp-block-my-block-view',
plugins_url( 'view.js', $script_path ),
array(),
false,
true
Expand All @@ -36,10 +36,10 @@ function render_my_block() {
}

function register_block_my_block() {
register_block_type_from_metadata(
__DIR__ . '/block-name',
register_block_type(
__DIR__ . '/my-block',
array(
'render_callback' => 'render_my_block',
'render_callback' => 'render_block_my_block',
)
);
}
Expand All @@ -51,21 +51,21 @@ add_action( 'init', 'register_block_my_block' );
2. Using the `render_block` filter:

```php
function render_my_block() {
$script_path = __DIR__ . '/block-name/frontend.js';
function render_block_my_block() {
$script_path = __DIR__ . '/my-block/view.js';

if ( file_exists( $script_path ) ) {
wp_enqueue_script(
'my_block_frontend_script',
plugins_url( 'frontend.js', $script_path ),
'wp-block-my-block-view',
plugins_url( 'view.js', $script_path ),
array(),
false,
true
);
}
}

apply_filter( 'render_block', 'render_my_block' );
apply_filter( 'render_block', 'render_block_my_block' );
```

## API
Expand Down
10 changes: 4 additions & 6 deletions packages/block-library/src/file/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@
*/

/**
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-library-file` script.
* When the `core/file` block is rendering, check if we need to enqueue the `'wp-block-file-view` script.
*
* @param array $attributes The block attributes.
* @param array $content The block content.
*
* @return string Returns the block content.
*/
function render_block_core_file( $attributes, $content ) {
if ( ! empty( $attributes['displayPreview'] ) ) {
// Check if it's already enqueued, so we don't add the inline script multiple times.
if ( ! wp_script_is( 'wp-block-library-file' ) ) {
wp_enqueue_script( 'wp-block-library-file', plugins_url( 'file/frontend.js', __FILE__ ) );
}
$should_load_view_script = ! empty( $attributes['displayPreview'] ) && ! wp_script_is( 'wp-block-file-view' );
if ( $should_load_view_script ) {
wp_enqueue_script( 'wp-block-file-view' );
}

return $content;
Expand Down
24 changes: 22 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { get, omit, pick } from 'lodash';
import { get, has, omit, pick } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -71,6 +71,22 @@ const isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );
*/
export const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );

/**
* Checks if WP generated default image size. Size generation is skipped
* when the image is smaller than the said size.
*
* @param {Object} image
* @param {string} defaultSize
*
* @return {boolean} Whether or not it has default image size.
*/
function hasDefaultSize( image, defaultSize ) {
return (
has( image, [ 'sizes', defaultSize, 'url' ] ) ||
has( image, [ 'media_details', 'sizes', defaultSize, 'source_url' ] )
);
}

export function ImageEdit( {
attributes,
setAttributes,
Expand Down Expand Up @@ -148,7 +164,11 @@ export function ImageEdit( {
additionalAttributes = {
width: undefined,
height: undefined,
sizeSlug: imageDefaultSize,
// Fallback to size "full" if there's no default image size.
// It means the image is smaller, and the block will use a full-size URL.
sizeSlug: hasDefaultSize( media, imageDefaultSize )
? imageDefaultSize
: 'full',
};
} else {
// Keep the same url when selecting the same file, so "Image Size"
Expand Down
11 changes: 2 additions & 9 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"title": "Navigation",
"category": "theme",
"description": "A collection of blocks that allow visitors to get around your site.",
"keywords": [
"menu",
"navigation",
"links"
],
"keywords": [ "menu", "navigation", "links" ],
"textdomain": "default",
"attributes": {
"orientation": {
Expand Down Expand Up @@ -56,10 +52,7 @@
"orientation": "orientation"
},
"supports": {
"align": [
"wide",
"full"
],
"align": [ "wide", "full" ],
"anchor": true,
"html": false,
"inserter": true,
Expand Down
14 changes: 4 additions & 10 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,10 @@ function render_block_core_navigation( $attributes, $content, $block ) {
}

unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] );
$should_load_frontend_script = $attributes['isResponsive'] && ! wp_script_is( 'core_block_navigation_load_frontend_scripts' );

if ( $should_load_frontend_script ) {
wp_enqueue_script(
'core_block_navigation_load_frontend_scripts',
plugins_url( 'frontend.js', __DIR__ . '/navigation/frontend.js' ),
array(),
false,
true
);

$should_load_view_script = ! empty( $attributes['isResponsive'] ) && ! wp_script_is( 'wp-block-navigation-view' );
if ( $should_load_view_script ) {
wp_enqueue_script( 'wp-block-navigation-view' );
}

if ( empty( $block->inner_blocks ) ) {
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
ToolbarGroup,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
import { renderToString, useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -61,7 +60,10 @@ export default function TableOfContentsEdit( {
listBlockExists: !! select( blocksStore ).getBlockType(
'core/list'
),
postContent: select( editorStore ).getEditedPostContent(),
// FIXME: @wordpress/block-library should not depend on @wordpress/editor.
// Blocks can be loaded into a *non-post* block editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
postContent: select( 'core/editor' ).getEditedPostContent(),
} ),
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SelectControl, TextControl } from '@wordpress/components';
import { sprintf, __ } from '@wordpress/i18n';
import { InspectorAdvancedControls } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';

export function TemplatePartAdvancedControls( {
tagName,
Expand All @@ -30,8 +29,11 @@ export function TemplatePartAdvancedControls( {
);

const { areaOptions } = useSelect( ( select ) => {
// FIXME: @wordpress/block-library should not depend on @wordpress/editor.
// Blocks can be loaded into a *non-post* block editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const definedAreas = select(
editorStore
'core/editor'
).__experimentalGetDefaultTemplatePartAreas();
return {
areaOptions: definedAreas.map( ( { label, area: _area } ) => ( {
Expand Down
Loading