Skip to content

Commit

Permalink
Block Bindings: Don't provide default canUserEditValue in reducer (#…
Browse files Browse the repository at this point in the history
…63628)

* Remove default `canUserEditValue`

* Call `canUserEditValue` conditionally

Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>
Co-authored-by: ockham <bernhard-reiter@git.wordpress.org>
Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
  • Loading branch information
4 people authored Jul 19, 2024
1 parent d09b7ac commit a0fb3c6
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function RichTextWrapper(
binding.source
);
if (
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context: blockContext,
args: binding.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function ButtonEdit( props ) {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context,
args: metadata?.bindings?.url?.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function ImageEdit( {
return {
lockUrlControls:
!! metadata?.bindings?.url &&
! blockBindingsSource?.canUserEditValue( {
! blockBindingsSource?.canUserEditValue?.( {
select,
context,
args: metadata?.bindings?.url?.args,
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export default function Image( {
return {
lockUrlControls:
!! urlBinding &&
! urlBindingSource?.canUserEditValue( {
! urlBindingSource?.canUserEditValue?.( {
select,
context,
args: urlBinding?.args,
Expand All @@ -494,7 +494,7 @@ export default function Image( {
hasParentPattern,
lockAltControls:
!! altBinding &&
! altBindingSource?.canUserEditValue( {
! altBindingSource?.canUserEditValue?.( {
select,
context,
args: altBinding?.args,
Expand All @@ -508,7 +508,7 @@ export default function Image( {
: __( 'Connected to dynamic data' ),
lockTitleControls:
!! titleBinding &&
! titleBindingSource?.canUserEditValue( {
! titleBindingSource?.canUserEditValue?.( {
select,
context,
args: titleBinding?.args,
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
} );

Expand Down
3 changes: 1 addition & 2 deletions packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit a0fb3c6

Please sign in to comment.