Skip to content

Commit

Permalink
Merge branch 'trunk' into try/56668-hide-template-parts-hint-theme-pr…
Browse files Browse the repository at this point in the history
…eview
  • Loading branch information
carolinan committed Feb 22, 2024
2 parents bdf51fe + 6e9dca5 commit 6547af3
Show file tree
Hide file tree
Showing 406 changed files with 4,096 additions and 2,264 deletions.
13 changes: 9 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,25 @@ module.exports = {
},
{
files: [ 'packages/components/src/**' ],
excludedFiles: [ 'packages/components/src/utils/colors-values.js' ],
excludedFiles: [
'packages/components/src/utils/colors-values.js',
'packages/components/src/theme/**',
],
rules: {
'no-restricted-syntax': [
'error',
{
selector: 'Literal[value=/--wp-admin-theme-/]',
selector:
':matches(Literal[value=/--wp-admin-theme-/],TemplateElement[value.cooked=/--wp-admin-theme-/])',
message:
'--wp-admin-theme-* variables do not support component theming. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
},
{
selector:
'TemplateElement[value.cooked=/--wp-admin-theme-/]',
// Allow overriding definitions, but not access with var()
':matches(Literal[value=/var\\(\\s*--wp-components-color-/],TemplateElement[value.cooked=/var\\(\\s*--wp-components-color-/])',
message:
'--wp-admin-theme-* variables do not support component theming. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
'To ensure proper fallbacks, --wp-components-color-* variables should not be used directly. Use variables from the COLORS object in packages/components/src/utils/colors-values.js instead.',
},
],
},
Expand Down
252 changes: 252 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/contributors/folder-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ The following snippet explains how the Gutenberg repository is structured omitti
├── README.md
├── SECURITY.md
├── CONTRIBUTING.md
├── CODE_OF_CONDUCT.md
├── .editorconfig
├── .eslintignore
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to-guides/themes/global-settings-and-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ Note, however, that not all settings are relevant for all blocks. The settings s

There's one special setting property, `appearanceTools`, which is a boolean and its default value is false. Themes can use this setting to enable the following ones:

- background: backgroundImage
- background: backgroundImage, backgroundSize
- border: color, radius, style, width
- color: link
- dimensions: minHeight
- dimensions: aspectRatio, minHeight
- position: sticky
- spacing: blockGap, margin, padding
- typography: lineHeight
Expand Down
15 changes: 15 additions & 0 deletions docs/reference-guides/block-api/block-supports.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ supports: {
}
```

## interactivity

- Type: `boolean` or `object`
- Default value: `false`
- Subproperties:
- `clientNavigation`: type `boolean`, default value `false`
- `interactive`: type `boolean`, default value `false`

Indicates if the block is using Interactivity API features.

The `clientNavigation` sub-property indicates whether a block is compatible with the Interactivity API client-side navigation.
Set it to true only if the block is not interactive or if it is interactive using the Interactivity API. Set it to false if the block is interactive but uses vanilla JS, jQuery or another JS framework/library other than the Interactivity API.

The `interactive` sub-property indicates whether the block is using the Interactivity API directives.

## layout

- Type: `boolean` or `Object`
Expand Down
4 changes: 2 additions & 2 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1263,15 +1263,15 @@ Action that hides the insertion point.

### insertAfterBlock

Action that inserts an empty block after a given block.
Action that inserts a default block after a given block.

_Parameters_

- _clientId_ `string`:

### insertBeforeBlock

Action that inserts an empty block before a given block.
Action that inserts a default block before a given block.

_Parameters_

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/richtext.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If you'd still like to use RichText, you can eliminate all of the formatting opt

If you want to limit the formats allowed, you can specify using `allowedFormats` property in your code, see the example above or [the component documentation](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md#allowedformats-array) for details.

### Disable specific fromat types in Editor
### Disable specific format types in Editor

The RichText component uses formats to display inline elements, for example images within the paragraph block. If you just want to disable a format from the editor, you can use the `unregisterFormatType` function. For example to disable inline images, use:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Code editors can pick up the schema and can provide helpful hints and suggestion

Setting that enables the following UI tools:

- background: backgroundImage
- background: backgroundImage, backgroundSize
- border: color, radius, style, width
- color: link
- dimensions: aspectRatio, minHeight
Expand Down Expand Up @@ -107,6 +107,7 @@ Settings related to background.
| Property | Type | Default | Props |
| --- | --- | --- |--- |
| backgroundImage | boolean | false | |
| backgroundSize | boolean | false | |

---

Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.3
* Requires PHP: 7.0
* Version: 17.7.0
* Version: 17.8.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
5 changes: 3 additions & 2 deletions lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ function gutenberg_render_elements_support_styles( $pre_render, $block ) {
'skip' => $skip_button_color_serialization,
),
'link' => array(
'selector' => ".$class_name a",
'hover_selector' => ".$class_name a:hover",
// :where(:not) matches theme.json selector.
'selector' => ".$class_name a:where(:not(.wp-element-button))",
'hover_selector' => ".$class_name a:where(:not(.wp-element-button)):hover",
'skip' => $skip_link_color_serialization,
),
'heading' => array(
Expand Down
28 changes: 25 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,16 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {

/**
* If columnSpan is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,
* the columnSpan should be removed on small grids.
* the columnSpan should be removed on small grids. If there's a minimumColumnWidth, the grid is responsive.
* But if the minimumColumnWidth value wasn't changed, it won't be set. In that case, if columnCount doesn't
* exist, we can assume that the grid is responsive.
*/
if ( isset( $block['attrs']['style']['layout']['columnSpan'] ) && isset( $block['attrs']['style']['layout']['parentColumnWidth'] ) ) {
if ( isset( $block['attrs']['style']['layout']['columnSpan'] ) && ( isset( $block['parentLayout']['minimumColumnWidth'] ) || ! isset( $block['parentLayout']['columnCount'] ) ) ) {
$column_span_number = floatval( $block['attrs']['style']['layout']['columnSpan'] );
$parent_column_width = $block['attrs']['style']['layout']['parentColumnWidth'];
$parent_column_width = isset( $block['parentLayout']['minimumColumnWidth'] ) ? $block['parentLayout']['minimumColumnWidth'] : '12rem';
$parent_column_value = floatval( $parent_column_width );
$parent_column_unit = explode( $parent_column_value, $parent_column_width );

/**
* If there is no unit, the width has somehow been mangled so we reset both unit and value
* to defaults.
Expand Down Expand Up @@ -887,6 +890,25 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
return $processor->get_updated_html();
}

/**
* Add a `render_block_data` filter to fetch the parent block layout data.
*/
add_filter(
'render_block_data',
function ( $parsed_block, $source_block, $parent_block ) {
/**
* Check if the parent block exists and if it has a layout attribute.
* If it does, add the parent layout to the parsed block.
*/
if ( $parent_block && isset( $parent_block->parsed_block['attrs']['layout'] ) ) {
$parsed_block['parentLayout'] = $parent_block->parsed_block['attrs']['layout'];
}
return $parsed_block;
},
10,
3
);

// Register the block support. (overrides core one).
WP_Block_Supports::get_instance()->register(
'layout',
Expand Down
6 changes: 6 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3807,12 +3807,18 @@ private static function resolve_custom_css_format( $tree ) {
* Replaces CSS variables with their values in place.
*
* @since 6.3.0
* @since 6.6.0 Check for empty style before processing.
*
* @param array $styles CSS declarations to convert.
* @param array $values key => value pairs to use for replacement.
* @return array
*/
private static function convert_variables_to_value( $styles, $values ) {
foreach ( $styles as $key => $style ) {
if ( empty( $style ) ) {
continue;
}

if ( is_array( $style ) ) {
$styles[ $key ] = self::convert_variables_to_value( $style, $values );
continue;
Expand Down
23 changes: 12 additions & 11 deletions lib/compat/wordpress-6.5/block-bindings/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
* @param array $source_properties {
* The array of arguments that are used to register a source.
*
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of an attribute .
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of an attribute .
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type array $uses_context (optional) Array of values to add to block `uses_context` needed by the source.
* }
* @return WP_Block_Bindings_Source|false Source when the registration was successful, or `false` on failure.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ final class WP_Block_Bindings_Registry {
*/
private static $instance = null;

/**
* Supported source properties that can be passed to the registered source.
*
* @since 6.5.0
* @var array
*/
private $allowed_source_properties = array(
'label',
'get_value_callback',
'uses_context',
);

/**
* Supported blocks that can use the block bindings API.
*
* @since 6.5.0
* @var array
*/
private $supported_blocks = array(
'core/paragraph',
'core/heading',
'core/image',
'core/button',
);

/**
* Registers a new block bindings source.
*
Expand All @@ -48,18 +73,19 @@ final class WP_Block_Bindings_Registry {
* @param array $source_properties {
* The array of arguments that are used to register a source.
*
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of the target attribute.
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type string $label The label of the source.
* @type callback $get_value_callback A callback executed when the source is processed during block rendering.
* The callback should have the following signature:
*
* `function ($source_args, $block_instance,$attribute_name): mixed`
* - @param array $source_args Array containing source arguments
* used to look up the override value,
* i.e. {"key": "foo"}.
* - @param WP_Block $block_instance The block instance.
* - @param string $attribute_name The name of the target attribute.
* The callback has a mixed return type; it may return a string to override
* the block's original value, null, false to remove an attribute, etc.
* @type array $uses_context (optional) Array of values to add to block `uses_context` needed by the source.
* }
* @return WP_Block_Bindings_Source|false Source when the registration was successful, or `false` on failure.
*/
Expand Down Expand Up @@ -102,7 +128,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the source properties contain the label */
// Validate that the source properties contain the label.
if ( ! isset( $source_properties['label'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -112,7 +138,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the source properties contain the get_value_callback */
// Validate that the source properties contain the get_value_callback.
if ( ! isset( $source_properties['get_value_callback'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -122,7 +148,7 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

/* Validate that the get_value_callback is a valid callback */
// Validate that the get_value_callback is a valid callback.
if ( ! is_callable( $source_properties['get_value_callback'] ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -132,13 +158,49 @@ public function register( string $source_name, array $source_properties ) {
return false;
}

// Validate that the uses_context parameter is an array.
if ( isset( $source_properties['uses_context'] ) && ! is_array( $source_properties['uses_context'] ) ) {
_doing_it_wrong(
__METHOD__,
__( 'The "uses_context" parameter must be an array.' ),
'6.5.0'
);
return false;
}

// Validate that the source properties contain only allowed properties.
if ( ! empty( array_diff( array_keys( $source_properties ), $this->allowed_source_properties ) ) ) {
_doing_it_wrong(
__METHOD__,
__( 'The $source_properties array contains invalid properties.' ),
'6.5.0'
);
return false;
}

$source = new WP_Block_Bindings_Source(
$source_name,
$source_properties
);

$this->sources[ $source_name ] = $source;

// Add `uses_context` defined by block bindings sources.
add_filter(
'register_block_type_args',
function ( $args, $block_name ) use ( $source ) {
if ( ! in_array( $block_name, $this->supported_blocks, true ) || empty( $source->uses_context ) ) {
return $args;
}
$original_use_context = isset( $args['uses_context'] ) ? $args['uses_context'] : array();
// Use array_values to reset the array keys.
$args['uses_context'] = array_values( array_unique( array_merge( $original_use_context, $source->uses_context ) ) );

return $args;
},
10,
2
);
return $source;
}

Expand Down
Loading

0 comments on commit 6547af3

Please sign in to comment.