Skip to content

Commit

Permalink
Merge branch 'trunk' into combobox-reset-size
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka authored Nov 25, 2024
2 parents a572ae0 + 2215a04 commit bd1c162
Show file tree
Hide file tree
Showing 184 changed files with 2,400 additions and 1,069 deletions.
1 change: 1 addition & 0 deletions backport-changelog/6.8/7069.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ https://github.com/WordPress/wordpress-develop/pull/7069

* https://github.com/WordPress/gutenberg/pull/63401
* https://github.com/WordPress/gutenberg/pull/66918
* https://github.com/WordPress/gutenberg/pull/67018
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7848.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7848

* https://github.com/WordPress/gutenberg/pull/67154
16 changes: 9 additions & 7 deletions docs/explanations/architecture/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ The user may change the state of this block by applying different styles: a text
After some user modifications to the block, the initial markup may become something like this:

```html
<p class="has-color has-green-color has-font-size has-small-font-size my-custom-class"
style="line-height: 1em"></p>
<p
class="has-color has-green-color has-font-size has-small-font-size my-custom-class"
style="line-height: 1em"
></p>
```

This is what we refer to as "user-provided block styles", also know as "local styles" or "serialized styles". Essentially, each tool (font size, color, etc) ends up adding some classes and/or inline styles to the block markup. The CSS styling for these classes is part of the block, global, or theme stylesheets.
Expand Down Expand Up @@ -123,7 +125,7 @@ The block supports API only serializes the font size value to the wrapper, resul

