Skip to content

Commit

Permalink
Editor: 2nd update of npm packages for 6.4 RC3.
Browse files Browse the repository at this point in the history
This second update for RC3 includes the following fixes:

* [WordPress/gutenberg#55724 Update label for lightbox editor UI] - string change.
* [WordPress/gutenberg#55720 Query: Require queryId for enhanced pagination to prevent PHP notices] and warnings.
* [WordPress/gutenberg#55714 Query block enhanced pagination: Detect inner plugin blocks during render] - which avoids turning off enhanced pagination in TT4, includes string changes.
* [WordPress/gutenberg#55309 Query Loop block: Reuse existing screen-reader-text CSS class for the enhanced pagination aria-live region].

Follow up to [57034], [56987], [56961], [56849], [56818], [56816].

Reviewed by davidbaumwald , jorbin.
Merges [57048] to the 6.4 branch.

Props afercia, aristath, artemiosans, czapla, darerodz, glendaviesnz, hellofromTonya, jameskoster, joen, luisherranz, mikachan, ocean90, peterwilsoncc, ramonopoly, rajinsharwar, swissspidy.
Fixes #59411.
Built from https://develop.svn.wordpress.org/branches/6.4@57049


git-svn-id: http://core.svn.wordpress.org/branches/6.4@56560 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
hellofromtonya committed Nov 1, 2023
1 parent 55f2881 commit acef64f
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 83 deletions.
2 changes: 1 addition & 1 deletion wp-includes/assets/script-loader-packages.min.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wp-includes/assets/script-loader-packages.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wp-includes/blocks/query-pagination-next.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
wp_reset_postdata(); // Restore original Post Data.
}

if ( $enhanced_pagination ) {
if ( $enhanced_pagination && isset( $content ) ) {
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag(
array(
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/blocks/query-pagination-previous.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
);
}

if ( $enhanced_pagination ) {
if ( $enhanced_pagination && isset( $content ) ) {
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag(
array(
Expand Down
107 changes: 98 additions & 9 deletions wp-includes/blocks/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*
* @since 6.4.0
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param string $block Block instance.
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block The block instance.
*
* @return string Returns the modified output of the query block.
*/
function render_block_core_query( $attributes, $content, $block ) {
if ( $attributes['enhancedPagination'] ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag() ) {
// Add the necessary directives.
Expand Down Expand Up @@ -48,7 +48,7 @@ function render_block_core_query( $attributes, $content, $block ) {
$content = substr_replace(
$content,
'<div
class="wp-block-query__enhanced-pagination-navigation-announce"
class="wp-block-query__enhanced-pagination-navigation-announce screen-reader-text"
aria-live="polite"
data-wp-text="context.core.query.message"
></div>
Expand All @@ -67,11 +67,14 @@ class="wp-block-query__enhanced-pagination-animation"
if ( ! wp_script_is( $view_asset ) ) {
$script_handles = $block->block_type->view_script_handles;
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
if ( ! $attributes['enhancedPagination'] && in_array( $view_asset, $script_handles, true ) ) {
if (
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
&& in_array( $view_asset, $script_handles, true )
) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
}
// If the script is needed, but it was previously removed, add it again.
if ( $attributes['enhancedPagination'] && ! in_array( $view_asset, $script_handles, true ) ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
}
}
Expand All @@ -80,11 +83,14 @@ class="wp-block-query__enhanced-pagination-animation"
if ( ! wp_style_is( $style_asset ) ) {
$style_handles = $block->block_type->style_handles;
// If the styles are not needed, and they are still in the `style_handles`, remove them.
if ( ! $attributes['enhancedPagination'] && in_array( $style_asset, $style_handles, true ) ) {
if (
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
&& in_array( $style_asset, $style_handles, true )
) {
$block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
}
// If the styles are needed, but they were previously removed, add them again.
if ( $attributes['enhancedPagination'] && ! in_array( $style_asset, $style_handles, true ) ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $style_asset, $style_handles, true ) ) {
$block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
}
}
Expand Down Expand Up @@ -123,3 +129,86 @@ function register_block_core_query() {
);
}
add_action( 'init', 'register_block_core_query' );

/**
* Traverse the tree of blocks looking for any plugin block (i.e., a block from
* an installed plugin) inside a Query block with the enhanced pagination
* enabled. If at least one is found, the enhanced pagination is effectively
* disabled to prevent any potential incompatibilities.
*
* @since 6.4.0
*
* @param array $parsed_block The block being rendered.
* @return string Returns the parsed block, unmodified.
*/
function block_core_query_disable_enhanced_pagination( $parsed_block ) {
static $enhanced_query_stack = array();
static $dirty_enhanced_queries = array();
static $render_query_callback = null;

$block_name = $parsed_block['blockName'];

if (
'core/query' === $block_name &&
isset( $parsed_block['attrs']['enhancedPagination'] ) &&
true === $parsed_block['attrs']['enhancedPagination'] &&
isset( $parsed_block['attrs']['queryId'] )
) {
$enhanced_query_stack[] = $parsed_block['attrs']['queryId'];

if ( ! isset( $render_query_callback ) ) {
/**
* Filter that disables the enhanced pagination feature during block
* rendering when a plugin block has been found inside. It does so
* by adding an attribute called `data-wp-navigation-disabled` which
* is later handled by the front-end logic.
*
* @param string $content The block content.
* @param array $block The full block, including name and attributes.
* @return string Returns the modified output of the query block.
*/
$render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
$has_enhanced_pagination =
isset( $block['attrs']['enhancedPagination'] ) &&
true === $block['attrs']['enhancedPagination'] &&
isset( $block['attrs']['queryId'] );

if ( ! $has_enhanced_pagination ) {
return $content;
}

if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) {
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag() ) {
$p->set_attribute( 'data-wp-navigation-disabled', 'true' );
}
$content = $p->get_updated_html();
$dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null;
}

array_pop( $enhanced_query_stack );

if ( empty( $enhanced_query_stack ) ) {
remove_filter( 'render_block_core/query', $render_query_callback );
$render_query_callback = null;
}

return $content;
};

add_filter( 'render_block_core/query', $render_query_callback, 10, 2 );
}
} elseif (
! empty( $enhanced_query_stack ) &&
isset( $block_name ) &&
( ! str_starts_with( $block_name, 'core/' ) || 'core/post-content' === $block_name )
) {
foreach ( $enhanced_query_stack as $query_id ) {
$dirty_enhanced_queries[ $query_id ] = true;
}
}

return $parsed_block;
}

add_filter( 'render_block_data', 'block_core_query_disable_enhanced_pagination', 10, 1 );
10 changes: 0 additions & 10 deletions wp-includes/blocks/query/style-rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,4 @@
to{
opacity:0;
}
}
.wp-block-query__enhanced-pagination-navigation-announce{
clip:rect(0, 0, 0, 0);
border:0;
height:1px;
margin:-1px;
overflow:hidden;
padding:0;
position:absolute;
width:1px;
}
2 changes: 1 addition & 1 deletion wp-includes/blocks/query/style-rtl.min.css

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

10 changes: 0 additions & 10 deletions wp-includes/blocks/query/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,4 @@
to{
opacity:0;
}
}
.wp-block-query__enhanced-pagination-navigation-announce{
clip:rect(0, 0, 0, 0);
border:0;
height:1px;
margin:-1px;
overflow:hidden;
padding:0;
position:absolute;
width:1px;
}
2 changes: 1 addition & 1 deletion wp-includes/blocks/query/style.min.css

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

2 changes: 1 addition & 1 deletion wp-includes/blocks/query/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '19b95fd73ecd65d97c60');
<?php return array('dependencies' => array(), 'version' => 'f932eea8999458215fe1');
6 changes: 4 additions & 2 deletions wp-includes/blocks/query/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const isValidEvent = event => event.button === 0 &&
ref,
context
}) => {
if (isValidLink(ref) && isValidEvent(event)) {
const isDisabled = ref.closest('[data-wp-navigation-id]')?.dataset.wpNavigationDisabled;
if (isValidLink(ref) && isValidEvent(event) && !isDisabled) {
event.preventDefault();
const id = ref.closest('[data-wp-navigation-id]').dataset.wpNavigationId;

Expand Down Expand Up @@ -69,7 +70,8 @@ const isValidEvent = event => event.button === 0 &&
prefetch: async ({
ref
}) => {
if (isValidLink(ref)) {
const isDisabled = ref.closest('[data-wp-navigation-id]')?.dataset.wpNavigationDisabled;
if (isValidLink(ref) && !isDisabled) {
await (0,_wordpress_interactivity__WEBPACK_IMPORTED_MODULE_0__/* .prefetch */ .tL)(ref.href);
}
}
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/blocks/query/view.min.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '3dd5dbc0a377c7b7336f');
<?php return array('dependencies' => array(), 'version' => 'ecab5647d5d9321e0101');
2 changes: 1 addition & 1 deletion wp-includes/blocks/query/view.min.js

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

4 changes: 2 additions & 2 deletions wp-includes/js/dist/block-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58425,12 +58425,12 @@ function ImageSettingsPanel({
// Global Styles.
, {
hasValue: () => !!value?.lightbox,
label: (0,external_wp_i18n_namespaceObject.__)('Expand on Click'),
label: (0,external_wp_i18n_namespaceObject.__)('Expand on click'),
onDeselect: resetLightbox,
isShownByDefault: true,
panelId: panelId
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.ToggleControl, {
label: (0,external_wp_i18n_namespaceObject.__)('Expand on Click'),
label: (0,external_wp_i18n_namespaceObject.__)('Expand on click'),
checked: lightboxChecked,
onChange: onChangeLightbox
}))));
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/js/dist/block-editor.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit acef64f

Please sign in to comment.