From d35db113a7a73bb36bf737ddf5cbf6dc3f4ddbea Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 28 May 2024 11:01:24 +0200 Subject: [PATCH] Change name to `canUserEditValue` --- .../src/components/rich-text/index.js | 5 ++- packages/block-library/src/button/edit.js | 11 +++---- packages/block-library/src/image/edit.js | 11 +++---- packages/block-library/src/image/image.js | 33 +++++++++---------- packages/blocks/src/store/private-actions.js | 2 +- packages/blocks/src/store/reducer.js | 3 +- .../editor/src/bindings/pattern-overrides.js | 4 +-- packages/editor/src/bindings/post-meta.js | 10 +++--- 8 files changed, 35 insertions(+), 44 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 274af53b901805..d390cc691a6e1e 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -180,13 +180,12 @@ export function RichTextWrapper( break; } - // If the source is not defined, or if its value of `lockAttributesEditing` is `true`, disable it. + // If the source is not defined, or if its value of `canUserEditValue` is `false`, disable it. const blockBindingsSource = getBlockBindingsSource( binding.source ); if ( - ! blockBindingsSource || - blockBindingsSource.lockAttributesEditing( { + ! blockBindingsSource?.canUserEditValue( { select, context: select( blockEditorStore ).getBlockContext( diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index b1c8632087177f..d1b47a3a3b3c2e 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -247,12 +247,11 @@ function ButtonEdit( props ) { return { lockUrlControls: !! metadata?.bindings?.url && - ( ! blockBindingsSource || - blockBindingsSource?.lockAttributesEditing( { - select, - context, - args: metadata?.bindings?.url?.args, - } ) ), + ! blockBindingsSource?.canUserEditValue( { + select, + context, + args: metadata?.bindings?.url?.args, + } ), }; }, [ isSelected ] diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index 6761111c1c9ed6..0653e8684fd4af 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -317,12 +317,11 @@ export function ImageEdit( { return { lockUrlControls: !! metadata?.bindings?.url && - ( ! blockBindingsSource || - blockBindingsSource?.lockAttributesEditing( { - select, - context, - args: metadata?.bindings?.url?.args, - } ) ), + ! blockBindingsSource?.canUserEditValue( { + select, + context, + args: metadata?.bindings?.url?.args, + } ), lockUrlControlsMessage: blockBindingsSource?.label ? sprintf( /* translators: %s: Label of the bindings source. */ diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 40ab6800744514..dcd67c53b18690 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -462,12 +462,11 @@ export default function Image( { return { lockUrlControls: !! urlBinding && - ( ! urlBindingSource || - urlBindingSource?.lockAttributesEditing( { - select, - context, - args: urlBinding?.args, - } ) ), + ! urlBindingSource?.canUserEditValue( { + select, + context, + args: urlBinding?.args, + } ), lockHrefControls: // Disable editing the link of the URL if the image is inside a pattern instance. // This is a temporary solution until we support overriding the link on the frontend. @@ -478,12 +477,11 @@ export default function Image( { hasParentPattern, lockAltControls: !! altBinding && - ( ! altBindingSource || - altBindingSource?.lockAttributesEditing( { - select, - context, - args: altBinding?.args, - } ) ), + ! altBindingSource?.canUserEditValue( { + select, + context, + args: altBinding?.args, + } ), lockAltControlsMessage: altBindingSource?.label ? sprintf( /* translators: %s: Label of the bindings source. */ @@ -493,12 +491,11 @@ export default function Image( { : __( 'Connected to dynamic data' ), lockTitleControls: !! titleBinding && - ( ! titleBindingSource || - titleBindingSource?.lockAttributesEditing( { - select, - context, - args: titleBinding?.args, - } ) ), + ! titleBindingSource?.canUserEditValue( { + select, + context, + args: titleBinding?.args, + } ), lockTitleControlsMessage: titleBindingSource?.label ? sprintf( /* translators: %s: Label of the bindings source. */ diff --git a/packages/blocks/src/store/private-actions.js b/packages/blocks/src/store/private-actions.js index a47d9aacab37ae..dd6650338d9d1a 100644 --- a/packages/blocks/src/store/private-actions.js +++ b/packages/blocks/src/store/private-actions.js @@ -55,6 +55,6 @@ export function registerBlockBindingsSource( source ) { setValue: source.setValue, setValues: source.setValues, getPlaceholder: source.getPlaceholder, - lockAttributesEditing: source.lockAttributesEditing, + canUserEditValue: source.canUserEditValue, }; } diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index e7d2f553a8069c..c00810c534d55d 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -381,8 +381,7 @@ export function blockBindingsSources( state = {}, action ) { setValue: action.setValue, setValues: action.setValues, getPlaceholder: action.getPlaceholder, - lockAttributesEditing: - action.lockAttributesEditing || ( () => true ), + canUserEditValue: action.canUserEditValue || ( () => false ), }, }; } diff --git a/packages/editor/src/bindings/pattern-overrides.js b/packages/editor/src/bindings/pattern-overrides.js index e4be293246f352..740692b9e9a62f 100644 --- a/packages/editor/src/bindings/pattern-overrides.js +++ b/packages/editor/src/bindings/pattern-overrides.js @@ -89,7 +89,5 @@ export default { }, } ); }, - lockAttributesEditing() { - return false; - }, + canUserEditValue: () => true, }; diff --git a/packages/editor/src/bindings/post-meta.js b/packages/editor/src/bindings/post-meta.js index 62d073b212b0a1..872b30e26acd81 100644 --- a/packages/editor/src/bindings/post-meta.js +++ b/packages/editor/src/bindings/post-meta.js @@ -31,20 +31,20 @@ export default { }, } ); }, - lockAttributesEditing( { select, context, args } ) { + canUserEditValue( { select, context, args } ) { const postType = context?.postType || select( editorStore ).getCurrentPostType(); // Check that editing is happening in the post editor and not a template. if ( postType === 'wp_template' ) { - return true; + return false; } // Check that the custom field is not protected and available in the REST API. const isFieldExposed = select( editorStore ).getEditedPostAttribute( 'meta' )[ args.key ]; if ( ! isFieldExposed ) { - return true; + return false; } // Check that the user has the capability to edit post meta. @@ -54,9 +54,9 @@ export default { context?.postId ); if ( ! canUserEdit ) { - return true; + return false; } - return false; + return true; }, };