Skip to content

Commit

Permalink
Merge branch 'trunk' of https://github.com/WordPress/gutenberg into f…
Browse files Browse the repository at this point in the history
…eat/add-use-event-and-use-observe-element-size
  • Loading branch information
DaniGuardiola committed Sep 9, 2024
2 parents 4aa01b3 + a89c8bd commit 55946ef
Show file tree
Hide file tree
Showing 550 changed files with 8,319 additions and 3,360 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ module.exports = {
'SelectControl',
'TextControl',
'ToggleGroupControl',
'UnitControl',
].map( ( componentName ) => ( {
// Falsy `__next40pxDefaultSize` without a non-default `size` prop.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"][value.expression.value!=false])):not(:has(JSXAttribute[name.name="size"][value.value!="default"]))`,
Expand All @@ -345,7 +346,7 @@ module.exports = {
'FormFileUpload should have the `__next40pxDefaultSize` prop to opt-in to the new default size.',
},
// Temporary rules until all existing components have the `__next40pxDefaultSize` prop.
...[ 'Button', 'UnitControl' ].map( ( componentName ) => ( {
...[ 'Button' ].map( ( componentName ) => ( {
// Not strict. Allows pre-existing __next40pxDefaultSize={ false } usage until they are all manually updated.
selector: `JSXOpeningElement[name.name="${ componentName }"]:not(:has(JSXAttribute[name.name="__next40pxDefaultSize"])):not(:has(JSXAttribute[name.name="size"]))`,
message:
Expand Down
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7258.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7258

* https://github.com/WordPress/gutenberg/pull/64570
File renamed without changes.
356 changes: 356 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/reference-guides/interactivity-api/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ It provides a **local** state available to a specific HTML node and its children
The `wp-context` directive accepts a stringified JSON as a value.

```php
//render.php
// render.php
<div data-wp-context='{ "post": { "id": <?php echo $post->ID; ?> } }' >
<button data-wp-on--click="actions.logId" >
Click Me!
Expand All @@ -110,13 +110,13 @@ store( "myPlugin", {
Different contexts can be defined at different levels, and deeper levels will merge their own context with any parent one:

```html
<div data-wp-context="{ foo: 'bar' }">
<div data-wp-context='{ "foo": "bar" }'>
<span data-wp-text="context.foo"><!-- Will output: "bar" --></span>

<div data-wp-context="{ bar: 'baz' }">
<div data-wp-context='{ "bar": "baz" }'>
<span data-wp-text="context.foo"><!-- Will output: "bar" --></span>

<div data-wp-context="{ foo: 'bob' }">
<div data-wp-context='{ "foo": "bob" }'>
<span data-wp-text="context.foo"><!-- Will output: "bob" --></span>
</div>

Expand Down Expand Up @@ -356,8 +356,7 @@ The callback passed as the reference receives [the event](https://developer.mozi

### `wp-on-async`

This directive is a more performant approach for `wp-on`. It immediately yields to main to avoid contributing to a long task, allowing other interactions that otherwise would be waiting on the main thread
to run sooner. Use this async version whenever there is no need for synchronous access to the `event` object, in particular the methods `event.preventDefault()`, `event.stopPropagation()`, and `event.stopImmediatePropagation()`.
This directive is a more performant approach for `wp-on`. It immediately yields to main to avoid contributing to a long task, allowing other interactions that otherwise would be waiting on the main thread to run sooner. Use this async version whenever there is no need for synchronous access to the `event` object, in particular the methods `event.preventDefault()`, `event.stopPropagation()`, and `event.stopImmediatePropagation()`.

### `wp-on-window`

Expand All @@ -369,8 +368,7 @@ This directive allows you to attach global window events like `resize`, `copy`,

[List of supported window events.](https://developer.mozilla.org/en-US/docs/Web/API/Window#events)

The syntax of this directive is `data-wp-on-window--[window-event]` (like `data-wp-on-window--resize`
or `data-wp-on-window--languagechange`).
The syntax of this directive is `data-wp-on-window--[window-event]` (like `data-wp-on-window--resize` or `data-wp-on-window--languagechange`).

```php
<div data-wp-on-window--resize="callbacks.logWidth"></div>
Expand Down Expand Up @@ -406,8 +404,7 @@ This directive allows you to attach global document events like `scroll`, `mouse

[List of supported document events.](https://developer.mozilla.org/en-US/docs/Web/API/Document#events)

The syntax of this directive is `data-wp-on-document--[document-event]` (like `data-wp-on-document--keydown`
or `data-wp-on-document--selectionchange`).
The syntax of this directive is `data-wp-on-document--[document-event]` (like `data-wp-on-document--keydown` or `data-wp-on-document--selectionchange`).

```php
<div data-wp-on-document--keydown="callbacks.logKeydown"></div>
Expand Down Expand Up @@ -520,6 +517,8 @@ Here's another example with several `wp-init` directives on the same DOM element
<summary><em>See store used with the directive above</em></summary>

```js
import { store, getElement } from '@wordpress/interactivity';

store( "myPlugin", {
callbacks: {
logTimeInit: () => console.log( `Init at ` + new Date() ),
Expand Down Expand Up @@ -882,10 +881,10 @@ const { state } = store( "myPlugin", {
GBP: 0.85,
},
get amountInUSD() {
return state.currencyExchange[ 'USD' ] * state.amount,
return state.currencyExchange[ 'USD' ] * state.amount;
},
get amountInGBP() {
return state.currencyExchange[ 'GBP' ] * state.amount,
return state.currencyExchange[ 'GBP' ] * state.amount;
},
},
} );
Expand Down Expand Up @@ -965,7 +964,7 @@ This approach enables some functionalities that make directives flexible and pow

*In the `view.js` file of each block* the developer can define both the state and the elements of the store referencing functions like actions, side effects or derived state.

The `store` method used to set the store in javascript can be imported from `@wordpress/interactivity`.
The `store` method used to set the store in JavaScript can be imported from `@wordpress/interactivity`.

```js
// store
Expand Down Expand Up @@ -1111,7 +1110,7 @@ store( "myPlugin", {
actions: {
log: () => {
const element = getElement();
// Logs "false"
// Logs attributes
console.log('element attributes => ', element.attributes)
},
},
Expand All @@ -1122,7 +1121,7 @@ The code will log:

```json
{
"data-wp-on--click": 'actions.increaseCounter',
"data-wp-on--click": 'actions.log',
"children": ['Log'],
"onclick": event => { evaluate(entry, event); }
}
Expand All @@ -1147,6 +1146,7 @@ store('mySliderPlugin', {
3_000
);
},
},
})
```

Expand Down Expand Up @@ -1245,7 +1245,7 @@ echo $processed_html;

will output:
```html
<div data-wp-text="create-block::state.greeting">Hello, World!</div>
<div data-wp-text="myPlugin::state.greeting">Hello, World!</div>
```

### wp_interactivity_data_wp_context
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.5
* Requires PHP: 7.2
* Version: 19.1.0
* Version: 19.2.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public static function decode( $context, $text ) {
*
* @since 6.6.0
*
* @global WP_Token_Map $html5_named_character_references
*
* @param string $context `attribute` for decoding attribute values, `data` otherwise.
* @param string $text Text document containing span of text to decode.
* @param int $at Optional. Byte offset into text where span begins, defaults to the beginning (0).
Expand Down
15 changes: 15 additions & 0 deletions lib/compat/wordpress-6.7/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,18 @@ function gutenberg_add_server_block_bindings_sources_to_editor_settings( $editor
}

add_filter( 'block_editor_settings_all', 'gutenberg_add_server_block_bindings_sources_to_editor_settings', 10 );

/**
* Initialize `canUpdateBlockBindings` editor setting if it doesn't exist. By default, it is `true` only for admin users.
*
* @param array $settings The block editor settings from the `block_editor_settings_all` filter.
* @return array The editor settings including `canUpdateBlockBindings`.
*/
function gutenberg_add_can_update_block_bindings_editor_setting( $editor_settings ) {
if ( empty( $editor_settings['canUpdateBlockBindings'] ) ) {
$editor_settings['canUpdateBlockBindings'] = current_user_can( 'manage_options' );
}
return $editor_settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_add_can_update_block_bindings_editor_setting', 10 );
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public static function decode( $context, $text ): string {
*
* @since 6.6.0
*
* @global WP_Token_Map $html5_named_character_references
*
* @param string $context `attribute` for decoding attribute values, `data` otherwise.
* @param string $text Text document containing span of text to decode.
* @param int $at Optional. Byte offset into text where span begins, defaults to the beginning (0).
Expand Down
9 changes: 3 additions & 6 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-full-page-client-side-navigation' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalFullPageClientSideNavigation = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-zoomed-out-patterns-tab', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableZoomedOutPatternsTab = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-quick-edit-dataviews', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalQuickEditDataViews = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-bindings-ui', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalBlockBindingsUI = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-media-processing', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalMediaProcessing = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-zoom-out-experiment', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableZoomOutExperiment = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
Expand Down
29 changes: 8 additions & 21 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-zoomed-out-patterns-tab',
__( 'Enable zoomed out view when patterns are browsed in the inserter', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable zoomed out view when selecting a pattern category in the main inserter.', 'gutenberg' ),
'id' => 'gutenberg-zoomed-out-patterns-tab',
)
);

add_settings_field(
'gutenberg-new-posts-dashboard',
__( 'Redesigned posts dashboard', 'gutenberg' ),
Expand All @@ -176,29 +164,28 @@ function gutenberg_initialize_experiments_settings() {
);

add_settings_field(
'gutenberg-block-bindings-ui',
__( 'UI to create block bindings', 'gutenberg' ),
'gutenberg-media-processing',
__( 'Client-side media processing', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Add UI to create and update block bindings in block inspector controls.', 'gutenberg' ),
'id' => 'gutenberg-block-bindings-ui',
'label' => __( 'Enable client-side media processing.', 'gutenberg' ),
'id' => 'gutenberg-media-processing',
)
);

add_settings_field(
'gutenberg-media-processing',
__( 'Client-side media processing', 'gutenberg' ),
'gutenberg-zoom-out-experiment',
__( 'Zoom out experiments', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable client-side media processing.', 'gutenberg' ),
'id' => 'gutenberg-media-processing',
'label' => __( 'Enable zoom out experiments; shows zoom out in the device preview and other zoom out experiments.', 'gutenberg' ),
'id' => 'gutenberg-zoom-out-experiment',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
Loading

0 comments on commit 55946ef

Please sign in to comment.