Make WordPress Core


Ignore:
Timestamp:
01/29/2024 09:04:18 PM (12 months ago)
Author:
youknowriad
Message:

Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.

This patch, somewhat small brings a lot to WordPress.
This includes features like:

  • DataViews.
  • Customization tools like box shadow, background size and repeat.
  • UI improvements in the site editor.
  • Preferences sharing between the post and site editors.
  • Unified panels and editors between post and site editors.
  • Improved template mode in the post editor.
  • Iterations to multiple interactive blocks.
  • Preparing the blocks and UI for pattern overrides.
  • and a lot more.

Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.

File:
1 edited

Legend:

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

    r57109 r57377  
    1818 */
    1919function render_block_core_query( $attributes, $content, $block ) {
    20     if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
     20    $is_interactive = isset( $attributes['enhancedPagination'] ) && true === $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
     21
     22    // Enqueue the script module and add the necessary directives if the block is
     23    // interactive.
     24    if ( $is_interactive ) {
     25        wp_enqueue_script_module( '@wordpress/block-library/query' );
     26
    2127        $p = new WP_HTML_Tag_Processor( $content );
    2228        if ( $p->next_tag() ) {
    2329            // Add the necessary directives.
    24             $p->set_attribute( 'data-wp-interactive', true );
    25             $p->set_attribute( 'data-wp-navigation-id', 'query-' . $attributes['queryId'] );
     30            $p->set_attribute( 'data-wp-interactive', '{"namespace":"core/query"}' );
     31            $p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] );
     32            $p->set_attribute( 'data-wp-init', 'callbacks.setQueryRef' );
    2633            // Use context to send translated strings.
    2734            $p->set_attribute(
     
    2936                wp_json_encode(
    3037                    array(
    31                         'core' => array(
    32                             'query' => array(
    33                                 'loadingText' => __( 'Loading page, please wait.' ),
    34                                 'loadedText'  => __( 'Page Loaded.' ),
    35                             ),
    36                         ),
     38                        'loadingText' => __( 'Loading page, please wait.' ),
     39                        'loadedText'  => __( 'Page Loaded.' ),
    3740                    ),
    3841                    JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
     
    5558                    class="screen-reader-text"
    5659                    aria-live="polite"
    57                     data-wp-text="context.core.query.message"
     60                    data-wp-text="context.message"
    5861                ></div>
    5962                <div
    6063                    class="wp-block-query__enhanced-pagination-animation"
    61                     data-wp-class--start-animation="selectors.core.query.startAnimation"
    62                     data-wp-class--finish-animation="selectors.core.query.finishAnimation"
     64                    data-wp-class--start-animation="state.startAnimation"
     65                    data-wp-class--finish-animation="state.finishAnimation"
    6366                ></div>',
    6467                $last_tag_position,
     
    6871    }
    6972
    70     $view_asset = 'wp-block-query-view';
    71     if ( ! wp_script_is( $view_asset ) ) {
    72         $script_handles = $block->block_type->view_script_handles;
    73         // If the script is not needed, and it is still in the `view_script_handles`, remove it.
    74         if (
    75             ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
    76             && in_array( $view_asset, $script_handles, true )
    77         ) {
    78             $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
    79         }
    80         // If the script is needed, but it was previously removed, add it again.
    81         if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) {
    82             $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
    83         }
    84     }
    85 
     73    // Add the styles to the block type if the block is interactive and remove
     74    // them if it's not.
    8675    $style_asset = 'wp-block-query';
    8776    if ( ! wp_style_is( $style_asset ) ) {
    8877        $style_handles = $block->block_type->style_handles;
    8978        // If the styles are not needed, and they are still in the `style_handles`, remove them.
    90         if (
    91             ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
    92             && in_array( $style_asset, $style_handles, true )
    93         ) {
     79        if ( ! $is_interactive && in_array( $style_asset, $style_handles, true ) ) {
    9480            $block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
    9581        }
    9682        // If the styles are needed, but they were previously removed, add them again.
    97         if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $style_asset, $style_handles, true ) ) {
     83        if ( $is_interactive && ! in_array( $style_asset, $style_handles, true ) ) {
    9884            $block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
    9985        }
     
    10288    return $content;
    10389}
    104 
    105 /**
    106  * Ensure that the view script has the `wp-interactivity` dependency.
    107  *
    108  * @since 6.4.0
    109  *
    110  * @global WP_Scripts $wp_scripts
    111  */
    112 function block_core_query_ensure_interactivity_dependency() {
    113     global $wp_scripts;
    114     if (
    115         isset( $wp_scripts->registered['wp-block-query-view'] ) &&
    116         ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-query-view']->deps, true )
    117     ) {
    118         $wp_scripts->registered['wp-block-query-view']->deps[] = 'wp-interactivity';
    119     }
    120 }
    121 
    122 add_action( 'wp_print_scripts', 'block_core_query_ensure_interactivity_dependency' );
    12390
    12491/**
     
    13198            'render_callback' => 'render_block_core_query',
    13299        )
     100    );
     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' )
    133116    );
    134117}
     
    151134    static $render_query_callback  = null;
    152135
    153     $block_name = $parsed_block['blockName'];
     136    $is_interactive = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );
     137    $block_name     = $parsed_block['blockName'];
    154138
    155     if (
    156         'core/query' === $block_name &&
    157         isset( $parsed_block['attrs']['enhancedPagination'] ) &&
    158         true === $parsed_block['attrs']['enhancedPagination'] &&
    159         isset( $parsed_block['attrs']['queryId'] )
    160     ) {
     139    if ( 'core/query' === $block_name && $is_interactive ) {
    161140        $enhanced_query_stack[] = $parsed_block['attrs']['queryId'];
    162141
     
    173152             */
    174153            $render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
    175                 $has_enhanced_pagination =
    176                     isset( $block['attrs']['enhancedPagination'] ) &&
    177                     true === $block['attrs']['enhancedPagination'] &&
    178                     isset( $block['attrs']['queryId'] );
     154                $is_interactive = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );
    179155
    180                 if ( ! $has_enhanced_pagination ) {
     156                if ( ! $is_interactive ) {
    181157                    return $content;
    182158                }
Note: See TracChangeset for help on using the changeset viewer.