Make WordPress Core


Ignore:
Timestamp:
02/09/2024 06:20:12 PM (10 months ago)
Author:
youknowriad
Message:

Editor: Update the WordPress packages to Gutenberg 17.7RC1.

This brings the latest and greatest from Gutenberg.
The full changelog is available here
https://github.com/WordPress/gutenberg/releases/tag/v17.7.0-rc.1

Props youknowriad, get_dave.
See #60315.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/query.php

    r57377 r57578  
    1818 */
    1919function render_block_core_query( $attributes, $content, $block ) {
    20     $is_interactive = isset( $attributes['enhancedPagination'] ) && true === $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
     20    $is_interactive = isset( $attributes['enhancedPagination'] )
     21        && true === $attributes['enhancedPagination']
     22        && isset( $attributes['queryId'] );
    2123
    2224    // Enqueue the script module and add the necessary directives if the block is
    2325    // interactive.
    2426    if ( $is_interactive ) {
     27        $suffix = wp_scripts_get_suffix();
     28        if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
     29            $module_url = gutenberg_url( '/build/interactivity/query.min.js' );
     30        }
     31
     32        wp_register_script_module(
     33            '@wordpress/block-library/query',
     34            isset( $module_url ) ? $module_url : includes_url( "blocks/query/view{$suffix}.js" ),
     35            array(
     36                array(
     37                    'id'     => '@wordpress/interactivity',
     38                    'import' => 'static',
     39                ),
     40                array(
     41                    'id'     => '@wordpress/interactivity-router',
     42                    'import' => 'dynamic',
     43                ),
     44            ),
     45            defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
     46        );
    2547        wp_enqueue_script_module( '@wordpress/block-library/query' );
    2648
     
    3153            $p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] );
    3254            $p->set_attribute( 'data-wp-init', 'callbacks.setQueryRef' );
    33             // Use context to send translated strings.
    34             $p->set_attribute(
    35                 'data-wp-context',
    36                 wp_json_encode(
    37                     array(
    38                         'loadingText' => __( 'Loading page, please wait.' ),
    39                         'loadedText'  => __( 'Page Loaded.' ),
    40                     ),
    41                     JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
    42                 )
    43             );
     55            $p->set_attribute( 'data-wp-context', '{}' );
    4456            $content = $p->get_updated_html();
    45 
    46             // Mark the block as interactive.
    47             $block->block_type->supports['interactivity'] = true;
    48 
    49             // Add a div to announce messages using `aria-live`.
    50             $html_tag = 'div';
    51             if ( ! empty( $attributes['tagName'] ) ) {
    52                 $html_tag = esc_attr( $attributes['tagName'] );
    53             }
    54             $last_tag_position = strripos( $content, '</' . $html_tag . '>' );
    55             $content           = substr_replace(
    56                 $content,
    57                 '<div
    58                     class="screen-reader-text"
    59                     aria-live="polite"
    60                     data-wp-text="context.message"
    61                 ></div>
    62                 <div
    63                     class="wp-block-query__enhanced-pagination-animation"
    64                     data-wp-class--start-animation="state.startAnimation"
    65                     data-wp-class--finish-animation="state.finishAnimation"
    66                 ></div>',
    67                 $last_tag_position,
    68                 0
    69             );
    7057        }
    7158    }
     
    9986        )
    10087    );
    101 
    102     wp_register_script_module(
    103         '@wordpress/block-library/query',
    104         defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/query.min.js' ) : includes_url( 'blocks/query/view.min.js' ),
    105         array(
    106             array(
    107                 'id'     => '@wordpress/interactivity',
    108                 'import' => 'static',
    109             ),
    110             array(
    111                 'id'     => '@wordpress/interactivity-router',
    112                 'import' => 'dynamic',
    113             ),
    114         ),
    115         defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
    116     );
    11788}
    11889add_action( 'init', 'register_block_core_query' );
     
    134105    static $render_query_callback  = null;
    135106
    136     $is_interactive = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );
    137     $block_name     = $parsed_block['blockName'];
     107    $block_name              = $parsed_block['blockName'];
     108    $block_type              = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
     109    $has_enhanced_pagination = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );
     110    /*
     111     * Client side navigation can be true in two states:
     112     *  - supports.interactivity = true;
     113     *  - supports.interactivity.clientNavigation = true;
     114     */
     115    $supports_client_navigation = ( isset( $block_type->supports['interactivity']['clientNavigation'] ) && true === $block_type->supports['interactivity']['clientNavigation'] )
     116        || ( isset( $block_type->supports['interactivity'] ) && true === $block_type->supports['interactivity'] );
    138117
    139     if ( 'core/query' === $block_name && $is_interactive ) {
     118    if ( 'core/query' === $block_name && $has_enhanced_pagination ) {
    140119        $enhanced_query_stack[] = $parsed_block['attrs']['queryId'];
    141120
     
    152131             */
    153132            $render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
    154                 $is_interactive = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );
     133                $has_enhanced_pagination = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );
    155134
    156                 if ( ! $is_interactive ) {
     135                if ( ! $has_enhanced_pagination ) {
    157136                    return $content;
    158137                }
    159138
    160139                if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) {
    161                     $p = new WP_HTML_Tag_Processor( $content );
    162                     if ( $p->next_tag() ) {
    163                         $p->set_attribute( 'data-wp-navigation-disabled', 'true' );
    164                     }
    165                     $content = $p->get_updated_html();
     140                    // Disable navigation in the router store config.
     141                    wp_interactivity_config( 'core/router', array( 'clientNavigationDisabled' => true ) );
    166142                    $dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null;
    167143                }
     
    182158        ! empty( $enhanced_query_stack ) &&
    183159        isset( $block_name ) &&
    184         ( ! str_starts_with( $block_name, 'core/' ) || 'core/post-content' === $block_name )
     160        ( ! $supports_client_navigation )
    185161    ) {
    186162        foreach ( $enhanced_query_stack as $query_id ) {
Note: See TracChangeset for help on using the changeset viewer.