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

[pull] trunk from WordPress:trunk #147

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions packages/block-editor/src/components/block-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
/**
* Internal dependencies
*/
import { useNotifyCopy } from '../../utils/use-notify-copy';
import usePasteStyles from '../use-paste-styles';
import { store as blockEditorStore } from '../../store';

Expand Down Expand Up @@ -76,7 +75,6 @@ export default function BlockActions( {
flashBlock,
} = useDispatch( blockEditorStore );

const notifyCopy = useNotifyCopy();
const pasteStyles = usePasteStyles();

return children( {
Expand Down Expand Up @@ -130,7 +128,6 @@ export default function BlockActions( {
if ( clientIds.length === 1 ) {
flashBlock( clientIds[ 0 ] );
}
notifyCopy( 'copy', clientIds );
},
async onPasteStyles() {
await pasteStyles( getBlocksByClientId( clientIds ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* WordPress dependencies
*/
import { box, button, cog, paragraph } from '@wordpress/icons';

/**
* Internal dependencies
*/
import BlockIcon from '../';

const meta = {
title: 'BlockEditor/BlockIcon',
component: BlockIcon,
parameters: {
docs: {
description: {
component:
'The `BlockIcon` component allows to display an icon for a block.',
},
canvas: { sourceState: 'shown' },
},
},
argTypes: {
icon: {
control: 'select',
options: [ 'paragraph', 'cog', 'box', 'button' ],
mapping: {
paragraph,
cog,
box,
button,
},
description:
'The icon of the block. This can be any of [WordPress Dashicons](https://developer.wordpress.org/resource/dashicons/), or a custom `svg` element.',
table: {
type: { summary: 'string | object' },
},
},
showColors: {
control: 'boolean',
description: 'Whether to show background and foreground colors.',
table: {
type: { summary: 'boolean' },
},
},
className: {
control: 'text',
description: 'Additional CSS class for the icon.',
table: {
type: { summary: 'string' },
},
},
context: {
control: 'text',
description: 'Context where the icon is being used.',
table: {
type: { summary: 'string' },
},
},
},
};

export default meta;

export const Default = {
args: {
icon: 'paragraph',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@ import BlockSettingsMenuControls from '../block-settings-menu-controls';
import BlockParentSelectorMenuItem from './block-parent-selector-menu-item';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import { useNotifyCopy } from '../../utils/use-notify-copy';

const POPOVER_PROPS = {
className: 'block-editor-block-settings-menu__popover',
placement: 'bottom-start',
};

function CopyMenuItem( { clientIds, onCopy, label, shortcut } ) {
function CopyMenuItem( {
clientIds,
onCopy,
label,
shortcut,
eventType = 'copy',
} ) {
const { getBlocksByClientId } = useSelect( blockEditorStore );
const notifyCopy = useNotifyCopy();
const ref = useCopyToClipboard(
() => serialize( getBlocksByClientId( clientIds ) ),
onCopy
() => {
if ( onCopy && eventType === 'copy' ) {
onCopy();
}
notifyCopy( eventType, clientIds );
}
);
const copyMenuItemLabel = label ? label : __( 'Copy' );
return (
Expand Down Expand Up @@ -305,6 +318,7 @@ export function BlockSettingsDropdown( {
clientIds={ clientIds }
onCopy={ onCopy }
label={ __( 'Copy styles' ) }
eventType="copyStyles"
/>
<MenuItem onClick={ onPasteStyles }>
{ __( 'Paste styles' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export default function ImageSettingsPanel( {
// "RESET" button ONLY when the user has explicitly set a value in the
// Global Styles.
hasValue={ () => !! value?.lightbox }
label={ __( 'Expand on click' ) }
label={ __( 'Enlarge on click' ) }
onDeselect={ resetLightbox }
isShownByDefault
panelId={ panelId }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Expand on click' ) }
label={ __( 'Enlarge on click' ) }
checked={ lightboxChecked }
onChange={ onChangeLightbox }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ const ImageURLInputUI = ( {
<div className="block-editor-url-popover__expand-on-click">
<Icon icon={ fullscreen } />
<div className="text">
<p>{ __( 'Expand on click' ) }</p>
<p>{ __( 'Enlarge on click' ) }</p>
<p className="description">
{ __( 'Scales the image with a lightbox effect' ) }
</p>
</div>
<Button
icon={ linkOff }
label={ __( 'Disable expand on click' ) }
label={ __( 'Disable enlarge on click' ) }
onClick={ () => {
onSetLightbox?.( false );
} }
Expand Down Expand Up @@ -372,7 +372,7 @@ const ImageURLInputUI = ( {
stopEditLink();
} }
>
{ __( 'Expand on click' ) }
{ __( 'Enlarge on click' ) }
</MenuItem>
) }
</NavigableMenu>
Expand Down
94 changes: 51 additions & 43 deletions packages/block-editor/src/utils/use-notify-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,55 @@ export function useNotifyCopy() {
const { getBlockType } = useSelect( blocksStore );
const { createSuccessNotice } = useDispatch( noticesStore );

return useCallback( ( eventType, selectedBlockClientIds ) => {
let notice = '';
if ( selectedBlockClientIds.length === 1 ) {
const clientId = selectedBlockClientIds[ 0 ];
const title = getBlockType( getBlockName( clientId ) )?.title;
notice =
eventType === 'copy'
? sprintf(
// Translators: Name of the block being copied, e.g. "Paragraph".
__( 'Copied "%s" to clipboard.' ),
title
)
: sprintf(
// Translators: Name of the block being cut, e.g. "Paragraph".
__( 'Moved "%s" to clipboard.' ),
title
);
} else {
notice =
eventType === 'copy'
? sprintf(
// Translators: %d: Number of blocks being copied.
_n(
'Copied %d block to clipboard.',
'Copied %d blocks to clipboard.',
selectedBlockClientIds.length
),
selectedBlockClientIds.length
)
: sprintf(
// Translators: %d: Number of blocks being cut.
_n(
'Moved %d block to clipboard.',
'Moved %d blocks to clipboard.',
selectedBlockClientIds.length
),
selectedBlockClientIds.length
);
}
createSuccessNotice( notice, {
type: 'snackbar',
} );
}, [] );
return useCallback(
( eventType, selectedBlockClientIds ) => {
let notice = '';

if ( eventType === 'copyStyles' ) {
notice = __( 'Styles copied to clipboard.' );
} else if ( selectedBlockClientIds.length === 1 ) {
const clientId = selectedBlockClientIds[ 0 ];
const title = getBlockType( getBlockName( clientId ) )?.title;

if ( eventType === 'copy' ) {
notice = sprintf(
// Translators: Name of the block being copied, e.g. "Paragraph".
__( 'Copied "%s" to clipboard.' ),
title
);
} else {
notice = sprintf(
// Translators: Name of the block being cut, e.g. "Paragraph".
__( 'Moved "%s" to clipboard.' ),
title
);
}
} else if ( eventType === 'copy' ) {
notice = sprintf(
// Translators: %d: Number of blocks being copied.
_n(
'Copied %d block to clipboard.',
'Copied %d blocks to clipboard.',
selectedBlockClientIds.length
),
selectedBlockClientIds.length
);
} else {
notice = sprintf(
// Translators: %d: Number of blocks being moved.
_n(
'Moved %d block to clipboard.',
'Moved %d blocks to clipboard.',
selectedBlockClientIds.length
),
selectedBlockClientIds.length
);
}

createSuccessNotice( notice, {
type: 'snackbar',
} );
},
[ createSuccessNotice, getBlockName, getBlockType ]
);
}
2 changes: 1 addition & 1 deletion packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const LINK_OPTIONS = [
},
{
icon: fullscreen,
label: __( 'Expand on click' ),
label: __( 'Enlarge on click' ),
value: LINK_DESTINATION_LIGHTBOX,
noticeText: __( 'Lightbox effect' ),
infoText: __( 'Scale images with a lightbox effect' ),
Expand Down
22 changes: 9 additions & 13 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,14 @@ function block_core_image_render_lightbox( $block_content, $block ) {
return $block_content;
}

$alt = $p->get_attribute( 'alt' );
$img_uploaded_src = $p->get_attribute( 'src' );
$img_class_names = $p->get_attribute( 'class' );
$img_styles = $p->get_attribute( 'style' );
$img_width = 'none';
$img_height = 'none';
$aria_label = __( 'Enlarge image' );

if ( $alt ) {
/* translators: %s: Image alt text. */
$aria_label = sprintf( __( 'Enlarge image: %s' ), $alt );
}
$alt = $p->get_attribute( 'alt' );
$img_uploaded_src = $p->get_attribute( 'src' );
$img_class_names = $p->get_attribute( 'class' );
$img_styles = $p->get_attribute( 'style' );
$img_width = 'none';
$img_height = 'none';
$aria_label = __( 'Enlarge' );
$dialog_aria_label = __( 'Enlarged image' );

if ( isset( $block['attrs']['id'] ) ) {
$img_uploaded_src = wp_get_attachment_url( $block['attrs']['id'] );
Expand Down Expand Up @@ -190,7 +186,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
'targetWidth' => $img_width,
'targetHeight' => $img_height,
'scaleAttr' => $block['attrs']['scale'] ?? false,
'ariaLabel' => $aria_label,
'ariaLabel' => $dialog_aria_label,
'alt' => $alt,
),
),
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,17 +859,17 @@ test.describe( 'Image', () => {
} )
).toBeFocused();

// Select "Expand on click", then remove it.
// Select "Enlarge on click", then remove it.
await pageUtils.pressKeys( 'Tab' );
await page.keyboard.press( 'Enter' );
await pageUtils.pressKeys( 'Tab', { times: 5 } );
await expect(
page.getByRole( 'menuitem', { name: 'Expand on click' } )
page.getByRole( 'menuitem', { name: 'Enlarge on click' } )
).toBeFocused();
await page.keyboard.press( 'Enter' );
await expect(
page.getByRole( 'button', {
name: 'Disable expand on click',
name: 'Disable enlarge on click',
} )
).toBeFocused();
await page.keyboard.press( 'Enter' );
Expand Down Expand Up @@ -933,7 +933,7 @@ test.describe( 'Image - lightbox', () => {

await expect(
page.getByRole( 'menuitem', {
name: 'Expand on click',
name: 'Enlarge on click',
} )
).toBeHidden();
} );
Expand All @@ -958,13 +958,13 @@ test.describe( 'Image - lightbox', () => {

await page
.getByRole( 'button', {
name: 'Disable expand on click',
name: 'Disable enlarge on click',
} )
.click();

await expect(
page.getByRole( 'menuitem', {
name: 'Expand on click',
name: 'Enlarge on click',
} )
).toBeHidden();
} );
Expand Down
Loading