Make WordPress Core


Ignore:
Timestamp:
10/21/2025 07:11:53 AM (3 months ago)
Author:
ellatrix
Message:

Editor: update packages.

Updates the packages to match Gutenberg version 21.9.0 RC2.

Also updates the sync script to work with the new package-lock.json format.
Some reusable block tests were adjusted to work with more render arguments.
Added core-data to the ignore list for verify:source-maps because Yjs has been bundled by accident. To be removed in a follow-up. See https://core.trac.wordpress.org/ticket/64120. See https://github.com/WordPress/gutenberg/pull/72503.

See: https://github.com/WordPress/wordpress-develop/pull/10355.
See: https://core.trac.wordpress.org/ticket/64117.

Props ellatrix, dmsnell.
Fixes #64117.

File:
1 edited

Legend:

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

    r59775 r61009  
    2323    }
    2424
    25     $p = new WP_HTML_Tag_Processor( $content );
    26 
    27     if ( ! $p->next_tag( 'img' ) || ! $p->get_attribute( 'src' ) ) {
     25    $processor = new class( $content ) extends WP_HTML_Tag_Processor {
     26        /**
     27         * Return input span for an empty FIGCAPTION element.
     28         *
     29         * Returns span of input for an empty FIGCAPTION, if currently matched on a
     30         * FIGCAPTION opening tag and if the element is properly closed and empty.
     31         *
     32         * @since 6.9.0
     33         *
     34         * @return WP_HTML_Span|false Span of input if the element is empty; otherwise false.
     35         */
     36        public function block_core_image_extract_empty_figcaption_element() {
     37            $this->set_bookmark( 'here' );
     38            $opener = $this->bookmarks['here'];
     39
     40            // Allow comments within the definition of “empty.”
     41            while ( $this->next_token() && '#comment' === $this->get_token_name() ) {
     42                continue;
     43            }
     44
     45            if ( 'FIGCAPTION' !== $this->get_tag() || ! $this->is_tag_closer() ) {
     46                return false;
     47            }
     48
     49            $this->set_bookmark( 'here' );
     50            $closer = $this->bookmarks['here'];
     51
     52            return new WP_HTML_Span( $opener->start, $closer->start + $closer->length - $opener->start );
     53        }
     54    };
     55
     56    if ( ! $processor->next_tag( 'img' ) || ! $processor->get_attribute( 'src' ) ) {
    2857        return '';
    2958    }
     
    3766        // See https://github.com/WordPress/gutenberg/issues/62886 for why this is needed.
    3867        $id                       = $attributes['id'];
    39         $image_classnames         = $p->get_attribute( 'class' );
     68        $image_classnames         = $processor->get_attribute( 'class' );
    4069        $class_with_binding_value = "wp-image-$id";
    4170        if ( is_string( $image_classnames ) && ! str_contains( $image_classnames, $class_with_binding_value ) ) {
    4271            $image_classnames = preg_replace( '/wp-image-(\d+)/', $class_with_binding_value, $image_classnames );
    43             $p->set_attribute( 'class', $image_classnames );
     72            $processor->set_attribute( 'class', $image_classnames );
    4473        }
    4574    }
     
    5584        // third parties may be filtering its value.
    5685        $data_id = $has_id_binding ? $attributes['id'] : $attributes['data-id'];
    57         $p->set_attribute( 'data-id', $data_id );
     86        $processor->set_attribute( 'data-id', $data_id );
     87    }
     88
     89    /*
     90     * If the `caption` attribute is empty and we encounter a `<figcaption>` element,
     91     * we take note of its span so we can remove it later.
     92     */
     93    if ( $processor->next_tag( 'FIGCAPTION' ) && empty( $attributes['caption'] ) ) {
     94        $figcaption_span = $processor->block_core_image_extract_empty_figcaption_element();
    5895    }
    5996
     
    89126    }
    90127
    91     return $p->get_updated_html();
     128    $output = $processor->get_updated_html();
     129    if ( ! empty( $figcaption_span ) ) {
     130        return substr( $output, 0, $figcaption_span->start ) . substr( $output, $figcaption_span->start + $figcaption_span->length );
     131    }
     132    return $output;
    92133}
    93134
     
    101142 * @param array $block Block data.
    102143 *
    103  * @return array Filtered block data.
     144 * @return array|null Filtered block data.
    104145 */
    105146function block_core_image_get_lightbox_settings( $block ) {
     
    142183     * lightbox behavior.
    143184     */
    144     $p = new WP_HTML_Tag_Processor( $block_content );
    145     if ( $p->next_tag( 'figure' ) ) {
    146         $p->set_bookmark( 'figure' );
    147     }
    148     if ( ! $p->next_tag( 'img' ) ) {
     185    $processor = new WP_HTML_Tag_Processor( $block_content );
     186    if ( $processor->next_tag( 'figure' ) ) {
     187        $processor->set_bookmark( 'figure' );
     188    }
     189    if ( ! $processor->next_tag( 'img' ) ) {
    149190        return $block_content;
    150191    }
    151192
    152     $alt               = $p->get_attribute( 'alt' );
    153     $img_uploaded_src  = $p->get_attribute( 'src' );
    154     $img_class_names   = $p->get_attribute( 'class' );
    155     $img_styles        = $p->get_attribute( 'style' );
     193    $alt               = $processor->get_attribute( 'alt' );
     194    $img_uploaded_src  = $processor->get_attribute( 'src' );
     195    $img_class_names   = $processor->get_attribute( 'class' );
     196    $img_styles        = $processor->get_attribute( 'style' );
    156197    $img_width         = 'none';
    157198    $img_height        = 'none';
     
    167208
    168209    // Figure.
    169     $p->seek( 'figure' );
    170     $figure_class_names = $p->get_attribute( 'class' );
    171     $figure_styles      = $p->get_attribute( 'style' );
     210    $processor->seek( 'figure' );
     211    $figure_class_names = $processor->get_attribute( 'class' );
     212    $figure_styles      = $processor->get_attribute( 'style' );
    172213
    173214    // Create unique id and set the image metadata in the state.
     
    194235    );
    195236
    196     $p->add_class( 'wp-lightbox-container' );
    197     $p->set_attribute( 'data-wp-interactive', 'core/image' );
    198     $p->set_attribute(
     237    $processor->add_class( 'wp-lightbox-container' );
     238    $processor->set_attribute( 'data-wp-interactive', 'core/image' );
     239    $processor->set_attribute(
    199240        'data-wp-context',
    200241        wp_json_encode(
     
    205246        )
    206247    );
     248    $processor->set_attribute( 'data-wp-key', $unique_image_id );
    207249
    208250    // Image.
    209     $p->next_tag( 'img' );
    210     $p->set_attribute( 'data-wp-init', 'callbacks.setButtonStyles' );
    211     $p->set_attribute( 'data-wp-on-async--load', 'callbacks.setButtonStyles' );
    212     $p->set_attribute( 'data-wp-on-async-window--resize', 'callbacks.setButtonStyles' );
     251    $processor->next_tag( 'img' );
     252    $processor->set_attribute( 'data-wp-init', 'callbacks.setButtonStyles' );
     253    $processor->set_attribute( 'data-wp-on-async--load', 'callbacks.setButtonStyles' );
     254    $processor->set_attribute( 'data-wp-on-async-window--resize', 'callbacks.setButtonStyles' );
    213255    // Sets an event callback on the `img` because the `figure` element can also
    214256    // contain a caption, and we don't want to trigger the lightbox when the
    215257    // caption is clicked.
    216     $p->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' );
    217     $p->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' );
    218     $p->set_attribute( 'data-wp-class--show', 'state.isContentVisible' );
    219 
    220     $body_content = $p->get_updated_html();
     258    $processor->set_attribute( 'data-wp-on-async--click', 'actions.showLightbox' );
     259    $processor->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' );
     260    $processor->set_attribute( 'data-wp-class--show', 'state.isContentVisible' );
     261
     262    $body_content = $processor->get_updated_html();
    221263
    222264    // Adds a button alongside image in the body content.
     
    273315            class="wp-lightbox-overlay zoom"
    274316            data-wp-interactive="core/image"
     317            data-wp-router-region='{ "id": "core/image-overlay", "attachTo": "body" }'
     318            data-wp-key="wp-lightbox-overlay"
    275319            data-wp-context='{}'
    276320            data-wp-bind--role="state.roleAttribute"
     
    278322            data-wp-bind--aria-modal="state.ariaModal"
    279323            data-wp-class--active="state.overlayEnabled"
    280             data-wp-class--show-closing-animation="state.showClosingAnimation"
     324            data-wp-class--show-closing-animation="state.overlayOpened"
    281325            data-wp-watch="callbacks.setOverlayFocus"
    282326            data-wp-on--keydown="actions.handleKeydown"
Note: See TracChangeset for help on using the changeset viewer.