Skip to content
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
35 changes: 22 additions & 13 deletions packages/block-editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
getBlockType,
hasBlockSupport,
} from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { BlockControls, BlockAlignmentControl } from '../components';
import useAvailableAlignments from '../components/block-alignment-control/use-available-alignments';
import { store as blockEditorStore } from '../store';

/**
* An array which includes all possible valid alignments,
Expand Down Expand Up @@ -116,6 +118,7 @@ export function addAttribute( settings ) {
*/
export const withToolbarControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const blockEdit = <BlockEdit { ...props } />;
const { name: blockName } = props;
// Compute the block valid alignments by taking into account,
// if the theme supports wide alignments or not and the layout's
Expand All @@ -129,6 +132,17 @@ export const withToolbarControls = createHigherOrderComponent(
const validAlignments = useAvailableAlignments(
blockAllowedAlignments
).map( ( { name } ) => name );
const isContentLocked = useSelect(
( select ) => {
return select(
blockEditorStore
).__unstableGetContentLockingParent( props.clientId );
},
[ props.clientId ]
);
if ( ! validAlignments.length || isContentLocked ) {
return blockEdit;
}

const updateAlignment = ( nextAlign ) => {
if ( ! nextAlign ) {
Expand All @@ -143,19 +157,14 @@ export const withToolbarControls = createHigherOrderComponent(

return (
<>
{ !! validAlignments.length && (
<BlockControls
group="block"
__experimentalShareWithChildBlocks
>
<BlockAlignmentControl
value={ props.attributes.align }
onChange={ updateAlignment }
controls={ validAlignments }
/>
</BlockControls>
) }
<BlockEdit { ...props } />
<BlockControls group="block" __experimentalShareWithChildBlocks>
<BlockAlignmentControl
value={ props.attributes.align }
onChange={ updateAlignment }
controls={ validAlignments }
/>
</BlockControls>
{ blockEdit }
</>
);
},
Expand Down
14 changes: 13 additions & 1 deletion packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import { useMemo, useContext, createPortal } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand All @@ -27,6 +28,7 @@ import {
__unstableDuotoneStylesheet as DuotoneStylesheet,
__unstableDuotoneUnsetStylesheet as DuotoneUnsetStylesheet,
} from '../components/duotone';
import { store as blockEditorStore } from '../store';

const EMPTY_ARRAY = [];

Expand Down Expand Up @@ -157,11 +159,21 @@ const withDuotoneControls = createHigherOrderComponent(
props.name,
'color.__experimentalDuotone'
);
const isContentLocked = useSelect(
( select ) => {
return select(
blockEditorStore
).__unstableGetContentLockingParent( props.clientId );
},
[ props.clientId ]
);

return (
<>
<BlockEdit { ...props } />
{ hasDuotoneSupport && <DuotonePanel { ...props } /> }
{ hasDuotoneSupport && ! isContentLocked && (
<DuotonePanel { ...props } />
) }
</>
);
},
Expand Down
21 changes: 16 additions & 5 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,20 @@ export function ImageEdit( {
}, [ caption ] );

const ref = useRef();
const { imageDefaultSize, mediaUpload } = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return pick( getSettings(), [ 'imageDefaultSize', 'mediaUpload' ] );
}, [] );
const { imageDefaultSize, mediaUpload, isContentLocked } = useSelect(
( select ) => {
const { getSettings, __unstableGetContentLockingParent } =
select( blockEditorStore );
const settings = getSettings();
return {
imageDefaultSize: settings.imageDefaultSize,
mediaUpload: settings.mediaUpload,
isContentLocked:
!! __unstableGetContentLockingParent( clientId ),
};
},
[]
);

const { createErrorNotice } = useDispatch( noticesStore );
function onUploadError( message ) {
Expand Down Expand Up @@ -346,9 +356,10 @@ export function ImageEdit( {
containerRef={ ref }
context={ context }
clientId={ clientId }
isContentLocked={ isContentLocked }
/>
) }
{ ! url && (
{ ! url && ! isContentLocked && (
<BlockControls group="block">
<BlockAlignmentControl
value={ align }
Expand Down
18 changes: 12 additions & 6 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default function Image( {
containerRef,
context,
clientId,
isContentLocked,
} ) {
const {
url = '',
Expand Down Expand Up @@ -111,7 +112,7 @@ export default function Image( {
),
};
},
[ id, isSelected ]
[ id, isSelected, clientId ]
);
const { canInsertCover, imageEditing, imageSizes, maxWidth, mediaUpload } =
useSelect(
Expand Down Expand Up @@ -152,7 +153,10 @@ export default function Image( {
const [ isEditingImage, setIsEditingImage ] = useState( false );
const [ externalBlob, setExternalBlob ] = useState();
const clientWidth = useClientWidth( containerRef, [ align ] );
const isResizable = allowResize && ! ( isWideAligned && isLargeViewport );
const isResizable =
allowResize &&
! isContentLocked &&
! ( isWideAligned && isLargeViewport );
const imageSizeOptions = map(
filter( imageSizes, ( { slug } ) =>
get( image, [ 'media_details', 'sizes', slug, 'source_url' ] )
Expand Down Expand Up @@ -309,10 +313,12 @@ export default function Image( {
const controls = (
<>
<BlockControls group="block">
<BlockAlignmentControl
value={ align }
onChange={ updateAlignment }
/>
{ ! isContentLocked && (
<BlockAlignmentControl
value={ align }
onChange={ updateAlignment }
/>
) }
{ ! multiImageSelection && ! isEditingImage && (
<ImageURLInputUI
url={ href || '' }
Expand Down