From a0fb3c6d9bed0c1fc560677a0c58c7613bcf0744 Mon Sep 17 00:00:00 2001 From: Mario Santos <34552881+SantosGuillamot@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:25:15 +0200 Subject: [PATCH] Block Bindings: Don't provide default `canUserEditValue` in reducer (#63628) * Remove default `canUserEditValue` * Call `canUserEditValue` conditionally Co-authored-by: SantosGuillamot Co-authored-by: ockham Co-authored-by: artemiomorales --- packages/block-editor/src/components/rich-text/index.js | 2 +- packages/block-library/src/button/edit.js | 2 +- packages/block-library/src/image/edit.js | 2 +- packages/block-library/src/image/image.js | 6 +++--- packages/blocks/src/api/test/registration.js | 2 +- packages/blocks/src/store/reducer.js | 3 +-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index cc22c9b804130..68f00ca1b5d14 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -188,7 +188,7 @@ export function RichTextWrapper( binding.source ); if ( - ! blockBindingsSource?.canUserEditValue( { + ! blockBindingsSource?.canUserEditValue?.( { select, context: blockContext, args: binding.args, diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index e5bd5e6b5f064..3b2bb562e63c0 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -247,7 +247,7 @@ function ButtonEdit( props ) { return { lockUrlControls: !! metadata?.bindings?.url && - ! blockBindingsSource?.canUserEditValue( { + ! blockBindingsSource?.canUserEditValue?.( { select, context, args: metadata?.bindings?.url?.args, diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index df07fd0474eff..9eba4dacb57c3 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -308,7 +308,7 @@ export function ImageEdit( { return { lockUrlControls: !! metadata?.bindings?.url && - ! blockBindingsSource?.canUserEditValue( { + ! blockBindingsSource?.canUserEditValue?.( { select, context, args: metadata?.bindings?.url?.args, diff --git a/packages/block-library/src/image/image.js b/packages/block-library/src/image/image.js index 17a860fa5f47c..5f376ffdac862 100644 --- a/packages/block-library/src/image/image.js +++ b/packages/block-library/src/image/image.js @@ -479,7 +479,7 @@ export default function Image( { return { lockUrlControls: !! urlBinding && - ! urlBindingSource?.canUserEditValue( { + ! urlBindingSource?.canUserEditValue?.( { select, context, args: urlBinding?.args, @@ -494,7 +494,7 @@ export default function Image( { hasParentPattern, lockAltControls: !! altBinding && - ! altBindingSource?.canUserEditValue( { + ! altBindingSource?.canUserEditValue?.( { select, context, args: altBinding?.args, @@ -508,7 +508,7 @@ export default function Image( { : __( 'Connected to dynamic data' ), lockTitleControls: !! titleBinding && - ! titleBindingSource?.canUserEditValue( { + ! titleBindingSource?.canUserEditValue?.( { select, context, args: titleBinding?.args, diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 26319253a13ab..991b299c08abf 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -1607,7 +1607,7 @@ describe( 'blocks', () => { expect( source.setValue ).toBeUndefined(); expect( source.setValues ).toBeUndefined(); expect( source.getPlaceholder ).toBeUndefined(); - expect( source.canUserEditValue() ).toBe( false ); + expect( source.canUserEditValue ).toBeUndefined(); unregisterBlockBindingsSource( 'core/valid-source' ); } ); diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index 1b6d348fd9ddd..4237590f8887a 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -382,8 +382,7 @@ export function blockBindingsSources( state = {}, action ) { setValue: action.setValue, setValues: action.setValues, getPlaceholder: action.getPlaceholder, - canUserEditValue: - action.canUserEditValue || ( () => false ), + canUserEditValue: action.canUserEditValue, }, }; case 'REMOVE_BLOCK_BINDINGS_SOURCE':