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

Media & Text: Replace the deprecated __experimentalImageSizeControl with ResolutionTool #57540

Merged
merged 22 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4ab14a0
Replace __experimentalImageSizeControl with ResolutionTool
carolinan Jan 4, 2024
adda7d7
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Jan 8, 2024
dad7236
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Jan 25, 2024
44f552f
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Feb 1, 2024
3b21002
Fix CS spacing issue after merge conflict
carolinan Feb 1, 2024
d7b97c1
Move the Media Width control
carolinan Mar 8, 2024
46d8469
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Mar 8, 2024
fb332b8
CS: Remove the default value from isShownByDefault.
carolinan Mar 8, 2024
2142b52
Import the constants for the ToolsPanel popover position
carolinan Mar 8, 2024
90d4fea
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Mar 12, 2024
f0c7d14
CS: Correct the spacing in edit.js after the merge conflict.
carolinan Mar 12, 2024
f6df613
Remove the condition that wraps the Media width control
carolinan Mar 12, 2024
ac8db83
Make sure that the media width resets to "50"
carolinan Mar 12, 2024
dd1dce1
Reverse the Stack on mobile setting
carolinan Mar 12, 2024
047bab1
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Mar 20, 2024
c5c42ea
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Apr 4, 2024
af478e6
Merge branch 'trunk' into update/media-text-image-size-control
carolinan Apr 30, 2024
570acfb
Merge branch 'trunk' into update/media-text-image-size-control
carolinan May 7, 2024
8a50d89
Remove function resetAll(), add ToolsPanelItem around the alternative…
carolinan May 7, 2024
e9a2c1e
Hide the resolution tool when the featured image is used
carolinan May 8, 2024
55f6165
Restore __next40pxDefaultSize on the RangeControl
carolinan May 20, 2024
b66be0f
Merge branch 'trunk' into update/media-text-image-size-control
carolinan May 20, 2024
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
176 changes: 116 additions & 60 deletions packages/block-library/src/media-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ import {
InspectorControls,
useBlockProps,
__experimentalImageURLInputUI as ImageURLInputUI,
__experimentalImageSizeControl as ImageSizeControl,
store as blockEditorStore,
useBlockEditingMode,
privateApis as blockEditorPrivateApis,
} from '@wordpress/block-editor';
import {
PanelBody,
RangeControl,
TextareaControl,
ToggleControl,
ToolbarButton,
ExternalLink,
FocalPointPicker,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { isBlobURL, getBlobTypeByURL } from '@wordpress/blob';
import { pullLeft, pullRight } from '@wordpress/icons';
Expand All @@ -44,6 +45,10 @@ import {
LINK_DESTINATION_ATTACHMENT,
TEMPLATE,
} from './constants';
import { unlock } from '../lock-unlock';
import { TOOLSPANEL_DROPDOWNMENU_PROPS } from '../utils/constants';

const { ResolutionTool } = unlock( blockEditorPrivateApis );

// this limits the resize to a safe zone to avoid making broken layouts
const applyWidthConstraints = ( width ) =>
Expand Down Expand Up @@ -267,86 +272,137 @@ function MediaTextEdit( {
};

const mediaTextGeneralSettings = (
<PanelBody title={ __( 'Settings' ) }>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
carolinan marked this conversation as resolved.
Show resolved Hide resolved
<ToolsPanel
label={ __( 'Settings' ) }
resetAll={ () => {
setAttributes( {
isStackedOnMobile: true,
imageFill: false,
mediaAlt: '',
focalPoint: undefined,
mediaWidth: 50,
mediaSizeSlug: undefined,
} );
} }
dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
>
<ToolsPanelItem
label={ __( 'Media width' ) }
value={ temporaryMediaWidth || mediaWidth }
onChange={ commitWidthChange }
min={ WIDTH_CONSTRAINT_PERCENTAGE }
max={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }
/>
<ToggleControl
__nextHasNoMarginBottom
isShownByDefault
hasValue={ () => mediaWidth !== 50 }
onDeselect={ () => setAttributes( { mediaWidth: 50 } ) }
>
<RangeControl
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Media width' ) }
value={ temporaryMediaWidth || mediaWidth }
onChange={ commitWidthChange }
min={ WIDTH_CONSTRAINT_PERCENTAGE }
max={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }
/>
</ToolsPanelItem>
<ToolsPanelItem
label={ __( 'Stack on mobile' ) }
checked={ isStackedOnMobile }
onChange={ () =>
setAttributes( {
isStackedOnMobile: ! isStackedOnMobile,
} )
isShownByDefault
hasValue={ () => ! isStackedOnMobile }
onDeselect={ () =>
setAttributes( { isStackedOnMobile: true } )
}
/>
{ mediaType === 'image' && (
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Crop image to fill' ) }
checked={ !! imageFill }
label={ __( 'Stack on mobile' ) }
checked={ isStackedOnMobile }
onChange={ () =>
setAttributes( {
imageFill: ! imageFill,
isStackedOnMobile: ! isStackedOnMobile,
} )
}
/>
</ToolsPanelItem>
{ mediaType === 'image' && (
<ToolsPanelItem
label={ __( 'Crop image to fill' ) }
isShownByDefault
hasValue={ () => !! imageFill }
onDeselect={ () => setAttributes( { imageFill: false } ) }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Crop image to fill' ) }
checked={ !! imageFill }
onChange={ () =>
setAttributes( {
imageFill: ! imageFill,
} )
}
/>
</ToolsPanelItem>
) }
{ imageFill &&
( mediaUrl || featuredImageURL ) &&
mediaType === 'image' && (
<FocalPointPicker
__nextHasNoMarginBottom
<ToolsPanelItem
label={ __( 'Focal point' ) }
url={
useFeaturedImage && featuredImageURL
? featuredImageURL
: mediaUrl
isShownByDefault
hasValue={ () => !! focalPoint }
onDeselect={ () =>
setAttributes( { focalPoint: undefined } )
}
value={ focalPoint }
onChange={ ( value ) =>
setAttributes( { focalPoint: value } )
}
onDragStart={ imperativeFocalPointPreview }
onDrag={ imperativeFocalPointPreview }
/>
>
<FocalPointPicker
__nextHasNoMarginBottom
__next40pxDefaultSize
label={ __( 'Focal point' ) }
url={
useFeaturedImage && featuredImageURL
? featuredImageURL
: mediaUrl
}
value={ focalPoint }
onChange={ ( value ) =>
setAttributes( { focalPoint: value } )
}
onDragStart={ imperativeFocalPointPreview }
onDrag={ imperativeFocalPointPreview }
/>
</ToolsPanelItem>
) }
{ mediaType === 'image' && mediaUrl && ! useFeaturedImage && (
<TextareaControl
__nextHasNoMarginBottom
<ToolsPanelItem
label={ __( 'Alternative text' ) }
value={ mediaAlt }
onChange={ onMediaAltChange }
help={
<>
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
{ __( 'Describe the purpose of the image.' ) }
</ExternalLink>
<br />
{ __( 'Leave empty if decorative.' ) }
</>
}
/>
isShownByDefault
hasValue={ () => !! mediaAlt }
onDeselect={ () => setAttributes( { mediaAlt: '' } ) }
>
<TextareaControl
__nextHasNoMarginBottom
label={ __( 'Alternative text' ) }
value={ mediaAlt }
onChange={ onMediaAltChange }
help={
<>
<ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
{ __(
'Describe the purpose of the image.'
) }
</ExternalLink>
<br />
{ __( 'Leave empty if decorative.' ) }
</>
}
/>
</ToolsPanelItem>
) }
{ mediaType === 'image' && (
<ImageSizeControl
onChangeImage={ updateImage }
slug={ mediaSizeSlug }
imageSizeOptions={ imageSizeOptions }
isResizable={ false }
imageSizeHelp={ __(
'Select the size of the source image.'
) }
{ mediaType === 'image' && ! useFeaturedImage && (
<ResolutionTool
value={ mediaSizeSlug }
options={ imageSizeOptions }
onChange={ updateImage }
/>
) }
</PanelBody>
</ToolsPanel>
);

const blockProps = useBlockProps( {
Expand Down
Loading