From aabc7e77ad0aa9bf90ef8884566795afdd147f86 Mon Sep 17 00:00:00 2001 From: Jorge Date: Wed, 7 Sep 2022 16:36:27 +0100 Subject: [PATCH] Update: Improve content locking experience. --- packages/block-editor/src/hooks/align.js | 35 ++++++++++++++-------- packages/block-editor/src/hooks/duotone.js | 14 ++++++++- packages/block-library/src/image/edit.js | 21 +++++++++---- packages/block-library/src/image/image.js | 18 +++++++---- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/packages/block-editor/src/hooks/align.js b/packages/block-editor/src/hooks/align.js index 4d3a22340b1eed..d559d5d8ea585a 100644 --- a/packages/block-editor/src/hooks/align.js +++ b/packages/block-editor/src/hooks/align.js @@ -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, @@ -116,6 +118,7 @@ export function addAttribute( settings ) { */ export const withToolbarControls = createHigherOrderComponent( ( BlockEdit ) => ( props ) => { + const blockEdit = ; 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 @@ -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 ) { @@ -143,19 +157,14 @@ export const withToolbarControls = createHigherOrderComponent( return ( <> - { !! validAlignments.length && ( - - - - ) } - + + + + { blockEdit } ); }, diff --git a/packages/block-editor/src/hooks/duotone.js b/packages/block-editor/src/hooks/duotone.js index 99704845844096..a33ad059cb6653 100644 --- a/packages/block-editor/src/hooks/duotone.js +++ b/packages/block-editor/src/hooks/duotone.js @@ -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 @@ -27,6 +28,7 @@ import { __unstableDuotoneStylesheet as DuotoneStylesheet, __unstableDuotoneUnsetStylesheet as DuotoneUnsetStylesheet, } from '../components/duotone'; +import { store as blockEditorStore } from '../store'; const EMPTY_ARRAY = []; @@ -157,11 +159,21 @@ const withDuotoneControls = createHigherOrderComponent( props.name, 'color.__experimentalDuotone' ); + const isContentLocked = useSelect( + ( select ) => { + return select( + blockEditorStore + ).__unstableGetContentLockingParent( props.clientId ); + }, + [ props.clientId ] + ); return ( <> - { hasDuotoneSupport && } + { hasDuotoneSupport && ! isContentLocked && ( + + ) } ); }, diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 78edfa5a54636d..baba2cee24ec33 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -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 ) { @@ -346,9 +356,10 @@ export function ImageEdit( { containerRef={ ref } context={ context } clientId={ clientId } + isContentLocked={ isContentLocked } /> ) } - { ! url && ( + { ! url && ! isContentLocked && ( get( image, [ 'media_details', 'sizes', slug, 'source_url' ] ) @@ -309,10 +313,12 @@ export default function Image( { const controls = ( <> - + { ! isContentLocked && ( + + ) } { ! multiImageSelection && ! isEditingImage && (