Skip to content

Commit

Permalink
Merge branch 'trunk' into rnmobile/update-general-e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geriux committed Feb 15, 2023
2 parents 7f99005 + 58cd891 commit 07a792b
Show file tree
Hide file tree
Showing 222 changed files with 4,726 additions and 3,297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ phpunit-watcher.yml
.tool-versions
test/storybook-playwright/test-results
test/storybook-playwright/specs/__snapshots__
test/storybook-playwright/specs/*-snapshots/**
7 changes: 3 additions & 4 deletions docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ You can attach private selectors and actions to a public store:

```js
// In packages/package1/store.js:
import { experiments as dataExperiments } from '@wordpress/data';
import { __experimentalHasContentRoleAttribute, ...selectors } from './selectors';
import { __experimentalToggleFeature, ...actions } from './selectors';
// The `lock` function is exported from the internal experiments.js file where
Expand Down Expand Up @@ -340,9 +339,9 @@ function MyComponent() {
// In packages/package1/index.js:
import { lock } from './private-apis';

export const experiments = {};
export const privateApis = {};
/* Attach private data to the exported object */
lock( experiments, {
lock( privateApis, {
__experimentalCallback: function () {},
__experimentalReactComponent: function ExperimentalComponent() {
return <div />;
Expand All @@ -352,7 +351,7 @@ lock( experiments, {
} );

// In packages/package2/index.js:
import { experiments } from '@wordpress/package1';
import { privateApis } from '@wordpress/package1';
import { unlock } from './private-apis';

const {
Expand Down
20 changes: 9 additions & 11 deletions docs/contributors/code/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ xvfb-run -- npm run test:e2e:playwright -- --project=webkit

## Best practices

Read the [best practices](https://playwright.dev/docs/best-practices) guide for Playwright.

<details>
<summary><h3>Forbid `$`, use `locator` instead</h3></summary>

Expand All @@ -45,26 +47,22 @@ In fact, any API that returns `ElementHandle` is [discouraged](https://playwrigh
<details>
<summary><h3>Use accessible selectors</h3></summary>

Use the selector engine [role-selector](https://playwright.dev/docs/selectors#role-selector) to construct the query wherever possible. It enables us to write accessible queries without having to rely on internal implementations. The syntax should be straightforward and looks like this:
Use [`getByRole`](https://playwright.dev/docs/locators#locate-by-role) to construct the query wherever possible. It enables us to write accessible queries without having to rely on internal implementations.

```js
// Select a button with the accessible name "Hello World" (case-insensitive).
page.locator( 'role=button[name="Hello World"i]' );

// Using short-form API, the `name` is case-insensitive by default.
// Select a button which includes the accessible name "Hello World" (case-insensitive).
page.getByRole( 'button', { name: 'Hello World' } );
```

It's recommended to append `i` to the name attribute to match it case-insensitively wherever it makes sense. It can also be chained with built-in selector engines to perform complex queries:
It can also be chained to perform complex queries:

```js
// Select a button with a name ends with `Back` and is visible on the screen.
page.locator( 'role=button[name=/Back$/] >> visible=true' );
// Select a button with the (exact) name "View options" under `#some-section`.
page.locator( 'css=#some-section >> role=button[name="View options"]' );
// Select an option with a name "Buttons" under the "Block Library" region.
page.getByRole( 'region', { name: 'Block Library' } )
.getByRole( 'option', { name: 'Buttons' } )
```

See the [official documentation](https://playwright.dev/docs/selectors#role-selector) for more info on how to use them.
See the [official documentation](https://playwright.dev/docs/locators) for more info on how to use them.
</details>

<details>
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,12 @@
"markdown_source": "../packages/components/src/navigator/navigator-screen/README.md",
"parent": "components"
},
{
"title": "NavigatorToParentButton",
"slug": "navigator-to-parent-button",
"markdown_source": "../packages/components/src/navigator/navigator-to-parent-button/README.md",
"parent": "components"
},
{
"title": "Notice",
"slug": "notice",
Expand Down
75 changes: 72 additions & 3 deletions docs/reference-guides/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,39 @@ supports: {
}
```

## dimensions

_**Note:** Since WordPress 6.2._

- Type: `Object`
- Default value: null
- Subproperties:
- `minHeight`: type `boolean`, default value `false`

This value signals that a block supports some of the CSS style properties related to dimensions. When it does, the block editor will show UI controls for the user to set their values if [the theme declares support](/docs/how-to-guides/themes/theme-json/#opt-in-into-ui-controls).

```js
supports: {
dimensions: {
minHeight: true // Enable min height control.
}
}
```

When a block declares support for a specific dimensions property, its attributes definition is extended to include the `style` attribute.

- `style`: attribute of `object` type with no default assigned. This is added when `minHeight` support is declared. It stores the custom values set by the user, e.g.:

```js
attributes: {
style: {
dimensions: {
minHeight: "50vh"
}
}
}
```

## html

- Type: `boolean`
Expand All @@ -485,7 +518,7 @@ supports: {
- Type: `boolean`
- Default value: `true`
By default, all blocks will appear in the inserter, block transforms menu, Style Book, etc. To hide a block from all parts of the user interface so that it can only be inserted programatically, set `inserter` to `false`.
By default, all blocks will appear in the inserter, block transforms menu, Style Book, etc. To hide a block from all parts of the user interface so that it can only be inserted programmatically, set `inserter` to `false`.
```js
supports: {
Expand Down Expand Up @@ -536,6 +569,42 @@ supports: {
}
```

## position

_**Note:** Since WordPress 6.2._

- Type: `Object`
- Default value: null
- Subproperties:
- `sticky`: type `boolean`, default value `false`

This value signals that a block supports some of the CSS style properties related to position. When it does, the block editor will show UI controls for the user to set their values if [the theme declares support](/docs/how-to-guides/themes/theme-json/#opt-in-into-ui-controls).

Note that sticky position controls are currently only available for blocks set at the root level of the document. Setting a block to the `sticky` position will stick the block to its most immediate parent when the user scrolls the page.

```js
supports: {
position: {
sticky: true // Enable selecting sticky position.
}
}
```

When the block declares support for a specific position property, its attributes definition is extended to include the `style` attribute.

- `style`: attribute of `object` type with no default assigned. This is added when `sticky` support is declared. It stores the custom values set by the user, e.g.:

```js
attributes: {
style: {
position: {
type: "sticky",
top: "0px"
}
}
}
```

## spacing

- Type: `Object`
Expand All @@ -545,7 +614,7 @@ supports: {
- `padding`: type `boolean` or `array`, default value `false`
- `blockGap`: type `boolean` or `array`, default value `false`

This value signals that a block supports some of the CSS style properties related to spacing. When it does, the block editor will show UI controls for the user to set their values, if [the theme declares support](/docs/how-to-guides/themes/theme-support.md#cover-block-padding).
This value signals that a block supports some of the CSS style properties related to spacing. When it does, the block editor will show UI controls for the user to set their values if [the theme declares support](/docs/how-to-guides/themes/theme-support.md#cover-block-padding).

```js
supports: {
Expand All @@ -557,7 +626,7 @@ supports: {
}
```

When the block declares support for a specific spacing property, the attributes definition is extended to include the `style` attribute.
When the block declares support for a specific spacing property, its attributes definition is extended to include the `style` attribute.

- `style`: attribute of `object` type with no default assigned. This is added when `margin` or `padding` support is declared. It stores the custom values set by the user, e.g.:

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ Display a list of your most recent comments. ([Source](https://github.com/WordPr

- **Name:** core/latest-comments
- **Category:** widgets
- **Supports:** align, anchor, spacing (margin, padding), ~~html~~
- **Supports:** align, anchor, spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** commentsToShow, displayAvatar, displayDate, displayExcerpt

## Latest Posts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Setting that enables the following UI tools:
- border: color, radius, style, width
- color: link
- dimensions: minHeight
- position: sticky
- spacing: blockGap, margin, padding
- typography: lineHeight

Expand Down
16 changes: 8 additions & 8 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,9 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
return (string) $content;
}

$global_settings = gutenberg_get_global_settings();
$block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
$has_block_gap_support = isset( $block_gap );
$global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
$root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );

$default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout;
$global_settings = gutenberg_get_global_settings();
$global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );

if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) {
return $block_content;
Expand All @@ -403,6 +398,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$used_layout['type'] = 'constrained';
}

$root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );

if (
$root_padding_aware_alignments &&
isset( $used_layout['type'] ) &&
Expand Down Expand Up @@ -470,6 +467,9 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
*/
$should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );

$block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
$has_block_gap_support = isset( $block_gap );

$style = gutenberg_get_layout_style(
".$container_class.$container_class",
$used_layout,
Expand Down
7 changes: 5 additions & 2 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
* @return string The new selector.
*/
protected static function append_to_selector( $selector, $to_append, $position = 'right' ) {
if ( ! str_contains( ',', $selector ) ) {
return 'right' === $position ? $selector . $to_append : $to_append . $selector;
}
$new_selectors = array();
$selectors = explode( ',', $selector );
foreach ( $selectors as $sel ) {
Expand Down Expand Up @@ -2513,9 +2516,9 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
// The above rule is negated for alignfull children of nested containers.
$css .= '.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }';
// Some of the children of alignfull blocks without content width should also get padding: text blocks and non-alignfull container blocks.
$css .= '.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }';
$css .= '.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),.wp-block:not(.alignfull),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }';
// The above rule also has to be negated for blocks inside nested `.has-global-padding` blocks.
$css .= '.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; }';
$css .= '.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),.wp-block:not(.alignfull),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; }';
}

$css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }';
Expand Down
13 changes: 7 additions & 6 deletions lib/compat/wordpress-6.1/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t

$post_type = isset( $query['post_type'] ) ? $query['post_type'] : '';
$wp_query_args = array(
'post_status' => array( 'auto-draft', 'draft', 'publish' ),
'post_type' => $template_type,
'posts_per_page' => -1,
'no_found_rows' => true,
'tax_query' => array(
'post_status' => array( 'auto-draft', 'draft', 'publish' ),
'post_type' => $template_type,
'posts_per_page' => -1,
'no_found_rows' => true,
'lazy_load_term_meta' => false,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
Expand Down Expand Up @@ -147,7 +148,7 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t
}

$is_not_custom = false === array_search(
wp_get_theme()->get_stylesheet() . '//' . $template_file['slug'],
get_stylesheet() . '//' . $template_file['slug'],
array_column( $query_result, 'id' ),
true
);
Expand Down
25 changes: 0 additions & 25 deletions lib/compat/wordpress-6.1/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,28 +323,3 @@ function gutenberg_block_type_metadata_render_template( $settings, $metadata ) {
return $settings;
}
add_filter( 'block_type_metadata_settings', 'gutenberg_block_type_metadata_render_template', 10, 2 );

/**
* Registers the metadata block attribute for block types.
*
* Once 6.1 is the minimum supported WordPress version for the Gutenberg
* plugin, this shim can be removed
*
* @param array $args Array of arguments for registering a block type.
* @return array $args
*/
function gutenberg_register_metadata_attribute( $args ) {
// Setup attributes if needed.
if ( ! isset( $args['attributes'] ) || ! is_array( $args['attributes'] ) ) {
$args['attributes'] = array();
}

if ( ! array_key_exists( 'metadata', $args['attributes'] ) ) {
$args['attributes']['metadata'] = array(
'type' => 'object',
);
}

return $args;
}
add_filter( 'register_block_type_args', 'gutenberg_register_metadata_attribute' );
15 changes: 0 additions & 15 deletions lib/compat/wordpress-6.2/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
* @package gutenberg
*/

/**
* Update `wp_template` and `wp_template-part` post types to use
* Gutenberg's REST controller.
*
* @param array $args Array of arguments for registering a post type.
* @param string $post_type Post type key.
*/
function gutenberg_update_templates_template_parts_rest_controller( $args, $post_type ) {
if ( in_array( $post_type, array( 'wp_template', 'wp_template-part' ), true ) ) {
$args['rest_controller_class'] = 'Gutenberg_REST_Templates_Controller_6_2';
}
return $args;
}
add_filter( 'register_post_type_args', 'gutenberg_update_templates_template_parts_rest_controller', 10, 2 );

/**
* Registers the block pattern categories REST API routes.
*/
Expand Down
21 changes: 21 additions & 0 deletions lib/compat/wordpress-6.2/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ function gutenberg_site_editor_unset_homepage_setting( $settings, $context ) {
return $settings;
}
add_filter( 'block_editor_settings_all', 'gutenberg_site_editor_unset_homepage_setting', 10, 2 );

/**
* Overrides the site editor initialization for WordPress 6.2 and cancels the redirection.
* The logic of this function is not important, we just need to remove the redirection from core.
*
* @param string $location Location.
*
* @return string Updated location.
*/
function gutenberg_prevent_site_editor_redirection( $location ) {
if ( strpos( $location, 'site-editor.php' ) !== false && strpos( $location, '?' ) !== false ) {
return add_query_arg(
array( 'postId' => 'none' ),
admin_url( 'site-editor.php' )
);
}

return $location;
}

add_filter( 'wp_redirect', 'gutenberg_prevent_site_editor_redirection', 1 );
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Base Templates REST API Controller.
*/
class Gutenberg_REST_Templates_Controller_6_2 extends Gutenberg_REST_Templates_Controller {
class Gutenberg_REST_Templates_Controller_6_3 extends Gutenberg_REST_Templates_Controller {

/**
* Registers the controllers routes.
Expand Down
Loading

0 comments on commit 07a792b

Please sign in to comment.