This is an active area of work you can follow [in the tracking issue](https://github.com/WordPress/gutenberg/issues/38167). The linked proposal is exploring a different way to serialize the user changes: instead of each block support serializing its own data (for example, classes such as `has-small-font-size`, `has-green-color`) the idea is the block would get a single class instead (for example, `wp-style-UUID`) and the CSS styling for that class will be generated in the server by WordPress.

While work continues in that proposal, there's an escape hatch, an experimental option block authors can use. Any block support can skip the serialization to HTML markup by using `__experimentalSkipSerialization`. For example:
While work continues in that proposal, there's an escape hatch, an experimental option block authors can use. Any block support can skip the serialization to HTML markup by using `skipSerialization`. For example:

```json
{
Expand All @@ -132,15 +134,15 @@ While work continues in that proposal, there's an escape hatch, an experimental
"supports": {
"typography": {
"fontSize": true,
"__experimentalSkipSerialization": true
"skipSerialization": true
}
}
}
```

This means that the typography block support will do all of the things (create a UI control, bind the block attribute to the control, etc) except serializing the user values into the HTML markup. The classes and inline styles will not be automatically applied to the wrapper and it is the block author's responsibility to implement this in the `edit`, `save`, and `render_callback` functions. See [this issue](https://github.com/WordPress/gutenberg/issues/28913) for examples of how it was done for some blocks provided by WordPress.

Note that, if `__experimentalSkipSerialization` is enabled for a group (typography, color, spacing) it affects _all_ block supports within this group. In the example above _all_ the properties within the `typography` group will be affected (e.g. `fontSize`, `lineHeight`, `fontFamily` .etc).
Note that, if `skipSerialization` is enabled for a group (typography, color, spacing) it affects _all_ block supports within this group. In the example above _all_ the properties within the `typography` group will be affected (e.g. `fontSize`, `lineHeight`, `fontFamily` .etc).

To enable for a _single_ property only, you may use an array to declare which properties are to be skipped. In the example below, only `fontSize` will skip serialization, leaving other items within the `typography` group (e.g. `lineHeight`, `fontFamily` .etc) unaffected.

Expand All @@ -152,7 +154,7 @@ To enable for a _single_ property only, you may use an array to declare which pr
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalSkipSerialization": [ "fontSize" ]
"skipSerialization": [ "fontSize" ]
}
}
}
Expand Down Expand Up @@ -473,7 +475,7 @@ If blocks do this, they need to be registered in the server using the `block.jso

Every chunk of styles can only use a single selector.

This is particularly relevant if the block is using `__experimentalSkipSerialization` to serialize the different style properties to different nodes other than the wrapper. See "Current limitations of blocks supports" for more.
This is particularly relevant if the block is using `skipSerialization` to serialize the different style properties to different nodes other than the wrapper. See "Current limitations of blocks supports" for more.

#### 3. **Only a single property per block**

Expand Down
11 changes: 6 additions & 5 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,8 @@ Action that autosaves the current post. This includes server-side autosaving (de
_Parameters_
- _options_ `Object?`: Extra flags to identify the autosave.
- _options_ `[Object]`: Extra flags to identify the autosave.
- _options.local_ `[boolean]`: Whether to perform a local autosave.
### clearSelectedBlock
Expand Down Expand Up @@ -1204,7 +1205,7 @@ const getFeaturedMediaUrl = useSelect( ( select ) => {
_Parameters_
- _edits_ `Object`: Post attributes to edit.
- _options_ `Object`: Options for the edit.
- _options_ `[Object]`: Options for the edit.
_Returns_
Expand Down Expand Up @@ -1417,7 +1418,7 @@ Returns an action object used to signal that the blocks have been updated.
_Parameters_
- _blocks_ `Array`: Block Array.
- _options_ `?Object`: Optional options.
- _options_ `[Object]`: Optional options.
### resetPost
Expand All @@ -1431,7 +1432,7 @@ Action for saving the current post in the editor.
_Parameters_
- _options_ `Object`:
- _options_ `[Object]`:
### selectBlock
Expand Down Expand Up @@ -1519,7 +1520,7 @@ _Parameters_
- _post_ `Object`: Post object.
- _edits_ `Object`: Initial edited attributes object.
- _template_ `Array?`: Block Template.
- _template_ `[Array]`: Block Template.
### setupEditorState
Expand Down
139 changes: 92 additions & 47 deletions lib/compat/wordpress-6.8/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,122 @@ function gutenberg_stabilize_experimental_block_supports( $args ) {
return $args;
}

$experimental_to_stable_keys = array(
'typography' => array(
$experimental_supports_map = array( '__experimentalBorder' => 'border' );
$common_experimental_properties = array(
'__experimentalDefaultControls' => 'defaultControls',
'__experimentalSkipSerialization' => 'skipSerialization',
);
$experimental_support_properties = array(
'typography' => array(
'__experimentalFontFamily' => 'fontFamily',
'__experimentalFontStyle' => 'fontStyle',
'__experimentalFontWeight' => 'fontWeight',
'__experimentalLetterSpacing' => 'letterSpacing',
'__experimentalTextDecoration' => 'textDecoration',
'__experimentalTextTransform' => 'textTransform',
),
'__experimentalBorder' => 'border',
);
$done = array();

$updated_supports = array();
foreach ( $args['supports'] as $support => $config ) {
// Add the support's config as is when it's not in need of stabilization.
if ( empty( $experimental_to_stable_keys[ $support ] ) ) {
/*
* If this support config has already been stabilized, skip it.
* A stable support key occurring after an experimental key, gets
* stabilized then so that the two configs can be merged effectively.
*/
if ( isset( $done[ $support ] ) ) {
continue;
}

$stable_support_key = $experimental_supports_map[ $support ] ?? $support;

/*
* Use the support's config as is when it's not in need of stabilization.
*
* A support does not need stabilization if:
* - The support key doesn't need stabilization AND
* - Either:
* - The config isn't an array, so can't have experimental properties OR
* - The config is an array but has no experimental properties to stabilize.
*/
if ( $support === $stable_support_key &&
( ! is_array( $config ) ||
( ! isset( $experimental_support_properties[ $stable_support_key ] ) &&
empty( array_intersect_key( $common_experimental_properties, $config ) )
)
)
) {
$updated_supports[ $support ] = $config;
continue;
}

// Stabilize the support's key if needed e.g. __experimentalBorder => border.
if ( is_string( $experimental_to_stable_keys[ $support ] ) ) {
$stabilized_key = $experimental_to_stable_keys[ $support ];
$stabilize_config = function ( $unstable_config, $stable_support_key ) use ( $experimental_support_properties, $common_experimental_properties ) {
$stable_config = array();
foreach ( $unstable_config as $key => $value ) {
// Get stable key from support-specific map, common properties map, or keep original.
$stable_key = $experimental_support_properties[ $stable_support_key ][ $key ] ??
$common_experimental_properties[ $key ] ??
$key;

$stable_config[ $stable_key ] = $value;

// If there is no stabilized key present, use the experimental config as is.
if ( ! array_key_exists( $stabilized_key, $args['supports'] ) ) {
$updated_supports[ $stabilized_key ] = $config;
continue;
/*
* The `__experimentalSkipSerialization` key needs to be kept until
* WP 6.8 becomes the minimum supported version. This is due to the
* core `wp_should_skip_block_supports_serialization` function only
* checking for `__experimentalSkipSerialization` in earlier versions.
*/
if ( '__experimentalSkipSerialization' === $key || 'skipSerialization' === $key ) {
$stable_config['__experimentalSkipSerialization'] = $value;
}
}
return $stable_config;
};

/*
* Determine the order of keys, so the last defined can be preferred.
*
* The reason for preferring the last defined key is that after filters
* are applied, the last inserted key is likely the most up-to-date value.
* We cannot determine with certainty which value was "last modified" so
* the insertion order is the best guess. The extreme edge case of multiple
* filters tweaking the same support property will become less over time as
* extenders migrate existing blocks and plugins to stable keys.
*/
// Stabilize the config value.
$stable_config = is_array( $config ) ? $stabilize_config( $config, $stable_support_key ) : $config;

/*
* If a plugin overrides the support config with the `register_block_type_args`
* filter, both experimental and stable configs may be present. In that case,
* use the order keys are defined in to determine the final value.
* - If config is an array, merge the arrays in their order of definition.
* - If config is not an array, use the value defined last.
*
* The reason for preferring the last defined key is that after filters
* are applied, the last inserted key is likely the most up-to-date value.
* We cannot determine with certainty which value was "last modified" so
* the insertion order is the best guess. The extreme edge case of multiple
* filters tweaking the same support property will become less over time as
* extenders migrate existing blocks and plugins to stable keys.
*/
if ( $support !== $stable_support_key && isset( $args['supports'][ $stable_support_key ] ) ) {
$key_positions = array_flip( array_keys( $args['supports'] ) );
$experimental_index = $key_positions[ $support ] ?? -1;
$stabilized_index = $key_positions[ $stabilized_key ] ?? -1;
$experimental_first = $experimental_index < $stabilized_index;
$experimental_first =
( $key_positions[ $support ] ?? PHP_INT_MAX ) <
( $key_positions[ $stable_support_key ] ?? PHP_INT_MAX );

// Update support config, prefer the last defined value.
if ( is_array( $config ) ) {
$updated_supports[ $stabilized_key ] = $experimental_first
? array_merge( $config, $args['supports'][ $stabilized_key ] )
: array_merge( $args['supports'][ $stabilized_key ], $config );
if ( is_array( $args['supports'][ $stable_support_key ] ) ) {
/*
* To merge the alternative support config effectively, it also needs to be
* stabilized before merging to keep stabilized and experimental flags in
* sync.
*/
$args['supports'][ $stable_support_key ] = $stabilize_config( $args['supports'][ $stable_support_key ], $stable_support_key );
$stable_config = $experimental_first
? array_merge( $stable_config, $args['supports'][ $stable_support_key ] )
: array_merge( $args['supports'][ $stable_support_key ], $stable_config );
// Prevents reprocessing this support as it was merged above.
$done[ $stable_support_key ] = true;
} else {
$updated_supports[ $stabilized_key ] = $experimental_first
? $args['supports'][ $stabilized_key ]
: $config;
$stable_config = $experimental_first
? $args['supports'][ $stable_support_key ]
: $stable_config;
}

continue;
}

// Stabilize individual support feature keys e.g. __experimentalFontFamily => fontFamily.
if ( is_array( $experimental_to_stable_keys[ $support ] ) ) {
$stable_support_config = array();
foreach ( $config as $key => $value ) {
if ( array_key_exists( $key, $experimental_to_stable_keys[ $support ] ) ) {
$stable_support_config[ $experimental_to_stable_keys[ $support ][ $key ] ] = $value;
} else {
$stable_support_config[ $key ] = $value;
}
}
$updated_supports[ $support ] = $stable_support_config;
}
$updated_supports[ $stable_support_key ] = $stable_config;
}

$args['supports'] = $updated_supports;
Expand Down
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.8/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function gutenberg_post_type_default_rendering_mode( $args, $post_type ) {
if (
wp_is_block_theme() &&
( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) &&
( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) )
( ! empty( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) )
) {
// Validate the supplied rendering mode.
if (
Expand Down
29 changes: 29 additions & 0 deletions lib/compat/wordpress-6.8/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,32 @@ function gutenberg_add_post_type_rendering_mode() {
}
}
add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' );

// When querying terms for a given taxonomy in the REST API, respect the default
// query arguments set for that taxonomy upon registration.
function gutenberg_respect_taxonomy_default_args_in_rest_api( $args ) {
// If a `post` argument is provided, the Terms controller will use
// `wp_get_object_terms`, which respects the default query arguments,
// so we don't need to do anything.
if ( ! empty( $args['post'] ) ) {
return $args;
}

$t = get_taxonomy( $args['taxonomy'] );
if ( isset( $t->args ) && is_array( $t->args ) ) {
$args = array_merge( $args, $t->args );
}
return $args;
}
add_action(
'registered_taxonomy',
function ( $taxonomy ) {
add_filter( "rest_{$taxonomy}_query", 'gutenberg_respect_taxonomy_default_args_in_rest_api' );
}
);
add_action(
'unregistered_taxonomy',
function ( $taxonomy ) {
remove_filter( "rest_{$taxonomy}_query", 'gutenberg_respect_taxonomy_default_args_in_rest_api' );
}
);
11 changes: 6 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"eslint-import-resolver-node": "0.3.4",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-jest": "27.2.3",
"eslint-plugin-jest": "27.4.3",
"eslint-plugin-jest-dom": "5.0.2",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react-compiler": "19.0.0-beta-0dec889-20241115",
Expand Down
8 changes: 5 additions & 3 deletions packages/block-editor/src/components/block-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export default function BlockControlsSlot( { group = 'default', ...props } ) {
[ toolbarState, contextState ]
);

const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot ) {
const slotFill = groups[ group ];
const fills = useSlotFills( slotFill.name );

if ( ! slotFill ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}
Expand All @@ -42,6 +43,7 @@ export default function BlockControlsSlot( { group = 'default', ...props } ) {
return null;
}

const { Slot } = slotFill;
const slot = <Slot { ...props } bubblesVirtually fillProps={ fillProps } />;

if ( group === 'default' ) {
Expand Down
Loading

0 comments on commit bd1c162

Please sign in to comment.