Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Bindings: lock editing of blocks by default #58787

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
};