Skip to content
Merged
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
61 changes: 25 additions & 36 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,30 @@ export default function Image( {
},
[ id, isSelected, clientId ]
);
const { canInsertCover, imageEditing, imageSizes, maxWidth, mediaUpload } =
useSelect(
( select ) => {
const {
getBlockRootClientId,
getSettings,
canInsertBlockType,
} = select( blockEditorStore );

const rootClientId = getBlockRootClientId( clientId );
const settings = Object.fromEntries(
Object.entries( getSettings() ).filter( ( [ key ] ) =>
[
'imageEditing',
'imageSizes',
'maxWidth',
'mediaUpload',
].includes( key )
const { canInsertCover, imageEditing, imageSizes, mediaUpload } = useSelect(
( select ) => {
const { getBlockRootClientId, getSettings, canInsertBlockType } =
select( blockEditorStore );

const rootClientId = getBlockRootClientId( clientId );
const settings = Object.fromEntries(
Object.entries( getSettings() ).filter( ( [ key ] ) =>
[ 'imageEditing', 'imageSizes', 'mediaUpload' ].includes(
key
)
);
)
);

return {
...settings,
canInsertCover: canInsertBlockType(
'core/cover',
rootClientId
),
};
},
[ clientId ]
);
return {
...settings,
canInsertCover: canInsertBlockType(
'core/cover',
rootClientId
),
};
},
[ clientId ]
);
const { replaceBlocks, toggleSelection } = useDispatch( blockEditorStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
Expand Down Expand Up @@ -549,13 +542,9 @@ export default function Image( {
// With the current implementation of ResizableBox, an image needs an
// explicit pixel value for the max-width. In absence of being able to
// set the content-width, this max-width is currently dictated by the
// vanilla editor style. The following variable adds a buffer to this
// vanilla style, so 3rd party themes have some wiggleroom. This does,
// in most cases, allow you to scale the image beyond the width of the
// main column, though not infinitely.
// @todo It would be good to revisit this once a content-width variable
// becomes available.
const maxWidthBuffer = maxWidth * 2.5;
// vanilla editor style. We'll use the clientWidth here, to prevent the width
// of the image growing larger than the width of the block column.
const maxWidthBuffer = clientWidth;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we compare with maxWidth here and choose the minimum?

Suggested change
const maxWidthBuffer = clientWidth;
const maxWidthBuffer = Math.min( clientWidth, maxWidth * 2.5 );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin940726 I believe the goal of this commit is to prevent the image from being larger than its container (clientWidth). Is there an instance where maxWidth * 2.5 is smaller than the container?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure! It's a question and I'm not very familiar with the maxWidth settings. I think it's fine to keep just the clientWidth though.


let showRightHandle = false;
let showLeftHandle = false;
Expand Down