mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Editor: Update npm packages ahead of 6.4 RC1.
Updates the npm packages and code for: * [https://github.com/WordPress/gutenberg/pull/55121 List: fix forward merging of nested list] * [https://github.com/WordPress/gutenberg/pull/55182 Update consent string for using private APIs.] * [https://github.com/WordPress/gutenberg/pull/55204 useBlockSettings: add missing useMemo dependencies] * [https://github.com/WordPress/gutenberg/pull/55120 Remove the lightbox filter and view file when the lightbox setting is disabled.] * [https://github.com/WordPress/gutenberg/pull/55245 Patterns: Remove the version enforcement for npm in engines field] * [https://github.com/WordPress/gutenberg/pull/55237 Remove `@return void` from PHP function docs] * [https://github.com/WordPress/gutenberg/pull/55141 Image: Disable lightbox editor UI for linked images] * [https://github.com/WordPress/gutenberg/pull/55269 Image: Stop crashing with Lightbox on image blocks without an image] * [https://github.com/WordPress/gutenberg/pull/55021 Update fullscreen icon] * [https://github.com/WordPress/gutenberg/pull/55217 Template Part block: Fall back to current theme if no theme attribute is given.] This change is part of fix for a performance regression re-introduced by [56818]. References: * [https://github.com/WordPress/gutenberg/pull/55298 Gutenberg PR 55298] Cherry-pick commits Follow-up to [56818], [56816]. Props ellatrix, peterwilsoncc, jsnajdr, afercia, gziolo, isabel_brison, artemiosans, richtabor, bernhard-reiter, flixos90, mikachan, spacedmonkey, hellofromTonya. See #59583, #59411. git-svn-id: https://develop.svn.wordpress.org/trunk@56849 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -16,11 +16,13 @@
|
||||
* @return string The block content with the data-id attribute added.
|
||||
*/
|
||||
function render_block_core_image( $attributes, $content, $block ) {
|
||||
if ( false === stripos( $content, '<img' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$processor = new WP_HTML_Tag_Processor( $content );
|
||||
$processor->next_tag( 'img' );
|
||||
|
||||
if ( $processor->get_attribute( 'src' ) === null ) {
|
||||
if ( ! $processor->next_tag( 'img' ) || null === $processor->get_attribute( 'src' ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -32,45 +34,47 @@ function render_block_core_image( $attributes, $content, $block ) {
|
||||
$processor->set_attribute( 'data-id', $attributes['data-id'] );
|
||||
}
|
||||
|
||||
$lightbox_enabled = false;
|
||||
$link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
|
||||
$lightbox_settings = block_core_image_get_lightbox_settings( $block->parsed_block );
|
||||
|
||||
// If the lightbox is enabled and the image is not linked, flag the lightbox to be rendered.
|
||||
if ( isset( $lightbox_settings ) && 'none' === $link_destination ) {
|
||||
$view_js_file_handle = 'wp-block-image-view';
|
||||
$script_handles = $block->block_type->view_script_handles;
|
||||
|
||||
if ( isset( $lightbox_settings['enabled'] ) && true === $lightbox_settings['enabled'] ) {
|
||||
$lightbox_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If at least one block in the page has the lightbox, mark the block type as interactive.
|
||||
if ( $lightbox_enabled ) {
|
||||
/*
|
||||
* If the lightbox is enabled and the image is not linked, add the filter
|
||||
* and the JavaScript view file.
|
||||
*/
|
||||
if (
|
||||
isset( $lightbox_settings ) &&
|
||||
'none' === $link_destination &&
|
||||
isset( $lightbox_settings['enabled'] ) &&
|
||||
true === $lightbox_settings['enabled']
|
||||
) {
|
||||
$block->block_type->supports['interactivity'] = true;
|
||||
}
|
||||
|
||||
// Determine whether the view script should be enqueued or not.
|
||||
$view_js_file = 'wp-block-image-view';
|
||||
if ( ! wp_script_is( $view_js_file ) ) {
|
||||
$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 ( ! $lightbox_enabled && in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
||||
if ( ! in_array( $view_js_file_handle, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file_handle ) );
|
||||
}
|
||||
// If the script is needed, but it was previously removed, add it again.
|
||||
if ( $lightbox_enabled && ! in_array( $view_js_file, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $lightbox_enabled ) {
|
||||
// This render needs to happen in a filter with priority 15 to ensure that it
|
||||
// runs after the duotone filter and that duotone styles are applied to the image
|
||||
// in the lightbox. We also need to ensure that the lightbox works with any plugins
|
||||
// that might use filters as well. We can consider removing this in the future if the
|
||||
// way the blocks are rendered changes, or if a new kind of filter is introduced.
|
||||
/*
|
||||
* This render needs to happen in a filter with priority 15 to ensure
|
||||
* that it runs after the duotone filter and that duotone styles are
|
||||
* applied to the image in the lightbox. We also need to ensure that the
|
||||
* lightbox works with any plugins that might use filters as well. We
|
||||
* can consider removing this in the future if the way the blocks are
|
||||
* rendered changes, or if a new kind of filter is introduced.
|
||||
*/
|
||||
add_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15, 2 );
|
||||
} else {
|
||||
/*
|
||||
* Remove the filter and the JavaScript view file if previously added by
|
||||
* other Image blocks.
|
||||
*/
|
||||
remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 );
|
||||
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
||||
if ( in_array( $view_js_file_handle, $script_handles, true ) ) {
|
||||
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
||||
}
|
||||
}
|
||||
|
||||
return $processor->get_updated_html();
|
||||
@@ -123,11 +127,28 @@ function block_core_image_get_lightbox_settings( $block ) {
|
||||
* @return string Filtered block content.
|
||||
*/
|
||||
function block_core_image_render_lightbox( $block_content, $block ) {
|
||||
/*
|
||||
* If it's not possible that an IMG element exists then return the given
|
||||
* block content as-is. It may be that there's no actual image in the block
|
||||
* or it could be that another plugin already modified this HTML.
|
||||
*/
|
||||
if ( false === stripos( $block_content, '<img' ) ) {
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
$processor = new WP_HTML_Tag_Processor( $block_content );
|
||||
|
||||
$aria_label = __( 'Enlarge image' );
|
||||
|
||||
$processor->next_tag( 'img' );
|
||||
/*
|
||||
* If there's definitely no IMG element in the block then return the given
|
||||
* block content as-is. There's nothing that this code can knowingly modify
|
||||
* to add the lightbox behavior.
|
||||
*/
|
||||
if ( ! $processor->next_tag( 'img' ) ) {
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
$alt_attribute = $processor->get_attribute( 'alt' );
|
||||
|
||||
// An empty alt attribute `alt=""` is valid for decorative images.
|
||||
@@ -310,8 +331,6 @@ HTML;
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @global WP_Scripts $wp_scripts
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function block_core_image_ensure_interactivity_dependency() {
|
||||
global $wp_scripts;
|
||||
@@ -327,8 +346,6 @@ add_action( 'wp_print_scripts', 'block_core_image_ensure_interactivity_dependenc
|
||||
|
||||
/**
|
||||
* Registers the `core/image` block on server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function register_block_core_image() {
|
||||
register_block_type_from_metadata(
|
||||
|
||||
Reference in New Issue
Block a user