Skip to content

Commit

Permalink
Editor: Update npm packages ahead of 6.4 RC1.
Browse files Browse the repository at this point in the history
Updates the npm packages and code for:

* [WordPress/gutenberg#55121 List: fix forward merging of nested list]

* [WordPress/gutenberg#55182 Update consent string for using private APIs.]

* [WordPress/gutenberg#55204 useBlockSettings: add missing useMemo dependencies]

* [WordPress/gutenberg#55120 Remove the lightbox filter and view file when the lightbox setting is disabled.]

* [WordPress/gutenberg#55245 Patterns: Remove the version enforcement for npm in engines field]

* [WordPress/gutenberg#55237 Remove `@return void` from PHP function docs]

* [WordPress/gutenberg#55141 Image: Disable lightbox editor UI for linked images]

* [WordPress/gutenberg#55269 Image: Stop crashing with Lightbox on image blocks without an image]

* [WordPress/gutenberg#55021 Update fullscreen icon]

* [WordPress/gutenberg#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:
* [WordPress/gutenberg#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.
Built from https://develop.svn.wordpress.org/trunk@56849


git-svn-id: https://core.svn.wordpress.org/trunk@56361 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
hellofromtonya committed Oct 12, 2023
1 parent 5f72548 commit 58d8b09
Show file tree
Hide file tree
Showing 41 changed files with 118 additions and 108 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.

91 changes: 54 additions & 37 deletions wp-includes/blocks/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}

Expand All @@ -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 ) {

if ( isset( $lightbox_settings['enabled'] ) && true === $lightbox_settings['enabled'] ) {
$lightbox_enabled = true;
}
}
$view_js_file_handle = 'wp-block-image-view';
$script_handles = $block->block_type->view_script_handles;

// 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 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 ( ! 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 ( $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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -310,8 +331,6 @@ function block_core_image_render_lightbox( $block_content, $block ) {
* @since 6.4.0
*
* @global WP_Scripts $wp_scripts
*
* @return void
*/
function block_core_image_ensure_interactivity_dependency() {
global $wp_scripts;
Expand All @@ -327,8 +346,6 @@ function block_core_image_ensure_interactivity_dependency() {

/**
* Registers the `core/image` block on server.
*
* @return void
*/
function register_block_core_image() {
register_block_type_from_metadata(
Expand Down
3 changes: 0 additions & 3 deletions wp-includes/blocks/pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

/**
* Registers the `core/pattern` block on the server.
*
* @return void
*/
function register_block_core_pattern() {
register_block_type_from_metadata(
Expand Down Expand Up @@ -46,7 +44,6 @@ function render_block_core_pattern( $attributes ) {
// Backward compatibility for handling Block Hooks and injecting the theme attribute in the Gutenberg plugin.
// This can be removed when the minimum supported WordPress is >= 6.4.
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && ! function_exists( 'traverse_and_serialize_blocks' ) ) {
$content = _inject_theme_attribute_in_block_template_content( $content );
$blocks = parse_blocks( $content );
$content = gutenberg_serialize_blocks( $blocks );
}
Expand Down
4 changes: 0 additions & 4 deletions wp-includes/blocks/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ function classnames_for_block_core_search( $attributes ) {
* @param array $wrapper_styles Current collection of wrapper styles.
* @param array $button_styles Current collection of button styles.
* @param array $input_styles Current collection of input styles.
*
* @return void
*/
function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) {
$is_button_inside = isset( $attributes['buttonPosition'] ) && 'button-inside' === $attributes['buttonPosition'];
Expand Down Expand Up @@ -327,8 +325,6 @@ function apply_block_core_search_border_style( $attributes, $property, $side, &$
* @param array $wrapper_styles Current collection of wrapper styles.
* @param array $button_styles Current collection of button styles.
* @param array $input_styles Current collection of input styles.
*
* @return void
*/
function apply_block_core_search_border_styles( $attributes, $property, &$wrapper_styles, &$button_styles, &$input_styles ) {
apply_block_core_search_border_style( $attributes, $property, null, $wrapper_styles, $button_styles, $input_styles );
Expand Down
11 changes: 4 additions & 7 deletions wp-includes/blocks/template-part.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ function render_block_core_template_part( $attributes ) {
$template_part_id = null;
$content = null;
$area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
$theme = isset( $attributes['theme'] ) ? $attributes['theme'] : get_stylesheet();

if (
isset( $attributes['slug'] ) &&
isset( $attributes['theme'] ) &&
get_stylesheet() === $attributes['theme']
) {
$template_part_id = $attributes['theme'] . '//' . $attributes['slug'];
if ( isset( $attributes['slug'] ) && get_stylesheet() === $theme ) {
$template_part_id = $theme . '//' . $attributes['slug'];
$template_part_query = new WP_Query(
array(
'post_type' => 'wp_template_part',
Expand All @@ -34,7 +31,7 @@ function render_block_core_template_part( $attributes ) {
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => $attributes['theme'],
'terms' => $theme,
),
),
'posts_per_page' => 1,
Expand Down
6 changes: 3 additions & 3 deletions wp-includes/js/dist/block-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10910,7 +10910,7 @@ var external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
const {
lock,
unlock
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/block-editor');
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/block-editor');

;// CONCATENATED MODULE: ./node_modules/@wordpress/block-editor/build-module/store/index.js
/**
Expand Down Expand Up @@ -14192,7 +14192,7 @@ function useBlockSettings(name, parentLayout) {
layout,
parentLayout
};
}, [fontFamilies, fontSizes, customFontSize, fontStyle, fontWeight, lineHeight, textColumns, textDecoration, textTransform, letterSpacing, writingMode, padding, margin, blockGap, spacingSizes, units, minHeight, layout, parentLayout, borderColor, borderRadius, borderStyle, borderWidth, customColorsEnabled, customColors, customDuotone, themeColors, defaultColors, defaultPalette, defaultDuotone, userDuotonePalette, themeDuotonePalette, defaultDuotonePalette, userGradientPalette, themeGradientPalette, defaultGradientPalette, defaultGradients, areCustomGradientsEnabled, isBackgroundEnabled, isLinkEnabled, isTextEnabled]);
}, [fontFamilies, fontSizes, customFontSize, fontStyle, fontWeight, lineHeight, textColumns, textDecoration, textTransform, letterSpacing, writingMode, padding, margin, blockGap, spacingSizes, units, minHeight, layout, parentLayout, borderColor, borderRadius, borderStyle, borderWidth, customColorsEnabled, customColors, customDuotone, themeColors, defaultColors, defaultPalette, defaultDuotone, userDuotonePalette, themeDuotonePalette, defaultDuotonePalette, userGradientPalette, themeGradientPalette, defaultGradientPalette, defaultGradients, areCustomGradientsEnabled, isBackgroundEnabled, isLinkEnabled, isTextEnabled, isHeadingEnabled, isButtonEnabled]);
return useSettingsForBlockElement(rawSettings, name);
}

Expand Down Expand Up @@ -45430,7 +45430,7 @@ const fullscreen = (0,external_wp_element_namespaceObject.createElement)(externa
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
d: "M4.2 9h1.5V5.8H9V4.2H4.2V9zm14 9.2H15v1.5h4.8V15h-1.5v3.2zM15 4.2v1.5h3.2V9h1.5V4.2H15zM5.8 15H4.2v4.8H9v-1.5H5.8V15z"
d: "M6 4a2 2 0 0 0-2 2v3h1.5V6a.5.5 0 0 1 .5-.5h3V4H6Zm3 14.5H6a.5.5 0 0 1-.5-.5v-3H4v3a2 2 0 0 0 2 2h3v-1.5Zm6 1.5v-1.5h3a.5.5 0 0 0 .5-.5v-3H20v3a2 2 0 0 1-2 2h-3Zm3-16a2 2 0 0 1 2 2v3h-1.5V6a.5.5 0 0 0-.5-.5h-3V4h3Z"
}));
/* harmony default export */ var library_fullscreen = (fullscreen);

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/js/dist/block-editor.min.js

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions wp-includes/js/dist/block-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ var external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
const {
lock,
unlock
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/block-library');
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/block-library');

;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/embed/util.js

Expand Down Expand Up @@ -6078,7 +6078,7 @@ const fullscreen = (0,external_wp_element_namespaceObject.createElement)(externa
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
d: "M4.2 9h1.5V5.8H9V4.2H4.2V9zm14 9.2H15v1.5h4.8V15h-1.5v3.2zM15 4.2v1.5h3.2V9h1.5V4.2H15zM5.8 15H4.2v4.8H9v-1.5H5.8V15z"
d: "M6 4a2 2 0 0 0-2 2v3h1.5V6a.5.5 0 0 1 .5-.5h3V4H6Zm3 14.5H6a.5.5 0 0 1-.5-.5v-3H4v3a2 2 0 0 0 2 2h3v-1.5Zm6 1.5v-1.5h3a.5.5 0 0 0 .5-.5v-3H20v3a2 2 0 0 1-2 2h-3Zm3-16a2 2 0 0 1 2 2v3h-1.5V6a.5.5 0 0 0-.5-.5h-3V4h3Z"
}));
/* harmony default export */ var library_fullscreen = (fullscreen);

Expand Down Expand Up @@ -24122,6 +24122,7 @@ function image_Image({
const lightboxSetting = (0,external_wp_blockEditor_namespaceObject.useSetting)('lightbox');
const showLightboxToggle = !!lightbox || lightboxSetting?.allowEditing === true;
const lightboxChecked = !!lightbox?.enabled || !lightbox && !!lightboxSetting?.enabled;
const lightboxToggleDisabled = linkDestination !== 'none';
const dimensionsControl = (0,external_wp_element_namespaceObject.createElement)(DimensionsTool, {
value: {
width,
Expand Down Expand Up @@ -24255,7 +24256,9 @@ function image_Image({
enabled: newValue
}
});
}
},
disabled: lightboxToggleDisabled,
help: lightboxToggleDisabled ? (0,external_wp_i18n_namespaceObject.__)('“Expand on click” scales the image up, and can’t be combined with a link.') : ''
})))), (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.InspectorControls, {
group: "advanced"
}, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, {
Expand Down Expand Up @@ -27571,6 +27574,19 @@ function useMerge(clientId, onMerge) {
return getBlockOrder(order[0])[0];
}
return forward => {
function mergeWithNested(clientIdA, clientIdB) {
registry.batch(() => {
// When merging a sub list item with a higher next list item, we
// also need to move any nested list items. Check if there's a
// listed list, and append its nested list items to the current
// list.
const [nestedListClientId] = getBlockOrder(clientIdB);
if (nestedListClientId) {
moveBlocksToPosition(getBlockOrder(nestedListClientId), nestedListClientId, getBlockRootClientId(clientIdA));
}
mergeBlocks(clientIdA, clientIdB);
});
}
if (forward) {
const nextBlockClientId = getNextId(clientId);
if (!nextBlockClientId) {
Expand All @@ -27580,10 +27596,7 @@ function useMerge(clientId, onMerge) {
if (getParentListItemId(nextBlockClientId)) {
outdentListItem(nextBlockClientId);
} else {
registry.batch(() => {
moveBlocksToPosition(getBlockOrder(nextBlockClientId), nextBlockClientId, getPreviousBlockClientId(nextBlockClientId));
mergeBlocks(clientId, nextBlockClientId);
});
mergeWithNested(clientId, nextBlockClientId);
}
} else {
// Merging is only done from the top level. For lowel levels, the
Expand All @@ -27593,17 +27606,7 @@ function useMerge(clientId, onMerge) {
outdentListItem(clientId);
} else if (previousBlockClientId) {
const trailingId = getTrailingId(previousBlockClientId);
registry.batch(() => {
// When merging a list item with a previous trailing list
// item, we also need to move any nested list items. First,
// check if there's a listed list. If there's a nested list,
// append its nested list items to the trailing list.
const [nestedListClientId] = getBlockOrder(clientId);
if (nestedListClientId) {
moveBlocksToPosition(getBlockOrder(nestedListClientId), nestedListClientId, getBlockRootClientId(trailingId));
}
mergeBlocks(trailingId, clientId);
});
mergeWithNested(trailingId, clientId);
} else {
onMerge(forward);
}
Expand Down
4 changes: 2 additions & 2 deletions wp-includes/js/dist/block-library.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wp-includes/js/dist/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6845,7 +6845,7 @@ var external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
const {
lock,
unlock
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/blocks');
} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/blocks');

;// CONCATENATED MODULE: ./node_modules/@wordpress/blocks/build-module/api/registration.js
/* eslint no-console: [ 'error', { allow: [ 'error', 'warn' ] } ] */
Expand Down
Loading

0 comments on commit 58d8b09

Please sign in to comment.