Skip to content

Commit

Permalink
Block Bindings: lock editing of blocks by default (#58787)
Browse files Browse the repository at this point in the history
* Lock editing by default when bindings exist

* Use default in post meta source

* Set `lockEditing` to false in pattern overrides

* Move default value to reducer

* Use `_x` for sources translations

* Add context to translations
  • Loading branch information
SantosGuillamot authored and youknowriad committed Feb 13, 2024
1 parent 50cd70c commit 72a22e5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/use-bindings-attributes.js
Expand Up @@ -46,7 +46,7 @@ const createEditFunctionWithBindingsAttribute = () =>
settings.source
);

if ( source ) {
if ( source && source.useSource ) {
// Second argument (`updateMetaValue`) will be used to update the value in the future.
const {
placeholder,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/store/reducer.js
Expand Up @@ -2057,7 +2057,7 @@ function blockBindingsSources( state = {}, action ) {
[ action.sourceName ]: {
label: action.sourceLabel,
useSource: action.useSource,
lockAttributesEditing: action.lockAttributesEditing,
lockAttributesEditing: action.lockAttributesEditing ?? true,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/button/edit.js
Expand Up @@ -246,7 +246,7 @@ function ButtonEdit( props ) {
lockUrlControls:
!! metadata?.bindings?.url &&
getBlockBindingsSource( metadata?.bindings?.url?.source )
?.lockAttributesEditing === true,
?.lockAttributesEditing,
};
},
[ isSelected ]
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/image/edit.js
Expand Up @@ -349,7 +349,7 @@ export function ImageEdit( {
lockUrlControls:
!! metadata?.bindings?.url &&
getBlockBindingsSource( metadata?.bindings?.url?.source )
?.lockAttributesEditing === true,
?.lockAttributesEditing,
};
},
[ isSingleSelected ]
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/image/image.js
Expand Up @@ -427,19 +427,19 @@ export default function Image( {
lockUrlControls:
!! urlBinding &&
getBlockBindingsSource( urlBinding?.source )
?.lockAttributesEditing === true,
?.lockAttributesEditing,
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.
hasParentPattern,
lockAltControls:
!! altBinding &&
getBlockBindingsSource( altBinding?.source )
?.lockAttributesEditing === true,
?.lockAttributesEditing,
lockTitleControls:
!! titleBinding &&
getBlockBindingsSource( titleBinding?.source )
?.lockAttributesEditing === true,
?.lockAttributesEditing,
};
},
[ clientId, isSingleSelected, metadata?.bindings ]
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/bindings/index.js
Expand Up @@ -7,7 +7,9 @@ import { dispatch } from '@wordpress/data';
* Internal dependencies
*/
import { unlock } from '../lock-unlock';
import patternOverrides from './pattern-overrides';
import postMeta from './post-meta';

const { registerBlockBindingsSource } = unlock( dispatch( blockEditorStore ) );
registerBlockBindingsSource( patternOverrides );
registerBlockBindingsSource( postMeta );
11 changes: 11 additions & 0 deletions packages/editor/src/bindings/pattern-overrides.js
@@ -0,0 +1,11 @@
/**
* WordPress dependencies
*/
import { _x } from '@wordpress/i18n';

export default {
name: 'core/pattern-overrides',
label: _x( 'Pattern Overrides', 'block bindings source' ),
useSource: null,
lockAttributesEditing: false,
};
5 changes: 2 additions & 3 deletions packages/editor/src/bindings/post-meta.js
Expand Up @@ -3,15 +3,15 @@
*/
import { useEntityProp } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { store as editorStore } from '../store';

export default {
name: 'core/post-meta',
label: __( 'Post Meta' ),
label: _x( 'Post Meta', 'block bindings source' ),
useSource( props, sourceAttributes ) {
const { getCurrentPostType } = useSelect( editorStore );
const { context } = props;
Expand All @@ -38,5 +38,4 @@ export default {
useValue: [ metaValue, updateMetaValue ],
};
},
lockAttributesEditing: true,
};

0 comments on commit 72a22e5

Please sign in to comment.