Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-picked commits for WordPress 6.4 Beta 3 #55039

Merged
merged 28 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
05755f3
Add clearer labels and context to BlockPatternsSyncFilter (#54838)
richtabor Oct 2, 2023
089c0a3
Font Library: use snake_case instead of camelCase on fontFamilies end…
matiasbenedetto Oct 2, 2023
020570d
Fix output of Navigation block classnames in the editor. (#54992)
tellthemachines Oct 3, 2023
5c01d3d
Block Editor: Avoid double-wrapping selectors when transforming the s…
Mamaduka Oct 3, 2023
f112f14
Don't display the navigation section in template parts details when a…
Mamaduka Oct 3, 2023
d36bd6d
Scripts: Properly use CommonJS for default Playwright config (#54988)
swissspidy Oct 3, 2023
283f4e7
Add template replace flow to template inspector (#54609)
scruffian Oct 3, 2023
fba6504
List View: Fix performance issue when selecting all blocks (#54900)
andrewserong Oct 4, 2023
2998442
Fix left and right aligmnent in children of Post Template (#54997)
tellthemachines Oct 4, 2023
e2eb0ab
Site Editor: Avoid stale navigation block values when parsing entity …
Mamaduka Oct 4, 2023
d11de67
Removed unwanted space from the string (#54654)
mujuonly Sep 23, 2023
3c227eb
Fix Deleted Navigation Menu warning string (#55033)
getdave Oct 4, 2023
aca3f6d
[Inserter]: Fix reset of registered media categories (#55012)
ntsekouras Oct 4, 2023
202a297
Try fixing the flaky 'Toolbar roving tabindex' e2e test (#54785)
Mamaduka Sep 26, 2023
fcb06c7
Fallback to Twitter provider when embedding X URLs (#54876)
fluiddot Sep 27, 2023
e790617
Based on the efforts in https://github.com/WordPress/gutenberg/pull/5…
ramonjd Sep 22, 2023
e93d348
Update pattern import menu item (#54782)
jameskoster Sep 26, 2023
baf1425
Image Block: Fix browser console error when clicking "Expand on Click…
t-hamano Sep 30, 2023
841537f
Patterns: Remove category description in inserter panel? (#54894)
aaronrobertshaw Oct 2, 2023
dac8a21
Media & Text: Fix React warning (#55038)
Mamaduka Oct 4, 2023
0c89d7e
Block Style: Display default style labels correctly in the block side…
t-hamano Oct 4, 2023
d0630d0
Site Editor: Do not display 'trashed' navigation menus in Sidebar (#5…
Mamaduka Oct 5, 2023
ae40d77
Image: Fix Lightbox display bug in Classic Themes. (#54837)
michalczaplinski Oct 5, 2023
11f6a6d
Latest Posts: add screen reader title text to Read more links and use…
ramonjd Oct 5, 2023
89f5e33
Fix Image block lightbox missing alt attribute and improve accessibil…
afercia Oct 6, 2023
9398b4a
Patterns: Add category selector to pattern creation modal (#55024)
glendaviesnz Oct 9, 2023
2e4bba1
Iframe: Fix positioning when dragging over an iframe (#55150)
andrewserong Oct 9, 2023
95e1f62
Site Editor: Fix template part area listing when a template has no ed…
Mamaduka Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions lib/block-supports/behaviors.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,35 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {

$aria_label = __( 'Enlarge image', 'gutenberg' );

$processor->next_tag( 'img' );
$alt_attribute = $processor->get_attribute( 'alt' );

if ( null !== $alt_attribute ) {
// An empty alt attribute `alt=""` is valid for decorative images.
if ( is_string( $alt_attribute ) ) {
$alt_attribute = trim( $alt_attribute );
}

// It only makes sense to append the alt text to the button aria-label when the alt text is non-empty.
if ( $alt_attribute ) {
/* translators: %s: Image alt text. */
$aria_label = sprintf( __( 'Enlarge image: %s', 'gutenberg' ), $alt_attribute );
}
$content = $processor->get_updated_html();

// If we don't set a default, it won't work if Lightbox is set to enabled by default.
$lightbox_animation = 'zoom';
if ( isset( $lightbox_settings['animation'] ) && '' !== $lightbox_settings['animation'] ) {
$lightbox_animation = $lightbox_settings['animation'];
}

// We want to store the src in the context so we can set it dynamically when the lightbox is opened.
$z = new WP_HTML_Tag_Processor( $content );
$z->next_tag( 'img' );

// Note: We want to store the `src` in the context so we
// can set it dynamically when the lightbox is opened.
if ( isset( $block['attrs']['id'] ) ) {
$img_uploaded_src = wp_get_attachment_url( $block['attrs']['id'] );
$img_metadata = wp_get_attachment_metadata( $block['attrs']['id'] );
$img_width = $img_metadata['width'];
$img_height = $img_metadata['height'];
} else {
$img_uploaded_src = $z->get_attribute( 'src' );
$img_uploaded_src = $processor->get_attribute( 'src' );
$img_width = 'none';
$img_height = 'none';
}
Expand All @@ -123,7 +123,7 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {
$scale_attr = false;
}

$w = new WP_HTML_Tag_Processor( $content );
$w = new WP_HTML_Tag_Processor( $block_content );
$w->next_tag( 'figure' );
$w->add_class( 'wp-lightbox-container' );
$w->set_attribute( 'data-wp-interactive', true );
Expand Down Expand Up @@ -163,27 +163,28 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {
// Wrap the image in the body content with a button.
$img = null;
preg_match( '/<img[^>]+>/', $body_content, $img );
$button =
'<button
type="button"
aria-haspopup="dialog"
aria-label="' . esc_attr( $aria_label ) . '"
data-wp-on--click="actions.core.image.showLightbox"
data-wp-style--width="context.core.image.imageButtonWidth"
data-wp-style--height="context.core.image.imageButtonHeight"
data-wp-style--left="context.core.image.imageButtonLeft"
data-wp-style--top="context.core.image.imageButtonTop"
>
</button>'
. $img[0];

$button =
$img[0]
. '<button
type="button"
aria-haspopup="dialog"
aria-label="' . esc_attr( $aria_label ) . '"
data-wp-on--click="actions.core.image.showLightbox"
data-wp-style--width="context.core.image.imageButtonWidth"
data-wp-style--height="context.core.image.imageButtonHeight"
data-wp-style--left="context.core.image.imageButtonLeft"
data-wp-style--top="context.core.image.imageButtonTop"
></button>';

$body_content = preg_replace( '/<img[^>]+>/', $button, $body_content );

// We need both a responsive image and an enlarged image to animate
// the zoom seamlessly on slow internet connections; the responsive
// image is a copy of the one in the body, which animates immediately
// as the lightbox is opened, while the enlarged one is a full-sized
// version that will likely still be loading as the animation begins.
$m = new WP_HTML_Tag_Processor( $content );
$m = new WP_HTML_Tag_Processor( $block_content );
$m->next_tag( 'figure' );
$m->add_class( 'responsive-image' );
$m->next_tag( 'img' );
Expand All @@ -199,7 +200,7 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {
$m->set_attribute( 'data-wp-style--object-fit', 'selectors.core.image.lightboxObjectFit' );
$initial_image_content = $m->get_updated_html();

$q = new WP_HTML_Tag_Processor( $content );
$q = new WP_HTML_Tag_Processor( $block_content );
$q->next_tag( 'figure' );
$q->add_class( 'enlarged-image' );
$q->next_tag( 'img' );
Expand All @@ -219,7 +220,7 @@ function gutenberg_render_behaviors_support_lightbox( $block_content, $block ) {

$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';
$close_button_color = esc_attr( wp_get_global_styles( array( 'color', 'text' ) ) );
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image', 'gutenberg' );
$dialog_label = esc_attr__( 'Enlarged image', 'gutenberg' );
$close_button_label = esc_attr__( 'Close', 'gutenberg' );

$lightbox_html = <<<HTML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function register_routes() {
'callback' => array( $this, 'install_fonts' ),
'permission_callback' => array( $this, 'update_font_library_permissions_check' ),
'args' => array(
'fontFamilies' => array(
'font_families' => array(
'required' => true,
'type' => 'string',
'validate_callback' => array( $this, 'validate_install_font_families' ),
Expand Down Expand Up @@ -147,13 +147,13 @@ private function get_validation_errors( $font_families, $files ) {
$error_messages = array();

if ( ! is_array( $font_families ) ) {
$error_messages[] = __( 'fontFamilies should be an array of font families.', 'gutenberg' );
$error_messages[] = __( 'font_families should be an array of font families.', 'gutenberg' );
return $error_messages;
}

// Checks if there is at least one font family.
if ( count( $font_families ) < 1 ) {
$error_messages[] = __( 'fontFamilies should have at least one font family definition.', 'gutenberg' );
$error_messages[] = __( 'font_families should have at least one font family definition.', 'gutenberg' );
return $error_messages;
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public function validate_install_font_families( $param, $request ) {
*/
public function uninstall_schema() {
return array(
'fontFamilies' => array(
'font_families' => array(
'type' => 'array',
'description' => __( 'The font families to install.', 'gutenberg' ),
'required' => true,
Expand Down Expand Up @@ -289,7 +289,7 @@ public function uninstall_schema() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function uninstall_fonts( $request ) {
$fonts_to_uninstall = $request->get_param( 'fontFamilies' );
$fonts_to_uninstall = $request->get_param( 'font_families' );

$errors = array();
$successes = array();
Expand Down Expand Up @@ -397,7 +397,7 @@ private function needs_write_permission( $font_families ) {
*/
public function install_fonts( $request ) {
// Get new fonts to install.
$fonts_param = $request->get_param( 'fontFamilies' );
$fonts_param = $request->get_param( 'font_families' );

/*
* As this is receiving form data, the font families are encoded as a string.
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,4 @@ function () {
require __DIR__ . '/block-supports/duotone.php';
require __DIR__ . '/block-supports/shadow.php';
require __DIR__ . '/block-supports/background.php';
require __DIR__ . '/block-supports/behaviors.php';
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ $z-layers: (
".block-editor-block-rename-modal": 1000001,
".edit-site-list__rename-modal": 1000001,
".edit-site-swap-template-modal": 1000001,
".edit-site-template-panel__replace-template-modal": 1000001,

// Note: The ConfirmDialog component's z-index is being set to 1000001 in packages/components/src/confirm-dialog/styles.ts
// because it uses emotion and not sass. We need it to render on top its parent popover.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Popover,
} from '@wordpress/components';
import deprecated from '@wordpress/deprecated';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -65,9 +64,7 @@ function BlockStyles( { clientId, onSwitch = noop, onHoverClassName = noop } ) {
<div className="block-editor-block-styles">
<div className="block-editor-block-styles__variants">
{ stylesToRender.map( ( style ) => {
const buttonText = style.isDefault
? __( 'Default' )
: style.label || style.name;
const buttonText = style.label || style.name;

return (
<Button
Expand Down
9 changes: 8 additions & 1 deletion packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ function bubbleEvent( event, Constructor, frame ) {
init[ key ] = event[ key ];
}

if ( event instanceof frame.ownerDocument.defaultView.MouseEvent ) {
// Check if the event is a MouseEvent generated within the iframe.
// If so, adjust the coordinates to be relative to the position of
// the iframe. This ensures that components such as Draggable
// receive coordinates relative to the window, instead of relative
// to the iframe. Without this, the Draggable event handler would
// result in components "jumping" position as soon as the user
// drags over the iframe.
if ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {
const rect = frame.getBoundingClientRect();
init.clientX += rect.left;
init.clientY += rect.top;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
DropdownMenu,
MenuGroup,
MenuItemsChoice,
ExternalLink,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useMemo } from '@wordpress/element';
import { useMemo, createInterpolateElement } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -73,13 +74,11 @@ export function BlockPatternsSyncFilter( {
{
value: SYNC_TYPES.full,
label: __( 'Synced' ),
info: __( 'Updated everywhere' ),
disabled: shouldDisableSyncFilter,
},
{
value: SYNC_TYPES.unsynced,
label: __( 'Standard' ),
info: __( 'Edit freely' ),
label: __( 'Not synced' ),
disabled: shouldDisableSyncFilter,
},
],
Expand All @@ -95,20 +94,17 @@ export function BlockPatternsSyncFilter( {
},
{
value: PATTERN_TYPES.directory,
label: __( 'Directory' ),
info: __( 'Pattern directory & core' ),
label: __( 'Pattern Directory' ),
disabled: shouldDisableNonUserSources,
},
{
value: PATTERN_TYPES.theme,
label: __( 'Theme' ),
info: __( 'Bundled with the theme' ),
label: __( 'Theme & Plugins' ),
disabled: shouldDisableNonUserSources,
},
{
value: PATTERN_TYPES.user,
label: __( 'User' ),
info: __( 'Custom created' ),
},
],
[ shouldDisableNonUserSources ]
Expand Down Expand Up @@ -149,7 +145,7 @@ export function BlockPatternsSyncFilter( {
>
{ () => (
<>
<MenuGroup label={ __( 'Author' ) }>
<MenuGroup label={ __( 'Source' ) }>
<MenuItemsChoice
choices={ patternSourceMenuOptions }
onSelect={ ( value ) => {
Expand All @@ -175,6 +171,22 @@ export function BlockPatternsSyncFilter( {
value={ patternSyncFilter }
/>
</MenuGroup>
<div className="block-editor-tool-selector__help">
{ createInterpolateElement(
__(
'Patterns are available from the <Link>WordPress.org Pattern Directory</Link>, bundled in the active theme, or created by users on this site. Only patterns created on this site can be synced.'
),
{
Link: (
<ExternalLink
href={ __(
'https://wordpress.org/patterns/'
) }
/>
),
}
) }
</div>
</>
) }
</DropdownMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,6 @@ export function BlockPatternsCategoryPanel( {
category={ category }
/>
</HStack>
{ category.description && (
<Text>{ category.description }</Text>
) }
{ ! currentCategoryPatterns.length && (
<Text
variant="muted"
Expand Down
54 changes: 10 additions & 44 deletions packages/block-editor/src/components/inserter/media-tab/hooks.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/**
* WordPress dependencies
*/
import { useEffect, useState, useRef, useMemo } from '@wordpress/element';
import { useEffect, useState, useRef } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../../store';
import { unlock } from '../../../lock-unlock';

/** @typedef {import('./api').InserterMediaRequest} InserterMediaRequest */
/** @typedef {import('./api').InserterMediaItem} InserterMediaItem */
/** @typedef {import('../../../store/actions').InserterMediaRequest} InserterMediaRequest */
/** @typedef {import('../../../store/actions').InserterMediaItem} InserterMediaItem */

/**
* Fetches media items based on the provided category.
Expand Down Expand Up @@ -50,48 +51,14 @@ export function useMediaResults( category, query = {} ) {
return { mediaList, isLoading };
}

function useInserterMediaCategories() {
const {
inserterMediaCategories,
allowedMimeTypes,
enableOpenverseMediaCategory,
} = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
return {
inserterMediaCategories: settings.inserterMediaCategories,
allowedMimeTypes: settings.allowedMimeTypes,
enableOpenverseMediaCategory: settings.enableOpenverseMediaCategory,
};
}, [] );
// The allowed `mime_types` can be altered by `upload_mimes` filter and restrict
// some of them. In this case we shouldn't add the category to the available media
// categories list in the inserter.
const allowedCategories = useMemo( () => {
if ( ! inserterMediaCategories || ! allowedMimeTypes ) {
return;
}
return inserterMediaCategories.filter( ( category ) => {
// Check if Openverse category is enabled.
if (
! enableOpenverseMediaCategory &&
category.name === 'openverse'
) {
return false;
}
return Object.values( allowedMimeTypes ).some( ( mimeType ) =>
mimeType.startsWith( `${ category.mediaType }/` )
);
} );
}, [
inserterMediaCategories,
allowedMimeTypes,
enableOpenverseMediaCategory,
] );
return allowedCategories;
}

export function useMediaCategories( rootClientId ) {
const [ categories, setCategories ] = useState( [] );

const inserterMediaCategories = useSelect(
( select ) =>
unlock( select( blockEditorStore ) ).getInserterMediaCategories(),
[]
);
const { canInsertImage, canInsertVideo, canInsertAudio } = useSelect(
( select ) => {
const { canInsertBlockType } = select( blockEditorStore );
Expand All @@ -112,7 +79,6 @@ export function useMediaCategories( rootClientId ) {
},
[ rootClientId ]
);
const inserterMediaCategories = useInserterMediaCategories();
useEffect( () => {
( async () => {
const _categories = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ $block-inserter-tabs-height: 44px;
overflow-y: auto;
flex-grow: 1;
height: 100%;
padding: $grid-unit-40 $grid-unit-30;
padding: $grid-unit-20 $grid-unit-30;
}
}

Expand Down
Loading
Loading